cmux-next agent pane: mock mode runs the real client against an in-page daemon

Merged
TE
1mo ago
+314-205

Part of the cmux-next parity work listed in #16174 (comment). Groundwork for the agent pane fixes from the real-agent clip on #16231 (comment).

Problem

Mock mode (CMUX_NEXT_AGENT_PANE_MOCK=1) kept its own list of finished rows and never ran the acpmux client. A mock turn skipped the event folding, which is where the clip's bugs live: joined message chunks, the wrong tool count and the status text. So fleet captures in mock mode could neither show those bugs nor prove a fix.

Change

  • MockAcpmuxSocket is an in-page acpmux daemon behind the WebSocket interface. It answers initialize, _acpmux/watch, _acpmux/harnesses, _acpmux/attach, _acpmux/events, session/new and session/prompt, and honours session/cancel.
  • A prompt streams a scripted turn as real _acpmux/event records, in the order a real agent sends them:
    • the user message and turn start;
    • two text chunks;
    • a read tool call with its update;
    • more text;
    • an edit with a diff and a location line, then its completion;
    • a new file;
    • an answer with a nested list;
    • a turn result.
  • In mock mode the page now connects the real AcpmuxDirectClient to that socket, through a new optional socket factory on connect. Everything after the socket is the production path: reducer, catalog query, renderers and the changes view.
  • A mock session is not persisted to the host.

The four transcript fixes (#16591 to #16594) have since merged, so a mock turn now shows the fixed transcript. The polish wave's browser harness (#16598) drives this mode.

Verification

  • bun test src/agent-session/acpmux: 87 pass. The mock test connects the real client to the mock socket and checks the transcript, catalog and edits that a prompt produces.
  • bun run lint:ci and tsgo --noEmit are clean.
  • Rendered in headless Chromium from the built page after merging feat-cmux-next (7fa278e): a mock turn goes through the client, and the reply splits around its tool fold in order.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Reworks agent-pane mock mode to run the real acpmux client against an in-page daemon, so a mock turn goes through the same event folding as a real agent's. Previously mock mode kept its own list of finished rows and never ran the client, so fleet captures of mock turns could neither show the joined-text, tool-count, and status-text bugs nor prove a fix.

MockAcpmuxSocket answers the daemon's JSON-RPC and paces a scripted turn as real _acpmux/event records; AcpmuxDirectClient.connect gains an optional socket factory, and everything below the socket is the unchanged production path. Mock sessions are not persisted to the host. New chats are sessions of their own with an empty transcript, prompts run one at a time as the daemon queues them, and closing the socket cancels a running turn; tests cover Stop and New chat.