benignswarm 0.12.9 → 0.12.10
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/watch.js +12 -3
- package/dist/commands/worktrees.js +30 -2
- package/dist/commands/wu.js +135 -11
- package/dist/git.js +54 -0
- package/dist/help.js +12 -1
- package/dist/index.js +3 -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", "to", "replay-of", "branch", "effort", "by"];
|
|
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"];
|
|
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", "effort", "by", "target", "milestone", "file"];
|
|
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", "prune", "abandon"];
|
|
5
5
|
export function parse(argv) {
|
|
6
6
|
const options = {};
|
|
7
7
|
for (const f of STRING_FLAGS)
|
package/dist/commands/watch.js
CHANGED
|
@@ -7,6 +7,7 @@ import { loadAgent, resolveAgentName } from "../config.js";
|
|
|
7
7
|
import { Client } from "../client.js";
|
|
8
8
|
import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
|
|
9
9
|
import { scanProject } from "./worktrees.js";
|
|
10
|
+
import { prunableWorktrees, removeWorktreeIfClean } from "../git.js";
|
|
10
11
|
import { CliError } from "../errors.js";
|
|
11
12
|
import { acquireWatchLock } from "../lock.js";
|
|
12
13
|
import { gatherUpdates } from "./hook.js";
|
|
@@ -47,7 +48,7 @@ export async function watch(p, out) {
|
|
|
47
48
|
throw new CliError("usage", `--env ${n}: not set in this shell; run this from a terminal inside the harness (Antigravity's terminal has ANTIGRAVITY_LS_ADDRESS and ANTIGRAVITY_CSRF_TOKEN)`);
|
|
48
49
|
extraEnv[n] = v;
|
|
49
50
|
}
|
|
50
|
-
return installLaunchd(name, exec, interval, followDelay, extraEnv, str(p.flags, "activity"), out);
|
|
51
|
+
return installLaunchd(name, exec, interval, followDelay, extraEnv, str(p.flags, "activity"), out, bool(p.flags, "prune"));
|
|
51
52
|
}
|
|
52
53
|
if (!exec && !once)
|
|
53
54
|
throw new CliError("usage", 'watch --exec "<command>" [--interval 30] | watch --once (print and exit) | watch --exec ... --launchd');
|
|
@@ -83,6 +84,13 @@ export async function watch(p, out) {
|
|
|
83
84
|
try {
|
|
84
85
|
const r = await scanProject(scanCreds, scanCreds.project);
|
|
85
86
|
log(`worktree scan: ${r.recorded} in ${r.repo}${r.missing ? `, ${r.missing} gone` : ""}`);
|
|
87
|
+
if (bool(p.flags, "prune")) {
|
|
88
|
+
// Space back on a schedule: only clean, merged worktrees; never the one a unit is being worked in (dirty or ahead).
|
|
89
|
+
for (const c of prunableWorktrees()) {
|
|
90
|
+
const res = removeWorktreeIfClean(c.path);
|
|
91
|
+
log(res.removed ? `pruned merged worktree ${c.path}${c.branch ? ` (${c.branch})` : ""}` : `kept ${c.path}: ${res.reason}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
86
94
|
}
|
|
87
95
|
catch (e) {
|
|
88
96
|
log(`worktree scan skipped: ${e.message}`);
|
|
@@ -220,7 +228,7 @@ function run(cmd, stdin, env) {
|
|
|
220
228
|
});
|
|
221
229
|
}
|
|
222
230
|
/** Writes a launchd agent that keeps `bschat watch` running for this identity on macOS. */
|
|
223
|
-
function installLaunchd(name, exec, interval, followDelay, extraEnv, activity, out) {
|
|
231
|
+
function installLaunchd(name, exec, interval, followDelay, extraEnv, activity, out, prune = false) {
|
|
224
232
|
if (process.platform !== "darwin")
|
|
225
233
|
throw new CliError("unsupported", "--launchd is macOS only; on Linux run `bschat watch` under a systemd user service");
|
|
226
234
|
const slug = name.replace("/", ".");
|
|
@@ -246,7 +254,8 @@ function installLaunchd(name, exec, interval, followDelay, extraEnv, activity, o
|
|
|
246
254
|
<string>--exec</string><string>${escapeXml(exec)}</string>
|
|
247
255
|
<string>--interval</string><string>${interval}</string>
|
|
248
256
|
<string>--follow-delay</string><string>${followDelay}</string>${activity ? `
|
|
249
|
-
<string>--activity</string><string>${escapeXml(activity)}</string>` : ""}
|
|
257
|
+
<string>--activity</string><string>${escapeXml(activity)}</string>` : ""}${prune ? `
|
|
258
|
+
<string>--prune</string>` : ""}
|
|
250
259
|
</array>
|
|
251
260
|
<key>EnvironmentVariables</key><dict><key>PATH</key><string>${escapeXml(process.env.PATH ?? "/usr/local/bin:/usr/bin:/bin")}</string><key>HOME</key><string>${homedir()}</string>${Object.entries(extraEnv).map(([k, v]) => `<key>${escapeXml(k)}</key><string>${escapeXml(v)}</string>`).join("")}</dict>
|
|
252
261
|
<key>WorkingDirectory</key><string>${escapeXml(process.cwd())}</string>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { str } from "../args.js";
|
|
1
|
+
import { str, bool } from "../args.js";
|
|
2
2
|
import { Client } from "../client.js";
|
|
3
3
|
import { loadAgent, resolveAgentName } from "../config.js";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
|
-
import { defaultMachine, scanWorktrees } from "../git.js";
|
|
5
|
+
import { defaultMachine, scanWorktrees, prunableWorktrees, removeWorktreeIfClean } from "../git.js";
|
|
6
6
|
import { table } from "../output.js";
|
|
7
7
|
/**
|
|
8
8
|
* The project's worktree registry.
|
|
@@ -16,6 +16,34 @@ export async function worktrees(p, out) {
|
|
|
16
16
|
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
17
17
|
if (!project)
|
|
18
18
|
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
19
|
+
if (sub === "prune") {
|
|
20
|
+
// Space back: delete linked worktrees that are clean and merged into the base branch. Dry run
|
|
21
|
+
// unless --yes. Branches are kept (deleting a worktree never deletes its branch).
|
|
22
|
+
const candidates = prunableWorktrees();
|
|
23
|
+
if (!candidates.length) {
|
|
24
|
+
out.print("(no clean, merged worktrees to remove)", { removed: [], candidates: [] });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!bool(p.flags, "yes")) {
|
|
28
|
+
out.print(`${candidates.length} clean, merged worktree(s) would be removed (run again with --yes):\n${candidates.map((c) => ` ${c.path}${c.branch ? ` (${c.branch})` : ""}`).join("\n")}`, { removed: [], candidates });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const removed = [];
|
|
32
|
+
const kept = [];
|
|
33
|
+
for (const c of candidates) {
|
|
34
|
+
const r = removeWorktreeIfClean(c.path);
|
|
35
|
+
if (r.removed)
|
|
36
|
+
removed.push(c.path);
|
|
37
|
+
else
|
|
38
|
+
kept.push({ path: c.path, reason: r.reason ?? "git refused" });
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await scanProject(creds, project);
|
|
42
|
+
}
|
|
43
|
+
catch { /* the registry catches up on the next scan */ }
|
|
44
|
+
out.print(`Removed ${removed.length} worktree(s)${removed.length ? `:\n${removed.map((r) => ` ${r}`).join("\n")}` : ""}${kept.length ? `\nKept ${kept.length}: ${kept.map((k) => `${k.path} (${k.reason})`).join("; ")}` : ""}`, { removed, kept, candidates });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
19
47
|
if (sub === "scan") {
|
|
20
48
|
const r = await scanProject(creds, project);
|
|
21
49
|
out.print(`Reported ${r.recorded} worktree(s) of ${r.repo} on ${r.machine}${r.missing ? `; ${r.missing} previously known worktree(s) are gone` : ""}.`, r);
|
package/dist/commands/wu.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { str } from "../args.js";
|
|
2
3
|
import { Client } from "../client.js";
|
|
3
4
|
import { loadAgent, resolveAgentName, resolveModel } from "../config.js";
|
|
4
5
|
import { CliError } from "../errors.js";
|
|
5
|
-
import { branchAndHead, commitAtTime, ensureWorktree, isAncestor, removeWorktreeIfClean, repoName, repoParent, worktreeForBranch } from "../git.js";
|
|
6
|
+
import { branchAndHead, commitAtTime, ensureReviewWorktree, ensureWorktree, fetchRef, fullSha, isAncestor, remoteHead, removeWorktreeIfClean, repoName, repoParent, worktreeForBranch } from "../git.js";
|
|
6
7
|
import { resolve } from "node:path";
|
|
7
8
|
import { table } from "../output.js";
|
|
8
9
|
/**
|
|
@@ -40,7 +41,7 @@ export async function wu(p, out) {
|
|
|
40
41
|
};
|
|
41
42
|
const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
|
|
42
43
|
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(" · ");
|
|
44
|
+
const flags = [u.assigned_by ? `assigned by ${u.assigned_by}` : null, u.milestone ? `milestone ${u.milestone}` : null, u.target ? `lands in ${u.target}` : null, u.replay_of ? "REPLAY" : null, u.trial_tags?.length ? `trial on ${u.trial_tags.map((t) => `#${t}`).join(" ")}` : null].filter(Boolean).join(" · ");
|
|
44
45
|
const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
|
|
45
46
|
const approvals = u.approvals.map((a) => a.name).join(", ");
|
|
46
47
|
return [
|
|
@@ -58,7 +59,7 @@ export async function wu(p, out) {
|
|
|
58
59
|
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--tags a,b] [--evidence id]');
|
|
59
60
|
// The unit exists first (it needs its number for the branch name), then its worktree is made
|
|
60
61
|
// and recorded exactly as `wu start` would; --here keeps the current checkout.
|
|
61
|
-
const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), ...branchAndHead(), worktree: process.cwd() });
|
|
62
|
+
const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), ...branchAndHead(), worktree: process.cwd(), target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null });
|
|
62
63
|
const n = r.unit.number;
|
|
63
64
|
const { path, branch, mode } = prepareWorktree(n, r.unit, await processDef(), p);
|
|
64
65
|
const where = branchAndHead(path);
|
|
@@ -73,7 +74,7 @@ export async function wu(p, out) {
|
|
|
73
74
|
if (!title || !to)
|
|
74
75
|
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--tags a,b] [--evidence id] [--replay-of <n>]');
|
|
75
76
|
const replay = str(p.flags, "replay-of");
|
|
76
|
-
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 });
|
|
77
|
+
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, target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null });
|
|
77
78
|
out.print(`${fmt(r.unit)}\n${r.unit.status === "queued" ? `Queued: nobody qualified is free; it goes to the first qualified worker with capacity (or bschat wu take ${r.unit.number} --to <agent>).` : `Assigned to ${r.unit.owner_name}; they start it with bschat wu start ${r.unit.number}.`}`, r);
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
@@ -97,7 +98,7 @@ export async function wu(p, out) {
|
|
|
97
98
|
const n = num();
|
|
98
99
|
const unit = (await client.call("GET", `${base}/${n}`)).unit;
|
|
99
100
|
const def = await processDef();
|
|
100
|
-
const target = def.merge.target_branch;
|
|
101
|
+
const target = unit.target ?? def.merge.target_branch;
|
|
101
102
|
const { path, branch, mode } = prepareWorktree(n, unit, def, p);
|
|
102
103
|
const where = branchAndHead(path);
|
|
103
104
|
const r = await client.call("POST", `${base}/${n}/start`, { branch: branch ?? where.branch, head: where.head, worktree: path, mode });
|
|
@@ -115,16 +116,26 @@ export async function wu(p, out) {
|
|
|
115
116
|
case "submit": {
|
|
116
117
|
const def = await processDef();
|
|
117
118
|
const where = branchAndHead();
|
|
119
|
+
const unitTarget = (await client.call("GET", `${base}/${num()}`)).unit.target ?? def.merge.target_branch;
|
|
118
120
|
let rebased = null;
|
|
119
121
|
// The rebase requirement may come from the project or from a tag; the server tells us which
|
|
120
122
|
// when it refuses. Check locally whenever we are in a repo so the claim is always a finding.
|
|
123
|
+
let pushed = null;
|
|
121
124
|
if (where.head) {
|
|
122
|
-
rebased = isAncestor(
|
|
125
|
+
rebased = isAncestor(unitTarget, "HEAD");
|
|
123
126
|
if (rebased === null)
|
|
124
127
|
rebased = null;
|
|
128
|
+
// Pushed means the remote branch is at this exact head: what a reviewer elsewhere can fetch.
|
|
129
|
+
if (where.branch) {
|
|
130
|
+
const remote = remoteHead(where.branch);
|
|
131
|
+
const local = fullSha("HEAD");
|
|
132
|
+
pushed = remote === null ? (fetchRef(where.branch) ? false : null) : remote === local;
|
|
133
|
+
if (pushed === false && def.merge.require_pushed)
|
|
134
|
+
throw new CliError("not_pushed", `${where.branch} is not pushed at ${local?.slice(0, 9)} (origin has ${remote ? remote.slice(0, 9) : "no such branch"})`, `git push -u origin ${where.branch}, then submit again`);
|
|
135
|
+
}
|
|
125
136
|
}
|
|
126
137
|
const pr = str(p.flags, "pr") ?? null;
|
|
127
|
-
const r = await client.call("POST", `${base}/${num()}/submit`, { evidence: list("evidence"), ...where, pr_url: pr, rebased });
|
|
138
|
+
const r = await client.call("POST", `${base}/${num()}/submit`, { evidence: list("evidence"), ...where, pr_url: pr, rebased, pushed });
|
|
128
139
|
const u = r.unit;
|
|
129
140
|
out.print(`${fmt(u)}\n${u.status === "classifying" ? `Waiting for ${u.reviewers[0]?.name} to classify it.` : `Routed to ${u.reviewers.map((x) => `@${x.name}`).join(", ")}; you will be told in chat when it is reviewed.`}`, r);
|
|
130
141
|
return;
|
|
@@ -155,12 +166,17 @@ export async function wu(p, out) {
|
|
|
155
166
|
case "done": {
|
|
156
167
|
const def = await processDef();
|
|
157
168
|
const merged = str(p.flags, "merged") ?? null;
|
|
169
|
+
const landsIn = (await client.call("GET", `${base}/${num()}`)).unit.target ?? def.merge.target_branch;
|
|
158
170
|
if (merged) {
|
|
159
|
-
|
|
171
|
+
// Where pushes are required the remote target is the truth, not this machine's copy of it.
|
|
172
|
+
const target = def.merge.require_pushed ? (fetchRef(landsIn) ? `origin/${landsIn}` : null) : landsIn;
|
|
173
|
+
if (target === null)
|
|
174
|
+
throw new CliError("no_remote", `cannot fetch origin/${landsIn}; this project requires merges to be on the remote`, "Check the remote is reachable and try again.");
|
|
175
|
+
const on = isAncestor(merged, target);
|
|
160
176
|
if (on === null)
|
|
161
|
-
throw new CliError("unknown_commit", `cannot verify ${merged} against ${
|
|
177
|
+
throw new CliError("unknown_commit", `cannot verify ${merged} against ${target} in this repository`, `Run from the repo with ${landsIn} fetched: git fetch origin ${landsIn}:${landsIn}`);
|
|
162
178
|
if (!on)
|
|
163
|
-
throw new CliError("not_merged", `${merged} is not on ${def.merge.
|
|
179
|
+
throw new CliError("not_merged", `${merged} is not on ${target}`, def.merge.require_pushed ? "Merge and push the target branch first, then pass the merge commit." : "Merge first, then pass the merge commit (or the branch head once it is on the target).");
|
|
164
180
|
}
|
|
165
181
|
else if (def.merge.require_merge_commit) {
|
|
166
182
|
throw new CliError("usage", `this project's process requires the merge commit: bschat wu done ${num()} --merged <sha>`);
|
|
@@ -192,6 +208,49 @@ export async function wu(p, out) {
|
|
|
192
208
|
out.print(fmt(r.unit), r);
|
|
193
209
|
return;
|
|
194
210
|
}
|
|
211
|
+
case "milestone": {
|
|
212
|
+
// Move the unit into a plan slice (or out with "none"); the slice must be ready.
|
|
213
|
+
const k = p.positionals[3];
|
|
214
|
+
if (!k)
|
|
215
|
+
throw new CliError("usage", "wu milestone <n> <key|none>");
|
|
216
|
+
const r = await client.call("POST", `${base}/${num()}/milestone`, { milestone: k === "none" ? null : k });
|
|
217
|
+
out.print(fmt(r.unit), r);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
case "target": {
|
|
221
|
+
// Move where the unit lands, before review. "default" restores the process target.
|
|
222
|
+
const t = p.positionals[3];
|
|
223
|
+
if (!t)
|
|
224
|
+
throw new CliError("usage", "wu target <n> <branch|default>");
|
|
225
|
+
const r = await client.call("POST", `${base}/${num()}/target`, { target: t === "default" ? null : t });
|
|
226
|
+
out.print(fmt(r.unit), r);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
case "review": {
|
|
230
|
+
// The reviewer's checkout: the submitted commit, fetched from the remote, in its own worktree.
|
|
231
|
+
const n = num();
|
|
232
|
+
const unit = (await client.call("GET", `${base}/${n}`)).unit;
|
|
233
|
+
if (!unit.branch)
|
|
234
|
+
throw new CliError("no_branch", `WU #${n} has no branch recorded; ask ${unit.owner_name} to submit from the branch`);
|
|
235
|
+
if (!unit.head)
|
|
236
|
+
throw new CliError("no_head", `WU #${n} has no head recorded`);
|
|
237
|
+
const name = repoName();
|
|
238
|
+
const parent = repoParent();
|
|
239
|
+
if (!name || !parent)
|
|
240
|
+
throw new CliError("not_a_repo", "run wu review from a checkout of the project's repository");
|
|
241
|
+
if (!fetchRef(unit.branch))
|
|
242
|
+
throw new CliError("fetch_failed", `cannot fetch ${unit.branch} from origin`, `Is it pushed? Ask ${unit.owner_name}: git push -u origin ${unit.branch}`);
|
|
243
|
+
const remote = fullSha("FETCH_HEAD");
|
|
244
|
+
if (!remote)
|
|
245
|
+
throw new CliError("fetch_failed", `fetched ${unit.branch} but found no commit`);
|
|
246
|
+
if (!remote.startsWith(unit.head))
|
|
247
|
+
throw new CliError("head_mismatch", `origin/${unit.branch} is at ${remote.slice(0, 9)} but WU #${n} was submitted at ${unit.head}`, `Either the owner pushed more since submitting (ask for a resubmit) or has not pushed the submitted commit.`);
|
|
248
|
+
const path = resolve(parent, `${name}-review-wu${n}`);
|
|
249
|
+
const made = ensureReviewWorktree(path, remote);
|
|
250
|
+
const ev = unit.evidence.map((e) => `evidence:${e}`).join(" ") || "(none)";
|
|
251
|
+
out.print(`${fmt(unit)}\nReview checkout: ${path} (detached at ${remote.slice(0, 9)}${made.created ? "" : ", already there"})\n cd ${path}\nEvidence: ${ev} (bschat evidence get <id>)\nVerdict: bschat wu approve ${n} --note "..." | bschat wu changes ${n} --note "..."\nWhen finished: git worktree remove ${path}`, { unit, worktree: path, head: remote });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
195
254
|
case "show": {
|
|
196
255
|
const r = await client.call("GET", `${base}/${num()}`);
|
|
197
256
|
const events = r.events.map((e) => ` ${e.at.slice(0, 16).replace("T", " ")} ${e.type.padEnd(18)} ${e.actor_name}${e.note ? `: ${e.note}` : ""}${e.data?.to && Array.isArray(e.data.to) ? ` -> ${e.data.to.join(", ")}` : ""}`).join("\n");
|
|
@@ -248,7 +307,10 @@ export async function processCmd(p, out) {
|
|
|
248
307
|
* continues existing work in its own worktree; --here uses the current checkout (single-agent repos).
|
|
249
308
|
*/
|
|
250
309
|
function prepareWorktree(n, unit, def, p) {
|
|
251
|
-
|
|
310
|
+
// The unit's own target when it has one: a lane or release branch the work lands in.
|
|
311
|
+
const target = unit.target ?? def.merge.target_branch;
|
|
312
|
+
if (!p.flags.here && fullSha(target) === null && !(fetchRef(target) && fullSha(`origin/${target}`) !== null))
|
|
313
|
+
throw new CliError("no_target", `the unit lands in ${target}, which this repository does not have`, `git fetch origin ${target}:${target} then try again`);
|
|
252
314
|
const log = (line) => process.stderr.write(`bschat: ${line}\n`);
|
|
253
315
|
if (p.flags.here)
|
|
254
316
|
return { mode: "here", path: process.cwd(), branch: branchAndHead().branch };
|
|
@@ -278,6 +340,68 @@ function prepareWorktree(n, unit, def, p) {
|
|
|
278
340
|
ensureWorktree(path, branch, baseRef, process.cwd(), log);
|
|
279
341
|
return { mode: "fresh", path, branch };
|
|
280
342
|
}
|
|
343
|
+
/** The plan's slices: readiness, dependencies, unit counts. */
|
|
344
|
+
export async function milestones(p, out) {
|
|
345
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
346
|
+
const creds = loadAgent(name);
|
|
347
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
348
|
+
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
349
|
+
if (!project)
|
|
350
|
+
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
351
|
+
if (p.positionals[1] === "set") {
|
|
352
|
+
// Define or replace the plan: a JSON list [{key, title, exit?, depends_on?}] from --file or stdin.
|
|
353
|
+
// Existing keys keep their status; the server refuses cycles, unknown dependencies and removing a key with units.
|
|
354
|
+
const file = str(p.flags, "file");
|
|
355
|
+
const text = file ? readFileSync(file, "utf8") : readFileSync(0, "utf8");
|
|
356
|
+
let list;
|
|
357
|
+
try {
|
|
358
|
+
list = JSON.parse(text);
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
throw new CliError("bad_json", `${file ?? "stdin"} is not JSON`, 'Expected [{"key":"p0","title":"...","exit":"...","depends_on":["..."]}, ...]');
|
|
362
|
+
}
|
|
363
|
+
const r = await client.call("PUT", `/projects/${project}/milestones`, { milestones: list });
|
|
364
|
+
out.print(`${r.milestones.length} milestone(s) defined: ${r.milestones.map((m) => `${m.key}${m.status !== "open" ? ` (${m.status})` : m.ready ? "" : ` (waits on ${m.waiting_on.join(",")})`}`).join(", ")}`, r);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const r = await client.call("GET", `/projects/${project}/milestones`);
|
|
368
|
+
const rows = r.milestones.map((m) => ({ key: m.key, status: m.status === "open" ? (m.ready ? "ready" : `waits on ${m.waiting_on.join(",")}`) : m.status, units: `${m.units.done}/${m.units.total}${m.units.queued ? ` (+${m.units.queued} queued)` : ""}`, "depends on": m.depends_on.join(",") || "-", title: m.title.slice(0, 50) }));
|
|
369
|
+
out.print(rows.length ? `${table(rows, ["key", "status", "units", "depends on", "title"])}\nbschat milestone show <key> for the exit criterion; wu open/assign --milestone <key> puts a unit on one.` : "(no milestones defined; the operator or an assigner defines them on the Process page or with bschat milestone set)", r);
|
|
370
|
+
}
|
|
371
|
+
/** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon] | milestone reopen <key> */
|
|
372
|
+
export async function milestone(p, out) {
|
|
373
|
+
const name = resolveAgentName(str(p.flags, "as"));
|
|
374
|
+
const creds = loadAgent(name);
|
|
375
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
376
|
+
const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
377
|
+
if (!project)
|
|
378
|
+
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
|
|
379
|
+
const sub = p.positionals[1];
|
|
380
|
+
const key = p.positionals[2];
|
|
381
|
+
if (!key)
|
|
382
|
+
throw new CliError("usage", 'milestone show <key> | milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon] | milestone reopen <key>');
|
|
383
|
+
if (sub === "show") {
|
|
384
|
+
const m = (await client.call("GET", `/projects/${project}/milestones`)).milestones.find((x) => x.key === key);
|
|
385
|
+
if (!m)
|
|
386
|
+
throw new CliError("not_found", `no milestone ${key}`);
|
|
387
|
+
out.print(`${m.key}: ${m.title} [${m.status}${m.status === "open" && !m.ready ? `, waits on ${m.waiting_on.join(", ")}` : ""}]\n depends on: ${m.depends_on.join(", ") || "-"}\n units: ${m.units.done} done, ${m.units.open} open, ${m.units.queued} queued of ${m.units.total}\n exit: ${m.exit || "(not written)"}${m.closed_at ? `\n closed ${m.closed_at} by ${m.closed_by}: ${m.closed_note}${m.evidence.length ? ` (${m.evidence.map((e) => `evidence:${e}`).join(" ")})` : ""}` : ""}`, m);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (sub === "close") {
|
|
391
|
+
const note = str(p.flags, "note");
|
|
392
|
+
if (!note)
|
|
393
|
+
throw new CliError("usage", 'milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon]');
|
|
394
|
+
const r = await client.call("POST", `/projects/${project}/milestones/${key}/close`, { how: p.flags.abandon ? "abandoned" : "done", note, evidence: (str(p.flags, "evidence") ?? "").split(",").map((s) => s.trim()).filter(Boolean) });
|
|
395
|
+
out.print(`Milestone ${r.milestone.key} ${r.milestone.status}.`, r);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (sub === "reopen") {
|
|
399
|
+
const r = await client.call("POST", `/projects/${project}/milestones/${key}/reopen`, {});
|
|
400
|
+
out.print(`Milestone ${r.milestone.key} reopened.`, r);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
throw new CliError("usage", "milestone <show|close|reopen> <key>");
|
|
404
|
+
}
|
|
281
405
|
export async function record(p, out) {
|
|
282
406
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
283
407
|
const creds = loadAgent(name);
|
package/dist/git.js
CHANGED
|
@@ -188,6 +188,60 @@ export function ensureWorktree(path, branch, base, cwd = process.cwd(), log = ()
|
|
|
188
188
|
createWorktree(path, branch, base, cwd);
|
|
189
189
|
return { created: true, repaired };
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Linked worktrees of the repository at cwd that are safe to delete: clean, fully merged into
|
|
193
|
+
* the base branch, not the main worktree and not the one we are standing in. Dirty or unmerged
|
|
194
|
+
* worktrees are never candidates, whatever their age.
|
|
195
|
+
*/
|
|
196
|
+
export function prunableWorktrees(cwd = process.cwd()) {
|
|
197
|
+
const scan = scanWorktrees(cwd);
|
|
198
|
+
if (!scan)
|
|
199
|
+
return [];
|
|
200
|
+
const here = realpathOrSelf(cwd);
|
|
201
|
+
return scan.worktrees
|
|
202
|
+
.filter((w) => realpathOrSelf(w.path) !== realpathOrSelf(scan.repo) && !here.startsWith(realpathOrSelf(w.path)))
|
|
203
|
+
.filter((w) => w.dirty === false && w.merged === true)
|
|
204
|
+
.map((w) => ({ path: w.path, branch: w.branch }));
|
|
205
|
+
}
|
|
206
|
+
/** The remote's current head for a branch, asked of the remote itself; null when there is no remote or it cannot be reached. */
|
|
207
|
+
export function remoteHead(branch, remote = "origin", cwd = process.cwd()) {
|
|
208
|
+
const r = spawnSync("git", ["ls-remote", "--heads", remote, branch], { cwd, encoding: "utf8", timeout: 30_000 });
|
|
209
|
+
if (r.status !== 0)
|
|
210
|
+
return null;
|
|
211
|
+
const line = r.stdout.split("\n").find((l) => l.trim().endsWith(`refs/heads/${branch}`));
|
|
212
|
+
return line ? line.split(/\s+/)[0] : null;
|
|
213
|
+
}
|
|
214
|
+
/** Full sha of a local ref, or null. */
|
|
215
|
+
export function fullSha(ref, cwd = process.cwd()) {
|
|
216
|
+
return git(["rev-parse", "--verify", "-q", `${ref}^{commit}`], cwd);
|
|
217
|
+
}
|
|
218
|
+
/** `git fetch <remote> <ref>`; false when the fetch fails (no remote, unreachable, no such ref). */
|
|
219
|
+
export function fetchRef(ref, remote = "origin", cwd = process.cwd()) {
|
|
220
|
+
return spawnSync("git", ["fetch", "--quiet", remote, ref], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A worktree detached at exactly `sha`, for reading someone else's submission: made if absent,
|
|
224
|
+
* reused if it is already at that commit, refused if it is at something else or dirty.
|
|
225
|
+
*/
|
|
226
|
+
export function ensureReviewWorktree(path, sha, cwd = process.cwd()) {
|
|
227
|
+
const st = worktreeState(path, cwd);
|
|
228
|
+
if (st.state === "foreign")
|
|
229
|
+
throw new Error(`${path} exists but is not a worktree of this repository`);
|
|
230
|
+
if (st.state === "ready") {
|
|
231
|
+
const at = fullSha("HEAD", path);
|
|
232
|
+
if (at !== sha)
|
|
233
|
+
throw new Error(`${path} is at ${at?.slice(0, 9) ?? "?"}, not the submitted ${sha.slice(0, 9)}; remove it (git worktree remove ${path}) and run again`);
|
|
234
|
+
if ((git(["status", "--porcelain"], path) ?? "").length)
|
|
235
|
+
throw new Error(`${path} has local changes; a review checkout must stay clean`);
|
|
236
|
+
return { created: false };
|
|
237
|
+
}
|
|
238
|
+
if (st.state === "partial")
|
|
239
|
+
spawnSync("git", ["worktree", "remove", "--force", "--force", path], { cwd, encoding: "utf8" });
|
|
240
|
+
const r = spawnSync("git", ["worktree", "add", "--detach", path, sha], { cwd, encoding: "utf8" });
|
|
241
|
+
if (r.status !== 0)
|
|
242
|
+
throw new Error(`git worktree add --detach ${path} ${sha.slice(0, 9)}: ${(r.stderr || r.stdout).trim()}`);
|
|
243
|
+
return { created: true };
|
|
244
|
+
}
|
|
191
245
|
/** Removes a worktree only when it is clean; returns false when it is dirty or git refuses. */
|
|
192
246
|
export function removeWorktreeIfClean(path, cwd = process.cwd()) {
|
|
193
247
|
const status = git(["status", "--porcelain"], path);
|
package/dist/help.js
CHANGED
|
@@ -29,7 +29,9 @@ Agent commands
|
|
|
29
29
|
bschat follow <channel> | unfollow <channel> | following followed channels' new messages are injected by the hook;
|
|
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
|
-
bschat wu open "<title>" --scope "..." [--tags a,b] [--evidence id] [--here] open a work unit in its own
|
|
32
|
+
bschat wu open "<title>" --scope "..." [--tags a,b] [--evidence id] [--target <branch>] [--here] open a work unit in its own
|
|
33
|
+
worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
|
|
34
|
+
process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
|
|
33
35
|
bschat wu assign "<title>" --to <agent|auto|queue> --scope ".." [--tags a,b] [--replay-of n] hand out a unit (assigner roles);
|
|
34
36
|
auto queues it when nobody qualified is free; queue waits deliberately
|
|
35
37
|
bschat wu take <n> [--to <agent>] pull a queued unit for yourself (qualified by works or trial), or hand it to someone
|
|
@@ -42,12 +44,21 @@ Agent commands
|
|
|
42
44
|
target branch as of the original); --branch continues existing work; --here uses this checkout
|
|
43
45
|
bschat record per agent per tag: first-round approvals, changes, replays, reviews overturned
|
|
44
46
|
bschat record --by model the same, keyed by model and effort setting (stamped on start and on each verdict)
|
|
47
|
+
bschat milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
|
|
48
|
+
bschat milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
|
|
49
|
+
{key, title, exit, depends_on}; existing keys keep their status; cycles are refused
|
|
50
|
+
bschat milestone show <key> exit criterion, dependencies, counts; wu milestone <n> <key|none> moves a unit
|
|
51
|
+
bschat milestone close <key> --note ".." [--evidence a,b] [--abandon] the lead closes a slice against its exit criterion
|
|
52
|
+
(refused while it has units not done); milestone reopen <key> undoes it
|
|
45
53
|
Global: --effort <high|medium|low|...> reasoning effort to report (else BSCHAT_EFFORT, CLAUDE_EFFORT, codex model_reasoning_effort)
|
|
46
54
|
bschat wu submit <n> [--evidence id] [--pr url] ask for review; routed to whoever is qualified for the tags
|
|
55
|
+
bschat wu review <n> reviewer's checkout: fetch the submitted branch from origin and open
|
|
56
|
+
../<repo>-review-wu<n> detached at the submitted head (refused if origin differs)
|
|
47
57
|
bschat wu approve|changes <n> --note ".." your approval covers the tags your role reviews; classify <n> --tags a,b
|
|
48
58
|
bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
|
|
49
59
|
bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies the sha is on the target; removes the unit's clean worktree
|
|
50
60
|
bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
|
|
61
|
+
bschat worktrees prune [--yes] remove linked worktrees that are clean and merged into the base (dry run without --yes)
|
|
51
62
|
bschat worktrees [scan] the project's worktree registry (machine, path, branch, dirty, merged, who);
|
|
52
63
|
scan reports every linked worktree of the repo you are in (watchers do this hourly)
|
|
53
64
|
bschat goal [set "<text>" [--state s] | achieved | paused | stalled | abandoned | clear]
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ 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, record, wu } from "./commands/wu.js";
|
|
13
|
+
import { processCmd, record, wu, milestones, milestone } from "./commands/wu.js";
|
|
14
14
|
import { worktrees } from "./commands/worktrees.js";
|
|
15
15
|
import { CliError } from "./errors.js";
|
|
16
16
|
import { HELP } from "./help.js";
|
|
@@ -49,6 +49,8 @@ const COMMANDS = {
|
|
|
49
49
|
wu,
|
|
50
50
|
process: processCmd,
|
|
51
51
|
record,
|
|
52
|
+
milestones,
|
|
53
|
+
milestone,
|
|
52
54
|
worktrees,
|
|
53
55
|
follow: a.followCmd,
|
|
54
56
|
unfollow: a.followCmd,
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.10";
|