Adds pi-style codemode (opt-in: codemode = true in config).
The model sends raw JS (body of an async function) and it runs in a QuickJS sandbox (rquickjs 0.14) with no fs, network or timers. Only the script output goes back to the model.
tools.<name>(args) calls any registered tool, MCP included (- becomes _). It resolves to the text output and throws ToolError when the tool errors. Calls go through Registry::call, so the permission gate and the read-before-edit State work exactly as for direct calls.
Globals: text(), return, console.* (shown in <console_output>), describeTool(name). Several text items get ==> text N/M <== headers.
Description lists tools.x({a: string, b?: integer}): first sentence, with a 12k-byte budget; anything past it goes to describeTool.
Limits: 256 MB VM, 1 MB stack. timeout defaults to 300s and covers both JS loops (interrupt handler) and awaited tools. Agent abort stops the script (drop flag). A promise that never settles fails at once. Output over ~10k tokens is head/tail cut, with the full text in a temp file.
Runs on its own thread with a current-thread tokio runtime, because QuickJS values are !Send.
Registry snapshot is taken after MCP, lens and task are added, so codemode cannot call itself.
Not included: pi's models (classifier/image), image(), searchTools, describeNamespace. Inner tool calls emit no agent events, so the TUI shows only the codemode call.
Cost: hx prefix with codemode on adds +490 tok (1249 to about 1739 with the default tool set). More MCP tools grow it, up to the listing budget (~3k tok). Off by default, so main's prefix is unchanged. Not yet measured on a real session whether scripts save more than the 490 they cost.
New dependency: rquickjs (compiles QuickJS C, needs cc).
Tests: 4 unit tests (parallel calls + filtering, ToolError/throw/partial output, unknown tool, syntax error, hanging promise, tool timeout, infinite loop, signatures/ident). tests/all.sh green. Note: running all.sh with an exported CARGO_TARGET_DIR makes the hx-lens real-cargo tests race; that is not caused by this PR.
Adds pi-style `codemode` (opt-in: `codemode = true` in config).
The model sends raw JS (body of an async function) and it runs in a QuickJS sandbox (rquickjs 0.14) with no fs, network or timers. Only the script output goes back to the model.
- `tools.<name>(args)` calls any registered tool, MCP included (`-` becomes `_`). It resolves to the text output and throws `ToolError` when the tool errors. Calls go through `Registry::call`, so the permission gate and the read-before-edit State work exactly as for direct calls.
- Globals: `text()`, `return`, `console.*` (shown in `<console_output>`), `describeTool(name)`. Several text items get `==> text N/M <==` headers.
- Description lists `tools.x({a: string, b?: integer}): first sentence`, with a 12k-byte budget; anything past it goes to `describeTool`.
- Limits: 256 MB VM, 1 MB stack. `timeout` defaults to 300s and covers both JS loops (interrupt handler) and awaited tools. Agent abort stops the script (drop flag). A promise that never settles fails at once. Output over ~10k tokens is head/tail cut, with the full text in a temp file.
- Runs on its own thread with a current-thread tokio runtime, because QuickJS values are !Send.
- Registry snapshot is taken after MCP, lens and task are added, so codemode cannot call itself.
Not included: pi's `models` (classifier/image), `image()`, `searchTools`, `describeNamespace`. Inner tool calls emit no agent events, so the TUI shows only the codemode call.
Cost: `hx prefix` with codemode on adds +490 tok (1249 to about 1739 with the default tool set). More MCP tools grow it, up to the listing budget (~3k tok). Off by default, so main's prefix is unchanged. Not yet measured on a real session whether scripts save more than the 490 they cost.
New dependency: rquickjs (compiles QuickJS C, needs cc).
Tests: 4 unit tests (parallel calls + filtering, ToolError/throw/partial output, unknown tool, syntax error, hanging promise, tool timeout, infinite loop, signatures/ident). `tests/all.sh` green. Note: running all.sh with an exported CARGO_TARGET_DIR makes the hx-lens real-cargo tests race; that is not caused by this PR.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Adds pi-style
codemode(opt-in:codemode = truein config).The model sends raw JS (body of an async function) and it runs in a QuickJS sandbox (rquickjs 0.14) with no fs, network or timers. Only the script output goes back to the model.
tools.<name>(args)calls any registered tool, MCP included (-becomes_). It resolves to the text output and throwsToolErrorwhen the tool errors. Calls go throughRegistry::call, so the permission gate and the read-before-edit State work exactly as for direct calls.text(),return,console.*(shown in<console_output>),describeTool(name). Several text items get==> text N/M <==headers.tools.x({a: string, b?: integer}): first sentence, with a 12k-byte budget; anything past it goes todescribeTool.timeoutdefaults to 300s and covers both JS loops (interrupt handler) and awaited tools. Agent abort stops the script (drop flag). A promise that never settles fails at once. Output over ~10k tokens is head/tail cut, with the full text in a temp file.Not included: pi's
models(classifier/image),image(),searchTools,describeNamespace. Inner tool calls emit no agent events, so the TUI shows only the codemode call.Cost:
hx prefixwith codemode on adds +490 tok (1249 to about 1739 with the default tool set). More MCP tools grow it, up to the listing budget (~3k tok). Off by default, so main's prefix is unchanged. Not yet measured on a real session whether scripts save more than the 490 they cost.New dependency: rquickjs (compiles QuickJS C, needs cc).
Tests: 4 unit tests (parallel calls + filtering, ToolError/throw/partial output, unknown tool, syntax error, hanging promise, tool timeout, infinite loop, signatures/ident).
tests/all.shgreen. Note: running all.sh with an exported CARGO_TARGET_DIR makes the hx-lens real-cargo tests race; that is not caused by this PR.