@speculoai/baton 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/README.zh-CN.md +4 -3
- package/dist/adapters/agy.js +3 -2
- package/dist/adapters/claude.js +2 -2
- package/dist/adapters/common.js +39 -11
- package/dist/adapters/cursor.js +2 -2
- package/dist/adapters/index.js +2 -1
- package/dist/adapters/kimi.js +84 -0
- package/dist/cli.js +65 -38
- package/dist/install-ui.js +3 -0
- package/dist/install.js +87 -28
- package/dist/mcp.js +4 -3
- package/dist/process.js +18 -0
- package/dist/report.js +194 -0
- package/dist/rules.js +8 -10
- package/dist/rulesync-setup.js +3 -3
- package/dist/scope.js +12 -3
- package/dist/store.js +20 -1
- package/dist/supervisor.js +14 -4
- package/dist/tasks.js +35 -18
- package/dist/usage.js +212 -0
- package/dist/worktree.js +71 -27
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ You're working in Claude Code. Codex is installed on the same laptop, logged in,
|
|
|
27
27
|
|
|
28
28
|
**Any agent as host, any agent as worker.** No API keys, no server, no cloud. Every agent uses its own login and subscription.
|
|
29
29
|
|
|
30
|
-
Workers: `codex` (Codex CLI) · `claude` (Claude Code) · `cursor` (Cursor Agent CLI) · `agy` (Antigravity).
|
|
30
|
+
Workers: `codex` (Codex CLI) · `claude` (Claude Code) · `cursor` (Cursor Agent CLI) · `agy` (Antigravity) · `kimi` (Kimi Code CLI).
|
|
31
31
|
|
|
32
32
|
## Before / After
|
|
33
33
|
|
|
@@ -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
|
|
|
@@ -70,7 +70,7 @@ Check which workers Baton can see:
|
|
|
70
70
|
baton agents
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
`npm i -g @speculoai/baton` upgrades the CLI only. Use `baton update` or `npx @speculoai/baton@latest update` to update both the CLI and the recorded host plugins. Restart open agent sessions afterward to load the updated skills and MCP. An install with `--dry-run` lists update steps that may run. 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).
|
|
74
74
|
|
|
75
75
|
## Use it
|
|
76
76
|
|
|
@@ -116,6 +116,7 @@ If no target is named, the task goes to `codex`, or to `claude` when you are alr
|
|
|
116
116
|
| `baton cancel` / `ls` / `prune` | Stops a job, lists jobs, or deletes old ones. |
|
|
117
117
|
| `baton worktree add/ls/rm` | Gives a job its own git worktree so it doesn't touch your checkout. |
|
|
118
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 (`--body` fills in what happened, `--label` sets labels, default `bug`; `--submit` uses `gh` or opens a browser). |
|
|
119
120
|
| `baton mcp` | Runs the same operations as an MCP server for hosts that can't run shell commands. |
|
|
120
121
|
|
|
121
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
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
**任何 Agent 都能当主控,任何 Agent 都能当执行者。** 不需要 API Key,不需要服务器,不上云。每个 Agent 都用它自己的登录和订阅额度。
|
|
29
29
|
|
|
30
|
-
可派工的执行者:`codex`(Codex CLI)· `claude`(Claude Code)· `cursor`(Cursor Agent CLI)· `agy`(Antigravity)。
|
|
30
|
+
可派工的执行者:`codex`(Codex CLI)· `claude`(Claude Code)· `cursor`(Cursor Agent CLI)· `agy`(Antigravity)· `kimi`(Kimi Code CLI)。
|
|
31
31
|
|
|
32
32
|
## 前后对比
|
|
33
33
|
|
|
@@ -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
|
|
|
@@ -70,7 +70,7 @@ npx @speculoai/baton install
|
|
|
70
70
|
baton agents
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
`npm i -g @speculoai/baton` 只升级 CLI。用 `baton update` 或 `npx @speculoai/baton@latest update` 同时更新 CLI 和已记录的宿主插件。升级后重开已打开的 agent 会话,加载新版 skills 和 MCP。安装时加 `--dry-run` 会列出可能执行的更新步骤。安装参数(`--only`、`--force`、`--dry-run`)、各宿主的手动安装方式,以及 Claude Desktop、Windsurf、Zed 的 MCP 配置,见[完整手册](docs/reference.zh-CN.md#安装指南-installation)。
|
|
74
74
|
|
|
75
75
|
## 怎么用
|
|
76
76
|
|
|
@@ -116,6 +116,7 @@ baton tail -f <task_id>
|
|
|
116
116
|
| `baton cancel` / `ls` / `prune` | 停止任务、列出任务、清理旧任务。 |
|
|
117
117
|
| `baton worktree add/ls/rm` | 给任务单独开一个 git worktree,不碰你的工作目录。 |
|
|
118
118
|
| `baton rules init` | 为当前项目安装并初始化 rulesync,写入前先预览改动。 |
|
|
119
|
+
| `baton report [id]` | 生成脱敏诊断报告和预填 GitHub issue 链接(`--submit` 有 `gh` 直接提,否则在浏览器打开)。 |
|
|
119
120
|
| `baton mcp` | 以 MCP 服务器的形式提供同样的操作,给不能跑 shell 的宿主用。 |
|
|
120
121
|
|
|
121
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
|
@@ -44,8 +44,8 @@ export const claude = {
|
|
|
44
44
|
args.push("--model", modelArg);
|
|
45
45
|
if (sessionId)
|
|
46
46
|
args.push("--resume", sessionId);
|
|
47
|
-
|
|
48
|
-
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 };
|
|
49
49
|
},
|
|
50
50
|
sessionIdFrom(line) {
|
|
51
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
|
}
|
|
@@ -23,3 +35,19 @@ export function authHit(text, phrases) {
|
|
|
23
35
|
const hay = String(text || "").toLowerCase();
|
|
24
36
|
return phrases.some((phrase) => hay.includes(phrase));
|
|
25
37
|
}
|
|
38
|
+
// cmd.exe cuts a .cmd/.bat argument at the first newline and has no safe escaping for these.
|
|
39
|
+
const CMD_UNSAFE = /[\r\n&|<>^%!"()]/;
|
|
40
|
+
const WIN_CMDLINE_MAX = 32767;
|
|
41
|
+
/** For CLIs that take the prompt in argv: refuse what Windows would truncate or reinterpret, instead of running a damaged prompt. */
|
|
42
|
+
export function assertArgvSafe(bin, args, platform = process.platform, hint) {
|
|
43
|
+
if (platform !== "win32")
|
|
44
|
+
return;
|
|
45
|
+
const base = path.win32.basename(bin);
|
|
46
|
+
if (/\.(cmd|bat)$/i.test(base) && args.some((arg) => CMD_UNSAFE.test(arg))) {
|
|
47
|
+
throw new Error(`${base} is a .cmd/.bat shim: Windows runs it through cmd.exe, which cuts a multi-line prompt at the first newline and cannot safely pass & | < > ^ % ! " ( ).${hint ? ` ${hint}` : ""}`);
|
|
48
|
+
}
|
|
49
|
+
// shortcut: counts each argument plus quotes and a space, ignoring escape growth; exact enough to fail before CreateProcess does.
|
|
50
|
+
const length = [bin, ...args].reduce((sum, arg) => sum + arg.length + 3, 0);
|
|
51
|
+
if (length > WIN_CMDLINE_MAX)
|
|
52
|
+
throw new Error(`The command line is ${length} characters; Windows allows at most ${WIN_CMDLINE_MAX}.`);
|
|
53
|
+
}
|
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/adapters/index.js
CHANGED
|
@@ -2,5 +2,6 @@ import { agy } from "./agy.js";
|
|
|
2
2
|
import { claude } from "./claude.js";
|
|
3
3
|
import { codex } from "./codex.js";
|
|
4
4
|
import { cursor } from "./cursor.js";
|
|
5
|
-
|
|
5
|
+
import { kimi } from "./kimi.js";
|
|
6
|
+
export const adapters = { codex, claude, cursor, agy, kimi };
|
|
6
7
|
export function getAdapter(id) { return Object.hasOwn(adapters, id) ? adapters[id] : null; }
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { redact } from "../redact.js";
|
|
2
|
+
import { assertArgvSafe, authHit, which } from "./common.js";
|
|
3
|
+
// Verified 2026-11-26 (kimi 2.8.0): stderr when no account or model is set up.
|
|
4
|
+
const AUTH = ["no model configured", "use /login"];
|
|
5
|
+
// Verified 2026-11-26 (kimi 2.8.0): the Bash tool result has no status field, only this trailer on failure.
|
|
6
|
+
const FAILED = /Command failed with exit code: \d+\.\s*$/;
|
|
7
|
+
function stamp(data) {
|
|
8
|
+
return { ts: new Date().toISOString(), turn: 0, ...data };
|
|
9
|
+
}
|
|
10
|
+
function parse(line) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(line);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function toolDetail(raw) {
|
|
19
|
+
const text = typeof raw === "string" ? raw : JSON.stringify(raw ?? {});
|
|
20
|
+
const input = parse(text);
|
|
21
|
+
return redact(String(input?.command ?? input?.path ?? input?.file_path ?? text)).slice(0, 200);
|
|
22
|
+
}
|
|
23
|
+
export const kimi = {
|
|
24
|
+
id: "kimi",
|
|
25
|
+
// No readonlyEnforcement: -p always runs with auto permission and cannot take --plan (verified 2026-11-26, kimi 2.8.0).
|
|
26
|
+
// `--agent explore` is read-only but its sessions fail to resume ("tool \"Agent\" is not declared"), so reply would break.
|
|
27
|
+
// Verified 2026-11-26: AGENTS.md and .kimi-code/AGENTS.md at every level from the git root to cwd; CLAUDE.md is not read.
|
|
28
|
+
rules: {
|
|
29
|
+
files: ["AGENTS.md", ".kimi-code/AGENTS.md"],
|
|
30
|
+
rulesyncTarget: "kimi-code",
|
|
31
|
+
gates: {
|
|
32
|
+
mcp: "Project .kimi-code/mcp.json loads under kimi -p only in a trusted workspace (or with KIMI_CODE_TRUST_WORKSPACE=1); Baton sets neither.",
|
|
33
|
+
hooks: "rulesync writes kimi-code hooks only with --global; project hooks are not generated.",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
resolve(env) {
|
|
37
|
+
return which(["kimi"], env);
|
|
38
|
+
},
|
|
39
|
+
build({ bin, prompt, sessionId, reasoningEffort, model }) {
|
|
40
|
+
// Verified 2026-11-26 (kimi 2.8.0): -p has no stdin form (`-p -` is taken literally), so the prompt goes in argv.
|
|
41
|
+
const args = ["-p", prompt, "--output-format", "stream-json"];
|
|
42
|
+
// Verified 2026-11-26: -m is honoured on -S resume, so pass it every turn.
|
|
43
|
+
const modelArg = model?.trim() || undefined;
|
|
44
|
+
if (modelArg)
|
|
45
|
+
args.push("-m", modelArg);
|
|
46
|
+
if (sessionId)
|
|
47
|
+
args.push("-S", sessionId);
|
|
48
|
+
assertArgvSafe(bin, args, process.platform, "Install the native kimi.exe with the official install.ps1 instead of the npm package.");
|
|
49
|
+
const spec = { command: bin, args, stdin: null };
|
|
50
|
+
if (modelArg)
|
|
51
|
+
spec.modelArg = modelArg;
|
|
52
|
+
// kimi has no thinking-effort flag (only config.toml [thinking] effort).
|
|
53
|
+
if (reasoningEffort)
|
|
54
|
+
spec.warning = `kimi has no command-line thinking effort; --effort ${reasoningEffort} was ignored.`;
|
|
55
|
+
return spec;
|
|
56
|
+
},
|
|
57
|
+
sessionIdFrom(line) {
|
|
58
|
+
const obj = parse(line);
|
|
59
|
+
return obj?.role === "meta" && obj.type === "session.resume_hint" && typeof obj.session_id === "string" ? obj.session_id : null;
|
|
60
|
+
},
|
|
61
|
+
parseLine(line) {
|
|
62
|
+
const obj = parse(line);
|
|
63
|
+
if (!obj || typeof obj !== "object" || typeof obj.role !== "string")
|
|
64
|
+
return null;
|
|
65
|
+
// system.version and session.resume_hint (handled by sessionIdFrom) stay out of the event stream.
|
|
66
|
+
if (obj.role === "meta")
|
|
67
|
+
return [];
|
|
68
|
+
if (obj.role === "assistant") {
|
|
69
|
+
const calls = Array.isArray(obj.tool_calls) ? obj.tool_calls : [];
|
|
70
|
+
const events = calls.map((call) => stamp({ type: "tool_call", name: String(call?.function?.name ?? "tool"), detail: toolDetail(call?.function?.arguments) }));
|
|
71
|
+
if (typeof obj.content === "string" && obj.content)
|
|
72
|
+
events.push(stamp({ type: "message", text: obj.content }));
|
|
73
|
+
return events;
|
|
74
|
+
}
|
|
75
|
+
if (obj.role === "tool") {
|
|
76
|
+
const content = typeof obj.content === "string" ? obj.content : JSON.stringify(obj.content ?? "");
|
|
77
|
+
return [stamp({ type: "tool_result", name: "tool", ok: !FAILED.test(content), detail: redact(content).slice(0, 200) })];
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
},
|
|
81
|
+
isAuthFailure(text) {
|
|
82
|
+
return authHit(text, AUTH);
|
|
83
|
+
},
|
|
84
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ 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, hasSubcommand, isCommand, renderHelp, wantsHelp } from "./usage.js";
|
|
9
10
|
function installChoice(value, flag) {
|
|
10
11
|
if (value === undefined)
|
|
11
12
|
return undefined;
|
|
@@ -16,6 +17,28 @@ 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
|
+
const sub = command === "help" ? args[1] : undefined;
|
|
23
|
+
if (name === undefined)
|
|
24
|
+
process.stdout.write(renderHelp());
|
|
25
|
+
else if (isCommand(name)) {
|
|
26
|
+
if (sub === undefined)
|
|
27
|
+
process.stdout.write(renderHelp(name));
|
|
28
|
+
else if (hasSubcommand(name, sub))
|
|
29
|
+
process.stdout.write(renderHelp(name, sub));
|
|
30
|
+
else
|
|
31
|
+
throw new Error(`Usage: ${COMMANDS[name].usage}`);
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
throw new Error(commandList);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Before parsing, so `start --help` neither trips strict parsing nor waits on stdin.
|
|
38
|
+
if (isCommand(command) && wantsHelp(args)) {
|
|
39
|
+
process.stdout.write(renderHelp(command, hasSubcommand(command, args[0]) ? args[0] : undefined));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
19
42
|
if (command === "_supervise") {
|
|
20
43
|
if (args.length !== 1)
|
|
21
44
|
throw new Error("task_id is missing.");
|
|
@@ -26,6 +49,20 @@ async function main() {
|
|
|
26
49
|
await (await import("./mcp.js")).startMcp();
|
|
27
50
|
return;
|
|
28
51
|
}
|
|
52
|
+
if (command === "report") {
|
|
53
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.report.options });
|
|
54
|
+
if (positionals.length > 1)
|
|
55
|
+
throw new Error("report takes at most one task_id.");
|
|
56
|
+
const { buildReport, submitReport } = await import("./report.js");
|
|
57
|
+
const report = buildReport(positionals[0], { title: values.title, body: values.body, labels: values.label });
|
|
58
|
+
if (values.submit) {
|
|
59
|
+
result = submitReport(report);
|
|
60
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
process.stdout.write(`${report.markdown}\n\nOpen issue: ${report.issueUrl}\n`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
29
66
|
if (command === "version" || command === "--version") {
|
|
30
67
|
result = { version: JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version };
|
|
31
68
|
}
|
|
@@ -33,15 +70,7 @@ async function main() {
|
|
|
33
70
|
result = { agents: agents() };
|
|
34
71
|
}
|
|
35
72
|
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" }, check: { type: "string" },
|
|
44
|
-
} });
|
|
73
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.start.options });
|
|
45
74
|
if (positionals.length)
|
|
46
75
|
throw new Error("start takes no positional arguments.");
|
|
47
76
|
result = await start({ target: values.target || "", prompt: values.prompt ?? fs.readFileSync(0, "utf8"), cwd: values.cwd, files: values.file,
|
|
@@ -61,7 +90,7 @@ async function main() {
|
|
|
61
90
|
result = status(args[0]);
|
|
62
91
|
}
|
|
63
92
|
else if (command === "reply") {
|
|
64
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
93
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.reply.options });
|
|
65
94
|
if (positionals.length !== 1)
|
|
66
95
|
throw new Error("reply requires one task_id.");
|
|
67
96
|
result = await reply(positionals[0], values.prompt ?? fs.readFileSync(0, "utf8"), (values.as ?? "host"));
|
|
@@ -71,14 +100,14 @@ async function main() {
|
|
|
71
100
|
else if (command === "wait") {
|
|
72
101
|
const { values, positionals } = parseArgs({
|
|
73
102
|
args, allowPositionals: true,
|
|
74
|
-
options:
|
|
103
|
+
options: COMMANDS.wait.options,
|
|
75
104
|
});
|
|
76
105
|
if (values["until-done"] && values.for !== undefined)
|
|
77
106
|
throw new Error("--until-done and --for cannot be used together.");
|
|
78
107
|
result = await wait(positionals, values["until-done"] ? Infinity : values.for === undefined ? 50 : Number(values.for));
|
|
79
108
|
}
|
|
80
109
|
else if (command === "result") {
|
|
81
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
110
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.result.options });
|
|
82
111
|
if (positionals.length !== 1)
|
|
83
112
|
throw new Error("result requires one task_id.");
|
|
84
113
|
// Plain text, like tail: the point is to read the answer without JSON escaping or the full transcript.
|
|
@@ -86,7 +115,7 @@ async function main() {
|
|
|
86
115
|
return;
|
|
87
116
|
}
|
|
88
117
|
else if (command === "diff") {
|
|
89
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
118
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.diff.options });
|
|
90
119
|
if (positionals.length !== 1)
|
|
91
120
|
throw new Error("diff requires one task_id.");
|
|
92
121
|
// Plain text, like result: a patch is read, not parsed.
|
|
@@ -94,26 +123,26 @@ async function main() {
|
|
|
94
123
|
return;
|
|
95
124
|
}
|
|
96
125
|
else if (command === "tail") {
|
|
97
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
126
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.tail.options });
|
|
98
127
|
if (positionals.length !== 1)
|
|
99
128
|
throw new Error("tail requires one task_id.");
|
|
100
129
|
await (await import("./tail.js")).tail(positionals[0], { follow: values.follow, raw: values.raw });
|
|
101
130
|
return;
|
|
102
131
|
}
|
|
103
132
|
else if (command === "ls") {
|
|
104
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
133
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.ls.options });
|
|
105
134
|
if (positionals.length)
|
|
106
135
|
throw new Error("ls takes no positional arguments.");
|
|
107
136
|
result = { tasks: ls(values.all) };
|
|
108
137
|
}
|
|
109
138
|
else if (command === "prune") {
|
|
110
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
139
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.prune.options });
|
|
111
140
|
if (positionals.length || values.older === undefined)
|
|
112
141
|
throw new Error("prune requires --older days.");
|
|
113
142
|
result = { deleted: prune(Number(values.older)) };
|
|
114
143
|
}
|
|
115
144
|
else if (command === "apply") {
|
|
116
|
-
const { values, positionals } = parseArgs({ args, allowPositionals: true, options:
|
|
145
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: COMMANDS.apply.options });
|
|
117
146
|
if (positionals.length !== 1)
|
|
118
147
|
throw new Error("apply requires one task_id.");
|
|
119
148
|
result = apply(positionals[0], { remove: values.remove });
|
|
@@ -129,21 +158,27 @@ async function main() {
|
|
|
129
158
|
const { values, positionals } = parseArgs({
|
|
130
159
|
args: rest,
|
|
131
160
|
allowPositionals: true,
|
|
132
|
-
options:
|
|
161
|
+
options: COMMANDS.worktree.subcommands.add.options,
|
|
133
162
|
});
|
|
134
163
|
if (positionals.length)
|
|
135
164
|
throw new Error("worktree add takes no positional arguments.");
|
|
136
165
|
result = addWorktree(process.cwd(), { name: values.name, branch: values.branch, base: values.base });
|
|
137
166
|
}
|
|
138
167
|
else if (action === "ls") {
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
const { positionals } = parseArgs({ args: rest, allowPositionals: true, options: {} });
|
|
169
|
+
if (positionals.length)
|
|
170
|
+
throw new Error("worktree ls takes no positional arguments.");
|
|
141
171
|
result = { worktrees: listWorktrees(process.cwd()) };
|
|
142
172
|
}
|
|
143
173
|
else if (action === "rm") {
|
|
144
|
-
|
|
174
|
+
const { values, positionals } = parseArgs({
|
|
175
|
+
args: rest,
|
|
176
|
+
allowPositionals: true,
|
|
177
|
+
options: COMMANDS.worktree.subcommands.rm.options,
|
|
178
|
+
});
|
|
179
|
+
if (positionals.length !== 1)
|
|
145
180
|
throw new Error("worktree rm requires one name or path.");
|
|
146
|
-
result = removeWorktree(process.cwd(),
|
|
181
|
+
result = removeWorktree(process.cwd(), positionals[0], { force: values.force });
|
|
147
182
|
}
|
|
148
183
|
else {
|
|
149
184
|
throw new Error("Usage: baton worktree add|ls|rm");
|
|
@@ -155,10 +190,7 @@ async function main() {
|
|
|
155
190
|
throw new Error("Usage: baton rules init");
|
|
156
191
|
const { values, positionals } = parseArgs({
|
|
157
192
|
args: rest, allowPositionals: true,
|
|
158
|
-
options:
|
|
159
|
-
install: { type: "string" }, source: { type: "string" }, template: { type: "boolean" },
|
|
160
|
-
targets: { type: "string", multiple: true }, yes: { type: "boolean" }, "dry-run": { type: "boolean" },
|
|
161
|
-
},
|
|
193
|
+
options: COMMANDS.rules.options,
|
|
162
194
|
});
|
|
163
195
|
if (positionals.length)
|
|
164
196
|
throw new Error("rules init takes no positional arguments.");
|
|
@@ -191,20 +223,11 @@ async function main() {
|
|
|
191
223
|
else if (command === "install" || command === "update" || command === "uninstall") {
|
|
192
224
|
const { values, positionals } = parseArgs({
|
|
193
225
|
args, allowPositionals: true,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
"dry-run": { type: "boolean" }, "skip-global": { type: "boolean" },
|
|
197
|
-
rulesync: { type: "string" },
|
|
198
|
-
},
|
|
226
|
+
// Each command parses with its own table (update/uninstall reject install-only flags); typed as install's superset.
|
|
227
|
+
options: COMMANDS[command].options,
|
|
199
228
|
});
|
|
200
229
|
if (positionals.length)
|
|
201
230
|
throw new Error(`${command} takes no positional arguments.`);
|
|
202
|
-
if (command !== "install" && values.force)
|
|
203
|
-
throw new Error(`${command} does not accept --force.`);
|
|
204
|
-
if (command === "uninstall" && values["skip-global"])
|
|
205
|
-
throw new Error("uninstall does not accept --skip-global.");
|
|
206
|
-
if (command !== "install" && values.rulesync !== undefined)
|
|
207
|
-
throw new Error(`${command} does not accept --rulesync.`);
|
|
208
231
|
const rulesyncChoice = installChoice(values.rulesync, "--rulesync");
|
|
209
232
|
const action = command;
|
|
210
233
|
const pretty = Boolean(process.stdin.isTTY);
|
|
@@ -300,6 +323,10 @@ async function main() {
|
|
|
300
323
|
else if (ran.result.missing?.length) {
|
|
301
324
|
ui.logInfo(`missing: ${ran.result.missing.join(", ")}`);
|
|
302
325
|
}
|
|
326
|
+
for (const warning of ran.result.warnings ?? [])
|
|
327
|
+
ui.logWarning(warning);
|
|
328
|
+
if (ran.result.note)
|
|
329
|
+
ui.logInfo(ran.result.note);
|
|
303
330
|
ui.endAction(ui.summarizeResult(ran.result));
|
|
304
331
|
}
|
|
305
332
|
result = rulesync ? { ...ran.result, rulesync } : ran.result;
|
|
@@ -311,7 +338,7 @@ async function main() {
|
|
|
311
338
|
return;
|
|
312
339
|
}
|
|
313
340
|
else
|
|
314
|
-
throw new Error(
|
|
341
|
+
throw new Error(commandList);
|
|
315
342
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
316
343
|
}
|
|
317
344
|
try {
|
package/dist/install-ui.js
CHANGED