Skip to content

feat(codemode): raw text input blocks for execute - #67579

Merged
rekram1-node merged 3 commits into
devfrom
codemode-input-blocks
Dec 1, 2026
Merged

rekram1-node merged 3 commits into
devfrom
codemode-input-blocks

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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

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

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: readme <<'END'
Run `npm run ${task}` from C:\work\app
END
await tools.write({ path: "README.md", content: inputs.readme })
  • A block is // @input: <name> <<'TAG', then the text, then a line equal to TAG. Blocks are removed before the JS is parsed and the text shows up as inputs.<name>. Their lines become empty lines, so error line numbers still match.
  • The description asks for blocks before the program, but blocks further down work too. An opener further down with no closing line is left alone as a comment.
  • A multi-line shell command goes in a block as the whole command: tools.shell({ command: inputs.cmd }).
  • inputs only exists when a script has a block, so scripts without blocks behave exactly as before.
  • If the script fails to parse and a later line equals a block's tag, the syntax error gets a short hint to pick a tag the text doesn't contain.
  • Blocks are always parsed, in execute and in automations. Only the description that tells models about them is limited to full_codemode, so creating and running an automation always see the same code.
  • The background check from fix(codemode): fail background execute on syntax errors before starting a job #67552 now parses the script after blocks are removed, so a background script with a block still starts as a job.

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?

  • Tests in test/codemode.test.ts, test/automation.test.ts and test/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 typecheck in packages/core; bun run check; tsc -p tsconfig.build.json --noEmit in server, sdk and simulation.

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.

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.

Comment thread packages/core/src/tool.ts
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

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.

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.

@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.

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.

@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 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.

@rekram1-node
rekram1-node merged commit 82fba13 into dev Dec 1, 2026
12 checks passed
@rekram1-node
rekram1-node deleted the codemode-input-blocks branch December 1, 2026 22:17
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