benignswarm 0.12.39 → 0.12.41

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.
@@ -6,6 +6,7 @@ import { hostname } from "node:os";
6
6
  import { spawnSync } from "node:child_process";
7
7
  import { CliError } from "../errors.js";
8
8
  import { table } from "../output.js";
9
+ import { milestoneWith, milestonesWith } from "./wu.js";
9
10
  import { accountAdmin, answerAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, worktreeAdmin } from "./operator.js";
10
11
  function adminClient(p) {
11
12
  return Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
@@ -66,6 +67,18 @@ export async function admin(p, out) {
66
67
  return keysAdmin(action, rest, p, out);
67
68
  case "process":
68
69
  return processAdmin(action, rest, p, out);
70
+ case "milestones": {
71
+ // bschat-admin milestones <project> [export [--out f] | set --file f]
72
+ if (!action)
73
+ throw new CliError("usage", "milestones <project> [export [--out plan.json] | set --file plan.json]");
74
+ return milestonesWith(adminClient(p), action, rest[0], p, out);
75
+ }
76
+ case "milestone": {
77
+ // bschat-admin milestone <project> add|edit|show|close|reopen|review|verdict|gap-units <key> ...
78
+ if (!action)
79
+ throw new CliError("usage", "milestone <project> <add|edit|show|close|reopen|review|verdict|gap-units> <key> ...");
80
+ return milestoneWith(adminClient(p), action, rest[0], rest[1], p, out);
81
+ }
69
82
  case "needs":
70
83
  return needsAdmin(p, out);
71
84
  case "answer":
@@ -7,7 +7,7 @@ import { join as pathJoin } from "node:path";
7
7
  import { CliError } from "../errors.js";
8
8
  import { defaultMachine } from "../git.js";
9
9
  import { ensureInstall } from "../install.js";
10
- import { HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
10
+ import { claudeCheckoutOwner, claudeCheckoutTaken, HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
11
11
  import { detectVendor } from "../vendor.js";
12
12
  function repoRoot() {
13
13
  const r = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
@@ -40,6 +40,11 @@ export async function setup(p, out) {
40
40
  const vendor = normalizeVendor(str(p.flags, "vendor") ?? creds.vendor);
41
41
  const root = str(p.flags, "dir") ?? repoRoot();
42
42
  const model = resolveModel(str(p.flags, "model"), process.env, process.cwd(), ref);
43
+ if (harnessList(p, vendor).includes("claude-code") && !bool(p.flags, "replace")) {
44
+ const owner = claudeCheckoutOwner(root);
45
+ if (owner && owner !== ref && owner !== creds.agent)
46
+ throw claudeCheckoutTaken(root, owner, creds.agent);
47
+ }
43
48
  const inst = machineInstall();
44
49
  const idPath = writeIdentity(root, vendor, creds.agent, model, bool(p.flags, "replace"), creds.project);
45
50
  const files = await fetchSkill(creds.url);
@@ -70,6 +75,13 @@ export async function join(p, out) {
70
75
  // A second agent of the same vendor in one worktree must not steal the repo mapping. With
71
76
  // --no-bind the credentials are saved and the agent is addressed per call instead.
72
77
  const noBind = bool(p.flags, "no-bind");
78
+ // --no-bind keeps the repo's mapping, but for Claude Code the hook still runs as the bound agent
79
+ // in every session here: a second Claude Code agent needs its own worktree, not --no-bind.
80
+ if (vendor === "claude-code" && !bool(p.flags, "replace")) {
81
+ const owner = claudeCheckoutOwner(root);
82
+ if (owner && owner.split("/").pop() !== name)
83
+ throw claudeCheckoutTaken(root, owner, name);
84
+ }
73
85
  if (!noBind)
74
86
  writeIdentityDryRun(root, vendor, name, bool(p.flags, "replace"));
75
87
  // The machine's one bschat install comes first: if it cannot be made, the token is not spent.
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { readFileSync } from "node:fs";
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
3
  import { bool, str } from "../args.js";
4
4
  import { Client } from "../client.js";
5
5
  import { loadAgent, resolveAgentName, resolveModel } from "../config.js";
@@ -449,7 +449,26 @@ export async function milestones(p, out) {
449
449
  const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
450
450
  if (!project)
451
451
  throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
452
- if (p.positionals[1] === "set") {
452
+ return milestonesWith(client, project, p.positionals[1], p, out);
453
+ }
454
+ /**
455
+ * The plan's milestones, shared by agents (`bschat milestones`) and the operator (`bschat-admin
456
+ * milestones <project>`): list, `export` (the editable JSON list `set` takes) and `set`.
457
+ */
458
+ export async function milestonesWith(client, project, sub, p, out) {
459
+ if (sub === "export") {
460
+ const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.depends_on }));
461
+ const text = JSON.stringify(list, null, 2) + "\n";
462
+ const file = str(p.flags, "out");
463
+ if (file) {
464
+ writeFileSync(file, text);
465
+ out.print(`Wrote ${list.length} milestone(s) to ${file}; edit it and load it with milestones set --file ${file}`, { file, milestones: list });
466
+ }
467
+ else
468
+ process.stdout.write(text);
469
+ return;
470
+ }
471
+ if (sub === "set") {
453
472
  // Define or replace the plan: a JSON list [{key, title, exit?, depends_on?}] from --file or stdin.
454
473
  // Existing keys keep their status; the server refuses cycles, unknown dependencies and removing a key with units.
455
474
  const file = str(p.flags, "file");
@@ -467,7 +486,7 @@ export async function milestones(p, out) {
467
486
  }
468
487
  const r = await client.call("GET", `/projects/${project}/milestones`);
469
488
  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) }));
470
- 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);
489
+ 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 defines them on the Process page or with bschat-admin milestones <project> set --file plan.json, an assigner with bschat milestones set --file plan.json)", r);
471
490
  }
472
491
  /** milestone show <key> | milestone close <key> --note ".." [--evidence a,b] [--abandon | --defer] | milestone reopen <key> */
473
492
  export async function milestone(p, out) {
@@ -477,8 +496,10 @@ export async function milestone(p, out) {
477
496
  const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
478
497
  if (!project)
479
498
  throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
480
- const sub = p.positionals[1];
481
- const key = p.positionals[2];
499
+ return milestoneWith(client, project, p.positionals[1], p.positionals[2], p, out);
500
+ }
501
+ /** One milestone, shared by agents (`bschat milestone`) and the operator (`bschat-admin milestone <project>`). */
502
+ export async function milestoneWith(client, project, sub, key, p, out) {
482
503
  if (!key)
483
504
  throw new CliError("usage", 'milestone show <key> | milestone close <key> --note "how the exit criterion was met" [--evidence id,id] [--abandon | --defer] | milestone reopen <key>');
484
505
  if (sub === "add" || sub === "edit") {
package/dist/harness.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { shellPath } from "./install.js";
3
- import { dirname, join } from "node:path";
3
+ import { basename, dirname, join } from "node:path";
4
4
  import { CliError } from "./errors.js";
5
5
  /** Canonical vendor ids and the aliases people type. */
6
6
  const VENDOR_ALIASES = {
@@ -45,6 +45,8 @@ export function writeIdentity(root, vendor, name, model, replace, project) {
45
45
  file = readIdentityFile(p);
46
46
  const existing = file.agents[vendor];
47
47
  if (existing && existing.name !== name && !replace) {
48
+ if (vendor === "claude-code")
49
+ throw claudeCheckoutTaken(root, existing.project ? `${existing.project}/${existing.name}` : existing.name, name);
48
50
  throw new CliError("identity_exists", `${p} already maps ${vendor} to agent "${existing.name}"`, `Two ${vendor} agents share this checkout. Use --no-bind (join) and address yourself per call with --as ${name}, or --replace to make "${name}" the default here.`);
49
51
  }
50
52
  file.agents[vendor] = { name, project, ...(model ? { model } : {}) };
@@ -182,3 +184,33 @@ export function withBschatHooks(hooks, bin) {
182
184
  }
183
185
  return out;
184
186
  }
187
+ /**
188
+ * The Claude Code agent this checkout's hook runs as (its settings' BSCHAT_AGENT, else the identity
189
+ * file's claude-code entry), or null when none is bound here.
190
+ */
191
+ export function claudeCheckoutOwner(root) {
192
+ const sp = join(root, ".claude", "settings.local.json");
193
+ if (existsSync(sp)) {
194
+ try {
195
+ const env = JSON.parse(readFileSync(sp, "utf8")).env;
196
+ if (env?.BSCHAT_AGENT)
197
+ return env.BSCHAT_AGENT;
198
+ }
199
+ catch {
200
+ throw new CliError("bad_settings", `${sp} is not valid JSON; fix it or remove it`);
201
+ }
202
+ }
203
+ const idp = findIdentityFile(root);
204
+ const e = idp && idp.startsWith(root) ? readIdentityFile(idp).agents["claude-code"] : undefined;
205
+ return e ? (e.project ? `${e.project}/${e.name}` : e.name) : null;
206
+ }
207
+ /**
208
+ * Two Claude Code agents cannot share a checkout: its hook runs as one agent for every Claude Code
209
+ * session opened there, so the second session would be handed the first agent's messages, and
210
+ * they would count as delivered. Learned from StickJoy: a second agent joined with --no-bind, and
211
+ * once the hook worked it would have taken the triage lead's notifications. The way out is a worktree.
212
+ */
213
+ export function claudeCheckoutTaken(root, owner, name) {
214
+ const sibling = join(dirname(root), `${basename(root)}-${name}`);
215
+ return new CliError("checkout_taken", `this checkout's Claude Code hook runs as ${owner} for every Claude Code session opened here, so ${name} would be handed ${owner}'s messages (and they would count as delivered)`, `Give ${name} its own worktree: git -C ${root} worktree add ${sibling} then start Claude Code in ${sibling} and run this command there. (--replace makes ${name} this checkout's Claude Code agent instead of ${owner}.)`);
216
+ }
package/dist/help.js CHANGED
@@ -177,6 +177,9 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
177
177
  bschat-admin process assigners <project> role1,role2 | agreements <project> --file agreements.md
178
178
  bschat-admin process charter <project> --file charter.md how the project weighs trade-offs; sent with every expert question
179
179
  bschat-admin process steward <project> on|off [--quiet m] [--summary m] [--churn n] (--churn: ask the operator when a goal is sent back or handed over n times; 0 off)
180
+ bschat-admin milestones <project> [export [--out plan.json] | set --file plan.json] the plan's slices: list, the editable JSON, or replace it (keys keep their status)
181
+ bschat-admin milestone <project> add|edit <key> --title .. [--exit ..] [--source ..] [--depends-on a,b] one slice in, the rest untouched
182
+ bschat-admin milestone <project> show|review|reopen <key> | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
180
183
  bschat-admin role edit <name> [--project p] --reviews a,b --works c --trials d which tags a role reviews, works and trials ("*" all, "" none)
181
184
  bschat-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
182
185
  bschat-admin answer <key> "decision" answer one; the asker is @mentioned
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { feedback } from "./commands/feedback.js";
11
11
  import { goal } from "./commands/goal.js";
12
12
  import { wake } from "./commands/wake.js";
13
13
  import { doctor, install } from "./commands/install.js";
14
+ import { warnIfForeignCopy } from "./install.js";
14
15
  import { processCmd, record, wu, milestones, milestone, lock, askOperator } from "./commands/wu.js";
15
16
  import { worktrees } from "./commands/worktrees.js";
16
17
  import { CliError } from "./errors.js";
@@ -82,6 +83,7 @@ async function main(argv) {
82
83
  const fn = COMMANDS[cmd];
83
84
  if (!fn)
84
85
  throw new CliError("usage", `unknown command ${cmd}`, "Run: bschat --help");
86
+ warnIfForeignCopy(cmd, CLI_VERSION);
85
87
  await fn(p, out);
86
88
  return 0;
87
89
  }
package/dist/install.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { configRoot } from "./config.js";
@@ -70,7 +70,10 @@ export function ensureInstall(version, log, npmOverride) {
70
70
  if (got !== version)
71
71
  throw new CliError("install_unverified", `after installing, ${bin} reports ${got ?? "nothing"} instead of ${version}`);
72
72
  }
73
- const rec = { bin, npm, version: binVersion(bin), installed_at: new Date().toISOString() };
73
+ // Record the npm in the global prefix's bin (a stable link, e.g. /opt/homebrew/bin/npm) rather than
74
+ // the resolved runtime path, which names a versioned folder that a Node upgrade removes.
75
+ const stableNpm = join(pre.stdout.trim(), "bin", "npm");
76
+ const rec = { bin, npm: existsSync(stableNpm) ? stableNpm : npm, version: binVersion(bin), installed_at: new Date().toISOString() };
74
77
  mkdirSync(configRoot(), { recursive: true });
75
78
  writeFileSync(installFile(), JSON.stringify(rec, null, 2) + "\n");
76
79
  return rec;
@@ -103,3 +106,61 @@ export function reloadLaunchAgent(label, path) {
103
106
  export function restartLaunchAgent(label) {
104
107
  return spawnSync("launchctl", ["kickstart", "-k", `gui/${process.getuid()}/${label}`], { stdio: "ignore" }).status === 0;
105
108
  }
109
+ /** Commands that legitimately run from a copy other than the recorded install (npx join, old npx hooks). */
110
+ const GUARD_EXEMPT = new Set(["join", "setup", "install", "doctor", "hook", "watch"]);
111
+ /**
112
+ * The line to print when this process is not the machine's recorded install, or null. Pure, so
113
+ * it is tested without a machine: `self` and `recorded` are real paths, `lastAt` when this copy
114
+ * was last warned about (epoch ms).
115
+ */
116
+ export function foreignCopyNotice(cmd, self, selfVersion, rec, recorded, lastAt, now) {
117
+ if (!rec || !recorded || GUARD_EXEMPT.has(cmd) || self === recorded)
118
+ return null;
119
+ if (lastAt !== null && now - lastAt < 24 * 3600_000)
120
+ return null;
121
+ return `[bschat] this is ${self} (${selfVersion}), not this machine's install ${rec.bin} (${rec.version}). Run that one (put ${dirname(rec.bin)} first on PATH, or remove this copy), or see: bschat doctor`;
122
+ }
123
+ /**
124
+ * Warns once a day per copy when a bschat other than the recorded install runs: another
125
+ * `npm i -g` with a different Node quietly puts a second copy ahead on PATH (a publish routine
126
+ * did exactly that and an operator's shell ran 0.12.37, which had no install command).
127
+ * Never fails a command: a machine state it cannot read only skips the notice.
128
+ */
129
+ export function warnIfForeignCopy(cmd, selfVersion) {
130
+ let rec;
131
+ try {
132
+ rec = readInstall();
133
+ }
134
+ catch {
135
+ return;
136
+ }
137
+ if (!rec || !process.argv[1])
138
+ return;
139
+ let self;
140
+ let recorded;
141
+ try {
142
+ self = realpathSync(process.argv[1]);
143
+ recorded = realpathSync(rec.bin);
144
+ }
145
+ catch {
146
+ return;
147
+ }
148
+ const stateFile = join(configRoot(), "state", "foreign-copy.json");
149
+ let seen = {};
150
+ try {
151
+ if (existsSync(stateFile))
152
+ seen = JSON.parse(readFileSync(stateFile, "utf8"));
153
+ }
154
+ catch {
155
+ seen = {};
156
+ }
157
+ const line = foreignCopyNotice(cmd, self, selfVersion, rec, recorded, seen[self] ?? null, Date.now());
158
+ if (!line)
159
+ return;
160
+ process.stderr.write(line + "\n");
161
+ try {
162
+ mkdirSync(dirname(stateFile), { recursive: true });
163
+ writeFileSync(stateFile, JSON.stringify({ ...seen, [self]: Date.now() }));
164
+ }
165
+ catch { /* the notice simply repeats next time */ }
166
+ }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.39";
1
+ export const CLI_VERSION = "0.12.41";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.39",
3
+ "version": "0.12.41",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {