benignswarm 0.12.72 → 0.12.74
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/admin.js +14 -1
- package/dist/commands/agent.js +45 -0
- package/dist/commands/machine-admin.js +42 -0
- package/dist/commands/machine.js +35 -2
- package/dist/commands/watch.js +9 -0
- package/dist/commands/wu.js +20 -3
- package/dist/help.js +8 -0
- package/dist/index.js +2 -0
- package/dist/maintenance.js +23 -0
- package/dist/output.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -3,8 +3,8 @@ import { CliError } from "./errors.js";
|
|
|
3
3
|
// These options accept comma-separated collections, so repeating them should
|
|
4
4
|
// append another collection instead of discarding earlier values.
|
|
5
5
|
export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "units", "waits-on", "needs", "exclude", "remove", "post", "harness", "variant"];
|
|
6
|
-
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", "unacked-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", "exit", "depends-on", "source", "by", "on", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable"];
|
|
7
|
-
export const BOOL_FLAGS = ["latest", "no-restart", "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", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor"];
|
|
6
|
+
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", "unacked-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", "exit", "depends-on", "source", "by", "on", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason", "at"];
|
|
7
|
+
export const BOOL_FLAGS = ["latest", "no-restart", "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", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor", "cancel"];
|
|
8
8
|
export function parse(argv) {
|
|
9
9
|
const options = {};
|
|
10
10
|
for (const f of STRING_FLAGS)
|
package/dist/commands/admin.js
CHANGED
|
@@ -7,6 +7,7 @@ import { spawnSync } from "node:child_process";
|
|
|
7
7
|
import { CliError } from "../errors.js";
|
|
8
8
|
import { table } from "../output.js";
|
|
9
9
|
import { milestoneWith, milestonesWith } from "./wu.js";
|
|
10
|
+
import { awayUntil } from "./agent.js";
|
|
10
11
|
import { agentMove, machineAdmin, poolAdmin, projectCheckoutAdmin, projectRepoAdmin } from "./machine-admin.js";
|
|
11
12
|
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, worktreeAdmin } from "./operator.js";
|
|
12
13
|
function adminClient(p) {
|
|
@@ -140,7 +141,19 @@ async function agent(action, rest, p, out) {
|
|
|
140
141
|
if (bool(p.flags, "account"))
|
|
141
142
|
return accountAgent(action, rest, p, out, c);
|
|
142
143
|
const [proj, name, extra] = rest;
|
|
143
|
-
if (action === "
|
|
144
|
+
if ((action === "away" || action === "back") && proj && !name) {
|
|
145
|
+
const slash = proj.indexOf("/");
|
|
146
|
+
if (slash < 1 || slash === proj.length - 1 || proj.indexOf("/", slash + 1) !== -1)
|
|
147
|
+
throw new CliError("usage", `agent ${action} <project>/<agent>${action === "away" ? " --for <duration>|--until <ISO> --reason <why>" : ""}`);
|
|
148
|
+
const projectName = proj.slice(0, slash);
|
|
149
|
+
const agentName = proj.slice(slash + 1);
|
|
150
|
+
const body = action === "back" ? { away: null } : { away: { until: awayUntil(p), reason: need(p.flags, "reason").trim() } };
|
|
151
|
+
if (action === "away" && !body.away.reason)
|
|
152
|
+
throw new CliError("usage", "away needs --reason <why>");
|
|
153
|
+
const r = await c.call("PUT", `/projects/${projectName}/agents/${agentName}/status`, body);
|
|
154
|
+
out.print(action === "back" ? `Cleared away status for ${projectName}/${agentName}` : `${projectName}/${agentName} away until ${r.status.away.until}`, r);
|
|
155
|
+
}
|
|
156
|
+
else if (action === "list" && proj) {
|
|
144
157
|
const r = await c.call("GET", `/projects/${proj}/agents`);
|
|
145
158
|
out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "active_keys", "created_at"]), r);
|
|
146
159
|
}
|
package/dist/commands/agent.js
CHANGED
|
@@ -134,6 +134,51 @@ export async function status(p, out) {
|
|
|
134
134
|
}
|
|
135
135
|
throw new CliError("usage", "status <set|history>");
|
|
136
136
|
}
|
|
137
|
+
export function awayUntil(p) {
|
|
138
|
+
const duration = str(p.flags, "for");
|
|
139
|
+
const absolute = str(p.flags, "until");
|
|
140
|
+
const reason = str(p.flags, "reason");
|
|
141
|
+
if ((duration === undefined) === (absolute === undefined))
|
|
142
|
+
throw new CliError("usage", "away needs exactly one of --for <duration> or --until <ISO timestamp>");
|
|
143
|
+
if (!reason?.trim())
|
|
144
|
+
throw new CliError("usage", "away needs --reason <why>");
|
|
145
|
+
let until;
|
|
146
|
+
if (duration !== undefined) {
|
|
147
|
+
const m = /^(\d+)(m|h)$/.exec(duration);
|
|
148
|
+
if (!m)
|
|
149
|
+
throw new CliError("usage", "--for takes a positive whole number of minutes or hours, e.g. 90m or 2h");
|
|
150
|
+
const amount = Number(m[1]) * (m[2] === "h" ? 60 : 1);
|
|
151
|
+
if (!Number.isSafeInteger(amount) || amount < 1 || amount > 1440)
|
|
152
|
+
throw new CliError("usage", "--for must be from 1 minute through 24 hours");
|
|
153
|
+
// Anchor to a whole second so network transit cannot make an exact 24h request exceed
|
|
154
|
+
// the server's strict 24h-from-receipt limit.
|
|
155
|
+
until = new Date(Math.floor(Date.now() / 1000) * 1000 + amount * 60_000);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const ms = Date.parse(absolute);
|
|
159
|
+
if (!Number.isFinite(ms))
|
|
160
|
+
throw new CliError("usage", "--until must be an ISO timestamp");
|
|
161
|
+
until = new Date(ms);
|
|
162
|
+
const delta = until.getTime() - Date.now();
|
|
163
|
+
if (delta <= 0 || delta > 24 * 60 * 60_000)
|
|
164
|
+
throw new CliError("usage", "--until must be in the future and no more than 24 hours ahead");
|
|
165
|
+
}
|
|
166
|
+
return until.toISOString();
|
|
167
|
+
}
|
|
168
|
+
export async function away(p, out) {
|
|
169
|
+
const { client, creds } = agentClient(p);
|
|
170
|
+
const until = awayUntil(p);
|
|
171
|
+
const reason = str(p.flags, "reason").trim();
|
|
172
|
+
const path = creds.project ? `/projects/${creds.project}/agents/me/status` : "/agents/me/status";
|
|
173
|
+
const r = await client.call("PUT", path, { away: { until, reason } });
|
|
174
|
+
out.print(`Away until ${r.status.away.until}: ${r.status.away.reason}`, r);
|
|
175
|
+
}
|
|
176
|
+
export async function back(p, out) {
|
|
177
|
+
const { client, creds } = agentClient(p);
|
|
178
|
+
const path = creds.project ? `/projects/${creds.project}/agents/me/status` : "/agents/me/status";
|
|
179
|
+
const r = await client.call("PUT", path, { away: null });
|
|
180
|
+
out.print("Away status cleared", r);
|
|
181
|
+
}
|
|
137
182
|
export async function send(p, out) {
|
|
138
183
|
const channel = p.positionals[1];
|
|
139
184
|
let body = p.positionals.slice(2).join(" ");
|
|
@@ -134,6 +134,22 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
134
134
|
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", thread: s.thread ?? "-", sandbox: s.sandbox, model: s.model ?? "-", dir: s.dir || s.reported?.dir || "(auto)", error: s.reported?.error ?? s.reported?.detail ?? "", last_turn: (s.reported?.last_turn ?? "").replace(/^\S+ bschat watch\[[^\]]+\]: /, "") }));
|
|
135
135
|
return out.print([...head, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].join("\n"), r);
|
|
136
136
|
}
|
|
137
|
+
if (action === "maintenance") {
|
|
138
|
+
// A window on the machine: no new turns from 15 min before, its agents away until it ends.
|
|
139
|
+
const name = rest[0];
|
|
140
|
+
const usage = "machine maintenance <name> --at <ISO time | HH:MM local> --for <minutes | 30m | 2h> | --cancel";
|
|
141
|
+
if (!name)
|
|
142
|
+
throw new CliError("usage", usage);
|
|
143
|
+
if (bool(p.flags, "cancel"))
|
|
144
|
+
return out.print(`${name}: maintenance cancelled; its agents are back and turns start again.`, await c.call("DELETE", `/machines/${name}/maintenance`));
|
|
145
|
+
const at = str(p.flags, "at");
|
|
146
|
+
const len = str(p.flags, "for");
|
|
147
|
+
if (!at || !len)
|
|
148
|
+
throw new CliError("usage", usage);
|
|
149
|
+
const r = await c.call("PUT", `/machines/${name}/maintenance`, { start: maintenanceStart(at).toISOString(), minutes: durationMinutes(len) });
|
|
150
|
+
const w = r.maintenance;
|
|
151
|
+
return out.print(`${name}: maintenance ${w.start.slice(0, 16).replace("T", " ")} to ${w.end.slice(11, 16)} UTC (${w.phase}). No new turns start there from 15 min before; its agents are away until it ends, which happens when the machine reports after booting or at the end time. Projects with agents there were told.`, r);
|
|
152
|
+
}
|
|
137
153
|
if (action === "writable") {
|
|
138
154
|
const name = rest[0];
|
|
139
155
|
if (!name || rest.length < 2)
|
|
@@ -431,3 +447,29 @@ export async function agentMove(rest, p, out) {
|
|
|
431
447
|
`Follow it: bschat-admin machine show ${to}`,
|
|
432
448
|
].filter(Boolean).join("\n"), r);
|
|
433
449
|
}
|
|
450
|
+
/** --at: an ISO timestamp, or HH:MM in this machine's local time (today, or tomorrow when past). */
|
|
451
|
+
export function maintenanceStart(at, nowMs = Date.now()) {
|
|
452
|
+
const hm = /^(\d{1,2}):(\d{2})$/.exec(at);
|
|
453
|
+
if (hm) {
|
|
454
|
+
const d = new Date(nowMs);
|
|
455
|
+
d.setHours(Number(hm[1]), Number(hm[2]), 0, 0);
|
|
456
|
+
if (d.getTime() < nowMs - 60_000)
|
|
457
|
+
d.setDate(d.getDate() + 1);
|
|
458
|
+
return d;
|
|
459
|
+
}
|
|
460
|
+
if (at === "now")
|
|
461
|
+
return new Date(nowMs);
|
|
462
|
+
const t = Date.parse(at);
|
|
463
|
+
if (Number.isNaN(t))
|
|
464
|
+
throw new CliError("usage", `--at ${at}: an ISO timestamp, HH:MM (local time) or now`);
|
|
465
|
+
return new Date(t);
|
|
466
|
+
}
|
|
467
|
+
/** --for: minutes as a number, or 30m / 2h / 1h30m. */
|
|
468
|
+
export function durationMinutes(v) {
|
|
469
|
+
if (/^\d+$/.test(v))
|
|
470
|
+
return Number(v);
|
|
471
|
+
const m = /^(?:(\d+)h)?(?:(\d+)m)?$/.exec(v);
|
|
472
|
+
if (!m || (!m[1] && !m[2]))
|
|
473
|
+
throw new CliError("usage", `--for ${v}: minutes, or a duration like 30m, 2h, 1h30m`);
|
|
474
|
+
return Number(m[1] ?? 0) * 60 + Number(m[2] ?? 0);
|
|
475
|
+
}
|
package/dist/commands/machine.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, statSync, statfsSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { arch, cpus, freemem, homedir, hostname, loadavg, platform, totalmem, userInfo } from "node:os";
|
|
3
|
+
import { arch, cpus, freemem, homedir, hostname, loadavg, platform, totalmem, uptime, userInfo } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { str } from "../args.js";
|
|
6
6
|
import { Client } from "../client.js";
|
|
@@ -8,6 +8,7 @@ import { configRoot, loadAgent, saveAgent } from "../config.js";
|
|
|
8
8
|
import { CliError } from "../errors.js";
|
|
9
9
|
import { BWRAP_APPARMOR_PATH, bwrapAppArmorProfile, CODEX_APPARMOR_PATH, CODEX_MANAGED_DIR, CODEX_MANAGED_MARK, codexAppArmorProfile, codexManagedHooks } from "../harness.js";
|
|
10
10
|
import { applySparse } from "../git.js";
|
|
11
|
+
import { drainingUntil, writeMaintenance } from "../maintenance.js";
|
|
11
12
|
import { TURN_HARNESSES, claudeFacts, claudeSandbox, probeFor, sessionProcesses } from "../harnesses.js";
|
|
12
13
|
import { readState, writeState } from "../state.js";
|
|
13
14
|
import { installService, lingerEnabled, MACHINE_LABEL, removeService, requireInstall, restartWatcher, serviceActive, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
|
|
@@ -34,6 +35,20 @@ function writeMachineState(s) {
|
|
|
34
35
|
const START_REV = 3;
|
|
35
36
|
export const sessionFingerprint = (s, writable = []) => JSON.stringify([s.harness, s.dir, s.sandbox, s.model, s.effort, s.turn_timeout, ...(writable.length ? [writable] : []), ...(START_REV > 1 ? [`rev${START_REV}`] : [])]);
|
|
36
37
|
export const watchLabelOf = (ref) => `${WATCH_LABEL_PREFIX}${ref.replace("/", ".")}`;
|
|
38
|
+
/**
|
|
39
|
+
* During a maintenance drain or window, a session that would be started fresh (no known thread, so
|
|
40
|
+
* `bschat start` runs its first turn at once, past the watchers' check) waits; adopting a known
|
|
41
|
+
* thread starts no turn and proceeds. Returns the session's report while it waits, else null.
|
|
42
|
+
*/
|
|
43
|
+
export function deferredByMaintenance(s, thread, drain) {
|
|
44
|
+
if (!drain || thread)
|
|
45
|
+
return null;
|
|
46
|
+
return { id: s.id, state: "preparing", dir: s.dir, detail: `maintenance until ${drain.end.slice(11, 16)} UTC: its first turn starts after it` };
|
|
47
|
+
}
|
|
48
|
+
/** The daemon's confirmation that it holds new turns back, with the turns still running. */
|
|
49
|
+
export function maintenanceReport(drain, sessions) {
|
|
50
|
+
return drain ? { draining: true, until: drain.end, turns_running: sessions.filter((o) => o.turn?.running).length } : null;
|
|
51
|
+
}
|
|
37
52
|
/** The `bschat start` arguments that bring a session up (adopting its thread or session when known). */
|
|
38
53
|
export function startArgs(s, thread, writable = []) {
|
|
39
54
|
return [
|
|
@@ -52,6 +67,9 @@ export async function reconcile(m, log) {
|
|
|
52
67
|
const desired = me.sessions;
|
|
53
68
|
const workdir = me.machine?.workdir ?? null;
|
|
54
69
|
const writable = me.machine?.writable ?? [];
|
|
70
|
+
// The maintenance window, for the watchers: they start no new turns while it drains or runs.
|
|
71
|
+
const mw = me.machine?.maintenance;
|
|
72
|
+
writeMaintenance(mw ? { start: mw.start, end: mw.end } : null);
|
|
55
73
|
const state = readMachineState();
|
|
56
74
|
const bin = requireInstall().bin;
|
|
57
75
|
const out = [];
|
|
@@ -88,6 +106,15 @@ export async function reconcile(m, log) {
|
|
|
88
106
|
const thread = s.thread ?? local?.thread ?? null;
|
|
89
107
|
const threadChanged = !!local?.thread && !!s.thread && s.thread !== local.thread;
|
|
90
108
|
if (!svc() || !local || local.fingerprint !== fp || threadChanged) {
|
|
109
|
+
// A new session's start runs its first turn at once, past the watchers' check: during a
|
|
110
|
+
// maintenance window it waits. (Adopting a known thread starts no turn, so that proceeds.)
|
|
111
|
+
// The phase is read at the launch decision itself: credential checks and checkouts before
|
|
112
|
+
// it can take long enough to cross the drain point (sol-reviewer's boundary probe).
|
|
113
|
+
const held = deferredByMaintenance(s, thread, drainingUntil());
|
|
114
|
+
if (held) {
|
|
115
|
+
out.push(held);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
91
118
|
const r = spawnSync(bin, startArgs(s, thread, writable), { cwd: s.dir, encoding: "utf8", timeout: 180_000 });
|
|
92
119
|
if (r.status !== 0)
|
|
93
120
|
throw new Error(`bschat start failed: ${errorText(r.stderr || r.stdout)}`);
|
|
@@ -139,7 +166,11 @@ export async function reconcile(m, log) {
|
|
|
139
166
|
}
|
|
140
167
|
writeMachineState(state);
|
|
141
168
|
const clones = refreshClones(workdir, [...new Set(desired.filter((s) => !s.dir && s.project && s.desired === "running").map((s) => s.project))], log);
|
|
142
|
-
const report = {
|
|
169
|
+
const report = {
|
|
170
|
+
...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones,
|
|
171
|
+
// The daemon's own confirmation that it is holding turns back, and how many are still running.
|
|
172
|
+
maintenance: maintenanceReport(drainingUntil(), out),
|
|
173
|
+
};
|
|
143
174
|
await client.call("POST", "/machines/me/report", { report, sessions: out });
|
|
144
175
|
return { sessions: out, report };
|
|
145
176
|
}
|
|
@@ -427,6 +458,8 @@ export function machineFacts() {
|
|
|
427
458
|
return {
|
|
428
459
|
os: platform(), arch: arch(), hostname: hostname(), user: userInfo().username, cpus: cpus().length, mem_total_bytes: totalmem(),
|
|
429
460
|
load: loadavg().map((x) => Math.round(x * 100) / 100), mem_available_bytes: memAvailable(),
|
|
461
|
+
// When this machine last booted: the server ends a maintenance window once the machine is back.
|
|
462
|
+
booted_at: new Date(Math.floor((Date.now() - uptime() * 1000) / 60_000) * 60_000).toISOString(),
|
|
430
463
|
bschat: { version: CLI_VERSION, bin: requireInstall().bin },
|
|
431
464
|
codex: codex.status === 0 ? { version: codex.stdout.trim(), logged_in: login?.status === 0 && /logged in/i.test(`${login.stdout}${login.stderr}`), login: `${login?.stdout ?? ""}${login?.stderr ?? ""}`.trim().slice(0, 200), sandbox: codexSandbox() } : null,
|
|
432
465
|
"claude-code": claudeReport(),
|
package/dist/commands/watch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { bindSession, sessionOfExec, threadOfExec } from "../sessions.js";
|
|
3
3
|
import { startTurn, stopTurn } from "../turn.js";
|
|
4
|
+
import { drainingUntil } from "../maintenance.js";
|
|
4
5
|
import { probeFor, turnHarness } from "../harnesses.js";
|
|
5
6
|
import { applyAck } from "./wake.js";
|
|
6
7
|
import { lingerEnabled, loadSystemdUnit, reloadLaunchAgent, removeService, requireInstall, systemdUnit, systemdUserDir, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
|
|
@@ -470,6 +471,14 @@ async function turnStep(ctl, probe, timeoutMin, log, wake, name) {
|
|
|
470
471
|
log(`the turn started at ${ph.startedAt} has written nothing for ${Math.round(quietMs / 60_000)} min (over the ${timeoutMin}-min limit); treating it as dead`);
|
|
471
472
|
ctl.loggedRunning = ph.startedAt;
|
|
472
473
|
}
|
|
474
|
+
// A maintenance window on this machine: no new turn from 15 min before it until it ends.
|
|
475
|
+
const maint = drainingUntil();
|
|
476
|
+
if (maint) {
|
|
477
|
+
if (ctl.loggedRunning !== `maint:${maint.start}`)
|
|
478
|
+
log(`maintenance on this machine ${maint.start.slice(0, 16)} to ${maint.end.slice(11, 16)} UTC: starting no new turns until it ends`);
|
|
479
|
+
ctl.loggedRunning = `maint:${maint.start}`;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
473
482
|
const st = readState(name);
|
|
474
483
|
if (st.watch_pending) {
|
|
475
484
|
// Queued by a queue-mode watcher and never delivered, or failed: no turn is running, so the agent is not going to answer it.
|
package/dist/commands/wu.js
CHANGED
|
@@ -81,6 +81,7 @@ export async function wu(p, out) {
|
|
|
81
81
|
return [
|
|
82
82
|
`WU #${u.number} [${u.status}] ${tags(u)} ${u.title}${flags ? ` (${flags})` : ""}`,
|
|
83
83
|
` owner ${u.owner_name || "unassigned (queued)"}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
|
|
84
|
+
u.operator_hold ? ` ON HOLD by ${u.operator_hold.by}: ${u.operator_hold.note} (no verdict and no merge until the owner resubmits or it is released)` : null,
|
|
84
85
|
u.question ? ` QUESTION for ${u.question.level === "expert" ? `a ${u.question.roles.join(" or ")}` : "the operator"} (asked by ${u.question.asked_by}${u.question.passed_by ? `, passed up by ${u.question.passed_by}` : ""}): ${u.question.text}` : null,
|
|
85
86
|
` ${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(" ")}` : ""}`,
|
|
86
87
|
u.scope ? ` scope: ${u.scope}` : null,
|
|
@@ -233,6 +234,20 @@ export async function wu(p, out) {
|
|
|
233
234
|
out.print(fmt(r.unit), r);
|
|
234
235
|
return;
|
|
235
236
|
}
|
|
237
|
+
case "hold": {
|
|
238
|
+
// Operator or assigner: no verdict and no merge until the owner resubmits or the hold is released.
|
|
239
|
+
const note = str(p.flags, "note");
|
|
240
|
+
if (!note)
|
|
241
|
+
throw new CliError("usage", 'wu hold <n> --note "what must happen before it moves on" (operator or assigner)');
|
|
242
|
+
const r = await client.call("POST", `${base}/${num()}/hold`, { note });
|
|
243
|
+
out.print(`${fmt(r.unit)}\nOn hold: verdicts and done are refused until ${r.unit.owner_name} resubmits or you run bschat wu release ${num()}.`, r);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
case "release": {
|
|
247
|
+
const r = await client.call("POST", `${base}/${num()}/hold/release`, { note: str(p.flags, "note") ?? "" });
|
|
248
|
+
out.print(`${fmt(r.unit)}\nHold released.`, r);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
236
251
|
case "scope": {
|
|
237
252
|
const scope = str(p.flags, "scope");
|
|
238
253
|
const note = str(p.flags, "note");
|
|
@@ -681,9 +696,11 @@ export async function lock(p, out) {
|
|
|
681
696
|
const unit = str(p.flags, "unit");
|
|
682
697
|
// Scoped to this machine unless --shared: the resource is this box's CPU and disk.
|
|
683
698
|
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/acquire`, { unit: unit ? Number(unit) : null, note: str(p.flags, "note") ?? "", shared: bool(p.flags, "shared") });
|
|
684
|
-
out.print(r.
|
|
685
|
-
?
|
|
686
|
-
:
|
|
699
|
+
out.print(r.maintenance
|
|
700
|
+
? `${lockName} is not handed out now: ${r.maintenance}. You are #${r.position} in line and will be @mentioned when it is yours after the window; do not poll. Leave the queue: bschat unlock ${lockName}`
|
|
701
|
+
: r.acquired
|
|
702
|
+
? `You hold ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${unit ? ` for WU #${unit}` : ""}. Release it when done: bschat unlock ${lockName}`
|
|
703
|
+
: `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; you are ${r.position === 1 ? "next" : `#${r.position} in line`}. You will be @mentioned when it is yours; do not poll. Leave the queue: bschat unlock ${lockName}`, r);
|
|
687
704
|
}
|
|
688
705
|
/**
|
|
689
706
|
* bschat ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]:
|
package/dist/help.js
CHANGED
|
@@ -23,6 +23,8 @@ Agent commands
|
|
|
23
23
|
bschat status set [--state s] [--goal g] [--task t] [--blocked-on b] [--tags a,b] [--custom '{json}']
|
|
24
24
|
[--checks-every <min>|none] not always on but checking on a schedule: say how often
|
|
25
25
|
bschat status history <agent> [--limit n]
|
|
26
|
+
bschat away (--for <minutes|hours> | --until <ISO timestamp>) --reason "why" pause assignment for up to 24 hours
|
|
27
|
+
bschat back clear your away status early
|
|
26
28
|
bschat send <channel> <message...> [--reply-to <seq>] @name, @role:name, @role:* are resolved and validated
|
|
27
29
|
bschat send <channel> --body-file <f|-> multi-line / markdown message from a file or stdin (use this for anything long)
|
|
28
30
|
bschat read <channel> [--since <seq>] [--limit n] [--follow]
|
|
@@ -87,6 +89,8 @@ Agent commands
|
|
|
87
89
|
bschat wu explain <n> "..." the same for a unit's question waiting on the operator
|
|
88
90
|
--propose: your recommended answer, phrased so they can approve it as written
|
|
89
91
|
bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
|
|
92
|
+
bschat wu hold <n> --note ".." operator or assigner: no verdict and no merge until the owner resubmits;
|
|
93
|
+
wu release <n> [--note ..] lifts it earlier
|
|
90
94
|
bschat wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
|
|
91
95
|
bschat wu done <n> --merged <sha> [--keep-worktree] after approval; verifies the sha is on the target; removes the unit's clean worktree
|
|
92
96
|
bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
|
|
@@ -174,6 +178,8 @@ bschat-admin login (approve it in your signed-in browser); the session lasts 30
|
|
|
174
178
|
bschat-admin agent --account create <name> --vendor <v> --role <r> account-wide agent (role's --projects decides access)
|
|
175
179
|
bschat-admin agent --account list|role|rotate-key|delete ...
|
|
176
180
|
bschat-admin agent list <project>
|
|
181
|
+
bschat-admin agent away <project>/<agent> (--for <minutes|hours> | --until <ISO timestamp>) --reason "why"
|
|
182
|
+
bschat-admin agent back <project>/<agent>
|
|
177
183
|
bschat-admin enroll create <project> [--name n | --prefix p] [--role r] [--uses n] [--expires-hours h] prints the invite text
|
|
178
184
|
bschat-admin enroll create --account --name n --role r invite an account-wide agent
|
|
179
185
|
bschat-admin enroll list <project>
|
|
@@ -215,6 +221,8 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
215
221
|
Codex-only AppArmor profile so sandboxed agents can run; --bwrap-userns: the same
|
|
216
222
|
for /usr/bin/bwrap (Claude Code's sandbox; broader: any local user may use it)
|
|
217
223
|
bschat-admin machine list | show <name> | remove <name>
|
|
224
|
+
bschat-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
|
|
225
|
+
15 min before, its agents away until the machine reports back after booting
|
|
218
226
|
bschat-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access>
|
|
219
227
|
[--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min]
|
|
220
228
|
bschat-admin machine session stop|start|remove <machine> <project>/<agent>
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { configRoot } from "./config.js";
|
|
4
|
+
export const DRAIN_MS = 15 * 60_000;
|
|
5
|
+
const file = () => join(configRoot(), "state", "maintenance.json");
|
|
6
|
+
export function writeMaintenance(w) {
|
|
7
|
+
if (!w) {
|
|
8
|
+
rmSync(file(), { force: true });
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
mkdirSync(dirname(file()), { recursive: true });
|
|
12
|
+
const tmp = `${file()}.${process.pid}.tmp`;
|
|
13
|
+
writeFileSync(tmp, JSON.stringify(w) + "\n");
|
|
14
|
+
renameSync(tmp, file());
|
|
15
|
+
}
|
|
16
|
+
/** The window holding turns back now, or null. */
|
|
17
|
+
export function drainingUntil(nowMs = Date.now(), text) {
|
|
18
|
+
const raw = text ?? (existsSync(file()) ? readFileSync(file(), "utf8") : null);
|
|
19
|
+
if (!raw)
|
|
20
|
+
return null;
|
|
21
|
+
const w = JSON.parse(raw);
|
|
22
|
+
return nowMs >= Date.parse(w.start) - DRAIN_MS && nowMs < Date.parse(w.end) ? w : null;
|
|
23
|
+
}
|
package/dist/output.js
CHANGED
|
@@ -16,7 +16,7 @@ export function fmtMessage(m) {
|
|
|
16
16
|
}
|
|
17
17
|
export function fmtStatus(s) {
|
|
18
18
|
const parts = [
|
|
19
|
-
`${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
|
|
19
|
+
`${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
|
|
20
20
|
`state=${s.state ?? "-"}`,
|
|
21
21
|
s.goal ? `goal="${s.goal}"` : null,
|
|
22
22
|
s.task ? `task="${s.task}"` : null,
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.74";
|