@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
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -8,11 +8,19 @@ import {digest as sha} from '../runtime/js/cm-ai/contracts.mjs';
|
|
|
8
8
|
import {resolveCodeProjects,codeProjectPaths,assertCodeProjectSelections} from '../runtime/js/cm-ai/code-projects.mjs';
|
|
9
9
|
import {preQaConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attachment.mjs';
|
|
10
10
|
import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
|
+
import {writeCmAiQaStatus} from '../runtime/js/cm-ai/cm-ai-run-finalizer.mjs';
|
|
11
12
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
12
13
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
13
|
-
import {previousQaMaterial,qaConfigurationSlice,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
14
|
-
import {inspectCmAiQaRevisionTarget,recordCmAiQaConfigurationRevision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
15
|
-
import {prepareReviewedEvidenceSupersession,archiveReviewedEvidence,recordEvidenceSupersession} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
14
|
+
import {hasLegacyQaPlanFingerprint,previousQaMaterial,qaConfigurationSlice,qaExecutorMaterial,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
15
|
+
import {hasCmAiQaRun,inspectCmAiQaRevisionTarget,recordCmAiQaConfigurationRevision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
16
|
+
import {prepareReviewedEvidenceSupersession,archiveReviewedEvidence,recordEvidenceSupersession,assertNoUnrecordedPriorCode} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
17
|
+
import {explainFingerprintMismatch} from '../runtime/js/cm-ai/launch-mismatch.mjs';
|
|
18
|
+
import {recordReviewAbandonment} from '../runtime/js/cm-ai/review-abandon-log.mjs';
|
|
19
|
+
import {recordEffectAbandonment} from '../runtime/js/cm-ai/effect-abandon-log.mjs';
|
|
20
|
+
import {reviewConsumedHandoff,reviewedHandoffConflict} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
21
|
+
import {RUN_ID_RULE,validRunId} from './cm-log-event.mjs';
|
|
22
|
+
import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
+
import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
16
24
|
|
|
17
25
|
const usage='cm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
18
26
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
@@ -128,16 +136,20 @@ export async function createCodexExecution(configuration,authority){
|
|
|
128
136
|
return execution;
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
// Also bounds every changed-file list a task handoff can carry (see the handoff
|
|
140
|
+
// size test): raising it means revisiting the 256 KiB handoff limit.
|
|
141
|
+
export const RUN_DEFINITION_LIMIT=64*1024;
|
|
131
142
|
export function readRunDefinition(file){
|
|
132
143
|
const info=fs.lstatSync(file);
|
|
133
144
|
if(!info.isFile()||info.isSymbolicLink())fail('invalid_config: not a regular file');
|
|
134
|
-
if(info.size>
|
|
145
|
+
if(info.size>RUN_DEFINITION_LIMIT)fail('invalid_config: file exceeds 64KiB');
|
|
135
146
|
return validateRunDefinition(JSON.parse(fs.readFileSync(file,'utf8')));
|
|
136
147
|
}
|
|
137
148
|
export function validateRunDefinition(input){
|
|
138
149
|
const value=structuredClone(input);
|
|
139
150
|
const keys=['version','specsDir','codeProject','feature','identity','scope','requirements'];
|
|
140
151
|
if(value&&Object.hasOwn(value,'codeProjects'))keys.push('codeProjects');
|
|
152
|
+
if(value&&Object.hasOwn(value,'taskSelection'))keys.push('taskSelection');
|
|
141
153
|
if(!value||typeof value!=='object')fail('invalid_config: expected an object');
|
|
142
154
|
const unexpected=Object.keys(value).filter(key=>!keys.includes(key));
|
|
143
155
|
const missing=keys.filter(key=>!Object.hasOwn(value,key));
|
|
@@ -157,6 +169,9 @@ export function validateRunDefinition(input){
|
|
|
157
169
|
for(const key of ['repositoryId','runId','taskId']){
|
|
158
170
|
if(typeof value.identity[key]!=='string'||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(value.identity[key]))fail('invalid_identity');
|
|
159
171
|
}
|
|
172
|
+
if(Object.hasOwn(value,'taskSelection')&&(!value.taskSelection||value.taskSelection.version!==1
|
|
173
|
+
||Object.keys(value.taskSelection).sort().join(',')!=='taskId,version'
|
|
174
|
+
||value.taskSelection.taskId!==value.identity.taskId))fail('invalid_task_selection');
|
|
160
175
|
for(const key of ['scope','requirements']){
|
|
161
176
|
if(!Array.isArray(value[key])||(!value[key].length&&!(key==='requirements'))||value[key].length>256
|
|
162
177
|
||value[key].some(p=>typeof p!=='string'||!p||p.includes('\\')||p.includes('\0')
|
|
@@ -170,13 +185,64 @@ export function validateRunDefinition(input){
|
|
|
170
185
|
}
|
|
171
186
|
return value;
|
|
172
187
|
}
|
|
188
|
+
// Create-time only: an existing journal keeps resuming (and can be abandoned)
|
|
189
|
+
// exactly as before, while a new run can no longer strand its first develop
|
|
190
|
+
// effect on a run ID the run log refuses.
|
|
191
|
+
export function assertCreatableRunId(identity){
|
|
192
|
+
if(!validRunId(identity?.runId))fail(`invalid_config: identity.runId must be ${RUN_ID_RULE} (run log requirement)`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Definition is data, never an import path, command, grant or executable callback.
|
|
196
|
+
// legacyQa rebuilds the historical QA executor form for stores created before
|
|
197
|
+
// the built-in plan left the fingerprint; it is never used to create a store.
|
|
198
|
+
export function runConfigMaterial(definition,execution,{parallelSelection=null,bootstrapConfig=null,legacyQa=false,knowledgeCloseout=null}={}){
|
|
199
|
+
if(execution===null)return parallelSelection===null?definition:{definition,parallelSelection};
|
|
200
|
+
return {definition,...(parallelSelection===null?{}:{parallelSelection}),execution:execution.configuration,
|
|
201
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
202
|
+
...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
|
|
203
|
+
...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
|
|
204
|
+
...(execution.hostDecisionProvider?{hostDecisionProvider:{version:1,timeoutMs:execution.hostDecisionProvider.timeoutMs}}:{}),
|
|
205
|
+
...(execution.qaDecisionProvider?{qaDecisionProvider:'host-v1',qaTimeoutMs:execution.qaDecisionProvider.timeoutMs}:{}),
|
|
206
|
+
...(execution.qaExecutor?{qaExecutor:qaExecutorMaterial(execution.qaExecutor,legacyQa)}:{}),
|
|
207
|
+
...(execution.applicableAgentFiles?{applicableAgentFiles:execution.applicableAgentFiles}:{}),
|
|
208
|
+
...(execution.documentationProvider?{documentationProvider:{version:1,timeoutMs:execution.documentationProvider.timeoutMs}}:{}),
|
|
209
|
+
...(execution.documentationResult?{documentationResult:execution.documentationResult}:{}),
|
|
210
|
+
...(execution.documentationSync?{documentationSync:{version:1,paths:execution.documentationSync.paths}}:{})};
|
|
211
|
+
}
|
|
212
|
+
const LEGACY_QA_FINGERPRINT_REASON='运行指纹与当前配置不符。若此运行由之前的版本创建,它的指纹还含有当时生效的 CM 配置'
|
|
213
|
+
+'(项目 .cm-workflow.yml、~/.cm-workflow/runtimes.yml 与插件内置默认值):把这些配置恢复为创建时的内容即可恢复;'
|
|
214
|
+
+'现在新建的运行不再把这些可变配置写进指纹。否则请核对 run.json、--workflow-config、宿主身份及授权参数是否与创建时一致。';
|
|
173
215
|
|
|
174
|
-
export async function openControlRun(definition,mode,execution=null,
|
|
216
|
+
export async function openControlRun(definition,mode,execution=null,options={}){
|
|
217
|
+
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
218
|
+
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
219
|
+
let guard;
|
|
220
|
+
try{
|
|
221
|
+
const acquire=async()=>{
|
|
222
|
+
const {acquireExternalRunGuard,externalRunGuardExists}=await import('../runtime/js/cm-ai/external-run-guard.mjs');
|
|
223
|
+
const strict=Boolean(execution?.configuration?.externalModels||execution?.configuration?.executionPolicy);
|
|
224
|
+
// Switching this binary to a legacy launch must not bypass an existing strict attempt.
|
|
225
|
+
if(strict||externalRunGuardExists(definition.specsDir,definition.codeProject))guard=acquireExternalRunGuard(definition,{strictOnly:!strict});
|
|
226
|
+
};
|
|
227
|
+
const result=await openControlRunOwned(definition,mode,execution,options,acquire);
|
|
228
|
+
const close=result.close;
|
|
229
|
+
return {...result,close:()=>{try{close();}finally{guard?.close();}}};
|
|
230
|
+
}catch(error){guard?.close();throw error;}
|
|
231
|
+
}
|
|
232
|
+
async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,holdRevision=false,specRebindReason=null}={},acquireGuard=async()=>{}){
|
|
175
233
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
176
234
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
177
|
-
const {conversationProtection}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
235
|
+
const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
178
236
|
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
237
|
+
if(mode==='create')assertCreatableRunId(definition?.identity);
|
|
179
238
|
if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
|
|
239
|
+
if(allowAbandonEffect&&mode!=='resume')fail('effect_abandon_unavailable');
|
|
240
|
+
if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
|
|
241
|
+
if(typeof holdRevision!=='boolean')fail('invalid_input');
|
|
242
|
+
if(specRebindReason!==null&&(mode!=='resume'||execution===null||typeof specRebindReason!=='string'||!specRebindReason.trim()
|
|
243
|
+
||Buffer.byteLength(specRebindReason,'utf8')>500||/[\r\n\0]/.test(specRebindReason)))fail('spec_rebind_unavailable');
|
|
244
|
+
if(typeof acceptSupersededCodeDrift!=='boolean'||acceptSupersededCodeDrift&&supersedeReason===null)
|
|
245
|
+
fail('supersede_unavailable');
|
|
180
246
|
if(qaConfigRevision!==null&&(mode!=='resume'||!execution?.qaExecutor||rerunUnknownQa||rerunBlockedQa
|
|
181
247
|
||typeof qaConfigRevision.reason!=='string'||!qaConfigRevision.reason.trim()||qaConfigRevision.reason.length>500
|
|
182
248
|
||/[\r\n\0]/.test(qaConfigRevision.reason)||!qaConfigRevision.previousWorkflow))fail('qa_revision_authorization_required');
|
|
@@ -184,7 +250,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
184
250
|
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
185
251
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
186
252
|
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
187
|
-
const {inspectCmAiAdmission,matchesCmAiTaskSelection}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
253
|
+
const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
188
254
|
const {captureReviewBaseline}=await import('../runtime/js/cm-ai/review-package.mjs');
|
|
189
255
|
if(execution!==null){
|
|
190
256
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
@@ -196,6 +262,11 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
196
262
|
if(Object.hasOwn(execution.configuration,'workflow')&&protectedExecutions.has(execution)
|
|
197
263
|
&&sha(execution.configuration.workflow.definition)!==sha(definition))fail('execution_definition_mismatch');
|
|
198
264
|
const conversation=conversationProtection(execution);
|
|
265
|
+
if(execution.configuration.externalModels||execution.configuration.executionPolicy){
|
|
266
|
+
const bound=externalConversationDefinition(execution);
|
|
267
|
+
if(bound===null)fail('external_execution_factory_required');
|
|
268
|
+
if(bound!==sha(definition))fail('execution_definition_mismatch');
|
|
269
|
+
}
|
|
199
270
|
const protection=protectedExecutions.get(execution)??conversation;
|
|
200
271
|
if(conversation&&conversation.definitionDigest!==sha(definition))fail('execution_definition_mismatch');
|
|
201
272
|
if(protection){
|
|
@@ -214,108 +285,169 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
214
285
|
const featureSlug=feature.replace(/^\d+\./,'');
|
|
215
286
|
const reviewsDir=path.join(specsDir,'.reviews');
|
|
216
287
|
const supersession=mode==='create'&&supersedeReason!==null
|
|
217
|
-
?prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason:supersedeReason,tasksPath
|
|
288
|
+
?prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason:supersedeReason,tasksPath,
|
|
289
|
+
acceptSupersededCodeDrift}):null;
|
|
218
290
|
let bootstrapConfig=null;
|
|
219
291
|
if(execution?.bootstrap){
|
|
220
292
|
const {bootstrapConfiguration}=await import('../runtime/js/cm-ai/host-bootstrap.mjs');
|
|
221
293
|
bootstrapConfig=bootstrapConfiguration(execution.bootstrap,{root:codeProject,identity,scope,feature});
|
|
222
294
|
}
|
|
223
295
|
if(parallelSelection!==null)parallelSelection=JSON.parse(JSON.stringify(parallelSelection));
|
|
296
|
+
if(parallelSelection!==null&&definition.taskSelection)fail('task_selection_mismatch');
|
|
297
|
+
const selection=parallelSelection??definition.taskSelection??null;
|
|
224
298
|
const selectedRoots=definition.codeProjects?codeProjectPaths(codeProject,resolveCodeProjects(codeProject,definition.codeProjects)):null;
|
|
225
299
|
if(selectedRoots){
|
|
226
300
|
if(!execution||conversationProtection(execution)===null)fail('multi_root_protection_required');
|
|
227
301
|
for(const root of definition.codeProjects){
|
|
228
302
|
const selected=inspectCmAiAdmission({specsDir,codeProject:root});
|
|
229
|
-
if(mode==='create'&&!matchesCmAiTaskSelection(selected,feature,identity.taskId,
|
|
303
|
+
if(mode==='create'&&!matchesCmAiTaskSelection(selected,feature,identity.taskId,selection))
|
|
230
304
|
return {blocked:selected,close:()=>{}};
|
|
231
305
|
}
|
|
232
306
|
}
|
|
233
307
|
const developer=execution?.documentationSync
|
|
234
308
|
?(await import('../runtime/js/cm-ai/host-documentation.mjs')).withHostDocumentation({developer:execution.developer,
|
|
235
|
-
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope,parallelSelection}):execution?.developer;
|
|
309
|
+
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope,parallelSelection:selection}):execution?.developer;
|
|
236
310
|
const admission=inspectCmAiAdmission({specsDir,codeProject});
|
|
237
311
|
if(mode==='create'&&admission.state!=='ready')return {blocked:admission,close:()=>{}};
|
|
238
|
-
if(mode==='create'&&!matchesCmAiTaskSelection(admission,feature,identity.taskId,
|
|
312
|
+
if(mode==='create'&&!matchesCmAiTaskSelection(admission,feature,identity.taskId,selection))
|
|
313
|
+
throw Object.assign(new Error('task_selection_mismatch'),{code:'task_selection_mismatch',
|
|
314
|
+
reason:explainCmAiTaskSelection(admission,{feature,taskId:identity.taskId,selection})});
|
|
239
315
|
const handoffs=[1,2].map(attempt=>path.join(reviewsDir,`${featureSlug}-${identity.taskId}-a${attempt}-handoff.json`));
|
|
316
|
+
if(mode==='create'&&supersession===null){
|
|
317
|
+
for(const [index,handoff] of handoffs.entries()){
|
|
318
|
+
if(fs.existsSync(handoff)&&reviewConsumedHandoff(reviewsDir,path.basename(handoff),index+1))reviewedHandoffConflict();
|
|
319
|
+
}
|
|
320
|
+
assertNoUnrecordedPriorCode({specsDir,codeProject,feature,identity,tasksPath});
|
|
321
|
+
}
|
|
240
322
|
// Reuse the runner's real validator before creating durable state. A failed
|
|
241
323
|
// baseline must not strand an otherwise unused run ID.
|
|
242
324
|
const specification={specsRoot:specsDir,feature};
|
|
243
325
|
const baselineOptions={root:codeProject,specsRoot:specsDir,identity,scope,requirements,specification,
|
|
244
326
|
...(bootstrapConfig?{bootstrapRequirements:bootstrapConfig.bootstrapRequirements}:{}),
|
|
245
327
|
...(selectedRoots?{codeProjectPaths:selectedRoots}:{})};
|
|
246
|
-
if(mode==='create')
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
328
|
+
if(mode==='create'){
|
|
329
|
+
// The baseline is journaled as one record. One that cannot fit even on its own
|
|
330
|
+
// is refused here, before any store exists; the runner checks the exact record.
|
|
331
|
+
const preview=captureReviewBaseline(baselineOptions),bytes=Buffer.byteLength(JSON.stringify(preview));
|
|
332
|
+
if(bytes>JOURNAL_PAYLOAD_LIMIT){
|
|
333
|
+
const largest=preview.files.filter(file=>Object.hasOwn(file,'contentBase64')).sort((a,b)=>b.size-a.size).slice(0,3)
|
|
334
|
+
.map(file=>`${file.path} ${file.size} bytes`);
|
|
335
|
+
throw Object.assign(new Error(boundedReason(`limit_exceeded: the task baseline alone is ${bytes} bytes, above the journal record limit `
|
|
336
|
+
+`${JOURNAL_PAYLOAD_LIMIT}; largest baseline material: `,largest)),{code:'limit_exceeded'});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const storeIdentity={repositoryId:identity.repositoryId,runId:identity.runId};
|
|
340
|
+
// Publish new ownership only after execution, admission, selection and baseline validation.
|
|
341
|
+
await acquireGuard();
|
|
342
|
+
// Every fingerprint check below runs against one candidate material and
|
|
343
|
+
// closes its store before the next candidate is tried.
|
|
344
|
+
const openFor=material=>{
|
|
345
|
+
const fingerprints={workflow:sha(execution===null?'cm-ai-control-v1':'cm-ai-host-execution-v1'),
|
|
346
|
+
config:sha(material),inputs:sha({feature,task:identity.taskId})};
|
|
347
|
+
const storeOptions={tasksPath,feature:featureSlug,specsRoot:specsDir,identity:storeIdentity,fingerprints,create:mode==='create'};
|
|
348
|
+
let store,attaching=false,priorMaterial=null;
|
|
349
|
+
if(qaConfigRevision!==null)priorMaterial=previousQaMaterial(material,qaConfigRevision.previousWorkflow);
|
|
350
|
+
try{store=openTaskExecutionStore(storeOptions);}
|
|
351
|
+
catch(error){
|
|
352
|
+
if(mode!=='resume'||error.code!=='fingerprint_mismatch')throw error;
|
|
353
|
+
const snapshot=readExecutionSnapshot({specsRoot:specsDir,identity:storeIdentity});
|
|
354
|
+
const last=qaRevisionChain(snapshot).revisions.at(-1);
|
|
355
|
+
if(priorMaterial&&last?.toFingerprint===fingerprints.config&&last.fromFingerprint===sha(priorMaterial)
|
|
356
|
+
&&last.reason===qaConfigRevision.reason)priorMaterial=null;
|
|
357
|
+
if(priorMaterial||snapshot.records.some(row=>row.payload.type==='qa-config-revised')){
|
|
358
|
+
verifyQaRevisionMaterial(snapshot,material,priorMaterial);
|
|
359
|
+
store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:snapshot.fingerprints.config}});
|
|
360
|
+
}
|
|
361
|
+
if(!store){
|
|
362
|
+
for(const previous of preQaConfigurations(material)){
|
|
363
|
+
try{store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:sha(previous)}});break;}
|
|
364
|
+
catch(cause){if(cause.code!=='fingerprint_mismatch')throw cause;}
|
|
365
|
+
}
|
|
366
|
+
if(!store){error.reason=explainFingerprintMismatch({snapshot,definition,execution,fingerprints});throw error;}
|
|
367
|
+
attaching=true;
|
|
368
|
+
}
|
|
276
369
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
370
|
+
try{
|
|
371
|
+
const chain=qaRevisionChain(store.snapshot());
|
|
372
|
+
if(chain.revisions.length&&chain.fingerprint!==fingerprints.config&&!priorMaterial)
|
|
373
|
+
throw Object.assign(new Error('fingerprint_mismatch'),{code:'fingerprint_mismatch',
|
|
374
|
+
reason:'QA 配置与最后一次 --revise-qa-config 修订后的配置不同;请用修订后的 --workflow-config 恢复'});
|
|
375
|
+
if(chain.revisions.length||priorMaterial)verifyQaRevisionMaterial(store.snapshot(),material,priorMaterial);
|
|
376
|
+
const attachments=store.snapshot().records.filter(row=>row.payload.type==='qa-attached');
|
|
377
|
+
if(attachments.length>1)fail('qa_attachment_duplicate');
|
|
378
|
+
const attached=attachments.length?readQaAttachment(attachments[0].payload.record):null;
|
|
379
|
+
if(attached&&!chain.revisions.length&&!priorMaterial&&attached.qaFingerprint!==fingerprints.config)
|
|
380
|
+
throw Object.assign(new Error('fingerprint_mismatch'),{code:'fingerprint_mismatch',
|
|
381
|
+
reason:'启动配置与事后附加 QA 时绑定的配置不同;请用附加 QA 时的 --workflow-config 与参数恢复'});
|
|
382
|
+
if(attaching&&store.snapshot().records.length===0)fail('qa_attach_not_completed');
|
|
383
|
+
return {material,fingerprints,store,attaching,priorMaterial,chain,attached};
|
|
384
|
+
}catch(error){store.close();throw error;}
|
|
385
|
+
};
|
|
386
|
+
const snapshot=mode==='resume'&&(execution?.documentationProvider||execution?.documentationResult)
|
|
387
|
+
?readExecutionSnapshot({specsRoot:specsDir,identity:storeIdentity}):null;
|
|
388
|
+
let opened,lastMismatch;
|
|
389
|
+
for(const knowledgeCloseout of closeoutPolicyCandidates(execution,mode,snapshot)){
|
|
390
|
+
const materialOptions={parallelSelection,bootstrapConfig,knowledgeCloseout};
|
|
391
|
+
try{opened=openFor(runConfigMaterial(definition,execution,materialOptions));break;}
|
|
392
|
+
catch(error){
|
|
393
|
+
if(mode!=='resume'||error.code!=='fingerprint_mismatch')throw error;
|
|
394
|
+
lastMismatch=error;
|
|
395
|
+
if(!hasLegacyQaPlanFingerprint(execution?.qaExecutor))continue;
|
|
396
|
+
// Preserve the original exact historical QA fingerprint fallback.
|
|
397
|
+
try{opened=openFor(runConfigMaterial(definition,execution,{...materialOptions,legacyQa:true}));break;}
|
|
398
|
+
catch(cause){
|
|
399
|
+
if(cause.code!=='fingerprint_mismatch')throw cause;
|
|
400
|
+
lastMismatch=Object.assign(error,{reason:error.reason?`${error.reason}。${LEGACY_QA_FINGERPRINT_REASON}`:LEGACY_QA_FINGERPRINT_REASON});
|
|
281
401
|
}
|
|
282
|
-
if(!store)throw error;
|
|
283
|
-
attaching=true;
|
|
284
402
|
}
|
|
285
403
|
}
|
|
404
|
+
if(!opened)throw lastMismatch;
|
|
405
|
+
const {material:configMaterial,fingerprints,store,attaching,priorMaterial,chain,attached}=opened;
|
|
406
|
+
const knowledgeCloseout=configMaterial.knowledgeCloseout??null;
|
|
286
407
|
try{
|
|
287
|
-
const chain=qaRevisionChain(store.snapshot());
|
|
288
|
-
if(chain.revisions.length&&chain.fingerprint!==fingerprints.config&&!priorMaterial)fail('fingerprint_mismatch');
|
|
289
|
-
if(chain.revisions.length||priorMaterial)verifyQaRevisionMaterial(store.snapshot(),configMaterial,priorMaterial);
|
|
290
|
-
const attachments=store.snapshot().records.filter(row=>row.payload.type==='qa-attached');
|
|
291
|
-
if(attachments.length>1)fail('qa_attachment_duplicate');
|
|
292
|
-
const attached=attachments.length?readQaAttachment(attachments[0].payload.record):null;
|
|
293
|
-
if(attached&&!chain.revisions.length&&!priorMaterial&&attached.qaFingerprint!==fingerprints.config)fail('fingerprint_mismatch');
|
|
294
|
-
if(attaching&&store.snapshot().records.length===0)fail('qa_attach_not_completed');
|
|
295
408
|
let runnerMode=mode;
|
|
296
409
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
297
410
|
// Only the genuine, fingerprint-matching empty initializer can be finished.
|
|
298
411
|
// Never reset/recreate a journal that contains any event.
|
|
299
|
-
if(!matchesCmAiTaskSelection(admission,feature,identity.taskId,
|
|
412
|
+
if(!matchesCmAiTaskSelection(admission,feature,identity.taskId,selection))
|
|
300
413
|
fail('initialization_admission_required');
|
|
301
414
|
captureReviewBaseline(baselineOptions);
|
|
302
415
|
runnerMode='create';
|
|
303
416
|
}
|
|
304
417
|
const unavailable=()=>fail('execution_adapter_required');
|
|
305
418
|
const host=createCmAiHost({
|
|
306
|
-
runner:{root:codeProject,identity,scope,requirements,specification,...(selectedRoots?{codeProjectPaths:selectedRoots}:{}),
|
|
419
|
+
runner:{root:codeProject,identity,scope,requirements,specification,...(selectedRoots?{codeProjectPaths:selectedRoots}:{}),
|
|
420
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
421
|
+
...(execution?.configuration.executionPolicy?{executionPolicy:execution.configuration.executionPolicy}:{}),
|
|
422
|
+
...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
|
|
307
423
|
developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
|
|
308
424
|
reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
|
|
309
425
|
persistence:{store,mode:runnerMode,version:execution===null?2:3},
|
|
426
|
+
...(execution===null?{}:{providerDevelopment:protectedExecutions.has(execution)
|
|
427
|
+
||Boolean(execution.configuration.providerDevelopment)}),
|
|
310
428
|
...(execution===null?{}:{developer,reviewers:execution.reviewers,
|
|
311
429
|
...(execution.bootstrap?{bootstrap:execution.bootstrap}:{}),
|
|
312
430
|
reviewInvocation:execution.reviewInvocation,check:execution.check,
|
|
313
431
|
excludedContexts:execution.excludedContexts,timeoutMs:execution.timeoutMs,
|
|
314
432
|
...(Object.hasOwn(execution,'verificationGate')?{verificationGate:execution.verificationGate}:{}),
|
|
315
433
|
taskLearning:{feature,hostHandoff:true}})},
|
|
316
|
-
entry
|
|
434
|
+
// The entry validates the declaration (single line, with --rerun-blocked-qa) before any durable write.
|
|
435
|
+
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
|
|
436
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
|
|
437
|
+
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
317
438
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
318
439
|
});
|
|
440
|
+
const logAbandonments=()=>{
|
|
441
|
+
for(const record of store.snapshot().records.filter(row=>row.payload.type==='review-invocation-abandoned'))
|
|
442
|
+
recordReviewAbandonment({specsDir,codeProject,feature,identity,record,
|
|
443
|
+
runtime:execution?.reviewers?.[0]?.provider??'codex',
|
|
444
|
+
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
445
|
+
for(const record of store.snapshot().records.filter(row=>row.payload.type==='effect-abandoned'))
|
|
446
|
+
recordEffectAbandonment({specsDir,codeProject,feature,identity,record,
|
|
447
|
+
runtime:execution?.developer?.provider??'codex',
|
|
448
|
+
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
449
|
+
};
|
|
450
|
+
if(mode==='resume')logAbandonments();
|
|
319
451
|
const recorded=store.snapshot().records.find(row=>row.payload.type==='evidence-superseded')?.payload.record??null;
|
|
320
452
|
if(supersession!==null||recorded!==null){
|
|
321
453
|
const record=host.supersedeEvidence(supersession??recorded);
|
|
@@ -335,25 +467,37 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
335
467
|
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})};
|
|
336
468
|
// Repair a crash after the journal append, before the log supersession.
|
|
337
469
|
for(const record of chain.revisions)recordCmAiQaConfigurationRevision({...qaBinding,identity:{...identity,attempt:record.taskAttempt},packageDigest:record.packageDigest},record);
|
|
470
|
+
if(specRebindReason!==null){
|
|
471
|
+
// Consumed once on this launch; the journal record is the audit trail.
|
|
472
|
+
host.rebindSpecification({version:1,reason:specRebindReason,at:new Date().toISOString()});
|
|
473
|
+
}
|
|
338
474
|
if(priorMaterial){
|
|
339
475
|
if(sha(priorMaterial)===fingerprints.config)fail('qa_revision_unchanged');
|
|
340
476
|
const current=await host.handle({version:1,operation:'status',requestId:'qa-revision-status',identity});
|
|
341
|
-
|
|
477
|
+
// No QA round of this run has started: record a round-0 revision that
|
|
478
|
+
// supersedes nothing and consumes no round. The runner re-checks state.
|
|
479
|
+
const beforeQa=!hasCmAiQaRun({specsDir,feature,identity:current.identity});
|
|
480
|
+
if(!beforeQa&&(current.state!=='fixture_completed'||current.code!==null))fail('qa_revision_not_completed');
|
|
342
481
|
const binding={...qaBinding,identity:current.identity,packageDigest:current.packageDigest};
|
|
343
|
-
const target=inspectCmAiQaRevisionTarget(binding);
|
|
482
|
+
const target=beforeQa?{testRunId:null,qaRound:0}:inspectCmAiQaRevisionTarget(binding);
|
|
344
483
|
const record=host.reviseQa({version:1,fromFingerprint:sha(priorMaterial),toFingerprint:fingerprints.config,
|
|
345
484
|
invariantDigest:qaInvariantDigest(configMaterial),previousQaDigest:sha(qaConfigurationSlice(priorMaterial)),qaDigest:sha(qaConfigurationSlice(configMaterial)),
|
|
346
485
|
reason:qaConfigRevision.reason,hostContextId:execution.configuration.hostContextId,
|
|
347
|
-
revisedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),packageDigest:current.packageDigest,
|
|
486
|
+
revisedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),packageDigest:current.packageDigest??null,
|
|
348
487
|
testRunId:target.testRunId,qaRound:target.qaRound,taskAttempt:current.identity.attempt});
|
|
349
488
|
recordCmAiQaConfigurationRevision(binding,record);
|
|
489
|
+
// Only the newly authorized revision projects a new pending QA phase.
|
|
490
|
+
// Replaying or repairing its audit mirror above is not new execution.
|
|
491
|
+
if(!beforeQa)writeCmAiQaStatus({specsDir,feature,identity:current.identity,phase:'configuration_revised'});
|
|
350
492
|
}
|
|
351
493
|
return {host:{async handle(request){
|
|
352
494
|
if(execution===null&&!['status','cancel'].includes(request.operation)){
|
|
353
495
|
// Do not imply an unavailable execution adapter was dispatched.
|
|
354
496
|
return {outcome:'blocked',code:'execution_adapter_required',providerCalls:0};
|
|
355
497
|
}
|
|
356
|
-
|
|
498
|
+
const result=await host.handle(request);
|
|
499
|
+
if(['abandon_review','abandon_effect'].includes(request.operation)&&result.outcome==='abandoned')logAbandonments();
|
|
500
|
+
return result;
|
|
357
501
|
}},inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,
|
|
358
502
|
checkpoint:()=>store.snapshot().revision,close:()=>store.close()};
|
|
359
503
|
}catch(error){store.close();throw error;}
|
|
@@ -15,7 +15,7 @@ const request=(operation,requestId=operation)=>({version:1,operation,requestId,i
|
|
|
15
15
|
const platform=process.platform==='darwin'&&Number(process.versions.node.split('.')[0])>=24;
|
|
16
16
|
test('QA attachment projections preserve every non-workflow fingerprint input and validate the immutable record',async()=>{
|
|
17
17
|
const {preQaConfigurations,readQaAttachment}=await import('../runtime/js/cm-ai/qa-attachment.mjs');
|
|
18
|
-
const material={definition:{identity,scope:['a.js'],requirements:['requirements.md']},
|
|
18
|
+
const material={definition:{identity,scope:['a.js'],requirements:['requirements.md']},knowledgeCloseout:{version:1,enabled:true},
|
|
19
19
|
execution:{kind:'cm-current-conversation-v1',hostContextId:'host',review:{model:'fixture'},
|
|
20
20
|
workflow:{qa:{commands:[],environment:{}},documentationPaths:['README.md'],applicableAgentFiles:[]}},
|
|
21
21
|
qaExecutor:{version:1,mode:'commands'},qaDecisionProvider:'host-v1',qaTimeoutMs:60000,
|
|
@@ -28,6 +28,7 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
|
|
|
28
28
|
assert(!Object.hasOwn(withoutWorkflow.execution,'workflow'));
|
|
29
29
|
assert(!Object.hasOwn(withoutWorkflow,'documentationSync'));
|
|
30
30
|
for(const projection of [withoutQa,withoutWorkflow]){
|
|
31
|
+
assert.deepEqual(projection.knowledgeCloseout,material.knowledgeCloseout);
|
|
31
32
|
assert.deepEqual(projection.definition,material.definition);
|
|
32
33
|
assert.deepEqual(projection.execution.review,material.execution.review);
|
|
33
34
|
assert.equal(projection.execution.hostContextId,'host');
|
|
@@ -78,8 +79,9 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
|
|
|
78
79
|
fs.writeFileSync(path.join(f.codeProject,'.git'),'gitdir: /nonexistent/cm-synthetic-worktree-metadata\n');
|
|
79
80
|
let stdout='',stderr='',calls=0,reviews=0;output.on('data',x=>stdout+=x);error.on('data',x=>stderr+=x);
|
|
80
81
|
const execution={configuration:{kind:'synthetic-host-v1'},timeoutMs:2000,excludedContexts:['main'],
|
|
81
|
-
developer:{provider:'codex',requestedModel:'fixture',contextId:'dev',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
82
|
-
|
|
82
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'dev',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async({prompt})=>{
|
|
83
|
+
// Attempt 2 must change the rejected bytes (develop_unchanged_after_review).
|
|
84
|
+
calls++;fs.writeFileSync(path.join(f.codeProject,'a.js'),JSON.parse(prompt.split('<cm-developer-data-json>\n')[1]).identity.attempt===1?'new\n':'new 2\n');
|
|
83
85
|
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
84
86
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
85
87
|
}})},
|
|
@@ -114,7 +116,7 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
|
|
|
114
116
|
}},
|
|
115
117
|
hostDecision:mode==='awaiting'?null:['approved','blocked','repair','review_limit','spec_drift'].includes(mode)?{status:'approved'}:{status:'denied',code:'permission_denied'},
|
|
116
118
|
check:createHostCheck({cwd:f.codeProject,commands:[{id:'content',command:[process.execPath,'-e',
|
|
117
|
-
"require('node:assert/strict').
|
|
119
|
+
"require('node:assert/strict').match(require('node:fs').readFileSync('a.js','utf8'),/^new( 2)?\\n$/)"]}]})};
|
|
118
120
|
let qaCalls=0,qaRuns=0,docInspections=0,docWrites=0,reviewDecisions=0;
|
|
119
121
|
const dynamicQa=mode==='approved'&&!nested;
|
|
120
122
|
const dynamicReview=dynamicQa||mode==='repair';
|