@promptdriven/runtime-client 1.1.0 → 1.1.2
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/package.json +1 -1
- package/src/runtime/adaptive-concurrency.mjs +53 -0
- package/src/runtime/agent-guide.mjs +3 -0
- package/src/runtime/agent-judge.mjs +73 -2
- package/src/runtime/index.mjs +19 -0
- package/src/runtime/product-composition.mjs +6 -4
- package/src/runtime/run-program.mjs +3 -2
- package/src/runtime/runtime-bindings.mjs +10 -11
- package/src/runtime/runtime-check-plan.mjs +26 -30
- package/src/runtime/runtime-check-reconcile.mjs +328 -0
- package/src/runtime/runtime-client.mjs +2284 -277
- package/src/runtime/runtime-outcome.mjs +3 -0
- package/src/runtime/runtime-output.mjs +219 -13
- package/src/runtime/runtime-preflight.mjs +215 -14
- package/src/runtime/runtime-stream.mjs +125 -0
- package/src/runtime/try-doors.mjs +1 -0
- package/src/runtime/try-http.mjs +11 -3
- package/src/runtime/try-mcp.mjs +8 -1
|
@@ -423,6 +423,7 @@ function progressFrom(value) {
|
|
|
423
423
|
const progress = {};
|
|
424
424
|
for (const key of ['steps_done', 'steps_total', 'calls_settled', 'calls_open']) if (count(value?.[key])) progress[key] = value[key];
|
|
425
425
|
if (Number.isSafeInteger(value?.step) && value.step >= 1 || typeof value?.step === 'string' && value.step.trim()) progress.step = value.step;
|
|
426
|
+
if (typeof value?.stage === 'string' && value.stage.trim()) progress.stage = value.stage.trim();
|
|
426
427
|
return progress;
|
|
427
428
|
}
|
|
428
429
|
|
|
@@ -435,7 +436,9 @@ export function outcomeText(outcome) {
|
|
|
435
436
|
const p = outcome.progress ?? {};
|
|
436
437
|
const number = typeof p.step === 'number' ? p.step : count(p.steps_done) && count(p.steps_total) && p.steps_done < p.steps_total ? p.steps_done + 1 : null;
|
|
437
438
|
const step = number ? `step ${number}${count(p.steps_total) ? ` of ${p.steps_total}` : ''}` : typeof p.step === 'string' ? p.step : null;
|
|
439
|
+
const stage = !step && typeof p.stage === 'string' && p.stage && !['running', 'queued'].includes(p.stage) ? p.stage : null;
|
|
438
440
|
return [state + (reason ? ` (${reason.code})` : ''), ...(count(outcome.ahead) ? [`${outcome.ahead} ahead`] : []),
|
|
441
|
+
...(stage ? [stage] : []),
|
|
439
442
|
...(step ? [step + (number && typeof p.step === 'string' ? ` (${p.step})` : '')] : []), ...callWords(p.calls_settled, p.calls_open)].join(' · ');
|
|
440
443
|
}
|
|
441
444
|
|
|
@@ -208,19 +208,101 @@ export function projectAnswer(answer, { origin, secrets = [], steps: authoredSte
|
|
|
208
208
|
evidence: Array.isArray(check.diagnosis.evidence) ? check.diagnosis.evidence.map(item => cleanText(item, secrets)).filter(Boolean) : undefined,
|
|
209
209
|
likely: check.diagnosis.likely === true ? true : undefined,
|
|
210
210
|
...(isObjectLike(check.diagnosis.rerun) ? { rerun: rerunStep(check.diagnosis.rerun) } : {}) } : null;
|
|
211
|
+
const json_path = typeof check?.json_path === 'string' ? cleanField(check.json_path, secrets) : undefined;
|
|
212
|
+
const html = isObjectLike(check?.html) ? (() => {
|
|
213
|
+
const meta = {};
|
|
214
|
+
if (typeof check.html.kind === 'string' && check.html.kind) meta.kind = cleanField(check.html.kind, secrets);
|
|
215
|
+
if (typeof check.html.attribute === 'string' && check.html.attribute) meta.attribute = cleanField(check.html.attribute, secrets);
|
|
216
|
+
if (isObjectLike(check.html.selector)) {
|
|
217
|
+
const sel = {};
|
|
218
|
+
if (typeof check.html.selector.tag === 'string' && check.html.selector.tag) sel.tag = cleanField(check.html.selector.tag, secrets);
|
|
219
|
+
if (isObjectLike(check.html.selector.attributes)) {
|
|
220
|
+
const attrs = Object.fromEntries(
|
|
221
|
+
Object.entries(check.html.selector.attributes).slice(0, 20)
|
|
222
|
+
.filter(([k, v]) => typeof k === 'string' && k && typeof v === 'string')
|
|
223
|
+
.map(([k, v]) => [cleanField(k, secrets), cleanField(v, secrets)])
|
|
224
|
+
);
|
|
225
|
+
if (Object.keys(attrs).length) sel.attributes = attrs;
|
|
226
|
+
}
|
|
227
|
+
if (Object.keys(sel).length) meta.selector = sel;
|
|
228
|
+
}
|
|
229
|
+
return Object.keys(meta).length ? meta : undefined;
|
|
230
|
+
})() : undefined;
|
|
211
231
|
const ref_target = typeof check?.ref_target === 'string' && check.ref_target ? cleanField(check.ref_target, secrets) : undefined;
|
|
212
232
|
const ref_path = typeof check?.ref_path === 'string' ? cleanField(check.ref_path, secrets) : undefined;
|
|
213
233
|
const ref_json_path = typeof check?.ref_json_path === 'string' ? cleanField(check.ref_json_path, secrets) : undefined;
|
|
234
|
+
const diff_summary = isObjectLike(check?.diff_summary) ? (() => {
|
|
235
|
+
const ds = check.diff_summary;
|
|
236
|
+
const expected_len = nonNegativeInt(ds.expected_len), actual_len = nonNegativeInt(ds.actual_len);
|
|
237
|
+
if (expected_len === undefined || actual_len === undefined) return undefined;
|
|
238
|
+
const out = { expected_len, actual_len };
|
|
239
|
+
if (ds.kind === 'array' || ds.kind === 'string') out.kind = ds.kind;
|
|
240
|
+
if (typeof ds.path === 'string' && ds.path) out.path = cleanField(ds.path, secrets);
|
|
241
|
+
const first_diff_index = nonNegativeInt(ds.first_diff_index);
|
|
242
|
+
const first_diff_offset = nonNegativeInt(ds.first_diff_offset);
|
|
243
|
+
if (first_diff_index !== undefined) {
|
|
244
|
+
out.first_diff_index = first_diff_index;
|
|
245
|
+
const window_start = nonNegativeInt(ds.window_start);
|
|
246
|
+
if (window_start !== undefined) out.window_start = window_start;
|
|
247
|
+
if (Array.isArray(ds.expected_window)) out.expected_window = cleanValues(ds.expected_window.slice(0, 32), secrets);
|
|
248
|
+
if (Array.isArray(ds.actual_window)) out.actual_window = cleanValues(ds.actual_window.slice(0, 32), secrets);
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
if (first_diff_offset !== undefined) {
|
|
252
|
+
out.first_diff_offset = first_diff_offset;
|
|
253
|
+
const excerpt_start = nonNegativeInt(ds.excerpt_start);
|
|
254
|
+
if (excerpt_start !== undefined) out.excerpt_start = excerpt_start;
|
|
255
|
+
if (typeof ds.expected_excerpt === 'string') out.expected_excerpt = cleanValues(ds.expected_excerpt.slice(0, 512), secrets);
|
|
256
|
+
if (typeof ds.actual_excerpt === 'string') out.actual_excerpt = cleanValues(ds.actual_excerpt.slice(0, 512), secrets);
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
})() : undefined;
|
|
214
261
|
const stepIndex = Number.isInteger(index) && index >= 0 ? index : Number.isInteger(check?.step_number) && check.step_number >= 1 ? check.step_number - 1 : undefined;
|
|
215
262
|
return { criterion_id,
|
|
216
263
|
step_id: cleanField(step?.step_id ?? check?.step_id, secrets) || (stepIndex !== undefined ? cleanField(authoredSteps[stepIndex]?.step_id, secrets) : '') || null,
|
|
217
264
|
criterion_text: typeof criterionTexts[criterion_id] === 'string' && criterionTexts[criterion_id].length <= 160 ? cleanField(criterionTexts[criterion_id], secrets) : null,
|
|
218
265
|
target: cleanField(check?.target, secrets), path: cleanField(check?.path, secrets),
|
|
266
|
+
...(json_path !== undefined ? { json_path } : {}),
|
|
267
|
+
...(html !== undefined ? { html } : {}),
|
|
219
268
|
...(ref_target !== undefined ? { op: cleanField(check?.op, secrets), ref_target, ...(ref_path !== undefined ? { ref_path } : {}), ...(ref_json_path !== undefined ? { ref_json_path } : {}) } : {}),
|
|
220
269
|
expected: cleanValues(check?.expected, secrets),
|
|
221
270
|
actual: cleanValues(check?.actual, secrets), passed: check?.passed === true,
|
|
222
|
-
normal_result: step ? Object.prototype.hasOwnProperty.call(step, 'result') && !step.error : false,
|
|
271
|
+
normal_result: step ? Object.prototype.hasOwnProperty.call(step, 'result') && !step.error : false,
|
|
272
|
+
...(diff_summary ? { diff_summary } : {}),
|
|
273
|
+
...(diagnosis ? { diagnosis } : {}) };
|
|
223
274
|
};
|
|
275
|
+
const primarySteps = Array.isArray(report?.samples?.[0]?.steps)
|
|
276
|
+
? report.samples[0].steps
|
|
277
|
+
: Array.isArray(report?.steps) ? report.steps : [];
|
|
278
|
+
const step_details = primarySteps.filter(isObjectLike).map((step, index) => {
|
|
279
|
+
const step_id = cleanField(step.step_id, secrets) || cleanField(authoredSteps[index]?.step_id, secrets) || `step-${index + 1}`;
|
|
280
|
+
const calls = isObjectLike(step.calls) ? {
|
|
281
|
+
...(isObjectLike(step.calls.internal) ? { internal: scrubTokens(step.calls.internal) } : {}),
|
|
282
|
+
...(isObjectLike(step.calls.resources) ? { resources: scrubTokens(step.calls.resources) } : {}),
|
|
283
|
+
} : null;
|
|
284
|
+
const hasCalls = calls && (Object.keys(calls.internal ?? {}).length > 0 || Object.keys(calls.resources ?? {}).length > 0);
|
|
285
|
+
return {
|
|
286
|
+
step_id,
|
|
287
|
+
verdict: typeof step.verdict === 'string' ? cleanField(step.verdict, secrets) : null,
|
|
288
|
+
...(step.error != null ? { error: scrubTokens(step.error) } : {}),
|
|
289
|
+
...(Object.prototype.hasOwnProperty.call(step, 'result') ? { result: scrubTokens(step.result) } : {}),
|
|
290
|
+
...(hasCalls ? { calls } : {}),
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
const rawDraftInterfaces = [result?.draft_interfaces, report?.draft_interfaces, report?.summary?.draft_interfaces]
|
|
294
|
+
.find(list => Array.isArray(list) && list.length > 0);
|
|
295
|
+
const draft_interfaces = rawDraftInterfaces
|
|
296
|
+
? rawDraftInterfaces.map(item => isObjectLike(item)
|
|
297
|
+
? {
|
|
298
|
+
path: typeof item.path === 'string' ? cleanField(item.path, secrets) : null,
|
|
299
|
+
...(typeof item.prose_sha256 === 'string' ? { prose_sha256: cleanField(item.prose_sha256, secrets) } : {}),
|
|
300
|
+
...(typeof item.state === 'string' ? { state: cleanField(item.state, secrets) } : {}),
|
|
301
|
+
}
|
|
302
|
+
: typeof item === 'string' ? { path: cleanField(item, secrets) } : null).filter(item => item?.path)
|
|
303
|
+
: Array.isArray(answer?.draft_prompts) && answer.draft_prompts.length > 0
|
|
304
|
+
? answer.draft_prompts.filter(item => typeof item === 'string' && item).map(path => ({ path: cleanField(path, secrets) }))
|
|
305
|
+
: [];
|
|
224
306
|
const all = sampleSteps.flatMap(({ step, index }) => Array.isArray(step?.checks) ? step.checks.map(check => ({ step, check, index })) : [])
|
|
225
307
|
.map(({ step, check, index }) => projectCheck(check, step, index));
|
|
226
308
|
const sampleFailed = all.filter(check => !check.passed).map(({ passed, ...check }) => check);
|
|
@@ -284,6 +366,8 @@ export function projectAnswer(answer, { origin, secrets = [], steps: authoredSte
|
|
|
284
366
|
time_limit, checks,
|
|
285
367
|
criteria: results.length ? { passed: results.filter(item => item?.status === 'passed').length, total: results.length } : null,
|
|
286
368
|
all_checks: all, failed_checks, refusals,
|
|
369
|
+
...(step_details.length && sampleEvidence !== 'flat' && (outcome.state === 'failed' || failed_checks.length > 0 || primarySteps.some(step => typeof step?.verdict === 'string' || Array.isArray(step?.checks))) ? { step_details } : {}),
|
|
370
|
+
...(draft_interfaces.length ? { draft_interfaces } : {}),
|
|
287
371
|
calls: !incomplete ? usageCalls : 'unknown',
|
|
288
372
|
...tokens,
|
|
289
373
|
...(incomplete ? { known_calls: knownCalls } : {}), unknown_calls: unknownCalls, accounting_complete: !incomplete, requested_model: model ? cleanText(model, secrets) : null,
|
|
@@ -358,20 +442,27 @@ export function tokenUsageOf(answer, { incomplete = false } = {}) {
|
|
|
358
442
|
if (allCurrent && ((tIn !== undefined && tIn !== cIn) || (tCached !== undefined && tCached !== cCached))) return unknownTokens();
|
|
359
443
|
muIn = cIn;
|
|
360
444
|
muCached = cCached;
|
|
361
|
-
if (dispatched.length
|
|
445
|
+
if (dispatched.length === 0 && complete === true) {
|
|
446
|
+
muOut = tOut ?? 0;
|
|
447
|
+
} else if (dispatched.length > 0 && dispatched.every(call => tokenInt(call.output_tokens) !== undefined)) {
|
|
362
448
|
muOut = dispatched.reduce((sum, call) => sum + call.output_tokens, 0);
|
|
449
|
+
} else if (tOut !== undefined) {
|
|
450
|
+
muOut = tOut;
|
|
363
451
|
}
|
|
364
452
|
} else if (complete === true) {
|
|
365
453
|
muIn = tIn ?? 0;
|
|
366
454
|
muCached = tCached ?? 0;
|
|
367
|
-
muOut = tOut;
|
|
455
|
+
muOut = tOut ?? 0;
|
|
368
456
|
}
|
|
369
457
|
} else if (complete === true) {
|
|
370
458
|
if (tIn === undefined || tCached === undefined) return unknownTokens();
|
|
371
459
|
muIn = tIn;
|
|
372
460
|
muCached = tCached;
|
|
373
|
-
muOut = tOut;
|
|
461
|
+
muOut = tOut ?? (tIn === 0 && usage.calls === 0 ? 0 : undefined);
|
|
374
462
|
} else return unknownTokens();
|
|
463
|
+
} else if (['passed', 'failed', 'refused'].includes(answer?.state) && usage.calls === 0
|
|
464
|
+
&& uIn === undefined && uCached === undefined && uOut === undefined) {
|
|
465
|
+
return { input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, cached_input_share: null };
|
|
375
466
|
}
|
|
376
467
|
const input_tokens = muIn ?? uIn ?? 'unknown';
|
|
377
468
|
const cached_input_tokens = muCached ?? uCached ?? 'unknown';
|
|
@@ -435,11 +526,16 @@ function batchTokenUsage(publicRows) {
|
|
|
435
526
|
return { input_tokens, cached_input_tokens, output_tokens, cached_input_share: shareOf(input_tokens, cached_input_tokens), complete };
|
|
436
527
|
}
|
|
437
528
|
|
|
438
|
-
export function renderJson({ batch = null, repo, sourceSha256 = null, coverage, rows, warnings = [], exitCode, summaryLine: line }, ports = {}) {
|
|
529
|
+
export function renderJson({ batch = null, repo, sourceSha256 = null, coverage, rows, warnings = [], exitCode, summaryLine: line, details = false }, ports = {}) {
|
|
439
530
|
rows = [...rows.filter(row=>row.unsent),...rows.filter(row=>!row.unsent)];
|
|
440
531
|
line = line ?? summaryLine(rows, null, ports);
|
|
441
532
|
const perStory = new Map(storyLines(rows, ports).map(([story, text]) => [story, text]));
|
|
442
|
-
const publicRows = rows.map(row => ({
|
|
533
|
+
const publicRows = rows.map(row => ({
|
|
534
|
+
...jsonRow(row),
|
|
535
|
+
...(details && row.step_details?.length ? { step_details: row.step_details } : {}),
|
|
536
|
+
...(details && row.draft_interfaces?.length ? { draft_interfaces: row.draft_interfaces } : {}),
|
|
537
|
+
summary_line: perStory.get(row.story) ?? null,
|
|
538
|
+
}));
|
|
443
539
|
const diagnostic = rows.filter(row=>row.diagnostic_subset === true);
|
|
444
540
|
return { batch, repo, ...(diagnostic.length ? {diagnostic_subset:true,selected_steps:[...new Set(diagnostic.flatMap(row=>row.selected_steps ?? []))]} : {}), ...(coverage ? { coverage } : {}), source_sha256: sourceSha256, exit_code: exitCode, summary_line: line, draft: rows.some(row => row.draft),
|
|
445
541
|
token_usage: batchTokenUsage(publicRows), rows: publicRows, warnings };
|
|
@@ -513,18 +609,110 @@ const plainLine = (text, secrets) => secrets.reduce((value, secret) => secret ?
|
|
|
513
609
|
const oneLine = value => typeof value !== 'string' || !/\n(?!$)/.test(value);
|
|
514
610
|
const valueLines = value => typeof value === 'string' ? value.replace(/\n$/, '').split('\n') : (JSON.stringify(value, null, 2) ?? 'nothing').split('\n');
|
|
515
611
|
|
|
612
|
+
const formatHtmlCheckLabel = (html, secrets) => {
|
|
613
|
+
if (!isObjectLike(html)) return '';
|
|
614
|
+
const tag = typeof html.selector?.tag === 'string' ? cleanField(html.selector.tag, secrets) : '';
|
|
615
|
+
const attrs = isObjectLike(html.selector?.attributes)
|
|
616
|
+
? Object.entries(html.selector.attributes).slice(0, 6).map(([k, v]) => `[${cleanField(k, secrets)}=${JSON.stringify(cleanField(v, secrets))}]`).join('')
|
|
617
|
+
: '';
|
|
618
|
+
const sel = `${tag}${attrs}`;
|
|
619
|
+
const kind = typeof html.kind === 'string' ? cleanField(html.kind, secrets) : '';
|
|
620
|
+
const attr = typeof html.attribute === 'string' ? `@${cleanField(html.attribute, secrets)}` : '';
|
|
621
|
+
const desc = [sel, kind && `${kind}${attr}`].filter(Boolean).join(' ');
|
|
622
|
+
return desc ? `(html ${desc})` : '';
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
const boundedPreview = (value, secrets, limit = 400) => {
|
|
626
|
+
const raw = typeof value === 'string' ? cleanField(value, secrets) : shown(value, secrets);
|
|
627
|
+
return raw.length <= limit ? raw : `${raw.slice(0, limit - 1)}…`;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
const formatStepCalls = (calls, secrets) => {
|
|
631
|
+
if (!isObjectLike(calls)) return null;
|
|
632
|
+
const parts = [];
|
|
633
|
+
for (const [group, label] of [['internal', 'internal'], ['resources', 'resources']]) {
|
|
634
|
+
if (!isObjectLike(calls[group])) continue;
|
|
635
|
+
const entries = Object.entries(calls[group]);
|
|
636
|
+
if (!entries.length) continue;
|
|
637
|
+
const shownEntries = entries.slice(0, 12).map(([name, count]) => `${cleanField(name, secrets)}=${count}`);
|
|
638
|
+
if (entries.length > 12) shownEntries.push(`… (+${entries.length - 12} more)`);
|
|
639
|
+
parts.push(`${label}: ${shownEntries.join(', ')}`);
|
|
640
|
+
}
|
|
641
|
+
return parts.length ? parts.join('; ') : null;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
function stepContextLines(step, secrets, { indent = ' ', includeVerdict = false } = {}) {
|
|
645
|
+
if (!isObjectLike(step)) return [];
|
|
646
|
+
const body = [];
|
|
647
|
+
if (step.error != null) body.push(`${indent} Error: ${boundedPreview(step.error, secrets, 400)}`);
|
|
648
|
+
if (Object.prototype.hasOwnProperty.call(step, 'result') && step.result !== undefined) {
|
|
649
|
+
if (isObjectLike(step.result)) {
|
|
650
|
+
const hasCliOrCode = ['exit_code', 'exitCode', 'code', 'stdout', 'stderr'].some(key => Object.hasOwn(step.result, key));
|
|
651
|
+
if (hasCliOrCode) {
|
|
652
|
+
const meta = [];
|
|
653
|
+
for (const key of ['exit_code', 'exitCode', 'code']) {
|
|
654
|
+
if (Object.hasOwn(step.result, key) && step.result[key] !== undefined) meta.push(`${key}=${boundedPreview(step.result[key], secrets, 120)}`);
|
|
655
|
+
}
|
|
656
|
+
if (meta.length) body.push(`${indent} Output: ${meta.join(' · ')}`);
|
|
657
|
+
if (typeof step.result.stdout === 'string' && step.result.stdout.trim()) body.push(`${indent} stdout: ${boundedPreview(step.result.stdout, secrets, 500)}`);
|
|
658
|
+
else if (step.result.stdout !== undefined && typeof step.result.stdout !== 'string') body.push(`${indent} stdout: ${boundedPreview(step.result.stdout, secrets, 500)}`);
|
|
659
|
+
if (typeof step.result.stderr === 'string' && step.result.stderr.trim()) body.push(`${indent} stderr: ${boundedPreview(step.result.stderr, secrets, 300)}`);
|
|
660
|
+
else if (step.result.stderr !== undefined && typeof step.result.stderr !== 'string') body.push(`${indent} stderr: ${boundedPreview(step.result.stderr, secrets, 300)}`);
|
|
661
|
+
} else {
|
|
662
|
+
body.push(`${indent} Result: ${boundedPreview(step.result, secrets, 500)}`);
|
|
663
|
+
}
|
|
664
|
+
} else {
|
|
665
|
+
body.push(`${indent} Result: ${boundedPreview(step.result, secrets, 500)}`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const callsText = formatStepCalls(step.calls, secrets);
|
|
669
|
+
if (callsText) body.push(`${indent} Calls: ${callsText}`);
|
|
670
|
+
if (!body.length && !includeVerdict) return [];
|
|
671
|
+
const label = cleanField(step.step_id || 'unnamed', secrets);
|
|
672
|
+
const verdict = includeVerdict && step.verdict ? ` (${cleanField(step.verdict, secrets)})` : '';
|
|
673
|
+
return [`${indent}Step ${label}${verdict}:`, ...body];
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function diffSummaryLines(summary, secrets) {
|
|
677
|
+
if (!isObjectLike(summary)) return [];
|
|
678
|
+
const expLen = summary.expected_len, actLen = summary.actual_len;
|
|
679
|
+
if (!Number.isSafeInteger(expLen) || !Number.isSafeInteger(actLen) || expLen < 0 || actLen < 0) return [];
|
|
680
|
+
const at = typeof summary.path === 'string' && summary.path ? ` at ${cleanField(summary.path, secrets)}` : '';
|
|
681
|
+
if (Number.isSafeInteger(summary.first_diff_index) && summary.first_diff_index >= 0) {
|
|
682
|
+
const lines = [` Diff${at}: array len expected ${expLen}, got ${actLen}; first difference at index ${summary.first_diff_index}`];
|
|
683
|
+
if (Array.isArray(summary.expected_window) && Array.isArray(summary.actual_window)) {
|
|
684
|
+
const start = Number.isSafeInteger(summary.window_start) && summary.window_start >= 0 ? summary.window_start : null;
|
|
685
|
+
const maxWin = Math.max(summary.expected_window.length, summary.actual_window.length);
|
|
686
|
+
const span = start !== null && maxWin > 0 ? ` [${start}..${start + maxWin - 1}]` : '';
|
|
687
|
+
lines.push(` Expected${span}: ${shown(summary.expected_window, secrets)}`);
|
|
688
|
+
lines.push(` Got${span}: ${shown(summary.actual_window, secrets)}`);
|
|
689
|
+
}
|
|
690
|
+
return lines;
|
|
691
|
+
}
|
|
692
|
+
if (Number.isSafeInteger(summary.first_diff_offset) && summary.first_diff_offset >= 0) {
|
|
693
|
+
const lines = [` Diff${at}: string len expected ${expLen}, got ${actLen}; first difference at offset ${summary.first_diff_offset}`];
|
|
694
|
+
if (typeof summary.expected_excerpt === 'string') lines.push(` Expected excerpt: ${shown(summary.expected_excerpt, secrets)}`);
|
|
695
|
+
if (typeof summary.actual_excerpt === 'string') lines.push(` Got excerpt: ${shown(summary.actual_excerpt, secrets)}`);
|
|
696
|
+
return lines;
|
|
697
|
+
}
|
|
698
|
+
return [];
|
|
699
|
+
}
|
|
700
|
+
|
|
516
701
|
// The check line: one line when both values fit, else the check and a block for each value, never cut inside a line.
|
|
517
702
|
function checkLines(check, secrets) {
|
|
518
|
-
const
|
|
703
|
+
const jsonPath = typeof check.json_path === 'string' ? ` (${check.json_path || '/'})` : '';
|
|
704
|
+
const htmlDesc = isObjectLike(check.html) ? formatHtmlCheckLabel(check.html, secrets) : '';
|
|
705
|
+
const head = `${check.criterion_id}${check.step_id ? ` step ${check.step_id}` : ''} ${check.target} ${check.path}${jsonPath}${htmlDesc ? ` ${htmlDesc}` : ''}`;
|
|
519
706
|
const noError = check.target === 'error' && check.actual && typeof check.actual === 'object' && !Array.isArray(check.actual)
|
|
520
707
|
&& check.actual.missing === true && Object.keys(check.actual).length === 1
|
|
521
708
|
&& (check.normal_result === true || ['no-error', 'needs-tool'].includes(check.diagnosis?.kind));
|
|
522
709
|
const actualValue = noError ? 'no error (a normal result)' : check.actual, actualDisplay = noError ? actualValue : shown(actualValue, secrets);
|
|
523
710
|
const criterion = check.criterion_text ? [` Criterion: ${plainLine(check.criterion_text, secrets)}`] : [];
|
|
711
|
+
const diffLines = diffSummaryLines(check.diff_summary, secrets);
|
|
524
712
|
const refLabel = check.ref_target && check.ref_path !== undefined
|
|
525
713
|
? `${check.op ? `${check.op} ` : ''}${check.ref_target} ${check.ref_path || '/'}${check.ref_json_path ? ` (${check.ref_json_path})` : ''}` : null;
|
|
526
714
|
const fits = [check.expected, check.actual].every(value => oneLine(value) && shown(value, secrets).length <= 80);
|
|
527
|
-
if (fits) return [`${head} expected ${refLabel ? `${refLabel} (${shown(check.expected, secrets)})` : shown(check.expected, secrets)}, got ${actualDisplay}`, ...criterion];
|
|
715
|
+
if (fits) return [`${head} expected ${refLabel ? `${refLabel} (${shown(check.expected, secrets)})` : shown(check.expected, secrets)}, got ${actualDisplay}`, ...criterion, ...diffLines];
|
|
528
716
|
const expected = valueLines(check.expected), actual = valueLines(actualValue);
|
|
529
717
|
// Start 2 lines before the first line where two strings differ, when it is past the first 20.
|
|
530
718
|
const differ = typeof check.expected === 'string' && typeof check.actual === 'string' ? expected.findIndex((text, index) => text !== actual[index]) : -1;
|
|
@@ -533,7 +721,7 @@ function checkLines(check, secrets) {
|
|
|
533
721
|
...lines.slice(from, from + VALUE_LINES).map(text => ` ${plainLine(text, secrets)}`),
|
|
534
722
|
...(lines.length > from + VALUE_LINES ? [` … ${lines.length - from - VALUE_LINES} more lines in the report`] : []),
|
|
535
723
|
...(typeof value === 'string' && value.endsWith('\n') ? [' (ends with a line break)'] : [])];
|
|
536
|
-
return [head, ...criterion, ...block(refLabel ? `expected (${refLabel})` : 'expected', check.expected, expected), ...block('got', check.actual, actual)];
|
|
724
|
+
return [head, ...criterion, ...diffLines, ...block(refLabel ? `expected (${refLabel})` : 'expected', check.expected, expected), ...block('got', check.actual, actual)];
|
|
537
725
|
}
|
|
538
726
|
// With a plain reason (#379): the reason, where and the fix; an AI service failure is not a problem in the test.
|
|
539
727
|
function refusalLines(item, serverNext = false) {
|
|
@@ -598,7 +786,7 @@ function localRefusals(rows, secrets) {
|
|
|
598
786
|
}
|
|
599
787
|
|
|
600
788
|
// The terminal result of a batch (stdout).
|
|
601
|
-
export function renderText({ batch, rows, coverage, warnings = [], details = false, timeoutMin = null, interrupted = false, reading = false, exitCode, secrets = [], recovery, now = Date.now(), noFailed = false }, ports = {}) {
|
|
789
|
+
export function renderText({ batch, rows, coverage, warnings = [], details = false, timeoutMin = null, batchTimeoutMin = null, interrupted = false, reading = false, exitCode, secrets = [], recovery, now = Date.now(), noFailed = false }, ports = {}) {
|
|
602
790
|
const out = [];
|
|
603
791
|
rows = [...rows.filter(row=>row.unsent),...rows.filter(row=>!row.unsent)];
|
|
604
792
|
out.push(...localRefusals(rows.filter(row=>row.unsent),secrets));
|
|
@@ -630,6 +818,14 @@ export function renderText({ batch, rows, coverage, warnings = [], details = fal
|
|
|
630
818
|
const key = check.step_id ?? '', line = rerunByStep.get(key);
|
|
631
819
|
if (line) { lines.push(line); rerunByStep.delete(key); }
|
|
632
820
|
}
|
|
821
|
+
if (Array.isArray(row.step_details) && row.step_details.length) {
|
|
822
|
+
const failedStepIds = [...new Set(failed.map(check => check.step_id).filter(Boolean))];
|
|
823
|
+
const stepMap = new Map(row.step_details.map(step => [step.step_id, step]));
|
|
824
|
+
for (const stepId of failedStepIds) {
|
|
825
|
+
const ctx = stepContextLines(stepMap.get(stepId), secrets, { indent: ' ' });
|
|
826
|
+
if (ctx.length) lines.push(...ctx);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
633
829
|
if (reruns.some(item => item.key === null)) lines.push(reruns.find(item => item.key === null).line);
|
|
634
830
|
if (fullFailure) lines.push(...(row.warnings ?? []).map(text => ` ${text}`));
|
|
635
831
|
const diagnosed = failed.some(check => check.diagnosis?.why || check.diagnosis?.next_step);
|
|
@@ -656,8 +852,10 @@ export function renderText({ batch, rows, coverage, warnings = [], details = fal
|
|
|
656
852
|
out.push(`NOT RUN ${row.title} (${row.test})${explanation ? `: ${explanation}` : ''}${note?.code ? ` (${note.code})` : ''}`, ...serverAdvice(row, secrets));
|
|
657
853
|
}
|
|
658
854
|
for (const row of rows.filter(row => OPEN_STATES.has(row.state))) {
|
|
659
|
-
const
|
|
660
|
-
|
|
855
|
+
const noteText = row.note?.message ?? row.reason?.message ?? '';
|
|
856
|
+
const effectiveMin = /--batch-timeout/.test(noteText) && batchTimeoutMin != null ? batchTimeoutMin : timeoutMin ?? batchTimeoutMin;
|
|
857
|
+
const limit = effectiveMin == null ? '' : Number.isInteger(effectiveMin) ? `${effectiveMin} min` : `${Math.round(effectiveMin * 60)} s`;
|
|
858
|
+
out.push(`STILL RUNNING${reading || (!interrupted && effectiveMin == null) ? '' : interrupted ? ' when pdd stopped reading' : ` after ${limit}`}: ${row.title}. Do not send it again.${row.note?.code === 'timeout-flag' || row.reason?.code === 'timeout-flag' ? ` ${row.note?.message ?? row.reason.message}` : ''}`);
|
|
661
859
|
}
|
|
662
860
|
for (const row of rows.filter(row => ['unknown', 'partial'].includes(row.state) && !row.provider && !row.time_limit)) {
|
|
663
861
|
out.push(`UNKNOWN ${row.title}: the run may have executed. Its result is unknown.`, ...((row.lost || row.final) && row.why ? [` ${row.why}`, ...(row.next_step ? [` Next: ${cleanText(row.next_step, secrets)}`] : [])] : serverAdvice(row, secrets)));
|
|
@@ -681,10 +879,18 @@ export function renderText({ batch, rows, coverage, warnings = [], details = fal
|
|
|
681
879
|
}
|
|
682
880
|
if (!evidence.complete) out.push('Sample comparison incomplete; agreement is unknown.');
|
|
683
881
|
}
|
|
684
|
-
if (details) for (const row of rows.filter(row => row.all_checks?.length || !row.cached && formatPromptCacheTokens(row))) {
|
|
882
|
+
if (details) for (const row of rows.filter(row => row.all_checks?.length || row.step_details?.length || row.draft_interfaces?.length || !row.cached && formatPromptCacheTokens(row))) {
|
|
685
883
|
const tokenText = !row.cached ? formatPromptCacheTokens(row) : null;
|
|
884
|
+
const draftLines = Array.isArray(row.draft_interfaces) && row.draft_interfaces.length
|
|
885
|
+
? [' Draft interfaces:', ...row.draft_interfaces.map(item => ` ${cleanField(item.path, secrets)}${item.prose_sha256 ? ` (${cleanField(item.prose_sha256, secrets).slice(0, 12)})` : ''}`)]
|
|
886
|
+
: [];
|
|
887
|
+
const stepLines = Array.isArray(row.step_details) && row.step_details.length
|
|
888
|
+
? [' Steps:', ...row.step_details.flatMap(step => stepContextLines(step, secrets, { indent: ' ', includeVerdict: true }))]
|
|
889
|
+
: [];
|
|
686
890
|
out.push(`Checks for ${row.title} (${row.test}):`,
|
|
687
891
|
...(tokenText ? [` Tokens: ${tokenText}`] : []),
|
|
892
|
+
...draftLines,
|
|
893
|
+
...stepLines,
|
|
688
894
|
...[...(row.all_checks ?? [])].sort((a, b) => a.passed - b.passed).flatMap(check => checkLines(check, secrets)
|
|
689
895
|
.map((text, index) => index ? ` ${text}` : ` ${check.passed ? 'passed' : 'failed'} ${text}`)));
|
|
690
896
|
}
|