back all client modes with the daemon - #456
Conversation
ENG-4685 Daemon-back all Prime Agent client modes
OutcomeMake the daemon/supervisor the execution infrastructure for every Prime Agent CLI client form while preserving all existing public behavior and wire contracts. Interactive, print, JSON, and RPC are client modes. The daemon is not a peer mode; it owns every root Existing evals, scripts, subprocess clients, and SDK consumers must continue to work without changes. The migration must preserve CLI parsing, stdout/stderr, exit codes, JSONL/RPC framing and schemas, event ordering, prompt semantics, session selection, extension behavior, signal handling, and model-visible context. Current state
Relevant foundations already exist:
Design principles
Compatibility contractBefore changing routing, add characterization coverage for all externally observable behavior. CLI and process behavior
Print contract
JSON contract
RPC contract
Model/session contract
Implementation planPhase 0 — Freeze behavior with a dual-backend compatibility harness
Phase 1 — Separate client mode from service bootstrap
Phase 2 — Introduce shared daemon-backed client session bootstrapCreate one composition-root helper used by all four client modes, conceptually: createDaemonClientSession({
clientMode,
sessionSelection,
runtimeConfig,
compatibilityProfile,
lifecycle,
capabilities,
})It must:
Phase 3 — Add explicit daemon session leasesDaemon residency must not be inferred solely from socket disconnects.
Add protocol operations for graceful close/release and an idempotent cleanup path for disconnected clients. Phase 4 — Provide a headless
|
…t-modes # Conflicts: # packages/coding-agent/CHANGELOG.md # packages/coding-agent/src/modes/daemon/daemon-mode.ts
…t-modes # Conflicts: # packages/coding-agent/CHANGELOG.md # packages/coding-agent/src/cli/daemon-launch.ts # packages/coding-agent/src/cli/subprocess-launch.ts # packages/coding-agent/src/modes/agent-connection/daemon-agent-connection.ts # packages/coding-agent/src/modes/daemon/daemon-mode.ts # packages/coding-agent/src/modes/daemon/daemon-protocol.ts # packages/coding-agent/src/modes/daemon/daemon-supervisor.ts # packages/coding-agent/test/agent-connection-daemon.test.ts # packages/coding-agent/test/daemon-launch.test.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4ad36b2. Configure here.
* refactor(coding-agent): daemon back all client modes (ENG-4685) * fix(coding-agent): harden daemon client modes (ENG-4685) * fix(coding-agent): address daemon client review findings (ENG-4685) * fix(coding-agent): close daemon client review gaps (ENG-4685) * fix(coding-agent): preserve daemon client ordering (ENG-4685) * fix(coding-agent): validate rpc command shapes (ENG-4685) * fix daemon worker adoption * fix daemon owned-session authorization (fixes PrimeIntellect-ai#456) * hide client-owned daemon sessions (fixes PrimeIntellect-ai#456) * route stale daemon clients locally (fixes PrimeIntellect-ai#456) * fix(coding-agent): drain rpc prompts before eof fixes PrimeIntellect-ai#456 * fix(coding-agent): preserve rpc prompt streaming fixes PrimeIntellect-ai#456 * fix(coding-agent): preserve prompt wait calls fixes PrimeIntellect-ai#456

Note
High Risk
All standard client modes now depend on daemon availability and supervisor/worker correctness; regressions affect session isolation, RPC wire compatibility, and headless lifecycle across a large surface area.
Overview
Interactive, print, JSON, RPC, piped stdin, and
--no-sessionnow run on the same supervisor/worker runtime instead of separate in-process or legacy owned-worker frontends, while keeping existing CLI commands, output shapes, and exit behavior.Headless paths use client-owned daemon workers (
createDaemonClientConnection+DaemonAgentConnectionwithownedSession): print/JSON go throughrunPrintModeWithConnection, RPC throughrunRpcModeWithConnection, and completion uses sharedwaitForHeadlessCompletion/ new daemon commands (prompt_and_wait,execute_bash_and_wait,wait_for_headless_completion,get_session_header,set_auto_retry). Workers can be completed, reconnected with launch env, promoted to resident when cron/heartbeat is added, and cleaned up after owner disconnect grace.The daemon protocol gains
client_owned_sessions, lifecycle on create, and supervisor routing that hides client-owned workers from global list/agents view unless owner-scoped. RPC docs add daemon-parity commands (schedules, heartbeats, agent messaging,observe/unobserve).Startup:
maybeStartDaemonEarlyreplaces interactive-only early launch (includes-p/print, longer 30s timeout); legacy owned-worker frontend is off by default with rollback when a stale busy daemon is detected. Shutdown confirmation counts busy client-owned sessions. Subprocess spawn usescreateCliSubprocessEnvfor tsx/tsconfig propagation.Reviewed by Cursor Bugbot for commit a7ffbe7. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Route all CLI client modes (interactive, print, JSON, RPC) through the daemon
AgentConnectionabstraction instead of an in-process runtime, enabling session sharing, scheduling, and messaging across clients.client_owned_sessionscapability to the daemon protocol: clients can create private owned sessions that are cleaned up on disconnect (with a grace period) or explicitly promoted to resident sessions.DaemonAgentConnectionwith new methods:promptAndWait,waitForHeadlessCompletion,executeBashAndWait,sendAgentMessage, heartbeat/cron management, and session observation.observe/unobservefor live session events.runPrintModeWithConnectionandrunRpcModeWithConnectionare introduced as new public entrypoints so anyAgentConnectionimplementation can drive those modes.createCliSubprocessEnvto propagateTSX_TSCONFIG_PATHinto child processes when running under tsx.Macroscope summarized a7ffbe7.