intentdna 1.8.7 → 1.9.0-rc.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli/commands/candidate-promotion.d.ts +15 -0
- package/dist/cli/commands/candidate-promotion.js +197 -0
- package/dist/cli/commands/run-lifecycle.js +1 -0
- package/dist/cli/commands/run.js +76 -42
- package/dist/cli/commands/setup.d.ts +10 -0
- package/dist/cli/commands/setup.js +129 -36
- package/dist/cli/commands/source-assets.d.ts +32 -0
- package/dist/cli/commands/source-assets.js +154 -0
- package/dist/cli/commands/sync.js +52 -12
- package/dist/cli/commands/templates.js +59 -37
- package/dist/cli/index.js +161 -5
- package/dist/compiler/cascade.js +1 -1
- package/dist/hooks/cli.d.ts +6 -0
- package/dist/hooks/cli.js +118 -10
- package/dist/hooks/enforcement-boundary.d.ts +1 -1
- package/dist/hooks/protocol.d.ts +1 -1
- package/dist/hooks/state.d.ts +5 -0
- package/dist/hooks/state.js +21 -6
- package/dist/mcp/tools-state.js +251 -15
- package/dist/runtime/claude-sync-target.d.ts +2 -0
- package/dist/runtime/claude-sync-target.js +1 -1
- package/dist/runtime/evaluator.d.ts +13 -0
- package/dist/runtime/evaluator.js +46 -0
- package/dist/runtime/index.d.ts +8 -4
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/plugin-adapter.d.ts +14 -1
- package/dist/runtime/plugin-adapter.js +23 -9
- package/dist/runtime/run-contracts.d.ts +5 -3
- package/dist/runtime/run-contracts.js +11 -1
- package/dist/runtime/run-controller.d.ts +15 -1
- package/dist/runtime/run-controller.js +235 -94
- package/dist/runtime/skill-adapter.js +24 -53
- package/dist/runtime/verifier.js +101 -2
- package/dist/runtime/workflow-plan-adapter.d.ts +2 -1
- package/dist/runtime/workflow-plan-adapter.js +78 -11
- package/dist/runtime/workflow-runtime-manifest.d.ts +48 -0
- package/dist/runtime/workflow-runtime-manifest.js +196 -0
- package/dist/runtime/workflow-variable-scopes.d.ts +12 -0
- package/dist/runtime/workflow-variable-scopes.js +55 -0
- package/dist/schema/types.d.ts +9 -0
- package/dist/schema/validate.js +29 -1
- package/dist/sources/authoring-packet.d.ts +8 -0
- package/dist/sources/authoring-packet.js +85 -0
- package/dist/sources/discovery.d.ts +7 -0
- package/dist/sources/discovery.js +150 -0
- package/dist/sources/license.d.ts +5 -0
- package/dist/sources/license.js +94 -0
- package/dist/sources/manifest.d.ts +11 -0
- package/dist/sources/manifest.js +84 -0
- package/dist/sources/skill-markdown.d.ts +6 -0
- package/dist/sources/skill-markdown.js +174 -0
- package/dist/sources/types.d.ts +125 -0
- package/dist/sources/types.js +1 -0
- package/dist/templates/asset-refinery.dna.yaml +192 -0
- package/dist/templates/flutter-behavior-lock.dna.yaml +17 -0
- package/dist/templates/flutter-refactoring-rescue.dna.yaml +11 -0
- package/dist/templates/flutter-rewrite.dna.yaml +154 -28
- package/dist/templates/metadata.js +2 -0
- package/dist/templates/multi-agent-handoff-coordination.dna.yaml +102 -37
- package/dist/templates/persistent-executor.dna.yaml +61 -3
- package/dist/templates/research-improvement.dna.yaml +295 -0
- package/dist/templates/subagent-parallel.dna.yaml +90 -17
- package/dist/templates/workflow-evidence-review.dna.yaml +8 -0
- package/dist/workflow/candidate-projection.d.ts +33 -0
- package/dist/workflow/candidate-projection.js +70 -0
- package/package.json +3 -1
- package/scripts/sync-release-plugin.cjs +87 -0
|
@@ -62,14 +62,14 @@ genes:
|
|
|
62
62
|
target: improvement_during_refactor
|
|
63
63
|
|
|
64
64
|
one_module_per_session:
|
|
65
|
-
description: Each session handles
|
|
65
|
+
description: Each session handles one target behavior module plus only diagnosis-approved supporting paths
|
|
66
66
|
codons:
|
|
67
67
|
- type: attract
|
|
68
|
-
target:
|
|
68
|
+
target: single_target_behavior_module
|
|
69
69
|
- type: repel
|
|
70
|
-
target:
|
|
70
|
+
target: unrelated_cross_module_changes
|
|
71
71
|
- type: threshold
|
|
72
|
-
condition: "
|
|
72
|
+
condition: "target_behavior_modules_per_session <= 1"
|
|
73
73
|
action: escalate
|
|
74
74
|
|
|
75
75
|
v1_is_truth:
|
|
@@ -160,17 +160,21 @@ context_files:
|
|
|
160
160
|
fix_reviewer:
|
|
161
161
|
- "docs/behavior/{{ARGUMENTS}}.md"
|
|
162
162
|
- ".dna/specs/diagnosis-{{ARGUMENTS}}.md"
|
|
163
|
+
- ".dna/specs/diagnosis-{{ARGUMENTS}}.contract.json"
|
|
163
164
|
test_runner:
|
|
164
165
|
- "docs/behavior/{{ARGUMENTS}}.md"
|
|
165
166
|
- ".dna/specs/diagnosis-{{ARGUMENTS}}.md"
|
|
167
|
+
- ".dna/specs/diagnosis-{{ARGUMENTS}}.contract.json"
|
|
166
168
|
|
|
167
169
|
verifier_policy:
|
|
168
170
|
allow_commands:
|
|
169
|
-
- "
|
|
170
|
-
- "node -e \"const fs=require('node:fs');const
|
|
171
|
+
- "flutter analyze {{v2_path}}/core"
|
|
172
|
+
- "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const path=require('node:path'); const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:core_align_'+m);process.exit(1)}; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const reviewPath='.dna/reviews/core-align-review.json'; if(!fs.existsSync(inside(reviewPath)))fail('review_missing'); const d=JSON.parse(fs.readFileSync(inside(reviewPath),'utf8')); const head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim(); if(d.reviewed_commit!==head||d.git_head!==head)fail('commit'); if(d.verdict!=='APPROVE')fail('review_verdict'); if(d.production_default_wiring_verified!==true)fail('production_default_wiring'); if(d.analyzer_passed!==true)fail('analyzer'); if(d.requires_non_core_changes!==false)fail('non_core_changes'); if(!Array.isArray(d.missing_paths)||d.missing_paths.length)fail('missing_paths'); if(typeof d.summary!=='string'||!d.summary.trim())fail('summary'); const updated=Date.parse(d.updated_at); const commitTime=Number(cp.execFileSync('git',['show','-s','--format=%ct',head],{encoding:'utf8'}).trim())*1000; const reviewMtime=fs.statSync(inside(reviewPath)).mtimeMs; if(!Number.isFinite(updated)||updated<commitTime||Math.abs(reviewMtime-updated)>300000)fail('review_stale'); const core=rel('{{v2_path}}/core'); if(!Array.isArray(d.evidence_paths)||!d.evidence_paths.length)fail('evidence'); for(const p of d.evidence_paths){const n=rel(p);const r=inside(p);if(!under(n,core)||!fs.existsSync(r)||!fs.statSync(r).isFile())fail('evidence')} const output=cp.execFileSync('git',['diff-tree','--root','--no-commit-id','--name-only','-r',head],{encoding:'utf8'}).trim(); const changed=output?output.split(/\\r?\\n/).filter(Boolean):[]; if(!changed.length)fail('empty_commit'); for(const p of changed){const n=rel(p);if(!under(n,core))fail('non_core_commit')} const dirty=cp.execFileSync('git',['status','--porcelain','--untracked-files=all','--',core],{encoding:'utf8'}).trim(); if(dirty)fail('uncommitted_core'); \""
|
|
173
|
+
- "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const crypto=require('node:crypto'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:fix_scope_'+m);process.exit(1)}; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const hash=v=>crypto.createHash('sha256').update(v).digest('hex'); const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v); const same=(a,b)=>Array.isArray(a)&&Array.isArray(b)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const snapSame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.sidecar_semantic_sha256===b.sidecar_semantic_sha256&&a.diagnosis_semantic_sha256===b.diagnosis_semantic_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const data=JSON.parse(fs.readFileSync(inside(contractPath),'utf8')); if(data.contract_version!=='diagnosis-contract/v2'||data.module!==mod||data.diagnosis_artifact!==diagnosisPath)fail('contract'); const snap=data.contract_snapshot||{}; const semantic=JSON.parse(JSON.stringify(data)); delete semantic.contract_snapshot.sidecar_semantic_sha256; delete semantic.contract_snapshot.diagnosis_artifact_sha256; delete semantic.staleness.diagnosis_artifact; if(snap.sidecar_semantic_sha256!==hash(canon(semantic)))fail('contract_snapshot'); const review=JSON.parse(fs.readFileSync(inside(reviewPath),'utf8')); if(review.contract_version!=='diagnosis-contract-review/v1'||review.contract_valid!==true||review.verdict!=='APPROVE')fail('review'); if(review.contract_artifact_reviewed!==contractPath||review.artifact_reviewed!==diagnosisPath||!snapSame(review.contract_snapshot,snap))fail('review_snapshot'); if(!Array.isArray(review.evidence_paths)||!review.evidence_paths.length)fail('review_evidence'); for(const p of review.evidence_paths){const r=inside(p);if(!fs.existsSync(r)||!fs.statSync(r).isFile())fail('review_evidence')} const cm=fs.statSync(inside(contractPath)).mtimeMs; const rm=fs.statSync(inside(reviewPath)).mtimeMs; const updated=Date.parse(review.updated_at); if(!Number.isFinite(updated)||rm<cm||updated+300000<cm||Math.abs(rm-updated)>300000)fail('review_stale'); const v1=rel('{{v1_path}}'); const v2=rel('{{v2_path}}'); const action=new Set(['BUG','UNIMPLEMENTED','INFRA','TEST_BUG']); const allowed=new Set(); for(const item of data.work_items||[]){if(!action.has(item.kind))continue;const evidence=new Set((item.v2_evidence_paths||[]).map(rel));for(const p of item.allowed_change_paths||[]){if(typeof p!=='string'||['*','?','[',']'].some(c=>p.includes(c)))fail('allowed_path_pattern');const n=rel(p);const r=inside(p);if(under(n,v1))fail('v1_change');if(!(under(n,v2)||under(n,'test')||under(n,'lib')))fail('allowed_path_root');if(fs.existsSync(r)?!fs.statSync(r).isFile():!path.basename(n).includes('.'))fail('allowed_path_not_file');if(!evidence.has(n))fail('allowed_path_not_evidence');allowed.add(n)}} if(!allowed.size)fail('allowed_paths'); const head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim(); const output=cp.execFileSync('git',['diff-tree','--root','--no-commit-id','--name-only','-r',head],{encoding:'utf8'}).trim(); const changed=output?output.split(/\\r?\\n/).filter(Boolean):[]; if(!changed.length)fail('empty_commit'); for(const p of changed){const n=rel(p);if(under(n,v1))fail('v1_change');if(!allowed.has(n))fail('outside_diagnosis')} const dirty=cp.execFileSync('git',['status','--porcelain','--untracked-files=all','--',...allowed],{encoding:'utf8'}).trim(); if(dirty)fail('uncommitted_allowed_path'); \""
|
|
174
|
+
- "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const crypto=require('node:crypto'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG']; const action=['BUG','UNIMPLEMENTED','INFRA','TEST_BUG']; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)}; const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const legacySame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); const modern=s=>s&&typeof s.sidecar_semantic_sha256==='string'&&typeof s.diagnosis_semantic_sha256==='string'; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8')); const hash=v=>crypto.createHash('sha256').update(v).digest('hex'); const fileHash=p=>hash(fs.readFileSync(inside(p))); const normalizedDiagnosisHash=p=>hash(fs.readFileSync(inside(p),'utf8').replace(/\\s+/g,' ').trim()); const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const progressPath='.dna/fix-progress/'+mod+'.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const behaviorPath='docs/behavior/'+mod+'.md'; const v1Root=rel('{{v1_path}}'); const v2Root=rel('{{v2_path}}'); if(v1Root==='.'||v2Root==='.'||under(v1Root,v2Root)||under(v2Root,v1Root))fail('configured_roots'); const data=readJson(contractPath); if(data.contract_version!=='diagnosis-contract/v2')fail('contract_version'); if(data.module!==mod)fail('module_mismatch'); if(data.diagnosis_artifact!==diagnosisPath)fail('diagnosis_artifact_path'); if(!same(data.allowed_kinds,allowed))fail('allowed_kinds'); const observed=Array.isArray(data.observed_failures)?data.observed_failures:fail('observed_failures'); const work=Array.isArray(data.work_items)?data.work_items:fail('work_items'); if(!observed.length)fail('empty_observed_failures'); if(!work.length)fail('empty_work_items'); const idOk=id=>typeof id==='string'&&/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id); const ids=new Set(); for(const f of observed){if(!idOk(f&&f.id)||ids.has(f.id))fail('observed_failure_ids');ids.add(f.id)} const workIds=new Set(); for(const item of work){if(!idOk(item&&item.id)||workIds.has(item.id))fail('work_item_ids');workIds.add(item.id)} const failureById=new Map(); for(const f of observed){if(typeof f.test_name!=='string'||!f.test_name.trim())fail('observed_failure_test_name');if(typeof f.symptom!=='string'||!f.symptom.trim())fail('observed_failure_symptom');if(!Array.isArray(f.evidence_paths)||!f.evidence_paths.length)fail('observed_failure_evidence');for(const p of f.evidence_paths)rel(p);if(f.kind!==undefined)fail('observed_failure_kind_forbidden');failureById.set(f.id,f)} const mapped=new Set(); const allAllowed=new Set(); const v1Evidence=new Set(); for(const item of work){if(!allowed.includes(item.kind))fail('invalid_kind');if(item.kind==='PLACEHOLDER_CONTRACT')fail('placeholder_kind');if(!Array.isArray(item.observed_failure_ids)||!item.observed_failure_ids.length)fail('work_item_observed_failure_ids');if(!Array.isArray(item.evidence_paths)||!item.evidence_paths.length)fail('work_item_evidence');for(const p of item.evidence_paths)rel(p);if(action.includes(item.kind)){if(!Array.isArray(item.v1_evidence_paths)||!item.v1_evidence_paths.length)fail('work_item_v1_evidence');if(!Array.isArray(item.v2_evidence_paths)||!item.v2_evidence_paths.length)fail('work_item_v2_evidence');const v2Evidence=new Set(item.v2_evidence_paths.map(rel));for(const p of item.v1_evidence_paths){const n=rel(p);if(!under(n,v1Root))fail('work_item_v1_evidence_root');v1Evidence.add(n)}for(const p of item.v2_evidence_paths)rel(p);if(!Array.isArray(item.allowed_change_paths)||!item.allowed_change_paths.length)fail('work_item_allowed_change_paths');const approved=new Set();for(const p of item.allowed_change_paths){if(typeof p!=='string'||['*','?','[',']'].some(c=>p.includes(c)))fail('work_item_allowed_change_path_pattern');const n=rel(p);const r=inside(p);if(under(n,v1Root))fail('work_item_allowed_change_path_v1');if(!(under(n,v2Root)||under(n,'test')||under(n,'lib')))fail('work_item_allowed_change_path_root');if(fs.existsSync(r)?!fs.statSync(r).isFile():!path.basename(n).includes('.'))fail('work_item_allowed_change_path_not_file');if(!v2Evidence.has(n))fail('work_item_allowed_change_path_not_evidence');if(approved.has(n))fail('work_item_allowed_change_path_duplicate');approved.add(n);allAllowed.add(n)}}for(const id of item.observed_failure_ids){const f=failureById.get(id);if(!f)fail('unknown_observed_failure_id');if(action.includes(item.kind)&&(!f.test_name||!String(f.test_name).trim()))fail('action_test_evidence');mapped.add(id)}} if(mapped.size!==ids.size)fail('unmapped_observed_failures'); for(const f of observed.filter(x=>String(x.symptom).includes('PLACEHOLDER_CONTRACT'))){const kinds=new Set(work.filter(i=>i.observed_failure_ids.includes(f.id)).map(i=>i.kind));if(![...kinds].every(k=>k==='TEST_BUG'||k==='UNIMPLEMENTED')||kinds.size===0)fail('placeholder_mapping')} const counts=data.baseline&&data.baseline.counts; if(!data.baseline||!data.baseline.source_path||!counts)fail('baseline'); for(const k of ['failed','skipped','hung']){if(!Number.isInteger(counts[k])||counts[k]<0)fail('baseline_count_'+k)} if(counts.failed+counts.skipped+counts.hung!==observed.length)fail('baseline_count_mismatch'); const summary=data.summary_counts||{}; for(const kind of allowed){if(!Number.isInteger(summary[kind])||summary[kind]!==work.filter(x=>x.kind===kind).length)fail('summary_count_'+kind)} const snap=data.contract_snapshot||{}; const baselineHash=fileHash(data.baseline.source_path); const diagnosisHash=fileHash(diagnosisPath); if(snap.observed_failure_count!==observed.length||snap.work_item_count!==work.length||!same(snap.allowed_kinds,allowed))fail('contract_snapshot'); if(snap.baseline_source_sha256!==baselineHash)fail('baseline_sha256'); if(snap.diagnosis_artifact_sha256!==diagnosisHash)fail('diagnosis_sha256'); const stale=data.staleness; if(!stale||stale.is_stale!==false)fail('stale_contract'); const source=(entry,p,n,expected)=>{if(!entry||entry.path!==p)fail('staleness_'+n+'_path');if(entry.sha256!==expected)fail('staleness_'+n+'_sha256')}; source(stale.behavior_doc,behaviorPath,'behavior_doc',fileHash(behaviorPath)); source(stale.baseline,data.baseline.source_path,'baseline',baselineHash); source(stale.diagnosis_artifact,diagnosisPath,'diagnosis_artifact',diagnosisHash); const expectedSources=[...new Set(work.filter(i=>action.includes(i.kind)).flatMap(i=>[...i.v1_evidence_paths,...i.v2_evidence_paths]).map(rel))].sort(); if(!Array.isArray(stale.source_files)||stale.source_files.length!==expectedSources.length)fail('staleness_source_files'); let relaxed=false; let head=''; if(fs.existsSync(inside(progressPath))){const progressMtime=fs.statSync(inside(progressPath)).mtimeMs;const artifactMtime=Math.max(fs.statSync(inside(contractPath)).mtimeMs,fs.statSync(inside(diagnosisPath)).mtimeMs,fs.existsSync(inside(reviewPath))?fs.statSync(inside(reviewPath)).mtimeMs:0);if(progressMtime>=artifactMtime){const progress=readJson(progressPath);head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim();if(progress.module!==mod||progress.verdict!=='CONTINUE'||progress.module_complete!==false||progress.diagnosis_invalid!==false)fail('progress_state');if(progress.diagnosis_artifact!==diagnosisPath||progress.review_artifact!=='.dna/reviews/'+mod+'-review.json')fail('progress_artifacts');if(progress.git_head!==head||progress.last_fix_commit!==head)fail('progress_commit');if(!Number.isInteger(progress.round)||progress.round<1||typeof progress.run_id!=='string'||!progress.run_id.trim())fail('progress_provenance');const progressTime=Date.parse(progress.updated_at);if(!Number.isFinite(progressTime)||progressTime+300000<artifactMtime)fail('progress_updated_at');relaxed=true}} const headState=p=>{try{const body=cp.execFileSync('git',['show',head+':'+p],{encoding:null,stdio:['ignore','pipe','ignore']});return {exists:true,sha256:hash(body)}}catch{return {exists:false,sha256:null}}}; const seenSources=new Set(); for(let i=0;i<expectedSources.length;i++){const p=expectedSources[i];const entry=stale.source_files[i];if(entry&&seenSources.has(entry.path))fail('staleness_source_file_duplicate');if(!entry||entry.path!==p)fail('staleness_source_file_path');seenSources.add(entry.path);if(typeof entry.exists!=='boolean')fail('staleness_source_file_exists');if(entry.exists?(typeof entry.sha256!=='string'||!/^[a-f0-9]{64}$/.test(entry.sha256)):entry.sha256!==null)fail('staleness_source_file_snapshot');if(v1Evidence.has(p)&&entry.exists!==true)fail('staleness_v1_source_missing');const r=inside(p);const currentExists=fs.existsSync(r);if(currentExists&&!fs.statSync(r).isFile())fail('staleness_source_file_not_file');const current={exists:currentExists,sha256:currentExists?fileHash(p):null};if(relaxed&&allAllowed.has(p)){const committed=headState(p);if(current.exists!==committed.exists||current.sha256!==committed.sha256)fail('staleness_source_file_uncommitted')}else if(current.exists!==entry.exists||current.sha256!==entry.sha256)fail('staleness_source_file_sha256')} const semantic=JSON.parse(JSON.stringify(data)); delete semantic.contract_snapshot.sidecar_semantic_sha256; delete semantic.contract_snapshot.diagnosis_artifact_sha256; delete semantic.staleness.diagnosis_artifact; const sidecarSemanticHash=hash(canon(semantic)); const diagnosisSemanticHash=normalizedDiagnosisHash(diagnosisPath); if(snap.sidecar_semantic_sha256!==sidecarSemanticHash||snap.diagnosis_semantic_sha256!==diagnosisSemanticHash)fail('contract_snapshot_semantic'); if(fs.existsSync(inside(reviewPath))){const prev=readJson(reviewPath);if(prev.verdict==='REQUEST_REANALYSIS'){const ps=prev.contract_snapshot||{};const unchanged=modern(ps)?ps.sidecar_semantic_sha256===sidecarSemanticHash&&ps.diagnosis_semantic_sha256===diagnosisSemanticHash:legacySame(ps,snap);if(unchanged)fail('reanalysis_unchanged');const cm=fs.statSync(inside(contractPath)).mtimeMs;const dm=fs.statSync(inside(diagnosisPath)).mtimeMs;const rm=fs.statSync(inside(reviewPath)).mtimeMs;if(cm<=rm||dm<=rm)fail('reanalysis_not_rewritten')}} \""
|
|
175
|
+
- "node -e \"const fs=require('node:fs'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG']; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)}; const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const snapSame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.sidecar_semantic_sha256===b.sidecar_semantic_sha256&&a.diagnosis_semantic_sha256===b.diagnosis_semantic_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8')); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const data=readJson(contractPath); const snap=data.contract_snapshot||{}; if(data.contract_version!=='diagnosis-contract/v2'||data.module!==mod)fail('contract_version'); const review=readJson(reviewPath); if(review.contract_version!=='diagnosis-contract-review/v1')fail('review_contract_version'); if(review.contract_valid!==true)fail('review_contract_valid'); if(review.verdict!=='APPROVE')fail('review_verdict'); if(review.contract_artifact_reviewed!==contractPath)fail('review_contract_artifact_path'); if(review.artifact_reviewed!==diagnosisPath)fail('review_artifact_path'); if(!snapSame(review.contract_snapshot,snap))fail('review_contract_snapshot'); const updated=Date.parse(review.updated_at); if(!Number.isFinite(updated))fail('review_updated_at'); if(!Array.isArray(review.evidence_paths)||!review.evidence_paths.length)fail('review_evidence_paths'); for(const p of review.evidence_paths){const r=inside(p);if(!fs.existsSync(r)||!fs.statSync(r).isFile())fail('review_evidence_paths')} const cm=fs.statSync(inside(contractPath)).mtimeMs; const dm=fs.statSync(inside(diagnosisPath)).mtimeMs; const rm=fs.statSync(inside(reviewPath)).mtimeMs; if(rm<cm||rm<dm||updated+300000<Math.max(cm,dm)||Math.abs(rm-updated)>300000)fail('review_stale'); \""
|
|
171
176
|
allow_builtin_asserts:
|
|
172
177
|
- clean_working_tree
|
|
173
|
-
|
|
174
178
|
roles:
|
|
175
179
|
# ── Phase 0/3: behavior-lock 角色 ──
|
|
176
180
|
scanner:
|
|
@@ -214,7 +218,9 @@ roles:
|
|
|
214
218
|
write: ["lib/**", "v2/**", "test/**"]
|
|
215
219
|
instructions:
|
|
216
220
|
- "REQUIRED FIRST: Read context files — CLAUDE.md, docs/refactoring-workflow-v2.md, v2/docs/PROVIDER_DESIGN.md, and the diagnosis spec (.dna/specs/diagnosis-$ARGUMENTS.md). Then read v1 corresponding file before any Edit. Hook will block Edit if context files are not read."
|
|
217
|
-
- Fix only the identified breakpoint or missing implementation
|
|
221
|
+
- Fix only the identified breakpoint or missing implementation, and edit only diagnosis-approved allowed_change_paths
|
|
222
|
+
- "A supporting path in another v2 package is in scope when an approved diagnosis work item lists it in allowed_change_paths; unrelated cross-package edits remain forbidden"
|
|
223
|
+
- "Never edit v1_evidence_paths or any path under the configured {{v1_path}} source root"
|
|
218
224
|
- Read v1 to understand intent, rewrite in v2 framework style
|
|
219
225
|
- Do not copy v1 code verbatim — adapt to v2 architecture
|
|
220
226
|
- "Logic layer: implement notifier/state, make logic tests pass"
|
|
@@ -244,6 +250,22 @@ roles:
|
|
|
244
250
|
- Only change DI pattern (GetX → Riverpod), not logic
|
|
245
251
|
- Do not add methods v1 doesn't have
|
|
246
252
|
- Do not remove methods v1 has
|
|
253
|
+
- "Verify the production default construction path wires real owners and dependencies; fake-only tests and no-owner no-ops are not alignment evidence"
|
|
254
|
+
- "If completing production ownership requires a non-core change, report the exact missing path and do not claim PASS"
|
|
255
|
+
|
|
256
|
+
core_alignment_reviewer:
|
|
257
|
+
description: Independently verifies core alignment against production wiring and analyzer evidence.
|
|
258
|
+
tool_permissions:
|
|
259
|
+
allow: [Read, Grep, Glob, Bash, Write]
|
|
260
|
+
deny: [Edit, NotebookEdit]
|
|
261
|
+
scope:
|
|
262
|
+
read: ["**/*"]
|
|
263
|
+
write: [".dna/reviews/core-align-review.json"]
|
|
264
|
+
instructions:
|
|
265
|
+
- "Review only the core-align commit and verify v1 behavior against the production v2 default construction path"
|
|
266
|
+
- "Reject fake-only proof, empty default owner lists, no-owner no-ops, and test-only dependency injection as completion evidence"
|
|
267
|
+
- "Run flutter analyze for v2 core independently"
|
|
268
|
+
- "Write .dna/reviews/core-align-review.json and never edit production or test code"
|
|
247
269
|
|
|
248
270
|
# ── v2 角色: diagnosis + fix workflow ──
|
|
249
271
|
analyzer:
|
|
@@ -260,8 +282,12 @@ roles:
|
|
|
260
282
|
- "For each failing, skipped, and hung test: read test code + v1 impl + v2 impl"
|
|
261
283
|
- "Classify each as BUG / UNIMPLEMENTED / INFRA / REMOVED / TEST_BUG (skipped tests are usually UNIMPLEMENTED)"
|
|
262
284
|
- "Output diagnosis spec with v1 code snippets + v2 current state + evidence paths"
|
|
263
|
-
- "Also write .dna/specs/diagnosis-$ARGUMENTS.contract.json as the structured sidecar mapping baseline observed_failures to diagnosis work_items"
|
|
285
|
+
- "Also write .dna/specs/diagnosis-$ARGUMENTS.contract.json using diagnosis-contract/v2 as the structured sidecar mapping baseline observed_failures to diagnosis work_items"
|
|
264
286
|
- "The sidecar allowed_kinds array must be exactly BUG, UNIMPLEMENTED, INFRA, REMOVED, TEST_BUG in that order; PLACEHOLDER_CONTRACT is never a kind"
|
|
287
|
+
- "Every actionable work item must list exact v1_evidence_paths, v2_evidence_paths, and file-only allowed_change_paths, including supporting v2 package files when required"
|
|
288
|
+
- "Every allowed_change_paths file must also be a v2_evidence_paths entry; snapshot every unique actionable source existence/hash in sorted staleness.source_files"
|
|
289
|
+
- "Directories, broad roots, globs, duplicate repair paths, and configured {{v1_path}} repair paths are invalid"
|
|
290
|
+
- "Do not invent capability ids or require a separate core-align run; the diagnosis sidecar itself authorizes exact supporting repair paths"
|
|
265
291
|
- "A placeholder-contract symptom may appear only in observed_failures.symptom and must map to concrete TEST_BUG and/or UNIMPLEMENTED work_items with evidence"
|
|
266
292
|
- "If reanalyzing after REQUEST_REANALYSIS, update every reviewer sections_to_fix item and report sections_updated"
|
|
267
293
|
- "Use mcp__intentdna__dna_artifact_digest for every exact contract SHA-256; never guess a digest or use Bash to compute one"
|
|
@@ -281,6 +307,8 @@ roles:
|
|
|
281
307
|
- "Verify analyzer spec: v1 references exist? Classifications sound?"
|
|
282
308
|
- "Independently validate .dna/specs/diagnosis-$ARGUMENTS.contract.json against the template sidecar contract; do not use Bash"
|
|
283
309
|
- "Use mcp__intentdna__dna_artifact_digest to independently verify exact raw, normalized-text, and canonical-JSON SHA-256 values"
|
|
310
|
+
- "Reject missing/directory/evidence-unrelated/duplicate allowed_change_paths and incomplete, duplicate, reordered, or stale staleness.source_files snapshots"
|
|
311
|
+
- "Treat an evidence-backed supporting path in another v2 package as valid in-diagnosis scope, not as an automatic human blocker"
|
|
284
312
|
- "Check missing: any failing test not covered?"
|
|
285
313
|
- "Verify diagnosis remains evidence-only: no fix prescriptions, implementation order, call-site instructions, or Notes for Surgeon"
|
|
286
314
|
- "Output a structured verdict block with contract_version, contract_valid, failure_reason, contract_artifact_reviewed, contract_snapshot, verdict, artifact_reviewed, sections_to_fix, evidence_paths, confidence, summary, and updated_at"
|
|
@@ -338,9 +366,12 @@ controllers:
|
|
|
338
366
|
policy:
|
|
339
367
|
diagnosis_reuse_criteria:
|
|
340
368
|
- "$diagnosis_artifact_path exists"
|
|
341
|
-
- ".dna/specs/diagnosis-$ARGUMENTS.contract.json
|
|
369
|
+
- ".dna/specs/diagnosis-$ARGUMENTS.contract.json uses diagnosis-contract/v2 and passes the declared completion validator"
|
|
342
370
|
- "$diagnosis_review_artifact_path exists and verdict is APPROVE"
|
|
343
371
|
- "$diagnosis_review_artifact_path contract_valid is true and contract_artifact_reviewed equals .dna/specs/diagnosis-$ARGUMENTS.contract.json"
|
|
372
|
+
- "every actionable work item has non-empty file-only allowed_change_paths backed by v2_evidence_paths"
|
|
373
|
+
- "before round 1, every staleness.source_files existence/hash snapshot is exact and current"
|
|
374
|
+
- "when resuming after a recorded fix commit, configured v1 evidence and unapproved v2 evidence must still match exactly; drift is allowed only for an allowed_change_paths file when progress provenance binds git_head and last_fix_commit to current HEAD and the working file equals HEAD"
|
|
344
375
|
- "behavior doc is not newer than diagnosis spec"
|
|
345
376
|
- "baseline artifact is not newer than diagnosis spec"
|
|
346
377
|
- "baseline artifact is not newer than diagnosis contract sidecar"
|
|
@@ -376,6 +407,9 @@ controllers:
|
|
|
376
407
|
- "是否回滚:say whether rollback/revert is recommended. If the commit direction looks wrong or the blast radius is unclear, recommend revert; if the failure is narrow and fixable, recommend fix-forward."
|
|
377
408
|
- "下一步:give one concrete next action. If recommending fix-forward, include a copy-paste single-fix prompt with current commit, exact failure, allowed scope, forbidden actions, verification command, commit expectation, and stop conditions."
|
|
378
409
|
constraints:
|
|
410
|
+
- "One session targets one behavior module; diagnosis-approved supporting package paths are part of that module's repair scope."
|
|
411
|
+
- "Do not require a capability id, capability catalog, or separate core-align invocation when the approved diagnosis already names the supporting paths."
|
|
412
|
+
- "Do not invalidate a diagnosis solely because a prior verified round changed an approved v2 evidence file; require the progress/commit provenance checks before accepting that drift."
|
|
379
413
|
- "Do not infer module completion from raw test output."
|
|
380
414
|
- "The controller must schedule only from $progress_artifact_path."
|
|
381
415
|
- "Manual /dna-frw-diagnosis and /dna-frw-fix flows remain separate and available."
|
|
@@ -452,7 +486,70 @@ workflows:
|
|
|
452
486
|
- id: align
|
|
453
487
|
role: core_aligner
|
|
454
488
|
description: "Compare {{v1_path}}/ and {{v2_path}}/core/ module by module. Fix mismatches."
|
|
455
|
-
prompt:
|
|
489
|
+
prompt: |
|
|
490
|
+
Compare v1 ({{v1_path}}/) and v2 core ({{v2_path}}/core/lib/) module by module.
|
|
491
|
+
|
|
492
|
+
Fix mismatches by preserving v1 behavior and changing only the DI integration needed by v2.
|
|
493
|
+
For every aligned lifecycle, provider, manager, or adapter:
|
|
494
|
+
- Trace the production default construction and registration path, not only injected test paths.
|
|
495
|
+
- Verify real production owners/dependencies are registered before claiming completion.
|
|
496
|
+
- A fake-only test, an empty default owner list, or a no-owner no-op is evidence of incomplete wiring, not PASS.
|
|
497
|
+
- Add or update a production-wiring regression test that fails when the default path has no real owner.
|
|
498
|
+
- Run flutter analyze for {{v2_path}}/core.
|
|
499
|
+
- Commit the coherent core-only change and hand the commit to independent review.
|
|
500
|
+
|
|
501
|
+
If correct production ownership requires any path outside {{v2_path}}/core/, do not add a shim and do not claim completion. Report INCOMPLETE with the exact required non-core paths so the owning module can authorize them through diagnosis allowed_change_paths.
|
|
502
|
+
completion:
|
|
503
|
+
- command_success: "flutter analyze {{v2_path}}/core"
|
|
504
|
+
handoff:
|
|
505
|
+
produces:
|
|
506
|
+
- type: git_commit
|
|
507
|
+
description: "Core alignment commit with production wiring and analyzer evidence"
|
|
508
|
+
|
|
509
|
+
- id: review_alignment
|
|
510
|
+
role: core_alignment_reviewer
|
|
511
|
+
depends_on: [align]
|
|
512
|
+
description: "Independently verify core production wiring and analyzer evidence."
|
|
513
|
+
prompt: |
|
|
514
|
+
Review the core-align commit independently.
|
|
515
|
+
|
|
516
|
+
Verify:
|
|
517
|
+
1. v1 behavior is preserved in the v2 core implementation.
|
|
518
|
+
2. The production default construction path registers real owners/dependencies.
|
|
519
|
+
3. Evidence is not limited to RecordingOwner-style fakes, injected tests, or no-owner no-op behavior.
|
|
520
|
+
4. A regression test exercises the production default wiring failure mode.
|
|
521
|
+
5. flutter analyze {{v2_path}}/core passes; the completion gate will run it again independently after this review.
|
|
522
|
+
6. No required production ownership change lies outside {{v2_path}}/core/.
|
|
523
|
+
|
|
524
|
+
Write exactly this contract to .dna/reviews/core-align-review.json:
|
|
525
|
+
```json
|
|
526
|
+
{
|
|
527
|
+
"verdict": "APPROVE | INCOMPLETE",
|
|
528
|
+
"reviewed_commit": "full git commit SHA from the align handoff",
|
|
529
|
+
"git_head": "current full git HEAD; must equal reviewed_commit",
|
|
530
|
+
"production_default_wiring_verified": false,
|
|
531
|
+
"analyzer_passed": false,
|
|
532
|
+
"requires_non_core_changes": false,
|
|
533
|
+
"missing_paths": [],
|
|
534
|
+
"evidence_paths": [],
|
|
535
|
+
"summary": "brief evidence-based reason",
|
|
536
|
+
"updated_at": "ISO-8601 timestamp"
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
Use APPROVE only when reviewed_commit and git_head equal the current align commit, production_default_wiring_verified and analyzer_passed are true, requires_non_core_changes is false, missing_paths is empty, and every evidence_paths file exists. Use the current time for updated_at. Otherwise use INCOMPLETE and name every known missing path. Do not edit code.
|
|
541
|
+
completion:
|
|
542
|
+
- command_success: "flutter analyze {{v2_path}}/core"
|
|
543
|
+
- command_success: "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const path=require('node:path'); const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:core_align_'+m);process.exit(1)}; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const reviewPath='.dna/reviews/core-align-review.json'; if(!fs.existsSync(inside(reviewPath)))fail('review_missing'); const d=JSON.parse(fs.readFileSync(inside(reviewPath),'utf8')); const head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim(); if(d.reviewed_commit!==head||d.git_head!==head)fail('commit'); if(d.verdict!=='APPROVE')fail('review_verdict'); if(d.production_default_wiring_verified!==true)fail('production_default_wiring'); if(d.analyzer_passed!==true)fail('analyzer'); if(d.requires_non_core_changes!==false)fail('non_core_changes'); if(!Array.isArray(d.missing_paths)||d.missing_paths.length)fail('missing_paths'); if(typeof d.summary!=='string'||!d.summary.trim())fail('summary'); const updated=Date.parse(d.updated_at); const commitTime=Number(cp.execFileSync('git',['show','-s','--format=%ct',head],{encoding:'utf8'}).trim())*1000; const reviewMtime=fs.statSync(inside(reviewPath)).mtimeMs; if(!Number.isFinite(updated)||updated<commitTime||Math.abs(reviewMtime-updated)>300000)fail('review_stale'); const core=rel('{{v2_path}}/core'); if(!Array.isArray(d.evidence_paths)||!d.evidence_paths.length)fail('evidence'); for(const p of d.evidence_paths){const n=rel(p);const r=inside(p);if(!under(n,core)||!fs.existsSync(r)||!fs.statSync(r).isFile())fail('evidence')} const output=cp.execFileSync('git',['diff-tree','--root','--no-commit-id','--name-only','-r',head],{encoding:'utf8'}).trim(); const changed=output?output.split(/\\r?\\n/).filter(Boolean):[]; if(!changed.length)fail('empty_commit'); for(const p of changed){const n=rel(p);if(!under(n,core))fail('non_core_commit')} const dirty=cp.execFileSync('git',['status','--porcelain','--untracked-files=all','--',core],{encoding:'utf8'}).trim(); if(dirty)fail('uncommitted_core'); \""
|
|
544
|
+
handoff:
|
|
545
|
+
consumes:
|
|
546
|
+
- type: git_commit
|
|
547
|
+
from: align
|
|
548
|
+
description: "Core alignment commit"
|
|
549
|
+
produces:
|
|
550
|
+
- type: file
|
|
551
|
+
path: ".dna/reviews/core-align-review.json"
|
|
552
|
+
description: "Independent production-wiring review verdict"
|
|
456
553
|
|
|
457
554
|
diagnosis:
|
|
458
555
|
name: Diagnosis
|
|
@@ -481,28 +578,34 @@ workflows:
|
|
|
481
578
|
- NO fix prescriptions, implementation order, call-site instructions, or "Notes for Surgeon"
|
|
482
579
|
- NO running tests (analysis only)
|
|
483
580
|
6. Write .dna/specs/diagnosis-$ARGUMENTS.contract.json with this sidecar contract:
|
|
484
|
-
- contract_version: "diagnosis-contract/
|
|
581
|
+
- contract_version: "diagnosis-contract/v2"
|
|
485
582
|
- module: "$ARGUMENTS"
|
|
486
583
|
- diagnosis_artifact: ".dna/specs/diagnosis-$ARGUMENTS.md"
|
|
487
584
|
- baseline: { "source_path": "structured baseline path or explicit fallback file", "counts": { "failed": N, "skipped": N, "hung": N } }
|
|
488
585
|
- allowed_kinds: ["BUG", "UNIMPLEMENTED", "INFRA", "REMOVED", "TEST_BUG"] exactly, no extra values
|
|
489
586
|
- observed_failures: one entry per failing/skipped/hung test with id, test_name, symptom, evidence_paths, and no kind field
|
|
490
|
-
- work_items: one or more entries mapping observed_failure_ids to kind, evidence_paths, v1_evidence_paths, and
|
|
587
|
+
- work_items: one or more entries mapping observed_failure_ids to kind, evidence_paths, v1_evidence_paths, v2_evidence_paths, and allowed_change_paths
|
|
491
588
|
- summary_counts: exact count of work_items by BUG / UNIMPLEMENTED / INFRA / REMOVED / TEST_BUG
|
|
492
589
|
- contract_snapshot: baseline_source_sha256, diagnosis_artifact_sha256, sidecar_semantic_sha256, diagnosis_semantic_sha256, observed_failure_count, work_item_count, allowed_kinds
|
|
493
|
-
- staleness: behavior_doc, baseline, and diagnosis_artifact entries each contain the exact project-relative path and current sha256; is_stale is false
|
|
590
|
+
- staleness: behavior_doc, baseline, and diagnosis_artifact entries each contain the exact project-relative path and current sha256; source_files is the sorted exact snapshot of every unique actionable work item v1_evidence_paths and v2_evidence_paths entry, using { path, exists: true, sha256 } for files and { path, exists: false, sha256: null } for a missing v2 target; is_stale is false
|
|
494
591
|
- Obtain hashes with mcp__intentdna__dna_artifact_digest, which is read-only and project-relative: bytes mode for behavior/baseline/diagnosis, whitespace_normalized_text for diagnosis_semantic_sha256, and canonical_json for the sidecar with exclude_json_pointers=["/contract_snapshot/sidecar_semantic_sha256", "/contract_snapshot/diagnosis_artifact_sha256", "/staleness/diagnosis_artifact"] for sidecar_semantic_sha256. Write the returned values back to the sidecar and re-run the canonical digest to confirm it is stable. Never guess hashes.
|
|
495
592
|
7. Contract rules:
|
|
496
593
|
- observed_failures must not be empty; work_items must not be empty.
|
|
497
594
|
- Every observed_failure id must be mapped by at least one work_item.
|
|
498
595
|
- Every work_item kind must be one of the five allowed kinds exactly.
|
|
596
|
+
- Every actionable BUG / UNIMPLEMENTED / INFRA / TEST_BUG work_item must have non-empty v1_evidence_paths, v2_evidence_paths, and allowed_change_paths.
|
|
597
|
+
- allowed_change_paths are the complete automatic repair authority for that work item. Every entry is an exact project-relative file path, never a directory or glob. Diagnosis-approved supporting files in another v2 package are valid and must be listed when required by the target module behavior.
|
|
598
|
+
- Every allowed_change_paths entry must also appear in the same work item's v2_evidence_paths so its initial existence/hash is covered by staleness.source_files. A missing v2 target may be listed with exists false and sha256 null; v1 evidence may never be missing.
|
|
599
|
+
- allowed_change_paths must remain under the configured {{v2_path}}, test/, or a non-v1 lib/ tree. Project/package/lib directory roots, duplicate paths, and any path under the configured {{v1_path}} source root are invalid.
|
|
600
|
+
- One diagnosis targets one behavior module, but its allowed_change_paths may authorize the exact supporting package changes needed to repair that behavior. Do not invent a capability id and do not require a separate core-align run.
|
|
601
|
+
- staleness.source_files must contain every unique actionable v1_evidence_paths/v2_evidence_paths source exactly once in sorted path order, including current existence and bytes SHA-256. Missing, extra, duplicate, reordered, unreadable, or stale source snapshots invalidate a fresh/first-round contract.
|
|
499
602
|
- PLACEHOLDER_CONTRACT is forbidden as a kind. If a placeholder-contract symptom exists, keep it in observed_failures.symptom and map it to concrete TEST_BUG and/or UNIMPLEMENTED work_items with evidence.
|
|
500
603
|
- REMOVED may be diagnosed but must be marked manual/user-approved before any future fix can execute it.
|
|
501
604
|
- Mixed unknown kinds, missing evidence, count mismatches, missing/changed contract_snapshot, and stale behavior/baseline/diagnosis snapshots make the contract invalid.
|
|
502
605
|
8. If this is a reanalysis after REQUEST_REANALYSIS or DIAGNOSIS_CONTRACT_INVALID, read the reviewer verdict first, update every section listed in sections_to_fix plus the summary table and contract sidecar, and report sections_updated in your final response. Reanalysis is not successful unless both the spec artifact and contract sidecar are rewritten.
|
|
503
606
|
9. Before handing off to review, the producer-side diagnosis contract completion gate must pass. It rejects grouped observations that hide per-test failures, duplicate/bad ids, unmapped observed_failures, missing evidence, count mismatches, bad hashes, stale state, and no-material-change reanalysis after REQUEST_REANALYSIS. Reanalysis compares the canonical sidecar with its self-digest and raw diagnosis snapshot fields omitted, plus a whitespace-normalized diagnosis hash, so a real sidecar-only correction is allowed while formatting-only Markdown changes are not.
|
|
504
607
|
completion:
|
|
505
|
-
- command_success: "node -e \"const fs=require('node:fs');const crypto=require('node:crypto');const path=require('node:path');const mod=process.env.ARGUMENTS||'$ARGUMENTS';const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG'];const action=['BUG','UNIMPLEMENTED','INFRA','TEST_BUG'];const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)};const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]);const legacySame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds);const modern=s=>s&&typeof s.sidecar_semantic_sha256==='string'&&typeof s.diagnosis_semantic_sha256==='string';const root=fs.realpathSync(process.cwd());const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');if(fs.existsSync(r)){const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r};const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8'));const hash=v=>crypto.createHash('sha256').update(v).digest('hex');const fileHash=p=>hash(fs.readFileSync(inside(p)));const normalizedDiagnosisHash=p=>hash(fs.readFileSync(inside(p),'utf8').replace(/\\s+/g,' ').trim());const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v);if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module');const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json';const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json';const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md';const behaviorPath='docs/behavior/'+mod+'.md';const data=readJson(contractPath);if(data.contract_version!=='diagnosis-contract/v1')fail('contract_version');if(data.module!==mod)fail('module_mismatch');if(data.diagnosis_artifact!==diagnosisPath)fail('diagnosis_artifact_path');if(!same(data.allowed_kinds,allowed))fail('allowed_kinds');const observed=Array.isArray(data.observed_failures)?data.observed_failures:fail('observed_failures');const work=Array.isArray(data.work_items)?data.work_items:fail('work_items');if(!observed.length)fail('empty_observed_failures');if(!work.length)fail('empty_work_items');const idOk=id=>typeof id==='string'&&/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id);const ids=new Set();for(const f of observed){if(!idOk(f&&f.id)||ids.has(f.id))fail('observed_failure_ids');ids.add(f.id)}const workIds=new Set();for(const item of work){if(!idOk(item&&item.id)||workIds.has(item.id))fail('work_item_ids');workIds.add(item.id)}const failureById=new Map();for(const f of observed){if(typeof f.test_name!=='string'||!f.test_name.trim())fail('observed_failure_test_name');if(typeof f.symptom!=='string'||!f.symptom.trim())fail('observed_failure_symptom');if(!Array.isArray(f.evidence_paths)||!f.evidence_paths.length)fail('observed_failure_evidence');for(const p of f.evidence_paths)inside(p);if(f.kind!==undefined)fail('observed_failure_kind_forbidden');failureById.set(f.id,f)}const mapped=new Set();for(const item of work){if(!allowed.includes(item.kind))fail('invalid_kind');if(item.kind==='PLACEHOLDER_CONTRACT')fail('placeholder_kind');if(!Array.isArray(item.observed_failure_ids)||!item.observed_failure_ids.length)fail('work_item_observed_failure_ids');if(!Array.isArray(item.evidence_paths)||!item.evidence_paths.length)fail('work_item_evidence');for(const p of item.evidence_paths)inside(p);if(action.includes(item.kind)){if(!Array.isArray(item.v1_evidence_paths)||!item.v1_evidence_paths.length)fail('work_item_v1_evidence');if(!Array.isArray(item.v2_evidence_paths)||!item.v2_evidence_paths.length)fail('work_item_v2_evidence');for(const p of item.v1_evidence_paths)inside(p);for(const p of item.v2_evidence_paths)inside(p)}for(const id of item.observed_failure_ids){const f=failureById.get(id);if(!f)fail('unknown_observed_failure_id');if(action.includes(item.kind)&&(!f.test_name||!String(f.test_name).trim()))fail('action_test_evidence');mapped.add(id)}}if(mapped.size!==ids.size)fail('unmapped_observed_failures');for(const f of observed.filter(x=>String(x.symptom).includes('PLACEHOLDER_CONTRACT'))){const kinds=new Set(work.filter(i=>i.observed_failure_ids.includes(f.id)).map(i=>i.kind));if(![...kinds].every(k=>k==='TEST_BUG'||k==='UNIMPLEMENTED')||kinds.size===0)fail('placeholder_mapping')}const counts=data.baseline&&data.baseline.counts;if(!data.baseline||!data.baseline.source_path||!counts)fail('baseline');for(const k of ['failed','skipped','hung']){if(!Number.isInteger(counts[k])||counts[k]<0)fail('baseline_count_'+k)}if(counts.failed+counts.skipped+counts.hung!==observed.length)fail('baseline_count_mismatch');const summary=data.summary_counts||{};for(const kind of allowed){if(!Number.isInteger(summary[kind])||summary[kind]!==work.filter(x=>x.kind===kind).length)fail('summary_count_'+kind)}const snap=data.contract_snapshot||{};const baselineHash=fileHash(data.baseline.source_path);const diagnosisHash=fileHash(diagnosisPath);if(snap.observed_failure_count!==observed.length||snap.work_item_count!==work.length||!same(snap.allowed_kinds,allowed))fail('contract_snapshot');if(snap.baseline_source_sha256!==baselineHash)fail('baseline_sha256');if(snap.diagnosis_artifact_sha256!==diagnosisHash)fail('diagnosis_sha256');const stale=data.staleness;if(!stale||stale.is_stale!==false)fail('stale_contract');const source=(entry,p,n,expected)=>{if(!entry||entry.path!==p)fail('staleness_'+n+'_path');if(entry.sha256!==expected)fail('staleness_'+n+'_sha256')};source(stale.behavior_doc,behaviorPath,'behavior_doc',fileHash(behaviorPath));source(stale.baseline,data.baseline.source_path,'baseline',baselineHash);source(stale.diagnosis_artifact,diagnosisPath,'diagnosis_artifact',diagnosisHash);const semantic=JSON.parse(JSON.stringify(data));delete semantic.contract_snapshot.sidecar_semantic_sha256;delete semantic.contract_snapshot.diagnosis_artifact_sha256;delete semantic.staleness.diagnosis_artifact;const sidecarSemanticHash=hash(canon(semantic));const diagnosisSemanticHash=normalizedDiagnosisHash(diagnosisPath);if(snap.sidecar_semantic_sha256!==sidecarSemanticHash||snap.diagnosis_semantic_sha256!==diagnosisSemanticHash)fail('contract_snapshot_semantic');if(fs.existsSync(inside(reviewPath))){const prev=readJson(reviewPath);if(prev.verdict==='REQUEST_REANALYSIS'){const ps=prev.contract_snapshot||{};const unchanged=modern(ps)?ps.sidecar_semantic_sha256===sidecarSemanticHash&&ps.diagnosis_semantic_sha256===diagnosisSemanticHash:legacySame(ps,snap);if(unchanged)fail('reanalysis_unchanged');const cm=fs.statSync(inside(contractPath)).mtimeMs;const dm=fs.statSync(inside(diagnosisPath)).mtimeMs;const rm=fs.statSync(inside(reviewPath)).mtimeMs;if(cm<=rm||dm<=rm)fail('reanalysis_not_rewritten')}}\""
|
|
608
|
+
- command_success: "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const crypto=require('node:crypto'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG']; const action=['BUG','UNIMPLEMENTED','INFRA','TEST_BUG']; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)}; const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const legacySame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); const modern=s=>s&&typeof s.sidecar_semantic_sha256==='string'&&typeof s.diagnosis_semantic_sha256==='string'; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8')); const hash=v=>crypto.createHash('sha256').update(v).digest('hex'); const fileHash=p=>hash(fs.readFileSync(inside(p))); const normalizedDiagnosisHash=p=>hash(fs.readFileSync(inside(p),'utf8').replace(/\\s+/g,' ').trim()); const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const progressPath='.dna/fix-progress/'+mod+'.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const behaviorPath='docs/behavior/'+mod+'.md'; const v1Root=rel('{{v1_path}}'); const v2Root=rel('{{v2_path}}'); if(v1Root==='.'||v2Root==='.'||under(v1Root,v2Root)||under(v2Root,v1Root))fail('configured_roots'); const data=readJson(contractPath); if(data.contract_version!=='diagnosis-contract/v2')fail('contract_version'); if(data.module!==mod)fail('module_mismatch'); if(data.diagnosis_artifact!==diagnosisPath)fail('diagnosis_artifact_path'); if(!same(data.allowed_kinds,allowed))fail('allowed_kinds'); const observed=Array.isArray(data.observed_failures)?data.observed_failures:fail('observed_failures'); const work=Array.isArray(data.work_items)?data.work_items:fail('work_items'); if(!observed.length)fail('empty_observed_failures'); if(!work.length)fail('empty_work_items'); const idOk=id=>typeof id==='string'&&/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id); const ids=new Set(); for(const f of observed){if(!idOk(f&&f.id)||ids.has(f.id))fail('observed_failure_ids');ids.add(f.id)} const workIds=new Set(); for(const item of work){if(!idOk(item&&item.id)||workIds.has(item.id))fail('work_item_ids');workIds.add(item.id)} const failureById=new Map(); for(const f of observed){if(typeof f.test_name!=='string'||!f.test_name.trim())fail('observed_failure_test_name');if(typeof f.symptom!=='string'||!f.symptom.trim())fail('observed_failure_symptom');if(!Array.isArray(f.evidence_paths)||!f.evidence_paths.length)fail('observed_failure_evidence');for(const p of f.evidence_paths)rel(p);if(f.kind!==undefined)fail('observed_failure_kind_forbidden');failureById.set(f.id,f)} const mapped=new Set(); const allAllowed=new Set(); const v1Evidence=new Set(); for(const item of work){if(!allowed.includes(item.kind))fail('invalid_kind');if(item.kind==='PLACEHOLDER_CONTRACT')fail('placeholder_kind');if(!Array.isArray(item.observed_failure_ids)||!item.observed_failure_ids.length)fail('work_item_observed_failure_ids');if(!Array.isArray(item.evidence_paths)||!item.evidence_paths.length)fail('work_item_evidence');for(const p of item.evidence_paths)rel(p);if(action.includes(item.kind)){if(!Array.isArray(item.v1_evidence_paths)||!item.v1_evidence_paths.length)fail('work_item_v1_evidence');if(!Array.isArray(item.v2_evidence_paths)||!item.v2_evidence_paths.length)fail('work_item_v2_evidence');const v2Evidence=new Set(item.v2_evidence_paths.map(rel));for(const p of item.v1_evidence_paths){const n=rel(p);if(!under(n,v1Root))fail('work_item_v1_evidence_root');v1Evidence.add(n)}for(const p of item.v2_evidence_paths)rel(p);if(!Array.isArray(item.allowed_change_paths)||!item.allowed_change_paths.length)fail('work_item_allowed_change_paths');const approved=new Set();for(const p of item.allowed_change_paths){if(typeof p!=='string'||['*','?','[',']'].some(c=>p.includes(c)))fail('work_item_allowed_change_path_pattern');const n=rel(p);const r=inside(p);if(under(n,v1Root))fail('work_item_allowed_change_path_v1');if(!(under(n,v2Root)||under(n,'test')||under(n,'lib')))fail('work_item_allowed_change_path_root');if(fs.existsSync(r)?!fs.statSync(r).isFile():!path.basename(n).includes('.'))fail('work_item_allowed_change_path_not_file');if(!v2Evidence.has(n))fail('work_item_allowed_change_path_not_evidence');if(approved.has(n))fail('work_item_allowed_change_path_duplicate');approved.add(n);allAllowed.add(n)}}for(const id of item.observed_failure_ids){const f=failureById.get(id);if(!f)fail('unknown_observed_failure_id');if(action.includes(item.kind)&&(!f.test_name||!String(f.test_name).trim()))fail('action_test_evidence');mapped.add(id)}} if(mapped.size!==ids.size)fail('unmapped_observed_failures'); for(const f of observed.filter(x=>String(x.symptom).includes('PLACEHOLDER_CONTRACT'))){const kinds=new Set(work.filter(i=>i.observed_failure_ids.includes(f.id)).map(i=>i.kind));if(![...kinds].every(k=>k==='TEST_BUG'||k==='UNIMPLEMENTED')||kinds.size===0)fail('placeholder_mapping')} const counts=data.baseline&&data.baseline.counts; if(!data.baseline||!data.baseline.source_path||!counts)fail('baseline'); for(const k of ['failed','skipped','hung']){if(!Number.isInteger(counts[k])||counts[k]<0)fail('baseline_count_'+k)} if(counts.failed+counts.skipped+counts.hung!==observed.length)fail('baseline_count_mismatch'); const summary=data.summary_counts||{}; for(const kind of allowed){if(!Number.isInteger(summary[kind])||summary[kind]!==work.filter(x=>x.kind===kind).length)fail('summary_count_'+kind)} const snap=data.contract_snapshot||{}; const baselineHash=fileHash(data.baseline.source_path); const diagnosisHash=fileHash(diagnosisPath); if(snap.observed_failure_count!==observed.length||snap.work_item_count!==work.length||!same(snap.allowed_kinds,allowed))fail('contract_snapshot'); if(snap.baseline_source_sha256!==baselineHash)fail('baseline_sha256'); if(snap.diagnosis_artifact_sha256!==diagnosisHash)fail('diagnosis_sha256'); const stale=data.staleness; if(!stale||stale.is_stale!==false)fail('stale_contract'); const source=(entry,p,n,expected)=>{if(!entry||entry.path!==p)fail('staleness_'+n+'_path');if(entry.sha256!==expected)fail('staleness_'+n+'_sha256')}; source(stale.behavior_doc,behaviorPath,'behavior_doc',fileHash(behaviorPath)); source(stale.baseline,data.baseline.source_path,'baseline',baselineHash); source(stale.diagnosis_artifact,diagnosisPath,'diagnosis_artifact',diagnosisHash); const expectedSources=[...new Set(work.filter(i=>action.includes(i.kind)).flatMap(i=>[...i.v1_evidence_paths,...i.v2_evidence_paths]).map(rel))].sort(); if(!Array.isArray(stale.source_files)||stale.source_files.length!==expectedSources.length)fail('staleness_source_files'); let relaxed=false; let head=''; if(fs.existsSync(inside(progressPath))){const progressMtime=fs.statSync(inside(progressPath)).mtimeMs;const artifactMtime=Math.max(fs.statSync(inside(contractPath)).mtimeMs,fs.statSync(inside(diagnosisPath)).mtimeMs,fs.existsSync(inside(reviewPath))?fs.statSync(inside(reviewPath)).mtimeMs:0);if(progressMtime>=artifactMtime){const progress=readJson(progressPath);head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim();if(progress.module!==mod||progress.verdict!=='CONTINUE'||progress.module_complete!==false||progress.diagnosis_invalid!==false)fail('progress_state');if(progress.diagnosis_artifact!==diagnosisPath||progress.review_artifact!=='.dna/reviews/'+mod+'-review.json')fail('progress_artifacts');if(progress.git_head!==head||progress.last_fix_commit!==head)fail('progress_commit');if(!Number.isInteger(progress.round)||progress.round<1||typeof progress.run_id!=='string'||!progress.run_id.trim())fail('progress_provenance');const progressTime=Date.parse(progress.updated_at);if(!Number.isFinite(progressTime)||progressTime+300000<artifactMtime)fail('progress_updated_at');relaxed=true}} const headState=p=>{try{const body=cp.execFileSync('git',['show',head+':'+p],{encoding:null,stdio:['ignore','pipe','ignore']});return {exists:true,sha256:hash(body)}}catch{return {exists:false,sha256:null}}}; const seenSources=new Set(); for(let i=0;i<expectedSources.length;i++){const p=expectedSources[i];const entry=stale.source_files[i];if(entry&&seenSources.has(entry.path))fail('staleness_source_file_duplicate');if(!entry||entry.path!==p)fail('staleness_source_file_path');seenSources.add(entry.path);if(typeof entry.exists!=='boolean')fail('staleness_source_file_exists');if(entry.exists?(typeof entry.sha256!=='string'||!/^[a-f0-9]{64}$/.test(entry.sha256)):entry.sha256!==null)fail('staleness_source_file_snapshot');if(v1Evidence.has(p)&&entry.exists!==true)fail('staleness_v1_source_missing');const r=inside(p);const currentExists=fs.existsSync(r);if(currentExists&&!fs.statSync(r).isFile())fail('staleness_source_file_not_file');const current={exists:currentExists,sha256:currentExists?fileHash(p):null};if(relaxed&&allAllowed.has(p)){const committed=headState(p);if(current.exists!==committed.exists||current.sha256!==committed.sha256)fail('staleness_source_file_uncommitted')}else if(current.exists!==entry.exists||current.sha256!==entry.sha256)fail('staleness_source_file_sha256')} const semantic=JSON.parse(JSON.stringify(data)); delete semantic.contract_snapshot.sidecar_semantic_sha256; delete semantic.contract_snapshot.diagnosis_artifact_sha256; delete semantic.staleness.diagnosis_artifact; const sidecarSemanticHash=hash(canon(semantic)); const diagnosisSemanticHash=normalizedDiagnosisHash(diagnosisPath); if(snap.sidecar_semantic_sha256!==sidecarSemanticHash||snap.diagnosis_semantic_sha256!==diagnosisSemanticHash)fail('contract_snapshot_semantic'); if(fs.existsSync(inside(reviewPath))){const prev=readJson(reviewPath);if(prev.verdict==='REQUEST_REANALYSIS'){const ps=prev.contract_snapshot||{};const unchanged=modern(ps)?ps.sidecar_semantic_sha256===sidecarSemanticHash&&ps.diagnosis_semantic_sha256===diagnosisSemanticHash:legacySame(ps,snap);if(unchanged)fail('reanalysis_unchanged');const cm=fs.statSync(inside(contractPath)).mtimeMs;const dm=fs.statSync(inside(diagnosisPath)).mtimeMs;const rm=fs.statSync(inside(reviewPath)).mtimeMs;if(cm<=rm||dm<=rm)fail('reanalysis_not_rewritten')}} \""
|
|
506
609
|
handoff:
|
|
507
610
|
produces:
|
|
508
611
|
- type: file
|
|
@@ -527,15 +630,17 @@ workflows:
|
|
|
527
630
|
4. Enough evidence detail for surgeon to act without adding fix prescriptions?
|
|
528
631
|
5. Diagnosis remains evidence-only: no implementation order, call-site instructions, or "Notes for Surgeon"?
|
|
529
632
|
6. .dna/specs/diagnosis-$ARGUMENTS.contract.json satisfies the structured sidecar contract:
|
|
530
|
-
- contract_version is "diagnosis-contract/
|
|
633
|
+
- contract_version is "diagnosis-contract/v2"
|
|
531
634
|
- allowed_kinds is exactly ["BUG", "UNIMPLEMENTED", "INFRA", "REMOVED", "TEST_BUG"]
|
|
532
635
|
- observed_failures and work_items are non-empty and every observed_failure is mapped
|
|
533
636
|
- baseline counts equal observed_failures count
|
|
534
637
|
- summary_counts match work_items by kind
|
|
535
|
-
- every work_item has evidence_paths and only allowed kinds
|
|
638
|
+
- every work_item has evidence_paths and only allowed kinds; every actionable work_item also has non-empty v1_evidence_paths, v2_evidence_paths, and allowed_change_paths
|
|
639
|
+
- allowed_change_paths are exact project-relative files also listed in v2_evidence_paths; directories, broad roots, globs, duplicates, and configured v1 source paths are invalid
|
|
640
|
+
- supporting paths in another v2 package are valid in-diagnosis scope when the work item evidence proves they are required
|
|
536
641
|
- PLACEHOLDER_CONTRACT is rejected as a kind but placeholder-contract symptoms are allowed when mapped to TEST_BUG and/or UNIMPLEMENTED
|
|
537
642
|
- contract_snapshot includes diagnosis_artifact_sha256, baseline_source_sha256, sidecar_semantic_sha256, diagnosis_semantic_sha256, observed_failure_count, work_item_count, and allowed_kinds
|
|
538
|
-
- staleness.is_stale is false
|
|
643
|
+
- staleness.is_stale is false; behavior_doc, baseline, and diagnosis_artifact path+sha256 entries match current project files; source_files exactly and freshly snapshots sorted unique actionable v1/v2 evidence source existence and hashes
|
|
539
644
|
- independently recompute hashes with mcp__intentdna__dna_artifact_digest using the same bytes, whitespace_normalized_text, and canonical_json modes; canonical_json must omit /contract_snapshot/sidecar_semantic_sha256, /contract_snapshot/diagnosis_artifact_sha256, and /staleness/diagnosis_artifact
|
|
540
645
|
- REMOVED work_items are reviewable diagnosis facts only and must not authorize automatic fix execution
|
|
541
646
|
|
|
@@ -570,7 +675,8 @@ workflows:
|
|
|
570
675
|
APPROVE → diagnosis complete.
|
|
571
676
|
REQUEST_REANALYSIS → sections_to_fix must be passed back to analyze. If contract_valid is false, set failure_reason to DIAGNOSIS_CONTRACT_INVALID and include the exact invalid rule in sections_to_fix. docs/behavior/blocked_items.md is historical context only and must not be treated as the current run verdict.
|
|
572
677
|
completion:
|
|
573
|
-
- command_success: "node -e \"const fs=require('node:fs');const crypto=require('node:crypto');const path=require('node:path');const mod=process.env.ARGUMENTS||'$ARGUMENTS';const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG'];const action=['BUG','UNIMPLEMENTED','INFRA','TEST_BUG'];const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)};const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]);const snapSame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.sidecar_semantic_sha256===b.sidecar_semantic_sha256&&a.diagnosis_semantic_sha256===b.diagnosis_semantic_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds);const root=fs.realpathSync(process.cwd());const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');if(fs.existsSync(r)){const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r};const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8'));const hash=v=>crypto.createHash('sha256').update(v).digest('hex');const fileHash=p=>hash(fs.readFileSync(inside(p)));const normalizedDiagnosisHash=p=>hash(fs.readFileSync(inside(p),'utf8').replace(/\\s+/g,' ').trim());const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v);if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module');const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json';const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json';const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md';const behaviorPath='docs/behavior/'+mod+'.md';const data=readJson(contractPath);if(data.contract_version!=='diagnosis-contract/v1')fail('contract_version');if(data.module!==mod)fail('module_mismatch');if(data.diagnosis_artifact!==diagnosisPath)fail('diagnosis_artifact_path');if(!same(data.allowed_kinds,allowed))fail('allowed_kinds');const observed=Array.isArray(data.observed_failures)?data.observed_failures:fail('observed_failures');const work=Array.isArray(data.work_items)?data.work_items:fail('work_items');if(!observed.length)fail('empty_observed_failures');if(!work.length)fail('empty_work_items');const idOk=id=>typeof id==='string'&&/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id);const ids=new Set();for(const f of observed){if(!idOk(f&&f.id)||ids.has(f.id))fail('observed_failure_ids');ids.add(f.id)}const workIds=new Set();for(const item of work){if(!idOk(item&&item.id)||workIds.has(item.id))fail('work_item_ids');workIds.add(item.id)}const failureById=new Map();for(const f of observed){if(typeof f.test_name!=='string'||!f.test_name.trim())fail('observed_failure_test_name');if(typeof f.symptom!=='string'||!f.symptom.trim())fail('observed_failure_symptom');if(!Array.isArray(f.evidence_paths)||!f.evidence_paths.length)fail('observed_failure_evidence');for(const p of f.evidence_paths)inside(p);if(f.kind!==undefined)fail('observed_failure_kind_forbidden');failureById.set(f.id,f)}const mapped=new Set();for(const item of work){if(!allowed.includes(item.kind))fail('invalid_kind');if(item.kind==='PLACEHOLDER_CONTRACT')fail('placeholder_kind');if(!Array.isArray(item.observed_failure_ids)||!item.observed_failure_ids.length)fail('work_item_observed_failure_ids');if(!Array.isArray(item.evidence_paths)||!item.evidence_paths.length)fail('work_item_evidence');for(const p of item.evidence_paths)inside(p);if(action.includes(item.kind)){if(!Array.isArray(item.v1_evidence_paths)||!item.v1_evidence_paths.length)fail('work_item_v1_evidence');if(!Array.isArray(item.v2_evidence_paths)||!item.v2_evidence_paths.length)fail('work_item_v2_evidence');for(const p of item.v1_evidence_paths)inside(p);for(const p of item.v2_evidence_paths)inside(p)}for(const id of item.observed_failure_ids){const f=failureById.get(id);if(!f)fail('unknown_observed_failure_id');if(action.includes(item.kind)&&(!f.test_name||!String(f.test_name).trim()))fail('action_test_evidence');mapped.add(id)}}if(mapped.size!==ids.size)fail('unmapped_observed_failures');for(const f of observed.filter(x=>String(x.symptom).includes('PLACEHOLDER_CONTRACT'))){const kinds=new Set(work.filter(i=>i.observed_failure_ids.includes(f.id)).map(i=>i.kind));if(![...kinds].every(k=>k==='TEST_BUG'||k==='UNIMPLEMENTED')||kinds.size===0)fail('placeholder_mapping')}const counts=data.baseline&&data.baseline.counts;if(!data.baseline||!data.baseline.source_path||!counts)fail('baseline');for(const k of ['failed','skipped','hung']){if(!Number.isInteger(counts[k])||counts[k]<0)fail('baseline_count_'+k)}if(counts.failed+counts.skipped+counts.hung!==observed.length)fail('baseline_count_mismatch');const summary=data.summary_counts||{};for(const kind of allowed){if(!Number.isInteger(summary[kind])||summary[kind]!==work.filter(x=>x.kind===kind).length)fail('summary_count_'+kind)}const snap=data.contract_snapshot||{};const baselineHash=fileHash(data.baseline.source_path);const diagnosisHash=fileHash(diagnosisPath);if(snap.observed_failure_count!==observed.length||snap.work_item_count!==work.length||!same(snap.allowed_kinds,allowed))fail('contract_snapshot');if(snap.baseline_source_sha256!==baselineHash)fail('baseline_sha256');if(snap.diagnosis_artifact_sha256!==diagnosisHash)fail('diagnosis_sha256');const stale=data.staleness;if(!stale||stale.is_stale!==false)fail('stale_contract');const source=(entry,p,n,expected)=>{if(!entry||entry.path!==p)fail('staleness_'+n+'_path');if(entry.sha256!==expected)fail('staleness_'+n+'_sha256')};source(stale.behavior_doc,behaviorPath,'behavior_doc',fileHash(behaviorPath));source(stale.baseline,data.baseline.source_path,'baseline',baselineHash);source(stale.diagnosis_artifact,diagnosisPath,'diagnosis_artifact',diagnosisHash);const semantic=JSON.parse(JSON.stringify(data));delete semantic.contract_snapshot.sidecar_semantic_sha256;delete semantic.contract_snapshot.diagnosis_artifact_sha256;delete semantic.staleness.diagnosis_artifact;const sidecarSemanticHash=hash(canon(semantic));const diagnosisSemanticHash=normalizedDiagnosisHash(diagnosisPath);if(snap.sidecar_semantic_sha256!==sidecarSemanticHash||snap.diagnosis_semantic_sha256!==diagnosisSemanticHash)fail('contract_snapshot_semantic');const review=readJson(reviewPath);if(review.contract_version!=='diagnosis-contract-review/v1')fail('review_contract_version');if(review.contract_valid!==true)fail('review_contract_valid');if(review.verdict!=='APPROVE')fail('review_verdict');if(review.contract_artifact_reviewed!==contractPath)fail('review_contract_artifact_path');if(review.artifact_reviewed!==diagnosisPath)fail('review_artifact_path');if(!snapSame(review.contract_snapshot,snap))fail('review_contract_snapshot');if(!review.updated_at||Number.isNaN(Date.parse(review.updated_at)))fail('review_updated_at');if(!Array.isArray(review.evidence_paths)||!review.evidence_paths.length)fail('review_evidence_paths');for(const p of review.evidence_paths)inside(p);const cm=fs.statSync(inside(contractPath)).mtimeMs;const dm=fs.statSync(inside(diagnosisPath)).mtimeMs;const rm=fs.statSync(inside(reviewPath)).mtimeMs;if(rm<cm||rm<dm)fail('review_stale');\""
|
|
678
|
+
- command_success: "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const crypto=require('node:crypto'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG']; const action=['BUG','UNIMPLEMENTED','INFRA','TEST_BUG']; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)}; const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const legacySame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); const modern=s=>s&&typeof s.sidecar_semantic_sha256==='string'&&typeof s.diagnosis_semantic_sha256==='string'; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8')); const hash=v=>crypto.createHash('sha256').update(v).digest('hex'); const fileHash=p=>hash(fs.readFileSync(inside(p))); const normalizedDiagnosisHash=p=>hash(fs.readFileSync(inside(p),'utf8').replace(/\\s+/g,' ').trim()); const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const progressPath='.dna/fix-progress/'+mod+'.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const behaviorPath='docs/behavior/'+mod+'.md'; const v1Root=rel('{{v1_path}}'); const v2Root=rel('{{v2_path}}'); if(v1Root==='.'||v2Root==='.'||under(v1Root,v2Root)||under(v2Root,v1Root))fail('configured_roots'); const data=readJson(contractPath); if(data.contract_version!=='diagnosis-contract/v2')fail('contract_version'); if(data.module!==mod)fail('module_mismatch'); if(data.diagnosis_artifact!==diagnosisPath)fail('diagnosis_artifact_path'); if(!same(data.allowed_kinds,allowed))fail('allowed_kinds'); const observed=Array.isArray(data.observed_failures)?data.observed_failures:fail('observed_failures'); const work=Array.isArray(data.work_items)?data.work_items:fail('work_items'); if(!observed.length)fail('empty_observed_failures'); if(!work.length)fail('empty_work_items'); const idOk=id=>typeof id==='string'&&/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id); const ids=new Set(); for(const f of observed){if(!idOk(f&&f.id)||ids.has(f.id))fail('observed_failure_ids');ids.add(f.id)} const workIds=new Set(); for(const item of work){if(!idOk(item&&item.id)||workIds.has(item.id))fail('work_item_ids');workIds.add(item.id)} const failureById=new Map(); for(const f of observed){if(typeof f.test_name!=='string'||!f.test_name.trim())fail('observed_failure_test_name');if(typeof f.symptom!=='string'||!f.symptom.trim())fail('observed_failure_symptom');if(!Array.isArray(f.evidence_paths)||!f.evidence_paths.length)fail('observed_failure_evidence');for(const p of f.evidence_paths)rel(p);if(f.kind!==undefined)fail('observed_failure_kind_forbidden');failureById.set(f.id,f)} const mapped=new Set(); const allAllowed=new Set(); const v1Evidence=new Set(); for(const item of work){if(!allowed.includes(item.kind))fail('invalid_kind');if(item.kind==='PLACEHOLDER_CONTRACT')fail('placeholder_kind');if(!Array.isArray(item.observed_failure_ids)||!item.observed_failure_ids.length)fail('work_item_observed_failure_ids');if(!Array.isArray(item.evidence_paths)||!item.evidence_paths.length)fail('work_item_evidence');for(const p of item.evidence_paths)rel(p);if(action.includes(item.kind)){if(!Array.isArray(item.v1_evidence_paths)||!item.v1_evidence_paths.length)fail('work_item_v1_evidence');if(!Array.isArray(item.v2_evidence_paths)||!item.v2_evidence_paths.length)fail('work_item_v2_evidence');const v2Evidence=new Set(item.v2_evidence_paths.map(rel));for(const p of item.v1_evidence_paths){const n=rel(p);if(!under(n,v1Root))fail('work_item_v1_evidence_root');v1Evidence.add(n)}for(const p of item.v2_evidence_paths)rel(p);if(!Array.isArray(item.allowed_change_paths)||!item.allowed_change_paths.length)fail('work_item_allowed_change_paths');const approved=new Set();for(const p of item.allowed_change_paths){if(typeof p!=='string'||['*','?','[',']'].some(c=>p.includes(c)))fail('work_item_allowed_change_path_pattern');const n=rel(p);const r=inside(p);if(under(n,v1Root))fail('work_item_allowed_change_path_v1');if(!(under(n,v2Root)||under(n,'test')||under(n,'lib')))fail('work_item_allowed_change_path_root');if(fs.existsSync(r)?!fs.statSync(r).isFile():!path.basename(n).includes('.'))fail('work_item_allowed_change_path_not_file');if(!v2Evidence.has(n))fail('work_item_allowed_change_path_not_evidence');if(approved.has(n))fail('work_item_allowed_change_path_duplicate');approved.add(n);allAllowed.add(n)}}for(const id of item.observed_failure_ids){const f=failureById.get(id);if(!f)fail('unknown_observed_failure_id');if(action.includes(item.kind)&&(!f.test_name||!String(f.test_name).trim()))fail('action_test_evidence');mapped.add(id)}} if(mapped.size!==ids.size)fail('unmapped_observed_failures'); for(const f of observed.filter(x=>String(x.symptom).includes('PLACEHOLDER_CONTRACT'))){const kinds=new Set(work.filter(i=>i.observed_failure_ids.includes(f.id)).map(i=>i.kind));if(![...kinds].every(k=>k==='TEST_BUG'||k==='UNIMPLEMENTED')||kinds.size===0)fail('placeholder_mapping')} const counts=data.baseline&&data.baseline.counts; if(!data.baseline||!data.baseline.source_path||!counts)fail('baseline'); for(const k of ['failed','skipped','hung']){if(!Number.isInteger(counts[k])||counts[k]<0)fail('baseline_count_'+k)} if(counts.failed+counts.skipped+counts.hung!==observed.length)fail('baseline_count_mismatch'); const summary=data.summary_counts||{}; for(const kind of allowed){if(!Number.isInteger(summary[kind])||summary[kind]!==work.filter(x=>x.kind===kind).length)fail('summary_count_'+kind)} const snap=data.contract_snapshot||{}; const baselineHash=fileHash(data.baseline.source_path); const diagnosisHash=fileHash(diagnosisPath); if(snap.observed_failure_count!==observed.length||snap.work_item_count!==work.length||!same(snap.allowed_kinds,allowed))fail('contract_snapshot'); if(snap.baseline_source_sha256!==baselineHash)fail('baseline_sha256'); if(snap.diagnosis_artifact_sha256!==diagnosisHash)fail('diagnosis_sha256'); const stale=data.staleness; if(!stale||stale.is_stale!==false)fail('stale_contract'); const source=(entry,p,n,expected)=>{if(!entry||entry.path!==p)fail('staleness_'+n+'_path');if(entry.sha256!==expected)fail('staleness_'+n+'_sha256')}; source(stale.behavior_doc,behaviorPath,'behavior_doc',fileHash(behaviorPath)); source(stale.baseline,data.baseline.source_path,'baseline',baselineHash); source(stale.diagnosis_artifact,diagnosisPath,'diagnosis_artifact',diagnosisHash); const expectedSources=[...new Set(work.filter(i=>action.includes(i.kind)).flatMap(i=>[...i.v1_evidence_paths,...i.v2_evidence_paths]).map(rel))].sort(); if(!Array.isArray(stale.source_files)||stale.source_files.length!==expectedSources.length)fail('staleness_source_files'); let relaxed=false; let head=''; if(fs.existsSync(inside(progressPath))){const progressMtime=fs.statSync(inside(progressPath)).mtimeMs;const artifactMtime=Math.max(fs.statSync(inside(contractPath)).mtimeMs,fs.statSync(inside(diagnosisPath)).mtimeMs,fs.existsSync(inside(reviewPath))?fs.statSync(inside(reviewPath)).mtimeMs:0);if(progressMtime>=artifactMtime){const progress=readJson(progressPath);head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim();if(progress.module!==mod||progress.verdict!=='CONTINUE'||progress.module_complete!==false||progress.diagnosis_invalid!==false)fail('progress_state');if(progress.diagnosis_artifact!==diagnosisPath||progress.review_artifact!=='.dna/reviews/'+mod+'-review.json')fail('progress_artifacts');if(progress.git_head!==head||progress.last_fix_commit!==head)fail('progress_commit');if(!Number.isInteger(progress.round)||progress.round<1||typeof progress.run_id!=='string'||!progress.run_id.trim())fail('progress_provenance');const progressTime=Date.parse(progress.updated_at);if(!Number.isFinite(progressTime)||progressTime+300000<artifactMtime)fail('progress_updated_at');relaxed=true}} const headState=p=>{try{const body=cp.execFileSync('git',['show',head+':'+p],{encoding:null,stdio:['ignore','pipe','ignore']});return {exists:true,sha256:hash(body)}}catch{return {exists:false,sha256:null}}}; const seenSources=new Set(); for(let i=0;i<expectedSources.length;i++){const p=expectedSources[i];const entry=stale.source_files[i];if(entry&&seenSources.has(entry.path))fail('staleness_source_file_duplicate');if(!entry||entry.path!==p)fail('staleness_source_file_path');seenSources.add(entry.path);if(typeof entry.exists!=='boolean')fail('staleness_source_file_exists');if(entry.exists?(typeof entry.sha256!=='string'||!/^[a-f0-9]{64}$/.test(entry.sha256)):entry.sha256!==null)fail('staleness_source_file_snapshot');if(v1Evidence.has(p)&&entry.exists!==true)fail('staleness_v1_source_missing');const r=inside(p);const currentExists=fs.existsSync(r);if(currentExists&&!fs.statSync(r).isFile())fail('staleness_source_file_not_file');const current={exists:currentExists,sha256:currentExists?fileHash(p):null};if(relaxed&&allAllowed.has(p)){const committed=headState(p);if(current.exists!==committed.exists||current.sha256!==committed.sha256)fail('staleness_source_file_uncommitted')}else if(current.exists!==entry.exists||current.sha256!==entry.sha256)fail('staleness_source_file_sha256')} const semantic=JSON.parse(JSON.stringify(data)); delete semantic.contract_snapshot.sidecar_semantic_sha256; delete semantic.contract_snapshot.diagnosis_artifact_sha256; delete semantic.staleness.diagnosis_artifact; const sidecarSemanticHash=hash(canon(semantic)); const diagnosisSemanticHash=normalizedDiagnosisHash(diagnosisPath); if(snap.sidecar_semantic_sha256!==sidecarSemanticHash||snap.diagnosis_semantic_sha256!==diagnosisSemanticHash)fail('contract_snapshot_semantic'); if(fs.existsSync(inside(reviewPath))){const prev=readJson(reviewPath);if(prev.verdict==='REQUEST_REANALYSIS'){const ps=prev.contract_snapshot||{};const unchanged=modern(ps)?ps.sidecar_semantic_sha256===sidecarSemanticHash&&ps.diagnosis_semantic_sha256===diagnosisSemanticHash:legacySame(ps,snap);if(unchanged)fail('reanalysis_unchanged');const cm=fs.statSync(inside(contractPath)).mtimeMs;const dm=fs.statSync(inside(diagnosisPath)).mtimeMs;const rm=fs.statSync(inside(reviewPath)).mtimeMs;if(cm<=rm||dm<=rm)fail('reanalysis_not_rewritten')}} \""
|
|
679
|
+
- command_success: "node -e \"const fs=require('node:fs'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const allowed=['BUG','UNIMPLEMENTED','INFRA','REMOVED','TEST_BUG']; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:'+m);process.exit(1)}; const same=(a,b)=>Array.isArray(a)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const snapSame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.sidecar_semantic_sha256===b.sidecar_semantic_sha256&&a.diagnosis_semantic_sha256===b.diagnosis_semantic_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const readJson=p=>JSON.parse(fs.readFileSync(inside(p),'utf8')); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const data=readJson(contractPath); const snap=data.contract_snapshot||{}; if(data.contract_version!=='diagnosis-contract/v2'||data.module!==mod)fail('contract_version'); const review=readJson(reviewPath); if(review.contract_version!=='diagnosis-contract-review/v1')fail('review_contract_version'); if(review.contract_valid!==true)fail('review_contract_valid'); if(review.verdict!=='APPROVE')fail('review_verdict'); if(review.contract_artifact_reviewed!==contractPath)fail('review_contract_artifact_path'); if(review.artifact_reviewed!==diagnosisPath)fail('review_artifact_path'); if(!snapSame(review.contract_snapshot,snap))fail('review_contract_snapshot'); const updated=Date.parse(review.updated_at); if(!Number.isFinite(updated))fail('review_updated_at'); if(!Array.isArray(review.evidence_paths)||!review.evidence_paths.length)fail('review_evidence_paths'); for(const p of review.evidence_paths){const r=inside(p);if(!fs.existsSync(r)||!fs.statSync(r).isFile())fail('review_evidence_paths')} const cm=fs.statSync(inside(contractPath)).mtimeMs; const dm=fs.statSync(inside(diagnosisPath)).mtimeMs; const rm=fs.statSync(inside(reviewPath)).mtimeMs; if(rm<cm||rm<dm||updated+300000<Math.max(cm,dm)||Math.abs(rm-updated)>300000)fail('review_stale'); \""
|
|
574
680
|
handoff:
|
|
575
681
|
consumes:
|
|
576
682
|
- type: file
|
|
@@ -601,7 +707,11 @@ workflows:
|
|
|
601
707
|
Before editing, read .dna/specs/diagnosis-$ARGUMENTS.review.json.
|
|
602
708
|
- If it is missing, invalid, or verdict is not APPROVE, stop immediately; do not edit.
|
|
603
709
|
- Also read .dna/specs/diagnosis-$ARGUMENTS.contract.json and perform the same preflight used by the diagnosis review completion validator before any Edit.
|
|
604
|
-
-
|
|
710
|
+
- The sidecar must use diagnosis-contract/v2. Older contracts must fail closed and trigger fresh diagnosis automatically.
|
|
711
|
+
- If the sidecar is missing, invalid, stale, has unmapped observed_failures, bad counts, missing/broad allowed_change_paths, incomplete/stale source_files snapshots, bad snapshot, unsupported kinds, or review contract_valid is not true, stop before edits with DIAGNOSIS_CONTRACT_INVALID.
|
|
712
|
+
- Before the first fix round, every source_files existence/hash must match exactly.
|
|
713
|
+
- On a later invocation with valid progress provenance, do not reject an approved v2 source merely because a prior verified fix round changed it. Such drift is valid only when the file is an exact allowed_change_paths entry, progress git_head and last_fix_commit equal current HEAD, and the working file equals HEAD.
|
|
714
|
+
- Configured v1 evidence, unapproved v2 evidence, uncommitted changes, HEAD/progress mismatches, and drift after diagnosis reanalysis remain DIAGNOSIS_CONTRACT_INVALID.
|
|
605
715
|
- If stopping for DIAGNOSIS_CONTRACT_INVALID, write/update .dna/fix-progress/$ARGUMENTS.json with verdict BLOCKED, failure_reason DIAGNOSIS_CONTRACT_INVALID, diagnosis_invalid true, and evidence_paths naming the sidecar/review problem; also update the markdown progress artifact.
|
|
606
716
|
- Manual fix invocations must obey this same gate.
|
|
607
717
|
- If verdict is REQUEST_REANALYSIS, run diagnosis reanalysis first instead of fixing.
|
|
@@ -622,20 +732,31 @@ workflows:
|
|
|
622
732
|
REMOVED is always skipped unless the user explicitly approved handling it.
|
|
623
733
|
REMOVED must never be auto-executed from diagnosis contract membership alone.
|
|
624
734
|
|
|
735
|
+
Repair authority:
|
|
736
|
+
- For each actionable work item, allowed_change_paths is the complete edit boundary.
|
|
737
|
+
- You may edit only an exact file listed by that work item. Directories and globs never grant repair authority.
|
|
738
|
+
- Every repair file must also be listed in that work item's v2_evidence_paths and covered by its source_files existence/hash snapshot.
|
|
739
|
+
- A listed supporting path in another v2 package, including core/device infrastructure, is in-diagnosis scope and must be repaired in this session when needed by the target behavior.
|
|
740
|
+
- One session means one target behavior module, not one physical package. Do not ask for a capability id and do not require the user to run core-align first.
|
|
741
|
+
- Never edit v1_evidence_paths or any path under the configured {{v1_path}} source root.
|
|
742
|
+
- If the required path is not listed, stop before touching it and request diagnosis reanalysis to add evidence-backed allowed_change_paths.
|
|
743
|
+
|
|
625
744
|
For each issue:
|
|
626
745
|
- BUG: read v1 file, edit v2 (use Riverpod per refactoring-workflow-v2.md)
|
|
627
746
|
- TEST_BUG: re-read v1, edit test to match v1 behavior
|
|
628
|
-
- INFRA: edit
|
|
747
|
+
- INFRA: edit only the approved test/helper paths in allowed_change_paths; do NOT touch unapproved v2/lib
|
|
629
748
|
- UNIMPLEMENTED: read v1 impl, implement in v2 style, remove skip marker from test
|
|
630
749
|
|
|
631
750
|
Continue within the round while changes are coherent and reviewable. If the remaining work is large, stop at a natural boundary and leave the rest for the next fix round.
|
|
632
751
|
|
|
633
752
|
Shared boundary rule:
|
|
634
|
-
- If this round changes an interface, abstract class, provider, initializer, repository contract, constructor, public model/DTO, fake/mock, or test helper, search for affected fake/mock/helper implementations
|
|
753
|
+
- If this round changes an interface, abstract class, provider, initializer, repository contract, constructor, public model/DTO, fake/mock, or test helper, search for affected fake/mock/helper implementations. Update them in the same round only when their exact file or narrow directory is also authorized by the targeted work item's allowed_change_paths; otherwise request diagnosis reanalysis before editing.
|
|
635
754
|
- In that case, run the targeted test plus the affected module behavior suite once when practical; do not wait for final verification to discover compile/load failures caused by stale test fakes.
|
|
636
755
|
|
|
637
756
|
After each fix: run tests ONCE for that specific file unless the shared boundary rule requires the affected module behavior suite.
|
|
638
|
-
Commit only the round's coherent changes, with message including what changed, why, and which tests were targeted.
|
|
757
|
+
Commit only the round's coherent changes, with message including what changed, why, and which tests were targeted. The completion gate compares every file in the current HEAD commit with the approved allowed_change_paths set and rejects any extra path.
|
|
758
|
+
completion:
|
|
759
|
+
- command_success: "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); const crypto=require('node:crypto'); const path=require('node:path'); const mod=process.env.ARGUMENTS||'$ARGUMENTS'; const fail=m=>{console.error('INTENTDNA_DIAGNOSTIC:fix_scope_'+m);process.exit(1)}; const root=fs.realpathSync(process.cwd()); const inside=p=>{if(typeof p!=='string'||!p||path.isAbsolute(p))fail('path_invalid');const r=path.resolve(root,p);if(r!==root&&!r.startsWith(root+path.sep))fail('path_escape');let stat=null;try{stat=fs.lstatSync(r)}catch(e){if(!e||e.code!=='ENOENT')fail('path_unreadable')}if(stat){if(stat.isSymbolicLink())fail('path_symlink');const real=fs.realpathSync(r);if(real!==root&&!real.startsWith(root+path.sep))fail('path_escape')}return r}; const rel=p=>path.relative(root,inside(p)).split(path.sep).join('/')||'.'; const under=(p,base)=>p===base||p.startsWith(base+'/'); const hash=v=>crypto.createHash('sha256').update(v).digest('hex'); const canon=v=>Array.isArray(v)?'['+v.map(canon).join(',')+']':v&&typeof v==='object'?'{'+Object.keys(v).sort().map(k=>JSON.stringify(k)+':'+canon(v[k])).join(',')+'}':JSON.stringify(v); const same=(a,b)=>Array.isArray(a)&&Array.isArray(b)&&a.length===b.length&&a.every((v,i)=>v===b[i]); const snapSame=(a,b)=>a&&b&&a.baseline_source_sha256===b.baseline_source_sha256&&a.diagnosis_artifact_sha256===b.diagnosis_artifact_sha256&&a.sidecar_semantic_sha256===b.sidecar_semantic_sha256&&a.diagnosis_semantic_sha256===b.diagnosis_semantic_sha256&&a.observed_failure_count===b.observed_failure_count&&a.work_item_count===b.work_item_count&&same(a.allowed_kinds,b.allowed_kinds); if(!/^[A-Za-z0-9_-]+$/.test(mod))fail('module'); const contractPath='.dna/specs/diagnosis-'+mod+'.contract.json'; const reviewPath='.dna/specs/diagnosis-'+mod+'.review.json'; const diagnosisPath='.dna/specs/diagnosis-'+mod+'.md'; const data=JSON.parse(fs.readFileSync(inside(contractPath),'utf8')); if(data.contract_version!=='diagnosis-contract/v2'||data.module!==mod||data.diagnosis_artifact!==diagnosisPath)fail('contract'); const snap=data.contract_snapshot||{}; const semantic=JSON.parse(JSON.stringify(data)); delete semantic.contract_snapshot.sidecar_semantic_sha256; delete semantic.contract_snapshot.diagnosis_artifact_sha256; delete semantic.staleness.diagnosis_artifact; if(snap.sidecar_semantic_sha256!==hash(canon(semantic)))fail('contract_snapshot'); const review=JSON.parse(fs.readFileSync(inside(reviewPath),'utf8')); if(review.contract_version!=='diagnosis-contract-review/v1'||review.contract_valid!==true||review.verdict!=='APPROVE')fail('review'); if(review.contract_artifact_reviewed!==contractPath||review.artifact_reviewed!==diagnosisPath||!snapSame(review.contract_snapshot,snap))fail('review_snapshot'); if(!Array.isArray(review.evidence_paths)||!review.evidence_paths.length)fail('review_evidence'); for(const p of review.evidence_paths){const r=inside(p);if(!fs.existsSync(r)||!fs.statSync(r).isFile())fail('review_evidence')} const cm=fs.statSync(inside(contractPath)).mtimeMs; const rm=fs.statSync(inside(reviewPath)).mtimeMs; const updated=Date.parse(review.updated_at); if(!Number.isFinite(updated)||rm<cm||updated+300000<cm||Math.abs(rm-updated)>300000)fail('review_stale'); const v1=rel('{{v1_path}}'); const v2=rel('{{v2_path}}'); const action=new Set(['BUG','UNIMPLEMENTED','INFRA','TEST_BUG']); const allowed=new Set(); for(const item of data.work_items||[]){if(!action.has(item.kind))continue;const evidence=new Set((item.v2_evidence_paths||[]).map(rel));for(const p of item.allowed_change_paths||[]){if(typeof p!=='string'||['*','?','[',']'].some(c=>p.includes(c)))fail('allowed_path_pattern');const n=rel(p);const r=inside(p);if(under(n,v1))fail('v1_change');if(!(under(n,v2)||under(n,'test')||under(n,'lib')))fail('allowed_path_root');if(fs.existsSync(r)?!fs.statSync(r).isFile():!path.basename(n).includes('.'))fail('allowed_path_not_file');if(!evidence.has(n))fail('allowed_path_not_evidence');allowed.add(n)}} if(!allowed.size)fail('allowed_paths'); const head=cp.execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8'}).trim(); const output=cp.execFileSync('git',['diff-tree','--root','--no-commit-id','--name-only','-r',head],{encoding:'utf8'}).trim(); const changed=output?output.split(/\\r?\\n/).filter(Boolean):[]; if(!changed.length)fail('empty_commit'); for(const p of changed){const n=rel(p);if(under(n,v1))fail('v1_change');if(!allowed.has(n))fail('outside_diagnosis')} const dirty=cp.execFileSync('git',['status','--porcelain','--untracked-files=all','--',...allowed],{encoding:'utf8'}).trim(); if(dirty)fail('uncommitted_allowed_path'); \""
|
|
639
760
|
handoff:
|
|
640
761
|
consumes:
|
|
641
762
|
- type: file
|
|
@@ -656,15 +777,17 @@ workflows:
|
|
|
656
777
|
depends_on: [fix_bugs]
|
|
657
778
|
description: "Review surgeon changes before verification"
|
|
658
779
|
prompt: |
|
|
659
|
-
Read diagnosis spec and behavior doc before reviewing the surgeon's handoff changes.
|
|
780
|
+
Read diagnosis spec, diagnosis-contract/v2 sidecar, and behavior doc before reviewing the surgeon's handoff changes.
|
|
660
781
|
|
|
661
782
|
Review only the surgeon's handoff changes:
|
|
662
|
-
1.
|
|
783
|
+
1. Identify the actionable diagnosis work_items addressed by the diff. Is every changed path an exact allowed_change_paths file for those work_items, and is each repair file also listed in that work item's v2_evidence_paths?
|
|
663
784
|
2. Is REMOVED handling absent unless explicitly approved by user?
|
|
664
785
|
3. Does implementation preserve v1 behavior and follow v2 architecture?
|
|
665
786
|
4. Are test infra changes honest, not fake mocks?
|
|
666
787
|
5. If shared interfaces/providers/initializers/contracts/constructors/models or test helpers changed, were affected fake/mock/helper implementations searched and synchronized?
|
|
667
788
|
6. Is there unrelated refactor or scope creep?
|
|
789
|
+
7. Do not classify a supporting path as outside_diagnosis merely because it belongs to another v2 package. If the approved work item lists it in allowed_change_paths, it is in_diagnosis.
|
|
790
|
+
8. A changed path not exactly covered by the targeted work_items' allowed_change_paths is outside_diagnosis and must be rejected. Confirm the deterministic fix-scope completion gate passed for the current HEAD commit.
|
|
668
791
|
|
|
669
792
|
Output exactly one structured verdict block:
|
|
670
793
|
```json
|
|
@@ -693,7 +816,7 @@ workflows:
|
|
|
693
816
|
- run_id is required and must equal the provided controller_run_id, or "manual-run" for manual fix invocation.
|
|
694
817
|
- actionability, scope, risk, and updated_at are required.
|
|
695
818
|
- APPROVE → actionability/scope/risk should be none, issues empty, failure_reason empty, next_round_focus empty.
|
|
696
|
-
- REQUEST_CHANGES can continue automatically only when actionability is actionable, scope is in_diagnosis, risk is low or medium, and next_round_focus is concrete.
|
|
819
|
+
- REQUEST_CHANGES can continue automatically only when actionability is actionable, scope is in_diagnosis (including diagnosis-approved supporting package paths), risk is low or medium, and next_round_focus is concrete.
|
|
697
820
|
- REQUEST_CHANGES must stop when actionability is needs_human/unsafe/unclear, scope is outside_diagnosis/unclear, risk is high, or next_round_focus is empty.
|
|
698
821
|
- REQUEST_CHANGES → include failure_reason and concrete next_round_focus for the next fix invocation. The next_round_focus must name the priority/classification and specific test file or evidence path to address first.
|
|
699
822
|
handoff:
|
|
@@ -704,6 +827,9 @@ workflows:
|
|
|
704
827
|
- type: file
|
|
705
828
|
path: ".dna/specs/diagnosis-$ARGUMENTS.md"
|
|
706
829
|
description: "Diagnosis spec"
|
|
830
|
+
- type: file
|
|
831
|
+
path: ".dna/specs/diagnosis-$ARGUMENTS.contract.json"
|
|
832
|
+
description: "Diagnosis-contract/v2 repair path authority"
|
|
707
833
|
- type: file
|
|
708
834
|
path: "docs/behavior/$ARGUMENTS.md"
|
|
709
835
|
description: "Behavior document"
|
|
@@ -717,10 +843,10 @@ workflows:
|
|
|
717
843
|
depends_on: [review_changes]
|
|
718
844
|
description: "Verify progress and output report"
|
|
719
845
|
prompt: |
|
|
720
|
-
Read the review verdict and diagnosis
|
|
846
|
+
Read the review verdict, diagnosis spec, and diagnosis-contract/v2 sidecar first.
|
|
721
847
|
|
|
722
848
|
If the review verdict is REQUEST_CHANGES:
|
|
723
|
-
- If actionability is actionable, scope is in_diagnosis, risk is low or medium, and next_round_focus is concrete, set Verdict: CONTINUE and do not run tests; copy reviewer next_round_focus into Next Round Focus.
|
|
849
|
+
- If actionability is actionable, scope is in_diagnosis, risk is low or medium, and next_round_focus is concrete, set Verdict: CONTINUE and do not run tests; copy reviewer next_round_focus into Next Round Focus. Diagnosis-approved supporting package paths remain in_diagnosis.
|
|
724
850
|
- Otherwise set Verdict: BLOCKED, set Failure reason: BLOCKED_BY_REVIEW plus reviewer details, and do not run tests.
|
|
725
851
|
|
|
726
852
|
If the review verdict is APPROVE:
|