@aibyzero/cm-workflow 0.16.8 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +489 -51
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
package/scripts/cm-ai-drive.mjs
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// fix_repair, fix_retrospective; host-qa-fix-owner.mjs
|
|
26
26
|
// forwards to cm-fix host.run/handle.
|
|
27
27
|
// fix_action selected cm-fix step; host-qa-fix-owner.mjs fix_action.
|
|
28
|
-
// status/cancel/abandon_review/abandon_effect/bootstrap_review_recover/fix_status/context_refresh: none; cm-ai-conversation-entry.mjs
|
|
28
|
+
// status/cancel/abandon_review/abandon_effect/bootstrap_review_recover/develop_redo/fix_status/context_refresh: none; cm-ai-conversation-entry.mjs
|
|
29
29
|
// status/cancel/context_refresh; host-qa-fix-owner.mjs fix_status.
|
|
30
30
|
// verification_precheck optional execution.verificationGate in
|
|
31
31
|
// host-conversation-execution.mjs; CLI has no runner for it.
|
|
@@ -38,7 +38,7 @@ import path from 'node:path';
|
|
|
38
38
|
import {createHash} from 'node:crypto';
|
|
39
39
|
import {fileURLToPath} from 'node:url';
|
|
40
40
|
import {createHostCheck,reportHostCheckProgress} from '../runtime/js/cm-ai/host-check.mjs';
|
|
41
|
-
import {
|
|
41
|
+
import {readQaAssessment} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
42
42
|
import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
43
43
|
import {inspectCmAiQaTaskContext} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
44
44
|
import {readLearningRetrospectiveContent} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
@@ -56,15 +56,16 @@ import {codeProjectPaths,resolveCodeProjects} from '../runtime/js/cm-ai/code-pro
|
|
|
56
56
|
import {parseHostInputLimit} from '../runtime/js/cm-ai/host-session.mjs';
|
|
57
57
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
58
58
|
import {readCloseoutReport} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
59
|
-
import {readRunnerHistory,attemptBaseline} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
59
|
+
import {readRunnerHistory,attemptBaseline,projectedRunnerStatus,RECHECK_CODES,DOCUMENTATION_SYNC_CODES} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
60
60
|
import {developmentRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
61
61
|
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
62
62
|
import {attemptAnswerName,inspectDriverBootstrap,readBootstrapRulesAnswers,createBootstrapRulesResponder} from '../runtime/js/cm-ai/drive-bootstrap.mjs';
|
|
63
63
|
import {driverLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
64
|
+
import {readControlPolicyFile,isControlRecovery as controlRecoveryRequest} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
64
65
|
|
|
65
66
|
// PLAN.liveEvidence: fresh current-session evidence; see docs/live-evidence-drivers.md.
|
|
66
67
|
const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
67
|
-
const OPERATIONS=new Set(['advance','start','resume','status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','decision','complete','qa','qa_result',
|
|
68
|
+
const OPERATIONS=new Set(['advance','start','resume','status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','develop_redo','decision','complete','qa','qa_result',
|
|
68
69
|
'fix_status','fix_advance','fix_action','fix_run','run_finalize','context_refresh','finish']);
|
|
69
70
|
const ADVANCE=new Set(['advance','start','resume']);
|
|
70
71
|
const PACKAGE_OPERATIONS=new Set(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize']);
|
|
@@ -72,28 +73,75 @@ const TEST_RUN_OPERATIONS=new Set(['qa_result','context_refresh','finish','run_f
|
|
|
72
73
|
const FIX_ASKS={advance:['fix_learning','fix_diagnose'],author_tests:['fix_learning','fix_test_author'],
|
|
73
74
|
repair:['fix_learning','fix_repair'],retrospective:['fix_learning','fix_retrospective'],
|
|
74
75
|
red_test:['fix_learning'],baseline:['fix_learning'],regression:['fix_learning'],
|
|
75
|
-
post_review_regression:['fix_learning'],prepare_revision:['fix_learning']};
|
|
76
|
+
post_review_regression:['fix_learning'],prepare_revision:['fix_learning'],rediagnose:['fix_learning','fix_diagnose']};
|
|
76
77
|
const FIX_ACTIONS=new Set(['red_test','baseline','author_tests','repair','regression','retrospective',
|
|
77
78
|
'learning_writeback','handoff','final_review_package','final_review','publish_review','check_n5',
|
|
78
79
|
'post_review_regression','publish_dossier','walkthrough','finish','prepare_revision',
|
|
79
|
-
'cause_review_package','cause_review','reconcile_review','abandon_step','abandon_review'
|
|
80
|
+
'cause_review_package','cause_review','reconcile_review','abandon_step','abandon_review',
|
|
81
|
+
'rediagnose','rerun_blocked_step','recover_final_review','revision_test_check']);
|
|
82
|
+
// Q23: parent launch flag per recovery fixOperation (host-qa-fix-owner.mjs QA_FIX_ACTION_FLAGS).
|
|
83
|
+
const FIX_ACTION_FLAGS={abandon_step:'--allow-qa-fix-abandon',abandon_review:'--allow-qa-fix-abandon-review',
|
|
84
|
+
rediagnose:'--allow-qa-fix-rediagnosis',rerun_blocked_step:'--allow-qa-fix-rerun-blocked-step',
|
|
85
|
+
recover_final_review:'--allow-qa-fix-final-review-recovery',revision_test_check:'--allow-qa-fix-regression'};
|
|
86
|
+
const FIX_REASONED=['abandon_step','abandon_review','rediagnose','rerun_blocked_step','recover_final_review'];
|
|
80
87
|
const FILES={develop:'develop.json',qa_assess:'qa-assess.json',documentation_inspect:'documentation-inspect.json',
|
|
81
88
|
documentation_sync:'documentation-sync.json',fix_learning:'learning.json',fix_diagnose:'diagnosis.json',
|
|
82
89
|
fix_test_author:'test-edits.json',fix_repair:'repair-edits.json',fix_retrospective:'retrospective.json'};
|
|
83
|
-
const PAIR_FLAGS=new Set(['--external-models-config','--
|
|
90
|
+
const PAIR_FLAGS=new Set(['--external-models-config','--review-config','--workflow-config',
|
|
84
91
|
'--input-limit',
|
|
85
92
|
'--protected-conversation-config','--protected-config','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure',
|
|
86
93
|
'--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--browser-qa',
|
|
87
94
|
'--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--spec-rebind-reason',
|
|
88
|
-
'--review-runtime','--feature']);
|
|
95
|
+
'--review-runtime','--feature','--qa-fix-final-review-recovery-invocation']);
|
|
89
96
|
const FLAG_FLAGS=new Set(['--execution-optimizations','--external-models','--allow-development','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',
|
|
90
97
|
'--verification-precheck',
|
|
91
|
-
'--allow-bootstrap-write','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--rerun-unknown-qa','--rerun-blocked-qa','--failover',
|
|
98
|
+
'--allow-bootstrap-write','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--allow-develop-redo','--rerun-unknown-qa','--rerun-blocked-qa','--failover',
|
|
92
99
|
'--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material',
|
|
93
100
|
...['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon','abandon-review',
|
|
94
|
-
'test-author','repair','cause-review','final-review'].map(name=>`--allow-qa-fix-${name}`)]);
|
|
101
|
+
'test-author','repair','cause-review','final-review','rediagnosis','rerun-blocked-step','final-review-recovery'].map(name=>`--allow-qa-fix-${name}`)]);
|
|
95
102
|
const object=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
|
|
96
103
|
const nonempty=value=>typeof value==='string'&&value.trim().length>0;
|
|
104
|
+
// V2 control is explicit configuration. Never derive a fresh recovery target
|
|
105
|
+
// from the journal or status here: the caller must carry its earlier preview.
|
|
106
|
+
export function readDriverControl(plan,base,operation,recovery=null){
|
|
107
|
+
if(!Object.hasOwn(plan,'controlConfig'))return null;
|
|
108
|
+
if(!nonempty(plan.controlConfig)||path.isAbsolute(plan.controlConfig))
|
|
109
|
+
throw Error('PLAN.controlConfig 必须是相对 PLAN 的配置文件路径');
|
|
110
|
+
if(!Array.isArray(plan.permissions)||plan.permissions.some(flag=>typeof flag!=='string'))
|
|
111
|
+
throw Error('permissions 必须是宿主参数数组');
|
|
112
|
+
if(plan.permissions.some(flag=>flag.startsWith('--allow-')))
|
|
113
|
+
throw Error('control v2 迁移错误:permissions 禁止 --allow-*;请改用 controlConfig 的明确模式和 expectedControl');
|
|
114
|
+
const recovering=recovery??isControlRecovery(operation,plan);
|
|
115
|
+
if(plan.mode==='create'&&Object.hasOwn(plan,'expectedControl'))
|
|
116
|
+
throw Error('control v2 create 禁止 expectedControl');
|
|
117
|
+
if(!recovering&&Object.hasOwn(plan,'expectedControl'))
|
|
118
|
+
throw Error('control v2 expectedControl 只用于显式恢复操作');
|
|
119
|
+
if(recovering&&(plan.mode!=='resume'||!object(plan.expectedControl)))
|
|
120
|
+
throw Error('control v2 恢复需要 PLAN.expectedControl;请携带此前 status 返回的 controlTarget');
|
|
121
|
+
const file=path.resolve(base,plan.controlConfig);
|
|
122
|
+
const policy=readControlPolicyFile(file);
|
|
123
|
+
if((policy.development==='provider')!==plan.permissions.includes('--protected-config'))
|
|
124
|
+
throw Error('invalid_arguments: development provider 需要 --protected-config;conversation 禁止 provider 配置');
|
|
125
|
+
if(policy.bootstrap==='disabled'&&plan.permissions.includes('--bootstrap-config'))
|
|
126
|
+
throw Error('invalid_arguments: bootstrap disabled 禁止 --bootstrap-config;未读取该配置');
|
|
127
|
+
if(policy.qaFix==='disabled'&&['--qa-fix-owner-config','--qa-fix-template-config'].some(flag=>plan.permissions.includes(flag)))
|
|
128
|
+
throw Error('invalid_arguments: qaFix disabled 禁止 QA Fix 配置;未读取该配置');
|
|
129
|
+
return {file,policy};
|
|
130
|
+
}
|
|
131
|
+
export const isControlRecovery=(operation,plan)=>controlRecoveryRequest({operation,fixOperation:plan.fixOperation});
|
|
132
|
+
export function controlDevelopAttempts(status,operation){
|
|
133
|
+
const {state,attempt,reviewPackage}=status;
|
|
134
|
+
const reviewAfterDevelop=operation==='advance'&&attempt===1;
|
|
135
|
+
if(state==='blocked'&&(RECHECK_CODES.includes(status.code)||DOCUMENTATION_SYNC_CODES.includes(status.code)))
|
|
136
|
+
return {attempts:reviewAfterDevelop?[2]:[],reviewFirst:false,reviewAfterDevelop,holdable:true,packageDigest:null};
|
|
137
|
+
if(developmentRetryable(status))
|
|
138
|
+
return {attempts:reviewAfterDevelop?[1,2]:[attempt],reviewFirst:false,reviewAfterDevelop,holdable:true,packageDigest:null};
|
|
139
|
+
if(state==='ready')return {attempts:reviewAfterDevelop?[1,2]:[attempt],reviewFirst:false,reviewAfterDevelop,holdable:true,packageDigest:null};
|
|
140
|
+
if(state==='changes_requested')return {attempts:[attempt],reviewFirst:false,packageDigest:null};
|
|
141
|
+
if(operation==='advance'&&['awaiting_review','pending_review'].includes(state)&&attempt<2)
|
|
142
|
+
return {attempts:[attempt+1],reviewFirst:true,reviewAfterDevelop:true,holdable:true,packageDigest:reviewPackage?.packageDigest??null};
|
|
143
|
+
return {attempts:[],reviewFirst:false,packageDigest:null};
|
|
144
|
+
}
|
|
97
145
|
// Needs the resolved --bootstrap-config path in permissions.
|
|
98
146
|
export const bootstrapDriverGap=(operation,definition,permissions)=>
|
|
99
147
|
inspectDriverBootstrap({advance:ADVANCE.has(operation),definition,permissions}).gap;
|
|
@@ -107,6 +155,11 @@ export const abandonEffectPlanError=(operation,plan,permissions)=>operation!=='a
|
|
|
107
155
|
&&typeof plan.reason==='string'&&plan.reason.trim().length>0
|
|
108
156
|
&&Buffer.byteLength(plan.reason,'utf8')<=500&&!/[\r\n\0]/.test(plan.reason)?null:
|
|
109
157
|
'abandon_effect 需要 resume、--allow-abandon-effect 与单行 reason(最多 500 UTF-8 字节)';
|
|
158
|
+
export const developRedoPlanError=(operation,plan,permissions)=>operation!=='develop_redo'?null:
|
|
159
|
+
plan.mode==='resume'&&permissions.includes('--allow-develop-redo')
|
|
160
|
+
&&typeof plan.reason==='string'&&plan.reason.trim().length>0
|
|
161
|
+
&&Buffer.byteLength(plan.reason,'utf8')<=500&&!/[\r\n\0]/.test(plan.reason)?null:
|
|
162
|
+
'develop_redo 需要 resume、--allow-develop-redo 与单行 reason(最多 500 UTF-8 字节),并先确认会话已停止修改代码';
|
|
110
163
|
export const bootstrapReviewRecoveryPlanError=(operation,plan,permissions)=>operation!=='bootstrap_review_recover'?null:
|
|
111
164
|
plan.mode==='resume'&&permissions.includes('--allow-bootstrap-review-recovery')
|
|
112
165
|
&&typeof plan.reason==='string'&&plan.reason.trim().length>0
|
|
@@ -414,32 +467,26 @@ export function readRunJournal(definition){
|
|
|
414
467
|
const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,identity:{
|
|
415
468
|
repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
416
469
|
const first=snapshot.records[0];
|
|
417
|
-
return {history:readRunnerHistory(snapshot.records,first.payload.config,3),baseline:first.payload.baseline,
|
|
470
|
+
return {history:readRunnerHistory(snapshot.records,first.payload.config,3),config:first.payload.config,baseline:first.payload.baseline,
|
|
418
471
|
frame:journalRestBytes(snapshot.records)};
|
|
419
472
|
}
|
|
420
|
-
function reachableDevelopAttempts({plan,operation,journal,permissions}){
|
|
473
|
+
function reachableDevelopAttempts({plan,operation,journal,permissions,controlPolicy=null}){
|
|
421
474
|
if(plan.mode==='create'){
|
|
422
|
-
const reviewAfterDevelop=operation==='advance'
|
|
423
|
-
|
|
424
|
-
|
|
475
|
+
const reviewAfterDevelop=operation==='advance';
|
|
476
|
+
return {attempts:reviewAfterDevelop?[1,2]:[1],reviewFirst:false,reviewAfterDevelop,
|
|
477
|
+
holdable:true,packageDigest:null,learning:null};
|
|
425
478
|
}
|
|
426
479
|
if(journal.error)stop(2,`无法只读检查恢复存档: ${journal.error.code??journal.error.message}`);
|
|
427
480
|
// learning is the journal's Learning result the next develop effect starts from
|
|
428
481
|
// (bootstrap rules bind their on-disk files to its recorded evidence).
|
|
429
|
-
|
|
482
|
+
// Q28: decide from what the host will show (projected answer-gap blocks), not the raw replay state.
|
|
483
|
+
const status=projectedRunnerStatus(journal.history,journal.config);
|
|
484
|
+
return {...(controlPolicy?controlDevelopAttempts(status,operation):projectDevelopAttempts(status,operation,permissions)),
|
|
485
|
+
learning:journal.history.state.learningResult??null};
|
|
430
486
|
}
|
|
431
|
-
export function projectDevelopAttempts(status,operation
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if(state==='ready'&&attempt===1&&operation==='advance'
|
|
435
|
-
&&permissions.some((flag,index)=>flag==='--allow-review-attempt'&&permissions[index+1]==='1'))
|
|
436
|
-
return {attempts:[1,2],reviewFirst:false,reviewAfterDevelop:true,packageDigest:null};
|
|
437
|
-
if(['ready','changes_requested'].includes(state))return {attempts:[attempt],reviewFirst:false,packageDigest:null};
|
|
438
|
-
if(operation==='advance'&&['awaiting_review','pending_review'].includes(state)
|
|
439
|
-
&&permissions.some((flag,index)=>flag==='--allow-review-attempt'&&Number(permissions[index+1])===attempt)
|
|
440
|
-
&&attempt<2)return {attempts:[attempt+1],reviewFirst:true,
|
|
441
|
-
packageDigest:reviewPackage?.packageDigest??null};
|
|
442
|
-
return {attempts:[],reviewFirst:false,packageDigest:null};
|
|
487
|
+
export function projectDevelopAttempts(status,operation){
|
|
488
|
+
// Review dispatch is direct; both attempts follow the same reachable-state rules.
|
|
489
|
+
return controlDevelopAttempts(status,operation);
|
|
443
490
|
}
|
|
444
491
|
function predictedQaAsks(definition,qa){
|
|
445
492
|
// Reuse the executor's validated initial plan for policy applicability.
|
|
@@ -500,7 +547,7 @@ export function validateCmAiAnswer(kind,value,root){
|
|
|
500
547
|
try{developEntries(value.edits,root,'develop.json.edits');}catch(error){stop(2,`答案格式错误:${error.message}`);}
|
|
501
548
|
}else {exact(value,['status','code'],'develop.json');requireShape(nonempty(value.code),'develop.json.code');}
|
|
502
549
|
}else if(kind==='qa_assess'){
|
|
503
|
-
try{
|
|
550
|
+
try{readQaAssessment(value);}
|
|
504
551
|
catch{stop(2,'答案格式错误:qa-assess.json');}
|
|
505
552
|
}else if(kind==='documentation_inspect'){
|
|
506
553
|
exact(value,['status','reason','at','closeout'],'documentation-inspect.json');
|
|
@@ -537,7 +584,8 @@ export function validateCmAiAnswer(kind,value,root){
|
|
|
537
584
|
}
|
|
538
585
|
function load(){
|
|
539
586
|
if(process.argv.length===3&&['--help','-h'].includes(process.argv[2])){
|
|
540
|
-
process.stdout.write('
|
|
587
|
+
process.stdout.write('新版 PLAN.controlConfig 为相对 PLAN 的 v2 控制配置路径;development、bootstrap、qa、qaFix 使用明确模式,permissions 禁止所有 --allow-*。普通 advance 自动独立审查;缺少 develop-a2.json 时保持 revision_answer_required。显式恢复需要 resume 与此前 status 返回的 PLAN.expectedControl,驾驶员不会读取新目标覆盖它。\n');
|
|
588
|
+
process.stdout.write('用法: cm-ai-drive.mjs --plan PLAN.json <operation>\nPLAN: config, mode, hostContext, originalHostContext (换会话 resume 必填), runtime, permissions, answers, checks, checkTimeoutMs。\nchecks 每项为 {id,command,timeoutMs?};checkTimeoutMs 与每项 timeoutMs 为 1..3600000 整数,默认 900000 ms(15 分钟)。\nabandon_review 需要 mode:resume、permissions:["--allow-abandon-review"] 与 PLAN.reason;abandon_effect 需要 mode:resume、permissions:["--allow-abandon-effect"] 与 PLAN.reason(均为单行、最多 500 UTF-8 字节)。develop_redo 需要 mode:resume、permissions:["--allow-develop-redo"] 与 PLAN.reason,先确认会话已停止修改代码。 bootstrap_review_recover 需要 mode:resume、permissions:["--allow-bootstrap-review-recovery"] 与 PLAN.reason;只核对原运行的已写规则与 handoff,不需要答案文件。\n人工答案放 answers/;check 只运行 PLAN.checks,不读取静态执行证据。bootstrap T-001 骨架可用;T-002 规范任务(纯规范 scope、单代码根、非 --protected-config)读 answers/init-generate.json({status:"generated",documents:[{path,contentFile}]},覆盖全部 targets)与 answers/init-verify.json(commands 为驾驶员实跑的草稿命令 {id,command,timeoutMs?},可选 commandsNotRun;checks 只含 globs/file_references/constraint_preservation/rule_applicability;constraintChanges:[];application/retrospective 沿原 Learning);第 1 轮也可用 *-a1.json,第 2 轮只读 init-generate-a2.json 与 init-verify-a2.json,审查自动派发;缺少第2轮草稿时先停在 changes_requested,读取首轮 findings 后再写草稿。commands 在宿主接受启动后、发送操作前由驾驶员实跑(须先带 --allow-bootstrap-write 等宿主授权;受保护模式在 specs 沙箱内),失败或改动了预检核对的文件即退出 2 且不发送操作(create 时改用 resume 重跑);结果只来自实跑,答案文件不能提供。\n'
|
|
541
589
|
+'develop.json.edits 每项是 scope 路径到下列之一:"内容文件"(写入;已有文件保留权限,新文件 0644)、{"file":"内容文件","mode":"0755"|"0644"}、{"mode":"0755"|"0644"}(只改已有文件权限)、{"delete":true}(删除已有文件)。改名 = 删旧路径 + 写新路径,两者都要在 scope 内;同时列在 requirements 里的路径不能删除。\n'
|
|
542
590
|
+'启动前拒绝:单个 scope 文件超过 1 MiB、审查材料(按审查包快照:scope、requirements 与树中全部 AGENTS.md 正文)合计超过 2 MiB 或超过 256 个文件、交付后与任务基线完全相同(edits 为空或内容和权限都没变)、开发检查点(含 handoff 与 AGENTS.md 回写,按宿主同一套构建代码计)装不进运行存档单条 1 MiB 记录减去为有界审查与完成记录推出的预留,或任务基线装不进一条记录。受保护模式(--protected-conversation-config)只收合法 UTF-8 文本,应答大于 --input-limit(默认 65536)时提示应加的值。\n'
|
|
543
591
|
+'runId 需 8–128 个字符(运行日志要求),create 前检查。resume 时按存档里的当前轮次发送 identity,第 2 轮的 decision/complete/qa 等无需手改。\n');
|
|
@@ -546,6 +594,12 @@ function load(){
|
|
|
546
594
|
const loaded=loadPlanFile({name:'cm-ai-drive.mjs',known:OPERATIONS});
|
|
547
595
|
const {plan,operation,base}=loaded;
|
|
548
596
|
requireFields(plan,['config','mode','hostContext','permissions']);
|
|
597
|
+
let control;
|
|
598
|
+
try{control=readDriverControl(plan,base,operation);}catch(error){stop(2,error.message);}
|
|
599
|
+
if(control?.policy.bootstrap==='write'&&!plan.permissions.includes('--bootstrap-config'))
|
|
600
|
+
stop(2,'invalid_arguments: bootstrap write 需要 --bootstrap-config');
|
|
601
|
+
if(control?.policy.qaFix==='disabled'&&['fix_advance','fix_run','fix_action'].includes(operation))
|
|
602
|
+
stop(2,'invalid_arguments: qaFix disabled 不执行 QA Fix 操作');
|
|
549
603
|
if(Object.hasOwn(plan,'verificationPrecheck')&&typeof plan.verificationPrecheck!=='boolean')stop(2,'verificationPrecheck 需要 boolean');
|
|
550
604
|
try{planCheckTimeout(plan);}catch(error){stop(2,error.message);}
|
|
551
605
|
if(!['create','resume'].includes(plan.mode))stop(2,'mode 只能是 create 或 resume');
|
|
@@ -569,11 +623,18 @@ function load(){
|
|
|
569
623
|
if(permissions.includes('--rebind-spec-material')!==permissions.includes('--spec-rebind-reason')
|
|
570
624
|
||permissions.includes('--rebind-spec-material')&&plan.mode!=='resume')
|
|
571
625
|
stop(2,'--rebind-spec-material 只用于 mode resume,并须同时提供 --spec-rebind-reason 原因');
|
|
572
|
-
|
|
626
|
+
// V2 recovery operations are gated by the original expectedControl in the
|
|
627
|
+
// host, while the driver still validates the explicit operation and reason.
|
|
628
|
+
if(control&&['abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation)
|
|
629
|
+
&&(plan.mode!=='resume'||!nonempty(plan.reason)||Buffer.byteLength(plan.reason,'utf8')>500||/[\r\n\0]/.test(plan.reason)))
|
|
630
|
+
stop(2,`${operation} 需要 resume、expectedControl 与单行 reason(最多 500 UTF-8 字节)`);
|
|
631
|
+
const abandonError=control?null:abandonReviewPlanError(operation,plan,permissions);
|
|
573
632
|
if(abandonError)stop(2,abandonError);
|
|
574
|
-
const abandonEffectError=abandonEffectPlanError(operation,plan,permissions);
|
|
633
|
+
const abandonEffectError=control?null:abandonEffectPlanError(operation,plan,permissions);
|
|
575
634
|
if(abandonEffectError)stop(2,abandonEffectError);
|
|
576
|
-
const
|
|
635
|
+
const developRedoError=control?null:developRedoPlanError(operation,plan,permissions);
|
|
636
|
+
if(developRedoError)stop(2,developRedoError);
|
|
637
|
+
const bootstrapRecoveryError=control?null:bootstrapReviewRecoveryPlanError(operation,plan,permissions);
|
|
577
638
|
if(bootstrapRecoveryError)stop(2,bootstrapRecoveryError);
|
|
578
639
|
const config=path.resolve(base,plan.config),answers=plan.answers?path.resolve(base,plan.answers):null;
|
|
579
640
|
if(!fs.existsSync(config))stop(2,`运行定义不存在: ${config}`);
|
|
@@ -606,18 +667,18 @@ function load(){
|
|
|
606
667
|
}
|
|
607
668
|
const permissionFiles=[];
|
|
608
669
|
for(let i=0;i<permissions.length;i++)if(PAIR_FLAGS.has(permissions[i])
|
|
609
|
-
&&permissions[i]!=='--
|
|
670
|
+
&&permissions[i]!=='--browser-qa'
|
|
610
671
|
&&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--qa-environment-failure'&&permissions[i]!=='--allow-provider-development-attempt'
|
|
611
672
|
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'
|
|
612
|
-
&&permissions[i]!=='--review-runtime'&&permissions[i]!=='--feature'){
|
|
673
|
+
&&permissions[i]!=='--review-runtime'&&permissions[i]!=='--feature'&&permissions[i]!=='--qa-fix-final-review-recovery-invocation'){
|
|
613
674
|
const file=path.resolve(base,permissions[i+1]);if(!fs.existsSync(file))stop(2,`${permissions[i]} 文件不存在: ${file}`);
|
|
614
675
|
permissions[i+1]=file;permissionFiles.push(file);i++;
|
|
615
676
|
}
|
|
616
|
-
const bootstrap=inspectDriverBootstrap({advance:ADVANCE.has(operation),definition,permissions});
|
|
677
|
+
const bootstrap=inspectDriverBootstrap({advance:ADVANCE.has(operation),definition,permissions,controlPolicy:control?.policy??null});
|
|
617
678
|
if(bootstrap.gap)stop(2,bootstrap.gap);
|
|
618
679
|
const rules=bootstrap.mode==='instructions';
|
|
619
|
-
const providerMode=permissions.includes('--protected-config');
|
|
620
|
-
const protectedMode=
|
|
680
|
+
const providerMode=control?control.policy.development==='provider':permissions.includes('--protected-config');
|
|
681
|
+
const protectedMode=permissions.includes('--protected-config')||permissions.includes('--protected-conversation-config');
|
|
621
682
|
const asks=[];
|
|
622
683
|
if(ADVANCE.has(operation)){
|
|
623
684
|
// A pure rules scope never reaches develop: host-bootstrap.mjs asks the session instead.
|
|
@@ -627,24 +688,29 @@ function load(){
|
|
|
627
688
|
}
|
|
628
689
|
if((plan.verificationPrecheck===true||permissions.includes('--verification-precheck'))&&(ADVANCE.has(operation)||operation==='complete'))asks.push('verification_precheck');
|
|
629
690
|
if(operation==='complete'&&!protectedMode)asks.push('check');
|
|
630
|
-
if((operation==='advance'||operation==='qa')&&workflow
|
|
691
|
+
if((operation==='advance'||operation==='qa')&&workflow&&(control||workflow.qa)){asks.push('qa_assess');
|
|
631
692
|
}
|
|
632
|
-
if((operation==='advance'||operation==='qa')&&workflow?.qa){
|
|
693
|
+
if((operation==='advance'||operation==='qa')&&workflow?.qa&&(!control||control.policy.qa==='run')){
|
|
633
694
|
try{asks.push(...predictedQaAsks(definition,workflow.qa));}
|
|
634
695
|
catch(error){stop(2,`QA 请求预测失败: ${error.code??error.message}`);}
|
|
635
696
|
}
|
|
636
697
|
if(operation==='advance'&&workflow?.documentationPaths?.length&&!protectedMode)asks.push('documentation_sync');
|
|
637
698
|
if(['advance','finish','run_finalize'].includes(operation)&&workflow)asks.push('documentation_inspect');
|
|
638
|
-
if(operation==='advance'&&permissions.includes('--auto-qa-fix')){
|
|
699
|
+
if(operation==='advance'&&(control?control.policy.qaFix==='auto':permissions.includes('--auto-qa-fix'))){
|
|
639
700
|
asks.push(...new Set(Object.values(FIX_ASKS).flat()));
|
|
640
701
|
}
|
|
641
702
|
if(['fix_advance','fix_run'].includes(operation))asks.push(...new Set(Object.values(FIX_ASKS).flat()));
|
|
642
703
|
if(operation==='fix_action'){
|
|
643
704
|
if(plan.fixOperation==='reconcile_review'&&(plan.mode!=='resume'||!nonempty(plan.invocationId)))stop(2,'fix reconciliation requires resume and original invocationId');
|
|
644
705
|
if(!FIX_ACTIONS.has(plan.fixOperation))stop(2,'fix_action 需要宿主支持的 fixOperation');
|
|
645
|
-
const
|
|
646
|
-
if(
|
|
647
|
-
|
|
706
|
+
const actionFlag=FIX_ACTION_FLAGS[plan.fixOperation];
|
|
707
|
+
if(actionFlag&&!control&&!permissions.includes(actionFlag))stop(2,`${plan.fixOperation} 需要 ${actionFlag}`);
|
|
708
|
+
if(FIX_REASONED.includes(plan.fixOperation)&&!(nonempty(plan.reason)&&Buffer.byteLength(plan.reason,'utf8')<=1000
|
|
709
|
+
&&!/[\r\n\0\u0085\u2028\u2029]/.test(plan.reason)))stop(2,`${plan.fixOperation} 需要单行 reason(最多 1000 UTF-8 字节)`);
|
|
710
|
+
if(plan.fixOperation==='rediagnose'&&plan.mode!=='resume')stop(2,'rediagnose 需要 mode:resume');
|
|
711
|
+
if(plan.fixOperation==='recover_final_review'&&(plan.mode!=='resume'||!nonempty(plan.invocationId)
|
|
712
|
+
||!/^[a-f0-9]{64}$/.test(plan.reviewPackageDigest??'')||plan.previousInvocationStopped!==true))
|
|
713
|
+
stop(2,'recover_final_review 需要 mode:resume、原 invocationId、子运行终审包 reviewPackageDigest,以及确认旧审查进程已停的 previousInvocationStopped:true');
|
|
648
714
|
asks.push(...(FIX_ASKS[plan.fixOperation]??[]));
|
|
649
715
|
}
|
|
650
716
|
let live;
|
|
@@ -666,18 +732,28 @@ function load(){
|
|
|
666
732
|
}
|
|
667
733
|
catch(error){stop(2,`PLAN.checks 格式错误: ${error.code??error.message}`);}
|
|
668
734
|
}
|
|
669
|
-
|
|
670
|
-
?reachableDevelopAttempts({plan,operation,journal,permissions})
|
|
735
|
+
let reachable=(asks.includes('develop')||rules)&&!providerMode
|
|
736
|
+
?reachableDevelopAttempts({plan,operation,journal,permissions,controlPolicy:control?.policy??null})
|
|
671
737
|
:{attempts:[],reviewFirst:false,packageDigest:null};
|
|
738
|
+
// Rules answers are authored after reading the review findings. V2 can run
|
|
739
|
+
// that review automatically, but it must stop before asking for a new draft.
|
|
740
|
+
const holdBootstrapRevision=Boolean(rules&&reachable.reviewAfterDevelop);
|
|
741
|
+
if(holdBootstrapRevision)reachable={...reachable,attempts:reachable.attempts.filter(attempt=>attempt<2),reviewAfterDevelop:false,reviewFirst:false};
|
|
672
742
|
const bootstrapAnswers=rules
|
|
673
|
-
?readBootstrapRulesAnswers({answers,operation,definition,plan,permissions,bootstrap,reachable}):null;
|
|
674
|
-
const developAnswers=new Map(),deliveries=[];
|
|
743
|
+
?readBootstrapRulesAnswers({answers,operation,definition,plan,permissions,bootstrap,reachable,controlPolicy:control?.policy??null}):null;
|
|
744
|
+
const developAnswers=new Map(),deliveries=[];let holdRevision=holdBootstrapRevision;
|
|
675
745
|
if(asks.includes('develop'))for(const attempt of reachable.attempts){
|
|
676
746
|
const file=answerPath(answers??'',developFilename(answers??'',attempt));
|
|
677
747
|
if(!answers||!fs.existsSync(file)){
|
|
678
748
|
const reviewFile=`.reviews/${definition.feature.replace(/^\d+\./,'')}-${definition.identity.taskId}-r1.md`;
|
|
679
|
-
|
|
680
|
-
|
|
749
|
+
// Resuming a retryable block: let the redo and its review run, then stop
|
|
750
|
+
// at changes_requested (revision_answer_required) instead of asking a
|
|
751
|
+
// round-2 develop nobody can answer.
|
|
752
|
+
if(reachable.reviewAfterDevelop&&reachable.holdable&&attempt===2){
|
|
753
|
+
holdRevision=true;
|
|
754
|
+
stderr(`没有 ${path.basename(file)}:本次 advance 的首轮审查若要求修改,任务会停在 changes_requested(revision_answer_required),不会发起第 2 轮开发;读取 ${reviewFile} 的 findings,写 answers/develop-a2.json 后再 advance`);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
681
757
|
if(reachable.reviewFirst)stop(2,`缺少 ${path.basename(file)};请先以 decision 和当前 packageDigest ${reachable.packageDigest} 单独运行审查,读取 .reviews/${definition.feature.replace(/^\d+\./,'')}-${definition.identity.taskId}-r${attempt-1}.md 中的 findings,写 answers/develop-a${attempt}.json 后再 advance`);
|
|
682
758
|
stop(2,`步骤 ${operation} 会反问 develop,但答案文件不存在: ${file}`);
|
|
683
759
|
}
|
|
@@ -694,13 +770,15 @@ function load(){
|
|
|
694
770
|
exact:!permissions.includes('--bootstrap-config')})});
|
|
695
771
|
const unique=[...new Set(asks.filter(kind=>FILES[kind]&&kind!=='develop'))];
|
|
696
772
|
const answer=preflightAnswers(unique,kind=>{
|
|
697
|
-
|
|
773
|
+
// A rediagnosis is a new conclusion; never reuse the first diagnosis file (same as cm-fix-drive).
|
|
774
|
+
const file=answerPath(answers??'',operation==='fix_action'&&plan.fixOperation==='rediagnose'&&kind==='fix_diagnose'
|
|
775
|
+
?'diagnosis-rediagnosis.json':FILES[kind]);
|
|
698
776
|
if(!answers||!fs.existsSync(file))stop(2,`步骤 ${operation} 会反问 ${kind},但答案文件不存在: ${file}`);
|
|
699
777
|
const value=readJson(file,kind);validateCmAiAnswer(kind,value,answers);return value;
|
|
700
778
|
});
|
|
701
779
|
if(answer.documentation_sync)for(const target of Object.keys(answer.documentation_sync.edits))
|
|
702
780
|
if(!workflow.documentationPaths.includes(target))stop(2,`documentation-sync.json.edits 越过文档 scope: ${target}`);
|
|
703
|
-
return {...loaded,definition,identity,permissions,config,answers,answer,developAnswers,live,executionPolicy,
|
|
781
|
+
return {...loaded,control,definition,identity,permissions,config,answers,answer,developAnswers,live,executionPolicy,holdRevision,
|
|
704
782
|
bootstrapRules:bootstrapAnswers&&createBootstrapRulesResponder({definition,plan,bootstrap,answers:bootstrapAnswers,
|
|
705
783
|
// Same execution as the task checks: the host's specs sandbox in protected mode, else the driver's own.
|
|
706
784
|
specsRoot:protectedMode?definition.specsDir:null,watch:[config,...permissionFiles]})};
|
|
@@ -775,19 +853,25 @@ async function answerFor(row,answer,paths,control){
|
|
|
775
853
|
return value??null;
|
|
776
854
|
}
|
|
777
855
|
export function buildCmAiDriveRequest(operation,plan,definition,identity=definition.identity){
|
|
778
|
-
|
|
856
|
+
// Recovery is bound to the caller's earlier preview, including its attempt.
|
|
857
|
+
// The host compares that whole target before dispatching anything.
|
|
858
|
+
if(Object.hasOwn(plan,'controlConfig')&&isControlRecovery(operation,plan))identity=plan.expectedControl?.identity??identity;
|
|
859
|
+
return {version:Object.hasOwn(plan,'controlConfig')?2:1,identity,
|
|
860
|
+
...(Object.hasOwn(plan,'controlConfig')&&isControlRecovery(operation,plan)?{expectedControl:plan.expectedControl}:{}),
|
|
779
861
|
...(operation==='reconcile_review'?{invocationId:plan.invocationId}:{}),
|
|
780
|
-
...(['abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation)?{reason:plan.reason}:{}),
|
|
862
|
+
...(['abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation)?{reason:plan.reason}:{}),
|
|
781
863
|
...(PACKAGE_OPERATIONS.has(operation)?{packageDigest:plan.packageDigest}:{}),
|
|
782
864
|
...(TEST_RUN_OPERATIONS.has(operation)?{testRunId:plan.testRunId}:{}),
|
|
783
865
|
...(['fix_status','fix_advance','fix_action','fix_run'].includes(operation)?{
|
|
784
866
|
packageDigest:plan.packageDigest,testRunId:plan.testRunId,
|
|
785
867
|
...(operation==='fix_action'?{fixOperation:plan.fixOperation,...(plan.fixOperation==='reconcile_review'?{invocationId:plan.invocationId}:{}),
|
|
786
|
-
...(
|
|
868
|
+
...(FIX_REASONED.includes(plan.fixOperation)?{reason:plan.reason}:{}),
|
|
869
|
+
...(plan.fixOperation==='recover_final_review'?{invocationId:plan.invocationId,reviewPackageDigest:plan.reviewPackageDigest,
|
|
870
|
+
previousInvocationStopped:plan.previousInvocationStopped}:{})}: {})}: {})};
|
|
787
871
|
}
|
|
788
|
-
export function buildCmAiDriveHostArgs(plan,permissions,config){
|
|
872
|
+
export function buildCmAiDriveHostArgs(plan,permissions,config,controlConfig=null){
|
|
789
873
|
return ['serve','--config',config,'--mode',plan.mode,'--host-context',plan.hostContext,
|
|
790
|
-
'--allow-development',
|
|
874
|
+
...(Object.hasOwn(plan,'controlConfig')?['--control-config',controlConfig??plan.controlConfig]:['--allow-development']),
|
|
791
875
|
...(plan.verificationPrecheck===true&&!permissions.includes('--verification-precheck')?['--verification-precheck']:[]),
|
|
792
876
|
...(plan.originalHostContext?['--original-host-context',plan.originalHostContext]:[]),
|
|
793
877
|
'--runtime',plan.runtime??'codex',...permissions.filter(flag=>flag!=='--allow-development')];
|
|
@@ -807,7 +891,7 @@ async function main(){
|
|
|
807
891
|
// Rules init_verify commands really run once the host has accepted the launch
|
|
808
892
|
// (host_ready) and before the operation is sent: a failure never becomes an
|
|
809
893
|
// unknown develop effect, and the host's own launch validation came first.
|
|
810
|
-
driveHost({host:HOST,args:buildCmAiDriveHostArgs(plan,permissions,config),cwd:definition.codeProject,operation,request,
|
|
894
|
+
driveHost({host:HOST,args:[...buildCmAiDriveHostArgs(plan,permissions,config,loaded.control?.file),...(loaded.holdRevision?['--hold-revision']:[])],cwd:definition.codeProject,operation,request,
|
|
811
895
|
answers:answer,paths:{answers:loaded.answers},answerFor,
|
|
812
896
|
...(loaded.bootstrapRules?{beforeRequest:()=>loaded.bootstrapRules.prepare(plan.mode)}:{})});
|
|
813
897
|
}
|