@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/dist/usage.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const INSTALL_OPTIONS = {
|
|
2
|
+
only: { type: "string", multiple: true, arg: "agent", desc: "Only this agent: claude, codex, cursor, agy or gemini (repeatable)" },
|
|
3
|
+
force: { type: "boolean", desc: "Reinstall even when already installed" },
|
|
4
|
+
"dry-run": { type: "boolean", desc: "Print the commands without running them" },
|
|
5
|
+
"skip-global": { type: "boolean", desc: "Do not install or update the global baton command" },
|
|
6
|
+
rulesync: { type: "string", arg: "project|global|skip", desc: "Answer the rulesync install question up front" },
|
|
7
|
+
};
|
|
8
|
+
const UPDATE_OPTIONS = { only: INSTALL_OPTIONS.only, "dry-run": INSTALL_OPTIONS["dry-run"], "skip-global": INSTALL_OPTIONS["skip-global"] };
|
|
9
|
+
const UNINSTALL_OPTIONS = { only: INSTALL_OPTIONS.only, "dry-run": INSTALL_OPTIONS["dry-run"] };
|
|
10
|
+
export const COMMANDS = {
|
|
11
|
+
version: { usage: "baton version", summary: "Print the installed baton version." },
|
|
12
|
+
agents: { usage: "baton agents", summary: "List the local agent CLIs baton can delegate to and whether each is installed." },
|
|
13
|
+
start: {
|
|
14
|
+
usage: "baton start --target <agent> [--prompt <text> | stdin] [options]",
|
|
15
|
+
summary: "Start a job in the background and return its task_id.",
|
|
16
|
+
options: {
|
|
17
|
+
target: { type: "string", arg: "agent", desc: "Agent CLI to run: codex, claude, cursor or agy (required)" },
|
|
18
|
+
prompt: { type: "string", arg: "text", desc: "Task prompt; read from stdin when omitted" },
|
|
19
|
+
cwd: { type: "string", arg: "dir", desc: "Working directory for the job (default: current directory)" },
|
|
20
|
+
file: { type: "string", multiple: true, arg: "path", desc: "File the agent should focus on (repeatable)" },
|
|
21
|
+
effort: { type: "string", arg: "low|medium|high|ultra", desc: "Reasoning effort, mapped to the CLI's native flag (not cursor)" },
|
|
22
|
+
model: { type: "string", arg: "id", desc: "Model id for cursor, codex or claude; kept across reply" },
|
|
23
|
+
"idle-timeout": { type: "string", arg: "s", desc: "Stop after this many seconds with no output (default 600)" },
|
|
24
|
+
"max-duration": { type: "string", arg: "s", desc: "Maximum seconds per turn (default unlimited)" },
|
|
25
|
+
scope: { type: "string", multiple: true, arg: "glob", desc: "Paths allowed to change, checked after each turn (repeatable)" },
|
|
26
|
+
"scope-on-violation": { type: "string", arg: "warn|fail", desc: "What an out-of-scope change does (default warn)" },
|
|
27
|
+
mode: { type: "string", arg: "readonly|write", desc: "Permission mode (default write)" },
|
|
28
|
+
"allow-weak": { type: "boolean", desc: "Allow --mode readonly on a target that cannot enforce it" },
|
|
29
|
+
isolate: { type: "boolean", desc: "Run in a new git worktree; bring the work back with baton apply" },
|
|
30
|
+
"allow-dirty": { type: "boolean", desc: "Allow an in-place write job on a dirty working tree" },
|
|
31
|
+
rules: { type: "string", arg: "check|pointer|off", desc: "Project rule file discovery (default check)" },
|
|
32
|
+
check: { type: "string", arg: "cmd", desc: "Shell command run after each successful turn; non-zero ends it as check_failed" },
|
|
33
|
+
},
|
|
34
|
+
examples: [
|
|
35
|
+
"baton start --target codex --isolate --prompt \"fix the failing test in test/a.test.ts\"",
|
|
36
|
+
"baton start --target claude --mode readonly --scope \"src/**\" < task.md",
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
status: { usage: "baton status <task_id>", summary: "Print a job's current status; while running, includes liveness." },
|
|
40
|
+
cancel: { usage: "baton cancel <task_id>", summary: "Stop a running job and its whole process group." },
|
|
41
|
+
wait: {
|
|
42
|
+
usage: "baton wait <task_id>... [--for <s> | --until-done]",
|
|
43
|
+
summary: "Wait until any of the jobs leaves running, or until the time runs out.",
|
|
44
|
+
options: {
|
|
45
|
+
for: { type: "string", arg: "s", desc: "Seconds to wait (default 50)" },
|
|
46
|
+
"until-done": { type: "boolean", desc: "Block until a job leaves running" },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
result: {
|
|
50
|
+
usage: "baton result <task_id> [--turn <n>]",
|
|
51
|
+
summary: "Print the agent's full final message of a finished turn as plain text.",
|
|
52
|
+
options: { turn: { type: "string", arg: "n", desc: "Turn number (default latest)" } },
|
|
53
|
+
},
|
|
54
|
+
diff: {
|
|
55
|
+
usage: "baton diff <task_id> [--stat]",
|
|
56
|
+
summary: "Print the net change of an --isolate job as a plain-text patch.",
|
|
57
|
+
options: { stat: { type: "boolean", desc: "Print a diffstat instead of the patch" } },
|
|
58
|
+
},
|
|
59
|
+
apply: {
|
|
60
|
+
usage: "baton apply <task_id> [--remove]",
|
|
61
|
+
summary: "Bring an --isolate job's net change onto the current branch as one local commit; never pushes.",
|
|
62
|
+
options: { remove: { type: "boolean", desc: "Delete the worktree and its branch after a successful apply" } },
|
|
63
|
+
},
|
|
64
|
+
tail: {
|
|
65
|
+
usage: "baton tail <task_id> [-f] [--raw]",
|
|
66
|
+
summary: "Print a job's events in readable form.",
|
|
67
|
+
options: {
|
|
68
|
+
follow: { type: "boolean", short: "f", desc: "Keep following until the job stops" },
|
|
69
|
+
raw: { type: "boolean", desc: "Print the raw events.jsonl lines" },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
reply: {
|
|
73
|
+
usage: "baton reply <task_id> [--prompt <text> | stdin] [--as host|human]",
|
|
74
|
+
summary: "Start the next turn of a stopped job in the same session.",
|
|
75
|
+
options: {
|
|
76
|
+
prompt: { type: "string", arg: "text", desc: "Reply text; read from stdin when omitted" },
|
|
77
|
+
as: { type: "string", arg: "host|human", desc: "Who is speaking (default host)" },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
ls: {
|
|
81
|
+
usage: "baton ls [--all]",
|
|
82
|
+
summary: "List jobs for the current directory, newest first.",
|
|
83
|
+
options: { all: { type: "boolean", desc: "List jobs from every directory" } },
|
|
84
|
+
},
|
|
85
|
+
prune: {
|
|
86
|
+
usage: "baton prune --older <days>",
|
|
87
|
+
summary: "Delete non-running task directories older than N days (worktrees are kept).",
|
|
88
|
+
options: { older: { type: "string", arg: "days", desc: "Age threshold in days (required)" } },
|
|
89
|
+
},
|
|
90
|
+
worktree: {
|
|
91
|
+
usage: "baton worktree add [options] | ls | rm <name-or-path>",
|
|
92
|
+
summary: "Manage baton worktrees under .worktrees/.",
|
|
93
|
+
options: {
|
|
94
|
+
name: { type: "string", arg: "id", desc: "Worktree name (add)" },
|
|
95
|
+
branch: { type: "string", arg: "name", desc: "Branch to create (add)" },
|
|
96
|
+
base: { type: "string", arg: "ref", desc: "Ref to start from (add; default HEAD)" },
|
|
97
|
+
},
|
|
98
|
+
notes: ["rm refuses dirty or unmerged trees; when clean it removes the tree and deletes the local branch."],
|
|
99
|
+
},
|
|
100
|
+
rules: {
|
|
101
|
+
usage: "baton rules init [options]",
|
|
102
|
+
summary: "Set up rulesync so your agents share one set of rules.",
|
|
103
|
+
options: {
|
|
104
|
+
install: { type: "string", arg: "project|global|skip", desc: "How to install rulesync when it is missing" },
|
|
105
|
+
source: { type: "string", arg: "agent", desc: "Import existing rules from claudecode, codexcli or cursor" },
|
|
106
|
+
template: { type: "boolean", desc: "Start from baton's template instead of importing" },
|
|
107
|
+
targets: { type: "string", multiple: true, arg: "agent[,agent]", desc: "Agents to generate for (default: detected hosts)" },
|
|
108
|
+
yes: { type: "boolean", desc: "Apply the generated changes without asking" },
|
|
109
|
+
"dry-run": { type: "boolean", desc: "Preview only" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
install: {
|
|
113
|
+
usage: "baton install [options]",
|
|
114
|
+
summary: "Install the global baton command and the plugin into your agent CLIs.",
|
|
115
|
+
options: INSTALL_OPTIONS,
|
|
116
|
+
},
|
|
117
|
+
update: {
|
|
118
|
+
usage: "baton update [--only <agent>]... [--dry-run] [--skip-global]",
|
|
119
|
+
summary: "Update the global baton command and the installed plugins.",
|
|
120
|
+
options: UPDATE_OPTIONS,
|
|
121
|
+
},
|
|
122
|
+
uninstall: {
|
|
123
|
+
usage: "baton uninstall [--only <agent>]... [--dry-run]",
|
|
124
|
+
summary: "Remove the baton plugin from your agent CLIs.",
|
|
125
|
+
options: UNINSTALL_OPTIONS,
|
|
126
|
+
},
|
|
127
|
+
mcp: { usage: "baton mcp", summary: "Start the MCP server on stdio." },
|
|
128
|
+
report: {
|
|
129
|
+
usage: "baton report [task_id] [--title <text>] [--submit]",
|
|
130
|
+
summary: "Generate a redacted diagnostic report and GitHub issue link (optionally submit).",
|
|
131
|
+
options: {
|
|
132
|
+
title: { type: "string", arg: "text", desc: "Issue title override" },
|
|
133
|
+
submit: { type: "boolean", desc: "Create the issue via gh if logged in, otherwise open the prefilled form in a browser" },
|
|
134
|
+
},
|
|
135
|
+
notes: ["Never includes prompts, raw logs, file names, or credentials; still review before posting."],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
export function isCommand(name) {
|
|
139
|
+
return name !== undefined && Object.hasOwn(COMMANDS, name);
|
|
140
|
+
}
|
|
141
|
+
/** `-h` / `--help` anywhere before `--`. */
|
|
142
|
+
export function wantsHelp(args) {
|
|
143
|
+
const end = args.indexOf("--");
|
|
144
|
+
return (end < 0 ? args : args.slice(0, end)).some((arg) => arg === "-h" || arg === "--help");
|
|
145
|
+
}
|
|
146
|
+
export const commandList = `Usage: baton ${Object.keys(COMMANDS).join(" | ")}`;
|
|
147
|
+
function columns(rows) {
|
|
148
|
+
const width = Math.max(...rows.map(([left]) => left.length)) + 2;
|
|
149
|
+
return rows.map(([left, right]) => ` ${left.padEnd(width)}${right}`);
|
|
150
|
+
}
|
|
151
|
+
export function renderHelp(name) {
|
|
152
|
+
if (!name) {
|
|
153
|
+
return [
|
|
154
|
+
"Usage: baton <command> [options]",
|
|
155
|
+
"",
|
|
156
|
+
"Hand a bounded coding task to another local agent CLI, then continue the same session.",
|
|
157
|
+
"",
|
|
158
|
+
"Commands:",
|
|
159
|
+
...columns(Object.entries(COMMANDS).map(([cmd, def]) => [cmd, def.summary])),
|
|
160
|
+
"",
|
|
161
|
+
"Run `baton <command> --help` for a command's options.",
|
|
162
|
+
"",
|
|
163
|
+
].join("\n");
|
|
164
|
+
}
|
|
165
|
+
const cmd = COMMANDS[name];
|
|
166
|
+
const options = Object.entries(cmd.options ?? {}).map(([key, opt]) => [
|
|
167
|
+
`${opt.short ? `-${opt.short}, ` : ""}--${key}${opt.type === "string" ? ` <${opt.arg ?? "value"}>` : ""}`,
|
|
168
|
+
opt.desc,
|
|
169
|
+
]);
|
|
170
|
+
options.push(["-h, --help", "Show this help"]);
|
|
171
|
+
return [
|
|
172
|
+
`Usage: ${cmd.usage}`,
|
|
173
|
+
"",
|
|
174
|
+
cmd.summary,
|
|
175
|
+
"",
|
|
176
|
+
"Options:",
|
|
177
|
+
...columns(options),
|
|
178
|
+
...(cmd.notes?.length ? ["", ...cmd.notes] : []),
|
|
179
|
+
...(cmd.examples?.length ? ["", "Examples:", ...cmd.examples.map((line) => ` ${line}`)] : []),
|
|
180
|
+
"",
|
|
181
|
+
].join("\n");
|
|
182
|
+
}
|
package/dist/worktree.js
CHANGED
|
@@ -2,13 +2,122 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
+
import crossSpawn from "cross-spawn";
|
|
5
6
|
import { hasRulesyncSource, resolveRulesync, RULE_ENTRIES } from "./rules.js";
|
|
6
7
|
import { redact } from "./redact.js";
|
|
7
8
|
const META_NAME = ".baton-worktree.json";
|
|
8
|
-
function git(cwd, args) {
|
|
9
|
-
const ran = spawnSync("git", args, {
|
|
9
|
+
function git(cwd, args, options = {}) {
|
|
10
|
+
const ran = spawnSync("git", args, {
|
|
11
|
+
cwd, encoding: "utf8", input: options.input, maxBuffer: 256 * 1024 * 1024,
|
|
12
|
+
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
13
|
+
});
|
|
10
14
|
return { status: ran.status ?? 1, stdout: ran.stdout || "", stderr: ran.stderr || "" };
|
|
11
15
|
}
|
|
16
|
+
function mustGit(cwd, args, options = {}) {
|
|
17
|
+
const ran = git(cwd, args, options);
|
|
18
|
+
if (ran.status !== 0)
|
|
19
|
+
throw new Error(`git ${args[0]} failed: ${(ran.stderr || ran.stdout).trim()}`);
|
|
20
|
+
return ran.stdout;
|
|
21
|
+
}
|
|
22
|
+
export function headSha(cwd) {
|
|
23
|
+
return mustGit(cwd, ["rev-parse", "HEAD"]).trim();
|
|
24
|
+
}
|
|
25
|
+
/** Commit the task worktree forked from: the recorded sha, or (older tasks) the merge-base with the source HEAD. */
|
|
26
|
+
export function forkPoint(sourceRepo, branch, recorded) {
|
|
27
|
+
if (recorded)
|
|
28
|
+
return recorded;
|
|
29
|
+
const ran = git(sourceRepo, ["merge-base", branch, "HEAD"]);
|
|
30
|
+
if (ran.status !== 0 || !ran.stdout.trim())
|
|
31
|
+
throw new Error(`Cannot find where ${branch} forked from; no base_sha recorded and merge-base failed.`);
|
|
32
|
+
return ran.stdout.trim();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The worktree's net state as a tree object: HEAD plus every non-ignored working-tree change,
|
|
36
|
+
* minus Baton's own files (.baton-worktree.json, copy / symlink entries). Built in a throwaway
|
|
37
|
+
* index so the worktree's own index, branch and files stay untouched.
|
|
38
|
+
*/
|
|
39
|
+
export function netTree(worktreePath, indexFile) {
|
|
40
|
+
const env = { GIT_INDEX_FILE: indexFile };
|
|
41
|
+
try {
|
|
42
|
+
mustGit(worktreePath, ["read-tree", "HEAD"], { env });
|
|
43
|
+
const exclude = [...batonWorktreeExemptPaths(worktreePath)].map((entry) => `:(exclude,glob)${entry}`);
|
|
44
|
+
mustGit(worktreePath, ["add", "-A", "--", ".", ...exclude], { env });
|
|
45
|
+
return mustGit(worktreePath, ["write-tree"], { env }).trim();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
fs.rmSync(indexFile, { force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function diffTrees(cwd, base, tree, stat = false) {
|
|
52
|
+
return mustGit(cwd, ["diff", stat ? "--stat" : "--binary", base, tree]);
|
|
53
|
+
}
|
|
54
|
+
/** Paths touched between two trees; --no-renames so a rename lists both its old and new path. */
|
|
55
|
+
export function changedPaths(cwd, base, tree) {
|
|
56
|
+
return mustGit(cwd, ["diff", "--name-only", "--no-renames", "-z", base, tree]).split("\0").filter(Boolean);
|
|
57
|
+
}
|
|
58
|
+
const IN_PROGRESS = ["MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "rebase-merge", "rebase-apply"];
|
|
59
|
+
/** Why bringing `files` into `repo` is unsafe right now, or null. Checked before anything is written. */
|
|
60
|
+
function applyBlocker(repo, files) {
|
|
61
|
+
for (const name of IN_PROGRESS) {
|
|
62
|
+
if (fs.existsSync(path.resolve(repo, mustGit(repo, ["rev-parse", "--git-path", name]).trim()))) {
|
|
63
|
+
return `${repo} is in the middle of a merge, rebase, cherry-pick or revert (${name}); finish or abort it first.`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (git(repo, ["diff", "--cached", "--quiet"]).status !== 0)
|
|
67
|
+
return `Staged changes in ${repo}; commit or unstage them first.`;
|
|
68
|
+
// porcelain v1 -z: "XY path\0", and a rename / copy adds its source path as the next field.
|
|
69
|
+
const fields = mustGit(repo, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]).split("\0");
|
|
70
|
+
const dirty = new Set();
|
|
71
|
+
for (let i = 0; i < fields.length; i++) {
|
|
72
|
+
const entry = fields[i];
|
|
73
|
+
if (entry.length < 4)
|
|
74
|
+
continue;
|
|
75
|
+
dirty.add(entry.slice(3));
|
|
76
|
+
if (entry[0] === "R" || entry[0] === "C")
|
|
77
|
+
dirty.add(fields[++i]);
|
|
78
|
+
}
|
|
79
|
+
const overlap = files.filter((file) => dirty.has(file));
|
|
80
|
+
return overlap.length ? `Uncommitted or untracked files in ${repo} overlap the task's changes: ${overlap.join(", ")}. Commit, stash or move them first.` : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Bring `tree` (forked at `base`) onto the current branch of `repo` as one commit: commit-tree, then cherry-pick
|
|
84
|
+
* for a three-way merge. Any refusal or conflict leaves HEAD, index and working tree as they were.
|
|
85
|
+
*/
|
|
86
|
+
export function applyTree(repo, base, tree, message) {
|
|
87
|
+
const files = changedPaths(repo, base, tree);
|
|
88
|
+
if (!files.length)
|
|
89
|
+
return null;
|
|
90
|
+
const blocker = applyBlocker(repo, files);
|
|
91
|
+
if (blocker)
|
|
92
|
+
throw new Error(blocker);
|
|
93
|
+
const squash = mustGit(repo, ["commit-tree", tree, "-p", base, "-F", "-"], { input: message }).trim();
|
|
94
|
+
const picked = git(repo, ["cherry-pick", squash]);
|
|
95
|
+
if (picked.status !== 0) {
|
|
96
|
+
const conflicts = git(repo, ["diff", "--name-only", "--diff-filter=U", "-z"]).stdout.split("\0").filter(Boolean);
|
|
97
|
+
git(repo, ["cherry-pick", "--abort"]);
|
|
98
|
+
const detail = (picked.stderr || picked.stdout).trim();
|
|
99
|
+
throw new Error(`cherry-pick failed and was aborted; ${repo} is unchanged.${conflicts.length ? ` Conflicts: ${conflicts.join(", ")}.` : ""} ${detail}`.trim());
|
|
100
|
+
}
|
|
101
|
+
return { commit: headSha(repo), files };
|
|
102
|
+
}
|
|
103
|
+
/** Delete a task's worktree and branch regardless of their state; true when both are gone. */
|
|
104
|
+
/** Removes an --isolate worktree and its branch; null on success, otherwise what stayed behind and what git said. */
|
|
105
|
+
export function removeTaskWorktree(repo, worktreePath, branch) {
|
|
106
|
+
const problems = cleanupWorktree(repo, worktreePath, branch);
|
|
107
|
+
// Windows keeps a deleted directory visible ("delete pending", or git leaves it) until the last handle on it closes, e.g. a worker that is still exiting.
|
|
108
|
+
for (let wait = 0; process.platform === "win32" && wait < 20 && fs.existsSync(worktreePath); wait++) {
|
|
109
|
+
try {
|
|
110
|
+
fs.rmSync(worktreePath, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
catch { /* still held */ }
|
|
113
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
|
|
114
|
+
}
|
|
115
|
+
if (fs.existsSync(worktreePath))
|
|
116
|
+
problems.push(`${worktreePath} still exists`);
|
|
117
|
+
if (git(repo, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0)
|
|
118
|
+
problems.push(`branch ${branch} still exists`);
|
|
119
|
+
return problems.length ? problems.join("; ") : null;
|
|
120
|
+
}
|
|
12
121
|
function strings(value) {
|
|
13
122
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
14
123
|
}
|
|
@@ -69,8 +178,8 @@ export function assertNotNestedWorktree(cwd) {
|
|
|
69
178
|
if (dir.status !== 0 || common.status !== 0)
|
|
70
179
|
throw new Error("Current directory is not a git repository.");
|
|
71
180
|
// realpath: on macOS /var vs /private/var must not look like a linked worktree.
|
|
72
|
-
const gitDir = fs.realpathSync(path.resolve(cwd, dir.stdout.trim()));
|
|
73
|
-
const gitCommon = fs.realpathSync(path.resolve(cwd, common.stdout.trim()));
|
|
181
|
+
const gitDir = fs.realpathSync.native(path.resolve(cwd, dir.stdout.trim()));
|
|
182
|
+
const gitCommon = fs.realpathSync.native(path.resolve(cwd, common.stdout.trim()));
|
|
74
183
|
if (gitDir === gitCommon)
|
|
75
184
|
return;
|
|
76
185
|
const superproject = git(cwd, ["rev-parse", "--show-superproject-working-tree"]);
|
|
@@ -95,8 +204,8 @@ export function batonWorktreeExemptPaths(cwd) {
|
|
|
95
204
|
const common = git(cwd, ["rev-parse", "--git-common-dir"]);
|
|
96
205
|
if (dir.status !== 0 || common.status !== 0)
|
|
97
206
|
return new Set();
|
|
98
|
-
const gitDir = fs.realpathSync(path.resolve(cwd, dir.stdout.trim()));
|
|
99
|
-
const gitCommon = fs.realpathSync(path.resolve(cwd, common.stdout.trim()));
|
|
207
|
+
const gitDir = fs.realpathSync.native(path.resolve(cwd, dir.stdout.trim()));
|
|
208
|
+
const gitCommon = fs.realpathSync.native(path.resolve(cwd, common.stdout.trim()));
|
|
100
209
|
if (gitDir === gitCommon)
|
|
101
210
|
return new Set(); // main checkout
|
|
102
211
|
const top = git(cwd, ["rev-parse", "--show-toplevel"]);
|
|
@@ -202,7 +311,7 @@ function applyWorktreeRulesync(repo, worktreePath, cfg) {
|
|
|
202
311
|
if (!bin) {
|
|
203
312
|
return { rulesync: "skipped", detail: "rulesync not found in node_modules/.bin or PATH", missing, dirtied: [] };
|
|
204
313
|
}
|
|
205
|
-
const ran =
|
|
314
|
+
const ran = crossSpawn.sync(bin, ["generate"], {
|
|
206
315
|
cwd: worktreePath,
|
|
207
316
|
encoding: "utf8",
|
|
208
317
|
env: { ...process.env, BATON_DELEGATION: "1" },
|
|
@@ -270,7 +379,15 @@ function prepareWorktree(repo, worktreePath, cfg) {
|
|
|
270
379
|
continue;
|
|
271
380
|
if (fs.existsSync(dest))
|
|
272
381
|
fs.rmSync(dest, { recursive: true, force: true });
|
|
273
|
-
|
|
382
|
+
try {
|
|
383
|
+
// junction: Windows lets any user link a directory this way; file links need Developer Mode or admin.
|
|
384
|
+
fs.symlinkSync(src, dest, fs.statSync(src).isDirectory() ? "junction" : "file");
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
if (error.code !== "EPERM")
|
|
388
|
+
throw error;
|
|
389
|
+
throw new Error(`cannot symlink ${name}: Windows needs Developer Mode or admin rights for file links; list it under "copy" in .baton.json instead.`);
|
|
390
|
+
}
|
|
274
391
|
}
|
|
275
392
|
}
|
|
276
393
|
for (const command of cfg.post_create) {
|
|
@@ -288,9 +405,13 @@ function prepareWorktree(repo, worktreePath, cfg) {
|
|
|
288
405
|
}
|
|
289
406
|
}
|
|
290
407
|
function cleanupWorktree(repo, worktreePath, branch) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
408
|
+
const errors = [];
|
|
409
|
+
for (const args of [["worktree", "remove", "--force", worktreePath], ["branch", "-D", branch], ["worktree", "prune"]]) {
|
|
410
|
+
const ran = git(repo, args);
|
|
411
|
+
if (ran.status !== 0)
|
|
412
|
+
errors.push(`git ${args.slice(0, 2).join(" ")}: ${(ran.stderr || ran.stdout).trim()}`);
|
|
413
|
+
}
|
|
414
|
+
return errors;
|
|
294
415
|
}
|
|
295
416
|
function resolveManagedPath(cwd, nameOrPath) {
|
|
296
417
|
const repo = resolveRepoRoot(cwd);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speculoai/baton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Hand a bounded coding task to another local agent CLI, then continue the same session when it needs a decision.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@clack/prompts": "^1.9.0",
|
|
26
|
-
"@modelcontextprotocol/sdk": "^1.20.2"
|
|
26
|
+
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
27
|
+
"cross-spawn": "^7.0.6",
|
|
28
|
+
"picomatch": "^4.0.7"
|
|
27
29
|
},
|
|
28
30
|
"engines": {
|
|
29
31
|
"node": ">=20.17"
|
|
@@ -32,7 +34,9 @@
|
|
|
32
34
|
"access": "public"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
37
|
+
"@types/cross-spawn": "^6.0.6",
|
|
35
38
|
"@types/node": "^26.6.6",
|
|
39
|
+
"@types/picomatch": "^4.0.3",
|
|
36
40
|
"typescript": "^7.0.2"
|
|
37
41
|
}
|
|
38
42
|
}
|