Repository navigation
refactor(acp): simplify the turn fold - #52826
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why the change
The ACP turn fold mixed delivery policy into pure event folding and repeated root and child branches, so this PR separates those concerns without changing what the client sees.
Special things to note
turn.ts, so the wire test for child permissions after the turn checks them directly. After the prompt responds, the client gets nosession/update, even for a background child's text. Once the last open child ends, a later ask from that child never reaches the client. The translate test drops the background case that copied the filter.bash,task,apply_patch) in one place,canonicalNameintool.ts. Tool names are canonicalized where they are matched, not when a tool arrives, because the raw name is still the title fallback (apply_patchandtasktitles would change otherwise).context7_*names come from an MCP server namedcontext7.context, shellcmd/cwd, and theexternal_directorytitle fields can still come from custom tools or untracked permission asks, so none of them are provably dead.Change outline
The fold no longer knows about background delivery. It always emits its outputs. It finds the event's owner once, then hands the event to a root handler or a child handler. Both share one handler for streamed content.
turn.tsnow owns delivery policy. Each consumer gets oneTurnrecord, and the background follow gets its own copy of the state instead of sharing the finished turn'sRef.Permission and form asks no longer carry their own race. Each module exports its
askandrespond, andqueueAskruns the race once, next to thesettleddeferred, the turn'scancelledsignal and the ask queue. A cancelled or failed ask still falls back torejectfor permissions and a plain cancel for forms.Prompt preparation moves into its own module.
packages/cli/src/acp/ +├── prompt.ts # ACPPrompt.prepare: image check, unreadable file links, slash and compaction detection ├── permission.ts # exports ask and respond ├── elicitation.ts # exports ask and respond ├── tool.ts # canonicalName replaces six lowercase alias switches ├── translate.ts # fold, root and child handlers └── turn.ts # Turn record, ask race, delivery policy, background follow