Repository navigation
feat(core): take execute's options on a first line of its code for every model - #65714
rekram1-node wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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).
| 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 = |
There was a problem hiding this comment.
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?
|
Closing in favor of #65709, which keeps JSON fields for models without Lark instead of moving every model to the options line. |
0a43115 to
b7f76a5
Compare
There was a problem hiding this comment.
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.
Issue for this PR
One of three ways to give
executeits options withfull_codemode, alongside #65849 and #65709. They can be compared side by side; only one should merge.Type of change
What does this PR do?
With
full_codemode,executenow takes onlycodefor 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
executekeeps 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 inpackages/core/src/tool.ts:full_codemode, theexecutedescription explains the line.execute,Tool.snapshotrunsCodeModeTool.splitOptionson its input before thetool.execute.beforehook. That moves the line into the existingtimeoutandbackgroundfields and takes it out ofcode. Hooks and the job runner see the same fields they see ondev, so the plugin API doesn't change.timeoutandbackground, 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.full_codemode, nothing changes: the description doesn't mention the line, and a line like that is just a comment.Trade-offs:
timeoutorbackground. Clients and plugins that read the schema only seecode.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.tsinpackages/core: 102 pass. They cover:executetakes onlycodewith and withoutfull_codemode.Tool.snapshot,// @options: {"timeout": 5000}reaches the job runner as{ timeout: 5000 }, and an invalid line fails the call.full_codemode, the line is only a comment.bun typecheckandbun run typecheck:tscinpackages/core, andbun run checkat the root, pass.// @options:) withOPENCODE_FLAGS=full_codemodeandopenai/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