@aibyzero/cm-workflow 0.21.6 → 0.21.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-workflow",
3
- "version": "0.21.6",
3
+ "version": "0.21.7",
4
4
  "description": "Spec-driven product development workflow for Codex: external research, PRD, implementation, read-only feature testing, review, QA, fixes, refactors, and documentation.",
5
5
  "author": {
6
6
  "name": "cm-workflow maintainers",
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@
7
7
 
8
8
  (暂无)
9
9
 
10
+ ## 0.21.7 — 2026-11-27
11
+
12
+ - **运行时向导默认选 Claude**:安装向导与 `cm-runtime` 直接回车选只用 Claude / Claude 写 Codex 审;保存需每次随机的 8 位确认码,预先粘贴的行丢弃,EOF 无换行尾行取消。
13
+ - **审查通道遵守声明**:声明审查者为 `claude-cli` 时,N1/N4/review 不再先试 Codex;`js-host.md` 说明审查端选择。已知限制:JS 默认入口不强制遵守声明,批次入口在 `claude-only` 项目的 Codex 会话仍由 Codex 审。
14
+ - **状态栏只显示当前会话项目的状态**:按 Claude Code 传入的 cwd 判断,排除过宽根与已删目录;规格与代码目录互不包含时不显示(已知限制)。
15
+
10
16
  ## 0.21.6 — 2026-11-25
11
17
 
12
18
  - **修复 Claude 兼容安装下技能的 docs 链接失效**:安装时把本包技能里的 `../docs/` 链接改写为 `../cm-workflow/docs/`,并随包写入范围清单,`cm-check` 机器检查链接可达且不误查用户自装技能;`cm-notify` 不属于读取运行时合同的核心技能,第 2 组口径与检查一并改正。
package/README.md CHANGED
@@ -17,6 +17,12 @@
17
17
 
18
18
  ## 最近更新
19
19
 
20
+ **0.21.7**
21
+
22
+ - **运行时向导默认选 Claude**:安装向导和 `cm-runtime` 直接回车就是只用 Claude、Claude 写 Claude 审;保存配置要输入每次随机的 8 位确认码,粘贴的旧输入不会误保存。
23
+ - **声明 Claude 审查后不再先试 Codex**:兼容流程的审查通道说明改为遵守声明;JS 默认入口的限制写进 `js-host.md`。
24
+ - **状态栏不再串项目**:只显示属于当前会话项目的 CM 状态,别处的旧状态不显示。详见[更新日志](CHANGELOG.md)。
25
+
20
26
  **0.21.6**
21
27
 
22
28
  - **修复 Claude 兼容安装下技能里的文档链接失效**:技能里指向 `docs/` 的链接装完后能打开;`cm-check` 新增链接可达检查,不会误查你自己装的技能。
@@ -109,7 +115,7 @@
109
115
 
110
116
  - **运行时配置默认保留**:打开 `cm-runtime` 先看当前配置和来源,主动选择修改才进入预设向导;高级模型入口只提供说明和校验方法。
111
117
  - **外部模型按 provider 配置**:单任务、批次及修复可显式启用 `cm-model-setup.mjs` 的模型及可选强度;宿主保持当前模型,run 冻结参数,未知调用停止重派。见[配置与恢复边界](docs/external-models.md)。
112
- - **确认前看清影响**:预览目标、字段变化和项目覆盖关系,最终 `[y/N]` 回车不保存;确认期间配置改变会要求重新预览。安装后的配置可跳过,已有用户默认优先保留。
118
+ - **确认前看清影响**:预览目标、字段变化和项目覆盖关系,最终要输入预览显示的 8 位确认码,回车或输错都不保存;确认期间配置改变会要求重新预览。安装后的配置可跳过,已有用户默认优先保留。
113
119
  - **保留模型别名并提示兼容性**:切换预设不改已有模型或正在运行的任务;配置校验不代表新适配器一定支持该模型。
114
120
 
115
121
  **0.16.5**
@@ -298,7 +304,7 @@ $cm-check
298
304
 
299
305
  仓库直接分发 Skills 和脚本,无需在仓库根目录运行 `npm install` 或构建。完整安装行为、覆盖范围和卸载说明见[安装指南](docs/installation.md)。
300
306
 
301
- 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.6 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
307
+ 需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.7 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
302
308
 
303
309
  ## 升级旧版本
304
310
 
@@ -484,7 +490,7 @@ Pi 资源加载器直接发现 Skills 与 Prompts,不运行上述安装器,
484
490
 
485
491
  ## 配置与深入阅读
486
492
 
487
- 交互安装可跳过运行时配置;已有用户默认优先保留,主动配置后再以 `[y/N]` 明确确认保存到 `~/.cm-workflow/runtimes.yml`。`--yes` / `-Yes` 或非 TTY 跳过且不写。运行时声明按 **项目 > 用户级默认 > 未声明** 解析。`$cm-runtime` 默认查看并保留,主动修改时预览影响、保留模型别名,配置改变后须重新确认;已创建 run 保留原配置。
493
+ 交互安装可跳过运行时配置;已有用户默认优先保留,主动配置后再输入预览显示的 8 位确认码确认保存到 `~/.cm-workflow/runtimes.yml`。`--yes` / `-Yes` 或非 TTY 跳过且不写。运行时声明按 **项目 > 用户级默认 > 未声明** 解析。`$cm-runtime` 默认查看并保留,主动修改时预览影响、保留模型别名,配置改变后须重新确认;已创建 run 保留原配置。
488
494
 
489
495
  配置独立审查时,`--review-model` 要写本机 CLI 实际接受的完整模型 id,预检会替你核对;真实审查一次常超过一分钟,建议在审查配置里把 `timeoutMs` 调大(上限一小时)。没等到结果就超时时记为可续跑的审查超时,同一轮最多重派一次;已经收到部分结果的超时要先核对,不会自动重派。
490
496
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.21.6
1
+ 0.21.7
@@ -76,7 +76,7 @@ Install or upgrade with the same command:
76
76
  npx @aibyzero/cm-workflow@latest install
77
77
  ```
78
78
 
79
- To pin a version, use `npx @aibyzero/cm-workflow@0.21.6 install` from outside
79
+ To pin a version, use `npx @aibyzero/cm-workflow@0.21.7 install` from outside
80
80
  the CM Workflow source checkout (for example, your home directory). Inside a
81
81
  checkout with the same package name and version, npm can select the local
82
82
  uninstalled package and report `cm-workflow: command not found`.
@@ -566,7 +566,7 @@ offer an optional user-default setup. First-time setup defaults to skipping; an
566
566
  declaration is displayed and “Keep it? [Y/n]” defaults to keeping it.
567
567
  Only opting in asks which tools you have: Codex only, Claude only, or both, and which
568
568
  tool codes when both are selected. Preview the target, fields and impact, then explicitly
569
- confirm `[y/N]` to save. Enter at this final step does not save.
569
+ type the 8-character confirmation code shown with the preview to save. Enter or any other input at this final step does not save.
570
570
  The shared prompt writes only `~/.cm-workflow/runtimes.yml` using a temporary file
571
571
  and atomic rename. It never changes settings.json or CLAUDE.md.
572
572
  An invalid existing declaration is reported and preserved; setup does not overwrite it.
@@ -593,13 +593,13 @@ without arguments to display current effective configuration, source and model a
593
593
  `[1] Keep current configuration (recommended, default)`, `[2] Change runtime preset`, or
594
594
  `[3] Advanced model configuration` (documentation and validation only). Keeping missing
595
595
  configuration does not create any file. Only option 2 starts the wizard:
596
- `[1] Current project / [2] User default` → `[1] Codex only / [2] Claude only / [3] Both`
597
- (with `[1] Codex writes, Claude reviews (recommended) / [2] Claude writes, Codex reviews`
598
- when both are selected) → preview the fields and effective impact and confirm `[y/N]`.
596
+ `[1] Current project / [2] User default` → `[1] Codex only / [2] Claude only (default) / [3] Both`
597
+ (with `[1] Codex writes, Claude reviews / [2] Claude writes, Codex reviews (default)`
598
+ when both are selected) → preview the fields and effective impact; in the conversation, save only after you explicitly agree in your own reply (the 8-character confirmation code appears only in the terminal wizard).
599
599
  In a terminal, `node <workflow-root>/scripts/cm-runtime.mjs [--project PATH]` opens the same wizard.
600
600
  Scope defaults to 1 with an existing project config, otherwise 2. Choosing 1 without a config
601
- announces creation from the template. The tool question has no default. Ctrl+C, three consecutive
602
- empty answers to that required question, EOF, declining confirmation or Enter at confirmation
601
+ announces creation from the template. Enter at the tool question or the writer question picks Claude (the default). Ctrl+C,
602
+ EOF, a wrong or empty confirmation code, or Enter at confirmation
603
603
  cancels without writing. Invalid configuration is reported and preserved, not automatically repaired.
604
604
  Project overrides are shown explicitly. Model aliases are retained across adapter changes;
605
605
  validation does not prove provider compatibility, model access or quota.
@@ -84,11 +84,13 @@ cm-ai-host failover: CLI 可解析不等于配额可用;本次切换只决定
84
84
  ### 限制
85
85
 
86
86
  - **只决定起跑运行时**,任务开始后不再切换;中途失效由 L1 交接接手。
87
- - 与 `--protected-config` 互斥(protected 模式只支持 Codex,无备端可选),组合报
87
+ - 与 `--protected-config` 互斥(protected 模式按 roles 自行选开发/审查端,不走起跑选路),组合报
88
88
  `failover_unsupported_in_protected_mode`。
89
89
  - 当前会话 host 下 developer 与 reviewer 共用同一 runtime 参数,选路按
90
- `developer` 角色进行。要让 N4 跨模型,用 `--review-config` 指定审查通道,或走
91
- `codex-review` skill。
90
+ `developer` 角色进行。要让 N4 跨模型,普通宿主显式传 `--review-runtime {另一端}`(并按
91
+ `skills/cm-ai/references/js-host.md` 用审查端生成预检、配 `--review-config`),或走
92
+ `codex-review` skill。与 `--failover` 同用时,起跑端若因故障切到另一端,开发端与声明不符,
93
+ 宿主会以 `runtime_selection_mismatch` 拒绝,声明端 CLI 仍不可用时,去掉 `--failover` 并先恢复该端,或改项目声明。
92
94
 
93
95
  ## 定点测试
94
96
 
@@ -796,7 +796,7 @@ $cm-security {项目路径} --semgrep-rules {外部本地规则文件} --osv-db
796
796
 
797
797
  交互安装在核心成功后提供可跳过的用户默认配置入口;已有文件显示当前值并默认保留。
798
798
  主动配置才询问“只有 Codex / 只有 Claude / 两个都有”,两家都有再问谁写代码,
799
- 预览后明确确认 `[y/N]` 才保存为 `~/.cm-workflow/runtimes.yml`,回车不保存。
799
+ 预览后输入显示的 8 位确认码才保存为 `~/.cm-workflow/runtimes.yml`,回车或输错都不保存。
800
800
  `--yes` / `-Yes` 或非 TTY 跳过提问且不写文件。测试时可用 `CM_WORKFLOW_HOME` 覆盖目录。
801
801
 
802
802
  优先级:**项目 > 用户级默认 > 未声明**。项目没有 `runtimes.available` 才读取用户文件;
@@ -814,11 +814,11 @@ $cm-security {项目路径} --semgrep-rules {外部本地规则文件} --osv-db
814
814
  直接输入 `$cm-runtime`(Claude Code 为 `/cm-runtime`)会先展示当前有效配置、来源和模型别名,
815
815
  提供 `[1] 保留当前配置(推荐,默认)`、`[2] 修改运行时预设`、`[3] 查看高级模型配置说明`。
816
816
  保留时不写文件,配置缺失也不会创建;高级选项只显示说明与校验方法。只有选 2 才进入:
817
- `[1] 当前项目 / [2] 用户级默认` → `[1] 只有 Codex / [2] 只有 Claude / [3] 两个都有`
818
- (选 3 再选 `[1] Codex 写、Claude 审(推荐) / [2] Claude 写、Codex 审`)→ 预览并明确确认 `[y/N]`。
817
+ `[1] 当前项目 / [2] 用户级默认` → `[1] 只有 Codex / [2] 只有 Claude(默认) / [3] 两个都有`
818
+ (选 3 再选 `[1] Codex 写、Claude 审 / [2] Claude 写、Codex 审(默认)`)→ 预览后由你在对话里明确回复同意才保存(8 位确认码只出现在终端向导)。
819
819
  终端无参数运行 `node <workflow-root>/scripts/cm-runtime.mjs [--project PATH]` 进入同一向导。
820
- 有项目配置时范围默认 1,否则默认 2;无配置选 1 会提示从模板新建。工具问题必须选择;
821
- Ctrl+C、EOF、必选问题连续三次空输入、拒绝确认或最终确认直接回车均不写。
820
+ 有项目配置时范围默认 1,否则默认 2;无配置选 1 会提示从模板新建。工具问题与写代码问题直接回车默认选 Claude;
821
+ Ctrl+C、EOF、拒绝确认或最终确认直接回车均不写。
822
822
  预览显示目标文件/范围、字段前后值、当前项目保存后的实际有效值;项目声明覆盖用户默认时会说明
823
823
  当前项目不会切换。模型别名保持原样,但更换适配器后可能不兼容。校验不证明模型可调用或配额可用。
824
824
  等待确认时相关配置改变会拒绝旧确认,须重新预览;无效配置报告错误并保留,不自动修复。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibyzero/cm-workflow",
3
- "version": "0.21.6",
3
+ "version": "0.21.7",
4
4
  "description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -17,7 +17,11 @@ const sameRun=(left,right)=>same({...left,attempt:right.attempt},right);
17
17
  // It is not scope authority, a recovery grant, or a requirement to revise scope.
18
18
  export function packageMaterialEligible(rawConfig,version=3){
19
19
  try{const config=json(rawConfig,STATE_LIMIT),policy=config.controlPolicy;
20
- validIdentity(config.identity);shape(policy,['version','development','bootstrap','qa','qaFix']);
20
+ // verification 是 control policy 的合法可选项(取值规则同 readControlPolicy):漏掉它会让开了验证闸门的运行
21
+ // 永远不能存档审查包,审查包稍大就卡在开工前(实跑实拦)。验证闸门与存储表示正交,这里只放行这一项
22
+ const verifies=policy!==null&&typeof policy==='object'&&Object.hasOwn(policy,'verification');
23
+ validIdentity(config.identity);shape(policy,['version','development','bootstrap','qa','qaFix',...(verifies?['verification']:[])]);
24
+ must(!verifies||['disabled','precheck','auto'].includes(policy.verification));
21
25
  must(['disabled','run'].includes(policy.qa)&&['disabled','manual','auto'].includes(policy.qaFix)
22
26
  &&(policy.qaFix==='disabled'||policy.qa==='run'));
23
27
  return version===3&&typeof config.root==='string'&&path.isAbsolute(config.root)
@@ -157,7 +161,10 @@ export function checkpointStoragePlan({records:rawRecords,effectId,checkpoint:ra
157
161
  // Those later records enforce their actual limit, not that future reserve again;
158
162
  // a review or completion (including a reconciled review invocation) cannot
159
163
  // introduce a first material archive.
160
- if(!ref&&['review','complete'].includes(effect.kind)){
164
+ // 同理,不是合法存档来源的开发检查点(不在待审、或包不属于本轮,如第二轮失败仍保留的第一轮内联包)也不能
165
+ // 开第一份存档:资格可能在运行中途翻转(升级后放行 verification),这时照旧内联,按记录上限落盘(Codex 审查实拦)
166
+ const source=effect.kind==='develop'&&checkpoint.state==='awaiting_review'&&same(pkg.identity,identity)&&checkpoint.attempt===pkg.identity.attempt;
167
+ if(!ref&&!source){
161
168
  must(size(payload)<=JOURNAL_PAYLOAD_LIMIT);return freeze({checkpoint,payloadFields:{}});
162
169
  }
163
170
  const budget=checkpointPackageBudget({inlineBytes:size(payload),packageBytes:size(pkg),reserve,enabled,referenced:ref!==null});
@@ -136,6 +136,12 @@ export async function previewTools({ cwd, model, effort, fixtureResponse = false
136
136
  transport.argument];
137
137
  const env = cleanEnvironment();
138
138
  env.CM_JS_PROBE_AUTH = 'cm-js-synthetic-local-probe';
139
+ // The probe sink only listens on 127.0.0.1. cleanEnvironment drops the host's proxy
140
+ // bypass list, so on a macOS system proxy (e.g. Clash on 127.0.0.1) Codex sent this
141
+ // loopback request through the proxy, got 502 and the preflight failed (2026-11-25,
142
+ // codex-cli 0.167.0). Exempt only the fixed loopback address, never copy host values.
143
+ env.NO_PROXY = '127.0.0.1';
144
+ env.no_proxy = '127.0.0.1';
139
145
  let result;
140
146
  try {
141
147
  result = await new Promise((resolve, reject) => {
package/runtime/review.md CHANGED
@@ -52,6 +52,7 @@ New cm-ai runs additionally bind `specification` into the baseline, developer re
52
52
 
53
53
  ## Channel order
54
54
 
55
+ 0. Project declares `roles.reviewer.adapter: claude-cli` (including `claude-only`): go straight to item 3; do not try Codex first. This governs the compatibility flow; the ordinary JS host reviews with the current tool unless `--review-runtime` is passed (see `skills/cm-ai/references/js-host.md`).
55
56
  1. `codex-subagent`: spawn a fresh reviewer/subagent with the runtime's no-history/fresh-context option (for example `fork_turns: none`) and provide only the review package. Ask for concrete failure scenarios, ordered by severity, and require an explicit zero-findings result when applicable.
56
57
  2. `codex-cli`: if subagents are unavailable, run `codex review` only when the task changes are isolated from unrelated dirty work (clean pre-task tree or isolated worktree/commit).
57
58
  3. `claude-cli`: when selected by the project declaration, the protected host must actually spawn a fresh Claude reviewer and recover its registered V3 receipt before recording `independent: true`. A two-provider declaration requires coder and reviewer on different providers; a single-provider declaration uses a fresh context on that provider.
@@ -151,7 +151,7 @@ preset: codex-codes
151
151
  `cm-runtime show [--project PATH]` 只读;`set <preset> [--project PATH]` 原子改项目;
152
152
  `set --user <preset>` 改用户默认;`unset --user` 删除用户默认但不删除项目声明。
153
153
  无参数先显示有效配置、来源与模型,默认保留;高级模型入口只提供说明和现有校验方法。
154
- 终端/会话向导和安装器的最终确认均为 `[y/N]`,回车不写;无效配置保留并报告错误。
154
+ 终端/会话向导和安装器的最终确认要输入提问时随机生成的 8 位确认码,回车或输错都不写;无效配置保留并报告错误。
155
155
  `preview <preset> [--project PATH | --user] [--json]` 只读生成候选,复用同一合并和校验逻辑,
156
156
  展示范围、目标、字段前后值、项目覆盖和保留模型。`set ... --expect-preview <preview_sha256>`
157
157
  核对项目、范围、预设、候选内容及相关输入快照;漂移后必须重新预览确认。两次调用保持相同
@@ -175,6 +175,28 @@ test('r2 failed develop may retain the r1 package and exact r1 archive without s
175
175
  assert.throws(()=>resolveCheckpointPackage(replaced,records,nextIdentity),invalid);
176
176
  });
177
177
 
178
+ // Codex 审查实拦:资格可能在运行中途翻转(升级后 verification 运行才可存档)。第一轮包当时内联、没有存档,
179
+ // 第二轮开发失败仍保留它时,失败检查点不是合法存档来源(不在待审、包不属于本轮):必须照旧内联落盘,
180
+ // 不能标 packageMaterial 让存储失败、把本该持久化的失败结果丢掉
181
+ test('r2 failed develop retaining an inline (unarchived) r1 package stays inline when it cannot source an archive',()=>{
182
+ const material=pkg(700000);let records=append([],{version:3,protocol:'cm-task-runner',type:'init',config:{identity}});
183
+ records=intent(records,'develop-1');records=append(records,payload('develop-1',frame(material)));
184
+ const nextIdentity={...identity,attempt:2};records=intent(records,'develop-2','develop',nextIdentity);
185
+ const checkpoint=frame(material,'develop-2','develop','blocked',nextIdentity);
186
+ checkpoint.code='verification_precheck_failed';checkpoint.receiptPadding='p'.repeat(100000);
187
+ const reserve=272125,inline=Math.min(JOURNAL_PAYLOAD_LIMIT,1024*1024)-reserve;
188
+ const p0=payload('develop-2',checkpoint);
189
+ assert(size(p0)>inline&&size(p0)<=JOURNAL_PAYLOAD_LIMIT,'fixture crosses the inline budget yet fits one record');
190
+ for(const enabled of [false,true]){
191
+ const plan=checkpointStoragePlan({records,effectId:'develop-2',checkpoint,identity:nextIdentity,enabled,reserve});
192
+ assert.deepEqual(plan.payloadFields,{},String(enabled));assert.deepEqual(plan.checkpoint,checkpoint);
193
+ assert.deepEqual(resolveCheckpointPackage(payload('develop-2',plan.checkpoint,plan.payloadFields),records,nextIdentity),checkpoint);
194
+ }
195
+ // 当前轮待审的开发检查点仍是合法来源:照常存档,修复不放过本该存档的大包
196
+ const fresh=frame(pkg(700000,nextIdentity),'develop-2','develop','awaiting_review',nextIdentity);fresh.receiptPadding='p'.repeat(100000);
197
+ assert.deepEqual(checkpointStoragePlan({records,effectId:'develop-2',checkpoint:fresh,identity:nextIdentity,enabled:true,reserve}).payloadFields,{packageMaterial:true});
198
+ });
199
+
178
200
  test('a package above the original record limit cannot be admitted by material storage and no reserve is changed',()=>{
179
201
  const f=fixture(),oversize=frame(pkg(JOURNAL_PAYLOAD_LIMIT));
180
202
  const measured={inlineBytes:815380,packageBytes:789175,reserve:272125};
@@ -226,6 +248,12 @@ test('eligibility is limited to durable v3 single-project conversation v2 withou
226
248
  for(const controlPolicy of [{...config.controlPolicy,development:'provider'},{...config.controlPolicy,bootstrap:'write'},
227
249
  {...config.controlPolicy,qaFix:'manual'},undefined])assert.equal(packageMaterialEligible({...config,controlPolicy}),false);
228
250
  for(const root of ['relative','/fixture/../fixture',null])assert.equal(packageMaterialEligible({...config,root}),false);
251
+ // verification 是 control policy 的合法可选项(control-policy.mjs):带上它不能让大审查包失去存档资格;
252
+ // 存档资格只看执行方式,验证闸门与它正交。非法取值仍由 control policy 自身拒绝,这里不放宽其他未知键
253
+ for(const verification of ['disabled','precheck','auto'])
254
+ assert.equal(packageMaterialEligible({...config,controlPolicy:{...config.controlPolicy,verification}},3),true,verification);
255
+ assert.equal(packageMaterialEligible({...config,controlPolicy:{...config.controlPolicy,verification:'bogus'}},3),false);
256
+ assert.equal(packageMaterialEligible({...config,controlPolicy:{...config.controlPolicy,extra:true}},3),false);
229
257
  });
230
258
 
231
259
  test('reconciled review uses the same backward package reference and validates invocation binding',()=>{
@@ -0,0 +1,40 @@
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 {previewTools} from '../runtime/js/cm-ai/tool-preview.mjs';
7
+ import {cleanEnvironment} from '../runtime/js/cm-ai/codex-config.mjs';
8
+
9
+ // 2026-11-25: on a macOS system proxy the Codex child of tool-preview sent its loopback
10
+ // probe through the proxy (502). The probe child alone gets a fixed loopback exemption;
11
+ // host proxy values (addresses or bypass lists) reach no CM child.
12
+ const PROXY_KEYS=['NO_PROXY','no_proxy','HTTP_PROXY','http_proxy','HTTPS_PROXY','https_proxy','ALL_PROXY','all_proxy'];
13
+ function withHostProxy(t){
14
+ const saved=Object.fromEntries(PROXY_KEYS.map(k=>[k,process.env[k]]));
15
+ t.after(()=>{for(const [k,v] of Object.entries(saved)){if(v===undefined)delete process.env[k];else process.env[k]=v;}});
16
+ process.env.NO_PROXY='internal.example.test,127.0.0.1';
17
+ process.env.no_proxy='internal.example.test';
18
+ for(const k of PROXY_KEYS.slice(2))process.env[k]='http://proxy.example.test:8080';
19
+ }
20
+
21
+ test('tool-preview probe child gets only the fixed loopback proxy exemption',async t=>{
22
+ withHostProxy(t);
23
+ const dir=fs.mkdtempSync(path.join(os.tmpdir(),'cm-js-b1-'));
24
+ t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
25
+ const dump=path.join(dir,'env.json'),cli=path.join(dir,'fake-codex.mjs');
26
+ fs.writeFileSync(cli,`#!/usr/bin/env node\nimport fs from 'node:fs';\nfs.writeFileSync(${JSON.stringify(dump)},JSON.stringify(process.env));\nprocess.exit(1);\n`,{mode:0o755});
27
+ const receipt=await previewTools({cwd:fs.realpathSync(dir),model:'gpt-6.2-sol',cli,promptTransport:'argument',allowCodeProject:true});
28
+ assert.equal(receipt.passed,false);
29
+ const env=JSON.parse(fs.readFileSync(dump,'utf8'));
30
+ assert.equal(env.NO_PROXY,'127.0.0.1');
31
+ assert.equal(env.no_proxy,'127.0.0.1');
32
+ for(const k of PROXY_KEYS.slice(2))assert.equal(k in env,false,k);
33
+ assert.equal(JSON.stringify(env).includes('internal.example.test'),false);
34
+ });
35
+
36
+ test('other CM children still get no host proxy values',t=>{
37
+ withHostProxy(t);
38
+ const env=cleanEnvironment();
39
+ for(const k of PROXY_KEYS)assert.equal(k in env,false,k);
40
+ });
@@ -9,8 +9,8 @@ export const messages={
9
9
  menu:{zh:'运行时配置:[1] 保留当前配置(推荐,默认) [2] 修改运行时预设 [3] 查看高级模型配置说明 [1]: ',en:'Runtime configuration: [1] Keep current configuration (recommended, default) [2] Change runtime preset [3] Advanced model configuration [1]: '},
10
10
  kept:{zh:'已保留当前配置,未写入文件。\n',en:'Kept current configuration; no files written.\n'},
11
11
  builtin:{zh:'内置默认(未声明)',en:'Built-in defaults (undeclared)'},
12
- tools:{zh:'你手上有哪个 AI 工具?[1] 只有 Codex [2] 只有 Claude [3] 两个都有: ',en:'Which AI tools do you have? [1] Codex only [2] Claude only [3] Both: '},
13
- coder:{zh:'谁写代码?[1] Codex(Claude 审,推荐) [2] Claude(Codex 审): ',en:'Who writes code? [1] Codex (Claude reviews, recommended) [2] Claude (Codex reviews): '},
12
+ tools:{zh:'你手上有哪个 AI 工具?[1] 只有 Codex [2] 只有 Claude(默认) [3] 两个都有: ',en:'Which AI tools do you have? [1] Codex only [2] Claude only (default) [3] Both: '},
13
+ coder:{zh:'谁写代码?[1] Codex(Claude 审) [2] Claude(Codex 审,默认): ',en:'Who writes code? [1] Codex (Claude reviews) [2] Claude (Codex reviews, default): '},
14
14
  scope:{zh:'改哪一层?[1] 当前项目({project}) [2] 用户级默认({user}) [{default}]: ',en:'Which scope? [1] Current project ({project}) [2] User default ({user}) [{default}]: '},
15
15
  create:{zh:'将从模板新建项目配置:{file}\n',en:'Will create project configuration from the template: {file}\n'},
16
16
  current:{zh:'当前用户级默认: {available} / {preset}\n',en:'Current user default: {available} / {preset}\n'},
@@ -26,7 +26,7 @@ export const messages={
26
26
  drift:{zh:'预览后的配置已改变: {file};未保存,请重新预览并确认。',en:'Configuration changed after preview: {file}; not saved. Generate a fresh preview and confirm again.'},
27
27
  advanced:{zh:'高级模型配置说明:建议保留当前默认,仅在有明确需要时手工编辑项目 .cm-workflow.yml 的模型别名。\n合同说明: {doc}\n校验: node "{validator}" --project "<项目路径>" --print-effective\n校验不证明 provider 兼容或配额可用;预设切换保留模型别名。\nunset --user 只删除用户默认,项目声明仍优先,不是恢复所有默认值。\n',en:'Advanced model configuration: keep current defaults unless you have a specific need; edit model aliases manually in the project .cm-workflow.yml.\nContract: {doc}\nValidate: node "{validator}" --project "<project path>" --print-effective\nValidation does not prove provider compatibility or quota; preset changes preserve model aliases.\nunset --user removes only user defaults; project declarations still win. It is not a reset of all settings.\n'},
28
28
  absent:{zh:'未声明',en:'Undeclared'},
29
- confirm:{zh:'确认?[y/N] ',en:'Confirm? [y/N] '},
29
+ confirm:{zh:'输入确认码 {code} 保存;其他输入或直接回车取消: ',en:'Type confirmation code {code} to save; anything else cancels: '},
30
30
  cancelled:{zh:'已放弃,未修改运行时声明。\n',en:'Cancelled; runtime declaration unchanged.\n'},
31
31
  installed:{zh:'✓ 用户级运行时默认已写入 {file} ({preset})\n',en:'✓ User runtime default saved to {file} ({preset})\n'},
32
32
  comment:{zh:'用 cm-runtime set --user <preset> 修改用户级默认。',en:'Use cm-runtime set --user <preset> to change the user default.'},
@@ -4,6 +4,7 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import {fileURLToPath} from 'node:url';
6
6
  import {createInterface} from 'node:readline';
7
+ import {randomBytes} from 'node:crypto';
7
8
  import {userRuntimesPath,readConfigText,parseUserRuntimes} from './cm-workflow-config.mjs';
8
9
  import {writeUserRuntime,prepareRuntimePreview,formatRuntimePreview} from './cm-runtime.mjs';
9
10
  import {runtimeLanguage,runtimeText as t} from './cm-runtime-i18n.mjs';
@@ -12,32 +13,41 @@ export class PromptCancelled extends Error {}
12
13
  // Queue lines so injected streams and pasted answers cannot lose later responses.
13
14
  export function runtimeQuestions(input,output,lang=runtimeLanguage()){
14
15
  const rl=createInterface({input,output,terminal:false});
15
- const queue=[];let pending=null,closed=false,cancelled=false;
16
+ const queue=[];let pending=null,closed=false,cancelled=false,unterminated=false;
17
+ // 输入最后一行没回车就结束(EOF),那一行不算数:防止未提交的 y 被当成确认。
18
+ input.on('data',chunk=>{const text=String(chunk);if(text.length)unterminated=!text.endsWith('\n');});
16
19
  rl.on('line',line=>{if(pending){const resolve=pending;pending=null;resolve(line);}else queue.push(line);});
17
20
  const close=()=>{closed=true;if(pending){pending(null);pending=null;}};
18
21
  rl.on('close',close);
19
22
  const interrupt=()=>{cancelled=true;queue.length=0;rl.close();close();};
20
23
  rl.on('SIGINT',interrupt);process.on('SIGINT',interrupt);
21
24
  return {
22
- async ask(question){
25
+ // fresh=true(确认题):确认码是此刻才生成的,提问显示前已排队的行一律丢弃。
26
+ async ask(question,{fresh=false}={}){
27
+ if(fresh)queue.length=0;
23
28
  if(cancelled||closed&&!queue.length)throw new PromptCancelled();
24
29
  output.write(question);
25
30
  const answer=queue.length?queue.shift():await new Promise(resolve=>{pending=resolve;});
26
31
  if(answer===null||cancelled)throw new PromptCancelled();
32
+ if(closed&&!queue.length&&unterminated)throw new PromptCancelled();
27
33
  return answer.trim();
28
34
  },
29
35
  close(){process.removeListener('SIGINT',interrupt);rl.close();},
30
36
  };
31
37
  }
38
+ // 保存确认:必须输入本次提问随机生成的 8 位确认码(每次提问重新生成,不由预览内容算出,
39
+ // 所以重复预览、提前粘贴都复用不了)。回车、n、y 等其他输入一律取消,不写。
40
+ export const newConfirmCode=()=>randomBytes(4).toString('hex'); // 8 位十六进制,碰撞概率约 1/43 亿
41
+ export async function askConfirm(ask,preview,lang=runtimeLanguage(),code=newConfirmCode()){
42
+ return (await ask(t('confirm',lang,{code}),{fresh:true})).toLowerCase()===code;
43
+ }
32
44
  export async function askRuntimePreset(ask,lang=runtimeLanguage()){
33
- let choice,empty=0;
34
- do{
35
- choice=await ask(t('tools',lang));
36
- if(choice===''){if(++empty===3)throw new PromptCancelled();}else empty=0;
37
- }while(!['1','2','3'].includes(choice));
45
+ // 空回车默认选 Claude(工具题=只有 Claude,写代码题=Claude 写)。
46
+ let choice;
47
+ do{choice=await ask(t('tools',lang));if(choice==='')choice='2';}while(!['1','2','3'].includes(choice));
38
48
  if(choice!=='3')return choice==='1'?'codex-only':'claude-only';
39
49
  let coder;
40
- do{coder=await ask(t('coder',lang));}while(!['','1','2'].includes(coder));
50
+ do{coder=await ask(t('coder',lang));if(coder==='')coder='2';}while(!['1','2'].includes(coder));
41
51
  return coder==='2'?'claude-codes':'codex-codes';
42
52
  }
43
53
  export async function promptRuntime(argv=process.argv.slice(2),input=process.stdin,output=process.stdout){
@@ -61,8 +71,7 @@ export async function promptRuntime(argv=process.argv.slice(2),input=process.std
61
71
  const preset=await askRuntimePreset(ask,lang);
62
72
  const preview=prepareRuntimePreview(null,preset,{user:true,lang});
63
73
  output.write(formatRuntimePreview(preview,lang));
64
- let confirm;do{confirm=(await ask(t('confirm',lang))).toLowerCase();}while(!['','y','n'].includes(confirm));
65
- if(confirm!=='y')throw new PromptCancelled();
74
+ if(!await askConfirm(ask,preview,lang))throw new PromptCancelled();
66
75
  output.write(t('installed',lang,{file:writeUserRuntime(preset,{lang,preview}),preset}));
67
76
  }catch(error){if(error instanceof PromptCancelled)output.write(t('cancelled',lang));else throw error;}
68
77
  finally{questions.close();}
@@ -10,7 +10,7 @@ import {ConfigError,findConfig,loadConfig,readConfigText,parseUserRuntimes,
10
10
  CONFIG_FILENAMES,previewUserRuntimeConfig} from './cm-workflow-config.mjs';
11
11
  import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
12
12
  import {runtimeLanguage,runtimeText as t} from './cm-runtime-i18n.mjs';
13
- import {askRuntimePreset,runtimeQuestions,PromptCancelled} from './cm-runtime-install.mjs';
13
+ import {askRuntimePreset,askConfirm,runtimeQuestions,PromptCancelled} from './cm-runtime-install.mjs';
14
14
  export {askRuntimePreset} from './cm-runtime-install.mjs';
15
15
  import {probeRuntimes} from './cm-failover.mjs';
16
16
 
@@ -188,9 +188,7 @@ export async function interactiveRuntime(project,{input=process.stdin,output=pro
188
188
  const preset=await askRuntimePreset(ask,lang);
189
189
  const preview=prepareRuntimePreview(root,preset,{user,lang});
190
190
  output.write(formatRuntimePreview(preview,lang));
191
- let confirm;
192
- do{confirm=(await ask(t('confirm',lang))).toLowerCase();}while(!['','y','n'].includes(confirm));
193
- if(confirm!=='y')throw new PromptCancelled();
191
+ if(!await askConfirm(ask,preview,lang))throw new PromptCancelled();
194
192
  saveRuntime(root,preset,user,lang,output,preview);
195
193
  output.write(showRuntime(root,{lang})+'\n');return 0;
196
194
  }catch(error){if(error instanceof PromptCancelled){output.write(t('cancelled',lang));return 0;}throw error;}
@@ -135,9 +135,22 @@ function tty(){
135
135
  let text='';output.on('data',chunk=>{text+=chunk;});
136
136
  return {input,output,text:()=>text};
137
137
  }
138
+ // 逐行喂入:每个提问(不以换行结尾的输出)出现后才送下一行;{CODE} 换成提示里显示的确认码。
139
+ function feed(io,answers){
140
+ const lines=answers.split(/(?<=\n)/);let seen='';
141
+ io.output.on('data',chunk=>{
142
+ seen+=chunk;
143
+ if(String(chunk).endsWith('\n'))return;
144
+ let next=lines.shift();
145
+ if(next===undefined){io.input.end();return;}
146
+ if(next.includes('{CODE}')){const code=(/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk))??[])[1];next=next.replace('{CODE}',code??'????');}
147
+ if(lines.length===0)io.input.end(next);else io.input.write(next);
148
+ });
149
+ }
138
150
  async function wizard(root,answers,lang='en'){
139
- const io=tty();const running=main(['--project',root],{...io,lang});
140
- io.input.end(answers);const code=await running;return {code,text:io.text()};
151
+ const io=tty();feed(io,answers);
152
+ const running=main(['--project',root],{...io,lang});
153
+ const code=await running;return {code,text:io.text()};
141
154
  }
142
155
  test('wizard and installer share the same preset question function',()=>assert.equal(wizardPreset,installerPreset));
143
156
  test('entry keeps missing and existing configuration by default, without logs or run writes',()=>wizardFixture(async root=>{
@@ -156,7 +169,7 @@ test('advanced model information is read-only and has no model editing prompt',(
156
169
  assert.deepEqual(fs.readdirSync(root),[]);
157
170
  }));
158
171
  test('Enter at the final confirmation declines the proposed change',()=>wizardFixture(async root=>{
159
- const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/Confirm\? \[y\/N\]/);
172
+ const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/confirmation code/);
160
173
  assert.match(result.text,/Cancelled/);assert.deepEqual(fs.readdirSync(root),[]);
161
174
  }));
162
175
  test('first-install declaration is optional and Enter skips it',()=>wizardFixture(async root=>{
@@ -180,7 +193,7 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
180
193
  const before='\ufeff# keep\r\nversion: 1\r\nruntimes: {available: codex}\r\nroles:\r\n coder: {adapter: current-ai, source: local, model: default} # keep coder\r\n reviewer: {adapter: current-ai, source: local, model: default}\r\n';
181
194
  const initial=before;
182
195
  fs.writeFileSync(file,initial);
183
- const result=await wizard(root,'2\n1\n3\n1\nY\n');assert.equal(result.code,0,result.text);
196
+ const result=await wizard(root,'2\n1\n3\n1\n{CODE}\n');assert.equal(result.code,0,result.text);
184
197
  assert.equal(fs.readFileSync(file,'utf8'),initial.replace('available: codex','available: both').replace('adapter: current-ai','adapter: codex-cli').replace('adapter: current-ai','adapter: claude-cli').replaceAll('source: local','source: subscription'));
185
198
  assert.match(result.text,/Which AI tools do you have/);assert.match(result.text,/Who writes code/);
186
199
  assert.match(result.text,/preset: codex-codes/);assert.match(result.text,/runtimes_source: project/);
@@ -189,12 +202,12 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
189
202
  assert.equal(event.event,'decision');assert.equal(event.preset,'codex-codes');
190
203
  }));
191
204
  test('missing project defaults to user scope and Chinese preset/comment/output',()=>wizardFixture(async root=>{
192
- const result=await wizard(root,'2\n\n2\nY\n','zh');assert.equal(result.code,0);
205
+ const result=await wizard(root,'2\n\n2\n{CODE}\n','zh');assert.equal(result.code,0);
193
206
  assert(!fs.existsSync(path.join(root,'.cm-workflow.yml')));
194
207
  assert.match(fs.readFileSync(path.join(root,'user','runtimes.yml'),'utf8'),/# 用 cm-runtime.*\npreset: claude-only/s);
195
- assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text,/确认?/);assert.match(result.text,/runtimes_source: user/);
208
+ assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text,/确认码/);assert.match(result.text,/runtimes_source: user/);
196
209
  }));
197
- test('three empty mandatory answers, refusal, EOF and SIGINT do not write',()=>wizardFixture(async root=>{
210
+ test('empty final confirmation, refusal, EOF and SIGINT do not write',()=>wizardFixture(async root=>{
198
211
  for(const [lang,cancelled] of [['en',/Cancelled/],['zh',/已放弃/]]){
199
212
  for(const answers of ['2\n2\n\n\n\n','2\n2\n1\nn\n','2\n2\n','2\n2\n1\n']){
200
213
  const result=await wizard(root,answers,lang);assert.equal(result.code,0);
@@ -204,9 +217,38 @@ test('three empty mandatory answers, refusal, EOF and SIGINT do not write',()=>w
204
217
  assert.equal(await running,0);assert.match(io.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
205
218
  }
206
219
  }));
220
+ test('empty answers default to Claude: tools question and coder question',async()=>{
221
+ const feed=list=>async()=>list.shift();
222
+ assert.equal(await installerPreset(feed([''])),'claude-only');
223
+ assert.equal(await installerPreset(feed(['3',''])),'claude-codes');
224
+ assert.equal(await installerPreset(feed(['3','1'])),'codex-codes');
225
+ assert.equal(await installerPreset(feed(['1'])),'codex-only');
226
+ });
227
+ test('saving needs the preview confirmation code: pasted y, n, Enter, wrong code and unterminated EOF code never write',()=>wizardFixture(async root=>{
228
+ const cancelled=/Cancelled/;
229
+ // 提前粘贴(含猜测 y):确认码预览前不可知 → 取消,不写。
230
+ const pasted=tty(),running=main(['--project',root],{...pasted,lang:'en'});
231
+ pasted.input.end('2\n2\n\ny\n');assert.equal(await running,0);
232
+ assert.match(pasted.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
233
+ // y、n、回车、错码:立即取消(不挂起、不吞输入),不写。
234
+ for(const answer of ['y\n','n\n','\n','zzzz\n']){
235
+ const r=await wizard(root,`2\n2\n\n${answer}`);assert.equal(r.code,0);
236
+ assert.match(r.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
237
+ }
238
+ // 确认码每次提问随机生成:同一预览两次提问的码不同,上一次的码复用不了。
239
+ const codes=[];for(let i=0;i<2;i++){const r=await wizard(root,'2\n2\n\nn\n');codes.push(/(?:confirmation code|确认码) (\w{8})/.exec(r.text)[1]);}
240
+ assert.notEqual(codes[0],codes[1]);
241
+ const reused=await wizard(root,`2\n2\n\n${codes[0]}\n`);assert.match(reused.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
242
+ // 正确确认码但没回车就 EOF:不算数,不写。
243
+ const tail=await wizard(root,'2\n2\n\n{CODE}');assert.equal(tail.code,0);
244
+ assert.match(tail.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
245
+ // 对照:输入显示的确认码并回车才写入,且确认码大小写不敏感。
246
+ const ok=await wizard(root,'2\n2\n\n{CODE}\n');assert.equal(ok.code,0);
247
+ assert.match(ok.text,/Saved|已保存|installed/i);assert(fs.existsSync(path.join(root,'user','runtimes.yml')));
248
+ }));
207
249
  test('explicit project creation, existing-project scope default and invalid choice retry',()=>wizardFixture(async root=>{
208
- const created=await wizard(root,'2\n1\nwrong\n1\ny\n');assert.equal(created.code,0);assert.match(created.text,/Will create project configuration/);
209
- const changed=await wizard(root,'2\n\n3\n2\ny\n');assert.equal(changed.code,0);assert.match(changed.text,/preset: claude-codes/);
250
+ const created=await wizard(root,'2\n1\nwrong\n1\n{CODE}\n');assert.equal(created.code,0);assert.match(created.text,/Will create project configuration/);
251
+ const changed=await wizard(root,'2\n\n3\n2\n{CODE}\n');assert.equal(changed.code,0);assert.match(changed.text,/preset: claude-codes/);
210
252
  assert.equal(loadConfig({projectRoot:root}).roles.coder.adapter,'claude-cli');
211
253
  }));
212
254
  test('non-TTY no command exits 2 with usage and no writes',()=>fixture((root,run)=>{
@@ -234,8 +276,8 @@ test('installer culture reaches shared prompts and comments; explicit override w
234
276
  for(const key of keys)delete process.env[key];
235
277
  for(const [culture,override,expected] of [['zh-CN',undefined,'zh'],['en-US',undefined,'en'],['zh-CN','en','en']]){
236
278
  if(override)process.env.CM_WORKFLOW_LANG=override;else delete process.env.CM_WORKFLOW_LANG;
237
- const io=tty(),running=promptRuntime(['--lang',culture],io.input,io.output);
238
- io.input.end('y\n3\n2\ny\n');await running;
279
+ const io=tty();feed(io,'y\n3\n2\n{CODE}\n');const running=promptRuntime(['--lang',culture],io.input,io.output);
280
+ await running;
239
281
  assert.match(io.text(),expected==='zh'?/你手上有哪个 AI 工具/:/Which AI tools do you have/);
240
282
  const file=path.join(root,'user','runtimes.yml');assert.match(fs.readFileSync(file,'utf8'),expected==='zh'?/# 用 cm-runtime/:/# Use cm-runtime/);
241
283
  fs.unlinkSync(file);
@@ -297,7 +339,7 @@ test('project preview save refuses target edits and preserves the external write
297
339
  test('TTY confirmation cannot overwrite edits made after its preview',()=>wizardFixture(async root=>{
298
340
  const file=path.join(root,'.cm-workflow.yml');fs.writeFileSync(file,'version: 1\n');
299
341
  const io=tty(),external='version: 1\n# external edit\n';let changed=false;
300
- io.output.on('data',chunk=>{if(String(chunk).includes('Confirm?')){fs.writeFileSync(file,external);changed=true;io.input.end('y\n');}});
342
+ io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){fs.writeFileSync(file,external);changed=true;io.input.end(`${m[1]}\n`);}});
301
343
  const running=main(['--project',root],{...io,lang:'en'});io.input.write('2\n1\n1\n');
302
344
  assert.equal(await running,1);assert(changed);assert.equal(fs.readFileSync(file,'utf8'),external);
303
345
  assert(!fs.existsSync(path.join(root,'logs')));
@@ -310,7 +352,7 @@ test('installer keeps existing defaults, defaults No at final confirmation and r
310
352
  assert.deepEqual(fs.readFileSync(file),before);
311
353
  }
312
354
  const io=tty();let changed=false;
313
- io.output.on('data',chunk=>{if(String(chunk).includes('[y/N]')){writeUserRuntime('claude-codes');changed=true;io.input.end('y\n');}});
355
+ io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){writeUserRuntime('claude-codes');changed=true;io.input.end(`${m[1]}\n`);}});
314
356
  const running=promptRuntime([],io.input,io.output);io.input.write('n\n2\n');
315
357
  await assert.rejects(running,/fresh preview|重新预览/);assert(changed);
316
358
  assert.match(fs.readFileSync(file,'utf8'),/preset: claude-codes/);
@@ -0,0 +1,54 @@
1
+ // 状态条只显示属于当前会话项目的 CM 状态(按 stdin 的 cwd 判断)。
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import {spawnSync} from 'node:child_process';
8
+ import {fileURLToPath} from 'node:url';
9
+
10
+ const script=fileURLToPath(new URL('../templates/statusline/cm-statusline.sh',import.meta.url));
11
+ function fixture(fn){
12
+ const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-statusline-')));
13
+ try{
14
+ const home=path.join(root,'home'),project=path.join(root,'proj'),specs=path.join(project,'specs','feat');
15
+ fs.mkdirSync(path.join(home,'.claude'),{recursive:true});fs.mkdirSync(specs,{recursive:true});
16
+ fs.mkdirSync(path.join(root,'proj2'));fs.mkdirSync(path.join(root,'other'));
17
+ fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),specs);
18
+ fs.writeFileSync(path.join(specs,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
19
+ fn({root,home,project,specs});
20
+ }finally{fs.rmSync(root,{recursive:true,force:true});}
21
+ }
22
+ const run=(home,input)=>spawnSync('/bin/bash',[script],{input:JSON.stringify(input),env:{...process.env,HOME:home},encoding:'utf8'}).stdout;
23
+
24
+ test('shows CM status when cwd is the project, inside specs, or via workspace.current_dir',()=>fixture(({home,project,specs})=>{
25
+ for(const input of [{cwd:project},{cwd:specs},{workspace:{current_dir:project}}])
26
+ assert.match(run(home,input),/正在开发接口/,JSON.stringify(input));
27
+ }));
28
+ test('hides another project\'s status, a prefix-lookalike dir, and a missing cwd',()=>fixture(({root,home})=>{
29
+ for(const input of [{cwd:path.join(root,'other')},{cwd:path.join(root,'proj2')},{model:{display_name:'M'}}]){
30
+ const out=run(home,input);
31
+ assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),JSON.stringify(input)+out);
32
+ }
33
+ }));
34
+
35
+ test('inherited GIT_DIR / GIT_WORK_TREE cannot pull in another project\'s status',()=>fixture(({root,home,project})=>{
36
+ assert.equal(spawnSync('git',['init','-q',project]).status,0);
37
+ const env={...process.env,HOME:home,GIT_DIR:path.join(project,'.git'),GIT_WORK_TREE:project};
38
+ const out=spawnSync('/bin/bash',[script],{input:JSON.stringify({cwd:path.join(root,'other')}),env,encoding:'utf8'}).stdout;
39
+ assert(!out.includes('正在开发接口'),out);
40
+ }));
41
+
42
+ test('a cwd that is "/", an ancestor of HOME, or a deleted directory never shows another project\'s status',()=>fixture(({root,home})=>{
43
+ const gone=path.join(root,'gone');fs.mkdirSync(gone);fs.rmSync(gone,{recursive:true});
44
+ for(const cwd of ['/',root,home,gone]){
45
+ const out=run(home,{cwd});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),cwd+out);
46
+ }
47
+ }));
48
+
49
+ test('a pointer to HOME with a stale status file never leaks into projects under HOME',()=>fixture(({home})=>{
50
+ const other=path.join(home,'work','other');fs.mkdirSync(other,{recursive:true});
51
+ fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),home);
52
+ fs.writeFileSync(path.join(home,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
53
+ const out=run(home,{cwd:other});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),out);
54
+ }));
@@ -94,11 +94,12 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-spec-amend.mjs" inspect --specs-dir "{SPECS_
94
94
 
95
95
  开工前按 `runtime/review.md` 探测能否建立**与实现者不同上下文**的审查通道,而不是检查当前进程是否叫 Codex:
96
96
 
97
- - 可创建 fresh Codex 子代理/独立线程 → 作为主通道
97
+ - 项目声明审查者为 `claude-cli`(含 `claude-only`)→ 只探测全新 Claude CLI 审查进程,不探测 Codex;不可用即暂停
98
+ - 其余情况:可创建 fresh Codex 子代理/独立线程 → 作为主通道
98
99
  - 子代理不可用,但可以安全启动隔离的 `codex` CLI 审查会话 → 作为备用通道
99
100
  - 两者都不可用 → 暂停新开发,已有实现保持待审并说明通道失败原因;不论任务风险高低,都不能用 `self-degraded` 诊断代替独立审查或进入成功收尾
100
101
 
101
- 当前 gate 支持的是上述 Codex 通道;未来 Claude-native 适配须单独验证,不能把
102
+ Codex 与 Claude 两条通道都由 protected host 实际启动并回收 V3 凭证;凭证标明实际审查端,不能把
102
103
  Claude 结果标成 Codex 通过门禁。通道不可用不算代码 finding,不消耗实现审查轮次。
103
104
 
104
105
  ## Git 前置检查(字段优先,询问兜底)
@@ -17,7 +17,10 @@ N3 保留开发期 lint 与测试;这些正常检查不构成作者自审前
17
17
 
18
18
  ## 1. 独立审查(强制)
19
19
 
20
- 按以下顺序选择一个**新上下文**的审查者:
20
+ 按以下顺序选择一个**新上下文**的审查者。**先看项目声明的 `roles.reviewer.adapter`**(含 `claude-only` 预设):
21
+ 声明为 `claude-cli` → 直接用第 3 项,不再尝试 Codex(实跑教训:声明 claude-only 后仍总被派去 Codex 审,因为旧顺序固定先试 Codex);
22
+ 声明为 `codex-cli`,或未声明 → 按下列顺序。
23
+ 本条只约束兼容流程;JS 宿主按 `--review-runtime` 显式选择审查端(声明与实际不符时需人工核对),不在此处自动改选。
21
24
 
22
25
  1. `codex-subagent`:用当前运行时的 no-history/fresh-context 选项(如 `fork_turns: none`)新建独立 Codex 子代理/线程,只接收任务范围、验收标准、diff 和验证结果
23
26
  2. `codex-cli`:子代理不可用时,启动隔离的非交互 Codex CLI 审查会话;禁止它修改文件
@@ -305,8 +305,19 @@ scope、命令及恢复存档。批次宿主没有 `--original-host-context`,
305
305
  上述 runtime,并使用真实宿主提供的 `--host-context`。不要为了使用 Claude 改写规格、
306
306
  Review 头或完成记录;provider 标签由原 adapter/V3 绑定,失败不切到另一端兜底。
307
307
 
308
+ **普通宿主的审查端**:省略 `--review-runtime` 时,审查端就是当前会话所在工具;项目声明了另一端审查
309
+ (如 `codex-codes` 在 Codex 会话里)也不会自动改选,声明只是偏好。要让声明的审查端执行,必须显式传
310
+ `--review-runtime {claude|codex}`(须与声明一致,恢复时要重复传,否则指纹不符);该参数只用于单任务
311
+ `cm-ai-host.mjs`,批次入口 `cm-ai-batch-host.mjs` 不接受,会报 `invalid_arguments`。只有 `--protected-config`
312
+ 按 roles 自行选开发/审查端;`--external-models` 单独使用时仍按 `--runtime` 绑定的当前端,不会改选。
313
+ 已知限制(维护者 2026-11-27 定):默认入口不强制遵守声明,也不在不一致时停住;曾试过强制拒绝,会破坏
314
+ 既有恢复指纹合同(旧运行不得变)。批次入口在 `claude-only` 项目的 Codex 会话里仍会由 Codex 审,需改在 Claude 会话开跑。
315
+
308
316
  需配置审查时,按文档运行单任务脚本的
309
- `preflight --config {该代码根的单任务配置} --review-model {已选择模型} --runtime {当前端}`。
317
+ `preflight --config {该代码根的单任务配置} --review-model {已选择模型} --runtime {审查端}`(未传
318
+ `--review-runtime` 时审查端就是当前端;传了则用 `--review-runtime` 指定的那一端;用单任务 `--protected-config` 时用
319
+ roles 声明的审查端;批次成员可能因授权不同而审查端不同,按各成员 status 给出的审查端分别预检。用错端宿主会报
320
+ `tool_preflight_missing`)。
310
321
  即使后续执行批次,诊断仍用同一代码根的单任务配置,不把 batch/workflows 配置传给该命令。
311
322
  诊断输出直接作为 review-config 输入,不手造或修补 `passed`/指纹;失败则保留原因。
312
323
  本机配置诊断通过不证明模型可用、Review 协议成功或用户已批准外发。
@@ -26,21 +26,21 @@ macOS/Linux 兼容别名 `/cm:runtime`。这是独立配置工具,不进入 N1
26
26
  `[2] 用户级默认 / User default`(`~/.cm-workflow/runtimes.yml`)。有项目配置默认 1,
27
27
  无配置默认 2;无配置仍选 1 时,提示将从模板新建 `.cm-workflow.yml`。
28
28
  2. 你手上有哪个 AI 工具?/ Which AI tools do you have?
29
- `[1] 只有 Codex / Codex only` `[2] 只有 Claude / Claude only` `[3] 两个都有 / Both`。
30
- 此问无默认,必须选择;选 3 再问:谁写代码?/ Who writes code?
31
- `[1] Codex(Claude 审,推荐)/ Codex (Claude reviews, recommended)`
32
- `[2] Claude(Codex 审)/ Claude (Codex reviews)`,默认 1。
29
+ `[1] 只有 Codex / Codex only` `[2] 只有 Claude / Claude only (default)` `[3] 两个都有 / Both`。
30
+ 直接回车选 2;选 3 再问:谁写代码?/ Who writes code?
31
+ `[1] Codex(Claude 审)/ Codex (Claude reviews)`
32
+ `[2] Claude(Codex 审,默认)/ Claude (Codex reviews, default)`,默认 2。
33
33
  3. 执行只读 `preview <preset> --project "{代码项目路径}"`;用户范围用 `preview <preset> --user`,
34
34
  工作目录必须是代码项目根,以便核对该项目的覆盖关系。可加 `--json` 读取结构化结果。
35
35
  展示目标文件/范围、字段前后值、当前项目保存前后的有效值及模型兼容性提示,保留返回的
36
- `preview_sha256`,询问确认 / Confirm? `[y/N]`,默认不保存。
36
+ `preview_sha256`,会话里必须由用户本人在对话中明确回复同意才保存,不得代答,也不得自造确认码;终端向导才使用随机 8 位确认码(每次提问重新生成),输入其他内容或直接回车都不保存。
37
37
  4. 只有用户明确同意才调用相同项目、范围、预设、语言和运行时环境的
38
38
  `set ... --expect-preview <preview_sha256>`。不得用普通 `set` 绕过摘要校验。
39
39
  配置漂移或校验失败时保留文件,重新预览并取得新的确认,不沿用旧批准。
40
40
  成功后执行 `show --project "{代码项目路径}"` 并回显。
41
41
 
42
42
  工具选 1/2 分别映射 `codex-only`/`claude-only`;两个都有、写代码选 1/2 分别映射
43
- `codex-codes`/`claude-codes`。取消、拒绝确认或必选问题连续三次空输入时放弃,不写。
43
+ `codex-codes`/`claude-codes`。取消或拒绝确认时放弃,不写;两道选择题直接回车选 Claude。
44
44
  会话没有回复不代表回车或确认,不得因等待超时执行;选择了修改也不等于批准保存。
45
45
  用户声明被项目覆盖时如实报告当前项目不会切换。摘要仅用于预览一致性,不是用户授权证据。
46
46
 
@@ -3,11 +3,73 @@
3
3
  # 输出原则: 大白话,路过的人扫一眼能懂;工程细节收在行尾暗色角标
4
4
  input=$(cat)
5
5
 
6
+ # 全局记录 ~/.claude/cm-current-specs 只是「上一次用 CM 的项目」,所有会话共用。
7
+ # 只在它属于当前会话的项目时才显示:用 Claude Code 经标准输入传来的 cwd 判断,
8
+ # 属于别处的旧状态(含「可能已中断」)整条不显示(实跑教训:别的会话显示了不相干项目的旧状态)。
9
+ # 已知限制:规格目录与代码目录互相不包含(如 ~/code/app 与 ~/projects/app-specs)时,
10
+ # 在代码目录开的会话不显示 CM 状态;要显示需在状态文件里记项目根,属另一个改动。
6
11
  PTR="$HOME/.claude/cm-current-specs"
12
+ specs_belong_here() {
13
+ CM_SL_INPUT="$input" python3 - "$1" <<'PYEOF'
14
+ import json, os, subprocess, sys
15
+ try:
16
+ d = json.loads(os.environ.get("CM_SL_INPUT", "")) # 脚本走 heredoc,stdin 不能再读 JSON,改走环境变量
17
+ except Exception:
18
+ sys.exit(1)
19
+ cwd = d.get("cwd") or d.get("workspace", {}).get("current_dir") or ""
20
+ if not cwd:
21
+ sys.exit(1) # 拿不到当前目录就不显示,宁缺毋滥
22
+ specs, cwd = os.path.realpath(sys.argv[1]), os.path.realpath(cwd)
23
+ roots = [cwd]
24
+ try:
25
+ # 清掉继承来的 GIT_* 环境变量:它们会让 git 指向别的仓库(别会话的旧项目)
26
+ env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
27
+ top = subprocess.run(["git", "-C", cwd, "rev-parse", "--show-toplevel"],
28
+ capture_output=True, text=True, timeout=2, env=env).stdout.strip()
29
+ if top:
30
+ roots.append(os.path.realpath(top))
31
+ except Exception:
32
+ pass
33
+
34
+ def inside(child, parent):
35
+ # child 在 parent 内(含相同);用 samefile 比较,大小写不敏感的文件系统上也认得同一目录
36
+ p = child
37
+ while True:
38
+ try:
39
+ if os.path.samefile(p, parent):
40
+ return True
41
+ except OSError:
42
+ pass
43
+ up = os.path.dirname(p)
44
+ if up == p:
45
+ return False
46
+ p = up
47
+
48
+ # 过宽的根(/、家目录及其上级)会把别的项目也算进来:不当作项目根
49
+ home = os.path.realpath(os.path.expanduser("~"))
50
+ too_broad = lambda r: inside(home, r)
51
+ # 路径已不存在(目录被删)不比较,免得沿父目录误放行
52
+ if not (os.path.isdir(specs) and os.path.isdir(cwd)):
53
+ sys.exit(1)
54
+ # 规格目录本身过宽(指针指向家目录等)也不显示:否则家目录下任何项目都会命中
55
+ if too_broad(specs):
56
+ sys.exit(1)
57
+ def depth(child, root):
58
+ return os.path.relpath(child, root).count(os.sep) + 1
59
+ ok = False
60
+ for r in roots:
61
+ if too_broad(r) or not os.path.isdir(r):
62
+ continue
63
+ # specs 在项目内(最多 4 层,如 项目/specs/功能名),或当前目录在 specs 内
64
+ if (inside(specs, r) and depth(specs, r) <= 4) or inside(r, specs):
65
+ ok = True
66
+ sys.exit(0 if ok else 1)
67
+ PYEOF
68
+ }
7
69
  if [ -f "$PTR" ]; then
8
70
  SPECS=$(cat "$PTR" 2>/dev/null)
9
71
  ST="$SPECS/.cm-status.json"
10
- if [ -f "$ST" ]; then
72
+ if [ -f "$ST" ] && specs_belong_here "$SPECS"; then
11
73
  python3 - "$ST" "$SPECS" <<'EOF' && exit 0
12
74
  import json, sys, os, re, time
13
75
  try: