@aibyzero/cm-workflow 0.16.2 → 0.16.4
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 +4 -0
- package/CHANGELOG.md +147 -0
- package/README.md +44 -3
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +46 -7
- package/docs/next-steps.md +100 -0
- package/docs/untested-branches.md +24 -18
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +18 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
- package/runtime/js/cm-ai/cm-ai-admission.mjs +7 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
- package/runtime/js/cm-ai/drive-core.mjs +68 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
- package/runtime/js/cm-ai/effect-contract.mjs +4 -3
- package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
- package/runtime/js/cm-ai/host-handoff.mjs +9 -14
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
- package/runtime/js/cm-ai/host-session.mjs +10 -3
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
- package/runtime/js/cm-ai/task-runner.mjs +41 -8
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
- package/runtime/js/cm-fix/cause-package.mjs +21 -0
- package/runtime/js/cm-fix/dossier.mjs +40 -1
- package/runtime/js/cm-fix/execution.mjs +360 -83
- package/runtime/js/cm-fix/host.mjs +7 -3
- package/runtime/js/cm-fix/layout.mjs +14 -6
- package/runtime/js/cm-fix/progress.mjs +14 -0
- package/runtime/js/cm-fix/protected-edits.mjs +1 -1
- package/runtime/js/cm-fix/red-test.mjs +7 -6
- package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
- package/runtime/js/cm-fix/regression.mjs +16 -10
- package/runtime/js/cm-fix/repair.mjs +16 -13
- package/runtime/js/cm-fix/test-author.mjs +2 -1
- package/runtime/js/cm-fix/test-extension.mjs +45 -0
- package/runtime/js/cm-prd/accepted-design.mjs +28 -9
- package/runtime/js/cm-prd/analysis.mjs +68 -16
- package/runtime/js/cm-prd/change.mjs +21 -1
- package/runtime/js/cm-prd/draft-save.mjs +96 -2
- package/runtime/js/cm-prd/failed-correction.mjs +51 -0
- package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
- package/runtime/js/cm-prd/review-correction.mjs +3 -0
- package/runtime/js/cm-prd/review-disposition.mjs +33 -15
- package/runtime/js/cm-prd/review-findings.mjs +2 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -0
- package/runtime/js/cm-prd/review-preparation.mjs +28 -1
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
- package/runtime/js/cm-prd/session.mjs +5 -5
- package/runtime/js/cm-prd/split-design.mjs +67 -0
- package/runtime/js/cm-prd/summary.mjs +57 -10
- package/runtime/js/cm-refactor/workflow.mjs +100 -19
- package/runtime/js/specs-status.mjs +6 -2
- package/scripts/cm-ai-admission.mjs +2 -0
- package/scripts/cm-ai-batch-drive.mjs +251 -0
- package/scripts/cm-ai-batch-drive.test.mjs +159 -0
- package/scripts/cm-ai-batch-host.mjs +13 -5
- package/scripts/cm-ai-batch-host.test.mjs +25 -0
- package/scripts/cm-ai-contracts.test.mjs +30 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
- package/scripts/cm-ai-drive.mjs +335 -0
- package/scripts/cm-ai-drive.test.mjs +258 -0
- package/scripts/cm-ai-fix-integration.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +48 -20
- package/scripts/cm-ai-host.test.mjs +79 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
- package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
- package/scripts/cm-ai-review-timeout.test.mjs +30 -0
- package/scripts/cm-ai-run.mjs +59 -11
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
- package/scripts/cm-ai-session-chain.test.mjs +261 -0
- package/scripts/cm-ai-supersede.test.mjs +320 -0
- package/scripts/cm-check-drive.mjs +94 -0
- package/scripts/cm-check-drive.test.mjs +78 -0
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +103 -0
- package/scripts/cm-check-runtime.sh +15 -6
- package/scripts/cm-claude-developer-worker.test.mjs +40 -1
- package/scripts/cm-claude-probe.test.mjs +117 -2
- package/scripts/cm-claude-review-stream.test.mjs +43 -0
- package/scripts/cm-fix-abandon.test.mjs +383 -0
- package/scripts/cm-fix-cause-package.test.mjs +31 -1
- package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
- package/scripts/cm-fix-drive.mjs +168 -0
- package/scripts/cm-fix-drive.test.mjs +117 -0
- package/scripts/cm-fix-escalation.test.mjs +214 -0
- package/scripts/cm-fix-execution.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +4 -2
- package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
- package/scripts/cm-fix-qa-source.test.mjs +3 -3
- package/scripts/cm-fix-session-chain.test.mjs +244 -0
- package/scripts/cm-fix-test-extension.test.mjs +246 -0
- package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
- package/scripts/cm-host-handoff.test.mjs +37 -0
- package/scripts/cm-idea-drive.mjs +99 -0
- package/scripts/cm-idea-drive.test.mjs +50 -0
- package/scripts/cm-init-drive.mjs +191 -0
- package/scripts/cm-init-drive.test.mjs +59 -0
- package/scripts/cm-log-event.mjs +9 -0
- package/scripts/cm-prd-completion.test.mjs +30 -2
- package/scripts/cm-prd-design-phase.test.mjs +355 -15
- package/scripts/cm-prd-drive.mjs +314 -0
- package/scripts/cm-prd-drive.test.mjs +164 -0
- package/scripts/cm-prd-host.mjs +46 -17
- package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
- package/scripts/cm-prd-review-disposition.test.mjs +133 -7
- package/scripts/cm-prd-review-gate.mjs +23 -4
- package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
- package/scripts/cm-prd-summary.test.mjs +79 -4
- package/scripts/cm-refactor-drive.mjs +237 -0
- package/scripts/cm-refactor-drive.test.mjs +77 -0
- package/scripts/cm-refactor-gaps.test.mjs +276 -0
- package/scripts/cm-refactor-host.test.mjs +1 -48
- package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
- package/scripts/cm-specs-status.test.mjs +19 -0
- package/scripts/cm-test-drive.mjs +132 -0
- package/scripts/cm-test-drive.test.mjs +91 -0
- package/scripts/cm-test-session.test.mjs +117 -0
- package/scripts/correction-check.test.mjs +38 -0
- package/scripts/fixtures/claude-model-marker.mjs +6 -0
- package/scripts/fixtures/claude-review-process.mjs +7 -0
- package/scripts/fixtures/cm-refactor.mjs +56 -0
- package/scripts/test-shell-compat.sh +67 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -0
- package/skills/cm-ai/references/N8-finish.md +1 -0
- package/skills/cm-ai/references/js-host.md +85 -3
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +4 -2
- package/skills/cm-fix/SKILL.md +11 -4
- package/skills/cm-fix/references/js-host.md +67 -2
- package/skills/cm-fix/references/test-extension.md +57 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-prd/SKILL.md +8 -8
- package/skills/cm-prd/references/js-change-recovery.md +71 -0
- package/skills/cm-prd/references/js-host.md +64 -2
- package/skills/cm-prd/references/spec-self-check.md +14 -2
- package/skills/cm-refactor/SKILL.md +5 -0
- package/skills/cm-refactor/references/js-batch.md +3 -1
- package/skills/cm-refactor/references/js-host.md +49 -0
- package/skills/cm-test/references/js-host.md +5 -0
- package/skills/cm-test/references/unit-coverage.md +2 -2
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// cm-ai host 的单步驾驶员。PLAN 路径相对 PLAN 文件;命令仅在 codeProject 内执行。
|
|
3
|
+
// 请求表来自 host-session.mjs operationNames(传输允许集)、host-conversation-execution.mjs
|
|
4
|
+
// developer/check/verificationGate、host-workflow-capabilities.mjs QA/文档接线、
|
|
5
|
+
// host-qa-executor.mjs logic/browser 和 host-documentation.mjs sync、
|
|
6
|
+
// host-qa-fix-owner.mjs fix_* 转发 cm-fix。保守预检整个 operation 可达的反问。
|
|
7
|
+
// operation possible host_request kinds; proving route
|
|
8
|
+
// advance develop, check; workflow adds documentation_sync,
|
|
9
|
+
// qa_assess, qa_logic, qa_browser, documentation_inspect;
|
|
10
|
+
// auto QA-fix adds fix_* below.
|
|
11
|
+
// cm-ai-conversation-entry.mjs advance -> start/complete/qa/finish;
|
|
12
|
+
// host-conversation-execution.mjs + host-workflow-capabilities.mjs.
|
|
13
|
+
// start/resume develop, check; cm-ai-conversation-entry.mjs start/resume
|
|
14
|
+
// -> runner.executeEffect and host-conversation-execution.mjs.
|
|
15
|
+
// complete check; cm-ai-conversation-entry.mjs complete -> executeEffect.
|
|
16
|
+
// qa qa_assess; cm-ai-conversation-entry.mjs qa
|
|
17
|
+
// -> host-workflow-capabilities.mjs QA policy.
|
|
18
|
+
// finish/run_finalize documentation_inspect; cm-ai-conversation-entry.mjs
|
|
19
|
+
// documentationFor -> host-workflow-capabilities.mjs.
|
|
20
|
+
// decision/qa_result none; cm-ai-conversation-entry.mjs decision/qa_result.
|
|
21
|
+
// fix_advance/fix_run fix_learning, fix_diagnose, fix_test_author,
|
|
22
|
+
// fix_repair, fix_retrospective; host-qa-fix-owner.mjs
|
|
23
|
+
// forwards to cm-fix host.run/handle.
|
|
24
|
+
// fix_action selected cm-fix step; host-qa-fix-owner.mjs fix_action.
|
|
25
|
+
// status/cancel/fix_status/context_refresh: none; cm-ai-conversation-entry.mjs
|
|
26
|
+
// status/cancel/context_refresh; host-qa-fix-owner.mjs fix_status.
|
|
27
|
+
// verification_precheck optional execution.verificationGate in
|
|
28
|
+
// host-conversation-execution.mjs; CLI has no runner for it.
|
|
29
|
+
// host-session.mjs's remaining names belong to other workflow hosts and are
|
|
30
|
+
// intentionally not advertised as cm-ai operations.
|
|
31
|
+
// For unsupported evidence kinds, preflight refuses before the host starts.
|
|
32
|
+
import fs from 'node:fs';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import {fileURLToPath} from 'node:url';
|
|
35
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
36
|
+
import {decideHostQaPolicy} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
37
|
+
import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
38
|
+
import {inspectCmAiQaTaskContext} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
39
|
+
import {readLearningRetrospectiveContent} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
40
|
+
import {inspectFixInvestigation} from '../runtime/js/cm-fix/investigation.mjs';
|
|
41
|
+
import {readRunDefinition} from './cm-ai-run.mjs';
|
|
42
|
+
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
43
|
+
|
|
44
|
+
const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
45
|
+
const OPERATIONS=new Set(['advance','start','resume','status','cancel','decision','complete','qa','qa_result',
|
|
46
|
+
'fix_status','fix_advance','fix_action','fix_run','run_finalize','context_refresh','finish']);
|
|
47
|
+
const ADVANCE=new Set(['advance','start','resume']);
|
|
48
|
+
const PACKAGE_OPERATIONS=new Set(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize']);
|
|
49
|
+
const TEST_RUN_OPERATIONS=new Set(['qa_result','context_refresh','finish','run_finalize']);
|
|
50
|
+
const FIX_ASKS={advance:['fix_learning','fix_diagnose'],author_tests:['fix_learning','fix_test_author'],
|
|
51
|
+
repair:['fix_learning','fix_repair'],retrospective:['fix_learning','fix_retrospective'],
|
|
52
|
+
red_test:['fix_learning'],baseline:['fix_learning'],regression:['fix_learning'],
|
|
53
|
+
post_review_regression:['fix_learning'],prepare_revision:['fix_learning']};
|
|
54
|
+
const FIX_ACTIONS=new Set(['red_test','baseline','author_tests','repair','regression','retrospective',
|
|
55
|
+
'learning_writeback','handoff','final_review_package','final_review','publish_review','check_n5',
|
|
56
|
+
'post_review_regression','publish_dossier','walkthrough','finish','prepare_revision',
|
|
57
|
+
'cause_review_package','cause_review','abandon_step']);
|
|
58
|
+
const FILES={develop:'develop.json',qa_assess:'qa-assess.json',documentation_inspect:'documentation-inspect.json',
|
|
59
|
+
documentation_sync:'documentation-sync.json',fix_learning:'learning.json',fix_diagnose:'diagnosis.json',
|
|
60
|
+
fix_test_author:'test-edits.json',fix_repair:'repair-edits.json',fix_retrospective:'retrospective.json'};
|
|
61
|
+
const PAIR_FLAGS=new Set(['--allow-review-attempt','--review-config','--workflow-config',
|
|
62
|
+
'--input-limit',
|
|
63
|
+
'--protected-conversation-config','--protected-config','--revise-qa-config','--qa-config-revision-reason',
|
|
64
|
+
'--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--browser-qa',
|
|
65
|
+
'--bootstrap-config','--allow-provider-development-attempt','--supersede-reason']);
|
|
66
|
+
const FLAG_FLAGS=new Set(['--allow-development','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',
|
|
67
|
+
'--allow-bootstrap-write','--rerun-unknown-qa','--rerun-blocked-qa','--failover',
|
|
68
|
+
'--supersede-reviewed-evidence',
|
|
69
|
+
...['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
|
|
70
|
+
'test-author','repair','cause-review','final-review'].map(name=>`--allow-qa-fix-${name}`)]);
|
|
71
|
+
const object=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
|
|
72
|
+
const nonempty=value=>typeof value==='string'&&value.trim().length>0;
|
|
73
|
+
function requireShape(ok,label){if(!ok)stop(2,`答案格式错误:${label}`);}
|
|
74
|
+
function exact(value,allowed,label){requireShape(object(value)&&Object.keys(value).every(key=>allowed.includes(key)),label);}
|
|
75
|
+
function answerPath(root,file){return path.join(root,file);}
|
|
76
|
+
function predictedQaAsks(definition,qa){
|
|
77
|
+
// Reuse the executor's validated initial plan for policy applicability.
|
|
78
|
+
// QA runs after this task completes, so project its task
|
|
79
|
+
// state at that point before applying the executor's taskIds deferral rule.
|
|
80
|
+
const executor=createHostQaExecutor({specsDir:definition.specsDir,codeProject:definition.codeProject,
|
|
81
|
+
feature:definition.feature,requirements:definition.requirements,runtime:'codex',
|
|
82
|
+
...(definition.codeProjects?{codeProjects:definition.codeProjects}:{}),
|
|
83
|
+
...qa,timeoutMs:1800000,logHome:path.join(definition.specsDir,'.reviews','host-log-mirror')});
|
|
84
|
+
const plan=executor.configuration.plan;
|
|
85
|
+
const context=inspectCmAiQaTaskContext({specsDir:definition.specsDir,codeProject:definition.codeProject,
|
|
86
|
+
feature:definition.feature});
|
|
87
|
+
const completed=new Set(context.completed.filter(task=>task.feature===definition.feature).map(task=>task.id));
|
|
88
|
+
const taskWasPending=!completed.has(definition.identity.taskId);
|
|
89
|
+
completed.add(definition.identity.taskId);
|
|
90
|
+
const pendingAfter=context.pending-(taskWasPending?1:0);
|
|
91
|
+
const cases=plan.cases.filter(item=>pendingAfter===0||item.taskIds.every(taskId=>completed.has(taskId)));
|
|
92
|
+
const asks=[];
|
|
93
|
+
// The current executor still calls logic() for mapped cases; command evidence
|
|
94
|
+
// only affects the later verdict. Keep the preflight conservative until that
|
|
95
|
+
// runtime contract changes.
|
|
96
|
+
if(cases.some(item=>item.kind==='logic'))
|
|
97
|
+
asks.push('qa_logic');
|
|
98
|
+
if(cases.some(item=>item.kind==='browser'&&!item.expected.some(value=>value.includes('[需确认]'))))
|
|
99
|
+
asks.push('qa_browser');
|
|
100
|
+
return asks;
|
|
101
|
+
}
|
|
102
|
+
function edits(value,root,label){
|
|
103
|
+
requireShape(object(value),`${label} 应为路径到内容文件的对象`);
|
|
104
|
+
for(const [target,local] of Object.entries(value)){
|
|
105
|
+
requireShape(nonempty(target)&&typeof local==='string'&&local.length>0&&!path.isAbsolute(local)
|
|
106
|
+
&&!local.split(/[\\/]/).includes('..'),`${label} 路径无效`);
|
|
107
|
+
const file=answerPath(root,local);
|
|
108
|
+
requireShape(fs.existsSync(file)&&fs.lstatSync(file).isFile()&&!fs.lstatSync(file).isSymbolicLink()
|
|
109
|
+
&&fs.realpathSync(file).startsWith(fs.realpathSync(root)+path.sep),`${label} 缺少安全的内容文件 ${file}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function validateCmAiAnswer(kind,value,root){
|
|
113
|
+
if(kind==='develop'){
|
|
114
|
+
requireShape(object(value)&&['succeeded','failed'].includes(value.status),'develop.json.status');
|
|
115
|
+
if(value.status==='succeeded'){
|
|
116
|
+
exact(value,['status','value','edits'],'develop.json');
|
|
117
|
+
requireShape(object(value.value)&&['implemented','blocked'].includes(value.value.outcome),'develop.json.value.outcome');
|
|
118
|
+
exact(value.value,['outcome','application','retrospective','reason'],'develop.json.value');
|
|
119
|
+
if(value.value.outcome==='implemented')requireShape(object(value.value.application)
|
|
120
|
+
&&['applied','no_relevant_lesson'].includes(value.value.application.status)
|
|
121
|
+
&&(value.value.application.status==='applied'?nonempty(value.value.application.note):value.value.application.note===null)
|
|
122
|
+
&&object(value.value.retrospective)&&Array.isArray(value.value.retrospective.candidates)
|
|
123
|
+
&&['no_new_lesson','lesson_candidate','writeback_pending'].includes(value.value.retrospective.status),
|
|
124
|
+
'develop.json.value Learning');
|
|
125
|
+
if(value.value.application)exact(value.value.application,['status','note'],'develop.json.value.application');
|
|
126
|
+
if(value.value.outcome==='implemented')try{readLearningRetrospectiveContent(value.value.retrospective);}
|
|
127
|
+
catch{stop(2,'答案格式错误:develop.json.value.retrospective');}
|
|
128
|
+
requireShape(object(value.edits),'develop.json.edits');edits(value.edits,root,'develop.json.edits');
|
|
129
|
+
}else {exact(value,['status','code'],'develop.json');requireShape(nonempty(value.code),'develop.json.code');}
|
|
130
|
+
}else if(kind==='qa_assess'){
|
|
131
|
+
try{decideHostQaPolicy({assessment:value,pending:1,mergeEligible:false,unassessedTasks:1});}
|
|
132
|
+
catch{stop(2,'答案格式错误:qa-assess.json');}
|
|
133
|
+
}else if(kind==='documentation_inspect'){
|
|
134
|
+
exact(value,['status','reason','at'],'documentation-inspect.json');
|
|
135
|
+
requireShape(['completed','blocked'].includes(value.status)&&typeof value.reason==='string'
|
|
136
|
+
&&value.reason.length<=200&&!/[\r\n\0]/.test(value.reason),'documentation-inspect.json');
|
|
137
|
+
if(Object.hasOwn(value,'at'))requireShape(typeof value.at==='string'
|
|
138
|
+
&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/.test(value.at)
|
|
139
|
+
&&Number.isFinite(Date.parse(value.at)),'documentation-inspect.json.at');
|
|
140
|
+
}
|
|
141
|
+
else if(kind==='documentation_sync'){
|
|
142
|
+
exact(value,['status','edits'],'documentation-sync.json');
|
|
143
|
+
requireShape(object(value)&&value.status==='completed'&&object(value.edits),'documentation-sync.json');
|
|
144
|
+
edits(value.edits,root,'documentation-sync.json.edits');
|
|
145
|
+
}else if(kind==='fix_learning'){
|
|
146
|
+
exact(value,['status','summary'],'learning.json');
|
|
147
|
+
requireShape(['applied','no_relevant_lesson'].includes(value.status)
|
|
148
|
+
&&nonempty(value.summary)&&value.summary.length<=1000&&!/[\r\n\0]/.test(value.summary),'learning.json');
|
|
149
|
+
}else if(kind==='fix_diagnose'){
|
|
150
|
+
exact(value,['status','rootCause','affectedPaths','plan','crossLayer','affectedModules','investigation'],'diagnosis.json');
|
|
151
|
+
requireShape(['diagnosed','needs_evidence','design_change'].includes(value.status)
|
|
152
|
+
&&nonempty(value.rootCause)&&nonempty(value.plan)&&typeof value.crossLayer==='boolean'
|
|
153
|
+
&&Array.isArray(value.affectedPaths)&&value.affectedPaths.length>0
|
|
154
|
+
&&Array.isArray(value.affectedModules)&&value.affectedModules.length>0
|
|
155
|
+
&&[...value.affectedPaths,...value.affectedModules].every(item=>nonempty(item)
|
|
156
|
+
&&!path.isAbsolute(item)&&!item.includes('\\')&&!item.split('/').includes('..')),'diagnosis.json');
|
|
157
|
+
if(Object.hasOwn(value,'investigation'))try{inspectFixInvestigation(value.investigation,value.crossLayer);}
|
|
158
|
+
catch{stop(2,'答案格式错误:diagnosis.json.investigation');}
|
|
159
|
+
}
|
|
160
|
+
else if(kind==='fix_retrospective')try{readLearningRetrospectiveContent(value);}
|
|
161
|
+
catch{stop(2,'答案格式错误:retrospective.json');}
|
|
162
|
+
else if(['fix_test_author','fix_repair'].includes(kind))edits(value,root,FILES[kind]);
|
|
163
|
+
}
|
|
164
|
+
function load(){
|
|
165
|
+
if(process.argv.length===3&&['--help','-h'].includes(process.argv[2])){
|
|
166
|
+
process.stdout.write('用法: cm-ai-drive.mjs --plan PLAN.json <operation>\nPLAN: config, mode, hostContext, originalHostContext (resume), runtime, permissions, answers, checks。\n人工答案放 answers/;check 只运行 PLAN.checks,不读取静态执行证据。\n');
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}
|
|
169
|
+
const loaded=loadPlanFile({name:'cm-ai-drive.mjs',known:OPERATIONS});
|
|
170
|
+
const {plan,operation,base}=loaded;
|
|
171
|
+
requireFields(plan,['config','mode','hostContext','permissions']);
|
|
172
|
+
if(!['create','resume'].includes(plan.mode))stop(2,'mode 只能是 create 或 resume');
|
|
173
|
+
if(!nonempty(plan.hostContext))stop(2,'hostContext 必须是当前真实会话 ID');
|
|
174
|
+
if(plan.mode==='resume'&&!nonempty(plan.originalHostContext))stop(2,'resume 需要 originalHostContext');
|
|
175
|
+
if(plan.mode==='create'&&plan.originalHostContext)stop(2,'originalHostContext 只在 resume 时有意义');
|
|
176
|
+
if(!Array.isArray(plan.permissions)||!plan.permissions.every(x=>typeof x==='string'))stop(2,'permissions 必须是宿主参数数组');
|
|
177
|
+
const permissions=[];
|
|
178
|
+
for(let i=0;i<plan.permissions.length;i++){
|
|
179
|
+
const flag=plan.permissions[i];
|
|
180
|
+
if(FLAG_FLAGS.has(flag))permissions.push(flag);
|
|
181
|
+
else if(PAIR_FLAGS.has(flag)&&nonempty(plan.permissions[i+1]))permissions.push(flag,plan.permissions[++i]);
|
|
182
|
+
else stop(2,`permissions 无效或缺少参数: ${flag}`);
|
|
183
|
+
}
|
|
184
|
+
const supersedeFlag=permissions.includes('--supersede-reviewed-evidence');
|
|
185
|
+
const supersedeReason=permissions.includes('--supersede-reason');
|
|
186
|
+
if(supersedeFlag!==supersedeReason)
|
|
187
|
+
stop(2,'--supersede-reviewed-evidence 与 --supersede-reason 必须同时提供');
|
|
188
|
+
if(supersedeFlag&&plan.mode!=='create')stop(2,'supersede 只允许 mode create');
|
|
189
|
+
const config=path.resolve(base,plan.config),answers=plan.answers?path.resolve(base,plan.answers):null;
|
|
190
|
+
if(!fs.existsSync(config))stop(2,`运行定义不存在: ${config}`);
|
|
191
|
+
let definition;
|
|
192
|
+
try{definition=readRunDefinition(config);}catch(error){stop(2,`运行定义无效或 codeProject/specsDir 无法解析: ${error.code??error.message}`);}
|
|
193
|
+
const store=path.join(definition.specsDir,'.reviews','.execution',definition.identity.runId);
|
|
194
|
+
if(plan.mode==='resume'&&!fs.existsSync(path.join(store,'state.json')))stop(2,`恢复存档不存在: ${store}`);
|
|
195
|
+
const workflowAt=permissions.indexOf('--workflow-config');let workflow=null;
|
|
196
|
+
if(workflowAt!==-1){
|
|
197
|
+
const file=path.resolve(base,permissions[workflowAt+1]);workflow=readJson(file,'workflow-config');
|
|
198
|
+
if(workflow===undefined)stop(2,`workflow-config 不存在: ${file}`);
|
|
199
|
+
permissions[workflowAt+1]=file;
|
|
200
|
+
}
|
|
201
|
+
for(let i=0;i<permissions.length;i++)if(PAIR_FLAGS.has(permissions[i])
|
|
202
|
+
&&permissions[i]!=='--allow-review-attempt'&&permissions[i]!=='--browser-qa'
|
|
203
|
+
&&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--allow-provider-development-attempt'
|
|
204
|
+
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--input-limit'){
|
|
205
|
+
const file=path.resolve(base,permissions[i+1]);if(!fs.existsSync(file))stop(2,`${permissions[i]} 文件不存在: ${file}`);
|
|
206
|
+
permissions[i+1]=file;i++;
|
|
207
|
+
}
|
|
208
|
+
const providerMode=permissions.includes('--protected-config');
|
|
209
|
+
const protectedMode=providerMode||permissions.includes('--protected-conversation-config');
|
|
210
|
+
const asks=[];
|
|
211
|
+
if(ADVANCE.has(operation)){
|
|
212
|
+
if(!providerMode)asks.push('develop');
|
|
213
|
+
if(!protectedMode)asks.push('check');
|
|
214
|
+
}
|
|
215
|
+
if(plan.verificationPrecheck===true&&(ADVANCE.has(operation)||operation==='complete'))asks.push('verification_precheck');
|
|
216
|
+
if(operation==='complete'&&!protectedMode)asks.push('check');
|
|
217
|
+
if((operation==='advance'||operation==='qa')&&workflow?.qa){asks.push('qa_assess');
|
|
218
|
+
}
|
|
219
|
+
if(operation==='advance'&&workflow?.qa){
|
|
220
|
+
try{asks.push(...predictedQaAsks(definition,workflow.qa));}
|
|
221
|
+
catch(error){stop(2,`QA 请求预测失败: ${error.code??error.message}`);}
|
|
222
|
+
}
|
|
223
|
+
if(operation==='advance'&&workflow?.documentationPaths?.length&&!protectedMode)asks.push('documentation_sync');
|
|
224
|
+
if(['advance','finish','run_finalize'].includes(operation)&&workflow)asks.push('documentation_inspect');
|
|
225
|
+
if(operation==='advance'&&permissions.includes('--auto-qa-fix')){
|
|
226
|
+
asks.push(...new Set(Object.values(FIX_ASKS).flat()));
|
|
227
|
+
}
|
|
228
|
+
if(['fix_advance','fix_run'].includes(operation))asks.push(...new Set(Object.values(FIX_ASKS).flat()));
|
|
229
|
+
if(operation==='fix_action'){
|
|
230
|
+
if(!FIX_ACTIONS.has(plan.fixOperation))stop(2,'fix_action 需要宿主支持的 fixOperation');
|
|
231
|
+
if(plan.fixOperation==='abandon_step'&&(!nonempty(plan.reason)
|
|
232
|
+
||!permissions.includes('--allow-qa-fix-abandon')))stop(2,'abandon_step 需要 reason 与 --allow-qa-fix-abandon');
|
|
233
|
+
asks.push(...(FIX_ASKS[plan.fixOperation]??[]));
|
|
234
|
+
}
|
|
235
|
+
if(['qa_logic','qa_browser','verification_precheck'].some(kind=>asks.includes(kind)))
|
|
236
|
+
stop(2,`缺少真实执行 runner: ${asks.filter(kind=>['qa_logic','qa_browser','verification_precheck'].includes(kind)).join(', ')};不能从静态答案文件应答`);
|
|
237
|
+
if(asks.includes('check')){
|
|
238
|
+
if(!Array.isArray(plan.checks)||plan.checks.length===0)stop(2,'步骤会反问 check,但 PLAN.checks 缺少真实命令列表');
|
|
239
|
+
try{createHostCheck({cwd:definition.codeProject,commands:plan.checks});}
|
|
240
|
+
catch(error){stop(2,`PLAN.checks 格式错误: ${error.code??error.message}`);}
|
|
241
|
+
}
|
|
242
|
+
const unique=[...new Set(asks.filter(kind=>FILES[kind]))];
|
|
243
|
+
const answer=preflightAnswers(unique,kind=>{
|
|
244
|
+
const file=answerPath(answers??'',FILES[kind]);
|
|
245
|
+
if(!answers||!fs.existsSync(file))stop(2,`步骤 ${operation} 会反问 ${kind},但答案文件不存在: ${file}`);
|
|
246
|
+
const value=readJson(file,kind);validateCmAiAnswer(kind,value,answers);return value;
|
|
247
|
+
});
|
|
248
|
+
if(answer.develop?.status==='succeeded')for(const target of Object.keys(answer.develop.edits))
|
|
249
|
+
if(!definition.scope.includes(target))stop(2,`develop.json.edits 越过批准 scope: ${target}`);
|
|
250
|
+
if(answer.documentation_sync)for(const target of Object.keys(answer.documentation_sync.edits))
|
|
251
|
+
if(!workflow.documentationPaths.includes(target))stop(2,`documentation-sync.json.edits 越过文档 scope: ${target}`);
|
|
252
|
+
return {...loaded,definition,permissions,config,answers,answer};
|
|
253
|
+
}
|
|
254
|
+
function applyEdits(map,root,allowed){
|
|
255
|
+
for(const target of Object.keys(map)){
|
|
256
|
+
if(!allowed.includes(target))throw Error(`${target} 不在宿主允许的范围`);
|
|
257
|
+
const file=path.resolve(root,target);
|
|
258
|
+
if(!file.startsWith(root+path.sep))throw Error('编辑路径越界');
|
|
259
|
+
for(let parent=path.dirname(file);parent!==root;parent=path.dirname(parent))
|
|
260
|
+
if(fs.existsSync(parent)&&fs.lstatSync(parent).isSymbolicLink())throw Error('编辑路径经过符号链接');
|
|
261
|
+
if(fs.existsSync(file)&&fs.lstatSync(file).isSymbolicLink())throw Error('编辑路径是符号链接');
|
|
262
|
+
}
|
|
263
|
+
for(const [target,local] of Object.entries(map)){
|
|
264
|
+
const file=path.resolve(root,target);
|
|
265
|
+
fs.mkdirSync(path.dirname(file),{recursive:true});fs.writeFileSync(file,fs.readFileSync(path.join(loaded.answers,local)));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
let loaded;
|
|
269
|
+
export function qaFixAnswerFor(row,answer,answerRoot){
|
|
270
|
+
const kind=row.kind,value=answer[kind];
|
|
271
|
+
if(kind==='fix_learning')return {contextDigest:row.payload.contextDigest,status:value.status,summary:value.summary};
|
|
272
|
+
if(['fix_test_author','fix_repair'].includes(kind)){
|
|
273
|
+
const edits=[];for(const [target,local] of Object.entries(value)){
|
|
274
|
+
if(!Object.hasOwn(row.payload.expected??{},target))return {outcome:'blocked',edits:[]};
|
|
275
|
+
edits.push({path:target,beforeSha256:row.payload.expected[target],content:fs.readFileSync(path.join(answerRoot,local),'utf8')});
|
|
276
|
+
}
|
|
277
|
+
return {outcome:kind==='fix_repair'?'repaired':'authored',edits};
|
|
278
|
+
}
|
|
279
|
+
return value??null;
|
|
280
|
+
}
|
|
281
|
+
async function answerFor(row,answer){
|
|
282
|
+
const kind=row.kind,value=answer[kind];
|
|
283
|
+
if(kind==='check'){
|
|
284
|
+
const results=[];
|
|
285
|
+
for(const command of loaded.plan.checks){
|
|
286
|
+
const run=createHostCheck({cwd:loaded.definition.codeProject,commands:[command],
|
|
287
|
+
onOutput:({stream,chunk})=>{process.stderr.write(`[drive check ${command.id} ${stream}] ${chunk.toString('utf8')}`);}});
|
|
288
|
+
const [item]=await run({identity:row.payload.identity},{signal:new AbortController().signal});
|
|
289
|
+
results.push(item);
|
|
290
|
+
if(item.outcome!=='passed')break;
|
|
291
|
+
}
|
|
292
|
+
return results;
|
|
293
|
+
}
|
|
294
|
+
if(kind==='develop'){
|
|
295
|
+
if(value.status!=='succeeded')return {status:'failed',code:value.code};
|
|
296
|
+
if(row.payload.editMode==='protected-text-v1'){
|
|
297
|
+
const edits=Object.entries(value.edits).map(([target,local])=>({path:target,
|
|
298
|
+
beforeSha256:row.payload.expected?.[target]??null,content:fs.readFileSync(path.join(loaded.answers,local),'utf8')}));
|
|
299
|
+
return {status:'succeeded',value:value.value,edits};
|
|
300
|
+
}
|
|
301
|
+
applyEdits(value.edits,loaded.definition.codeProject,row.payload.request.payload.scope);
|
|
302
|
+
return {status:'succeeded',value:value.value};
|
|
303
|
+
}
|
|
304
|
+
if(kind==='documentation_sync'){
|
|
305
|
+
applyEdits(value.edits,loaded.definition.codeProject,row.payload.paths);return {status:'completed'};
|
|
306
|
+
}
|
|
307
|
+
if(kind==='documentation_inspect')return {...value,syncId:row.payload.syncId,identity:row.payload.identity,
|
|
308
|
+
packageDigest:row.payload.packageDigest,contextDigest:row.payload.contextDigest,
|
|
309
|
+
at:value.at??new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
|
|
310
|
+
if(kind.startsWith('fix_'))return qaFixAnswerFor(row,answer,loaded.answers);
|
|
311
|
+
return value??null;
|
|
312
|
+
}
|
|
313
|
+
function main(){
|
|
314
|
+
loaded=load();
|
|
315
|
+
const {plan,operation,definition,permissions,config,answer}=loaded;
|
|
316
|
+
if(PACKAGE_OPERATIONS.has(operation)&&!(typeof plan.packageDigest==='string'&&/^[a-f0-9]{64}$/.test(plan.packageDigest)))
|
|
317
|
+
stop(2,`${operation} 需要 packageDigest(64 位十六进制)`);
|
|
318
|
+
if(TEST_RUN_OPERATIONS.has(operation)&&!(operation==='qa_result'?nonempty(plan.testRunId)
|
|
319
|
+
:plan.testRunId===null||nonempty(plan.testRunId)))stop(2,`${operation} 需要 testRunId(可为 null)`);
|
|
320
|
+
const request={version:1,identity:definition.identity,
|
|
321
|
+
...(PACKAGE_OPERATIONS.has(operation)?{packageDigest:plan.packageDigest}:{}),
|
|
322
|
+
...(TEST_RUN_OPERATIONS.has(operation)?{testRunId:plan.testRunId}:{}),
|
|
323
|
+
...(['fix_status','fix_advance','fix_action','fix_run'].includes(operation)?{
|
|
324
|
+
packageDigest:plan.packageDigest,testRunId:plan.testRunId,
|
|
325
|
+
...(operation==='fix_action'?{fixOperation:plan.fixOperation,
|
|
326
|
+
...(plan.fixOperation==='abandon_step'?{reason:plan.reason}:{})}: {})}: {})};
|
|
327
|
+
if(operation.startsWith('fix_')&&(!nonempty(plan.packageDigest)||!nonempty(plan.testRunId)))
|
|
328
|
+
stop(2,`${operation} 需要 packageDigest 和 testRunId`);
|
|
329
|
+
driveHost({host:HOST,args:['serve','--config',config,'--mode',plan.mode,'--host-context',plan.hostContext,
|
|
330
|
+
'--allow-development',
|
|
331
|
+
...(plan.originalHostContext?['--original-host-context',plan.originalHostContext]:[]),
|
|
332
|
+
'--runtime',plan.runtime??'codex',...permissions.filter(flag=>flag!=='--allow-development')],cwd:definition.codeProject,operation,request,
|
|
333
|
+
answers:answer,paths:{answers:loaded.answers},answerFor});
|
|
334
|
+
}
|
|
335
|
+
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))main();
|
|
@@ -0,0 +1,258 @@
|
|
|
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
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {qaFixAnswerFor} from './cm-ai-drive.mjs';
|
|
10
|
+
|
|
11
|
+
const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
12
|
+
const identity={repositoryId:'drive-fixture',runId:'drive-run',taskId:'T-001',attempt:1};
|
|
13
|
+
test('help prints the plan command without launching a host',()=>{
|
|
14
|
+
const help=spawnSync(process.execPath,[DRIVER,'--help'],{encoding:'utf8'});
|
|
15
|
+
assert.equal(help.status,0);assert.match(help.stdout,/--plan PLAN\.json <operation>/);
|
|
16
|
+
});
|
|
17
|
+
function fixture(t){
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-')));
|
|
19
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
20
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
21
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
22
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
23
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
24
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
25
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
26
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({version:1,specsDir,codeProject,feature,identity,
|
|
27
|
+
scope:['target.mjs'],requirements:['requirements.md']}));
|
|
28
|
+
const answers=path.join(root,'answers');fs.mkdirSync(answers);
|
|
29
|
+
const write=(name,value)=>fs.writeFileSync(path.join(answers,name),JSON.stringify(value));
|
|
30
|
+
const plan=(extra={})=>{const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
31
|
+
fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',hostContext:'drive-host-a',
|
|
32
|
+
permissions:[],answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra}));
|
|
33
|
+
return file;};
|
|
34
|
+
const drive=(file,operation)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],
|
|
35
|
+
{encoding:'utf8',timeout:30000,env:{...process.env,CM_WORKFLOW_HOME:path.join(root,'home'),
|
|
36
|
+
CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
37
|
+
const store=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
38
|
+
return {root,codeProject,specsDir,answers,write,plan,drive,store};
|
|
39
|
+
}
|
|
40
|
+
const develop={status:'succeeded',value:{outcome:'implemented',
|
|
41
|
+
application:{status:'no_relevant_lesson',note:null},
|
|
42
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
43
|
+
edits:{'target.mjs':'target-content.mjs'}};
|
|
44
|
+
function prepared(f){f.write('develop.json',develop);fs.writeFileSync(path.join(f.answers,'target-content.mjs'),'export const value = 42;\n');}
|
|
45
|
+
function qaFixture(f,kinds,caseIds=[]){
|
|
46
|
+
const featureRoot=path.join(f.specsDir,'1.work');
|
|
47
|
+
fs.writeFileSync(path.join(featureRoot,'requirements.md'),'- [AC-001]: fixture\n');
|
|
48
|
+
const cases=kinds.map(({kind,expected,taskIds=['T-001']},index)=>({id:`TC-${String(index+1).padStart(3,'0')}`,origin:'user',kind,
|
|
49
|
+
blocking:true,acIds:['AC-001'],taskIds,title:`${kind} fixture`,preconditions:[],
|
|
50
|
+
steps:['Observe fixture'],expected:[expected],cleanup:[]}));
|
|
51
|
+
fs.writeFileSync(path.join(featureRoot,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases}));
|
|
52
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
|
|
53
|
+
specFiles:buildManifest(f.specsDir)}));
|
|
54
|
+
fs.writeFileSync(path.join(f.root,'workflow.json'),JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
|
|
55
|
+
qa:{commands:[{id:'unit',command:[process.execPath,'--check','target.mjs'],caseIds}],
|
|
56
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-local',scope:'local'}}}));
|
|
57
|
+
f.write('qa-assess.json',{scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
58
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
59
|
+
f.write('documentation-inspect.json',{status:'blocked',reason:'Fixture stops before documentation review'});
|
|
60
|
+
return f.plan({permissions:['--workflow-config','workflow.json','--allow-qa',
|
|
61
|
+
...(kinds.some(item=>item.kind==='browser')?['--browser-qa','available']:[])]});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test('create and advance run authored edits and actual check, then resume with original context',t=>{
|
|
65
|
+
const f=fixture(t);prepared(f);
|
|
66
|
+
const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
|
|
67
|
+
const result=JSON.parse(first.stdout).result;
|
|
68
|
+
assert.equal(result.state,'awaiting_review');assert.equal(result.code,'decision_required');
|
|
69
|
+
assert.match(first.stderr,/应答 develop/);assert.match(first.stderr,/应答 check/);
|
|
70
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
71
|
+
assert(fs.existsSync(f.store));
|
|
72
|
+
const resumed=f.drive(f.plan({mode:'resume',hostContext:'drive-host-b',originalHostContext:'drive-host-a'}),'advance');
|
|
73
|
+
assert.equal(resumed.status,0,resumed.stderr);assert.equal(JSON.parse(resumed.stdout).result.code,'decision_required');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('missing develop answer is refused before store creation',t=>{
|
|
77
|
+
const f=fixture(t);const run=f.drive(f.plan(),'advance');
|
|
78
|
+
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
79
|
+
});
|
|
80
|
+
test('single driver accepts input limit as a value before host launch',t=>{
|
|
81
|
+
const f=fixture(t);
|
|
82
|
+
const run=f.drive(f.plan({permissions:['--input-limit','1048576']}),'advance');
|
|
83
|
+
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);
|
|
84
|
+
assert.doesNotMatch(run.stderr,/permissions 无效|--input-limit 文件不存在/);
|
|
85
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
86
|
+
});
|
|
87
|
+
test('out-of-scope develop edit is refused before host launch',t=>{
|
|
88
|
+
const f=fixture(t);prepared(f);
|
|
89
|
+
f.write('develop.json',{...develop,edits:{'outside.mjs':'target-content.mjs'}});
|
|
90
|
+
const run=f.drive(f.plan(),'advance');
|
|
91
|
+
assert.equal(run.status,2,run.stderr);
|
|
92
|
+
assert.match(run.stderr,/develop\.json\.edits 越过批准 scope: outside\.mjs/);
|
|
93
|
+
assert.equal(fs.existsSync(path.dirname(f.store)),false,'preflight must not create the run store');
|
|
94
|
+
});
|
|
95
|
+
test('unprotected advance without checks is refused before host launch',t=>{
|
|
96
|
+
const f=fixture(t);prepared(f);
|
|
97
|
+
const run=f.drive(f.plan({checks:undefined}),'advance');
|
|
98
|
+
assert.equal(run.status,2,run.stderr);
|
|
99
|
+
assert.match(run.stderr,/步骤会反问 check,但 PLAN\.checks 缺少真实命令列表/);
|
|
100
|
+
assert.equal(fs.existsSync(path.dirname(f.store)),false,'preflight must not create the run store');
|
|
101
|
+
});
|
|
102
|
+
test('missing checks cannot be replaced with static check.json',t=>{
|
|
103
|
+
const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
|
|
104
|
+
const run=f.drive(f.plan({checks:undefined}),'advance');
|
|
105
|
+
assert.equal(run.status,2);assert.match(run.stderr,/PLAN\.checks/);assert.equal(fs.existsSync(f.store),false);
|
|
106
|
+
});
|
|
107
|
+
test('a static passed check cannot override a failed real command',t=>{
|
|
108
|
+
const f=fixture(t);prepared(f);f.write('check.json',[{id:'syntax',outcome:'passed',exitCode:0}]);
|
|
109
|
+
const run=f.drive(f.plan({checks:[{id:'actual',command:[process.execPath,'-e','process.exit(7)']}]}),'advance');
|
|
110
|
+
assert.equal(run.status,0,run.stderr);
|
|
111
|
+
const evidence=fs.readFileSync(f.store,'utf8');
|
|
112
|
+
assert.match(evidence,/host check exited 7/);
|
|
113
|
+
assert.doesNotMatch(evidence,/"outcome":"passed","exitCode":0/);
|
|
114
|
+
});
|
|
115
|
+
test('malformed develop answer is rejected before host launch',t=>{
|
|
116
|
+
const f=fixture(t);prepared(f);f.write('develop.json',{status:'succeeded',value:{outcome:'implemented'},
|
|
117
|
+
edits:{'target.mjs':'target-content.mjs'}});
|
|
118
|
+
const run=f.drive(f.plan(),'advance');assert.equal(run.status,2);assert.match(run.stderr,/答案格式错误/);
|
|
119
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
120
|
+
});
|
|
121
|
+
test('verification_precheck static answer is refused without an execution runner',t=>{
|
|
122
|
+
const f=fixture(t);prepared(f);f.write('verification-precheck.json',{items:[{requirement:'synthetic',satisfied:true,evidence:'claim'}]});
|
|
123
|
+
const run=f.drive(f.plan({verificationPrecheck:true}),'advance');
|
|
124
|
+
assert.equal(run.status,2);assert.match(run.stderr,/verification_precheck/);assert.equal(fs.existsSync(f.store),false);
|
|
125
|
+
});
|
|
126
|
+
test('mapped logic case is still refused because executor asks qa_logic',t=>{
|
|
127
|
+
const f=fixture(t);prepared(f);
|
|
128
|
+
const plan=qaFixture(f,[{kind:'logic',expected:'Unit check passes'},
|
|
129
|
+
{kind:'browser',expected:'[需确认] Browser evidence'}],['TC-001']);
|
|
130
|
+
const run=f.drive(plan,'advance');
|
|
131
|
+
assert.equal(run.status,2,run.stderr);
|
|
132
|
+
assert.match(run.stderr,/缺少真实执行 runner: qa_logic/);
|
|
133
|
+
assert.doesNotMatch(run.stderr,/qa_browser/);
|
|
134
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
135
|
+
});
|
|
136
|
+
test('marked browser case launches without qa_browser runner',t=>{
|
|
137
|
+
const f=fixture(t);prepared(f);
|
|
138
|
+
const run=f.drive(qaFixture(f,[{kind:'browser',expected:'[需确认] Browser evidence'}]),'advance');
|
|
139
|
+
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
140
|
+
assert(fs.existsSync(f.store),run.stderr);
|
|
141
|
+
});
|
|
142
|
+
test('uncovered logic case is refused before launch without qa_logic runner',t=>{
|
|
143
|
+
const f=fixture(t);prepared(f);
|
|
144
|
+
const run=f.drive(qaFixture(f,[{kind:'logic',expected:'Unit check passes'}]),'advance');
|
|
145
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/缺少真实执行 runner: qa_logic/);
|
|
146
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
147
|
+
});
|
|
148
|
+
test('unmarked browser case is refused before launch without qa_browser runner',t=>{
|
|
149
|
+
const f=fixture(t);prepared(f);
|
|
150
|
+
const run=f.drive(qaFixture(f,[{kind:'browser',expected:'Browser evidence'}]),'advance');
|
|
151
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/缺少真实执行 runner: qa_browser/);
|
|
152
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
153
|
+
});
|
|
154
|
+
test('cases bound to another unfinished task do not require QA runners yet',t=>{
|
|
155
|
+
const f=fixture(t);prepared(f);
|
|
156
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: current\n- [ ] T-002: future\n');
|
|
157
|
+
const run=f.drive(qaFixture(f,[{kind:'logic',expected:'Future logic',taskIds:['T-002']},
|
|
158
|
+
{kind:'browser',expected:'Future browser',taskIds:['T-002']}]),'advance');
|
|
159
|
+
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
160
|
+
assert(fs.existsSync(f.store),run.stderr);
|
|
161
|
+
});
|
|
162
|
+
test('protected conversation still requires the authored develop answer',t=>{
|
|
163
|
+
const f=fixture(t);fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands:[
|
|
164
|
+
{id:'syntax',command:[process.execPath,'--check','target.mjs']}],timeoutMs:60000}));
|
|
165
|
+
const run=f.drive(f.plan({checks:undefined,
|
|
166
|
+
permissions:['--protected-conversation-config','protection.json']}),'advance');
|
|
167
|
+
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
168
|
+
});
|
|
169
|
+
test('resume requires originalHostContext before host launch',t=>{
|
|
170
|
+
const f=fixture(t);prepared(f);
|
|
171
|
+
const run=f.drive(f.plan({mode:'resume'}),'advance');assert.equal(run.status,2);
|
|
172
|
+
assert.match(run.stderr,/originalHostContext/);assert.equal(fs.existsSync(f.store),false);
|
|
173
|
+
});
|
|
174
|
+
test('supersession flags reach create and incomplete or resume pairs stop before host launch',t=>{
|
|
175
|
+
const f=fixture(t);prepared(f);
|
|
176
|
+
const both=['--supersede-reviewed-evidence','--supersede-reason','operator restart'];
|
|
177
|
+
const create=f.drive(f.plan({permissions:both}),'advance');
|
|
178
|
+
assert.equal(create.status,1,create.stderr);
|
|
179
|
+
assert.match(create.stderr,/supersede_unavailable/);
|
|
180
|
+
for(const permissions of [['--supersede-reviewed-evidence'],['--supersede-reason','operator restart']]){
|
|
181
|
+
const refused=f.drive(f.plan({permissions}),'advance');
|
|
182
|
+
assert.equal(refused.status,2,refused.stderr);
|
|
183
|
+
assert.match(refused.stderr,/supersede-reviewed-evidence.*supersede-reason/);
|
|
184
|
+
}
|
|
185
|
+
const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions:both}),'status');
|
|
186
|
+
assert.equal(resumed.status,2,resumed.stderr);
|
|
187
|
+
assert.match(resumed.stderr,/supersede.*create/);
|
|
188
|
+
});
|
|
189
|
+
test('status reads the existing run without answer files or checks',t=>{
|
|
190
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
191
|
+
const before=fs.readFileSync(f.store);
|
|
192
|
+
const status=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',answers:undefined,checks:undefined}),'status');
|
|
193
|
+
assert.equal(status.status,0,status.stderr);assert.equal(JSON.parse(status.stdout).result.state,'awaiting_review');
|
|
194
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
195
|
+
});
|
|
196
|
+
test('decision sends the package binding and needs no answer files',t=>{
|
|
197
|
+
const f=fixture(t);prepared(f);
|
|
198
|
+
const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
|
|
199
|
+
const packageDigest=JSON.parse(first.stdout).result.packageDigest;
|
|
200
|
+
const decision=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',
|
|
201
|
+
packageDigest,answers:undefined,checks:undefined}),'decision');
|
|
202
|
+
assert.equal(decision.status,0,decision.stderr);
|
|
203
|
+
assert.equal(JSON.parse(decision.stdout).result.code,'decision_required');
|
|
204
|
+
});
|
|
205
|
+
test('explicit allow-development permission reaches the host once',t=>{
|
|
206
|
+
const f=fixture(t);prepared(f);
|
|
207
|
+
const run=f.drive(f.plan({permissions:['--allow-development']}),'advance');
|
|
208
|
+
assert.equal(run.status,0,run.stderr);assert.equal(JSON.parse(run.stdout).result.code,'decision_required');
|
|
209
|
+
});
|
|
210
|
+
test('QA-fix child operation forwards its binding and returns parent gate result',t=>{
|
|
211
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
212
|
+
const binding={feature:'1.work',identity,packageDigest:'a'.repeat(64),testRunId:'qa-child'};
|
|
213
|
+
fs.writeFileSync(path.join(f.root,'fix-owner.json'),JSON.stringify({specsRoot:f.specsDir,identity:{...identity,runId:'fix-run'},
|
|
214
|
+
configuration:{hostContextId:'drive-host-a',reproduction:{cwd:f.codeProject},qaSource:binding}}));
|
|
215
|
+
const attempt=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',
|
|
216
|
+
permissions:['--qa-fix-owner-config','fix-owner.json'],packageDigest:'a'.repeat(64),testRunId:'qa-child'}),'fix_status');
|
|
217
|
+
assert.equal(attempt.status,1,attempt.stderr);
|
|
218
|
+
assert.match(attempt.stderr,/qa_fix_parent_not_completed/);
|
|
219
|
+
});
|
|
220
|
+
test('QA-fix child action requires its own answer before any host request',t=>{
|
|
221
|
+
const f=fixture(t);prepared(f);assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
222
|
+
const binding={feature:'1.work',identity,packageDigest:'a'.repeat(64),testRunId:'qa-child'};
|
|
223
|
+
fs.writeFileSync(path.join(f.root,'fix-owner.json'),JSON.stringify({specsRoot:f.specsDir,identity:{...identity,runId:'fix-run'},
|
|
224
|
+
configuration:{hostContextId:'drive-host-a',reproduction:{cwd:f.codeProject},qaSource:binding}}));
|
|
225
|
+
const options={mode:'resume',originalHostContext:'drive-host-a',packageDigest:'a'.repeat(64),
|
|
226
|
+
testRunId:'qa-child',fixOperation:'red_test',permissions:['--qa-fix-owner-config','fix-owner.json','--allow-qa-fix-start']};
|
|
227
|
+
const missing=f.drive(f.plan(options),'fix_action');assert.equal(missing.status,2);
|
|
228
|
+
assert.match(missing.stderr,/learning\.json/);
|
|
229
|
+
f.write('learning.json',{status:'no_relevant_lesson',summary:'No applicable project lesson'});
|
|
230
|
+
const sent=f.drive(f.plan(options),'fix_action');assert.equal(sent.status,1,sent.stderr);
|
|
231
|
+
assert.match(sent.stderr,/qa_fix_parent_not_completed/);
|
|
232
|
+
const learning={status:'no_relevant_lesson',summary:'No applicable project lesson'};
|
|
233
|
+
assert.deepEqual(qaFixAnswerFor({kind:'fix_learning',payload:{contextDigest:'binding'}},{fix_learning:learning},f.answers),
|
|
234
|
+
{contextDigest:'binding',...learning});
|
|
235
|
+
fs.writeFileSync(path.join(f.answers,'repair.txt'),'export const value = 43;\n');
|
|
236
|
+
assert.deepEqual(qaFixAnswerFor({kind:'fix_repair',payload:{expected:{'target.mjs':'old-hash'}}},
|
|
237
|
+
{fix_repair:{'target.mjs':'repair.txt'}},f.answers),
|
|
238
|
+
{outcome:'repaired',edits:[{path:'target.mjs',beforeSha256:'old-hash',content:'export const value = 43;\n'}]});
|
|
239
|
+
});
|
|
240
|
+
test('QA-fix answer travels through the shared JSONL core',t=>{
|
|
241
|
+
const f=fixture(t),host=path.join(f.root,'child-host.mjs'),wrapper=path.join(f.root,'child-drive.mjs');
|
|
242
|
+
fs.writeFileSync(host,`process.stdout.write(JSON.stringify({type:'host_ready',sessionId:'child'})+'\\n');
|
|
243
|
+
let text='';process.stdin.on('data',chunk=>{text+=chunk;let at;while((at=text.indexOf('\\n'))>=0){
|
|
244
|
+
const line=text.slice(0,at);text=text.slice(at+1);if(!line)continue;const row=JSON.parse(line);
|
|
245
|
+
if(row.operation==='fix_action')process.stdout.write(JSON.stringify({type:'host_request',sessionId:'child',
|
|
246
|
+
callId:'learning-call',requestDigest:'digest',kind:'fix_learning',payload:{contextDigest:'context'}})+'\\n');
|
|
247
|
+
if(row.type==='host_result')process.stdout.write(JSON.stringify({requestId:'drive',result:{stage:'child_answered',answer:row.result}})+'\\n');
|
|
248
|
+
}});`);
|
|
249
|
+
fs.writeFileSync(wrapper,`import {driveHost} from ${JSON.stringify(new URL('../runtime/js/cm-ai/drive-core.mjs',import.meta.url).href)};
|
|
250
|
+
import {qaFixAnswerFor} from ${JSON.stringify(new URL('./cm-ai-drive.mjs',import.meta.url).href)};
|
|
251
|
+
const answers={fix_learning:{status:'no_relevant_lesson',summary:'No applicable lesson'}};
|
|
252
|
+
driveHost({host:${JSON.stringify(host)},args:[],cwd:${JSON.stringify(f.root)},operation:'fix_action',answers,
|
|
253
|
+
answerFor:(row,value)=>qaFixAnswerFor(row,value,${JSON.stringify(f.answers)})});`);
|
|
254
|
+
const run=spawnSync(process.execPath,[wrapper],{encoding:'utf8',timeout:5000});
|
|
255
|
+
assert.equal(run.status,0,run.stderr);assert.match(run.stderr,/应答 fix_learning/);
|
|
256
|
+
assert.deepEqual(JSON.parse(run.stdout).result.answer,
|
|
257
|
+
{contextDigest:'context',status:'no_relevant_lesson',summary:'No applicable lesson'});
|
|
258
|
+
});
|
|
@@ -99,7 +99,7 @@ for(const mode of ['history','retest','unknown','failed-retest','double-pass','d
|
|
|
99
99
|
baseline:{cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
100
100
|
repair:{scope:['value.mjs'],requirements:['requirements.md']},
|
|
101
101
|
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
|
|
102
|
-
const makeSerial=(parent,childIdentity,configuration,repairValue)=>createQaFixOwnerHost({parent,reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
102
|
+
const makeSerial=(parent,childIdentity,configuration,repairValue)=>createQaFixOwnerHost({parent,hostContextId:'parent-host',parentHostContextId:'parent-host',reopenParent:()=>openControlRun(definition,'resume',execution),
|
|
103
103
|
...(double||automatic?{template:{specsRoot:specsDir,feature,identity,configuration:Object.fromEntries(Object.entries(configuration).filter(([key])=>key!=='qaSource'))}}
|
|
104
104
|
:{fix:{specsRoot:specsDir,identity:childIdentity,configuration}}),allowStart:true,autoFix:automatic,fixPermissions:permissions,
|
|
105
105
|
fixAuthorities:{authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority},fixExecution:{...reviewHost.execution,
|