@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
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {readExecutionPolicy} from '../cm-ai/execution-policy.mjs';
|
|
2
|
+
import {readExecutionSnapshot} from '../cm-ai/execution-snapshot.mjs';
|
|
3
|
+
import {acquireExternalRunGuard,externalRunGuardExists} from '../cm-ai/external-run-guard.mjs';
|
|
4
|
+
import {fixReviewLedger,reconciledFixResultRecord} from './review-reconciliation.mjs';
|
|
5
|
+
import {readReconciliationReceipt} from '../cm-ai/review-reconciliation.mjs';
|
|
6
|
+
import {readExternalModels} from '../cm-ai/external-models.mjs';
|
|
1
7
|
// Fixed initial cm-fix stages over the shared durable store; no task completion authority.
|
|
2
8
|
import {inventory,readTestExtensionPlan,extensionConfig,inspectExtensionCheck,currentTestFiles,verifyExtensionFiles,extendRevisionReviewBaseline} from './test-extension.mjs';
|
|
3
9
|
import path from 'node:path';
|
|
@@ -9,7 +15,7 @@ import {inspectFixQaSource,readFixQaSourceHistory,qaFixIdentity,fixQaDiagnosisEv
|
|
|
9
15
|
import {digest,id,json,need,shape,text,validIdentity,requestFor,failureCode} from '../cm-ai/effect-contract.mjs';
|
|
10
16
|
import {createFixReproduction,inspectFixReproduction} from './reproduce.mjs';
|
|
11
17
|
import {inspectFixLearning} from './learning.mjs';
|
|
12
|
-
import {createFixCausePackage,verifyFixCauseTransition} from './cause-package.mjs';
|
|
18
|
+
import {createFixCausePackage,verifyFixCauseTransition,rediagnosisPackage} from './cause-package.mjs';
|
|
13
19
|
import {validateCauseReviewer,inspectCauseRegistration,inspectCauseResult,causeExpectation,fixHostContexts,MAX_FIX_JOINED_HOSTS} from './cause-invocation.mjs';
|
|
14
20
|
import {inspectProviderCauseReview} from '../cm-ai/provider-review-observation.mjs';
|
|
15
21
|
import {publishCauseEvidence} from './cause-evidence.mjs';
|
|
@@ -60,6 +66,27 @@ function stepRecord(id){
|
|
|
60
66
|
}
|
|
61
67
|
const retryBase=id=>id.replace(/-retry-[1-8]-(intent|result)$/,'-$1');
|
|
62
68
|
const latestStepRecord=(records,id)=>[...records].reverse().find(row=>retryBase(row.id)===id);
|
|
69
|
+
// A cause or second-round final review that produced no review result may be
|
|
70
|
+
// abandoned once, audited, and dispatched again under its own record prefix.
|
|
71
|
+
const REVIEW_ABANDON={cause_review:'fix-cause',revision_final_review:'fix-revision-final'};
|
|
72
|
+
const causeRecord=(records,suffix)=>{
|
|
73
|
+
const marker=records.findIndex(row=>row.id==='fix-rediagnosis-intent');
|
|
74
|
+
const row=marker<0?reviewCycleRecord(records,'fix-cause',suffix)
|
|
75
|
+
:records.slice(marker+1).find(row=>row.id===`fix-cause-rediagnosis-${suffix}`);
|
|
76
|
+
return suffix==='result'?reconciledFixResultRecord(records,row):row;
|
|
77
|
+
};
|
|
78
|
+
const reviewCycleRecord=(records,prefix,suffix)=>{
|
|
79
|
+
const row=records.some(row=>row.id===`${prefix}-abandoned`)
|
|
80
|
+
?records.find(row=>row.id===`${prefix}-retry-${suffix}`):records.find(row=>row.id===`${prefix}-${suffix}`);
|
|
81
|
+
return suffix==='result'?reconciledFixResultRecord(records,row):row;
|
|
82
|
+
};
|
|
83
|
+
// Reviews wait for their own budget (host review configuration), never for the
|
|
84
|
+
// reproduction command's. Embedders that supply none keep the historical budget.
|
|
85
|
+
function reviewTimeout(adapter,fallback){
|
|
86
|
+
if(adapter?.timeoutMs===undefined)return fallback;
|
|
87
|
+
need(Number.isInteger(adapter.timeoutMs)&&adapter.timeoutMs>=1&&adapter.timeoutMs<=3600000,'invalid_review_config');
|
|
88
|
+
return adapter.timeoutMs;
|
|
89
|
+
}
|
|
63
90
|
|
|
64
91
|
function diagnosis(raw){
|
|
65
92
|
const value=json(raw,32*1024);
|
|
@@ -79,7 +106,22 @@ function diagnosis(raw){
|
|
|
79
106
|
return value;
|
|
80
107
|
}
|
|
81
108
|
|
|
82
|
-
|
|
109
|
+
const HISTORY_INSPECTION=Symbol('fix-history-inspection');
|
|
110
|
+
// Same owner projection, backed by a read-only journal and no writer/dispatch.
|
|
111
|
+
export function inspectFixExecutionHistory({specsRoot,identity}){
|
|
112
|
+
const snapshot=readExecutionSnapshot({specsRoot,identity});
|
|
113
|
+
const initial=snapshot.records[0]?.payload;need(initial?.workflow==='cm-fix-stages-v1','fix_history_invalid');
|
|
114
|
+
validIdentity(initial.identity);
|
|
115
|
+
const runIdentity={repositoryId:initial.identity.repositoryId,runId:initial.identity.runId};
|
|
116
|
+
need(digest(runIdentity)===digest(snapshot.identity)&&digest(runIdentity)===digest(identity),'identity_mismatch');
|
|
117
|
+
need(digest(snapshot.fingerprints)===digest({workflow:digest('cm-fix-stages-v1'),config:digest(initial.configuration),inputs:digest(initial.identity)}),'fingerprint_mismatch');
|
|
118
|
+
const {archiveMode,...configuration}=initial.configuration;
|
|
119
|
+
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.status();}finally{owner.close();}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function openFixExecution(options,{bridge=null,prepare=null,causeReview=null,finalReview=null,assertReviewReady=null,[HISTORY_INSPECTION]:inspectionSnapshot=null}={}){
|
|
83
125
|
shape(options,['identity','configuration','create',...(Object.hasOwn(options,'hostContextId')?['hostContextId']:[]),
|
|
84
126
|
...(Object.hasOwn(options,'specsRoot')?['specsRoot']:[])]);
|
|
85
127
|
const {identity,configuration:originalConfiguration,create}=json(options,64*1024);validIdentity(identity);
|
|
@@ -88,7 +130,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
88
130
|
const configuration=json({...originalConfiguration,...(bare?{archiveMode:'bare'}:{})});
|
|
89
131
|
need(typeof create==='boolean','invalid_input');
|
|
90
132
|
const specsRoot=fixArchiveRoot(options.specsRoot,configuration.reproduction.cwd,create);
|
|
91
|
-
shape(configuration,['hostContextId','defect','reproduction',
|
|
133
|
+
shape(configuration,['hostContextId','defect','reproduction',...(Object.hasOwn(configuration,'externalModels')?['externalModels']:[]),...(Object.hasOwn(configuration,'executionPolicy')?['executionPolicy']:[]),
|
|
92
134
|
...(bare?['archiveMode']:[]),
|
|
93
135
|
...(Object.hasOwn(configuration,'protectSpecs')?['protectSpecs']:[]),
|
|
94
136
|
...(Object.hasOwn(configuration,'qaSource')?['qaSource']:[]),
|
|
@@ -99,6 +141,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
99
141
|
...(Object.hasOwn(configuration,'baseline')?['baseline']:[]),
|
|
100
142
|
...(Object.hasOwn(configuration,'testAuthor')?['testAuthor']:[]),
|
|
101
143
|
...(Object.hasOwn(configuration,'repair')?['repair']:[]),...(Object.hasOwn(configuration,'walkthrough')?['walkthrough']:[])]);
|
|
144
|
+
if(configuration.executionPolicy)readExecutionPolicy(configuration.executionPolicy);
|
|
145
|
+
if(configuration.externalModels){readExternalModels(configuration.externalModels);need(configuration.causeReview,'external_review_configuration_required');need(configuration.causeReview?.requestedModel===configuration.externalModels.providers[configuration.causeReview.provider]?.model,'external_model_pair_conflict');}
|
|
102
146
|
id(configuration.hostContextId);text(configuration.defect);
|
|
103
147
|
need(!bare||!configuration.qaSource,'fix_qa_specs_required');
|
|
104
148
|
if(isVisual(configuration.reproduction)||isVisual(configuration.redTest)){
|
|
@@ -149,8 +193,13 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
149
193
|
}
|
|
150
194
|
if(create)assertFixEvidenceNamesFree(evidenceSpecsRoot,identity,configuration);
|
|
151
195
|
if(create&&Object.hasOwn(configuration,'qaSource'))inspectFixQaSource({specsRoot,identity,configuration});
|
|
152
|
-
const
|
|
153
|
-
|
|
196
|
+
const codeProject=fs.realpathSync(configuration.reproduction.cwd);
|
|
197
|
+
const guard=!inspectionSnapshot&&((configuration.externalModels||configuration.executionPolicy)||externalRunGuardExists(evidenceSpecsRoot,codeProject))
|
|
198
|
+
?acquireExternalRunGuard({specsDir:evidenceSpecsRoot,codeProject,identity,feature:configuration.qaSource?.feature??'fix'}, {strictOnly:!(configuration.externalModels||configuration.executionPolicy)}):null;
|
|
199
|
+
let store;
|
|
200
|
+
try{store=inspectionSnapshot?{snapshot:()=>inspectionSnapshot,close(){},append(){need(false,'fix_read_only');}}:openExecutionStore({specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId},create,
|
|
201
|
+
fingerprints:{workflow:digest('cm-fix-stages-v1'),config:digest(configuration),inputs:digest(identity)}});}catch(error){guard?.close();throw error;}
|
|
202
|
+
const closeStore=()=>{try{store.close();}finally{guard?.close();}};
|
|
154
203
|
let active=null,closed=false;
|
|
155
204
|
const retryCount=base=>{
|
|
156
205
|
const records=store.snapshot().records;
|
|
@@ -187,19 +236,22 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
187
236
|
// bound human decision. Selection never falls back to an older result.
|
|
188
237
|
const recoveryPrefix=cycle=>cycle===0?'fix-final':cycle===1?'fix-final-recovery':`fix-final-recovery-${cycle}`;
|
|
189
238
|
const recoveryCount=records=>records.filter(row=>/^fix-final-recovery-(?:[1-9]\d*-)?authorized$/.test(row.id)).length;
|
|
190
|
-
const finalRecord=(records,suffix)=>records.find(row=>row.id===`${recoveryPrefix(recoveryCount(records))}-${suffix}`);
|
|
239
|
+
const finalRecord=(records,suffix)=>{const row=records.find(row=>row.id===`${recoveryPrefix(recoveryCount(records))}-${suffix}`);return suffix==='result'?reconciledFixResultRecord(records,row):row;};
|
|
191
240
|
const finalCycleRecord=(row,suffix)=>new RegExp(`^fix-final-(?:recovery-(?:[1-9]\\d*-)?)?${suffix}$`).test(row.id);
|
|
192
241
|
const publishCause=(inspectOnly=false)=>{
|
|
193
242
|
const records=store.snapshot().records;
|
|
194
243
|
return publishCauseEvidence({specsRoot:evidenceSpecsRoot,configuration:reviewConfiguration,inspectOnly,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
244
|
+
round:records.some(row=>row.id==='fix-rediagnosis-intent')?2:1,
|
|
245
|
+
registration:causeRecord(records,'registered')?.payload,
|
|
246
|
+
started:causeRecord(records,'started')?.payload.providerThreadId??null,
|
|
247
|
+
result:causeRecord(records,'result')?.payload});
|
|
198
248
|
};
|
|
249
|
+
const causeThreads=(thread,records=store.snapshot().records)=>[...new Set([thread,
|
|
250
|
+
records.find(row=>row.id==='fix-rediagnosis-intent')?.payload.priorProviderThreadId].filter(Boolean))];
|
|
199
251
|
const publishFinal=(inspectOnly=false)=>{
|
|
200
252
|
const records=store.snapshot().records;
|
|
201
253
|
return publishFixFinalEvidence({specsRoot:evidenceSpecsRoot,configuration:reviewConfiguration,inspectOnly,
|
|
202
|
-
causeThread:records
|
|
254
|
+
causeThread:causeThreads(causeRecord(records,'started')?.payload.providerThreadId),
|
|
203
255
|
registration:finalRecord(records,'registered')?.payload,
|
|
204
256
|
started:finalRecord(records,'started')?.payload.providerThreadId??null,
|
|
205
257
|
result:finalRecord(records,'result')?.payload});
|
|
@@ -208,7 +260,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
208
260
|
const records=store.snapshot().records;
|
|
209
261
|
const failed=latestStepRecord(records,'fix-walkthrough-result')?.payload;
|
|
210
262
|
const regression=latestStepRecord(records,'fix-post-regression-result')?.payload;
|
|
211
|
-
return {configuration:fixFinalReviewConfiguration(reviewConfiguration,records
|
|
263
|
+
return {configuration:fixFinalReviewConfiguration(reviewConfiguration,causeThreads(causeRecord(records,'started')?.payload.providerThreadId)),
|
|
212
264
|
registration:finalRecord(records,'registered')?.payload,
|
|
213
265
|
started:finalRecord(records,'started')?.payload.providerThreadId??null,
|
|
214
266
|
result:finalRecord(records,'result')?.payload,
|
|
@@ -222,9 +274,9 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
222
274
|
const publishRevisionFinal=(inspectOnly=false)=>{
|
|
223
275
|
const records=store.snapshot().records;
|
|
224
276
|
return publishFixFinalEvidence({specsRoot:evidenceSpecsRoot,configuration:reviewConfiguration,inspectOnly,reviewFeedback:revisionFeedback(),
|
|
225
|
-
registration:records
|
|
226
|
-
started:records
|
|
227
|
-
result:records
|
|
277
|
+
registration:reviewCycleRecord(records,'fix-revision-final','registered')?.payload,
|
|
278
|
+
started:reviewCycleRecord(records,'fix-revision-final','started')?.payload.providerThreadId??null,
|
|
279
|
+
result:reviewCycleRecord(records,'fix-revision-final','result')?.payload});
|
|
228
280
|
};
|
|
229
281
|
const reviewBaseline=()=>{
|
|
230
282
|
const records=store.snapshot().records;
|
|
@@ -327,6 +379,19 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
327
379
|
&&row.dossier_file===dossier.path&&row.dossier_sha256===dossier.sha256),'fix_escalation_exit_conflict');
|
|
328
380
|
return current;
|
|
329
381
|
}
|
|
382
|
+
function saveReviewReceipt(prefix,raw){
|
|
383
|
+
if(!(configuration.externalModels||configuration.executionPolicy)||!raw||project().stage!=='unknown')return;
|
|
384
|
+
try{
|
|
385
|
+
const records=store.snapshot().records,registration=records.find(r=>r.id===prefix+'-registered'),started=records.find(r=>r.id===prefix+'-started'),result=records.find(r=>r.id===prefix+'-result');
|
|
386
|
+
need(registration&&started&&result,'review_reconciliation_evidence_required');
|
|
387
|
+
const invocationId=registration.payload.request.invocationId;
|
|
388
|
+
const payload={prefix,invocationId,registeredDigest:digest(registration),startedDigest:digest(started),resultDigest:digest(result),receipt:readReconciliationReceipt(raw)};
|
|
389
|
+
const recordId='fix-review-receipt-'+digest(invocationId).slice(0,24);
|
|
390
|
+
need(!records.some(r=>r.id===recordId),'review_reconciliation_duplicate');
|
|
391
|
+
fixReviewLedger([...records,{id:recordId,seq:records.length+1,kind:'result',payload}],configuration);
|
|
392
|
+
append(recordId,'result',payload);
|
|
393
|
+
}catch{/* Missing, conflicting or unbound receipts never change the original unknown. */}
|
|
394
|
+
}
|
|
330
395
|
function project(){
|
|
331
396
|
const snapshot=store.snapshot();
|
|
332
397
|
need(snapshot.records.length>0,'fix_history_invalid');
|
|
@@ -359,6 +424,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
359
424
|
let repairBaseline=null,repaired=null;
|
|
360
425
|
let regression=null,retrospective=null,retrospectivePackage=null,writeback=null,learningPackage=null,handoff=null;
|
|
361
426
|
let finalRegistration=null,finalStarted=null,finalResult=null,finalRecovery=null,finalRecoveryCount=0;
|
|
427
|
+
let rediagnosis=null,rediagnosisThread=null;
|
|
428
|
+
let causeOrigin=null,causeResultPayload=null,causeAbandonment=null,revisionFinalResultPayload=null,revisionAbandonment=null;
|
|
362
429
|
const finalInvocations=new Set(),finalThreads=new Set();
|
|
363
430
|
let joinedCount=0;const seenJoined=new Set();
|
|
364
431
|
let n5=null,postReviewRegression=null,walkthrough=null,revision=null,revisionBaseline=null,revisionRepair=null,revisionRegression=null;
|
|
@@ -377,8 +444,10 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
377
444
|
}
|
|
378
445
|
need(digest(inventory([...reviewedFiles.values()]))===digest(inventory(next.files)),'fix_revision_source_mismatch');
|
|
379
446
|
}
|
|
447
|
+
const reviewLedger=fixReviewLedger(snapshot.records,configuration);
|
|
380
448
|
for(const storedRecord of records){
|
|
381
|
-
|
|
449
|
+
if(/^fix-review-(receipt|reconciled)-/.test(storedRecord.id))continue;
|
|
450
|
+
let record=reviewLedger.overlays.has(storedRecord.id)?{...storedRecord,payload:reviewLedger.overlays.get(storedRecord.id)}:storedRecord;
|
|
382
451
|
const abandonedMatch=/^fix-abandoned-([1-8])$/.exec(record.id);
|
|
383
452
|
if(abandonedMatch){
|
|
384
453
|
need(Number(abandonedMatch[1])===abandoned.length+1&&record.kind==='result'
|
|
@@ -410,6 +479,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
410
479
|
record={...record,id:baseId};
|
|
411
480
|
}
|
|
412
481
|
if(/^fix-final-recovery-(?:[1-9]\d*-)?authorized$/.test(record.id)){
|
|
482
|
+
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
413
483
|
need(record.id===`${recoveryPrefix(finalRecoveryCount+1)}-authorized`,'fix_history_invalid');
|
|
414
484
|
need(identity.attempt===1&&stage==='unknown'&&finalRegistration&&finalStarted&&!revision
|
|
415
485
|
&&(!finalResult||finalResult.observationStatus==='unknown')&&record.kind==='result','fix_review_recovery_unavailable');
|
|
@@ -428,6 +498,37 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
428
498
|
need(finalRecovery&&record.id===`${recoveryPrefix(finalRecoveryCount)}-${suffix}`,'fix_history_invalid');
|
|
429
499
|
record={...record,id:`fix-final-${suffix}`};
|
|
430
500
|
}else if(/^fix-final-(registered|started|result)$/.test(record.id))need(!finalRecovery,'fix_history_invalid');
|
|
501
|
+
if(record.id==='fix-rediagnosis-intent'){
|
|
502
|
+
need(record.kind==='intent'&&stage==='rediagnosis_required'&&pending===null&&rediagnosis===null
|
|
503
|
+
&&causeResult?.observationStatus==='completed'&&causeResult.review.verdict==='changes_requested'
|
|
504
|
+
&&authorBaseline===null&&red===null,'fix_history_invalid');
|
|
505
|
+
const value=record.payload;
|
|
506
|
+
shape(value,['reason','historyDigest','priorRegistrationDigest','priorObservationDigest','priorPackageDigest','priorProviderThreadId','reviewFeedback','learning']);
|
|
507
|
+
text(value.reason);need(Buffer.byteLength(value.reason,'utf8')<=1000&&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason),'fix_history_invalid');
|
|
508
|
+
need(value.historyDigest===digest(snapshot.records.slice(0,record.seq-1))
|
|
509
|
+
&&value.priorRegistrationDigest===digest(cause)&&value.priorObservationDigest===causeResult.observationDigest
|
|
510
|
+
&&value.priorPackageDigest===cause.request.payload.reviewPackage.packageDigest&&value.priorProviderThreadId===started
|
|
511
|
+
&&digest(value.reviewFeedback)===digest(causeResult.review),'fix_history_invalid');
|
|
512
|
+
if(value.learning!==null)inspectFixLearning(value.learning);
|
|
513
|
+
rediagnosis=value;rediagnosisThread=started;learning=value.learning;
|
|
514
|
+
cause=null;causeResult=null;causeResultPayload=null;started=null;causeAbandonment=null;
|
|
515
|
+
stage='unknown';pending='rediagnosis';continue;
|
|
516
|
+
}
|
|
517
|
+
if(record.id==='fix-rediagnosis-result'){
|
|
518
|
+
need(record.kind==='result'&&pending==='rediagnosis'&&rediagnosis!==null,'fix_history_invalid');
|
|
519
|
+
diagnosed=diagnosis(record.payload);pending=null;
|
|
520
|
+
stage=diagnosed.status==='needs_evidence'?'rediagnosis_blocked':'cause_review_required';continue;
|
|
521
|
+
}
|
|
522
|
+
const causeRevised=/^fix-cause-rediagnosis-(registered|started|result)$/.exec(record.id);
|
|
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');
|
|
525
|
+
// After a one-time abandonment only the retry cycle's records are valid.
|
|
526
|
+
const reviewRetry=/^(fix-cause|fix-revision-final)-retry-(registered|started|result)$/.exec(record.id);
|
|
527
|
+
if(reviewRetry){
|
|
528
|
+
need((reviewRetry[1]==='fix-cause'?causeAbandonment:revisionAbandonment)!==null,'fix_history_invalid');
|
|
529
|
+
record={...record,id:`${reviewRetry[1]}-${reviewRetry[2]}`};
|
|
530
|
+
}else if(/^fix-cause-(registered|started|result)$/.test(record.id))need(causeAbandonment===null,'fix_history_invalid');
|
|
531
|
+
else if(/^fix-revision-final-(registered|started|result)$/.test(record.id))need(revisionAbandonment===null,'fix_history_invalid');
|
|
431
532
|
const observed=/^fix-observation-(?:(\d+)-)?(resume-prepared|reproduce-intent|reproduce-result|diagnose-intent|diagnose-result)$/.exec(record.id);
|
|
432
533
|
if(observed){
|
|
433
534
|
const cycle=observed[2]==='resume-prepared'?observationCycle+1:observationCycle;
|
|
@@ -639,6 +740,28 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
639
740
|
need(record.payload.outcome==='created'&&record.payload.status==='ready_for_review'&&/^[a-f0-9]{64}$/.test(record.payload.handoffSha256),'invalid_handoff_result');
|
|
640
741
|
revisionHandoff=record.payload;pending=null;stage='revision_final_review_required';continue;
|
|
641
742
|
}
|
|
743
|
+
if(record.id==='fix-cause-abandoned'||record.id==='fix-revision-final-abandoned'){
|
|
744
|
+
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
745
|
+
const causeKind=record.id==='fix-cause-abandoned';
|
|
746
|
+
const registration=causeKind?cause:revisionFinalRegistration,result=causeKind?causeResult:revisionFinalResult;
|
|
747
|
+
need(record.kind==='result'&&(causeKind?causeAbandonment:revisionAbandonment)===null&®istration&&stage==='unknown'
|
|
748
|
+
&&(pending===(causeKind?'cause_review':'revision_final_review')&&!result
|
|
749
|
+
||pending===null&&result&&result.observationStatus!=='completed'),'fix_history_invalid');
|
|
750
|
+
const value=record.payload,resultPayload=causeKind?causeResultPayload:revisionFinalResultPayload;
|
|
751
|
+
shape(value,['invocationId','registrationDigest','providerThreadId','resultDigest','reason','abandonedAt']);
|
|
752
|
+
need(value.invocationId===registration.request.invocationId&&value.registrationDigest===digest(registration)
|
|
753
|
+
&&value.providerThreadId===(causeKind?started:revisionFinalStarted)
|
|
754
|
+
&&value.resultDigest===(resultPayload===null?null:digest(resultPayload)),'fix_review_abandon_mismatch');
|
|
755
|
+
need(typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason,'utf8')<=1000
|
|
756
|
+
&&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason)&&Number.isSafeInteger(value.abandonedAt)&&value.abandonedAt>0,'fix_history_invalid');
|
|
757
|
+
if(causeKind){
|
|
758
|
+
causeAbandonment=value;stage=causeOrigin;cause=null;started=null;causeResult=null;causeResultPayload=null;causeResumeStage=null;
|
|
759
|
+
}else{
|
|
760
|
+
revisionAbandonment=value;stage='revision_final_review_required';
|
|
761
|
+
revisionFinalRegistration=null;revisionFinalStarted=null;revisionFinalResult=null;revisionFinalResultPayload=null;
|
|
762
|
+
}
|
|
763
|
+
pending=null;continue;
|
|
764
|
+
}
|
|
642
765
|
if(record.id==='fix-revision-final-registered'){
|
|
643
766
|
need(revision&&stage==='revision_final_review_required'&&record.kind==='intent','fix_history_invalid');
|
|
644
767
|
revisionFinalRegistration=inspectFixFinalRegistration(record.payload,fixRevisionReviewConfiguration(revisionFeedback(),revision.nextIdentity,hostContextIds));
|
|
@@ -651,6 +774,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
651
774
|
need(revision&&pending==='revision_final_review'&&revisionFinalStarted===null&&record.kind==='result','fix_history_invalid');
|
|
652
775
|
need(record.payload.providerThreadId!==finalRecovery?.providerThreadId,'final_context_mismatch');
|
|
653
776
|
shape(record.payload,['providerThreadId']);id(record.payload.providerThreadId);
|
|
777
|
+
need(record.payload.providerThreadId!==revisionAbandonment?.providerThreadId,'final_context_mismatch');
|
|
654
778
|
const config=fixRevisionReviewConfiguration(revisionFeedback(),revision.nextIdentity,hostContextIds);
|
|
655
779
|
need(![...fixHostContexts(config),config.reviewer.contextId,...config.reviewer.excludedThreadIds].includes(record.payload.providerThreadId),'final_context_mismatch');
|
|
656
780
|
revisionFinalStarted=record.payload.providerThreadId;continue;
|
|
@@ -658,7 +782,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
658
782
|
if(record.id==='fix-revision-final-result'){
|
|
659
783
|
need(revision&&pending==='revision_final_review'&&record.kind==='result','fix_history_invalid');
|
|
660
784
|
revisionFinalResult=inspectFixFinalResult(record.payload,revisionFinalRegistration,fixRevisionReviewConfiguration(revisionFeedback(),revision.nextIdentity,hostContextIds),revisionFinalStarted);
|
|
661
|
-
pending=null;stage=revisionFinalResult.observationStatus==='completed'
|
|
785
|
+
revisionFinalResultPayload=record.payload;pending=null;stage=revisionFinalResult.observationStatus==='completed'
|
|
662
786
|
?revisionFinalResult.review.verdict==='approved'?'revision_final_review_evidence_required':revisionFinalResult.review.verdict==='changes_requested'?'revision_review_limit_reached':'revision_final_review_blocked':'unknown';continue;
|
|
663
787
|
}
|
|
664
788
|
if(record.id==='fix-revision-n5-result'){
|
|
@@ -721,7 +845,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
721
845
|
}
|
|
722
846
|
if(record.id==='fix-final-registered'){
|
|
723
847
|
need(stage==='final_review_required'&&record.kind==='intent','fix_history_invalid');
|
|
724
|
-
finalRegistration=inspectFixFinalRegistration(record.payload,fixFinalReviewConfiguration(reviewConfiguration,started));
|
|
848
|
+
finalRegistration=inspectFixFinalRegistration(record.payload,fixFinalReviewConfiguration(reviewConfiguration,causeThreads(started)));
|
|
725
849
|
need(!finalInvocations.has(finalRegistration.request.invocationId),'fix_review_recovery_mismatch');
|
|
726
850
|
finalInvocations.add(finalRegistration.request.invocationId);
|
|
727
851
|
if(finalRecovery)need(finalRegistration.request.invocationId!==finalRecovery.invocationId
|
|
@@ -734,14 +858,14 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
734
858
|
if(record.id==='fix-final-started'){
|
|
735
859
|
need(pending==='final_review'&&finalStarted===null&&record.kind==='result','fix_history_invalid');
|
|
736
860
|
shape(record.payload,['providerThreadId']);id(record.payload.providerThreadId);
|
|
737
|
-
const config=fixFinalReviewConfiguration(reviewConfiguration,started);
|
|
861
|
+
const config=fixFinalReviewConfiguration(reviewConfiguration,causeThreads(started));
|
|
738
862
|
need(!finalThreads.has(record.payload.providerThreadId),'final_context_mismatch');
|
|
739
863
|
need(![...fixHostContexts(config),config.reviewer.contextId,...config.reviewer.excludedThreadIds].includes(record.payload.providerThreadId),'final_context_mismatch');
|
|
740
864
|
finalStarted=record.payload.providerThreadId;finalThreads.add(finalStarted);continue;
|
|
741
865
|
}
|
|
742
866
|
if(record.id==='fix-final-result'){
|
|
743
867
|
need(pending==='final_review'&&record.kind==='result','fix_history_invalid');
|
|
744
|
-
finalResult=inspectFixFinalResult(record.payload,finalRegistration,fixFinalReviewConfiguration(reviewConfiguration,started),finalStarted);
|
|
868
|
+
finalResult=inspectFixFinalResult(record.payload,finalRegistration,fixFinalReviewConfiguration(reviewConfiguration,causeThreads(started)),finalStarted);
|
|
745
869
|
pending=null;stage=finalResult.observationStatus==='completed'
|
|
746
870
|
?finalResult.review.verdict==='approved'?'final_review_evidence_required':finalResult.review.verdict==='changes_requested'?'final_review_changes_requested':'final_review_blocked':'unknown';
|
|
747
871
|
continue;
|
|
@@ -907,20 +1031,22 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
907
1031
|
}else need(!Object.hasOwn(pkg,'correction'),'cause_registration_mismatch');
|
|
908
1032
|
need(digest(pkg.identity)===digest(identity)&&pkg.defect===configuration.defect
|
|
909
1033
|
&&digest(pkg.reproduction)===digest(reproduction)&&digest(pkg.diagnosis)===digest(diagnosed)
|
|
910
|
-
&&digest(pkg.learning)===digest(learning)
|
|
911
|
-
|
|
1034
|
+
&&digest(pkg.learning)===digest(learning)
|
|
1035
|
+
&&digest(pkg.rediagnosis??null)===digest(rediagnosis===null?null:rediagnosisPackage(rediagnosis)),'cause_registration_mismatch');
|
|
1036
|
+
causeOrigin=stage;stage='unknown';pending='cause_review';continue;
|
|
912
1037
|
}
|
|
913
1038
|
if(record.id==='fix-cause-started'){
|
|
914
1039
|
need(pending==='cause_review'&&started===null&&record.kind==='result','fix_history_invalid');
|
|
915
1040
|
shape(record.payload,['providerThreadId']);id(record.payload.providerThreadId);started=record.payload.providerThreadId;
|
|
916
|
-
need(![...hostContextIds,configuration.causeReview.contextId,finalStarted,...configuration.causeReview.excludedThreadIds
|
|
1041
|
+
need(![...hostContextIds,configuration.causeReview.contextId,finalStarted,rediagnosisThread,...configuration.causeReview.excludedThreadIds,
|
|
1042
|
+
causeAbandonment?.providerThreadId].includes(started),'cause_registration_mismatch');continue;
|
|
917
1043
|
}
|
|
918
1044
|
if(record.id==='fix-cause-result'){
|
|
919
1045
|
need(pending==='cause_review'&&record.kind==='result','fix_history_invalid');
|
|
920
|
-
causeResult=inspectCauseResult(record.payload,cause,reviewConfiguration,started);pending=null;
|
|
1046
|
+
causeResult=inspectCauseResult(record.payload,cause,reviewConfiguration,started);causeResultPayload=record.payload;pending=null;
|
|
921
1047
|
stage=causeResult.observationStatus!=='completed'?'unknown':causeResult.review.verdict==='approved'
|
|
922
1048
|
?(causeResumeStage??(diagnosed.status==='design_change'?'design_change_required':'red_test_required'))
|
|
923
|
-
:causeResult.review.verdict==='changes_requested'?'rediagnosis_required':'cause_review_blocked';continue;
|
|
1049
|
+
:causeResult.review.verdict==='changes_requested'?(rediagnosis?'rediagnosis_review_limit_reached':'rediagnosis_required'):'cause_review_blocked';continue;
|
|
924
1050
|
}
|
|
925
1051
|
if(record.id.startsWith('fix-learning-')){
|
|
926
1052
|
need(record.kind==='result'&&pending===null&&['reproduce','diagnose','observation_resume_prepared','observation_diagnose_required'].includes(stage),'fix_history_invalid');
|
|
@@ -968,6 +1094,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
968
1094
|
try{
|
|
969
1095
|
const current=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
970
1096
|
status:{identity,stage:'cause_review_required',reproduction,diagnosis:diagnosed,learning,
|
|
1097
|
+
...(rediagnosis?{rediagnosis}:{}),
|
|
971
1098
|
...(cause.request.payload.reviewPackage.correction?{causeReviewCorrection:cause.request.payload.reviewPackage.correction}:{})}});
|
|
972
1099
|
verifyFixCauseTransition(cause.request.payload.reviewPackage,current,authorBaseline,authored);
|
|
973
1100
|
}catch{stage='cause_review_drift';}
|
|
@@ -1086,8 +1213,21 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1086
1213
|
catch{stage='visual_evidence_required';}
|
|
1087
1214
|
}
|
|
1088
1215
|
if(stage==='design_change_required'&&!runRed)stage='escalation_required';
|
|
1216
|
+
// Registered review with no review result: nothing arrived, or only a timeout,
|
|
1217
|
+
// disconnect or cancellation observation. Each kind may be abandoned once.
|
|
1218
|
+
const noReviewResult=(registration,result,kind)=>stage==='unknown'&®istration!==null
|
|
1219
|
+
&&(pending===kind&&!result||pending===null&&result!==null&&result.observationStatus!=='completed');
|
|
1220
|
+
const causeNoResult=rediagnosis===null&&noReviewResult(cause,causeResult,'cause_review');
|
|
1221
|
+
const revisionNoResult=noReviewResult(revisionFinalRegistration,revisionFinalResult,'revision_final_review');
|
|
1222
|
+
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
|
+
const reviewAbandonable=!(configuration.externalModels||configuration.executionPolicy)&&causeNoResult&&!causeAbandonment?'cause_review':!(configuration.externalModels||configuration.executionPolicy)&&revisionNoResult&&!revisionAbandonment?'revision_final_review':null;
|
|
1089
1224
|
const status=json({identity,stage,pending,abandoned,executionActive:active!==null,reproduction,diagnosis:diagnosed,learning,causeReview:causeResult,
|
|
1090
|
-
...(
|
|
1225
|
+
...(reviewAbandonable?{reviewAbandonable}:{}),
|
|
1226
|
+
...((configuration.externalModels||configuration.executionPolicy)&&stage==='unknown'?{reviewReconciliation:{available:reviewLedger.pending.length===1,invocationId:reviewLedger.pending[0]?.invocationId??null}}:{}),
|
|
1227
|
+
...(causeNoResult&&causeAbandonment||revisionNoResult&&revisionAbandonment?{reviewAbandonBudgetExhausted:true}:{}),
|
|
1228
|
+
...(causeAbandonment?{causeReviewAbandonment:causeAbandonment}:{}),
|
|
1229
|
+
...(revisionAbandonment?{revisionFinalReviewAbandonment:revisionAbandonment}:{}),
|
|
1230
|
+
...(causeReviewCorrection?{causeReviewCorrection}:{}),...(rediagnosis?{rediagnosis}:{}),
|
|
1091
1231
|
...(observationResume?{observationResume,observationCycle}:{}),
|
|
1092
1232
|
...(observationReproduction?{observationReproduction}:{}),
|
|
1093
1233
|
...(observationDiagnosis?{observationDiagnosis}:{}),
|
|
@@ -1123,15 +1263,26 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1123
1263
|
try{
|
|
1124
1264
|
// The existing shared writer lock is already held here: a live parent
|
|
1125
1265
|
// cannot overlap this child. Recheck current evidence before registration.
|
|
1126
|
-
if(Object.hasOwn(configuration,'qaSource')){
|
|
1266
|
+
if(!inspectionSnapshot&&Object.hasOwn(configuration,'qaSource')){
|
|
1127
1267
|
const completed=store.snapshot().records.length>0&&project().completionEligible===true;
|
|
1128
1268
|
(completed?readFixQaSourceHistory:inspectFixQaSource)({specsRoot,identity,configuration});
|
|
1129
1269
|
}
|
|
1130
1270
|
if(store.snapshot().records.length===0)append('fix-configuration','intent',initial);
|
|
1131
1271
|
project();
|
|
1132
|
-
}catch(error){
|
|
1272
|
+
}catch(error){closeStore();throw error;}
|
|
1133
1273
|
return Object.freeze({
|
|
1134
1274
|
status:project,
|
|
1275
|
+
reconcileReview({invocationId}={}){
|
|
1276
|
+
need(!closed&&active===null&&(configuration.externalModels||configuration.executionPolicy),'review_reconciliation_unavailable');id(invocationId);
|
|
1277
|
+
const ledger=fixReviewLedger(store.snapshot().records,configuration);
|
|
1278
|
+
if(ledger.applied.has(invocationId))return project();
|
|
1279
|
+
need(project().stage==='unknown','review_reconciliation_unavailable');
|
|
1280
|
+
const proof=ledger.pending.find(p=>p.invocationId===invocationId);
|
|
1281
|
+
need(proof,ledger.pending.length?'review_reconciliation_binding':'review_reconciliation_evidence_required');
|
|
1282
|
+
const {prefix,registeredDigest,startedDigest,resultDigest,receiptDigest}=proof;
|
|
1283
|
+
append('fix-review-reconciled-'+digest(invocationId).slice(0,24),'result',{prefix,invocationId,registeredDigest,startedDigest,resultDigest,receiptDigest});
|
|
1284
|
+
return project();
|
|
1285
|
+
},
|
|
1135
1286
|
abandonStep({reason,authorized=false}={}){
|
|
1136
1287
|
need(!closed&&active===null,'fix_busy');
|
|
1137
1288
|
const current=project();
|
|
@@ -1148,7 +1299,29 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1148
1299
|
detail:`显式放弃 unknown 步骤:${current.pending}`,data:{pending:current.pending,reason}});
|
|
1149
1300
|
return project();
|
|
1150
1301
|
},
|
|
1302
|
+
// One audited abandonment per review kind, mirroring cm-ai abandon_review. The
|
|
1303
|
+
// host confirms the old reviewer process stopped; the record binds the exact
|
|
1304
|
+
// registration, thread and any no-result observation. The retry needs the
|
|
1305
|
+
// original review permission and a fresh reviewer thread.
|
|
1306
|
+
abandonReview({reason,authorized=false}={}){
|
|
1307
|
+
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
1308
|
+
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_review_abandon_authorization_required');
|
|
1309
|
+
need(typeof reason==='string'&&reason.trim().length>0&&Buffer.byteLength(reason,'utf8')<=1000
|
|
1310
|
+
&&!/[\r\n\0\u0085\u2028\u2029]/.test(reason),'fix_review_abandon_reason_required');
|
|
1311
|
+
const current=project();
|
|
1312
|
+
need(current.reviewAbandonBudgetExhausted!==true,'fix_review_abandon_budget_exhausted');
|
|
1313
|
+
need(current.reviewAbandonable,'fix_review_abandon_unavailable');
|
|
1314
|
+
const records=store.snapshot().records,prefix=REVIEW_ABANDON[current.reviewAbandonable];
|
|
1315
|
+
const registration=records.find(row=>row.id===`${prefix}-registered`),result=records.find(row=>row.id===`${prefix}-result`)??null;
|
|
1316
|
+
append(`${prefix}-abandoned`,'result',{invocationId:registration.payload.request.invocationId,registrationDigest:digest(registration.payload),
|
|
1317
|
+
providerThreadId:records.find(row=>row.id===`${prefix}-started`)?.payload.providerThreadId??null,
|
|
1318
|
+
resultDigest:result===null?null:digest(result.payload),reason,abandonedAt:Date.now()});
|
|
1319
|
+
logFixEvent({specsRoot:evidenceSpecsRoot,identity,configuration,event:'abandon',phase:current.reviewAbandonable,
|
|
1320
|
+
detail:`显式放弃无结果的审查:${current.reviewAbandonable}`,data:{pending:current.reviewAbandonable,reason}});
|
|
1321
|
+
return project();
|
|
1322
|
+
},
|
|
1151
1323
|
recoverFinalReview({authorized=false,recoveryInvocationId=null,invocationId,packageDigest,previousInvocationStopped,reason}={}){
|
|
1324
|
+
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
1152
1325
|
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_review_recovery_authorization_required');
|
|
1153
1326
|
const current=project(),records=store.snapshot().records;
|
|
1154
1327
|
need(identity.attempt===1&¤t.stage==='unknown'&&!current.revision
|
|
@@ -1176,7 +1349,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1176
1349
|
if(configuration.qaSource)readFixQaSourceHistory({specsRoot,identity,configuration});
|
|
1177
1350
|
const revised=Boolean(current.revisionN5),selected=revised?revisionCloseoutStatus(current):current;
|
|
1178
1351
|
const records=store.snapshot().records;
|
|
1179
|
-
const registration=(revised?records
|
|
1352
|
+
const registration=(revised?reviewCycleRecord(records,'fix-revision-final','registered'):finalRecord(records,'registered')).payload;
|
|
1180
1353
|
const reviewPackage=registration.request.payload.reviewPackage;
|
|
1181
1354
|
need(selected.n5.packageDigest===reviewPackage.packageDigest,'fix_completion_evidence_unavailable');
|
|
1182
1355
|
// Only a projection of the original owner and gate, never a new completion
|
|
@@ -1254,7 +1427,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1254
1427
|
const ended=escalationEvents(status,dossier);need(ended.length===1,'fix_escalation_exit_conflict');
|
|
1255
1428
|
if(!status.escalation)append('fix-escalation-result','result',{dossier,eventId:ended[0].event_id});
|
|
1256
1429
|
const result={...project(),dossier:archived.dossier,escalationRunEnded:true};
|
|
1257
|
-
closed=true;
|
|
1430
|
+
closed=true;closeStore();return result;
|
|
1258
1431
|
}
|
|
1259
1432
|
if(['observation','observation_not_reproduced','observation_needs_evidence'].includes(status.stage)){
|
|
1260
1433
|
const archived=this.publishDossier();
|
|
@@ -1268,11 +1441,11 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1268
1441
|
detail:`观测中:等${status.observationDiagnosis?.plan??status.diagnosis?.plan??JSON.stringify(configuration.reproduction.expectedFailure)}`,
|
|
1269
1442
|
data});
|
|
1270
1443
|
const result={...archived,observationRunEnded:true};
|
|
1271
|
-
closed=true;
|
|
1444
|
+
closed=true;closeStore();return result;
|
|
1272
1445
|
}
|
|
1273
1446
|
if(status.revisionN5){
|
|
1274
1447
|
need(['revision_closeout_required','revision_closeout_incomplete','completed'].includes(status.stage),'fix_closeout_unavailable');
|
|
1275
|
-
const registration=store.snapshot().records
|
|
1448
|
+
const registration=reviewCycleRecord(store.snapshot().records,'fix-revision-final','registered');
|
|
1276
1449
|
finishFix({specsRoot:evidenceSpecsRoot,identity:status.revision.nextIdentity,configuration,status:revisionCloseoutStatus(status),registeredAt:registration.payload.registeredAt},{assertOwned(){
|
|
1277
1450
|
const current=project();need(['revision_closeout_required','revision_closeout_incomplete','completed'].includes(current.stage),'fix_evidence_changed');
|
|
1278
1451
|
need(digest(current.revisionN5)===digest(status.revisionN5)&&digest(current.revisionWalkthrough)===digest(status.revisionWalkthrough),'fix_evidence_changed');
|
|
@@ -1341,7 +1514,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1341
1514
|
need(!closed&&active===null,'fix_busy');const current=project();
|
|
1342
1515
|
if(current.stage==='revision_completion_gate_required'){
|
|
1343
1516
|
need(!current.revisionN5,'n5_evidence_changed');
|
|
1344
|
-
const gate=checkN5(revisionN5Options()),registration=store.snapshot().records
|
|
1517
|
+
const gate=checkN5(revisionN5Options()),registration=reviewCycleRecord(store.snapshot().records,'fix-revision-final','registered').payload;
|
|
1345
1518
|
append('fix-revision-n5-result','result',{gate,packageDigest:registration.request.payload.reviewPackage.packageDigest});return project();
|
|
1346
1519
|
}
|
|
1347
1520
|
if(current.stage!=='completion_gate_required')return current;
|
|
@@ -1354,7 +1527,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1354
1527
|
need(!closed&&active===null,'fix_busy');const current=project();
|
|
1355
1528
|
if(['revision_final_review_evidence_required','revision_review_limit_reached','revision_final_review_blocked','revision_completion_gate_required','revision_post_review_regression_required','revision_post_review_regression_blocked','revision_closeout_required','revision_walkthrough_blocked'].includes(current.stage)){
|
|
1356
1529
|
need(current.revisionFinalReview?.observationStatus==='completed','final_review_evidence_unavailable');publishRevisionFinal();
|
|
1357
|
-
const registration=store.snapshot().records
|
|
1530
|
+
const registration=reviewCycleRecord(store.snapshot().records,'fix-revision-final','registered').payload,result=current.revisionFinalReview;
|
|
1358
1531
|
logFixEvent({specsRoot:evidenceSpecsRoot,identity:current.revision.nextIdentity,configuration,event:'review',phase:'complete',
|
|
1359
1532
|
detail:'Independent fix second implementation review evidence published',data:{feature:`fix-${identity.taskId.slice(6)}`,review_kind:'implementation',round:2,
|
|
1360
1533
|
result:result.review.verdict,provider:result.provider,package_digest:registration.request.payload.reviewPackage.packageDigest,
|
|
@@ -1377,7 +1550,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1377
1550
|
},
|
|
1378
1551
|
async reviewFinal(){
|
|
1379
1552
|
need(!closed&&active===null,'fix_busy');const start=project();if(!['final_review_required','revision_final_review_required'].includes(start.stage))return start;
|
|
1380
|
-
const revising=start.stage==='revision_final_review_required'
|
|
1553
|
+
const revising=start.stage==='revision_final_review_required';
|
|
1554
|
+
const prefix=revising?(start.revisionFinalReviewAbandonment?'fix-revision-final-retry':'fix-revision-final'):recoveryPrefix(start.finalReviewRecoveryCount);
|
|
1381
1555
|
need(finalReview&&typeof assertReviewReady==='function','final_review_unavailable');
|
|
1382
1556
|
const ready=assertReviewReady();if(types.isPromise(ready))Promise.prototype.then.call(ready,()=>{},()=>{});
|
|
1383
1557
|
need(ready===undefined,'final_sync_registration_required');
|
|
@@ -1385,11 +1559,11 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1385
1559
|
const checks=reviewChecks(revising?start.revisionRegression:start.regression),selectedHandoff=revising?revisionHandoffPath():handoffPath();
|
|
1386
1560
|
const pkg=createReviewPackage({root:configuration.reproduction.cwd,baseline,checks,handoffPath:selectedHandoff});
|
|
1387
1561
|
if(start.finalReviewRecovery&&!revising)need(pkg.packageDigest===start.finalReviewRecovery.packageDigest,'fix_review_recovery_drift');
|
|
1388
|
-
const run=createFixFinalReview({reviewPackage:pkg,configuration:revising?fixRevisionReviewConfiguration(revisionFeedback(),start.revision.nextIdentity,hostContextIds):fixFinalReviewConfiguration(reviewConfiguration,start.causeReview?.providerThreadId
|
|
1389
|
-
timeoutMs:configuration.reproduction.timeoutMs},finalReview);
|
|
1390
|
-
const controller=new AbortController();active=controller;let registered=false;
|
|
1562
|
+
const run=createFixFinalReview({reviewPackage:pkg,configuration:revising?fixRevisionReviewConfiguration(revisionFeedback(),start.revision.nextIdentity,hostContextIds):fixFinalReviewConfiguration(reviewConfiguration,causeThreads(start.causeReview?.providerThreadId)),
|
|
1563
|
+
timeoutMs:reviewTimeout(finalReview,configuration.reproduction.timeoutMs)},finalReview);
|
|
1564
|
+
const controller=new AbortController();active=controller;let registered=false,capturedReceipt=null,receiptConflict=false;
|
|
1391
1565
|
try{
|
|
1392
|
-
const result=await run({signal:controller.signal,register(value){
|
|
1566
|
+
const result=await run({signal:controller.signal,...((configuration.externalModels||configuration.executionPolicy)?{onReconciliation(raw){try{const receipt=readReconciliationReceipt(raw);if(capturedReceipt&&digest(receipt)!==digest(capturedReceipt))receiptConflict=true;else capturedReceipt=receipt;}catch{receiptConflict=true;}}}:{}),register(value){
|
|
1393
1567
|
need(project().stage===start.stage,'fix_evidence_changed');
|
|
1394
1568
|
if(!revising)need(!store.snapshot().records.some(row=>finalCycleRecord(row,'registered')
|
|
1395
1569
|
&&row.payload.request.invocationId===value.request.invocationId),'fix_review_recovery_mismatch');
|
|
@@ -1397,13 +1571,15 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1397
1571
|
need(current.packageDigest===pkg.packageDigest,'final_package_mismatch');
|
|
1398
1572
|
joinLiveHost();append(`${prefix}-registered`,'intent',value);registered=true;
|
|
1399
1573
|
},onStarted(providerThreadId){
|
|
1400
|
-
need(providerThreadId!==start.finalReviewRecovery?.providerThreadId
|
|
1574
|
+
need(providerThreadId!==start.finalReviewRecovery?.providerThreadId
|
|
1575
|
+
&&providerThreadId!==(revising?start.revisionFinalReviewAbandonment?.providerThreadId:undefined),'final_context_mismatch');
|
|
1401
1576
|
if(!revising)need(!store.snapshot().records.some(row=>finalCycleRecord(row,'started')
|
|
1402
1577
|
&&row.payload.providerThreadId===providerThreadId),'final_context_mismatch');
|
|
1403
1578
|
append(`${prefix}-started`,'result',{providerThreadId});
|
|
1404
1579
|
}});
|
|
1405
1580
|
if(result.outcome==='denied')return {...project(),reason:'permission_denied'};
|
|
1406
|
-
if(result.outcome==='observed'&&!controller.signal.aborted)append(`${prefix}-result`,'result',result.value);
|
|
1581
|
+
if((result.outcome==='observed'||(configuration.externalModels||configuration.executionPolicy)&&result.value)&&!controller.signal.aborted)append(`${prefix}-result`,'result',result.value);
|
|
1582
|
+
if(!receiptConflict)saveReviewReceipt(prefix,capturedReceipt);
|
|
1407
1583
|
if(result.outcome==='unknown')return {...project(),reason:result.reason,diagnostic:result.diagnostic};
|
|
1408
1584
|
return project();
|
|
1409
1585
|
}catch(error){
|
|
@@ -1687,17 +1863,20 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1687
1863
|
&&!(status.stage==='observation_cause_review_correction_required'&&status.causeReviewCorrection))return status;
|
|
1688
1864
|
need(configuration.causeReview&&causeReview&&typeof causeReview.authorize==='function'&&typeof causeReview.run==='function','cause_review_unavailable');
|
|
1689
1865
|
const reviewer=configuration.causeReview;
|
|
1866
|
+
const budget=reviewTimeout(causeReview,configuration.reproduction.timeoutMs);
|
|
1867
|
+
const prefix=status.rediagnosis?'fix-cause-rediagnosis':status.causeReviewAbandonment?'fix-cause-retry':'fix-cause';
|
|
1868
|
+
const abandonedThread=status.causeReviewAbandonment?.providerThreadId??null;
|
|
1690
1869
|
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,status});
|
|
1691
1870
|
const request=requestFor({invocationId:`fix-cause.${randomUUID()}`,identity,role:'reviewer',provider:reviewer.provider,
|
|
1692
1871
|
requestedModel:reviewer.requestedModel,contextId:reviewer.contextId,payload:{reviewPackage:pkg,priorReview:null}});
|
|
1693
|
-
const controller=new AbortController();active=controller;let timer,registered=false;
|
|
1872
|
+
const controller=new AbortController();active=controller;let timer,registered=false,capturedReceipt=null,receiptConflict=false;
|
|
1694
1873
|
try{
|
|
1695
1874
|
const authorizationAt=Date.now(),grant=causeReview.authorize(request,{authorizationAt});
|
|
1696
1875
|
if(types.isPromise(grant)){grant.catch(()=>{});need(false,'cause_authorization_invalid');}
|
|
1697
1876
|
need(!controller.signal.aborted,'cancelled');
|
|
1698
1877
|
if(digest(grant)===digest({status:'denied',code:'permission_denied'}))return {...project(),reason:'permission_denied'};
|
|
1699
1878
|
const registration=inspectCauseRegistration({request,authorizationAt,registeredAt:Date.now(),grant},reviewConfiguration);
|
|
1700
|
-
joinLiveHost();append(
|
|
1879
|
+
joinLiveHost();append(`${prefix}-registered`,'intent',registration);
|
|
1701
1880
|
registered=true;
|
|
1702
1881
|
const dispatchAt=Date.now();need(dispatchAt>=registration.registeredAt&&dispatchAt<grant.expiresAt,'grant_expired');
|
|
1703
1882
|
const events=[];let invalid=false,sealed=false,timedOut=false,started=null;
|
|
@@ -1709,7 +1888,9 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1709
1888
|
inspectProviderCauseReview(JSON.stringify({...observation({status:'failed',code:'in_progress'}),events:[...events,event]}),
|
|
1710
1889
|
JSON.stringify(causeExpectation(request,reviewConfiguration)));
|
|
1711
1890
|
if(event.event==='thread.started'){
|
|
1712
|
-
|
|
1891
|
+
// A retry is a fresh reviewer thread, never the abandoned one.
|
|
1892
|
+
need(event.provider_thread!==abandonedThread&&event.provider_thread!==status.rediagnosis?.priorProviderThreadId,'observation_context');
|
|
1893
|
+
append(`${prefix}-started`,'result',{providerThreadId:event.provider_thread});started=event.provider_thread;
|
|
1713
1894
|
}
|
|
1714
1895
|
events.push(event);return true;
|
|
1715
1896
|
}catch{invalid=true;controller.abort();return false;}
|
|
@@ -1717,18 +1898,23 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1717
1898
|
let rejectAbort;
|
|
1718
1899
|
const interrupted=new Promise((resolve,reject)=>{rejectAbort=()=>reject(Object.assign(new Error('cause_review_interrupted'),{code:'cause_review_interrupted'}));});
|
|
1719
1900
|
controller.signal.addEventListener('abort',rejectAbort,{once:true});
|
|
1720
|
-
timer=setTimeout(()=>{timedOut=true;controller.abort();},
|
|
1721
|
-
let result;
|
|
1901
|
+
timer=setTimeout(()=>{timedOut=true;controller.abort();},budget);
|
|
1902
|
+
let result,transport;
|
|
1722
1903
|
try{
|
|
1723
|
-
|
|
1904
|
+
transport=Promise.resolve().then(()=>{
|
|
1724
1905
|
need(!controller.signal.aborted,'cause_review_interrupted');
|
|
1725
|
-
return causeReview.run(request,{signal:controller.signal,onEvent});
|
|
1726
|
-
})
|
|
1727
|
-
|
|
1728
|
-
if(invalid||
|
|
1906
|
+
return causeReview.run(request,{signal:controller.signal,onEvent,...((configuration.externalModels||configuration.executionPolicy)?{onReconciliation(raw){try{const receipt=readReconciliationReceipt(raw);if(capturedReceipt&&digest(receipt)!==digest(capturedReceipt))receiptConflict=true;else capturedReceipt=receipt;}catch{receiptConflict=true;}}}:{})});
|
|
1907
|
+
});
|
|
1908
|
+
result=await Promise.race([interrupted,transport]);
|
|
1909
|
+
}catch(error){if(!timedOut||invalid)throw error;if((configuration.externalModels||configuration.executionPolicy)){let drain;await Promise.race([transport.catch(()=>{}),new Promise(resolve=>{drain=setTimeout(resolve,2500);})]);clearTimeout(drain);}}
|
|
1910
|
+
finally{sealed=true;controller.signal.removeEventListener('abort',rejectAbort);}
|
|
1911
|
+
// The review budget expiring is a recorded no-result observation, not an
|
|
1912
|
+
// unrecorded interruption; a cancellation or invalid stream stays unknown.
|
|
1913
|
+
if(invalid||controller.signal.aborted&&!timedOut||project().stage==='cancelled')return project();
|
|
1729
1914
|
const value={dispatchAt,observation:observation(timedOut?{status:'failed',code:'timeout'}:result)};
|
|
1730
1915
|
inspectCauseResult(value,registration,reviewConfiguration,started);
|
|
1731
|
-
append(
|
|
1916
|
+
append(`${prefix}-result`,'result',value);
|
|
1917
|
+
if(!receiptConflict)saveReviewReceipt(prefix,capturedReceipt);
|
|
1732
1918
|
if(project().causeReview?.observationStatus==='completed')publishCause();
|
|
1733
1919
|
return project();
|
|
1734
1920
|
}catch(error){
|
|
@@ -1737,6 +1923,47 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1737
1923
|
}
|
|
1738
1924
|
finally{clearTimeout(timer);active=null;}
|
|
1739
1925
|
},
|
|
1926
|
+
async rediagnose({authorized=false,reason}={}){
|
|
1927
|
+
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_rediagnosis_authorization_required');
|
|
1928
|
+
const start=project();need(start.stage==='rediagnosis_required'&&!start.rediagnosis,'fix_rediagnosis_unavailable');
|
|
1929
|
+
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');publishCause(true);
|
|
1931
|
+
const prior=causeRecord(store.snapshot().records,'registered').payload;
|
|
1932
|
+
const assertBasis=()=>{
|
|
1933
|
+
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
1934
|
+
status:{...start,stage:'cause_review_required'}});
|
|
1935
|
+
need(pkg.packageDigest===prior.request.payload.reviewPackage.packageDigest,'fix_rediagnosis_source_changed');
|
|
1936
|
+
const slug=identity.taskId.slice(6);
|
|
1937
|
+
const slot=path.join(evidenceSpecsRoot,'.reviews',`fix-${slug}-cause-r2.md`);
|
|
1938
|
+
let occupied=false;
|
|
1939
|
+
try{fs.lstatSync(slot);occupied=true;}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
1940
|
+
need(!occupied,'fix_rediagnosis_evidence_conflict');
|
|
1941
|
+
return pkg;
|
|
1942
|
+
};
|
|
1943
|
+
const pkg=assertBasis();
|
|
1944
|
+
const controller=new AbortController();active=controller;let registered=false,timer;
|
|
1945
|
+
try{
|
|
1946
|
+
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
1947
|
+
const learning=prepare===null?start.learning:inspectFixLearning(await prepare({identity,defect:configuration.defect},controller.signal));
|
|
1948
|
+
need(!controller.signal.aborted,'fix_learning_interrupted');
|
|
1949
|
+
need(project().stage===start.stage,'fix_evidence_changed');
|
|
1950
|
+
// Preparation awaits current-session work; recheck its original evidence before the single continuation is registered.
|
|
1951
|
+
assertBasis();
|
|
1952
|
+
const history=store.snapshot().records;
|
|
1953
|
+
append('fix-rediagnosis-intent','intent',{reason,historyDigest:digest(history),priorRegistrationDigest:digest(prior),
|
|
1954
|
+
priorObservationDigest:start.causeReview.observationDigest,priorPackageDigest:pkg.packageDigest,
|
|
1955
|
+
priorProviderThreadId:start.causeReview.providerThreadId,
|
|
1956
|
+
reviewFeedback:start.causeReview.review,learning});registered=true;
|
|
1957
|
+
const value=diagnosis(await bridge.call('fix_diagnose',{identity,defect:configuration.defect,
|
|
1958
|
+
codeProject:configuration.reproduction.cwd,reproduction:start.reproduction,previousDiagnosis:start.diagnosis,
|
|
1959
|
+
reviewFeedback:start.causeReview.review,diagnosticRecord:fixInvestigationRequest,
|
|
1960
|
+
...fixQaDiagnosisEvidence({specsRoot,identity,configuration})},controller.signal));
|
|
1961
|
+
if(controller.signal.aborted)return project();
|
|
1962
|
+
if(configuration.qaSource)inspectFixQaSource({specsRoot,identity,configuration});
|
|
1963
|
+
append('fix-rediagnosis-result','result',value);return project();
|
|
1964
|
+
}catch(error){if(!registered)throw error;return project();}
|
|
1965
|
+
finally{clearTimeout(timer);active=null;}
|
|
1966
|
+
},
|
|
1740
1967
|
async advance({authorized=false}={}){
|
|
1741
1968
|
need(!closed,'store_closed');need(active===null,'fix_busy');
|
|
1742
1969
|
const start=project();
|
|
@@ -1838,6 +2065,6 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1838
2065
|
const current=project();if(current.stage==='cancelled'||current.stage==='escalated')return current;
|
|
1839
2066
|
append('fix-cancel','cancel',{reason:'user_cancelled'});active?.abort();return project();
|
|
1840
2067
|
},
|
|
1841
|
-
close(){need(active===null,'fix_busy');closed=true;
|
|
2068
|
+
close(){need(active===null,'fix_busy');closed=true;closeStore();},
|
|
1842
2069
|
});
|
|
1843
2070
|
}
|