feat(drive): control tool calls at runtime#32
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.
What
Add Drive-owned runtime control for selected OpenCode tools. Scripts and library drivers can statically declare
shell,webfetch, orwebsearch, accept concurrent invocations by stable call ID, stream progress, and settle each call independently.The existing callback-style
tools(registry)API remains available for fixed handlers. Undeclared tools continue to use OpenCode's real implementations.How
src/tool/controller.tshosts declared adapters, routes exact-ID and FIFO waiters, serializes progress with terminal commitment, and owns interruption/shutdown cleanup.id,input,index,progress,succeed,fail, andawaitInterruptedoperations with structuredControlErrorfailures.takeis interrupted.OpenCodeInstanceowns the controller used to configure its plugin; prepared drivers and script contexts derive controls from that instance.Scope
shell,webfetch, andwebsearch.Testing
bun run test: 153 Effect tests, 51 CLI integration tests, and 28 catalog tests passed.bun run check: package/catalog lint, typecheck, generated catalog validation, tests, and builds passed.cd packages/drive && bun run drive check test/manual/tui-regressions/multi-tool-interleavings.tscd packages/drive && bun pm pack --dry-run, followed by packed-artifact installation andToolexport validation in a clean consumer.v2atbef6cfbffe, including permission-over-form priority, form-with-running-shell state, exact sibling settlement, interruption, and session recovery.Demo
The question form exists, but read and glob permissions retain prompt priority while the runtime-controlled shell stays active:
After glob completes and read is rejected, the form appears while the controlled shell remains active:
Flow
sequenceDiagram participant Program as Drive program participant Controls as Tool controls participant Adapter as OpenCode tool adapter participant OpenCode Program->>Controls: control("shell") Program->>Controls: take("call_build") OpenCode->>Adapter: shell(input, call_build) Adapter->>Controls: offer call_build Controls-->>Program: typed controlled call Program->>Controls: progress("building") Controls-->>Adapter: progress event Adapter-->>OpenCode: streamed progress Program->>Controls: succeed(result) Controls-->>Adapter: terminal result Adapter-->>OpenCode: success event