// Reconciles reports/os-implementation/progress.json for one K2101+ feature. // local K(n-4)..K(n-1): PLANNED -> LOCAL_VALIDATED // guest K(n): PLANNED -> DEVELOPMENT_GUEST_ACCEPTED // Counts, lastAcceptedGuest and nextImplementation are recomputed from the // individual moves (no hard-coded totals). Only the named moves may change; // the previous file is preserved next to the report. import assert from 'node:assert/strict'; import {copyFileSync,mkdtempSync,readFileSync,renameSync,writeFileSync} from 'node:fs'; import {join,relative,resolve} from 'node:path'; import {hashAt} from './boot-contract-report.mjs'; import {buildOsPlan} from '../os-roadmap.mjs'; import {validateDevelopment} from '../os-development.mjs'; assert.equal(process.argv.length,5,'usage: node feature-progress.mjs local|guest '); const root=process.cwd(),kind=process.argv[2],[specPath,evidencePath]=process.argv.slice(3).map(p=>relative(root,resolve(p))); const read=p=>JSON.parse(readFileSync(p,'utf8')),artifact=p=>({path:relative(root,p),sha256:hashAt(root,relative(root,p))}); const spec=read(specPath),evidence=read(evidencePath),n=Number(spec.milestone.slice(1)),plan=buildOsPlan(); assert.ok(kind==='local'||kind==='guest'); const ids=kind==='local'?[n-4,n-3,n-2,n-1].map(k=>'K'+k):['K'+n]; if(kind==='local'){assert.equal(evidence.status,`K${n-4}_K${n-1}_LOCAL_VALIDATED`);assert.match(evidencePath,new RegExp(`^reports/os-implementation/${spec.milestone}-${spec.slug}-local-[A-Za-z0-9_-]+/report\\.json$`));} else{assert.equal(evidence.status,`${spec.milestone}_FEATURE_DEVELOPMENT_MATRIX_VALIDATED`);assert.equal(evidence.guestAccepted,true);assert.equal(evidence.productAccepted,false); assert.match(evidencePath,new RegExp(`^reports/os-implementation/${spec.milestone}-${spec.slug}-matrix-check-[A-Za-z0-9_-]+/report\\.json$`));} const verify=v=>{if(!v||typeof v!=='object')return;if(typeof v.path==='string'&&/^[a-f0-9]{64}$/.test(v.sha256??''))assert.equal(hashAt(root,v.path),v.sha256,v.path);for(const x of Object.values(v))verify(x);}; verify(evidence); const progressPath='reports/os-implementation/progress.json',previousText=readFileSync(progressPath,'utf8'),progress=JSON.parse(previousText),before=structuredClone(progress); validateDevelopment(progress,plan); if(kind==='guest')for(let k=n-4;kx.id==='K'+k);assert.equal(m.status,'LOCAL_VALIDATED');assert.deepEqual(m.evidence,evidence.local,'guest acceptance binds the recorded local evidence');} const record=artifact(join(root,evidencePath)); for(const id of ids){ const m=progress.moves.find(x=>x.id===id);assert.equal(m.status,'PLANNED',`${id} must still be planned`);assert.equal(m.evidence,null); m.status=kind==='local'?'LOCAL_VALIDATED':'DEVELOPMENT_GUEST_ACCEPTED';m.evidence=record;m.productAccepted=false;m.scope=kind==='local'?spec.localScope:spec.guestScope; } const count=s=>progress.moves.filter(m=>m.status===s).length; progress.counts={locallyValidated:count('LOCAL_VALIDATED'),developmentGuestAccepted:count('DEVELOPMENT_GUEST_ACCEPTED'),partialExternal:count('PARTIAL_EXTERNAL'), partialGuestProfile:count('PARTIAL_GUEST_PROFILE'),notAccepted:0,productAccepted:0}; progress.counts.notAccepted=progress.moves.length-progress.counts.locallyValidated-progress.counts.developmentGuestAccepted; progress.lastAcceptedGuest=progress.moves.filter(m=>m.status==='DEVELOPMENT_GUEST_ACCEPTED').at(-1)?.id; progress.nextImplementation=progress.moves.find(m=>m.status==='PLANNED')?.id??progress.nextImplementation; progress.generatedAt=new Date().toISOString(); validateDevelopment(progress,plan); for(const [i,m]of progress.moves.entries())if(!ids.includes(m.id))assert.deepEqual(m,before.moves[i],'only the named moves may change'); const directory=mkdtempSync(join(root,`reports/os-implementation/${spec.milestone}-${spec.slug}-${kind}-progress-`)); copyFileSync(join(root,'scripts/os-acceptance/feature-progress.mjs'),join(directory,'harness.mjs.txt')); writeFileSync(join(directory,'previous-progress.json'),previousText);writeFileSync(join(directory,'current-progress.json'),JSON.stringify(progress,null,2)+'\n'); assert.equal(readFileSync(progressPath,'utf8'),previousText,'progress changed during reconciliation'); writeFileSync(progressPath+'.feature-tmp',JSON.stringify(progress,null,2)+'\n');renameSync(progressPath+'.feature-tmp',progressPath); const report={schema:'turkos-feature-progress/v1',status:kind==='local'?`K${n-4}_K${n-1}_DEVELOPMENT_PROGRESS_RECONCILED`:`${spec.milestone}_DEVELOPMENT_PROGRESS_RECONCILED`, moves:ids,evidence:record,previous:artifact(join(directory,'previous-progress.json')),current:artifact(join(directory,'current-progress.json')), harness:artifact(join(directory,'harness.mjs.txt')),counts:progress.counts,lastAcceptedGuest:progress.lastAcceptedGuest,nextImplementation:progress.nextImplementation}; writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); const statePath='reports/os-implementation/active-development-continuation.json',state=read(statePath); Object.assign(state,{lastAcceptedGuest:progress.lastAcceptedGuest,nextImplementation:progress.nextImplementation,counts:progress.counts,updatedAt:progress.generatedAt}); state[spec.milestone]={...(state[spec.milestone]??{}),[kind==='local'?'local':'matrixCheck']:evidencePath,[kind==='local'?'localProgress':'guestProgress']:relative(root,join(directory,'report.json')), status:kind==='local'?'LOCAL_VALIDATED_GUEST_PENDING':'DEVELOPMENT_ACCEPTED_PUBLICATION_PENDING',guestAccepted:kind==='guest',productAccepted:false,pipeline:'claude-feature-pipeline'}; writeFileSync(statePath+'.feature-tmp',JSON.stringify(state,null,2)+'\n');renameSync(statePath+'.feature-tmp',statePath); console.log(JSON.stringify({status:report.status,report:relative(root,join(directory,'report.json')),counts:progress.counts,last:progress.lastAcceptedGuest,next:progress.nextImplementation}));