Skip to content

feat(agent): M7 — headless serve control protocol over stdio#9

Merged
jaredLunde merged 1 commit into
mainfrom
agent-serve
Jun 30, 2026
Merged

feat(agent): M7 — headless serve control protocol over stdio#9
jaredLunde merged 1 commit into
mainfrom
agent-serve

Conversation

@jaredLunde

Copy link
Copy Markdown
Contributor

What — M7: headless serve

The provable headless server — modeled on pi's rpc mode and opencode's session server. The server is the source of truth; any client (a TUI, an editor, or an ssh pipe) drives it over newline-delimited JSON on stdio. This is the "remote control over SSH" requirement.

agent-core

  • AgentEvent (Stream(StreamEvent) / ToolStart / ToolEnd / TurnEnd) + Agent::run_events — the full observation surface. Agent::run becomes a thin wrapper forwarding only Stream events (no behavior change to existing callers/tests).

agent (serve)

  • Commands (stdin): {id?, type, …}prompt | get_state | get_messages | new_session.
  • Frames (stdout): {type:"response", …} and streamed {type:"event", event: <AgentEvent>}; a ready frame on startup. One writer task serializes all frames so output never interleaves.
  • Session persistence to --session-file after each turn → a later serve over the same file reattaches with the full transcript.

Proven by

tests/serve_e2e.rs drives the real serve binary over stdin/stdout against a mock model server:

  1. prompt → streams tool_start/tool_end events for a read round-trip, then a success response.
  2. get_messages → returns the transcript (tool result + final text).
  3. A fresh serve process over the same --session-file reattaches and restores the transcript — no re-prompt.

Plus the M5 run e2e still passes. Whole workspace: clippy -D warnings, cargo fmt --all --check, all unit + e2e tests green.

Series: M1 #5 · M2 #6 · M3+M4 #7 · M5+M6 #8 merged. Next: M8 — Beyond platform tools (fork/sync/logs) + full e2e through the actual gateway binary.

🤖 Generated with Claude Code

agent-core: add AgentEvent (Stream/ToolStart/ToolEnd/TurnEnd) and
Agent::run_events — the full observation surface. Agent::run is now a thin
wrapper that forwards only Stream events. No behavior change to existing tests.

agent: `beyond-ai-agent serve` — a newline-delimited JSON control protocol
over stdio, modeled on pi's rpc mode + opencode's session server. The server
is the source of truth; any client (TUI, editor, or an SSH pipe) drives it:
- commands {id?,type,…}: prompt | get_state | get_messages | new_session
- frames: {type:"response",…} and streamed {type:"event", event:<AgentEvent>}
- session state serde-persisted to --session-file, so a later serve over the
  same file reattaches with the full transcript (the SSH remote-control story).

Proven by a serve e2e (tests/serve_e2e.rs) driving the REAL binary over
stdin/stdout against a mock model server: a prompt streams tool_start/tool_end
events then a success response, get_messages returns the transcript, and a
FRESH serve process reattaches to the persisted session and restores it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jaredLunde jaredLunde merged commit db73c37 into main Jun 30, 2026
1 check passed
@jaredLunde jaredLunde deleted the agent-serve branch June 30, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant