Repository navigation
refactor(acp): run the catalog as an effect service - #52471
Merged
Merged
Conversation
3 of 6 tasks
Ichinose-Kazuki
pushed a commit
to Ichinose-Kazuki/opencode
that referenced
this pull request
Oct 7, 2026
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.
#35457 | #37229 | #52284
Fixes #37229
Refs #52284
Why the change
The ACP catalog was a promise cache with hand-written reload maps and a
Date.now()+Bun.sleeppolling loop. This turns it into a connection-scoped Effect service that sessions can subscribe to in PR 4, and it now advertises the built-in/compactcommand.Special things to note
ACPCatalog.promise(...)is a temporary adapter so the promise-basedservice.tskeeps working. PR 4 deletes it. It rejects with the typedACPCatalog.Error, and the onepromise()adapter inagent.tsclassifies it. A not-ready catalog still returns-32603"Internal service failure" and is still logged, butdata.errorNameis now"ACPCatalogNotReadyError"instead of"Error".agent.list, which core orders with its resolved default first (the sameselectedDefault()new sessions use), so ACP shows the agent a new session actually runs./compactcomes from one built-in table inservice.ts. Advertising and routing both use that table, and a built-in wins over a server command with the same name. Built-ins stay out ofcatalog.commands. OtherwisepreparePromptwould treat/compactas a server command and setaction: true, and the prompt would return before the compaction finished.Change outline
The service is per connection. Each entry is keyed by the resolved cwd and has one
SubscriptionRef, which is the only source of truth:Every reload, whether from a caller or a server event, goes through one
reload(entry)step. The reload counters let one load serve everyone who asked before it started:The readiness poll now uses a
Schedule, so it can be tested withTestClock:The adapter and the request boundary:
packages/cli/ ├── src/acp/catalog.ts # ACPCatalog.Service + make, reload step, temporary promise() adapter ├── src/acp/agent.ts # connect requires Scope and builds the catalog; promise() unwraps LoadError ├── src/acp/service.ts # catalog via ACPCatalog.promise; builtinCommands table for advertising + routing └── test/acp/ + ├── catalog-service.test.ts # batched reload, failed reload keeps previous, 25ms spacing, gives up at ~5s ├── catalog.test.ts # #37229 todo → test (built-in compact wins); default mode follows agent.list order ├── session.test.ts # command list includes compact └── wire-fixture.ts # agent runs in a Scope that dispose closes