Skip to content

feat(core): take execute's options on a first line of its code for every model - #65714

Open
rekram1-node wants to merge 2 commits into
devfrom
exec-header-line
Open

rekram1-node wants to merge 2 commits into
devfrom
exec-header-line

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

One of three ways to give execute its options with full_codemode, alongside #65849 and #65709. They can be compared side by side; only one should merge.

Type of change

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

What does this PR do?

With full_codemode, execute now takes only code for every model. Options go on an optional first line of that code:

 without full_codemode:  execute({ code })
-with full_codemode:     execute({ code, timeout?, background? })
+with full_codemode:     execute({ code })   // first line may be: // @options: {"background": true}

Since execute keeps a single string field, GPT gets it as a raw-text custom tool and doesn't have to JSON-escape its code. Other models get plain JSON { code }. No grammar is needed.

How it works. All of it lives in packages/core/src/codemode/tool.ts, plus one call in packages/core/src/tool.ts:

  • With full_codemode, the execute description explains the line.
  • When the model calls execute, Tool.snapshot runs CodeModeTool.splitOptions on its input before the tool.execute.before hook. That moves the line into the existing timeout and background fields and takes it out of code. Hooks and the job runner see the same fields they see on dev, so the plugin API doesn't change.
  • The prefix is one constant, and the regex is built from it. If the line isn't a JSON object with only timeout and background, including when it has any other key, the call fails with a message showing how to write it, so the model knows its options weren't applied.
  • Without full_codemode, nothing changes: the description doesn't mention the line, and a line like that is just a comment.
  • The session stores the call exactly as the model wrote it, line included, so the model sees its own format when the history is replayed. The line is a valid JavaScript comment, so the stored code still reads as code.

Trade-offs:

  • Every model sets options through the line, Claude included, instead of using typed JSON fields.
  • Nothing forces the line's format; a bad line fails the call instead. A grammar could still be added later for models that support one, since the tool keeps one field.
  • The tool's input schema no longer shows timeout or background. Clients and plugins that read the schema only see code.

How did you verify your code works?

  • bun run script/test.ts test/codemode-execute-options.test.ts test/tool-registry.test.ts test/tool-execute.test.ts in packages/core: 102 pass. They cover:
    • execute takes only code with and without full_codemode.
    • The line is parsed with CRLF and leading spaces. Invalid JSON, invalid values and unknown keys fail.
    • Through Tool.snapshot, // @options: {"timeout": 5000} reaches the job runner as { timeout: 5000 }, and an invalid line fails the call.
    • Without full_codemode, the line is only a comment.
  • bun typecheck and bun run typecheck:tsc in packages/core, and bun run check at the root, pass.
  • Live run (before the prefix was renamed to // @options:) with OPENCODE_FLAGS=full_codemode and openai/gpt-6.2-sol: the model wrote the options line with {"background": true} on its own and got a background job ID back.

Screenshots / recordings

N/A

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.

The approach works as described: with full_codemode, execute takes only code for every model, and the options line is turned into timeout/background before hooks run, so the job runner and execute.before hooks still see them as fields. I checked this with the changed and nearby core tests (175 pass) and tsc -b in packages/core. I didn't run OpenCode from source.

Public API: the only change is the execute tool's input schema under the experimental full_codemode flag: { code, timeout?, background? } → { code }, with the options now on an // @exec: first line. The exported CodeModeTool.FullInput is removed (nothing else uses it). Plugin hooks still receive timeout/background as fields, and the server, SDK and config are unchanged.

One thing to fix before merge: the TUI Scripts tab labels a background script by the first line of its stored code, which now begins with the options line (see inline comment).

Comment thread packages/core/src/tool.ts Outdated
const event = yield* beforeExecute(input.call.name, initial, input.call.input, context)
// With full_codemode, execute takes its options on the first line of its code. Hooks and the job see them as
// fields.
const split =

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 session stores the model's original call input (Tool.Called in publish-llm-event.ts → message-updater.ts), so the stored code still starts with // @exec: …. scriptLabel in packages/tui/src/util/session.ts names a background script by the first non-empty line of that code. Background scripts are the main reason to write this line, so in the Scripts tab they'd all show // @exec: {"background": true} instead of their real first line. Could scriptLabel skip a leading // @exec: line (via OPTIONS_PREFIX), or could the stored input be updated to the split form?

@rekram1-node

Copy link
Copy Markdown
Member Author

Closing in favor of #65709, which keeps JSON fields for models without Lark instead of moving every model to the options line.

@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 open thread about the Scripts tab label isn't addressed: scriptLabel still names a background script by its first line, which is now // @options: …. The new commits look sound and I found nothing new to fix: the prefix is now one constant with the regex built from it, unknown keys fail the call instead of being dropped, and the split runs before the hook whenever the call is named execute under full_codemode. The three changed test files pass (102 tests) and tsc -b passes in packages/core. I didn't run OpenCode end to end.

Public API: under the experimental full_codemode flag, execute's input schema changes from { code, timeout?, background? } to { code }, with the options now on a // @options: first line. tool.execute.before hooks still get timeout and background as fields. Nothing else changes.

This branch has not been deployed

No deployments
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