@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
|
@@ -9,9 +9,12 @@ export function recordEffectAbandonment({specsDir,codeProject,feature,identity,r
|
|
|
9
9
|
const data={node:p.effectKind==='complete'?'N5':p.effectKind==='review'?'N4':'N3',feature,task:identity.taskId,
|
|
10
10
|
effect_id:p.effectId,effect_kind:p.effectKind,intent_digest:p.intentDigest,
|
|
11
11
|
record_digest:record.digest,reason:p.reason};
|
|
12
|
-
|
|
12
|
+
// effect-interrupted (V8) retires the step and the run continues from its block.
|
|
13
|
+
const interrupted=p.type==='effect-interrupted';
|
|
14
|
+
const args=[writer,'--workflow','cm-ai','--event',interrupted?'effect_interrupted':'effect_abandoned','--runtime',runtime,
|
|
13
15
|
'--project-root',codeProject,'--specs-dir',specsDir,'--run-id',identity.runId,
|
|
14
|
-
'--at',p.at,'--detail','
|
|
16
|
+
'--at',p.at,'--detail',interrupted?'中断且无检查点的任务 effect 已登记,运行从这一步的可重试阻断继续'
|
|
17
|
+
:'显式放弃中断且无检查点的任务 effect','--data-json',JSON.stringify(data)];
|
|
15
18
|
const result=spawnSync('python3',args,{timeout:10000,maxBuffer:1024*1024,
|
|
16
19
|
...(logHome?{env:{...process.env,CM_WORKFLOW_LOG_HOME:logHome}}:{})});
|
|
17
20
|
need(!result.error&&result.status===0,'effect_abandon_log_failed');
|
|
@@ -51,7 +51,12 @@ const failureCodes=new Set(['invalid_input','limit_exceeded','call_timeout','can
|
|
|
51
51
|
'unregistered_receipt','invalid_receipt','receipt_identity','receipt_package_mismatch','review_not_approved',
|
|
52
52
|
'checks_not_passed','async_commit','commit_unknown','unsupported_path','unsupported_file','read_failed',
|
|
53
53
|
'snapshot_changed','spec_drift','invalid_baseline','out_of_scope','empty_changes','invalid_package','package_mismatch',
|
|
54
|
-
'handoff_exists','verification_precheck_failed','completion_checks_changed','bootstrap_review_mismatch'
|
|
54
|
+
'handoff_exists','verification_precheck_failed','completion_checks_changed','bootstrap_review_mismatch',
|
|
55
|
+
// A lost or malformed session answer keeps its own code instead of collapsing
|
|
56
|
+
// into execution_error, so the answer-gap projections can tell it apart.
|
|
57
|
+
'host_disconnected','host_request_timeout','verification_precheck_invalid',
|
|
58
|
+
// Raised only by the host's own role routing, before any session request.
|
|
59
|
+
'role_log_failed','invalid_workflow_config']);
|
|
55
60
|
// An unlisted code becomes execution_error, which on its own is not actionable.
|
|
56
61
|
// The EEXIST that blocked every retry of a task in #81 stayed invisible in the
|
|
57
62
|
// log, the state and stderr until a temporary print was added by hand. Emit one
|
|
@@ -30,6 +30,22 @@ function fixCallsResolved(records,configuration){
|
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
const codeBinding=codeProject=>path.join(codeProject,'.cm-external-models-v1.json');
|
|
33
|
+
// The two refusals below are shared with callers that must tell, read-only, whether
|
|
34
|
+
// a new run on the same code root would pass this guard (cm-ai-batch-run.mjs hints).
|
|
35
|
+
// A strict (external-model or execution-policy) prior run: unknown external work
|
|
36
|
+
// belongs to the code root, even across tasks/features.
|
|
37
|
+
export function strictPriorAttemptResolved(config,history,records){
|
|
38
|
+
return !(config.externalModels||config.executionPolicy)||!history.pending&&history.state.state!=='unknown'
|
|
39
|
+
&&history.state.reviewInvocation?.result?.reconciliationRequired!==true
|
|
40
|
+
&&!history.state.calls.some(call=>call.requestedModel!=='current-session'
|
|
41
|
+
&&!['succeeded','not_dispatched'].includes(call.terminal)
|
|
42
|
+
&&!records.some(row=>row.payload.type==='review-invocation-reconciled'&&row.payload.invocationId===call.invocationId));
|
|
43
|
+
}
|
|
44
|
+
// A prior run of the same task on the same code root.
|
|
45
|
+
export function sameTaskPriorAttemptResolved(history){
|
|
46
|
+
return !history.pending&&!['unknown','ready','awaiting_review','pending_review','changes_requested','approved'].includes(history.state.state)
|
|
47
|
+
&&history.state.reviewInvocation?.result?.reconciliationRequired!==true;
|
|
48
|
+
}
|
|
33
49
|
export const externalRunGuardExists=(specsDir,codeProject)=>fs.existsSync(path.join(specsDir,'.cm-external-models-v1'))||fs.existsSync(codeBinding(codeProject));
|
|
34
50
|
export function acquireExternalRunGuard(definition,{strictOnly=false}={}){
|
|
35
51
|
const {specsDir,codeProject,identity,feature}=definition;
|
|
@@ -79,16 +95,11 @@ export function acquireExternalRunGuard(definition,{strictOnly=false}={}){
|
|
|
79
95
|
if(config.root!==codeProject)continue;
|
|
80
96
|
const history=readRunnerHistory(snapshot.records,config,init.version);
|
|
81
97
|
// Unknown external work belongs to the code root, even across tasks/features.
|
|
82
|
-
|
|
83
|
-
&&history.state.reviewInvocation?.result?.reconciliationRequired!==true
|
|
84
|
-
&&!history.state.calls.some(call=>call.requestedModel!=='current-session'
|
|
85
|
-
&&!['succeeded','not_dispatched'].includes(call.terminal)
|
|
86
|
-
&&!snapshot.records.some(row=>row.payload.type==='review-invocation-reconciled'&&row.payload.invocationId===call.invocationId)),'external_prior_attempt_unresolved');
|
|
98
|
+
need(strictPriorAttemptResolved(config,history,snapshot.records),'external_prior_attempt_unresolved');
|
|
87
99
|
need(!oldWriterOpen(execution,entry.name),'external_prior_writer_active');
|
|
88
100
|
if(config.identity.taskId!==identity.taskId
|
|
89
101
|
||config.completion?.owner?.tasksPath!==path.join(specsDir,feature,'tasks.md'))continue;
|
|
90
|
-
need(
|
|
91
|
-
&&history.state.reviewInvocation?.result?.reconciliationRequired!==true,'external_prior_attempt_unresolved');
|
|
102
|
+
need(sameTaskPriorAttemptResolved(history),'external_prior_attempt_unresolved');
|
|
92
103
|
need(!oldWriterOpen(execution,entry.name),'external_prior_writer_active');
|
|
93
104
|
}
|
|
94
105
|
return lease;
|
|
@@ -12,10 +12,10 @@ export function checkCompletion({receipt,registered,execution,reviewPackage,iden
|
|
|
12
12
|
for(const field of ['packageDigest','baseIdentity','artifactDigest','requirementsDigest','checksDigest'])
|
|
13
13
|
need(r[field]===reviewPackage[field],'receipt_package_mismatch');
|
|
14
14
|
const executionKeys=['invocationId','contextId','provider','requestedModel','effectiveModel','channel','started','terminal','requestDigest','resultDigest'];
|
|
15
|
-
const
|
|
16
|
-
shape(r.execution,[...executionKeys,...(
|
|
17
|
-
need(['fixture','host-authorized'].includes(r.execution.channel),'execution_mismatch');
|
|
18
|
-
if(
|
|
15
|
+
const observedReview=['host-review','host-authorized'].includes(r.execution?.channel);
|
|
16
|
+
shape(r.execution,[...executionKeys,...(observedReview?['providerThreadId']:[])]);
|
|
17
|
+
need(['fixture','host-review','host-authorized'].includes(r.execution.channel),'execution_mismatch');
|
|
18
|
+
if(observedReview)id(r.execution.providerThreadId);
|
|
19
19
|
need(r.id===r.execution.invocationId && r.execution.started===true && r.execution.terminal==='succeeded'
|
|
20
20
|
&& digest(r.execution)===digest(json(execution)),'execution_mismatch');
|
|
21
21
|
const result=reviewResult(r.result,reviewPackage);
|
|
@@ -14,12 +14,13 @@ export function reportHostCheckProgress(event){
|
|
|
14
14
|
`检查结束 ${event.id}: ${event.outcome} (exit ${event.exitCode??'unavailable'})`;
|
|
15
15
|
try{process.stderr.write(`[check] ${message}\n`);}catch{/* display is not a check verdict */}
|
|
16
16
|
}
|
|
17
|
-
export function createHostCheck({cwd,commands,timeoutMs=60000,specsRoot=null,outputIncludes=null,onOutput=null,onProgress=null,reuseDeclared=false}){
|
|
17
|
+
export function createHostCheck({cwd,commands,timeoutMs=60000,specsRoot=null,outputIncludes=null,onOutput=null,onProgress=null,reuseDeclared=false,onSpawn=null}){
|
|
18
18
|
need(typeof reuseDeclared==='boolean','invalid_check_config');
|
|
19
19
|
need(path.isAbsolute(cwd)&&fs.realpathSync(cwd)===cwd&&fs.statSync(cwd).isDirectory());
|
|
20
20
|
validCallTimeout(timeoutMs);
|
|
21
21
|
need(onOutput===null||typeof onOutput==='function');
|
|
22
22
|
need(onProgress===null||typeof onProgress==='function');
|
|
23
|
+
need(onSpawn===null||typeof onSpawn==='function');
|
|
23
24
|
const notify=event=>{
|
|
24
25
|
try{
|
|
25
26
|
const returned=onProgress?.(Object.freeze(event));
|
|
@@ -63,6 +64,8 @@ export function createHostCheck({cwd,commands,timeoutMs=60000,specsRoot=null,out
|
|
|
63
64
|
shell:false,detached:true,stdio:['ignore','pipe','pipe']});
|
|
64
65
|
}
|
|
65
66
|
catch{resolve({outcome:'unavailable',exitCode:null,evidence:'host check: spawn_failed'});return;}
|
|
67
|
+
// Observers cannot change results or prevent cleanup.
|
|
68
|
+
if(onSpawn&&Number.isInteger(child.pid)&&child.pid>0)try{onSpawn(Object.freeze({id:item.id,pid:child.pid}));}catch{}
|
|
66
69
|
let failure=null,cleanup,bytes=0;
|
|
67
70
|
const counts=new Map();
|
|
68
71
|
const collect=line=>{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {createNativeUsageLog} from './native-usage-log.mjs';
|
|
2
2
|
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
3
|
+
import {readControlPolicy} from './control-policy.mjs';
|
|
3
4
|
import {selectExternalModels} from './external-models.mjs';
|
|
4
5
|
// Fixed current-conversation factory, separate from CLI top-level execution.
|
|
5
6
|
import fs from 'node:fs';
|
|
@@ -17,7 +18,6 @@ import {createCodexReviewRun} from './codex-review-adapter.mjs';
|
|
|
17
18
|
import {createClaudeReviewRun} from './claude-review-adapter.mjs';
|
|
18
19
|
import {claudeWorker,claudePreflightMatches} from './worker-claude.mjs';
|
|
19
20
|
import {codexWorker,preflightMatches} from './worker-codex.mjs';
|
|
20
|
-
import {createHostReviewAuthority} from './host-review-authority.mjs';
|
|
21
21
|
import {createHostWorkflowCapabilities} from './host-workflow-capabilities.mjs';
|
|
22
22
|
import {resolveHostRole} from './host-role-routing.mjs';
|
|
23
23
|
import {checklistGaps} from './checklist-coverage.mjs';
|
|
@@ -105,13 +105,21 @@ export function resolveReviewTimeout(review,protection){
|
|
|
105
105
|
// after its own deadline; the margin leaves room for that and for close.
|
|
106
106
|
export const REVIEW_BOUND_MARGIN_MS=60000;
|
|
107
107
|
export const reviewRaceTimeout=(outerTimeoutMs,reviewTimeoutMs)=>Math.max(outerTimeoutMs,reviewTimeoutMs+REVIEW_BOUND_MARGIN_MS);
|
|
108
|
-
export function createConversationExecution(definition,hostContextId,bridge,review=null,
|
|
108
|
+
export function createConversationExecution(definition,hostContextId,bridge,review=null,reservedReviewAttempt=null,workflow=null,allowQa=false,runtime='codex',options={}){
|
|
109
109
|
definition=json(definition);workflow=workflow===null?null:json(workflow);options=json(options);
|
|
110
|
-
shape(options,[...['originalHostContextId','protection','batchWorkflowsDigest','qaLogHome','bootstrap','providerDevelopment','externalModels','reviewerRuntime','reviewRuntime','parallelMember','verificationPrecheck','executionPolicy'].filter(key=>Object.hasOwn(options,key))]);
|
|
110
|
+
shape(options,[...['originalHostContextId','protection','batchWorkflowsDigest','qaLogHome','bootstrap','providerDevelopment','externalModels','reviewerRuntime','reviewRuntime','parallelMember','verificationPrecheck','executionPolicy','controlPolicy'].filter(key=>Object.hasOwn(options,key))]);
|
|
111
|
+
const controlPolicy=options.controlPolicy?readControlPolicy(options.controlPolicy):null;
|
|
111
112
|
need(!Object.hasOwn(options,'verificationPrecheck')||typeof options.verificationPrecheck==='boolean','invalid_input');
|
|
112
113
|
const executionPolicy=options.executionPolicy?readExecutionPolicy(options.executionPolicy):null;
|
|
113
114
|
const parallelMember=options.parallelMember??false;need(typeof parallelMember==='boolean','invalid_input');
|
|
114
115
|
const provider=options.providerDevelopment??null;
|
|
116
|
+
if(controlPolicy){
|
|
117
|
+
need((controlPolicy.development==='provider')===Boolean(provider),'invalid_arguments');
|
|
118
|
+
need(controlPolicy.bootstrap!=='write'||Boolean(options.bootstrap),'invalid_arguments');
|
|
119
|
+
need(controlPolicy.qa!=='run'||workflow?.qa!=null,'invalid_arguments');
|
|
120
|
+
need(!options.bootstrap||controlPolicy.bootstrap==='write','invalid_arguments');
|
|
121
|
+
need(allowQa===(controlPolicy.qa==='run'),'invalid_input');
|
|
122
|
+
}
|
|
115
123
|
if(provider){
|
|
116
124
|
shape(provider,['model','attempt','coderRuntime','reviewerRuntime',...(Object.hasOwn(provider,'effort')?['effort']:[])]);
|
|
117
125
|
need(options.protection&&review!==null,'protected_configuration_required');
|
|
@@ -148,9 +156,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
148
156
|
const check=projectExecution?.check??null;
|
|
149
157
|
const documentationPaths=workflow?validateDocumentationPaths(workflow.documentationPaths,definition.scope):[];
|
|
150
158
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
151
|
-
|
|
152
|
-
need(allowedAttempts.length<=2&&new Set(allowedAttempts).size===allowedAttempts.length
|
|
153
|
-
&&allowedAttempts.every(value=>value===1||value===2),'invalid_review_attempt');
|
|
159
|
+
need(reservedReviewAttempt===null,'invalid_input');
|
|
154
160
|
const author='cm-conversation-author',reviewContexts=['cm-conversation-review-1','cm-conversation-review-2'];
|
|
155
161
|
const durableHostContextId=options.originalHostContextId??hostContextId;
|
|
156
162
|
for(const context of [hostContextId,durableHostContextId]){
|
|
@@ -160,6 +166,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
160
166
|
// slice too. A transport is not physical protection of nested specs.
|
|
161
167
|
need(protection||!definition.specsDir.startsWith(definition.codeProject+path.sep),'nested_specs_protection_required');
|
|
162
168
|
const configuration={kind:'cm-current-conversation-v1',...(parallelMember?{parallelMember}:{}),definitionDigest:digest(definition),hostContextId:durableHostContextId,
|
|
169
|
+
...(controlPolicy?{controlPolicy}:{}),
|
|
163
170
|
...(runtime==='claude'?{runtime}:{}),
|
|
164
171
|
...(options.reviewRuntime===undefined?{}:{reviewRuntime:options.reviewRuntime}),
|
|
165
172
|
...(executionPolicy?{executionPolicy}:{}),
|
|
@@ -174,21 +181,23 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
174
181
|
disabledSkills:review?.disabledSkills??[],
|
|
175
182
|
...resolveReviewTimeout(review,protection),
|
|
176
183
|
promptTransport:'stdin',schemaPath:fileURLToPath(new URL('./review-result.schema.json',import.meta.url))};
|
|
177
|
-
|
|
178
|
-
if(allowedAttempts.length||provider)need((reviewerRuntime==='codex'?preflightMatches:claudePreflightMatches)(reviewOptions.preflight,reviewOptions),'tool_preflight_missing');
|
|
184
|
+
if(review!==null||provider)need((reviewerRuntime==='codex'?preflightMatches:claudePreflightMatches)(reviewOptions.preflight,reviewOptions),'tool_preflight_missing');
|
|
179
185
|
need(reviewerRuntime!=='claude'||!review||review.disabledSkills.length===0,'invalid_review_config');
|
|
180
186
|
// Preserve P4a's unauthorizable placeholder bytes for existing unconfigured runs.
|
|
181
187
|
const reviewProvider=review?reviewerRuntime:'codex', adapterId=`${reviewProvider}-review-adapter`;
|
|
182
|
-
const authority=review?createHostReviewAuthority({hostContextId,reviewerId:'reviewer',adapterId,
|
|
183
|
-
decide:async binding=>allowedAttempts.includes(binding.identity.attempt)?{status:'approved'}:null}):null;
|
|
184
188
|
// Reread role declarations at each boundary; never switch a bound invocation.
|
|
185
|
-
|
|
189
|
+
// onWorker (provider development, task-runner.mjs) journals the worker's
|
|
190
|
+
// identity right before and right after the spawn; a journal failure kills
|
|
191
|
+
// the new process group like a refused role route does.
|
|
192
|
+
const dispatchSpawn=(role,identity,signal,onWorker=null)=>{
|
|
186
193
|
const configuration=loadConfig({projectRoot:definition.codeProject});
|
|
187
194
|
need(digest(resolveProtectedRuntimes(configuration,runtime))===digest({coderRuntime,reviewerRuntime}),'runtime_selection_mismatch');
|
|
188
195
|
return (cli,args,options)=>{
|
|
196
|
+
onWorker?.({phase:'spawning'});
|
|
189
197
|
const child=spawn(cli,args,options);
|
|
190
198
|
if(Number.isInteger(child.pid)){
|
|
191
|
-
try{
|
|
199
|
+
try{onWorker?.({phase:'started',pid:child.pid});
|
|
200
|
+
resolveHostRole({definition,identity,role,signal,runtime,configuration,
|
|
192
201
|
dispatchedRuntime:role==='coder'?coderRuntime:reviewerRuntime});}
|
|
193
202
|
catch(error){child.on('error',()=>{});child.stdin?.on('error',()=>{});
|
|
194
203
|
try{options.detached?process.kill(-child.pid,'SIGKILL'):child.kill('SIGKILL');}catch{}throw error;}
|
|
@@ -227,17 +236,17 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
227
236
|
const outerTimeoutMs=provider?protection.timeoutMs:1800000;
|
|
228
237
|
const progress=(request,control,stage,run,selectedRuntime=runtime)=>withHostProgress({definition,
|
|
229
238
|
identity:request.identity,runtime:selectedRuntime,stage,signal:control.signal},run);
|
|
230
|
-
const execution={configuration,timeoutMs:outerTimeoutMs,excludedContexts:[durableHostContextId],
|
|
239
|
+
const execution={configuration,timeoutMs:outerTimeoutMs,excludedContexts:[durableHostContextId],applicableAgentFiles:[],
|
|
231
240
|
...(verificationGate?{verificationGate:(request,control)=>progress(request,control,'verifying',()=>verificationGate(request,control))}:{}),
|
|
232
241
|
...(bootstrap?{bootstrap}:{}),
|
|
233
|
-
...(provider?{developmentAttempt:provider.attempt}:{}),
|
|
234
|
-
...(workflow?createHostWorkflowCapabilities({definition,configuration:workflow,bridge,allowQa,runtime,protectedExecution:protection!==null,bootstrap,parallelMember}):{}),
|
|
242
|
+
...(provider&&!controlPolicy?{developmentAttempt:provider.attempt}:{}),
|
|
243
|
+
...(workflow?createHostWorkflowCapabilities({definition,configuration:workflow,bridge,allowQa,runtime,protectedExecution:protection!==null,bootstrap,parallelMember,controlPolicy}):{}),
|
|
235
244
|
...(options.qaLogHome?{qaLogHome:options.qaLogHome}:{}),
|
|
236
|
-
...(authority?{hostDecisionProvider:authority.hostDecisionProvider}:{}),
|
|
237
245
|
developer:{provider:coderRuntime,requestedModel:provider?.model??'current-session',contextId:author,run:async(request,control)=>{
|
|
238
246
|
const bound=(coderRuntime==='codex'?readCodexDeveloperRequest:readClaudeDeveloperRequest)(request);
|
|
239
247
|
if(provider){
|
|
240
|
-
need(bound.identity.attempt
|
|
248
|
+
need((controlPolicy?[1,2].includes(bound.identity.attempt):bound.identity.attempt===provider.attempt)
|
|
249
|
+
&&digest({...bound.identity,attempt:1})===digest(definition.identity),'invalid_development_attempt');
|
|
241
250
|
need(!used.has(bound.invocationId),'duplicate_dispatch');used.add(bound.invocationId);
|
|
242
251
|
}
|
|
243
252
|
const route=provider?null:resolveHostRole({definition,identity:bound.identity,role:'coder',signal:control.signal,runtime});
|
|
@@ -246,7 +255,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
246
255
|
...(developerLog?{onUsageClaim:()=>developerLog.claimed(),onUsage:value=>{developerUsage=value;}}:{}),
|
|
247
256
|
cwd:definition.codeProject,model:provider.model,...(externalModels?{effort:provider.effort}:{}),timeoutMs:protection.timeoutMs,
|
|
248
257
|
...(coderRuntime==='codex'?{specsRoot:definition.specsDir}:{}),
|
|
249
|
-
spawnProcess:dispatchSpawn('coder',bound.identity,control.signal)}):null;
|
|
258
|
+
spawnProcess:dispatchSpawn('coder',bound.identity,control.signal,typeof control.onWorker==='function'?control.onWorker:null)}):null;
|
|
250
259
|
const worker=async({prompt})=>{
|
|
251
260
|
if(provider&&coderRuntime==='codex'){
|
|
252
261
|
if(documentationPaths.length)prompt='Synchronize approved documentation inside this invocation: '+JSON.stringify(documentationPaths)+'\n'+prompt;
|
|
@@ -297,8 +306,10 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
297
306
|
if(protection&&response.value.outcome!=='blocked'){
|
|
298
307
|
if(bound.payload.specification)verifySpecificationMaterial({specificationRoot:definition.specsDir,
|
|
299
308
|
specification:bound.payload.specification,identity:bound.identity});
|
|
309
|
+
// The applying sandbox subprocess is journaled like the worker (V9).
|
|
300
310
|
try{await projectExecution.commit({scope:bound.payload.scope,
|
|
301
|
-
edits,expected,identity:bound.identity,signal:control.signal
|
|
311
|
+
edits,expected,identity:bound.identity,signal:control.signal,
|
|
312
|
+
...(typeof control.onWorker==='function'?{onApply:event=>control.onWorker(event)}:{})});}
|
|
302
313
|
catch(error){
|
|
303
314
|
// This code is emitted by the pre-write expected-hash check.
|
|
304
315
|
// Sandbox execution/partial-write failures stay ambiguous.
|
|
@@ -307,7 +318,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
307
318
|
}
|
|
308
319
|
}
|
|
309
320
|
// CLI session identity comes from the observed process stream; current
|
|
310
|
-
// conversation responses retain the
|
|
321
|
+
// conversation responses retain the declared host context.
|
|
311
322
|
return {status:response.status,value:response.value,providerThread:provider?response.providerThread:hostContextId};
|
|
312
323
|
}
|
|
313
324
|
if(provider){const {providerThread,...failure}=response;shape(failure,['status','code']);return failure;}
|
|
@@ -322,8 +333,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
322
333
|
return bridge.call('check',{...request,codeProject:definition.codeProject,
|
|
323
334
|
scope:definition.scope,requirements:definition.requirements,route},control.signal);
|
|
324
335
|
}),
|
|
325
|
-
// The
|
|
326
|
-
// Diagnostic preflight alone never grants review dispatch.
|
|
336
|
+
// The process adapter records observed reviewer events. Preflight checks capability.
|
|
327
337
|
reviewers:[{id:'reviewer',adapterId,provider:reviewProvider,requestedModel:reviewOptions.model,
|
|
328
338
|
allowed:true,available:true,contexts:reviewContexts,
|
|
329
339
|
run:(request,control)=>{
|
|
@@ -343,8 +353,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
343
353
|
}}],
|
|
344
354
|
reviewInvocation:{developerThreadId:author,excludedThreadIds:[durableHostContextId],hostContextId,
|
|
345
355
|
// Not journaled (unlike timeoutMs above), so a resumed run may raise it.
|
|
346
|
-
timeoutMs:reviewRaceTimeout(outerTimeoutMs,reviewOptions.timeoutMs),
|
|
347
|
-
authorize:authority?.authorize??(()=>({status:'denied',code:'permission_denied'}))},
|
|
356
|
+
timeoutMs:reviewRaceTimeout(outerTimeoutMs,reviewOptions.timeoutMs)},
|
|
348
357
|
};
|
|
349
358
|
if(definition.codeProjects)execution.applicableAgentFiles=[...new Set([...execution.applicableAgentFiles,
|
|
350
359
|
...codeProjectInstructionPaths(codeProjectPaths(definition.codeProject,definition.codeProjects))
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// checks/Learning/handoff/review. This adapter grants no additional file scope.
|
|
3
3
|
import {isFinalCmAiTask} from './cm-ai-admission.mjs';
|
|
4
4
|
import {captureReviewBaseline} from './review-package.mjs';
|
|
5
|
-
import {digest,json,shape,need,terminalFor} from './effect-contract.mjs';
|
|
5
|
+
import {digest,json,shape,need,terminalFor,boundedReason} from './effect-contract.mjs';
|
|
6
6
|
|
|
7
7
|
export function validateDocumentationPaths(raw,scope){
|
|
8
8
|
const paths=json(raw);
|
|
@@ -16,27 +16,68 @@ export function validateDocumentationPaths(raw,scope){
|
|
|
16
16
|
return paths;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// Q16/Q17: a code-root snapshot split into the documentation paths (each
|
|
20
|
+
// path's sha256, null when absent) and one digest of everything else. The
|
|
21
|
+
// task runner supplies the snapshot (control.documentationSnapshot): its fixed
|
|
22
|
+
// task-snapshot rules (full develop scope, the ignore policy bound at create),
|
|
23
|
+
// so a develop-scope file Git ignores is still part of "everything else". The
|
|
24
|
+
// runner records the split when the sync starts and compares a later one with
|
|
25
|
+
// it before it re-asks only documentation_sync.
|
|
26
|
+
export function splitDocumentationState(files,paths){
|
|
27
|
+
const others=files.filter(file=>!paths.includes(file.path));
|
|
28
|
+
return {files,documents:paths.map(file=>({path:file,
|
|
29
|
+
sha256:files.find(item=>item.path===file)?.sha256??null})),othersDigest:digest(others)};
|
|
30
|
+
}
|
|
31
|
+
// Without a runner snapshot (no journal: nothing is recorded or retried), the
|
|
32
|
+
// adapter keeps its own scope-only capture for the out-of-scope check.
|
|
33
|
+
export function captureDocumentationState({root,specsRoot,identity,paths,requirements,specification=null}){
|
|
34
|
+
const baseline=captureReviewBaseline({root,specsRoot,identity,scope:paths,requirements,
|
|
35
|
+
...(specification?{specification}:{})});
|
|
36
|
+
return splitDocumentationState(baseline.files,paths);
|
|
37
|
+
}
|
|
38
|
+
// Paths outside the documentation paths that differ between two captures.
|
|
39
|
+
export function documentationOutOfScopePaths(before,after,paths){
|
|
40
|
+
const index=files=>new Map(files.filter(file=>!paths.includes(file.path)).map(file=>[file.path,digest(file)]));
|
|
41
|
+
const a=index(before),b=index(after);
|
|
42
|
+
return [...new Set([...a.keys(),...b.keys()])].filter(file=>a.get(file)!==b.get(file)).sort();
|
|
43
|
+
}
|
|
44
|
+
const fail=(code,message=code)=>Object.assign(new Error(message),{code});
|
|
45
|
+
|
|
19
46
|
export function withHostDocumentation({developer,documentationSync,specsDir,codeProject,feature,scope,parallelSelection=null,featureSelection}){
|
|
20
47
|
shape(documentationSync,['paths','run']);need(typeof documentationSync.run==='function');
|
|
21
48
|
const paths=validateDocumentationPaths(documentationSync.paths,scope),run=documentationSync.run;
|
|
22
49
|
need(paths.length>0);
|
|
23
50
|
return {...developer,run:async(request,control)=>{
|
|
24
|
-
|
|
51
|
+
// A documentation-only redo (task-runner: documentation-sync-retry) reuses
|
|
52
|
+
// the developer answer journaled when the failed sync started; the
|
|
53
|
+
// developer is never asked again.
|
|
54
|
+
const redo=control.documentationRedo;
|
|
55
|
+
if(redo!==undefined)shape(redo,['result','effectiveModel']);
|
|
56
|
+
const response=terminalFor(redo!==undefined?{version:1,invocationId:request.invocationId,contextId:request.contextId,
|
|
57
|
+
provider:request.provider,effectiveModel:redo.effectiveModel,status:'succeeded',accepted:true,result:redo.result}
|
|
58
|
+
:await developer.run(request,control),request);
|
|
25
59
|
if(response.status!=='succeeded')return response;
|
|
26
60
|
need(!control.signal.aborted,'cancelled');
|
|
27
|
-
if(!isFinalCmAiTask({specsDir,codeProject,feature,taskId:request.identity.taskId,parallelSelection,featureSelection}))
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
if(!isFinalCmAiTask({specsDir,codeProject,feature,taskId:request.identity.taskId,parallelSelection,featureSelection})){
|
|
62
|
+
need(redo===undefined,'documentation_redo_mismatch');return response;
|
|
63
|
+
}
|
|
64
|
+
const capture=()=>typeof control.documentationSnapshot==='function'?control.documentationSnapshot(paths):captureDocumentationState({root:codeProject,specsRoot:specsDir,identity:request.identity,paths,
|
|
65
|
+
requirements:request.payload.requirements.map(file=>file.path),
|
|
66
|
+
specification:request.payload.specification?{specsRoot:specsDir,feature}:null});
|
|
67
|
+
const before=capture();
|
|
68
|
+
// The runner journals the developer answer and this start before the sync
|
|
69
|
+
// is asked, so a lost sync can be re-asked alone.
|
|
70
|
+
if(typeof control.onDocumentationSync==='function')control.onDocumentationSync({result:response.result,
|
|
71
|
+
effectiveModel:response.effectiveModel,documents:before.documents,othersDigest:before.othersDigest});
|
|
31
72
|
const result=json(await run(json({identity:request.identity,invocationId:request.invocationId,
|
|
32
73
|
specsDir,codeProject,feature,paths}),control.signal));
|
|
33
|
-
need(!control.signal.aborted,'cancelled');
|
|
74
|
+
need(!control.signal.aborted,'cancelled');
|
|
75
|
+
try{shape(result,['status']);need(['completed','blocked'].includes(result.status));}
|
|
76
|
+
catch{throw fail('documentation_sync_answer_invalid');}
|
|
34
77
|
need(result.status==='completed','documentation_sync_blocked');
|
|
35
|
-
const after=
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
need(digest(baseline.files.filter(file=>!paths.includes(file.path)))===
|
|
39
|
-
digest(after.files.filter(file=>!paths.includes(file.path))),'out_of_scope');
|
|
78
|
+
const after=capture();
|
|
79
|
+
if(after.othersDigest!==before.othersDigest)throw fail('out_of_scope',
|
|
80
|
+
boundedReason('out_of_scope: ',documentationOutOfScopePaths(before.files,after.files,paths),''));
|
|
40
81
|
return response;
|
|
41
82
|
}};
|
|
42
83
|
}
|
|
@@ -35,7 +35,7 @@ export function createProjectExecution({definition,protection,executionPolicy=nu
|
|
|
35
35
|
return Object.freeze({
|
|
36
36
|
expected(scope){recheck();return Object.fromEntries(groups(scope).flatMap(group=>
|
|
37
37
|
Object.entries(group.paths.length?captureProtectedEdits(group.codeProject,group.paths):{}).map(([file,hash])=>[full(group,file),hash])));},
|
|
38
|
-
async commit({scope,edits,expected,identity,signal}){
|
|
38
|
+
async commit({scope,edits,expected,identity,signal,onApply=null}){
|
|
39
39
|
recheck();need(Array.isArray(edits),'protected_edit_invalid');
|
|
40
40
|
for(const edit of edits)need(scope.includes(edit.path),'out_of_scope');
|
|
41
41
|
// Precheck all roots before the first root writes; no claim of atomicity.
|
|
@@ -47,7 +47,7 @@ export function createProjectExecution({definition,protection,executionPolicy=nu
|
|
|
47
47
|
.map(edit=>({...edit,path:group.prefix?edit.path.slice(group.prefix.length+1):edit.path}));
|
|
48
48
|
if(!local.length)continue;
|
|
49
49
|
await commitProtectedEdits({cwd:group.codeProject,specsRoot:data.specsDir,scope:group.paths,edits:local,
|
|
50
|
-
expected:Object.fromEntries(group.paths.map(file=>[file,expected[full(group,file)]])),identity,signal,timeoutMs:config.timeoutMs});
|
|
50
|
+
expected:Object.fromEntries(group.paths.map(file=>[file,expected[full(group,file)]])),identity,signal,timeoutMs:config.timeoutMs,onApply});
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
async check(request,control){
|
|
@@ -15,6 +15,24 @@ import {captureReviewBaseline} from './review-package.mjs';
|
|
|
15
15
|
import {writeCmAiQaStatus} from './cm-ai-run-finalizer.mjs';
|
|
16
16
|
import {digest,freeze,hex,id,json,need,shape,text,validCallTimeout,validIdentity} from './effect-contract.mjs';
|
|
17
17
|
import {isQaEnvironmentCarrier,QA_ENVIRONMENT_SCOPES} from './qa-environment.mjs';
|
|
18
|
+
export const QA_DEVICE_UNVERIFIED_REASON='qa_device_unverified: 浏览器用例的宿主请求超时没有拿到应答,会话可能仍在操作设备(浏览器、模拟器或真机),'
|
|
19
|
+
+'宿主无法核实设备已释放,本次 QA 停在这里,不再派发后面的浏览器用例。先确认该会话已停止、设备已空闲,'
|
|
20
|
+
+'再用 --rerun-unknown-qa 重跑本轮(因宿主原因替代的轮次不占三轮预算)。';
|
|
21
|
+
import {readProcessStartTime} from './worker-process-identity.mjs';
|
|
22
|
+
|
|
23
|
+
// Q12: the whole-round deadline scales with the plan: every command may use the
|
|
24
|
+
// command timeout, every logic case one request window and every browser case
|
|
25
|
+
// two (its one evidence correction), plus a minute of margin. Never below the
|
|
26
|
+
// historical 30 minutes and never above a day. Not part of any fingerprint.
|
|
27
|
+
export function qaRoundDeadlineMs({timeoutMs,requestTimeoutMs=null,configuration=null}){
|
|
28
|
+
const plan=configuration?.plan;
|
|
29
|
+
if(!Number.isSafeInteger(timeoutMs)||timeoutMs<=0)return 1800000;
|
|
30
|
+
if(!plan||!Array.isArray(plan.cases)||!Array.isArray(plan.commands)||!Array.isArray(plan.modes))return timeoutMs;
|
|
31
|
+
const request=Number.isSafeInteger(requestTimeoutMs)&&requestTimeoutMs>0?requestTimeoutMs:timeoutMs;
|
|
32
|
+
const commands=plan.modes.includes('commands')?plan.commands.length:0;
|
|
33
|
+
const logic=plan.cases.filter(item=>item.kind==='logic').length,browser=plan.cases.filter(item=>item.kind==='browser').length;
|
|
34
|
+
return Math.min(Math.max(timeoutMs,commands*timeoutMs+logic*request+browser*2*request+60000),24*3600000);
|
|
35
|
+
}
|
|
18
36
|
|
|
19
37
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
20
38
|
const order={ 'cm-default':['logic','commands','browser'],
|
|
@@ -225,18 +243,24 @@ export function createHostQaExecutor(options) {
|
|
|
225
243
|
else if(!plan.commands.length)rows.push({id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No declared project test command',...dropped]});
|
|
226
244
|
for(const command of plan.commands){
|
|
227
245
|
notCancelled();
|
|
246
|
+
// Q13: the command's process group identity, so a cleanup_failed row can
|
|
247
|
+
// later be released once the host proves that group gone.
|
|
248
|
+
let spawned=null;
|
|
228
249
|
const check=createHostCheck({cwd:roots?command.codeProject:configuration.codeProject,commands:[{id:command.id,command:command.command}],
|
|
229
|
-
timeoutMs:configuration.timeoutMs,specsRoot:configuration.specsRoot??null,onProgress:reportHostCheckProgress
|
|
250
|
+
timeoutMs:configuration.timeoutMs,specsRoot:configuration.specsRoot??null,onProgress:reportHostCheckProgress,
|
|
251
|
+
onSpawn:({pid})=>{spawned={pid,process_start_time:readProcessStartTime(pid)};}});
|
|
252
|
+
const failedCleanup=()=>({...resource,...(spawned?spawned:{})});
|
|
230
253
|
const resource={resource_id:`qa-command-${digest({testRunId:binding.testRunId,command:command.id}).slice(0,48)}`,
|
|
231
254
|
resource_kind:'qa_command'};
|
|
232
255
|
logStep(configuration,binding,'resource','acquired',{...resource,cleanup_required:true},'QA command resource acquired');
|
|
233
256
|
let observed;
|
|
234
257
|
try{
|
|
235
258
|
[observed]=await check({identity:binding.identity},{signal});
|
|
236
|
-
|
|
237
|
-
|
|
259
|
+
const failed=observed.evidence==='host check: cleanup_failed';
|
|
260
|
+
logStep(configuration,binding,'resource',failed?'cleanup_failed':'released',
|
|
261
|
+
failed?failedCleanup():resource,'QA command resource finished');
|
|
238
262
|
}catch(error){
|
|
239
|
-
logStep(configuration,binding,'resource','cleanup_failed',
|
|
263
|
+
logStep(configuration,binding,'resource','cleanup_failed',failedCleanup(),'QA command cleanup not confirmed');throw error;
|
|
240
264
|
}
|
|
241
265
|
notCancelled();
|
|
242
266
|
commandResults.set(command.id,observed);
|
|
@@ -312,12 +336,33 @@ export function createHostQaExecutor(options) {
|
|
|
312
336
|
...(answered&&observed.verdict==='BLOCKED'?{hostDeclaredBlocked:true}:{})});
|
|
313
337
|
// The durable log row, appended now through the writer, is the record
|
|
314
338
|
// that the session itself answered BLOCKED; the report only mirrors it.
|
|
339
|
+
// Why the host itself judged this case BLOCKED (Q06/Q11 read it after a
|
|
340
|
+
// call stopped as a whole); never for a session-declared or timed-out case.
|
|
341
|
+
// A missing capability and an unresolved [需确认] come first: neither is a
|
|
342
|
+
// host fault a rerun can fix, whatever the cleanup or evidence looked like.
|
|
343
|
+
const blockedReason=verdict!=='BLOCKED'||answered&&observed.verdict==='BLOCKED'||hostRequestTimeout&&!answered?null
|
|
344
|
+
:browser===null?'unavailable':item.expected.some(value=>value.includes('[需确认]'))?'needs_confirmation'
|
|
345
|
+
:evidenceProblem!==null?'evidence':digest(observed.environment)!==digest(environment)?'environment'
|
|
346
|
+
:observed.cleanup==='failed'||(item.cleanup.length>0&&observed.cleanup!=='completed')?'cleanup':'unclassified';
|
|
315
347
|
logStep(configuration,binding,'test_run',verdict==='BLOCKED'?'case_blocked':'case_complete',
|
|
316
348
|
{case_id:item.id,result:verdict,...(answered&&observed.verdict==='BLOCKED'?{host_declared_blocked:true}:{}),
|
|
349
|
+
...(blockedReason?{blocked_reason:blockedReason}:{}),
|
|
350
|
+
// The session's own verdict before any host downgrade: a FAIL the host
|
|
351
|
+
// turned BLOCKED (evidence, environment, cleanup) is never a host fault.
|
|
352
|
+
...(answered?{answered_verdict:observed.verdict}:{}),
|
|
317
353
|
// Whether this BLOCKED is a host request that timed out without an
|
|
318
354
|
// answer; --rerun-unknown-qa reads it after a whole-call timeout.
|
|
319
355
|
...(verdict==='BLOCKED'?{host_request_timeout:hostRequestTimeout&&!answered}:{})},
|
|
320
356
|
'QA browser case finished');
|
|
357
|
+
// Q07: an unanswered browser request may leave the session driving the
|
|
358
|
+
// device. Never dispatch the next browser case on top of it: stop this
|
|
359
|
+
// call (no complete row), so the round waits for the operator to confirm
|
|
360
|
+
// the device is free and rerun it with --rerun-unknown-qa.
|
|
361
|
+
if(hostRequestTimeout&&!answered){
|
|
362
|
+
const remaining=plan.cases.filter(candidate=>candidate.kind==='browser');
|
|
363
|
+
if(remaining.indexOf(item)<remaining.length-1)throw Object.assign(new Error(QA_DEVICE_UNVERIFIED_REASON),
|
|
364
|
+
{code:'qa_device_unverified',reason:QA_DEVICE_UNVERIFIED_REASON});
|
|
365
|
+
}
|
|
321
366
|
}
|
|
322
367
|
}
|
|
323
368
|
}
|
|
@@ -7,9 +7,27 @@ import {openFixExecution} from '../cm-fix/execution.mjs';
|
|
|
7
7
|
import {createFixHost} from '../cm-fix/host.mjs';
|
|
8
8
|
import {bindQaFixDefinition} from './qa-fix-definition.mjs';
|
|
9
9
|
import {digest,id,json,need,shape,validIdentity,hex} from './effect-contract.mjs';
|
|
10
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
11
|
+
import {readFixControlTarget,CONTROL_FIX_RECOVERY_OPERATIONS} from './control-policy.mjs';
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// Q23: the child's recovery operations, each with the original cm-fix flag the
|
|
14
|
+
// shared dispatcher (cm-fix/host.mjs) checks and the parent flag that grants it.
|
|
15
|
+
// The dispatcher stays the only validator; this table only names the missing flag.
|
|
16
|
+
const QA_FIX_ACTION_FLAGS=Object.freeze({rediagnose:'--allow-rediagnosis',rerun_blocked_step:'--allow-rerun-blocked-step',
|
|
17
|
+
recover_final_review:'--allow-final-review-recovery',abandon_step:'--allow-abandon',abandon_review:'--allow-abandon-review',
|
|
18
|
+
revision_test_check:'--allow-regression'});
|
|
19
|
+
const QA_FIX_REASONED=['abandon_step','abandon_review','rediagnose','rerun_blocked_step'];
|
|
20
|
+
export const QA_FIX_ACTIONS=Object.freeze(['red_test','baseline','author_tests','repair','regression','retrospective','learning_writeback',
|
|
21
|
+
'handoff','final_review_package','final_review','publish_review','check_n5','post_review_regression',
|
|
22
|
+
'publish_dossier','walkthrough','finish','prepare_revision','cause_review_package','cause_review','reconcile_review',
|
|
23
|
+
...Object.keys(QA_FIX_ACTION_FLAGS)]);
|
|
24
|
+
const parentFlag=flag=>flag.replace(/^--allow-/,'--allow-qa-fix-');
|
|
25
|
+
const actionRefusal=(fixOperation,code,reason)=>Object.freeze({outcome:'rejected',code,fixOperation,reason,
|
|
26
|
+
guidance:Object.freeze({summary:'QA 修复子流程的这次操作被拒绝,子运行没有因此改变。',nextStep:reason,
|
|
27
|
+
recoveryOperation:null,prerequisites:Object.freeze([]),authorizationGranted:false})});
|
|
28
|
+
export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHostContextId,fix=null,template=null,allowStart=false,autoFix=false,fixExecution={},fixPermissions=[],fixAuthorities={},externalModels=null,executionPolicy=null,recoveryInvocationId=null,controlPolicy=null}){
|
|
12
29
|
id(hostContextId);id(parentHostContextId);
|
|
30
|
+
if(recoveryInvocationId!==null)id(recoveryInvocationId);
|
|
13
31
|
need((fix===null)!==(template===null),'invalid_fix_config');
|
|
14
32
|
let definition=null;
|
|
15
33
|
let fixedTemplate=template===null?null:json(template,64*1024);
|
|
@@ -59,8 +77,14 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
59
77
|
if(!['fix_status','fix_advance','fix_action','fix_run'].includes(request.operation)){
|
|
60
78
|
busy=true;try{return await current.host.handle(request);}finally{busy=false;}
|
|
61
79
|
}
|
|
80
|
+
// recover_final_review binds the child's final review package; packageDigest
|
|
81
|
+
// here is the parent QA package, so the child digest is reviewPackageDigest.
|
|
62
82
|
const value=json(request);shape(value,['version','requestId','operation','identity','packageDigest','testRunId',
|
|
63
|
-
...(request.operation==='fix_action'?['fixOperation',...(request.fixOperation==='reconcile_review'?['invocationId']:[])
|
|
83
|
+
...(request.operation==='fix_action'?['fixOperation',...(request.fixOperation==='reconcile_review'?['invocationId']:[]),
|
|
84
|
+
...(QA_FIX_REASONED.includes(request.fixOperation)&&Object.hasOwn(request,'reason')?['reason']:[]),
|
|
85
|
+
...(request.fixOperation==='prepare_revision'&&Object.hasOwn(request,'tests')?['tests']:[]),
|
|
86
|
+
...(request.fixOperation==='recover_final_review'?['invocationId','reviewPackageDigest','previousInvocationStopped','reason']:[])]:[]),
|
|
87
|
+
...(controlPolicy&&request.operation==='fix_action'&&CONTROL_FIX_RECOVERY_OPERATIONS.includes(request.fixOperation)?['expectedFixControl']:[])]);
|
|
64
88
|
need(value.version===1,'invalid_input');id(value.requestId);validIdentity(value.identity);hex(value.packageDigest);id(value.testRunId);
|
|
65
89
|
if(fixedTemplate)definition=bindQaFixDefinition({template:fixedTemplate,identity:value.identity,
|
|
66
90
|
packageDigest:value.packageDigest,testRunId:value.testRunId});
|
|
@@ -70,10 +94,13 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
70
94
|
const running=value.operation==='fix_run';
|
|
71
95
|
const advancing=value.operation==='fix_advance'||running;
|
|
72
96
|
const acting=value.operation==='fix_action';
|
|
73
|
-
if(acting)need(
|
|
74
|
-
'handoff','final_review_package','final_review','publish_review','check_n5','post_review_regression',
|
|
75
|
-
'publish_dossier','walkthrough','finish','prepare_revision','cause_review_package','cause_review','reconcile_review','abandon_step','abandon_review'].includes(value.fixOperation),'fix_operation_unavailable');
|
|
97
|
+
if(acting)need(QA_FIX_ACTIONS.includes(value.fixOperation),'fix_operation_unavailable');
|
|
76
98
|
need(!(advancing||acting)||allowStart,'qa_fix_start_authorization_required');
|
|
99
|
+
// Refuse a recovery action whose flag this launch lacks before the parent is
|
|
100
|
+
// closed, naming the parent flag; the cm-fix dispatcher still re-checks it.
|
|
101
|
+
const actionFlag=acting?QA_FIX_ACTION_FLAGS[value.fixOperation]:undefined;
|
|
102
|
+
if(actionFlag&&!permissions.includes(actionFlag))return actionRefusal(value.fixOperation,'qa_fix_action_authorization_required',
|
|
103
|
+
`fix_action ${value.fixOperation} 需要父宿主启动参数 ${parentFlag(actionFlag)}(等同单独 cm-fix-host 的 ${actionFlag});关闭父宿主,带上该参数以 --mode resume 重开后再发 fix_action。`);
|
|
77
104
|
busy=true;let child=null,released=false,result;
|
|
78
105
|
try{
|
|
79
106
|
const status=await current.host.handle({version:1,operation:'status',requestId:value.requestId,identity:value.identity});
|
|
@@ -86,13 +113,29 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
86
113
|
if(advancing&&!existing)need([hostContextId,parentHostContextId].includes(definition.configuration.hostContextId),'qa_fix_host_mismatch');
|
|
87
114
|
child=openFixExecution({...definition,hostContextId,create:advancing&&!existing},advancing||acting?fixExecution:{});
|
|
88
115
|
activeChild=child;
|
|
116
|
+
const childTarget=()=>readFixControlTarget({runId:definition.identity.runId,stage:child.status().stage,
|
|
117
|
+
revision:readExecutionSnapshot({specsRoot:definition.specsRoot,
|
|
118
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}}).revision});
|
|
119
|
+
if(controlPolicy&&acting&&CONTROL_FIX_RECOVERY_OPERATIONS.includes(value.fixOperation))
|
|
120
|
+
need(digest(readFixControlTarget(value.expectedFixControl))===digest(childTarget()),'snapshot_changed');
|
|
89
121
|
let actionResult;
|
|
90
122
|
if(advancing||acting){
|
|
91
123
|
const host=createFixHost({owner:child,config:{...definition.configuration,specsRoot:definition.specsRoot,identity:definition.identity},
|
|
92
|
-
runtime:definition.configuration.runtime??'codex',permissions:[...permissions,'--allow-reproduction'],...fixAuthorities});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
124
|
+
runtime:definition.configuration.runtime??'codex',permissions:[...permissions,'--allow-reproduction'],...fixAuthorities,recoveryInvocationId});
|
|
125
|
+
const action=advancing?{operation:'advance'}:{operation:value.fixOperation,
|
|
126
|
+
...(value.fixOperation==='reconcile_review'?{invocationId:value.invocationId}:{}),
|
|
127
|
+
...(QA_FIX_REASONED.includes(value.fixOperation)?{reason:value.reason}:{}),
|
|
128
|
+
...(value.fixOperation==='prepare_revision'&&Object.hasOwn(value,'tests')?{tests:value.tests}:{}),
|
|
129
|
+
...(value.fixOperation==='recover_final_review'?{invocationId:value.invocationId,packageDigest:value.reviewPackageDigest,
|
|
130
|
+
previousInvocationStopped:value.previousInvocationStopped,reason:value.reason}:{})};
|
|
131
|
+
try{actionResult=running?await host.run(value.requestId):await host.handle({requestId:value.requestId,...action});}
|
|
132
|
+
catch(error){
|
|
133
|
+
// A refused recovery action is the original cm-fix refusal, reported with
|
|
134
|
+
// its code instead of an opaque host failure; the parent still reopens.
|
|
135
|
+
if(!(acting&&actionFlag&&typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)))throw error;
|
|
136
|
+
return actionRefusal(value.fixOperation,error.code,
|
|
137
|
+
`cm-fix 拒绝了 ${value.fixOperation}(${error.code}):子运行当前阶段不满足该操作的条件或参数不匹配;先用 fix_status 核对 fixStage 与 progress,再按 skills/cm-fix/references/js-host.md 的条件重发。`);
|
|
138
|
+
}
|
|
96
139
|
}
|
|
97
140
|
// Original observation/escalation finish intentionally closes its owner. Preserve
|
|
98
141
|
// that successful incomplete exit without reading a closed store.
|
|
@@ -103,6 +146,7 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
103
146
|
?json({outcome:'verified',code:'qa_fix_completed',evidence:child.completionEvidence()},12*1024*1024)
|
|
104
147
|
:json({outcome:'blocked',code:'qa_fix_incomplete',fixStage:observed.stage,
|
|
105
148
|
...(acting?{actionResult}: {})},12*1024*1024);
|
|
149
|
+
if(controlPolicy&&value.operation==='fix_status')result={...result,childControlTarget:childTarget()};
|
|
106
150
|
}finally{
|
|
107
151
|
try{activeChild=null;child?.close();if(released)current=await reopenParent();}
|
|
108
152
|
finally{busy=false;switching=false;}
|