feat(cli): add headless agent session control

Merged
KI
4mo ago
+3709-298

What changed

  • add superset agents sessions list/read/send/wait for inspecting and continuing live terminal agents without opening the desktop renderer
  • expose non-destructive PTY snapshots through protocol v3 and render bounded ANSI state through headless xterm
  • preserve protocol v2 negotiation for existing daemons and fd-handoff upgrades while gating snapshots to v3
  • add normalized lifecycle status, exact cross-host session resolution, multiline bracketed-paste sends, cancellation/timeouts, and race-safe send --wait
  • replace large interactive prompt writes with a secure prompt-file/POSIX launcher and launch acknowledgement for argv- and stdin-based agents
  • add repeatable local/pre-uploaded attachments to workspaces create --agent and preserve attachment-expanded large prompts
  • report partial failure when workspace creation succeeds but its inline agent does not start
  • add a production-ABI CLI E2E harness with ignored, scrubbed artifacts
  • share cross-host discovery between workspace and agent-session commands
  • document the CLI surface and the real Electron/CDP verification workflow

Why

The CLI could launch an agent but could not read or continue the resulting
session. Large prompts could also be truncated at the PTY line-editor boundary
while the CLI still returned a successful terminal ID.

This keeps the PTY daemon as the owner of live process state and exposes the
smallest useful headless loop: find a live session, inspect recent output, send
one semantic follow-up, and optionally wait for the resulting transition.

Impact

Scripts and operators can control live terminal agents while the renderer is
closed. Reads take bounded, non-attaching snapshots. Sends survive a
host-service restart by adopting the daemon-owned PTY. Exited sessions are not
silently recreated, and immediate launch failures no longer masquerade as
success. Explicit --file <path> prompts do not consume ambient non-TTY stdin,
and a new host can still reach and hand off an existing v2 daemon without
losing its live PTYs.

Workspace creation now accepts repeatable local attachment paths and pre-uploaded attachment IDs for inline agent launches, using the same upload and prompt-expansion boundary as agents create.

Issues

Closes #5767
Closes #5475
Resolves SUPER-1568

Partially addresses #5252, #5126, and #5029. Those broader issues remain open for generic terminal control, historical indexing/recovery, attach/close, and direct session-opening support.

Related follow-ups: #5092, #4705, and #5305 are not resolved by this PR.

Validation

  • CLI E2E: 8/8 assertions across 9 real CLI subprocesses
  • exact 87,994-byte multiline/Unicode prompt delivery with SHA-256 agreement
  • explicit file prompt ignores ambient non-TTY stdin
  • protocol v2 client negotiation, list, and handoff request; v3-only snapshot guard
  • host supervisor probes advertise v2/v3 compatibility
  • CLI session unit tests: 10 passed
  • focused host tests: 58 passed
  • PTY daemon unit tests: 65 passed
  • PTY daemon integration: 55 passed, including live two-session fd handoff
  • daemon client integration: 9 passed
  • monorepo typecheck: 35/35 tasks
  • repository lint: 5,254 files clean
  • documented shell snippets pass bash -n
  • git diff --check: clean

The standalone host adoption suite is locally blocked by a pre-existing
better-sqlite3 Node ABI mismatch. The Electron-as-Node E2E exercises the
relevant production-ABI launch and restart path successfully.


Open in Stage