@qwen-code/qwen-harness 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,6 +15,9 @@ qwen-harness --help
15
15
 
16
16
  For repository development, install dependencies with `npm install --ignore-scripts`.
17
17
 
18
+ Pi runtime dependencies are pinned to 1.5.0. The explicit `@earendil-works/pi-server`
19
+ dependency supplies the server runtime used by Pi.
20
+
18
21
  ## Development
19
22
 
20
23
  Use one development command for every harness. Omitting `--harness` runs the `pi` profile:
@@ -31,7 +34,7 @@ qwen-harness
31
34
  qwen-harness --harness bash-apply-patch -p "Fix the failing tests"
32
35
  ```
33
36
 
34
- Pass any name from the [Profiles](#profiles) table to `--harness`. The wrapper consumes only this optional argument; every other argument is passed to Pi unchanged.
37
+ Pass any name from the [Profiles](#profiles) table to `--harness`. The `scaling` profile also consumes its `--scaling-*` options; the remaining arguments are passed to Pi.
35
38
 
36
39
  To use the same command from a checkout, run `npm run build && npm link` once. Re-run
37
40
  `npm run build` after source changes; `qwen-harness` will continue to point at this checkout.
@@ -52,6 +55,146 @@ The tool-comparison profiles keep Pi's built-in implementations except for the b
52
55
  `bash` capability, apply an explicit
53
56
  model-visible tool allowlist, and load only the selected custom editor when one is required.
54
57
 
58
+ ## Harness Scaling: Components × Design
59
+
60
+ The `scaling` profile assembles one design from each of six components. It includes the
61
+ survey's 18 pairwise-orthogonal configurations (`H01`–`H18`): each design appears six
62
+ times, and each of the 135 cross-component pairs appears twice. These are the first
63
+ evaluation batch: evaluate all 18, identify weak configurations, add targeted SFT/RL,
64
+ and reevaluate. The full six-axis space contains 729 configurations.
65
+
66
+ ```bash
67
+ # Show the 18 configurations without calling a model.
68
+ npm run dev -- --harness scaling --scaling-list
69
+
70
+ # Inspect the selected prompt, tool entry points, and limits.
71
+ npm run dev -- --harness scaling --scaling-preset H02 --scaling-describe
72
+
73
+ # Run through Pi's normal model/provider, output, and session options.
74
+ npm run dev -- --harness scaling --scaling-preset H02 -p "Fix the failing tests"
75
+ npm run dev -- --harness scaling --scaling-config ./experiment.json -p "Fix the failing tests"
76
+ ```
77
+
78
+ `experiment.json` specifies exactly six choices, for example:
79
+
80
+ ```json
81
+ {"S":"S2","TS":"TS3","TC":"TC3","O":"O3","C":"C2","W":"W3"}
82
+ ```
83
+
84
+ | Component | Design 1 | Design 2 | Design 3 | Mechanism reference |
85
+ | --- | --- | --- | --- | --- |
86
+ | S: system prompt | Minimal guidance | Eight explicit engineering rules | The same rules plus steps, failure branches, and two examples | Pi's concise core; Codex engineering rules and Qwen Code mandates/workflows |
87
+ | TS: task tools | `bash` | `read`, `write`, `edit`, `bash`, `grep`, `glob` | `bash`, `apply_patch` | Existing Pi tools and the packaged Codex-style patch implementation |
88
+ | TC: invocation | Direct tools | `run_code`, fresh JavaScript scope per call | `exec`, persistent JavaScript variables and functions | Pi's native codemode; [Fibona](https://github.com/FibonaAI/fibona-agent) native REPL pattern |
89
+ | O: observations | Direct text within the feedback limit | Fixed head/tail preview, no saved-output path | Same preview plus a complete output file, read through the selected task tools | Qwen Code / OpenCode / Pi / Kimi Code saved-output paths |
90
+ | C: context | Host-generated summary at pressure threshold | Model-authored Notes and explicit window handoff | Segment summaries, older summary rollups, and source index | Pi compaction; local Qwen Code Notes; [Headlong](https://github.com/laude-institute/headlong) tiered recap |
91
+ | W: workflow | Autonomous loop | Investigate, submit a plan, automatically execute next turn | Optional, bounded one-level `subagent` delegation | Codex Plan mode; independent returning subagent sessions |
92
+
93
+ TS, C, and W first contribute their tools to one registry. TC then determines
94
+ how the model reaches **all** of them. TC2/TC3 register the underlying tools as
95
+ callable-only and expose one entry point. Every nested call goes through Pi's
96
+ `executeTool`, preserving validation, hooks, planning gates, observation policy,
97
+ and usage records. Pi's registration allowlist includes both visible and callable
98
+ tools; the active loadout controls visibility.
99
+
100
+ The concrete adaptations are:
101
+
102
+ - **S:** all three designs share the same identity, workspace description, and selected
103
+ component mechanisms. S1 follows Pi's concise guidance style. S2 combines Codex and
104
+ Qwen Code engineering guidance into eight rules covering evidence, project conventions,
105
+ scope, existing work, dependencies, verification, failures, and completion. S3 includes
106
+ all of S2 and adds an iterative task workflow, failure and missing-information branches,
107
+ and two worked examples adapted from Qwen Code's workflow style. The templates are
108
+ rewritten for this experiment. Tool names and calling protocols come from TS/TC;
109
+ planning, delegation, and context tools remain controlled by W/C.
110
+ - **TC2:** uses `@earendil-works/pi-codemode` 1.5.0 for the QuickJS sandbox, tool
111
+ declarations, bridge, cancellation, and execution deadline. Registered nested calls
112
+ still pass through Pi's `executeTool` and the selected O/C/W policies. Each call has
113
+ fresh variables and functions; `store/load` writes are not retained between calls.
114
+ Native `text`, `console`, `image`, `exit`, and return values are supported; timers
115
+ and direct Node/filesystem/network APIs are unavailable. The native default deadline
116
+ is five minutes (overridden by `timeout_ms`), with a 96 MiB VM memory limit. Native
117
+ output limits fail explicitly; successful output reaches O before display truncation,
118
+ so O3 can save the complete emitted text. Tool search and additional model APIs are
119
+ not added by this adapter. The standalone `pi-ptc` profile retains its existing runtime.
120
+ - **C1:** uses Pi's built-in compaction end to end: native threshold detection, history
121
+ selection, summary prompts, and context restoration, including manual and overflow
122
+ compaction. The composer records summary requests/usage and clears TC3 execution
123
+ state after successful compaction. C1 continues from the summary and recent messages;
124
+ it registers no Notes, history lookup, or context-capacity tools.
125
+ Pi's effective `compaction.reserveTokens` and `compaction.keepRecentTokens`, including
126
+ model overrides, are recorded in the session and inherited by C1 subagents. Automatic
127
+ compaction must be enabled. The composer's `contextTriggerRatio` and `summaryTokens`
128
+ do not override C1's native policy.
129
+ - **TC3:** follows Fibona's native REPL mechanism (`f3a007f`), using the same JavaScript
130
+ language, `tools.<name>` API, and registered Pi execution path as TC2. A separate process has a 96 MiB heap limit and
131
+ no model-visible Node, filesystem, or network APIs. REPL state survives cells;
132
+ compaction, Notes handoff, session replacement/resume, cancellation, and execution
133
+ errors reset it. Unawaited work is cancelled when a cell ends.
134
+ - **C2:** follows the local Qwen Code branch
135
+ `dragon/local-notes-compaction@7ee219f032`: `session_notes` saves a versioned
136
+ checkpoint, `new_context` stages a switch using that revision, and
137
+ `session_history` recovers old observations. Saving and switching require separate
138
+ tool-only model turns. The safe turn boundary retains Notes and user task anchors
139
+ without a summary call. The JSONL log is authoritative; a `.notes.md` projection
140
+ beside it is available for inspection. A stale checkpoint or pending user input
141
+ prevents a handoff. C2 also receives context-capacity estimates and
142
+ `get_context_remaining` to help decide when to switch. Its context tools follow TC.
143
+ - **C3:** follows Headlong's implemented tiered recap (`2e39a3f`). A segment becomes
144
+ a leaf summary; three adjacent summaries of one level form the next level. The
145
+ live context contains older coarse summaries plus newer fine summaries and recent
146
+ raw messages. `memory_lookup` expands children and source references;
147
+ `session_history` reads those sources, adapting Headlong's `traj show` / `traj search`
148
+ access to preserved steps. The tree and original observations survive resume.
149
+ C3 uses a 75% host-managed pressure threshold; C1 uses Pi's effective settings.
150
+ Neither exposes a capacity query tool or per-request capacity reminder. C2 prompts the model to manage
151
+ its window and uses an explicitly recorded emergency summary at 90% pressure.
152
+ - **W2:** adapts Codex's investigation-to-execution phase boundary (`5b1d656018`) to automatic
153
+ evaluation. Before `submit_plan`, write/edit tools are blocked. Shell investigation
154
+ accepts literal read-only commands and pipelines (`pwd`, `ls`, `cat`, `head`,
155
+ `tail`, `wc`, `grep`, `rg`, selected Git queries, and numeric `sed -n ...p`).
156
+ It rejects command substitution, redirection, interpreters, and mutation commands.
157
+ Scaling profiles use Pi's default Shell setup and omit user-configured command prefixes.
158
+ Execution opens in the next model turn, including when the plan was submitted
159
+ through TC2 or TC3.
160
+ - **W3:** permits at most four children, one at a time, with at most 30 model calls
161
+ per child. Each child starts with the supplied task description, uses the parent's
162
+ model route and S/TS/TC/O/C, shares the project directory, and has no `subagent`
163
+ tool. Child sessions are retained under the parent's session directory. Parent,
164
+ child, and summarization usage share one budget and are recorded in the session.
165
+
166
+ All configurations use an 8,000-character observation preview and a 64,000-character
167
+ ceiling for an individual feedback text payload. O runs before a result enters either
168
+ the model or its JavaScript program; native structured output and internal spool paths
169
+ cannot bypass O2. O3 saves the complete tool text or native Bash spool to a session-associated
170
+ file before applying the preview budget. The 64,000-character feedback ceiling does not
171
+ truncate that file. Large native spools are copied in full and previewed with bounded reads;
172
+ program output is also preserved before the requested display limit is applied.
173
+
174
+ O3 returns the file path and a reading hint: TS2 uses `read` with line offset/limit or
175
+ `grep`; TS1/TS3 use `bash` to select lines or byte ranges. A long single-line result
176
+ needs a byte-range read or a query of the saved data. These are the existing task tools,
177
+ reached directly in TC1 or through `run_code`/`exec` in TC2/TC3. Every retrieval still
178
+ passes through O and counts toward the task budget. Output files live under
179
+ `scaling-outputs/<session-id>/` in the session directory and remain available after resume.
180
+
181
+ O3 output files are individual tool artifacts, so C1 can read them through its task
182
+ tools while retaining no conversation-history query. C2/C3 history lookup returns
183
+ delivered observations, including to nested programs, and cannot recover text discarded
184
+ by O2.
185
+
186
+ The common defaults are 200 model requests, 1,000 tool calls, two million reported
187
+ tokens, and one hour per task. The token limit is checked between requests: a final
188
+ in-flight response can cross it, after which further calls stop. The ledger includes
189
+ summary calls and child usage. API callers can pass shared `limits` to
190
+ `createScalingRuntime`; configuration and limits are pinned in the session and must
191
+ match on resume. TC4 (deferred discovery) is excluded because this tool registry is
192
+ small and fixed.
193
+
194
+ The local tests use Pi sessions against a deterministic local provider to exercise
195
+ all 18 loadouts and the cross-component mechanics. Model quality and real benchmark
196
+ performance remain the next evaluation step.
197
+
55
198
  ## Pi settings
56
199
 
57
200
  Pi and the harness tools use the same global file:
@@ -179,6 +322,7 @@ chmod 600 ~/.pi/agent/settings.json
179
322
  | --- | --- |
180
323
  | `pi` | Pi's default prompt and tool names, with the bounded `bash` capability |
181
324
  | `pi-ptc` | Pi's default prompt with only `run_code` model-visible; JavaScript can call nested `read`, `bash`, `edit`, and `write` |
325
+ | `scaling` | Six-component composition with the 18 survey presets and explicit configuration files |
182
326
  | `self-compact` | Isolated Pi plus the bounded `bash`, SelfCompact-style context status, rubric, and the `compact_context` tool |
183
327
  | `agent-arena` | General workspace agent tools, multimodal file reading, search, image and speech generation, and interactive `ask_user` |
184
328
  | `code-arena-html` | Single-file HTML tools with a smaller edit/search/media tool set |
@@ -1,9 +1,15 @@
1
1
  // src/capabilities/tools/programmatic-tool-calling/child-runtime.js
2
2
  import readline from "node:readline";
3
+ import repl from "node:repl";
4
+ import { PassThrough } from "node:stream";
3
5
  import vm from "node:vm";
4
6
  var input = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
5
7
  var initialized = false;
6
8
  var finished = false;
9
+ var persistent = false;
10
+ var runtimeContext;
11
+ var replServer;
12
+ var rejectEvaluation;
7
13
  var nextCallId = 1;
8
14
  var nextTimerId = 1;
9
15
  var hostTimers = /* @__PURE__ */ new Map();
@@ -27,8 +33,11 @@ function fail(error) {
27
33
  clearHostTimers();
28
34
  const message = error instanceof Error ? error.message : String(error);
29
35
  send({ type: "done", error: message });
30
- input.close();
31
- process.stdin.unref();
36
+ takeOutput?.();
37
+ if (!persistent) {
38
+ input.close();
39
+ process.stdin.unref();
40
+ }
32
41
  }
33
42
  function createBridge() {
34
43
  const bridge = (operation, first, second, third) => {
@@ -105,7 +114,13 @@ function bootstrapGlobals() {
105
114
  if (error !== void 0) entry.reject(new Error(error));
106
115
  else entry.resolve(value === void 0 ? void 0 : parse(value));
107
116
  };
108
- const output = () => stringify(emitted);
117
+ const output = () => {
118
+ const result = stringify(emitted);
119
+ emitted.length = 0;
120
+ pending.clear();
121
+ timerCallbacks.clear();
122
+ return result;
123
+ };
109
124
  const fireTimerCallback = (id) => {
110
125
  const entry = timerCallbacks.get(id);
111
126
  if (!entry) return void 0;
@@ -221,16 +236,52 @@ function handleToolResponse(message) {
221
236
  async function start(message) {
222
237
  if (initialized) throw new Error("run_code child received more than one init message");
223
238
  initialized = true;
239
+ persistent = message.mode === "persistent";
224
240
  const context = vm.createContext(/* @__PURE__ */ Object.create(null), {
225
241
  name: "pi-run-code",
226
242
  codeGeneration: { strings: false, wasm: false }
227
243
  });
228
244
  installGlobals(context, message.tools);
229
- const wrapped = `"use strict"; (async () => {
245
+ runtimeContext = context;
246
+ if (persistent) {
247
+ const output = new PassThrough();
248
+ output.resume();
249
+ const replOptions = {
250
+ input: new PassThrough(),
251
+ output,
252
+ terminal: false,
253
+ prompt: "",
254
+ useGlobal: false,
255
+ // Node 26 replaced REPL domains with an explicit error handler.
256
+ handleError: (error) => {
257
+ rejectEvaluation?.(error);
258
+ return "ignore";
259
+ }
260
+ };
261
+ replServer = repl.start(replOptions);
262
+ Object.defineProperty(replServer, "context", { value: context });
263
+ replServer._domain?.on("error", (error) => rejectEvaluation?.(error));
264
+ }
265
+ await evaluate(message);
266
+ }
267
+ async function evaluate(message) {
268
+ if (!runtimeContext) throw new Error("Code runtime has not been initialized");
269
+ const context = runtimeContext;
270
+ if (message.type === "eval" && (!persistent || !finished)) throw new Error("Concurrent code cells are not supported");
271
+ finished = false;
272
+ if (replServer) {
273
+ await new Promise((resolve, reject) => {
274
+ rejectEvaluation = reject;
275
+ replServer?.eval(message.code + "\n", context, "exec-cell.js", (error, value) => error ? reject(error) : resolve(value));
276
+ });
277
+ rejectEvaluation = void 0;
278
+ } else {
279
+ const wrapped = `"use strict"; (async () => {
230
280
  ${message.code}
231
281
  })()`;
232
- const script = new vm.Script(wrapped, { filename: "run_code.js" });
233
- await script.runInContext(context, { timeout: message.syncTimeoutMs });
282
+ const script = new vm.Script(wrapped, { filename: "run_code.js" });
283
+ await script.runInContext(runtimeContext, { timeout: message.syncTimeoutMs });
284
+ }
234
285
  if (finished) return;
235
286
  finished = true;
236
287
  clearHostTimers();
@@ -239,8 +290,10 @@ ${message.code}
239
290
  }
240
291
  const output = takeOutput();
241
292
  send({ type: "done", content: JSON.parse(output) });
242
- input.close();
243
- process.stdin.unref();
293
+ if (!persistent) {
294
+ input.close();
295
+ process.stdin.unref();
296
+ }
244
297
  }
245
298
  input.on("line", (line) => {
246
299
  let message;
@@ -254,11 +307,18 @@ input.on("line", (line) => {
254
307
  void start(message).catch(fail);
255
308
  return;
256
309
  }
310
+ if (message.type === "eval") {
311
+ void evaluate(message).catch(fail);
312
+ return;
313
+ }
257
314
  if (message.type === "tool_result" || message.type === "tool_error") {
258
315
  handleToolResponse(message);
259
316
  }
260
317
  });
261
318
  input.on("close", () => {
262
319
  if (!finished) fail(new Error("run_code parent disconnected"));
320
+ clearHostTimers();
321
+ replServer?.close();
322
+ process.stdin.unref();
263
323
  });
264
324
  //# sourceMappingURL=child-runtime.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/capabilities/tools/programmatic-tool-calling/child-runtime.js"],
4
- "sourcesContent": ["// @ts-check\n\n/**\n * Short-lived JavaScript runtime used by run_code.\n *\n * This file is both directly executable from the source tree and compiled as a\n * separate package entrypoint. Model-authored code runs in a vm context without\n * Node globals. Nested tool calls are forwarded to the parent over JSON lines.\n */\n\nimport readline from \"node:readline\";\nimport vm from \"node:vm\";\n\n/** @typedef {import(\"./protocol.js\").ChildDoneMessage} ChildDoneMessage */\n/** @typedef {import(\"./protocol.js\").ChildMessage} ChildMessage */\n/** @typedef {import(\"./protocol.js\").ChildToolCallMessage} ChildToolCallMessage */\n/** @typedef {import(\"./protocol.js\").NestedToolMetadata} NestedToolMetadata */\n/** @typedef {import(\"./protocol.js\").ParentMessage} ParentMessage */\n\nconst input = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });\nlet initialized = false;\nlet finished = false;\nlet nextCallId = 1;\nlet nextTimerId = 1;\n/** @type {Map<string, ReturnType<typeof setTimeout>>} */\nconst hostTimers = new Map();\n/** @type {((id: string, value: string | undefined, error: string | undefined) => void) | undefined} */\nlet settleToolCall;\n/** @type {(() => string) | undefined} */\nlet takeOutput;\n/** @type {((id: string) => unknown) | undefined} */\nlet fireTimer;\n\n/** @param {ChildMessage} message */\nfunction send(message) {\n\tprocess.stdout.write(`${JSON.stringify(message)}\\n`);\n}\n\nfunction sendTimerState() {\n\tif (!finished) send({ type: \"timer_state\", active: hostTimers.size });\n}\n\nfunction clearHostTimers() {\n\tfor (const timer of hostTimers.values()) clearTimeout(timer);\n\thostTimers.clear();\n}\n\n/** @param {unknown} error */\nfunction fail(error) {\n\tif (finished) return;\n\tfinished = true;\n\tclearHostTimers();\n\tconst message = error instanceof Error ? error.message : String(error);\n\tsend({ type: \"done\", error: message });\n\tinput.close();\n\tprocess.stdin.unref();\n}\n\nfunction createBridge() {\n\t/**\n\t * @param {\"register\" | \"call\" | \"set_timer\" | \"clear_timer\"} operation\n\t * @param {string | ((id: string, value: string | undefined, error: string | undefined) => void)} first\n\t * @param {(() => string) | undefined} [second]\n\t * @param {((id: string) => unknown) | undefined} [third]\n\t */\n\tconst bridge = (operation, first, second, third) => {\n\t\tif (operation === \"register\") {\n\t\t\tif (\n\t\t\t\tsettleToolCall\n\t\t\t\t\t|| takeOutput\n\t\t\t\t\t|| fireTimer\n\t\t\t\t\t|| typeof first !== \"function\"\n\t\t\t\t\t|| typeof second !== \"function\"\n\t\t\t\t\t|| typeof third !== \"function\"\n\t\t\t) {\n\t\t\t\tthrow new Error(\"run_code bridge registration failed\");\n\t\t\t}\n\t\t\tsettleToolCall = first;\n\t\t\ttakeOutput = second;\n\t\t\tfireTimer = third;\n\t\t\treturn undefined;\n\t\t}\n\t\tif (typeof first !== \"string\") {\n\t\t\tthrow new TypeError(\"run_code bridge expects serialized input\");\n\t\t}\n\t\tif (operation === \"set_timer\") {\n\t\t\t/** @type {{ delay?: unknown }} */\n\t\t\tconst request = JSON.parse(first);\n\t\t\tconst delay = Number(request.delay ?? 0);\n\t\t\tif (!Number.isFinite(delay) || delay < 0 || delay > 600_000) {\n\t\t\t\tthrow new RangeError(\"setTimeout delay must be between 0 and 600000 ms\");\n\t\t\t}\n\t\t\tconst id = `timer-${String(nextTimerId++)}`;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\thostTimers.delete(id);\n\t\t\t\tsendTimerState();\n\t\t\t\tif (finished || typeof fireTimer !== \"function\") return;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = fireTimer(id);\n\t\t\t\t\tif (result && typeof /** @type {any} */ (result).then === \"function\") {\n\t\t\t\t\t\tvoid Promise.resolve(result).catch(fail);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfail(error);\n\t\t\t\t}\n\t\t\t}, Math.floor(delay));\n\t\t\ttimer.unref();\n\t\t\thostTimers.set(id, timer);\n\t\t\tsendTimerState();\n\t\t\treturn id;\n\t\t}\n\t\tif (operation === \"clear_timer\") {\n\t\t\tconst timer = hostTimers.get(first);\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\thostTimers.delete(first);\n\t\t\tsendTimerState();\n\t\t\treturn undefined;\n\t\t}\n\t\tif (operation !== \"call\") throw new Error(`Unknown run_code bridge operation: ${operation}`);\n\t\t/** @type {{ name: string; args?: unknown }} */\n\t\tconst request = JSON.parse(first);\n\t\tconst id = String(nextCallId++);\n\t\tsend({ type: \"tool_call\", id, name: request.name, args: request.args });\n\t\treturn id;\n\t};\n\tObject.setPrototypeOf(bridge, null);\n\treturn bridge;\n}\n\n/**\n * This function is stringified and evaluated inside the model's vm context so\n * all user-facing functions belong to that realm, not the Node host realm.\n */\nfunction bootstrapGlobals() {\n\tconst runtimeGlobal = /** @type {any} */ (globalThis);\n\t/** @type {(operation: \"register\" | \"call\" | \"set_timer\" | \"clear_timer\", first: string | ((id: string, value: string | undefined, error: string | undefined) => void), second?: () => string, third?: (id: string) => unknown) => string | undefined} */\n\tconst bridge = runtimeGlobal.__runCodeBridge;\n\tconst parse = JSON.parse.bind(JSON);\n\tconst stringify = JSON.stringify.bind(JSON);\n\t/** @type {NestedToolMetadata[]} */\n\tconst metadata = parse(runtimeGlobal.__runCodeMetadata);\n\t/** @type {Array<{ type: \"text\"; text: string } | { type: \"image\"; data: string; mimeType: string }>} */\n\tconst emitted = [];\n\t/** @type {Map<string, { resolve: (value: unknown) => void; reject: (reason?: unknown) => void }>} */\n\tconst pending = new Map();\n\t/** @type {Map<string, { callback: (...args: unknown[]) => unknown; args: unknown[] }>} */\n\tconst timerCallbacks = new Map();\n\n\t/**\n\t * @param {string} id\n\t * @param {string | undefined} value\n\t * @param {string | undefined} error\n\t */\n\tconst settle = (id, value, error) => {\n\t\tconst entry = pending.get(id);\n\t\tif (!entry) return;\n\t\tpending.delete(id);\n\t\tif (error !== undefined) entry.reject(new Error(error));\n\t\telse entry.resolve(value === undefined ? undefined : parse(value));\n\t};\n\tconst output = () => stringify(emitted);\n\t/** @param {string} id */\n\tconst fireTimerCallback = (id) => {\n\t\tconst entry = timerCallbacks.get(id);\n\t\tif (!entry) return undefined;\n\t\ttimerCallbacks.delete(id);\n\t\treturn entry.callback(...entry.args);\n\t};\n\tbridge(\"register\", settle, output, fireTimerCallback);\n\n\tconst tools = Object.create(null);\n\tfor (const item of metadata) {\n\t\tObject.defineProperty(tools, item.name, {\n\t\t\tenumerable: true,\n\t\t\tvalue: (/** @type {unknown} */ args) => new Promise((resolve, reject) => {\n\t\t\t\tlet request;\n\t\t\t\ttry {\n\t\t\t\t\trequest = stringify({ name: item.name, args });\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst id = bridge(\"call\", request);\n\t\t\t\tif (typeof id !== \"string\") {\n\t\t\t\t\treject(new Error(\"run_code bridge did not return a tool call id\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tpending.set(id, { resolve, reject });\n\t\t\t}),\n\t\t});\n\t}\n\tObject.freeze(tools);\n\n\t/** @param {unknown} value */\n\tconst printable = (value) => {\n\t\tif (typeof value === \"string\") return value;\n\t\tif (value === undefined) return \"undefined\";\n\t\ttry {\n\t\t\tconst encoded = stringify(value);\n\t\t\treturn encoded === undefined ? String(value) : encoded;\n\t\t} catch {\n\t\t\treturn String(value);\n\t\t}\n\t};\n\t/** @param {unknown} value */\n\tconst text = (value) => emitted.push({ type: \"text\", text: printable(value) });\n\t/** @param {unknown} value */\n\tconst image = (value) => {\n\t\tif (!value || typeof value !== \"object\") {\n\t\t\tthrow new TypeError(\"image() expects an image content block or nested tool result\");\n\t\t}\n\t\tconst item = /** @type {Record<string, unknown>} */ (value);\n\t\tconst candidates = Array.isArray(item.content) ? item.content : [item];\n\t\tlet count = 0;\n\t\tfor (const candidate of candidates) {\n\t\t\tif (!candidate || typeof candidate !== \"object\") continue;\n\t\t\tconst content = /** @type {Record<string, unknown>} */ (candidate);\n\t\t\tif (\n\t\t\t\t(content.type === undefined || content.type === \"image\")\n\t\t\t\t\t&& typeof content.data === \"string\"\n\t\t\t\t\t&& typeof content.mimeType === \"string\"\n\t\t\t) {\n\t\t\t\temitted.push({ type: \"image\", data: content.data, mimeType: content.mimeType });\n\t\t\t\tcount += 1;\n\t\t\t}\n\t\t}\n\t\tif (!count) throw new TypeError(\"image() input does not contain an image block\");\n\t};\n\t/**\n\t * @param {(...args: unknown[]) => unknown} callback\n\t * @param {unknown} [delay]\n\t * @param {...unknown} args\n\t */\n\tconst scheduleTimeout = (callback, delay = 0, ...args) => {\n\t\tif (typeof callback !== \"function\") throw new TypeError(\"setTimeout callback must be a function\");\n\t\tconst numericDelay = Number(delay);\n\t\tif (!Number.isFinite(numericDelay) || numericDelay < 0 || numericDelay > 600_000) {\n\t\t\tthrow new RangeError(\"setTimeout delay must be between 0 and 600000 ms\");\n\t\t}\n\t\tconst id = bridge(\"set_timer\", stringify({ delay: Math.floor(numericDelay) }));\n\t\tif (typeof id !== \"string\") throw new Error(\"run_code bridge did not return a timer id\");\n\t\ttimerCallbacks.set(id, { callback, args });\n\t\treturn id;\n\t};\n\t/** @param {unknown} handle */\n\tconst cancelTimeout = (handle) => {\n\t\tif (typeof handle !== \"string\") return;\n\t\ttimerCallbacks.delete(handle);\n\t\tbridge(\"clear_timer\", handle);\n\t};\n\n\tObject.defineProperties(runtimeGlobal, {\n\t\ttools: { value: tools, enumerable: true },\n\t\tALL_TOOLS: {\n\t\t\tvalue: Object.freeze(metadata.map((item) => Object.freeze({ ...item }))),\n\t\t\tenumerable: true,\n\t\t},\n\t\ttext: { value: text, enumerable: true },\n\t\timage: { value: image, enumerable: true },\n\t\tsetTimeout: { value: scheduleTimeout, enumerable: true },\n\t\tclearTimeout: { value: cancelTimeout, enumerable: true },\n\t\tconsole: { value: undefined },\n\t});\n\tdelete runtimeGlobal.__runCodeBridge;\n\tdelete runtimeGlobal.__runCodeMetadata;\n}\n\n/**\n * @param {vm.Context} context\n * @param {NestedToolMetadata[]} metadata\n */\nfunction installGlobals(context, metadata) {\n\tcontext.__runCodeBridge = createBridge();\n\tcontext.__runCodeMetadata = JSON.stringify(metadata);\n\tconst bootstrap = new vm.Script(`(${bootstrapGlobals.toString()})()`);\n\tbootstrap.runInContext(context);\n\tif (typeof settleToolCall !== \"function\" || typeof takeOutput !== \"function\") {\n\t\tthrow new Error(\"run_code failed to initialize its tool bridge\");\n\t}\n}\n\n/** @param {import(\"./protocol.js\").ChildToolResultMessage | import(\"./protocol.js\").ChildToolErrorMessage} message */\nfunction handleToolResponse(message) {\n\tif (typeof settleToolCall !== \"function\") return;\n\tif (message.type === \"tool_result\") {\n\t\tconst value = message.value === undefined ? undefined : JSON.stringify(message.value);\n\t\tsettleToolCall(message.id, value, undefined);\n\t} else {\n\t\tsettleToolCall(message.id, undefined, message.error || \"Nested tool call failed\");\n\t}\n}\n\n/** @param {import(\"./protocol.js\").ChildInitMessage} message */\nasync function start(message) {\n\tif (initialized) throw new Error(\"run_code child received more than one init message\");\n\tinitialized = true;\n\tconst context = vm.createContext(Object.create(null), {\n\t\tname: \"pi-run-code\",\n\t\tcodeGeneration: { strings: false, wasm: false },\n\t});\n\tinstallGlobals(context, message.tools);\n\tconst wrapped = `\"use strict\"; (async () => {\\n${message.code}\\n})()`;\n\tconst script = new vm.Script(wrapped, { filename: \"run_code.js\" });\n\tawait script.runInContext(context, { timeout: message.syncTimeoutMs });\n\n\tif (finished) return;\n\tfinished = true;\n\tclearHostTimers();\n\tif (typeof takeOutput !== \"function\") {\n\t\tthrow new Error(\"run_code output bridge is unavailable\");\n\t}\n\tconst output = takeOutput();\n\tsend({ type: \"done\", content: JSON.parse(output) });\n\tinput.close();\n\tprocess.stdin.unref();\n}\n\ninput.on(\"line\", (line) => {\n\t/** @type {ParentMessage} */\n\tlet message;\n\ttry {\n\t\tmessage = JSON.parse(line);\n\t} catch (error) {\n\t\tfail(new Error(`Invalid parent message: ${error instanceof Error ? error.message : String(error)}`));\n\t\treturn;\n\t}\n\tif (message.type === \"init\") {\n\t\tvoid start(message).catch(fail);\n\t\treturn;\n\t}\n\tif (message.type === \"tool_result\" || message.type === \"tool_error\") {\n\t\thandleToolResponse(message);\n\t}\n});\n\ninput.on(\"close\", () => {\n\tif (!finished) fail(new Error(\"run_code parent disconnected\"));\n});\n"],
5
- "mappings": ";AAUA,OAAO,cAAc;AACrB,OAAO,QAAQ;AAQf,IAAM,QAAQ,SAAS,gBAAgB,EAAE,OAAO,QAAQ,OAAO,WAAW,SAAS,CAAC;AACpF,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,aAAa;AACjB,IAAI,cAAc;AAElB,IAAM,aAAa,oBAAI,IAAI;AAE3B,IAAI;AAEJ,IAAI;AAEJ,IAAI;AAGJ,SAAS,KAAK,SAAS;AACtB,UAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,OAAO,CAAC;AAAA,CAAI;AACpD;AAEA,SAAS,iBAAiB;AACzB,MAAI,CAAC,SAAU,MAAK,EAAE,MAAM,eAAe,QAAQ,WAAW,KAAK,CAAC;AACrE;AAEA,SAAS,kBAAkB;AAC1B,aAAW,SAAS,WAAW,OAAO,EAAG,cAAa,KAAK;AAC3D,aAAW,MAAM;AAClB;AAGA,SAAS,KAAK,OAAO;AACpB,MAAI,SAAU;AACd,aAAW;AACX,kBAAgB;AAChB,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,OAAK,EA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uC;AAAA,EACxD;AACA,QAAM,SAAS,WAAW;AAC1B,OAAK,EAAE,MAAM,QAAQ,SAAS,KAAK,MAAM,MAAM,EAAE,CAAC;AAClD,QAAM,MAAM;AACZ,UAAQ,MAAM,MAAM;AACrB;AAEA,MAAM,GAAG,QAAQ,CAAC,SAAS;AAE1B,MAAI;AACJ,MAAI;AACH,cAAU,KAAK,MAAM,IAAI;AAAA,EAC1B,SAAS,OAAO;AACf,SAAK,IAAI,MAAM,2BAA2B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE,CAAC;AACnG;AAAA,EACD;AACA,MAAI,QAAQ,SAAS,QAAQ;AAC5B,SAAK,MAAM,OAAO,EAAE,MAAM,IAAI;AAC9B;AAAA,EACD;AACA,MAAI,QAAQ,SAAS,iBAAiB,QAAQ,SAAS,cAAc;AACpE,uBAAmB,OAAO;AAAA,EAC3B;AACD,CAAC;AAED,MAAM,GAAG,SAAS,MAAM;AACvB,MAAI,CAAC,SAAU,MAAK,IAAI,MAAM,8BAA8B,CAAC;AAC9D,CAAC;",
4
+ "sourcesContent": ["// @ts-check\n\n/**\n * Short-lived JavaScript runtime used by run_code.\n *\n * This file is both directly executable from the source tree and compiled as a\n * separate package entrypoint. Model-authored code runs in a vm context without\n * Node globals. Nested tool calls are forwarded to the parent over JSON lines.\n */\n\nimport readline from \"node:readline\";\nimport repl from \"node:repl\";\nimport { PassThrough } from \"node:stream\";\nimport vm from \"node:vm\";\n\n/** @typedef {import(\"./protocol.js\").ChildDoneMessage} ChildDoneMessage */\n/** @typedef {import(\"./protocol.js\").ChildMessage} ChildMessage */\n/** @typedef {import(\"./protocol.js\").ChildToolCallMessage} ChildToolCallMessage */\n/** @typedef {import(\"./protocol.js\").NestedToolMetadata} NestedToolMetadata */\n/** @typedef {import(\"./protocol.js\").ParentMessage} ParentMessage */\n\nconst input = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });\nlet initialized = false;\nlet finished = false;\nlet persistent = false;\n/** @type {vm.Context | undefined} */\nlet runtimeContext;\n/** @type {repl.REPLServer | undefined} */\nlet replServer;\n/** @type {((error: unknown) => void) | undefined} */\nlet rejectEvaluation;\nlet nextCallId = 1;\nlet nextTimerId = 1;\n/** @type {Map<string, ReturnType<typeof setTimeout>>} */\nconst hostTimers = new Map();\n/** @type {((id: string, value: string | undefined, error: string | undefined) => void) | undefined} */\nlet settleToolCall;\n/** @type {(() => string) | undefined} */\nlet takeOutput;\n/** @type {((id: string) => unknown) | undefined} */\nlet fireTimer;\n\n/** @param {ChildMessage} message */\nfunction send(message) {\n\tprocess.stdout.write(`${JSON.stringify(message)}\\n`);\n}\n\nfunction sendTimerState() {\n\tif (!finished) send({ type: \"timer_state\", active: hostTimers.size });\n}\n\nfunction clearHostTimers() {\n\tfor (const timer of hostTimers.values()) clearTimeout(timer);\n\thostTimers.clear();\n}\n\n/** @param {unknown} error */\nfunction fail(error) {\n\tif (finished) return;\n\tfinished = true;\n\tclearHostTimers();\n\tconst message = error instanceof Error ? error.message : String(error);\n\tsend({ type: \"done\", error: message });\n\ttakeOutput?.(); // Discard output and pending callbacks from the failed cell.\n\tif (!persistent) {\n\t\tinput.close();\n\t\tprocess.stdin.unref();\n\t}\n}\n\nfunction createBridge() {\n\t/**\n\t * @param {\"register\" | \"call\" | \"set_timer\" | \"clear_timer\"} operation\n\t * @param {string | ((id: string, value: string | undefined, error: string | undefined) => void)} first\n\t * @param {(() => string) | undefined} [second]\n\t * @param {((id: string) => unknown) | undefined} [third]\n\t */\n\tconst bridge = (operation, first, second, third) => {\n\t\tif (operation === \"register\") {\n\t\t\tif (\n\t\t\t\tsettleToolCall\n\t\t\t\t\t|| takeOutput\n\t\t\t\t\t|| fireTimer\n\t\t\t\t\t|| typeof first !== \"function\"\n\t\t\t\t\t|| typeof second !== \"function\"\n\t\t\t\t\t|| typeof third !== \"function\"\n\t\t\t) {\n\t\t\t\tthrow new Error(\"run_code bridge registration failed\");\n\t\t\t}\n\t\t\tsettleToolCall = first;\n\t\t\ttakeOutput = second;\n\t\t\tfireTimer = third;\n\t\t\treturn undefined;\n\t\t}\n\t\tif (typeof first !== \"string\") {\n\t\t\tthrow new TypeError(\"run_code bridge expects serialized input\");\n\t\t}\n\t\tif (operation === \"set_timer\") {\n\t\t\t/** @type {{ delay?: unknown }} */\n\t\t\tconst request = JSON.parse(first);\n\t\t\tconst delay = Number(request.delay ?? 0);\n\t\t\tif (!Number.isFinite(delay) || delay < 0 || delay > 600_000) {\n\t\t\t\tthrow new RangeError(\"setTimeout delay must be between 0 and 600000 ms\");\n\t\t\t}\n\t\t\tconst id = `timer-${String(nextTimerId++)}`;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\thostTimers.delete(id);\n\t\t\t\tsendTimerState();\n\t\t\t\tif (finished || typeof fireTimer !== \"function\") return;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = fireTimer(id);\n\t\t\t\t\tif (result && typeof /** @type {any} */ (result).then === \"function\") {\n\t\t\t\t\t\tvoid Promise.resolve(result).catch(fail);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfail(error);\n\t\t\t\t}\n\t\t\t}, Math.floor(delay));\n\t\t\ttimer.unref();\n\t\t\thostTimers.set(id, timer);\n\t\t\tsendTimerState();\n\t\t\treturn id;\n\t\t}\n\t\tif (operation === \"clear_timer\") {\n\t\t\tconst timer = hostTimers.get(first);\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\thostTimers.delete(first);\n\t\t\tsendTimerState();\n\t\t\treturn undefined;\n\t\t}\n\t\tif (operation !== \"call\") throw new Error(`Unknown run_code bridge operation: ${operation}`);\n\t\t/** @type {{ name: string; args?: unknown }} */\n\t\tconst request = JSON.parse(first);\n\t\tconst id = String(nextCallId++);\n\t\tsend({ type: \"tool_call\", id, name: request.name, args: request.args });\n\t\treturn id;\n\t};\n\tObject.setPrototypeOf(bridge, null);\n\treturn bridge;\n}\n\n/**\n * This function is stringified and evaluated inside the model's vm context so\n * all user-facing functions belong to that realm, not the Node host realm.\n */\nfunction bootstrapGlobals() {\n\tconst runtimeGlobal = /** @type {any} */ (globalThis);\n\t/** @type {(operation: \"register\" | \"call\" | \"set_timer\" | \"clear_timer\", first: string | ((id: string, value: string | undefined, error: string | undefined) => void), second?: () => string, third?: (id: string) => unknown) => string | undefined} */\n\tconst bridge = runtimeGlobal.__runCodeBridge;\n\tconst parse = JSON.parse.bind(JSON);\n\tconst stringify = JSON.stringify.bind(JSON);\n\t/** @type {NestedToolMetadata[]} */\n\tconst metadata = parse(runtimeGlobal.__runCodeMetadata);\n\t/** @type {Array<{ type: \"text\"; text: string } | { type: \"image\"; data: string; mimeType: string }>} */\n\tconst emitted = [];\n\t/** @type {Map<string, { resolve: (value: unknown) => void; reject: (reason?: unknown) => void }>} */\n\tconst pending = new Map();\n\t/** @type {Map<string, { callback: (...args: unknown[]) => unknown; args: unknown[] }>} */\n\tconst timerCallbacks = new Map();\n\n\t/**\n\t * @param {string} id\n\t * @param {string | undefined} value\n\t * @param {string | undefined} error\n\t */\n\tconst settle = (id, value, error) => {\n\t\tconst entry = pending.get(id);\n\t\tif (!entry) return;\n\t\tpending.delete(id);\n\t\tif (error !== undefined) entry.reject(new Error(error));\n\t\telse entry.resolve(value === undefined ? undefined : parse(value));\n\t};\n\tconst output = () => {\n\t\tconst result = stringify(emitted);\n\t\temitted.length = 0;\n\t\tpending.clear();\n\t\ttimerCallbacks.clear();\n\t\treturn result;\n\t};\n\t/** @param {string} id */\n\tconst fireTimerCallback = (id) => {\n\t\tconst entry = timerCallbacks.get(id);\n\t\tif (!entry) return undefined;\n\t\ttimerCallbacks.delete(id);\n\t\treturn entry.callback(...entry.args);\n\t};\n\tbridge(\"register\", settle, output, fireTimerCallback);\n\n\tconst tools = Object.create(null);\n\tfor (const item of metadata) {\n\t\tObject.defineProperty(tools, item.name, {\n\t\t\tenumerable: true,\n\t\t\tvalue: (/** @type {unknown} */ args) => new Promise((resolve, reject) => {\n\t\t\t\tlet request;\n\t\t\t\ttry {\n\t\t\t\t\trequest = stringify({ name: item.name, args });\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst id = bridge(\"call\", request);\n\t\t\t\tif (typeof id !== \"string\") {\n\t\t\t\t\treject(new Error(\"run_code bridge did not return a tool call id\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tpending.set(id, { resolve, reject });\n\t\t\t}),\n\t\t});\n\t}\n\tObject.freeze(tools);\n\n\t/** @param {unknown} value */\n\tconst printable = (value) => {\n\t\tif (typeof value === \"string\") return value;\n\t\tif (value === undefined) return \"undefined\";\n\t\ttry {\n\t\t\tconst encoded = stringify(value);\n\t\t\treturn encoded === undefined ? String(value) : encoded;\n\t\t} catch {\n\t\t\treturn String(value);\n\t\t}\n\t};\n\t/** @param {unknown} value */\n\tconst text = (value) => emitted.push({ type: \"text\", text: printable(value) });\n\t/** @param {unknown} value */\n\tconst image = (value) => {\n\t\tif (!value || typeof value !== \"object\") {\n\t\t\tthrow new TypeError(\"image() expects an image content block or nested tool result\");\n\t\t}\n\t\tconst item = /** @type {Record<string, unknown>} */ (value);\n\t\tconst candidates = Array.isArray(item.content) ? item.content : [item];\n\t\tlet count = 0;\n\t\tfor (const candidate of candidates) {\n\t\t\tif (!candidate || typeof candidate !== \"object\") continue;\n\t\t\tconst content = /** @type {Record<string, unknown>} */ (candidate);\n\t\t\tif (\n\t\t\t\t(content.type === undefined || content.type === \"image\")\n\t\t\t\t\t&& typeof content.data === \"string\"\n\t\t\t\t\t&& typeof content.mimeType === \"string\"\n\t\t\t) {\n\t\t\t\temitted.push({ type: \"image\", data: content.data, mimeType: content.mimeType });\n\t\t\t\tcount += 1;\n\t\t\t}\n\t\t}\n\t\tif (!count) throw new TypeError(\"image() input does not contain an image block\");\n\t};\n\t/**\n\t * @param {(...args: unknown[]) => unknown} callback\n\t * @param {unknown} [delay]\n\t * @param {...unknown} args\n\t */\n\tconst scheduleTimeout = (callback, delay = 0, ...args) => {\n\t\tif (typeof callback !== \"function\") throw new TypeError(\"setTimeout callback must be a function\");\n\t\tconst numericDelay = Number(delay);\n\t\tif (!Number.isFinite(numericDelay) || numericDelay < 0 || numericDelay > 600_000) {\n\t\t\tthrow new RangeError(\"setTimeout delay must be between 0 and 600000 ms\");\n\t\t}\n\t\tconst id = bridge(\"set_timer\", stringify({ delay: Math.floor(numericDelay) }));\n\t\tif (typeof id !== \"string\") throw new Error(\"run_code bridge did not return a timer id\");\n\t\ttimerCallbacks.set(id, { callback, args });\n\t\treturn id;\n\t};\n\t/** @param {unknown} handle */\n\tconst cancelTimeout = (handle) => {\n\t\tif (typeof handle !== \"string\") return;\n\t\ttimerCallbacks.delete(handle);\n\t\tbridge(\"clear_timer\", handle);\n\t};\n\n\tObject.defineProperties(runtimeGlobal, {\n\t\ttools: { value: tools, enumerable: true },\n\t\tALL_TOOLS: {\n\t\t\tvalue: Object.freeze(metadata.map((item) => Object.freeze({ ...item }))),\n\t\t\tenumerable: true,\n\t\t},\n\t\ttext: { value: text, enumerable: true },\n\t\timage: { value: image, enumerable: true },\n\t\tsetTimeout: { value: scheduleTimeout, enumerable: true },\n\t\tclearTimeout: { value: cancelTimeout, enumerable: true },\n\t\tconsole: { value: undefined },\n\t});\n\tdelete runtimeGlobal.__runCodeBridge;\n\tdelete runtimeGlobal.__runCodeMetadata;\n}\n\n/**\n * @param {vm.Context} context\n * @param {NestedToolMetadata[]} metadata\n */\nfunction installGlobals(context, metadata) {\n\tcontext.__runCodeBridge = createBridge();\n\tcontext.__runCodeMetadata = JSON.stringify(metadata);\n\tconst bootstrap = new vm.Script(`(${bootstrapGlobals.toString()})()`);\n\tbootstrap.runInContext(context);\n\tif (typeof settleToolCall !== \"function\" || typeof takeOutput !== \"function\") {\n\t\tthrow new Error(\"run_code failed to initialize its tool bridge\");\n\t}\n}\n\n/** @param {import(\"./protocol.js\").ChildToolResultMessage | import(\"./protocol.js\").ChildToolErrorMessage} message */\nfunction handleToolResponse(message) {\n\tif (typeof settleToolCall !== \"function\") return;\n\tif (message.type === \"tool_result\") {\n\t\tconst value = message.value === undefined ? undefined : JSON.stringify(message.value);\n\t\tsettleToolCall(message.id, value, undefined);\n\t} else {\n\t\tsettleToolCall(message.id, undefined, message.error || \"Nested tool call failed\");\n\t}\n}\n\n/** @param {import(\"./protocol.js\").ChildInitMessage} message */\nasync function start(message) {\n\tif (initialized) throw new Error(\"run_code child received more than one init message\");\n\tinitialized = true;\n\tpersistent = message.mode === \"persistent\";\n\tconst context = vm.createContext(Object.create(null), {\n\t\tname: \"pi-run-code\",\n\t\tcodeGeneration: { strings: false, wasm: false },\n\t});\n\tinstallGlobals(context, message.tools);\n\truntimeContext = context;\n\tif (persistent) {\n\t\tconst output = new PassThrough();\n\t\toutput.resume();\n\t\tconst replOptions = {\n\t\t\tinput: new PassThrough(), output, terminal: false, prompt: \"\", useGlobal: false,\n\t\t\t// Node 26 replaced REPL domains with an explicit error handler.\n\t\t\thandleError: (/** @type {unknown} */ error) => { rejectEvaluation?.(error); return \"ignore\"; },\n\t\t};\n\t\treplServer = repl.start(replOptions);\n\t\t// Keep Node's native top-level-await/declaration handling, but replace its\n\t\t// default context (which exposes require/process) with our restricted realm.\n\t\tObject.defineProperty(replServer, \"context\", { value: context });\n\t\t// Node sends runtime exceptions through this domain instead of eval's callback.\n\t\t/** @type {any} */ (replServer)._domain?.on(\"error\", (/** @type {unknown} */ error) => rejectEvaluation?.(error));\n\t}\n\tawait evaluate(message);\n}\n\n/** @param {import(\"./protocol.js\").ChildInitMessage | import(\"./protocol.js\").ChildEvalMessage} message */\nasync function evaluate(message) {\n\tif (!runtimeContext) throw new Error(\"Code runtime has not been initialized\");\n\tconst context = runtimeContext;\n\tif (message.type === \"eval\" && (!persistent || !finished)) throw new Error(\"Concurrent code cells are not supported\");\n\tfinished = false;\n\tif (replServer) {\n\t\tawait new Promise((resolve, reject) => {\n\t\t\trejectEvaluation = reject;\n\t\t\treplServer?.eval(message.code + \"\\n\", context, \"exec-cell.js\", (error, value) => error ? reject(error) : resolve(value));\n\t\t});\n\t\trejectEvaluation = undefined;\n\t} else {\n\t\tconst wrapped = `\"use strict\"; (async () => {\\n${message.code}\\n})()`;\n\t\tconst script = new vm.Script(wrapped, { filename: \"run_code.js\" });\n\t\tawait script.runInContext(runtimeContext, { timeout: message.syncTimeoutMs });\n\t}\n\n\tif (finished) return;\n\tfinished = true;\n\tclearHostTimers();\n\tif (typeof takeOutput !== \"function\") {\n\t\tthrow new Error(\"run_code output bridge is unavailable\");\n\t}\n\tconst output = takeOutput();\n\tsend({ type: \"done\", content: JSON.parse(output) });\n\tif (!persistent) {\n\t\tinput.close();\n\t\tprocess.stdin.unref();\n\t}\n}\n\ninput.on(\"line\", (line) => {\n\t/** @type {ParentMessage} */\n\tlet message;\n\ttry {\n\t\tmessage = JSON.parse(line);\n\t} catch (error) {\n\t\tfail(new Error(`Invalid parent message: ${error instanceof Error ? error.message : String(error)}`));\n\t\treturn;\n\t}\n\tif (message.type === \"init\") {\n\t\tvoid start(message).catch(fail);\n\t\treturn;\n\t}\n\tif (message.type === \"eval\") {\n\t\tvoid evaluate(message).catch(fail);\n\t\treturn;\n\t}\n\tif (message.type === \"tool_result\" || message.type === \"tool_error\") {\n\t\thandleToolResponse(message);\n\t}\n});\n\ninput.on(\"close\", () => {\n\tif (!finished) fail(new Error(\"run_code parent disconnected\"));\n\tclearHostTimers();\n\treplServer?.close();\n\tprocess.stdin.unref();\n});\n"],
5
+ "mappings": ";AAUA,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,SAAS,mBAAmB;AAC5B,OAAO,QAAQ;AAQf,IAAM,QAAQ,SAAS,gBAAgB,EAAE,OAAO,QAAQ,OAAO,WAAW,SAAS,CAAC;AACpF,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,aAAa;AAEjB,IAAI;AAEJ,IAAI;AAEJ,IAAI;AACJ,IAAI,aAAa;AACjB,IAAI,cAAc;AAElB,I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