@aibyzero/cm-workflow 0.16.5 → 0.16.7
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 +19 -1
- package/README.md +17 -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 +96 -6
- 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-admission.mjs +34 -10
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +111 -34
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +93 -31
- 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/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +22 -12
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +146 -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 +59 -17
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- 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 +54 -8
- 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/log-rows.mjs +36 -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 +89 -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 +176 -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/finish.mjs +2 -19
- 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/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- 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/js/cm-test/recovery.mjs +4 -4
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +52 -23
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +44 -16
- package/scripts/cm-ai-batch-run.mjs +77 -29
- 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 +73 -28
- package/scripts/cm-ai-drive.test.mjs +119 -1
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-host.mjs +79 -27
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-protected-scope.test.mjs +194 -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 +94 -19
- 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-large-log.test.mjs +113 -0
- 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 +329 -3
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +34 -7
- 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 +26 -6
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- 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-branch-impact.test.mjs +11 -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/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +16 -7
- 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-prd/SKILL.md +5 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
- 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,11 +1,15 @@
|
|
|
1
|
+
import {readExecutionPolicy,readBatchExecutionPolicy,freezeBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
2
|
+
import {readModelJsonRecord} from '../runtime/js/cm-ai/model-configuration-file.mjs';
|
|
3
|
+
import {readExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
|
|
1
4
|
// Trusted in-process batch driver. Task lifecycle and completion remain owned
|
|
2
5
|
// by the existing runner; only transitions between task runs are logged here.
|
|
3
6
|
import fs from 'node:fs';
|
|
4
7
|
import path from 'node:path';
|
|
5
8
|
import {spawnSync} from 'node:child_process';
|
|
6
9
|
import {fileURLToPath} from 'node:url';
|
|
7
|
-
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
10
|
+
import {openControlRun,validateRunDefinition,assertCreatableScope} from './cm-ai-run.mjs';
|
|
8
11
|
import {developmentRetryable,completionRetryable,reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
12
|
+
import {batchOperatorGuidance} from '../runtime/js/cm-ai/operator-guidance.mjs';
|
|
9
13
|
import {digest,json,shape,need,id,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
14
|
import {scanRows,findCmAiQaDecision,latestCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
15
|
import {checkParallelWrite} from './cm-task-gate.mjs';
|
|
@@ -23,21 +27,41 @@ export const batchTaskRunId=(batchId,taskKey)=>`task-${digest({batchId,task:task
|
|
|
23
27
|
// cancel of a parallel group does not end its member runs, so a parallel
|
|
24
28
|
// member cannot be superseded afterwards and only the spec revert applies.
|
|
25
29
|
export function batchMemberResult(result,{parallel=false}={}){
|
|
26
|
-
|
|
30
|
+
const decorate=value=>{
|
|
31
|
+
const guidance=batchOperatorGuidance(value);
|
|
32
|
+
return guidance?Object.freeze({...value,guidance}):value;
|
|
33
|
+
};
|
|
34
|
+
if(result?.pendingAction!=='spec_rebind')return decorate(result);
|
|
27
35
|
const files=/变更文件:([^;]+)/.exec(result.reason??'')?.[1]??'规格文件';
|
|
28
36
|
const revert=`规格已重新批准(变更:${files},只动了其他任务),但批次成员不能换绑。出口:还原这些规格改动并重新批准后继续本批次`;
|
|
29
|
-
return Object.freeze({...result,pendingAction:'none',
|
|
37
|
+
return decorate(Object.freeze({...result,pendingAction:'none',
|
|
30
38
|
reason:parallel?`${revert}。并行组成员没有单独重做的出口。`
|
|
31
|
-
:`${revert};或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务。`});
|
|
39
|
+
:`${revert};或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务。`}));
|
|
32
40
|
}
|
|
33
41
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
34
|
-
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[]}){
|
|
42
|
+
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[],bootstrapKeys=[]}){
|
|
35
43
|
const config=json(configuration);
|
|
36
|
-
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
44
|
+
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
37
45
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
38
46
|
need(typeof executionFor==='function'&&typeof logHome==='string'&&path.isAbsolute(logHome));
|
|
39
47
|
need(Array.isArray(config.tasks)&&config.tasks.length>0&&config.tasks.length<=256);
|
|
40
48
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
49
|
+
if(config.externalModels)readExternalModels(config.externalModels);
|
|
50
|
+
if(config.executionPolicy)readExecutionPolicy(config.executionPolicy);
|
|
51
|
+
const batchGit=(cwd,args,code)=>{
|
|
52
|
+
if((config.externalModels||config.executionPolicy)&&args[0]==='add'&&args[1]==='-A')args=['add','-A','--','.',':!.cm-external-models-v1.json',':!.cm-model-config.lock'];
|
|
53
|
+
if((config.externalModels||config.executionPolicy)&&args[0]==='worktree'&&args[1]==='remove'){
|
|
54
|
+
const file=path.join(args[2],'.cm-external-models-v1.json');
|
|
55
|
+
if(fs.existsSync(file)){
|
|
56
|
+
need(digest(readModelJsonRecord(file).value)===digest({version:1,kind:'cm-external-code-binding',specsDir:config.specsDir}),'external_code_specs_conflict');
|
|
57
|
+
const lock=path.join(args[2],'.cm-model-config.lock');
|
|
58
|
+
if(fs.existsSync(lock)){const stat=fs.lstatSync(lock);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size===0&&(stat.mode&0o077)===0,'invalid_model_configuration_lock');fs.unlinkSync(lock);}
|
|
59
|
+
fs.unlinkSync(file);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const output=git(cwd,args,code);
|
|
63
|
+
return (config.externalModels||config.executionPolicy)&&args[0]==='status'?output.split('\n').filter(line=>!['?? .cm-external-models-v1.json','?? .cm-model-config.lock'].includes(line)).join('\n'):output;
|
|
64
|
+
};
|
|
41
65
|
const plans=new Map();
|
|
42
66
|
for(const task of config.tasks){
|
|
43
67
|
shape(task,['feature','taskId','scope','requirements']);
|
|
@@ -46,6 +70,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
46
70
|
identity:{repositoryId:config.repositoryId,runId:batchTaskRunId(config.batchId,key(task)),
|
|
47
71
|
taskId:task.taskId,attempt:1},scope:task.scope,requirements:task.requirements});
|
|
48
72
|
need(definition.specsDir===config.specsDir&&definition.codeProject===config.codeProject,'invalid_path');
|
|
73
|
+
// A member that will be created is refused before the batch locks, logs or
|
|
74
|
+
// prepares a worktree; an existing member keeps its own recovery path.
|
|
75
|
+
if(!bootstrapKeys.includes(key(task))&&!fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')))
|
|
76
|
+
try{assertCreatableScope(definition.scope);}catch(error){error.reason=`${key(task)}: ${error.reason}`;throw error;}
|
|
49
77
|
plans.set(key(task),definition);
|
|
50
78
|
}
|
|
51
79
|
// Tasks whose second-round answer is not written yet stop after a changes_requested review.
|
|
@@ -172,7 +200,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
172
200
|
need(revision===row.checkpoint&&digest(body)===revision,'batch_checkpoint_mismatch');
|
|
173
201
|
const binding={specsDir:config.specsDir,feature:definition.feature,identity:row.identity,packageDigest:row.package_digest};
|
|
174
202
|
need(findCmAiQaDecision(binding)?.status==='skipped'&&inspectRunClosure(log,definition.identity.runId).closed,'batch_qa_not_ready');
|
|
175
|
-
|
|
203
|
+
batchGit(config.codeProject,['merge-base','--is-ancestor',row.merge_commit,'HEAD'],'batch_merge_history_changed');
|
|
176
204
|
}
|
|
177
205
|
function prepareGroup(group){
|
|
178
206
|
const state=progress(),remaining=group.filter(key=>membership.has(key)&&!state.done.has(key));
|
|
@@ -181,9 +209,9 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
181
209
|
if(!fs.existsSync(worktree)){
|
|
182
210
|
need(!state.ready.has(key),'batch_worktree_missing');
|
|
183
211
|
fs.mkdirSync(path.dirname(worktree),{recursive:true});
|
|
184
|
-
|
|
212
|
+
batchGit(config.codeProject,['worktree','add','-b',branch,worktree,'HEAD'],'batch_worktree_failed');
|
|
185
213
|
}
|
|
186
|
-
need(
|
|
214
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
187
215
|
const definition=plans.get(key);
|
|
188
216
|
plans.set(key,validateRunDefinition({...definition,codeProject:worktree,
|
|
189
217
|
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})}));
|
|
@@ -196,11 +224,11 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
196
224
|
function preserveBlockedMember(row){
|
|
197
225
|
const {worktree,branch}=location(row.from_key);
|
|
198
226
|
need(row.worktree===worktree&&row.branch===branch,'batch_worktree_mismatch');
|
|
199
|
-
|
|
227
|
+
batchGit(config.codeProject,['rev-parse','--verify',`refs/heads/${branch}`],'batch_worktree_missing');
|
|
200
228
|
if(!fs.existsSync(worktree))return;
|
|
201
|
-
need(
|
|
229
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
202
230
|
commitChanges(worktree,taskCommitArgs(plans.get(row.from_key).identity.taskId,taskDescription(config,plans.get(row.from_key)),row.code,row.reason));
|
|
203
|
-
|
|
231
|
+
batchGit(config.codeProject,['worktree','remove',worktree]);
|
|
204
232
|
// Keep the branch: its WIP is evidence, not approved code to merge.
|
|
205
233
|
}
|
|
206
234
|
async function driveMember(key,request){
|
|
@@ -252,31 +280,31 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
252
280
|
}finally{run.close();}
|
|
253
281
|
let intent=progress().merging.get(key);
|
|
254
282
|
if(!intent){
|
|
255
|
-
|
|
256
|
-
if(
|
|
257
|
-
need(
|
|
258
|
-
intent={from_key:key,expected_old:
|
|
283
|
+
batchGit(worktree,['add','-A']);
|
|
284
|
+
if(batchGit(worktree,['status','--porcelain']))batchGit(worktree,['commit',...taskCommitArgs(plans.get(key).identity.taskId,taskDescription(config,plans.get(key)))]);
|
|
285
|
+
need(batchGit(config.codeProject,['status','--porcelain'])==='','batch_main_dirty');
|
|
286
|
+
intent={from_key:key,expected_old:batchGit(config.codeProject,['rev-parse','HEAD']),member_commit:batchGit(worktree,['rev-parse','HEAD'])};
|
|
259
287
|
record('batch_merge_started',intent);
|
|
260
288
|
}
|
|
261
|
-
const current=
|
|
289
|
+
const current=batchGit(config.codeProject,['rev-parse','HEAD']);
|
|
262
290
|
if(current===intent.expected_old){
|
|
263
291
|
const restore=unionAttributes(config.codeProject);
|
|
264
292
|
let result;
|
|
265
293
|
try{result=spawnSync('git',['-C',config.codeProject,'merge','--no-ff','--no-edit',intent.member_commit],gitOptions());}
|
|
266
294
|
finally{restore();}
|
|
267
295
|
if(result.error||result.status!==0){
|
|
268
|
-
const files=
|
|
269
|
-
|
|
270
|
-
need(
|
|
296
|
+
const files=batchGit(config.codeProject,['diff','--name-only','--diff-filter=U']).split('\n').filter(Boolean);
|
|
297
|
+
batchGit(config.codeProject,['merge','--abort'],'batch_merge_abort_failed');
|
|
298
|
+
need(batchGit(config.codeProject,['rev-parse','HEAD'])===intent.expected_old,'batch_merge_history_changed');
|
|
271
299
|
record('batch_merge_conflict',{from_key:key,code:'merge_conflict',files,expected_old:intent.expected_old});
|
|
272
300
|
return {outcome:'blocked',code:'merge_conflict',batchId:config.batchId,files};
|
|
273
301
|
}
|
|
274
302
|
}else{
|
|
275
303
|
// A crash may happen after Git commits but before the handoff log append.
|
|
276
|
-
const parents=
|
|
304
|
+
const parents=batchGit(config.codeProject,['show','-s','--format=%P','HEAD']).split(' ');
|
|
277
305
|
need(parents.length===2&&parents[0]===intent.expected_old&&parents[1]===intent.member_commit,'batch_merge_history_changed');
|
|
278
306
|
}
|
|
279
|
-
const merge_commit=
|
|
307
|
+
const merge_commit=batchGit(config.codeProject,['rev-parse','HEAD']);
|
|
280
308
|
let post_merge_check='skipped';
|
|
281
309
|
if(checkCommands?.length){
|
|
282
310
|
const check=createHostCheck({cwd:config.codeProject,commands:checkCommands,timeoutMs:checkTimeoutMs});
|
|
@@ -291,7 +319,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
291
319
|
const next=[...plans.keys()].find(key=>!done.has(key));need(next,'parallel_final_task_excluded');
|
|
292
320
|
record('batch_handoff',{from_key:key,to_key:next,checkpoint:row.checkpoint,package_digest:row.package_digest,
|
|
293
321
|
identity:row.identity,merge_commit,post_merge_check});
|
|
294
|
-
|
|
322
|
+
batchGit(config.codeProject,['worktree','remove',worktree]);batchGit(config.codeProject,['branch','-d',branch]);
|
|
295
323
|
return null;
|
|
296
324
|
}
|
|
297
325
|
async function parallelGroup(group,request){
|
|
@@ -326,7 +354,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
326
354
|
const terminal=['blocked','failed','unknown'].includes(status.state)
|
|
327
355
|
&&!developmentRetryable(status)&&!completionRetryable(status)
|
|
328
356
|
||status.state==='pending_review'&&status.code!==null&&!reviewRetryable(status);
|
|
329
|
-
if(!terminal){waiting??=status;continue;}
|
|
357
|
+
if(!terminal||config.externalModels||config.executionPolicy){waiting??=status;continue;}
|
|
330
358
|
const key=pending[index];
|
|
331
359
|
record('batch_member_blocked',{from_key:key,code:status.code??status.state,
|
|
332
360
|
reason:status.blockedReason??status.reason??status.code??status.state,...location(key),generation:2});
|
|
@@ -338,8 +366,8 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
338
366
|
return null;
|
|
339
367
|
}
|
|
340
368
|
return Object.freeze({async handle(raw){
|
|
341
|
-
const request=json(raw);shape(request,['operation','requestId']);id(request.requestId);
|
|
342
|
-
need(['advance','status','cancel'].includes(request.operation));
|
|
369
|
+
const request=json(raw);shape(request,['operation','requestId',...(request.operation==='reconcile_review'?['taskKey','invocationId']:[])]);id(request.requestId);
|
|
370
|
+
need(['advance','status','cancel','reconcile_review'].includes(request.operation));
|
|
343
371
|
if(request.operation==='cancel'&&busy){
|
|
344
372
|
cancelled=true;
|
|
345
373
|
if(members.size){record('batch_cancel',{from_key:liveKey});
|
|
@@ -357,9 +385,29 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
357
385
|
try{
|
|
358
386
|
releaseLock=acquireBatchLock(config);
|
|
359
387
|
const initial=progress();liveKey=initial.current;
|
|
388
|
+
const {externalModels:ignoredModels,executionPolicy:ignoredPolicy,...policyBatch}=config;
|
|
389
|
+
const policy=readBatchExecutionPolicy({batch:policyBatch,started:initial.rows.length>0,enabled:!!config.executionPolicy});
|
|
390
|
+
need(digest(policy)===digest(config.executionPolicy??null),'execution_policy_batch_binding');
|
|
391
|
+
if(request.operation!=='status')await freezeBatchExecutionPolicy(policyBatch,policy);
|
|
392
|
+
if(request.operation==='reconcile_review'){
|
|
393
|
+
need((config.externalModels||config.executionPolicy)&&plans.has(request.taskKey),'review_reconciliation_unavailable');id(request.invocationId);
|
|
394
|
+
if(membership.has(request.taskKey)){
|
|
395
|
+
const {worktree,branch}=location(request.taskKey);
|
|
396
|
+
need(fs.existsSync(worktree),'review_reconciliation_unavailable');
|
|
397
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
398
|
+
const definition=plans.get(request.taskKey);
|
|
399
|
+
plans.set(request.taskKey,validateRunDefinition({...definition,codeProject:worktree,
|
|
400
|
+
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})}));
|
|
401
|
+
}
|
|
402
|
+
const definition=plans.get(request.taskKey);
|
|
403
|
+
need(fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')),'review_reconciliation_unavailable');
|
|
404
|
+
const run=await open(request.taskKey);
|
|
405
|
+
try{return await run.host.handle({version:1,operation:'reconcile_review',requestId:request.requestId,identity:definition.identity,invocationId:request.invocationId});}
|
|
406
|
+
finally{run.close();}
|
|
407
|
+
}
|
|
360
408
|
if(initial.stopped)return {outcome:'blocked',code:initial.code??'cancelled',batchId:config.batchId};
|
|
361
409
|
if(request.operation==='advance'&&!initial.rows.length){
|
|
362
|
-
const dirty=
|
|
410
|
+
const dirty=batchGit(config.codeProject,['status','--porcelain']);
|
|
363
411
|
if(dirty)return {outcome:'blocked',code:'batch_main_dirty',batchId:config.batchId,
|
|
364
412
|
reason:`batch_main_dirty\n${dirty}`,files:dirty.split('\n')};
|
|
365
413
|
}
|
|
@@ -424,8 +472,8 @@ function git(cwd,args,code='batch_git_failed'){
|
|
|
424
472
|
need(!result.error&&result.status===0&&result.signal===null,code);return result.stdout.trim();
|
|
425
473
|
}
|
|
426
474
|
function commitChanges(cwd,messageArgs){
|
|
427
|
-
if(!git(cwd,['status','--porcelain']))return null;
|
|
428
|
-
git(cwd,['add','-A']);git(cwd,['commit',...messageArgs]);
|
|
475
|
+
if(!git(cwd,['status','--porcelain']).split('\n').filter(line=>!['?? .cm-external-models-v1.json','?? .cm-model-config.lock'].includes(line)).join('\n'))return null;
|
|
476
|
+
git(cwd,['add','-A','--','.',':!.cm-external-models-v1.json',':!.cm-model-config.lock']);git(cwd,['commit',...messageArgs]);
|
|
429
477
|
return git(cwd,['rev-parse','HEAD']);
|
|
430
478
|
}
|
|
431
479
|
// Keep the original description in the body; only the subject is summarized.
|
|
@@ -130,14 +130,15 @@ test(`approved ${feature} completes T-001 and T-002 with Learning preserved thro
|
|
|
130
130
|
assert.match(fs.readFileSync(path.join(f.specsDir,feature,'tasks.md'),'utf8'),/\[x\] T-002/);
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
test('numbered bootstrap
|
|
133
|
+
test('numbered bootstrap blocks pre-existing non-Learning instructions before dispatch',async t=>{
|
|
134
134
|
const f=fixture(t,'1.bootstrap');
|
|
135
135
|
let run=open(f,'T-001');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
|
|
136
136
|
run=open(f,'T-001','resume');assert.equal((await run.effect('review')).state,'approved');
|
|
137
137
|
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
138
138
|
const agents=path.join(f.codeProject,'AGENTS.md');fs.writeFileSync(agents,'# Existing user rules\n');
|
|
139
139
|
run=open(f,'T-002');const result=await run.effect('develop');run.close();
|
|
140
|
-
assert.equal(result.state,'
|
|
140
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'bootstrap_instruction_conflict');
|
|
141
|
+
assert.equal(result.calls.length,0);
|
|
141
142
|
assert.equal(fs.readFileSync(agents,'utf8'),'# Existing user rules\n');
|
|
142
143
|
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
143
144
|
});
|
|
@@ -3,9 +3,12 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
6
7
|
import {fileURLToPath} from 'node:url';
|
|
7
8
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
8
|
-
import {createHostBootstrap,mergeBootstrapAgents} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
9
|
+
import {createHostBootstrap,mergeBootstrapAgents,validateBootstrapReviewPackage} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
10
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
import {bootstrapReviewRecoverable} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
9
12
|
import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
10
13
|
|
|
11
14
|
const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
|
|
@@ -23,6 +26,120 @@ test('bootstrap AGENTS merge preserves existing Learning bytes and other constra
|
|
|
23
26
|
assert.throws(()=>mergeBootstrapAgents(existing,generated+'## 项目教训\n- changed\n'),{code:'bootstrap_instruction_conflict'});
|
|
24
27
|
});
|
|
25
28
|
|
|
29
|
+
test('approved rule refresh replaces the rule body but preserves Learning bytes',()=>{
|
|
30
|
+
const lesson='## 项目教训\r\n\r\n- **Earlier lesson**:逐字保留。\r\n';
|
|
31
|
+
const existing='# Old rules\r\n\r\n'+lesson;
|
|
32
|
+
const generated='# Updated rules\n\nNew approved invariant.\n';
|
|
33
|
+
assert.equal(mergeBootstrapAgents(existing,generated,{refresh:true}),generated+'\n'+lesson);
|
|
34
|
+
assert.throws(()=>mergeBootstrapAgents(existing,generated+'\n## 项目教训\n- rewritten\n',{refresh:true}),
|
|
35
|
+
{code:'bootstrap_instruction_conflict'});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('bootstrap review requires a changed entry only when the final target differs from its original bytes',()=>{
|
|
39
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt:1};
|
|
40
|
+
const paths=['AGENTS.md','.claude/rules/security.md'];
|
|
41
|
+
const original='a'.repeat(64),updated='b'.repeat(64);
|
|
42
|
+
const configuration={instructionPaths:paths};
|
|
43
|
+
const body={version:1,workflow:'cm-ai',phase:'bootstrap_instructions',identity,invocationId:'fixture-invocation',
|
|
44
|
+
configurationDigest:digest(configuration),files:[
|
|
45
|
+
{path:paths[0],beforeSha256:original,afterSha256:updated},
|
|
46
|
+
{path:paths[1],beforeSha256:original,afterSha256:original}],
|
|
47
|
+
contextFiles:[{scope:'project',path:paths[0],sha256:updated},
|
|
48
|
+
{scope:'project',path:paths[1],sha256:original}]};
|
|
49
|
+
const evidence={...body,evidenceDigest:digest(body)};
|
|
50
|
+
const pkg={scope:paths,changes:[{path:paths[0],before:{sha256:original},after:{sha256:updated}}],
|
|
51
|
+
unchangedScope:[{path:paths[1],sha256:original}]};
|
|
52
|
+
const writeback={outcome:'no_new_lesson'};
|
|
53
|
+
assert.doesNotThrow(()=>validateBootstrapReviewPackage(pkg,evidence,configuration,identity,writeback));
|
|
54
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,changes:[]},evidence,configuration,identity,writeback),
|
|
55
|
+
{code:'bootstrap_review_mismatch'});
|
|
56
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,scope:[paths[0]]},evidence,configuration,identity,writeback),
|
|
57
|
+
{code:'bootstrap_review_mismatch'});
|
|
58
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,unchangedScope:[]},evidence,configuration,identity,writeback),
|
|
59
|
+
{code:'bootstrap_review_mismatch'});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for(const attempt of [1,2])test(`attempt ${attempt} retry may restore a written rule to the original baseline`,()=>{
|
|
63
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt};
|
|
64
|
+
const paths=['AGENTS.md','.claude/rules/security.md'];
|
|
65
|
+
const original='a'.repeat(64),updated='b'.repeat(64);
|
|
66
|
+
const configuration={instructionPaths:paths};
|
|
67
|
+
const body={version:1,workflow:'cm-ai',phase:'bootstrap_instructions',identity,invocationId:'second-attempt',
|
|
68
|
+
configurationDigest:digest(configuration),files:[
|
|
69
|
+
{path:paths[0],beforeSha256:original,afterSha256:updated},
|
|
70
|
+
{path:paths[1],beforeSha256:updated,afterSha256:original}],
|
|
71
|
+
contextFiles:[{scope:'project',path:paths[0],sha256:updated},
|
|
72
|
+
{scope:'project',path:paths[1],sha256:original}]};
|
|
73
|
+
const pkg={scope:paths,changes:[{path:paths[0],before:{sha256:original},after:{sha256:updated}}],
|
|
74
|
+
unchangedScope:[{path:paths[1],sha256:original}]};
|
|
75
|
+
assert.doesNotThrow(()=>validateBootstrapReviewPackage(pkg,{...body,evidenceDigest:digest(body)},
|
|
76
|
+
configuration,identity,{outcome:'no_new_lesson'}));
|
|
77
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,unchangedScope:[{path:paths[1],sha256:updated}]},
|
|
78
|
+
{...body,evidenceDigest:digest(body)},configuration,identity,{outcome:'no_new_lesson'}),
|
|
79
|
+
{code:'bootstrap_review_mismatch'});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('only a completed bootstrap develop with retained passing evidence offers local review recovery',()=>{
|
|
83
|
+
const state={state:'unknown',code:'execution_error',attempt:1,reviewPackage:null,receipt:null,reviewInvocation:null,
|
|
84
|
+
calls:[{terminal:'succeeded'}],currentChecks:[{kind:'command',outcome:'passed',exitCode:0}],
|
|
85
|
+
learningResult:{bootstrap:{files:[]},writeback:{outcome:'no_new_lesson'}},
|
|
86
|
+
cache:[{effect:{kind:'develop',identity:{attempt:1}},result:{state:'unknown',code:'execution_error'}}]};
|
|
87
|
+
const bootstrap={mode:'instructions'};
|
|
88
|
+
assert.equal(bootstrapReviewRecoverable(state,null,bootstrap),true);
|
|
89
|
+
assert.equal(bootstrapReviewRecoverable({...state,reviewPackage:{}},null,bootstrap),false);
|
|
90
|
+
assert.equal(bootstrapReviewRecoverable({...state,currentChecks:[{kind:'command',outcome:'failed',exitCode:1}]},null,bootstrap),false);
|
|
91
|
+
assert.equal(bootstrapReviewRecoverable(state,{kind:'develop'},bootstrap),false);
|
|
92
|
+
assert.equal(bootstrapReviewRecoverable({...state,state:'unknown',code:'reconciliation_required'},null,bootstrap),false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('later same-feature rules task binds clean committed targets and rejects drift',t=>{
|
|
96
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-refresh-')));
|
|
97
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
98
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.bootstrap';
|
|
99
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
100
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Approved fixture\n');
|
|
101
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: 生成骨架 scaffold\n- [x] T-002: 生成 AGENTS.md 与 .claude/ 规则\n- [ ] T-010: 同步 AGENTS.md 与 .claude/ 规则\n');
|
|
102
|
+
const targets=cmInitRuleTargets(selection);
|
|
103
|
+
for(const file of targets){const target=path.join(codeProject,file);fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
104
|
+
fs.writeFileSync(target,file==='AGENTS.md'?'# Existing rules\n\n## 项目教训\n\n- Prior lesson\n':'# Existing rules\n');}
|
|
105
|
+
const git=(...args)=>{const result=spawnSync('git',args,{cwd:codeProject,encoding:'utf8'});
|
|
106
|
+
assert.equal(result.status,0,result.stderr);return result.stdout.trim();};
|
|
107
|
+
git('init','-q');git('config','user.email','fixture@example.test');git('config','user.name','Fixture');
|
|
108
|
+
git('add','--',...targets);git('commit','-qm','Bootstrap rules');
|
|
109
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
110
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt:1};
|
|
111
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:targets,requirements:[]};
|
|
112
|
+
const bootstrap=createHostBootstrap({definition,workflowRoot,selection,bridge:{call:async()=>{throw Error('unused');}},allowWrite:true});
|
|
113
|
+
assert.equal(bootstrap.configuration.committedBasis.commit,git('rev-parse','HEAD'));
|
|
114
|
+
assert.deepEqual(bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}).originals.map(x=>x.path),targets);
|
|
115
|
+
fs.writeFileSync(path.join(codeProject,'.claude/rules/testing.md'),'# Uncommitted change\n');
|
|
116
|
+
assert.throws(()=>bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
117
|
+
{code:'bootstrap_instruction_conflict'});
|
|
118
|
+
git('add','--','.claude/rules/testing.md');
|
|
119
|
+
fs.writeFileSync(path.join(codeProject,'.claude/rules/testing.md'),'# Existing rules\n');
|
|
120
|
+
assert.throws(()=>bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
121
|
+
{code:'bootstrap_instruction_conflict'});
|
|
122
|
+
const unavailable=createHostBootstrap({definition,workflowRoot,selection,
|
|
123
|
+
bridge:{call:async()=>{throw Error('unused');}},allowWrite:true});
|
|
124
|
+
assert.equal(unavailable.configuration.committedBasisRequired,true);
|
|
125
|
+
assert.deepEqual(unavailable.configuration.committedBasis,bootstrap.configuration.committedBasis);
|
|
126
|
+
assert.throws(()=>unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
127
|
+
{code:'bootstrap_instruction_conflict'});
|
|
128
|
+
git('reset','-q','--','.claude/rules/testing.md');
|
|
129
|
+
assert.deepEqual(unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null})
|
|
130
|
+
.originals.map(item=>item.path),targets);
|
|
131
|
+
const marker=path.join(root,'git-config-executed'),driver=path.join(root,'git-driver');
|
|
132
|
+
fs.writeFileSync(driver,`#!/bin/sh\ntouch '${marker}'\ncat\n`,{mode:0o700});
|
|
133
|
+
fs.writeFileSync(path.join(codeProject,'.gitattributes'),'AGENTS.md filter=probe\n');
|
|
134
|
+
git('config','core.fsmonitor',driver);
|
|
135
|
+
git('config','filter.probe.clean',driver);
|
|
136
|
+
git('config','filter.probe.process',driver);
|
|
137
|
+
git('config','filter.probe.required','true');
|
|
138
|
+
assert.deepEqual(unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null})
|
|
139
|
+
.originals.map(item=>item.path),targets);
|
|
140
|
+
assert.equal(fs.existsSync(marker),false);
|
|
141
|
+
});
|
|
142
|
+
|
|
26
143
|
test('numbered approved bootstrap binds fixed rules targets and its own requirements',t=>{
|
|
27
144
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-compat-')));
|
|
28
145
|
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
@@ -4,6 +4,7 @@ import assert from 'node:assert/strict';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import {createHash} from 'node:crypto';
|
|
7
8
|
import {spawn,spawnSync} from 'node:child_process';
|
|
8
9
|
import {fileURLToPath} from 'node:url';
|
|
9
10
|
import {createHostBootstrap} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
@@ -19,90 +20,7 @@ import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
|
19
20
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
20
21
|
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-bootstrap-home-'));
|
|
24
|
-
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
25
|
-
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
26
|
-
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
27
|
-
|
|
28
|
-
const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
|
|
29
|
-
const selection={versionControl:'none',modules:['frontend'],analysis:'Approved synthetic JavaScript project'};
|
|
30
|
-
const checks=()=>Object.fromEntries(['commands','globs','file_references','constraint_preservation','rule_applicability']
|
|
31
|
-
.map(name=>[name,{status:'verified',evidence:'Synthetic semantic report for the local fixture'}]));
|
|
32
|
-
function fixture(t){
|
|
33
|
-
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-')));
|
|
34
|
-
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
35
|
-
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
36
|
-
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,'0.bootstrap'),{recursive:true});fs.mkdirSync(path.join(specsDir,'.reviews'));
|
|
37
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','requirements.md'),'# Requirements\nSynthetic approved scaffold and project instructions.\n');
|
|
38
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','design.md'),'# Design\nJavaScript; no Git; frontend module.\n');
|
|
39
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','tasks.md'),'- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 .claude/ 规范(cm-init)\n');
|
|
40
|
-
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.bootstrap'],specFiles:buildManifest(specsDir)}));
|
|
41
|
-
return {root,codeProject,specsDir,calls:[],reviews:[],businessCalls:0};
|
|
42
|
-
}
|
|
43
|
-
function definition(f,taskId){
|
|
44
|
-
return {version:1,codeProject:f.codeProject,specsDir:f.specsDir,feature:'0.bootstrap',
|
|
45
|
-
identity:{repositoryId:'bootstrap-fixture',runId:'run-'+taskId,taskId,attempt:1},
|
|
46
|
-
scope:taskId==='T-001'?['app.mjs']:[...cmInitRuleTargets(selection)],requirements:[]};
|
|
47
|
-
}
|
|
48
|
-
function reply(f,kind,payload){
|
|
49
|
-
f.calls.push(kind);
|
|
50
|
-
if(kind==='init_generate')return {status:'generated',documents:payload.targets.map(file=>({path:file,
|
|
51
|
-
content:file==='AGENTS.md'&&fs.existsSync(path.join(f.codeProject,file))?fs.readFileSync(path.join(f.codeProject,file),'utf8'):
|
|
52
|
-
file==='.claude/CLAUDE.md'?'# Fixture instructions\n'+payload.targets.filter(p=>p.startsWith('.claude/rules/'))
|
|
53
|
-
.map(p=>'@rules/'+path.basename(p)).join('\n')+'\n':'# Fixture instructions\nUse approved scope.\n'
|
|
54
|
-
// A revision must change the rejected bytes (develop_unchanged_after_review).
|
|
55
|
-
+(payload.bootstrap?.priorReview?'Revised for the review findings.\n':'')}))};
|
|
56
|
-
if(kind==='init_verify')return {checks:checks(),constraintChanges:[],application:{status:'no_relevant_lesson',note:null},
|
|
57
|
-
retrospective:f.lesson&&f.calls.filter(kind=>kind==='init_verify').length===1
|
|
58
|
-
?{status:'lesson_candidate',candidates:[{classification:'structured',trigger:'Bootstrap recovery',
|
|
59
|
-
action:'Preserve reviewed instruction lessons across attempts',evidence:['app.mjs']}],reason:null}
|
|
60
|
-
:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
61
|
-
assert.fail('unexpected host call '+kind);
|
|
62
|
-
}
|
|
63
|
-
function open(f,taskId,mode='create',overrides={}){
|
|
64
|
-
const d=definition(f,taskId),bridge={call:async(kind,payload)=>overrides.reply?overrides.reply(kind,payload):reply(f,kind,payload)};
|
|
65
|
-
const bootstrap=createHostBootstrap({definition:d,workflowRoot,selection:taskId==='T-001'?null:selection,bridge,
|
|
66
|
-
allowWrite:overrides.allowWrite??true});
|
|
67
|
-
const store=openTaskExecutionStore({tasksPath:path.join(f.specsDir,'0.bootstrap','tasks.md'),feature:'bootstrap',specsRoot:f.specsDir,
|
|
68
|
-
identity:{repositoryId:d.identity.repositoryId,runId:d.identity.runId},
|
|
69
|
-
fingerprints:{workflow:digest('bootstrap-test'),config:digest({d,bootstrap:bootstrap.configuration}),inputs:digest(taskId)},create:mode==='create'});
|
|
70
|
-
const developer={provider:'codex',requestedModel:'synthetic',contextId:'scaffold-author',run:createDeveloperRun({provider:'codex',requestedModel:'synthetic',worker:async request=>{
|
|
71
|
-
f.businessCalls++;assert(!request.prompt.includes('"scope":["AGENTS.md"'));
|
|
72
|
-
assert(request.prompt.includes(Buffer.from('JavaScript; no Git; frontend module.').toString('base64').slice(0,12))
|
|
73
|
-
||request.prompt.includes('0.bootstrap/design.md'));
|
|
74
|
-
fs.writeFileSync(path.join(f.codeProject,'app.mjs'),'export const fixture = true;\n');
|
|
75
|
-
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
76
|
-
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
77
|
-
}})};
|
|
78
|
-
const runner=createTaskRunner({root:f.codeProject,identity:d.identity,scope:d.scope,requirements:d.requirements,bootstrap,
|
|
79
|
-
taskLearning:{feature:'0.bootstrap',hostHandoff:true},developer,excludedContexts:['main'],timeoutMs:5000,
|
|
80
|
-
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic-review',allowed:true,available:true,contexts:['review-one','review-two'],
|
|
81
|
-
run:async(request,{onEvent})=>{f.reviews.push(request.payload.reviewPackage);
|
|
82
|
-
onEvent({event:'thread.started',provider_thread:'actual-review-'+request.identity.attempt});
|
|
83
|
-
onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
|
|
84
|
-
onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
85
|
-
const revise=f.requestRevision&&taskId==='T-002'&&request.identity.attempt===1;
|
|
86
|
-
return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
87
|
-
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
|
|
88
|
-
message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
|
|
89
|
-
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],authorize:(request,{authorizationAt})=>{
|
|
90
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
|
|
91
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
92
|
-
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
|
|
93
|
-
decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
94
|
-
return {...body,grantDigest:digest(body)};
|
|
95
|
-
}},
|
|
96
|
-
check:createHostCheck({cwd:f.codeProject,timeoutMs:1000,commands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}]}),
|
|
97
|
-
taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
|
|
98
|
-
persistence:{store,mode,version:3}});
|
|
99
|
-
return {runner,store,definition:d,close:()=>store.close(),effect:(kind,suffix='')=>{
|
|
100
|
-
const identity=runner.status().identity;
|
|
101
|
-
return runner.executeEffect({version:1,id:kind+'-'+identity.attempt+suffix,kind,identity,...(kind==='develop'?{
|
|
102
|
-
learningInput:inspectCmAiTaskLearningInput({specsDir:f.specsDir,codeProject:f.codeProject,feature:'0.bootstrap',identity,
|
|
103
|
-
applicableAgentFiles:[]},{admission:runner.inspectBootstrapAdmission()})}:{})});
|
|
104
|
-
}};
|
|
105
|
-
}
|
|
23
|
+
import {workflowRoot,selection,fixture,definition,reply,open} from './fixtures/bootstrap-review-runner.mjs';
|
|
106
24
|
|
|
107
25
|
function prepareCli(f){
|
|
108
26
|
const config=path.join(f.root,'run.json'),bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
@@ -217,7 +135,7 @@ test('bootstrap denies missing authority before intent and a newly authorized la
|
|
|
217
135
|
});
|
|
218
136
|
|
|
219
137
|
for(const scenario of ['existing-instructions','target-drift'])
|
|
220
|
-
test('rules task preserves files
|
|
138
|
+
test('rules task preserves files on conflict: '+scenario,{timeout:5000},async t=>{
|
|
221
139
|
const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
|
|
222
140
|
// A previously accepted scaffold is test setup, not a second execution path.
|
|
223
141
|
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('[ ] T-001','[x] T-001'));
|
|
@@ -232,11 +150,86 @@ test('rules task preserves files and original unknown outcome: '+scenario,{timeo
|
|
|
232
150
|
}
|
|
233
151
|
return response;
|
|
234
152
|
}});
|
|
235
|
-
const
|
|
153
|
+
const expected=scenario==='existing-instructions'?'blocked':'unknown';
|
|
154
|
+
const result=await run.effect('develop');assert.equal(result.state,expected);run.close();
|
|
155
|
+
if(scenario==='existing-instructions'){
|
|
156
|
+
assert.equal(result.code,'bootstrap_instruction_conflict');
|
|
157
|
+
assert.equal(result.calls.length,0);
|
|
158
|
+
}
|
|
236
159
|
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
237
160
|
assert.match(fs.readFileSync(agents,'utf8'),/user|User/);
|
|
238
161
|
const before=[...f.calls],resumed=open(f,'T-002','resume');
|
|
239
|
-
assert.equal(resumed.runner.status().state,
|
|
162
|
+
assert.equal(resumed.runner.status().state,expected);resumed.close();assert.deepEqual(f.calls,before);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('completed same-feature rules task refreshes committed rules and replays its evidence',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
166
|
+
const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
|
|
167
|
+
fs.appendFileSync(tasks,'- [ ] T-010: 同步 AGENTS.md 与 .claude/ 规则\n');
|
|
168
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.bootstrap'],
|
|
169
|
+
specFiles:buildManifest(f.specsDir)}));
|
|
170
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
171
|
+
f.lesson=true;
|
|
172
|
+
run=open(f,'T-002');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
173
|
+
const git=(...args)=>{const result=spawnSync('git',args,{cwd:f.codeProject,encoding:'utf8'});
|
|
174
|
+
assert.equal(result.status,0,result.stderr);return result.stdout.trim();};
|
|
175
|
+
git('init','-q');git('config','user.email','fixture@example.test');git('config','user.name','Fixture');
|
|
176
|
+
git('add','.');git('commit','-qm','Committed bootstrap rules');
|
|
177
|
+
const previous=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
178
|
+
assert.match(previous,/## 项目教训/);
|
|
179
|
+
const testing=path.join(f.codeProject,'.claude/rules/testing.md');
|
|
180
|
+
const committedTesting=fs.readFileSync(testing,'utf8');
|
|
181
|
+
fs.writeFileSync(testing,'# Staged rules drift\n');git('add','--','.claude/rules/testing.md');
|
|
182
|
+
fs.writeFileSync(testing,committedTesting);
|
|
183
|
+
const callsBefore=f.calls.length;
|
|
184
|
+
run=open(f,'T-010','create');
|
|
185
|
+
const blocked=await run.effect('develop');
|
|
186
|
+
assert.equal(blocked.state,'blocked');assert.equal(blocked.code,'bootstrap_instruction_conflict');
|
|
187
|
+
assert.equal(f.calls.length,callsBefore);run.close();
|
|
188
|
+
git('reset','-q','--','.claude/rules/testing.md');
|
|
189
|
+
run=open(f,'T-010','resume',{reply:(kind,payload)=>{
|
|
190
|
+
const answer=reply(f,kind,payload);
|
|
191
|
+
if(kind==='init_generate')answer.documents=answer.documents.map(document=>({path:document.path,
|
|
192
|
+
content:document.path==='AGENTS.md'?'# Refreshed rules\n\nNew invariant.\n'
|
|
193
|
+
:document.path==='.claude/rules/security.md'?fs.readFileSync(path.join(f.codeProject,document.path),'utf8')
|
|
194
|
+
:document.content+'Refreshed.\n'}));
|
|
195
|
+
return answer;
|
|
196
|
+
}});
|
|
197
|
+
assert.equal((await run.effect('develop','-after-restore')).state,'awaiting_review');
|
|
198
|
+
const pkg=run.runner.status().packageDigest;
|
|
199
|
+
assert(pkg);assert.equal(run.store.snapshot().records.at(-1).payload.checkpoint.reviewPackage.changes.length,5);
|
|
200
|
+
assert.deepEqual(run.store.snapshot().records.at(-1).payload.checkpoint.reviewPackage.unchangedScope,
|
|
201
|
+
[{path:'.claude/rules/security.md',sha256:run.store.snapshot().records.at(-1).payload.checkpoint.learningResult.bootstrap.files
|
|
202
|
+
.find(file=>file.path==='.claude/rules/security.md').afterSha256}]);run.close();
|
|
203
|
+
const refreshed=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
204
|
+
assert.match(refreshed,/# Refreshed rules/);
|
|
205
|
+
assert(refreshed.includes(previous.slice(previous.indexOf('## 项目教训'))));
|
|
206
|
+
run=open(f,'T-010','resume');assert.equal(run.runner.status().state,'awaiting_review');
|
|
207
|
+
assert.equal((await run.effect('review')).state,'approved');
|
|
208
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('bootstrap review mismatch blocks and rejects recovery when handoff content no longer matches',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
212
|
+
const f=fixture(t);
|
|
213
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
214
|
+
const security=path.join(f.codeProject,'.claude/rules/security.md');
|
|
215
|
+
let originalSecurity;
|
|
216
|
+
run=open(f,'T-002','create',{afterCheck:()=>{originalSecurity=fs.readFileSync(security);
|
|
217
|
+
fs.writeFileSync(security,'# Concurrent drift\n');}});
|
|
218
|
+
const blocked=await run.effect('develop');
|
|
219
|
+
assert.equal(blocked.state,'blocked',JSON.stringify(blocked));assert.equal(blocked.code,'bootstrap_review_mismatch');
|
|
220
|
+
assert.equal(run.runner.status().bootstrapReviewRecovery,true);
|
|
221
|
+
const calls=[...f.calls],journalBefore=run.store.snapshot().records.length;
|
|
222
|
+
const evidence=run.store.snapshot().records.at(-1).payload.checkpoint.learningResult.bootstrap;
|
|
223
|
+
const expected=evidence.files.find(file=>file.path==='.claude/rules/security.md').afterSha256;
|
|
224
|
+
run.close();
|
|
225
|
+
fs.writeFileSync(security,originalSecurity);
|
|
226
|
+
assert.equal(createHash('sha256').update(fs.readFileSync(security)).digest('hex'),expected);
|
|
227
|
+
run=open(f,'T-002','resume');
|
|
228
|
+
assert.equal(run.runner.status().state,'blocked');
|
|
229
|
+
const recovered=run.runner.recoverBootstrapReview({allowed:true,reason:'Checked original bootstrap evidence and handoff'});
|
|
230
|
+
assert.equal(recovered.outcome,'rejected');assert.equal(recovered.code,'bootstrap_review_recovery_mismatch');
|
|
231
|
+
assert.equal(run.store.snapshot().records.length,journalBefore);
|
|
232
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
240
233
|
});
|
|
241
234
|
|
|
242
235
|
const ruleHashes=f=>Object.fromEntries(cmInitRuleTargets(selection).map(file=>{
|
|
@@ -60,6 +60,21 @@ test('check output block reaches operator status with paths and resume action',(
|
|
|
60
60
|
assert.equal(result.code,'check_output_out_of_scope');
|
|
61
61
|
assert.equal(result.pendingAction,'resume');
|
|
62
62
|
assert.equal(result.reason,'out_of_scope: build/product');
|
|
63
|
+
assert.equal(result.guidance.recoveryOperation,'advance');assert.match(result.guidance.nextStep,/保留用户改动/);
|
|
64
|
+
assert.equal(f.effects(),0);
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
test('in-flight status explains waiting and never offers abandonment or another developer dispatch',()=>fixture(async f=>{
|
|
68
|
+
f.setStatus('blocked','completion_checks_changed');f.setCompletionBlocks(()=>1);let release;
|
|
69
|
+
const started=new Promise(resolve=>{release=resolve;});let enter;
|
|
70
|
+
const entered=new Promise(resolve=>{enter=resolve;});
|
|
71
|
+
f.setExecutor(async()=>{f.setStatus('unknown','execution_error');enter();await started;return f.status();});
|
|
72
|
+
const entry=f.entry(),active=entry.handle({version:1,operation:'complete',requestId:'complete',identity,packageDigest});await entered;
|
|
73
|
+
const status=await entry.handle(control('status'));
|
|
74
|
+
assert.equal(status.guidance.recoveryOperation,null);assert.match(status.guidance.summary,/仍有操作在执行/);
|
|
75
|
+
assert.equal(f.effects(),1);release();await active;
|
|
76
|
+
const idle=await entry.handle(control('status'));
|
|
77
|
+
assert.match(idle.guidance.nextStep,/只读核对/);assert.equal(f.effects(),1);
|
|
63
78
|
}));
|
|
64
79
|
|
|
65
80
|
test('review package drift reports paths and suppresses refused decision and completion actions',()=>fixture(async f=>{
|