@aibyzero/cm-workflow 0.16.5 → 0.16.6
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/AGENTS.md +14 -0
- package/CHANGELOG.md +7 -0
- package/README.md +11 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +28 -7
- package/docs/js-workflow-control.md +48 -0
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +79 -20
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +1 -4
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +20 -10
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +117 -14
- package/runtime/js/cm-ai/effect-contract.mjs +1 -1
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +70 -20
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +50 -16
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +15 -0
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/review-package.mjs +11 -0
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-runner.mjs +171 -25
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +183 -40
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +25 -6
- package/runtime/js/cm-fix/host.mjs +4 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-publication.mjs +23 -13
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-batch-drive.mjs +50 -21
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +37 -14
- package/scripts/cm-ai-batch-run.mjs +71 -27
- package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
- package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
- package/scripts/cm-ai-bootstrap.test.mjs +80 -87
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
- package/scripts/cm-ai-drive.mjs +59 -25
- package/scripts/cm-ai-drive.test.mjs +97 -1
- package/scripts/cm-ai-host.mjs +64 -24
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
- package/scripts/cm-ai-review-failure.test.mjs +71 -11
- package/scripts/cm-ai-run.mjs +58 -14
- package/scripts/cm-ai-run.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-check-drive.test.mjs +1 -0
- package/scripts/cm-check-runtime.sh +11 -0
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +1 -1
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-fix-drive.mjs +28 -13
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +17 -10
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +21 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +8 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +146 -10
- package/scripts/cm-task-gate.py +1 -0
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +3 -1
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +10 -1
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +13 -5
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +30 -2
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
// Reviewer failures,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Reviewer failures, verdict rules and review race bounds use native
|
|
2
|
+
// driver/host fixtures or production worker/runner fixtures with in-memory
|
|
3
|
+
// transport. Prompt checks build packages directly. No model service is contacted.
|
|
4
4
|
import nodeTest from 'node:test';
|
|
5
5
|
import assert from 'node:assert/strict';
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import {EventEmitter} from 'node:events';
|
|
10
|
+
import {PassThrough} from 'node:stream';
|
|
9
11
|
import {spawnSync} from 'node:child_process';
|
|
10
12
|
import {fileURLToPath} from 'node:url';
|
|
11
13
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
-
import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
14
|
+
import {claudeReviewFingerprint,claudeWorker} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
15
|
+
import {createClaudeReviewRun} from '../runtime/js/cm-ai/claude-review-adapter.mjs';
|
|
16
|
+
import {reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
17
|
+
import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
13
18
|
import {digest,requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
19
|
import {readRunnerHistory,runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
15
20
|
import {inspectProviderReview,inspectProviderReviewFailure} from '../runtime/js/cm-ai/provider-review-observation.mjs';
|
|
@@ -18,8 +23,8 @@ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
|
18
23
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
19
24
|
import {guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
|
|
20
25
|
|
|
21
|
-
//
|
|
22
|
-
//
|
|
26
|
+
// Native V3 runner fixtures require Node 24.14+ on macOS/Linux. Preserve the
|
|
27
|
+
// suite's existing explicit platform gate; only CLI fixtures spawn POSIX shims.
|
|
23
28
|
const skip=!isSupportedExecutionPlatform();
|
|
24
29
|
const test=(name,fn)=>nodeTest(name,{skip},fn);
|
|
25
30
|
|
|
@@ -115,7 +120,55 @@ const apiErrors=[
|
|
|
115
120
|
['model_not_found',404,'model: claude-opus-5 not found','reviewer_model_not_found'],
|
|
116
121
|
];
|
|
117
122
|
for(const [error,status,text,failure] of apiErrors)
|
|
118
|
-
test(`#8 real Claude CLI ${error} ends in a retryable review that names ${failure}`,t=>{
|
|
123
|
+
test(`#8 ${error==='authentication_failed'?'real Claude CLI':'in-process Claude worker'} ${error} ends in a retryable review that names ${failure}`,t=>{
|
|
124
|
+
// The authentication case retains the real driver/host/CLI round trip.
|
|
125
|
+
// These variants still traverse the production worker, adapter and durable
|
|
126
|
+
// runner, but only the transport is in memory; no child or process cleanup.
|
|
127
|
+
if(error!=='authentication_failed')return runnerFixture(t,async f=>{
|
|
128
|
+
const spawned=[],signals=[];
|
|
129
|
+
f.state.review=(request,control)=>{
|
|
130
|
+
const config={cwd:f.root,model:'fixture',cli:'never-run-review-cli'};
|
|
131
|
+
const worker=claudeWorker({...config,timeoutMs:5000,
|
|
132
|
+
preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)},
|
|
133
|
+
killProcess:(pid,signal)=>signals.push({pid,signal}),
|
|
134
|
+
spawnProcess:(cli,args,{stdio,detached})=>{
|
|
135
|
+
const child=new EventEmitter();child.pid=12345;
|
|
136
|
+
child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
|
|
137
|
+
child.kill=signal=>{signals.push({pid:child.pid,signal});return true;};
|
|
138
|
+
let prompt='';child.stdin.on('data',chunk=>prompt+=chunk);
|
|
139
|
+
spawned.push({cli,args,stdio,detached});
|
|
140
|
+
child.stdin.once('finish',()=>queueMicrotask(()=>{
|
|
141
|
+
const marker='<cm-review-data-json>\n',data=JSON.parse(prompt.slice(prompt.indexOf(marker)+marker.length));
|
|
142
|
+
assert.equal(data.reviewPackage.packageDigest,request.payload.reviewPackage.packageDigest);
|
|
143
|
+
const session_id='in-memory-review';
|
|
144
|
+
const messages=[{type:'system',subtype:'init',session_id},
|
|
145
|
+
{type:'assistant',session_id,parent_tool_use_id:null,error,is_api_error_message:true,
|
|
146
|
+
message:{role:'assistant',content:[{type:'text',text}]}},
|
|
147
|
+
{type:'result',subtype:'success',session_id,is_error:true,num_turns:1,result:text,
|
|
148
|
+
terminal_reason:'api_error',api_error_status:status}];
|
|
149
|
+
child.stdout.write(messages.map(JSON.stringify).join('\n')+'\n');
|
|
150
|
+
child.stdout.end();child.stderr.end();child.emit('close',1,null);
|
|
151
|
+
}));
|
|
152
|
+
return child;
|
|
153
|
+
}});
|
|
154
|
+
return createClaudeReviewRun(worker)(request,control);
|
|
155
|
+
};
|
|
156
|
+
const runner=f.make();
|
|
157
|
+
assert.equal((await runner.executeEffect(f.effect('develop'))).state,'awaiting_review');
|
|
158
|
+
const failed=await runner.executeEffect(f.effect('review'));
|
|
159
|
+
assert.equal(failed.state,'pending_review');assert.equal(failed.code,'review_provider_failed');
|
|
160
|
+
assert.equal(reviewRetryable(failed),true);assert.match(failed.reason,new RegExp(`^${failure}: `));
|
|
161
|
+
const result=f.records().findLast(row=>row.payload.type==='review-invocation-result').payload;
|
|
162
|
+
assert.equal(result.outcome,'failed');assert.equal(result.reconciliationRequired,false);
|
|
163
|
+
assert.equal(result.inspection.kind,'cm-provider-review-failure');assert.equal(result.inspection.category,'provider');
|
|
164
|
+
assert.equal(result.inspection.failure,failure);assert.equal(result.observation.result.code,failure);
|
|
165
|
+
assert.deepEqual(result.observation.events.map(event=>event.event),['thread.started','turn.started','process_closed']);
|
|
166
|
+
const history=f.replay();assert.equal(history.state.state,'pending_review');assert.equal(history.state.code,'review_provider_failed');
|
|
167
|
+
assert.equal(history.state.receipts.length,0);assert.deepEqual(f.reopen().status(),failed);
|
|
168
|
+
assert.equal(spawned.length,1);assert.equal(spawned[0].cli,'never-run-review-cli');
|
|
169
|
+
assert.equal(spawned[0].detached,true);assert.deepEqual(spawned[0].stdio,['pipe','pipe','pipe']);
|
|
170
|
+
assert(signals.every(row=>row.pid===-12345),'signals must target only the injected transport');
|
|
171
|
+
},{reviewerProvider:'claude',reviewTimeoutMs:5000});
|
|
119
172
|
const f=fixture(t),packageDigest=f.awaitingReview();
|
|
120
173
|
f.behave({mode:'api_error',error,status,text});
|
|
121
174
|
const failed=f.decide(packageDigest);
|
|
@@ -203,8 +256,15 @@ test('#9 a blocked verdict stays terminal and says why instead of a bare code',t
|
|
|
203
256
|
});
|
|
204
257
|
|
|
205
258
|
test('#9 every reviewer prompt states the verdict rules and what blocked means',t=>{
|
|
206
|
-
|
|
207
|
-
const
|
|
259
|
+
// Prompt content requires a valid package, not a running driver or reviewer.
|
|
260
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-prompt-')));
|
|
261
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
262
|
+
fs.writeFileSync(path.join(root,'target.mjs'),'export const value = 1;\n');
|
|
263
|
+
fs.writeFileSync(path.join(root,'requirements.md'),'# Synthetic requirement\n');
|
|
264
|
+
const baseline=captureReviewBaseline({root,identity,scope:['target.mjs'],requirements:['requirements.md']});
|
|
265
|
+
fs.writeFileSync(path.join(root,'target.mjs'),'export const value = 42;\n');
|
|
266
|
+
const reviewPackage=createReviewPackage({root,baseline,
|
|
267
|
+
checks:[{id:'synthetic',command:['synthetic'],outcome:'passed',exitCode:0,evidence:'Synthetic check'}]});
|
|
208
268
|
for(const provider of ['codex','claude']){
|
|
209
269
|
const request=requestFor({invocationId:'prompt-check',identity,role:'reviewer',provider,requestedModel:'fixture',
|
|
210
270
|
contextId:'cm-conversation-review-1',payload:{reviewPackage,priorReview:null}});
|
|
@@ -327,7 +387,7 @@ const reviewEvents=(onEvent,request,{result=true,close=true}={})=>{
|
|
|
327
387
|
};
|
|
328
388
|
const verdict=(request,value,findings=[])=>({status:'succeeded',value:{verdict:value,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
329
389
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings,summary:'Synthetic'}});
|
|
330
|
-
async function runnerFixture(t,fn,{timeoutMs=1000,reviewTimeoutMs}={}){
|
|
390
|
+
async function runnerFixture(t,fn,{timeoutMs=1000,reviewTimeoutMs,reviewerProvider='codex'}={}){
|
|
331
391
|
const {createTaskRunner}=await import('../runtime/js/cm-ai/task-runner.mjs');
|
|
332
392
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
333
393
|
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-failure-runner-')));
|
|
@@ -346,7 +406,7 @@ async function runnerFixture(t,fn,{timeoutMs=1000,reviewTimeoutMs}={}){
|
|
|
346
406
|
fs.writeFileSync(path.join(root,'code.js'),state.content(request.identity.attempt));return {version:1,invocationId:request.invocationId,
|
|
347
407
|
contextId:request.contextId,provider:request.provider,effectiveModel:'fixture',status:'succeeded',accepted:true,
|
|
348
408
|
result:{outcome:'implemented'}};}},
|
|
349
|
-
reviewers:[{id:'reviewer',adapterId
|
|
409
|
+
reviewers:[{id:'reviewer',adapterId:`${reviewerProvider}-review-adapter`,provider:reviewerProvider,requestedModel:'fixture',allowed:true,
|
|
350
410
|
available:true,contexts:['review-logical-1','review-logical-2'],run:(request,control)=>{dispatches++;return state.review(request,control);}}],
|
|
351
411
|
check:request=>checks(request),
|
|
352
412
|
taskCompletion:{reviewsDir,handoffs:[path.join(reviewsDir,'a1.json'),path.join(reviewsDir,'a2.json')]},
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import {digest as sha} from '../runtime/js/cm-ai/contracts.mjs';
|
|
|
8
8
|
import {resolveCodeProjects,codeProjectPaths,assertCodeProjectSelections} from '../runtime/js/cm-ai/code-projects.mjs';
|
|
9
9
|
import {preQaConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attachment.mjs';
|
|
10
10
|
import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
|
+
import {writeCmAiQaStatus} from '../runtime/js/cm-ai/cm-ai-run-finalizer.mjs';
|
|
11
12
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
12
13
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
13
14
|
import {hasLegacyQaPlanFingerprint,previousQaMaterial,qaConfigurationSlice,qaExecutorMaterial,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
@@ -19,6 +20,7 @@ import {recordEffectAbandonment} from '../runtime/js/cm-ai/effect-abandon-log.mj
|
|
|
19
20
|
import {reviewConsumedHandoff,reviewedHandoffConflict} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
20
21
|
import {RUN_ID_RULE,validRunId} from './cm-log-event.mjs';
|
|
21
22
|
import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
+
import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
22
24
|
|
|
23
25
|
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.';
|
|
24
26
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
@@ -193,9 +195,10 @@ export function assertCreatableRunId(identity){
|
|
|
193
195
|
// Definition is data, never an import path, command, grant or executable callback.
|
|
194
196
|
// legacyQa rebuilds the historical QA executor form for stores created before
|
|
195
197
|
// the built-in plan left the fingerprint; it is never used to create a store.
|
|
196
|
-
export function runConfigMaterial(definition,execution,{parallelSelection=null,bootstrapConfig=null,legacyQa=false}={}){
|
|
198
|
+
export function runConfigMaterial(definition,execution,{parallelSelection=null,bootstrapConfig=null,legacyQa=false,knowledgeCloseout=null}={}){
|
|
197
199
|
if(execution===null)return parallelSelection===null?definition:{definition,parallelSelection};
|
|
198
200
|
return {definition,...(parallelSelection===null?{}:{parallelSelection}),execution:execution.configuration,
|
|
201
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
199
202
|
...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
|
|
200
203
|
...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
|
|
201
204
|
...(execution.hostDecisionProvider?{hostDecisionProvider:{version:1,timeoutMs:execution.hostDecisionProvider.timeoutMs}}:{}),
|
|
@@ -210,14 +213,31 @@ const LEGACY_QA_FINGERPRINT_REASON='运行指纹与当前配置不符。若此
|
|
|
210
213
|
+'(项目 .cm-workflow.yml、~/.cm-workflow/runtimes.yml 与插件内置默认值):把这些配置恢复为创建时的内容即可恢复;'
|
|
211
214
|
+'现在新建的运行不再把这些可变配置写进指纹。否则请核对 run.json、--workflow-config、宿主身份及授权参数是否与创建时一致。';
|
|
212
215
|
|
|
213
|
-
export async function openControlRun(definition,mode,execution=null,
|
|
216
|
+
export async function openControlRun(definition,mode,execution=null,options={}){
|
|
217
|
+
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
218
|
+
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
219
|
+
let guard;
|
|
220
|
+
try{
|
|
221
|
+
const acquire=async()=>{
|
|
222
|
+
const {acquireExternalRunGuard,externalRunGuardExists}=await import('../runtime/js/cm-ai/external-run-guard.mjs');
|
|
223
|
+
const strict=Boolean(execution?.configuration?.externalModels||execution?.configuration?.executionPolicy);
|
|
224
|
+
// Switching this binary to a legacy launch must not bypass an existing strict attempt.
|
|
225
|
+
if(strict||externalRunGuardExists(definition.specsDir,definition.codeProject))guard=acquireExternalRunGuard(definition,{strictOnly:!strict});
|
|
226
|
+
};
|
|
227
|
+
const result=await openControlRunOwned(definition,mode,execution,options,acquire);
|
|
228
|
+
const close=result.close;
|
|
229
|
+
return {...result,close:()=>{try{close();}finally{guard?.close();}}};
|
|
230
|
+
}catch(error){guard?.close();throw error;}
|
|
231
|
+
}
|
|
232
|
+
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,holdRevision=false,specRebindReason=null}={},acquireGuard=async()=>{}){
|
|
214
233
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
215
234
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
216
|
-
const {conversationProtection}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
235
|
+
const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
217
236
|
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
218
237
|
if(mode==='create')assertCreatableRunId(definition?.identity);
|
|
219
238
|
if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
|
|
220
239
|
if(allowAbandonEffect&&mode!=='resume')fail('effect_abandon_unavailable');
|
|
240
|
+
if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
|
|
221
241
|
if(typeof holdRevision!=='boolean')fail('invalid_input');
|
|
222
242
|
if(specRebindReason!==null&&(mode!=='resume'||execution===null||typeof specRebindReason!=='string'||!specRebindReason.trim()
|
|
223
243
|
||Buffer.byteLength(specRebindReason,'utf8')>500||/[\r\n\0]/.test(specRebindReason)))fail('spec_rebind_unavailable');
|
|
@@ -242,6 +262,11 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
242
262
|
if(Object.hasOwn(execution.configuration,'workflow')&&protectedExecutions.has(execution)
|
|
243
263
|
&&sha(execution.configuration.workflow.definition)!==sha(definition))fail('execution_definition_mismatch');
|
|
244
264
|
const conversation=conversationProtection(execution);
|
|
265
|
+
if(execution.configuration.externalModels||execution.configuration.executionPolicy){
|
|
266
|
+
const bound=externalConversationDefinition(execution);
|
|
267
|
+
if(bound===null)fail('external_execution_factory_required');
|
|
268
|
+
if(bound!==sha(definition))fail('execution_definition_mismatch');
|
|
269
|
+
}
|
|
245
270
|
const protection=protectedExecutions.get(execution)??conversation;
|
|
246
271
|
if(conversation&&conversation.definitionDigest!==sha(definition))fail('execution_definition_mismatch');
|
|
247
272
|
if(protection){
|
|
@@ -312,6 +337,8 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
312
337
|
}
|
|
313
338
|
}
|
|
314
339
|
const storeIdentity={repositoryId:identity.repositoryId,runId:identity.runId};
|
|
340
|
+
// Publish new ownership only after execution, admission, selection and baseline validation.
|
|
341
|
+
await acquireGuard();
|
|
315
342
|
// Every fingerprint check below runs against one candidate material and
|
|
316
343
|
// closes its store before the next candidate is tried.
|
|
317
344
|
const openFor=material=>{
|
|
@@ -356,18 +383,27 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
356
383
|
return {material,fingerprints,store,attaching,priorMaterial,chain,attached};
|
|
357
384
|
}catch(error){store.close();throw error;}
|
|
358
385
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
try{opened=openFor(runConfigMaterial(definition,execution,
|
|
365
|
-
catch(
|
|
366
|
-
if(
|
|
367
|
-
|
|
386
|
+
const snapshot=mode==='resume'&&(execution?.documentationProvider||execution?.documentationResult)
|
|
387
|
+
?readExecutionSnapshot({specsRoot:specsDir,identity:storeIdentity}):null;
|
|
388
|
+
let opened,lastMismatch;
|
|
389
|
+
for(const knowledgeCloseout of closeoutPolicyCandidates(execution,mode,snapshot)){
|
|
390
|
+
const materialOptions={parallelSelection,bootstrapConfig,knowledgeCloseout};
|
|
391
|
+
try{opened=openFor(runConfigMaterial(definition,execution,materialOptions));break;}
|
|
392
|
+
catch(error){
|
|
393
|
+
if(mode!=='resume'||error.code!=='fingerprint_mismatch')throw error;
|
|
394
|
+
lastMismatch=error;
|
|
395
|
+
if(!hasLegacyQaPlanFingerprint(execution?.qaExecutor))continue;
|
|
396
|
+
// Preserve the original exact historical QA fingerprint fallback.
|
|
397
|
+
try{opened=openFor(runConfigMaterial(definition,execution,{...materialOptions,legacyQa:true}));break;}
|
|
398
|
+
catch(cause){
|
|
399
|
+
if(cause.code!=='fingerprint_mismatch')throw cause;
|
|
400
|
+
lastMismatch=Object.assign(error,{reason:error.reason?`${error.reason}。${LEGACY_QA_FINGERPRINT_REASON}`:LEGACY_QA_FINGERPRINT_REASON});
|
|
401
|
+
}
|
|
368
402
|
}
|
|
369
403
|
}
|
|
404
|
+
if(!opened)throw lastMismatch;
|
|
370
405
|
const {material:configMaterial,fingerprints,store,attaching,priorMaterial,chain,attached}=opened;
|
|
406
|
+
const knowledgeCloseout=configMaterial.knowledgeCloseout??null;
|
|
371
407
|
try{
|
|
372
408
|
let runnerMode=mode;
|
|
373
409
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
@@ -380,7 +416,10 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
380
416
|
}
|
|
381
417
|
const unavailable=()=>fail('execution_adapter_required');
|
|
382
418
|
const host=createCmAiHost({
|
|
383
|
-
runner:{root:codeProject,identity,scope,requirements,specification,...(selectedRoots?{codeProjectPaths:selectedRoots}:{}),
|
|
419
|
+
runner:{root:codeProject,identity,scope,requirements,specification,...(selectedRoots?{codeProjectPaths:selectedRoots}:{}),
|
|
420
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout}),
|
|
421
|
+
...(execution?.configuration.executionPolicy?{executionPolicy:execution.configuration.executionPolicy}:{}),
|
|
422
|
+
...(execution?.configuration.externalModels?{externalModels:execution.configuration.externalModels}:{}),excludedContexts:['control-host'],
|
|
384
423
|
developer:{provider:'codex',requestedModel:'unconfigured',contextId:'control-developer',run:unavailable},
|
|
385
424
|
reviewers:[],check:unavailable,taskCompletion:{reviewsDir,handoffs},taskLearning:{feature},
|
|
386
425
|
persistence:{store,mode:runnerMode,version:execution===null?2:3},
|
|
@@ -393,7 +432,9 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
393
432
|
...(Object.hasOwn(execution,'verificationGate')?{verificationGate:execution.verificationGate}:{}),
|
|
394
433
|
taskLearning:{feature,hostHandoff:true}})},
|
|
395
434
|
// The entry validates the declaration (single line, with --rerun-blocked-qa) before any durable write.
|
|
396
|
-
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa
|
|
435
|
+
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
|
|
436
|
+
...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
|
|
437
|
+
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
397
438
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
398
439
|
});
|
|
399
440
|
const logAbandonments=()=>{
|
|
@@ -445,6 +486,9 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
445
486
|
revisedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),packageDigest:current.packageDigest??null,
|
|
446
487
|
testRunId:target.testRunId,qaRound:target.qaRound,taskAttempt:current.identity.attempt});
|
|
447
488
|
recordCmAiQaConfigurationRevision(binding,record);
|
|
489
|
+
// Only the newly authorized revision projects a new pending QA phase.
|
|
490
|
+
// Replaying or repairing its audit mirror above is not new execution.
|
|
491
|
+
if(!beforeQa)writeCmAiQaStatus({specsDir,feature,identity:current.identity,phase:'configuration_revised'});
|
|
448
492
|
}
|
|
449
493
|
return {host:{async handle(request){
|
|
450
494
|
if(execution===null&&!['status','cancel'].includes(request.operation)){
|
|
@@ -15,7 +15,7 @@ const request=(operation,requestId=operation)=>({version:1,operation,requestId,i
|
|
|
15
15
|
const platform=process.platform==='darwin'&&Number(process.versions.node.split('.')[0])>=24;
|
|
16
16
|
test('QA attachment projections preserve every non-workflow fingerprint input and validate the immutable record',async()=>{
|
|
17
17
|
const {preQaConfigurations,readQaAttachment}=await import('../runtime/js/cm-ai/qa-attachment.mjs');
|
|
18
|
-
const material={definition:{identity,scope:['a.js'],requirements:['requirements.md']},
|
|
18
|
+
const material={definition:{identity,scope:['a.js'],requirements:['requirements.md']},knowledgeCloseout:{version:1,enabled:true},
|
|
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,
|
|
@@ -28,6 +28,7 @@ test('QA attachment projections preserve every non-workflow fingerprint input an
|
|
|
28
28
|
assert(!Object.hasOwn(withoutWorkflow.execution,'workflow'));
|
|
29
29
|
assert(!Object.hasOwn(withoutWorkflow,'documentationSync'));
|
|
30
30
|
for(const projection of [withoutQa,withoutWorkflow]){
|
|
31
|
+
assert.deepEqual(projection.knowledgeCloseout,material.knowledgeCloseout);
|
|
31
32
|
assert.deepEqual(projection.definition,material.definition);
|
|
32
33
|
assert.deepEqual(projection.execution.review,material.execution.review);
|
|
33
34
|
assert.equal(projection.execution.hostContextId,'host');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fixture,open} from './fixtures/bootstrap-review-runner.mjs';
|
|
6
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
7
|
+
import {runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
8
|
+
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
9
|
+
|
|
10
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
11
|
+
function rechain(records){
|
|
12
|
+
let previousDigest=null;
|
|
13
|
+
for(const row of records){row.previousDigest=previousDigest;const {digest:old,...body}=row;row.digest=digest(body);previousDigest=row.digest;}
|
|
14
|
+
return records;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('legacy unknown bootstrap checkpoint recovers its original package without redispatch',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
18
|
+
const f=fixture(t);
|
|
19
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
20
|
+
run=open(f,'T-002');assert.equal((await run.effect('develop')).state,'awaiting_review');
|
|
21
|
+
const calls=[...f.calls],storePath=path.join(f.specsDir,'.reviews','.execution','run-T-002','state.json');
|
|
22
|
+
const saved=run.store.snapshot(),rows=structuredClone(saved.records),originalPackage=rows.at(-1).payload.checkpoint.reviewPackage;
|
|
23
|
+
assert(originalPackage);run.close();
|
|
24
|
+
// Model the exact older checkpoint shape: the developer succeeded and the
|
|
25
|
+
// host retained checks and Learning evidence, but package validation threw.
|
|
26
|
+
const checkpoint=rows.at(-1).payload.checkpoint;
|
|
27
|
+
checkpoint.state='unknown';checkpoint.code='execution_error';checkpoint.reason=null;checkpoint.reviewPackage=null;
|
|
28
|
+
checkpoint.cache.at(-1).result=runnerStatus(checkpoint,rows[0].payload.config);
|
|
29
|
+
rechain(rows);
|
|
30
|
+
const {revision:oldRevision,...body}=saved,legacy={...body,records:rows};
|
|
31
|
+
assert(oldRevision);
|
|
32
|
+
fs.writeFileSync(storePath,JSON.stringify({...legacy,revision:digest(legacy)})+'\n');
|
|
33
|
+
run=open(f,'T-002','resume');
|
|
34
|
+
assert.equal(run.runner.status().state,'unknown');assert.equal(run.runner.status().bootstrapReviewRecovery,true);
|
|
35
|
+
const entry=createCmAiConversationEntry({specsDir:f.specsDir,codeProject:f.codeProject,feature:'0.bootstrap',
|
|
36
|
+
identity:run.definition.identity,runner:run.runner,allowBootstrapReviewRecovery:true});
|
|
37
|
+
const statusBefore=run.store.snapshot();
|
|
38
|
+
const guidance=(await entry.handle({version:1,operation:'status',requestId:'recovery-status',identity:run.definition.identity})).guidance;
|
|
39
|
+
assert.equal(guidance.recoveryOperation,'bootstrap_review_recover');assert.match(guidance.nextStep,/不重新派发开发/);
|
|
40
|
+
assert.equal(guidance.authorizationGranted,false);assert.deepEqual(run.store.snapshot(),statusBefore);
|
|
41
|
+
const recovery=await entry.handle({version:1,operation:'bootstrap_review_recover',requestId:'recover-bootstrap',
|
|
42
|
+
identity:run.definition.identity,reason:'Original package validation rejected an unchanged rule'});
|
|
43
|
+
assert.equal(recovery.outcome,'advanced',JSON.stringify(recovery));
|
|
44
|
+
assert.equal(recovery.pendingAction,'decision');
|
|
45
|
+
const result=run.runner.status();
|
|
46
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));
|
|
47
|
+
assert.equal(result.packageDigest,originalPackage.packageDigest);
|
|
48
|
+
assert.equal(run.store.snapshot().records.at(-1).payload.type,'bootstrap-review-recovered');
|
|
49
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
50
|
+
run=open(f,'T-002','resume');assert.equal(run.runner.status().state,'awaiting_review');
|
|
51
|
+
assert.equal((await run.effect('review')).state,'approved');
|
|
52
|
+
const completed=await run.effect('complete');assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));run.close();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('instruction bootstrap review material limits never grant a developer redispatch',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
56
|
+
const f=fixture(t);
|
|
57
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
58
|
+
run=open(f,'T-002','create',{afterCheck:()=>{
|
|
59
|
+
fs.mkdirSync(path.join(f.codeProject,'notes'),{recursive:true});
|
|
60
|
+
fs.writeFileSync(path.join(f.codeProject,'notes','AGENTS.md'),'x'.repeat(2100*1024));
|
|
61
|
+
}});
|
|
62
|
+
const result=await run.effect('develop');
|
|
63
|
+
assert.equal(result.state,'unknown',JSON.stringify(result));assert.equal(result.code,'limit_exceeded');
|
|
64
|
+
assert.equal(run.runner.status().bootstrapReviewRecovery,undefined);
|
|
65
|
+
const calls=[...f.calls];run.close();
|
|
66
|
+
run=open(f,'T-002','resume');
|
|
67
|
+
const retry=await run.effect('develop','-retry');
|
|
68
|
+
assert.equal(retry.outcome,'rejected');assert.equal(retry.code,'stage_mismatch');
|
|
69
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
70
|
+
});
|
|
@@ -12,6 +12,7 @@ function fixture(t,exit=0){
|
|
|
12
12
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
13
13
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-check-drive.mjs',
|
|
14
14
|
'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs',
|
|
15
|
+
'runtime/js/cm-ai/operator-guidance.mjs',
|
|
15
16
|
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
16
17
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
17
18
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
@@ -310,8 +310,19 @@ require_file "scripts/cm-openai-compatible-call.py"
|
|
|
310
310
|
require_file "scripts/test-cm-openai-compatible-call.py"
|
|
311
311
|
require_file "scripts/cm-task-gate.mjs"
|
|
312
312
|
require_file "scripts/cm-task-gate.test.mjs"
|
|
313
|
+
require_file "scripts/cm-task-gate-correction.test.mjs"
|
|
314
|
+
HUMAN_CORRECTION_DOC="docs/human-correction.md"
|
|
315
|
+
if [ "$MODE" != "plugin" ]; then
|
|
316
|
+
HUMAN_CORRECTION_DOC="cm-workflow/docs/human-correction.md"
|
|
317
|
+
fi
|
|
318
|
+
require_file "$HUMAN_CORRECTION_DOC"
|
|
313
319
|
require_file "scripts/cm-task-gate.py"
|
|
314
320
|
require_file "scripts/test-task-gate.py"
|
|
321
|
+
for correction_command in prepare-human-correction publish-human-correction-review; do
|
|
322
|
+
grep -Fq "$correction_command" "$ROOT/scripts/cm-task-gate.mjs" &&
|
|
323
|
+
grep -Fq "$correction_command" "$ROOT/$HUMAN_CORRECTION_DOC" ||
|
|
324
|
+
fail "human correction command/document pair incomplete: $correction_command"
|
|
325
|
+
done
|
|
315
326
|
require_file "scripts/cm-workflow-config.mjs"
|
|
316
327
|
require_file "scripts/cm-workflow-config.test.mjs"
|
|
317
328
|
# Group 4: user runtimes.yml producers <-> authoritative consumer.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
const source=fileURLToPath(new URL('..',import.meta.url));
|
|
9
|
+
test('real isolated Claude install checks correction docs at its installed layout and refuses a missing document',
|
|
10
|
+
{skip:process.platform==='win32',timeout:180000},t=>{
|
|
11
|
+
const home=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-claude-install-layout-')));
|
|
12
|
+
t.after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
13
|
+
const target=path.join(home,'.claude'),env={...process.env,HOME:home,CLAUDE_HOME:target,
|
|
14
|
+
CM_WORKFLOW_HOME:path.join(home,'user'),CM_WORKFLOW_LOG_HOME:path.join(home,'logs')};
|
|
15
|
+
const installed=spawnSync('/bin/bash',[path.join(source,'install.sh'),'--yes'],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
|
|
16
|
+
assert.equal(installed.status,0,installed.stdout+installed.stderr);
|
|
17
|
+
assert.match(installed.stdout,/cm runtime check: PASSED \(claude-compat v/);
|
|
18
|
+
const doc=path.join(target,'cm-workflow/docs/human-correction.md');
|
|
19
|
+
assert.equal(fs.readFileSync(doc,'utf8'),fs.readFileSync(path.join(source,'docs/human-correction.md'),'utf8'));
|
|
20
|
+
assert.equal(fs.existsSync(path.join(target,'docs/human-correction.md')),false);
|
|
21
|
+
fs.unlinkSync(doc);
|
|
22
|
+
const rejected=spawnSync('/bin/bash',[path.join(target,'scripts/cm-check-runtime.sh'),'--project',source],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
|
|
23
|
+
assert.notEqual(rejected.status,0);
|
|
24
|
+
assert.match(rejected.stderr,/missing cm-workflow\/docs\/human-correction\.md/);
|
|
25
|
+
assert.match(rejected.stderr,/human correction command\/document pair incomplete/);
|
|
26
|
+
});
|
|
@@ -40,7 +40,7 @@ test('fake Claude process stderr marker yields only its reported model',async()=
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// Darwin fixtures run in the dedicated macOS CI job and were exercised locally.
|
|
44
44
|
// The sink intentionally retains protocol checks, never the decoded body bytes.
|
|
45
45
|
for(const encoding of ['gzip','zstd','br'])test(`Claude probe ${encoding} body reaches only its declared decoder`,
|
|
46
46
|
{skip:process.platform!=='darwin'||(encoding==='zstd'&&typeof zlib.zstdCompressSync!=='function')},async()=>{
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Small metadata fallback for Codex versions without the old optional helpers.
|
|
3
|
+
|
|
4
|
+
Official plugin-creator still owns marketplace registration; Codex CLI validates
|
|
5
|
+
and installs the plugin. This script only reads a marketplace name or updates a
|
|
6
|
+
staged plugin's cache version. It never installs or edits user configuration.
|
|
7
|
+
"""
|
|
8
|
+
import datetime
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def object_pairs(pairs):
|
|
17
|
+
value = {}
|
|
18
|
+
for key, item in pairs:
|
|
19
|
+
if key in value:
|
|
20
|
+
raise ValueError('duplicate JSON key: ' + key)
|
|
21
|
+
value[key] = item
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def read_object(file):
|
|
26
|
+
if file.is_symlink() or not file.is_file():
|
|
27
|
+
raise ValueError('metadata must be a regular non-symlink file')
|
|
28
|
+
value = json.loads(file.read_text(encoding='utf-8'), object_pairs_hook=object_pairs)
|
|
29
|
+
if not isinstance(value, dict):
|
|
30
|
+
raise ValueError('metadata must be a JSON object')
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main(args):
|
|
35
|
+
if len(args) != 2 or args[0] not in ('marketplace-name', 'initialize-marketplace', 'cache-version'):
|
|
36
|
+
raise ValueError('usage: cm-codex-plugin-metadata.py {marketplace-name|initialize-marketplace|cache-version} PATH')
|
|
37
|
+
operation, raw = args
|
|
38
|
+
if operation == 'initialize-marketplace':
|
|
39
|
+
file = Path(raw)
|
|
40
|
+
marketplace = read_object(file)
|
|
41
|
+
if marketplace.get('name') == '[TODO: marketplace-name]':
|
|
42
|
+
plugins = marketplace.get('plugins')
|
|
43
|
+
if not isinstance(plugins, list) or len(plugins) != 1 or not isinstance(plugins[0], dict) or plugins[0].get('name') != 'cm-workflow':
|
|
44
|
+
raise ValueError('initial marketplace must be the official fresh CM scaffold')
|
|
45
|
+
marketplace['name'] = 'personal'
|
|
46
|
+
interface = marketplace.get('interface')
|
|
47
|
+
if isinstance(interface, dict) and interface.get('displayName') == '[TODO: display-name]':
|
|
48
|
+
interface['displayName'] = 'Personal plugins'
|
|
49
|
+
file.write_text(json.dumps(marketplace, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
50
|
+
elif not isinstance(marketplace.get('name'), str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]*', marketplace['name']):
|
|
51
|
+
raise ValueError('initial marketplace requires a valid name or official placeholder')
|
|
52
|
+
return
|
|
53
|
+
if operation == 'marketplace-name':
|
|
54
|
+
name = read_object(Path(raw)).get('name')
|
|
55
|
+
if not isinstance(name, str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]*', name):
|
|
56
|
+
raise ValueError('marketplace requires a valid name')
|
|
57
|
+
print(name)
|
|
58
|
+
return
|
|
59
|
+
root = Path(raw)
|
|
60
|
+
if root.is_symlink() or not root.is_dir():
|
|
61
|
+
raise ValueError('stage must be a real directory')
|
|
62
|
+
file = root / '.codex-plugin' / 'plugin.json'
|
|
63
|
+
if file.parent.is_symlink():
|
|
64
|
+
raise ValueError('manifest parent must be a real directory')
|
|
65
|
+
plugin = read_object(file)
|
|
66
|
+
version = (root / 'VERSION').read_text(encoding='utf-8').strip()
|
|
67
|
+
if plugin.get('name') != 'cm-workflow' or not re.fullmatch(r'\d+\.\d+\.\d+', version):
|
|
68
|
+
raise ValueError('cache version requires a CM plugin and base VERSION')
|
|
69
|
+
if plugin.get('version', '').split('+', 1)[0] != version:
|
|
70
|
+
raise ValueError('manifest base version must match VERSION')
|
|
71
|
+
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d%H%M%S%f')
|
|
72
|
+
fingerprint = hashlib.sha256(file.read_bytes()).hexdigest()[:12]
|
|
73
|
+
plugin['version'] = version + '+codex.' + stamp + '.' + fingerprint
|
|
74
|
+
file.write_text(json.dumps(plugin, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
75
|
+
print(plugin['version'])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == '__main__':
|
|
79
|
+
try:
|
|
80
|
+
main(sys.argv[1:])
|
|
81
|
+
except (ValueError, OSError) as error:
|
|
82
|
+
print('ERROR: ' + str(error), file=sys.stderr)
|
|
83
|
+
raise SystemExit(1)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
const script=fileURLToPath(new URL('./cm-codex-plugin-metadata.py',import.meta.url));
|
|
9
|
+
function fixture(t){
|
|
10
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-plugin-metadata-')));
|
|
11
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
12
|
+
const run=(operation,file)=>spawnSync(process.env.CM_PYTHON_BIN||'python3',[script,operation,file],{encoding:'utf8'});
|
|
13
|
+
return {root,run};
|
|
14
|
+
}
|
|
15
|
+
test('metadata fallback reads marketplace identity without rewriting other plugins or user bytes',t=>{
|
|
16
|
+
const {root,run}=fixture(t),file=path.join(root,'marketplace.json');
|
|
17
|
+
const bytes='{"name":"local-personal","plugins":[{"name":"unrelated"}]}\n';fs.writeFileSync(file,bytes);
|
|
18
|
+
const result=run('marketplace-name',file);assert.equal(result.status,0,result.stderr);assert.equal(result.stdout,'local-personal\n');assert.equal(fs.readFileSync(file,'utf8'),bytes);
|
|
19
|
+
for(const value of ['[]','{"name":"bad@name"}','{"name":"good","name":"other"}']){
|
|
20
|
+
fs.writeFileSync(file,value);assert.equal(run('marketplace-name',file).status,1);
|
|
21
|
+
assert.equal(fs.readFileSync(file,'utf8'),value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
test('cache version fallback keeps manifest contents and source base while yielding distinct build identities',t=>{
|
|
25
|
+
const {root,run}=fixture(t);fs.mkdirSync(path.join(root,'.codex-plugin'));
|
|
26
|
+
const file=path.join(root,'.codex-plugin/plugin.json'),before={name:'cm-workflow',version:'0.16.5',skills:'./skills',interface:{displayName:'CM'}};
|
|
27
|
+
fs.writeFileSync(file,JSON.stringify(before));fs.writeFileSync(path.join(root,'VERSION'),'0.16.5\n');
|
|
28
|
+
const first=run('cache-version',root);assert.equal(first.status,0,first.stderr);
|
|
29
|
+
const after=JSON.parse(fs.readFileSync(file));assert.match(after.version,/^0\.16\.5\+codex\.\d{20}\.[a-f0-9]{12}$/);
|
|
30
|
+
assert.deepEqual({...after,version:before.version},before);assert.equal(fs.readFileSync(path.join(root,'VERSION'),'utf8'),'0.16.5\n');
|
|
31
|
+
const second=run('cache-version',root);assert.equal(second.status,0,second.stderr);assert.notEqual(first.stdout,second.stdout);
|
|
32
|
+
});
|
|
33
|
+
test('metadata fallback rejects unsafe manifests and stages before writing',t=>{
|
|
34
|
+
const {root,run}=fixture(t);fs.mkdirSync(path.join(root,'.codex-plugin'));fs.writeFileSync(path.join(root,'VERSION'),'0.16.5');
|
|
35
|
+
const file=path.join(root,'.codex-plugin/plugin.json');
|
|
36
|
+
for(const data of [{name:'other',version:'0.16.5'},{name:'cm-workflow',version:'0.16.4'}]){
|
|
37
|
+
const bytes=JSON.stringify(data);fs.writeFileSync(file,bytes);assert.equal(run('cache-version',root).status,1);assert.equal(fs.readFileSync(file,'utf8'),bytes);
|
|
38
|
+
}
|
|
39
|
+
const external=path.join(root,'external');fs.writeFileSync(external,'{"name":"cm-workflow","version":"0.16.5"}');
|
|
40
|
+
fs.unlinkSync(file);fs.symlinkSync(external,file);assert.equal(run('cache-version',root).status,1);assert.equal(fs.readFileSync(external,'utf8'),'{"name":"cm-workflow","version":"0.16.5"}');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Uses the same placeholder emitted by the current official creator; installed
|
|
44
|
+
// user names and sibling plugins must not be normalized during an upgrade.
|
|
45
|
+
test('fresh official marketplace placeholder gets a valid personal name while existing identity is preserved',t=>{
|
|
46
|
+
const {root,run}=fixture(t),file=path.join(root,'marketplace.json');
|
|
47
|
+
const seed={name:'[TODO: marketplace-name]',interface:{displayName:'[TODO: display-name]'},plugins:[{name:'cm-workflow',source:{source:'local',path:'./plugins/cm-workflow'}}]};
|
|
48
|
+
fs.writeFileSync(file,JSON.stringify(seed));assert.equal(run('initialize-marketplace',file).status,0);
|
|
49
|
+
assert.equal(run('marketplace-name',file).stdout,'personal\n');
|
|
50
|
+
const initialized=JSON.parse(fs.readFileSync(file));assert.deepEqual(initialized.plugins,seed.plugins);
|
|
51
|
+
const existing=JSON.stringify({name:'existing-personal',plugins:[...seed.plugins,{name:'other'}]});
|
|
52
|
+
fs.writeFileSync(file,existing);assert.equal(run('initialize-marketplace',file).status,0);assert.equal(fs.readFileSync(file,'utf8'),existing);
|
|
53
|
+
seed.plugins.push({name:'other'});const invalid=JSON.stringify(seed);fs.writeFileSync(file,invalid);
|
|
54
|
+
assert.equal(run('initialize-marketplace',file).status,1);assert.equal(fs.readFileSync(file,'utf8'),invalid);
|
|
55
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
7
|
+
const identity={repositoryId:'fixture',runId:'efficiency',taskId:'T-001',attempt:1};
|
|
8
|
+
function fixture(t){const cwd=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-efficiency-check-')));t.after(()=>fs.rmSync(cwd,{recursive:true,force:true}));return cwd;}
|
|
9
|
+
const control=()=>({signal:new AbortController().signal});
|
|
10
|
+
const command=[process.execPath,'-e',"require('node:fs').appendFileSync('executions','x');console.log('tests 3\\npass 3\\nfail 0')"];
|
|
11
|
+
test('declared adjacent identical checks share one execution; final acceptance executes again',async t=>{
|
|
12
|
+
const cwd=fixture(t),output=[],progress=[];
|
|
13
|
+
const check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'tests',command},{id:'ui',command,sameExecutionAs:'tests'}],
|
|
14
|
+
onOutput:value=>{output.push(value.chunk.toString());},onProgress:value=>{progress.push(value);}});
|
|
15
|
+
const rows=await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'x');
|
|
16
|
+
assert.deepEqual(rows.map(r=>r.id),['tests','ui']);assert(rows.every(r=>r.outcome==='passed'));
|
|
17
|
+
assert.match(rows[1].evidence,/same execution as tests;.*tests 3/);assert.equal(output.length,1);
|
|
18
|
+
assert.equal(progress.filter(p=>p.phase==='start').length,1);
|
|
19
|
+
await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'xx');
|
|
20
|
+
});
|
|
21
|
+
test('identical commands without explicit alias continue to execute twice',async t=>{
|
|
22
|
+
const cwd=fixture(t),check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'one',command},{id:'two',command}]});
|
|
23
|
+
await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'xx');
|
|
24
|
+
});
|
|
25
|
+
test('alias requires opt-in, same command, adjacent source and unique identity',t=>{
|
|
26
|
+
const cwd=fixture(t),base=[{id:'one',command},{id:'two',command,sameExecutionAs:'one'}];
|
|
27
|
+
assert.throws(()=>createHostCheck({cwd,commands:base}),/invalid_input/);
|
|
28
|
+
for(const commands of [[base[1]], [base[0],{...base[1],command:[process.execPath,'--version']}],
|
|
29
|
+
[base[0],{id:'other',command},base[1]], [base[0],{...base[1],id:'one'}]])
|
|
30
|
+
assert.throws(()=>createHostCheck({cwd,reuseDeclared:true,commands}));
|
|
31
|
+
assert(!fs.existsSync(path.join(cwd,'executions')));
|
|
32
|
+
});
|
|
33
|
+
test('failed original command is never recycled into a passed alias',async t=>{
|
|
34
|
+
const cwd=fixture(t),fail=[process.execPath,'-e','process.exit(1)'];
|
|
35
|
+
const check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'one',command:fail},{id:'two',command:fail,sameExecutionAs:'one'}]});
|
|
36
|
+
const rows=await check({identity},control());assert.equal(rows.length,1);assert.equal(rows[0].outcome,'failed');
|
|
37
|
+
});
|