benignswarm 0.12.84 → 0.12.86
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/commands/install.js +9 -8
- package/dist/commands/watch.js +3 -0
- package/dist/help.js +6 -5
- package/dist/install.js +78 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/install.js
CHANGED
|
@@ -3,7 +3,7 @@ import { accessSync, constants, existsSync, readFileSync, readdirSync, realpathS
|
|
|
3
3
|
import { delimiter, join } from "node:path";
|
|
4
4
|
import { bool } from "../args.js";
|
|
5
5
|
import { CliError } from "../errors.js";
|
|
6
|
-
import { binVersion, ensureInstall, latestPublished, lingerEnabled, readInstall,
|
|
6
|
+
import { binVersion, ensureInstall, formatWatcherRestartReport, latestPublished, lingerEnabled, readInstall, restartWatcherServices, watcherServices } from "../install.js";
|
|
7
7
|
import { CLI_VERSION } from "../version.js";
|
|
8
8
|
import { refreshInstalledHooks } from "../harness.js";
|
|
9
9
|
/**
|
|
@@ -26,24 +26,25 @@ export async function install(p, out) {
|
|
|
26
26
|
lines.push(`(was ${prev.bin}; run b9s doctor to find hooks and watchers still pointing there)`);
|
|
27
27
|
const restarted = [];
|
|
28
28
|
const elsewhere = [];
|
|
29
|
+
const notStarted = [];
|
|
29
30
|
if (!bool(p.flags, "no-restart")) {
|
|
31
|
+
const matching = [];
|
|
30
32
|
for (const w of watcherServices()) {
|
|
31
33
|
const program = w.args?.[0];
|
|
32
34
|
if (program !== rec.bin) {
|
|
33
35
|
elsewhere.push(`${w.label} runs ${program ?? "(unreadable definition)"}`);
|
|
34
36
|
continue;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
restarted.push(w.label);
|
|
38
|
-
else
|
|
39
|
-
elsewhere.push(`${w.label} is not loaded (b9s doctor shows how to load it)`);
|
|
38
|
+
matching.push(w);
|
|
40
39
|
}
|
|
40
|
+
const report = await restartWatcherServices(matching);
|
|
41
|
+
restarted.push(...report.restarted);
|
|
42
|
+
lines.push(...formatWatcherRestartReport(report));
|
|
43
|
+
notStarted.push(...report.not_started.map((failure) => `${failure.label}: ${failure.reason}`));
|
|
41
44
|
}
|
|
42
|
-
if (restarted.length)
|
|
43
|
-
lines.push(`Restarted ${restarted.length} watcher${restarted.length === 1 ? "" : "s"} on it: ${restarted.map((l) => l.replace("org.benignswarm.watch.", "")).join(", ")}`);
|
|
44
45
|
if (elsewhere.length)
|
|
45
46
|
lines.push(`Not restarted:\n ${elsewhere.join("\n ")}`);
|
|
46
|
-
out.print(lines.join("\n"), { install: rec, restarted, not_restarted: elsewhere });
|
|
47
|
+
out.print(lines.join("\n"), { install: rec, restarted, not_restarted: [...elsewhere, ...notStarted] });
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* b9s doctor every b9s on this machine and who uses which: the recorded install, copies on
|
package/dist/commands/watch.js
CHANGED
|
@@ -113,6 +113,9 @@ export async function watch(p, out) {
|
|
|
113
113
|
stoppingCode = code;
|
|
114
114
|
releaseWatchLock?.();
|
|
115
115
|
signalStop();
|
|
116
|
+
// The harness command may be awaiting I/O that never settles. The lock is released first,
|
|
117
|
+
// then the watcher exits with the service's signal code; detached turns are separate groups.
|
|
118
|
+
process.exit(code);
|
|
116
119
|
};
|
|
117
120
|
if (!once) {
|
|
118
121
|
// Only one long-running watcher per identity on this machine; a second one exits here.
|
package/dist/help.js
CHANGED
|
@@ -17,7 +17,7 @@ Joining (first time on a machine, with an enrollment token from the account owne
|
|
|
17
17
|
Account-wide agents: project commands take --project <name> (or BSCHAT_PROJECT); see projects with: b9s me
|
|
18
18
|
Assistant use is off by default; an admin key or signed-in owner toggles it with PATCH /account {"assistant_enabled":true|false}.
|
|
19
19
|
GET /account/usage reports used and allowed micro-dollars, uncertain calls and the reset date.
|
|
20
|
-
Session/admin clients can use GET /assistant/conversations, POST /assistant/conversations/:id/messages (SSE), and DELETE /assistant/conversations/:id. The assistant can draft changes; POST /assistant/proposals/:id/apply or /discard is the operator's explicit action. See the agent/operator skill API reference for events and tools.
|
|
20
|
+
Session/admin clients can use GET /assistant/conversations, GET /assistant/conversations/:id/messages (paged history with saved tool notices), POST /assistant/conversations/:id/messages (SSE), and DELETE /assistant/conversations/:id. Old assistant messages report notices_available=false. The assistant can draft changes; POST /assistant/proposals/:id/apply or /discard is the operator's explicit action. See the agent/operator skill API reference for events and tools.
|
|
21
21
|
Free and paid accounts without a live Stripe subscription use the UTC calendar month; subscribed paid accounts reset at current_period_end.
|
|
22
22
|
|
|
23
23
|
Agent commands
|
|
@@ -137,9 +137,10 @@ Agent commands
|
|
|
137
137
|
--service (launchd on macOS, systemd on Linux; --launchd is the same). --turn runs each turn
|
|
138
138
|
itself (--harness codex|claude-code --session <id>); set up by b9s start.
|
|
139
139
|
Codex: b9s watch --exec "codex queue --thread <id> --message {summary}" --service
|
|
140
|
-
b9s update the same as install --latest: upgrade this machine's b9s
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
b9s update the same as install --latest: upgrade this machine's b9s, restart watchers
|
|
141
|
+
without waiting on one stop, and report any that did not come up
|
|
142
|
+
b9s install [<version> | --latest] make or upgrade this machine's one b9s (join does it once), restart watchers
|
|
143
|
+
without waiting on one stop, and report any that did not come up
|
|
143
144
|
b9s doctor every b9s on this machine and who runs which (PATH, npx caches, this repo's
|
|
144
145
|
hook and instructions, each watcher's plist versus what launchd runs), with fixes
|
|
145
146
|
b9s codex hooks | bind <thread-id> | sync install b9s's Codex hooks (~/.codex/hooks.json) and say which thread is you
|
|
@@ -250,7 +251,7 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
|
|
|
250
251
|
b9s-admin notifier [--agent name|none] [--email yes|no] [--repeat m] how you are reached away from the console, and the last report
|
|
251
252
|
b9s-admin account [--summary-minutes m] plan, usage and the account summary period
|
|
252
253
|
assistant stays opt-in: PATCH /account {"assistant_enabled":true|false}; GET /account/usage shows used, allowance, uncertain calls and reset date
|
|
253
|
-
session/admin clients use GET/POST/DELETE /assistant/conversations; POST messages streams data and
|
|
254
|
+
session/admin clients use GET /assistant/conversations/:id/messages for paged history and GET/POST/DELETE /assistant/conversations; POST messages streams data and saves tool notices with assistant messages; old assistant messages have notices_available=false; operator must explicitly apply or discard (see operator skill)
|
|
254
255
|
POST /assistant/proposals/:id/apply|discard applies or discards the operator-reviewed draft (see operator skill)
|
|
255
256
|
b9s-admin worktree forget <project> <id> delete a stale worktree record (never the directory)
|
|
256
257
|
|
package/dist/install.js
CHANGED
|
@@ -260,6 +260,84 @@ export function restartWatcher(s) {
|
|
|
260
260
|
return restartLaunchAgent(s.label);
|
|
261
261
|
return spawnSync("systemctl", ["--user", "restart", `${s.label}.service`], { stdio: "ignore" }).status === 0;
|
|
262
262
|
}
|
|
263
|
+
/** Restart request accepted; on systemd the stop/start job runs without blocking this process. */
|
|
264
|
+
export function requestWatcherRestart(s) {
|
|
265
|
+
if (s.kind === "launchd")
|
|
266
|
+
return restartLaunchAgent(s.label);
|
|
267
|
+
return spawnSync("systemctl", ["--user", "--no-block", "restart", `${s.label}.service`], { stdio: "ignore" }).status === 0;
|
|
268
|
+
}
|
|
269
|
+
function watcherPid(service) {
|
|
270
|
+
if (service.kind === "systemd") {
|
|
271
|
+
const r = spawnSync("systemctl", ["--user", "show", "--property=MainPID", "--value", `${service.label}.service`], { encoding: "utf8" });
|
|
272
|
+
const pid = Number((r.stdout ?? "").trim());
|
|
273
|
+
return r.status === 0 && Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
274
|
+
}
|
|
275
|
+
const output = spawnSync("launchctl", ["list", service.label], { encoding: "utf8" }).stdout ?? "";
|
|
276
|
+
const pid = Number(/"PID" = (\d+);/.exec(output)?.[1]);
|
|
277
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
278
|
+
}
|
|
279
|
+
const watcherRestartDriver = {
|
|
280
|
+
pid: watcherPid,
|
|
281
|
+
active: serviceActive,
|
|
282
|
+
request: requestWatcherRestart,
|
|
283
|
+
now: Date.now,
|
|
284
|
+
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Queue every restart before polling any service. A single slow stop therefore cannot keep later
|
|
288
|
+
* watchers on the old version. A changed MainPID/PID proves that each previously-running watcher
|
|
289
|
+
* came back; previously-stopped services count once they become active.
|
|
290
|
+
*/
|
|
291
|
+
export async function restartWatcherServices(services, driver = watcherRestartDriver, timeoutMs = 5_000, pollMs = 100) {
|
|
292
|
+
const pending = new Map();
|
|
293
|
+
const notStarted = [];
|
|
294
|
+
for (const service of services) {
|
|
295
|
+
const previousPid = driver.pid(service);
|
|
296
|
+
let accepted = false;
|
|
297
|
+
try {
|
|
298
|
+
accepted = driver.request(service);
|
|
299
|
+
}
|
|
300
|
+
catch { /* reported below */ }
|
|
301
|
+
if (accepted)
|
|
302
|
+
pending.set(service.label, { service, previousPid });
|
|
303
|
+
else
|
|
304
|
+
notStarted.push({ label: service.label, reason: "restart request failed" });
|
|
305
|
+
}
|
|
306
|
+
const restarted = [];
|
|
307
|
+
const deadline = driver.now() + timeoutMs;
|
|
308
|
+
while (pending.size && driver.now() < deadline) {
|
|
309
|
+
for (const [label, entry] of pending) {
|
|
310
|
+
let running = false;
|
|
311
|
+
try {
|
|
312
|
+
const pid = driver.pid(entry.service);
|
|
313
|
+
running = driver.active(entry.service) && (entry.previousPid === null || (pid !== null && pid !== entry.previousPid));
|
|
314
|
+
}
|
|
315
|
+
catch { /* retry while there is time */ }
|
|
316
|
+
if (running) {
|
|
317
|
+
restarted.push(label);
|
|
318
|
+
pending.delete(label);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (pending.size)
|
|
322
|
+
await driver.wait(Math.min(pollMs, Math.max(0, deadline - driver.now())));
|
|
323
|
+
}
|
|
324
|
+
for (const label of pending.keys())
|
|
325
|
+
notStarted.push({ label, reason: `did not come up within ${timeoutMs >= 1000 ? `${timeoutMs / 1000} s` : `${timeoutMs} ms`}` });
|
|
326
|
+
return { restarted, not_started: notStarted };
|
|
327
|
+
}
|
|
328
|
+
/** Lines for the install/update output and its structured JSON equivalent. */
|
|
329
|
+
export function formatWatcherRestartReport(report) {
|
|
330
|
+
const short = (label) => label.replace(WATCH_LABEL_PREFIX, "");
|
|
331
|
+
const total = report.restarted.length + report.not_started.length;
|
|
332
|
+
const completed = report.restarted.length;
|
|
333
|
+
const heading = completed === total
|
|
334
|
+
? `Restarted ${completed} watcher${completed === 1 ? "" : "s"}`
|
|
335
|
+
: `Restarted ${completed} of ${total} watcher${total === 1 ? "" : "s"}`;
|
|
336
|
+
const lines = [`${heading}${completed ? `: ${report.restarted.map(short).join(", ")}` : "."}`];
|
|
337
|
+
if (report.not_started.length)
|
|
338
|
+
lines.push(`Watchers that did not come up:\n ${report.not_started.map((failure) => `${short(failure.label)}: ${failure.reason}`).join("\n ")}`);
|
|
339
|
+
return lines;
|
|
340
|
+
}
|
|
263
341
|
/** Whether this user's systemd services run while nobody is logged in (null when it cannot be told). */
|
|
264
342
|
export function lingerEnabled() {
|
|
265
343
|
const r = spawnSync("loginctl", ["show-user", userInfo().username, "-p", "Linger", "--value"], { encoding: "utf8" });
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.86";
|