@aibyzero/cm-workflow 0.16.9 → 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 +12 -0
- package/README.md +9 -1
- package/VERSION +1 -1
- 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 +101 -84
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- 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-tool-bridge.mjs +3 -0
- 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 +1 -24
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +36 -99
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +62 -38
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +34 -8
- 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 +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +43 -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 +6 -10
- package/scripts/cm-ai-host-fixture.mjs +38 -10
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +19 -18
- 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 +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- 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 +1 -2
- 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 +18 -3
- 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 +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +15 -128
- package/scripts/cm-ai-run.mjs +78 -24
- 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 +3 -10
- 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 +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-worker.test.mjs +5 -3
- 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 +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +91 -19
- package/scripts/cm-patrol.test.mjs +3 -2
- 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/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +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 +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +65 -28
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
|
12
12
|
import {writeCmAiQaStatus} from '../runtime/js/cm-ai/cm-ai-run-finalizer.mjs';
|
|
13
13
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
14
14
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
15
|
+
import {assertControlEntry,withControlPolicyHost,controlTarget,assertExpectedControl,readControlTarget} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
16
|
+
import {readRunnerHistory,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
15
17
|
import {hasLegacyQaPlanFingerprint,previousQaMaterial,qaConfigurationSlice,qaExecutorMaterial,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
16
18
|
import {hasCmAiQaRun,inspectCmAiQaRevisionTarget,recordCmAiQaConfigurationRevision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
17
19
|
import {prepareReviewedEvidenceSupersession,archiveReviewedEvidence,recordEvidenceSupersession,assertNoUnrecordedPriorCode} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
@@ -24,11 +26,22 @@ import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-co
|
|
|
24
26
|
import {protectedScopePaths} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
25
27
|
import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
26
28
|
|
|
27
|
-
const usage='cm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
29
|
+
const usage='cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json (validated read-only history; no owner lock or provider dispatch)\ncm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
28
30
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
29
31
|
// In-process provenance only; a config flag cannot certify protected callbacks.
|
|
30
32
|
const protectedExecutions=new WeakMap();
|
|
31
33
|
|
|
34
|
+
// Launch recovery binds the durable runner projection, while controlTarget on
|
|
35
|
+
// ordinary status may additionally project current QA/specification evidence.
|
|
36
|
+
export function controlLaunchTarget(snapshot){
|
|
37
|
+
const initial=snapshot.records[0]?.payload;
|
|
38
|
+
if(initial?.type!=='init')fail('snapshot_changed');
|
|
39
|
+
const history=readRunnerHistory(snapshot.records,initial.config,initial.version);
|
|
40
|
+
const status=projectedRunnerStatus(history,initial.config);
|
|
41
|
+
return controlTarget({...status,identity:{...initial.config.identity,attempt:status.attempt},
|
|
42
|
+
packageDigest:status.reviewPackage?.packageDigest??null},snapshot);
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// Fixed adapter assembly for a trusted host. The authority callbacks are never
|
|
33
46
|
// sourced from run.json or the JSONL channel. Construction performs no dispatch.
|
|
34
47
|
export async function createCodexExecution(configuration,authority){
|
|
@@ -42,16 +55,10 @@ export async function createCodexExecution(configuration,authority){
|
|
|
42
55
|
need(!['codex-independent-review-1','codex-independent-review-2'].some(value=>
|
|
43
56
|
value===config.hostContextId||value===config.developerContextId),'not_independent');
|
|
44
57
|
validCallTimeout(config.timeoutMs);
|
|
45
|
-
shape(authority,['authorizeDevelopment',
|
|
46
|
-
...['
|
|
47
|
-
need(typeof authority.authorizeDevelopment==='function'
|
|
58
|
+
shape(authority,['authorizeDevelopment',
|
|
59
|
+
...['developmentAttempt','workflow','bootstrap'].filter(key=>Object.hasOwn(authority,key))]);
|
|
60
|
+
need(typeof authority.authorizeDevelopment==='function');
|
|
48
61
|
if(Object.hasOwn(authority,'developmentAttempt'))need([1,2].includes(authority.developmentAttempt),'invalid_development_attempt');
|
|
49
|
-
if(Object.hasOwn(authority,'hostDecisionProvider')){
|
|
50
|
-
shape(authority.hostDecisionProvider,['decide','timeoutMs']);
|
|
51
|
-
need(typeof authority.hostDecisionProvider.decide==='function'
|
|
52
|
-
&&Number.isInteger(authority.hostDecisionProvider.timeoutMs)&&authority.hostDecisionProvider.timeoutMs>0
|
|
53
|
-
&&authority.hostDecisionProvider.timeoutMs<=60000,'invalid_input');
|
|
54
|
-
}
|
|
55
62
|
const disabledSkills=config.disabledSkills??[];
|
|
56
63
|
need(Array.isArray(disabledSkills)&&disabledSkills.length<=4096
|
|
57
64
|
&&disabledSkills.every(p=>typeof p==='string'&&path.isAbsolute(p)&&!/[\n\r\0]/.test(p)),'invalid_review_config');
|
|
@@ -100,15 +107,13 @@ export async function createCodexExecution(configuration,authority){
|
|
|
100
107
|
const execution={
|
|
101
108
|
configuration:config,timeoutMs:config.timeoutMs,excludedContexts:[config.hostContextId],check,
|
|
102
109
|
...(bootstrap?{bootstrap}:{}),
|
|
103
|
-
hostDecision:json(authority.hostDecision),
|
|
104
110
|
...workflowCapabilities,
|
|
105
111
|
...(Object.hasOwn(authority,'developmentAttempt')?{developmentAttempt:authority.developmentAttempt}:{}),
|
|
106
|
-
...(Object.hasOwn(authority,'hostDecisionProvider')?{hostDecisionProvider:authority.hostDecisionProvider}:{}),
|
|
107
112
|
developer:{provider:'codex',requestedModel:config.developerModel,contextId:config.developerContextId,
|
|
108
113
|
run:async(request,control)=>{
|
|
109
114
|
const bound=readCodexDeveloperRequest(request);
|
|
110
115
|
const decision=json(await authority.authorizeDevelopment(bound));
|
|
111
|
-
shape(decision,['status']);need(decision.status==='approved','
|
|
116
|
+
shape(decision,['status']);need(decision.status==='approved','invalid_development_attempt');
|
|
112
117
|
need(!control.signal.aborted,'cancelled');
|
|
113
118
|
need(!used.has(bound.invocationId),'duplicate_dispatch');used.add(bound.invocationId);
|
|
114
119
|
// The runner journals the worker identity around the spawn (develop-worker).
|
|
@@ -134,8 +139,7 @@ export async function createCodexExecution(configuration,authority){
|
|
|
134
139
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:config.reviewerModel,
|
|
135
140
|
allowed:true,available:true,contexts:['codex-independent-review-1','codex-independent-review-2'],
|
|
136
141
|
run:(request,control)=>createCodexReviewRun(codexWorker(reviewOptions))(request,control)}],
|
|
137
|
-
reviewInvocation:{developerThreadId:config.developerContextId,excludedThreadIds:[config.hostContextId],
|
|
138
|
-
authorize:authority.authorizeReview},
|
|
142
|
+
reviewInvocation:{developerThreadId:config.developerContextId,excludedThreadIds:[config.hostContextId],hostContextId:config.hostContextId},
|
|
139
143
|
};
|
|
140
144
|
if(specsRoot!==null){
|
|
141
145
|
// Do not permit later replacement of the developer/check or addition of an
|
|
@@ -228,7 +232,6 @@ export function runConfigMaterial(definition,execution,{parallelSelection=null,b
|
|
|
228
232
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
229
233
|
...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
|
|
230
234
|
...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
|
|
231
|
-
...(execution.hostDecisionProvider?{hostDecisionProvider:{version:1,timeoutMs:execution.hostDecisionProvider.timeoutMs}}:{}),
|
|
232
235
|
...(execution.qaDecisionProvider?{qaDecisionProvider:'host-v1',qaTimeoutMs:execution.qaDecisionProvider.timeoutMs}:{}),
|
|
233
236
|
...(execution.qaExecutor?{qaExecutor:qaExecutorMaterial(execution.qaExecutor,legacyQa)}:{}),
|
|
234
237
|
...(execution.applicableAgentFiles?{applicableAgentFiles:execution.applicableAgentFiles}:{}),
|
|
@@ -236,6 +239,27 @@ export function runConfigMaterial(definition,execution,{parallelSelection=null,b
|
|
|
236
239
|
...(execution.documentationResult?{documentationResult:execution.documentationResult}:{}),
|
|
237
240
|
...(execution.documentationSync?{documentationSync:{version:1,paths:execution.documentationSync.paths}}:{})};
|
|
238
241
|
}
|
|
242
|
+
// Inspect only the validated store envelope. Do not replay old grants or open
|
|
243
|
+
// a writer merely to explain an unsupported historical execution.
|
|
244
|
+
export function inspectRunHistory(definition){
|
|
245
|
+
const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
|
|
246
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
247
|
+
return {identity:snapshot.identity,revision:snapshot.revision,fingerprints:snapshot.fingerprints,
|
|
248
|
+
records:snapshot.records.map(record=>({seq:record.seq,id:record.id,kind:record.kind,type:record.payload.type??null,
|
|
249
|
+
legacyReviewGrant:record.payload.type==='review-invocation-registered'
|
|
250
|
+
&&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))}))};
|
|
251
|
+
}
|
|
252
|
+
export function assertSupportedResumeHistory(definition){
|
|
253
|
+
let snapshot;
|
|
254
|
+
try{snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,
|
|
255
|
+
identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});}
|
|
256
|
+
catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
257
|
+
if(snapshot.records.some(record=>record.payload.type==='review-invocation-registered'
|
|
258
|
+
&&(Object.hasOwn(record.payload,'grant')||Object.hasOwn(record.payload,'authorizationAt'))))
|
|
259
|
+
throw Object.assign(new Error('runner_invocation'),{code:'runner_invocation',
|
|
260
|
+
reason:'旧授权协议不支持恢复。原运行与审查历史已保留;重复原参数不会恢复。只读查看历史:node scripts/cm-ai-run.mjs inspect-history --config RUN_DEFINITION.json(使用原运行定义文件)。'});
|
|
261
|
+
return snapshot;
|
|
262
|
+
}
|
|
239
263
|
const LEGACY_QA_FINGERPRINT_REASON='运行指纹与当前配置不符。若此运行由之前的版本创建,它的指纹还含有当时生效的 CM 配置'
|
|
240
264
|
+'(项目 .cm-workflow.yml、~/.cm-workflow/runtimes.yml 与插件内置默认值):把这些配置恢复为创建时的内容即可恢复;'
|
|
241
265
|
+'现在新建的运行不再把这些可变配置写进指纹。否则请核对 run.json、--workflow-config、宿主身份及授权参数是否与创建时一致。';
|
|
@@ -256,7 +280,7 @@ export async function openControlRun(definition,mode,execution=null,options={}){
|
|
|
256
280
|
return {...result,close:()=>{try{close();}finally{guard?.close();}}};
|
|
257
281
|
}catch(error){guard?.close();throw error;}
|
|
258
282
|
}
|
|
259
|
-
async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null}={},acquireGuard=async()=>{}){
|
|
283
|
+
async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,parallelSelection=null,qaConfigRevision=null,supersedeReason=null,acceptSupersededCodeDrift=false,allowAbandonReview=false,allowAbandonEffect=false,allowBootstrapReviewRecovery=false,allowDevelopRedo=false,holdRevision=false,specRebindReason=null,expectedControl=null}={},acquireGuard=async()=>{}){
|
|
260
284
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
261
285
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
262
286
|
const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
@@ -282,13 +306,27 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
282
306
|
if(typeof rerunUnknownQa!=='boolean'||typeof rerunBlockedQa!=='boolean'||rerunUnknownQa&&rerunBlockedQa
|
|
283
307
|
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
284
308
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
309
|
+
const controlPolicy=execution?.configuration?.controlPolicy??null;
|
|
310
|
+
const launchRecovery=qaConfigRevision!==null||rerunUnknownQa||rerunBlockedQa||specRebindReason!==null;
|
|
311
|
+
if(controlPolicy){
|
|
312
|
+
if(supersedeReason!==null)fail('supersede_unavailable');
|
|
313
|
+
if(launchRecovery){
|
|
314
|
+
if(mode!=='resume')fail('supersede_unavailable');
|
|
315
|
+
if(expectedControl===null)fail('invalid_input');
|
|
316
|
+
expectedControl=readControlTarget(expectedControl);
|
|
317
|
+
}else if(expectedControl!==null)fail('invalid_input');
|
|
318
|
+
}
|
|
319
|
+
if(mode==='resume'){
|
|
320
|
+
const snapshot=assertSupportedResumeHistory(definition);
|
|
321
|
+
if(snapshot?.records.length)assertControlEntry(snapshot,controlPolicy);
|
|
322
|
+
}
|
|
285
323
|
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
286
324
|
const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection,selectedFeature}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
287
325
|
const {captureReviewBaseline}=await import('../runtime/js/cm-ai/review-package.mjs');
|
|
288
326
|
if(execution!==null){
|
|
289
327
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
290
|
-
shape(execution,['configuration','developer','reviewers','reviewInvocation','check','
|
|
291
|
-
...['bootstrap','developmentAttempt','
|
|
328
|
+
shape(execution,['configuration','developer','reviewers','reviewInvocation','check','excludedContexts','timeoutMs',
|
|
329
|
+
...['bootstrap','developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult','documentationSync','verificationGate'].filter(key=>Object.hasOwn(execution,key))]);
|
|
292
330
|
json(execution.configuration);validCallTimeout(execution.timeoutMs);
|
|
293
331
|
if(Object.hasOwn(execution.configuration,'codeProject'))
|
|
294
332
|
if(execution.configuration.codeProject!==definition.codeProject)fail('execution_root_mismatch');
|
|
@@ -444,6 +482,15 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
444
482
|
const {material:configMaterial,fingerprints,store,attaching,priorMaterial,chain,attached}=opened;
|
|
445
483
|
const knowledgeCloseout=configMaterial.knowledgeCloseout??null;
|
|
446
484
|
try{
|
|
485
|
+
// The store owns the actual writer lock. Check before constructing the
|
|
486
|
+
// runner (which may journal a session join), audit repair, or recovery.
|
|
487
|
+
if(controlPolicy&&launchRecovery){
|
|
488
|
+
try{assertExpectedControl(expectedControl,controlLaunchTarget(store.snapshot()));}
|
|
489
|
+
catch(error){
|
|
490
|
+
if(error.code==='snapshot_changed')error.reason='启动恢复目标已经变化;核对当前状态和原操作,不能自动替换原 launchControlTarget 后重试。';
|
|
491
|
+
throw error;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
447
494
|
let runnerMode=mode;
|
|
448
495
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
449
496
|
// Only the genuine, fingerprint-matching empty initializer can be finished.
|
|
@@ -459,6 +506,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
459
506
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
460
507
|
...(execution?.configuration.executionPolicy?{executionPolicy:execution.configuration.executionPolicy}:{}),
|
|
461
508
|
...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
|
|
509
|
+
...(controlPolicy?{controlPolicy}:{}),
|
|
462
510
|
developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
|
|
463
511
|
reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
|
|
464
512
|
persistence:{store,mode:runnerMode,version:execution===null?2:3},
|
|
@@ -474,8 +522,8 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
474
522
|
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
|
|
475
523
|
...(definition.featureSelection?{featureSelection:definition.featureSelection.feature}:{}),
|
|
476
524
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
|
|
477
|
-
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,allowDevelopRedo,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
|
|
478
|
-
...Object.fromEntries(['developmentAttempt','
|
|
525
|
+
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,allowDevelopRedo,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{
|
|
526
|
+
...Object.fromEntries(['developmentAttempt','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
479
527
|
});
|
|
480
528
|
const logAbandonments=()=>{
|
|
481
529
|
for(const record of store.snapshot().records.filter(row=>row.payload.type==='review-invocation-abandoned'))
|
|
@@ -530,7 +578,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
530
578
|
// Replaying or repairing its audit mirror above is not new execution.
|
|
531
579
|
if(!beforeQa)writeCmAiQaStatus({specsDir,feature,identity:current.identity,phase:'configuration_revised'});
|
|
532
580
|
}
|
|
533
|
-
|
|
581
|
+
const legacyHost={async handle(request){
|
|
534
582
|
if(execution===null&&!['status','cancel'].includes(request.operation)){
|
|
535
583
|
// Do not imply an unavailable execution adapter was dispatched.
|
|
536
584
|
return {outcome:'blocked',code:'execution_adapter_required',providerCalls:0};
|
|
@@ -538,7 +586,9 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
538
586
|
const result=await host.handle(request);
|
|
539
587
|
if(['abandon_review','abandon_effect'].includes(request.operation)&&['abandoned','recorded'].includes(result.outcome))logAbandonments();
|
|
540
588
|
return result;
|
|
541
|
-
}}
|
|
589
|
+
}};
|
|
590
|
+
const controlHost=controlPolicy?withControlPolicyHost(legacyHost,{identity,snapshot:()=>store.snapshot(),launchTarget:controlLaunchTarget}):null;
|
|
591
|
+
return {host:legacyHost,...(controlHost?{controlHost}:{}),inspectFixAssociation:host.inspectFixAssociation,acceptCompletedFix:host.acceptCompletedFix,
|
|
542
592
|
checkpoint:()=>store.snapshot().revision,close:()=>store.close()};
|
|
543
593
|
}catch(error){store.close();throw error;}
|
|
544
594
|
}
|
|
@@ -549,6 +599,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
549
599
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
|
|
550
600
|
let run;
|
|
551
601
|
try{
|
|
602
|
+
if(argv.length===3&&argv[0]==='inspect-history'&&argv[1]==='--config'){
|
|
603
|
+
output.write(JSON.stringify(inspectRunHistory(readRunDefinition(argv[2])))+'\n');return 0;
|
|
604
|
+
}
|
|
552
605
|
if(argv.length!==5||argv[0]!=='serve'||argv[1]!=='--config'||argv[3]!=='--mode')fail('invalid_arguments');
|
|
553
606
|
run=await openControlRun(readRunDefinition(argv[2]),argv[4],execution);
|
|
554
607
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
@@ -557,7 +610,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
557
610
|
// Config diagnostics contain field names/reasons, never field values or provider text.
|
|
558
611
|
const code=typeof cause.code==='string'&&(/^[a-z_]+$/.test(cause.code)
|
|
559
612
|
||cause.code.startsWith('invalid_config: '))?cause.code:'control_failed';
|
|
560
|
-
|
|
613
|
+
const reason=code==='runner_invocation'&&typeof cause.reason==='string'?cause.reason:null;
|
|
614
|
+
error.write(JSON.stringify({error:{code,...(reason?{reason}:{})}})+'\n');return 1;
|
|
561
615
|
}finally{run?.close();}
|
|
562
616
|
}
|
|
563
617
|
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -19,8 +19,7 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
|
|
|
19
19
|
execution:{kind:'cm-current-conversation-v1',hostContextId:'host',review:{model:'fixture'},
|
|
20
20
|
workflow:{qa:{commands:[],environment:{}},documentationPaths:['README.md'],applicableAgentFiles:[]}},
|
|
21
21
|
qaExecutor:{version:1,mode:'commands'},qaDecisionProvider:'host-v1',qaTimeoutMs:60000,
|
|
22
|
-
applicableAgentFiles:[],documentationProvider:{version:1,timeoutMs:60000},documentationSync:{version:1,paths:['README.md']},
|
|
23
|
-
hostDecisionProvider:{version:1,timeoutMs:60000},developmentAuthorization:'per-attempt-v1'};
|
|
22
|
+
applicableAgentFiles:[],documentationProvider:{version:1,timeoutMs:60000},documentationSync:{version:1,paths:['README.md']},developmentAuthorization:'per-attempt-v1'};
|
|
24
23
|
const original=structuredClone(material),[withoutQa,withoutWorkflow]=preQaConfigurations(material);
|
|
25
24
|
assert.deepEqual(material,original);
|
|
26
25
|
assert.equal(withoutQa.execution.workflow.qa,null);
|
|
@@ -32,7 +31,6 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
|
|
|
32
31
|
assert.deepEqual(projection.definition,material.definition);
|
|
33
32
|
assert.deepEqual(projection.execution.review,material.execution.review);
|
|
34
33
|
assert.equal(projection.execution.hostContextId,'host');
|
|
35
|
-
assert.deepEqual(projection.hostDecisionProvider,material.hostDecisionProvider);
|
|
36
34
|
assert.equal(projection.developmentAuthorization,material.developmentAuthorization);
|
|
37
35
|
assert(!Object.hasOwn(projection,'qaExecutor'));
|
|
38
36
|
}
|
|
@@ -53,19 +51,20 @@ test('fixed Codex assembly requires review preflight and denies developer dispat
|
|
|
53
51
|
const {requestFor}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
54
52
|
const config={codeProject:f.codeProject,developerModel:'fixture',reviewerModel:'fixture',hostContextId:'main',
|
|
55
53
|
developerContextId:'author',checkCommands:[{id:'check',command:[process.execPath,'--version']}],timeoutMs:1000,reviewerPreflight:null};
|
|
56
|
-
let decisions=0;const authority={authorizeDevelopment:()=>{decisions++;return {status:'denied'};}
|
|
57
|
-
authorizeReview:()=>({status:'denied',code:'permission_denied'}),hostDecision:{status:'denied',code:'permission_denied'}};
|
|
54
|
+
let decisions=0;const authority={authorizeDevelopment:()=>{decisions++;return {status:'denied'};}};
|
|
58
55
|
await assert.rejects(createCodexExecution(config,authority),{code:'tool_preflight_missing'});
|
|
59
56
|
config.reviewerPreflight={passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
60
57
|
config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})};
|
|
61
58
|
const execution=await createCodexExecution(config,authority);assert.equal(decisions,0);
|
|
62
59
|
const request=requestFor({invocationId:'dev-1',identity,role:'developer',provider:'codex',requestedModel:'fixture',
|
|
63
60
|
contextId:'author',payload:{scope:['a.js'],requirements:[],priorReview:null}});
|
|
64
|
-
|
|
61
|
+
let workerEvents=0;
|
|
62
|
+
await assert.rejects(execution.developer.run(request,{signal:new AbortController().signal,onWorker:()=>workerEvents++}),{code:'invalid_development_attempt'});
|
|
63
|
+
assert.equal(workerEvents,0,'denied workflow scope must refuse before worker spawn');
|
|
65
64
|
assert.equal(decisions,1);assert.equal(fs.readFileSync(path.join(f.codeProject,'a.js'),'utf8'),'old\n');
|
|
66
|
-
assert.equal(execution.reviewInvocation
|
|
65
|
+
assert.equal(Object.hasOwn(execution.reviewInvocation,'authorize'),false);
|
|
67
66
|
}));
|
|
68
|
-
for(const [mode,nested] of [...['manual','approved','
|
|
67
|
+
for(const [mode,nested] of [...['manual','approved','blocked','repair','review_limit','spec_drift'].map(mode=>[mode,false]),['approved',true],['blocked',true]])
|
|
69
68
|
test(`trusted host execution uses the same entry and sole gate: ${mode} nested=${nested}`,
|
|
70
69
|
{skip:!platform},()=>fixture(async f=>{
|
|
71
70
|
const {main}=await import('./cm-ai-run.mjs');
|
|
@@ -105,34 +104,11 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
|
|
|
105
104
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:verdict==='changes_requested'
|
|
106
105
|
?[{id:'F1',severity:'P2',path:'a.js',message:'Synthetic repair required',evidence:'First implementation'}]:[],summary:'Synthetic review'}};
|
|
107
106
|
}}],
|
|
108
|
-
reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main'],
|
|
109
|
-
authorize:(request,{authorizationAt})=>{
|
|
110
|
-
assert(['approved','blocked','repair','review_limit','spec_drift'].includes(mode));
|
|
111
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.attempt}`,adapterId:'codex-review-adapter',
|
|
112
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
113
|
-
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
114
|
-
hostContextId:'main',decisionId:`decision-${request.identity.attempt}`,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
115
|
-
return {...body,grantDigest:digest(body)};
|
|
116
|
-
}},
|
|
117
|
-
hostDecision:mode==='awaiting'?null:['approved','blocked','repair','review_limit','spec_drift'].includes(mode)?{status:'approved'}:{status:'denied',code:'permission_denied'},
|
|
107
|
+
reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main']},
|
|
118
108
|
check:createHostCheck({cwd:f.codeProject,commands:[{id:'content',command:[process.execPath,'-e',
|
|
119
109
|
"require('node:assert/strict').match(require('node:fs').readFileSync('a.js','utf8'),/^new( 2)?\\n$/)"]}]})};
|
|
120
|
-
let qaCalls=0,qaRuns=0,docInspections=0,docWrites=0
|
|
110
|
+
let qaCalls=0,qaRuns=0,docInspections=0,docWrites=0;
|
|
121
111
|
const dynamicQa=mode==='approved'&&!nested;
|
|
122
|
-
const dynamicReview=dynamicQa||mode==='repair';
|
|
123
|
-
if(dynamicReview){
|
|
124
|
-
const {createHostReviewAuthority}=await import('../runtime/js/cm-ai/host-review-authority.mjs');
|
|
125
|
-
const authority=createHostReviewAuthority({hostContextId:'main',reviewerId:'reviewer',adapterId:'codex-review-adapter',
|
|
126
|
-
timeoutMs:1000,decide:async(binding,signal)=>{
|
|
127
|
-
reviewDecisions++;await Promise.resolve();assert.equal(signal.aborted,false);
|
|
128
|
-
assert.equal(binding.identity.attempt,reviewDecisions);
|
|
129
|
-
const handoff=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews',`login-T-001-a${binding.identity.attempt}-handoff.json`),'utf8'));
|
|
130
|
-
assert.equal(handoff.status,'ready_for_review');assert.match(binding.packageDigest,/^[a-f0-9]{64}$/);
|
|
131
|
-
return {status:'approved'};
|
|
132
|
-
}});
|
|
133
|
-
execution.hostDecision=null;execution.hostDecisionProvider=authority.hostDecisionProvider;
|
|
134
|
-
execution.reviewInvocation.authorize=authority.authorize;
|
|
135
|
-
}
|
|
136
112
|
if(dynamicQa){
|
|
137
113
|
const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
138
114
|
definition.scope.push('README.md');fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
@@ -189,8 +165,6 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
|
|
|
189
165
|
if(repaired)assert.equal(JSON.parse(stdout).result.identity.attempt,2);
|
|
190
166
|
if(mode==='spec_drift')assert.equal(JSON.parse(stdout).result.code,'spec_drift');
|
|
191
167
|
if(mode==='review_limit')assert.equal(JSON.parse(stdout).result.code,'review_limit');
|
|
192
|
-
if(mode==='denied')assert.equal(JSON.parse(stdout).result.outcome,'denied');
|
|
193
|
-
if(mode==='awaiting')assert.equal(JSON.parse(stdout).result.code,'decision_required');
|
|
194
168
|
assert.equal(fs.readFileSync(path.join(f.specsDir,'1.login','tasks.md'),'utf8').includes('[x]'),completed);
|
|
195
169
|
assert(fs.existsSync(path.join(f.specsDir,'.reviews','login-T-001-a1-handoff.json')));
|
|
196
170
|
assert.equal(f.invoke('resume',[request('status')]).status,1);
|
|
@@ -201,7 +175,6 @@ test(`trusted host execution uses the same entry and sole gate: ${mode} nested=$
|
|
|
201
175
|
{input:resumedInput,output:resumedOutput,error,execution}),0,stderr);
|
|
202
176
|
assert.equal(JSON.parse(resumed).result.state,expected,resumed);
|
|
203
177
|
assert.equal(calls,repaired?2:1);assert.equal(reviews,repaired?2:['approved','blocked','spec_drift'].includes(mode)?1:0);
|
|
204
|
-
if(dynamicReview)assert.equal(reviewDecisions,repaired?2:1,'reopen must not reauthorize completed review');
|
|
205
178
|
if(dynamicQa){
|
|
206
179
|
assert.equal(qaCalls,1);assert.equal(qaRuns,1);assert.equal(docInspections,2);assert.equal(docWrites,1);
|
|
207
180
|
assert.equal(JSON.parse(resumed).result.code,'run_done');
|
|
@@ -400,13 +373,13 @@ test('trusted parallel selection binds admission, Learning, start and resume fin
|
|
|
400
373
|
const learning={specsDir:f.specsDir,codeProject:f.codeProject,feature:'1.login',identity:definition.identity,applicableAgentFiles:[]};
|
|
401
374
|
assert.throws(()=>inspectCmAiTaskLearningInput(learning),{code:'learning_context_invalid'});
|
|
402
375
|
assert.equal(inspectCmAiTaskLearningInput(learning,{parallelSelection}).identity.taskId,'T-002');
|
|
403
|
-
const execution={configuration:{kind:'selection-fixture'},timeoutMs:2000,excludedContexts:['host'],
|
|
376
|
+
const execution={configuration:{kind:'selection-fixture'},timeoutMs:2000,excludedContexts:['host'],
|
|
404
377
|
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.js'),'selected implementation\n');return {status:'succeeded',value:{outcome:'implemented',
|
|
405
378
|
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
406
379
|
check:async()=>[{id:'check',command:['fixture'],outcome:'passed',exitCode:0,evidence:'fixture'}],reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',
|
|
407
380
|
requestedModel:'fixture',allowed:true,available:true,contexts:['review-1','review-2'],
|
|
408
381
|
run:async()=>{throw new Error('no review');}}],
|
|
409
|
-
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']
|
|
382
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']}};
|
|
410
383
|
await assert.rejects(openControlRun(definition,'create',execution),{code:'task_selection_mismatch'});
|
|
411
384
|
await assert.rejects(openControlRun(definition,'create',execution,{parallelSelection:{version:1,group:['T-001','T-003']}}),{code:'task_selection_mismatch'});
|
|
412
385
|
const direct=createCmAiHost({runner:{root:f.codeProject,identity:definition.identity,scope:['a.js'],requirements:['requirements.md'],
|
|
@@ -21,12 +21,12 @@ function fixture(t){
|
|
|
21
21
|
const definition=(runId,taskId='T-001',taskSelection)=>validateRunDefinition({version:1,specsDir,codeProject,feature,
|
|
22
22
|
identity:{repositoryId:'guard-fixture',runId,taskId,attempt:1},scope:['a.mjs'],requirements:[],
|
|
23
23
|
...(taskSelection?{taskSelection}: {})});
|
|
24
|
-
const execution={configuration:{kind:'guard-fixture'},timeoutMs:1000,excludedContexts:['host'],
|
|
24
|
+
const execution={configuration:{kind:'guard-fixture'},timeoutMs:1000,excludedContexts:['host'],
|
|
25
25
|
qaLogHome:path.join(root,'logs'),
|
|
26
26
|
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:async()=>{throw Error('unexpected development');}},
|
|
27
27
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,
|
|
28
28
|
available:true,contexts:['review-one','review-two'],run:async()=>{throw Error('unexpected review');}}],
|
|
29
|
-
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']
|
|
29
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host']},
|
|
30
30
|
check:async()=>{throw Error('unexpected check');}};
|
|
31
31
|
return {root,specsDir,codeProject,feature,definition,execution};
|
|
32
32
|
}
|
|
@@ -41,10 +41,10 @@ function fixture(t){
|
|
|
41
41
|
return {root,definition,codeProject,specsDir,config,review,reviewFile,records,fake,
|
|
42
42
|
env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
|
|
43
43
|
}
|
|
44
|
-
function launch(f,{host='session-A',original,mode='resume',operation='status',review=false}={}){
|
|
44
|
+
function launch(f,{host='session-A',original,mode='resume',operation='status',review=false,hold=false}={}){
|
|
45
45
|
return new Promise((resolve,reject)=>{
|
|
46
46
|
const args=['serve','--config',f.config,'--mode',mode,'--host-context',host,'--allow-development','--review-config',f.reviewFile,
|
|
47
|
-
...(original===undefined?[]:['--original-host-context',original]),...(
|
|
47
|
+
...(original===undefined?[]:['--original-host-context',original]),...(hold?['--hold-revision']:[])];
|
|
48
48
|
const child=spawn(process.execPath,[cli,...args],{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
49
49
|
let buffer='',stderr='';const rows=[];
|
|
50
50
|
const timer=setTimeout(()=>{child.kill();reject(Error('session chain timeout'));},15000);
|
|
@@ -76,11 +76,13 @@ function launch(f,{host='session-A',original,mode='resume',operation='status',re
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,rows,result:rows.find(r=>r.requestId===operation)?.result});});
|
|
79
|
-
|
|
79
|
+
const attempt=fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'))
|
|
80
|
+
?runnerStatus(readRunnerHistory(f.records(),f.records()[0].payload.config,3).state,f.records()[0].payload.config).identity.attempt:1;
|
|
81
|
+
send({version:1,operation,requestId:operation,identity:{...identity,attempt}});
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
const ok=run=>{assert.equal(run.code,0,run.stderr);return run.result;};
|
|
83
|
-
async function created(t){const f=fixture(t);assert.equal(ok(await launch(f,{mode:'create',operation:'
|
|
85
|
+
async function created(t){const f=fixture(t);assert.equal(ok(await launch(f,{mode:'create',operation:'start'})).state,'awaiting_review');return f;}
|
|
84
86
|
async function reviewed(t,host='session-B'){
|
|
85
87
|
const f=await created(t);f.before=f.records().map(row=>JSON.stringify(row));
|
|
86
88
|
assert.equal(ok(await launch(f,{host,original:'session-A',operation:'advance',review:true})).state,'fixture_completed');return f;
|
|
@@ -102,7 +104,7 @@ test('original-host-context on create fails before opening store, including equa
|
|
|
102
104
|
}
|
|
103
105
|
});
|
|
104
106
|
|
|
105
|
-
test('A creates, B
|
|
107
|
+
test('A creates, B runs review, C declaring only A replays the completed run',async t=>{
|
|
106
108
|
const f=await reviewed(t),before=f.records();
|
|
107
109
|
for(const host of ['session-C','session-B','session-A']){
|
|
108
110
|
assert.equal(ok(await launch(f,{host,original:'session-A'})).state,'fixture_completed');
|
|
@@ -110,12 +112,12 @@ test('A creates, B signs review, C declaring only A replays the completed run',a
|
|
|
110
112
|
}
|
|
111
113
|
});
|
|
112
114
|
|
|
113
|
-
test('joining host is journaled once immediately before its
|
|
115
|
+
test('joining host is journaled once immediately before its review binding; old records keep exact bytes',async t=>{
|
|
114
116
|
const f=await reviewed(t),rows=f.records(),joins=rows.filter(r=>r.payload.type==='host-joined');
|
|
115
117
|
assert.equal(joins.length,1);assert.equal(joins[0].kind,'result');
|
|
116
118
|
assert.deepEqual(joins[0].payload,{version:3,protocol:'cm-task-runner',type:'host-joined',hostContextId:'session-B'});
|
|
117
119
|
const index=rows.indexOf(joins[0]);assert.equal(rows[index+1].payload.type,'review-invocation-registered');
|
|
118
|
-
assert.equal(rows[index+1].payload.
|
|
120
|
+
assert.equal(rows[index+1].payload.binding.hostContextId,'session-B');
|
|
119
121
|
assert.deepEqual(rows.slice(0,f.before.length).map(row=>JSON.stringify(row)),f.before);
|
|
120
122
|
for(const host of ['session-B','session-C'])ok(await launch(f,{host,original:'session-A'}));
|
|
121
123
|
assert.deepEqual(f.records(),rows);
|
|
@@ -166,8 +168,9 @@ test('V3 joined-host grammar rejects misplaced, duplicate, durable and extra rec
|
|
|
166
168
|
|
|
167
169
|
test('V3 joined-host grammar rejects an earlier reviewer joining before a later review registration',async t=>{
|
|
168
170
|
const f=await created(t);reviewerResult(f,{thread:'earlier-reviewer',changes:true});
|
|
169
|
-
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
|
|
170
|
-
assert.equal(revised.state,'
|
|
171
|
+
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true,hold:true}));
|
|
172
|
+
assert.equal(revised.state,'changes_requested');assert.equal(revised.code,'revision_answer_required');
|
|
173
|
+
assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
|
|
171
174
|
const rows=f.records(),config=rows[0].payload.config;
|
|
172
175
|
const reviewerThread=rows.find(r=>r.payload.type==='review-invocation-started').payload.providerThreadId;
|
|
173
176
|
const firstIntent=rows.find(r=>r.payload.type==='effect-intent'&&r.payload.effect.kind==='review');
|
|
@@ -188,7 +191,7 @@ test('V3 joined-host grammar rejects an earlier reviewer joining before a later
|
|
|
188
191
|
|
|
189
192
|
test('development after cross-session reopen reports live provider thread without changing init',async t=>{
|
|
190
193
|
const f=fixture(t);ok(await launch(f,{mode:'create'}));const before=f.records();
|
|
191
|
-
assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'
|
|
194
|
+
assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
|
|
192
195
|
const rows=f.records();assert.deepEqual(rows.slice(0,before.length),before);
|
|
193
196
|
assert.deepEqual(rows[0].payload.config.reviewInvocation,{developerThreadId:'cm-conversation-author',excludedThreadIds:['session-A']});
|
|
194
197
|
const call=rows.filter(r=>r.payload.type==='effect-checkpoint').at(-1).payload.checkpoint.calls[0];
|
|
@@ -213,9 +216,9 @@ for(const thread of ['session-A','session-B'])test(`live reviewer cannot be dura
|
|
|
213
216
|
|
|
214
217
|
test('second review excludes earlier joined host even when the current host is C',async t=>{
|
|
215
218
|
const f=await created(t);reviewerResult(f,{changes:true});
|
|
216
|
-
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
|
|
217
|
-
|
|
218
|
-
assert.equal(
|
|
219
|
+
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true,hold:true}));
|
|
220
|
+
assert.equal(revised.state,'changes_requested');assert.equal(revised.code,'revision_answer_required');
|
|
221
|
+
assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'start'})).state,'awaiting_review');
|
|
219
222
|
reviewerResult(f,{thread:'session-B'});
|
|
220
223
|
const result=ok(await launch(f,{host:'session-C',original:'session-A',operation:'advance',review:2}));
|
|
221
224
|
assert.equal(result.state,'unknown');
|
|
@@ -243,7 +246,7 @@ test('runner session chain without CLI reaches B grant and replays it in C',asyn
|
|
|
243
246
|
}};
|
|
244
247
|
const durable=createConversationExecution(f.definition,'session-A',bridge,f.review);
|
|
245
248
|
const execution=(host,allow=false)=>{
|
|
246
|
-
const live=createConversationExecution(f.definition,host,bridge,f.review,
|
|
249
|
+
const live=createConversationExecution(f.definition,host,bridge,f.review,null);
|
|
247
250
|
return {...live,configuration:durable.configuration,excludedContexts:durable.excludedContexts,
|
|
248
251
|
reviewInvocation:{...live.reviewInvocation,excludedThreadIds:durable.reviewInvocation.excludedThreadIds},
|
|
249
252
|
reviewers:live.reviewers.map(reviewer=>({...reviewer,run(request,{onEvent}){
|
|
@@ -258,7 +261,7 @@ test('runner session chain without CLI reaches B grant and replays it in C',asyn
|
|
|
258
261
|
const run=await openControlRun(f.definition,mode,execution(host,allow));
|
|
259
262
|
try{return await run.host.handle({version:1,operation,requestId:operation,identity});}finally{run.close();}
|
|
260
263
|
}
|
|
261
|
-
assert.equal((await session('session-A','create','
|
|
264
|
+
assert.equal((await session('session-A','create','start')).state,'awaiting_review');
|
|
262
265
|
const reviewed=await session('session-B','resume','advance',true);
|
|
263
266
|
assert.equal(reviewed.state,'fixture_completed',JSON.stringify(reviewed));
|
|
264
267
|
assert.equal((await session('session-C','resume','status')).state,'fixture_completed');
|
|
@@ -15,6 +15,7 @@ import {writeSpecsStatus,readSpecsStatus} from '../runtime/js/specs-status.mjs';
|
|
|
15
15
|
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
16
16
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
17
17
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
18
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
18
19
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
19
20
|
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
20
21
|
|
|
@@ -62,15 +63,7 @@ function executionFor(f,{decision=null,onReview=()=>{},onDevelop=()=>{}}={}){
|
|
|
62
63
|
requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'export const a=2;\n');onDevelop();
|
|
63
64
|
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
64
65
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
65
|
-
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
66
|
-
authorize:(request,{authorizationAt})=>{
|
|
67
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.runId}`,
|
|
68
|
-
adapterId:'codex-review-adapter',invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
69
|
-
identity:request.identity,reviewerId:'reviewer',logicalContextId:request.contextId,
|
|
70
|
-
packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'control',decisionId:'approved',
|
|
71
|
-
decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
72
|
-
return {...body,grantDigest:digest(body)};
|
|
73
|
-
}},hostDecision:decision,check:createHostCheck({cwd:f.codeProject,
|
|
66
|
+
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,
|
|
74
67
|
commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]})};
|
|
75
68
|
}
|
|
76
69
|
async function withRun(f,mode,options,run,runId){
|
|
@@ -80,8 +73,8 @@ async function withRun(f,mode,options,run,runId){
|
|
|
80
73
|
const ask=(host,identity,operation,extra={})=>host.handle({version:1,operation,requestId:operation,identity,...extra});
|
|
81
74
|
async function awaitingReview(f){
|
|
82
75
|
return withRun(f,'create',{},async(host,identity)=>{
|
|
83
|
-
const result=await ask(host,identity,'
|
|
84
|
-
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.code,
|
|
76
|
+
const result=await ask(host,identity,'start');
|
|
77
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.code,null);
|
|
85
78
|
return result.packageDigest;
|
|
86
79
|
});
|
|
87
80
|
}
|
|
@@ -96,8 +89,10 @@ test('another task changed and re-approved: status names spec_drift and the rebi
|
|
|
96
89
|
assert.equal(status.state,'awaiting_review');assert.equal(status.code,'spec_drift');
|
|
97
90
|
assert.equal(status.pendingAction,'spec_rebind');
|
|
98
91
|
assert.match(status.reason,/1\.work\/tasks\.md/);assert.match(status.reason,/--rebind-spec-material/);
|
|
99
|
-
const
|
|
100
|
-
|
|
92
|
+
const beforeAction=fs.readFileSync(stateFile(f));
|
|
93
|
+
const decision=await ask(host,identity,'advance');
|
|
94
|
+
assert.deepEqual(fs.readFileSync(stateFile(f)),beforeAction,'spec drift dispatch refusal keeps exact journal bytes');
|
|
95
|
+
assert.equal(decision.outcome,'reported');assert.equal(decision.code,'spec_drift');
|
|
101
96
|
assert.equal(decision.pendingAction,'spec_rebind');
|
|
102
97
|
});
|
|
103
98
|
const before=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records.length;
|
|
@@ -164,7 +159,7 @@ test('a rebind cannot carry changed content: a later content change still drifts
|
|
|
164
159
|
// advertise an action the run would refuse.
|
|
165
160
|
test('a spec change during review never leaves status advertising a refused action',async t=>{
|
|
166
161
|
const f=fixture(t);
|
|
167
|
-
await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'
|
|
162
|
+
await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'start')).state,'awaiting_review'));
|
|
168
163
|
const changeDuringReview=()=>{
|
|
169
164
|
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 审查期间改了\n\n- T-002 依赖 T-001\n');reapprove(f);};
|
|
170
165
|
await withRun(f,'resume',{decision:{status:'approved'},onReview:changeDuringReview},async(host,identity)=>{
|
|
@@ -179,7 +174,8 @@ test('a spec change during review never leaves status advertising a refused acti
|
|
|
179
174
|
test('host CLI accepts the rebind only on resume with a single-line reason',t=>{
|
|
180
175
|
const f=fixture(t),config=path.join(f.root,'run.json'),review=path.join(f.root,'review.json');
|
|
181
176
|
fs.writeFileSync(config,JSON.stringify(f.definition('rebind-cli-run')));
|
|
182
|
-
fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{
|
|
177
|
+
fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
178
|
+
config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})}}));
|
|
183
179
|
const launch=(mode,extra)=>{
|
|
184
180
|
const result=spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context','cli-host',
|
|
185
181
|
'--allow-development','--review-config',review,...extra],{encoding:'utf8',timeout:20000,input:'',
|
|
@@ -209,7 +205,7 @@ test('a run rebound before its first delivery develops against the re-approved s
|
|
|
209
205
|
assert.equal((await ask(host,identity,'advance')).code,'spec_drift');
|
|
210
206
|
});
|
|
211
207
|
await withRun(f,'resume',{specRebindReason:'只改了 T-002'},async(host,identity)=>{
|
|
212
|
-
const result=await ask(host,identity,'
|
|
208
|
+
const result=await ask(host,identity,'start');
|
|
213
209
|
assert.equal(result.state,'awaiting_review',JSON.stringify(result));
|
|
214
210
|
});
|
|
215
211
|
});
|
|
@@ -470,9 +466,9 @@ test('a batch member never advertises spec_rebind and names the real exits',asyn
|
|
|
470
466
|
const batch=()=>createCmAiBatch({configuration:{version:1,repositoryId:'rebind-fixture',batchId:'rebind-batch-1',
|
|
471
467
|
specsDir:f.specsDir,codeProject:f.codeProject,tasks:['T-001','T-002'].map(taskId=>({feature:f.feature,taskId,
|
|
472
468
|
scope:[taskId==='T-001'?'a.mjs':'b.mjs'],requirements:['requirements.md']}))},
|
|
473
|
-
executionFor:async()=>executionFor(f),logHome:path.join(f.root,'batch-logs')});
|
|
469
|
+
executionFor:async()=>({...executionFor(f),check:createHostCheck({cwd:f.codeProject,commands:[{id:'hold',command:[process.execPath,'-e','process.exit(1)']}]})}),logHome:path.join(f.root,'batch-logs')});
|
|
474
470
|
const first=await batch().handle({operation:'advance',requestId:'batch-advance'});
|
|
475
|
-
assert.equal(first.state,'
|
|
471
|
+
assert.equal(first.state,'blocked',JSON.stringify(first));assert.equal(first.code,'develop_checks_not_passed');
|
|
476
472
|
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
477
473
|
const status=await batch().handle({operation:'status',requestId:'batch-status'});
|
|
478
474
|
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {syntheticReviewConfig} from './cm-ai-host-fixture.mjs';
|
|
1
2
|
import test,{after} from 'node:test';
|
|
2
3
|
import assert from 'node:assert/strict';
|
|
3
4
|
import fs from 'node:fs';
|
|
@@ -801,15 +802,7 @@ function executionFor(f,content,verdict='blocked',qaResult=null){
|
|
|
801
802
|
JSON.parse(prompt.split('<cm-developer-data-json>\n')[1]).identity.attempt===1?content:content+'revised\n');
|
|
802
803
|
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
803
804
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
804
|
-
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
805
|
-
authorize:(request,{authorizationAt})=>{
|
|
806
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.runId}`,
|
|
807
|
-
adapterId:'codex-review-adapter',invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
808
|
-
identity:request.identity,reviewerId:'reviewer',logicalContextId:request.contextId,
|
|
809
|
-
packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'control',decisionId:'approved',
|
|
810
|
-
decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
811
|
-
return {...body,grantDigest:digest(body)};
|
|
812
|
-
}},hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,
|
|
805
|
+
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,
|
|
813
806
|
commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]})};
|
|
814
807
|
if(qaResult){
|
|
815
808
|
execution.qaDecisionProvider={timeoutMs:1000,decide:async binding=>({decisionId:'qa-decision',
|
|
@@ -953,7 +946,7 @@ test('host launch prints supersede code drift reason and stderr hint',async()=>{
|
|
|
953
946
|
const definition={version:1,specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,
|
|
954
947
|
identity:identityFor('run-host-new-0002'),scope:['a.mjs'],requirements:['requirements.md']};
|
|
955
948
|
const config=path.join(f.root,'run.json');fs.writeFileSync(config,JSON.stringify(definition));
|
|
956
|
-
const review=path.join(f.root,'review.json');fs.writeFileSync(review,JSON.stringify(
|
|
949
|
+
const review=path.join(f.root,'review.json');fs.writeFileSync(review,JSON.stringify(syntheticReviewConfig(f.codeProject,'claude')));
|
|
957
950
|
const output=new PassThrough(),error=new PassThrough();let stderr='';error.on('data',chunk=>stderr+=chunk);
|
|
958
951
|
assert.equal(await hostMain(['serve','--config',config,'--mode','create','--host-context','fixture-host',
|
|
959
952
|
'--allow-development','--runtime','claude','--review-config',review,'--supersede-reviewed-evidence','--supersede-reason','restart'],
|