@speculoai/baton 0.4.0 → 0.5.0
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/LICENSE +21 -0
- package/README.md +103 -391
- package/README.zh-CN.md +103 -391
- package/dist/adapters/agy.js +8 -3
- package/dist/adapters/claude.js +11 -4
- package/dist/adapters/codex.js +11 -2
- package/dist/adapters/cursor.js +14 -6
- package/dist/cli.js +99 -37
- package/dist/contract.js +7 -7
- package/dist/git.js +22 -3
- package/dist/install-ui.js +74 -0
- package/dist/install.js +21 -31
- package/dist/mcp.js +21 -16
- package/dist/process.js +1 -1
- package/dist/rules.js +394 -0
- package/dist/scope.js +5 -5
- package/dist/store.js +2 -2
- package/dist/supervisor.js +38 -11
- package/dist/tail.js +5 -5
- package/dist/tasks.js +146 -34
- package/dist/worktree.js +104 -19
- package/package.json +5 -3
package/README.zh-CN.md
CHANGED
|
@@ -1,460 +1,172 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">Baton</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>把活儿递给隔壁的 Agent。</strong>
|
|
5
|
+
</p>
|
|
4
6
|
|
|
5
|
-
>
|
|
6
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/SpeculoAI/baton/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/SpeculoAI/baton/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@speculoai/baton"><img src="https://img.shields.io/npm/v/@speculoai/baton?style=flat-square&color=111111&label=npm" alt="npm"></a>
|
|
10
|
+
<img src="https://img.shields.io/node/v/@speculoai/baton?style=flat-square&color=111111" alt="Node 版本">
|
|
11
|
+
<img src="https://img.shields.io/badge/hosts-Claude%20Code%20%C2%B7%20Codex%20%C2%B7%20Cursor%20%C2%B7%20Antigravity%20%C2%B7%20Gemini-111111?style=flat-square" alt="支持的宿主">
|
|
12
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-111111?style=flat-square" alt="MIT 许可证"></a>
|
|
13
|
+
</p>
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- [核心工作原理](#核心工作原理)
|
|
17
|
-
- [安装指南 (Installation)](#安装指南-installation)
|
|
18
|
-
- [验证安装](#验证安装)
|
|
19
|
-
- [使用方法](#使用方法)
|
|
20
|
-
- [宿主内的技能](#宿主内的技能)
|
|
21
|
-
- [命令行](#命令行)
|
|
22
|
-
- [状态与存活判定](#状态与存活判定)
|
|
23
|
-
- [停下提问与续轮 (needs_input / reply)](#停下提问与续轮-needs_input--reply)
|
|
24
|
-
- [MCP 工具](#mcp-工具)
|
|
25
|
-
- [任务目录 ~/.baton](#任务目录-baton)
|
|
26
|
-
- [各平台底层调用规范](#各平台底层调用规范)
|
|
27
|
-
- [安全机制](#安全机制)
|
|
28
|
-
- [手工冒烟测试](#手工冒烟测试)
|
|
29
|
-
- [开发与单元测试](#开发与单元测试)
|
|
30
|
-
- [从 0.3.x 升级](#从-03x-升级)
|
|
31
|
-
- [从 0.2.x 升级](#从-02x-升级)
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## 核心工作原理
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
宿主 CLI ──shell──> baton start ──拉起脱离父进程的守护进程──> baton _supervise <id>
|
|
39
|
-
│ │ (立即返回 task_id) │ 持有子 CLI 进程组
|
|
40
|
-
│ ▼ │ 解析流式输出 → 统一事件
|
|
41
|
-
│ ~/.baton/tasks/<id>/ <──────── 唯一写者 ────────┘
|
|
42
|
-
│ ▲
|
|
43
|
-
└──shell/MCP──> baton status / wait / tail / reply / cancel / ls
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
- **任务不依附宿主**:守护进程独立运行。宿主会话退出、MCP 重启、终端关掉,任务照常跑完,之后仍能读到结果。
|
|
47
|
-
- **没有总时长上限**:默认只有空闲超时(连续 600 秒没有任何输出才停),慢模型跑几个小时也行。
|
|
48
|
-
- **过程可见**:各家 CLI 的流式输出被统一成事件(消息、工具调用、工具结果、错误),用 `baton tail -f` 实时看;`status` 直接告诉你它是在动、在安静思考,还是守护进程已经死了。
|
|
49
|
-
- **按轮交互**:子 CLI 停下来提问时,人或主 Agent 用 `baton reply` 在原会话里接着说,每一轮谁说了什么都落盘。
|
|
50
|
-
- **零额外 API Key**:复用本机各家 CLI 已登录的会话与订阅额度。
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## 安装指南 (Installation)
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npx @speculoai/baton install
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
这条命令会把 `baton` 装成全局命令,并把插件装进你选中的 agent。`--only <agent>` 可重复(`claude`、`codex`、`cursor`、`agy`、`gemini`),`--force` 重装,`--dry-run` 只打印命令。以后更新:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
npx @speculoai/baton@latest update
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
下面各家的命令是同一套步骤,供手动安装。
|
|
67
|
-
|
|
68
|
-
### 前置要求
|
|
69
|
-
|
|
70
|
-
1. **Node.js** >= 20.17。
|
|
71
|
-
2. 本地已安装并登录至少一个受支持的 Agent CLI(`codex`、`claude`、`agy`、`cursor`)。
|
|
72
|
-
3. 通过插件市场安装不会把 `baton` 放进 PATH。运行 `/baton:setup`,或执行 `npm install -g @speculoai/baton`。
|
|
73
|
-
4. (可选)本地开发:
|
|
74
|
-
```bash
|
|
75
|
-
git clone https://github.com/SpeculoAI/baton.git
|
|
76
|
-
cd baton
|
|
77
|
-
npm install
|
|
78
|
-
npm run build
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
### Claude Code
|
|
84
|
-
|
|
85
|
-
Claude Code 原生支持通过插件市场进行扩展。
|
|
86
|
-
|
|
87
|
-
#### 远程一键安装(推荐)
|
|
88
|
-
|
|
89
|
-
在系统终端中运行:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
claude plugin marketplace add https://github.com/SpeculoAI/baton
|
|
93
|
-
claude plugin install baton@speculoai
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
或者在已开启的 `claude` 交互终端内直接输入 Slash 命令:
|
|
97
|
-
|
|
98
|
-
```text
|
|
99
|
-
/plugin marketplace add https://github.com/SpeculoAI/baton
|
|
100
|
-
/plugin install baton@speculoai
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### 本地克隆安装
|
|
104
|
-
|
|
105
|
-
在克隆好的 `baton` 目录下执行:
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
claude plugin marketplace add .
|
|
109
|
-
claude plugin install baton@speculoai
|
|
110
|
-
```
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="#前后对比">前后对比</a> •
|
|
17
|
+
<a href="#安装">安装</a> •
|
|
18
|
+
<a href="#怎么用">怎么用</a> •
|
|
19
|
+
<a href="#工作原理">工作原理</a> •
|
|
20
|
+
<a href="docs/reference.zh-CN.md">完整手册</a> •
|
|
21
|
+
<a href="README.md">English</a>
|
|
22
|
+
</p>
|
|
111
23
|
|
|
112
24
|
---
|
|
113
25
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Antigravity 原生支持插件系统与技能自动加载。
|
|
26
|
+
你正在 Claude Code 里干活。同一台电脑上还装着 Codex,已经登录、已经付了费,却闲着。Baton 让你正在对话的这个 Agent 把一块有边界的代码任务交给那个 Agent:盯着它跑、替你转达它的问题,最后把结果带回来。
|
|
117
27
|
|
|
118
|
-
|
|
28
|
+
**任何 Agent 都能当主控,任何 Agent 都能当执行者。** 不需要 API Key,不需要服务器,不上云。每个 Agent 都用它自己的登录和订阅额度。
|
|
119
29
|
|
|
120
|
-
|
|
30
|
+
可派工的执行者:`codex`(Codex CLI)· `claude`(Claude Code)· `cursor`(Cursor Agent CLI)· `agy`(Antigravity)。
|
|
121
31
|
|
|
122
|
-
|
|
123
|
-
agy plugin install https://github.com/SpeculoAI/baton
|
|
124
|
-
```
|
|
32
|
+
## 前后对比
|
|
125
33
|
|
|
126
|
-
|
|
34
|
+
<table>
|
|
35
|
+
<tr>
|
|
36
|
+
<td width="50%">
|
|
127
37
|
|
|
128
|
-
|
|
38
|
+
### 没有 Baton
|
|
129
39
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
40
|
+
1. 另开一个终端,启动 `codex`。
|
|
41
|
+
2. 把任务和它需要的上下文复制进去。
|
|
42
|
+
3. 来回切窗口看它跑到哪了。
|
|
43
|
+
4. 它问一句“选 A 还是 B?”,然后就一直等着你,可能一等几个小时。
|
|
44
|
+
5. 再把结果复制回第一个会话,解释它改了什么。
|
|
133
45
|
|
|
134
|
-
>
|
|
46
|
+
</td>
|
|
47
|
+
<td width="50%">
|
|
135
48
|
|
|
136
|
-
|
|
49
|
+
### 有了 Baton
|
|
137
50
|
|
|
138
|
-
|
|
51
|
+
> **你:** 把这次重构交给 Codex。
|
|
139
52
|
|
|
140
|
-
Codex
|
|
53
|
+
主控 Agent 启动任务,分小段检查进度,把 Codex 的“A 还是 B?”转给你,最后告诉你 Codex 做了什么、改了哪些文件。你全程不用离开当前会话。
|
|
141
54
|
|
|
142
|
-
|
|
55
|
+
</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</table>
|
|
143
58
|
|
|
144
|
-
|
|
59
|
+
## 安装
|
|
145
60
|
|
|
146
61
|
```bash
|
|
147
|
-
|
|
148
|
-
codex plugin add baton@speculoai
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### 交互式安装
|
|
152
|
-
|
|
153
|
-
在 `codex` 交互界面中输入:
|
|
154
|
-
|
|
155
|
-
```text
|
|
156
|
-
/plugins
|
|
62
|
+
npx @speculoai/baton install
|
|
157
63
|
```
|
|
158
64
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
#### 本地克隆安装
|
|
65
|
+
它会找出本机装了哪些 Agent CLI,问你要给哪些装插件,并安装全局 `baton` 命令。需要 Node ≥ 20.17,以及至少一个已登录的受支持 Agent CLI。
|
|
162
66
|
|
|
163
|
-
|
|
67
|
+
看看 Baton 能找到哪些执行者:
|
|
164
68
|
|
|
165
69
|
```bash
|
|
166
|
-
|
|
167
|
-
codex plugin add baton@speculoai
|
|
70
|
+
baton agents
|
|
168
71
|
```
|
|
169
72
|
|
|
170
|
-
|
|
73
|
+
以后用 `npx @speculoai/baton@latest update` 一键更新。安装参数(`--only`、`--force`、`--dry-run`)、各宿主的手动安装方式,以及 Claude Desktop、Windsurf、Zed 的 MCP 配置,见[完整手册](docs/reference.zh-CN.md#安装指南-installation)。
|
|
171
74
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
适用于 Codex 桌面客户端:
|
|
175
|
-
|
|
176
|
-
1. 打开 Codex App,点击左侧边栏的 **Plugins**。
|
|
177
|
-
2. 搜索 `Baton`(或点击添加自定义市场源:`https://github.com/SpeculoAI/baton`)。
|
|
178
|
-
3. 点击 **Install** 确认安装。
|
|
179
|
-
|
|
180
|
-
---
|
|
75
|
+
## 怎么用
|
|
181
76
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
#### Cursor Agent CLI 终端安装
|
|
185
|
-
|
|
186
|
-
Cursor 官方 Agent CLI 支持直接添加 Git 地址:
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
agent plugin marketplace add https://github.com/SpeculoAI/baton
|
|
190
|
-
agent plugin install baton@speculoai
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
或者在 Cursor Agent 聊天框中输入:
|
|
77
|
+
直接用大白话说:
|
|
194
78
|
|
|
195
79
|
```text
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
#### Cursor IDE (MCP 模式配置)
|
|
200
|
-
|
|
201
|
-
如果你主要使用 Cursor 编辑器窗口,可将其作为 MCP 服务器挂载:
|
|
202
|
-
|
|
203
|
-
在项目根目录 `.cursor/mcp.json`(或全局 Cursor 设置中的 MCP 配置)中添加:
|
|
204
|
-
|
|
205
|
-
```json
|
|
206
|
-
{
|
|
207
|
-
"mcpServers": {
|
|
208
|
-
"baton": {
|
|
209
|
-
"command": "baton",
|
|
210
|
-
"args": ["mcp"]
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
### Gemini CLI
|
|
219
|
-
|
|
220
|
-
Gemini CLI 采用扩展(Extensions)系统。这里把 baton 装进 Gemini CLI 当宿主用;暂不支持把任务派给 gemini。
|
|
221
|
-
|
|
222
|
-
#### 远程安装
|
|
223
|
-
|
|
224
|
-
在终端中执行:
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
gemini extensions install https://github.com/SpeculoAI/baton --consent
|
|
80
|
+
把这个失败的测试交给 codex 修
|
|
81
|
+
让 claude 只读地审一下这次 diff
|
|
82
|
+
把迁移拆成三个任务,分给 codex 和 cursor 跑
|
|
228
83
|
```
|
|
229
84
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
在克隆好的 `baton` 目录下执行:
|
|
85
|
+
主控 Agent 在背后执行的只是普通 shell 命令:
|
|
233
86
|
|
|
234
87
|
```bash
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
#### 扩展更新
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
gemini extensions update baton
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
---
|
|
245
|
-
|
|
246
|
-
### 通用 MCP 客户端 (Claude Desktop / Windsurf 等)
|
|
247
|
-
|
|
248
|
-
本仓库提供标准的 MCP Stdio 协议服务,可以接入任何兼容 MCP 的客户端(例如 Claude Desktop、Windsurf、Zed、Cline、Roo Code)。
|
|
249
|
-
|
|
250
|
-
在宿主的 MCP 配置文件中添加:
|
|
251
|
-
|
|
252
|
-
```json
|
|
253
|
-
{
|
|
254
|
-
"mcpServers": {
|
|
255
|
-
"baton": {
|
|
256
|
-
"command": "baton",
|
|
257
|
-
"args": ["mcp"]
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
从 Dock 启动的应用常常拿不到 nvm 或 volta 的 PATH。如果终端里 `baton` 可用、MCP 却起不来,把 `command -v baton` 的绝对路径填进 `command`。
|
|
264
|
-
|
|
265
|
-
---
|
|
266
|
-
|
|
267
|
-
## 验证安装
|
|
268
|
-
|
|
269
|
-
```bash
|
|
270
|
-
baton agents
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
输出示例:
|
|
274
|
-
|
|
275
|
-
```json
|
|
276
|
-
{"agents":[{"id":"codex","installed":true,"bin":"/opt/homebrew/bin/codex","version":"codex-cli 0.167.0"},{"id":"claude","installed":true,"bin":"/Users/user/.local/bin/claude","version":"2.1.323 (Claude Code)"},{"id":"cursor","installed":true,"bin":"/Users/user/.local/bin/cursor-agent","version":"2026.11.11-043ef28"},{"id":"agy","installed":true,"bin":"/Users/user/.local/bin/agy","version":"1.5.6"}]}
|
|
88
|
+
baton start --target codex --prompt "修复 src/parser.ts 里失败的测试" # 立刻返回 task_id
|
|
89
|
+
baton wait <task_id> --for 50 # 反复调用,直到任务停下
|
|
277
90
|
```
|
|
278
91
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
---
|
|
282
|
-
|
|
283
|
-
## 使用方法
|
|
284
|
-
|
|
285
|
-
### 宿主内的技能
|
|
286
|
-
|
|
287
|
-
安装插件后,宿主会加载三个技能:
|
|
288
|
-
|
|
289
|
-
- [skills/setup/SKILL.md](skills/setup/SKILL.md):`/baton:setup`,确认 `baton` 命令在 PATH 上
|
|
290
|
-
- [skills/baton-rescue/SKILL.md](skills/baton-rescue/SKILL.md):单跳派工,有界等待,转问或代答子 CLI 的问题
|
|
291
|
-
- [skills/baton-orchestrate/SKILL.md](skills/baton-orchestrate/SKILL.md):多单调度,持依赖图、逐单推进、审查、返工、换家、汇总(不绑定 Speckit / OpenSpec / agent-skills)
|
|
292
|
-
|
|
293
|
-
对宿主说"把这个重构 rescue 给 Codex 做"之类的话,宿主就会用 shell 调 `baton start`,再循环 `baton wait --for 50` 直到结束。技能只依赖 shell 命令,不要求宿主有后台子 Agent。
|
|
294
|
-
|
|
295
|
-
**路由规则**:用户指定了目标就用指定的;没指定时实现与排错默认派给 `codex`,当前会话本身是 Codex 时改派 `claude`;绝不派给自己。
|
|
296
|
-
|
|
297
|
-
### 命令行
|
|
298
|
-
|
|
299
|
-
所有命令都只输出一个 JSON 对象(`tail` 除外),出错时退出码非 0。`baton` 是 `@speculoai/baton` 提供的全局命令。
|
|
92
|
+
想看执行者在干什么,在任意终端里运行:
|
|
300
93
|
|
|
301
94
|
```bash
|
|
302
|
-
baton
|
|
303
|
-
baton start --target <codex|claude|cursor|agy> [--prompt <text> | stdin] [--file <p>...] [--effort low|medium|high|ultra]
|
|
304
|
-
[--model <id>] [--idle-timeout <秒>] [--max-duration <秒>] [--cwd <dir>]
|
|
305
|
-
[--scope <glob> ...] [--scope-on-violation warn|fail]
|
|
306
|
-
[--mode readonly|write] [--allow-weak]
|
|
307
|
-
baton status <id>
|
|
308
|
-
baton wait <id>... [--for <秒> | --until-done] # 默认 --for 50;--until-done 阻塞到任一任务离开 running
|
|
309
|
-
baton tail <id> [-f] [--raw] # 人读格式的事件;-f 跟到任务停下;--raw 输出 events.jsonl 原行
|
|
310
|
-
baton reply <id> [--prompt <text> | stdin] [--as host|human] # scope_violation / readonly_violation 后也可续轮
|
|
311
|
-
baton cancel <id>
|
|
312
|
-
baton ls [--all] # 默认只列当前目录的任务,按更新时间倒序
|
|
313
|
-
baton prune --older <天数> # 删除早于 N 天的非 running 任务目录(不级联删 worktree)
|
|
314
|
-
baton worktree add [--name <id>] [--branch <name>] [--base <ref>]
|
|
315
|
-
baton worktree ls
|
|
316
|
-
baton worktree rm <name-or-path> # 脏或未合并则拒绝;干净则 remove + 删本地分支
|
|
317
|
-
baton mcp # 启动 MCP 服务(stdio)
|
|
95
|
+
baton tail -f <task_id>
|
|
318
96
|
```
|
|
319
97
|
|
|
320
|
-
|
|
321
|
-
- `--model <id>`(目前仅 Cursor):按任务指定模型,写入 meta,`reply` 延续。Cursor 规则:仅 model → `--model <id>`;model+effort → `--model '<id>[effort=...]'`;若 id 已含档位(如 `grok-4.7-xhigh`)或已有括号再带 `--effort` 则报错。不会出现两个 `--model`。`status` 含 `model`(请求)与 `model_argv`(传给 CLI 的参数);这不是 provider 确认的“实际模型”。
|
|
322
|
-
- `--idle-timeout` 默认 600:连续这么久没有任何输出字节才停掉。`--max-duration` 默认不限。两者都按单轮计时,`reply` 开新一轮时重新计时。
|
|
323
|
-
- **`--mode readonly|write`(默认 `write`):** 映射到各家只读参数(Codex `--sandbox read-only`、Claude `--permission-mode plan`、Cursor `--mode ask`、Agy `--mode plan`)。写入 meta,`reply` 延续。每轮结束后若有净变更,会把干净的 `success` 升为 `readonly_violation`。无映射的目标默认拒绝,需显式 `--allow-weak`。**兼容性:** 新增终态 `readonly_violation`。
|
|
324
|
-
- **Worktree 与任务解耦:** 先 `baton worktree add`,再 `baton start --cwd <path>`。默认目录 `.worktrees/`(会写入 `.gitignore`);可选 `.baton.json` 配置 `copy` / `symlink` / `post_create`。软链 `node_modules` 在分支依赖不一致时可能互相污染,必要时改用 `post_create` 独立安装。
|
|
325
|
-
- **`--scope`(可选):** 可重复,glob 相对任务 `cwd`。每轮结束后对照**任务起点净变更**(自 baseline HEAD 起的提交 ∪ 工作区 digest 差分)。`--scope-on-violation warn`(默认)保留原终态并写 `scope_violations` + `warning`;`fail` 会把干净的 `success` 升为 `scope_violation`。这是**防失误**,不是沙箱:忽略文件、仓外写入、共享 cwd 并发改动是已知盲区——建议与 worktree 叠用。带 `--scope` 时 cwd 必须是 git 仓库。**兼容性:** 新增终态 `scope_violation` 及可选 `scope_*` 字段。
|
|
98
|
+
没指定目标时默认交给 `codex`;如果你本来就在 Codex 里,就交给 `claude`。Baton 永远不会把任务派给你当前正在用的那个 Agent。
|
|
326
99
|
|
|
327
|
-
|
|
100
|
+
## 你会得到什么
|
|
328
101
|
|
|
329
|
-
|
|
|
330
|
-
|---|---|
|
|
331
|
-
| `running` | 还在跑,额外带 `liveness` 和 `quiet_for_s` |
|
|
332
|
-
| `needs_input` | 子 CLI 停下来提问,`decision` 里有 `question` 和 `options` |
|
|
333
|
-
| `success` | 本轮完成,带 `summary` 和本轮的 `git_changes`(warn 策略下仍可能有 `scope_violations`) |
|
|
334
|
-
| `scope_violation` | `--scope-on-violation fail` 下越界;可 `reply` |
|
|
335
|
-
| `readonly_violation` | `--mode readonly` 但工作区有净变更;可 `reply` |
|
|
336
|
-
| `failed` / `timed_out` / `cancelled` | 终态,不能再 `reply` |
|
|
337
|
-
| `not_authenticated` / `quota_exceeded` | 对方 CLI 没登录 / 额度用尽 |
|
|
338
|
-
| `not_installed` | `start` 时就返回,目标不在 `PATH` 里 |
|
|
339
|
-
|
|
340
|
-
`running` 时的 `liveness`:
|
|
341
|
-
|
|
342
|
-
| `liveness` | 条件 |
|
|
102
|
+
| 技能 | 作用 |
|
|
343
103
|
|---|---|
|
|
344
|
-
| `
|
|
345
|
-
| `
|
|
346
|
-
| `
|
|
347
|
-
|
|
348
|
-
### 停下提问与续轮 (needs_input / reply)
|
|
349
|
-
|
|
350
|
-
派工时 baton 会在 prompt 末尾附上输出约定:需要选择时用 `BATON_DECISION` 块提问,做完时用 `BATON_RESULT` 块总结。子 CLI 提问后任务进入 `needs_input`,进程正常退出。
|
|
351
|
-
|
|
352
|
-
```bash
|
|
353
|
-
baton reply <id> --as human --prompt "选 A"
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
- 在原会话上开下一轮。`--as human` 表示这是人说的话;主 Agent 依据用户先前指示代答时用默认的 `--as host`。
|
|
357
|
-
- `success` 之后也能 `reply` 追问。任务 `running` 时 `reply` 返回 `busy`。
|
|
358
|
-
- 每一轮的作者、输入和结果都记在 `turns/<n>.json`,事后可回看。
|
|
104
|
+
| `baton-rescue` | 派出一个任务,分小段等待,把执行者的问题转给你,最后汇报结果。 |
|
|
105
|
+
| `baton-orchestrate` | 调度多个有依赖关系的任务:逐个审查、返工,某个执行者失败时换一家,最后写汇总。 |
|
|
106
|
+
| `/baton:setup` | 如果通过插件市场安装时没装上 `baton` 命令,用它补上。 |
|
|
359
107
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
MCP 是同一套逻辑的薄壳,进程里不存任何任务状态,重启 MCP 不影响正在跑的任务:
|
|
363
|
-
|
|
364
|
-
| 工具 | 对应命令 |
|
|
108
|
+
| 命令 | 作用 |
|
|
365
109
|
|---|---|
|
|
366
|
-
| `
|
|
367
|
-
| `
|
|
368
|
-
| `
|
|
369
|
-
| `
|
|
370
|
-
| `
|
|
371
|
-
| `
|
|
372
|
-
| `
|
|
110
|
+
| `baton start` | 启动任务。可选参数包括 `--effort`、`--mode readonly`、`--scope <glob>`、`--rules check\|pointer\|off`、`--cwd <worktree>`。 |
|
|
111
|
+
| `baton wait` / `status` | 等任务停下,或者看一眼当前状态。 |
|
|
112
|
+
| `baton tail [-f]` | 以可读文本显示实时事件流。 |
|
|
113
|
+
| `baton reply` | 执行者提问、或者你想追加要求时,在同一个会话里接着说。 |
|
|
114
|
+
| `baton cancel` / `ls` / `prune` | 停止任务、列出任务、清理旧任务。 |
|
|
115
|
+
| `baton worktree add/ls/rm` | 给任务单独开一个 git worktree,不碰你的工作目录。 |
|
|
116
|
+
| `baton mcp` | 以 MCP 服务器的形式提供同样的操作,给不能跑 shell 的宿主用。 |
|
|
373
117
|
|
|
374
|
-
|
|
118
|
+
每个命令都只输出一个 JSON 对象,主控 Agent 读起来不会出错。全部参数和状态见[完整手册](docs/reference.zh-CN.md#命令行)。
|
|
375
119
|
|
|
376
|
-
##
|
|
377
|
-
|
|
378
|
-
根目录默认 `~/.baton`,可用 `BATON_HOME` 换位置。目录权限 `0700`,文件 `0600`(里面有 prompt 原文)。
|
|
120
|
+
## 工作原理
|
|
379
121
|
|
|
380
122
|
```
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
123
|
+
主控 Agent ──shell──> baton start ──拉起独立的守护进程──> 执行者 CLI(codex / claude / ...)
|
|
124
|
+
│ │ 立刻返回 task_id │ 流式输出 → 统一事件
|
|
125
|
+
│ ▼ │
|
|
126
|
+
│ ~/.baton/tasks/<id>/ <────── 唯一写者 ───┘
|
|
127
|
+
│ ▲
|
|
128
|
+
└──shell/MCP──> baton wait / status / tail / reply / cancel
|
|
387
129
|
```
|
|
388
130
|
|
|
389
|
-
|
|
131
|
+
- **任务不依附主控。** 每个任务都由自己的守护进程看管。关掉会话、关掉终端或重启 MCP,任务都照常跑,之后仍能读到结果。
|
|
132
|
+
- **没有总时长上限。** 只有连续 10 分钟没有任何输出才会停,慢模型想几个小时也没问题。
|
|
133
|
+
- **统一的事件格式。** 各家 CLI 的消息、工具调用和错误都转换成同一种事件;`status` 会告诉你执行者是在干活、在安静思考,还是已经死了。
|
|
134
|
+
- **提问不会把任务卡死。** 执行者需要你拍板时,任务停在 `needs_input`;`baton reply` 会在原会话里继续,并记下是谁回答的。
|
|
135
|
+
- **是护栏,不是沙箱。** `--mode readonly` 使用各家 CLI 自带的只读模式,如果文件还是被改了就标记出来;`--scope` 在每轮结束后用路径规则检查 git 改动。执行者不能再调用 Baton,事件日志里的凭据会被脱敏。
|
|
390
136
|
|
|
391
|
-
|
|
137
|
+
## 常见问题
|
|
392
138
|
|
|
393
|
-
|
|
139
|
+
**需要 API Key 吗?**
|
|
140
|
+
不需要。Baton 调用的是你已经装好的 CLI,用它们现有的登录。
|
|
394
141
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
| **Codex** | `codex exec --json --color never --approve-for-me --skip-git-repo-check --cd <cwd> -` | `codex exec resume --json <thread_id> -` | write 用 `--approve-for-me`(与 `--sandbox` 互斥);readonly 首轮用 `--sandbox read-only`;`exec resume` 无 sandbox 参数,也不接受 `--cd`、`--color` |
|
|
398
|
-
| **Claude Code** | `claude -p --output-format stream-json --verbose --permission-mode acceptEdits --permission-prompts none` | 追加 `--resume <session_id>` | readonly → `--permission-mode plan`;`stream-json` 在 `-p` 下必须配 `--verbose`;hook 事件不进事件流 |
|
|
399
|
-
| **Cursor** | `cursor-agent --print --force --trust --output-format stream-json --workspace <cwd>` | 追加 `--resume <session_id>` | readonly → `--mode ask`(去掉 `--force`,保留 `--trust`);优先找 `cursor-agent`,再找 `agent`,不调用 IDE 的 `cursor` |
|
|
400
|
-
| **Antigravity (agy)** | `agy --print <prompt> --mode accept-edits --output-format stream-json` | 追加 `--conversation <id>` | readonly → `--mode plan`;回复是逐字增量,完整文本取自最终 `result` |
|
|
142
|
+
**任务跑到一半我把主控会话关了怎么办?**
|
|
143
|
+
任务会继续跑。开个新会话,运行 `baton ls` 或 `baton status <id>`。
|
|
401
144
|
|
|
402
|
-
|
|
145
|
+
**`--scope` 算安全边界吗?**
|
|
146
|
+
不算。它只能拦住 git 看得见的文件里的误改。要真正隔离,请把任务放进 `baton worktree`。
|
|
403
147
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
## 安全机制
|
|
148
|
+
**执行者会遵守我的项目规则 / 环境吗?**
|
|
149
|
+
`baton status` 会报告 `rules.unseen`(目标原生不会加载的规则文件);若你用了 [rulesync](https://github.com/dyoshikawa/rulesync),还会报告生成配置是否同步。需要时加 `--rules pointer`,让执行者先去读那些文件。更稳妥的做法是维护共享的 `AGENTS.md`,并用 rulesync 把 MCP/skills/hooks 同步到各家 CLI。
|
|
407
150
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
3. **凭据脱敏**:写进事件和摘要的文本先脱敏再截断;原始日志完整保留在受 `0600` 保护的 `raw/` 下。
|
|
411
|
-
4. **id 校验**:所有传入的 task id 先校验是 UUID,再拼路径。
|
|
412
|
-
5. **`--scope` 不是安全边界**:只事后检查 git 可见的净变更。被 ignore 的路径、仓外写入、共享 cwd 并发、orphaned(检查未跑)是已知盲区。
|
|
413
|
-
|
|
414
|
-
---
|
|
151
|
+
**Gemini CLI 能当执行者吗?**
|
|
152
|
+
暂时不能,但可以当主控。
|
|
415
153
|
|
|
416
|
-
|
|
154
|
+
**状态存在哪?**
|
|
155
|
+
在 `~/.baton/tasks/<id>/` 下(可用 `BATON_HOME` 修改):`meta.json`、`events.jsonl`、每轮一个文件,以及原始日志。不会被自动删除。
|
|
417
156
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
1. `baton agents`,确认目标 `installed: true`。
|
|
421
|
-
2. 发起一个会停下提问的任务:
|
|
422
|
-
```bash
|
|
423
|
-
baton start --target codex --effort low --prompt "不要改文件。先停下来问我:选 A 还是 B,用 BATON_DECISION 格式,options: A | B。"
|
|
424
|
-
```
|
|
425
|
-
3. 另开一个终端 `baton tail -f <id>`,能实时看到事件。
|
|
426
|
-
4. `baton wait <id> --for 50` 直到返回 `needs_input`,`decision` 里是 A/B。
|
|
427
|
-
5. `baton reply <id> --as human --prompt "A。回复你选的字母后用 BATON_RESULT 结束。"`,再 `wait` 到 `success`,确认 `session_id` 与第一轮相同。
|
|
428
|
-
|
|
429
|
-
---
|
|
430
|
-
|
|
431
|
-
## 开发与单元测试
|
|
157
|
+
## 开发
|
|
432
158
|
|
|
433
159
|
```bash
|
|
434
|
-
npm
|
|
435
|
-
npm
|
|
160
|
+
npm install
|
|
161
|
+
npm test # 类型检查 + node --test,用假 CLI 跑,不消耗模型额度
|
|
436
162
|
```
|
|
437
163
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
---
|
|
441
|
-
|
|
442
|
-
## 从 0.3.x 升级
|
|
443
|
-
|
|
444
|
-
- 用 `npx @speculoai/baton install` 安装,用 `npx @speculoai/baton@latest update` 更新。插件 id 是 `baton@speculoai`。
|
|
445
|
-
- MCP 运行 `baton`,参数是 `["mcp"]`。`/baton:setup` 安装全局包,不再往插件目录里执行 npm。
|
|
446
|
-
- Node 要求改为 >= 20.17。发布包由 `tsc` 构建,市场安装不再需要 TypeScript 源码。
|
|
164
|
+
所有改动都必须通过 PR 合并,分支、PR、CI 和发布流程见 [CONTRIBUTING](.github/CONTRIBUTING.md)。设计文档见 [docs/architecture.md](docs/architecture.md) 和 [docs/hosts.md](docs/hosts.md)。从 0.3.x 或更早版本升级,请看[升级说明](docs/reference.zh-CN.md#从-03x-升级)。
|
|
447
165
|
|
|
448
|
-
##
|
|
166
|
+
## 许可证
|
|
449
167
|
|
|
450
|
-
|
|
451
|
-
- 手工 MCP 配置的 `command` 为 `baton`,`args` 为 `["mcp"]`。
|
|
452
|
-
- CLI 去掉 `delegate`,改为 `start` + `wait` + `reply`;`wait` 用位置参数传 id。
|
|
453
|
-
- MCP 去掉 `delegate_task(session_id)` 续派和 `task_wait_any`:续轮用 `task_reply`,多单等待用 `task_wait(task_ids)`。
|
|
454
|
-
- `needs_decision` 改名 `needs_input`;`timeout_seconds`(上限 1800)改为 `idle_timeout_seconds` + `max_duration_seconds`,默认没有总时长上限。
|
|
455
|
-
- 任务状态从系统临时目录移到 `~/.baton`。
|
|
456
|
-
- **暂不支持 gemini 作为派工目标**(本机鉴权问题,无法验证)。Gemini CLI 作为宿主安装 baton 扩展不受影响。
|
|
168
|
+
[MIT](LICENSE)
|
|
457
169
|
|
|
458
170
|
---
|
|
459
171
|
|
|
460
|
-
|
|
172
|
+
<sub>曾用名 **Agent-Plugin-Agent (APA)**。旧的安装字符串已失效,请使用 `baton@speculoai`。</sub>
|
package/dist/adapters/agy.js
CHANGED
|
@@ -15,6 +15,11 @@ function parse(line) {
|
|
|
15
15
|
export const agy = {
|
|
16
16
|
id: "agy",
|
|
17
17
|
readonlyEnforcement: "agent-enforced",
|
|
18
|
+
// Verified 2026-11-21: AGENTS.md / GEMINI.md / .agents/rules (and legacy .agent/rules). No load gates surveyed.
|
|
19
|
+
rules: {
|
|
20
|
+
files: ["AGENTS.md", "GEMINI.md", ".agents/AGENTS.md", ".agents/GEMINI.md", ".agents/rules", ".agent/rules"],
|
|
21
|
+
rulesyncTarget: "antigravity-cli",
|
|
22
|
+
},
|
|
18
23
|
resolve(env) {
|
|
19
24
|
return which(["agy"], env);
|
|
20
25
|
},
|
|
@@ -38,8 +43,8 @@ export const agy = {
|
|
|
38
43
|
return [];
|
|
39
44
|
if (obj.event === "step_update") {
|
|
40
45
|
const step = obj.step_update ?? {};
|
|
41
|
-
// agent_response
|
|
42
|
-
//
|
|
46
|
+
// agent_response text_delta events are per-character increments; the full reply appears once in result.response,
|
|
47
|
+
// otherwise marker parsing would only see the last increment.
|
|
43
48
|
if (step.step_type !== "tool")
|
|
44
49
|
return [];
|
|
45
50
|
const name = String(step.tool_name ?? step.tool_info?.name ?? "tool");
|
|
@@ -51,7 +56,7 @@ export const agy = {
|
|
|
51
56
|
if (obj.event === "result") {
|
|
52
57
|
const result = obj.result ?? {};
|
|
53
58
|
if (result.status !== "SUCCESS")
|
|
54
|
-
return event({ type: "error", text: redact(String(result.response || result.status || "agy
|
|
59
|
+
return event({ type: "error", text: redact(String(result.response || result.status || "agy returned an error")) });
|
|
55
60
|
return typeof result.response === "string" && result.response ? event({ type: "message", text: result.response }) : [];
|
|
56
61
|
}
|
|
57
62
|
return null;
|
package/dist/adapters/claude.js
CHANGED
|
@@ -22,11 +22,18 @@ function contentText(content) {
|
|
|
22
22
|
export const claude = {
|
|
23
23
|
id: "claude",
|
|
24
24
|
readonlyEnforcement: "agent-enforced",
|
|
25
|
+
// Verified 2026-11-21/22: CLAUDE.md hierarchy; AGENTS.md only when none of those three exist.
|
|
26
|
+
// Baton uses -p, which loads project .mcp.json without an approval prompt (no mcp gate).
|
|
27
|
+
rules: {
|
|
28
|
+
files: ["CLAUDE.md", ".claude/CLAUDE.md", "CLAUDE.local.md"],
|
|
29
|
+
conditional: [{ file: "AGENTS.md", unless: ["CLAUDE.md", ".claude/CLAUDE.md", "CLAUDE.local.md"] }],
|
|
30
|
+
rulesyncTarget: "claudecode",
|
|
31
|
+
},
|
|
25
32
|
resolve(env) {
|
|
26
33
|
return which(["claude"], env);
|
|
27
34
|
},
|
|
28
35
|
build({ bin, prompt, sessionId, reasoningEffort, mode }) {
|
|
29
|
-
// stream-json
|
|
36
|
+
// stream-json requires --verbose with -p.
|
|
30
37
|
const permission = mode === "readonly" ? "plan" : "acceptEdits";
|
|
31
38
|
const args = ["-p", "--output-format", "stream-json", "--verbose", "--permission-mode", permission, "--permission-prompts", "none"];
|
|
32
39
|
if (reasoningEffort)
|
|
@@ -44,7 +51,7 @@ export const claude = {
|
|
|
44
51
|
const obj = parse(line);
|
|
45
52
|
if (!obj || typeof obj !== "object" || typeof obj.type !== "string")
|
|
46
53
|
return null;
|
|
47
|
-
// system
|
|
54
|
+
// system: init is handled by sessionIdFrom; hook_* carries host hook output and stays out of the event stream.
|
|
48
55
|
if (obj.type === "system" || obj.type === "rate_limit_event")
|
|
49
56
|
return [];
|
|
50
57
|
const parts = Array.isArray(obj.message?.content) ? obj.message.content : [];
|
|
@@ -68,8 +75,8 @@ export const claude = {
|
|
|
68
75
|
.map((p) => stamp({ type: "tool_result", name: "tool", ok: p.is_error !== true, detail: redact(contentText(p.content)).slice(0, 200) }));
|
|
69
76
|
}
|
|
70
77
|
if (obj.type === "result") {
|
|
71
|
-
//
|
|
72
|
-
return obj.is_error ? [stamp({ type: "error", text: redact(String(obj.result ?? obj.subtype ?? "claude
|
|
78
|
+
// The final text was already emitted once as an assistant message; only report errors here.
|
|
79
|
+
return obj.is_error ? [stamp({ type: "error", text: redact(String(obj.result ?? obj.subtype ?? "claude returned an error")) })] : [];
|
|
73
80
|
}
|
|
74
81
|
return null;
|
|
75
82
|
},
|