@promptdriven/runtime-client 1.1.1 → 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 +10 -0
- package/src/runtime/product-composition.mjs +6 -4
- package/src/runtime/runtime-bindings.mjs +4 -5
- package/src/runtime/runtime-check-plan.mjs +7 -3
- package/src/runtime/runtime-client.mjs +1485 -139
- package/src/runtime/runtime-output.mjs +63 -6
- package/src/runtime/runtime-preflight.mjs +11 -3
- package/src/runtime/try-mcp.mjs +8 -1
|
@@ -231,6 +231,33 @@ export function projectAnswer(answer, { origin, secrets = [], steps: authoredSte
|
|
|
231
231
|
const ref_target = typeof check?.ref_target === 'string' && check.ref_target ? cleanField(check.ref_target, secrets) : undefined;
|
|
232
232
|
const ref_path = typeof check?.ref_path === 'string' ? cleanField(check.ref_path, secrets) : undefined;
|
|
233
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;
|
|
234
261
|
const stepIndex = Number.isInteger(index) && index >= 0 ? index : Number.isInteger(check?.step_number) && check.step_number >= 1 ? check.step_number - 1 : undefined;
|
|
235
262
|
return { criterion_id,
|
|
236
263
|
step_id: cleanField(step?.step_id ?? check?.step_id, secrets) || (stepIndex !== undefined ? cleanField(authoredSteps[stepIndex]?.step_id, secrets) : '') || null,
|
|
@@ -241,7 +268,9 @@ export function projectAnswer(answer, { origin, secrets = [], steps: authoredSte
|
|
|
241
268
|
...(ref_target !== undefined ? { op: cleanField(check?.op, secrets), ref_target, ...(ref_path !== undefined ? { ref_path } : {}), ...(ref_json_path !== undefined ? { ref_json_path } : {}) } : {}),
|
|
242
269
|
expected: cleanValues(check?.expected, secrets),
|
|
243
270
|
actual: cleanValues(check?.actual, secrets), passed: check?.passed === true,
|
|
244
|
-
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 } : {}) };
|
|
245
274
|
};
|
|
246
275
|
const primarySteps = Array.isArray(report?.samples?.[0]?.steps)
|
|
247
276
|
? report.samples[0].steps
|
|
@@ -644,6 +673,31 @@ function stepContextLines(step, secrets, { indent = ' ', includeVerdict = false
|
|
|
644
673
|
return [`${indent}Step ${label}${verdict}:`, ...body];
|
|
645
674
|
}
|
|
646
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
|
+
|
|
647
701
|
// The check line: one line when both values fit, else the check and a block for each value, never cut inside a line.
|
|
648
702
|
function checkLines(check, secrets) {
|
|
649
703
|
const jsonPath = typeof check.json_path === 'string' ? ` (${check.json_path || '/'})` : '';
|
|
@@ -654,10 +708,11 @@ function checkLines(check, secrets) {
|
|
|
654
708
|
&& (check.normal_result === true || ['no-error', 'needs-tool'].includes(check.diagnosis?.kind));
|
|
655
709
|
const actualValue = noError ? 'no error (a normal result)' : check.actual, actualDisplay = noError ? actualValue : shown(actualValue, secrets);
|
|
656
710
|
const criterion = check.criterion_text ? [` Criterion: ${plainLine(check.criterion_text, secrets)}`] : [];
|
|
711
|
+
const diffLines = diffSummaryLines(check.diff_summary, secrets);
|
|
657
712
|
const refLabel = check.ref_target && check.ref_path !== undefined
|
|
658
713
|
? `${check.op ? `${check.op} ` : ''}${check.ref_target} ${check.ref_path || '/'}${check.ref_json_path ? ` (${check.ref_json_path})` : ''}` : null;
|
|
659
714
|
const fits = [check.expected, check.actual].every(value => oneLine(value) && shown(value, secrets).length <= 80);
|
|
660
|
-
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];
|
|
661
716
|
const expected = valueLines(check.expected), actual = valueLines(actualValue);
|
|
662
717
|
// Start 2 lines before the first line where two strings differ, when it is past the first 20.
|
|
663
718
|
const differ = typeof check.expected === 'string' && typeof check.actual === 'string' ? expected.findIndex((text, index) => text !== actual[index]) : -1;
|
|
@@ -666,7 +721,7 @@ function checkLines(check, secrets) {
|
|
|
666
721
|
...lines.slice(from, from + VALUE_LINES).map(text => ` ${plainLine(text, secrets)}`),
|
|
667
722
|
...(lines.length > from + VALUE_LINES ? [` … ${lines.length - from - VALUE_LINES} more lines in the report`] : []),
|
|
668
723
|
...(typeof value === 'string' && value.endsWith('\n') ? [' (ends with a line break)'] : [])];
|
|
669
|
-
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)];
|
|
670
725
|
}
|
|
671
726
|
// With a plain reason (#379): the reason, where and the fix; an AI service failure is not a problem in the test.
|
|
672
727
|
function refusalLines(item, serverNext = false) {
|
|
@@ -731,7 +786,7 @@ function localRefusals(rows, secrets) {
|
|
|
731
786
|
}
|
|
732
787
|
|
|
733
788
|
// The terminal result of a batch (stdout).
|
|
734
|
-
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 = {}) {
|
|
735
790
|
const out = [];
|
|
736
791
|
rows = [...rows.filter(row=>row.unsent),...rows.filter(row=>!row.unsent)];
|
|
737
792
|
out.push(...localRefusals(rows.filter(row=>row.unsent),secrets));
|
|
@@ -797,8 +852,10 @@ export function renderText({ batch, rows, coverage, warnings = [], details = fal
|
|
|
797
852
|
out.push(`NOT RUN ${row.title} (${row.test})${explanation ? `: ${explanation}` : ''}${note?.code ? ` (${note.code})` : ''}`, ...serverAdvice(row, secrets));
|
|
798
853
|
}
|
|
799
854
|
for (const row of rows.filter(row => OPEN_STATES.has(row.state))) {
|
|
800
|
-
const
|
|
801
|
-
|
|
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}` : ''}`);
|
|
802
859
|
}
|
|
803
860
|
for (const row of rows.filter(row => ['unknown', 'partial'].includes(row.state) && !row.provider && !row.time_limit)) {
|
|
804
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)));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated from prompts/cli/runtime-preflight.prompt.md (sha256:
|
|
1
|
+
// Generated from prompts/cli/runtime-preflight.prompt.md (sha256: 44554fdc6a301396b96768844239cb202714e7ea65f501452c020be929df06ca).
|
|
2
2
|
import { markdownLinks, markdownDefinitions, markdownSectionText } from './runtime-markdown.mjs';
|
|
3
3
|
import { buildBindingPlan, runtimeBoundary } from './runtime-binding-plan.mjs';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
@@ -940,7 +940,10 @@ export function runtimeCoverage({ root, paths = discoveryPromptPaths(root), allo
|
|
|
940
940
|
for (const path of paths) {
|
|
941
941
|
try {
|
|
942
942
|
const prompt = readPrompt(root, visible, path);
|
|
943
|
-
if (prompt.error === 'interface-missing')
|
|
943
|
+
if (prompt.error === 'interface-missing') {
|
|
944
|
+
if (allowMissingInterfaces && typeof prompt.text === 'string' && prompt.text.trim()) checkable++;
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
944
947
|
if (promptRefusal(prompt, 'interface') || interfaceSchemaProblems(prompt.interface).length) continue;
|
|
945
948
|
if (prompt.interface.kind === 'native-only') native_only++;
|
|
946
949
|
else if (Array.isArray(prompt.interface.entries) && prompt.interface.entries.length && prompt.interface.entries.every(entry => typeof entry?.operation === 'string' && entry.operation.trim() && entry.input_schema && entry.result_schema)) checkable++;
|
|
@@ -1169,10 +1172,15 @@ function criterionPlan(doc, story) {
|
|
|
1169
1172
|
const not_checked = criteria.filter(item => !exact.has(item.id)).map(item => ({criterion_id:item.id,text:item.text,
|
|
1170
1173
|
reason:assigned.has(item.id) ? 'no exact check is assigned' : 'no check is assigned'}));
|
|
1171
1174
|
const unmatched = [...doc.criteria.map(item => item.text)], used = new Set(criteria.map(item => item.id));
|
|
1175
|
+
const useContentIds = typeof doc.story_path === 'string' && doc.story_path.length > 0
|
|
1176
|
+
&& doc.criteria.length > 0 && doc.criteria.every(item => item.id.startsWith('ac-sha256-'));
|
|
1172
1177
|
for (const [index, text] of story.entries()) {
|
|
1173
1178
|
const at = unmatched.indexOf(text);
|
|
1174
1179
|
if (at >= 0) { unmatched.splice(at, 1); continue; }
|
|
1175
|
-
const base =
|
|
1180
|
+
const base = useContentIds
|
|
1181
|
+
? `ac-sha256-${sha256(Buffer.from(`${doc.story_path}\0${text}`, 'utf8')).slice(0, 48)}`
|
|
1182
|
+
: `ac-${index + 1}`;
|
|
1183
|
+
let id = base;
|
|
1176
1184
|
for (let n = 2; used.has(id); n++) id = `${base}-${n}`;
|
|
1177
1185
|
used.add(id); criteria.push({id,text});
|
|
1178
1186
|
not_checked.push({criterion_id:id,text,reason:'the test has no criterion for this Story item'});
|
package/src/runtime/try-mcp.mjs
CHANGED
|
@@ -120,16 +120,23 @@ export function createTryTools({ cwd = process.cwd(), words = [], env } = {}, po
|
|
|
120
120
|
throw error;
|
|
121
121
|
}
|
|
122
122
|
const isProgramError = answer.error !== undefined && answer.error !== null;
|
|
123
|
+
const recordingAvailable = typeof answer.recordingAvailable === 'boolean' ? answer.recordingAvailable
|
|
124
|
+
: typeof answer.recording_available === 'boolean' ? answer.recording_available : undefined;
|
|
123
125
|
const run = { id: answer.id, ...(answer.actionId !== undefined ? { action_id: answer.actionId } : {}),
|
|
124
126
|
...(answer.replayed !== undefined ? { replayed: Boolean(answer.replayed) } : {}),
|
|
125
127
|
entry: `${entry.entry_path}#${entry.operation}`, input,
|
|
126
128
|
...(answer.inputWorld !== undefined ? { world_before: answer.inputWorld } : {}),
|
|
127
129
|
...(isProgramError ? { error: answer.error } : { result: answer.result, error: null }),
|
|
128
|
-
...(answer.world !== undefined ? { world_after: answer.world } : {}),
|
|
130
|
+
...(answer.world !== undefined ? { world_after: answer.world } : {}),
|
|
131
|
+
...(object(answer.calls) ? { calls: answer.calls } : {}),
|
|
132
|
+
...(recordingAvailable !== undefined ? { recording_available: recordingAvailable } : {}),
|
|
133
|
+
lossless: true };
|
|
129
134
|
runs.push(run);
|
|
130
135
|
return { run_id: run.id, action_id: answer.actionId ?? null, replayed: Boolean(answer.replayed),
|
|
131
136
|
result: isProgramError ? null : run.result, error: isProgramError ? run.error : null,
|
|
132
137
|
data_before: run.world_before ?? null, data_after: run.world_after ?? null,
|
|
138
|
+
...(run.calls !== undefined ? { calls: run.calls } : {}),
|
|
139
|
+
...(run.recording_available !== undefined ? { recording_available: run.recording_available } : {}),
|
|
133
140
|
...(answer.inputWorld === undefined || answer.world === undefined ? { data_warning: 'The interpreter did not supply both run world snapshots; world checks may be unavailable.' } : {}),
|
|
134
141
|
usage: answer.usage ?? null, seconds: Math.round((Date.now() - started) / 100) / 10 };
|
|
135
142
|
}
|