Skip to content

feat: move RPC, ACP and CLI onto threads - #113

Merged
sanchitrk merged 6 commits into
canaryfrom
feat/thread-consumers-rpc-acp-cli
Oct 30, 2026
Merged

sanchitrk merged 6 commits into
canaryfrom
feat/thread-consumers-rpc-acp-cli

Conversation

@sanchitrk

@sanchitrk sanchitrk commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Moves the server RPC, ACP and CLI surfaces in packages/codework onto the thread model (session = container of linear threads). The apps (apps/web, apps/widget, desktop) follow in a separate PR; apps/ still compiles and stays wire-compatible.

RPC

  • Per-thread usage: ThreadInfo.usage = { cost, input, output, cacheRead, cacheWrite }, counting the thread's own entries only (the inherited prefix counts for its source).
  • session.relink returns the thread: it answers with ThreadInfo for the given threadId (main when absent), so its placement and embedded session show where it now runs, with no second call. The directory rebase lives in one place: the store's new rebase, used by both the embedder relink and the store relink.
  • Event filter: event.subscribe and session.log take an optional threadId. Only events whose data names that thread pass. server.connected still comes first and log.synced still ends the replay. There is still one session log and no new method; every thread-scoped event already carries threadId. Client.run now subscribes filtered.

ACP: each thread is an ACP session

The installed SDK (1.5.1) has session/fork, but only as "fork this session": it takes no entry, so on its own it can't reach forks made elsewhere (CLI, RPC). So every thread is an ACP session of its own:

  • The main thread keeps the CodeWork session id, so sessions an editor already knows still load. Every other thread uses its thread id.
  • session/list lists threads (a fork with no title shows its source's title). load replays the thread's whole line. prompt, cancel and set_config_option address that thread.
  • session/fork is advertised and forks at the line's last committed entry. With no messages yet it fails with invalidRequest.

CLI

  • codework thread list <session>: id, origin, model, tokens and cost, title. --json prints the wire form.
  • codework thread fork <session> [--thread <id|main>] (--at <entry> | --before <entry>): prints the new thread id, and for --before the text to edit.
  • codework session relink <session> [--thread <id|main>] [-C <dir>] [--sandbox-id <id>]
  • --thread parsing is shared with run. The new verbs talk to a running server, like session link.

Docs: the packages/codework and packages/harness READMEs describe threads. The docs site (sites/) is left for a separate update.

Tests (E2E, with __artifacts__/ snapshots)

  • server.threads.json: per-thread usage on the wire, a live event.subscribe({ threadId }) seeing only the fork while main also runs, session.log filtered, and relink placement for a thread vs. the session.
  • server.cli-threads.json: thread fork --at/--before, session relink --thread, thread list (text and --json decoded with the contract), and the error paths.
  • acp.fork.json: ACP session/fork, prompting the fork, listing both, and loading each with its line. It runs against a local fake chat-completions endpoint, so no live key is needed.
  • acp.json now includes the fork capability.

vp check passes. vp run typecheck passes except sites/www under parallel runs (exit 137, out of memory); it passes when run alone. Known unrelated failures: live deepseek (OpenRouter credits), and tui.test.ts "registration another server took over", because port 7610 is held by an orphaned server from another worktree on this machine. The ACP live case "streams, runs tools, cancels…" sometimes hits its 180s timeout, on openai in one run and on openai-codex in another; it does the same with this PR's cancel swapped back to the old session-wide interrupt.

🤖 Generated with Claude Code

sanchitrk and others added 6 commits October 29, 2026 23:23
ThreadInfo carries the thread's own billed usage. The session store's
new `rebase` is the only place that works out where a session's or a
thread's directory lands under another root; the embedder relink and
the store relink both use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- RPC: ThreadInfo gains `usage`; `session.relink` answers with the
  addressed thread (main when absent); `event.subscribe` and
  `session.log` take an optional `threadId` filter.
- ACP: every thread is an ACP session (main keeps the session id, others
  use their thread id) for list, load, prompt and cancel; `session/fork`
  forks at the last committed entry.
- CLI: `thread list`, `thread fork --at|--before`, and
  `session relink [--thread]`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Leaves the docs site as it was; it is updated separately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ACP `session/fork` cuts at the last committed entry of any type, as the
  harness does, so a trailing tool result or compaction comes along.
- The ACP one-prompt-at-a-time guard is keyed by thread, since main answers
  to both its session id and its thread id.
- `session relink -C` says what it does: the checkout to move into, with the
  work keeping its position under it.
- Contract docs: cost is in US dollars; a fork's filtered `session.log`
  starts at its `thread.forked`.
- The ACP fork artifact no longer records an idle cancel that proved nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`thread.forked` and `thread.configured` become `session.thread.forked` and
`session.thread.configured`, like every other event in the session's log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sanchitrk
sanchitrk merged commit 8233e4e into canary Oct 30, 2026
2 checks passed
@sanchitrk
sanchitrk deleted the feat/thread-consumers-rpc-acp-cli branch October 30, 2026 05:31
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