Repository navigation
feat(automation): give scheduled code the session's Code Mode tools - #65236
Conversation
There was a problem hiding this comment.
Scheduled fetch, Bun/path and tools.shell work as described. I ran the new tests, the automation and Code Mode suites (125 passing) and core's tsc (passes), and probed the webfetch permission: details in the verification notes.
Public API: only the model-facing description of CodeActionInput.code changes (schema and openapi.json). Backwards compatible.
Concerns:
- Creation approval misses the new globals.
authorizeonly asks about thetools.*calls thatscanfinds.fetch(webfetch) and theBunfile APIs (read/edit/external_directory) are never asked about at creation. So when one of those permissions isask, the automation is created without any prompt, and its first run pauses with "Permission webfetch needs approval, and nobody is present to give it". I reproduced this by settingwebfetch: "ask"in the new fetch test. - Shell grant plus fetch. Taking
shellout ofFORBIDDEN_TOOLSwas a deliberate choice, but the old reason still holds, and withfetchnow available it matters more (inline). - Schema text. The schema description no longer mentions the 30s timeout, which still applies (inline).
There was a problem hiding this comment.
Creation now asks for webfetch when the code uses fetch, and for the Bun permissions when it uses Bun, so runs no longer pause on a permission nobody approved. I checked this with the updated fetch test (webfetch: "ask", one approval at creation, then the run fetches) and a probe of a Bun-only program. The core automation and Code Mode suites and all of packages/codemode pass (61 and 322 tests).
The shell grant and the missing 30s timeout in the schema description are still open in their threads.
One new concern: any use of Bun now asks for blanket edit and external_directory access, even for a program that only reads a file (inline).
Public API: this commit adds the scanProgram export to @opencode/codemode and changes nothing else; backwards compatible.
27d5ca1 to
fb2a34b
Compare
There was a problem hiding this comment.
The new commit narrows what Bun asks for at creation: a read through Bun.file asks for read and external_directory, and edit only when the file is used for more than reading or through Bun.write. But it stopped asking for glob. A script using new Bun.Glob(...).scan() is now created without a glob prompt, and its first run pauses with "Permission glob needs approval". I confirmed this with a probe in the core tests (inline).
The unattended shell grant (thread 2) is still open.
Tests: core automation-shell, automation, codemode and tool-automation suites (63) and packages/codemode (322) pass; core typecheck:tsc passes. Public API unchanged by this commit.
There was a problem hiding this comment.
Thread 5 isn't fixed: Bun.Glob now asks for read and external_directory, but the scan itself checks glob, which creation still never requests. The new test shows it: with glob: "ask", the script is approved at creation and its first run pauses with "Permission glob needs approval". The test expects that pause, so it passes even though the script can't work (inline). The fallback for a bare Bun reference or an import from "bun" also still leaves out glob. Thread 2 is unchanged.
Tests: automation-shell.test.ts and automation.test.ts pass (52). Public API unchanged.
272cffb to
a82feb8
Compare
There was a problem hiding this comment.
The Bun.Glob gap is closed. After the rebase onto #65255, glob scans ask for read (and external_directory outside the project), which matches what creation now requests. The updated test checks that an approved scan fires and returns ["fixture.txt"]. automation-shell.test.ts, automation.test.ts and tool-execute.test.ts pass (89). Public API unchanged by this commit. Nothing new to flag.
96c21d5 to
c6a313b
Compare
There was a problem hiding this comment.
The refactor keeps the same behaviour as far as I can tell. I ran the new scan on eight sample Bun scripts: direct and variable Bun.file reads, slice forwarding, a write through a closure that runs before the declaration, a file object passed to another function, and a Bun alias. Each asks for the same access as before. The direct codeModeTools lookup matches the registry ids from effectiveName. Core automation, tool and Code Mode tests (100) and packages/codemode (322) pass; core typecheck:tsc passes. Public API: scanProgram in @opencode/codemode gains an optional forwardingMembers argument (backwards compatible). Nothing new to flag.
Issue for this PR
No linked issue.
Type of change
What does this PR do?
I gave scheduled code the same Code Mode extensions as a session.
fetchis available with either flag setting. Withfull_codemodeon, scripts also getpath,Bun, and Code Mode tools liketools.readandtools.shell.tools.shellgoes through the existing one-time approval at creation. That approval covers the tool, and each run still checks the current deny rules. I removed the tool-call cap and kept the 30-second timeout and 32 KB output cap.How did you verify your code works?
I tested a scheduled fetch against a loopback HTTP server and ran a scheduled script that reads a fixture with
Bunand calls shell after one approval. The focused automation, Code Mode, and tool tests had 151 passing tests. Core and schema typechecks andbun run checkpassed.Screenshots / recordings
No UI change.
Checklist