@aibyzero/cm-workflow 0.16.7 → 0.16.9
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 +37 -0
- package/README.md +39 -3
- package/VERSION +1 -1
- package/assets/readme/workflow-recovery-detailed.png +0 -0
- package/assets/readme/workflow-stages-detailed.png +0 -0
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +61 -4
- package/docs/next-steps.md +8 -2
- package/docs/user-guide.md +204 -0
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-admission.mjs +3 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +138 -26
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +142 -21
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-core.mjs +26 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +951 -43
- 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/execution-store.mjs +4 -2
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -4
- 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 +86 -17
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
- package/runtime/js/cm-ai/host-session.mjs +47 -7
- package/runtime/js/cm-ai/host-tool-bridge.mjs +55 -6
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +112 -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-dispatch-limits.mjs +18 -0
- package/runtime/js/cm-ai/review-package.mjs +10 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
- 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 +636 -65
- 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/cause-package.mjs +37 -8
- package/runtime/js/cm-fix/diagnosis.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +356 -187
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/investigation.mjs +25 -9
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +15 -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-prd/review-correction.mjs +10 -4
- 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 +79 -9
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-run.mjs +26 -0
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +312 -0
- package/runtime/js/notify.mjs +492 -0
- package/runtime/js/policy-binding-compat.mjs +54 -0
- package/runtime/model-efficiency.md +17 -0
- 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 +70 -2
- 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 +96 -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 +55 -10
- package/scripts/cm-ai-batch-drive.test.mjs +65 -0
- package/scripts/cm-ai-batch-host.mjs +132 -13
- package/scripts/cm-ai-batch-host.test.mjs +255 -7
- package/scripts/cm-ai-batch-run-fixture.mjs +499 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +38 -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 +189 -22
- package/scripts/cm-ai-batch-run.test.mjs +22 -334
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +104 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +153 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +4 -3
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive.mjs +68 -23
- package/scripts/cm-ai-drive.test.mjs +37 -2
- package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
- package/scripts/cm-ai-host-cli-workflow.test.mjs +271 -0
- package/scripts/cm-ai-host-fixture.mjs +268 -0
- package/scripts/cm-ai-host-protected.test.mjs +251 -0
- package/scripts/cm-ai-host.mjs +28 -16
- package/scripts/cm-ai-host.test.mjs +17 -759
- package/scripts/cm-ai-light-modules.test.mjs +57 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
- package/scripts/cm-ai-protected-scope.test.mjs +7 -3
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +78 -11
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +127 -8
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +475 -0
- package/scripts/cm-ai-review-failure.test.mjs +124 -13
- package/scripts/cm-ai-review-timeout.test.mjs +188 -10
- package/scripts/cm-ai-run.mjs +15 -6
- package/scripts/cm-ai-supersede.test.mjs +486 -41
- 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 +18 -2
- package/scripts/cm-external-model-recovery.test.mjs +29 -3
- package/scripts/cm-fix-abandon.test.mjs +249 -10
- package/scripts/cm-fix-cause-package.test.mjs +33 -0
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +34 -8
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +35 -0
- 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 +143 -10
- 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-log-event.mjs +49 -12
- package/scripts/cm-notify-command.test.mjs +900 -0
- package/scripts/cm-notify-read-drift.test.mjs +205 -0
- package/scripts/cm-notify.mjs +469 -0
- package/scripts/cm-notify.test.mjs +685 -0
- package/scripts/cm-patrol.mjs +83 -0
- package/scripts/cm-patrol.test.mjs +161 -0
- 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-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/cm-token-report.mjs +497 -0
- package/scripts/cm-token-report.test.mjs +346 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/policy-binding-compat.test.mjs +99 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +7 -3
- package/skills/cm-ai/references/N6-qa-eval.md +2 -2
- package/skills/cm-ai/references/js-host-modes.md +90 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +136 -0
- package/skills/cm-ai/references/js-host-recovery.md +311 -0
- package/skills/cm-ai/references/js-host.md +76 -331
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +2 -0
- package/skills/cm-fix/references/js-host.md +56 -10
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +16 -3
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/SKILL.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- 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
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { randomUUID,createHash } from 'node:crypto';
|
|
5
|
-
import
|
|
5
|
+
// Loaded on first open, so modules that only import this one (task-runner via
|
|
6
|
+
// reviewed-deliveries) print no SQLite ExperimentalWarning.
|
|
7
|
+
const sqlite=()=>process.getBuiltinModule('node:sqlite');
|
|
6
8
|
import { need,shape,id,hex,json,digest,freeze,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
|
|
7
9
|
import { isSupportedExecutionPlatform } from './execution-platform.mjs';
|
|
8
10
|
import { MiB,STATE_LIMIT,PHYSICAL_LIMIT } from './execution-store-limits.mjs';
|
|
@@ -141,7 +143,7 @@ function acquireWriter(p,create) {
|
|
|
141
143
|
// An O_EXCL loser must NEVER open an incompletely initialized native DB.
|
|
142
144
|
certificate=readiness(p,inspectionFd);fs.fsyncSync(inspectionFd);syncPath(readyPath(p));syncPath(path.dirname(p));
|
|
143
145
|
}
|
|
144
|
-
db=new DatabaseSync(p,{timeout:0,allowExtension:false});
|
|
146
|
+
db=new (sqlite().DatabaseSync)(p,{timeout:0,allowExtension:false});
|
|
145
147
|
db.exec('PRAGMA busy_timeout=0; PRAGMA trusted_schema=OFF; PRAGMA synchronous=EXTRA');
|
|
146
148
|
// F_FULLFSYNC is macOS-specific. Linux keeps SQLite's native sync plus the
|
|
147
149
|
// mandatory file/parent fsync below; unsupported sync must still fail closed.
|
|
@@ -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;
|
|
@@ -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=>{
|
|
@@ -182,13 +182,18 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
182
182
|
const authority=review?createHostReviewAuthority({hostContextId,reviewerId:'reviewer',adapterId,
|
|
183
183
|
decide:async binding=>allowedAttempts.includes(binding.identity.attempt)?{status:'approved'}:null}):null;
|
|
184
184
|
// Reread role declarations at each boundary; never switch a bound invocation.
|
|
185
|
-
|
|
185
|
+
// onWorker (provider development, task-runner.mjs) journals the worker's
|
|
186
|
+
// identity right before and right after the spawn; a journal failure kills
|
|
187
|
+
// the new process group like a refused role route does.
|
|
188
|
+
const dispatchSpawn=(role,identity,signal,onWorker=null)=>{
|
|
186
189
|
const configuration=loadConfig({projectRoot:definition.codeProject});
|
|
187
190
|
need(digest(resolveProtectedRuntimes(configuration,runtime))===digest({coderRuntime,reviewerRuntime}),'runtime_selection_mismatch');
|
|
188
191
|
return (cli,args,options)=>{
|
|
192
|
+
onWorker?.({phase:'spawning'});
|
|
189
193
|
const child=spawn(cli,args,options);
|
|
190
194
|
if(Number.isInteger(child.pid)){
|
|
191
|
-
try{
|
|
195
|
+
try{onWorker?.({phase:'started',pid:child.pid});
|
|
196
|
+
resolveHostRole({definition,identity,role,signal,runtime,configuration,
|
|
192
197
|
dispatchedRuntime:role==='coder'?coderRuntime:reviewerRuntime});}
|
|
193
198
|
catch(error){child.on('error',()=>{});child.stdin?.on('error',()=>{});
|
|
194
199
|
try{options.detached?process.kill(-child.pid,'SIGKILL'):child.kill('SIGKILL');}catch{}throw error;}
|
|
@@ -246,7 +251,7 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
246
251
|
...(developerLog?{onUsageClaim:()=>developerLog.claimed(),onUsage:value=>{developerUsage=value;}}:{}),
|
|
247
252
|
cwd:definition.codeProject,model:provider.model,...(externalModels?{effort:provider.effort}:{}),timeoutMs:protection.timeoutMs,
|
|
248
253
|
...(coderRuntime==='codex'?{specsRoot:definition.specsDir}:{}),
|
|
249
|
-
spawnProcess:dispatchSpawn('coder',bound.identity,control.signal)}):null;
|
|
254
|
+
spawnProcess:dispatchSpawn('coder',bound.identity,control.signal,typeof control.onWorker==='function'?control.onWorker:null)}):null;
|
|
250
255
|
const worker=async({prompt})=>{
|
|
251
256
|
if(provider&&coderRuntime==='codex'){
|
|
252
257
|
if(documentationPaths.length)prompt='Synchronize approved documentation inside this invocation: '+JSON.stringify(documentationPaths)+'\n'+prompt;
|
|
@@ -297,8 +302,10 @@ export function createConversationExecution(definition,hostContextId,bridge,revi
|
|
|
297
302
|
if(protection&&response.value.outcome!=='blocked'){
|
|
298
303
|
if(bound.payload.specification)verifySpecificationMaterial({specificationRoot:definition.specsDir,
|
|
299
304
|
specification:bound.payload.specification,identity:bound.identity});
|
|
305
|
+
// The applying sandbox subprocess is journaled like the worker (V9).
|
|
300
306
|
try{await projectExecution.commit({scope:bound.payload.scope,
|
|
301
|
-
edits,expected,identity:bound.identity,signal:control.signal
|
|
307
|
+
edits,expected,identity:bound.identity,signal:control.signal,
|
|
308
|
+
...(typeof control.onWorker==='function'?{onApply:event=>control.onWorker(event)}:{})});}
|
|
302
309
|
catch(error){
|
|
303
310
|
// This code is emitted by the pre-write expected-hash check.
|
|
304
311
|
// Sandbox execution/partial-write failures stay ambiguous.
|
|
@@ -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'],
|
|
@@ -36,25 +54,36 @@ function readPlan(configuration,selectCompleted=true) {
|
|
|
36
54
|
need(validateTestCases(contract).length===0&&contract.feature===feature.replace(/^\d+\./,''),'test_cases_invalid');
|
|
37
55
|
cases=contract.cases;
|
|
38
56
|
}
|
|
39
|
-
const context=selectCompleted?inspectCmAiQaTaskContext({specsDir,codeProject,feature}):{completed:[],pending:0};
|
|
57
|
+
const context=selectCompleted?inspectCmAiQaTaskContext({specsDir,codeProject,feature}):{completed:[],pending:0,dropped:[]};
|
|
40
58
|
const completed=new Set(context.completed.filter(task=>task.feature===feature).map(task=>task.id));
|
|
41
|
-
|
|
59
|
+
// A case bound only to [DROPPED] tasks has no deliverable to verify (its AC is
|
|
60
|
+
// deferred with the task), blocking or not: it is recorded, never planned.
|
|
61
|
+
const dropped=new Set(context.dropped);
|
|
62
|
+
const droppedOnly=item=>item.taskIds.length>0&&item.taskIds.every(taskId=>dropped.has(taskId));
|
|
63
|
+
// Identified before the test-kind policy, so a command declared only for them is never scheduled.
|
|
64
|
+
const droppedCases=cases.filter(droppedOnly).map(item=>({id:item.id,taskIds:item.taskIds}));
|
|
65
|
+
const droppedIds=new Set(droppedCases.map(item=>item.id));
|
|
66
|
+
const applicable=cases.filter(item=>!droppedIds.has(item.id)&&(item.blocking||config.policies.tests.includes(item.kind)));
|
|
42
67
|
const deferred=context.pending===0?[]:applicable.map(item=>({id:item.id,
|
|
43
68
|
taskIds:item.taskIds.filter(taskId=>!completed.has(taskId))})).filter(item=>item.taskIds.length>0);
|
|
44
69
|
const deferredIds=new Set(deferred.map(item=>item.id));
|
|
45
70
|
const selected=applicable.filter(item=>!deferredIds.has(item.id));
|
|
46
71
|
const wanted=new Set(selected.filter(item=>item.kind==='logic').map(item=>item.id));
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
// A command declared only for such cases is not run for them either.
|
|
73
|
+
const droppedCommands=commands.filter(item=>item.caseIds.length>0&&item.caseIds.every(caseId=>droppedIds.has(caseId)))
|
|
74
|
+
.map(item=>({id:item.id,caseIds:item.caseIds}));
|
|
75
|
+
const scheduled=commands.filter(item=>!droppedCommands.some(other=>other.id===item.id)&&((config.policies.tests.includes('commands')
|
|
76
|
+
&&(context.pending===0||item.caseIds.length===0))||item.caseIds.some(caseId=>wanted.has(caseId))));
|
|
49
77
|
for(const item of commands)for(const caseId of item.caseIds)
|
|
50
78
|
need(cases.some(candidate=>candidate.id===caseId&&candidate.kind==='logic'),'qa_command_mapping_invalid');
|
|
51
79
|
const modes=order[config.project.workflow].filter(mode=>mode==='commands'
|
|
52
|
-
?scheduled.length>0||(config.policies.tests.includes('commands')&&(context.pending===0||commands.length===
|
|
80
|
+
?scheduled.length>0||(config.policies.tests.includes('commands')&&(context.pending===0||commands.length===droppedCommands.length))
|
|
53
81
|
:selected.some(item=>item.kind===mode));
|
|
54
82
|
const noApplicableCases=context.pending>0&&selected.length===0&&scheduled.length===0;
|
|
55
83
|
if(noApplicableCases)modes.splice(0,modes.length,'commands');
|
|
56
84
|
return json({config,cases:selected,...(selectCompleted?{deferred_cases:deferred}:{}),commands:scheduled,modes,
|
|
57
|
-
...(noApplicableCases?{no_applicable_cases:true}:{})})
|
|
85
|
+
...(noApplicableCases?{no_applicable_cases:true}:{}),...(droppedCases.length?{dropped_task_cases:droppedCases}:{}),
|
|
86
|
+
...(droppedCommands.length?{dropped_task_commands:droppedCommands}:{})});
|
|
58
87
|
}
|
|
59
88
|
|
|
60
89
|
function logStep(configuration,binding,event,phase,data,detail) {
|
|
@@ -106,14 +135,22 @@ function evidence(raw) {
|
|
|
106
135
|
return result;
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
|
|
138
|
+
// Cases (and commands declared only for them) bound only to [DROPPED] tasks:
|
|
139
|
+
// listed as NOT_APPLICABLE beside the rows, never counted as PASS/FAIL/BLOCKED.
|
|
140
|
+
const notApplicable=plan=>[
|
|
141
|
+
...(plan.dropped_task_cases??[]).map(item=>({...item,verdict:'NOT_APPLICABLE',reason:`bound only to dropped tasks: ${item.taskIds.join(', ')}`})),
|
|
142
|
+
...(plan.dropped_task_commands??[]).map(item=>({...item,kind:'commands',verdict:'NOT_APPLICABLE',
|
|
143
|
+
reason:`declared only for cases bound only to dropped tasks: ${item.caseIds.join(', ')}`}))];
|
|
144
|
+
|
|
145
|
+
function saveReport(configuration,binding,rows,summary,plan) {
|
|
110
146
|
const reviews=path.join(configuration.specsDir,'.reviews'),stat=fs.lstatSync(reviews);
|
|
111
147
|
need(stat.isDirectory()&&!stat.isSymbolicLink()&&fs.realpathSync(reviews)===reviews,'qa_report_invalid');
|
|
112
148
|
const target=path.join(reviews,`${binding.testRunId}-execution.md`);
|
|
113
149
|
const body=Buffer.from(`# CM QA execution report\n\nOverall: ${summary.result}\n\n`
|
|
114
150
|
+'Counts are declared command checks plus selected cases, not framework test totals.\n'
|
|
115
151
|
+'Static verdicts are retained separately; only observed command/browser evidence counts as PASS.\n\n'
|
|
116
|
-
+`## deferred_cases\n\n${JSON.stringify(
|
|
152
|
+
+`## deferred_cases\n\n${JSON.stringify(plan.deferred_cases,null,2)}\n\n`
|
|
153
|
+
+(notApplicable(plan).length?`## not_applicable\n\n${JSON.stringify(notApplicable(plan),null,2)}\n\n`:'')
|
|
117
154
|
+rows.map(row=>`## ${row.id}\n\n${JSON.stringify(row,null,2)}\n`).join('\n'));
|
|
118
155
|
need(body.length<=1024*1024,'limit_exceeded');
|
|
119
156
|
const fd=fs.openSync(target,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY|fs.constants.O_NOFOLLOW,0o600);
|
|
@@ -199,24 +236,31 @@ export function createHostQaExecutor(options) {
|
|
|
199
236
|
for(const stage of plan.modes){
|
|
200
237
|
const routed=route(stage==='browser'?'browser_qa':'tester');
|
|
201
238
|
if(stage==='commands'){
|
|
239
|
+
const dropped=notApplicable(plan).map(item=>`${item.id}: ${item.reason}`);
|
|
202
240
|
if(plan.no_applicable_cases)rows.push({id:'no-applicable-cases',kind:'commands',verdict:'BLOCKED',
|
|
203
241
|
evidence:['all applicable cases are bound to unfinished tasks; deferred to feature completion',
|
|
204
|
-
...plan.deferred_cases.map(item=>`${item.id}: ${item.taskIds.join(', ')}`)]});
|
|
205
|
-
else if(!plan.commands.length)rows.push({id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No declared project test command']});
|
|
242
|
+
...plan.deferred_cases.map(item=>`${item.id}: ${item.taskIds.join(', ')}`),...dropped]});
|
|
243
|
+
else if(!plan.commands.length)rows.push({id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No declared project test command',...dropped]});
|
|
206
244
|
for(const command of plan.commands){
|
|
207
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;
|
|
208
249
|
const check=createHostCheck({cwd:roots?command.codeProject:configuration.codeProject,commands:[{id:command.id,command:command.command}],
|
|
209
|
-
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:{})});
|
|
210
253
|
const resource={resource_id:`qa-command-${digest({testRunId:binding.testRunId,command:command.id}).slice(0,48)}`,
|
|
211
254
|
resource_kind:'qa_command'};
|
|
212
255
|
logStep(configuration,binding,'resource','acquired',{...resource,cleanup_required:true},'QA command resource acquired');
|
|
213
256
|
let observed;
|
|
214
257
|
try{
|
|
215
258
|
[observed]=await check({identity:binding.identity},{signal});
|
|
216
|
-
|
|
217
|
-
|
|
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');
|
|
218
262
|
}catch(error){
|
|
219
|
-
logStep(configuration,binding,'resource','cleanup_failed',
|
|
263
|
+
logStep(configuration,binding,'resource','cleanup_failed',failedCleanup(),'QA command cleanup not confirmed');throw error;
|
|
220
264
|
}
|
|
221
265
|
notCancelled();
|
|
222
266
|
commandResults.set(command.id,observed);
|
|
@@ -292,9 +336,33 @@ export function createHostQaExecutor(options) {
|
|
|
292
336
|
...(answered&&observed.verdict==='BLOCKED'?{hostDeclaredBlocked:true}:{})});
|
|
293
337
|
// The durable log row, appended now through the writer, is the record
|
|
294
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';
|
|
295
347
|
logStep(configuration,binding,'test_run',verdict==='BLOCKED'?'case_blocked':'case_complete',
|
|
296
|
-
{case_id:item.id,result:verdict,...(answered&&observed.verdict==='BLOCKED'?{host_declared_blocked:true}:{})
|
|
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}:{}),
|
|
353
|
+
// Whether this BLOCKED is a host request that timed out without an
|
|
354
|
+
// answer; --rerun-unknown-qa reads it after a whole-call timeout.
|
|
355
|
+
...(verdict==='BLOCKED'?{host_request_timeout:hostRequestTimeout&&!answered}:{})},
|
|
297
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
|
+
}
|
|
298
366
|
}
|
|
299
367
|
}
|
|
300
368
|
}
|
|
@@ -318,7 +386,8 @@ export function createHostQaExecutor(options) {
|
|
|
318
386
|
if(row.verdict==='BLOCKED'&&row.staticVerdict==='SUPPORTED'&&!needsConfirmation
|
|
319
387
|
&&observed.some(result=>result?.outcome==='unavailable'))row.commandUnavailable=true;
|
|
320
388
|
}
|
|
321
|
-
if(rows.length===0)rows.push({id:'qa-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No executable QA contract'
|
|
389
|
+
if(rows.length===0)rows.push({id:'qa-unavailable',kind:'commands',verdict:'BLOCKED',evidence:['No executable QA contract',
|
|
390
|
+
...notApplicable(plan).map(item=>`${item.id}: ${item.reason}`)]});
|
|
322
391
|
const drift=digest(before.files)!==digest(snapshot().files);
|
|
323
392
|
// Keep each row's own verdict: a later explicit rerun may only recover a row
|
|
324
393
|
// that was PASS or a host-judged BLOCKED before the source changed, never a FAIL.
|
|
@@ -327,7 +396,7 @@ export function createHostQaExecutor(options) {
|
|
|
327
396
|
blocked=rows.filter(item=>item.verdict==='BLOCKED').length;
|
|
328
397
|
need(passed+failed+blocked===caseCount,'qa_result_invalid');
|
|
329
398
|
const summary={result:failed>0?'FAIL':blocked>0?'BLOCKED':'PASS',passed,failed,blocked};
|
|
330
|
-
const report=saveReport(configuration,binding,rows,summary,plan
|
|
399
|
+
const report=saveReport(configuration,binding,rows,summary,plan);
|
|
331
400
|
return json({...summary,report});
|
|
332
401
|
}});
|
|
333
402
|
}
|
|
@@ -8,8 +8,24 @@ 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
10
|
|
|
11
|
-
|
|
11
|
+
// Q23: the child's recovery operations, each with the original cm-fix flag the
|
|
12
|
+
// shared dispatcher (cm-fix/host.mjs) checks and the parent flag that grants it.
|
|
13
|
+
// The dispatcher stays the only validator; this table only names the missing flag.
|
|
14
|
+
const QA_FIX_ACTION_FLAGS=Object.freeze({rediagnose:'--allow-rediagnosis',rerun_blocked_step:'--allow-rerun-blocked-step',
|
|
15
|
+
recover_final_review:'--allow-final-review-recovery',abandon_step:'--allow-abandon',abandon_review:'--allow-abandon-review',
|
|
16
|
+
revision_test_check:'--allow-regression'});
|
|
17
|
+
const QA_FIX_REASONED=['abandon_step','abandon_review','rediagnose','rerun_blocked_step'];
|
|
18
|
+
export const QA_FIX_ACTIONS=Object.freeze(['red_test','baseline','author_tests','repair','regression','retrospective','learning_writeback',
|
|
19
|
+
'handoff','final_review_package','final_review','publish_review','check_n5','post_review_regression',
|
|
20
|
+
'publish_dossier','walkthrough','finish','prepare_revision','cause_review_package','cause_review','reconcile_review',
|
|
21
|
+
...Object.keys(QA_FIX_ACTION_FLAGS)]);
|
|
22
|
+
const parentFlag=flag=>flag.replace(/^--allow-/,'--allow-qa-fix-');
|
|
23
|
+
const actionRefusal=(fixOperation,code,reason)=>Object.freeze({outcome:'rejected',code,fixOperation,reason,
|
|
24
|
+
guidance:Object.freeze({summary:'QA 修复子流程的这次操作被拒绝,子运行没有因此改变。',nextStep:reason,
|
|
25
|
+
recoveryOperation:null,prerequisites:Object.freeze([]),authorizationGranted:false})});
|
|
26
|
+
export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHostContextId,fix=null,template=null,allowStart=false,autoFix=false,fixExecution={},fixPermissions=[],fixAuthorities={},externalModels=null,executionPolicy=null,recoveryInvocationId=null}){
|
|
12
27
|
id(hostContextId);id(parentHostContextId);
|
|
28
|
+
if(recoveryInvocationId!==null)id(recoveryInvocationId);
|
|
13
29
|
need((fix===null)!==(template===null),'invalid_fix_config');
|
|
14
30
|
let definition=null;
|
|
15
31
|
let fixedTemplate=template===null?null:json(template,64*1024);
|
|
@@ -59,8 +75,13 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
59
75
|
if(!['fix_status','fix_advance','fix_action','fix_run'].includes(request.operation)){
|
|
60
76
|
busy=true;try{return await current.host.handle(request);}finally{busy=false;}
|
|
61
77
|
}
|
|
78
|
+
// recover_final_review binds the child's final review package; packageDigest
|
|
79
|
+
// here is the parent QA package, so the child digest is reviewPackageDigest.
|
|
62
80
|
const value=json(request);shape(value,['version','requestId','operation','identity','packageDigest','testRunId',
|
|
63
|
-
...(request.operation==='fix_action'?['fixOperation',...(request.fixOperation==='reconcile_review'?['invocationId']:[])
|
|
81
|
+
...(request.operation==='fix_action'?['fixOperation',...(request.fixOperation==='reconcile_review'?['invocationId']:[]),
|
|
82
|
+
...(QA_FIX_REASONED.includes(request.fixOperation)&&Object.hasOwn(request,'reason')?['reason']:[]),
|
|
83
|
+
...(request.fixOperation==='prepare_revision'&&Object.hasOwn(request,'tests')?['tests']:[]),
|
|
84
|
+
...(request.fixOperation==='recover_final_review'?['invocationId','reviewPackageDigest','previousInvocationStopped','reason']:[])]:[])]);
|
|
64
85
|
need(value.version===1,'invalid_input');id(value.requestId);validIdentity(value.identity);hex(value.packageDigest);id(value.testRunId);
|
|
65
86
|
if(fixedTemplate)definition=bindQaFixDefinition({template:fixedTemplate,identity:value.identity,
|
|
66
87
|
packageDigest:value.packageDigest,testRunId:value.testRunId});
|
|
@@ -70,10 +91,13 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
70
91
|
const running=value.operation==='fix_run';
|
|
71
92
|
const advancing=value.operation==='fix_advance'||running;
|
|
72
93
|
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');
|
|
94
|
+
if(acting)need(QA_FIX_ACTIONS.includes(value.fixOperation),'fix_operation_unavailable');
|
|
76
95
|
need(!(advancing||acting)||allowStart,'qa_fix_start_authorization_required');
|
|
96
|
+
// Refuse a recovery action whose flag this launch lacks before the parent is
|
|
97
|
+
// closed, naming the parent flag; the cm-fix dispatcher still re-checks it.
|
|
98
|
+
const actionFlag=acting?QA_FIX_ACTION_FLAGS[value.fixOperation]:undefined;
|
|
99
|
+
if(actionFlag&&!permissions.includes(actionFlag))return actionRefusal(value.fixOperation,'qa_fix_action_authorization_required',
|
|
100
|
+
`fix_action ${value.fixOperation} 需要父宿主启动参数 ${parentFlag(actionFlag)}(等同单独 cm-fix-host 的 ${actionFlag});关闭父宿主,带上该参数以 --mode resume 重开后再发 fix_action。`);
|
|
77
101
|
busy=true;let child=null,released=false,result;
|
|
78
102
|
try{
|
|
79
103
|
const status=await current.host.handle({version:1,operation:'status',requestId:value.requestId,identity:value.identity});
|
|
@@ -89,10 +113,21 @@ export function createQaFixOwnerHost({parent,reopenParent,hostContextId,parentHo
|
|
|
89
113
|
let actionResult;
|
|
90
114
|
if(advancing||acting){
|
|
91
115
|
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
|
-
|
|
116
|
+
runtime:definition.configuration.runtime??'codex',permissions:[...permissions,'--allow-reproduction'],...fixAuthorities,recoveryInvocationId});
|
|
117
|
+
const action=advancing?{operation:'advance'}:{operation:value.fixOperation,
|
|
118
|
+
...(value.fixOperation==='reconcile_review'?{invocationId:value.invocationId}:{}),
|
|
119
|
+
...(QA_FIX_REASONED.includes(value.fixOperation)?{reason:value.reason}:{}),
|
|
120
|
+
...(value.fixOperation==='prepare_revision'&&Object.hasOwn(value,'tests')?{tests:value.tests}:{}),
|
|
121
|
+
...(value.fixOperation==='recover_final_review'?{invocationId:value.invocationId,packageDigest:value.reviewPackageDigest,
|
|
122
|
+
previousInvocationStopped:value.previousInvocationStopped,reason:value.reason}:{})};
|
|
123
|
+
try{actionResult=running?await host.run(value.requestId):await host.handle({requestId:value.requestId,...action});}
|
|
124
|
+
catch(error){
|
|
125
|
+
// A refused recovery action is the original cm-fix refusal, reported with
|
|
126
|
+
// its code instead of an opaque host failure; the parent still reopens.
|
|
127
|
+
if(!(acting&&actionFlag&&typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)))throw error;
|
|
128
|
+
return actionRefusal(value.fixOperation,error.code,
|
|
129
|
+
`cm-fix 拒绝了 ${value.fixOperation}(${error.code}):子运行当前阶段不满足该操作的条件或参数不匹配;先用 fix_status 核对 fixStage 与 progress,再按 skills/cm-fix/references/js-host.md 的条件重发。`);
|
|
130
|
+
}
|
|
96
131
|
}
|
|
97
132
|
// Original observation/escalation finish intentionally closes its owner. Preserve
|
|
98
133
|
// that successful incomplete exit without reading a closed store.
|