Skip to content

Commit 16edf9f

Browse files
7418claude
andcommitted
feat: CLI Tools — curated tool catalog, detection, install, chat awareness
New sidebar page for managing system CLI tools (ffmpeg, jq, ripgrep, yt-dlp, pandoc). Core modules: - cli-tools-catalog.ts: static catalog of 6 curated tools + EXTRA_WELL_KNOWN_BINS - cli-tools-detect.ts: system detection via which/where + --version (2min cache) - cli-tools-context.ts: builds <available_cli_tools> block for chat system prompt API routes: - GET /api/cli-tools/catalog, /installed, /[id]/status, /[id]/detail - POST /api/cli-tools/[id]/install (SSE streaming), /[id]/describe (AI gen) UI components: - CliToolsManager: installed + recommended sections with grid layout - CliToolCard: two variants (installed/recommended) with status badges - CliToolDetailDialog: intro, use cases, guide steps, example prompts - CliToolInstallDialog: SSE-based install progress with live terminal log Chat integration: - Chat input toolbar: Terminal icon opens CLI tool picker popover - System prompt injection: buildCliToolsContext() in /api/chat - MessageInput: CLI popover with search, keyboard nav, locale-aware prefill - NavRail + ChatListPanel: frosted glass (bg-sidebar/80 backdrop-blur-xl) - SlashCommandButton: Lightning icon, unified 16px toolbar icons - input-group: shadow-md → shadow-sm - Model selector: searchable popover with provider grouping Docs: - docs/handover/cli-tools.md + apps/site/content/docs/{en,zh}/cli-tools.mdx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4e60332 commit 16edf9f

37 files changed

+3108
-78
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: CLI Tools
3+
description: Manage system CLI tools so Claude can automatically detect and use command-line capabilities on your machine.
4+
---
5+
6+
# CLI Tools
7+
8+
Many AI workflows require command-line tools — FFmpeg for video processing, jq for JSON parsing, ripgrep for code search. CodePilot's CLI Tools feature helps you manage these tools and lets Claude automatically know what's available on your machine.
9+
10+
## Why This Matters
11+
12+
When you tell Claude "convert this video to MP4," it needs to know whether FFmpeg is installed on your system. Without that knowledge, it can only offer generic advice. With it, Claude can give you a ready-to-run command.
13+
14+
The CLI Tools feature does three things:
15+
16+
1. **Detect** — Automatically scans your system for installed command-line tools
17+
2. **Recommend** — Offers a curated list of useful tools with one-click installation
18+
3. **Awareness** — Automatically tells Claude what tools you have during conversations, so it gives more precise answers
19+
20+
## Opening the Tool Manager
21+
22+
Click the **CLI Tools** icon (terminal icon) in the left navigation rail.
23+
24+
The page has two sections:
25+
26+
- **Installed** — Tools detected on your system, showing version and status
27+
- **Recommended** — Curated tools commonly used in AI workflows, ready to install
28+
29+
## Installing Tools
30+
31+
Find the tool you need in the Recommended section and click **Install**.
32+
33+
If a tool supports multiple installation methods (e.g., Homebrew, npm), you'll be asked to choose. The installation progress shows real-time terminal output so you can see exactly what's happening.
34+
35+
Currently recommended tools:
36+
37+
| Tool | Purpose | Install via |
38+
|------|---------|------------|
39+
| FFmpeg | Audio/video transcoding, trimming, merging | Homebrew |
40+
| jq | JSON data parsing and transformation | Homebrew |
41+
| ripgrep | Ultra-fast text search (much faster than grep) | Homebrew |
42+
| yt-dlp | Video downloading | Homebrew / pipx |
43+
| pandoc | Document format conversion (Markdown, Word, PDF) | Homebrew |
44+
45+
## Viewing Tool Details
46+
47+
Click the **Details** button on a tool card to see:
48+
49+
- **Introduction** — What the tool does
50+
- **Use Cases** — Most common scenarios
51+
- **Setup Guide** — Steps from installation to first use
52+
- **Example Prompts** — Ready-to-use prompts you can copy into a conversation
53+
54+
Example prompts are the most practical part. For FFmpeg, you might see:
55+
56+
> "Convert input.mov to MP4 format, keeping original quality"
57+
58+
Click the copy button or "Send to Chat" to start a conversation with that prompt immediately.
59+
60+
## AI-Enhanced Descriptions
61+
62+
Installed tools support AI-generated detailed descriptions. Click the **Auto Describe** button on a tool card, and Claude will generate a bilingual description based on the tool's name and capabilities.
63+
64+
The description is saved locally and will persist across sessions.
65+
66+
## Using Tools in Conversations
67+
68+
### Automatic Awareness (Recommended)
69+
70+
After installing tools, you don't need to do anything extra. CodePilot automatically detects your installed tools before each conversation and includes them in the system prompt.
71+
72+
This means when you say:
73+
74+
> "Convert all .mov files in this directory to .mp4"
75+
76+
Claude knows you have FFmpeg and gives you a ready-to-run command, instead of first asking "Do you have FFmpeg installed?"
77+
78+
### Manual Tool Selection
79+
80+
If you want to explicitly tell Claude to use a specific tool, click the **terminal icon** in the chat input toolbar to open the CLI tool picker.
81+
82+
After selecting a tool:
83+
84+
- If the input is empty, it auto-fills a guide phrase like "I want to use FFmpeg to: " — just add your specific request
85+
- If there's already text in the input, a tool badge is attached to the message, and Claude will prioritize that tool in its response
86+
87+
## Best Practices
88+
89+
### Describe the Goal, Not the Command
90+
91+
Less effective:
92+
> "Run ffmpeg -i input.mov -c:v libx264 output.mp4"
93+
94+
More effective:
95+
> "Convert input.mov to MP4, keep the quality, minimize file size"
96+
97+
Let Claude choose the optimal parameters. It knows FFmpeg's encoding options better than most people.
98+
99+
### Combine Multiple Tools
100+
101+
CLI tools work great together. For example:
102+
103+
> "Download the video from this YouTube link, trim the first 30 seconds, and convert to GIF"
104+
105+
If you have yt-dlp and FFmpeg installed, Claude will chain them together into a complete workflow.
106+
107+
### Start with Example Prompts
108+
109+
Not sure how to use a tool? Open its detail page and start with the example prompts. They cover the most common use cases and are the fastest way to get started.

apps/site/content/docs/en/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"providers",
99
"mcp",
1010
"skills",
11+
"cli-tools",
1112
"bridge",
1213
"assistant-workspace",
1314
"design-agent",
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: CLI 工具
3+
description: 管理系统 CLI 工具,让 Claude 自动识别并使用你电脑上的命令行能力。
4+
---
5+
6+
# CLI 工具
7+
8+
很多 AI 工作流需要配合命令行工具——用 FFmpeg 处理视频、用 jq 解析 JSON、用 ripgrep 搜索代码。CodePilot 的 CLI 工具功能帮你管理这些工具,并让 Claude 自动知道你的电脑上有什么可用。
9+
10+
## 为什么需要这个功能?
11+
12+
当你跟 Claude 说"帮我把这个视频转成 MP4",Claude 需要知道你的系统上是否安装了 FFmpeg。如果不知道,它只能给出通用建议;如果知道,它可以直接给你一条可以执行的命令。
13+
14+
CLI 工具功能做了三件事:
15+
16+
1. **检测** — 自动扫描你系统上已安装的命令行工具
17+
2. **推荐** — 提供精选工具列表,一键安装
18+
3. **感知** — 在对话中自动告诉 Claude 你有哪些工具,让它给出更精准的回答
19+
20+
## 打开工具管理
21+
22+
点击左侧导航栏的 **CLI Tools** 图标(终端图标)进入管理页面。
23+
24+
页面分为两个区域:
25+
26+
- **已安装** — 系统上检测到的工具,显示版本号和状态
27+
- **推荐** — 精选的常用 AI 工作流工具,可以直接安装
28+
29+
## 安装工具
30+
31+
在推荐区找到你需要的工具,点击 **安装** 按钮。
32+
33+
如果工具支持多种安装方式(如 Homebrew、npm),会先让你选择。安装过程中会实时显示终端日志,你可以看到完整的安装输出。
34+
35+
目前推荐的工具包括:
36+
37+
| 工具 | 用途 | 安装方式 |
38+
|------|------|---------|
39+
| FFmpeg | 音视频转码、剪辑、合并 | Homebrew |
40+
| jq | JSON 数据解析和转换 | Homebrew |
41+
| ripgrep | 极速文本搜索(比 grep 快得多) | Homebrew |
42+
| yt-dlp | 视频下载 | Homebrew / pipx |
43+
| pandoc | 文档格式转换(Markdown、Word、PDF 互转) | Homebrew |
44+
45+
## 查看工具详情
46+
47+
点击工具卡片上的 **详情** 按钮,可以看到:
48+
49+
- **工具简介** — 这个工具能做什么
50+
- **适用场景** — 最常见的使用方式
51+
- **操作引导** — 从安装到上手的步骤
52+
- **示例提示词** — 可以直接复制到对话中使用的提示词
53+
54+
示例提示词是这个功能最实用的部分。比如 FFmpeg 的示例提示词:
55+
56+
> "把 input.mov 转换成 MP4 格式,保持原始质量"
57+
58+
点击旁边的复制按钮或"发送到聊天"按钮,就可以直接用这个提示词开始对话。
59+
60+
## AI 自动完善介绍
61+
62+
已安装的工具支持用 AI 生成更详细的介绍。点击工具卡片上的 **自动完善** 按钮,Claude 会根据工具的名称和用途生成一段中英双语的详细描述。
63+
64+
这个描述会保存在本地,下次打开时自动显示。
65+
66+
## 在对话中使用
67+
68+
### 自动感知(推荐)
69+
70+
安装好工具后,不需要做任何额外操作。CodePilot 会在每次对话时自动检测你的已安装工具,并在 system prompt 中告诉 Claude。
71+
72+
这意味着当你说:
73+
74+
> "帮我把这个目录下所有的 .mov 文件转成 .mp4"
75+
76+
Claude 会知道你有 FFmpeg,直接给出可执行的命令,而不是先问你"是否安装了 FFmpeg"。
77+
78+
### 手动选择工具
79+
80+
如果你想明确告诉 Claude 使用某个特定工具,可以在聊天输入框的工具栏中点击 **终端图标**,打开 CLI 工具选择器。
81+
82+
选择一个工具后:
83+
84+
- 如果输入框为空,会自动预填一段引导文字,比如"我想用 FFmpeg 工具完成:" — 你只需补充具体需求
85+
- 如果输入框已有内容,会在消息上附加一个工具标记,Claude 会优先使用这个工具来回答
86+
87+
## 最佳实践
88+
89+
### 描述需求而不是命令
90+
91+
不好的用法:
92+
> "运行 ffmpeg -i input.mov -c:v libx264 output.mp4"
93+
94+
好的用法:
95+
> "把 input.mov 转成 MP4,画质保持不变,文件尽量小"
96+
97+
让 Claude 来选择最优的参数组合。它比大多数人更了解 FFmpeg 的编码选项。
98+
99+
### 组合多个工具
100+
101+
CLI 工具之间可以组合使用。比如:
102+
103+
> "从这个 YouTube 链接下载视频,然后裁剪前 30 秒,转成 GIF"
104+
105+
如果你安装了 yt-dlp 和 FFmpeg,Claude 会把它们串联起来,给你一个完整的工作流。
106+
107+
### 用示例提示词起步
108+
109+
不确定怎么用一个工具?打开它的详情页,从示例提示词开始。这些提示词覆盖了最常见的使用场景,是快速上手的好方法。

apps/site/content/docs/zh/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"providers",
99
"mcp",
1010
"skills",
11+
"cli-tools",
1112
"bridge",
1213
"assistant-workspace",
1314
"design-agent",

docs/handover/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
| bridge-system.md | 多 IM 远程桥接系统架构(目录结构、数据流、设计决策) |
1313
| assistant-workspace.md | 助理工作区:人格/记忆文件、对话式引导、自动触发、确定性落盘 |
1414
| theme-system.md | 主题家族系统:两层架构、JSON schema、代码高亮三条渲染链、12 个主题清单 |
15+
| cli-tools.md | CLI 工具管理:静态 catalog、系统检测、一键安装、AI 描述、聊天上下文注入、输入框选择器 |

docs/handover/cli-tools.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# CLI Tools — 系统 CLI 工具管理与聊天感知
2+
3+
## 核心思路
4+
5+
AI 工作流中 CLI 工具(ffmpeg、jq、ripgrep 等)是重要基础设施,但用户往往不知道装什么、怎么装。本功能在侧边栏新增 "CLI Tools" 页面,提供精选工具推荐、一键安装、AI 补全描述,并在聊天时自动将已安装工具注入 system prompt,让 Claude 知道用户系统上有哪些工具可用。
6+
7+
## 目录结构
8+
9+
```
10+
src/lib/
11+
├── cli-tools-catalog.ts # 静态精选 catalog(6 个核心 + EXTRA_WELL_KNOWN_BINS)
12+
├── cli-tools-detect.ts # 系统检测逻辑(which/where + --version)
13+
├── cli-tools-context.ts # 聊天上下文构建(system prompt 注入块)
14+
15+
src/app/api/cli-tools/
16+
├── catalog/route.ts # GET — 返回完整 catalog 列表
17+
├── installed/route.ts # GET — 检测并返回已安装工具的 runtime info
18+
└── [id]/
19+
├── status/route.ts # GET — 单个工具状态 + 版本
20+
├── install/route.ts # POST — SSE 流式安装日志
21+
├── detail/route.ts # GET — 详情弹窗数据
22+
└── describe/route.ts # POST — AI 生成双语工具描述
23+
24+
src/components/cli-tools/
25+
├── CliToolsManager.tsx # 主管理容器(已安装区 + 推荐区)
26+
├── CliToolCard.tsx # 工具卡片(installed / recommended 两种 variant)
27+
├── CliToolDetailDialog.tsx # 详情弹窗(简介 / 场景 / 引导 / 示例提示词)
28+
├── CliToolInstallDialog.tsx # SSE 安装进度弹窗
29+
├── CliToolBatchDescribeDialog.tsx # 批量 AI 描述生成
30+
└── CliToolExtraDetailDialog.tsx # 额外检测工具的详情弹窗
31+
32+
src/app/cli-tools/page.tsx # 页面入口
33+
```
34+
35+
## 数据流
36+
37+
### 工具检测
38+
39+
```
40+
页面加载 → CliToolsManager 并行请求:
41+
GET /api/cli-tools/catalog → CLI_TOOLS_CATALOG(静态数据)
42+
GET /api/cli-tools/installed → detectAllCliTools()
43+
→ 遍历 catalog binNames + EXTRA_WELL_KNOWN_BINS
44+
→ which/where 查找 → --version 提取版本
45+
→ 模块级缓存(TTL 2 分钟)
46+
→ 合并 catalog + runtime info → 分区渲染
47+
```
48+
49+
### 工具安装
50+
51+
```
52+
用户点击"安装" → 选择安装方式(brew/npm/pipx)
53+
→ POST /api/cli-tools/[id]/install { method }
54+
→ 服务端 spawn 子进程执行 catalog 中声明的 command
55+
→ SSE 流式返回 stdout/stderr
56+
→ CliToolInstallDialog 实时显示日志
57+
→ 完成后重新检测工具状态
58+
```
59+
60+
安全约束:只执行 catalog 中声明的 command,不接受用户自定义命令。
61+
62+
### AI 描述生成
63+
64+
```
65+
用户点击"自动完善介绍" → POST /api/cli-tools/[id]/describe { providerId }
66+
→ 校验 tool.supportsAutoDescribe === true
67+
→ generateTextViaSdk() 生成中英双语介绍(60s 超时)
68+
→ 返回 { zh, en } 文本
69+
→ 前端存入 localStorage(key: cli-tool-desc-{id})
70+
→ 刷新后从 localStorage 恢复
71+
```
72+
73+
### 聊天上下文注入
74+
75+
```
76+
用户发送消息 → POST /api/chat
77+
→ buildCliToolsContext()
78+
→ detectAllCliTools()(命中缓存则直接返回)
79+
→ 格式化已安装工具为 <available_cli_tools> XML 块
80+
→ 追加到 system prompt 末尾
81+
→ Claude 获知用户系统上可用的 CLI 工具
82+
```
83+
84+
### 聊天侧 CLI 选择器
85+
86+
```
87+
聊天输入框工具栏 → 点击 Terminal 图标 → popoverMode = 'cli'
88+
→ 异步 fetch /api/cli-tools/installed + /api/cli-tools/catalog
89+
→ 搜索框过滤 → 选择工具
90+
→ 若输入框为空:预填 "我想用 {tool} 工具完成:" (zh) / "I want to use {tool} to: " (en)
91+
→ 若输入框有内容:附加 CliBadge { id, name }
92+
→ 发送时 CliBadge → systemPromptAppend 注入到 system prompt(不显示在对话中)
93+
```
94+
95+
## 类型定义
96+
97+
关键类型在 `src/types/index.ts`
98+
99+
| 类型 | 用途 |
100+
|------|------|
101+
| `CliToolStatus` | `'not_installed' \| 'installed' \| 'needs_auth' \| 'ready'` |
102+
| `CliToolCategory` | `'media' \| 'data' \| 'search' \| 'download' \| 'document' \| 'productivity'` |
103+
| `InstallMethod` | `'brew' \| 'npm' \| 'pipx' \| 'cargo'` |
104+
| `CliToolDefinition` | 完整的工具定义(名称、binNames、摘要、分类、安装方式、详情、示例提示词) |
105+
| `CliToolRuntimeInfo` | 运行时检测结果(状态、版本、路径、AI 描述) |
106+
| `CliToolInstallMethod` | 包含 `method``command``platforms` |
107+
108+
## 设计决策
109+
110+
### 为什么用静态 catalog 而不是动态发现?
111+
112+
安全性——只允许执行预审过的安装命令。可预测性——工具列表、描述、示例提示词都是策划过的内容,质量可控。
113+
114+
### 为什么检测用 which 而不是直接运行?
115+
116+
Electron 桌面环境中 PATH 往往不完整。通过 `getExpandedPath()``src/lib/platform.ts`)展开 `/usr/local/bin``~/.cargo/bin` 等常见路径后传给 `which`,兼容桌面和终端两种启动方式。
117+
118+
### 为什么 AI 描述存 localStorage 而不是 DB?
119+
120+
描述是锦上添花,不是核心数据。避免 schema 迁移负担,丢失可重新生成。
121+
122+
### 聊天侧 CLI 选择器的 popover 模式
123+
124+
采用 `PopoverMode = 'file' | 'skill' | 'cli' | null` 枚举,CLI 是 button-triggered(点击工具栏图标触发),与 skill 的 text-triggered(输入 `/` 触发)不同。button-triggered 弹窗的焦点策略是将焦点交给弹窗内的搜索框,而 text-triggered 弹窗焦点保留在 textarea。
125+
126+
### EXTRA_WELL_KNOWN_BINS
127+
128+
除 catalog 中的 6 个精选工具外,`cli-tools-catalog.ts` 还导出 `EXTRA_WELL_KNOWN_BINS` 数组——常见但不需要详情页的工具(如 python、node、go、docker 等),用于聊天上下文注入,让 Claude 知道系统上还有哪些工具。
129+
130+
## 修改文件清单
131+
132+
| 文件 | 改动 |
133+
|------|------|
134+
| `src/types/index.ts` | 新增 CLI tool 相关类型定义 |
135+
| `src/components/layout/NavRail.tsx` | navItems 增加 CLI Tools 导航项 |
136+
| `src/i18n/en.ts` | 新增 `nav.cliTools` + `cli_tools.*` 英文 key |
137+
| `src/i18n/zh.ts` | 新增 `nav.cliTools` + `cli_tools.*` 中文 key |
138+
| `src/app/api/chat/route.ts` | system prompt 末尾追加 CLI tools context |
139+
| `src/components/chat/MessageInput.tsx` | CLI 选择器弹窗 + CliBadge + systemPromptAppend |

src/__tests__/unit/provider-resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ describe('Provider Resolver', () => {
479479
const config = toAiSdkConfig(resolved);
480480
assert.equal(config.sdkType, 'anthropic');
481481
assert.equal(config.apiKey, 'key');
482-
assert.equal(config.baseUrl, 'https://api.anthropic.com');
482+
assert.equal(config.baseUrl, 'https://api.anthropic.com/v1');
483483
assert.equal(config.modelId, 'sonnet');
484484
assert.deepEqual(config.processEnvInjections, {});
485485
});

0 commit comments

Comments
 (0)