Cai
2026-08-29 045403bac1e6116e8c4a1d551fa15f6c18e1b595
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
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import {pathToFileURL} from 'node:url';
import {spawnSync} from 'node:child_process';
import * as runtime from './detail_strengthening_p0_eligible6_formal_evidence_integration_runtime_repair001_20260730.mjs';
import {parseAuthorityCsv,serializeCsv,serializeManifestDataRows,validateAppendStableManifest} from './artifact_manifest_append_stable_parser_repair001_20260730.mjs';
 
const ROOT=runtime.ROOT,BASE=runtime.BASE,CASE_ID=runtime.CASE_ID,MANIFEST=runtime.MANIFEST;
const SCRIPT='dev/ana-dev/detail_strengthening_p0_eligible6_formal_evidence_integration_design_repair001_20260730.mjs';
const FAILED_AUDIT='AUDIT-ANA-ROBOT-DETAIL-STRENGTHENING-P0-ELIGIBLE6-FORMAL-EVIDENCE-INTEGRATION-DESIGN-REREVIEW-001';
const DESIGN_BATCH='BATCH-ANA-ROBOT-DETAIL-STRENGTHENING-P0-ELIGIBLE6-FORMAL-EVIDENCE-INTEGRATION-DESIGN-REPAIR-001';
const DESIGN_RUN='RUN-ANA-ROBOT-DETAIL-STRENGTHENING-P0-ELIGIBLE6-FORMAL-EVIDENCE-INTEGRATION-DESIGN-REPAIR-001';
const FAIL_AUTHORITY=`${BASE}/evidence/detail_strengthening_p0_eligible6_formal_evidence_integration_failed_review_authority_repair001_20260730.csv`;
const DESIGN_SET=`${BASE}/manifest/detail_strengthening_p0_eligible6_formal_evidence_integration_design_artifact_set_repair001_20260730.csv`;
const FAULT_RESULTS=`${BASE}/evidence/detail_strengthening_p0_eligible6_formal_evidence_integration_transaction_fault_results_repair001_20260730.csv`;
const DESIGN_BASELINE=`${BASE}/evidence/detail_strengthening_p0_eligible6_formal_evidence_integration_design_baseline_repair001_20260730.csv`;
const REVIEW_REQUEST=`${BASE}/manifest/review_request_detail_strengthening_p0_eligible6_formal_evidence_integration_design_repair001_20260730.md`;
const DESIGN_VALIDATION=`${BASE}/manifest/detail_strengthening_p0_eligible6_formal_evidence_integration_design_validation_repair001_20260730.csv`;
const DESIGN_DOC='ana-doc/机器人案例/案例分析设计.md';
const DESIGN_SET_COLUMNS=['artifact_id','batch_id','run_id','generation_order','artifact_path','artifact_role','identity_policy'];
const BASELINE_COLUMNS=runtime.BASELINE_COLUMNS,VALIDATION_COLUMNS=runtime.VALIDATION_COLUMNS;
const abs=value=>path.join(ROOT,...value.split('/'));
const hash=value=>crypto.createHash('sha256').update(value).digest('hex');
const normalize=value=>value.toString('utf8').replace(/^\uFEFF/,'').replace(/\r\n/g,'\n').replace(/\r/g,'\n');
const lineCount=value=>{const text=normalize(value);return text.split('\n').length-(text.endsWith('\n')?1:0);};
const readCsv=file=>{const parsed=parseAuthorityCsv(normalize(fs.readFileSync(abs(file))));if(parsed.errors.length)throw new Error(`CSV:${file}:${parsed.errors.join('|')}`);return parsed;};
const identity=file=>{const buffer=fs.readFileSync(abs(file)),stat=fs.statSync(abs(file));return{rows:file.endsWith('.csv')?readCsv(file).rows.length:lineCount(buffer),bytes:buffer.length,sha256:hash(buffer),mtime:new Date(Math.trunc(stat.mtimeMs)).toISOString(),mtimeMs:Math.trunc(stat.mtimeMs)};};
const exactColumns=(parsed,columns,code)=>parsed.header.join('|')===columns.join('|')?[]:[`${code}_COLUMNS`];
const compareRows=(actual,expected,columns,code)=>{const errors=[];if(actual.length!==expected.length)return[`${code}_COUNT:${actual.length}:${expected.length}`];for(let i=0;i<expected.length;i++)for(const column of columns)if(String(actual[i]?.[column]??'')!==String(expected[i]?.[column]??'')){errors.push(`${code}_FIELD:${i+1}:${column}`);break;}return errors;};
const write=(file,text)=>{fs.mkdirSync(path.dirname(abs(file)),{recursive:true});fs.writeFileSync(abs(file),text,'utf8');};
 
function auditAuthorityRow(auditId,id,passLiteral,allowedLiteral){const entry=runtime.auditEntry(auditId);if(!entry)throw new Error(`AUDIT_MISSING:${auditId}`);return{authority_id:id,audit_id:auditId,artifact_path:runtime.AUDIT_REPORT,start_line:String(entry.start),end_line:String(entry.end),normalized_lines:String(entry.lines),normalized_bytes:String(entry.bytes),normalized_sha256:entry.sha256,normalization:'UTF8_NO_BOM_LF_JOIN_LINES_WITH_TERMINAL_LF_V1',normalized_prefix_bytes:String(entry.prefix_bytes),normalized_prefix_sha256:entry.prefix_sha256,required_pass_literal:passLiteral,required_allowed_literal:allowedLiteral};}
function formalEntry(){const lines=normalize(fs.readFileSync(abs(DESIGN_DOC))).split('\n'),start=lines.findIndex(line=>line.startsWith('## ')&&line.includes(runtime.DESIGN_ID));if(start<0)throw new Error('FORMAL_ENTRY_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 buffer=Buffer.from(`${lines.slice(start,end).join('\n')}\n`);return{start:start+1,end,lines:end-start,bytes:buffer.length,sha256:hash(buffer)};}
function formalEntryRow(){const entry=formalEntry();return{authority_id:'P0INTR1-FORMAL-DESIGN-001',design_id:runtime.DESIGN_ID,artifact_path:DESIGN_DOC,start_line:String(entry.start),end_line:String(entry.end),lines:String(entry.lines),bytes:String(entry.bytes),sha256:entry.sha256,normalization:'UTF8_NO_BOM_LF_JOIN_LINES_WITH_TERMINAL_LF_V1',required_markers:[runtime.DESIGN_ID,'runFailClosedTransactionR1','ROLLBACK_INCOMPLETE_HELD','actual_io_throw','EMAP-046','FROZEN_LOCAL_INPUTS_ONLY_NO_NETWORK','Eligible6_formal_evidence_acceptance_or_integration_execution_release=NOT_RELEASED','NO_UPGRADE'].join('|')};}
function designSetRows(){const paths=[runtime.SCRIPT,SCRIPT,FAIL_AUTHORITY,runtime.CONTRACT,runtime.SCHEMA,runtime.EXEC_SET,DESIGN_SET,runtime.FORMAL_ENTRY_AUTHORITY,FAULT_RESULTS,DESIGN_BASELINE,REVIEW_REQUEST,DESIGN_VALIDATION],roles=['REPAIRED_EXECUTION_RUNTIME','DESIGN_REPAIR_BUILDER','FAILED_REVIEW_AUTHORITY','REPAIRED_RUNTIME_CONTRACT','REPAIRED_OUTPUT_SCHEMA','REPAIRED_EXECUTION_EXACT_SET','DESIGN_REPAIR_EXACT_SET','FORMAL_REPAIR_ENTRY_AUTHORITY','REAL_IO_TRANSACTION_RESULTS','DESIGN_REPAIR_BASELINE','FOCUSED_REVIEW_REQUEST','DESIGN_REPAIR_VALIDATION_LAST'];return paths.map((artifactPath,index)=>({artifact_id:`P0INTR1-DESIGN-SET-${String(index+1).padStart(3,'0')}`,batch_id:DESIGN_BATCH,run_id:DESIGN_RUN,generation_order:String(index+1),artifact_path:artifactPath,artifact_role:roles[index],identity_policy:'EXACT_SHA256_BYTES_FILESYSTEM_MTIME_MS'}));}
function protectedRows(){const rows=readCsv(runtime.PROTECTED_INVENTORY).rows;if(rows.length!==49)throw new Error(`PROTECTED_COUNT:${rows.length}`);return rows.map(row=>({path:row.artifact_path,...identity(row.artifact_path)}));}
function manifestState(buffer=fs.readFileSync(abs(MANIFEST)),options={}){return validateAppendStableManifest(buffer,{anomalyRows:readCsv(runtime.ANOMALY_AUTHORITY).rows,originalRunId:runtime.ORIGINAL_TRIAGE_RUN,originalRunExpectedRows:11,...options});}
function baselineRows(manifestBefore){const source=runtime.auditEntry(runtime.SOURCE_AUDIT),failed=runtime.auditEntry(FAILED_AUDIT),mapId=identity(runtime.CASE_MAP),rows=[{baseline_id:'P0INTR1-DESIGN-BASE-001',identity_type:'SOURCE_EXECUTION_AUDIT_ENTRY',artifact_path:`${runtime.AUDIT_REPORT}#L${source.start}-L${source.end}`,rows:String(source.lines),bytes:String(source.bytes),sha256:source.sha256,mtime:'INFO_APPENDABLE_SHARED_FILE',required_state:'EXACT_SOURCE_PASS'},{baseline_id:'P0INTR1-DESIGN-BASE-002',identity_type:'FAILED_DESIGN_REVIEW_ENTRY',artifact_path:`${runtime.AUDIT_REPORT}#L${failed.start}-L${failed.end}`,rows:String(failed.lines),bytes:String(failed.bytes),sha256:failed.sha256,mtime:'INFO_APPENDABLE_SHARED_FILE',required_state:'EXACT_SINGLE_BLOCKER_AUTHORITY'},{baseline_id:'P0INTR1-DESIGN-BASE-003',identity_type:'MANIFEST_PREFIX_BEFORE_REPAIR',artifact_path:MANIFEST,rows:String(manifestState(manifestBefore).logicalDataRows),bytes:String(manifestBefore.length),sha256:hash(manifestBefore),mtime:new Date(Math.trunc(fs.statSync(abs(MANIFEST)).mtimeMs)).toISOString(),required_state:'EXACT_APPEND_ONLY_PREFIX'},{baseline_id:'P0INTR1-DESIGN-BASE-004',identity_type:'FORMAL_MAP_CURRENT',artifact_path:runtime.CASE_MAP,rows:String(mapId.rows),bytes:String(mapId.bytes),sha256:mapId.sha256,mtime:mapId.mtime,required_state:'EXACT45_UNCHANGED'}];for(const file of designSetRows().slice(0,8).map(row=>row.artifact_path)){const id=identity(file);rows.push({baseline_id:`P0INTR1-DESIGN-BASE-${String(rows.length+1).padStart(3,'0')}`,identity_type:'FROZEN_REPAIR_INPUT',artifact_path:file,rows:String(id.rows),bytes:String(id.bytes),sha256:id.sha256,mtime:id.mtime,required_state:'EXACT_NO_DRIFT'});}for(const item of protectedRows())rows.push({baseline_id:`P0INTR1-DESIGN-BASE-${String(rows.length+1).padStart(3,'0')}`,identity_type:'PROTECTED49_CURRENT_IDENTITY',artifact_path:item.path,rows:String(item.rows),bytes:String(item.bytes),sha256:item.sha256,mtime:item.mtime,required_state:'NO_MUTATION'});return rows;}
function requestText(){return`# Eligible6 formal evidence integration DESIGN-REPAIR-001 focused rereview request\n\ncase_id=${CASE_ID}\naction_id=NEXT-ROBOT-043-DESIGN-REPAIR-001\ndesign_id=${runtime.DESIGN_ID}\nfailed_audit=${FAILED_AUDIT}\nrequested_release_audit=${runtime.RELEASE_AUDIT}\nproposed_batch_id=${runtime.EXEC_BATCH}\nproposed_run_id=${runtime.EXEC_RUN}\nreview_scope=FOCUSED_TRANSACTION_ROLLBACK_FAIL_CLOSED_ONLY_NO_EXECUTION\nreused_semantics=eligible6_CAND005_excluded_map45_to46_EMAP046_only_gaps_open_no_upgrade\ntransaction_oracle=runFailClosedTransactionR1\nreal_io_fault_tests=9\nactual_io_throw_cases=6\nrollback_held_cases=5\nsafe_state_verified=9\nexecution_exact_set=25\ndesign_repair_exact_set=12\nnetwork_scope=FROZEN_LOCAL_INPUTS_ONLY_NO_NETWORK\nintegration_ceiling=FORMAL_REFERENCE_REGISTRATION_ONLY_GAPS_REMAIN_OPEN_NO_UPGRADE\nmap_effect=APPEND_ONE_REGISTER_ROW_EMAP_046_ONLY\nexecution_release=NOT_RELEASED_PENDING_FOCUSED_INDEPENDENT_REREVIEW\n`;} 
function validationRows(manifestBefore){const faults=runtime.transactionFaultRows(),negative=runtime.negativeRowsR1(),preview=spawnSync(process.execPath,[abs(runtime.SCRIPT),'--preview'],{cwd:ROOT,encoding:'utf8'}),inputErrors=runtime.designInputErrorsR1({requireRelease:false,expectNoExecution:true}),checks=[['NODE_RUNTIME','0',String(spawnSync(process.execPath,['--check',abs(runtime.SCRIPT)],{cwd:ROOT}).status??1)],['NODE_BUILDER','0',String(spawnSync(process.execPath,['--check',abs(SCRIPT)],{cwd:ROOT}).status??1)],['PREVIEW_EXIT','0',String(preview.status??1)],['DESIGN_INPUT_ERRORS','0',String(inputErrors.length)],['REAL_IO_TESTS','9',String(faults.length)],['REAL_IO_PASS','9',String(faults.filter(row=>row.result==='PASS').length)],['ACTUAL_IO_THROW','6',String(faults.filter(row=>row.actual_io_throw==='YES').length)],['ROLLBACK_HELD','5',String(faults.filter(row=>row.actual_result==='ROLLBACK_INCOMPLETE_HELD').length)],['SAFE_STATE','9',String(faults.filter(row=>row.safe_state_verified==='YES').length)],['NEGATIVE_ALL_PASS','28',String(negative.filter(row=>row.result==='PASS').length)],['CONTRACTS','44',String(runtime.contractRowsR1().length)],['SCHEMAS','8',String(runtime.schemaRowsR1().length)],['EXECUTION_EXACT_SET','25',String(runtime.executionSetRowsR1().length)],['DESIGN_EXACT_SET','12',String(designSetRows().length)],['DESIGN_BASELINE','61','61'],['PROTECTED49','49',String(protectedRows().length)],['MAP_CURRENT','45',String(readCsv(runtime.CASE_MAP).rows.length)],['EXECUTION_OUTPUTS','0',String(runtime.GENERATED.filter(file=>fs.existsSync(abs(file))).length)],['EXECUTION_RUN_ROWS','0',String(manifestState(manifestBefore).logicalRows.filter(row=>row.run_id===runtime.EXEC_RUN).length)]];const rows=checks.map((item,index)=>({check_id:`P0INTR1-DESIGN-VAL-${String(index+1).padStart(3,'0')}`,check_description:item[0],expected:item[1],actual:item[2],status:item[1]===item[2]?'PASS':'FAIL',evidence:'ELIGIBLE6_INTEGRATION_REPAIR001_FOCUSED_REAL_IO_ORACLE'}));rows.push({check_id:'P0INTR1-DESIGN-VAL-020',check_description:'SELF_REFERENCE_EXCLUDED',expected:'SELF_REFERENCE_EXCLUDED',actual:'SELF_REFERENCE_EXCLUDED',status:'INFO',evidence:'validation and manifest identities postchecked'});return rows;}
function manifestRowsFor(paths){return paths.map(file=>{const id=identity(file);return{case_id:CASE_ID,run_id:DESIGN_RUN,batch_id:DESIGN_BATCH,artifact_path:file,sha256:id.sha256,bytes:String(id.bytes),mtime:id.mtime};});}
function validateDesign({postManifest=false}={}){const errors=[],checks=[[FAIL_AUTHORITY,runtime.SOURCE_ENTRY_COLUMNS,[auditAuthorityRow(FAILED_AUDIT,'P0INTR1-FAILED-AUDIT-001','result=FAIL','execution_release=NOT_RELEASED')],'FAIL_AUTHORITY'],[runtime.CONTRACT,runtime.CONTRACT_COLUMNS,runtime.contractRowsR1(),'CONTRACT'],[runtime.SCHEMA,runtime.SCHEMA_COLUMNS,runtime.schemaRowsR1(),'SCHEMA'],[runtime.EXEC_SET,runtime.EXEC_SET_COLUMNS,runtime.executionSetRowsR1(),'EXEC_SET'],[DESIGN_SET,DESIGN_SET_COLUMNS,designSetRows(),'DESIGN_SET'],[runtime.FORMAL_ENTRY_AUTHORITY,runtime.FORMAL_ENTRY_COLUMNS,[formalEntryRow()],'FORMAL_ENTRY'],[FAULT_RESULTS,runtime.TRANSACTION_FAULT_COLUMNS,runtime.transactionFaultRows(),'FAULT_RESULTS']];for(const [file,columns,expected,code] of checks){if(!fs.existsSync(abs(file))){errors.push(`${code}_MISSING`);continue;}const parsed=readCsv(file);errors.push(...exactColumns(parsed,columns,code),...compareRows(parsed.rows,expected,columns,code));}errors.push(...runtime.designInputErrorsR1({requireRelease:false,expectNoExecution:true}));const baseline=readCsv(DESIGN_BASELINE),manifest=fs.readFileSync(abs(MANIFEST)),prefixBytes=Number(baseline.rows[2]?.bytes??0),prefix=manifest.subarray(0,prefixBytes);if(baseline.rows.length!==61)errors.push(`BASELINE_COUNT:${baseline.rows.length}:61`);if(hash(prefix)!==baseline.rows[2]?.sha256)errors.push('BASELINE_MANIFEST_PREFIX');for(const row of baseline.rows.slice(4)){if(!fs.existsSync(abs(row.artifact_path))){errors.push(`BASELINE_MISSING:${row.artifact_path}`);continue;}const id=identity(row.artifact_path);if(row.rows!==String(id.rows)||row.bytes!==String(id.bytes)||row.sha256!==id.sha256||Date.parse(row.mtime)!==id.mtimeMs)errors.push(`BASELINE_IDENTITY:${row.artifact_path}`);}if(normalize(fs.readFileSync(abs(REVIEW_REQUEST)))!==requestText())errors.push('REQUEST_TEXT');const validation=readCsv(DESIGN_VALIDATION);if(validation.rows.length!==20||validation.rows.some(row=>row.status==='FAIL'))errors.push('VALIDATION_STATUS');if(postManifest){const expected=manifestRowsFor(designSetRows().map(row=>row.artifact_path)),state=manifestState(manifest,{frozenPrefix:{bytes:prefixBytes,sha256:hash(prefix)},expectedRunRows:expected,expectedRunId:DESIGN_RUN,expectedPhysicalDelta:12,filesystemIdentity:{runIds:[DESIGN_RUN],get:file=>fs.existsSync(abs(file))?identity(file):null}});errors.push(...state.errors.map(code=>`MANIFEST:${code}`));}else if(manifestState(manifest).logicalRows.some(row=>row.run_id===DESIGN_RUN))errors.push('DESIGN_RUN_ROWS_EXIST');return[...new Set(errors)];}
function build(){const existing=designSetRows().slice(2).map(row=>row.artifact_path).filter(file=>fs.existsSync(abs(file)));if(existing.length)throw new Error(`TARGETS_EXIST:${existing.join('|')}`);const manifestBefore=fs.readFileSync(abs(MANIFEST)),created=[];try{const emit=(file,text)=>{write(file,text);created.push(file);};emit(FAIL_AUTHORITY,serializeCsv([auditAuthorityRow(FAILED_AUDIT,'P0INTR1-FAILED-AUDIT-001','result=FAIL','execution_release=NOT_RELEASED')],runtime.SOURCE_ENTRY_COLUMNS));emit(runtime.CONTRACT,serializeCsv(runtime.contractRowsR1(),runtime.CONTRACT_COLUMNS));emit(runtime.SCHEMA,serializeCsv(runtime.schemaRowsR1(),runtime.SCHEMA_COLUMNS));emit(runtime.EXEC_SET,serializeCsv(runtime.executionSetRowsR1(),runtime.EXEC_SET_COLUMNS));emit(DESIGN_SET,serializeCsv(designSetRows(),DESIGN_SET_COLUMNS));emit(runtime.FORMAL_ENTRY_AUTHORITY,serializeCsv([formalEntryRow()],runtime.FORMAL_ENTRY_COLUMNS));emit(FAULT_RESULTS,serializeCsv(runtime.transactionFaultRows(),runtime.TRANSACTION_FAULT_COLUMNS));emit(DESIGN_BASELINE,serializeCsv(baselineRows(manifestBefore),BASELINE_COLUMNS));emit(REVIEW_REQUEST,requestText());const validation=validationRows(manifestBefore);emit(DESIGN_VALIDATION,serializeCsv(validation,VALIDATION_COLUMNS));const validationFailures=validation.filter(row=>row.status==='FAIL');if(validationFailures.length)throw new Error(`DESIGN_VALIDATION_FAIL:${validationFailures.map(row=>`${row.check_description}:${row.expected}:${row.actual}`).join('|')}`);const pre=validateDesign();if(pre.length)throw new Error(`PREWRITE:${pre.join('|')}`);const rows=manifestRowsFor(designSetRows().map(row=>row.artifact_path)),candidate=Buffer.concat([manifestBefore,Buffer.from(serializeManifestDataRows(rows),'utf8')]),state=manifestState(candidate,{frozenPrefix:{bytes:manifestBefore.length,sha256:hash(manifestBefore)},expectedRunRows:rows,expectedRunId:DESIGN_RUN,expectedPhysicalDelta:12});if(state.errors.length)throw new Error(`MANIFEST_CANDIDATE:${state.errors.join('|')}`);fs.writeFileSync(abs(MANIFEST),candidate);const post=validateDesign({postManifest:true});if(post.length)throw new Error(`POSTWRITE:${post.join('|')}`);return{status:'DESIGN_REPAIR001_BUILT_PENDING_FOCUSED_INDEPENDENT_REREVIEW',transaction_fault_tests:9,actual_io_throw_cases:6,rollback_held_cases:5,safe_state_verified:9,negative_tests:28,execution_exact_set:25,design_exact_set:12,manifest_rows:12};}catch(error){fs.writeFileSync(abs(MANIFEST),manifestBefore);for(const file of created.reverse())if(fs.existsSync(abs(file)))fs.rmSync(abs(file));throw error;}}
 
function debugDesignInputErrors(){const manifestBefore=fs.readFileSync(abs(MANIFEST)),created=[];try{const emit=(file,text)=>{write(file,text);created.push(file);};emit(FAIL_AUTHORITY,serializeCsv([auditAuthorityRow(FAILED_AUDIT,'P0INTR1-FAILED-AUDIT-001','result=FAIL','execution_release=NOT_RELEASED')],runtime.SOURCE_ENTRY_COLUMNS));emit(runtime.CONTRACT,serializeCsv(runtime.contractRowsR1(),runtime.CONTRACT_COLUMNS));emit(runtime.SCHEMA,serializeCsv(runtime.schemaRowsR1(),runtime.SCHEMA_COLUMNS));emit(runtime.EXEC_SET,serializeCsv(runtime.executionSetRowsR1(),runtime.EXEC_SET_COLUMNS));emit(DESIGN_SET,serializeCsv(designSetRows(),DESIGN_SET_COLUMNS));emit(runtime.FORMAL_ENTRY_AUTHORITY,serializeCsv([formalEntryRow()],runtime.FORMAL_ENTRY_COLUMNS));emit(FAULT_RESULTS,serializeCsv(runtime.transactionFaultRows(),runtime.TRANSACTION_FAULT_COLUMNS));emit(DESIGN_BASELINE,serializeCsv(baselineRows(manifestBefore),BASELINE_COLUMNS));emit(REVIEW_REQUEST,requestText());return runtime.designInputErrorsR1({requireRelease:false,expectNoExecution:true});}finally{for(const file of created.reverse())if(fs.existsSync(abs(file)))fs.rmSync(abs(file));}}
 
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==='--debug-input-errors')console.log(JSON.stringify({errors:debugDesignInputErrors()},null,2));else if(mode==='--validate-design'){const errors=validateDesign({postManifest:true});console.log(JSON.stringify({status:errors.length?'FAIL':'PASS_DESIGN_REPAIR001_PACKAGE',errors},null,2));if(errors.length)process.exitCode=1;}else if(mode==='--self-test'){const rows=runtime.negativeRowsR1();console.log(JSON.stringify({status:rows.every(row=>row.result==='PASS')?'SELF_TEST_PASS':'FAIL',tests:rows.length,rows},null,2));if(rows.some(row=>row.result!=='PASS'))process.exitCode=1;}else if(mode==='--validate-package-manifest'){const errors=validateDesign({postManifest:true}).filter(error=>error.startsWith('MANIFEST:'));console.log(JSON.stringify({status:errors.length?'FAIL':'PASS_PACKAGE_MANIFEST',errors},null,2));if(errors.length)process.exitCode=1;}else throw new Error(`UNKNOWN_MODE:${mode}`);}