@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SpeculoAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,460 +1,172 @@
1
- # Baton
1
+ <h1 align="center">Baton</h1>
2
2
 
3
- **English** | [简体中文](README.zh-CN.md)
3
+ <p align="center">
4
+ <strong>Pass the task to the agent next door.</strong>
5
+ </p>
4
6
 
5
- > A local compute bridge for AI agents: **Any Agent as Host, Any Agent as Worker**.
6
- > The CLI/IDE you are using is the Host. It hands bounded coding tasks to other agent CLIs installed on the same machine (Workers), spending their subscriptions. Each task runs in its own process with its state on disk, can run as long as it needs, and can be watched at any time.
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 version">
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="Hosts">
12
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-111111?style=flat-square" alt="MIT license"></a>
13
+ </p>
7
14
 
8
- Delegation targets: `claude` (Claude Code), `codex` (Codex CLI), `cursor` (Cursor Agent CLI), `agy` (Antigravity).
9
-
10
- > **0.4.0 is a breaking release.** See [Upgrading from 0.3.x](#upgrading-from-03x). 0.3.0 notes are in [Upgrading from 0.2.x](#upgrading-from-02x).
11
-
12
- ---
13
-
14
- ## Table of Contents
15
-
16
- - [How It Works](#how-it-works)
17
- - [Installation](#installation)
18
- - [Verify Installation](#verify-installation)
19
- - [Usage](#usage)
20
- - [Skills in the host](#skills-in-the-host)
21
- - [Command line](#command-line)
22
- - [Statuses and liveness](#statuses-and-liveness)
23
- - [Questions and follow-up turns (needs_input / reply)](#questions-and-follow-up-turns-needs_input--reply)
24
- - [MCP tools](#mcp-tools)
25
- - [Task directory ~/.baton](#task-directory-baton)
26
- - [Underlying Calling Conventions](#underlying-calling-conventions)
27
- - [Safety](#safety)
28
- - [Manual Smoke Testing](#manual-smoke-testing)
29
- - [Development & Testing](#development--testing)
30
- - [Upgrading from 0.3.x](#upgrading-from-03x)
31
- - [Upgrading from 0.2.x](#upgrading-from-02x)
32
-
33
- ---
34
-
35
- ## How It Works
36
-
37
- ```
38
- Host CLI ──shell──> baton start ──spawns a detached supervisor──> baton _supervise <id>
39
- │ │ (returns task_id at once) │ owns the worker's process group
40
- │ ▼ │ parses streamed output → events
41
- │ ~/.baton/tasks/<id>/ <──────── single writer ──────┘
42
- │ ▲
43
- └──shell/MCP──> baton status / wait / tail / reply / cancel / ls
44
- ```
45
-
46
- - **Tasks outlive the host**: the supervisor runs on its own. Closing the host session, restarting MCP, or closing the terminal does not stop the task, and its result can still be read afterwards.
47
- - **No total time cap**: by default only an idle timeout applies (stop after 600 seconds with no output at all), so slow models can run for hours.
48
- - **Visible progress**: each CLI's streamed output becomes uniform events (messages, tool calls, tool results, errors). Watch them live with `baton tail -f`; `status` says whether the worker is busy, quietly thinking, or whether its supervisor died.
49
- - **Turn-based interaction**: when the worker stops to ask a question, a human or the host agent continues the same conversation with `baton reply`. Every turn and its author are recorded.
50
- - **No extra API keys**: reuses each CLI's existing login and subscription.
51
-
52
- ---
53
-
54
- ## Installation
55
-
56
- ```bash
57
- npx @speculoai/baton install
58
- ```
59
-
60
- This installs the `baton` command globally and the plugin into the agent CLIs you select. `--only <agent>` is repeatable (`claude`, `codex`, `cursor`, `agy`, `gemini`), `--force` reinstalls, and `--dry-run` prints the commands. Update everything later with:
61
-
62
- ```bash
63
- npx @speculoai/baton@latest update
64
- ```
65
-
66
- The per-host commands below are the same steps, run by hand.
67
-
68
- ### Prerequisites
69
-
70
- 1. **Node.js** >= 20.17.
71
- 2. At least one supported Agent CLI installed and logged in locally (`codex`, `claude`, `agy`, or `cursor`).
72
- 3. A marketplace install does not put `baton` on PATH. Run `/baton:setup`, or `npm install -g @speculoai/baton`.
73
- 4. (Optional) Local checkout:
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 supports plugins via its plugin marketplace.
86
-
87
- #### Remote One-Click Install (Recommended)
88
-
89
- Run directly in your system terminal:
90
-
91
- ```bash
92
- claude plugin marketplace add https://github.com/SpeculoAI/baton
93
- claude plugin install baton@speculoai
94
- ```
95
-
96
- Or inside an active `claude` session using Slash commands:
97
-
98
- ```text
99
- /plugin marketplace add https://github.com/SpeculoAI/baton
100
- /plugin install baton@speculoai
101
- ```
102
-
103
- #### Local Checkout Install
104
-
105
- From inside your local `baton` directory:
106
-
107
- ```bash
108
- claude plugin marketplace add .
109
- claude plugin install baton@speculoai
110
- ```
15
+ <p align="center">
16
+ <a href="#before--after">Before/After</a> •
17
+ <a href="#install">Install</a> •
18
+ <a href="#use-it">Use it</a> •
19
+ <a href="#how-it-works">How it works</a> •
20
+ <a href="docs/reference.md">Full reference</a> •
21
+ <a href="README.zh-CN.md">Chinese</a>
22
+ </p>
111
23
 
112
24
  ---
113
25
 
114
- ### Antigravity (agy)
115
-
116
- Antigravity natively discovers plugins and auto-loads their skills.
26
+ You're working in Claude Code. Codex is installed on the same laptop, logged in, already paid for, and sitting idle. Baton lets the agent you're talking to hand a bounded coding task to that other agent, keep an eye on it, answer its questions, and bring the result back.
117
27
 
118
- #### Remote One-Click Install (Recommended)
28
+ **Any agent as host, any agent as worker.** No API keys, no server, no cloud. Every agent uses its own login and subscription.
119
29
 
120
- Run in your terminal:
30
+ Workers: `codex` (Codex CLI) · `claude` (Claude Code) · `cursor` (Cursor Agent CLI) · `agy` (Antigravity).
121
31
 
122
- ```bash
123
- agy plugin install https://github.com/SpeculoAI/baton
124
- ```
32
+ ## Before / After
125
33
 
126
- #### Local Checkout Install
34
+ <table>
35
+ <tr>
36
+ <td width="50%">
127
37
 
128
- From inside your local `baton` directory:
38
+ ### Without Baton
129
39
 
130
- ```bash
131
- agy plugin install .
132
- ```
40
+ 1. Open a second terminal and start `codex`.
41
+ 2. Copy the task in, plus the context it needs.
42
+ 3. Keep switching windows to check on it.
43
+ 4. It asks "A or B?" and waits for you, possibly for hours.
44
+ 5. Copy the result back into the first session and explain what changed.
133
45
 
134
- > **Update**: Re-running the same install command updates the plugin to the latest version.
46
+ </td>
47
+ <td width="50%">
135
48
 
136
- ---
49
+ ### With Baton
137
50
 
138
- ### Codex CLI
51
+ > **You:** rescue this refactor to Codex.
139
52
 
140
- Codex CLI supports adding plugin marketplaces and registering MCP tools.
53
+ The host starts the job, checks on it in short steps, passes Codex's "A or B?" to you, and then reports what Codex did and which files it changed. You never leave the session.
141
54
 
142
- #### Terminal Command Install
55
+ </td>
56
+ </tr>
57
+ </table>
143
58
 
144
- Run in your system terminal:
59
+ ## Install
145
60
 
146
61
  ```bash
147
- codex plugin marketplace add https://github.com/SpeculoAI/baton
148
- codex plugin add baton@speculoai
149
- ```
150
-
151
- #### Interactive TUI Install
152
-
153
- Inside an interactive `codex` session:
154
-
155
- ```text
156
- /plugins
62
+ npx @speculoai/baton install
157
63
  ```
158
64
 
159
- Search for `baton` and select `Install Plugin`.
160
-
161
- #### Local Checkout Install
65
+ It finds the agent CLIs on your machine, asks which ones should get the plugin, and installs the global `baton` command. Requires Node ≥ 20.17 and at least one supported agent CLI that is already logged in.
162
66
 
163
- From inside your local `baton` directory:
67
+ Check which workers Baton can see:
164
68
 
165
69
  ```bash
166
- codex plugin marketplace add .
167
- codex plugin add baton@speculoai
70
+ baton agents
168
71
  ```
169
72
 
170
- ---
73
+ Update everything later with `npx @speculoai/baton@latest update`. Flags (`--only`, `--force`, `--dry-run`), per-host manual installs, and MCP config for Claude Desktop, Windsurf, and Zed are covered in the [reference](docs/reference.md#installation).
171
74
 
172
- ### Codex App
173
-
174
- For the Codex desktop application:
175
-
176
- 1. Open Codex App and navigate to **Plugins** in the sidebar.
177
- 2. Search for `Baton` (or add custom marketplace source: `https://github.com/SpeculoAI/baton`).
178
- 3. Click **Install**.
179
-
180
- ---
75
+ ## Use it
181
76
 
182
- ### Cursor (Agent CLI & IDE)
183
-
184
- #### Cursor Agent CLI Install
185
-
186
- Cursor's official Agent CLI accepts Git repositories:
187
-
188
- ```bash
189
- agent plugin marketplace add https://github.com/SpeculoAI/baton
190
- agent plugin install baton@speculoai
191
- ```
192
-
193
- Or in the Cursor Agent chat window:
77
+ Just ask in plain language:
194
78
 
195
79
  ```text
196
- /add-plugin baton
197
- ```
198
-
199
- #### Cursor IDE (MCP Mode)
200
-
201
- If using the Cursor editor interface, configure it directly as an MCP server.
202
-
203
- In your project's `.cursor/mcp.json` (or global Cursor MCP Settings):
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 uses an extension system. This installs baton into Gemini CLI as the host; delegating tasks to gemini is not supported.
221
-
222
- #### Remote Install
223
-
224
- Run in your terminal:
225
-
226
- ```bash
227
- gemini extensions install https://github.com/SpeculoAI/baton --consent
80
+ rescue this failing test to codex
81
+ have claude review the diff, read-only
82
+ split the migration into three jobs and run them on codex and cursor
228
83
  ```
229
84
 
230
- #### Local Link Mode (For development)
231
-
232
- From inside your local `baton` directory:
85
+ Behind the scenes, the host runs ordinary shell commands:
233
86
 
234
87
  ```bash
235
- gemini extensions link .
236
- ```
237
-
238
- #### Update Extension
239
-
240
- ```bash
241
- gemini extensions update baton
242
- ```
243
-
244
- ---
245
-
246
- ### Generic MCP Clients (Claude Desktop / Windsurf / etc.)
247
-
248
- Baton exposes a standard Stdio MCP server compatible with any MCP client (including Claude Desktop, Windsurf, Zed, Cline, Roo Code).
249
-
250
- Add the following to your client's MCP configuration JSON:
251
-
252
- ```json
253
- {
254
- "mcpServers": {
255
- "baton": {
256
- "command": "baton",
257
- "args": ["mcp"]
258
- }
259
- }
260
- }
261
- ```
262
-
263
- Apps launched from the Dock often miss an nvm or volta PATH. If `baton` works in a terminal but MCP cannot start it, set `command` to the absolute path from `command -v baton`.
264
-
265
- ---
266
-
267
- ## Verify Installation
268
-
269
- ```bash
270
- baton agents
271
- ```
272
-
273
- Example output:
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 "Fix the failing test in src/parser.ts" # returns a task_id at once
89
+ baton wait <task_id> --for 50 # repeats until the job stops
277
90
  ```
278
91
 
279
- Only agents with `installed: true` can be delegation targets.
280
-
281
- ---
282
-
283
- ## Usage
284
-
285
- ### Skills in the host
286
-
287
- After installation the host loads three skills:
288
-
289
- - [skills/setup/SKILL.md](skills/setup/SKILL.md): `/baton:setup`, makes sure the `baton` command is on PATH
290
- - [skills/baton-rescue/SKILL.md](skills/baton-rescue/SKILL.md): one hop, bounded waiting, relays or answers the worker's questions
291
- - [skills/baton-orchestrate/SKILL.md](skills/baton-orchestrate/SKILL.md): several jobs with a dependency graph, per-job review, rework, fail-over, and a summary (does not require Speckit / OpenSpec / agent-skills)
292
-
293
- Say something like "rescue this refactor to Codex" and the host runs `baton start` through its shell, then repeats `baton wait --for 50` until the job stops. The skills rely only on shell commands; they do not need the host to have background sub-agents.
294
-
295
- **Routing**: use the target the user names. Otherwise implementation and debugging go to `codex`, or to `claude` when the current session is already Codex. Never delegate to yourself.
296
-
297
- ### Command line
298
-
299
- Every command prints exactly one JSON object (except `tail`) and exits non-zero on error. `baton` is the global command from `@speculoai/baton`.
92
+ Want to see what the worker is doing? Run this in any terminal:
300
93
 
301
94
  ```bash
302
- baton agents
303
- baton start --target <codex|claude|cursor|agy> [--prompt <text> | stdin] [--file <p>...] [--effort low|medium|high|ultra]
304
- [--model <id>] [--idle-timeout <s>] [--max-duration <s>] [--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 <s> | --until-done] # default --for 50; --until-done blocks until a job leaves running
309
- baton tail <id> [-f] [--raw] # readable events; -f follows until the job stops; --raw prints events.jsonl lines
310
- baton reply <id> [--prompt <text> | stdin] [--as host|human] # also after scope_violation / readonly_violation
311
- baton cancel <id>
312
- baton ls [--all] # jobs for the current directory by default, newest first
313
- baton prune --older <days> # delete non-running task dirs older than N days (does not remove worktrees)
314
- baton worktree add [--name <id>] [--branch <name>] [--base <ref>]
315
- baton worktree ls
316
- baton worktree rm <name-or-path> # refuses dirty/unmerged trees; remove + delete local branch when clean
317
- baton mcp # start the MCP server (stdio)
95
+ baton tail -f <task_id>
318
96
  ```
319
97
 
320
- - `--effort` maps to each CLI's native flag: Codex `-c model_reasoning_effort=...`; Claude/Agy `--effort` (`ultra` becomes `max`); Cursor alone → `--model auto[effort=...]`.
321
- - `--model <id>` (Cursor only for now): sets the requested model, stored on the task and kept across `reply`. Cursor rules: model only → `--model <id>`; model+effort → `--model '<id>[effort=...]'`; if the id already embeds a tier (e.g. `grok-4.7-xhigh`) or brackets, combining `--effort` errors. Never emits two `--model` flags. `status` shows `model` (requested) and `model_argv` (passed to the CLI). That is not a provider-confirmed “actual model”.
322
- - `--idle-timeout` defaults to 600: the job stops only after that many seconds without a single output byte. `--max-duration` is unlimited by default. Both apply per turn and restart on `reply`.
323
- - **`--mode readonly|write` (default `write`):** maps to each CLI's read-only path (Codex `--sandbox read-only`, Claude `--permission-mode plan`, Cursor `--mode ask`, Agy `--mode plan`). Stored on the task and kept across `reply`. After each turn, dirty net changes upgrade a clean `success` to `readonly_violation`. Targets with no mapping fail unless `--allow-weak` is set. **Breaking note:** new terminal status `readonly_violation`.
324
- - **Worktrees are separate from tasks:** `baton worktree add`, then `baton start --cwd <path>`. Default root is `.worktrees/` (appended to `.gitignore` if needed). Optional `.baton.json` configures `copy` / `symlink` / `post_create`. Symlinking `node_modules` can cross-contaminate when branches diverge — prefer `post_create` installs when unsure.
325
- - **`--scope` (optional):** repeatable globs relative to the task `cwd`. After each turn, Baton checks **task-baseline net changes** (commits since start HEAD ∪ working-tree digest diff) against those globs. `--scope-on-violation warn` (default) keeps the transport status and sets `scope_violations` + `warning`; `fail` upgrades a clean `success` to `scope_violation`. This is a **mistake fence**, not a sandbox: ignored paths, non-git writes, and concurrent edits on a shared cwd are blind spots — prefer combining with worktree. Requires a git repo when `--scope` is set. **Breaking note for clients:** new terminal status `scope_violation` (and optional `scope_*` meta fields).
98
+ If no target is named, the task goes to `codex`, or to `claude` when you are already in Codex. Baton never delegates to the agent you are already using.
326
99
 
327
- ### Statuses and liveness
100
+ ## What you get
328
101
 
329
- | `status` | Meaning |
330
- |---|---|
331
- | `running` | Still working; includes `liveness` and `quiet_for_s` |
332
- | `needs_input` | The worker asked a question; `decision` holds `question` and `options` |
333
- | `success` | Turn finished; includes `summary` and this turn's `git_changes` (still check `scope_violations` under warn) |
334
- | `scope_violation` | Out-of-scope edits under `--scope-on-violation fail`; `reply` allowed |
335
- | `readonly_violation` | `--mode readonly` but the tree changed; `reply` allowed |
336
- | `failed` / `timed_out` / `cancelled` | Terminal; cannot be replied to |
337
- | `not_authenticated` / `quota_exceeded` | The target CLI is not logged in / out of quota |
338
- | `not_installed` | Returned by `start`; the target is not on `PATH` |
339
-
340
- `liveness` while `running`:
341
-
342
- | `liveness` | Condition |
102
+ | Skill | What it does |
343
103
  |---|---|
344
- | `active` | Output within the last 60 seconds |
345
- | `quiet` | Supervisor alive but silent for more than 60 seconds (usually thinking) |
346
- | `orphaned` | Supervisor gone or heartbeat older than 30 seconds; the next read kills leftover processes and records `failed` |
347
-
348
- ### Questions and follow-up turns (needs_input / reply)
349
-
350
- Baton appends an output contract to every prompt: ask with a `BATON_DECISION` block when a choice is needed, finish with a `BATON_RESULT` block. When the worker asks, the task moves to `needs_input` and the worker process exits normally.
351
-
352
- ```bash
353
- baton reply <id> --as human --prompt "A"
354
- ```
355
-
356
- - Starts the next turn in the same conversation. `--as human` marks the words as the user's; the default `--as host` is for answers the host gives from the user's earlier instructions.
357
- - `reply` also works after `success` for a follow-up. While the job is `running`, `reply` returns `busy`.
358
- - Each turn's author, input, and result are stored in `turns/<n>.json`.
104
+ | `baton-rescue` | Hands off one job, waits in short steps, passes the worker's questions to you, and reports the result. |
105
+ | `baton-orchestrate` | Runs several jobs with dependencies between them, reviews each one, retries, switches workers when one fails, and writes a summary. |
106
+ | `/baton:setup` | Puts the `baton` command on PATH if a marketplace install skipped it. |
359
107
 
360
- ### MCP tools
361
-
362
- MCP is a thin shell over the same logic. It keeps no task state, so restarting MCP does not affect running jobs:
363
-
364
- | Tool | Command |
108
+ | Command | What it does |
365
109
  |---|---|
366
- | `list_agents` | `agents` |
367
- | `delegate_task` | `start` (`target_agent`, `prompt`, `files`, `reasoning_effort`, `idle_timeout_seconds`, `max_duration_seconds`, `cwd`) |
368
- | `task_status` | `status` |
369
- | `task_wait` | `wait` (`task_ids`, `wait_seconds` default 50, max 55; sends a progress notification every 15 seconds) |
370
- | `task_reply` | `reply` (`task_id`, `prompt`, `as`) |
371
- | `task_cancel` | `cancel` |
372
- | `task_list` | `ls` (`all`, `cwd`) |
110
+ | `baton start` | Starts a job. Options include `--effort`, `--mode readonly`, `--scope <glob>`, `--rules check\|pointer\|off`, and `--cwd <worktree>`. |
111
+ | `baton wait` / `status` | Waits for the job to stop, or takes one look at it. |
112
+ | `baton tail [-f]` | Shows the live event stream as readable text. |
113
+ | `baton reply` | Continues the same conversation when the worker asks a question or you want a follow-up. |
114
+ | `baton cancel` / `ls` / `prune` | Stops a job, lists jobs, or deletes old ones. |
115
+ | `baton worktree add/ls/rm` | Gives a job its own git worktree so it doesn't touch your checkout. |
116
+ | `baton mcp` | Runs the same operations as an MCP server for hosts that can't run shell commands. |
373
117
 
374
- ---
118
+ Every command prints exactly one JSON object, so the host agent can read it reliably. See the [full flag list and statuses](docs/reference.md#command-line).
375
119
 
376
- ## Task directory ~/.baton
377
-
378
- The root is `~/.baton` by default; set `BATON_HOME` to move it. Directories are `0700` and files `0600` (they contain prompts).
120
+ ## How it works
379
121
 
380
122
  ```
381
- ~/.baton/tasks/<task_id>/
382
- meta.json current state (atomic writes)
383
- events.jsonl uniform event stream
384
- turns/<n>.json turn n: author, input, final status, summary, git_changes
385
- raw/<n>.stdout.log raw worker output for turn n, not truncated
386
- raw/<n>.stderr.log
123
+ Host agent ──shell──> baton start ──spawns a detached supervisor──> worker CLI (codex / claude / ...)
124
+ │ │ returns task_id at once │ streamed output → uniform events
125
+ │ ▼ │
126
+ │ ~/.baton/tasks/<id>/ <──────── single writer ───────┘
127
+ │ ▲
128
+ └──shell/MCP──> baton wait / status / tail / reply / cancel
387
129
  ```
388
130
 
389
- Task directories are never deleted automatically; use `baton prune --older <days>`.
131
+ - **Jobs outlive the host.** Each job runs under its own supervisor, so closing the session or the terminal, or restarting MCP, doesn't stop it. You can still read the result afterwards.
132
+ - **No total time limit.** A job is stopped only after 10 minutes with no output at all, so slow models can think for hours.
133
+ - **One event format.** Messages, tool calls, and errors from every CLI are converted to the same events, and `status` tells you whether the worker is working, quietly thinking, or dead.
134
+ - **Questions don't strand the job.** When the worker needs a decision, the job pauses at `needs_input`. `baton reply` resumes the same session and records who answered.
135
+ - **Guardrails, not a sandbox.** `--mode readonly` uses each CLI's own read-only mode and flags the job if files change anyway. `--scope` checks git changes against path patterns after each turn. Workers can't call Baton again, and credentials are redacted from the event log.
390
136
 
391
- ---
137
+ ## FAQ
392
138
 
393
- ## Underlying Calling Conventions
139
+ **Do I need API keys?**
140
+ No. Baton runs the CLIs you already have, with their existing logins.
394
141
 
395
- | Agent | First call | Resume | Notes |
396
- | :--- | :--- | :--- | :--- |
397
- | **Codex** | `codex exec --json --color never --approve-for-me --skip-git-repo-check --cd <cwd> -` | `codex exec resume --json <thread_id> -` | write uses `--approve-for-me` (conflicts with `--sandbox`); readonly first turn uses `--sandbox read-only`; `exec resume` has no sandbox flag and rejects `--cd` / `--color` |
398
- | **Claude Code** | `claude -p --output-format stream-json --verbose --permission-mode acceptEdits --permission-prompts none` | add `--resume <session_id>` | readonly → `--permission-mode plan`; `stream-json` with `-p` requires `--verbose`; hook events stay out of the event stream |
399
- | **Cursor** | `cursor-agent --print --force --trust --output-format stream-json --workspace <cwd>` | add `--resume <session_id>` | readonly → `--mode ask` (drops `--force`, keeps `--trust`); prefers `cursor-agent`, then `agent`; never the IDE's `cursor` |
400
- | **Antigravity (agy)** | `agy --print <prompt> --mode accept-edits --output-format stream-json` | add `--conversation <id>` | readonly → `--mode plan`; replies stream as deltas; the full text comes from the final `result` |
142
+ **What happens if I close my host session mid-job?**
143
+ The job keeps running. Open a new session and run `baton ls` or `baton status <id>`.
401
144
 
402
- Any output line a parser does not recognize is kept as a `raw` event, never dropped. Real output samples for each CLI live in `test/fixtures/`.
145
+ **Is `--scope` a security boundary?**
146
+ No. It catches mistakes in files git can see. For real isolation, put the job in a `baton worktree`.
403
147
 
404
- ---
405
-
406
- ## Safety
148
+ **Will the worker follow my project rules / environment?**
149
+ `baton status` reports `rules.unseen` (rule files the target does not load natively) and, if you use [rulesync](https://github.com/dyoshikawa/rulesync), whether generated configs are in sync. Pass `--rules pointer` to tell the worker to read unread rule files first. Prefer a shared `AGENTS.md` (and rulesync for MCP/skills/hooks across CLIs).
407
150
 
408
- 1. **No recursion (`BATON_DELEGATION=1`)**: set in the worker's environment; a downstream call into baton is refused.
409
- 2. **Process groups**: each worker runs in its own process group; timeouts and `cancel` kill the whole group, grandchildren included.
410
- 3. **Credential redaction**: text written to events and summaries is redacted before truncation; full raw logs stay under `raw/`, protected by `0600`.
411
- 4. **Id validation**: every task id is checked to be a UUID before it is used in a path.
412
- 5. **`--scope` is not a security boundary**: it only post-checks git-visible net changes. `.gitignore`d files, writes outside the repo, concurrent shared-cwd edits, and orphaned supervisors (check skipped) are known blind spots.
413
-
414
- ---
151
+ **Can Gemini CLI be a worker?**
152
+ Not yet. Gemini CLI works as a host.
415
153
 
416
- ## Manual Smoke Testing
154
+ **Where is the state?**
155
+ In `~/.baton/tasks/<id>/` (change it with `BATON_HOME`): `meta.json`, `events.jsonl`, one file per turn, and the raw logs. Nothing is deleted automatically.
417
156
 
418
- Use a separate throwaway Git repository:
419
-
420
- 1. `baton agents`; confirm the target shows `installed: true`.
421
- 2. Start a task that stops to ask:
422
- ```bash
423
- baton start --target codex --effort low --prompt "Do not edit files. Stop and ask me: A or B, using the BATON_DECISION format, options: A | B."
424
- ```
425
- 3. In another terminal, `baton tail -f <id>` shows events live.
426
- 4. Repeat `baton wait <id> --for 50` until it returns `needs_input` with A/B in `decision`.
427
- 5. `baton reply <id> --as human --prompt "A. Reply with the letter, then finish with BATON_RESULT."`, wait until `success`, and check that `session_id` matches turn 1.
428
-
429
- ---
430
-
431
- ## Development & Testing
157
+ ## Development
432
158
 
433
159
  ```bash
434
- npm test # tsc --noEmit + node --test, no real model quota used
435
- npm run typecheck
160
+ npm install
161
+ npm test # typecheck + node --test, using fake CLIs; no model quota spent
436
162
  ```
437
163
 
438
- Integration tests use fake CLIs in `test/fake-cli/` and a temporary `BATON_HOME`. They cover: a task finishing after its parent is killed, idle and total timeouts, cancel killing the whole group, orphan detection after the supervisor dies, needs_input → reply on the same session, bounded wait, tail, ls/prune, and reading tasks after an MCP restart. Adapter tests use real output samples from each CLI.
439
-
440
- ---
441
-
442
- ## Upgrading from 0.3.x
443
-
444
- - Install and update with `npx @speculoai/baton install` and `npx @speculoai/baton@latest update`. The marketplace id is `baton@speculoai`.
445
- - MCP runs `baton` with args `["mcp"]`. `/baton:setup` installs the global package instead of running npm inside the plugin directory.
446
- - Node requirement is >= 20.17. The published package is built with `tsc`; a marketplace install no longer needs the TypeScript source.
164
+ Changes land through pull requests only; see [CONTRIBUTING](.github/CONTRIBUTING.md) for the branch, PR, CI, and release workflow. Design notes are in [docs/architecture.md](docs/architecture.md) and [docs/hosts.md](docs/hosts.md). Upgrading from 0.3.x or earlier? See [the upgrade notes](docs/reference.md#upgrading-from-03x).
447
165
 
448
- ## Upgrading from 0.2.x
166
+ ## License
449
167
 
450
- - **Node 20.17 or newer.** The source is TypeScript. Published installs use the `baton` command.
451
- - Hand-written MCP config uses `command: "baton"` and `args: ["mcp"]`.
452
- - The CLI drops `delegate` in favor of `start` + `wait` + `reply`; `wait` takes ids as positional arguments.
453
- - MCP drops `delegate_task(session_id)` continuation and `task_wait_any`: continue with `task_reply`, wait on several jobs with `task_wait(task_ids)`.
454
- - `needs_decision` is now `needs_input`. `timeout_seconds` (capped at 1800) is replaced by `idle_timeout_seconds` + `max_duration_seconds`, with no total cap by default.
455
- - Task state moved from the system temp directory to `~/.baton`.
456
- - **gemini is not a delegation target for now** (it could not be verified because of a local auth problem). Installing baton as an extension inside Gemini CLI as the host still works.
168
+ [MIT](LICENSE)
457
169
 
458
170
  ---
459
171
 
460
- Formerly named **Agent-Plugin-Agent (APA)**. Older install strings are no longer valid; use `baton@speculoai`.
172
+ <sub>Formerly **Agent-Plugin-Agent (APA)**. Old install strings no longer work; use `baton@speculoai`.</sub>