Fold doctor into status, and stop id taking the lock
`status` asked a running agent and failed without one; `doctor` checked
the host and ignored the agent. Between them they answered one question
in two halves. They are now one command: device, agent, networks, host
capability, local addresses, all graded and aligned the same way.
`id` was worse than either. It spawned a whole agent to print three
facts, which took the directory lock and so failed with "owned by
another running agent instance" exactly when the answer was most wanted.
The lock exists to keep one writer over the mandatory state; reading who
this device is needs no such thing.
So both commands now prefer the running agent, which is live and
authoritative, and fall back to the state store, which takes no lock.
StateStore gains device_identity(), which reads and never writes:
load_or_create had the side effect of deciding an identity as a
consequence of asking about one.
Presentation moved out of the library. StatusReport::render is gone and
the CLI renders the structured data, so there is one renderer rather than
two that would drift. Health gains an Info level for rows that are facts
rather than checks — an endpoint id is neither good nor bad, and a column
of green next to plain data teaches the eye to ignore the column. A
report with no checks in it now ends without a summary instead of
claiming that everything checked out.
PathAddr and TransportKind grew Display impls; both were reaching the
user through {:?}, which is how "Direct via Ip(88.198.17.44:49792)" got
printed. The transport grading compares without regard to case, because
the agent answering can be a different build from the client asking and
this field's spelling has now changed once.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+24
-12
@@ -175,11 +175,15 @@ impl StateStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Loads the stored device identity, creating one on first use.
|
||||
/// Loads the stored device identity, if there is one.
|
||||
///
|
||||
/// A stored key of the wrong length is a corruption error, never a reason to
|
||||
/// silently mint a new identity.
|
||||
pub fn load_or_create_device_identity(&self) -> Result<DeviceIdentity> {
|
||||
/// Reads and never writes, so asking who this device is does not decide
|
||||
/// it. A store that has never run an agent has no identity yet, which is
|
||||
/// `None` rather than an error.
|
||||
///
|
||||
/// A stored key of the wrong length is a corruption error, never a reason
|
||||
/// to silently mint a new identity.
|
||||
pub fn device_identity(&self) -> Result<Option<DeviceIdentity>> {
|
||||
let stored: Option<Vec<u8>> = self
|
||||
.conn
|
||||
.query_row(
|
||||
@@ -190,14 +194,22 @@ impl StateStore {
|
||||
.optional()
|
||||
.map_err(|err| self.corrupt(format!("cannot read device identity: {err}")))?;
|
||||
|
||||
if let Some(bytes) = stored {
|
||||
let bytes: [u8; 32] = bytes.as_slice().try_into().map_err(|_| {
|
||||
self.corrupt(format!(
|
||||
"stored device key has {} bytes, expected 32; refusing to replace it",
|
||||
bytes.len()
|
||||
))
|
||||
})?;
|
||||
return Ok(DeviceIdentity::from_secret_bytes(&bytes));
|
||||
let Some(bytes) = stored else {
|
||||
return Ok(None);
|
||||
};
|
||||
let bytes: [u8; 32] = bytes.as_slice().try_into().map_err(|_| {
|
||||
self.corrupt(format!(
|
||||
"stored device key has {} bytes, expected 32; refusing to replace it",
|
||||
bytes.len()
|
||||
))
|
||||
})?;
|
||||
Ok(Some(DeviceIdentity::from_secret_bytes(&bytes)))
|
||||
}
|
||||
|
||||
/// Loads the stored device identity, creating one on first use.
|
||||
pub fn load_or_create_device_identity(&self) -> Result<DeviceIdentity> {
|
||||
if let Some(identity) = self.device_identity()? {
|
||||
return Ok(identity);
|
||||
}
|
||||
|
||||
let identity = DeviceIdentity::generate();
|
||||
|
||||
Reference in New Issue
Block a user