fix(acp): bridge question prompts via extMethod#33482
Open
Jayl1n wants to merge 3 commits into
Open
Conversation
Re-implements PR anomalyco#20017 for the refactored ACP layer. question.asked events are forwarded to ACP clients that advertise the opencode/question capability via connection.extMethod('opencode/question', ...), mapping the response back to sdk.question.reply/reject. Mirrors the permission handler pattern (per-session serialization) in a new acp/question.ts module wired into ACPEvent.Subscription. The tool registration still requires OPENCODE_ENABLE_QUESTION_TOOL=1 before server start (the flag is snapshotted at boot); the defunct runtime process.env write from the original PR is intentionally not carried over.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR Found:
No other duplicate or conflicting open PRs found. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #17920. Also addresses #13752.
Type of change
What does this PR do?
In ACP mode the
questiontool hangs forever:question.askedis published, aDeferredwaits for the answer, but nothing forwards it to the ACP client, so the tool blocks indefinitely (#17920).This adds an ACP bridge for
question.asked, gated behind a client capability so existing clients keep their current behavior. WhenOPENCODE_ENABLE_QUESTION_TOOL=1is set and the client advertisesclientCapabilities._meta["opencode/question"]at initialize, the question request is forwarded over the ACP extension methodopencode/question(connection.extMethod), and the response is mapped back tosdk.question.reply/sdk.question.reject. If the client declines, throws, or doesn't advertise the capability, the question is rejected so the agent isn't left waiting.The handler mirrors the existing
permission.tsHandler(per-session serialization via a promise queue), wired intoACPEvent.Subscription. The capability is parsed inACPService.initializeviasetQuestionEnabled.Note: this is a port of #20017, which was written against the old monolithic
agent.tsbefore the ACP layer was split intoservice.ts/event.ts/permission.ts. The original PR also wroteprocess.env.OPENCODE_ENABLE_QUESTION_TOOLinsideinitialize()to register the tool at runtime — that no longer works because the flag is now an EffectRuntimeFlagsvalue snapshotted once at boot when the tool registry is built, so registering thequestiontool still requires the env var before server start (documented in the newacp/README.md).Files:
src/acp/question.ts(new) —Handler, mirrorspermission.tssrc/acp/event.ts—ConnectiongainsextMethod;Subscriptionowns the handler +setQuestionEnabledsrc/acp/service.ts—initializeparses the capabilitysrc/acp/README.md(new) — capability contracttest/acp/question.test.ts(new) — reply / reject / no-capability / extMethod-throwsHow did you verify your code works?
bun typecheck(run frompackages/opencode)bun test test/acp/question.test.ts test/acp/permission.test.ts test/acp/event.test.ts— 26 pass / 0 failA reviewer can reproduce the fix by enabling the tool against an ACP client that advertises the capability:
Screenshots / recordings
N/A (no UI changes)
Checklist