|
| 1 | +# 命令系统设计 |
| 2 | + |
| 3 | +> 来源: V6.md 八 |
| 4 | +> 优先级: P2 |
| 5 | +> 风险: 低 |
| 6 | +
|
| 7 | +## 用户输入 "/" 触发流程 |
| 8 | + |
| 9 | +``` |
| 10 | +REPL.tsx (用户按 Enter) |
| 11 | + │ |
| 12 | + ▼ |
| 13 | +handlePromptSubmit.ts (610行) |
| 14 | + │ |
| 15 | + ▼ |
| 16 | +processUserInput.ts (605行) ─── 识别 "/" 前缀 |
| 17 | + │ |
| 18 | + ▼ |
| 19 | +processSlashCommand.tsx (921行) ─── 命令分发器 |
| 20 | + │ |
| 21 | + │ 解析命令名 + 参数 |
| 22 | + │ findCommand() → 查找 Command 对象 |
| 23 | + │ |
| 24 | + ├──────────────┬──────────────────┬─────────────────┐ |
| 25 | + ▼ ▼ ▼ ▼ |
| 26 | +┌─────────┐ ┌─────────────┐ ┌──────────────┐ ┌──────────┐ |
| 27 | +│ local │ │ local-jsx │ │ prompt │ │ 未知命令 │ |
| 28 | +│ │ │ │ │ │ │ → 错误 │ |
| 29 | +│ load() │ │ load() │ │ getPrompt() │ └──────────┘ |
| 30 | +│ →call() │ │ →call() │ │ → 注入消息 │ |
| 31 | +│ →结果 │ │ → ReactNode│ │ → 发送查询 │ |
| 32 | +└─────────┘ └─────────────┘ └──────────────┘ |
| 33 | + │ │ │ |
| 34 | + └──────────────┴──────────────────┘ |
| 35 | + │ |
| 36 | + ▼ |
| 37 | + 返回结果给 REPL |
| 38 | +``` |
| 39 | + |
| 40 | +## 命令注册 |
| 41 | + |
| 42 | +`src/commands.ts (~470行)` |
| 43 | + |
| 44 | +``` |
| 45 | +┌───────────────────────────────────────────────────────────────────┐ |
| 46 | +│ COMMANDS() ─── 静态注册 ~96 个命令 │ |
| 47 | +│ (71个静态导入 + 条件feature控制 + ~25个INTERNAL_ONLY) │ |
| 48 | +│ │ |
| 49 | +│ ┌─ src/commands/ (93个目录, 228文件) ─── 每个命令: │ |
| 50 | +│ │ name, description, aliases, type │ |
| 51 | +│ │ load: () => import('./impl.js') ← 懒加载 │ |
| 52 | +│ │ isEnabled(), availability │ |
| 53 | +│ └──────────────────────────────────────────────────────────────── │ |
| 54 | +└───────────────────────────────────────────────────────────────────┘ |
| 55 | + + |
| 56 | +┌───────────────────────────────────────────────────────────────────┐ |
| 57 | +│ getCommands() ─── 动态源 (合并到最终列表) │ |
| 58 | +│ │ |
| 59 | +│ ├─ getSkillDirCommands() .claude/commands/ + skills/ │ |
| 60 | +│ ├─ getBundledSkills() 内置 skill │ |
| 61 | +│ ├─ getPluginSkills() 插件 skill │ |
| 62 | +│ ├─ getPluginCommands() 插件命令 │ |
| 63 | +│ ├─ getWorkflowCommands() workflow 脚本命令 │ |
| 64 | +│ └─ getDynamicSkills() 运行时动态发现 │ |
| 65 | +└───────────────────────────────────────────────────────────────────┘ |
| 66 | + │ |
| 67 | + ▼ |
| 68 | +过滤: isEnabled → meetsAvailability → 去重 |
| 69 | + │ |
| 70 | + ▼ |
| 71 | +findCommand() / getCommand() / hasCommand() |
| 72 | +(按 name, alias 查找, Fuse.js 模糊匹配) |
| 73 | +``` |
| 74 | + |
| 75 | +## 自动补全 |
| 76 | + |
| 77 | +`useTypeahead (1384行)` |
| 78 | + |
| 79 | +``` |
| 80 | +用户键入 "/" |
| 81 | + │ |
| 82 | + ▼ |
| 83 | +generateCommandSuggestions() (567行) |
| 84 | + │ |
| 85 | + ▼ |
| 86 | +Fuse.js 模糊搜索 ─── 精确 > alias > 前缀 > 模糊 |
| 87 | + │ |
| 88 | + ▼ |
| 89 | +Ghost Text 补全 / 列表选择 / Tab/Enter 确认 |
| 90 | +``` |
| 91 | + |
| 92 | +## 耦合特征 |
| 93 | + |
| 94 | +- commands.ts (~470行) 静态导入所有命令, 新增命令必须手动注册 |
| 95 | +- src/commands/ 93个目录 228文件, 每个命令独立目录 |
| 96 | +- processSlashCommand.tsx switch 分发, 新命令类型需改分发器 |
| 97 | +- SkillTool (1109行) 提供第二条路径: 模型直接调用 skill |
| 98 | +- REMOTE_SAFE_COMMANDS / BRIDGE_SAFE_COMMANDS 硬编码安全列表 |
0 commit comments