zencode-cli 0.1.0 → 0.2.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/DESIGN.md +613 -0
- package/README.md +400 -0
- package/dist/bin/zencode.js +309 -57
- package/dist/bin/zencode.js.map +1 -1
- package/package.json +4 -2
package/README.md
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# ZenCode
|
|
2
|
+
|
|
3
|
+
极简 CLI AI 编程工具 — 用最少的提示词,让模型把全部能力集中在编程本身。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🤖 **双 Agent 协作** — 调度者(Orchestrator)收集上下文 + 编码者(Coder)专注编程
|
|
8
|
+
- 📝 **Memo 协作桥** — 双 Agent 通过共享备忘录传递上下文,避免重复探索
|
|
9
|
+
- ⚡ **并行子 Agent** — 用 spawn-agents 并行处理多文件任务
|
|
10
|
+
- 📋 **Todo 计划** — 内置任务清单,跟踪多步骤项目
|
|
11
|
+
- 🖥️ **全屏 TUI** — 交互式终端界面,支持流式输出、工具确认
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# 从 npm 安装
|
|
17
|
+
npm install -g zencode-cli
|
|
18
|
+
|
|
19
|
+
# 或者用 yarn
|
|
20
|
+
yarn global add zencode-cli
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 交互式 TUI 模式(推荐)
|
|
27
|
+
zencode
|
|
28
|
+
|
|
29
|
+
# 单次执行
|
|
30
|
+
zencode "帮我写一个 Hello World"
|
|
31
|
+
|
|
32
|
+
# 查看帮助
|
|
33
|
+
zencode --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 配置
|
|
37
|
+
|
|
38
|
+
### 配置文件
|
|
39
|
+
|
|
40
|
+
在 `~/.zencode/config.yaml`(Linux/Mac)或 `%USERPROFILE%\.zencode\config.yaml`(Windows)创建配置文件:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
# 模型配置
|
|
44
|
+
model: deepseek-chat # 模型名称
|
|
45
|
+
api_key: sk-xxx # API 密钥
|
|
46
|
+
base_url: https://api.deepseek.com/v1 # API 地址
|
|
47
|
+
|
|
48
|
+
# Agent 模式
|
|
49
|
+
agent_mode: dual # single | dual
|
|
50
|
+
collaboration: delegated # delegated | autonomous | controlled
|
|
51
|
+
|
|
52
|
+
# 功能开关
|
|
53
|
+
features:
|
|
54
|
+
parallel_agents: on # on | off
|
|
55
|
+
todo: on # on | off
|
|
56
|
+
|
|
57
|
+
# 高级选项
|
|
58
|
+
max_tokens: 8192
|
|
59
|
+
temperature: 0.7
|
|
60
|
+
max_tool_output: 4000 # 工具输出最大字符数
|
|
61
|
+
|
|
62
|
+
# 权限配置(可选)
|
|
63
|
+
permissions:
|
|
64
|
+
bash: confirm # auto | confirm | deny
|
|
65
|
+
write-file: confirm
|
|
66
|
+
read-file: auto
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 环境变量
|
|
70
|
+
|
|
71
|
+
| 变量 | 说明 |
|
|
72
|
+
|------|------|
|
|
73
|
+
| `ZENCODE_API_KEY` | API 密钥(优先级高于配置文件) |
|
|
74
|
+
| `ZENCODE_BASE_URL` | API 地址 |
|
|
75
|
+
| `ZENCODE_MODEL` | 模型名称 |
|
|
76
|
+
|
|
77
|
+
### CLI 参数
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
zencode [options] [prompt...]
|
|
81
|
+
|
|
82
|
+
Arguments:
|
|
83
|
+
prompt 直接执行的提示词(非交互式)
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
-V, --version output the version number
|
|
87
|
+
-m, --model <model> 指定模型名称
|
|
88
|
+
-k, --api-key <key> API 密钥
|
|
89
|
+
-u, --base-url <url> API 基础 URL
|
|
90
|
+
--single 使用单 Agent 模式
|
|
91
|
+
--dual 使用双 Agent 模式
|
|
92
|
+
--mode <mode> 协作模式 (delegated/autonomous/controlled)
|
|
93
|
+
--simple 使用简单 REPL 模式(非全屏 TUI)
|
|
94
|
+
-h, --help display help for command
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 使用模式
|
|
98
|
+
|
|
99
|
+
### 1. 交互式 TUI 模式(默认)
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
zencode
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
启动全屏终端界面:
|
|
106
|
+
- 上半部分:对话历史(流式输出)
|
|
107
|
+
- 下半部分:输入框 + 状态栏
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
┌─────────────────────────────────────────────────────────┐
|
|
111
|
+
│ ◆ 你好,我想创建一个春节祝福网页 │
|
|
112
|
+
│ │
|
|
113
|
+
│ ⏳ + write-file demo/index.html │
|
|
114
|
+
│ ✎ 生成中... 150 行 │
|
|
115
|
+
│ ✓ + write-file demo/index.html 203 行 │
|
|
116
|
+
│ <!DOCTYPE html>... │
|
|
117
|
+
├─────────────────────────────────────────────────────────┤
|
|
118
|
+
│ > 创建马年春节祝福网页 │
|
|
119
|
+
│ ───────────────────────────────────────────────────── │
|
|
120
|
+
│ dual(delegated) ▶ deepseek-chat │ ⚙ coder │ /help │
|
|
121
|
+
└─────────────────────────────────────────────────────────┘
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 2. 单次执行模式
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
zencode "帮我写一个 Python 脚本,批量重命名文件"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 3. 简单 REPL 模式
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
zencode --simple
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
适合不支持全屏 TUI 的终端环境。
|
|
137
|
+
|
|
138
|
+
## Agent 模式
|
|
139
|
+
|
|
140
|
+
### 单 Agent 模式(`--single`)
|
|
141
|
+
|
|
142
|
+
一个 Agent 完成所有工作:理解需求 → 收集上下文 → 写代码 → 执行验证。
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
zencode --single
|
|
146
|
+
# 或
|
|
147
|
+
zencode --single "修复 src/utils.ts 中的类型错误"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 双 Agent 模式(默认)
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
用户请求
|
|
154
|
+
↓
|
|
155
|
+
Orchestrator(调度者)
|
|
156
|
+
├── 评估任务复杂度
|
|
157
|
+
├── 收集上下文(glob/read-file)
|
|
158
|
+
├── 记入 memo(共享记忆)
|
|
159
|
+
└── 委派给 Coder
|
|
160
|
+
↓
|
|
161
|
+
Coder(编码者)
|
|
162
|
+
├── 读 memo 获取上下文
|
|
163
|
+
├── write-file / edit-file
|
|
164
|
+
├── 写 memo 记录改动
|
|
165
|
+
└── 返回结果
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 协作模式
|
|
169
|
+
|
|
170
|
+
| 模式 | 说明 | 适用场景 |
|
|
171
|
+
|------|------|----------|
|
|
172
|
+
| `delegated` | 调度者委派任务,Coder 有完整工具 | 大多数场景 |
|
|
173
|
+
| `autonomous` | Coder 自主决策,适合强模型 | 简单任务、能力强模型 |
|
|
174
|
+
| `controlled` | Coder 只返回代码,调度者执行 | 需要严格控制文件操作 |
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# 切换协作模式
|
|
178
|
+
zencode --mode delegated
|
|
179
|
+
zencode --mode autonomous
|
|
180
|
+
zencode --mode controlled
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
或在 TUI 中输入:
|
|
184
|
+
```
|
|
185
|
+
/mode delegated
|
|
186
|
+
/mode autonomous
|
|
187
|
+
/mode controlled
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 功能
|
|
191
|
+
|
|
192
|
+
### Memo 共享备忘录
|
|
193
|
+
|
|
194
|
+
双 Agent 协作的核心桥梁。
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# 写入
|
|
198
|
+
memo write key="项目结构" value="使用 React + Vite"
|
|
199
|
+
|
|
200
|
+
# 读取
|
|
201
|
+
memo read 项目结构
|
|
202
|
+
|
|
203
|
+
# 列出所有
|
|
204
|
+
memo list
|
|
205
|
+
|
|
206
|
+
# 删除
|
|
207
|
+
memo delete 项目结构
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**协作流程:**
|
|
211
|
+
1. Orchestrator 收集上下文 → `memo write`
|
|
212
|
+
2. 委派时引用 memo key
|
|
213
|
+
3. Coder 先 `memo read` 获取上下文
|
|
214
|
+
4. Coder 完成后 `memo write` 记录改动
|
|
215
|
+
|
|
216
|
+
### Todo 计划
|
|
217
|
+
|
|
218
|
+
多步骤任务管理。
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
# 在 TUI 中
|
|
222
|
+
/todo # 切换 todo 功能
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# 添加任务
|
|
227
|
+
todo add "创建 HTML 结构"
|
|
228
|
+
|
|
229
|
+
# 查看计划
|
|
230
|
+
todo list
|
|
231
|
+
|
|
232
|
+
# 标记完成
|
|
233
|
+
todo done <id>
|
|
234
|
+
|
|
235
|
+
# 删除任务
|
|
236
|
+
todo delete <id>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Spawn Agents 并行子 Agent
|
|
240
|
+
|
|
241
|
+
并行处理多文件任务。
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
# 在 TUI 中
|
|
245
|
+
/parallel # 切换并行功能
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
让多个 Coder 子任务并行运行,适合:
|
|
249
|
+
- 并行读取多个文件
|
|
250
|
+
- 并行搜索代码
|
|
251
|
+
- 多文件批量处理
|
|
252
|
+
|
|
253
|
+
## 快捷键
|
|
254
|
+
|
|
255
|
+
| 快捷键 | 说明 |
|
|
256
|
+
|--------|------|
|
|
257
|
+
| `Ctrl+C` | 取消当前请求 / 退出 |
|
|
258
|
+
| `Ctrl+D` | 退出程序 |
|
|
259
|
+
| `Enter` | 发送消息 |
|
|
260
|
+
| `↑/↓` | 历史命令(简单模式) |
|
|
261
|
+
|
|
262
|
+
### TUI 命令
|
|
263
|
+
|
|
264
|
+
| 命令 | 说明 |
|
|
265
|
+
|------|------|
|
|
266
|
+
| `/help` | 显示帮助 |
|
|
267
|
+
| `/mode [模式]` | 切换协作模式 |
|
|
268
|
+
| `/single` | 切换到单 Agent |
|
|
269
|
+
| `/dual` | 切换到双 Agent |
|
|
270
|
+
| `/parallel` | 开关并行子 Agent |
|
|
271
|
+
| `/todo` | 开关 Todo 计划 |
|
|
272
|
+
| `/clear` | 清空对话历史 |
|
|
273
|
+
| `/info` | 显示当前配置 |
|
|
274
|
+
|
|
275
|
+
## 支持的模型
|
|
276
|
+
|
|
277
|
+
ZenCode 通过 OpenAI 兼容 API 连接各种模型。
|
|
278
|
+
|
|
279
|
+
### 推荐模型
|
|
280
|
+
|
|
281
|
+
| 模型 | API | 特点 |
|
|
282
|
+
|------|-----|------|
|
|
283
|
+
| DeepSeek Chat | deepseek.com | 性价比高,效果好 |
|
|
284
|
+
| Qwen Turbo | dashscope.aliyun.com | 阿里出品 |
|
|
285
|
+
| GPT-4o | openai.com | 能力强 |
|
|
286
|
+
|
|
287
|
+
### 配置示例
|
|
288
|
+
|
|
289
|
+
```yaml
|
|
290
|
+
# DeepSeek
|
|
291
|
+
model: deepseek-chat
|
|
292
|
+
base_url: https://api.deepseek.com/v1
|
|
293
|
+
|
|
294
|
+
# 阿里 Qwen
|
|
295
|
+
model: qwen-turbo
|
|
296
|
+
base_url: https://dashscope.aliyuncs.com/compatible-mode/v1
|
|
297
|
+
|
|
298
|
+
# OpenAI
|
|
299
|
+
model: gpt-4o
|
|
300
|
+
base_url: https://api.openai.com/v1
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## 工具
|
|
304
|
+
|
|
305
|
+
ZenCode 内置以下工具:
|
|
306
|
+
|
|
307
|
+
| 工具 | 说明 | 权限 |
|
|
308
|
+
|------|------|------|
|
|
309
|
+
| `read-file` | 读取文件内容 | auto |
|
|
310
|
+
| `write-file` | 创建/覆盖文件 | confirm |
|
|
311
|
+
| `edit-file` | 编辑文件 | confirm |
|
|
312
|
+
| `glob` | 文件搜索 | auto |
|
|
313
|
+
| `grep` | 代码搜索 | auto |
|
|
314
|
+
| `bash` | 执行命令 | confirm |
|
|
315
|
+
| `spawn-agents` | 并行子 Agent | confirm |
|
|
316
|
+
| `memo` | 共享备忘录 | auto |
|
|
317
|
+
| `todo` | 任务计划 | auto |
|
|
318
|
+
|
|
319
|
+
权限级别:
|
|
320
|
+
- `auto` — 自动执行
|
|
321
|
+
- `confirm` — 需要用户确认
|
|
322
|
+
- `deny` — 禁止执行
|
|
323
|
+
|
|
324
|
+
## 提示词技巧
|
|
325
|
+
|
|
326
|
+
### 1. 明确目标
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
❌ 帮我优化一下代码
|
|
330
|
+
✅ 重构 src/utils.ts 中的 formatDate 函数,使用 dayjs
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 2. 提供上下文
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
✅ 在 demo/ 目录下创建 index.html,使用现有 weather.html 的样式
|
|
337
|
+
✅ 修改 src/api/user.ts,增加获取用户头像的接口
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 3. 分步执行
|
|
341
|
+
|
|
342
|
+
```
|
|
343
|
+
✅ 第一步:创建数据模型
|
|
344
|
+
✅ 第二步:实现 API 接口
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 4. 指定约束
|
|
348
|
+
|
|
349
|
+
```
|
|
350
|
+
✅ 用 TypeScript,不要 any
|
|
351
|
+
✅ 保持现有代码风格,使用 React Hooks
|
|
352
|
+
✅ 不要添加测试,只做核心功能
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## 常见问题
|
|
356
|
+
|
|
357
|
+
### Q: 工具执行被拒绝
|
|
358
|
+
|
|
359
|
+
A: 检查配置文件的 `permissions` 设置,或在 TUI 中按 `y` 允许执行。
|
|
360
|
+
|
|
361
|
+
### Q: 模型响应慢
|
|
362
|
+
|
|
363
|
+
A: 尝试:
|
|
364
|
+
1. 换更快的模型(如 qwen-turbo)
|
|
365
|
+
2. 减少 `max_tokens`
|
|
366
|
+
3. 使用 `--simple` 模式减少 UI 开销
|
|
367
|
+
|
|
368
|
+
### Q: Windows 终端显示异常
|
|
369
|
+
|
|
370
|
+
A: 确保使用支持 ANSI 的终端(如 Windows Terminal、PowerShell)。
|
|
371
|
+
|
|
372
|
+
### Q: 如何更新
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
npm update -g zencode-cli
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## 开发
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
# 克隆项目
|
|
382
|
+
git clone https://github.com/your-repo/zencode.git
|
|
383
|
+
cd zencode
|
|
384
|
+
|
|
385
|
+
# 安装依赖
|
|
386
|
+
npm install
|
|
387
|
+
|
|
388
|
+
# 开发模式
|
|
389
|
+
npm run dev
|
|
390
|
+
|
|
391
|
+
# 构建
|
|
392
|
+
npm run build
|
|
393
|
+
|
|
394
|
+
# 链接本地
|
|
395
|
+
npm link
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## 许可证
|
|
399
|
+
|
|
400
|
+
MIT
|