@aibyzero/cm-workflow 0.16.8 → 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 +19 -0
- package/README.md +14 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +25 -1
- package/docs/next-steps.md +8 -2
- 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 +111 -20
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +69 -22
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- 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/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 +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +40 -3
- 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-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/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-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-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +312 -0
- package/runtime/js/notify.mjs +137 -33
- package/runtime/js/policy-binding-compat.mjs +54 -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 +184 -22
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- 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 +64 -22
- package/scripts/cm-ai-drive.test.mjs +29 -2
- 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 +27 -15
- 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-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 +56 -10
- 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 +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 +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 +22 -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 +21 -10
- 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 +221 -4
- 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/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/references/js-host-qa-recovery.md +27 -1
- package/skills/cm-ai/references/js-host-recovery.md +120 -8
- package/skills/cm-ai/references/js-host.md +14 -7
- package/skills/cm-check/SKILL.md +3 -3
- 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 +16 -3
- package/skills/cm-notify/SKILL.md +34 -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
package/scripts/cm-init-host.mjs
CHANGED
|
@@ -13,7 +13,29 @@ import {publishCmInitReviewEvidence,loadCmInitRecoveryDraft} from '../runtime/js
|
|
|
13
13
|
import {inspectCmInitDraft,readCmInitSource} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
14
14
|
import {inspectCmInitProjectAnalysis} from '../runtime/js/cm-init/project-analysis.mjs';
|
|
15
15
|
import {validateCmInitSelection} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
16
|
-
import {openDraftSession} from '../runtime/js/cm-idea/session.mjs';
|
|
16
|
+
import {openDraftSession,MAX_CALL_ABANDONS} from '../runtime/js/cm-idea/session.mjs';
|
|
17
|
+
import {legacyInitBindings} from '../runtime/js/policy-binding-compat.mjs';
|
|
18
|
+
|
|
19
|
+
const STEP_KINDS={ready:'init_generate',analysis_ready:'init_generate',draft_generated:'init_verify',
|
|
20
|
+
confirmation_required:'init_confirm',review_required:'init_review'};
|
|
21
|
+
// Chinese next steps for a blocked draft (R4). Presentation only, never authority.
|
|
22
|
+
export function initRecoveryGuidance({stage,pending,abandoned,retry,packageDigest}){
|
|
23
|
+
const used=kind=>abandoned.filter(item=>item.kind===kind).length;
|
|
24
|
+
const draft=packageDigest?`--resume-draft ${packageDigest}`:'--resume-draft <packageDigest>';
|
|
25
|
+
if(pending?.writing||['write_unknown','write_incomplete'].includes(stage))return {summary:'规则写入结果未知或只写了一部分,会话模式下 resume 会报 idea_save_outcome_unknown。',
|
|
26
|
+
nextStep:`不要重发 init_write。先运行 cm-init-entry.mjs --inspect-recovery ${packageDigest??'<packageDigest>'} 逐文件比对;然后去掉 --session-file,在启动参数末尾加 ${draft}:全部一致停在 rules_present,部分写入回到已审草稿续写(重新核验、确认、独立审查),冲突报 init_recovery_conflict 交人。`,
|
|
27
|
+
authorizationGranted:false};
|
|
28
|
+
const call=pending?.call;
|
|
29
|
+
if(call){const left=MAX_CALL_ABANDONS-used(call.kind),person=call.kind==='init_confirm';
|
|
30
|
+
if(call.status==='unknown')return {summary:`${call.kind} 的应答没有拿到(超时、断开或宿主退出)。`,
|
|
31
|
+
nextStep:`有原回执就 resume 交回;没有就 resume {resolution:{callId,requestDigest,abandon:true,evidence}} 作废后${person?'重新问当前用户':'重问'}(本会话 ${call.kind} 还可 ${left} 次)。迟到的旧答复一律不用。`,authorizationGranted:false};
|
|
32
|
+
return {summary:`${call.kind} 的应答已记录。`,
|
|
33
|
+
nextStep:`resume {resolution:null} 消费原结果;若宿主拒收(stderr diagnostic 的码),用 {callId,requestDigest,discard:true,evidence} 作废后${person?'重新问当前用户':'重问'}(还可 ${left} 次)。`,authorizationGranted:false};}
|
|
34
|
+
if(stage==='failed'&&retry)return {summary:`${retry.kind} 没有拿到合格应答(超时、校验不过或断开)。`,
|
|
35
|
+
nextStep:retry.remaining>0?`再发一次 ${retry.operation} 重问,还可 ${retry.remaining} 次。内存模式下宿主退出就只能从头开始,需要可恢复请改用 --session-file。`
|
|
36
|
+
:'本进程重问次数已用完(init_retry_limit);交人处理,或改用 --session-file 重新开始。',authorizationGranted:false};
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
17
39
|
|
|
18
40
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
19
41
|
let bridge,session;
|
|
@@ -25,6 +47,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
25
47
|
output.write('Optional --allow-write after --host-context ID permits one init_write host request only after the draft review approves and originals still match. The host edits only the fixed reviewed paths; JS reads back every target. Partial/unknown writes stop without retry or rollback. A private immutable .reviews/cm-init-<packageDigest>.md archive is saved before init_write; conflicts or archives over 256 KiB block writing. The archive is not a write result or completion receipt. rules_written does not complete a task; append --resume-draft DIGEST to load an archived draft without regeneration. Conflicts refuse startup. Partial drafts require fresh verification, confirmation when needed and independent review; --allow-write remains required. Only changed targets are dispatched. All-matching drafts stop at rules_present, not task completion. This is draft recovery, not replay of unknown in-flight calls.\n');
|
|
26
48
|
output.write('Optional --host-context ID binds the actual author context and is required for review. In review_required, advance requests init_review from the trusted host; it must return an actual independent reviewer result. The shared review result validator checks package/coverage/findings. Approval only reaches reviewed_draft, not completion or write authority. No provider dispatch authorization is implied.\n');
|
|
27
49
|
output.write('final_review_package is read-only in review_required: fixed draft, original constraints, host verification and confirmation, exact paths and package digest. It is not a registered V3 receipt and neither dispatches a reviewer nor authorizes completion.\n');
|
|
50
|
+
output.write('Recovery (V1/V7): with --session-file, resume {resolution:{callId,requestDigest,discard:true,evidence}} discards a recorded answer the host refused and {callId,requestDigest,abandon:true,evidence} abandons an unknown analyze/generate/verify/confirm/review call; both ask again under the same pending request with a fresh callId (init_confirm asks the current user again), keep append-only abandonedCalls, 2 per kind per session. init_write is never re-asked: use --inspect-recovery and --resume-draft. Without --session-file a failed step may be re-sent twice in the same process; a dead memory-only host starts over.\n');
|
|
28
51
|
output.write('cm-init-host.mjs serve --skill-dir PATH --project PATH\nOne local draft via existing JSONL host bridge: advance with selection {versionControl,modules,analysis,runtimes?}, then advance without selection for init_verify and, only when required, init_confirm. Status and cancel remain available. Replies use host_result with exact sessionId/callId/requestDigest. Confirmation must convey the explicit current user decision; approval only reaches independent review. Verification is a current-host report, not independent review. No provider or task-completion authority; project writes require --allow-write and the reviewed-draft stage. Host results retain the shared 64 KiB limit.\n');return 0;
|
|
29
52
|
}
|
|
30
53
|
const sessionFile=argv.at(-2)==='--session-file'?argv.at(-1):null;
|
|
@@ -43,7 +66,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
43
66
|
need(fs.realpathSync(fileURLToPath(import.meta.url))===path.join(admission.workflowRoot,'scripts/cm-init-host.mjs'),'entry_path_invalid');
|
|
44
67
|
bridge=createHostToolBridge();
|
|
45
68
|
const controller=new AbortController();let stage='ready',result=null,verification=null,selection=null,confirmation=null,review=null,writeResult=null,reviewPackage=null,reviewEvidence=null,analysisResult=null;
|
|
46
|
-
const revisionHistory=[];
|
|
69
|
+
const revisionHistory=[],retries={};let failedStep=null;
|
|
47
70
|
let authorContexts=hostContextId===null?[]:[hostContextId];
|
|
48
71
|
const snapshot=()=>({stage,result,verification,selection,confirmation,review,writeResult,reviewPackage,reviewEvidence,analysisResult,revisionHistory,authorContexts,authorContextId:hostContextId});
|
|
49
72
|
const restore=state=>{
|
|
@@ -55,15 +78,21 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
55
78
|
need(hostContextId!==null,'init_session_host_context_required');
|
|
56
79
|
const policyFiles=['skills/cm-init/SKILL.md','skills/cm-init/references/js-host.md',
|
|
57
80
|
...fs.readdirSync(path.join(admission.workflowRoot,'templates/rules')).filter(name=>name.endsWith('.md')).sort().map(name=>'templates/rules/'+name)];
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
const policy=policyFiles.map(file=>[file,readCmInitSource(admission.workflowRoot,file)?.toString('utf8')??null]);
|
|
82
|
+
session=openDraftSession(sessionFile,{project:admission.project,workflowRoot:admission.workflowRoot,policyDigest:digest(policy)},'cm-init',
|
|
83
|
+
{legacyBindings:legacyInitBindings({project:admission.project,workflowRoot:admission.workflowRoot,files:policy})});
|
|
60
84
|
if(session.state.checkpoint)restore(session.state.checkpoint);
|
|
61
85
|
if(session.state.cancelled){stage='cancelled';controller.abort();}
|
|
62
86
|
}
|
|
63
87
|
const call=(kind,payload,signal)=>session?session.call(kind,payload,signal,(body,abort)=>bridge.call(kind,body,abort)):bridge.call(kind,payload,signal);
|
|
64
88
|
if(resumeDigest!==null){
|
|
65
89
|
const restored=loadCmInitRecoveryDraft({project:admission.project,packageDigest:resumeDigest});
|
|
66
|
-
|
|
90
|
+
// V6: a conflict goes to a person with the per-file comparison, never as a new delivery.
|
|
91
|
+
if(restored.report.status==='conflict'){
|
|
92
|
+
error.write(JSON.stringify({diagnostic:'init_recovery_conflict',files:restored.report.files.map(({path,status})=>({path,status})),
|
|
93
|
+
guidance:'这些文件既不是原文也不是已审草稿(conflict):逐个核对是谁改的;保留用户改动,不覆盖、不回滚、不删档。处理后先用 cm-init-entry.mjs --inspect-recovery 复核,再决定续写或重新初始化。'})+'\n');
|
|
94
|
+
need(false,'init_recovery_conflict');
|
|
95
|
+
}
|
|
67
96
|
need(restored.inspection.status==='structurally_checked','init_draft_structural_failure');
|
|
68
97
|
selection=restored.selection;
|
|
69
98
|
result={status:'draft_generated',documents:restored.documents,inspection:restored.inspection,
|
|
@@ -75,11 +104,29 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
75
104
|
need(inspection.status==='structurally_checked','init_draft_structural_failure');
|
|
76
105
|
need(digest(inspection.changes)===digest(result.inspection.changes),'init_verification_project_changed');
|
|
77
106
|
};
|
|
107
|
+
const retryInfo=()=>failedStep&&!session?{...failedStep,remaining:MAX_CALL_ABANDONS-(retries[failedStep.kind]??0)}:null;
|
|
108
|
+
const guidance=()=>initRecoveryGuidance({stage,retry:retryInfo(),abandoned:session?.abandonedCalls??[],
|
|
109
|
+
pending:session?.state.pending?{writing:session.state.pending.writing,call:session.state.pending.call?{kind:session.state.pending.call.kind,
|
|
110
|
+
status:Object.hasOwn(session.state.pending.call,'result')?'recorded':'unknown'}:null}:null,
|
|
111
|
+
packageDigest:writeResult?.packageDigest??reviewPackage?.packageDigest??null});
|
|
78
112
|
const handle=async raw=>{
|
|
79
113
|
const message=json(raw);need(['start','advance','status','cancel','final_review_package','prepare_revision'].includes(message.operation),'host_operation_invalid');
|
|
114
|
+
// V1 without --session-file: nothing was recorded for a failed step, so the
|
|
115
|
+
// same operation may be sent again from the stage before it, twice per kind.
|
|
116
|
+
if(stage==='failed'&&failedStep&&!session&&['start','advance'].includes(message.operation)){
|
|
117
|
+
need(message.operation===failedStep.operation,'init_generation_already_started');
|
|
118
|
+
need((retries[failedStep.kind]??0)<MAX_CALL_ABANDONS,'init_retry_limit');
|
|
119
|
+
retries[failedStep.kind]=(retries[failedStep.kind]??0)+1;stage=failedStep.priorStage;failedStep=null;
|
|
120
|
+
}
|
|
121
|
+
const priorStage=stage,failedKind=message.operation==='start'?'init_analyze':STEP_KINDS[stage];
|
|
122
|
+
const fail=cause=>{stage=controller.signal.aborted?'cancelled':'failed';
|
|
123
|
+
if(stage==='failed'&&failedKind&&['start','advance'].includes(message.operation))failedStep={operation:message.operation,priorStage,kind:failedKind};
|
|
124
|
+
throw cause;};
|
|
80
125
|
shape(message,message.operation==='prepare_revision'?['requestId','operation','documents']:
|
|
81
126
|
message.operation==='advance'&&stage==='ready'?['requestId','operation','selection']:['requestId','operation']);
|
|
82
|
-
if(message.operation==='status')
|
|
127
|
+
if(message.operation==='status'){const advice=guidance(),retry=retryInfo();
|
|
128
|
+
return {stage,result,analysisResult,verification,confirmation,review,writeResult,reviewEvidence,revisionHistory,writeAuthorized:false,
|
|
129
|
+
...(retry?{retry}:{}),...(advice?{guidance:advice}:{})};}
|
|
83
130
|
if(message.operation==='prepare_revision'){
|
|
84
131
|
need(['verification_blocked','review_changes_requested','review_blocked'].includes(stage),'init_revision_not_ready');
|
|
85
132
|
current();
|
|
@@ -113,7 +160,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
113
160
|
analysisResult={source:'current_host_report',observations,...response};stage='analysis_ready';
|
|
114
161
|
}
|
|
115
162
|
return {stage,analysisResult,writeAuthorized:false};
|
|
116
|
-
}catch(cause){
|
|
163
|
+
}catch(cause){fail(cause);}
|
|
117
164
|
}
|
|
118
165
|
if(message.operation==='final_review_package'){
|
|
119
166
|
need(stage==='review_required','init_review_not_ready');current();
|
|
@@ -190,7 +237,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
190
237
|
reviewPackage=pkg;
|
|
191
238
|
stage=checked.verdict==='approved'?'reviewed_draft':checked.verdict==='changes_requested'?'review_changes_requested':'review_blocked';
|
|
192
239
|
return {stage,review,writeAuthorized:false,completionAuthorized:false};
|
|
193
|
-
}catch(cause){
|
|
240
|
+
}catch(cause){fail(cause);}
|
|
194
241
|
}
|
|
195
242
|
if(stage==='confirmation_required'){
|
|
196
243
|
stage='confirming';
|
|
@@ -208,7 +255,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
208
255
|
paths:[...verification.constraintChanges],decision:response.decision};
|
|
209
256
|
stage=response.decision==='approved'?'review_required':'confirmation_rejected';
|
|
210
257
|
return {stage,confirmation,independentReviewRequired:true,writeAuthorized:false};
|
|
211
|
-
}catch(cause){
|
|
258
|
+
}catch(cause){fail(cause);}
|
|
212
259
|
}
|
|
213
260
|
if(stage==='draft_generated'){
|
|
214
261
|
stage='verifying';
|
|
@@ -232,7 +279,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
232
279
|
stage=Object.values(response.checks).some(check=>['unverified','failed'].includes(check.status))?'verification_blocked'
|
|
233
280
|
:response.constraintChanges.length?'confirmation_required':'review_required';
|
|
234
281
|
return {stage,verification,independentReviewRequired:true,writeAuthorized:false};
|
|
235
|
-
}catch(cause){
|
|
282
|
+
}catch(cause){fail(cause);}
|
|
236
283
|
}
|
|
237
284
|
need(['ready','analysis_ready'].includes(stage),'init_generation_already_started');
|
|
238
285
|
if(stage==='analysis_ready')need(digest(analysisResult.observations)===digest(inspectCmInitProjectAnalysis({project:admission.project})),'init_analysis_project_changed');
|
|
@@ -242,7 +289,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
242
289
|
result=await generateCmInitRules(request,selection,{signal:controller.signal,
|
|
243
290
|
generate:(payload,signal)=>call('init_generate',payload,signal)});
|
|
244
291
|
stage=result.status;return result;
|
|
245
|
-
}catch(cause){
|
|
292
|
+
}catch(cause){fail(cause);}
|
|
246
293
|
};
|
|
247
294
|
const host={handle:async raw=>{
|
|
248
295
|
if(!session)return handle(raw);
|
|
@@ -260,7 +307,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
260
307
|
let message=raw;
|
|
261
308
|
if(raw.operation==='resume'){
|
|
262
309
|
shape(raw,['requestId','operation','resolution']);
|
|
263
|
-
|
|
310
|
+
const reask=raw.resolution?.discard===true||raw.resolution?.abandon===true;
|
|
311
|
+
if(reask)session.abandonCall(raw.resolution);
|
|
312
|
+
message=session.resume(reask?null:raw.resolution);
|
|
264
313
|
if(message===null)return host.handle({requestId:raw.requestId,operation:'status'});
|
|
265
314
|
restore(session.state.checkpoint);
|
|
266
315
|
}else session.begin(raw,snapshot());
|
package/scripts/cm-log-event.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import os from 'node:os';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {statusProjectionCommand} from '../runtime/js/cm-ai/status-projection.mjs';
|
|
9
|
+
import {qaRoundLimit,nonProductSupersession} from '../runtime/js/cm-ai/qa-round-budget.mjs';
|
|
9
10
|
|
|
10
11
|
const IDENTIFIER=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/;
|
|
11
12
|
const RESOURCE_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
@@ -350,8 +351,10 @@ function validateQaAbandonment(state,event){
|
|
|
350
351
|
|
|
351
352
|
function validateQaSupersession(state,event){
|
|
352
353
|
const {start,complete}=state;
|
|
354
|
+
// Q14: rounds superseded for a host or answer problem do not count (qa-round-budget.mjs).
|
|
355
|
+
const roundLimit=qaRoundLimit((state.freed??0)+(nonProductSupersession(event.reason)?1:0));
|
|
353
356
|
if(event.reason==='qa_configuration_revision'){
|
|
354
|
-
if(state.active||state.superseded||!start||!complete||start.attempt>=
|
|
357
|
+
if(state.active||state.superseded||!start||!complete||start.attempt>=roundLimit
|
|
355
358
|
||event.workflow!=='cm-ai'||event.node!=='N6'||event.previous_test_run_id!==start.operation_id
|
|
356
359
|
||!['PASS','FAIL','BLOCKED'].includes(complete.result)||!/^[a-f0-9]{64}$/.test(event.qa_revision_digest??'')
|
|
357
360
|
||!['repository_id','run_id','feature','task','package_digest','qa_decision_id','operation_id','attempt','mode','case_count']
|
|
@@ -365,9 +368,9 @@ function validateQaSupersession(state,event){
|
|
|
365
368
|
// row. The host re-reads that report under the blocked-evidence rules; here the
|
|
366
369
|
// structural part: the still active, otherwise unclosed latest invocation.
|
|
367
370
|
if(event.incomplete_report!==undefined){
|
|
368
|
-
if(event.incomplete_report!==true||!state.active||state.superseded||!start||complete||start.attempt>=
|
|
371
|
+
if(event.incomplete_report!==true||!state.active||state.superseded||!start||complete||start.attempt>=roundLimit
|
|
369
372
|
||event.workflow!=='cm-ai'||event.node!=='N6'||event.reason!=='host_evidence_problem'
|
|
370
|
-
||event.previous_test_run_id!==start.operation_id
|
|
373
|
+
||event.previous_test_run_id!==start.operation_id||![2,3].includes(event.recovery_rule)
|
|
371
374
|
||!Array.isArray(event.blocked_cases)||event.blocked_cases.length===0||event.blocked_cases.length>start.case_count
|
|
372
375
|
||!caseList(event.blocked_cases,event.blocked_cases.length)
|
|
373
376
|
||!['repository_id','run_id','feature','task','package_digest','qa_decision_id','operation_id','attempt','mode','case_count']
|
|
@@ -379,10 +382,17 @@ function validateQaSupersession(state,event){
|
|
|
379
382
|
// host re-reads its case rows (PASS or host request timeout only); here the
|
|
380
383
|
// structural part: the still active latest invocation and its PASS rows.
|
|
381
384
|
if(event.reason==='host_request_timeout'){
|
|
382
|
-
if(!state.active||state.superseded||!start||complete||start.attempt>=
|
|
385
|
+
if(!state.active||state.superseded||!start||complete||start.attempt>=roundLimit
|
|
383
386
|
||event.workflow!=='cm-ai'||event.node!=='N6'||event.previous_test_run_id!==start.operation_id
|
|
384
|
-
||!Array.isArray(event.timed_out_cases)||event.timed_out_cases.length
|
|
387
|
+
||!Array.isArray(event.timed_out_cases)||event.timed_out_cases.length>start.case_count
|
|
385
388
|
||!caseList(event.timed_out_cases,event.timed_out_cases.length)
|
|
389
|
+
// Q06/Q11: cases the session declared BLOCKED or the host judged BLOCKED for
|
|
390
|
+
// an evidence, environment or cleanup gap before the call stopped.
|
|
391
|
+
||event.host_blocked_cases!==undefined&&(!Array.isArray(event.host_blocked_cases)||event.host_blocked_cases.length===0
|
|
392
|
+
||!caseList(event.host_blocked_cases,event.host_blocked_cases.length)
|
|
393
|
+
||event.host_blocked_cases.some(item=>event.timed_out_cases.includes(item)))
|
|
394
|
+
||event.timed_out_cases.length+(event.host_blocked_cases?.length??0)===0
|
|
395
|
+
||event.timed_out_cases.length+(event.host_blocked_cases?.length??0)>start.case_count
|
|
386
396
|
||JSON.stringify(event.partial_pass_cases)!==JSON.stringify([...state.partialPassCases].sort())
|
|
387
397
|
||event.request_timeout_ms!==undefined&&!(Number.isSafeInteger(event.request_timeout_ms)&&event.request_timeout_ms>0)
|
|
388
398
|
||event.legacy_timeout_attestation!==undefined&&(typeof event.legacy_timeout_attestation!=='string'
|
|
@@ -396,7 +406,7 @@ function validateQaSupersession(state,event){
|
|
|
396
406
|
if(event.reason==='declared_environment_failure'){
|
|
397
407
|
const reason=event.environment_failure_reason;
|
|
398
408
|
if(state.active||state.superseded||!start||!complete||complete.result!=='FAIL'||!(complete.failed>0)
|
|
399
|
-
||start.attempt>=
|
|
409
|
+
||start.attempt>=roundLimit||event.workflow!=='cm-ai'||event.node!=='N6'||event.previous_test_run_id!==start.operation_id
|
|
400
410
|
||!caseList(event.failed_cases,complete.failed)||!caseList(event.blocked_cases,complete.blocked)
|
|
401
411
|
||typeof reason!=='string'||!reason.trim()||Buffer.byteLength(reason,'utf8')>500||/[\r\n\0]/.test(reason)
|
|
402
412
|
||!['repository_id','run_id','feature','task','package_digest','qa_decision_id','operation_id','attempt','mode','case_count']
|
|
@@ -405,7 +415,7 @@ function validateQaSupersession(state,event){
|
|
|
405
415
|
return;
|
|
406
416
|
}
|
|
407
417
|
if(state.active||state.superseded||!start||!complete||complete.result!=='BLOCKED'||complete.failed!==0
|
|
408
|
-
||complete.blocked<=0||start.attempt>=
|
|
418
|
+
||complete.blocked<=0||start.attempt>=roundLimit||event.workflow!=='cm-ai'||event.node!=='N6'
|
|
409
419
|
||event.reason!=='host_evidence_problem'||event.previous_test_run_id!==start.operation_id
|
|
410
420
|
||!Array.isArray(event.blocked_cases)||event.blocked_cases.length!==complete.blocked
|
|
411
421
|
||new Set(event.blocked_cases).size!==event.blocked_cases.length
|
|
@@ -416,7 +426,7 @@ function validateQaSupersession(state,event){
|
|
|
416
426
|
}
|
|
417
427
|
|
|
418
428
|
function loadTestRunState(file,runId){
|
|
419
|
-
let active=false,start=null,complete=null,hasNonPassResult=false,abandoned=false,superseded=false;
|
|
429
|
+
let active=false,start=null,complete=null,hasNonPassResult=false,abandoned=false,superseded=false,freed=0;
|
|
420
430
|
const openCases=new Set(),partialPassCases=new Set();
|
|
421
431
|
for(const value of readJsonLines(file,{strict:true})){
|
|
422
432
|
if(!value||typeof value!=='object'||value.run_id!==runId||value.event!=='test_run'||value.phase===null||value.phase===undefined)continue;
|
|
@@ -426,7 +436,8 @@ function loadTestRunState(file,runId){
|
|
|
426
436
|
throw new UsageError('test_run state log contains a malformed case event');
|
|
427
437
|
if(phase==='complete'&&!active&&!openCases.size)continue;
|
|
428
438
|
if(phase==='abandoned')validateQaAbandonment({active,start,hasNonPassResult,partialPassCases},value);
|
|
429
|
-
if(phase==='superseded')validateQaSupersession({active,start,complete,superseded,partialPassCases},value);
|
|
439
|
+
if(phase==='superseded'){validateQaSupersession({active,start,complete,superseded,partialPassCases,freed},value);
|
|
440
|
+
if(nonProductSupersession(value.reason))freed++;}
|
|
430
441
|
active=applyTestRunTransition(active,openCases,phase,typeof caseId==='string'?caseId:null,value.incomplete_report===true,
|
|
431
442
|
phase==='superseded'&&value.reason==='host_request_timeout');
|
|
432
443
|
if(phase==='start'){start=value;complete=null;hasNonPassResult=false;partialPassCases.clear();abandoned=false;superseded=false;}
|
|
@@ -439,7 +450,7 @@ function loadTestRunState(file,runId){
|
|
|
439
450
|
if(phase==='abandoned')abandoned=true;
|
|
440
451
|
if(phase==='superseded')superseded=true;
|
|
441
452
|
}
|
|
442
|
-
return {active,openCases,start,complete,hasNonPassResult,partialPassCases,abandoned,superseded};
|
|
453
|
+
return {active,openCases,start,complete,hasNonPassResult,partialPassCases,abandoned,superseded,freed};
|
|
443
454
|
}
|
|
444
455
|
|
|
445
456
|
// Read-only reuse of the writer's existing resource/test lifecycle guards by
|