feat(cli): add external-agent identity and listen primitives
Summary
Adds the CLI primitives needed for a resident external agent to identify itself, publish a complete agent profile, and consume scoped Buzz events without being owned or supervised by Desktop.
What changed
- Adds
buzz users me, a local identity command that prints the configured public identity without making a relay request or exposing private key material. - Adds
buzz listen, which streams channel-scoped and mention-scoped relay events as NDJSON with a versioned envelope suitable for long-running external consumers. - Adds
buzz keys generate, a local-only identity generation command that writes secrets with owner-only permissions and refuses accidental overwrite. - Adds
buzz agents profile get/setand routeschannels set-add-policythrough the same read-modify-write path so kind:10100 updates do not clobber existing profile fields. - Documents the external-agent CLI contract and adds fixture/subprocess tests for identity, listen, fixture normalization, and key generation behavior.
Why
Buzz already has the relay and profile model needed for agents that run outside Desktop, but the CLI was missing a small stable contract for those agents to bootstrap safely. External adapters need to prove local key custody, publish the agent's own directory record, and receive scoped events without relying on Desktop-owned process lifecycle or private key transfer.
The implementation keeps the boundary narrow: it adds generic CLI primitives and tests, without adding runtime-specific adapter code or new relay endpoints.
Compatibility / risk
- Existing compact message consumers remain compatible; additional compact fields are additive.
buzz listenis opt-in and uses explicit channel/mention filters.buzz keys generatedoes not require an existing Buzz identity or relay connection, and does not print the secret unless explicitly requested.- kind:10100 writes become safer by preserving existing and unknown profile fields instead of publishing partial replacement documents.
Validation
cargo fmt -p buzz-cli --check— passedcargo clippy -p buzz-cli --all-targets -- -D warnings— passedcargo test -p buzz-cli— passed
I exercised the CLI branch in a composed checkout (all Buzz CLI/unit and added external-agent tests passed), but found four production blockers for long-running Hermes/OpenClaw residents:
-
Windows secret-file ACLs:
keys generate --outapplies/reasserts0600only under#[cfg(unix)]. On Windows the key inherits the parent DACL while the command/docs promise owner-only storage. Please install and verify a restrictive DACL or fail closed as unsupported; a transactional write would also avoid partial key files. -
Replaceable-profile lost updates:
apply_profile_updateperforms fetch → merge → publish without optimistic concurrency or post-write head verification. Kind10100uses second-resolution timestamps and event-ID tie-breaking, while a dominated replaceable event can still produce an accepted/duplicate response and exit zero. Same-second or concurrent updates can therefore be lost while the adapter believes they succeeded. Please verify the submitted event became the current head and return conflict/retry otherwise. -
Lossy catch-up above 1,000 events:
listen --sincesupplies no limit, pagination cursor, or overflow signal. The relay/DB ceiling defaults to the newest 1,000 rows and then emits EOSE, silently skipping older unseen events after a long outage. A resident bridge needs paginated catch-up or an explicit composite cursor/overflow recovery contract. -
Events cannot be independently verified: the WebSocket path deserializes relay events, then
normalize_eventsremovessigbefore output. The adapter cannot verify the claimed ID/author afterward, yet owner/allowlist activation depends on those claims. Please verify ID/signature before emitting and preservesig(or include an explicit trustworthy verification result), with tests for forged authors, invalid signatures, and filter mismatches.
The scoped #h/#p subscriptions, NIP-42/NIP-OA use, public-only users me, and documented at-least-once reconnect behavior are good foundations. These fixes would make the surface suitable for a durable independently hosted resident rather than only a happy-path adapter.
@murdawkmedia Thanks for the careful read. I agree these are the right durability concerns, especially event verification/signature preservation and bounded catch-up.
Before I start changing the branch, I want to confirm whether this CLI surface is still the path maintainers want under the broader remote/resident-agent direction in #4174. If yes, I think this PR can be tightened sooner rather than later around the items you called out.
@murdawkmedia I refreshed this branch onto current upstream main and addressed all four durability blockers in d3e92df21:
- Windows secret-file output now fails closed until a verified owner-only ACL path exists.
- Kind:10100 writes now reject dominated/duplicate responses and verify the submitted event is the current coordinate head.
listen --sincecounts each scoped filter and fails with an explicit recovery error above the relay 1,000-event ceiling.- Listen now verifies filter membership, canonical IDs, and Schnorr signatures before emitting, preserves
sig, and has negative coverage for forged/out-of-scope events.
cargo test -p buzz-cli and the full just ci repository gate pass on head d3e92df212f0572326ce35a50ab6471edcc0faaf. The PR body now documents the overlap with #2942 so maintainers can evaluate the generic primitives without ambiguity.
Final rewrite note: the current one-commit head 0ba5a8662 replaces the earlier branch history, so my prior update about the old profile-write implementation is historical and no longer describes this PR.
The current draft contains no kind:10100 writer or profile merge path. It keeps only the generic, independently useful pieces: verified scoped listening, bounded catch-up, safe local key generation, public identity inspection, lifecycle/error behavior, and implementation-independent fixtures. Directory publication, activation/routing policy, process supervision, and deployment configuration are all out of scope pending the upstream directory decision.
The rewritten head passed just ci; current DCO, Semgrep, and zizmor checks are green.
Thanks for the rewrite. I rechecked 0ba5a866: event ID/signature verification and signature-preserving output are present, Windows key-file output fails closed, and the old profile writer is outside the new scope. All 41 selected CLI/core tests and integrations passed in an isolated CLI workspace; I have not run the full workspace or native Windows tests.
One replay gap remains. COUNT runs once before the reconnect loop. With a fake relay reporting 0 initially and 1001 after disconnect, the CLI reconnected with the same since and limit=1000, then emitted EOSE without another COUNT. This proves the missing recheck; event loss is inferred from the bounded request rather than a replay of 1001 signed events. Could the bounded-window check run before every resubscription, or reconnect require a fresh consumer cursor? Please add that regression. The unconditional key-file success tests also need Windows guards to match the deliberate refusal.