Skip to content

refactor(acp): run ACP prompt turns on the shared turn engine - #2102

Merged
will-lamerton merged 2 commits into
mainfrom
refactor/acp-turn-engine
Nov 11, 2026
Merged

will-lamerton merged 2 commits into
mainfrom
refactor/acp-turn-engine

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

Step 2 of moving the agent loops onto the shared turn engine (#2097). ACP's runTurn now runs on runTurnEngine instead of its own hand-written loop. Nothing about how it behaves is meant to change.

What moved where

runTurn keeps its per-prompt setup: the turn id, the walkthrough lifecycle, wrotePlan, usage accumulation, withTurnUsage and stopWithNotice. Its loop is now a TurnEngineAdapter<'cancelled'>:

ACP loop piece now in
the history in session.messages, written at every step history
the system message from session.systemMessage; none means end_turn getSystemMessage + mapping
the live mode, the per-session disabled tools, the offered tools prepareTurn (the disabled-tools list taken at the start of the turn is kept for the per-call checks, as before)
agent_message_chunk / agent_thought_chunk streaming, with leading whitespace trimmed from reasoning beginModelCall
recordUsage onModelResponse
partitionUnknownToolCalls without an offered-name filter partitionToolCalls
aggressiveCompact compactOptions
the plan-mode write_plan fallback, then the walkthrough nudge onFinalAnswer
batch announce, mode/disabled refusal, ask_user, approval, plugin vote, permission, timeline capture, execution, write_tasks plan update executeTools. The code is moved unchanged. A cancelled permission returns {stop, results}, so the cancellation results are still recorded

The engine's result maps onto the same stopReasons as before:

  • completed, no reply and no system message give end_turn
  • an abort or a cancelled permission gives cancelled
  • a non-abort model error is rethrown
  • the turn ceiling gives max_turn_requests
  • guard stops keep stopWithNotice: a repeated call gives max_turn_requests, and malformed or empty turns give end_turn. A repeated stop on valid calls still records an Error: not run. result for each call.

Engine change: compactOptions is now a function that is read every turn. ACP needs this to pick up session.aggressiveCompact at compaction time, as the old loop did. Plain is updated to match.

The ACP copy of FINAL_TURN_INSTRUCTION and its own guards, parsing, capping and compaction calls are gone. Ignoring whitespace, acp-conversation.ts is +100/−240. The rest of the raw diff is the tool-execution block re-indented into the adapter.

Behaviour

No change intended. The contract spec from #2097 ran these same scenarios against the old ACP loop, and it still passes against the new one.

Tests

  • No existing spec was changed. All source/acp specs pass unmodified, including the timeline, queued-tool, permission and plan-fallback tests.
  • source/agent-loop/turn-engine.contract.spec.ts (plain + ACP) passes.
  • Ran tsc --noEmit, biome check, knip (both passes), and AVA over source/acp, source/agent-loop, source/plain, source/subagents and source/hooks (468 + 624 passed), plus no-ink-fast-paths.

No changeset: this is a refactor with no user-visible change.

Conflict note: #2095 (tune tool mode) adds nativeToolsDisabled: session.nativeToolsDisabled to ACP's modeOverrides. If that merges first, the line moves into prepareTurn's modeOverrides here. Whichever lands second needs a one-line rebase.

Next in the sequence

  1. The subagent executor moves onto the engine. The guards are turned off through engine options so its current behaviour is kept; turning them on comes later as its own PR with a changeset.
  2. A small fix PR with a changeset: "no reply from the model" becomes an error in every frontend.
  3. The TUI loop, in two PRs.

🤖 Generated with Claude Code

runTurn's hand-written loop becomes a TurnEngineAdapter: the session's
messages are the engine's history, streaming goes to agent_message_chunk /
agent_thought_chunk, the per-call announce / permission / timeline /
execute sequence moves into executeTools unchanged, and the plan and
walkthrough fallbacks move into onFinalAnswer. The engine result maps onto
the same stopReasons as before, including the notice and "not run" results
on a guard stop.

compactOptions becomes a per-turn function so ACP reads the session's
aggressive-compact preset at compaction time, as it did before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

No changeset found

This PR does not add a changeset, so it will not appear in the changelog or trigger a release.

If the change is user-facing, add one:

pnpm changeset

Pick a bump (patch / minor / major) and write the changelog entry in our usual voice ("Added X... Thanks to @you. Closes #123."), then commit the generated .changeset/*.md file.

If this PR is docs-only or a chore that needs no release note, you can ignore this — or run pnpm changeset --empty to record that intentionally.

@github-actions

Copy link
Copy Markdown
Contributor

nc-review could not produce a verdict this run (agent exit 1). This is a problem with the review agent, not with your pull request. A maintainer can retry with /re-review.

@will-lamerton
will-lamerton merged commit ec28aba into main Nov 11, 2026
18 checks passed
@will-lamerton
will-lamerton deleted the refactor/acp-turn-engine branch November 11, 2026 16:49
jay23606 added a commit to jay23606/nanocoder that referenced this pull request Nov 12, 2026
…ollective#2102)

runTurn's hand-written loop becomes a TurnEngineAdapter: the session's
messages are the engine's history, streaming goes to agent_message_chunk /
agent_thought_chunk, the per-call announce / permission / timeline /
execute sequence moves into executeTools unchanged, and the plan and
walkthrough fallbacks move into onFinalAnswer. The engine result maps onto
the same stopReasons as before, including the notice and "not run" results
on a guard stop.

compactOptions becomes a per-turn function so ACP reads the session's
aggressive-compact preset at compaction time, as it did before.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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