code_mode: Move exec params from runtime declarations to @pragma (#14511)

This change moves code_mode exec session settings out of the runtime API
and into an optional first-line pragma, so instead of calling runtime
helpers like set_yield_time() or set_max_output_tokens_per_exec_call(),
the model can write // @exec: {"yield_time_ms": ...,
"max_output_tokens": ...} at the top of the freeform exec source. Rust
now parses that pragma before building the source, validates it, and
passes the values directly in the exec start message to the code-mode
broker, which applies them at session start without any worker-runtime
mutation path. The @openai/code_mode module no longer exposes those
setter functions, the docs and grammar were updated to describe the
pragma form, and the existing code_mode tests were converted to use
pragma-based configuration instead.
This commit is contained in:
Channing Conger
2026-03-12 20:27:42 -07:00
committed by GitHub
parent 1a363d5fcf
commit 0daffe667a
9 changed files with 235 additions and 99 deletions

View File

@@ -2018,8 +2018,13 @@ fn create_js_repl_reset_tool() -> ToolSpec {
fn create_code_mode_tool(enabled_tool_names: &[String]) -> ToolSpec {
const CODE_MODE_FREEFORM_GRAMMAR: &str = r#"
start: source
source: /[\s\S]+/
start: pragma_source | plain_source
pragma_source: PRAGMA_LINE NEWLINE SOURCE
plain_source: SOURCE
PRAGMA_LINE: /[ \t]*\/\/ @exec:[^\r\n]*/
NEWLINE: /\r?\n/
SOURCE: /[\s\S]+/
"#;
ToolSpec::Freeform(FreeformTool {