@speculoai/baton 0.6.2 → 0.8.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/README.md +3 -1
- package/README.zh-CN.md +3 -1
- package/dist/adapters/agy.js +3 -2
- package/dist/adapters/claude.js +7 -3
- package/dist/adapters/common.js +23 -11
- package/dist/adapters/cursor.js +2 -2
- package/dist/cli.js +58 -34
- package/dist/install.js +2 -2
- package/dist/mcp.js +13 -3
- package/dist/process.js +18 -0
- package/dist/report.js +191 -0
- package/dist/rules.js +4 -8
- package/dist/rulesync-setup.js +3 -3
- package/dist/scope.js +12 -3
- package/dist/store.js +20 -1
- package/dist/supervisor.js +81 -3
- package/dist/tail.js +2 -0
- package/dist/tasks.js +86 -17
- package/dist/usage.js +182 -0
- package/dist/worktree.js +132 -11
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ The host starts the job, checks on it in short steps, passes Codex's "A or B?" t
|
|
|
62
62
|
npx @speculoai/baton install
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
It finds the agent CLIs on your machine, asks which ones should get the plugin, and installs the global `baton` command. It then offers to set up [rulesync](https://github.com/dyoshikawa/rulesync) for the current project (optional; rerun any time with `baton rules init`).
|
|
65
|
+
It finds the agent CLIs on your machine, asks which ones should get the plugin, and installs the global `baton` command. It then offers to set up [rulesync](https://github.com/dyoshikawa/rulesync) for the current project (optional; rerun any time with `baton rules init`). Supports macOS, Linux, and native Windows 10/11 (PowerShell or cmd); requires Node ≥ 20.17 and at least one supported agent CLI that is already logged in. See [Windows notes](docs/reference.md#windows-notes) for platform differences.
|
|
66
66
|
|
|
67
67
|
Check which workers Baton can see:
|
|
68
68
|
|
|
@@ -110,11 +110,13 @@ If no target is named, the task goes to `codex`, or to `claude` when you are alr
|
|
|
110
110
|
| `baton start` | Starts a job. Options include `--effort`, `--mode readonly`, `--scope <glob>`, `--rules check\|pointer\|off`, and `--cwd <worktree>`. |
|
|
111
111
|
| `baton wait` / `status` | Waits for the job to stop, or takes one look at it. |
|
|
112
112
|
| `baton result` | Prints the worker's full final answer, without the transcript. |
|
|
113
|
+
| `baton diff` / `apply` | Shows what an `--isolate` job changed, then brings it back as one local commit on your current branch (never pushes). |
|
|
113
114
|
| `baton tail [-f]` | Shows the live event stream as readable text. |
|
|
114
115
|
| `baton reply` | Continues the same conversation when the worker asks a question or you want a follow-up. |
|
|
115
116
|
| `baton cancel` / `ls` / `prune` | Stops a job, lists jobs, or deletes old ones. |
|
|
116
117
|
| `baton worktree add/ls/rm` | Gives a job its own git worktree so it doesn't touch your checkout. |
|
|
117
118
|
| `baton rules init` | Installs and initializes rulesync for the current project, previewing changes before writing. |
|
|
119
|
+
| `baton report [id]` | Prints a redacted diagnostic report and prefilled GitHub issue link (`--submit` uses `gh` or opens a browser). |
|
|
118
120
|
| `baton mcp` | Runs the same operations as an MCP server for hosts that can't run shell commands. |
|
|
119
121
|
|
|
120
122
|
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).
|
package/README.zh-CN.md
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
npx @speculoai/baton install
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
它会找出本机装了哪些 Agent CLI,问你要给哪些装插件,并安装全局 `baton` 命令。之后会推荐为当前项目配置 [rulesync](https://github.com/dyoshikawa/rulesync)(可选,以后可随时用 `baton rules init`
|
|
65
|
+
它会找出本机装了哪些 Agent CLI,问你要给哪些装插件,并安装全局 `baton` 命令。之后会推荐为当前项目配置 [rulesync](https://github.com/dyoshikawa/rulesync)(可选,以后可随时用 `baton rules init` 重跑)。支持 macOS、Linux 与原生 Windows 10/11(PowerShell 或 cmd);需要 Node ≥ 20.17,以及至少一个已登录的受支持 Agent CLI。Windows 差异与限制见[Windows 平台说明](docs/reference.zh-CN.md#windows-平台说明)。
|
|
66
66
|
|
|
67
67
|
看看 Baton 能找到哪些执行者:
|
|
68
68
|
|
|
@@ -110,11 +110,13 @@ baton tail -f <task_id>
|
|
|
110
110
|
| `baton start` | 启动任务。可选参数包括 `--effort`、`--mode readonly`、`--scope <glob>`、`--rules check\|pointer\|off`、`--cwd <worktree>`。 |
|
|
111
111
|
| `baton wait` / `status` | 等任务停下,或者看一眼当前状态。 |
|
|
112
112
|
| `baton result` | 只打印 worker 的完整最终回答,不含过程记录。 |
|
|
113
|
+
| `baton diff` / `apply` | 查看 `--isolate` 任务改了什么,再把改动作为一个本地 commit 收回到当前分支(不 push)。 |
|
|
113
114
|
| `baton tail [-f]` | 以可读文本显示实时事件流。 |
|
|
114
115
|
| `baton reply` | 执行者提问、或者你想追加要求时,在同一个会话里接着说。 |
|
|
115
116
|
| `baton cancel` / `ls` / `prune` | 停止任务、列出任务、清理旧任务。 |
|
|
116
117
|
| `baton worktree add/ls/rm` | 给任务单独开一个 git worktree,不碰你的工作目录。 |
|
|
117
118
|
| `baton rules init` | 为当前项目安装并初始化 rulesync,写入前先预览改动。 |
|
|
119
|
+
| `baton report [id]` | 生成脱敏诊断报告和预填 GitHub issue 链接(`--submit` 有 `gh` 直接提,否则在浏览器打开)。 |
|
|
118
120
|
| `baton mcp` | 以 MCP 服务器的形式提供同样的操作,给不能跑 shell 的宿主用。 |
|
|
119
121
|
|
|
120
122
|
每个命令都只输出一个 JSON 对象,主控 Agent 读起来不会出错。全部参数和状态见[完整手册](docs/reference.zh-CN.md#命令行)。
|
package/dist/adapters/agy.js
CHANGED
|
@@ -24,12 +24,13 @@ export const agy = {
|
|
|
24
24
|
return which(["agy"], env);
|
|
25
25
|
},
|
|
26
26
|
build({ bin, prompt, sessionId, reasoningEffort, mode }) {
|
|
27
|
-
|
|
27
|
+
// Verified 2026-11-25: agy has no plain-text stdin. `--print=` (empty) plus stream-json input reads one {"event":"user","message":{"content":…}} line per turn from stdin.
|
|
28
|
+
const args = ["--print=", "--mode", mode === "readonly" ? "plan" : "accept-edits", "--input-format", "stream-json", "--output-format", "stream-json"];
|
|
28
29
|
if (reasoningEffort)
|
|
29
30
|
args.push("--effort", reasoningEffort === "ultra" ? "max" : reasoningEffort);
|
|
30
31
|
if (sessionId)
|
|
31
32
|
args.push("--conversation", sessionId);
|
|
32
|
-
return { command: bin, args, stdin:
|
|
33
|
+
return { command: bin, args, stdin: `${JSON.stringify({ event: "user", message: { content: prompt } })}\n` };
|
|
33
34
|
},
|
|
34
35
|
sessionIdFrom(line) {
|
|
35
36
|
const obj = parse(line);
|
package/dist/adapters/claude.js
CHANGED
|
@@ -32,16 +32,20 @@ export const claude = {
|
|
|
32
32
|
resolve(env) {
|
|
33
33
|
return which(["claude"], env);
|
|
34
34
|
},
|
|
35
|
-
build({ bin, prompt, sessionId, reasoningEffort, mode }) {
|
|
35
|
+
build({ bin, prompt, sessionId, reasoningEffort, model, mode }) {
|
|
36
36
|
// stream-json requires --verbose with -p.
|
|
37
37
|
const permission = mode === "readonly" ? "plan" : "acceptEdits";
|
|
38
38
|
const args = ["-p", "--output-format", "stream-json", "--verbose", "--permission-mode", permission, "--permission-prompts", "none"];
|
|
39
39
|
if (reasoningEffort)
|
|
40
40
|
args.push("--effort", reasoningEffort === "ultra" ? "max" : reasoningEffort);
|
|
41
|
+
// Verified 2026-11-24 (Claude Code 2.1.332): --resume without --model falls back to the default model, so pass it every turn.
|
|
42
|
+
const modelArg = model?.trim() || undefined;
|
|
43
|
+
if (modelArg)
|
|
44
|
+
args.push("--model", modelArg);
|
|
41
45
|
if (sessionId)
|
|
42
46
|
args.push("--resume", sessionId);
|
|
43
|
-
|
|
44
|
-
return { command: bin, args, stdin:
|
|
47
|
+
// The prompt goes through stdin: argv would pass through cmd.exe for a .cmd shim on Windows, which cuts it at the first newline.
|
|
48
|
+
return { command: bin, args, stdin: prompt, modelArg };
|
|
45
49
|
},
|
|
46
50
|
sessionIdFrom(line) {
|
|
47
51
|
const obj = parse(line);
|
package/dist/adapters/common.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
// Windows variable names are case-insensitive ("Path"), but a copied env object is not.
|
|
4
|
+
const envValue = (env, key) => process.platform === "win32" ? env[key] ?? env[Object.keys(env).find((name) => name.toUpperCase() === key) ?? key] : env[key];
|
|
5
|
+
// Windows: only the extensions cross-spawn can run. The extensionless npm shim next to a .cmd is a sh script and must not match.
|
|
6
|
+
function fileNames(name, env) {
|
|
7
|
+
if (process.platform !== "win32")
|
|
8
|
+
return [name];
|
|
9
|
+
const runnable = [".com", ".exe", ".bat", ".cmd"];
|
|
10
|
+
const exts = (envValue(env, "PATHEXT") || ".COM;.EXE;.BAT;.CMD").split(";").map((ext) => ext.toLowerCase());
|
|
11
|
+
return exts.filter((ext) => runnable.includes(ext)).map((ext) => name + ext);
|
|
12
|
+
}
|
|
3
13
|
export function which(names, env = process.env) {
|
|
4
|
-
const dirs = (env
|
|
14
|
+
const dirs = (envValue(env, "PATH") || "").split(path.delimiter).filter(Boolean);
|
|
5
15
|
for (const name of names) {
|
|
6
16
|
for (const dir of dirs) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
for (const file of fileNames(name, env)) {
|
|
18
|
+
const full = path.join(dir, file);
|
|
19
|
+
try {
|
|
20
|
+
const stat = fs.statSync(full);
|
|
21
|
+
if (!stat.isFile())
|
|
22
|
+
continue;
|
|
23
|
+
fs.accessSync(full, fs.constants.X_OK);
|
|
24
|
+
return full;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Try the next PATH entry.
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
}
|
|
19
31
|
}
|
package/dist/adapters/cursor.js
CHANGED
|
@@ -50,8 +50,8 @@ export const cursor = {
|
|
|
50
50
|
args.push("--model", modelArg);
|
|
51
51
|
if (sessionId)
|
|
52
52
|
args.push("--resume", sessionId);
|
|
53
|
-
|
|
54
|
-
return { command: bin, args, stdin:
|
|
53
|
+
// Prompt on stdin, not argv (see claude.ts).
|
|
54
|
+
return { command: bin, args, stdin: prompt, modelArg: modelArg ?? undefined };
|
|
55
55
|
},
|
|
56
56
|
sessionIdFrom(line) {
|
|
57
57
|
const obj = parse(line);
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { agents, start, status, cancel, wait, reply, ls, prune, result as turnResult } from "./tasks.js";
|
|
4
|
+
import { agents, start, status, cancel, wait, reply, ls, prune, diff, apply, result as turnResult } from "./tasks.js";
|
|
5
5
|
import { addWorktree, listWorktrees, removeWorktree } from "./worktree.js";
|
|
6
6
|
import { redact } from "./redact.js";
|
|
7
7
|
import { detectedHosts, runInstall } from "./install.js";
|
|
8
8
|
import { mappedAgents, rulesInit } from "./rulesync-setup.js";
|
|
9
|
+
import { COMMANDS, commandList, isCommand, renderHelp, wantsHelp } from "./usage.js";
|
|
9
10
|
function installChoice(value, flag) {
|
|
10
11
|
if (value === undefined)
|
|
11
12
|
return undefined;
|
|
@@ -16,6 +17,21 @@ function installChoice(value, flag) {
|
|
|
16
17
|
async function main() {
|
|
17
18
|
const [command, ...args] = process.argv.slice(2);
|
|
18
19
|
let result;
|
|
20
|
+
if (command === undefined || command === "help" || command === "-h" || command === "--help") {
|
|
21
|
+
const name = command === "help" ? args[0] : undefined;
|
|
22
|
+
if (name === undefined)
|
|
23
|
+
process.stdout.write(renderHelp());
|
|
24
|
+
else if (isCommand(name))
|
|
25
|
+
process.stdout.write(renderHelp(name));
|
|
26
|
+
else
|
|
27
|
+
throw new Error(commandList);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Before parsing, so `start --help` neither trips strict parsing nor waits on stdin.
|
|
31
|
+
if (isCommand(command) && wantsHelp(args)) {
|
|
32
|
+
process.stdout.write(renderHelp(command));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
19
35
|
if (command === "_supervise") {
|
|
20
36
|
if (args.length !== 1)
|
|
21
37
|
throw new Error("task_id is missing.");
|
|
@@ -26,6 +42,20 @@ async function main() {
|
|
|
26
42
|
await (await import("./mcp.js")).startMcp();
|
|
27
43
|
return;
|
|
28
44
|
}
|
|
45
|
+
if (command === "report") {
|
|
46
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.report.options });
|
|
47
|
+
if (positionals.length > 1)
|
|
48
|
+
throw new Error("report takes at most one task_id.");
|
|
49
|
+
const { buildReport, submitReport } = await import("./report.js");
|
|
50
|
+
const report = buildReport(positionals[0], { title: values.title });
|
|
51
|
+
if (values.submit) {
|
|
52
|
+
result = submitReport(report);
|
|
53
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
process.stdout.write(`${report.markdown}\n\nOpen issue: ${report.issueUrl}\n`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
29
59
|
if (command === "version" || command === "--version") {
|
|
30
60
|
result = { version: JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version };
|
|
31
61
|
}
|
|
@@ -33,15 +63,7 @@ async function main() {
|
|
|
33
63
|
result = { agents: agents() };
|
|
34
64
|
}
|
|
35
65
|
else if (command === "start") {
|
|
36
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
37
|
-
target: { type: "string" }, prompt: { type: "string" }, cwd: { type: "string" },
|
|
38
|
-
file: { type: "string", multiple: true }, effort: { type: "string" }, model: { type: "string" },
|
|
39
|
-
"idle-timeout": { type: "string" }, "max-duration": { type: "string" },
|
|
40
|
-
scope: { type: "string", multiple: true }, "scope-on-violation": { type: "string" },
|
|
41
|
-
mode: { type: "string" }, "allow-weak": { type: "boolean" },
|
|
42
|
-
isolate: { type: "boolean" }, "allow-dirty": { type: "boolean" },
|
|
43
|
-
rules: { type: "string" },
|
|
44
|
-
} });
|
|
66
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.start.options });
|
|
45
67
|
if (positionals.length)
|
|
46
68
|
throw new Error("start takes no positional arguments.");
|
|
47
69
|
result = await start({ target: values.target || "", prompt: values.prompt ?? fs.readFileSync(0, "utf8"), cwd: values.cwd, files: values.file,
|
|
@@ -51,7 +73,7 @@ async function main() {
|
|
|
51
73
|
mode: values.mode, allowWeak: values["allow-weak"],
|
|
52
74
|
isolate: values.isolate, allowDirty: values["allow-dirty"],
|
|
53
75
|
rules: values.rules,
|
|
54
|
-
|
|
76
|
+
check: values.check, });
|
|
55
77
|
if (result.status !== "running")
|
|
56
78
|
process.exitCode = 1;
|
|
57
79
|
}
|
|
@@ -61,7 +83,7 @@ async function main() {
|
|
|
61
83
|
result = status(args[0]);
|
|
62
84
|
}
|
|
63
85
|
else if (command === "reply") {
|
|
64
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
86
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.reply.options });
|
|
65
87
|
if (positionals.length !== 1)
|
|
66
88
|
throw new Error("reply requires one task_id.");
|
|
67
89
|
result = await reply(positionals[0], values.prompt ?? fs.readFileSync(0, "utf8"), (values.as ?? "host"));
|
|
@@ -71,39 +93,53 @@ async function main() {
|
|
|
71
93
|
else if (command === "wait") {
|
|
72
94
|
const { values, positionals } = parseArgs({
|
|
73
95
|
args, allowPositionals: true,
|
|
74
|
-
options:
|
|
96
|
+
options: COMMANDS.wait.options,
|
|
75
97
|
});
|
|
76
98
|
if (values["until-done"] && values.for !== undefined)
|
|
77
99
|
throw new Error("--until-done and --for cannot be used together.");
|
|
78
100
|
result = await wait(positionals, values["until-done"] ? Infinity : values.for === undefined ? 50 : Number(values.for));
|
|
79
101
|
}
|
|
80
102
|
else if (command === "result") {
|
|
81
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
103
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.result.options });
|
|
82
104
|
if (positionals.length !== 1)
|
|
83
105
|
throw new Error("result requires one task_id.");
|
|
84
106
|
// Plain text, like tail: the point is to read the answer without JSON escaping or the full transcript.
|
|
85
107
|
process.stdout.write(`${turnResult(positionals[0], values.turn === undefined ? undefined : Number(values.turn)).final_message}\n`);
|
|
86
108
|
return;
|
|
87
109
|
}
|
|
110
|
+
else if (command === "diff") {
|
|
111
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.diff.options });
|
|
112
|
+
if (positionals.length !== 1)
|
|
113
|
+
throw new Error("diff requires one task_id.");
|
|
114
|
+
// Plain text, like result: a patch is read, not parsed.
|
|
115
|
+
process.stdout.write(diff(positionals[0], { stat: values.stat }));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
88
118
|
else if (command === "tail") {
|
|
89
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
119
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.tail.options });
|
|
90
120
|
if (positionals.length !== 1)
|
|
91
121
|
throw new Error("tail requires one task_id.");
|
|
92
122
|
await (await import("./tail.js")).tail(positionals[0], { follow: values.follow, raw: values.raw });
|
|
93
123
|
return;
|
|
94
124
|
}
|
|
95
125
|
else if (command === "ls") {
|
|
96
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
126
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.ls.options });
|
|
97
127
|
if (positionals.length)
|
|
98
128
|
throw new Error("ls takes no positional arguments.");
|
|
99
129
|
result = { tasks: ls(values.all) };
|
|
100
130
|
}
|
|
101
131
|
else if (command === "prune") {
|
|
102
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
132
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.prune.options });
|
|
103
133
|
if (positionals.length || values.older === undefined)
|
|
104
134
|
throw new Error("prune requires --older days.");
|
|
105
135
|
result = { deleted: prune(Number(values.older)) };
|
|
106
136
|
}
|
|
137
|
+
else if (command === "apply") {
|
|
138
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.apply.options });
|
|
139
|
+
if (positionals.length !== 1)
|
|
140
|
+
throw new Error("apply requires one task_id.");
|
|
141
|
+
result = apply(positionals[0], { remove: values.remove });
|
|
142
|
+
}
|
|
107
143
|
else if (command === "cancel") {
|
|
108
144
|
if (args.length !== 1)
|
|
109
145
|
throw new Error("cancel requires one task_id.");
|
|
@@ -115,7 +151,7 @@ async function main() {
|
|
|
115
151
|
const { values, positionals } = parseArgs({
|
|
116
152
|
args: rest,
|
|
117
153
|
allowPositionals: true,
|
|
118
|
-
options:
|
|
154
|
+
options: COMMANDS.worktree.options,
|
|
119
155
|
});
|
|
120
156
|
if (positionals.length)
|
|
121
157
|
throw new Error("worktree add takes no positional arguments.");
|
|
@@ -141,10 +177,7 @@ async function main() {
|
|
|
141
177
|
throw new Error("Usage: baton rules init");
|
|
142
178
|
const { values, positionals } = parseArgs({
|
|
143
179
|
args: rest, allowPositionals: true,
|
|
144
|
-
options:
|
|
145
|
-
install: { type: "string" }, source: { type: "string" }, template: { type: "boolean" },
|
|
146
|
-
targets: { type: "string", multiple: true }, yes: { type: "boolean" }, "dry-run": { type: "boolean" },
|
|
147
|
-
},
|
|
180
|
+
options: COMMANDS.rules.options,
|
|
148
181
|
});
|
|
149
182
|
if (positionals.length)
|
|
150
183
|
throw new Error("rules init takes no positional arguments.");
|
|
@@ -177,20 +210,11 @@ async function main() {
|
|
|
177
210
|
else if (command === "install" || command === "update" || command === "uninstall") {
|
|
178
211
|
const { values, positionals } = parseArgs({
|
|
179
212
|
args, allowPositionals: true,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
"dry-run": { type: "boolean" }, "skip-global": { type: "boolean" },
|
|
183
|
-
rulesync: { type: "string" },
|
|
184
|
-
},
|
|
213
|
+
// Each command parses with its own table (update/uninstall reject install-only flags); typed as install's superset.
|
|
214
|
+
options: COMMANDS[command].options,
|
|
185
215
|
});
|
|
186
216
|
if (positionals.length)
|
|
187
217
|
throw new Error(`${command} takes no positional arguments.`);
|
|
188
|
-
if (command !== "install" && values.force)
|
|
189
|
-
throw new Error(`${command} does not accept --force.`);
|
|
190
|
-
if (command === "uninstall" && values["skip-global"])
|
|
191
|
-
throw new Error("uninstall does not accept --skip-global.");
|
|
192
|
-
if (command !== "install" && values.rulesync !== undefined)
|
|
193
|
-
throw new Error(`${command} does not accept --rulesync.`);
|
|
194
218
|
const rulesyncChoice = installChoice(values.rulesync, "--rulesync");
|
|
195
219
|
const action = command;
|
|
196
220
|
const pretty = Boolean(process.stdin.isTTY);
|
|
@@ -297,7 +321,7 @@ async function main() {
|
|
|
297
321
|
return;
|
|
298
322
|
}
|
|
299
323
|
else
|
|
300
|
-
throw new Error(
|
|
324
|
+
throw new Error(commandList);
|
|
301
325
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
302
326
|
}
|
|
303
327
|
try {
|
package/dist/install.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import spawn from "cross-spawn";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { which } from "./adapters/common.js";
|
|
@@ -118,7 +118,7 @@ export function planInstall(input) {
|
|
|
118
118
|
return { hosts, missing };
|
|
119
119
|
const version = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
120
120
|
const spec = input.action === "update" ? "@speculoai/baton@latest" : `@speculoai/baton@${version}`;
|
|
121
|
-
return { hosts, missing, global: { command: [
|
|
121
|
+
return { hosts, missing, global: { command: ["npm", "install", "-g", spec] } };
|
|
122
122
|
}
|
|
123
123
|
export function readInstalled(home = batonHome()) {
|
|
124
124
|
try {
|
package/dist/mcp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { agents, cancel, ls, reply, result, start, status, wait } from "./tasks.js";
|
|
4
|
+
import { agents, apply, cancel, diff, ls, reply, result, start, status, wait } from "./tasks.js";
|
|
5
5
|
import { redact } from "./redact.js";
|
|
6
6
|
const MAX_WAIT_SECONDS = 55;
|
|
7
7
|
const PROGRESS_MS = 15_000;
|
|
@@ -26,7 +26,7 @@ export function createServer() {
|
|
|
26
26
|
prompt: z.string(),
|
|
27
27
|
files: z.array(z.string()).optional(),
|
|
28
28
|
reasoning_effort: z.enum(["low", "medium", "high", "ultra"]).optional(),
|
|
29
|
-
model: z.string().optional().describe("Per-task model (cursor and
|
|
29
|
+
model: z.string().optional().describe("Per-task model (cursor, codex and claude; stored in meta and carried over by reply)."),
|
|
30
30
|
idle_timeout_seconds: z.number().optional().describe("Stop after this long with no output at all; default 600."),
|
|
31
31
|
max_duration_seconds: z.number().optional().describe("Maximum total duration per turn; default unlimited."),
|
|
32
32
|
cwd: z.string().optional(),
|
|
@@ -37,6 +37,7 @@ export function createServer() {
|
|
|
37
37
|
isolate: z.boolean().optional().describe("Create a git worktree and run the write job there (default false)."),
|
|
38
38
|
allow_dirty: z.boolean().optional().describe("Allow in-place write on a dirty working tree (default false)."),
|
|
39
39
|
rules: z.enum(["check", "pointer", "off"]).optional().describe("Project rules discovery; default check. pointer injects unread rule paths into the first-turn prompt."),
|
|
40
|
+
check: z.string().optional().describe("Shell command Baton runs in the task cwd after each successful turn; a non-zero exit ends the turn as check_failed."),
|
|
40
41
|
},
|
|
41
42
|
}, (args) => respond(() => start({
|
|
42
43
|
target: args.target_agent, prompt: args.prompt, files: args.files, cwd: args.cwd,
|
|
@@ -46,6 +47,7 @@ export function createServer() {
|
|
|
46
47
|
mode: args.mode, allowWeak: args.allow_weak,
|
|
47
48
|
isolate: args.isolate, allowDirty: args.allow_dirty,
|
|
48
49
|
rules: args.rules,
|
|
50
|
+
check: args.check,
|
|
49
51
|
})));
|
|
50
52
|
server.registerTool("task_status", {
|
|
51
53
|
description: "Get a task's current status. While running, includes liveness (active/quiet/orphaned) and quiet_for_s.",
|
|
@@ -80,8 +82,16 @@ export function createServer() {
|
|
|
80
82
|
description: "Get the agent's full final message of a finished turn (default: the latest), without the tool-call transcript. task_status/task_wait only carry the one-line summary.",
|
|
81
83
|
inputSchema: { task_id: z.string(), turn: z.number().int().optional() },
|
|
82
84
|
}, (args) => respond(() => result(args.task_id, args.turn)));
|
|
85
|
+
server.registerTool("task_diff", {
|
|
86
|
+
description: "Net change of an --isolate task since its worktree was created (worker commits, edits and new files; Baton's own worktree files excluded). stat=true returns a diffstat instead of the patch.",
|
|
87
|
+
inputSchema: { task_id: z.string(), stat: z.boolean().optional() },
|
|
88
|
+
}, (args) => respond(() => ({ task_id: args.task_id, diff: diff(args.task_id, { stat: args.stat }) })));
|
|
89
|
+
server.registerTool("task_apply", {
|
|
90
|
+
description: "Bring an --isolate task's net change onto the source repo's current branch as one local commit (three-way cherry-pick; never pushes). Refuses, changing nothing, on staged changes, overlapping dirty or untracked files, an operation in progress, or a conflict. remove=true then deletes the worktree and branch. Only with the user's consent.",
|
|
91
|
+
inputSchema: { task_id: z.string(), remove: z.boolean().optional() },
|
|
92
|
+
}, (args) => respond(() => apply(args.task_id, { remove: args.remove })));
|
|
83
93
|
server.registerTool("task_reply", {
|
|
84
|
-
description: "After a task stops at needs_input, success, scope_violation or
|
|
94
|
+
description: "After a task stops at needs_input, success, scope_violation, readonly_violation or check_failed, start the next turn in the same session. as=human means a human said it; default host. Returns busy while running.",
|
|
85
95
|
inputSchema: { task_id: z.string(), prompt: z.string(), as: z.enum(["host", "human"]).optional() },
|
|
86
96
|
}, (args) => respond(() => reply(args.task_id, args.prompt, (args.as ?? "host"))));
|
|
87
97
|
server.registerTool("task_cancel", {
|
package/dist/process.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
// Absolute, because a sandboxed or trimmed PATH need not contain them.
|
|
4
|
+
const SYSTEM32 = path.join(process.env.SystemRoot ?? "C:\\Windows", "System32");
|
|
1
5
|
export function isAlive(pid) {
|
|
2
6
|
if (!pid || !Number.isSafeInteger(pid) || pid <= 1)
|
|
3
7
|
return false;
|
|
@@ -13,6 +17,20 @@ export function isAlive(pid) {
|
|
|
13
17
|
export function killGroup(pid) {
|
|
14
18
|
if (!pid || !Number.isSafeInteger(pid) || pid <= 1)
|
|
15
19
|
return;
|
|
20
|
+
if (process.platform === "win32") {
|
|
21
|
+
// shortcut: taskkill follows parent pids, so a grandchild whose parent already exited escapes; a Job Object would need a native addon.
|
|
22
|
+
const killed = spawnSync(path.join(SYSTEM32, "taskkill.exe"), ["/PID", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
23
|
+
// libuv ends a worker's direct child (a .cmd shim's cmd.exe) when the supervisor dies, but the shim's own children keep that dead pid
|
|
24
|
+
// as their parent, so taskkill finds nothing (or only a half-closed root). Kill whatever still names it as parent.
|
|
25
|
+
if (killed.status !== 0) {
|
|
26
|
+
const listed = spawnSync(path.join(SYSTEM32, "WindowsPowerShell", "v1.0", "powershell.exe"), ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter 'ParentProcessId=${pid}').ProcessId`], { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
27
|
+
for (const child of (listed.stdout ?? "").split(/\s+/).map(Number)) {
|
|
28
|
+
if (Number.isSafeInteger(child) && child > 1)
|
|
29
|
+
spawnSync(path.join(SYSTEM32, "taskkill.exe"), ["/PID", String(child), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
16
34
|
try {
|
|
17
35
|
process.kill(-pid, "SIGKILL");
|
|
18
36
|
}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import spawn from "cross-spawn";
|
|
5
|
+
import { redact } from "./redact.js";
|
|
6
|
+
import { readMeta, taskDir } from "./store.js";
|
|
7
|
+
import { agents } from "./tasks.js";
|
|
8
|
+
const REPO = "SpeculoAI/baton";
|
|
9
|
+
const ISSUE_NEW_URL = `https://github.com/${REPO}/issues/new`;
|
|
10
|
+
const MAX_URL_LEN = 3500;
|
|
11
|
+
const MAX_EVENTS = 30;
|
|
12
|
+
const MAX_TEXT = 200;
|
|
13
|
+
function replaceAllCase(text, needle, replacement) {
|
|
14
|
+
if (!needle)
|
|
15
|
+
return text;
|
|
16
|
+
if (process.platform !== "win32")
|
|
17
|
+
return text.split(needle).join(replacement);
|
|
18
|
+
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
19
|
+
return text.replace(new RegExp(escaped, "gi"), replacement);
|
|
20
|
+
}
|
|
21
|
+
/** Redact secrets and replace home/cwd paths so user-specific paths never leave the machine. */
|
|
22
|
+
export function sanitize(text, cwd) {
|
|
23
|
+
let out = redact(text);
|
|
24
|
+
const paths = [];
|
|
25
|
+
if (cwd) {
|
|
26
|
+
paths.push([cwd, "<cwd>"]);
|
|
27
|
+
try {
|
|
28
|
+
const real = fs.realpathSync.native(cwd);
|
|
29
|
+
if (real !== cwd)
|
|
30
|
+
paths.push([real, "<cwd>"]);
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
}
|
|
34
|
+
const home = os.homedir();
|
|
35
|
+
if (home)
|
|
36
|
+
paths.push([home, "~"]);
|
|
37
|
+
// Longest first so a cwd under home becomes <cwd>, not ~/...
|
|
38
|
+
paths.sort((a, b) => b[0].length - a[0].length);
|
|
39
|
+
for (const [needle, repl] of paths)
|
|
40
|
+
out = replaceAllCase(out, needle, repl);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function clip(text, limit = MAX_TEXT) {
|
|
44
|
+
const single = text.replace(/\s+/g, " ").trim();
|
|
45
|
+
return single.length > limit ? `${single.slice(0, limit)}...` : single;
|
|
46
|
+
}
|
|
47
|
+
function readVersion() {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version ?? "unknown";
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return "unknown";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Keep only baton-generated diagnostic summaries; drop agent-authored business summaries from success/needs_input. */
|
|
56
|
+
function safeSummary(meta) {
|
|
57
|
+
if (!meta.summary || meta.status === "success" || meta.status === "needs_input")
|
|
58
|
+
return undefined;
|
|
59
|
+
const firstLine = meta.summary.split(/\r?\n/, 1)[0] ?? "";
|
|
60
|
+
return clip(sanitize(firstLine, meta.cwd));
|
|
61
|
+
}
|
|
62
|
+
function readEventSkeleton(id, cwd) {
|
|
63
|
+
let raw;
|
|
64
|
+
try {
|
|
65
|
+
raw = fs.readFileSync(path.join(taskDir(id), "events.jsonl"), "utf8");
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error.code === "ENOENT")
|
|
69
|
+
return [];
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
const lines = [];
|
|
73
|
+
for (const line of raw.split("\n")) {
|
|
74
|
+
if (!line.trim())
|
|
75
|
+
continue;
|
|
76
|
+
let ev;
|
|
77
|
+
try {
|
|
78
|
+
ev = JSON.parse(line);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const parts = [ev.ts, `t${ev.turn}`, ev.type];
|
|
84
|
+
if (ev.type === "turn_ended") {
|
|
85
|
+
parts.push(`status=${ev.status}`, `exit=${ev.exit_code ?? "null"}`);
|
|
86
|
+
}
|
|
87
|
+
else if (ev.type === "check_ended") {
|
|
88
|
+
parts.push(`status=${ev.status}`, `exit=${ev.exit_code ?? "null"}`);
|
|
89
|
+
}
|
|
90
|
+
else if (ev.type === "error") {
|
|
91
|
+
parts.push(clip(sanitize(ev.text, cwd)));
|
|
92
|
+
}
|
|
93
|
+
lines.push(parts.join(" "));
|
|
94
|
+
}
|
|
95
|
+
return lines.slice(-MAX_EVENTS);
|
|
96
|
+
}
|
|
97
|
+
function makeIssueUrl(title, body, shortBody) {
|
|
98
|
+
const full = `${ISSUE_NEW_URL}?${new URLSearchParams({ title, body }).toString()}`;
|
|
99
|
+
if (full.length <= MAX_URL_LEN)
|
|
100
|
+
return full;
|
|
101
|
+
return `${ISSUE_NEW_URL}?${new URLSearchParams({ title, body: shortBody }).toString()}`;
|
|
102
|
+
}
|
|
103
|
+
export function buildReport(taskId, opts = {}) {
|
|
104
|
+
const meta = taskId ? readMeta(taskId) : null;
|
|
105
|
+
if (taskId && !meta)
|
|
106
|
+
throw new Error("No such task.");
|
|
107
|
+
const detected = agents().map((a) => `- ${a.id}: ${a.installed ? (a.version ? clip(sanitize(a.version), 80) : "installed") : "not installed"}`);
|
|
108
|
+
const envSection = [
|
|
109
|
+
"### Environment",
|
|
110
|
+
`- baton: ${readVersion()}`,
|
|
111
|
+
`- node: ${process.version}`,
|
|
112
|
+
`- os: ${process.platform} ${process.arch} (${os.release()})`,
|
|
113
|
+
"- agents:",
|
|
114
|
+
...detected.map((line) => ` ${line}`),
|
|
115
|
+
];
|
|
116
|
+
const taskSection = [];
|
|
117
|
+
if (meta) {
|
|
118
|
+
const fields = [
|
|
119
|
+
["target", meta.target],
|
|
120
|
+
["status", meta.status],
|
|
121
|
+
["turn", meta.turn],
|
|
122
|
+
["mode", meta.mode],
|
|
123
|
+
["enforcement", meta.enforcement],
|
|
124
|
+
["isolated", Boolean(meta.worktree)],
|
|
125
|
+
["stop_reason", meta.stop_reason],
|
|
126
|
+
["idle_timeout_s", meta.idle_timeout_s],
|
|
127
|
+
["max_duration_s", meta.max_duration_s ?? undefined],
|
|
128
|
+
["scope_on_violation", meta.scope_on_violation],
|
|
129
|
+
["rules_mode", meta.rules?.mode],
|
|
130
|
+
["rulesync_status", meta.rules?.rulesync?.status],
|
|
131
|
+
["check", meta.check ? `${meta.check.status} (exit=${meta.check.exit_code ?? "null"}, ${meta.check.duration_ms}ms)` : undefined],
|
|
132
|
+
["summary", safeSummary(meta)],
|
|
133
|
+
];
|
|
134
|
+
taskSection.push("", "### Task (redacted)", ...fields.filter(([, value]) => value !== undefined).map(([key, value]) => `- ${key}: ${value}`));
|
|
135
|
+
const timeline = readEventSkeleton(meta.task_id, meta.cwd);
|
|
136
|
+
if (timeline.length) {
|
|
137
|
+
taskSection.push("", "### Event timeline", "```text", ...timeline, "```");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const header = [
|
|
141
|
+
"> Review before posting: remove any project-specific terms if present.",
|
|
142
|
+
"",
|
|
143
|
+
"### What happened",
|
|
144
|
+
"<!-- Describe what you expected vs. what happened -->",
|
|
145
|
+
"",
|
|
146
|
+
];
|
|
147
|
+
const markdown = [...header, ...envSection, ...taskSection].join("\n");
|
|
148
|
+
const title = opts.title?.trim() || (meta ? `bug(${meta.target}): ${meta.status}` : "bug: <describe issue>");
|
|
149
|
+
const shortBody = [
|
|
150
|
+
...header,
|
|
151
|
+
...envSection,
|
|
152
|
+
"",
|
|
153
|
+
"<!-- Full task timeline omitted for URL length; paste the output of `baton report` here -->",
|
|
154
|
+
].join("\n");
|
|
155
|
+
const issueUrl = makeIssueUrl(title, markdown, shortBody);
|
|
156
|
+
return { title, markdown, issueUrl };
|
|
157
|
+
}
|
|
158
|
+
function defaultOpenBrowser(url) {
|
|
159
|
+
try {
|
|
160
|
+
// Windows: rundll32 avoids cmd.exe, which would split the URL on `&`.
|
|
161
|
+
const [cmd, args] = process.platform === "darwin"
|
|
162
|
+
? ["open", [url]]
|
|
163
|
+
: process.platform === "win32"
|
|
164
|
+
? ["rundll32", ["url.dll,FileProtocolHandler", url]]
|
|
165
|
+
: ["xdg-open", [url]];
|
|
166
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
167
|
+
child.unref();
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export function submitReport(report, deps = {}) {
|
|
175
|
+
const runSync = deps.spawnSync ?? spawn.sync;
|
|
176
|
+
const openBrowser = deps.openBrowser ?? defaultOpenBrowser;
|
|
177
|
+
const auth = runSync("gh", ["auth", "status"], { stdio: "ignore", windowsHide: true });
|
|
178
|
+
if (auth.status === 0) {
|
|
179
|
+
const created = runSync("gh", ["issue", "create", "-R", REPO, "--title", report.title, "--body-file", "-"], {
|
|
180
|
+
input: report.markdown,
|
|
181
|
+
encoding: "utf8",
|
|
182
|
+
windowsHide: true,
|
|
183
|
+
});
|
|
184
|
+
const url = (created.stdout ?? "").trim();
|
|
185
|
+
if (created.status === 0 && url)
|
|
186
|
+
return { method: "gh", url, submitted: true };
|
|
187
|
+
}
|
|
188
|
+
if (openBrowser(report.issueUrl))
|
|
189
|
+
return { method: "browser", url: report.issueUrl, submitted: false };
|
|
190
|
+
return { method: "url", url: report.issueUrl, submitted: false };
|
|
191
|
+
}
|