benignswarm 0.12.94 → 0.12.95
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 +3 -3
- package/dist/boot-time.js +39 -0
- package/dist/build-caches.js +891 -0
- package/dist/commands/admin.js +97 -2
- package/dist/commands/cloud-admin.js +74 -0
- package/dist/commands/codex-start.js +20 -17
- package/dist/commands/machine-admin.js +94 -10
- package/dist/commands/machine.js +130 -28
- package/dist/commands/watch.js +22 -13
- package/dist/commands/wu.js +27 -2
- package/dist/git.js +19 -5
- package/dist/help.js +32 -14
- package/dist/turn-guard.js +31 -12
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/admin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cliUserAgent } from "../legacy-alias.js";
|
|
2
2
|
import { bool, need, str } from "../args.js";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
3
4
|
import { Client } from "../client.js";
|
|
4
5
|
import { DEFAULT_URL, forgetAdmin, loadAdmin, resolveAdminName, saveAdmin } from "../config.js";
|
|
5
6
|
import { hostname } from "node:os";
|
|
@@ -11,6 +12,7 @@ import { awayUntil } from "./agent.js";
|
|
|
11
12
|
import { agentMove, machineAdmin, poolAdmin, projectCheckoutAdmin, projectRepoAdmin } from "./machine-admin.js";
|
|
12
13
|
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, textCheckAdmin, worktreeAdmin } from "./operator.js";
|
|
13
14
|
import { adminNotice } from "./notices.js";
|
|
15
|
+
import { cloudAdmin } from "./cloud-admin.js";
|
|
14
16
|
function adminClient(p) {
|
|
15
17
|
return Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
|
|
16
18
|
}
|
|
@@ -61,7 +63,13 @@ export async function admin(p, out) {
|
|
|
61
63
|
return projectRepoAdmin(rest, p, out);
|
|
62
64
|
if (action === "checkout")
|
|
63
65
|
return projectCheckoutAdmin(rest, p, out);
|
|
66
|
+
if (action === "github")
|
|
67
|
+
return projectGitHubAdmin(rest, p, out);
|
|
68
|
+
if (action === "hosted-merge")
|
|
69
|
+
return projectHostedMergeAdmin(rest, p, out);
|
|
64
70
|
return project(action, rest, p, out);
|
|
71
|
+
case "github":
|
|
72
|
+
return githubAdmin(action, rest, p, out);
|
|
65
73
|
case "agent":
|
|
66
74
|
if (action === "move")
|
|
67
75
|
return agentMove(rest, p, out);
|
|
@@ -109,6 +117,8 @@ export async function admin(p, out) {
|
|
|
109
117
|
case "machine":
|
|
110
118
|
case "machines":
|
|
111
119
|
return machineAdmin(action, rest, p, out);
|
|
120
|
+
case "cloud":
|
|
121
|
+
return cloudAdmin(action, rest, p, out);
|
|
112
122
|
case "pool":
|
|
113
123
|
case "pools":
|
|
114
124
|
return poolAdmin(action, rest, p, out, process.argv.slice(2));
|
|
@@ -126,6 +136,51 @@ export async function admin(p, out) {
|
|
|
126
136
|
throw new CliError("usage", `unknown admin command ${group ?? ""}`, "Run: b9s --help");
|
|
127
137
|
}
|
|
128
138
|
}
|
|
139
|
+
async function githubAdmin(action, rest, p, out) {
|
|
140
|
+
const c = adminClient(p);
|
|
141
|
+
if (action === "status" && !rest.length) {
|
|
142
|
+
const r = await c.call("GET", "/github/repositories");
|
|
143
|
+
const rows = (r.installations ?? []).map((i) => ({ installation: i.installation_id, owner: i.owner_login, repositories: i.repositories?.length ?? 0, settings: i.settings_url }));
|
|
144
|
+
out.print(rows.length ? table(rows, ["installation", "owner", "repositories", "settings"]) : "No GitHub installations connected.", r);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (action === "disconnect" && rest.length === 1 && /^\d{1,20}$/.test(rest[0])) {
|
|
148
|
+
const r = await c.call("DELETE", `/github/installations/${rest[0]}`);
|
|
149
|
+
out.print(`Disconnected GitHub installation ${rest[0]}; linked projects have hosted merge disabled.`, r);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
throw new CliError("usage", "b9s-admin github status | disconnect <installation-id>");
|
|
153
|
+
}
|
|
154
|
+
async function projectGitHubAdmin(rest, p, out) {
|
|
155
|
+
const [project, action, ...extra] = rest;
|
|
156
|
+
if (!project || extra.length)
|
|
157
|
+
throw new CliError("usage", "b9s-admin project github <project> status | unlink");
|
|
158
|
+
const c = adminClient(p);
|
|
159
|
+
if (action === "status") {
|
|
160
|
+
const r = await c.call("GET", `/projects/${project}/github-link`);
|
|
161
|
+
const link = r.link;
|
|
162
|
+
out.print(`${project}: ${link.owner}/${link.name} -> ${link.target_branch}; hosted merge ${r.hosted_merge_enabled ? "enabled" : "disabled"}${link.ruleset_unverified_reason ? `; ruleset unverified: ${link.ruleset_unverified_reason}` : ""}`, r);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (action === "unlink") {
|
|
166
|
+
const r = await c.call("DELETE", `/projects/${project}/github-link`);
|
|
167
|
+
out.print(`Unlinked GitHub repository from ${project}; hosted merge disabled.`, r);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
throw new CliError("usage", "b9s-admin project github <project> status | unlink");
|
|
171
|
+
}
|
|
172
|
+
async function projectHostedMergeAdmin(rest, p, out) {
|
|
173
|
+
const [project, action, ...extra] = rest;
|
|
174
|
+
if (!project || !["enable", "disable"].includes(action ?? "") || extra.length) {
|
|
175
|
+
throw new CliError("usage", "b9s-admin project hosted-merge <project> enable|disable [--confirm-bypass-signal]");
|
|
176
|
+
}
|
|
177
|
+
const enabled = action === "enable";
|
|
178
|
+
const confirmed = bool(p.flags, "confirm-bypass-signal");
|
|
179
|
+
if (enabled && !confirmed)
|
|
180
|
+
throw new CliError("usage", "enable only after the live GitHub bypass-change signal check; pass --confirm-bypass-signal after confirming it");
|
|
181
|
+
const r = await adminClient(p).call("PATCH", `/projects/${project}/github-link`, { hosted_merge_enabled: enabled, ...(enabled ? { bypass_signal_verified: true } : {}) });
|
|
182
|
+
out.print(`Hosted merge ${enabled ? "enabled" : "disabled"} for ${project}.`, r);
|
|
183
|
+
}
|
|
129
184
|
async function project(action, rest, p, out) {
|
|
130
185
|
const c = adminClient(p);
|
|
131
186
|
if (action === "list") {
|
|
@@ -147,6 +202,14 @@ async function agent(action, rest, p, out) {
|
|
|
147
202
|
const c = adminClient(p);
|
|
148
203
|
if (bool(p.flags, "account"))
|
|
149
204
|
return accountAgent(action, rest, p, out, c);
|
|
205
|
+
if (action === "retire") {
|
|
206
|
+
const [ref, extra] = rest;
|
|
207
|
+
const slash = ref?.indexOf("/") ?? -1;
|
|
208
|
+
if (!ref || extra || slash < 1 || slash === ref.length - 1 || ref.indexOf("/", slash + 1) !== -1) {
|
|
209
|
+
throw new CliError("usage", "admin agent retire <project>/<agent> [--note <text> | --note-file <file>] --yes");
|
|
210
|
+
}
|
|
211
|
+
return retireAdminAgent(c, ref, `/projects/${ref.slice(0, slash)}/agents/${ref.slice(slash + 1)}/retire`, p, out);
|
|
212
|
+
}
|
|
150
213
|
if ((action === "bench" || action === "unbench") && rest[0]) {
|
|
151
214
|
const ref = rest[0];
|
|
152
215
|
const slash = ref.indexOf("/");
|
|
@@ -205,10 +268,15 @@ async function agent(action, rest, p, out) {
|
|
|
205
268
|
out.print(`deleted agent ${name}`, r);
|
|
206
269
|
}
|
|
207
270
|
else
|
|
208
|
-
throw new CliError("usage", "admin agent create|list|role|tier <project>/<agent> <tier>|rotate-key|bench|unbench|delete ...", "Run: b9s --help");
|
|
271
|
+
throw new CliError("usage", "admin agent create|list|retire|role|tier <project>/<agent> <tier>|rotate-key|bench|unbench|delete ...", "Run: b9s --help");
|
|
209
272
|
}
|
|
210
273
|
async function accountAgent(action, rest, p, out, c) {
|
|
211
274
|
const [name, extra] = rest;
|
|
275
|
+
if (action === "retire" && name && !extra) {
|
|
276
|
+
if (name.includes("/"))
|
|
277
|
+
throw new CliError("usage", "admin agent --account retire <agent> [--note <text> | --note-file <file>] --yes");
|
|
278
|
+
return retireAdminAgent(c, `account/${name}`, `/agents/${name}/retire`, p, out);
|
|
279
|
+
}
|
|
212
280
|
if ((action === "bench" || action === "unbench") && name) {
|
|
213
281
|
if (name.includes("/"))
|
|
214
282
|
throw new CliError("usage", `agent ${action} --account <agent>${action === "bench" ? " [--note <text>]" : ""}`);
|
|
@@ -244,7 +312,34 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
244
312
|
out.print(`deleted account agent ${name}`, r);
|
|
245
313
|
}
|
|
246
314
|
else
|
|
247
|
-
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | role <name> <role> | tier <name> <tier> | rotate-key <name> | bench|unbench <name> | delete <name>");
|
|
315
|
+
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | retire <name> [--note <text> | --note-file <file>] --yes | role <name> <role> | tier <name> <tier> | rotate-key <name> | bench|unbench <name> | delete <name>");
|
|
316
|
+
}
|
|
317
|
+
async function retireAdminAgent(c, ref, path, p, out) {
|
|
318
|
+
const note = str(p.flags, "note");
|
|
319
|
+
const noteFile = str(p.flags, "note-file");
|
|
320
|
+
if (note !== undefined && noteFile !== undefined)
|
|
321
|
+
throw new CliError("usage", "use either --note or --note-file, not both");
|
|
322
|
+
let handoffNote = note;
|
|
323
|
+
if (noteFile !== undefined) {
|
|
324
|
+
try {
|
|
325
|
+
handoffNote = readFileSync(noteFile, "utf8");
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
throw new CliError("bad_file", `${noteFile}: ${e.message}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (handoffNote !== undefined && !handoffNote.trim())
|
|
332
|
+
throw new CliError("usage", "a retirement note must not be empty");
|
|
333
|
+
if (handoffNote !== undefined && handoffNote.length > 60_000)
|
|
334
|
+
throw new CliError("usage", "a retirement note must be under 60000 chars");
|
|
335
|
+
if (!bool(p.flags, "yes")) {
|
|
336
|
+
out.print(`Would retire ${ref}, revoke its keys, and release its units to the queue.${handoffNote === undefined ? "" : " A resume handoff note will be saved."}\nRe-run with --yes to confirm.`, { would_retire: ref, confirmed: false });
|
|
337
|
+
throw new CliError("confirmation_required", "agent retirement requires --yes");
|
|
338
|
+
}
|
|
339
|
+
const result = await c.call("POST", path, handoffNote === undefined ? {} : { note: handoffNote });
|
|
340
|
+
const released = result.released_units?.length ? `; released units ${result.released_units.join(", ")}` : "";
|
|
341
|
+
const saved = result.handoff ? `; handoff note saved as handoff:${result.handoff.id}` : "";
|
|
342
|
+
out.print(`Retired ${ref}; keys revoked${released}${saved}.`, result);
|
|
248
343
|
}
|
|
249
344
|
function permsFromFlags(p, projectScoped) {
|
|
250
345
|
const raw = str(p.flags, "permissions");
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { CliError } from "../errors.js";
|
|
3
|
+
import { need, str } from "../args.js";
|
|
4
|
+
import { Client } from "../client.js";
|
|
5
|
+
import { loadAdmin, resolveAdminName } from "../config.js";
|
|
6
|
+
export async function cloudAdmin(action, rest, p, out) {
|
|
7
|
+
const creds = loadAdmin(resolveAdminName(str(p.flags, "admin")));
|
|
8
|
+
const c = Client.forAdmin(creds);
|
|
9
|
+
switch (action) {
|
|
10
|
+
case "connect": {
|
|
11
|
+
const file = need(p.flags, "file");
|
|
12
|
+
let value;
|
|
13
|
+
try {
|
|
14
|
+
value = JSON.parse(readFileSync(file, "utf8"));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
throw new CliError("usage", `could not read connection JSON from ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
18
|
+
}
|
|
19
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
20
|
+
throw new CliError("usage", "connection file must contain a JSON object");
|
|
21
|
+
const r = await c.call("POST", "/cloud/connections", value);
|
|
22
|
+
out.print(`Connected AWS account ${r.connection.aws_account_id} in ${r.connection.region}. Save the external ID now; it is shown only in this response.\n\nExternal ID: ${r.external_id}\n\nReview and install this AWS role trust policy and permissions policy:\n\nTrust policy:\n${JSON.stringify(r.policy.trust_policy, null, 2)}\n\nPermissions policy:\n${JSON.stringify(r.policy.permissions_policy, null, 2)}\n\n${r.policy.read_scope_note}`, r);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
case "show": {
|
|
26
|
+
const r = await c.call("GET", "/cloud/connections");
|
|
27
|
+
out.print(r.connection ? `BYO AWS ${r.connection.aws_account_id} / ${r.connection.region}; role ${r.connection.role_arn}; template ${r.connection.template_id}:${r.connection.template_version}; cap ${r.connection.daily_cap_cents} cents/day` : "No BYO AWS connection.", r);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
case "policy": {
|
|
31
|
+
const r = await c.call("GET", "/cloud/connections/policy");
|
|
32
|
+
out.print(`${r.policy.read_scope_note}\n\n${JSON.stringify(r.policy, null, 2)}`, r);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
case "test": {
|
|
36
|
+
const r = await c.call("POST", "/cloud/connections/test", {});
|
|
37
|
+
out.print(r.ok ? `AWS connection verified: ${r.aws_account_id} / ${r.region}; ${r.checks.join(", ")}` : `AWS permission test failed: ${r.reason}`, r);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
case "disconnect": {
|
|
41
|
+
const r = await c.call("DELETE", "/cloud/connections");
|
|
42
|
+
out.print("BYO AWS connection disabled.", r);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
case "launch": {
|
|
46
|
+
const machine = need(p.flags, "machine"), idempotency = need(p.flags, "idempotency-key");
|
|
47
|
+
const r = await c.call("POST", "/cloud/operations", { machine_id: machine, idempotency_key: idempotency });
|
|
48
|
+
out.print(`Cloud operation ${r.operation.id}: ${r.operation.state} (${r.operation.idempotency_key})`, r);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
case "operations": {
|
|
52
|
+
const r = await c.call("GET", "/cloud/operations");
|
|
53
|
+
out.print(JSON.stringify(r.operations, null, 2), r);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
case "inspect": {
|
|
57
|
+
const id = rest[0];
|
|
58
|
+
if (!id)
|
|
59
|
+
throw new CliError("usage", "cloud inspect <operation-id>");
|
|
60
|
+
const r = await c.call("GET", `/cloud/operations/${encodeURIComponent(id)}/provider`);
|
|
61
|
+
out.print(`Operation ${id}: provider ${r.provider_state ?? "not launched"}; ownership proof ${r.ownership_verified ? "verified" : "not verified"}`, r);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
case "terminate": {
|
|
65
|
+
const id = rest[0];
|
|
66
|
+
if (!id)
|
|
67
|
+
throw new CliError("usage", "cloud terminate <operation-id>");
|
|
68
|
+
const r = await c.call("POST", `/cloud/operations/${encodeURIComponent(id)}/terminate`, { reason: need(p.flags, "reason") });
|
|
69
|
+
out.print(`Operation ${id}: ${r.state}`, r);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
default: throw new CliError("usage", "cloud connect|show|policy|test|disconnect|launch|operations|inspect|terminate");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -16,7 +16,7 @@ import { beginTurnGuardAttempt, completePendingTurnGuard, installWatcherService
|
|
|
16
16
|
import { randomUUID } from "node:crypto";
|
|
17
17
|
import { HARNESS_BIN, HARNESS_LABEL, assertClaudeSelfCheck, claudeCodePath, claudeResultError, claudeResultFile, claudeSandboxEnv, claudeSettings, claudeTranscript, claudeTurnArgs, dshPath, dshResultError, dshSessionFromEvents, dshSettings, dshTurnLog, probeFor } from "../harnesses.js";
|
|
18
18
|
import { claudeTurnEnv } from "../providers.js";
|
|
19
|
-
import { DEFAULT_TURNS_PER_HOUR, MAX_TURNS_PER_HOUR } from "../turn-guard.js";
|
|
19
|
+
import { DEFAULT_TURNS_PER_HOUR, DEFAULT_UNPRODUCTIVE_PER_HOUR, MAX_TURNS_PER_HOUR } from "../turn-guard.js";
|
|
20
20
|
import { antigravityConversationDb, antigravityLog, antigravityResumeCommand, antigravitySettings, antigravityTotalTokens, antigravityTurnArgs, antigravityTurnEnv, runAntigravityTurn } from "../antigravity.js";
|
|
21
21
|
import { configureGitCredentialForWorktree } from "./git-credential.js";
|
|
22
22
|
const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
|
|
@@ -69,6 +69,9 @@ export async function harnessStart(p, out, harness) {
|
|
|
69
69
|
const turnsPerHour = Number(str(p.flags, "turns-per-hour") ?? String(DEFAULT_TURNS_PER_HOUR));
|
|
70
70
|
if (!Number.isInteger(turnsPerHour) || turnsPerHour < 1 || turnsPerHour > MAX_TURNS_PER_HOUR)
|
|
71
71
|
throw new CliError("usage", `--turns-per-hour must be a whole number between 1 and ${MAX_TURNS_PER_HOUR}`);
|
|
72
|
+
const unproductivePerHour = Number(str(p.flags, "unproductive-per-hour") ?? String(DEFAULT_UNPRODUCTIVE_PER_HOUR));
|
|
73
|
+
if (!Number.isInteger(unproductivePerHour) || unproductivePerHour < 1 || unproductivePerHour > 60)
|
|
74
|
+
throw new CliError("usage", "--unproductive-per-hour must be a whole number between 1 and 60");
|
|
72
75
|
const interval = Number(str(p.flags, "interval") ?? "30");
|
|
73
76
|
if (!Number.isInteger(interval) || interval < 5)
|
|
74
77
|
throw new CliError("usage", "--interval must be an integer number of seconds, at least 5");
|
|
@@ -143,7 +146,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
143
146
|
const priorState = readState(ref);
|
|
144
147
|
if (priorState.turn_guard?.fault) {
|
|
145
148
|
const fault = priorState.turn_guard.fault;
|
|
146
|
-
throw new CliError("turn_mode_fault", `turn mode is stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.
|
|
149
|
+
throw new CliError("turn_mode_fault", `turn mode is stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; resume it with b9s-admin machine session resume; last output: ${fault.output_tail || "(empty)"}`);
|
|
147
150
|
}
|
|
148
151
|
const initialTurnPending = priorState.turn_guard?.turns.some((attempt) => attempt.productive === null) ?? false;
|
|
149
152
|
const rememberedSession = initialTurnPending && priorState.harness_session?.harness === harness ? priorState.harness_session.session_id : null;
|
|
@@ -172,7 +175,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
172
175
|
if (!claudeTranscript(session))
|
|
173
176
|
throw new CliError("not_found", `no Claude Code transcript for session ${session} under ~/.claude/projects on this machine`);
|
|
174
177
|
if (sandbox === "workspace-write") {
|
|
175
|
-
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), randomUUID());
|
|
178
|
+
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), randomUUID(), undefined, unproductivePerHour);
|
|
176
179
|
}
|
|
177
180
|
lines.push(`Adopted Claude Code session ${session}. Do not resume it in a terminal while the watcher runs it: two clients on one session conflict.`);
|
|
178
181
|
}
|
|
@@ -187,7 +190,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
187
190
|
lines.push(`Adopted Antigravity conversation ${session}. Do not resume it elsewhere while the watcher runs it: two clients on one conversation conflict.`);
|
|
188
191
|
}
|
|
189
192
|
if (harness === "antigravity" && sandbox === "workspace-write")
|
|
190
|
-
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour);
|
|
193
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
191
194
|
}
|
|
192
195
|
}
|
|
193
196
|
else {
|
|
@@ -195,7 +198,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
195
198
|
// first real turn resumes this same checked session and receives a separate reservation below.
|
|
196
199
|
if (harness === "claude-code" && sandbox === "workspace-write") {
|
|
197
200
|
session = randomUUID();
|
|
198
|
-
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), session);
|
|
201
|
+
await runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, providerEnv, process.cwd(), session, undefined, unproductivePerHour);
|
|
199
202
|
}
|
|
200
203
|
const logDir = joinPath(configRoot(), "logs");
|
|
201
204
|
mkdirSync(logDir, { recursive: true });
|
|
@@ -207,7 +210,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
207
210
|
`If you ran on another machine before, read your latest note first: \`b9s handoffs --agent ${creds.agent}\` (your units, branches and chat are on the server as before).`,
|
|
208
211
|
].join("\n");
|
|
209
212
|
const diagnostic = [];
|
|
210
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (m) => diagnostic.push(m)))) {
|
|
213
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (m) => diagnostic.push(m), process.env, unproductivePerHour))) {
|
|
211
214
|
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the onboarding turn");
|
|
212
215
|
}
|
|
213
216
|
try {
|
|
@@ -227,7 +230,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
227
230
|
await completePendingTurnGuard(ref, probeFor(harness, session, ref), (message) => diagnostic.push(message), started.output, antigravityTokenTotal(started.record.result?.usage));
|
|
228
231
|
lines.push(`Started Antigravity conversation ${session}; its first turn (reading its role and inbox) completed, JSON turn log: ${firstTurnLog}`);
|
|
229
232
|
if (sandbox === "workspace-write")
|
|
230
|
-
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox));
|
|
233
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
231
234
|
}
|
|
232
235
|
else {
|
|
233
236
|
// Claude Code takes the session id from us, so nothing has to be read back from its output.
|
|
@@ -241,7 +244,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
241
244
|
await completePendingTurnGuard(ref, probeFor(harness, session ?? "", ref), (m) => diagnostic.push(m), `${error.message}\n${raw}`.slice(-800));
|
|
242
245
|
const fault = readState(ref).turn_guard?.fault;
|
|
243
246
|
if (fault)
|
|
244
|
-
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
247
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
245
248
|
throw error;
|
|
246
249
|
}
|
|
247
250
|
}
|
|
@@ -276,7 +279,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
276
279
|
// volume had 750 GB free, and which empties /tmp at every boot.
|
|
277
280
|
const tmp = sessionTmpDir(process.cwd(), creds.agent);
|
|
278
281
|
mkdirSync(tmp, { recursive: true });
|
|
279
|
-
installWatcherService(ref, exec, interval, Number(str(p.flags, "follow-delay") ?? "300"), { TMPDIR: tmp, ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox, BSCHAT_MODEL: model, ...(effort ? { BSCHAT_EFFORT: effort } : {}) } : {}) }, undefined, { json: false, print: (h) => watcherOut.push(h) }, bool(p.flags, "prune"), { harness, session, timeout: turnTimeout, turnsPerHour, provider, model });
|
|
282
|
+
installWatcherService(ref, exec, interval, Number(str(p.flags, "follow-delay") ?? "300"), { TMPDIR: tmp, ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox, BSCHAT_MODEL: model, ...(effort ? { BSCHAT_EFFORT: effort } : {}) } : {}) }, undefined, { json: false, print: (h) => watcherOut.push(h) }, bool(p.flags, "prune"), { harness, session, timeout: turnTimeout, turnsPerHour, unproductivePerHour, provider, model });
|
|
280
283
|
const wl = watcherOut.join("\n").split("\n");
|
|
281
284
|
lines.push(wl[0].replace(/^Wrote /, "Watcher: wrote "), ...wl.filter((l) => l.startsWith("Linger is off")));
|
|
282
285
|
// 5. Hooks.
|
|
@@ -453,9 +456,9 @@ export function runClaudeSandboxSelfCheck(bin, settings, maxBudgetUsd, env, cwd,
|
|
|
453
456
|
return { output, tokens };
|
|
454
457
|
}
|
|
455
458
|
/** Guard a model-spending connectivity preflight independently from the agent's real turn. */
|
|
456
|
-
export async function runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, env, cwd, session, run = runClaudeSandboxSelfCheck) {
|
|
459
|
+
export async function runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, env, cwd, session, run = runClaudeSandboxSelfCheck, unproductivePerHour = DEFAULT_UNPRODUCTIVE_PER_HOUR) {
|
|
457
460
|
const diagnostic = [];
|
|
458
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message)))) {
|
|
461
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour))) {
|
|
459
462
|
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the sandbox self-check");
|
|
460
463
|
}
|
|
461
464
|
const probe = probeFor("claude-code", session, ref);
|
|
@@ -468,13 +471,13 @@ export async function runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, s
|
|
|
468
471
|
await completePendingTurnGuard(ref, probe, (message) => diagnostic.push(message), output, null);
|
|
469
472
|
const fault = readState(ref).turn_guard?.fault;
|
|
470
473
|
if (fault)
|
|
471
|
-
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
474
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
472
475
|
throw error;
|
|
473
476
|
}
|
|
474
477
|
await completePendingTurnGuard(ref, probe, (message) => diagnostic.push(message), result.output, result.tokens);
|
|
475
478
|
const fault = readState(ref).turn_guard?.fault;
|
|
476
479
|
if (fault)
|
|
477
|
-
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
480
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
478
481
|
}
|
|
479
482
|
function antigravityTokenTotal(usage) {
|
|
480
483
|
return antigravityTotalTokens(usage);
|
|
@@ -504,9 +507,9 @@ export function assertAntigravitySelfCheck(output) {
|
|
|
504
507
|
}
|
|
505
508
|
}
|
|
506
509
|
/** Run the two connectivity checks through the real model tools inside the per-turn sandbox. */
|
|
507
|
-
export async function runAntigravitySandboxSelfCheck(ref, bin, settings, cwd, session, model, effort, timeoutSeconds, logPath, turnsPerHour = DEFAULT_TURNS_PER_HOUR, env = antigravityTurnEnv("workspace-write")) {
|
|
510
|
+
export async function runAntigravitySandboxSelfCheck(ref, bin, settings, cwd, session, model, effort, timeoutSeconds, logPath, turnsPerHour = DEFAULT_TURNS_PER_HOUR, env = antigravityTurnEnv("workspace-write"), unproductivePerHour = DEFAULT_UNPRODUCTIVE_PER_HOUR) {
|
|
508
511
|
const diagnostic = [];
|
|
509
|
-
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message)))) {
|
|
512
|
+
if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour))) {
|
|
510
513
|
throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the Antigravity sandbox self-check");
|
|
511
514
|
}
|
|
512
515
|
const prompt = [
|
|
@@ -524,13 +527,13 @@ export async function runAntigravitySandboxSelfCheck(ref, bin, settings, cwd, se
|
|
|
524
527
|
await completePendingTurnGuard(ref, probeFor("antigravity", session, ref), (message) => diagnostic.push(message), error.message, null);
|
|
525
528
|
const fault = readState(ref).turn_guard?.fault;
|
|
526
529
|
if (fault)
|
|
527
|
-
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
530
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
528
531
|
throw error;
|
|
529
532
|
}
|
|
530
533
|
await completePendingTurnGuard(ref, probeFor("antigravity", session, ref), (message) => diagnostic.push(message), started.output, antigravityTokenTotal(started.record.result?.usage));
|
|
531
534
|
const fault = readState(ref).turn_guard?.fault;
|
|
532
535
|
if (fault)
|
|
533
|
-
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
536
|
+
throw new CliError("turn_mode_fault", `turn mode stopped after ${fault.reason === "unproductive" ? `${fault.consecutive_unproductive} consecutive turns without a BenignSwarm call` : `${fault.unproductive_last_hour} unproductive turns in the rolling hour`}; estimated tokens spent: ${fault.estimated_tokens}; last output: ${fault.output_tail || "(empty)"}`);
|
|
534
537
|
assertAntigravitySelfCheck(started.output);
|
|
535
538
|
}
|
|
536
539
|
/**
|
|
@@ -140,14 +140,43 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
140
140
|
const m = r.machine;
|
|
141
141
|
const rep = m.report ?? {};
|
|
142
142
|
const head = [
|
|
143
|
-
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; writable ${(m.writable ?? []).join(", ") || "-"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}`,
|
|
143
|
+
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; writable ${(m.writable ?? []).join(", ") || "-"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}; cache budget ${m.cache_budget_gb ?? 40} GB (floor ${m.cache_floor_pct ?? 15}%)`,
|
|
144
144
|
rep.os ? ` ${rep.os}/${rep.arch} ${rep.hostname} as ${rep.user}; ${rep.cpus ?? "?"} CPUs, ${rep.mem_total_bytes ? `${Math.round(rep.mem_total_bytes / 1024 ** 3)} GB RAM` : "? RAM"}; b9s ${rep.bschat?.version}; codex ${rep.codex ? `${rep.codex.version}, ${rep.codex.logged_in ? "logged in" : "NOT logged in"}, sandbox ${rep.codex.sandbox ? (rep.codex.sandbox.ok ? "ok" : `FAILS (${rep.codex.sandbox.error})`) : "?"}` : "missing"}; hooks ${rep.managed_hooks ? "managed by policy" : "user-level"}; linger ${rep.linger ?? "n/a"}; disk free ${rep.disk_free_bytes ? `${Math.round(rep.disk_free_bytes / 1e9)} GB` : "?"}` : " (no report yet: is its daemon running?)",
|
|
145
|
+
rep.os ? ` Antigravity: ${rep.antigravity ? `${rep.antigravity.version ?? "agy"}, ${rep.antigravity.available ? "available" : "unavailable"}, ${rep.antigravity.logged_in ? "logged in" : "not logged in"}, sandbox ${rep.antigravity.sandbox ? (rep.antigravity.sandbox.ok ? "ok" : `FAILS (${rep.antigravity.sandbox.error})`) : "not checked"}` : "not installed"}` : null,
|
|
145
146
|
];
|
|
147
|
+
const cacheLines = [];
|
|
148
|
+
const declaredCaches = (m.build_caches ?? []);
|
|
149
|
+
if (declaredCaches.length)
|
|
150
|
+
cacheLines.push(` declared build caches: ${declaredCaches.map((c) => c.path).join(", ")}`);
|
|
151
|
+
const cacheReport = rep.build_caches;
|
|
152
|
+
if (cacheReport) {
|
|
153
|
+
for (const v of cacheReport.volumes ?? []) {
|
|
154
|
+
const freed = v.freed_bytes > 0 ? `, freed ${Math.round(v.freed_bytes / 1e6)} MB` : "";
|
|
155
|
+
cacheLines.push(` volume ${v.mount}: ${v.free_pct.toFixed(1)}% free${v.under_floor ? " (UNDER FLOOR)" : ""}${freed}`);
|
|
156
|
+
}
|
|
157
|
+
for (const cItem of cacheReport.caches ?? []) {
|
|
158
|
+
const mb = Math.round(cItem.size_bytes / 1e6);
|
|
159
|
+
const protectedNote = cItem.skipped_protected?.length ? `; retained protected: ${cItem.skipped_protected.join(", ")}` : "";
|
|
160
|
+
const note = cItem.status === "skipped_in_use"
|
|
161
|
+
? ` (${cItem.probe_incomplete ? "inspection incomplete: " : "in use by "}${(cItem.active_processes ?? []).join(", ")}${protectedNote})`
|
|
162
|
+
: cItem.status === "skipped_protected"
|
|
163
|
+
? ` (protected subtrees retained: ${(cItem.skipped_protected ?? []).join(", ")})`
|
|
164
|
+
: cItem.status === "cleaned"
|
|
165
|
+
? ` (cleaned ${Math.round(cItem.removed_bytes / 1e6)} MB${protectedNote})`
|
|
166
|
+
: protectedNote ? ` (${protectedNote.slice(2)})` : "";
|
|
167
|
+
cacheLines.push(` cache ${cItem.path} [${cItem.volume}]: ${mb} MB [${cItem.status}]${note}`);
|
|
168
|
+
}
|
|
169
|
+
for (const f of cacheReport.faults ?? []) {
|
|
170
|
+
cacheLines.push(f.kind === "inspection_incomplete"
|
|
171
|
+
? ` FAULT ${f.volume}: ${f.reason ?? "build process inspection incomplete"} (${(f.caches ?? []).join(", ")}; uninspected: ${(f.processes ?? []).join(", ") || "unknown"})`
|
|
172
|
+
: ` FAULT ${f.volume}: ${f.free_pct.toFixed(1)}% < ${f.floor_pct}% floor while ${(f.processes ?? []).join(", ") || "build"} uses ${(f.caches ?? []).join(", ")}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
146
175
|
const capabilityLines = machineCapabilityLines(m.capabilities ?? []);
|
|
147
176
|
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", thread: s.thread ?? "-", harness: s.harness, provider: s.provider ?? "anthropic", 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+ b9s watch\[[^\]]+\]: /, "") }));
|
|
148
177
|
const providers = rep.claude_code?.providers ?? {};
|
|
149
178
|
const providerLines = Object.entries(providers).map(([provider, check]) => ` Claude Code ${provider}: ${check.logged_in ? "verified" : `NOT verified (${check.reason ?? "unknown reason"})`}`);
|
|
150
|
-
return out.print([...head, ...capabilityLines, ...providerLines, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "harness", "provider", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].join("\n"), r);
|
|
179
|
+
return out.print([...head, ...cacheLines, ...capabilityLines, ...providerLines, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "harness", "provider", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].filter((line) => line !== null).join("\n"), r);
|
|
151
180
|
}
|
|
152
181
|
if (action === "maintenance") {
|
|
153
182
|
// A window on the machine: no new turns from 15 min before, its agents away until it ends.
|
|
@@ -179,6 +208,49 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
179
208
|
const r = await c.call("PATCH", `/machines/${name}`, { workdir: path === "default" ? null : path });
|
|
180
209
|
return out.print(`${name}: pool checkouts go to ${r.machine.workdir ?? "~/bschat"} from its next pass (existing checkouts stay where they are).`, r);
|
|
181
210
|
}
|
|
211
|
+
if (action === "cache-budget") {
|
|
212
|
+
const name = rest[0];
|
|
213
|
+
const budgetArg = rest[1];
|
|
214
|
+
const floorArg = str(p.flags, "floor");
|
|
215
|
+
const usage = "machine cache-budget <name> [<GB> | default] [--floor <pct | default>] (per declared cache directory; default 40 GB budget, 15% free volume floor)";
|
|
216
|
+
if (!name || (!budgetArg && !floorArg))
|
|
217
|
+
throw new CliError("usage", usage);
|
|
218
|
+
const body = {};
|
|
219
|
+
if (budgetArg !== undefined) {
|
|
220
|
+
if (budgetArg === "default")
|
|
221
|
+
body.cache_budget_gb = null;
|
|
222
|
+
else {
|
|
223
|
+
const gb = Number(budgetArg);
|
|
224
|
+
if (!Number.isInteger(gb) || gb < 1 || gb > 100_000)
|
|
225
|
+
throw new CliError("usage", "cache-budget <GB> must be a whole number 1..100000, or 'default'");
|
|
226
|
+
body.cache_budget_gb = gb;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (floorArg !== undefined) {
|
|
230
|
+
if (floorArg === "default")
|
|
231
|
+
body.cache_floor_pct = null;
|
|
232
|
+
else {
|
|
233
|
+
const pct = Number(floorArg);
|
|
234
|
+
if (!Number.isInteger(pct) || pct < 1 || pct > 90)
|
|
235
|
+
throw new CliError("usage", "--floor <pct> must be a whole percentage 1..90, or 'default'");
|
|
236
|
+
body.cache_floor_pct = pct;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const r = await c.call("PATCH", `/machines/${name}`, body);
|
|
240
|
+
const gb = r.machine.cache_budget_gb ?? 40;
|
|
241
|
+
const fl = r.machine.cache_floor_pct ?? 15;
|
|
242
|
+
return out.print(`${name}: build cache budget ${gb} GB${r.machine.cache_budget_gb == null ? " (default)" : ""}, volume free-space floor ${fl}%${r.machine.cache_floor_pct == null ? " (default)" : ""}.`, r);
|
|
243
|
+
}
|
|
244
|
+
if (action === "caches") {
|
|
245
|
+
const name = rest[0];
|
|
246
|
+
if (!name || rest.length < 2)
|
|
247
|
+
throw new CliError("usage", "machine caches <name> <path...> | none [--tool auto|cargo|generic] [--processes cmd,...] (declared build cache paths managed by the daemon)");
|
|
248
|
+
const tool = str(p.flags, "tool");
|
|
249
|
+
const processes = (str(p.flags, "processes") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
250
|
+
const build_caches = rest[1] === "none" ? [] : rest.slice(1).map((path) => ({ path, ...(tool ? { tool } : {}), ...(processes.length ? { processes } : {}) }));
|
|
251
|
+
const r = await c.call("PATCH", `/machines/${name}`, { build_caches });
|
|
252
|
+
return out.print(`${name}: declared build caches ${r.machine.build_caches.map((x) => x.path).join(", ") || "(none; only project-declared caches apply)"}.`, r);
|
|
253
|
+
}
|
|
182
254
|
if (action === "label" || action === "slots") {
|
|
183
255
|
const name = rest[0];
|
|
184
256
|
if (!name)
|
|
@@ -211,13 +283,17 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
211
283
|
if (sub === "add") {
|
|
212
284
|
const turnTimeout = str(p.flags, "turn-timeout");
|
|
213
285
|
const turnsPerHour = str(p.flags, "turns-per-hour");
|
|
286
|
+
const unproductivePerHour = str(p.flags, "unproductive-per-hour");
|
|
214
287
|
if (turnsPerHour !== undefined && (!/^\d+$/.test(turnsPerHour) || Number(turnsPerHour) < 1 || Number(turnsPerHour) > 60))
|
|
215
288
|
throw new CliError("usage", "--turns-per-hour must be a whole number from 1 to 60");
|
|
289
|
+
if (unproductivePerHour !== undefined && (!/^\d+$/.test(unproductivePerHour) || Number(unproductivePerHour) < 1 || Number(unproductivePerHour) > 60))
|
|
290
|
+
throw new CliError("usage", "--unproductive-per-hour must be a whole number from 1 to 60");
|
|
216
291
|
const body = {
|
|
217
292
|
project, agent, harness: str(p.flags, "harness") ?? "codex", provider: str(p.flags, "provider") ?? "anthropic", dir: str(p.flags, "dir"), sandbox: str(p.flags, "sandbox"),
|
|
218
293
|
model: str(p.flags, "model"), effort: str(p.flags, "effort"), thread: str(p.flags, "thread"),
|
|
219
294
|
...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
|
|
220
295
|
...(turnsPerHour ? { turns_per_hour: Number(turnsPerHour) } : {}),
|
|
296
|
+
...(unproductivePerHour ? { unproductive_per_hour: Number(unproductivePerHour) } : {}),
|
|
221
297
|
create: bool(p.flags, "create"), role: str(p.flags, "role"),
|
|
222
298
|
};
|
|
223
299
|
const r = await c.call("POST", `/machines/${machineName}/sessions`, body);
|
|
@@ -240,10 +316,15 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
240
316
|
}
|
|
241
317
|
if (sub === "limit") {
|
|
242
318
|
const value = str(p.flags, "turns-per-hour");
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
319
|
+
const unproductive = str(p.flags, "unproductive-per-hour");
|
|
320
|
+
if (!value && !unproductive)
|
|
321
|
+
throw new CliError("usage", "machine session limit <machine> <project>/<agent> [--turns-per-hour <1..60>] [--unproductive-per-hour <1..60>]");
|
|
322
|
+
if (value && (!/^\d+$/.test(value) || Number(value) < 1 || Number(value) > 60))
|
|
323
|
+
throw new CliError("usage", "--turns-per-hour must be a whole number from 1 to 60");
|
|
324
|
+
if (unproductive && (!/^\d+$/.test(unproductive) || Number(unproductive) < 1 || Number(unproductive) > 60))
|
|
325
|
+
throw new CliError("usage", "--unproductive-per-hour must be a whole number from 1 to 60");
|
|
326
|
+
const r = await c.call("PATCH", `/machines/${machineName}/sessions/${project}/${agent}`, { ...(value ? { turns_per_hour: Number(value) } : {}), ...(unproductive ? { unproductive_per_hour: Number(unproductive) } : {}) });
|
|
327
|
+
return out.print(`${ref} on ${machineName}: ${value ? `busy cap ${value}/hour` : "busy cap unchanged"}; ${unproductive ? `${unproductive} unproductive turns/hour` : "unproductive fault threshold unchanged"}; the daemon applies changes within 30 s.`, r);
|
|
247
328
|
}
|
|
248
329
|
if (sub === "remove") {
|
|
249
330
|
await c.call("DELETE", `/machines/${machineName}/sessions/${project}/${agent}`);
|
|
@@ -273,13 +354,13 @@ export function repeated(argv, flag) {
|
|
|
273
354
|
return out;
|
|
274
355
|
}
|
|
275
356
|
/**
|
|
276
|
-
* pool set <project>/<name> --role r --variant spec [--variant ...] --count n --sandbox mode [--needs a,b] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..60]
|
|
357
|
+
* pool set <project>/<name> --role r --variant spec [--variant ...] --count n --sandbox mode [--needs a,b] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..60] [--unproductive-per-hour 1..60]
|
|
277
358
|
* pool list [project] | show <project>/<name> | remove <project>/<name>
|
|
278
359
|
*/
|
|
279
360
|
export async function poolAdmin(action, rest, p, out, argv) {
|
|
280
361
|
const c = adminClient(p);
|
|
281
362
|
const statusLines = (pool) => [
|
|
282
|
-
`${pool.project}/${pool.name}: ${pool.count} × role ${pool.role ?? "(none)"}, ${pool.sandbox};
|
|
363
|
+
`${pool.project}/${pool.name}: ${pool.count} × role ${pool.role ?? "(none)"}, ${pool.sandbox}; busy cap ${pool.turns_per_hour ?? 60}/hour, unproductive fault ${pool.unproductive_per_hour ?? 6}/hour; variants ${pool.variants.map((v) => `${v.tag}=${v.harness}:${v.model ?? "default"}${v.effort ? `:${v.effort}` : ""}${v.weight > 1 ? `*${v.weight}` : ""}${v.provider && v.provider !== "anthropic" ? `@${v.provider}` : ""}`).join(", ")}${pool.needs?.labels?.length ? `; needs ${pool.needs.labels.join(", ")}` : ""}${pool.needs?.min_ram_gb ? `; min ${pool.needs.min_ram_gb} GB` : ""}`,
|
|
283
364
|
...(pool.status?.placed ?? []).map((x) => ` ${x.agent.padEnd(32)} on ${x.machine}`),
|
|
284
365
|
...(pool.status?.unplaced ?? []).map((x) => ` ${x.agent.padEnd(32)} NOT PLACED: ${x.reason}`),
|
|
285
366
|
];
|
|
@@ -288,13 +369,16 @@ export async function poolAdmin(action, rest, p, out, argv) {
|
|
|
288
369
|
const variants = repeated(argv, "variant").map(parseVariant);
|
|
289
370
|
const count = Number(str(p.flags, "count"));
|
|
290
371
|
if (!project || !name || !variants.length || !Number.isInteger(count))
|
|
291
|
-
throw new CliError("usage", "pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...] --count <n> --sandbox <read-only|workspace-write|danger-full-access> [--needs label,label] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..60]");
|
|
372
|
+
throw new CliError("usage", "pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...] --count <n> --sandbox <read-only|workspace-write|danger-full-access> [--needs label,label] [--min-ram GB] [--turn-timeout min] [--turns-per-hour 1..60] [--unproductive-per-hour 1..60]");
|
|
292
373
|
const needs = { ...(str(p.flags, "needs") ? { labels: str(p.flags, "needs").split(",").map((x) => x.trim()).filter(Boolean) } : {}), ...(str(p.flags, "min-ram") ? { min_ram_gb: Number(str(p.flags, "min-ram")) } : {}) };
|
|
293
374
|
const tt = str(p.flags, "turn-timeout");
|
|
294
375
|
const tph = str(p.flags, "turns-per-hour");
|
|
376
|
+
const uph = str(p.flags, "unproductive-per-hour");
|
|
295
377
|
if (tph !== undefined && (!/^\d+$/.test(tph) || Number(tph) < 1 || Number(tph) > 60))
|
|
296
378
|
throw new CliError("usage", "--turns-per-hour must be a whole number from 1 to 60");
|
|
297
|
-
|
|
379
|
+
if (uph !== undefined && (!/^\d+$/.test(uph) || Number(uph) < 1 || Number(uph) > 60))
|
|
380
|
+
throw new CliError("usage", "--unproductive-per-hour must be a whole number from 1 to 60");
|
|
381
|
+
const r = await c.call("PUT", `/projects/${project}/pools/${name}`, { role: str(p.flags, "role") ?? null, variants, count, sandbox: str(p.flags, "sandbox"), needs, ...(tt ? { turn_timeout: Number(tt) } : {}), ...(tph ? { turns_per_hour: Number(tph) } : {}), ...(uph ? { unproductive_per_hour: Number(uph) } : {}) });
|
|
298
382
|
return out.print([...statusLines(r.pool), "Their machines' daemons start them within 30 s: b9s-admin machine show <machine>"].join("\n"), r);
|
|
299
383
|
}
|
|
300
384
|
if (action === "list" || action === undefined) {
|