@qwen-code/qwen-harness 0.1.10 → 0.1.11
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 +9 -4
- package/dist/entrypoint.js +67 -34
- package/dist/entrypoint.js.map +3 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -183,9 +183,14 @@ The concrete adaptations are:
|
|
|
183
183
|
in one ledger, with no extra call or child-count ceiling.
|
|
184
184
|
|
|
185
185
|
All configurations use an 8,000-character observation preview and a 64,000-character
|
|
186
|
-
ceiling for an individual feedback text payload. O
|
|
187
|
-
the
|
|
188
|
-
|
|
186
|
+
ceiling for an individual feedback text payload. O applies only immediately before model
|
|
187
|
+
delivery: to the direct tool result in TC1, or the completed program output in TC2/TC3.
|
|
188
|
+
Internal `tools.xxx` calls keep their native content, structured output, error details,
|
|
189
|
+
limits and spool paths. Only explicitly emitted output enters the model's observation/history.
|
|
190
|
+
Typed image blocks are never text-cropped. Each delivered image is actually decoded;
|
|
191
|
+
an invalid image is replaced by error text without discarding other valid content.
|
|
192
|
+
Valid images, including 1×1 images, are not enlarged or subjected to provider minimum-size rules.
|
|
193
|
+
O3 saves the complete delivered text or native TC1 Bash spool to a session-associated
|
|
189
194
|
file before applying the preview budget. The 64,000-character feedback ceiling does not
|
|
190
195
|
truncate that file. Large native spools are copied in full and previewed with bounded reads;
|
|
191
196
|
program output is also preserved before the requested display limit is applied.
|
|
@@ -194,7 +199,7 @@ O3 returns the file path and a reading hint: TS2 uses `read` with line offset/li
|
|
|
194
199
|
`grep`; TS1/TS3 use `bash` to select lines or byte ranges. A long single-line result
|
|
195
200
|
needs a byte-range read or a query of the saved data. These are the existing task tools,
|
|
196
201
|
reached directly in TC1 or through `run_code`/`exec` in TC2/TC3. Every retrieval still
|
|
197
|
-
passes through O and is included in usage accounting. Output files live under
|
|
202
|
+
passes through O at the model delivery boundary and is included in usage accounting. Output files live under
|
|
198
203
|
`scaling-outputs/<session-id>/` in the session directory and remain available after resume.
|
|
199
204
|
|
|
200
205
|
O3 output files are individual tool artifacts, so C1 can read them through its task
|
package/dist/entrypoint.js
CHANGED
|
@@ -169,6 +169,49 @@ var init_harness_args = __esm({
|
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
+
// src/capabilities/tools/image-output.ts
|
|
173
|
+
import { PhotonImage } from "@silvia-odwyer/photon-node";
|
|
174
|
+
function prepareImageOutput(image, maxBytes) {
|
|
175
|
+
let reason;
|
|
176
|
+
if (typeof image.data !== "string") reason = "missing base64 image data";
|
|
177
|
+
else {
|
|
178
|
+
const data = image.data.replace(/\s+/gu, "");
|
|
179
|
+
if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/u.test(data)) reason = "invalid base64 image data";
|
|
180
|
+
else {
|
|
181
|
+
const signature = IMAGE_SIGNATURES.find(([, pattern]) => pattern.test(data.slice(0, 16)));
|
|
182
|
+
if (!signature) reason = "expected PNG, JPEG, GIF, or WebP image data";
|
|
183
|
+
else if (maxBytes !== void 0 && Buffer.byteLength(data, "base64") > maxBytes) reason = "image exceeds the tool's byte limit";
|
|
184
|
+
else {
|
|
185
|
+
try {
|
|
186
|
+
const decoded = PhotonImage.new_from_byteslice(Buffer.from(data, "base64"));
|
|
187
|
+
decoded.free();
|
|
188
|
+
return { ...image, type: "image", data, mimeType: signature[0] };
|
|
189
|
+
} catch {
|
|
190
|
+
reason = "image decoder rejected the data";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { type: "text", text: `${IMAGE_OMITTED_MESSAGE}: ${reason}.` };
|
|
196
|
+
}
|
|
197
|
+
function prepareToolOutputContent(content, maxBytes) {
|
|
198
|
+
return content.map((part) => part.type === "image" ? prepareImageOutput(part, maxBytes) : part);
|
|
199
|
+
}
|
|
200
|
+
var IMAGE_OMITTED_MESSAGE, MAX_EMITTED_IMAGE_BYTES, IMAGE_SIGNATURES;
|
|
201
|
+
var init_image_output = __esm({
|
|
202
|
+
"src/capabilities/tools/image-output.ts"() {
|
|
203
|
+
"use strict";
|
|
204
|
+
IMAGE_OMITTED_MESSAGE = "image content omitted because it could not be processed";
|
|
205
|
+
MAX_EMITTED_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
206
|
+
IMAGE_SIGNATURES = [
|
|
207
|
+
["image/png", /^iVBORw0KGg/u],
|
|
208
|
+
["image/jpeg", /^[/]9j[/](?!9)/u],
|
|
209
|
+
["image/gif", /^R0lGOD[dl]h/u],
|
|
210
|
+
["image/webp", /^UklG.{8}RUJQ/u]
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
172
215
|
// src/capabilities/tools/programmatic-tool-calling/index.ts
|
|
173
216
|
import { spawn as spawn2 } from "node:child_process";
|
|
174
217
|
import path13 from "node:path";
|
|
@@ -275,7 +318,7 @@ function runCodeDescription(tools) {
|
|
|
275
318
|
"declare function image(value: ImageContent | NestedToolResult): void;",
|
|
276
319
|
"declare function setTimeout(callback: (...args: unknown[]) => void, delayMs?: number, ...args: unknown[]): string;",
|
|
277
320
|
"declare function clearTimeout(handle: string): void;",
|
|
278
|
-
'type NestedToolResult = { content: Array<{ type: "text"; text: string } | ImageContent
|
|
321
|
+
'type NestedToolResult = { content: Array<{ type: "text"; text: string } | ImageContent>; isError?: boolean; structuredContent?: unknown; details?: unknown; terminate?: boolean };',
|
|
279
322
|
"```",
|
|
280
323
|
"",
|
|
281
324
|
...tools.map(nestedToolDescription)
|
|
@@ -312,6 +355,7 @@ function nestedResultValue(result, structured = false) {
|
|
|
312
355
|
content: result.content,
|
|
313
356
|
isError: result.isError ?? false,
|
|
314
357
|
...result.structuredContent === void 0 ? {} : { structuredContent: result.structuredContent },
|
|
358
|
+
...result.details === void 0 ? {} : { details: result.details },
|
|
315
359
|
...result.terminate ? { terminate: true } : {}
|
|
316
360
|
};
|
|
317
361
|
const content = result.content.map((item) => item.type === "text" ? { type: "text", text: item.text } : { type: "image", data: item.data, mimeType: item.mimeType });
|
|
@@ -333,7 +377,7 @@ function cappedText(text, remaining) {
|
|
|
333
377
|
used: remaining
|
|
334
378
|
};
|
|
335
379
|
}
|
|
336
|
-
function emittedContent(value, maxOutputChars) {
|
|
380
|
+
function emittedContent(value, maxOutputChars, prepareImages = true) {
|
|
337
381
|
if (!Array.isArray(value)) throw new Error("run_code child returned invalid content");
|
|
338
382
|
const content = [];
|
|
339
383
|
let remaining = maxOutputChars;
|
|
@@ -347,21 +391,8 @@ function emittedContent(value, maxOutputChars) {
|
|
|
347
391
|
remaining -= capped.used;
|
|
348
392
|
continue;
|
|
349
393
|
}
|
|
350
|
-
if (candidate.type === "image"
|
|
351
|
-
|
|
352
|
-
if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/u.test(data)) {
|
|
353
|
-
throw new Error("Invalid image output: image data is not valid base64 (truncated or mixed with tool text?).");
|
|
354
|
-
}
|
|
355
|
-
const signature = IMAGE_SIGNATURES.find(([, pattern]) => pattern.test(data.slice(0, 16)));
|
|
356
|
-
if (!signature) throw new Error("Invalid image output: expected PNG, JPEG, GIF, or WebP image data.");
|
|
357
|
-
if (Buffer.byteLength(data, "base64") > MAX_IMAGE_BYTES) {
|
|
358
|
-
throw new Error("run_code image output exceeds the 20 MiB limit");
|
|
359
|
-
}
|
|
360
|
-
content.push({
|
|
361
|
-
type: "image",
|
|
362
|
-
data,
|
|
363
|
-
mimeType: signature[0]
|
|
364
|
-
});
|
|
394
|
+
if (candidate.type === "image") {
|
|
395
|
+
content.push(prepareImages ? prepareImageOutput({ data: candidate.data, mimeType: candidate.mimeType }, MAX_EMITTED_IMAGE_BYTES) : { type: "image", data: candidate.data, mimeType: candidate.mimeType });
|
|
365
396
|
}
|
|
366
397
|
}
|
|
367
398
|
return content.length ? content : [{ type: "text", text: "Code completed without emitted output." }];
|
|
@@ -624,24 +655,18 @@ function createProgrammaticToolCallingCapability(cwd = process.cwd(), options =
|
|
|
624
655
|
extensionFactories: [createProgrammaticToolCallingExtension(cwd, options)]
|
|
625
656
|
};
|
|
626
657
|
}
|
|
627
|
-
var RUN_CODE_TOOL_NAME, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_SYNC_TIMEOUT_MS, MAX_TIMEOUT_MS, DEFAULT_MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS,
|
|
658
|
+
var RUN_CODE_TOOL_NAME, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_SYNC_TIMEOUT_MS, MAX_TIMEOUT_MS, DEFAULT_MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS, TRUNCATION_MARKER, RUN_CODE_CHILD_PATH, runCodeSchema, createCodeModeCapability;
|
|
628
659
|
var init_programmatic_tool_calling = __esm({
|
|
629
660
|
"src/capabilities/tools/programmatic-tool-calling/index.ts"() {
|
|
630
661
|
"use strict";
|
|
631
662
|
init_bash();
|
|
663
|
+
init_image_output();
|
|
632
664
|
RUN_CODE_TOOL_NAME = "run_code";
|
|
633
665
|
DEFAULT_IDLE_TIMEOUT_MS = 3e4;
|
|
634
666
|
DEFAULT_SYNC_TIMEOUT_MS = 5e3;
|
|
635
667
|
MAX_TIMEOUT_MS = 6e5;
|
|
636
668
|
DEFAULT_MAX_OUTPUT_CHARS = 5e4;
|
|
637
669
|
MAX_OUTPUT_CHARS = 2e5;
|
|
638
|
-
MAX_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
639
|
-
IMAGE_SIGNATURES = [
|
|
640
|
-
["image/png", /^iVBORw0KGg/u],
|
|
641
|
-
["image/jpeg", /^[/]9j[/](?!9)/u],
|
|
642
|
-
["image/gif", /^R0lGOD[dl]h/u],
|
|
643
|
-
["image/webp", /^UklG.{8}RUJQ/u]
|
|
644
|
-
];
|
|
645
670
|
TRUNCATION_MARKER = "\n... run_code output truncated ...\n";
|
|
646
671
|
RUN_CODE_CHILD_PATH = fileURLToPath3(new URL("./child-runtime.js", import.meta.url));
|
|
647
672
|
runCodeSchema = Type21.Object({
|
|
@@ -774,6 +799,7 @@ var init_persistent = __esm({
|
|
|
774
799
|
metadata;
|
|
775
800
|
idleTimeoutMs;
|
|
776
801
|
retainFullOutput;
|
|
802
|
+
prepareImages;
|
|
777
803
|
constructor(tools, idleTimeoutMs = 5e3, options = {}) {
|
|
778
804
|
assertNestedTools(tools);
|
|
779
805
|
if (tools.some((tool) => tool.name === "exec")) throw new Error("exec cannot call itself");
|
|
@@ -781,6 +807,7 @@ var init_persistent = __esm({
|
|
|
781
807
|
this.tools = new Map(tools.map((tool) => [normalizedToolName(tool.name), tool]));
|
|
782
808
|
this.idleTimeoutMs = idleTimeoutMs;
|
|
783
809
|
this.retainFullOutput = options.retainFullOutput ?? false;
|
|
810
|
+
this.prepareImages = options.prepareImages ?? true;
|
|
784
811
|
}
|
|
785
812
|
post(message) {
|
|
786
813
|
if (this.child?.stdin.writable) this.child.stdin.write(JSON.stringify(message) + "\n");
|
|
@@ -890,7 +917,7 @@ var init_persistent = __esm({
|
|
|
890
917
|
}
|
|
891
918
|
try {
|
|
892
919
|
resolve({
|
|
893
|
-
content: emittedContent(message.content, this.retainFullOutput ? Number.MAX_SAFE_INTEGER : params.max_output_chars ?? 64e3),
|
|
920
|
+
content: emittedContent(message.content, this.retainFullOutput ? Number.MAX_SAFE_INTEGER : params.max_output_chars ?? 64e3, this.prepareImages),
|
|
894
921
|
details: { calls: cell.calls, generation: this.generation },
|
|
895
922
|
...cell.terminate ? { terminate: true } : {}
|
|
896
923
|
});
|
|
@@ -1599,6 +1626,7 @@ var OUTPUT_ENTRY, OBSERVATION_ENTRY, ObservationPolicy;
|
|
|
1599
1626
|
var init_observation = __esm({
|
|
1600
1627
|
"src/harnesses/scaling/observation.ts"() {
|
|
1601
1628
|
"use strict";
|
|
1629
|
+
init_image_output();
|
|
1602
1630
|
init_tools();
|
|
1603
1631
|
OUTPUT_ENTRY = "scaling-output";
|
|
1604
1632
|
OBSERVATION_ENTRY = "scaling-observation";
|
|
@@ -1616,6 +1644,8 @@ var init_observation = __esm({
|
|
|
1616
1644
|
this.pi = pi;
|
|
1617
1645
|
}
|
|
1618
1646
|
async apply(name, result, ctx, callId, outputLimit) {
|
|
1647
|
+
const prepared = prepareToolOutputContent(result.content, ["run_code", "exec"].includes(name) ? MAX_EMITTED_IMAGE_BYTES : void 0);
|
|
1648
|
+
const images = prepared.filter((_part, index) => result.content[index]?.type === "image");
|
|
1619
1649
|
const source = nativeSource(name, result);
|
|
1620
1650
|
const page = ["session_history", "memory_lookup"].includes(name);
|
|
1621
1651
|
const budget = Math.min(this.design === "O1" || page ? this.limits.hardOutputChars : this.limits.previewChars, outputLimit ?? this.limits.hardOutputChars);
|
|
@@ -1641,7 +1671,7 @@ var init_observation = __esm({
|
|
|
1641
1671
|
const readHint = this.taskTools === "TS2" ? "Use read with this path, offset (1-based line), and a small limit, or grep with path and pattern. For a long single line, use bash to read a byte range." : "Use bash with sed -n 'START,ENDp' to read selected lines or head/tail -c for byte ranges. Read bounded sections.";
|
|
1642
1672
|
const content = [
|
|
1643
1673
|
...preview.text ? [{ type: "text", text: preview.text }] : [],
|
|
1644
|
-
...
|
|
1674
|
+
...images,
|
|
1645
1675
|
...outputPath ? [{ type: "text", text: `Full output saved to: ${outputPath}
|
|
1646
1676
|
${readHint}` }] : [],
|
|
1647
1677
|
{ type: "text", text: `[tool status: ${JSON.stringify(status)}]` }
|
|
@@ -2171,7 +2201,7 @@ function createScalingCodemodeTool(tools) {
|
|
|
2171
2201
|
description: [
|
|
2172
2202
|
"Run JavaScript in Pi's codemode sandbox. Every call starts a fresh QuickJS environment.",
|
|
2173
2203
|
"Call tools with tools.<name>(args) and await operations whose results or completion matter. Unawaited operations are cancelled when the script ends.",
|
|
2174
|
-
"Each tool result includes content, isError, and optional structuredContent. Inspect isError to handle failed operations.",
|
|
2204
|
+
"Each tool result includes content, isError, and optional native structuredContent and details. Inspect isError to handle failed operations.",
|
|
2175
2205
|
"Use text(value) or console.log(value) to emit text; use image(block) for an individual image content block or a base64 data URI. A returned value is also emitted.",
|
|
2176
2206
|
"ALL_TOOLS lists the available tools. No Node, filesystem, network, setTimeout, or clearTimeout APIs are exposed; use the registered task tools.",
|
|
2177
2207
|
"Variables, functions, and store/load values do not survive this call. Reconstruct needed values from the current context and available tools.",
|
|
@@ -2205,7 +2235,7 @@ function createScalingCodemodeTool(tools) {
|
|
|
2205
2235
|
if (!result.ok) content.push({ type: "text", text: `Script ${result.error.kind}: ${result.error.message}` });
|
|
2206
2236
|
return {
|
|
2207
2237
|
// O receives the complete emitted output before applying its display/recovery policy.
|
|
2208
|
-
content: emittedContent(content, Number.MAX_SAFE_INTEGER),
|
|
2238
|
+
content: emittedContent(content, Number.MAX_SAFE_INTEGER, false),
|
|
2209
2239
|
details: { engine: "pi-codemode", calls: result.calls.map((call, index) => failedCalls.has(index) ? { ...call, status: "error" } : call) },
|
|
2210
2240
|
...result.ok ? {} : { isError: true },
|
|
2211
2241
|
...terminate ? { terminate: true } : {}
|
|
@@ -2227,7 +2257,8 @@ var init_codemode = __esm({
|
|
|
2227
2257
|
Type27.Object({ type: Type27.Literal("image"), data: Type27.String(), mimeType: Type27.String() })
|
|
2228
2258
|
])),
|
|
2229
2259
|
isError: Type27.Boolean(),
|
|
2230
|
-
structuredContent: Type27.Optional(Type27.
|
|
2260
|
+
structuredContent: Type27.Optional(Type27.Unknown()),
|
|
2261
|
+
details: Type27.Optional(Type27.Unknown()),
|
|
2231
2262
|
terminate: Type27.Optional(Type27.Boolean())
|
|
2232
2263
|
});
|
|
2233
2264
|
}
|
|
@@ -2591,10 +2622,12 @@ function createScalingRuntime(input, options = {}) {
|
|
|
2591
2622
|
}
|
|
2592
2623
|
};
|
|
2593
2624
|
function guarded(tool, outer = false) {
|
|
2625
|
+
const delivered = outer || config.TC === "TC1";
|
|
2594
2626
|
return {
|
|
2595
2627
|
...tool,
|
|
2596
|
-
//
|
|
2597
|
-
|
|
2628
|
+
// Only model delivery uses O's shared result shape. Programs retain
|
|
2629
|
+
// native content, structured results, and their schema.
|
|
2630
|
+
outputSchema: delivered ? void 0 : tool.outputSchema,
|
|
2598
2631
|
exposure: outer ? "model-only" : config.TC === "TC1" ? "direct" : "codemode",
|
|
2599
2632
|
async execute(id, args, signal, _update, ctx) {
|
|
2600
2633
|
if (fatal) throw fatal;
|
|
@@ -2611,7 +2644,7 @@ function createScalingRuntime(input, options = {}) {
|
|
|
2611
2644
|
if (signal?.aborted || fatal) throw error;
|
|
2612
2645
|
result = { ...textResult(error instanceof Error ? error.message : String(error)), isError: true };
|
|
2613
2646
|
}
|
|
2614
|
-
const observed = await observation.apply(tool.name, result, ctx, id, outputLimit);
|
|
2647
|
+
const observed = delivered ? await observation.apply(tool.name, result, ctx, id, outputLimit) : result;
|
|
2615
2648
|
if (config.C === "C2" && !outer && !["session_notes", "new_context", "session_history", "get_context_remaining", "memory_lookup"].includes(tool.name)) context.notes.workChanged();
|
|
2616
2649
|
return observed;
|
|
2617
2650
|
}
|
|
@@ -2637,7 +2670,7 @@ function createScalingRuntime(input, options = {}) {
|
|
|
2637
2670
|
registered.push(guarded(tool, true));
|
|
2638
2671
|
exposed = [tool.name];
|
|
2639
2672
|
} else {
|
|
2640
|
-
code = new PersistentCodeRuntime(registered, void 0, { retainFullOutput: true });
|
|
2673
|
+
code = new PersistentCodeRuntime(registered, void 0, { retainFullOutput: true, prepareImages: false });
|
|
2641
2674
|
registered.push(guarded(createExecTool(code), true));
|
|
2642
2675
|
exposed = ["exec"];
|
|
2643
2676
|
}
|