Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

Fix explainer patch resource origins across output directories

tt-a1id1fb2caed77c
diff --git a/archify.zip b/archify.zip
index 8d00159f..2ba687f2 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/explainer/patch.mjs b/archify/explainer/patch.mjs
index da7c172c..8e432636 100644
--- a/archify/explainer/patch.mjs
+++ b/archify/explainer/patch.mjs
@@ -91,7 +91,7 @@ export async function preparePanelPatch({artifactPath,panelId,replacementPath,re
const original=(previous.dependencies || []).find(dep=>dep.kind==='diagram-spec' && dep.id===entry.id);
if(!original) fail('payload','The original diagram has no frozen specification evidence.',artifactPath,panelId,'Rebuild the original artifact before patching.');
newDiagrams.diagrams[entry.id].specification=previous.preparedDiagrams.diagrams[entry.id].specification;
- return {...original,retained:true};
+ return {...original,path:near(original.path),retained:true};
});
const preparedSources={...previous.preparedSources,sources:{...previous.preparedSources.sources,...newSources.sources},assets:{...previous.preparedSources.assets,...newSources.assets},charts:{...previous.preparedSources.charts,...newSources.charts}};
const preparedDiagrams={...previous.preparedDiagrams,diagrams:{...previous.preparedDiagrams.diagrams,...newDiagrams.diagrams}};
@@ -107,10 +107,11 @@ export async function preparePanelPatch({artifactPath,panelId,replacementPath,re
const dependencyKey=entry=>`${entry.kind}:${entry.id}`;
const newDependencies=[...(newSources.dependencies||[]),...(newDiagrams.dependencies||[])];
const preparedIds=new Set(newDependencies.map(dependencyKey));
- const dependencies=[...(previous.dependencies||[]).filter(entry=>!preparedIds.has(dependencyKey(entry)) && (entry.kind!=='image'||imageIds.has(entry.id)) && (entry.kind!=='data'||dataChartIds.has(entry.id)) && (entry.kind!=='diagram-spec'||diagramIds.has(entry.id))),...newDependencies].map(entry=>({ ...entry,
- ...(entry.kind==='repository'||entry.inline?{}:{path:path.resolve(common.baseDir,entry.path)}) }));
+ const localDependency=(entry,baseDir)=>({...entry,...(entry.kind==='repository'||entry.inline?{}:{path:path.resolve(baseDir,entry.path)})});
+ const dependencies=[...(previous.dependencies||[]).filter(entry=>!preparedIds.has(dependencyKey(entry)) && (entry.kind!=='image'||imageIds.has(entry.id)) && (entry.kind!=='data'||dataChartIds.has(entry.id)) && (entry.kind!=='diagram-spec'||diagramIds.has(entry.id))).map(entry=>localDependency(entry,path.dirname(artifactPath))),
+ ...newDependencies.map(entry=>localDependency(entry,common.baseDir))];
// Old dependencies are embedded immutable bytes. Only newly prepared resources are reread/verified.
- const bundle=rebindPreparedBundle({...previous,preparedSources,preparedDiagrams,dependencies,quality:selectedQuality,writingMode:writingMode || previous.writingMode || 'warn'},parsed);
+ const bundle=rebindPreparedBundle({...previous,sourcePath:common.sourcePath,baseDir:common.baseDir,preparedSources,preparedDiagrams,dependencies,quality:selectedQuality,writingMode:writingMode || previous.writingMode || 'warn'},parsed);
bundle.dependencies = dependencies.map(entry => ({...entry, retained: entry.retained===true || !preparedIds.has(dependencyKey(entry))}));
return {bundle:rebindPreparedBundle(bundle,parsed),sourceText,sourcePath:draft.sourcePath || artifactPath,previousRevision:computeExplainerRevision(previous),previousSourceSha256:previous.source.sha256,panelId};
}
diff --git a/test/delivery-contract.test.mjs b/test/delivery-contract.test.mjs
index 6c17fc37..a6addbae 100644
--- a/test/delivery-contract.test.mjs
+++ b/test/delivery-contract.test.mjs
@@ -34,7 +34,7 @@ const browserSection = delivery.match(/## Automated browser evidence[\s\S]*?## O
const perceptualReviewSection = delivery.match(/## Perceptual review[\s\S]*?## Handoff receipt/)?.[0] ?? '';
test('ordinary handoff uses one deterministic finalizer without image capability', () => {
- assert.ok(skill.indexOf('## Existing candidate handoff') < skill.indexOf('## Fast authoring path'));
+ assert.ok(skill.indexOf('## Existing candidate handoff') < skill.indexOf('## Native diagram authoring'));
assert.match(skill, /run `finalize` first as one CLI invocation/);
assert.match(skill, /passing receipt completes the automated gates; follow any visual review recommendation/i);
assert.match(skill, /archify\.mjs finalize <type> <candidate\.json> <output\.html> --quality showcase --json/);
@@ -76,7 +76,7 @@ test('delivery, browser evidence, capture evidence, and perceptual review remain
test('strict provenance succeeds before either browser command', () => {
const ordering = delivery.match(/Run strict `check` after `deliver` exits zero\.[\s\S]*?collecting new browser evidence\./)?.[0] ?? '';
assert.match(ordering, /Run `browser-check` or optional\s+`visual-check` only after that strict check exits zero/i);
- assert.match(skill, /Recovery follows `deliver` → strict provenance `check` → `browser-check`/);
+ assert.match(skill, /Native diagram recovery follows `deliver` → strict provenance `check` → `browser-check`/);
assert.match(skill, /captures require strict provenance/);
});
diff --git a/test/explainer-cli.test.mjs b/test/explainer-cli.test.mjs
index c0f5ea5b..caae28ec 100644
--- a/test/explainer-cli.test.mjs
+++ b/test/explainer-cli.test.mjs
@@ -22,7 +22,7 @@ test('explainer CLI binds original draft bytes through validate, deliver and str
assert.equal(JSON.parse(validation.stdout).candidate.sha256,sha(fs.readFileSync(input)));
const delivery=run(['deliver','explainer',input,output,'--json']);assert.equal(delivery.status,0,delivery.stdout+delivery.stderr);
const receipt=JSON.parse(delivery.stdout);assert.equal(receipt.specification.sha256,sha(fs.readFileSync(input)));assert.equal(receipt.artifact.sha256,sha(fs.readFileSync(output)));
- const frozen=bundle(output);assert.equal(frozen.sourceText,fs.readFileSync(input,'utf8'));assert.equal(frozen.sourcePath,input);
+ const frozen=bundle(output);assert.equal(frozen.sourceText,fs.readFileSync(input,'utf8'));assert.equal(path.isAbsolute(frozen.sourcePath),false);assert.equal(fs.realpathSync(path.resolve(path.dirname(output),frozen.sourcePath)),fs.realpathSync(input));
const check=run(['check',output,'--json','--require-provenance']);assert.equal(check.status,0,check.stdout+check.stderr);assert.equal(JSON.parse(check.stdout).deliveryReceiptId,receipt.receiptId);
});
diff --git a/test/explainer-patch.test.mjs b/test/explainer-patch.test.mjs
index 52cac9a8..a45f8143 100644
--- a/test/explainer-patch.test.mjs
+++ b/test/explainer-patch.test.mjs
@@ -92,3 +92,28 @@ test('panel patch quality override validates every native child from frozen inpu
assert.deepEqual(patched.dependencies.find(dep=>dep.id==='second-diagram'),{...previous.dependencies.find(dep=>dep.id==='second-diagram'),retained:true});
const check=run(['check',output,'--json','--require-provenance']);assert.equal(check.status,0,check.stdout+check.stderr);
});
+
+
+test('panel patch across directories retains resource origins for subsequent edits',t=>{
+ const dir=fs.realpathSync(temp(t)),source=path.join(dir,'source'),out=path.join(dir,'out'),moved=path.join(dir,'moved','deep');
+ for(const folder of [source,out,moved])fs.mkdirSync(folder,{recursive:true});
+ const png=Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a8XcAAAAASUVORK5CYII=','base64');
+ fs.writeFileSync(path.join(source,'asset.png'),png);
+ const doc=fixture();doc.panels[1].blocks.push({id:'retained-image',type:'image',path:'asset.png',alt:'Retained image'});
+ const input=path.join(source,'draft.json'),artifact=path.join(out,'page.html'),replacement=path.join(dir,'replacement.json');
+ fs.writeFileSync(input,JSON.stringify(doc));
+ const delivered=run(['deliver','explainer',input,artifact,'--json']);assert.equal(delivered.status,0,delivered.stdout+delivered.stderr);
+ const next={...doc.panels[0],title:'Changed title'};fs.writeFileSync(replacement,JSON.stringify(next));
+ const relocated=path.join(moved,'page.html');
+ const first=run(['patch','explainer',artifact,'first',replacement,relocated,'--json']);assert.equal(first.status,0,first.stdout+first.stderr);
+ next.blocks=[...next.blocks,{id:'new-image',type:'image',path:'asset.png',alt:'New image'}];fs.writeFileSync(replacement,JSON.stringify(next));
+ const output=path.join(out,'final.html');
+ const second=run(['patch','explainer',relocated,'first',replacement,output,'--json']);assert.equal(second.status,0,second.stdout+second.stderr);
+ const result=read(output);
+ assert.equal(path.resolve(out,result.sourcePath),input);assert.equal(path.resolve(out,result.baseDir),source);
+ for(const id of ['retained-image','new-image']){
+ assert.equal(path.resolve(out,result.dependencies.find(entry=>entry.id===id).path),path.join(source,'asset.png'));
+ assert.deepEqual(Buffer.from(result.preparedSources.assets[id].contentBase64,'base64'),png);
+ }
+ const checked=run(['check',output,'--json','--require-provenance']);assert.equal(checked.status,0,checked.stdout+checked.stderr);
+});
diff --git a/test/ordinary-model-floor.test.mjs b/test/ordinary-model-floor.test.mjs
index 5f35dc4f..7069b619 100644
--- a/test/ordinary-model-floor.test.mjs
+++ b/test/ordinary-model-floor.test.mjs
@@ -1005,7 +1005,7 @@ test('packaged skill keeps first-draft rules inline and repair contracts behind
const authoring = read('references/authoring-contract.md');
const delivery = read('references/delivery-contract.md');
const repository = read('references/repository-authoring.md');
- const fastPath = skill.slice(skill.indexOf('## Fast authoring path'), skill.indexOf('## Update awareness'));
+ const fastPath = skill.slice(skill.indexOf('## Native diagram authoring'), skill.indexOf('## Update awareness'));
assert.match(skill, /## Existing candidate handoff[\s\S]*run `finalize` first as one CLI invocation/);
assert.match(fastPath, /exact schema and example paths in the Type router without listing their directories/);
assert.match(fastPath, /references\/authoring-defaults\.md/);