GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(automation): give scheduled code the session's Code Mode tools by rekram1-node · Pull Request #65236 · anomalyco/opencode

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Uh oh!

There was an error while loading. Please reload this page.

Merged

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

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
935e6f3
feat(automation): give scheduled code the session's Code Mode tools
rekram1-node Nov 20, 2026
7b6c516
fix(automation): ask at creation for what fetch and Bun need
rekram1-node Nov 20, 2026
0143218
fix(automation): ask only for the Bun access a script uses
rekram1-node Nov 20, 2026
29c48b1
fix(automation): ask read access for Bun.Glob
rekram1-node Nov 20, 2026
2b4854c
test(automation): expect approved Bun.Glob scans to run
rekram1-node Nov 20, 2026
c6a313b
refactor(automation): simplify scheduled code capabilities and tests
rekram1-node Nov 20, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 2 additions & 2 deletions 4 packages/codemode/src/codemode/codemode.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Effect, Schema } from "effect"
import { type Extension, isAsync, isConstructible } from "./extension.js"
import { scanTools } from "./scan.js"
import { scanProgram, scanTools } from "./scan.js"
import { hooked, type Services, type ToolDescription, ToolRuntime } from "./tool-runtime.js"
import type { Tools } from "./tools.js"
import {
Expand All @@ -17,7 +17,7 @@ import {

export const SuspendError: typeof Language.SuspendError = Language.SuspendError
export type SuspendError = Language.SuspendError
export { fromBytes, scanTools, SnapshotError, toBytes }
export { fromBytes, scanProgram, scanTools, SnapshotError, toBytes }
export type { Snapshot, SnapshotHeader }

/** A tool call admitted during an execution. */
Expand Down
174 changes: 145 additions & 29 deletions 174 packages/codemode/src/codemode/scan.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,49 @@ import { formatLocation, moduleName, parseProgram } from "psychoscript/effect"
* dynamic bracket access (`tools[name]`), or aliasing/passing `tools` rather than calling `tools.<path>(...)` directly.
*/
export function scanTools(code: string): Result.Result<ReadonlyArray<string>, Diagnostic> {
return scanProgram(code, []).pipe(Result.map((scanned) => scanned.tools))
}

interface ProgramScan {
readonly tools: ReadonlyArray<string>
readonly globals: ReadonlyMap<string, ReadonlyArray<GlobalUse>>
readonly modules: ReadonlySet<string>
}

interface GlobalUse {
readonly member?: string
// First non-forwarding member used on a call's result. Undefined means the value escaped or was used dynamically.
readonly resultMembers: Iterable<string | undefined>
}

/** Scans static tool calls, references to the given globals, and literal module loads. */
export function scanProgram(
code: string,
globals: ReadonlyArray<string>,
forwardingMembers: ReadonlyArray<string> = [],
): Result.Result<ProgramScan, Diagnostic> {
if (code.trim().length === 0) {
return Result.fail({ kind: "ParseError", message: "Code cannot be empty." })
}
const parsed = parseProgram(code)
// A parse failure's kind is always ParseError.
if (!parsed.ok) return Result.fail(parsed.error as Diagnostic)

const found = new Set<string>()
const tools = new Set<string>()
const referenced = new Map<string, GlobalUse[]>()
const localUses = new Map<Set<string>, Map<string, Set<string | undefined>>>()
const modules = new Set<string>()
const scopes: Array<Set<string>> = [collectScope(parsed.program, true)]
const ancestors: Array<AnyNode> = []

const isShadowed = () => scopes.some((scope) => scope.has("tools"))
// A binding may be referenced in a closure before its initializer appears in the walk.
const bindingUses = (scope: Set<string>, name: string) => {
const locals = localUses.get(scope) ?? new Map<string, Set<string | undefined>>()
localUses.set(scope, locals)
const uses = locals.get(name) ?? new Set<string | undefined>()
locals.set(name, uses)
return uses
}

const fail = (node: AnyNode, message: string): Diagnostic => {
const loc = node.loc?.start ? { line: node.loc.start.line, column: node.loc.start.column + 1 } : undefined
Expand All @@ -33,19 +64,61 @@ export function scanTools(code: string): Result.Result<ReadonlyArray<string>, Di
const visit = (node: AnyNode | null | undefined): Diagnostic | undefined => {
if (!node) return undefined

if (node.type === "Identifier" && node.name === "tools" && !isShadowed()) {
const parent = ancestors.at(-1)
if (!isReferencePosition(node, parent)) return undefined
const chain = readStaticToolCall(node, ancestors)
if (!chain.ok) return fail(chain.node, chain.reason)
found.add(chain.path)
return undefined
if (
node.type === "Identifier" &&
(globals.length > 0 || node.name === "tools") &&
isReferencePosition(node, ancestors.at(-1))
) {
const scope = scopes.findLast((scope) => scope.has(node.name))
if (scope && globals.length > 0)
bindingUses(scope, node.name).add(resultMember(node, ancestors, ancestors.length - 1, forwardingMembers))

if (!scope && node.name === "tools") {
const chain = readStaticToolCall(node, ancestors)
if (!chain.ok) return fail(chain.node, chain.reason)
tools.add(chain.path)
return undefined
}

if (!scope && globals.includes(node.name)) {
const uses = referenced.get(node.name) ?? []
referenced.set(node.name, uses)
const property = ancestors.at(-1)
const member =
property?.type === "MemberExpression" && property.object === node ? memberName(property) : undefined
const call = ancestors.at(-2)
if (member === undefined || call?.type !== "CallExpression" || call.callee !== property) {
uses.push({ member, resultMembers: [undefined] })
return undefined
}
const result = valueUse(call, ancestors, ancestors.length - 3)
if (result.parent?.type === "ExpressionStatement") {
uses.push({ member, resultMembers: [] })
return undefined
}
if (
result.parent?.type === "VariableDeclarator" &&
result.parent.init === result.value &&
result.parent.id.type === "Identifier"
) {
const name = result.parent.id.name
const binding = scopes.findLast((scope) => scope.has(name))
if (binding) {
uses.push({ member, resultMembers: bindingUses(binding, name) })
return undefined
}
}
uses.push({ member, resultMembers: [resultMember(result.value, ancestors, result.index, forwardingMembers)] })
}
}

// `import`/`require` of "tools" would reach tools the scan never sees.
const loaded = loadedModule(node)
if (loaded !== undefined && (loaded === null || moduleName(loaded) === "tools")) {
return fail(node, "Automation code must call tools directly as tools.<name>(...), not import or require them.")
if (loaded !== undefined) {
const name = loaded === null ? undefined : moduleName(loaded)
if (name === undefined || name === "tools")
return fail(node, "Automation code must call tools directly as tools.<name>(...), not import or require them.")
modules.add(name)
}

const pushedScope = enterNodeScope(node)
Expand All @@ -61,7 +134,44 @@ export function scanTools(code: string): Result.Result<ReadonlyArray<string>, Di

const diagnostic = visit(parsed.program)
if (diagnostic) return Result.fail(diagnostic)
return Result.succeed(Array.from(found))
return Result.succeed({ tools: [...tools], globals: referenced, modules })
}

function memberName(node: Extract<AnyNode, { type: "MemberExpression" }>) {
if (!node.computed && node.property.type === "Identifier") return node.property.name
if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string")
return node.property.value
}

/** Skip wrappers that leave the wrapped value available for another access. */
function valueUse(value: AnyNode, ancestors: ReadonlyArray<AnyNode>, index: number) {
for (; index >= 0; index--) {
const parent = ancestors[index]
if (
(parent.type === "AwaitExpression" && parent.argument === value) ||
(parent.type === "ChainExpression" && parent.expression === value)
) {
value = parent
continue
}
return { value, parent, index }
}
return { value, parent: undefined, index }
}

function resultMember(
value: AnyNode,
ancestors: ReadonlyArray<AnyNode>,
index: number,
forwardingMembers: ReadonlyArray<string>,
): string | undefined {
const use = valueUse(value, ancestors, index)
if (use.parent?.type !== "MemberExpression" || use.parent.object !== use.value) return
const name = memberName(use.parent)
if (name === undefined || !forwardingMembers.includes(name)) return name
const call = ancestors[use.index - 1]
if (call?.type === "CallExpression" && call.callee === use.parent)
return resultMember(call, ancestors, use.index - 2, forwardingMembers)
}

/** The module an `import` or `require(...)` loads, `null` when it is computed, or `undefined` for other nodes. */
Expand All @@ -78,6 +188,12 @@ function loadedModule(node: AnyNode): string | null | undefined {

function isReferencePosition(node: AnyNode, parent: AnyNode | undefined): boolean {
if (!parent) return true
if (
parent.type === "ImportSpecifier" ||
parent.type === "ImportDefaultSpecifier" ||
parent.type === "ImportNamespaceSpecifier"
)
return false
if (parent.type === "MemberExpression" && parent.property === node && !parent.computed) return false
if (parent.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand) return false
if (parent.type === "MethodDefinition" && parent.key === node && !parent.computed) return false
Expand All @@ -100,7 +216,9 @@ function isReferencePosition(node: AnyNode, parent: AnyNode | undefined): boolea
function readStaticToolCall(
root: AnyNode,
ancestors: ReadonlyArray<AnyNode>,
): { readonly ok: true; readonly path: string } | { readonly ok: false; readonly node: AnyNode; readonly reason: string } {
):
| { readonly ok: true; readonly path: string }
| { readonly ok: false; readonly node: AnyNode; readonly reason: string } {
const segments: Array<string> = []
let current = root
let index = ancestors.length - 1
Expand All @@ -113,23 +231,18 @@ function readStaticToolCall(
continue
}
if (parent.type !== "MemberExpression" || parent.object !== current) break
if (!parent.computed && parent.property.type === "Identifier") {
segments.push(parent.property.name)
current = parent
index -= 1
continue
}
if (parent.computed && parent.property.type === "Literal" && typeof parent.property.value === "string") {
segments.push(parent.property.value)
current = parent
index -= 1
continue
}
return {
ok: false,
node: parent.property,
reason: "Automation code must reference tools statically (e.g. tools.slack.read_thread), not with dynamic bracket expressions.",
const member = memberName(parent)
if (member === undefined) {
return {
ok: false,
node: parent.property,
reason:
"Automation code must reference tools statically (e.g. tools.slack.read_thread), not with dynamic bracket expressions.",
}
}
segments.push(member)
current = parent
index -= 1
}

const callParent = index >= 0 ? ancestors[index] : undefined
Expand Down Expand Up @@ -183,6 +296,9 @@ function enterNodeScope(node: AnyNode): Set<string> | undefined {
function collectScope(container: Program | BlockStatement, includeVar: boolean): Set<string> {
const names = new Set<string>()
for (const statement of container.body) {
if (statement.type === "ImportDeclaration") {
for (const specifier of statement.specifiers) names.add(specifier.local.name)
}
if (statement.type === "FunctionDeclaration" && statement.id) names.add(statement.id.name)
if (statement.type === "ClassDeclaration" && statement.id) names.add(statement.id.name)
if (statement.type === "VariableDeclaration" && (includeVar || statement.kind !== "var")) {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.