Repository navigation
feat(codemode): raw text input blocks for execute - #67579
Conversation
There was a problem hiding this comment.
Blocks parse as described, and the tests and type check pass. One small issue is worth fixing before merge (inline): without full_codemode, a script with a block now starts as a background job and fails there.
How I checked: the codemode, automation and tool-shell tests pass, apart from one sh permissions test that fails the same way on the base. typecheck:tsc in packages/core passes. I also ran the block parser directly on CRLF text, the README example, an unclosed opener and line numbers, and all behaved as described.
Public API: no SDK, HTTP, plugin, config or CLI changes. Only the model-facing execute description changes and an inputs global is added to scripts that contain blocks. Scripts without blocks behave as before.
Edge case, not blocking: text inside a template literal that happens to look like a block (an opener line followed by a tag line) is still pulled out as a block, which silently changes the string.
| const background = yield* CodeModeJob.Current | ||
| // Parse before starting a job, so bad code fails on this call instead of in the background. | ||
| const validInput = full ? Schema.is(CodeModeTool.FullInput) : Schema.is(CodeMode.Input) | ||
| const blocks = validInput(event.input) ? CodeModeInputBlocks.parse(event.input.code) : undefined |
There was a problem hiding this comment.
This always removes blocks, but execute only does that with full_codemode, and CodeModeJob.Current is provided without the flag too. Without the flag, a script with a block passes this check, starts as a job, and then fails to parse in the background instead of on the call. Before this change it failed on the call, which is what this check is for. Removing blocks only when full is set (otherwise parse event.input.code as before) would keep the check and the run in step.
There was a problem hiding this comment.
My earlier point about the background check is fixed: execute now always removes input blocks, as automations and the background-start check do. With or without full_codemode, a script with a block is now checked and run as the same code. Only the description that tells models about blocks still depends on full_codemode. The new commits raise nothing else.
I checked by re-running the codemode, automation and tool-shell tests and typecheck:tsc in packages/core. The one failing sh permissions test fails the same way on the base. The public API is unchanged: only the model-facing execute description changes, and scripts with blocks get an inputs global.
There was a problem hiding this comment.
The only new commit rewords the input-block sentence in the execute description that models see. No code behaviour changes, and I see no new concerns. The background-check point was already fixed in the previous push: execute now always removes blocks, the same as the check in tool.ts. The codemode tests still pass, and the public API is unchanged.
Issue for this PR
Related: pain points about escaping long text in Code Mode scripts (backticks,
${, backslashes and quotes inside JS strings).Type of change
What does this PR do?
A Code Mode script can carry multi-line text as an input block instead of a JS string, so nothing needs escaping:
// @input: <name> <<'TAG', then the text, then a line equal toTAG. Blocks are removed before the JS is parsed and the text shows up asinputs.<name>. Their lines become empty lines, so error line numbers still match.tools.shell({ command: inputs.cmd }).inputsonly exists when a script has a block, so scripts without blocks behave exactly as before.executeand in automations. Only the description that tells models about them is limited tofull_codemode, so creating and running an automation always see the same code.Eval (1,848 runs, 7 models incl. Opus, GPT-6.2 Sol, Gemini 4 Neon, Kimi, DeepSeek and GLM): with this wording, runs on long text full of backticks,
${and heredocs took 7.8 s less and 2.4k fewer tokens than today (about 12% cheaper), with success flat. Models never use blocks unless the description mentions them.How did you verify your code works?
test/codemode.test.ts,test/automation.test.tsandtest/tool-shell.test.ts: parsing, line numbers, CRLF,__proto__names, the tag hint, blocks further down, automations with the flag on and off, and a heredoc command in a block in both a script and an automation.bun run typecheckinpackages/core;bun run check;tsc -p tsconfig.build.json --noEmitin server, sdk and simulation.Screenshots / recordings
N/A
Checklist