Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions prompts/cli/workflow-replay.prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ identity truncation. Distinct values must remain visibly distinct. Use JSON Unic
units outside printable ASCII, including invisible and bidi characters. Escape Markdown, HTML, controls and
path separators so outer body cleaning cannot collapse different paths or damage quoted URLs.
Escape pdd-workflow: and pdd-product: as in the runner's inert summary text; they cannot become ownership markers.
The Markdown, HTML and separator escaping is for the PR body only. With option `terminal` true, as in the
runner's command output, warnings keep the JSON form, the Unicode escapes and the inert markers, and show
paths and links as plain text (`"tests/add.json"`, not `tests/add.json`).
Missing is distinct from a literal string or null. The default report shows all warnings. Optional
maxCharacters is a display budget for the entire replay section: retain its status, counts and trust
boundary, show the longest prefix of whole warning items that fits, then name the exact omitted count
Expand Down Expand Up @@ -383,8 +386,8 @@ A present base `pdd.json` must be a regular readable blob within the 10 MiB read

```json
{
"status": "approved",
"prose_sha256": "1e33b05732de6ee39ded88d14250981f25af96387498a72f0d73550d05aee9ed",
"status": "draft",
"prose_sha256": "08c72da17e3a491341065a13f7121265bcb2a6a66e3bfeddb7d74c6f012f9b4f",
"entries": [
{
"operation": "adoptReplayCorpus",
Expand Down
12 changes: 8 additions & 4 deletions src/workflow-replay.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from prompts/cli/workflow-replay.prompt.md (sha256: f9778f1a6b64cb48ef33e4e5a781d4e2ffcc1e280ae5f7c3e3dc573d8e242908).
// Generated from prompts/cli/workflow-replay.prompt.md (sha256: 8b0758bc28dcdbb53d8af6a54ba63a0b0bc584dab532c6fc0b99df38aa98b9a9).
import { execFileSync } from 'node:child_process';
import { tmpdir } from 'node:os';
import { createHash } from 'node:crypto';
Expand Down Expand Up @@ -461,7 +461,10 @@ function valueChanges(before, after, path = '') {
const changeValue=value=>value===undefined ? '(missing)' : stringifyScenario(value);
// JSON escaping keeps identities and values distinct. Entities display complete
// separators without exposing URLs or matching the outer body's path cleaner.
const renderValue=value=>inertMarkers(String(value).replace(/[^\x20-\x7e]/g,char=>'\\u'+char.charCodeAt(0).toString(16).padStart(4,'0')))
// The terminal keeps only the JSON form, Unicode escapes and inert markers, so paths and links read plainly (#2953).
const plainValue=value=>inertMarkers(String(value).replace(/[^\x20-\x7e]/g,char=>'\\u'+char.charCodeAt(0).toString(16).padStart(4,'0')));
const plainIdentity=value=>plainValue(JSON.stringify(String(value)).slice(1,-1));
const renderValue=value=>plainValue(value)
.replace(/[\\`*_[\]()|]/g,'\\$&').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
const reviewText=value=>renderValue(value).replaceAll('/','&#47;');
const reviewIdentity=value=>reviewText(JSON.stringify(String(value)).slice(1,-1));
Expand Down Expand Up @@ -654,13 +657,14 @@ export function formatFormalEvidence(value, rules) {
if (shown.notNeeded) return `Formal check: not needed (no Rules to check in the Story).${formal.status === 'missing' ? '' : ` The formal block is not accepted: ${shown.words} — ${shown.cause}.`}`;
return `Formal check (agent reported): ${shown.words} — ${shown.detail}. Repair: ${shown.repair}.${shown.note ? ` ${shown.note}` : ''}`;
}
export function formatReplayEvidence(result, {maxCharacters=Infinity, rules} = {}) {
export function formatReplayEvidence(result, {maxCharacters=Infinity, rules, terminal=false} = {}) {
const counts=result.counts??emptyCounts(), emptyPass=result.outcome==='pass' && !(Number.isSafeInteger(counts.total) && counts.total>0);
const label=String(emptyPass?'blocked':result.outcome).replace('_',' ').toUpperCase();
const failedFormal=formalStatus(result.formal).status==='recorded' && result.formal.result==='failed';
const head=[ ...(counts.fail ? [`✗ ${counts.fail} replay assertions fail`] : []), ...(failedFormal ? ['✗ Formal check failed (counterexample in replay-evidence.json).'] : []),
`Code replay: ${label} — ${render(emptyPass?'Replay cannot pass with zero checks.':result.reason)}`,`${counts.total} checks: ${counts.pass} passed, ${counts.fail} failed, ${counts.blocked} blocked, ${counts.not_replayed} not replayed.`];
const warnings=(result.warnings??[]).map(w=>`warning: Saved test values changed: ${reviewIdentity(w.vector)} ${w.reason ? reviewIdentity(w.reason) : `${reviewIdentity(w.path)} ${reviewText(typeof w.exact?.before==='string'?w.exact.before:changeValue(w.before))} -> ${reviewText(typeof w.exact?.after==='string'?w.exact.after:changeValue(w.after))}`}`);
const [shownIdentity,shownText]=terminal ? [plainIdentity,plainValue] : [reviewIdentity,reviewText];
const warnings=(result.warnings??[]).map(w=>`warning: Saved test values changed: ${shownIdentity(w.vector)} ${w.reason ? shownIdentity(w.reason) : `${shownIdentity(w.path)} ${shownText(typeof w.exact?.before==='string'?w.exact.before:changeValue(w.before))} -> ${shownText(typeof w.exact?.after==='string'?w.exact.after:changeValue(w.after))}`}`);
const tail=[...(warnings.length ? ['Saved-value changes are advisory; the checker or person decides.'] : []),
...(result.adoption ? [`Anchor adopted from ${render(result.adoption.repository)}@${render(result.adoption.commit)}; approval reference ${render(result.adoption.reference)} by ${render(result.adoption.asserted_by)}; external-assertion-unverified`] : []),
...(result.anchor ? [anchorLine(result.anchor)] : []),
Expand Down
4 changes: 2 additions & 2 deletions src/workflow-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ async function finishPr(run, area, step, p, lines, packageRoot = PACKAGE_ROOT) {
latest.metricsObservations=[...(latest.metricsObservations ?? []),{type:'milestone',at:new Date(p.now()).toISOString(),data:{stage:'implementation-ready',pr:pr.number,head:pr.publishedHeadSha}}];
}
};
if(area.replay_evidence===REPLAY_POLICY)lines.push(formatReplayEvidence(run.replayEvidence,{rules:await rulesToCheck(run,p)}));
if(area.replay_evidence===REPLAY_POLICY)lines.push(formatReplayEvidence(run.replayEvidence,{rules:await rulesToCheck(run,p),terminal:true}));
if (area.then === 'ask-code') {
// New commits on an open PR 1 keep the question's time, so a yes the person already gave still counts
// (a change request with pdd workflow changes moves it).
Expand Down Expand Up @@ -3215,7 +3215,7 @@ async function stepDoneCommand({ step, summary, skipped, noPublish = false, cwd,
const hasRuntime=runtimeLines(record.summary).length>0;
if(hasRuntime)record.source={kind:'git-content-v1',sha256:gitFingerprint(run.root)};
const replay=area.replay_evidence===REPLAY_POLICY && (noPublish || run.localPublication?.area === area.name || area.steps.some(item=>item!==step&&!run.done[item]) || area.gate!=='pr' || area.before==='approve'&&!prOf(run,area.name))?await currentReplayEvidence(run,p):null;
if(replay){record.replayEvidence=replay;lines.push(formatReplayEvidence(replay,{rules:await rulesToCheck(run,p,record.summary)}));}
if(replay){record.replayEvidence=replay;lines.push(formatReplayEvidence(replay,{rules:await rulesToCheck(run,p,record.summary),terminal:true}));}
if (run.workflow === 'small-change' && !askArea(run) && ['scope','change','verify','formal'].includes(step))
record.smallChange = {checklist: readSmallChangeChecklist(run), formal: readFormalEvidence(run)};
const applyDone=latest=>{
Expand Down
13 changes: 13 additions & 0 deletions test/workflow-replay.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ test('2870 review: path and Try values stay distinct, quoted and inert, and long
assert.match(report,/x\\\\u200b/);assert.doesNotMatch(report,/\u200b/);
});

test('2953: terminal warnings show plain paths and links; the PR form keeps its escaping',async t=>{
const f=await fixture(t),result=f.api.readReplayEvidence(f.run);
result.warnings=[
{vector:'tests/add_one.json',path:'/link',before:'https://example.com/a?x=1&y=2',after:'https://example.com/b'},
{vector:'tests/add_one.json',path:'/marker',before:'pdd-workflow:old',after:'x\u200b'}
];
const terminal=f.api.formatReplayEvidence(result,{terminal:true}),pr=f.api.formatReplayEvidence(result);
assert.ok(terminal.includes('warning: Saved test values changed: tests/add_one.json /link "https://example.com/a?x=1&y=2" -> "https://example.com/b"'),terminal);
assert.doesNotMatch(terminal,/&#47;|&amp;|\\_/);
assert.match(terminal,/pdd-workflow\\u003aold/);assert.match(terminal,/x\\u200b/);assert.doesNotMatch(terminal,/\u200b|pdd-workflow:/);
assert.match(pr,/tests&#47;add\\_one\.json/);assert.match(pr,/&amp;/);assert.doesNotMatch(pr,/https:\/\//);
});

test('2870 review: a display budget counts overflow and keeps the complete warning list',async t=>{
const f=await fixture(t),result=f.api.readReplayEvidence(f.run);
result.warnings=Array.from({length:800},(_,i)=>({vector:'tests/add.json',path:`/numbers/${i}`,before:i,after:i+1}));
Expand Down
2 changes: 1 addition & 1 deletion test/workflow-runner.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ test('2870: vector edits after prompt-space approval warn and replay without rep
writeFileSync(join(run.runDir,'replay-evidence.json'),JSON.stringify(await replayManifest(f,run,vector)));
const out=await stepDone({step:'verify',summary:'PASS',cwd:run.root},f.agentPorts());assert.equal(out.exitCode,0,out.message);
assert.match(f.prs[1].body,/Code replay: PASS/);assert.match(f.prs[1].body.replaceAll('&#47;','/'),/warning: Saved test values changed:.*\/value.*3.*999/);
assert.match(out.message,/warning: Saved test values changed:/);
assert.match(out.message,/warning: Saved test values changed: tests\/add\.json \/steps\/0\/checks\/0\/value 3 -> 999/);assert.doesNotMatch(out.message,/&#47;/);
assert.deepEqual(f.record().replayBaseline,original);
});

Expand Down
Loading