Skip to content

refactor(server): move client command dispatch out of ws.ts - #112

Merged
adampeterhiggins merged 1 commit into
mainfrom
ah/mcp-thread-write-operations
Oct 1, 2026
Merged

adampeterhiggins merged 1 commit into
mainfrom
ah/mcp-thread-write-operations

Conversation

@adampeterhiggins

@adampeterhiggins adampeterhiggins commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Stack 1 of 8: agents operate T3 Code over MCP.

Thread bootstrap lived inside the per-connection WebSocket RPC closure in ws.ts. That covers creating the thread, preparing the worktree, running the setup script, cloning context repositories, the startup command queue, and the session stop and terminal close after an archive. Anything else that dispatched a command skipped it. For example, POST /api/orchestration/dispatch handed a bootstrap thread.turn.start straight to the engine. The MCP write tools later in this stack need the same path.

This moves that code into ClientCommandDispatcher (apps/server/src/orchestration/ClientCommandDispatcher.ts). forOrigin(origin).dispatch(normalizedCommand) runs a command the way a client send does, and tags every server-generated step with the caller's origin.

  • The move is mechanical. Ignoring whitespace and trailing commas, the moved code is identical to the original.
  • What callers keep: normalizing the command, cleaning up failed uploads, and analytics.
  • POST /api/orchestration/dispatch now uses the dispatcher too, so a bootstrap turn over HTTP creates its thread like one over the WebSocket. A new test in server.test.ts covers this; it fails against the old route.
  • Clone rejection now runs after normalization, so attachments uploaded with a command rejected mid-clone are cleaned up.

Testing:

  • tsc on apps/server is clean.
  • server.test.ts + bin.test.ts: 234/235 pass. flushes more than one tool chunk before the synchronization marker fails on main as well.

Done by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

Thread bootstrap (create, worktree, setup script, context repositories),
the startup command queue, and post-archive cleanup lived inside the
WebSocket RPC closure, so the HTTP dispatch route skipped all of it.
They now live in ClientCommandDispatcher, which both transports call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@adampeterhiggins
adampeterhiggins force-pushed the ah/mcp-thread-write-operations branch from c72016c to c56b00c Compare October 1, 2026 08:28
@adampeterhiggins
adampeterhiggins merged commit 7c1194b into main Oct 1, 2026
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