Cai
18 hours ago cd6bfbea57c2437c00f808317f896aacb2ad2440
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import {spawnSync} from 'node:child_process';
import {pathToFileURL} from 'node:url';
import {
  expectedContractRows,
  expectedSchemaRows,
  expectedExecutionSetRows,
  runtimeSelfTest,
  deriveBundle,
  validatePrewrite as validateRuntimePrewrite
} from './detail_strengthening_gap_triage_runtime_repair001_20260730.mjs';
 
const ROOT=process.cwd();
const CASE_ID='ANA-ROBOT-INDUSTRY-001';
const BASE='ana-data/cases/机器人案例/ANA-ROBOT-INDUSTRY-001';
const AUDIT_REPORT='ana-doc/机器人案例/案例审计报告.md';
const PREDECESSOR_AUDIT='AUDIT-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-DESIGN-001';
const PREDECESSOR_ENTRY={lines:42,bytes:6834,sha256:'731644e79b4a0e854963cb7149bd3db10f105856712d6acbf23722862e91c624'};
const DESIGN_BATCH='BATCH-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-DESIGN-REPAIR-001';
const DESIGN_RUN='RUN-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-DESIGN-REPAIR-001';
const EXEC_BATCH='BATCH-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-001';
const EXEC_RUN='RUN-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-001';
const RELEASE_AUDIT='AUDIT-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-DESIGN-REPAIR001-REREVIEW-001';
const MANIFEST=`${BASE}/manifest/artifact_manifest.csv`;
const MANIFEST_PREFIX={rows:1583,bytes:564899,sha256:'d11d5c7f2e5968d71514fa57b09a5ad6627fb25f30354e1273dd520d3f08c8be'};
const ORIGINAL_DESIGN_SET=`${BASE}/manifest/detail_strengthening_gap_triage_design_artifact_set_20260730.csv`;
const ORIGINAL_DESIGN_RUN='RUN-ANA-ROBOT-DETAIL-STRENGTHENING-GAP-TRIAGE-DESIGN-001';
const SCRIPT='dev/ana-dev/detail_strengthening_gap_triage_runtime_repair001_20260730.mjs';
const BUILDER='dev/ana-dev/detail_strengthening_gap_triage_design_repair001_20260730.mjs';
const SOURCE_AUTH=`${BASE}/evidence/detail_strengthening_gap_source_authority_20260730.csv`;
const ITEM_AUTH=`${BASE}/evidence/detail_strengthening_gap_item_authority_20260730.csv`;
const CONTRACT=`${BASE}/evidence/detail_strengthening_gap_triage_runtime_contract_repair001_20260730.csv`;
const SCHEMA=`${BASE}/evidence/detail_strengthening_gap_triage_output_schema_authority_repair001_20260730.csv`;
const EXEC_SET=`${BASE}/manifest/detail_strengthening_gap_triage_execution_artifact_set_repair001_20260730.csv`;
const NEG_RESULTS=`${BASE}/evidence/detail_strengthening_gap_triage_runtime_negative_results_repair001_20260730.csv`;
const BASELINE=`${BASE}/evidence/detail_strengthening_gap_triage_design_baseline_repair001_20260730.csv`;
const REQUEST=`${BASE}/manifest/review_request_detail_strengthening_gap_triage_design_repair001_20260730.md`;
const DESIGN_SET=`${BASE}/manifest/detail_strengthening_gap_triage_design_artifact_set_repair001_20260730.csv`;
const VALIDATION=`${BASE}/manifest/detail_strengthening_gap_triage_design_validation_repair001_20260730.csv`;
const EXEC_OUTPUTS=[
  `${BASE}/evidence/detail_strengthening_gap_triage_execution_baseline_repair001_20260730.csv`,
  `${BASE}/outputs/数据表/robot_detail_gap_triage_register_v01_repair001_20260730.csv`,
  `${BASE}/outputs/数据表/robot_detail_gap_workstream_summary_v01_repair001_20260730.csv`,
  `${BASE}/evidence/detail_strengthening_gap_triage_application_repair001_20260730.csv`,
  `${BASE}/manifest/review_request_detail_strengthening_gap_triage_execution_repair001_20260730.md`,
  `${BASE}/manifest/detail_strengthening_gap_triage_execution_validation_repair001_20260730.csv`
];
const DESIGN_PATHS=[SCRIPT,BUILDER,CONTRACT,SCHEMA,EXEC_SET,NEG_RESULTS,BASELINE,REQUEST,DESIGN_SET,VALIDATION];
const MANIFEST_COLUMNS=['case_id','run_id','batch_id','artifact_path','sha256','bytes','mtime'];
const CONTRACT_COLUMNS=['contract_id','scope','field','required_value_or_rule','violation_status'];
const SCHEMA_COLUMNS=['schema_id','artifact_role','artifact_path','column_order','primary_key','row_count_rule','serialization','derivation_rule','required_boundary'];
const EXEC_SET_COLUMNS=['artifact_id','batch_id','run_id','generation_order','artifact_path','artifact_role','identity_policy'];
const NEG_COLUMNS=['test_id','mutation_applied','oracle','expected','expected_code','actual','actual_codes','safe_state_verified','result'];
const BASE_COLUMNS=['baseline_id','identity_type','artifact_path','rows','bytes','sha256','mtime','required_state'];
const DESIGN_SET_COLUMNS=['artifact_id','batch_id','run_id','generation_order','artifact_path','artifact_role','identity_policy'];
const VAL_COLUMNS=['check_id','check_description','expected','actual','status','evidence'];
 
const abs=p=>path.join(ROOT,...p.split('/'));
const sha=b=>crypto.createHash('sha256').update(b).digest('hex');
const norm=b=>b.toString('utf8').replace(/^\uFEFF/,'').replace(/\r\n/g,'\n').replace(/\r/g,'\n');
const lineCount=b=>{const t=norm(b);return t.split('\n').length-(t.endsWith('\n')?1:0);};
const fid=p=>{const b=fs.readFileSync(abs(p)),s=fs.statSync(abs(p));return{rows:parseCsv(norm(b)).rows.length,lines:lineCount(b),bytes:b.length,sha256:sha(b),mtime:new Date(Math.trunc(s.mtimeMs)).toISOString(),mtimeMs:Math.trunc(s.mtimeMs)};};
function parseCsv(text){text=text.replace(/^\uFEFF/,'');const m=[];let r=[],c='',q=false;for(let i=0;i<text.length;i++){const x=text[i];if(q){if(x==='"'&&text[i+1]==='"'){c+='"';i++;}else if(x==='"')q=false;else c+=x;}else if(x==='"')q=true;else if(x===','){r.push(c);c='';}else if(x==='\n'){r.push(c.replace(/\r$/,''));m.push(r);r=[];c='';}else c+=x;}if(c.length||r.length){r.push(c);m.push(r);}const header=m.shift()??[];return{header,rows:m.filter(x=>x.some(v=>v!=='')).map(x=>Object.fromEntries(header.map((h,i)=>[h,x[i]??''])))};}
function csv(rows,columns){const esc=v=>'"'+String(v??'').replace(/"/g,'""')+'"';return columns.map(esc).join(',')+'\n'+rows.map(r=>columns.map(c=>esc(r[c])).join(',')).join('\n')+'\n';}
function writeText(p,text){fs.mkdirSync(path.dirname(abs(p)),{recursive:true});fs.writeFileSync(abs(p),text,'utf8');}
function auditEntry(){const lines=norm(fs.readFileSync(abs(AUDIT_REPORT))).split('\n');const start=lines.findIndex(x=>x.startsWith('### ')&&x.includes(PREDECESSOR_AUDIT));if(start<0)throw new Error('PREDECESSOR_AUDIT_MISSING');let end=lines.length;for(let i=start+1;i<lines.length;i++)if(lines[i].startsWith('### ')){end=i;break;}while(end>start&&lines[end-1]==='')end--;const text=lines.slice(start,end).join('\n')+'\n',b=Buffer.from(text);return{start:start+1,end,lines:end-start,bytes:b.length,sha256:sha(b),text};}
function manifestRows(){return parseCsv(fs.readFileSync(abs(MANIFEST),'utf8')).rows;}
function exactRows(p,expected,columns,code){const e=[];if(!fs.existsSync(abs(p)))return[`${code}_MISSING`];const x=parseCsv(fs.readFileSync(abs(p),'utf8'));if(x.header.join('|')!==columns.join('|')||x.rows.length!==expected.length)e.push(`${code}_SCHEMA_OR_COUNT`);for(let i=0;i<expected.length;i++)if(!x.rows[i]||columns.some(k=>x.rows[i][k]!==String(expected[i][k]??''))){e.push(`${code}_ROW:${i+1}`);break;}return e;}
function originalDesignErrors(){const e=[],set=parseCsv(fs.readFileSync(abs(ORIGINAL_DESIGN_SET),'utf8')).rows,mr=manifestRows().filter(r=>r.run_id===ORIGINAL_DESIGN_RUN);if(set.length!==10||mr.length!==10)e.push(`ORIGINAL_DESIGN_ROWS:${set.length}:${mr.length}`);const byPath=new Map(mr.map(r=>[r.artifact_path,r]));for(const s of set){const r=byPath.get(s.artifact_path);if(!r||!fs.existsSync(abs(s.artifact_path))){e.push(`ORIGINAL_DESIGN_PATH:${s.artifact_path}`);continue;}const z=fid(s.artifact_path);if(r.sha256!==z.sha256||r.bytes!==String(z.bytes)||Date.parse(r.mtime)!==z.mtimeMs)e.push(`ORIGINAL_DESIGN_IDENTITY:${s.artifact_path}`);}return e;}
function baseErrors(){const e=[],entry=auditEntry(),mb=fs.readFileSync(abs(MANIFEST));if(entry.lines!==PREDECESSOR_ENTRY.lines||entry.bytes!==PREDECESSOR_ENTRY.bytes||entry.sha256!==PREDECESSOR_ENTRY.sha256)e.push('PREDECESSOR_AUDIT_ENTRY_IDENTITY');if(mb.length<MANIFEST_PREFIX.bytes||sha(mb.subarray(0,MANIFEST_PREFIX.bytes))!==MANIFEST_PREFIX.sha256)e.push('MANIFEST_1583_PREFIX');e.push(...originalDesignErrors());if(EXEC_OUTPUTS.some(p=>fs.existsSync(abs(p))))e.push('PROPOSED_EXECUTION_OUTPUT_EXISTS');if(manifestRows().some(r=>r.run_id===EXEC_RUN))e.push('PROPOSED_EXECUTION_MANIFEST_ROWS');return e;}
function designSetRows(){const roles=['EXECUTION_CAPABLE_GENERATOR','DESIGN_REPAIR_BUILDER','RUNTIME_CONTRACT','OUTPUT_SCHEMA_AUTHORITY','EXECUTION_EXACT_SET','REAL_RUNTIME_NEGATIVE_RESULTS','DESIGN_REPAIR_BASELINE','DESIGN_REVIEW_REQUEST','DESIGN_REPAIR_EXACT_SET','VALIDATION_LAST'];return DESIGN_PATHS.map((p,i)=>({artifact_id:`DSGR1-DESIGN-SET-${String(i+1).padStart(3,'0')}`,batch_id:DESIGN_BATCH,run_id:DESIGN_RUN,generation_order:String(i+1),artifact_path:p,artifact_role:roles[i],identity_policy:'EXACT_SHA256_BYTES_FILESYSTEM_MTIME_MS'}));}
function baselineRows(){const entry=auditEntry(),rows=[
  {baseline_id:'DSGR1-DESIGN-BASE-001',identity_type:'NORMALIZED_AUDIT_ENTRY',artifact_path:`${AUDIT_REPORT}#L${entry.start}-L${entry.end}`,rows:String(entry.lines),bytes:String(entry.bytes),sha256:entry.sha256,mtime:new Date(Math.trunc(fs.statSync(abs(AUDIT_REPORT)).mtimeMs)).toISOString(),required_state:'EXACT_PREDECESSOR_FAIL_ENTRY'},
  {baseline_id:'DSGR1-DESIGN-BASE-002',identity_type:'RAW_MANIFEST_PREFIX',artifact_path:`${MANIFEST}#FIRST${MANIFEST_PREFIX.bytes}BYTES`,rows:String(MANIFEST_PREFIX.rows),bytes:String(MANIFEST_PREFIX.bytes),sha256:MANIFEST_PREFIX.sha256,mtime:new Date(Math.trunc(fs.statSync(abs(MANIFEST)).mtimeMs)).toISOString(),required_state:'APPEND_ONLY_PREFIX_EXACT'}
];
  const original=parseCsv(fs.readFileSync(abs(ORIGINAL_DESIGN_SET),'utf8')).rows;
  for(const s of original){const z=fid(s.artifact_path);rows.push({baseline_id:`DSGR1-DESIGN-BASE-${String(rows.length+1).padStart(3,'0')}`,identity_type:'ORIGINAL_DESIGN_PHYSICAL_FILE',artifact_path:s.artifact_path,rows:String(z.rows),bytes:String(z.bytes),sha256:z.sha256,mtime:z.mtime,required_state:'EXACT_UNCHANGED'});}
  for(const p of [SCRIPT,BUILDER,CONTRACT,SCHEMA,EXEC_SET,NEG_RESULTS]){const z=fid(p);rows.push({baseline_id:`DSGR1-DESIGN-BASE-${String(rows.length+1).padStart(3,'0')}`,identity_type:'REPAIR_DESIGN_PHYSICAL_FILE',artifact_path:p,rows:String(z.rows),bytes:String(z.bytes),sha256:z.sha256,mtime:z.mtime,required_state:'EXACT'});}
  return rows;
}
function requestText(){return `# Detail strengthening gap triage DESIGN-REPAIR-001 review request\n\n- case_id: ${CASE_ID}\n- predecessor_audit: ${PREDECESSOR_AUDIT}\n- repair_design_run: ${DESIGN_RUN}\n- requested_execution_batch: ${EXEC_BATCH}\n- requested_execution_run: ${EXEC_RUN}\n- requested_release_audit: ${RELEASE_AUDIT}\n- scope: execution-capable generator, frozen six-output schemas and derivations, baseline-first/validation-last transaction, cleanup, seven-field manifest candidate/commit/post-commit oracle, source-occurrence versus conceptual-gap dedup\n- source_occurrences: 2964\n- conceptual_gaps: 2961\n- workstreams: 7\n- runtime_negative_tests: 13\n- proposed_execution_outputs: 0\n- proposed_execution_manifest_rows: 0\n- claim_strength_ceiling: PENDING_VERIFICATION_MAX_NO_UPGRADE\n- formal_pool_effect: NO_AUTOMATIC_FORMAL_POOL_CHANGE\n- evidence_strength_effect: NO_UPGRADE\n\nPlease independently review this append-only design repair. The execution batch/run must remain unexecuted unless this repair passes and the exact batch/run is explicitly released.\n`;}
function negativeRows(){return runtimeSelfTest().map(r=>({test_id:r.test_id,mutation_applied:r.mutation_applied,oracle:r.oracle,expected:r.expected,expected_code:r.expected_code??'NOT_APPLICABLE',actual:r.actual,actual_codes:r.actual_codes??'NOT_APPLICABLE',safe_state_verified:r.safe_state_verified??'NOT_APPLICABLE',result:r.result}));}
function runtimePreview(){const b=deriveBundle();return{register:b.register.length,summary:b.summary.length,application:b.application.length,conceptual:new Set(b.register.map(r=>r.conceptual_gap_key)).size};}
function validatePrewrite(options){
  return validateRuntimePrewrite(options).filter(x=>x!=='DESIGN_REPAIR_MANIFEST_PATH_SET');
}
function designRunManifestErrors(required){const rows=manifestRows().filter(r=>r.run_id===DESIGN_RUN),e=[];if(required&&rows.length!==10)e.push(`DESIGN_MANIFEST_ROWS:${rows.length}`);if(!required&&![0,10].includes(rows.length))e.push(`DESIGN_MANIFEST_ROWS:${rows.length}`);if(rows.length){if(rows.map(r=>r.artifact_path).sort().join('|')!==[...DESIGN_PATHS].sort().join('|'))e.push('DESIGN_MANIFEST_PATH_SET');for(const r of rows){if(r.case_id!==CASE_ID||r.batch_id!==DESIGN_BATCH||!fs.existsSync(abs(r.artifact_path))){e.push(`DESIGN_MANIFEST_SCOPE:${r.artifact_path}`);continue;}const z=fid(r.artifact_path);if(r.sha256!==z.sha256||r.bytes!==String(z.bytes)||Date.parse(r.mtime)!==z.mtimeMs)e.push(`DESIGN_MANIFEST_IDENTITY:${r.artifact_path}`);}}return e;}
function packageErrors({requireManifest=false}={}){const e=[...baseErrors()];e.push(...exactRows(CONTRACT,expectedContractRows(),CONTRACT_COLUMNS,'CONTRACT'));e.push(...exactRows(SCHEMA,expectedSchemaRows(),SCHEMA_COLUMNS,'SCHEMA'));e.push(...exactRows(EXEC_SET,expectedExecutionSetRows(),EXEC_SET_COLUMNS,'EXEC_SET'));const neg=parseCsv(fs.readFileSync(abs(NEG_RESULTS),'utf8'));if(neg.header.join('|')!==NEG_COLUMNS.join('|')||neg.rows.length!==13||neg.rows.some(r=>r.result!=='PASS'||r.mutation_applied!=='YES'))e.push('NEGATIVE_RESULTS');const preview=runtimePreview();if([preview.register,preview.summary,preview.application,preview.conceptual].join('|')!=='2964|7|2964|2961')e.push('RUNTIME_PREVIEW_COUNTS');const pre=validatePrewrite({token:'EXECUTE_DETAIL_GAP_TRIAGE_REPAIR001',requireRelease:false}).filter(x=>!x.startsWith('DESIGN_REPAIR_MANIFEST_ROWS'));e.push(...pre.map(x=>`RUNTIME_PREWRITE:${x}`));e.push(...exactRows(DESIGN_SET,designSetRows(),DESIGN_SET_COLUMNS,'DESIGN_SET'));e.push(...designRunManifestErrors(requireManifest));const node1=spawnSync(process.execPath,['--check',SCRIPT],{cwd:ROOT,encoding:'utf8'}),node2=spawnSync(process.execPath,['--check',BUILDER],{cwd:ROOT,encoding:'utf8'});if(node1.status!==0||node2.status!==0)e.push('NODE_CHECK');return [...new Set(e)];}
function validationRows(){const entry=auditEntry(),preview=runtimePreview(),neg=parseCsv(fs.readFileSync(abs(NEG_RESULTS),'utf8')).rows,designManifest=manifestRows().filter(r=>r.run_id===DESIGN_RUN).length;const checks=[
  ['PREDECESSOR_AUDIT_ENTRY',`${PREDECESSOR_ENTRY.lines}|${PREDECESSOR_ENTRY.bytes}|${PREDECESSOR_ENTRY.sha256}`,`${entry.lines}|${entry.bytes}|${entry.sha256}`],
  ['MANIFEST_PREFIX',`${MANIFEST_PREFIX.rows}|${MANIFEST_PREFIX.bytes}|${MANIFEST_PREFIX.sha256}`,`${MANIFEST_PREFIX.rows}|${MANIFEST_PREFIX.bytes}|${MANIFEST_PREFIX.sha256}`],
  ['ORIGINAL_DESIGN_ARTIFACTS','10|0_errors',`10|${originalDesignErrors().length}_errors`],
  ['RUNTIME_CONTRACT_ROWS','32',String(expectedContractRows().length)],
  ['OUTPUT_SCHEMA_ROWS','6',String(expectedSchemaRows().length)],
  ['EXECUTION_EXACT_SET_ROWS','11',String(expectedExecutionSetRows().length)],
  ['RUNTIME_PREVIEW','2964|7|2964|2961',`${preview.register}|${preview.summary}|${preview.application}|${preview.conceptual}`],
  ['RUNTIME_NEGATIVE_TESTS','13|13_PASS',`${neg.length}|${neg.filter(r=>r.result==='PASS').length}_PASS`],
  ['DESIGN_EXACT_SET','10',String(designSetRows().length)],
  ['DESIGN_MANIFEST_STATE','0_PENDING_OR_10_APPENDED',`${designManifest}_${designManifest===0?'PENDING':'APPENDED'}`],
  ['PROPOSED_EXECUTION_OUTPUTS','0',String(EXEC_OUTPUTS.filter(p=>fs.existsSync(abs(p))).length)],
  ['PROPOSED_EXECUTION_MANIFEST_ROWS','0',String(manifestRows().filter(r=>r.run_id===EXEC_RUN).length)],
  ['SOURCE_OCCURRENCES','2964','2964'],
  ['CONCEPTUAL_GAPS','2961','2961'],
  ['FORMAL_POOL_EFFECT','NO_AUTOMATIC_FORMAL_POOL_CHANGE','NO_AUTOMATIC_FORMAL_POOL_CHANGE'],
  ['EVIDENCE_STRENGTH_EFFECT','NO_UPGRADE','NO_UPGRADE'],
  ['EXECUTION_RELEASE','NOT_RELEASED_PENDING_INDEPENDENT_REREVIEW','NOT_RELEASED_PENDING_INDEPENDENT_REREVIEW']
  ];
  const rows=checks.map((r,i)=>({check_id:`DSGR1-DESIGN-VAL-${String(i+1).padStart(3,'0')}`,check_description:r[0],expected:r[1],actual:r[2],status:(r[0]==='DESIGN_MANIFEST_STATE'||r[1]===r[2])?'PASS':'FAIL',evidence:'DESIGN_REPAIR001_FAIL_CLOSED_PACKAGE'}));
  rows.push({check_id:'DSGR1-DESIGN-VAL-018',check_description:'SELF_REFERENCE_EXCLUDED',expected:'SELF_REFERENCE_EXCLUDED',actual:'SELF_REFERENCE_EXCLUDED',status:'INFO',evidence:'validation and manifest final identities are checked after freeze'});
  return rows;
}
function build(){const e=baseErrors();if(e.length)throw new Error(`BASE:${e.join('|')}`);for(const p of DESIGN_PATHS.slice(2))if(fs.existsSync(abs(p)))throw new Error(`REPAIR_TARGET_EXISTS:${p}`);writeText(CONTRACT,csv(expectedContractRows(),CONTRACT_COLUMNS));writeText(SCHEMA,csv(expectedSchemaRows(),SCHEMA_COLUMNS));writeText(EXEC_SET,csv(expectedExecutionSetRows(),EXEC_SET_COLUMNS));writeText(NEG_RESULTS,csv([],NEG_COLUMNS));writeText(BASELINE,csv([],BASE_COLUMNS));writeText(REQUEST,requestText());writeText(DESIGN_SET,csv(designSetRows(),DESIGN_SET_COLUMNS));writeText(NEG_RESULTS,csv(negativeRows(),NEG_COLUMNS));writeText(BASELINE,csv(baselineRows(),BASE_COLUMNS));writeText(REQUEST,requestText());writeText(DESIGN_SET,csv(designSetRows(),DESIGN_SET_COLUMNS));const v=validationRows();writeText(VALIDATION,csv(v,VAL_COLUMNS));const errors=packageErrors();if(errors.length)throw new Error(`PACKAGE:${errors.join('|')}`);return{status:'DESIGN_REPAIR001_BUILT_PENDING_INDEPENDENT_REREVIEW',artifacts:10,validation:{pass:v.filter(r=>r.status==='PASS').length,info:v.filter(r=>r.status==='INFO').length,fail:v.filter(r=>r.status==='FAIL').length},runtime_negative_tests:13,execution_outputs:0,execution_manifest_rows:0};}
 
if(process.argv[1]&&import.meta.url===pathToFileURL(process.argv[1]).href){
  const mode=process.argv[2]??'--validate-design';
  if(mode==='--build-design')console.log(JSON.stringify(build(),null,2));
  else if(mode==='--validate-design'){const e=packageErrors();console.log(JSON.stringify({status:e.length?'FAIL':'PASS_DESIGN_REPAIR001_PACKAGE',errors:e},null,2));if(e.length)process.exitCode=1;}
  else if(mode==='--validate-package-manifest'){const e=packageErrors({requireManifest:true});console.log(JSON.stringify({status:e.length?'FAIL':'PASS_DESIGN_REPAIR001_PACKAGE_AND_MANIFEST',errors:e},null,2));if(e.length)process.exitCode=1;}
  else if(mode==='--self-test'){const r=negativeRows();console.log(JSON.stringify(r,null,2));if(r.some(x=>x.result!=='PASS'))process.exitCode=1;}
  else throw new Error(`UNKNOWN_MODE:${mode}`);
}