benignswarm 0.12.1 → 0.12.2
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/dist/args.js +2 -2
- package/dist/commands/hook.js +4 -1
- package/dist/commands/watch.js +15 -0
- package/dist/commands/worktrees.js +42 -0
- package/dist/commands/wu.js +102 -6
- package/dist/git.js +91 -1
- package/dist/help.js +9 -1
- package/dist/index.js +4 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { CliError } from "./errors.js";
|
|
3
|
-
export const STRING_FLAGS = ["as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task", "state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions", "cardinality", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "reply-to", "event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent", "parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval", "requeue-after", "category", "command", "follow-delay", "env", "scope", "pr", "note", "add", "remove", "merged", "tag", "activity", "max-unanswered"];
|
|
4
|
-
export const BOOL_FLAGS = ["json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "unread", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all"];
|
|
3
|
+
export const STRING_FLAGS = ["as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task", "state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions", "cardinality", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "reply-to", "event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent", "parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval", "requeue-after", "category", "command", "follow-delay", "env", "scope", "pr", "note", "add", "remove", "merged", "tag", "activity", "max-unanswered", "to", "replay-of", "branch"];
|
|
4
|
+
export const BOOL_FLAGS = ["json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "unread", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree"];
|
|
5
5
|
export function parse(argv) {
|
|
6
6
|
const options = {};
|
|
7
7
|
for (const f of STRING_FLAGS)
|
package/dist/commands/hook.js
CHANGED
|
@@ -75,8 +75,11 @@ export async function gatherUpdates(name, opts) {
|
|
|
75
75
|
const unread = ch.cursor - last;
|
|
76
76
|
if (unread <= 0)
|
|
77
77
|
continue;
|
|
78
|
-
|
|
78
|
+
// Only followed channels earn a read command in a wake-up. Unfollowed traffic is one digest
|
|
79
|
+
// line: a worker that reads every busy channel on every wake-up fills its context with chat
|
|
80
|
+
// that was never for it.
|
|
79
81
|
if (follows.has(key)) {
|
|
82
|
+
readCommands.push(`bschat read ${creds.project ? "" : `--project ${project} `}${ch.name} --since ${last}`);
|
|
80
83
|
const r = await client.call("GET", `/projects/${project}/channels/${ch.name}/messages?since=${last}&limit=5`);
|
|
81
84
|
const seen = new Set(messages.map((m) => m.id));
|
|
82
85
|
const others = r.messages.filter((m) => m.agent_name !== creds.agent && !seen.has(m.id));
|
package/dist/commands/watch.js
CHANGED
|
@@ -6,6 +6,7 @@ import { bool, str } from "../args.js";
|
|
|
6
6
|
import { loadAgent, resolveAgentName } from "../config.js";
|
|
7
7
|
import { Client } from "../client.js";
|
|
8
8
|
import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
|
|
9
|
+
import { scanProject } from "./worktrees.js";
|
|
9
10
|
import { CliError } from "../errors.js";
|
|
10
11
|
import { acquireWatchLock } from "../lock.js";
|
|
11
12
|
import { gatherUpdates } from "./hook.js";
|
|
@@ -70,9 +71,23 @@ export async function watch(p, out) {
|
|
|
70
71
|
log("no harness activity source found (pass --activity <file-or-dir>); liveness is reported as unknown when the agent is quiet");
|
|
71
72
|
const heartbeatClient = activity ? Client.forAgent(loadAgent(name), undefined, { presence: false }) : null;
|
|
72
73
|
let lastSample = null;
|
|
74
|
+
// The watcher sits in a checkout on the machine, so it keeps the worktree registry current: a
|
|
75
|
+
// scan on start and then hourly reports worktrees nobody is touching, which agent calls never would.
|
|
76
|
+
const scanCreds = loadAgent(name);
|
|
77
|
+
let lastScan = 0;
|
|
73
78
|
for (;;) {
|
|
74
79
|
if (activity && heartbeatClient)
|
|
75
80
|
lastSample = await heartbeatIfActive(heartbeatClient, activity, lastSample, interval, log);
|
|
81
|
+
if (scanCreds.project && Date.now() - lastScan > 3_600_000) {
|
|
82
|
+
lastScan = Date.now();
|
|
83
|
+
try {
|
|
84
|
+
const r = await scanProject(scanCreds, scanCreds.project);
|
|
85
|
+
log(`worktree scan: ${r.recorded} in ${r.repo}${r.missing ? `, ${r.missing} gone` : ""}`);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
log(`worktree scan skipped: ${e.message}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
76
91
|
if (!full) {
|
|
77
92
|
await wakeOnce(name, exec, requeueAfter, followDelay, maxUnanswered, log, str(p.flags, "model"), once);
|
|
78
93
|
if (once)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { str } from "../args.js";
|
|
2
|
+
import { Client } from "../client.js";
|
|
3
|
+
import { loadAgent, resolveAgentName } from "../config.js";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
import { defaultMachine, scanWorktrees } from "../git.js";
|
|
6
|
+
import { table } from "../output.js";
|
|
7
|
+
/**
|
|
8
|
+
* The project's worktree registry.
|
|
9
|
+
* bschat worktrees every worktree the project knows about: machine, path, branch, dirty, merged, who, suggestion
|
|
10
|
+
* bschat worktrees scan report every linked worktree of the repository you are in (run on each machine)
|
|
11
|
+
*/
|
|
12
|
+
export async function worktrees(p, out) {
|
|
13
|
+
const sub = p.positionals[1];
|
|
14
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
15
|
+
const creds = loadAgent(name);
|
|
16
|
+
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
17
|
+
if (!project)
|
|
18
|
+
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
19
|
+
if (sub === "scan") {
|
|
20
|
+
const r = await scanProject(creds, project);
|
|
21
|
+
out.print(`Reported ${r.recorded} worktree(s) of ${r.repo} on ${r.machine}${r.missing ? `; ${r.missing} previously known worktree(s) are gone` : ""}.`, r);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
25
|
+
const r = await client.call("GET", `/projects/${project}/worktrees`);
|
|
26
|
+
const rows = r.worktrees.map((w) => ({
|
|
27
|
+
suggestion: w.suggestion, machine: w.machine.split("/")[0], path: w.path.replace(/^\/(Users|home)\/[^/]+\//, "~/"), branch: `${w.branch ?? "?"}${w.head ? `@${w.head}` : ""}`,
|
|
28
|
+
state: `${w.dirty === null ? "?" : w.dirty ? "dirty" : "clean"}, ${w.merged === null ? "?" : w.merged ? "merged" : `${w.ahead ?? "?"} ahead`}`,
|
|
29
|
+
idle: `${w.idle_days}d`, who: w.agents.map((a) => a.name).slice(0, 3).join(","), unit: w.unit ? `#${w.unit.number}` : "-",
|
|
30
|
+
}));
|
|
31
|
+
out.print(rows.length ? table(rows, ["suggestion", "machine", "path", "branch", "state", "idle", "who", "unit"]) : "(no worktrees recorded; agents register them by working, or run: bschat worktrees scan)", r);
|
|
32
|
+
}
|
|
33
|
+
/** Scan the repository at cwd and report it. Shared with the watcher, which runs it periodically. */
|
|
34
|
+
export async function scanProject(creds, project) {
|
|
35
|
+
const scan = scanWorktrees();
|
|
36
|
+
if (!scan)
|
|
37
|
+
throw new CliError("not_a_repo", "the current directory is not inside a git repository", "Run bschat worktrees scan from a checkout of the project's repository.");
|
|
38
|
+
const machine = creds.machine || defaultMachine();
|
|
39
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
40
|
+
const r = await client.call("POST", `/projects/${project}/worktrees/scan`, { machine, repo: scan.repo, worktrees: scan.worktrees });
|
|
41
|
+
return { machine, repo: scan.repo, recorded: r.recorded, missing: r.missing };
|
|
42
|
+
}
|
package/dist/commands/wu.js
CHANGED
|
@@ -2,7 +2,8 @@ import { str } from "../args.js";
|
|
|
2
2
|
import { Client } from "../client.js";
|
|
3
3
|
import { loadAgent, resolveAgentName, resolveModel } from "../config.js";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
|
-
import { branchAndHead, isAncestor } from "../git.js";
|
|
5
|
+
import { branchAndHead, commitAtTime, createWorktree, isAncestor, removeWorktreeIfClean, repoName, repoParent, worktreeForBranch } from "../git.js";
|
|
6
|
+
import { resolve } from "node:path";
|
|
6
7
|
import { table } from "../output.js";
|
|
7
8
|
/**
|
|
8
9
|
* Work units under the project's process. Work is described by tags from the project's
|
|
@@ -39,12 +40,13 @@ export async function wu(p, out) {
|
|
|
39
40
|
};
|
|
40
41
|
const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
|
|
41
42
|
const fmt = (u) => {
|
|
43
|
+
const flags = [u.assigned_by ? `assigned by ${u.assigned_by}` : null, u.replay_of ? "REPLAY" : null, u.trial_tags?.length ? `trial on ${u.trial_tags.map((t) => `#${t}`).join(" ")}` : null].filter(Boolean).join(" · ");
|
|
42
44
|
const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
|
|
43
45
|
const approvals = u.approvals.map((a) => a.name).join(", ");
|
|
44
46
|
return [
|
|
45
|
-
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}`,
|
|
47
|
+
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}`,
|
|
46
48
|
` owner ${u.owner_name}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
|
|
47
|
-
` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
|
|
49
|
+
` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.worktree ? ` in ${u.worktree.replace(/^\/(Users|home)\/[^/]+\//, "~/")}` : ""}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
|
|
48
50
|
u.scope ? ` scope: ${u.scope}` : null,
|
|
49
51
|
].filter(Boolean).join("\n");
|
|
50
52
|
};
|
|
@@ -54,10 +56,79 @@ export async function wu(p, out) {
|
|
|
54
56
|
const title = p.positionals.slice(2).join(" ").trim();
|
|
55
57
|
if (!title)
|
|
56
58
|
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--tags a,b] [--evidence id]');
|
|
57
|
-
const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), ...branchAndHead() });
|
|
59
|
+
const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), ...branchAndHead(), worktree: process.cwd() });
|
|
58
60
|
out.print(`${fmt(r.unit)}\nSubmit for review when ready: bschat wu submit ${r.unit.number} --evidence <id>`, r);
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
63
|
+
case "assign": {
|
|
64
|
+
// Dispatch as state: the unit exists from now, the worker is mentioned, the sweep chases it.
|
|
65
|
+
const title = p.positionals.slice(2).join(" ").trim();
|
|
66
|
+
const to = str(p.flags, "to");
|
|
67
|
+
if (!title || !to)
|
|
68
|
+
throw new CliError("usage", 'wu assign "<title>" --to <agent> --scope "<what it covers and does not>" [--tags a,b] [--evidence id] [--replay-of <n>]');
|
|
69
|
+
const replay = str(p.flags, "replay-of");
|
|
70
|
+
const r = await client.call("POST", `${base}/assign`, { to, title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), replay_of: replay ? Number(replay) : null, branch: str(p.flags, "branch") ?? null });
|
|
71
|
+
out.print(`${fmt(r.unit)}\nAssigned to ${to}; they start it with bschat wu start ${r.unit.number}.`, r);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
case "start": {
|
|
75
|
+
// One worktree per unit, made here. Exceptions are explicit and recorded: --branch continues
|
|
76
|
+
// existing work in its own worktree; --here uses the current checkout (single-agent repos).
|
|
77
|
+
const n = num();
|
|
78
|
+
const unit = (await client.call("GET", `${base}/${n}`)).unit;
|
|
79
|
+
const def = await processDef();
|
|
80
|
+
const target = def.merge.target_branch;
|
|
81
|
+
let mode;
|
|
82
|
+
let path;
|
|
83
|
+
let branch;
|
|
84
|
+
if (p.flags.here) {
|
|
85
|
+
mode = "here";
|
|
86
|
+
path = process.cwd();
|
|
87
|
+
branch = branchAndHead().branch;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const name = repoName();
|
|
91
|
+
const parent = repoParent();
|
|
92
|
+
if (!name || !parent)
|
|
93
|
+
throw new CliError("not_a_repo", "run wu start from a checkout of the project's repository (it creates your worktree next to it), or pass --here");
|
|
94
|
+
const pinned = str(p.flags, "branch") ?? unit.branch ?? null;
|
|
95
|
+
if (pinned) {
|
|
96
|
+
mode = "branch";
|
|
97
|
+
branch = pinned;
|
|
98
|
+
const existing = worktreeForBranch(pinned);
|
|
99
|
+
path = existing ?? resolve(parent, `${name}-wu${n}`);
|
|
100
|
+
if (!existing)
|
|
101
|
+
createWorktree(path, pinned, target);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
mode = "fresh";
|
|
105
|
+
const slug = String(unit.title).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40);
|
|
106
|
+
branch = `wu/${n}-${slug}`;
|
|
107
|
+
path = resolve(parent, `${name}-wu${n}`);
|
|
108
|
+
// A replay starts from the target branch as it was when the original was opened: the same ground, none of the original's work.
|
|
109
|
+
let baseRef = target;
|
|
110
|
+
if (unit.replay?.created_at) {
|
|
111
|
+
const at = commitAtTime(target, unit.replay.created_at);
|
|
112
|
+
if (!at)
|
|
113
|
+
throw new CliError("no_base", `cannot find ${target} as of ${unit.replay.created_at} for the replay`, `git fetch origin ${target}:${target} then try again`);
|
|
114
|
+
baseRef = at;
|
|
115
|
+
}
|
|
116
|
+
createWorktree(path, branch, baseRef);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const where = branchAndHead(path);
|
|
120
|
+
const r = await client.call("POST", `${base}/${n}/start`, { branch: branch ?? where.branch, head: where.head, worktree: path, mode });
|
|
121
|
+
out.print(`${fmt(r.unit)}\nYour worktree: ${path}${mode === "fresh" ? ` (new branch ${branch} from ${target}${unit.replay ? " as of the original" : ""})` : mode === "branch" ? ` (branch ${branch})` : " (this checkout)"}\n cd ${path}\nWork there. Submit when ready: bschat wu submit ${n} --evidence <id>`, { ...r, worktree: path, branch, mode });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
case "decline": {
|
|
125
|
+
const note = str(p.flags, "note");
|
|
126
|
+
if (!note)
|
|
127
|
+
throw new CliError("usage", 'wu decline <n> --note "why"');
|
|
128
|
+
const r = await client.call("POST", `${base}/${num()}/decline`, { note });
|
|
129
|
+
out.print(fmt(r.unit), r);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
61
132
|
case "submit": {
|
|
62
133
|
const def = await processDef();
|
|
63
134
|
const where = branchAndHead();
|
|
@@ -112,7 +183,20 @@ export async function wu(p, out) {
|
|
|
112
183
|
throw new CliError("usage", `this project's process requires the merge commit: bschat wu done ${num()} --merged <sha>`);
|
|
113
184
|
}
|
|
114
185
|
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
|
|
115
|
-
|
|
186
|
+
// The unit's worktree goes with it when it is clean and we are not standing in it.
|
|
187
|
+
let cleanup = "";
|
|
188
|
+
const wt = r.unit.worktree;
|
|
189
|
+
if (wt && !p.flags["keep-worktree"]) {
|
|
190
|
+
if (resolve(process.cwd()).startsWith(resolve(wt)))
|
|
191
|
+
cleanup = `\nWorktree ${wt} left in place (you are in it); remove it from elsewhere: git worktree remove ${wt}`;
|
|
192
|
+
else if (wt === repoParent() || worktreeForBranch(def.merge.target_branch) === wt)
|
|
193
|
+
cleanup = "";
|
|
194
|
+
else {
|
|
195
|
+
const res = removeWorktreeIfClean(wt);
|
|
196
|
+
cleanup = res.removed ? `\nRemoved worktree ${wt}.` : `\nWorktree ${wt} kept: ${res.reason}.`;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
out.print(fmt(r.unit) + cleanup, r);
|
|
116
200
|
return;
|
|
117
201
|
}
|
|
118
202
|
case "abandon": {
|
|
@@ -145,7 +229,7 @@ export async function wu(p, out) {
|
|
|
145
229
|
return;
|
|
146
230
|
}
|
|
147
231
|
default:
|
|
148
|
-
throw new CliError("usage", "wu open|submit|approve|changes|classify|tags|done|abandon|note|show|list");
|
|
232
|
+
throw new CliError("usage", "wu open|assign|start [--branch b|--here]|decline|submit|approve|changes|classify|tags|done [--keep-worktree]|abandon|note|show|list");
|
|
149
233
|
}
|
|
150
234
|
}
|
|
151
235
|
/** The project's process: the tag vocabulary, who reviews what, requirements, and the working agreements. */
|
|
@@ -175,3 +259,15 @@ export async function processCmd(p, out) {
|
|
|
175
259
|
if (creds.project && r.process.version > 0)
|
|
176
260
|
await client.call("POST", `/projects/${project}/process/ack`, { version: r.process.version });
|
|
177
261
|
}
|
|
262
|
+
/** Per agent per tag, what real units have shown. */
|
|
263
|
+
export async function record(p, out) {
|
|
264
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
265
|
+
const creds = loadAgent(name);
|
|
266
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
267
|
+
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
268
|
+
if (!project)
|
|
269
|
+
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
270
|
+
const r = await client.call("GET", `/projects/${project}/record`);
|
|
271
|
+
const rows = r.record.map((x) => ({ agent: x.agent, tag: `#${x.tag}`, done: x.units, "1st-round": x.approved_first_round, changes: x.changes_requested, replays: x.replays, reviewed: x.reviewed, overturned: x.overturned, escalated: x.escalated }));
|
|
272
|
+
out.print(rows.length ? table(rows, ["agent", "tag", "done", "1st-round", "changes", "replays", "reviewed", "overturned", "escalated"]) : "(no reviewed units yet)", r);
|
|
273
|
+
}
|
package/dist/git.js
CHANGED
|
@@ -13,13 +13,47 @@ export function collectAuto(opts) {
|
|
|
13
13
|
let branch = null;
|
|
14
14
|
let head = null;
|
|
15
15
|
let dirty = null;
|
|
16
|
+
let repo = null;
|
|
17
|
+
let base = null;
|
|
18
|
+
let merged = null;
|
|
19
|
+
let ahead = null;
|
|
16
20
|
if (worktree) {
|
|
17
21
|
branch = git(["symbolic-ref", "--short", "-q", "HEAD"], cwd) ?? git(["rev-parse", "--short", "HEAD"], cwd);
|
|
18
22
|
head = git(["rev-parse", "--short", "HEAD"], cwd);
|
|
19
23
|
const status = git(["status", "--porcelain"], cwd);
|
|
20
24
|
dirty = status === null ? null : status.length > 0;
|
|
25
|
+
({ repo, base, merged, ahead } = mergeFacts(cwd, worktree));
|
|
21
26
|
}
|
|
22
|
-
return { model: opts.model && opts.model.length > 0 ? opts.model : "unknown", machine: opts.machine, cwd, worktree, branch, head, dirty };
|
|
27
|
+
return { model: opts.model && opts.model.length > 0 ? opts.model : "unknown", machine: opts.machine, cwd, worktree, branch, head, dirty, repo, base, merged, ahead };
|
|
28
|
+
}
|
|
29
|
+
/** Where this worktree belongs and how it relates to the base branch. Local facts only; nothing is fetched. */
|
|
30
|
+
export function mergeFacts(cwd, worktree) {
|
|
31
|
+
const common = git(["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd);
|
|
32
|
+
const repo = common ? common.replace(/\/\.git$/, "") : worktree;
|
|
33
|
+
const base = ["main", "master"].find((b) => git(["rev-parse", "--verify", "-q", `${b}^{commit}`], cwd) !== null) ?? null;
|
|
34
|
+
if (!base)
|
|
35
|
+
return { repo, base: null, merged: null, ahead: null };
|
|
36
|
+
const merged = spawnSync("git", ["merge-base", "--is-ancestor", "HEAD", base], { cwd, stdio: "ignore" }).status === 0;
|
|
37
|
+
const count = git(["rev-list", "--count", `${base}..HEAD`], cwd);
|
|
38
|
+
return { repo, base, merged, ahead: count === null ? null : Number(count) };
|
|
39
|
+
}
|
|
40
|
+
/** Every linked worktree of the repository at cwd, with the same facts an agent call reports. */
|
|
41
|
+
export function scanWorktrees(cwd = process.cwd()) {
|
|
42
|
+
const list = git(["worktree", "list", "--porcelain"], cwd);
|
|
43
|
+
if (list === null)
|
|
44
|
+
return null;
|
|
45
|
+
const paths = list.split("\n").filter((l) => l.startsWith("worktree ")).map((l) => l.slice(9));
|
|
46
|
+
if (!paths.length)
|
|
47
|
+
return null;
|
|
48
|
+
const repo = paths[0];
|
|
49
|
+
const worktrees = paths.map((p) => {
|
|
50
|
+
const branch = git(["symbolic-ref", "--short", "-q", "HEAD"], p) ?? git(["rev-parse", "--short", "HEAD"], p);
|
|
51
|
+
const head = git(["rev-parse", "--short", "HEAD"], p);
|
|
52
|
+
const status = git(["status", "--porcelain"], p);
|
|
53
|
+
const f = head ? mergeFacts(p, p) : { base: null, merged: null, ahead: null };
|
|
54
|
+
return { path: p, branch, head, dirty: status === null ? null : status.length > 0, base: f.base, merged: f.merged, ahead: f.ahead };
|
|
55
|
+
});
|
|
56
|
+
return { repo, worktrees };
|
|
23
57
|
}
|
|
24
58
|
export function defaultMachine(label) {
|
|
25
59
|
const h = hostname();
|
|
@@ -37,3 +71,59 @@ export function branchAndHead(cwd = process.cwd()) {
|
|
|
37
71
|
const a = collectAuto({ model: undefined, machine: "", cwd });
|
|
38
72
|
return { branch: a.branch, head: a.head };
|
|
39
73
|
}
|
|
74
|
+
/** Repository name from its main worktree path, for naming sibling worktrees. */
|
|
75
|
+
export function repoName(cwd = process.cwd()) {
|
|
76
|
+
const common = git(["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd);
|
|
77
|
+
if (!common)
|
|
78
|
+
return null;
|
|
79
|
+
const root = common.replace(/\/\.git$/, "");
|
|
80
|
+
return root.split("/").pop() ?? null;
|
|
81
|
+
}
|
|
82
|
+
/** The main worktree's parent directory, where sibling worktrees live. */
|
|
83
|
+
export function repoParent(cwd = process.cwd()) {
|
|
84
|
+
const common = git(["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd);
|
|
85
|
+
if (!common)
|
|
86
|
+
return null;
|
|
87
|
+
const root = common.replace(/\/\.git$/, "");
|
|
88
|
+
return root.slice(0, root.lastIndexOf("/"));
|
|
89
|
+
}
|
|
90
|
+
/** Path of the worktree already checked out on `branch`, if any. */
|
|
91
|
+
export function worktreeForBranch(branch, cwd = process.cwd()) {
|
|
92
|
+
const list = git(["worktree", "list", "--porcelain"], cwd);
|
|
93
|
+
if (list === null)
|
|
94
|
+
return null;
|
|
95
|
+
let path = null;
|
|
96
|
+
for (const line of list.split("\n")) {
|
|
97
|
+
if (line.startsWith("worktree "))
|
|
98
|
+
path = line.slice(9);
|
|
99
|
+
else if (line === `branch refs/heads/${branch}` && path)
|
|
100
|
+
return path;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/** The newest commit on `ref` at or before `iso`, so a replay starts from what the original's author saw. */
|
|
105
|
+
export function commitAtTime(ref, iso, cwd = process.cwd()) {
|
|
106
|
+
return git(["rev-list", "-1", `--before=${iso}`, ref], cwd);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a worktree for a unit. `branch` is created from `base` unless it already exists, in
|
|
110
|
+
* which case it is checked out as is. Returns the path. Fails loudly: a half-made worktree is
|
|
111
|
+
* worse than none.
|
|
112
|
+
*/
|
|
113
|
+
export function createWorktree(path, branch, base, cwd = process.cwd()) {
|
|
114
|
+
const exists = git(["rev-parse", "--verify", "-q", `refs/heads/${branch}`], cwd) !== null;
|
|
115
|
+
const args = exists ? ["worktree", "add", path, branch] : ["worktree", "add", "-b", branch, path, base];
|
|
116
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
117
|
+
if (r.status !== 0)
|
|
118
|
+
throw new Error(`git ${args.join(" ")}: ${(r.stderr || r.stdout).trim()}`);
|
|
119
|
+
}
|
|
120
|
+
/** Removes a worktree only when it is clean; returns false when it is dirty or git refuses. */
|
|
121
|
+
export function removeWorktreeIfClean(path, cwd = process.cwd()) {
|
|
122
|
+
const status = git(["status", "--porcelain"], path);
|
|
123
|
+
if (status === null)
|
|
124
|
+
return { removed: false, reason: "not a worktree" };
|
|
125
|
+
if (status.length > 0)
|
|
126
|
+
return { removed: false, reason: "uncommitted changes" };
|
|
127
|
+
const r = spawnSync("git", ["worktree", "remove", path], { cwd, encoding: "utf8" });
|
|
128
|
+
return r.status === 0 ? { removed: true } : { removed: false, reason: (r.stderr || r.stdout).trim() };
|
|
129
|
+
}
|
package/dist/help.js
CHANGED
|
@@ -30,11 +30,19 @@ Agent commands
|
|
|
30
30
|
other channels appear as a one-line unread digest
|
|
31
31
|
bschat process the project's process: tag vocabulary, who reviews what, requirements, agreements
|
|
32
32
|
bschat wu open "<title>" --scope "..." [--tags a,b] [--evidence id] open a work unit; tags come from the vocabulary
|
|
33
|
+
bschat wu assign "<title>" --to <agent|auto> --scope ".." [--tags a,b] [--replay-of n] hand out a unit (assigner roles);
|
|
34
|
+
--to auto picks the active worker qualified for the tags with the lightest load;
|
|
35
|
+
it exists on the board as assigned and the sweep chases it; wu decline <n> --note
|
|
36
|
+
bschat wu start <n> [--branch b | --here] take it up: makes ../<repo>-wu<n> on branch wu/<n>-<slug> (replays: from the
|
|
37
|
+
target branch as of the original); --branch continues existing work; --here uses this checkout
|
|
38
|
+
bschat record per agent per tag: first-round approvals, changes, replays, reviews overturned
|
|
33
39
|
bschat wu submit <n> [--evidence id] [--pr url] ask for review; routed to whoever is qualified for the tags
|
|
34
40
|
bschat wu approve|changes <n> --note ".." your approval covers the tags your role reviews; classify <n> --tags a,b
|
|
35
41
|
bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
|
|
36
|
-
bschat wu done <n> --merged <sha>
|
|
42
|
+
bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies the sha is on the target; removes the unit's clean worktree
|
|
37
43
|
bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
|
|
44
|
+
bschat worktrees [scan] the project's worktree registry (machine, path, branch, dirty, merged, who);
|
|
45
|
+
scan reports every linked worktree of the repo you are in (watchers do this hourly)
|
|
38
46
|
bschat goal [set "<text>" [--state s] | achieved | paused | stalled | abandoned | clear]
|
|
39
47
|
report your harness's /goal so the board shows what you are held to (Codex app
|
|
40
48
|
threads and DeepSeek keep it where no file shows it; Claude Code's hook reads it itself)
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { item, list, lists } from "./commands/lists.js";
|
|
|
10
10
|
import { watch } from "./commands/watch.js";
|
|
11
11
|
import { feedback } from "./commands/feedback.js";
|
|
12
12
|
import { goal } from "./commands/goal.js";
|
|
13
|
-
import { processCmd, wu } from "./commands/wu.js";
|
|
13
|
+
import { processCmd, record, wu } from "./commands/wu.js";
|
|
14
|
+
import { worktrees } from "./commands/worktrees.js";
|
|
14
15
|
import { CliError } from "./errors.js";
|
|
15
16
|
import { HELP } from "./help.js";
|
|
16
17
|
import { CLI_VERSION } from "./version.js";
|
|
@@ -46,6 +47,8 @@ const COMMANDS = {
|
|
|
46
47
|
goal,
|
|
47
48
|
wu,
|
|
48
49
|
process: processCmd,
|
|
50
|
+
record,
|
|
51
|
+
worktrees,
|
|
49
52
|
follow: a.followCmd,
|
|
50
53
|
unfollow: a.followCmd,
|
|
51
54
|
following: a.followCmd,
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.2";
|