@aibyzero/cm-workflow 0.16.6 → 0.16.8
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +29 -0
- package/README.md +32 -1
- package/VERSION +1 -1
- package/assets/readme/workflow-recovery-detailed.png +0 -0
- package/assets/readme/workflow-stages-detailed.png +0 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +84 -9
- package/docs/user-guide.md +104 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-admission.mjs +37 -11
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +56 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +172 -33
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +2 -2
- package/runtime/js/cm-ai/drive-core.mjs +17 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +29 -0
- package/runtime/js/cm-ai/execution-store.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -3
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +89 -19
- package/runtime/js/cm-ai/host-session.mjs +46 -6
- package/runtime/js/cm-ai/host-tool-bridge.mjs +15 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
- package/runtime/js/cm-ai/log-rows.mjs +36 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +3 -0
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
- package/runtime/js/cm-ai/task-runner.mjs +6 -1
- package/runtime/js/cm-fix/cause-package.mjs +37 -8
- package/runtime/js/cm-fix/diagnosis.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +189 -148
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/investigation.mjs +25 -9
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +3 -1
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- package/runtime/js/cm-test/recovery.mjs +4 -4
- package/runtime/js/notify-run.mjs +26 -0
- package/runtime/js/notify.mjs +388 -0
- package/runtime/model-efficiency.md +17 -0
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +2 -2
- package/scripts/cm-ai-batch-host.mjs +7 -2
- package/scripts/cm-ai-batch-run.mjs +11 -2
- package/scripts/cm-ai-batch-run.test.mjs +9 -1
- package/scripts/cm-ai-drive.mjs +18 -4
- package/scripts/cm-ai-drive.test.mjs +30 -0
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
- package/scripts/cm-ai-host.mjs +20 -8
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +77 -4
- package/scripts/cm-ai-run.mjs +36 -5
- package/scripts/cm-fix-abandon.test.mjs +89 -3
- package/scripts/cm-fix-cause-package.test.mjs +33 -0
- package/scripts/cm-fix-drive.mjs +9 -1
- package/scripts/cm-fix-host.mjs +1 -1
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
- package/scripts/cm-host-qa-executor.test.mjs +429 -3
- package/scripts/cm-log-event.mjs +53 -6
- package/scripts/cm-notify.test.mjs +468 -0
- package/scripts/cm-patrol.mjs +83 -0
- package/scripts/cm-patrol.test.mjs +161 -0
- package/scripts/cm-prd-host.mjs +13 -2
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- package/scripts/cm-test-branch-impact.test.mjs +11 -0
- package/scripts/cm-token-report.mjs +497 -0
- package/scripts/cm-token-report.test.mjs +346 -0
- package/skills/cm-ai/SKILL.md +7 -3
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +2 -2
- package/skills/cm-ai/references/js-host-modes.md +90 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +110 -0
- package/skills/cm-ai/references/js-host-recovery.md +199 -0
- package/skills/cm-ai/references/js-host.md +69 -330
- package/skills/cm-fix/SKILL.md +2 -0
- package/skills/cm-fix/references/js-host.md +16 -9
- package/skills/cm-prd/SKILL.md +7 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// One fix_diagnose validator for journal replay, live answers and the driver
|
|
2
|
+
// preflight. Replay keeps its historical error codes; a live answer that fails
|
|
3
|
+
// becomes invalid_diagnosis with the failing field, so the caller can resubmit.
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {json,need,shape,text} from '../cm-ai/effect-contract.mjs';
|
|
6
|
+
import {tagDiagnosticReason} from '../cm-ai/diagnostic-reason.mjs';
|
|
7
|
+
import {atField,inspectFixInvestigation} from './investigation.mjs';
|
|
8
|
+
|
|
9
|
+
export function inspectFixDiagnosis(raw){
|
|
10
|
+
const value=atField('(answer)',()=>json(raw,32*1024));
|
|
11
|
+
atField('(answer)',()=>shape(value,['status','rootCause','affectedPaths','plan','crossLayer','affectedModules',...(Object.hasOwn(value,'investigation')?['investigation']:[])]));
|
|
12
|
+
atField('status',()=>need(['diagnosed','needs_evidence','design_change'].includes(value.status),'invalid_diagnosis'));
|
|
13
|
+
for(const key of ['rootCause','plan'])atField(key,()=>text(value[key]));
|
|
14
|
+
atField('crossLayer',()=>need(typeof value.crossLayer==='boolean','invalid_diagnosis'));
|
|
15
|
+
if(Object.hasOwn(value,'investigation'))inspectFixInvestigation(value.investigation,value.crossLayer);
|
|
16
|
+
for(const key of ['affectedPaths','affectedModules']){
|
|
17
|
+
atField(key,()=>need(Array.isArray(value[key])&&value[key].length>0&&value[key].length<=32,'invalid_diagnosis'),32,
|
|
18
|
+
Array.isArray(value[key])?value[key].length:null);
|
|
19
|
+
value[key].forEach((item,index)=>atField(`${key}[${index}]`,()=>{
|
|
20
|
+
text(item);need(!path.isAbsolute(item)&&item===path.posix.normalize(item)
|
|
21
|
+
&&item!=='.'&&!item.startsWith('../')&&!/[\\\0]/.test(item),'invalid_diagnosis');
|
|
22
|
+
}));
|
|
23
|
+
atField(key,()=>need(new Set(value[key]).size===value[key].length,'invalid_diagnosis'));
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function describeFixDiagnosisError(error){
|
|
29
|
+
const field=typeof error?.field==='string'?error.field:'(answer)';
|
|
30
|
+
const limit=Number.isSafeInteger(error?.limit)?`:最多 ${error.limit} 项${Number.isSafeInteger(error.actual)?`,实际 ${error.actual} 项`:''}`:'';
|
|
31
|
+
return `诊断答案字段 ${field} 不合法${limit}(${error?.code??'invalid_input'})`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Live answer: never an interruption. The step stays pending and the same
|
|
35
|
+
// request may be answered again; nothing about the rejected answer is recorded.
|
|
36
|
+
export function fixDiagnosisAnswer(raw){
|
|
37
|
+
try{return inspectFixDiagnosis(raw);}
|
|
38
|
+
catch(error){
|
|
39
|
+
const failure=Object.assign(new Error('invalid_diagnosis'),{code:'invalid_diagnosis'});
|
|
40
|
+
throw tagDiagnosticReason(failure,describeFixDiagnosisError(error));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const isInvalidFixDiagnosis=error=>error?.code==='invalid_diagnosis'&&typeof error.reason==='string';
|
|
@@ -38,7 +38,8 @@ import {readProjectInstructionContext} from '../cm-ai/cm-ai-context-refresh.mjs'
|
|
|
38
38
|
import {publishFixDossier,publishFixObservationDossier,publishFixEscalationDossier,readFixObservationArchive} from './dossier.mjs';
|
|
39
39
|
import {readFixWalkthrough,fixWalkthroughBinding,createFixWalkthrough,inspectFixWalkthrough,verifyFixWalkthroughEvidence,walkthroughCoversDiagnosis} from './walkthrough.mjs';
|
|
40
40
|
import {logFixEvent} from './start.mjs';
|
|
41
|
-
import {
|
|
41
|
+
import {fixInvestigationRequest} from './investigation.mjs';
|
|
42
|
+
import {inspectFixDiagnosis,fixDiagnosisAnswer,isInvalidFixDiagnosis} from './diagnosis.mjs';
|
|
42
43
|
import {finishFix,fixCompletionProjection,eventsAt,isFixObservationExit} from './finish.mjs';
|
|
43
44
|
import {specsPermissionArgs} from '../cm-ai/codex-config.mjs';
|
|
44
45
|
import {protectedFixBridge} from './protected-edits.mjs';
|
|
@@ -68,11 +69,14 @@ const retryBase=id=>id.replace(/-retry-[1-8]-(intent|result)$/,'-$1');
|
|
|
68
69
|
const latestStepRecord=(records,id)=>[...records].reverse().find(row=>retryBase(row.id)===id);
|
|
69
70
|
// A cause or second-round final review that produced no review result may be
|
|
70
71
|
// abandoned once, audited, and dispatched again under its own record prefix.
|
|
72
|
+
// Each cause review round has its own one-time abandonment: round 1 under
|
|
73
|
+
// fix-cause-*, the post-rediagnosis round 2 under fix-cause-rediagnosis-*.
|
|
71
74
|
const REVIEW_ABANDON={cause_review:'fix-cause',revision_final_review:'fix-revision-final'};
|
|
72
75
|
const causeRecord=(records,suffix)=>{
|
|
73
76
|
const marker=records.findIndex(row=>row.id==='fix-rediagnosis-intent');
|
|
77
|
+
const tail=marker<0?null:records.slice(marker+1),retried=tail?.some(row=>row.id==='fix-cause-rediagnosis-abandoned');
|
|
74
78
|
const row=marker<0?reviewCycleRecord(records,'fix-cause',suffix)
|
|
75
|
-
:
|
|
79
|
+
:tail.find(row=>row.id===`fix-cause-rediagnosis-${retried?'retry-':''}${suffix}`);
|
|
76
80
|
return suffix==='result'?reconciledFixResultRecord(records,row):row;
|
|
77
81
|
};
|
|
78
82
|
const reviewCycleRecord=(records,prefix,suffix)=>{
|
|
@@ -88,27 +92,21 @@ function reviewTimeout(adapter,fallback){
|
|
|
88
92
|
return adapter.timeoutMs;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
const value=json(raw,32*1024);
|
|
93
|
-
shape(value,['status','rootCause','affectedPaths','plan','crossLayer','affectedModules',...(Object.hasOwn(value,'investigation')?['investigation']:[])]);
|
|
94
|
-
need(['diagnosed','needs_evidence','design_change'].includes(value.status),'invalid_diagnosis');
|
|
95
|
-
for(const key of ['rootCause','plan'])text(value[key]);
|
|
96
|
-
need(typeof value.crossLayer==='boolean','invalid_diagnosis');
|
|
97
|
-
if(Object.hasOwn(value,'investigation'))inspectFixInvestigation(value.investigation,value.crossLayer);
|
|
98
|
-
for(const key of ['affectedPaths','affectedModules']){
|
|
99
|
-
need(Array.isArray(value[key])&&value[key].length>0&&value[key].length<=32,'invalid_diagnosis');
|
|
100
|
-
for(const item of value[key]){
|
|
101
|
-
text(item);need(!path.isAbsolute(item)&&item===path.posix.normalize(item)
|
|
102
|
-
&&item!=='.'&&!item.startsWith('../')&&!/[\\\0]/.test(item),'invalid_diagnosis');
|
|
103
|
-
}
|
|
104
|
-
need(new Set(value[key]).size===value[key].length,'invalid_diagnosis');
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
95
|
+
const diagnosis=inspectFixDiagnosis;
|
|
108
96
|
|
|
109
|
-
const HISTORY_INSPECTION=Symbol('fix-history-inspection');
|
|
97
|
+
const HISTORY_INSPECTION=Symbol('fix-history-inspection'),DURABLE_HISTORY=Symbol('fix-durable-history');
|
|
110
98
|
// Same owner projection, backed by a read-only journal and no writer/dispatch.
|
|
111
99
|
export function inspectFixExecutionHistory({specsRoot,identity}){
|
|
100
|
+
return readFixHistory({specsRoot,identity},owner=>owner.status());
|
|
101
|
+
}
|
|
102
|
+
// The same read-only owner's completion evidence: present only for a run that
|
|
103
|
+
// reached its normal completed closeout (approved final review of the exact
|
|
104
|
+
// package, task_done and run_done bound), else it throws. Grants nothing.
|
|
105
|
+
export function inspectFixCompletionHistory({specsRoot,identity}){
|
|
106
|
+
return readFixHistory({specsRoot,identity,durable:true},(owner,initial)=>({identity:initial.identity,
|
|
107
|
+
configuration:initial.configuration,evidence:owner.completionEvidence()}));
|
|
108
|
+
}
|
|
109
|
+
function readFixHistory({specsRoot,identity,durable=false},read){
|
|
112
110
|
const snapshot=readExecutionSnapshot({specsRoot,identity});
|
|
113
111
|
const initial=snapshot.records[0]?.payload;need(initial?.workflow==='cm-fix-stages-v1','fix_history_invalid');
|
|
114
112
|
validIdentity(initial.identity);
|
|
@@ -117,11 +115,12 @@ export function inspectFixExecutionHistory({specsRoot,identity}){
|
|
|
117
115
|
need(digest(snapshot.fingerprints)===digest({workflow:digest('cm-fix-stages-v1'),config:digest(initial.configuration),inputs:digest(initial.identity)}),'fingerprint_mismatch');
|
|
118
116
|
const {archiveMode,...configuration}=initial.configuration;
|
|
119
117
|
need(archiveMode===undefined||archiveMode==='bare','fix_history_invalid');
|
|
120
|
-
const owner=openFixExecution({specsRoot:archiveMode==='bare'?null:specsRoot,identity:initial.identity,configuration,create:false},{[HISTORY_INSPECTION]:snapshot});
|
|
121
|
-
try{return owner
|
|
118
|
+
const owner=openFixExecution({specsRoot:archiveMode==='bare'?null:specsRoot,identity:initial.identity,configuration,create:false},{[HISTORY_INSPECTION]:snapshot,[DURABLE_HISTORY]:durable});
|
|
119
|
+
try{return read(owner,initial);}finally{owner.close();}
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
export function openFixExecution(options,{bridge=null,prepare=null,causeReview=null,finalReview=null,assertReviewReady=null,[HISTORY_INSPECTION]:inspectionSnapshot=null}={}){
|
|
122
|
+
export function openFixExecution(options,{bridge=null,prepare=null,causeReview=null,finalReview=null,assertReviewReady=null,[HISTORY_INSPECTION]:inspectionSnapshot=null,[DURABLE_HISTORY]:durableHistory=false}={}){
|
|
123
|
+
need(!durableHistory||inspectionSnapshot,'fix_read_only');
|
|
125
124
|
shape(options,['identity','configuration','create',...(Object.hasOwn(options,'hostContextId')?['hostContextId']:[]),
|
|
126
125
|
...(Object.hasOwn(options,'specsRoot')?['specsRoot']:[])]);
|
|
127
126
|
const {identity,configuration:originalConfiguration,create}=json(options,64*1024);validIdentity(identity);
|
|
@@ -519,9 +518,10 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
519
518
|
diagnosed=diagnosis(record.payload);pending=null;
|
|
520
519
|
stage=diagnosed.status==='needs_evidence'?'rediagnosis_blocked':'cause_review_required';continue;
|
|
521
520
|
}
|
|
522
|
-
|
|
521
|
+
// Round 2 (after rediagnosis) replays as the cause review cycle, including its own one-time abandonment and retry.
|
|
522
|
+
const causeRevised=/^fix-cause-rediagnosis-((?:retry-)?(?:registered|started|result)|abandoned)$/.exec(record.id);
|
|
523
523
|
if(causeRevised){need(rediagnosis!==null,'fix_history_invalid');record={...record,id:`fix-cause-${causeRevised[1]}`};}
|
|
524
|
-
else if(rediagnosis!==null&&/^fix-cause-(?:retry-)?(?:registered|started|result)$/.test(record.id))need(false,'fix_history_invalid');
|
|
524
|
+
else if(rediagnosis!==null&&/^fix-cause-(?:(?:retry-)?(?:registered|started|result)|abandoned)$/.test(record.id))need(false,'fix_history_invalid');
|
|
525
525
|
// After a one-time abandonment only the retry cycle's records are valid.
|
|
526
526
|
const reviewRetry=/^(fix-cause|fix-revision-final)-retry-(registered|started|result)$/.exec(record.id);
|
|
527
527
|
if(reviewRetry){
|
|
@@ -1090,102 +1090,108 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1090
1090
|
if(configuration.walkthrough&&diagnosed?.status==='diagnosed'
|
|
1091
1091
|
&&['red_test_required','cause_review_required'].includes(stage)
|
|
1092
1092
|
&&!walkthroughCoversDiagnosis(configuration.walkthrough,diagnosed))stage='walkthrough_configuration_mismatch';
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1093
|
+
// Live re-verification of the run's evidence against the current tree. A
|
|
1094
|
+
// durable history read (a completed run as a later delivery of its root) asks
|
|
1095
|
+
// only what the journal and its closeout settled: later reviewed changes may
|
|
1096
|
+
// legitimately move these files, and the caller checks the tree itself.
|
|
1097
|
+
if(!durableHistory){
|
|
1098
|
+
if(causeResult?.review?.verdict==='approved'&&stage!=='cancelled'&&repairBaseline===null){
|
|
1099
|
+
try{
|
|
1100
|
+
const current=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
1101
|
+
context:Object.hasOwn(cause.request.payload.reviewPackage,'contextFiles'),status:{identity,stage:'cause_review_required',reproduction,diagnosis:diagnosed,learning,
|
|
1102
|
+
...(rediagnosis?{rediagnosis}:{}),
|
|
1103
|
+
...(cause.request.payload.reviewPackage.correction?{causeReviewCorrection:cause.request.payload.reviewPackage.correction}:{})}});
|
|
1104
|
+
verifyFixCauseTransition(cause.request.payload.reviewPackage,current,authorBaseline,authored);
|
|
1105
|
+
}catch{stage='cause_review_drift';}
|
|
1106
|
+
}
|
|
1107
|
+
if(causeResult?.observationStatus==='completed'&&!['cancelled','cause_review_drift'].includes(stage)){
|
|
1108
|
+
try{publishCause(true);}catch{stage='cause_review_evidence_required';}
|
|
1109
|
+
}
|
|
1110
|
+
if(red&&!(revisionAuthorBaseline&&stage==='unknown')&&!['cancelled','cause_review_drift','cause_review_evidence_required'].includes(stage)){
|
|
1111
|
+
try{verifyFixRedEvidence(red,configuration.redTest,evidenceSpecsRoot,currentTestFiles(red.testFiles,revisionAuthored?.outcome==='authored'?{files:revisionAuthored.testFiles}:null));}catch{stage='red_test_evidence_required';}
|
|
1112
|
+
}
|
|
1113
|
+
if(baseline&&['repair_required','baseline_blocked'].includes(stage)){
|
|
1114
|
+
try{need(digest(fixBaselineFiles(configuration.baseline))===digest(baseline.testFiles),'baseline_files_changed');}
|
|
1115
|
+
catch{stage='baseline_evidence_required';}
|
|
1116
|
+
}
|
|
1117
|
+
if(stage===redStage()&&configuration.testAuthor&&!authored)stage='test_author_required';
|
|
1118
|
+
if(stage===redStage()&&authored){
|
|
1119
|
+
try{need(digest(redTestFiles(configuration.redTest))===digest(authored.testFiles),'test_author_drift');}
|
|
1120
|
+
catch{stage='test_author_evidence_required';}
|
|
1121
|
+
}
|
|
1122
|
+
if(!revisionAuthorBaseline&&repaired&&!learningPackage&&['regression_required','repair_blocked','handoff_required','regression_blocked','handoff_ready','learning_writeback_required','learning_writeback_blocked',...finalStages].includes(stage)){
|
|
1123
|
+
try{verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,baseline:repairBaseline,result:repaired});}
|
|
1124
|
+
catch{stage='repair_evidence_required';}
|
|
1125
|
+
}
|
|
1126
|
+
if(!revisionAuthorBaseline&&retrospective&&!learningPackage&&['handoff_ready','learning_writeback_required',...finalStages].includes(stage)){
|
|
1127
|
+
try{need(implementationPackage(regression).packageDigest===retrospective.packageDigest,'retrospective_drift');}
|
|
1128
|
+
catch{stage='retrospective_evidence_required';}
|
|
1129
|
+
}
|
|
1130
|
+
if(!revisionAuthorBaseline&&learningPackage&&['handoff_ready',...finalStages].includes(stage)){
|
|
1131
|
+
try{need(implementationPackage(regression,true).packageDigest===learningPackage.packageDigest,'writeback_drift');}
|
|
1132
|
+
catch{stage='learning_writeback_evidence_required';}
|
|
1133
|
+
}
|
|
1134
|
+
if(!revisionAuthorBaseline&&handoff&&finalStages.includes(stage)){
|
|
1135
|
+
try{
|
|
1136
|
+
const checked=verifyHostHandoff({root:configuration.reproduction.cwd,baseline:learningPackage?fixLearningReviewBaseline(reviewBaseline()):reviewBaseline(),
|
|
1137
|
+
checks:reviewChecks(regression),handoffPath:handoffPath(),evidence:store.snapshot().records.find(record=>record.id==='fix-handoff-intent').payload.evidence});
|
|
1138
|
+
need(checked.handoffSha256===handoff.handoffSha256,'handoff_drift');
|
|
1139
|
+
}catch{stage='handoff_evidence_required';}
|
|
1140
|
+
}
|
|
1141
|
+
if(finalResult?.observationStatus==='completed'&&finalStages.includes(stage)){
|
|
1142
|
+
try{publishFinal(true);if(finalResult.review.verdict==='approved'&&!n5)stage='completion_gate_required';}
|
|
1143
|
+
catch{stage='final_review_evidence_required';}
|
|
1144
|
+
}
|
|
1145
|
+
if(n5&&['post_review_regression_required','post_review_regression_blocked','closeout_required','walkthrough_blocked'].includes(stage)){
|
|
1146
|
+
try{need(digest(checkN5(n5Options()))===digest(n5.gate),'n5_binding_mismatch');}
|
|
1147
|
+
catch{stage='completion_gate_required';}
|
|
1148
|
+
}
|
|
1149
|
+
if(walkthrough&&['closeout_required','walkthrough_blocked'].includes(stage)){
|
|
1150
|
+
try{verifyFixWalkthroughEvidence(walkthrough,evidenceSpecsRoot);}catch{stage='walkthrough_evidence_required';}
|
|
1151
|
+
}
|
|
1152
|
+
if(revision&&['final_review_changes_requested','walkthrough_blocked','post_review_regression_blocked'].includes(stage))stage='revision_prepared';
|
|
1153
|
+
if(stage==='revision_test_author_required'){
|
|
1154
|
+
try{verifyRevisionStart(captureReviewBaseline({root:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,
|
|
1155
|
+
identity:revision.nextIdentity,scope:revision.tests.testFiles,requirements:configuration.repair.requirements}));}
|
|
1156
|
+
catch{stage='revision_test_evidence_required';}
|
|
1157
|
+
}
|
|
1158
|
+
if(revisionAuthored?.outcome==='authored'&&!['unknown','cancelled'].includes(stage)){
|
|
1159
|
+
try{
|
|
1160
|
+
verifyExtensionFiles(configuration.reproduction.cwd,{plan:revision.tests,files:revisionAuthored.testFiles});
|
|
1161
|
+
if(!revisionBaseline)verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,
|
|
1162
|
+
baseline:revisionAuthorBaseline,result:{outcome:'repaired',baselineDigest:revisionAuthored.baselineDigest,changedFiles:revisionAuthored.changedFiles,files:revisionAuthored.testFiles,completionEligible:false}});
|
|
1163
|
+
}catch{stage='revision_test_evidence_required';}
|
|
1164
|
+
}
|
|
1165
|
+
if(revisionRepair&&!revisionLearningPackage&&['revision_regression_required','revision_repair_blocked','revision_handoff_required','revision_regression_blocked','revision_handoff_ready','revision_learning_writeback_required','revision_learning_writeback_blocked',...revisionFinalStages].includes(stage)){
|
|
1166
|
+
try{verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,baseline:revisionBaseline,result:revisionRepair,allowUnchanged:Boolean(revision.tests)});}
|
|
1167
|
+
catch{stage='revision_repair_evidence_required';}
|
|
1168
|
+
}
|
|
1169
|
+
if(revisionRetrospective&&!revisionLearningPackage&&['revision_handoff_ready','revision_learning_writeback_required',...revisionFinalStages].includes(stage)){
|
|
1170
|
+
try{need(revisionImplementationPackage(revisionRegression).packageDigest===revisionRetrospective.packageDigest,'retrospective_drift');}
|
|
1171
|
+
catch{stage='revision_retrospective_evidence_required';}
|
|
1172
|
+
}
|
|
1173
|
+
if(revisionLearningPackage&&['revision_handoff_ready',...revisionFinalStages].includes(stage)){
|
|
1174
|
+
try{need(revisionImplementationPackage(revisionRegression).packageDigest===revisionLearningPackage.packageDigest,'writeback_drift');}
|
|
1175
|
+
catch{stage='revision_learning_writeback_evidence_required';}
|
|
1176
|
+
}
|
|
1177
|
+
if(revisionHandoff&&revisionFinalStages.includes(stage)){
|
|
1178
|
+
try{
|
|
1179
|
+
const checked=verifyHostHandoff({root:configuration.reproduction.cwd,baseline:revisionReviewBaseline(),checks:reviewChecks(revisionRegression),
|
|
1180
|
+
handoffPath:revisionHandoffPath(),evidence:store.snapshot().records.find(row=>row.id==='fix-revision-handoff-intent').payload.evidence});
|
|
1181
|
+
need(checked.handoffSha256===revisionHandoff.handoffSha256,'handoff_drift');
|
|
1182
|
+
}catch{stage='revision_handoff_evidence_required';}
|
|
1183
|
+
}
|
|
1184
|
+
if(revisionFinalResult?.observationStatus==='completed'&&revisionFinalStages.includes(stage)){
|
|
1185
|
+
try{publishRevisionFinal(true);if(revisionFinalResult.review.verdict==='approved'&&!revisionN5)stage='revision_completion_gate_required';}
|
|
1186
|
+
catch{stage='revision_final_review_evidence_required';}
|
|
1187
|
+
}
|
|
1188
|
+
if(revisionN5&&['revision_post_review_regression_required','revision_post_review_regression_blocked','revision_closeout_required','revision_walkthrough_blocked'].includes(stage)){
|
|
1189
|
+
try{need(digest(checkN5(revisionN5Options()))===digest(revisionN5.gate),'n5_binding_mismatch');}
|
|
1190
|
+
catch{stage='revision_completion_gate_required';}
|
|
1191
|
+
}
|
|
1192
|
+
if(revisionWalkthrough&&['revision_closeout_required','revision_walkthrough_blocked'].includes(stage)){
|
|
1193
|
+
try{verifyFixWalkthroughEvidence(revisionWalkthrough,evidenceSpecsRoot);}catch{stage='revision_walkthrough_evidence_required';}
|
|
1194
|
+
}
|
|
1189
1195
|
}
|
|
1190
1196
|
if(observationResume&&!['unknown','cancelled'].includes(stage)){
|
|
1191
1197
|
try{verifyObservationResume(observationResume);}catch{stage='observation_resume_evidence_required';}
|
|
@@ -1217,7 +1223,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1217
1223
|
// disconnect or cancellation observation. Each kind may be abandoned once.
|
|
1218
1224
|
const noReviewResult=(registration,result,kind)=>stage==='unknown'&®istration!==null
|
|
1219
1225
|
&&(pending===kind&&!result||pending===null&&result!==null&&result.observationStatus!=='completed');
|
|
1220
|
-
const causeNoResult=
|
|
1226
|
+
const causeNoResult=noReviewResult(cause,causeResult,'cause_review');
|
|
1221
1227
|
const revisionNoResult=noReviewResult(revisionFinalRegistration,revisionFinalResult,'revision_final_review');
|
|
1222
1228
|
if(stage==='unknown'&&[...reviewLedger.receipts.values()].some(p=>reviewLedger.applied.has(p.invocationId)&&p.inspection.kind==='cm-provider-review-failure')){stage='review_provider_failed';pending=null;}
|
|
1223
1229
|
const reviewAbandonable=!(configuration.externalModels||configuration.executionPolicy)&&causeNoResult&&!causeAbandonment?'cause_review':!(configuration.externalModels||configuration.executionPolicy)&&revisionNoResult&&!revisionAbandonment?'revision_final_review':null;
|
|
@@ -1311,7 +1317,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1311
1317
|
const current=project();
|
|
1312
1318
|
need(current.reviewAbandonBudgetExhausted!==true,'fix_review_abandon_budget_exhausted');
|
|
1313
1319
|
need(current.reviewAbandonable,'fix_review_abandon_unavailable');
|
|
1314
|
-
const records=store.snapshot().records,prefix=
|
|
1320
|
+
const records=store.snapshot().records,prefix=current.reviewAbandonable==='cause_review'&¤t.rediagnosis
|
|
1321
|
+
?'fix-cause-rediagnosis':REVIEW_ABANDON[current.reviewAbandonable];
|
|
1315
1322
|
const registration=records.find(row=>row.id===`${prefix}-registered`),result=records.find(row=>row.id===`${prefix}-result`)??null;
|
|
1316
1323
|
append(`${prefix}-abandoned`,'result',{invocationId:registration.payload.request.invocationId,registrationDigest:digest(registration.payload),
|
|
1317
1324
|
providerThreadId:records.find(row=>row.id===`${prefix}-started`)?.payload.providerThreadId??null,
|
|
@@ -1864,7 +1871,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1864
1871
|
need(configuration.causeReview&&causeReview&&typeof causeReview.authorize==='function'&&typeof causeReview.run==='function','cause_review_unavailable');
|
|
1865
1872
|
const reviewer=configuration.causeReview;
|
|
1866
1873
|
const budget=reviewTimeout(causeReview,configuration.reproduction.timeoutMs);
|
|
1867
|
-
const prefix
|
|
1874
|
+
const prefix=`${status.rediagnosis?'fix-cause-rediagnosis':'fix-cause'}${status.causeReviewAbandonment?'-retry':''}`;
|
|
1868
1875
|
const abandonedThread=status.causeReviewAbandonment?.providerThreadId??null;
|
|
1869
1876
|
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,status});
|
|
1870
1877
|
const request=requestFor({invocationId:`fix-cause.${randomUUID()}`,identity,role:'reviewer',provider:reviewer.provider,
|
|
@@ -1911,8 +1918,17 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1911
1918
|
// The review budget expiring is a recorded no-result observation, not an
|
|
1912
1919
|
// unrecorded interruption; a cancellation or invalid stream stays unknown.
|
|
1913
1920
|
if(invalid||controller.signal.aborted&&!timedOut||project().stage==='cancelled')return project();
|
|
1914
|
-
|
|
1915
|
-
inspectCauseResult(value,registration,reviewConfiguration,started);
|
|
1921
|
+
let value={dispatchAt,observation:observation(timedOut?{status:'failed',code:'timeout'}:result)};
|
|
1922
|
+
try{inspectCauseResult(value,registration,reviewConfiguration,started);}
|
|
1923
|
+
catch(error){
|
|
1924
|
+
// A reviewer that finished but whose answer breaks the verdict contract
|
|
1925
|
+
// (e.g. invalid_finding_path, missing_material) is a recorded failed
|
|
1926
|
+
// observation with that code, never a silently dropped result. The same
|
|
1927
|
+
// events must still bind; otherwise it stays unrecorded as before.
|
|
1928
|
+
if(timedOut||result?.status!=='succeeded'||configuration.externalModels||configuration.executionPolicy)throw error;
|
|
1929
|
+
value={dispatchAt,observation:observation({status:'failed',code:typeof error?.code==='string'&&/^[a-z_]{1,64}$/.test(error.code)?error.code:'observation_invalid'})};
|
|
1930
|
+
inspectCauseResult(value,registration,reviewConfiguration,started);
|
|
1931
|
+
}
|
|
1916
1932
|
append(`${prefix}-result`,'result',value);
|
|
1917
1933
|
if(!receiptConflict)saveReviewReceipt(prefix,capturedReceipt);
|
|
1918
1934
|
if(project().causeReview?.observationStatus==='completed')publishCause();
|
|
@@ -1925,14 +1941,29 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1925
1941
|
},
|
|
1926
1942
|
async rediagnose({authorized=false,reason}={}){
|
|
1927
1943
|
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_rediagnosis_authorization_required');
|
|
1928
|
-
const start=project();
|
|
1944
|
+
const start=project();
|
|
1945
|
+
// The one continuation is the intent. It binds the request (prior review,
|
|
1946
|
+
// its feedback, Learning), never an answer, so an intent left without a
|
|
1947
|
+
// result (rejected answer or lost reply) is answered again under itself.
|
|
1948
|
+
const reasking=start.stage==='unknown'&&start.pending==='rediagnosis'&&Boolean(start.rediagnosis);
|
|
1949
|
+
need(reasking||start.stage==='rediagnosis_required'&&!start.rediagnosis,'fix_rediagnosis_unavailable');
|
|
1929
1950
|
text(reason);need(Buffer.byteLength(reason,'utf8')<=1000&&!/[\r\n\0\u0085\u2028\u2029]/.test(reason),'fix_rediagnosis_reason_invalid');
|
|
1930
|
-
need(bridge!==null,'fix_rediagnosis_unavailable');
|
|
1931
|
-
const
|
|
1951
|
+
need(bridge!==null,'fix_rediagnosis_unavailable');
|
|
1952
|
+
const records=store.snapshot().records,marker=records.findIndex(row=>row.id==='fix-rediagnosis-intent');
|
|
1953
|
+
const before=marker<0?records:records.slice(0,marker);
|
|
1954
|
+
const prior=reviewCycleRecord(before,'fix-cause','registered').payload;
|
|
1955
|
+
if(reasking){
|
|
1956
|
+
need(digest(prior)===start.rediagnosis.priorRegistrationDigest,'fix_rediagnosis_unavailable');
|
|
1957
|
+
publishCauseEvidence({specsRoot:evidenceSpecsRoot,configuration:reviewConfiguration,inspectOnly:true,round:1,registration:prior,
|
|
1958
|
+
started:reviewCycleRecord(before,'fix-cause','started')?.payload.providerThreadId??null,
|
|
1959
|
+
result:reviewCycleRecord(before,'fix-cause','result')?.payload});
|
|
1960
|
+
}else publishCause(true);
|
|
1961
|
+
const priorPackage=prior.request.payload.reviewPackage;
|
|
1932
1962
|
const assertBasis=()=>{
|
|
1933
1963
|
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
1934
|
-
status:{...start,stage:'cause_review_required'}
|
|
1935
|
-
|
|
1964
|
+
status:reasking?{...start,stage:'cause_review_required',rediagnosis:null,learning:priorPackage.learning}
|
|
1965
|
+
:{...start,stage:'cause_review_required'}});
|
|
1966
|
+
need(pkg.packageDigest===priorPackage.packageDigest,'fix_rediagnosis_source_changed');
|
|
1936
1967
|
const slug=identity.taskId.slice(6);
|
|
1937
1968
|
const slot=path.join(evidenceSpecsRoot,'.reviews',`fix-${slug}-cause-r2.md`);
|
|
1938
1969
|
let occupied=false;
|
|
@@ -1941,27 +1972,34 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1941
1972
|
return pkg;
|
|
1942
1973
|
};
|
|
1943
1974
|
const pkg=assertBasis();
|
|
1944
|
-
const
|
|
1975
|
+
const reviewFeedback=reasking?start.rediagnosis.reviewFeedback:start.causeReview.review;
|
|
1976
|
+
const controller=new AbortController();active=controller;let registered=reasking,timer;
|
|
1945
1977
|
try{
|
|
1946
1978
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1979
|
+
if(!reasking){
|
|
1980
|
+
const learning=prepare===null?start.learning:inspectFixLearning(await prepare({identity,defect:configuration.defect},controller.signal));
|
|
1981
|
+
need(!controller.signal.aborted,'fix_learning_interrupted');
|
|
1982
|
+
need(project().stage===start.stage,'fix_evidence_changed');
|
|
1983
|
+
// Preparation awaits current-session work; recheck its original evidence before the single continuation is registered.
|
|
1984
|
+
assertBasis();
|
|
1985
|
+
const history=store.snapshot().records;
|
|
1986
|
+
append('fix-rediagnosis-intent','intent',{reason,historyDigest:digest(history),priorRegistrationDigest:digest(prior),
|
|
1987
|
+
priorObservationDigest:start.causeReview.observationDigest,priorPackageDigest:pkg.packageDigest,
|
|
1988
|
+
priorProviderThreadId:start.causeReview.providerThreadId,
|
|
1989
|
+
reviewFeedback,learning});registered=true;
|
|
1990
|
+
}
|
|
1991
|
+
const value=fixDiagnosisAnswer(await bridge.call('fix_diagnose',{identity,defect:configuration.defect,
|
|
1958
1992
|
codeProject:configuration.reproduction.cwd,reproduction:start.reproduction,previousDiagnosis:start.diagnosis,
|
|
1959
|
-
reviewFeedback
|
|
1993
|
+
reviewFeedback,diagnosticRecord:fixInvestigationRequest,
|
|
1960
1994
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration})},controller.signal));
|
|
1961
1995
|
if(controller.signal.aborted)return project();
|
|
1962
1996
|
if(configuration.qaSource)inspectFixQaSource({specsRoot,identity,configuration});
|
|
1963
1997
|
append('fix-rediagnosis-result','result',value);return project();
|
|
1964
|
-
}catch(error){
|
|
1998
|
+
}catch(error){
|
|
1999
|
+
// A rejected answer is reported, not hidden as an interruption; rediagnosis stays pending.
|
|
2000
|
+
if(!registered||isInvalidFixDiagnosis(error))throw error;
|
|
2001
|
+
return project();
|
|
2002
|
+
}
|
|
1965
2003
|
finally{clearTimeout(timer);active=null;}
|
|
1966
2004
|
},
|
|
1967
2005
|
async advance({authorized=false}={}){
|
|
@@ -1997,7 +2035,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1997
2035
|
let value;
|
|
1998
2036
|
if(diagnosing){
|
|
1999
2037
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
2000
|
-
value=
|
|
2038
|
+
value=fixDiagnosisAnswer(await Promise.race([interrupted,Promise.resolve().then(()=>bridge.call('fix_diagnose',{
|
|
2001
2039
|
identity,defect:configuration.defect,codeProject:configuration.reproduction.cwd,
|
|
2002
2040
|
reproduction:current.observationReproduction,diagnosticRecord:fixInvestigationRequest,
|
|
2003
2041
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration}),
|
|
@@ -2009,7 +2047,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2009
2047
|
append(`${prefix}-result`,'result',value);current=project();
|
|
2010
2048
|
}
|
|
2011
2049
|
return current;
|
|
2012
|
-
}catch(error){if(!registered)throw error;return project();}
|
|
2050
|
+
}catch(error){if(!registered||isInvalidFixDiagnosis(error))throw error;return project();}
|
|
2013
2051
|
finally{clearTimeout(timer);controller.signal.removeEventListener('abort',rejectAbort);active=null;}
|
|
2014
2052
|
}
|
|
2015
2053
|
if(!['reproduce','diagnose'].includes(start.stage))return start;
|
|
@@ -2040,7 +2078,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2040
2078
|
?createFixReproduction(configuration.reproduction,{specsRoot:protectedSpecsRoot}):reproduce)({identity},{signal:controller.signal,authorized:true});
|
|
2041
2079
|
else{
|
|
2042
2080
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
2043
|
-
value=
|
|
2081
|
+
value=fixDiagnosisAnswer(await bridge.call('fix_diagnose',{identity,defect:configuration.defect,
|
|
2044
2082
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration}),
|
|
2045
2083
|
codeProject:configuration.reproduction.cwd,reproduction:current.reproduction,diagnosticRecord:fixInvestigationRequest},controller.signal));
|
|
2046
2084
|
}
|
|
@@ -2057,6 +2095,9 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2057
2095
|
'fix_learning_interrupted','cancelled','host_disconnected'].includes(error?.code)?error.code:'fix_preparation_failed';
|
|
2058
2096
|
need(false,code);
|
|
2059
2097
|
}
|
|
2098
|
+
// A rejected answer is reported as such; the intent stays without a result
|
|
2099
|
+
// (abandon_step remains the recovery). Transport loss stays unknown and is never redispatched.
|
|
2100
|
+
if(isInvalidFixDiagnosis(error))throw error;
|
|
2060
2101
|
// Intent without a valid result is unknown, including transport loss; never redispatch it.
|
|
2061
2102
|
return project();
|
|
2062
2103
|
}finally{active=null;}
|
|
@@ -11,25 +11,8 @@ import {logFixEvent} from './start.mjs';
|
|
|
11
11
|
import {loadConfig} from '../../../scripts/cm-workflow-config.mjs';
|
|
12
12
|
import {fixDossierRelative} from './layout.mjs';
|
|
13
13
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
const base='.reviews/host-log-mirror/runs',directory=path.join(specsRoot,base);
|
|
17
|
-
if(!fs.existsSync(directory))return [];
|
|
18
|
-
const names=[];
|
|
19
|
-
for(const month of fs.readdirSync(directory).sort()){
|
|
20
|
-
need(/^\d{4}-\d{2}$/.test(month)&&fs.realpathSync(path.join(directory,month))===path.join(directory,month),'fix_log_failed');
|
|
21
|
-
for(const file of fs.readdirSync(path.join(directory,month)).sort())if(file.endsWith('.jsonl'))names.push(`${base}/${month}/${file}`);
|
|
22
|
-
}
|
|
23
|
-
return names.flatMap(name=>{
|
|
24
|
-
const [file]=readReviewSourceFiles(specsRoot,[name]);
|
|
25
|
-
return new TextDecoder('utf-8',{fatal:true}).decode(Buffer.from(file.contentBase64,'base64')).trim().split('\n').filter(Boolean).map(JSON.parse);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
if(!fs.existsSync(path.join(specsRoot,'运行日志.jsonl')))return [];
|
|
29
|
-
const [file]=readReviewSourceFiles(specsRoot,['运行日志.jsonl']);
|
|
30
|
-
const body=new TextDecoder('utf-8',{fatal:true}).decode(Buffer.from(file.contentBase64,'base64')).trim();
|
|
31
|
-
return body?body.split('\n').map(JSON.parse):[];
|
|
32
|
-
}
|
|
14
|
+
export {eventsAt} from './log-events.mjs';
|
|
15
|
+
import {eventsAt} from './log-events.mjs';
|
|
33
16
|
const matches=(row,identity)=>row.workflow==='cm-fix'&&row.node==='FIX'&&row.run_id===identity.runId
|
|
34
17
|
&&row.repository_id===identity.repositoryId&&row.task===identity.taskId&&row.attempt===identity.attempt;
|
|
35
18
|
export const isFixObservationExit=row=>row.event==='run_done'&&row.phase==='observation'&&row.result==='observing';
|
|
@@ -2,19 +2,35 @@
|
|
|
2
2
|
// Structural completeness is not proof: independent Review checks the claims.
|
|
3
3
|
import {need,shape,text} from '../cm-ai/effect-contract.mjs';
|
|
4
4
|
|
|
5
|
+
// Names the first failing field (and its item limit) on the thrown error without
|
|
6
|
+
// changing its code, so a rejected answer can say what to fix.
|
|
7
|
+
export function atField(field,check,limit=null,actual=null){
|
|
8
|
+
try{return check();}
|
|
9
|
+
catch(error){
|
|
10
|
+
if(error&&typeof error==='object'&&error.field===undefined)Object.assign(error,{field},limit===null?{}:{limit,actual});
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const count=value=>Array.isArray(value)?value.length:null;
|
|
15
|
+
|
|
5
16
|
export function inspectFixInvestigation(value,crossLayer){
|
|
6
|
-
shape(value,['discardedAlternatives','boundaryAnalysis']);
|
|
7
|
-
need(Array.isArray(value.discardedAlternatives)
|
|
8
|
-
|
|
17
|
+
atField('investigation',()=>shape(value,['discardedAlternatives','boundaryAnalysis']));
|
|
18
|
+
atField('investigation.discardedAlternatives',()=>need(Array.isArray(value.discardedAlternatives)
|
|
19
|
+
&&value.discardedAlternatives.length<=3,'invalid_fix_investigation'),3,count(value.discardedAlternatives));
|
|
20
|
+
value.discardedAlternatives.forEach((item,index)=>atField(`investigation.discardedAlternatives[${index}]`,
|
|
21
|
+
()=>{shape(item,['option','reason']);text(item.option);text(item.reason);}));
|
|
9
22
|
const boundary=value.boundaryAnalysis;
|
|
10
23
|
if(boundary===null)return value; // Missing evidence stays missing, even on cross-layer work.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
atField('investigation.boundaryAnalysis',()=>{
|
|
25
|
+
need(crossLayer===true,'invalid_fix_investigation');
|
|
26
|
+
shape(boundary,['callChain','edgeEvidence','lastNormalEdge','firstFailingEdge','hypotheses']);
|
|
27
|
+
for(const key of ['callChain','edgeEvidence','lastNormalEdge','firstFailingEdge'])atField(`investigation.boundaryAnalysis.${key}`,()=>text(boundary[key]));
|
|
28
|
+
});
|
|
29
|
+
atField('investigation.boundaryAnalysis.hypotheses',()=>need(Array.isArray(boundary.hypotheses)&&boundary.hypotheses.length>0
|
|
30
|
+
&&boundary.hypotheses.length<=3,'invalid_fix_investigation'),3,count(boundary.hypotheses));
|
|
31
|
+
boundary.hypotheses.forEach((item,index)=>atField(`investigation.boundaryAnalysis.hypotheses[${index}]`,()=>{
|
|
16
32
|
shape(item,['hypothesis','support','counterTest','result']);for(const key of ['hypothesis','support','counterTest','result'])text(item[key]);
|
|
17
|
-
}
|
|
33
|
+
}));
|
|
18
34
|
return value;
|
|
19
35
|
}
|
|
20
36
|
|