benignswarm 0.12.114 → 0.12.116

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.
@@ -23,6 +23,19 @@ import { antigravityConversationDb, antigravityLog, antigravityResumeCommand, an
23
23
  import { configureGitCredentialForWorktree } from "./git-credential.js";
24
24
  const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
25
25
  export const DEFAULT_CLAUDE_MAX_BUDGET_USD = 1;
26
+ /** The guard states why it refuses. A refusal without a reason is still a refusal (no turn starts) and is reported as the defect it is. */
27
+ function refusalReason(diagnostic) {
28
+ return diagnostic.at(-1) ?? "the turn guard refused this turn without stating why; that is a CLI defect, report it with b9s feedback";
29
+ }
30
+ function reportMachineStartProgress(state) {
31
+ const file = process.env.BSCHAT_MACHINE_START_PROGRESS_FILE;
32
+ if (!file)
33
+ return;
34
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
35
+ const temp = `${file}.${process.pid}.tmp`;
36
+ writeFileSync(temp, `${JSON.stringify({ state, at: new Date().toISOString() })}\n`, { mode: 0o600 });
37
+ renameSync(temp, file);
38
+ }
26
39
  /**
27
40
  * `b9s start` (and `b9s codex start`): one command that brings an agent up on this machine
28
41
  * headless, with no app involved, so it works the same over ssh on a remote machine. It enrolls the
@@ -246,8 +259,9 @@ export async function harnessStart(p, out, harness) {
246
259
  ].join("\n");
247
260
  const diagnostic = [];
248
261
  if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (m) => diagnostic.push(m), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, harness))) {
249
- throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the onboarding turn");
262
+ throw new CliError("turn_mode_fault", refusalReason(diagnostic));
250
263
  }
264
+ reportMachineStartProgress("onboarding_turn_running");
251
265
  try {
252
266
  if (harness === "codex") {
253
267
  session = await startThread(bin, ["exec", "--json", ...settings, prompt], firstTurnLog, ref);
@@ -569,7 +583,7 @@ export function runClaudeSandboxSelfCheck(bin, settings, maxBudgetUsd, env, cwd,
569
583
  export async function runGuardedClaudeSandboxSelfCheck(ref, turnsPerHour, bin, settings, maxBudgetUsd, env, cwd, session, run = runClaudeSandboxSelfCheck, unproductivePerHour = DEFAULT_UNPRODUCTIVE_PER_HOUR) {
570
584
  const diagnostic = [];
571
585
  if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, "claude-code"))) {
572
- throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the sandbox self-check");
586
+ throw new CliError("turn_mode_fault", refusalReason(diagnostic));
573
587
  }
574
588
  const probe = probeFor("claude-code", session, ref);
575
589
  let result;
@@ -620,7 +634,7 @@ export function assertAntigravitySelfCheck(output) {
620
634
  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) {
621
635
  const diagnostic = [];
622
636
  if (!(await beginTurnGuardAttempt(ref, turnsPerHour, (message) => diagnostic.push(message), process.env, unproductivePerHour, process.env.BSCHAT_MACHINE_SESSION_ID, "antigravity"))) {
623
- throw new CliError("turn_mode_fault", diagnostic.at(-1) ?? "turn mode guard refused the Antigravity sandbox self-check");
637
+ throw new CliError("turn_mode_fault", refusalReason(diagnostic));
624
638
  }
625
639
  const prompt = [
626
640
  "BenignSwarm sandbox startup check. Use your terminal tool to execute these two commands separately, exactly as written:",
@@ -236,8 +236,13 @@ export async function machineAdmin(action, rest, p, out) {
236
236
  const rep = liveReport ?? m.report ?? {};
237
237
  const pressureText = (pressure) => `some ${pressure?.some_avg10 ?? "unknown"}% / full ${pressure?.full_avg10 ?? "unknown"}% (10s avg)`;
238
238
  const agentPressure = rep.agent_cgroup_pressure;
239
+ const limitText = (value) => value === "max" ? "unlimited" : value === 0 ? "0 bytes" : typeof value === "number" ? `${(value / 1024 ** 3).toFixed(1)} GiB` : "unknown";
240
+ const cgroupMemory = agentPressure?.memory_limits;
241
+ const watcherMemory = agentPressure?.watcher_service_memory_limits;
239
242
  const head = [
240
243
  ...[['I/O', 'io_pressure'], ['Memory', 'memory_pressure'], ['CPU', 'cpu_pressure']].map(([label, key]) => ` ${label} PSI host: ${pressureText(rep[key])}; agents: ${agentPressure?.status === "available" ? `${pressureText(agentPressure[key])} (${agentPressure.source})` : `${agentPressure?.status ?? "unknown"}; host PSI used when available`}${liveReport ? "" : "; live sample unavailable"}`),
244
+ cgroupMemory ? ` app.slice memory limits: ${cgroupMemory.status}; MemoryHigh ${limitText(cgroupMemory.memory_high_bytes)}; MemoryMax ${limitText(cgroupMemory.memory_max_bytes)}; MemorySwapMax ${limitText(cgroupMemory.memory_swap_max_bytes)}` : null,
245
+ ...(Array.isArray(watcherMemory?.services) ? watcherMemory.services.map((service) => ` watcher ${String(service.unit ?? "unknown").replace(/^org\.benignswarm\.watch\./, "")}: ${service.status}; measured MemoryMax ${limitText(service.effective_memory_max_bytes)}; configured ${limitText(service.configured_memory_max_bytes)}; current ${limitText(service.memory_current_bytes)}`) : []),
241
246
  `${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}%)`,
242
247
  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?)",
243
248
  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,