feat(remote): session ownership + myagent remote client CLI (M2.2)#12
Merged
Conversation
Builds on M1.3's bearer-token handshake. Two capabilities:
SESSION OWNERSHIP (packages/core/src/remote.ts)
- New `{ type: "role", role: "owner" | "follower" }` server message,
sent right after `ready` on every connection.
- The first authenticated connection becomes the owner. Later
connections are read-only followers. `createRemoteAgentServer` now
tracks `ownerConnectionId` plus a `connections` registry for fan-out.
- `user_message` and `permission_decision` are owner-only — a
follower gets `{ type: "error", message: "read-only follower ..." }`
and the turn/decision is not processed. `resume` and `ping` stay
open to any client (read-only / liveness).
- The owner's turn stream (agent_stdout/stderr, permission_request,
terminal_state, session_metadata) is now broadcast to every
connection so followers can watch live. `ack` and input-validation
errors stay targeted to the submitter.
- Owner disconnect releases the slot; the next NEW connection claims
it. Existing followers are deliberately NOT auto-promoted — keeps
the ownership transition race-free and predictable.
Backward compatible: a lone client (every existing remote test) is
the owner, and broadcast-to-one == the old targeted send. protocol
version stays 1; `role` is purely additive (unknown-message-tolerant
clients ignore it).
REMOTE CLIENT CLI (packages/cli/src/index.ts)
myagent remote client [--url ws://host:port] [--token <t>]
[--prompt "<p>"] [--session <id>]
- Parses --url (or --host/--port), resolves the token from --token or
falls back to the local .myagent/remote/auth.json.
- Prints the assigned role, streams agent stdout/stderr to the local
terminal, and forwards permission_request to the local TTY via the
existing prompt-session + requestPermissionFromPrompt path, sending
back permission_decision.
- With --prompt it submits a turn and exits on terminal_state; without
it, it's a pure read-only watcher (Ctrl+C to leave).
Tests: packages/core/test/security/remote-ownership.test.ts (6 cases)
— role assignment, follower user_message/permission_decision
rejection, broadcast-to-follower, owner-disconnect promotion of a
NEW connection, and no-auto-promotion of an existing follower.
Updated the cli --help assertion for the new subcommand list.
Security catalog + CLAUDE.md updated.
Local: 181 tests, 3/3 green.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on M1.3's bearer-token handshake. Two capabilities:
SESSION OWNERSHIP (packages/core/src/remote.ts)
{ type: "role", role: "owner" | "follower" }server message, sent right afterreadyon every connection.createRemoteAgentServernow tracksownerConnectionIdplus aconnectionsregistry for fan-out.user_messageandpermission_decisionare owner-only — a follower gets{ type: "error", message: "read-only follower ..." }and the turn/decision is not processed.resumeandpingstay open to any client (read-only / liveness).ackand input-validation errors stay targeted to the submitter.Backward compatible: a lone client (every existing remote test) is the owner, and broadcast-to-one == the old targeted send. protocol version stays 1;
roleis purely additive (unknown-message-tolerant clients ignore it).REMOTE CLIENT CLI (packages/cli/src/index.ts)
myagent remote client [--url ws://host:port] [--token ]
[--prompt "
"] [--session ]
Tests: packages/core/test/security/remote-ownership.test.ts (6 cases) — role assignment, follower user_message/permission_decision rejection, broadcast-to-follower, owner-disconnect promotion of a NEW connection, and no-auto-promotion of an existing follower. Updated the cli --help assertion for the new subcommand list. Security catalog + CLAUDE.md updated.
Local: 181 tests, 3/3 green.