@aibyzero/cm-workflow 0.21.7 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +64 -0
- package/README.md +15 -1
- package/VERSION +1 -1
- package/docs/architecture.md +9 -0
- package/docs/cm-acceptance-completion.md +3 -1
- package/docs/cm-control-policy-v2.md +35 -3
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +1 -0
- package/docs/human-correction.md +1 -1
- package/docs/installation.md +63 -19
- package/docs/js-workflow-control.md +67 -31
- package/docs/next-steps.md +10 -0
- package/docs/runtime-failover.md +2 -2
- package/docs/user-guide.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/batch-location.mjs +14 -0
- package/runtime/js/cm-ai/batch-plan.mjs +6 -2
- package/runtime/js/cm-ai/claude-probe-diagnosis.mjs +21 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +20 -7
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -2
- package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
- package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
- package/runtime/js/cm-ai/drive-core.mjs +50 -6
- package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
- package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
- package/runtime/js/cm-ai/execution-store.mjs +21 -3
- package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
- package/runtime/js/cm-ai/host-check.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +29 -2
- package/runtime/js/cm-ai/host-handoff.mjs +7 -0
- package/runtime/js/cm-ai/host-progress.mjs +18 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
- package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
- package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
- package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
- package/runtime/js/cm-ai/review-continuation.mjs +102 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
- package/runtime/js/cm-ai/review-package.mjs +25 -4
- package/runtime/js/cm-ai/review-presentation.mjs +31 -14
- package/runtime/js/cm-ai/review-runner.mjs +5 -4
- package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
- package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
- package/runtime/js/cm-ai/task-commit.mjs +7 -4
- package/runtime/js/cm-ai/task-owner.mjs +5 -2
- package/runtime/js/cm-ai/task-runner.mjs +343 -52
- package/runtime/js/cm-ai/worker-claude-developer.mjs +3 -1
- package/runtime/js/cm-ai/worker-claude.mjs +5 -1
- package/runtime/js/cm-check/host.mjs +13 -3
- package/runtime/js/cm-fix/diagnosis.mjs +16 -3
- package/runtime/js/cm-fix/execution.mjs +47 -9
- package/runtime/js/cm-fix/finish.mjs +9 -1
- package/runtime/js/cm-fix/step-timing.mjs +222 -0
- package/runtime/js/cm-idea/session.mjs +22 -3
- package/runtime/js/cm-init/review-evidence.mjs +20 -7
- package/runtime/js/cm-prd/ai-draft.mjs +260 -0
- package/runtime/js/cm-prd/analysis.mjs +27 -9
- package/runtime/js/cm-prd/change.mjs +29 -8
- package/runtime/js/cm-prd/failed-correction.mjs +24 -4
- package/runtime/js/cm-prd/narrow-review.mjs +63 -3
- package/runtime/js/cm-prd/review-channels.mjs +5 -0
- package/runtime/js/cm-prd/review-correction.mjs +65 -5
- package/runtime/js/cm-prd/review-disposition.mjs +10 -1
- package/runtime/js/cm-prd/review-publication.mjs +2 -1
- package/runtime/js/cm-prd/self-check.mjs +121 -9
- package/runtime/js/cm-prd/session.mjs +55 -13
- package/runtime/js/cm-prd/summary.mjs +34 -6
- package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
- package/runtime/js/cm-refactor/records.mjs +82 -11
- package/runtime/js/cm-refactor/workflow.mjs +3 -1
- package/runtime/js/executor-version.mjs +81 -0
- package/runtime/js/python-log-writer.mjs +15 -0
- package/runtime/js/run-analysis.mjs +136 -11
- package/runtime/logging.md +6 -0
- package/runtime/review.md +2 -1
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.mjs +27 -1
- package/scripts/cm-ai-admission.test.mjs +34 -2
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
- package/scripts/cm-ai-batch-drive.mjs +54 -17
- package/scripts/cm-ai-batch-drive.test.mjs +123 -6
- package/scripts/cm-ai-batch-host.mjs +64 -11
- package/scripts/cm-ai-batch-host.test.mjs +23 -3
- package/scripts/cm-ai-batch-location.test.mjs +22 -1
- package/scripts/cm-ai-batch-merge.mjs +102 -0
- package/scripts/cm-ai-batch-plan.mjs +55 -2
- package/scripts/cm-ai-batch-plan.test.mjs +228 -6
- package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
- package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
- package/scripts/cm-ai-batch-run.mjs +437 -34
- package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
- package/scripts/cm-ai-completion-summary.test.mjs +2 -1
- package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
- package/scripts/cm-ai-direct-review.test.mjs +1 -1
- package/scripts/cm-ai-disk-edits.test.mjs +229 -0
- package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
- package/scripts/cm-ai-drive.mjs +66 -14
- package/scripts/cm-ai-drive.test.mjs +13 -3
- package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
- package/scripts/cm-ai-host.mjs +20 -9
- package/scripts/cm-ai-host.test.mjs +12 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
- package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
- package/scripts/cm-ai-review-continuation.test.mjs +335 -0
- package/scripts/cm-ai-review-failure.test.mjs +13 -10
- package/scripts/cm-ai-review-timeout.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +42 -11
- package/scripts/cm-ai-run.test.mjs +26 -0
- package/scripts/cm-ai-supersede.test.mjs +10 -2
- package/scripts/cm-capability-gate.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +54 -0
- package/scripts/cm-check-runtime.sh +27 -15
- package/scripts/cm-check-update.mjs +83 -8
- package/scripts/cm-check-update.test.mjs +114 -1
- package/scripts/cm-claude-developer-worker.test.mjs +29 -1
- package/scripts/cm-claude-managed-preflight.test.mjs +126 -0
- package/scripts/cm-claude-probe.test.mjs +5 -0
- package/scripts/cm-claude-review-stream.test.mjs +4 -1
- package/scripts/cm-claude-worker.test.mjs +29 -0
- package/scripts/cm-codex-prompt-input.test.mjs +2 -1
- package/scripts/cm-developer-self-review.test.mjs +27 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
- package/scripts/cm-efficiency-response.test.mjs +2 -1
- package/scripts/cm-executor-version-draft.test.mjs +251 -0
- package/scripts/cm-executor-version-entries.test.mjs +93 -0
- package/scripts/cm-executor-version-prd.test.mjs +154 -0
- package/scripts/cm-executor-version-records.test.mjs +256 -0
- package/scripts/cm-executor-version.test.mjs +250 -0
- package/scripts/cm-external-model-host.test.mjs +6 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
- package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
- package/scripts/cm-fix-drive.mjs +7 -2
- package/scripts/cm-fix-drive.test.mjs +45 -0
- package/scripts/cm-fix-entry.mjs +5 -2
- package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
- package/scripts/cm-fix-host.mjs +9 -2
- package/scripts/cm-fix-review-preflight.mjs +2 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +19 -0
- package/scripts/cm-fix-test-extension.test.mjs +30 -2
- package/scripts/cm-host-check.test.mjs +12 -0
- package/scripts/cm-host-qa-executor.test.mjs +172 -1
- package/scripts/cm-host-qa-policy.test.mjs +55 -1
- package/scripts/cm-idea-drive.mjs +5 -2
- package/scripts/cm-idea-entry.mjs +5 -2
- package/scripts/cm-idea-host.mjs +3 -1
- package/scripts/cm-init-drive.mjs +8 -5
- package/scripts/cm-init-entry.mjs +5 -2
- package/scripts/cm-init-host.mjs +6 -2
- package/scripts/cm-log-event.mjs +10 -2
- package/scripts/cm-log-event.test.mjs +29 -0
- package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
- package/scripts/cm-prd-ai-draft.test.mjs +505 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
- package/scripts/cm-prd-completion.test.mjs +67 -4
- package/scripts/cm-prd-design-phase.test.mjs +48 -13
- package/scripts/cm-prd-drive.mjs +91 -21
- package/scripts/cm-prd-drive.test.mjs +126 -4
- package/scripts/cm-prd-entry.mjs +5 -2
- package/scripts/cm-prd-host.mjs +89 -20
- package/scripts/cm-prd-host.test.mjs +17 -8
- package/scripts/cm-prd-narrow-review.test.mjs +49 -1
- package/scripts/cm-prd-review-disposition.test.mjs +94 -1
- package/scripts/cm-prd-review-gate.mjs +13 -5
- package/scripts/cm-prd-review-publication.test.mjs +34 -0
- package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
- package/scripts/cm-prd-self-check.test.mjs +1 -1
- package/scripts/cm-refactor-drive.mjs +10 -4
- package/scripts/cm-refactor-entry.mjs +5 -2
- package/scripts/cm-refactor-host.mjs +3 -1
- package/scripts/cm-release-smoke.sh +3 -2
- package/scripts/cm-run-analysis.test.mjs +373 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
- package/scripts/cm-skill-hints-exam.mjs +3 -1
- package/scripts/cm-skill-hints-install.test.mjs +1 -1
- package/scripts/cm-skill-hints.mjs +106 -10
- package/scripts/cm-skill-hints.test.mjs +162 -6
- package/scripts/cm-skill-judge.mjs +2 -1
- package/scripts/cm-task-gate.mjs +88 -18
- package/scripts/cm-task-scope.test.mjs +1 -1
- package/scripts/cm-test-drive.mjs +13 -8
- package/scripts/cm-test-entry.mjs +5 -2
- package/scripts/cm-test-host.mjs +3 -1
- package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
- package/scripts/cm-workflow-config.test.mjs +8 -3
- package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +10 -1
- package/scripts/policy-binding-compat.test.mjs +3 -2
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/shell-pipe-early-exit.test.mjs +96 -0
- package/scripts/test-cm-prd-review-gate.py +55 -0
- package/scripts/test-shell-compat.sh +7 -5
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -2
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/js-host-recovery.md +5 -1
- package/skills/cm-ai/references/js-host.md +17 -8
- package/skills/cm-check/SKILL.md +3 -0
- package/skills/cm-fix/references/isolated-review.md +1 -1
- package/skills/cm-fix/references/js-host.md +20 -0
- package/skills/cm-fix/references/test-extension.md +1 -1
- package/skills/cm-prd/SKILL.md +8 -6
- package/skills/cm-prd/references/ai-draft.md +81 -0
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/greenfield.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -2
- package/skills/cm-prd/references/js-host.md +9 -6
- package/skills/cm-prd/references/light-mode.md +19 -0
- package/skills/cm-prd/references/requirement-grilling.md +2 -0
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-prd/references/summary-card.md +1 -0
- package/templates/auto-update/cm-update.sh +2 -2
|
@@ -12,6 +12,7 @@ import {assertCreatableScope} from './cm-ai-run.mjs';
|
|
|
12
12
|
import {createConversationExecution,readConversationReviewConfiguration,readConversationReviewConfigurationValue,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
|
|
13
13
|
import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
14
14
|
import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
|
|
15
|
+
import {claudeProbeDiagnosis} from '../runtime/js/cm-ai/claude-probe-diagnosis.mjs';
|
|
15
16
|
import {claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
16
17
|
import {createHostToolBridge,HOST_ANSWER_BACKSTOP_MS} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
17
18
|
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
@@ -19,12 +20,13 @@ import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapa
|
|
|
19
20
|
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
20
21
|
import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
|
|
21
22
|
import {readControlPolicyFile} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
23
|
+
import {EXECUTOR_REASON_CODES} from '../runtime/js/executor-version.mjs';
|
|
22
24
|
|
|
23
|
-
const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development --review-config PATH (required for a new batch; later launches pass the same file) [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--input-limit BYTES] [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa [--qa-environment-failure REASON]] [--allow-develop-redo FEATURE/TASK]... [--allow-abandon-effect FEATURE/TASK]... [--allow-abandon-review FEATURE/TASK]... [--allow-bootstrap-review-recovery FEATURE/TASK]... [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]... [--hold-revision FEATURE/TASK]...';
|
|
25
|
+
const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development --review-config PATH (required for a new batch; later launches pass the same file) [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--review-runtime codex|claude] [--input-limit BYTES] [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa [--qa-environment-failure REASON]] [--allow-develop-redo FEATURE/TASK]... [--allow-abandon-effect FEATURE/TASK]... [--allow-abandon-review FEATURE/TASK]... [--allow-bootstrap-review-recovery FEATURE/TASK]... [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]... [--hold-revision FEATURE/TASK]...';
|
|
24
26
|
const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
|
|
25
27
|
// Operator-facing reasons the batch owner writes itself (R4); others stay redacted.
|
|
26
|
-
const REASONED=new Set(['batch_resources_open','legacy_preflight_cache_invalid']);
|
|
27
|
-
const boundedReason=error=>REASONED.has(error?.code)&&typeof error.reason==='string'&&error.reason
|
|
28
|
+
const REASONED=new Set(['batch_resources_open','tool_preflight_missing','review_preflight_failed','legacy_preflight_cache_invalid','batch_qa_cadence_changed','batch_member_store_unreadable',...EXECUTOR_REASON_CODES]);
|
|
29
|
+
const boundedReason=error=>REASONED.has(error?.code)&&typeof error.reason==='string'&&Buffer.byteLength(error.reason,'utf8')<=8192&&!/[\r\n\0]/.test(error.reason)?error.reason:null;
|
|
28
30
|
const actionFlags=new Map(Object.entries(BATCH_MEMBER_ACTIONS).map(([name,{flag}])=>[flag,name]));
|
|
29
31
|
// Single-task recovery inputs a batch cannot take: each member's fingerprint binds
|
|
30
32
|
// the whole batch workflow map, and a member cannot be rebound alone.
|
|
@@ -33,6 +35,20 @@ const UNSUPPORTED={'--revise-qa-config':'batch_qa_revision_unavailable','--qa-co
|
|
|
33
35
|
const UNSUPPORTED_REASON={batch_qa_revision_unavailable:'批次不能修订单个成员的 QA 配置:每个成员的运行指纹绑定整批 workflows,改一个成员会让其他成员都无法恢复,单任务宿主也打不开批次成员运行。出口:QA 环境问题用 --rerun-blocked-qa(必要时加 --qa-environment-failure 原因);确需改 QA 命令,取消本批次后用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务',
|
|
34
36
|
batch_spec_rebind_unavailable:'批次成员不能换绑规格。出口:还原这些规格改动并重新批准后继续本批次;或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务'};
|
|
35
37
|
|
|
38
|
+
// Which launch input picked a batch member's reviewer, for a tool_preflight_missing reason.
|
|
39
|
+
// --review-runtime (#302) is refused with --protected-config and --external-models, so those
|
|
40
|
+
// batches are never told to add it (Codex round 4).
|
|
41
|
+
export function batchReviewerNote({runtime,reviewRuntime,protectedBatch,externalModels}){
|
|
42
|
+
const host=runtime??'codex,未传时的缺省值';
|
|
43
|
+
if(protectedBatch&&externalModels)return '。本批次带 --protected-config 且已冻结外部模型:所有成员的审查端都是项目 roles 声明的审查方'
|
|
44
|
+
+'(上面已写明本成员实际是哪一端),这类批次不能用 --review-runtime';
|
|
45
|
+
if(protectedBatch)return '。本批次带 --protected-config:provider 开发的成员与 v2 provider 批次里由会话开发的成员,审查端是项目 roles 声明的审查方;'
|
|
46
|
+
+`legacy 受保护批次里其余由会话开发的成员,审查端是宿主 --runtime(本次 ${host})。上面已写明本成员实际是哪一端;受保护批次不能用 --review-runtime`;
|
|
47
|
+
if(externalModels)return `。本批次已冻结外部模型:审查端是宿主 --runtime(本次 ${host}),这类批次不能用 --review-runtime`;
|
|
48
|
+
if(reviewRuntime!==null)return `。本批次用 --review-runtime ${reviewRuntime} 选审查端:当前会话开发的成员由 ${reviewRuntime} 审查`;
|
|
49
|
+
return `。本批次没传 --review-runtime:当前会话开发的成员,审查端就是宿主 --runtime(本次 ${host});`
|
|
50
|
+
+'要由另一端审查,只能在新批次启动时加 --review-runtime(须与项目 roles 一致,不能与 --protected-config、--external-models 同用,开跑后不能补加或改值)';
|
|
51
|
+
}
|
|
36
52
|
export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
|
|
37
53
|
return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
|
|
38
54
|
}
|
|
@@ -148,12 +164,18 @@ async function memberReviewConfiguration(batch,definition,review,runtime,pair=nu
|
|
|
148
164
|
}
|
|
149
165
|
need(allowPreflight,'review_preflight_missing');
|
|
150
166
|
const config=await runReviewPreflight(definition,{model:review.model,...(pair?{effort:pair.effort}:{}),runtime,disabledSkills:review.disabledSkills});
|
|
151
|
-
|
|
167
|
+
if(!matches(config)){
|
|
168
|
+
const reason=runtime==='claude'?claudeProbeDiagnosis(config):null;
|
|
169
|
+
throw Object.assign(new Error('review_preflight_failed'),{code:'review_preflight_failed',...(reason?{reason}:{})});
|
|
170
|
+
}
|
|
152
171
|
const temporary=`${file}.${process.pid}.tmp`;
|
|
153
172
|
fs.writeFileSync(temporary,JSON.stringify(config)+'\n',{flag:'wx',mode:0o600});
|
|
154
173
|
try{fs.renameSync(temporary,file);}finally{if(fs.existsSync(temporary))fs.unlinkSync(temporary);}
|
|
155
174
|
return withTimeout(config);
|
|
156
|
-
}catch
|
|
175
|
+
}catch(error){
|
|
176
|
+
if(error?.code==='review_preflight_failed'&&typeof error.reason==='string')throw error;
|
|
177
|
+
need(false,'review_preflight_failed');
|
|
178
|
+
}
|
|
157
179
|
}
|
|
158
180
|
|
|
159
181
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
@@ -178,6 +200,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
178
200
|
const stat=fs.lstatSync(argv[2]);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_batch_config');
|
|
179
201
|
const bundle=json(JSON.parse(fs.readFileSync(argv[2],'utf8')));shape(bundle,['batch','workflows',...(Object.hasOwn(bundle,'bootstraps')?['bootstraps']:[])]);
|
|
180
202
|
const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
|
|
203
|
+
// reviewRuntime is added by this host from --review-runtime only; a bundle that carries it
|
|
204
|
+
// would bind a reviewer into the plan digest that no member actually uses.
|
|
205
|
+
if(Object.hasOwn(batch,'reviewRuntime'))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
|
|
206
|
+
reason:'批次配置文件不能写 reviewRuntime;审查端只用启动参数 --review-runtime 选择'});
|
|
181
207
|
need(workflows!==null&&typeof workflows==='object'&&!Array.isArray(workflows),'invalid_batch_config');
|
|
182
208
|
const keys=batch.tasks.map(task=>`${task.feature}/${task.taskId}`);
|
|
183
209
|
// Grammar 3 execution table (batch-plan.mjs; validated again by createCmAiBatch): the
|
|
@@ -191,7 +217,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
191
217
|
}
|
|
192
218
|
need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
|
|
193
219
|
for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
|
|
194
|
-
let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
|
|
220
|
+
let review=null,allowQa=false,allowBootstrap=false,runtime=null,reviewRuntime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
|
|
195
221
|
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false,qaEnvironmentFailure=null;const developments=new Map(),holds=new Set();
|
|
196
222
|
const memberActions=Object.fromEntries(Object.keys(BATCH_MEMBER_ACTIONS).map(name=>[name,[]]));
|
|
197
223
|
let externalEnabled=false,externalFile,executionPolicyEnabled=false;
|
|
@@ -239,6 +265,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
239
265
|
else if(name==='--runtime'){
|
|
240
266
|
need(runtime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');runtime=argv[++index];
|
|
241
267
|
}
|
|
268
|
+
else if(name==='--review-runtime'){
|
|
269
|
+
need(reviewRuntime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');reviewRuntime=argv[++index];
|
|
270
|
+
}
|
|
242
271
|
else if(name==='--input-limit'){
|
|
243
272
|
need(inputLimitRaw===undefined&&typeof argv[index+1]==='string','invalid_arguments');
|
|
244
273
|
inputLimitRaw=argv[++index];parseHostInputLimit(inputLimitRaw);
|
|
@@ -265,7 +294,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
265
294
|
if(!Object.hasOwn(bootstraps??{},keys[index])&&!fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,keys[index]),'state.json')))
|
|
266
295
|
try{assertCreatableScope(task.scope);}catch(cause){cause.reason=`${keys[index]}: ${cause.reason}`;throw cause;}
|
|
267
296
|
const executionPolicy=readBatchExecutionPolicy({batch,started,enabled:executionPolicyEnabled});
|
|
268
|
-
|
|
297
|
+
// --review-runtime (same as the single-task host): the current session develops and
|
|
298
|
+
// the other declared tool reviews. Only for session-developed members; the provider
|
|
299
|
+
// and external-model routes pick their reviewer from roles. It is bound into every
|
|
300
|
+
// member configuration and the batch plan digest, so a batch resumes only with it.
|
|
301
|
+
if(reviewRuntime!==null&&(providerConfig||externalEnabled))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
|
|
302
|
+
reason:'--review-runtime 只用于当前会话开发的批次;--protected-config 与 --external-models 按 roles 自行选择审查端'});
|
|
303
|
+
const routes=providerConfig?resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex'):{reviewerRuntime:reviewRuntime??runtime??'codex'};
|
|
269
304
|
const externalModels=readBatchExternalModels({batch,started,enabled:externalEnabled,inputFile:externalFile,providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
|
|
270
305
|
if(providerConfig&&!externalModels)shape(providerConfig,['model','checkCommands','timeoutMs']);
|
|
271
306
|
if(providerConfig&&externalModels){
|
|
@@ -275,6 +310,17 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
275
310
|
providerConfig={...providerConfig,...pair};
|
|
276
311
|
}
|
|
277
312
|
need(!sessionMembers.size||!externalModels&&!executionPolicy,'session_member_unsupported_config');
|
|
313
|
+
if(reviewRuntime!==null){
|
|
314
|
+
if(reviewRuntime===(runtime??'codex'))throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
|
|
315
|
+
reason:`--review-runtime 只用于让另一工具审查;它和写代码方都是 ${reviewRuntime}。由当前工具全新上下文审查时省略 --review-runtime`});
|
|
316
|
+
if(externalModels)throw Object.assign(new Error('invalid_arguments'),{code:'invalid_arguments',
|
|
317
|
+
reason:'本批次已冻结外部模型,审查端按 roles 选择,不能再传 --review-runtime'});
|
|
318
|
+
const declared=resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex');
|
|
319
|
+
if(digest(declared)!==digest({coderRuntime:runtime??'codex',reviewerRuntime:reviewRuntime}))
|
|
320
|
+
throw Object.assign(new Error('runtime_selection_mismatch'),{code:'runtime_selection_mismatch',
|
|
321
|
+
reason:`项目声明写代码方 ${declared.coderRuntime}、审查方 ${declared.reviewerRuntime};本次是 --runtime ${runtime??'codex(缺省)'}、`
|
|
322
|
+
+`--review-runtime ${reviewRuntime}。按声明改参数,或先用 cm-runtime 改声明`});
|
|
323
|
+
}
|
|
278
324
|
// A v2 provider batch: a session member's coder is this host, so it must be the
|
|
279
325
|
// declared coder; it is reviewed by the declared reviewer like the provider members
|
|
280
326
|
// (reviewRuntime), never by the host itself.
|
|
@@ -315,7 +361,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
315
361
|
hostCallTail=pending.then(()=>{},()=>{});return pending;
|
|
316
362
|
}};
|
|
317
363
|
let reconciling=false;
|
|
318
|
-
const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
364
|
+
const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(reviewRuntime!==null?{reviewRuntime}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
319
365
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
320
366
|
rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),workflows,
|
|
321
367
|
executionFor:async(definition,{parallelMember=false,soloMember=false}={})=>{
|
|
@@ -326,7 +372,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
326
372
|
// declared one for a provider-developed member (the host runtime may be the coder
|
|
327
373
|
// there), else the one this member always had (host runtime, or the external route).
|
|
328
374
|
const memberReviewer=developments.has(key)?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime??'codex').reviewerRuntime
|
|
329
|
-
:externalModels?routes.reviewerRuntime:runtime??'codex';
|
|
375
|
+
:externalModels?routes.reviewerRuntime:reviewRuntime??runtime??'codex';
|
|
330
376
|
const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,memberReviewer,externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
|
|
331
377
|
const execution=createConversationExecution(definition,hostContextId,parallelMember?memberBridge:bridge,memberReview,null,workflows[key],allowQa,runtime??'codex',
|
|
332
378
|
{parallelMember,...(soloMember?{soloMember}:{}),...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),
|
|
@@ -334,6 +380,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
334
380
|
batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}
|
|
335
381
|
:Object.hasOwn(batch,'memberDevelopment')?{workflows,bootstraps,memberDevelopment:batch.memberDevelopment}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
336
382
|
...(sessionMembers.has(key)?{memberDevelopment:'session',...(sessionReviewRuntime!==null?{reviewRuntime:sessionReviewRuntime}:{})}:{}),
|
|
383
|
+
...(reviewRuntime!==null?{reviewRuntime}:{}),
|
|
337
384
|
// A protected CLI config also protects unauthorized tasks: they stay on the
|
|
338
385
|
// current-session transport but with the same sandbox checks (protected-text edits).
|
|
339
386
|
...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
|
|
@@ -357,13 +404,19 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
357
404
|
}
|
|
358
405
|
return result;
|
|
359
406
|
}
|
|
360
|
-
catch(cause){
|
|
407
|
+
catch(cause){
|
|
408
|
+
// Appended before the bound check, so the whole reason stays one line within 8192 bytes.
|
|
409
|
+
const note=cause?.code==='tool_preflight_missing'&&typeof cause.reason==='string'
|
|
410
|
+
?batchReviewerNote({runtime,reviewRuntime,protectedBatch:Boolean(providerConfig),externalModels:Boolean(externalModels)}):'';
|
|
411
|
+
const reason=boundedReason(note?{code:cause.code,reason:cause.reason+note}:cause);
|
|
412
|
+
return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};
|
|
413
|
+
}
|
|
361
414
|
}};
|
|
362
415
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
363
416
|
try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
|
|
364
417
|
finally{if(rawMode)input.setRawMode(false);}
|
|
365
418
|
return 0;
|
|
366
|
-
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope','session_coder_runtime_mismatch',...Object.keys(UNSUPPORTED_REASON)].includes(code)
|
|
419
|
+
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope','session_coder_runtime_mismatch','runtime_selection_mismatch',...Object.keys(UNSUPPORTED_REASON),...EXECUTOR_REASON_CODES].includes(code)
|
|
367
420
|
&&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
|
|
368
421
|
finally{bridge?.close();}
|
|
369
422
|
}
|
|
@@ -60,7 +60,9 @@ function fixture(runtime='codex'){
|
|
|
60
60
|
...(runtime==='claude'?{provider:runtime}:{}),prompt_transport:'stdin',
|
|
61
61
|
config_fingerprint:(runtime==='claude'?claudeReviewFingerprint:configFingerprint)({cwd:codeProject,model:'fixture'})}}));
|
|
62
62
|
const fake=path.join(bin,runtime);fs.copyFileSync(fileURLToPath(new URL(`./fixtures/${runtime}-review-process.mjs`,import.meta.url)),fake);fs.chmodSync(fake,0o700);
|
|
63
|
-
|
|
63
|
+
// The fixed call sequences below assume completion check reuse; an outer off switch must not leak in.
|
|
64
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH};delete env.CM_AI_COMPLETION_CHECK_REUSE;
|
|
65
|
+
return {runtime,root,specsDir,codeProject,config,review,batch,env,
|
|
64
66
|
args:['serve','--config',config,'--host-context','current-batch-host','--allow-development','--review-config',review,'--allow-qa',
|
|
65
67
|
...(runtime==='claude'?['--runtime','claude']:[])]};
|
|
66
68
|
}
|
|
@@ -191,7 +193,8 @@ for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves hel
|
|
|
191
193
|
assert.equal(first.result.identity.taskId,'T-002');assert.equal(first.result.state,'changes_requested');
|
|
192
194
|
assert.equal(first.result.identity.attempt,2);assert.equal(first.result.code,'revision_answer_required');
|
|
193
195
|
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-002'));
|
|
194
|
-
|
|
196
|
+
// A new run completes T-001 on its reviewed checks (completion check reuse): one check call.
|
|
197
|
+
assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:qa_assess',
|
|
195
198
|
'T-002:develop','T-002:documentation_sync','T-002:check']);
|
|
196
199
|
const original=fs.readFileSync(f.config,'utf8'),changed=JSON.parse(original);
|
|
197
200
|
changed.workflows['1.work/T-002'].documentationPaths=[];
|
|
@@ -206,7 +209,7 @@ for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves hel
|
|
|
206
209
|
}
|
|
207
210
|
const second=await execute(f);assert.equal(second.code,0,second.stderr);
|
|
208
211
|
assert.equal(second.result.state,'run_done',JSON.stringify(second.result));
|
|
209
|
-
assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check',
|
|
212
|
+
assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check',
|
|
210
213
|
'T-002:qa_assess','T-002:documentation_inspect']);
|
|
211
214
|
const reopened=await execute(f);assert.equal(reopened.code,0,reopened.stderr);
|
|
212
215
|
assert.equal(reopened.result.state,'run_done',JSON.stringify(reopened.result));
|
|
@@ -265,6 +268,7 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
265
268
|
const failed=await execute(f);
|
|
266
269
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
267
270
|
assert.equal(failed.result.currentTask,'1.work/T-002');assert.deepEqual(failed.calls,[]);
|
|
271
|
+
assert.equal(failed.result.reason,undefined,'a Codex preflight failure carries no Claude managed-endpoint reason');
|
|
268
272
|
assert.equal(probes().length,2);
|
|
269
273
|
fs.unlinkSync(fail);
|
|
270
274
|
const held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
@@ -591,3 +595,19 @@ test('Q24 batch host recovers a serial member stopped at develop_redo and contin
|
|
|
591
595
|
}finally{fs.rmSync(g.root,{recursive:true,force:true});}
|
|
592
596
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
593
597
|
});
|
|
598
|
+
|
|
599
|
+
// Codex 第四轮:受保护批次与外部模型批次不能用 --review-runtime,说明不能让人去加它。
|
|
600
|
+
test('the tool_preflight_missing batch note names the input that picked the reviewer',async()=>{
|
|
601
|
+
const {batchReviewerNote}=await import('./cm-ai-batch-host.mjs');
|
|
602
|
+
const roles=batchReviewerNote({runtime:'codex',reviewRuntime:null,protectedBatch:true,externalModels:false});
|
|
603
|
+
assert.match(roles,/--protected-config.*项目 roles 声明的审查方/);assert.doesNotMatch(roles,/加 --review-runtime|cm-runtime/);
|
|
604
|
+
// Codex 第五轮:legacy 受保护批次里其余会话成员由宿主 --runtime 审;外部模型恢复时可不带旗标。
|
|
605
|
+
assert.match(roles,/legacy.*其余.*宿主 --runtime(本次 codex)/);
|
|
606
|
+
const external=batchReviewerNote({runtime:'claude',reviewRuntime:null,protectedBatch:false,externalModels:true});
|
|
607
|
+
assert.match(external,/已冻结外部模型.*宿主 --runtime(本次 claude).*不能用 --review-runtime/);assert.doesNotMatch(external,/加 --review-runtime|带 --external-models/);
|
|
608
|
+
// Codex 第六轮:受保护且冻结外部模型时,所有成员都按 roles 审查,不再说 legacy 会话成员由宿主审。
|
|
609
|
+
const both=batchReviewerNote({runtime:'codex',reviewRuntime:null,protectedBatch:true,externalModels:true});
|
|
610
|
+
assert.match(both,/--protected-config.*已冻结外部模型.*所有成员.*项目 roles 声明的审查方/);assert.doesNotMatch(both,/宿主 --runtime(本次/);
|
|
611
|
+
assert.match(batchReviewerNote({runtime:'claude',reviewRuntime:'codex',protectedBatch:false,externalModels:false}),/--review-runtime codex.*由 codex 审查/);
|
|
612
|
+
assert.match(batchReviewerNote({runtime:null,reviewRuntime:null,protectedBatch:false,externalModels:false}),/没传 --review-runtime.*宿主 --runtime(本次 codex,未传时的缺省值).*新批次启动时加 --review-runtime/);
|
|
613
|
+
});
|
|
@@ -6,7 +6,8 @@ import assert from 'node:assert/strict';
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
-
import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
9
|
+
import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch,batchQaCadence} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
10
|
+
import {soloQaBase} from '../runtime/js/cm-ai/batch-plan.mjs';
|
|
10
11
|
|
|
11
12
|
function specs(t,rows=[]){
|
|
12
13
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-location-')));
|
|
@@ -55,3 +56,23 @@ test('the segment is a safe single path component and ref component',()=>{
|
|
|
55
56
|
for(const id of ['a','a.b.c.d.e.f.g.h','....----','batch_2026.10.23-x'])
|
|
56
57
|
assert.match(batchSegment(id),/^[A-Za-z0-9_-]{1,8}-[a-f0-9]{12}$/,id);
|
|
57
58
|
});
|
|
59
|
+
|
|
60
|
+
// Reviews q2/q3: one N6 count per batch. batch_start fixes it; before that, a member run an
|
|
61
|
+
// older host already initialized (e.g. by a status call) keeps the batch on the old count.
|
|
62
|
+
test('the batch QA cadence: batch_start first, then members already initialized',t=>{
|
|
63
|
+
const specsDir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-cadence-')));
|
|
64
|
+
t.after(()=>fs.rmSync(specsDir,{recursive:true,force:true}));
|
|
65
|
+
const log=path.join(specsDir,'运行日志.jsonl');
|
|
66
|
+
const snapshots={};const read=runId=>snapshots[runId]??null;
|
|
67
|
+
const cadence=()=>batchQaCadence({specsDir,batchId:'batch-cadence',runIds:['m1','m2'],readSnapshot:read});
|
|
68
|
+
assert.equal(cadence(),'feature-v1');
|
|
69
|
+
snapshots.m1={records:[]};assert.equal(cadence(),'feature-v1','an empty store froze nothing');
|
|
70
|
+
snapshots.m2={records:[{payload:{config:{qaCadence:'feature-v1'}}}]};assert.equal(cadence(),'feature-v1');
|
|
71
|
+
snapshots.m1={records:[{payload:{config:{}}}]};assert.equal(cadence(),'legacy');
|
|
72
|
+
const start={workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:'batch-cadence'};
|
|
73
|
+
fs.writeFileSync(log,JSON.stringify({...start,qa_cadence:'feature-v1'})+'\n');
|
|
74
|
+
assert.equal(cadence(),'feature-v1','batch_start decides once written');
|
|
75
|
+
fs.writeFileSync(log,JSON.stringify(start)+'\n');delete snapshots.m1;
|
|
76
|
+
assert.equal(cadence(),'legacy');
|
|
77
|
+
assert.throws(()=>soloQaBase({specsDir,codeProject:specsDir,feature:'1.work',repositoryId:'r',qaCadence:'other'}),{code:'invalid_input'});
|
|
78
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Git evidence for merge-before-complete batches. The coordinator owns journaling
|
|
2
|
+
// and the N5 capability. This module only checks and prepares Git images.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {randomUUID} from 'node:crypto';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
8
|
+
|
|
9
|
+
export const gitOid=value=>typeof value==='string'&&/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
|
|
10
|
+
const sorted=items=>[...items].sort();
|
|
11
|
+
const gitEntry=(git,repo,tree,name)=>git(repo,['--literal-pathspecs','ls-tree','-z',tree,'--',name]);
|
|
12
|
+
const fileMode=mode=>mode&0o100?'100755':'100644';
|
|
13
|
+
function blobEntry(repo,name,mode,bytes,options,code){
|
|
14
|
+
const hash=spawnSync('git',['-C',repo,'hash-object','--stdin'],{...options,input:bytes});
|
|
15
|
+
need(hash.status===0&&gitOid(hash.stdout.trim()),code);
|
|
16
|
+
return `${mode} blob ${hash.stdout.trim()}\t${name}\0`;
|
|
17
|
+
}
|
|
18
|
+
const diffPaths=(git,repo,from,to)=>git(repo,['diff','--no-renames','--name-only','-z',from,to]).split('\0').filter(Boolean);
|
|
19
|
+
|
|
20
|
+
export function verifyStagedDelivery(git,repo,base,tree,changes,options){
|
|
21
|
+
need(JSON.stringify(sorted(diffPaths(git,repo,base,tree)))===JSON.stringify(sorted(changes.map(item=>item.path))),
|
|
22
|
+
'batch_member_delivery_changed');
|
|
23
|
+
for(const {path:name,after} of changes){
|
|
24
|
+
if(after===null)continue;
|
|
25
|
+
const link=after.type==='symlink';
|
|
26
|
+
const mode=link?'120000':fileMode(after.mode);
|
|
27
|
+
const bytes=link?Buffer.from(after.target):Buffer.from(after.contentBase64,'base64');
|
|
28
|
+
const code='batch_member_delivery_changed';
|
|
29
|
+
need(gitEntry(git,repo,tree,name)===blobEntry(repo,name,mode,bytes,options,code),code);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function verifyIntegratedTree(git,repo,intent,tree,{allowUnion=false}={}){
|
|
34
|
+
const changed=diffPaths(git,repo,intent.member_base,intent.member_commit);
|
|
35
|
+
const integrated=diffPaths(git,repo,intent.expected_old,tree);
|
|
36
|
+
need(integrated.every(name=>changed.includes(name)),'batch_merge_delivery_changed');
|
|
37
|
+
const entry=(ref,name)=>gitEntry(git,repo,ref,name);
|
|
38
|
+
for(const name of changed){
|
|
39
|
+
const merged=entry(tree,name),member=entry(intent.member_commit,name);
|
|
40
|
+
if(merged===member)continue;
|
|
41
|
+
// Git's configured union driver is allowed to combine the two reviewed
|
|
42
|
+
// instruction files. Freeze that index tree before letting Git commit it.
|
|
43
|
+
need(allowUnion&&name.split('/').at(-1)==='AGENTS.md'&&merged&&member
|
|
44
|
+
&&entry(intent.expected_old,name)!==entry(intent.member_base,name),'batch_merge_delivery_changed');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Git status may hide paths with skip-worktree or assume-unchanged set.
|
|
49
|
+
export function verifyCheckoutDelivery(git,repo,base,tree,options,code,expectedTree=tree){
|
|
50
|
+
for(const name of diffPaths(git,repo,base,tree)){
|
|
51
|
+
const file=path.resolve(repo,name),parent=path.dirname(file);
|
|
52
|
+
need(file.startsWith(repo+path.sep),code);
|
|
53
|
+
const expected=gitEntry(git,repo,expectedTree,name);
|
|
54
|
+
let stat;
|
|
55
|
+
try{stat=fs.lstatSync(file);}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
56
|
+
if(!stat){need(!expected,code);continue;}
|
|
57
|
+
need(fs.realpathSync(parent)===parent&&(stat.isFile()||stat.isSymbolicLink()),code);
|
|
58
|
+
const mode=stat.isSymbolicLink()?'120000':fileMode(stat.mode);
|
|
59
|
+
const bytes=stat.isSymbolicLink()?fs.readlinkSync(file,{encoding:'buffer'}):fs.readFileSync(file);
|
|
60
|
+
need(expected===blobEntry(repo,name,mode,bytes,options,code),code);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function mergeHead(git,repo){
|
|
65
|
+
const file=git(repo,['rev-parse','--path-format=absolute','--git-path','MERGE_HEAD']);
|
|
66
|
+
return fs.existsSync(file)?fs.readFileSync(file,'utf8').trim():null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const unionSuffix=Buffer.from('\nAGENTS.md merge=union\n');
|
|
70
|
+
const attributesPath=(git,repo)=>git(repo,['rev-parse','--path-format=absolute','--git-path','info/attributes']);
|
|
71
|
+
function attributeBytes(target){
|
|
72
|
+
let stat;
|
|
73
|
+
try{stat=fs.lstatSync(target);}catch(error){if(error.code==='ENOENT')return null;throw error;}
|
|
74
|
+
need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size<=8192,'batch_attributes_invalid');
|
|
75
|
+
return fs.readFileSync(target);
|
|
76
|
+
}
|
|
77
|
+
export const readBatchAttributes=(git,repo)=>attributeBytes(attributesPath(git,repo))?.toString('base64')??null;
|
|
78
|
+
function replaceAttributes(target,bytes){
|
|
79
|
+
if(bytes===null){fs.unlinkSync(target);return;}
|
|
80
|
+
fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
81
|
+
// The temporary is private and has no meaning to Git if the process dies.
|
|
82
|
+
const temporary=path.join(path.dirname(target),`cm-attributes-${randomUUID()}`);
|
|
83
|
+
try{
|
|
84
|
+
const mode=fs.existsSync(target)?fs.statSync(target).mode&0o777:0o644;
|
|
85
|
+
const fd=fs.openSync(temporary,'wx',mode);
|
|
86
|
+
try{fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);}finally{fs.closeSync(fd);}
|
|
87
|
+
fs.renameSync(temporary,target);
|
|
88
|
+
}finally{if(fs.existsSync(temporary))fs.unlinkSync(temporary);}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function batchUnionAttributes(git,repo,saved,{install=false}={}){
|
|
92
|
+
need(saved===null||typeof saved==='string'&&saved.length<=11000
|
|
93
|
+
&&Buffer.from(saved,'base64').toString('base64')===saved,'batch_history_invalid');
|
|
94
|
+
const target=attributesPath(git,repo),before=saved===null?null:Buffer.from(saved,'base64');
|
|
95
|
+
const after=Buffer.concat([before??Buffer.alloc(0),unionSuffix]),current=attributeBytes(target);
|
|
96
|
+
if(current?.equals(after)){
|
|
97
|
+
if(!install)replaceAttributes(target,before);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
need(current===null&&before===null||current?.equals(before??Buffer.alloc(0))&&before!==null,'batch_attributes_changed');
|
|
101
|
+
if(install)replaceAttributes(target,after);
|
|
102
|
+
}
|
|
@@ -27,6 +27,60 @@ function parse(argv){
|
|
|
27
27
|
}
|
|
28
28
|
return ['specsDir','codeProject','repositoryId','batchId'].every(key=>typeof input[key]==='string')?input:null;
|
|
29
29
|
}
|
|
30
|
+
// A config error says what is wrong instead of a bare code (2026-12-01 probe). Parser messages
|
|
31
|
+
// interpolate key names, field paths, file paths and file text, so a message is shown only when
|
|
32
|
+
// it matches, whole, one of the parser's fixed templates below (Codex rounds 1-5: every
|
|
33
|
+
// cut-and-replace scheme leaked). Field paths in "must be …" templates come from validateRaw,
|
|
34
|
+
// which rejects unknown keys first; credential checks run earlier on raw keys, so their
|
|
35
|
+
// location is never shown. Anything else is named by category only.
|
|
36
|
+
const CONTROL=/[\x00-\x1f\x7f-\x9f\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff]+/g;
|
|
37
|
+
const FIXED=new Set(['unclosed quote or inline collection','empty scalar is not allowed','unterminated quoted scalar',
|
|
38
|
+
'mapping key cannot be empty','mapping keys must be strings','tabs are not allowed for indentation','configuration is empty',
|
|
39
|
+
'root indentation must be zero','configuration nesting is too deep','expected an indented mapping or list','unexpected indentation',
|
|
40
|
+
'mixed mapping and list','empty list item',"expected 'key: value'",'unexpected content','invalid JSON: unterminated string',
|
|
41
|
+
'invalid JSON: object key must be a string',"invalid JSON: expected ':'","invalid JSON: expected ',' or '}'","invalid JSON: expected ',' or ']'",
|
|
42
|
+
'configuration must be a regular file','file exceeds configuration size limit','secret-like value is forbidden',
|
|
43
|
+
'configuration contains a secret-like value','user.runtimes.available conflicts with user.preset','configuration text must be a string',
|
|
44
|
+
'roles.external_expert must use adapter external-browser and source browser','policies.tests includes browser but roles.browser_qa.adapter is not browser',
|
|
45
|
+
'invalid_runtime','runtime_not_declared','cross_runtime_review_required']);
|
|
46
|
+
const FIELD='(?:config|user|project|roles|policies|parallel|runtimes|preset)(?:\\.[a-z_]{1,32}){0,4}';
|
|
47
|
+
const TEMPLATES=[/^invalid JSON near byte \d+$/,/^configuration(?: text)? exceeds \d+ bytes$/,
|
|
48
|
+
new RegExp(`^${FIELD} (?:must be a mapping|must be a non-empty string|contains unsupported characters|must be boolean|must equal integer 1|must be an integer from 1 to 4|must be a non-empty list(?: of logic/commands/browser)?|contains an unsupported test kind|must be one of: [A-Za-z0-9_.-]+(?:, [A-Za-z0-9_.-]+)*)$`),
|
|
49
|
+
/^multiple CM workflow configs found: \.cm-workflow\.(?:yml|yaml|json)(?:, \.cm-workflow\.(?:yml|yaml|json))+$/,
|
|
50
|
+
/^(?:config\.)?roles\.[a-z_]{1,32}\.(?:adapter cannot be external-browser; only external_expert may use (?:the external browser|it)|adapter browser is reserved for browser_qa|source browser is reserved for external_expert)$/,
|
|
51
|
+
/^roles\.[a-z_]{1,32}\.adapter [a-z-]{1,32} needs the [a-z]{1,16} runtime, but runtimes\.available declares [a-z]{1,16}$/,
|
|
52
|
+
/^roles\.coder and roles\.reviewer both resolve to [a-z]{1,16}; with runtimes\.available both, review must run on the other runtime$/];
|
|
53
|
+
// Fixed heads whose tail is file text: the head names the kind of error.
|
|
54
|
+
const HEADS=['invalid inline mapping item','invalid quoted scalar','unsupported YAML feature','invalid JSON'];
|
|
55
|
+
export function redactConfigMessage(raw){
|
|
56
|
+
let message=String(raw).replace(CONTROL,' ').trim(),head='';
|
|
57
|
+
for(let prefix;(prefix=/^(?:runtimes\.yml|user\.runtimes|line \d{1,7}): /.exec(message));){head+=prefix[0];message=message.slice(prefix[0].length);}
|
|
58
|
+
if(FIXED.has(message)||TEMPLATES.some(template=>template.test(message)))return head+message;
|
|
59
|
+
// Only two parser messages carry a path, each at a fixed place (Codex round 7: scanning every
|
|
60
|
+
// ": " let an unknown key dressed as "<path>: <safe sentence>" through). In the batch plan a
|
|
61
|
+
// message that starts with an absolute path is readConfigText on the user-level runtimes.yml.
|
|
62
|
+
const oversized=/^configuration file exceeds (\d+) bytes: /.exec(message);
|
|
63
|
+
if(oversized)return `${head}项目配置文件 configuration file exceeds ${oversized[1]} bytes(路径不回显)`;
|
|
64
|
+
if(/^(?:\/|[A-Za-z]:\\)(?:.*?[\/\\])?runtimes\.yml: /.test(message)){
|
|
65
|
+
const tail=/: (configuration must be a regular file|configuration exceeds \d+ bytes)$/.exec(message);
|
|
66
|
+
return tail?`${head}用户级 runtimes.yml: ${tail[1]}`:`${head}用户级 runtimes.yml 读取失败(路径与系统原文不回显)`;
|
|
67
|
+
}
|
|
68
|
+
// "user.runtimes: " wraps only the lstat failure of the user-level file (loadUserRuntimes).
|
|
69
|
+
if(head.endsWith('user.runtimes: '))return `${head}用户级 runtimes.yml 读取失败(路径与系统原文不回显)`;
|
|
70
|
+
const unknown=new RegExp(`^(${FIELD}) has unknown field\\(s\\): `).exec(message);
|
|
71
|
+
if(unknown)return `${head}${unknown[1]} has unknown field(s)(字段名不回显)`;
|
|
72
|
+
if(/: (?:credential fields|secret-like values) are forbidden$/.test(message))return '有凭证字段名或疑似密钥的值(位置不回显)';
|
|
73
|
+
if(/^duplicate (?:JSON object )?key "/.test(message))return `${head}有重复的键(键名不回显)`;
|
|
74
|
+
if(/^missing value for "/.test(message))return `${head}缺少值(键名不回显)`;
|
|
75
|
+
const kind=HEADS.find(name=>message.startsWith(`${name}: `));
|
|
76
|
+
return head+(kind?`${kind}(原文不回显)`:'配置格式或字段不合法(原文含用户写的内容,不回显)');
|
|
77
|
+
}
|
|
78
|
+
function planFailureReason(error){
|
|
79
|
+
if(typeof error?.reason==='string')return {reason:error.reason};
|
|
80
|
+
if(error instanceof SyntaxError)return {reason:'--workflow-config 文件不是合法 JSON;改正后重新运行 cm-ai-batch-plan'};
|
|
81
|
+
if(error?.name!=='ConfigError'||typeof error.message!=='string')return {};
|
|
82
|
+
return {reason:`项目工作流配置无效:${redactConfigMessage(error.message)}。检查代码根的 .cm-workflow.yml(或 .yaml/.json)与用户级 ~/.cm-workflow/runtimes.yml,改正后重新运行 cm-ai-batch-plan`};
|
|
83
|
+
}
|
|
30
84
|
export function main(argv=process.argv.slice(2)){
|
|
31
85
|
if(argv.length===1&&['--help','-h'].includes(argv[0])){process.stdout.write(usage+'\n');return 0;}
|
|
32
86
|
const input=parse(argv);
|
|
@@ -41,8 +95,7 @@ export function main(argv=process.argv.slice(2)){
|
|
|
41
95
|
const plan=planCmAiBatch({specsDir,codeProject,repositoryId:input.repositoryId,batchId:input.batchId,settings,workflow});
|
|
42
96
|
process.stdout.write(JSON.stringify(plan)+'\n');return 0;
|
|
43
97
|
}catch(error){
|
|
44
|
-
process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed'
|
|
45
|
-
...(typeof error.reason==='string'?{reason:error.reason}:{})}})+'\n');return 1;
|
|
98
|
+
process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed',...planFailureReason(error)}})+'\n');return 1;
|
|
46
99
|
}
|
|
47
100
|
}
|
|
48
101
|
function isMain(entry){
|