2020 仅当子组下有 ≥2 个 action 时合理(否则拍平到两级)
2121```
2222
23- 文件路径与命令路径必须 1:1 对齐。
23+ 实现文件路径与命令语义 1:1 对齐; ** 产品在 map 里决定暴露路径 ** (rag 可将 ` knowledge retrieve ` remap 为 ` retrieve ` ) 。
2424
2525## CLI 命令注册架构(必读)
2626
27- 命令元数据以 ** ` catalog.ts ` 为单一登记处 ** ;` registry.ts ` 只负责解析与打印 help,不再内嵌命令表或手写 Resources 列表 。
27+ composable-cli:命令库只 export 单命令, ** 路径 map 由产品 / 测试各自注入 ** ;` createCli ` + ` CommandRegistry ` 在 ` bailian-cli-runtime ` 里解析 help 。
2828
2929```
30- commands/<...>.ts defineCommand({ name, description, usage, options, examples, run })
30+ packages/commands/src/commands/<...>.ts
31+ defineCommand({ name, description, usage, options, examples, run })
3132 ↓
32- commands/catalog .ts export const commands: Record<string, Command>
33+ packages/ commands/src/index .ts 单命令 re-export(无路径 preset)
3334 ↓
34- ┌────┴────┬──────────────────────┬─────────────────────┐
35- ↓ ↓ ↓ ↓
36- registry.ts main.ts tools/generate-reference.ts export-schema.ts
37- (解析/help) (入口) → skills/bailian-cli/reference/index.md + <group>.md
35+ ┌────┴────────────┬─────────────────────────┬──────────────────────────┐
36+ ↓ ↓ ↓ ↓
37+ cli/src/commands.ts rag/src/main.ts tests/fixtures/e2e-commands.ts (其他产品…)
38+ (bl 全量 map) (rag 裁剪 map) (契约 e2e 全量 map)
39+ ↓ ↓ ↓
40+ createCli(commands, opts) → runtime/registry.ts(建树、resolve、printHelp)
41+ ↓
42+ tools/generate-reference.ts 读 cli/src/commands.ts → skills/bailian-cli/reference/
3843```
3944
40- - ** ` packages/cli/src/commands/catalog.ts ` ** : ` import ` 命令模块 + ` "<path>": handler ` 映射;** 不** ` import registry.ts ` (避免构建时循环依赖)
41- - ** ` packages/cli/src/commands/index.ts ` ** : ` export { commands } from "./catalog.ts" ` (给包内 re-export 用)
42- - ** ` packages/cli/src/registry.ts ` ** : ` import { commands } from "./commands/catalog.ts" ` ,建树、` resolve ` 、` printHelp ` ;Commands / Global Flags 从 ` Command ` 元数据与 ` GLOBAL_OPTIONS ` ** 动态生成**
43- - ** ` tools/generate-reference.ts ` ** : pre-commit / ` pnpm run sync:skill-assets ` 时读 ` catalog.ts ` ,写 ` skills/bailian-cli/reference/index.md ` (索引) + ` skills/bailian-cli/reference/<一级命令>.md ` (详情,勿手改)。该目录** 纳入 git** ,随 ` npx skills add modelstudioai/cli ` 分发
45+ - ** ` packages/commands/src/index.ts ` ** : ` export { default as textChat } from "./commands/text/chat.ts" ` 等;** 不** 含 ` "<path>": handler ` 映射
46+ - ** ` packages/cli/src/commands.ts ` ** : bl 产品 map;` main.ts ` 传入 ` createCli `
47+ - ** ` packages/rag/src/main.ts ` ** : rag 产品 map(内联);路径可不同于 bl
48+ - ** ` packages/commands/tests/fixtures/e2e-commands.ts ` ** : 契约 e2e 全量 map;** 不** import ` packages/cli `
49+ - ** ` packages/runtime/src/registry.ts ` ** : 从注入的 ` Record<string, Command> ` 建树;Commands / Global Flags 从 ` Command ` 元数据与 ` GLOBAL_OPTIONS ` ** 动态生成**
50+ - ** ` tools/generate-reference.ts ` ** : pre-commit / ` pnpm run sync:skill-assets ` 时读 ** ` packages/cli/src/commands.ts ` ** ,写 ` skills/bailian-cli/reference/index.md ` (索引) + ` skills/bailian-cli/reference/<一级命令>.md ` (详情,勿手改)。该目录** 纳入 git** ,随 ` npx skills add modelstudioai/cli ` 分发
4451
45- 已删除、勿再引用:` commands/help .ts ` 、` registry .ts` 内联 ` new CommandRegistry({...}) ` 、` printRootHelp ` 手写命令行 。
52+ 已删除、勿再引用:` packages/cli/src/ commands/catalog .ts` 、` groups .ts` 、 ` packages/cli/src/registry.ts ` 、` config/export-schema.ts ` 。
4653
4754## 必查清单
4855
4956### A. 代码层
5057
51- - [ ] ** 新建/删除/移动** 对应的 ` packages/cli/src/commands/<...>.ts ` 文件
52- - [ ] ** ` packages/cli/src/commands/catalog.ts ` ** :
53- - 增删 ` import xxx from "./.../xxx.ts" `
54- - 在 ` export const commands ` 里增删 ` "<group> <action>": xxx ` (key 与 ` defineCommand({ name }) ` 一致)
55- - [ ] ** 不要** 在 ` registry.ts ` 里重复登记命令(已从 catalog 读取)
56- - [ ] 如果命令需要跳过入口的默认 DashScope API key 引导(` ensureApiKey ` ),在对应 ` defineCommand ` 上设 ` skipDefaultApiKeySetup: true ` (字段定义见 ` packages/core/src/types/command.ts ` ;` main.ts ` 根据已解析的 ` command ` 读取)
57- - [ ] ** ` config/export-schema.ts ` ** : 若新命令不适合作为 agent tool,评估是否加入 ` SKIP_PREFIXES ` ;该文件在 ` run() ` 内 ` import("../catalog.ts") ` ,勿顶层 import catalog 以免循环依赖
58+ - [ ] ** 新建/删除/移动** 对应的 ` packages/commands/src/commands/<...>.ts ` 文件
59+ - [ ] ** ` packages/commands/src/index.ts ` ** : 增删 ` export { default as xxx } from "./commands/.../xxx.ts" `
60+ - [ ] ** ` packages/commands/tests/fixtures/e2e-commands.ts ` ** : 增删 import 与 ` "<path>": xxx ` (契约 e2e 命令面)
61+ - [ ] ** ` packages/cli/src/commands.ts ` ** (bl 暴露该命令时): 同步 import 与 map key(key 与 ` defineCommand({ name }) ` 一致)
62+ - [ ] ** ` packages/rag/src/main.ts ` ** (rag 暴露该命令时): 同步 import 与 map key(路径可按 rag 产品约定 remap)
63+ - [ ] 如果命令需要跳过入口的默认 DashScope API key 引导(` ensureApiKey ` ),在对应 ` defineCommand ` 上设 ` skipDefaultApiKeySetup: true ` (字段定义见 ` packages/core/src/types/command.ts ` ;` createCli ` 根据已解析的 ` command ` 读取)
5864
5965### B. 文档层
6066
@@ -64,13 +70,14 @@ registry.ts main.ts tools/generate-reference.ts export-schema.ts
6470
6571### C. 测试层
6672
67- - [ ] 按 [ cli-e2e-tests.md] ( cli-e2e-tests.md ) 新建或更新 ` packages/cli/tests/e2e/<topic>.e2e.test.ts `
73+ - [ ] 按 [ cli-e2e-tests.md] ( cli-e2e-tests.md ) 新建或更新 ` packages/commands/tests/e2e/<topic>.e2e.test.ts `
74+ - [ ] bl / rag 命令面变更时,同步对应 smoke:` packages/cli/tests/e2e/smoke.e2e.test.ts ` 、` packages/rag/tests/e2e/smoke.e2e.test.ts `
6875- [ ] 删除命令时一并删对应 e2e
6976
7077### D. 重命名特殊处理
7178
7279- [ ] 全仓 grep ** 旧命令名字符串** ,确保以下位置全部更新:
73- - ` catalog .ts` 的 key
80+ - 各产品 / fixture map 的 key( ` cli/src/commands .ts` 、 ` e2e-commands.ts ` 、 ` rag/src/main.ts ` 等)
7481 - error hints(cli 层)
7582 - ` skills/bailian-cli/reference/ ` (重建后检查并提交)
7683 - README 示例
@@ -79,15 +86,17 @@ registry.ts main.ts tools/generate-reference.ts export-schema.ts
7986## 完成后自查
8087
8188``` sh
82- pnpm run sync:skill-assets # reference/ + SKILL metadata.version 与 catalog / package.json 一致
89+ pnpm run sync:skill-assets # reference/ + SKILL metadata.version 与 cli/commands.ts / package.json 一致
8390node packages/cli/src/main.ts < new-command> --help
8491node packages/cli/src/main.ts # 根 help 列表含新命令
85- vp test packages/cli/tests/e2e/< topic> .e2e.test.ts # 相关 e2e
92+ pnpm --filter bailian-cli-commands test tests/e2e/< topic> .e2e.test.ts
93+ pnpm --filter bailian-cli test tests/e2e/smoke.e2e.test.ts # bl 命令面变更时
8694```
8795
8896## 常见漏点
8997
90- - ✗ 只改了命令文件,忘了 ** ` catalog.ts ` ** → 命令不存在或 help 里没有
98+ - ✗ 只改了命令文件,忘了 ** ` index.ts ` 导出** → 产品 / e2e 无法 import
99+ - ✗ 忘了 ** ` e2e-commands.ts ` ** → 契约 e2e 跑不起来或缺命令
100+ - ✗ bl 要暴露却忘了 ** ` cli/src/commands.ts ` ** → ` bl --help ` 里没有、reference 也不会生成
91101- ✗ 手改 ** ` skills/bailian-cli/reference/*.md ` ** → 下次 generate 被覆盖;应改 ` defineCommand ` 后重新 generate 并提交
92- - ✗ 在 ` export-schema.ts ` 顶层 ` import catalog ` → 可能与 registry 循环依赖
93102- ✗ 单 action 的子组是反模式,新增时优先拍平为两级
0 commit comments