@aibyzero/cm-workflow 0.16.4 → 0.16.6
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/AGENTS.md +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +208 -34
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +977 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Lossless presentation inside the same no-tools prompt. Canonical evidence stays unchanged.
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import {json,need} from './effect-contract.mjs';
|
|
4
|
+
export function compactReviewData(raw){
|
|
5
|
+
const input=json(raw,10*1024*1024),contents={},keys=new Map();
|
|
6
|
+
need(!Object.hasOwn(input,'presentation')&&!Object.hasOwn(input,'contents')&&input.reviewPackage?.packageDigest,'review_presentation_invalid');
|
|
7
|
+
const visit=value=>{
|
|
8
|
+
if(Array.isArray(value))return value.map(visit);
|
|
9
|
+
if(value===null||typeof value!=='object')return value;
|
|
10
|
+
need(!Object.hasOwn(value,'contentRef'),'review_presentation_invalid');
|
|
11
|
+
const out=Object.fromEntries(Object.entries(value).map(([key,item])=>[key,visit(item)]));
|
|
12
|
+
if(typeof value.contentBase64!=='string')return out;
|
|
13
|
+
const bytes=Buffer.from(value.contentBase64,'base64');
|
|
14
|
+
need(bytes.toString('base64')===value.contentBase64,'review_presentation_invalid');
|
|
15
|
+
const hash=createHash('sha256').update(bytes).digest('hex');
|
|
16
|
+
if(Object.hasOwn(value,'sha256'))need(hash===value.sha256,'review_presentation_invalid');
|
|
17
|
+
if(Object.hasOwn(value,'size'))need(bytes.length===value.size,'review_presentation_invalid');
|
|
18
|
+
const key=hash+':'+bytes.length;let ref=keys.get(key);
|
|
19
|
+
if(!ref){
|
|
20
|
+
ref='content-'+(keys.size+1);keys.set(key,ref);
|
|
21
|
+
let text;try{text=new TextDecoder('utf8',{fatal:true}).decode(bytes);}catch{}
|
|
22
|
+
// Byte-exact decoding: BOM or invalid UTF-8 retains the original base64.
|
|
23
|
+
const utf8=text!==undefined&&Buffer.from(text,'utf8').equals(bytes);
|
|
24
|
+
contents[ref]={sha256:hash,size:bytes.length,encoding:utf8?'utf8':'base64',content:utf8?text:value.contentBase64};
|
|
25
|
+
}
|
|
26
|
+
delete out.contentBase64;out.contentRef=ref;return out;
|
|
27
|
+
};
|
|
28
|
+
return {presentation:{version:1,kind:'complete-inline-content-table',
|
|
29
|
+
packageDigest:input.reviewPackage.packageDigest},...visit(input),contents};
|
|
30
|
+
}
|
|
31
|
+
export function expandReviewData(raw){
|
|
32
|
+
const {presentation,contents,...data}=raw;
|
|
33
|
+
need(presentation?.version===1&&presentation.kind==='complete-inline-content-table','review_presentation_invalid');
|
|
34
|
+
const visit=value=>{
|
|
35
|
+
if(Array.isArray(value))return value.map(visit);
|
|
36
|
+
if(value===null||typeof value!=='object')return value;
|
|
37
|
+
const out=Object.fromEntries(Object.entries(value).map(([key,item])=>[key,visit(item)]));
|
|
38
|
+
if(!Object.hasOwn(value,'contentRef'))return out;
|
|
39
|
+
const content=contents[value.contentRef];need(content,'review_presentation_invalid');
|
|
40
|
+
const bytes=Buffer.from(content.content,content.encoding==='utf8'?'utf8':'base64');
|
|
41
|
+
need(bytes.length===content.size&&createHash('sha256').update(bytes).digest('hex')===content.sha256,'review_presentation_invalid');
|
|
42
|
+
delete out.contentRef;out.contentBase64=bytes.toString('base64');return out;
|
|
43
|
+
};
|
|
44
|
+
return visit(data);
|
|
45
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Trusted adapter-side capture, separate from the host's sealed observation.
|
|
2
|
+
// No timers, files, provider queries or dispatch authority live here.
|
|
3
|
+
import {json,need,shape} from './effect-contract.mjs';
|
|
4
|
+
export function reconciliationControl(control) {
|
|
5
|
+
if(typeof control.onReconciliation!=='function')return {signal:control.signal,onEvent:control.onEvent};
|
|
6
|
+
const events=[];let invalid=false,closed=false;
|
|
7
|
+
return {signal:control.signal,onEvent:event=>{
|
|
8
|
+
try{need(!closed&&events.length<64);events.push(json(event,64*1024));}catch{invalid=true;}
|
|
9
|
+
return control.onEvent(event);
|
|
10
|
+
},onTerminal:result=>{
|
|
11
|
+
if(closed)return;closed=true;
|
|
12
|
+
if(invalid)return;
|
|
13
|
+
try{control.onReconciliation(json({events,result,cleanup:'owned_process_group_closed'},512*1024));}catch{}
|
|
14
|
+
}};
|
|
15
|
+
}
|
|
16
|
+
export function readReconciliationReceipt(raw){
|
|
17
|
+
const value=json(raw,512*1024);shape(value,['events','result','cleanup']);
|
|
18
|
+
need(value.cleanup==='owned_process_group_closed','review_reconciliation_evidence_required');
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Pure review data functions. Only task-runner owns invocation/registration.
|
|
2
|
-
import { digest,need,shape,id,text,json,freeze } from './effect-contract.mjs';
|
|
2
|
+
import { digest,need,shape,id,text,json,freeze,REVIEW_TEXT_LIMIT } from './effect-contract.mjs';
|
|
3
3
|
export function reviewPaths(pkg) {
|
|
4
4
|
return [...new Set([...pkg.changes.map(c=>c.path),...pkg.requirements.map(f=>f.path),
|
|
5
5
|
...(pkg.unchangedScope??[]).map(file=>file.path),
|
|
@@ -34,6 +34,52 @@ export function reviewResultForPaths(raw,pkg,paths) {
|
|
|
34
34
|
need(r.verdict!=='approved'||blocking===0,'contradictory_verdict');
|
|
35
35
|
need(r.verdict!=='changes_requested'||blocking>0,'contradictory_verdict');return r;
|
|
36
36
|
}
|
|
37
|
+
// A reviewer result is journaled many times (see developCheckpointReserve), so its
|
|
38
|
+
// text is bounded before any record is written. Rule, applied only when the result
|
|
39
|
+
// JSON without examinedPaths exceeds REVIEW_TEXT_LIMIT bytes:
|
|
40
|
+
// 1. every finding message and evidence and the summary are cut to one shared,
|
|
41
|
+
// largest-fitting byte cap and end with TRUNCATED;
|
|
42
|
+
// 2. if even the smallest cap does not fit, findings are omitted from the end,
|
|
43
|
+
// P3 first, then blocking ones while at least one blocking finding remains,
|
|
44
|
+
// and the summary says how many were omitted.
|
|
45
|
+
// Ids, severities, paths and the verdict are never changed. Malformed results are
|
|
46
|
+
// returned as they are for the validator to refuse. Null means nothing fits.
|
|
47
|
+
const TRUNCATED=' …[cm-ai: truncated to the review text limit]';
|
|
48
|
+
const MIN_CAP=Buffer.byteLength(TRUNCATED)+16;
|
|
49
|
+
const reviewTextBytes=r=>Buffer.byteLength(JSON.stringify(r))-Buffer.byteLength(JSON.stringify(r.examinedPaths));
|
|
50
|
+
function utf8Prefix(value,max){
|
|
51
|
+
const bytes=Buffer.from(value);if(bytes.length<=max)return value;
|
|
52
|
+
let end=max;while(end>0&&(bytes[end]&0xc0)===0x80)end--;
|
|
53
|
+
return bytes.subarray(0,end).toString('utf8');
|
|
54
|
+
}
|
|
55
|
+
export function boundReviewText(value){
|
|
56
|
+
const shaped=value!==null&&typeof value==='object'&&!Array.isArray(value)&&typeof value.summary==='string'
|
|
57
|
+
&&Array.isArray(value.examinedPaths)&&Array.isArray(value.findings)
|
|
58
|
+
&&value.findings.every(f=>f!==null&&typeof f==='object'&&typeof f.message==='string'&&typeof f.evidence==='string');
|
|
59
|
+
if(!shaped||reviewTextBytes(value)<=REVIEW_TEXT_LIMIT)return value;
|
|
60
|
+
const cut=(text,cap)=>Buffer.byteLength(text)<=cap?text:utf8Prefix(text,cap-Buffer.byteLength(TRUNCATED))+TRUNCATED;
|
|
61
|
+
const candidate=(findings,cap,omitted)=>{
|
|
62
|
+
const note=omitted?` [cm-ai: ${omitted} findings omitted to fit the review text limit]`:'';
|
|
63
|
+
return {...value,findings:findings.map(f=>({...f,message:cut(f.message,cap),evidence:cut(f.evidence,cap)})),
|
|
64
|
+
summary:cut(value.summary,Math.max(MIN_CAP,cap-Buffer.byteLength(note)))+note};
|
|
65
|
+
};
|
|
66
|
+
const widest=Math.max(MIN_CAP,...[value.summary,...value.findings.flatMap(f=>[f.message,f.evidence])].map(text=>Buffer.byteLength(text)));
|
|
67
|
+
const fitted=(findings,omitted)=>{
|
|
68
|
+
if(reviewTextBytes(candidate(findings,MIN_CAP,omitted))>REVIEW_TEXT_LIMIT)return null;
|
|
69
|
+
let low=MIN_CAP,high=widest;
|
|
70
|
+
while(low<high){const middle=Math.ceil((low+high)/2);
|
|
71
|
+
if(reviewTextBytes(candidate(findings,middle,omitted))<=REVIEW_TEXT_LIMIT)low=middle;else high=middle-1;}
|
|
72
|
+
return candidate(findings,low,omitted);
|
|
73
|
+
};
|
|
74
|
+
let findings=[...value.findings];
|
|
75
|
+
for(;;){
|
|
76
|
+
const result=fitted(findings,value.findings.length-findings.length);if(result)return result;
|
|
77
|
+
let index=findings.findLastIndex(f=>f.severity==='P3');
|
|
78
|
+
if(index===-1&&findings.filter(f=>f.severity!=='P3').length>1)index=findings.length-1;
|
|
79
|
+
if(index===-1)return null;
|
|
80
|
+
findings=findings.filter((_,position)=>position!==index);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
37
83
|
export function reviewReceipt({request,call,result,reviewPackage,developerProvider,fallbackReasons}) {
|
|
38
84
|
const checked=reviewResult(result,reviewPackage);
|
|
39
85
|
need(call.started===true && call.terminal==='succeeded' && call.requestDigest===request.requestDigest
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Read-only discovery of other task runs' completed, reviewed deliveries in the
|
|
2
|
+
// same specs root. A delivery counts only after its own journal replays through
|
|
3
|
+
// the runner grammar to a committed fixture_completed state: its review package
|
|
4
|
+
// (and any accepted QA-fix packages) then describe reviewed before->after file
|
|
5
|
+
// transitions. This grants nothing, never repairs, and never opens a writer.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
9
|
+
import {readRunnerHistory} from './durable-runner-state.mjs';
|
|
10
|
+
import {deliveredAfter,deliveryStep} from './fix-code-association.mjs';
|
|
11
|
+
import {digest,need} from './effect-contract.mjs';
|
|
12
|
+
|
|
13
|
+
const RUN_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
14
|
+
const cache=new Map();
|
|
15
|
+
|
|
16
|
+
function readDelivery(specsRoot,identity){
|
|
17
|
+
try{
|
|
18
|
+
const snapshot=readExecutionSnapshot({specsRoot,identity});
|
|
19
|
+
const init=snapshot.records[0]?.payload;
|
|
20
|
+
if(init?.protocol!=='cm-task-runner'||init.type!=='init'||![2,3].includes(init.version))return null;
|
|
21
|
+
const history=readRunnerHistory(snapshot.records,init.config,init.version);
|
|
22
|
+
const state=history.state;
|
|
23
|
+
if(history.pending!==null||state.state!=='fixture_completed'||state.taskCommit?.outcome!=='fixture_committed'
|
|
24
|
+
||!state.reviewPackage)return null;
|
|
25
|
+
// Each package carries its own review time: the run's approving review, or
|
|
26
|
+
// for an accepted QA fix the fix's final review registration it cites.
|
|
27
|
+
return Object.freeze({runId:identity.runId,root:init.config.root,taskId:init.config.identity.taskId,
|
|
28
|
+
packages:Object.freeze([{pkg:state.reviewPackage,reviewedAt:approvedReviewAt(state)},
|
|
29
|
+
...history.acceptedFixes.map(item=>({pkg:item.evidence.reviewPackage,reviewedAt:fixReviewedAt(specsRoot,item.evidence)}))])});
|
|
30
|
+
}catch{return null;}
|
|
31
|
+
}
|
|
32
|
+
// A QA fix package's durable review time: the final review registration its
|
|
33
|
+
// completion evidence cites, read from the fix child's own store, for exactly
|
|
34
|
+
// that package. Anything else has no time and never orders.
|
|
35
|
+
export function fixReviewedAt(specsRoot,evidence){
|
|
36
|
+
try{
|
|
37
|
+
const {repositoryId,runId}=evidence.identity;
|
|
38
|
+
const row=readExecutionSnapshot({specsRoot,identity:{repositoryId,runId}}).records.find(record=>
|
|
39
|
+
/^fix-(?:revision-)?final(?:-recovery(?:-[1-9]\d*)?|-retry)?-registered$/.test(record.id)
|
|
40
|
+
&&digest(record.payload)===evidence.reviewRegistrationDigest
|
|
41
|
+
&&record.payload.request?.payload?.reviewPackage?.packageDigest===evidence.reviewPackage.packageDigest);
|
|
42
|
+
return Number.isSafeInteger(row?.payload.registeredAt)?row.payload.registeredAt:null;
|
|
43
|
+
}catch{return null;}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Durable order: when the approving review of this exact package was registered.
|
|
47
|
+
// Journals without a registered V3 review have no order and never qualify.
|
|
48
|
+
export function approvedReviewAt(state){
|
|
49
|
+
const registration=state?.reviewInvocation?.registration;
|
|
50
|
+
return registration&®istration.grant?.packageDigest===state.reviewPackage?.packageDigest
|
|
51
|
+
&&Number.isSafeInteger(registration.registeredAt)?registration.registeredAt:null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function cachedDelivery(specsRoot,repositoryId,runId,stat){
|
|
55
|
+
const slot=[specsRoot,repositoryId,runId].join('\0');
|
|
56
|
+
const version=[stat.dev,stat.ino,stat.size,stat.mtimeMs,stat.ctimeMs].join(':');
|
|
57
|
+
if(cache.get(slot)?.version!==version)cache.set(slot,{version,delivery:readDelivery(specsRoot,{repositoryId,runId})});
|
|
58
|
+
return cache.get(slot).delivery;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Resolve recorded steps to the real, completed, later reviewed packages of the
|
|
62
|
+
// named runs. allowAbsent is only for journal replay: a missing store cannot be
|
|
63
|
+
// re-proved there (returns null), and every live use refuses it.
|
|
64
|
+
export function resolveDeliverySteps({specsRoot,root,identity,after,steps,allowAbsent=false}){
|
|
65
|
+
const resolved=[];
|
|
66
|
+
for(const step of steps){
|
|
67
|
+
need(RUN_ID.test(step.runId)&&step.runId!==identity.runId,'fix_association_unverified');
|
|
68
|
+
let stat;
|
|
69
|
+
try{stat=fs.lstatSync(path.join(specsRoot,'.reviews','.execution',step.runId,'state.json'));}
|
|
70
|
+
catch(error){if(error.code==='ENOENT'){need(allowAbsent,'fix_association_unverified');return null;}throw error;}
|
|
71
|
+
const delivery=cachedDelivery(specsRoot,identity.repositoryId,step.runId,stat);
|
|
72
|
+
need(delivery&&delivery.root===root&&delivery.taskId!==identity.taskId,'fix_association_unverified');
|
|
73
|
+
const found=delivery.packages.find(item=>item.pkg.packageDigest===step.packageDigest);
|
|
74
|
+
need(found&&deliveredAfter(found,after)&&digest(deliveryStep(step.runId,found.pkg,step.beforeFix))===digest(step),'fix_association_unverified');
|
|
75
|
+
resolved.push({...step,pkg:found.pkg});
|
|
76
|
+
}
|
|
77
|
+
return resolved;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Deliveries for the same code root and repository, excluding the caller's own
|
|
81
|
+
// run and any other run of the same task: a superseding rerun of a task is not
|
|
82
|
+
// a later change that its superseded run may adopt.
|
|
83
|
+
export function completedReviewedDeliveries({specsRoot,root,identity}){
|
|
84
|
+
const execution=path.join(specsRoot,'.reviews','.execution');
|
|
85
|
+
let entries;
|
|
86
|
+
try{entries=fs.readdirSync(execution,{withFileTypes:true});}catch{return [];}
|
|
87
|
+
const deliveries=[];
|
|
88
|
+
for(const entry of entries.sort((left,right)=>left.name<right.name?-1:left.name>right.name?1:0)){
|
|
89
|
+
if(!entry.isDirectory()||!RUN_ID.test(entry.name)||entry.name===identity.runId)continue;
|
|
90
|
+
let stat;
|
|
91
|
+
try{stat=fs.lstatSync(path.join(execution,entry.name,'state.json'));}catch{continue;}
|
|
92
|
+
// Replay once per journal version; a changed state.json is read again.
|
|
93
|
+
const delivery=cachedDelivery(specsRoot,identity.repositoryId,entry.name,stat);
|
|
94
|
+
if(delivery&&delivery.root===root&&delivery.taskId!==identity.taskId)deliveries.push(delivery);
|
|
95
|
+
}
|
|
96
|
+
return deliveries;
|
|
97
|
+
}
|
|
@@ -10,16 +10,47 @@ import {readRunnerHistory} from './durable-runner-state.mjs';
|
|
|
10
10
|
import {supersedeWorkflowFile} from './review-evidence-file.mjs';
|
|
11
11
|
import {need,digest} from './effect-contract.mjs';
|
|
12
12
|
import {readEvidenceSupersession,supersedableEvidenceName} from './reviewed-evidence-supersession-record.mjs';
|
|
13
|
+
import {boundReviewText} from './review-runner.mjs';
|
|
13
14
|
import {scanRows} from './cm-ai-qa-log.mjs';
|
|
14
|
-
import {
|
|
15
|
+
import {taskDeclarations,approvedTaskGrammar} from '../spec-task-line.mjs';
|
|
16
|
+
import {compareReviewInventoryToBaseline,readReviewBaseline} from './review-package.mjs';
|
|
15
17
|
|
|
16
18
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
17
19
|
const unavailable=reason=>{const error=new Error('supersede_unavailable');error.code='supersede_unavailable';error.reason=reason;throw error;};
|
|
18
20
|
const hash=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
21
|
+
const codeDrift=reason=>{const error=new Error('supersede_code_drift');error.code='supersede_code_drift';error.reason=reason;throw error;};
|
|
22
|
+
const driftInstruction='这些文件与直接前驱运行开工前的基线不一致。手动还原这些文件后重建运行;或确认保留这些改动时加 --accept-superseded-code-drift 重建(这些文件会被当成已有代码,不进新运行的审查改动)。';
|
|
23
|
+
|
|
24
|
+
function verifyOldCodeBaseline(codeProject,rawBaseline){
|
|
25
|
+
// Legacy journals without a complete V2 inventory cannot prove code drift.
|
|
26
|
+
if(rawBaseline?.version!==2)return [];
|
|
27
|
+
const baseline=readReviewBaseline(rawBaseline);
|
|
28
|
+
let current;
|
|
29
|
+
try{
|
|
30
|
+
if(fs.realpathSync(codeProject)!==codeProject||!fs.lstatSync(codeProject).isDirectory())
|
|
31
|
+
codeDrift(`无法安全核对代码根目录。${driftInstruction}`);
|
|
32
|
+
current=compareReviewInventoryToBaseline(codeProject,baseline);
|
|
33
|
+
}catch(error){
|
|
34
|
+
if(error.code==='supersede_code_drift')throw error;
|
|
35
|
+
codeDrift(`无法安全核对代码树(${error.code??'read_failed'})。${driftInstruction}`);
|
|
36
|
+
}
|
|
37
|
+
// The shared comparison filters both sides with one ignore-decision union.
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The direct predecessor's last review receipt, or the context it carried itself
|
|
42
|
+
// when it never reached a review. Bounded like any journaled review text.
|
|
43
|
+
function carriedReviewFrom(runId,state,supersession){
|
|
44
|
+
const result=state.receipts.at(-1)?.result;
|
|
45
|
+
if(!result)return supersession?.carriedReview??null;
|
|
46
|
+
const bounded=boundReviewText({verdict:result.verdict,packageDigest:result.packageDigest,
|
|
47
|
+
examinedPaths:[],findings:result.findings,summary:result.summary});
|
|
48
|
+
return bounded?{previousRunId:runId,verdict:bounded.verdict,summary:bounded.summary,findings:bounded.findings}:null;
|
|
49
|
+
}
|
|
19
50
|
|
|
20
51
|
function taskChecked(tasksPath,taskId){
|
|
21
|
-
const
|
|
22
|
-
|
|
52
|
+
const rows=taskDeclarations(fs.readFileSync(tasksPath,'utf8'),
|
|
53
|
+
{grammar:approvedTaskGrammar(path.dirname(path.dirname(tasksPath)))}).filter(task=>task.id===taskId);
|
|
23
54
|
if(rows.length!==1)unavailable('tasks.md 中任务身份不唯一或不存在');
|
|
24
55
|
return rows[0].completed;
|
|
25
56
|
}
|
|
@@ -65,14 +96,14 @@ export function oldWriterOpen(execution,runId,{lsofPath}={}){
|
|
|
65
96
|
unavailable(`缺少核对旧运行 ${runId} writer 占用的本地工具`);
|
|
66
97
|
}
|
|
67
98
|
|
|
68
|
-
export function prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason,tasksPath}){
|
|
99
|
+
export function prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason,tasksPath,acceptSupersededCodeDrift=false}){
|
|
69
100
|
if(typeof reason!=='string'||!reason.trim()||Buffer.byteLength(reason,'utf8')>500||/[\r\n\0]/.test(reason))
|
|
70
101
|
unavailable('必须提供单行且不超过 500 字节的 --supersede-reason');
|
|
71
102
|
if(taskChecked(tasksPath,identity.taskId))unavailable('tasks.md 已将任务标为完成;若 QA BLOCKED 后确需重跑,先将该任务改回 - [ ],再以 --supersede-reviewed-evidence 和 --supersede-reason 创建新运行');
|
|
72
103
|
const reviewsDir=path.join(specsDir,'.reviews');
|
|
73
|
-
if(!fs.existsSync(reviewsDir))unavailable('
|
|
104
|
+
if(!fs.existsSync(reviewsDir))unavailable('没有同 feature、task 的旧运行');
|
|
74
105
|
const execution=path.join(reviewsDir,'.execution');
|
|
75
|
-
const previousRunIds=[];
|
|
106
|
+
const previousRunIds=[],priorRuns=[],alreadySuperseded=new Set();
|
|
76
107
|
if(fs.existsSync(execution))for(const entry of fs.readdirSync(execution,{withFileTypes:true})){
|
|
77
108
|
if(!entry.isDirectory()||entry.name===identity.runId)continue;
|
|
78
109
|
const stateFile=path.join(execution,entry.name,'state.json');
|
|
@@ -89,24 +120,87 @@ export function prepareReviewedEvidenceSupersession({specsDir,codeProject,featur
|
|
|
89
120
|
unavailable(`旧运行 ${entry.name} 的任务身份或路径不匹配`);
|
|
90
121
|
if(first.version!==3)unavailable(`旧运行 ${entry.name} 的 journal 版本无法验证`);
|
|
91
122
|
const history=readRunnerHistory(snapshot.records,first.config,3);
|
|
92
|
-
if(history.pending
|
|
123
|
+
if(history.pending){
|
|
124
|
+
const exit=history.pendingAbandonable?'abandon_effect':
|
|
125
|
+
history.pending.kind==='review'&&history.state.reviewInvocation?.registration
|
|
126
|
+
&&history.state.reviewInvocation.result===null?'abandon_review':'原运行恢复入口';
|
|
127
|
+
unavailable(`旧运行 ${entry.name} 的 ${history.pending.kind} effect 已中断且未结;先确认旧 host 和子进程已退出,再在原 run 上使用 ${exit},随后重新发起 supersede`);
|
|
128
|
+
}
|
|
129
|
+
if(!['blocked','cancelled','unknown','fixture_completed'].includes(history.state.state))
|
|
93
130
|
unavailable(`旧运行 ${entry.name} 仍可继续或有未结操作`);
|
|
94
131
|
if(oldWriterOpen(execution,entry.name))unavailable(`旧运行 ${entry.name} 的 writer 仍被进程持有`);
|
|
95
132
|
const qa=qaTerminal(specsDir,entry.name,identity.taskId);
|
|
96
133
|
if(history.state.state==='fixture_completed'&&!['BLOCKED','never_finished'].includes(qa))
|
|
97
|
-
unavailable(
|
|
134
|
+
unavailable(qa==='completed'?`旧运行 ${entry.name} 已完成(run_done)`
|
|
135
|
+
:['PASS','PASSED'].includes(qa)?`旧运行 ${entry.name} 的 QA 已通过`
|
|
136
|
+
:['FAIL','FAILED'].includes(qa)?`旧运行 ${entry.name} 的最新 QA 结果为 FAIL(未通过),失败要修复而不是重开发:在原运行上用 QA 修复(fix_advance / fix_run)处理;修复子运行的审查卡在结果未知时,确认旧进程已退出后用 abandon_review 放弃一次再重审`
|
|
137
|
+
:`旧运行 ${entry.name} 的最新 QA 结果为 ${qa},不是 BLOCKED,不能用重开发替换;请在原运行上按该结果的恢复入口处理`);
|
|
138
|
+
priorRuns.push({runId:entry.name,baseline:first.baseline,
|
|
139
|
+
carriedReview:carriedReviewFrom(entry.name,history.state,history.supersession)});
|
|
140
|
+
for(const runId of history.supersession?.previousRunIds??[])alreadySuperseded.add(runId);
|
|
98
141
|
previousRunIds.push(entry.name);
|
|
99
142
|
}
|
|
100
143
|
if(!previousRunIds.length)unavailable('没有同 feature、task 的旧运行');
|
|
144
|
+
const drift=priorRuns.filter(run=>!alreadySuperseded.has(run.runId))
|
|
145
|
+
.flatMap(run=>verifyOldCodeBaseline(codeProject,run.baseline)
|
|
146
|
+
.map(file=>({predecessorRunId:run.runId,...file})))
|
|
147
|
+
.sort((a,b)=>a.path<b.path?-1:a.path>b.path?1:
|
|
148
|
+
a.predecessorRunId<b.predecessorRunId?-1:a.predecessorRunId>b.predecessorRunId?1:0);
|
|
149
|
+
if(drift.length&&!acceptSupersededCodeDrift){
|
|
150
|
+
const paths=[...new Set(drift.map(file=>file.path))],listed=paths.slice(0,20).join('、');
|
|
151
|
+
codeDrift(`${listed}${paths.length>20?` 等 ${paths.length-20} 个`:''}:${driftInstruction}`);
|
|
152
|
+
}
|
|
153
|
+
// A run that stopped before any handoff or review has nothing to archive; the
|
|
154
|
+
// record still ends the prior runs and carries any accepted code drift.
|
|
155
|
+
const previous=new Set(previousRunIds);
|
|
156
|
+
const carriedReview=priorRuns.filter(run=>!alreadySuperseded.has(run.runId)&&run.carriedReview
|
|
157
|
+
&&previous.has(run.carriedReview.previousRunId))
|
|
158
|
+
.sort((a,b)=>a.runId<b.runId?-1:a.runId>b.runId?1:0).at(-1)?.carriedReview??null;
|
|
101
159
|
const names=evidenceNames(reviewsDir,feature,identity.taskId);
|
|
102
|
-
if(!names.length)unavailable('没有可归档的旧任务证据');
|
|
103
160
|
const files=names.map(name=>{
|
|
104
161
|
const p=path.join(reviewsDir,name),stat=fs.lstatSync(p);
|
|
105
162
|
if(!stat.isFile()||stat.isSymbolicLink()||stat.nlink!==1)unavailable(`证据文件不可安全归档:${name}`);
|
|
106
163
|
return {name,sha256:hash(fs.readFileSync(p))};
|
|
107
164
|
});
|
|
108
165
|
return readEvidenceSupersession({version:1,feature,taskId:identity.taskId,newRunId:identity.runId,
|
|
109
|
-
previousRunIds:previousRunIds.sort(),reason,files,authorizedAt:new Date().toISOString()
|
|
166
|
+
previousRunIds:previousRunIds.sort(),reason,files,authorizedAt:new Date().toISOString(),
|
|
167
|
+
...(drift.length?{acceptedCodeDrift:drift}:{}),...(carriedReview?{carriedReview}:{})});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// A plain create (no supersede) must not silently adopt a previous run's
|
|
171
|
+
// unreviewed edits as its baseline. Same comparison as supersede, over the runs
|
|
172
|
+
// of this task that no later run has superseded; the only way to keep the
|
|
173
|
+
// edits is the explicit supersede record with --accept-superseded-code-drift.
|
|
174
|
+
export function assertNoUnrecordedPriorCode({specsDir,codeProject,feature,identity,tasksPath}){
|
|
175
|
+
const execution=path.join(specsDir,'.reviews','.execution');
|
|
176
|
+
if(!fs.existsSync(execution))return;
|
|
177
|
+
const priorRuns=[],superseded=new Set();
|
|
178
|
+
for(const entry of fs.readdirSync(execution,{withFileTypes:true})){
|
|
179
|
+
if(!entry.isDirectory()||entry.name===identity.runId)continue;
|
|
180
|
+
if(!fs.existsSync(path.join(execution,entry.name,'state.json')))continue;
|
|
181
|
+
let snapshot;
|
|
182
|
+
try{snapshot=readExecutionSnapshot({specsRoot:specsDir,
|
|
183
|
+
identity:{repositoryId:identity.repositoryId,runId:entry.name}});}
|
|
184
|
+
catch(error){if(error.code==='identity_mismatch')continue;throw error;}
|
|
185
|
+
const first=snapshot.records[0]?.payload;
|
|
186
|
+
// Other tasks, roots and pre-V3 journals are out of this comparison (the
|
|
187
|
+
// latter cannot prove drift, as in supersede).
|
|
188
|
+
if(first?.version!==3||first.config?.identity?.taskId!==identity.taskId
|
|
189
|
+
||first.config?.taskLearning?.feature!==feature||first.config.root!==codeProject
|
|
190
|
+
||first.config.completion?.owner?.tasksPath!==tasksPath)continue;
|
|
191
|
+
const record=snapshot.records[1]?.payload;
|
|
192
|
+
if(record?.type==='evidence-superseded')for(const runId of readEvidenceSupersession(record.record).previousRunIds)
|
|
193
|
+
superseded.add(runId);
|
|
194
|
+
priorRuns.push({runId:entry.name,baseline:first.baseline});
|
|
195
|
+
}
|
|
196
|
+
const drift=priorRuns.filter(run=>!superseded.has(run.runId))
|
|
197
|
+
.flatMap(run=>verifyOldCodeBaseline(codeProject,run.baseline).map(file=>({runId:run.runId,path:file.path})));
|
|
198
|
+
if(!drift.length)return;
|
|
199
|
+
const paths=[...new Set(drift.map(file=>file.path))].sort(),runs=[...new Set(drift.map(file=>file.runId))].sort();
|
|
200
|
+
codeDrift(`旧运行 ${runs.join('、')} 开工后这些文件被改动,且没有替代记录:${paths.slice(0,20).join('、')}`
|
|
201
|
+
+`${paths.length>20?` 等 ${paths.length-20} 个`:''}。新运行不会把它们当成已有代码。`
|
|
202
|
+
+'可选:回到旧运行继续;手动还原这些文件后再新建;或旧运行结束后用 --supersede-reviewed-evidence --supersede-reason 原因 '
|
|
203
|
+
+'--accept-superseded-code-drift 新建(改动记入替代记录,作为已有代码,不进新运行的审查改动)。');
|
|
110
204
|
}
|
|
111
205
|
|
|
112
206
|
export function archiveReviewedEvidence(reviewsDir,raw){
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
// Strict V3 payload grammar, shared by live authorization and journal replay.
|
|
2
|
-
import {need,shape,id,hex,json} from './effect-contract.mjs';
|
|
2
|
+
import {need,shape,id,hex,text,json,REVIEW_TEXT_LIMIT} from './effect-contract.mjs';
|
|
3
|
+
|
|
4
|
+
// Read-only context carried from the most recent superseded run's last review
|
|
5
|
+
// receipt. It is never a verdict: runners only show it to the attempt-1
|
|
6
|
+
// developer and reviewer, and stage, attempt and budget rules never read it.
|
|
7
|
+
export function readCarriedReview(value,previousRunIds=null){
|
|
8
|
+
const fail=()=>need(false,'supersede_record_invalid');
|
|
9
|
+
try{
|
|
10
|
+
shape(value,['previousRunId','verdict','summary','findings']);id(value.previousRunId);
|
|
11
|
+
need(['approved','changes_requested','blocked'].includes(value.verdict));text(value.summary);
|
|
12
|
+
need(Array.isArray(value.findings)&&value.findings.length<=100);
|
|
13
|
+
const ids=new Set();
|
|
14
|
+
for(const f of value.findings){
|
|
15
|
+
shape(f,['id','severity','path','message','evidence']);id(f.id);need(!ids.has(f.id));ids.add(f.id);
|
|
16
|
+
need(['P0','P1','P2','P3'].includes(f.severity));text(f.path);text(f.message);text(f.evidence);
|
|
17
|
+
}
|
|
18
|
+
const {previousRunId,...body}=value;
|
|
19
|
+
need(Buffer.byteLength(JSON.stringify(body),'utf8')<=REVIEW_TEXT_LIMIT);
|
|
20
|
+
}catch{fail();}
|
|
21
|
+
if(previousRunIds)need(previousRunIds.has(value.previousRunId),'supersede_record_invalid');
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
3
24
|
|
|
4
25
|
export function readEvidenceSupersession(raw,expected=null){
|
|
5
26
|
const record=json(raw,1024*1024);
|
|
6
|
-
shape(record,['version','feature','taskId','newRunId','previousRunIds','reason','files','authorizedAt'
|
|
27
|
+
shape(record,['version','feature','taskId','newRunId','previousRunIds','reason','files','authorizedAt',
|
|
28
|
+
...(Object.hasOwn(record,'acceptedCodeDrift')?['acceptedCodeDrift']:[]),
|
|
29
|
+
...(Object.hasOwn(record,'carriedReview')?['carriedReview']:[])]);
|
|
7
30
|
need(record.version===1,'supersede_record_invalid');
|
|
8
31
|
need(typeof record.authorizedAt==='string'
|
|
9
32
|
&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(record.authorizedAt)
|
|
@@ -11,9 +34,25 @@ export function readEvidenceSupersession(raw,expected=null){
|
|
|
11
34
|
for(const key of ['feature','taskId','newRunId'])id(record[key]);
|
|
12
35
|
need(Array.isArray(record.previousRunIds)&&record.previousRunIds.length>0&&record.previousRunIds.length<=128,'supersede_record_invalid');
|
|
13
36
|
const runs=new Set();for(const runId of record.previousRunIds){id(runId);need(!runs.has(runId)&&runId!==record.newRunId,'supersede_record_invalid');runs.add(runId);}
|
|
37
|
+
if(Object.hasOwn(record,'acceptedCodeDrift')){
|
|
38
|
+
need(Array.isArray(record.acceptedCodeDrift)&&record.acceptedCodeDrift.length>0
|
|
39
|
+
&&record.acceptedCodeDrift.length<=8192,'supersede_record_invalid');
|
|
40
|
+
const seen=new Set();
|
|
41
|
+
for(const file of record.acceptedCodeDrift){
|
|
42
|
+
shape(file,['predecessorRunId','path','sha256']);
|
|
43
|
+
need(runs.has(file.predecessorRunId)&&typeof file.path==='string'&&file.path.length>0
|
|
44
|
+
&&file.path.normalize('NFC')===file.path&&!/[\\:\x00-\x1f\x7f-\x9f]/.test(file.path)
|
|
45
|
+
&&file.path.split('/').every(part=>part&&part!=='.'&&part!=='..'),'supersede_record_invalid');
|
|
46
|
+
if(file.sha256!==null)hex(file.sha256);
|
|
47
|
+
const key=`${file.predecessorRunId}\0${file.path}`;
|
|
48
|
+
need(!seen.has(key),'supersede_record_invalid');seen.add(key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if(Object.hasOwn(record,'carriedReview'))readCarriedReview(record.carriedReview,runs);
|
|
14
52
|
need(typeof record.reason==='string'&&record.reason.trim()&&Buffer.byteLength(record.reason,'utf8')<=500
|
|
15
53
|
&&!/[\r\n\0]/.test(record.reason),'supersede_reason_required');
|
|
16
|
-
|
|
54
|
+
// Zero files: the prior runs stopped before any handoff or review existed.
|
|
55
|
+
need(Array.isArray(record.files)&&record.files.length<=256,'supersede_record_invalid');
|
|
17
56
|
const names=new Set();for(const file of record.files){
|
|
18
57
|
shape(file,['name','sha256']);
|
|
19
58
|
need(typeof file.name==='string'&&/^[A-Za-z0-9._-]+\.(md|json)$/.test(file.name)
|