Skip to content

feat(automation): give scheduled code the session's Code Mode tools - #65236

Merged
rekram1-node merged 6 commits into
devfrom
automation-code-runtime
Nov 20, 2026
Merged

rekram1-node merged 6 commits into
devfrom
automation-code-runtime

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

Issue for this PR

No linked issue.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

I gave scheduled code the same Code Mode extensions as a session. fetch is available with either flag setting. With full_codemode on, scripts also get path, Bun, and Code Mode tools like tools.read and tools.shell.

tools.shell goes 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 Bun and calls shell after one approval. The focused automation, Code Mode, and tool tests had 151 passing tests. Core and schema typechecks and bun run check passed.

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. authorize only asks about the tools.* calls that scan finds. fetch (webfetch) and the Bun file APIs (read/edit/external_directory) are never asked about at creation. So when one of those permissions is ask, 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 setting webfetch: "ask" in the new fetch test.
  • Shell grant plus fetch. Taking shell out of FORBIDDEN_TOOLS was a deliberate choice, but the old reason still holds, and with fetch now available it matters more (inline).
  • Schema text. The schema description no longer mentions the 30s timeout, which still applies (inline).

Comment thread packages/core/src/automation/code.ts Resolved
Comment thread packages/core/src/automation/code.ts Resolved
Comment thread packages/schema/src/automation.ts Resolved

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/automation/code.ts Resolved
@rekram1-node
rekram1-node force-pushed the automation-code-runtime branch from 27d5ca1 to fb2a34b Compare November 20, 2026 18:55

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/automation/code.ts Resolved

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/automation/code.ts Resolved
@rekram1-node
rekram1-node force-pushed the automation-code-runtime branch from 272cffb to a82feb8 Compare November 20, 2026 19:17

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rekram1-node
rekram1-node force-pushed the automation-code-runtime branch from 96c21d5 to c6a313b Compare November 20, 2026 20:50

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rekram1-node
rekram1-node enabled auto-merge (squash) November 20, 2026 21:00
@rekram1-node
rekram1-node merged commit 1f92618 into dev Nov 20, 2026
11 checks passed
@rekram1-node
rekram1-node deleted the automation-code-runtime branch November 20, 2026 21:01
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant