benignswarm 0.12.61 → 0.12.63
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.
|
@@ -51,8 +51,13 @@ for b in bschat bschat-admin; do [ -e "$HOME/.local/bin/$b" ] || ln -sf "$(dirna
|
|
|
51
51
|
step bschat ok "$("$bin" --version) $bin"
|
|
52
52
|
`;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Runs `command` on `host` with /bin/sh, whatever the account's login shell: zsh aborts a command
|
|
56
|
+
* whose glob matches nothing (mini1: the archived-sessions pattern of a thread lookup). Output may be
|
|
57
|
+
* a whole Codex thread (ester's sol-reviewer: 87 MB).
|
|
58
|
+
*/
|
|
54
59
|
function ssh(host, command, input) {
|
|
55
|
-
const r = spawnSync("ssh", ["-o", "BatchMode=yes", host, command], { input, encoding: "utf8", timeout: 600_000, maxBuffer:
|
|
60
|
+
const r = spawnSync("ssh", ["-o", "BatchMode=yes", host, `/bin/sh -c ${shellSingle(command)}`], { input, encoding: "utf8", timeout: 600_000, maxBuffer: 512 * 1024 * 1024 });
|
|
56
61
|
if (r.error)
|
|
57
62
|
throw new CliError("ssh_failed", `ssh ${host}: ${r.error.message}`);
|
|
58
63
|
return { status: r.status ?? 255, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
@@ -295,6 +300,7 @@ export function lastTurnSettings(rollout) {
|
|
|
295
300
|
}
|
|
296
301
|
return { model: null, effort: null };
|
|
297
302
|
}
|
|
303
|
+
export const shellSingle = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
298
304
|
/** Runs a shell command on `host` ("local" runs it here). */
|
|
299
305
|
function on(host, command, input) {
|
|
300
306
|
if (host === "local") {
|
package/dist/commands/machine.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, statfsSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { arch, cpus, homedir, hostname, platform, totalmem, userInfo } from "node:os";
|
|
3
|
+
import { arch, cpus, freemem, homedir, hostname, loadavg, platform, totalmem, 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,9 @@ import { configRoot, loadAgent, saveAgent } from "../config.js";
|
|
|
8
8
|
import { CliError } from "../errors.js";
|
|
9
9
|
import { CODEX_APPARMOR_PATH, CODEX_MANAGED_DIR, CODEX_MANAGED_MARK, codexAppArmorProfile, codexManagedHooks } from "../harness.js";
|
|
10
10
|
import { applySparse } from "../git.js";
|
|
11
|
+
import { codexRollout } from "../sessions.js";
|
|
12
|
+
import { readState, writeState } from "../state.js";
|
|
13
|
+
import { readTurnPhase, usageLimitUntil } from "../turn.js";
|
|
11
14
|
import { installService, lingerEnabled, MACHINE_LABEL, removeService, requireInstall, restartWatcher, serviceActive, WATCH_LABEL_PREFIX, watcherServices } from "../install.js";
|
|
12
15
|
import { CLI_VERSION } from "../version.js";
|
|
13
16
|
export const machineFile = () => join(configRoot(), "machine.json");
|
|
@@ -96,7 +99,14 @@ export async function reconcile(m, log) {
|
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
const w = svc();
|
|
99
|
-
|
|
102
|
+
const th = state.sessions[s.id].thread;
|
|
103
|
+
// The operator lifted a usage-limit pause: what bschat codex unpause does, here.
|
|
104
|
+
if (s.unpause_at && state.sessions[s.id].unpause_applied !== s.unpause_at) {
|
|
105
|
+
writeState(s.agent, { ...readState(s.agent), turn_unpaused_at: Date.parse(s.unpause_at) });
|
|
106
|
+
state.sessions[s.id].unpause_applied = s.unpause_at;
|
|
107
|
+
log(`${s.agent}: usage-limit pause lifted by the operator`);
|
|
108
|
+
}
|
|
109
|
+
out.push({ id: s.id, state: "running", dir: s.dir, thread: th, watcher: w && serviceActive(w) ? "active" : "inactive", last_turn: lastTurnLine(s.agent), ...turnFacts(s.agent, th) });
|
|
100
110
|
}
|
|
101
111
|
catch (e) {
|
|
102
112
|
const error = e.message.slice(0, 1000);
|
|
@@ -226,6 +236,27 @@ function errorText(s) {
|
|
|
226
236
|
return last.slice(0, 500);
|
|
227
237
|
}
|
|
228
238
|
}
|
|
239
|
+
/** Whether the thread has a turn running, its process, and a usage-limit pause still in force. */
|
|
240
|
+
function turnFacts(agent, thread) {
|
|
241
|
+
const rollout = thread ? codexRollout(thread) : null;
|
|
242
|
+
if (!thread || !rollout)
|
|
243
|
+
return { turn: { running: false, since: null }, process: null, paused_until: null };
|
|
244
|
+
const ph = readTurnPhase(rollout);
|
|
245
|
+
const until = !ph.running ? usageLimitUntil(ph.lastError) : null;
|
|
246
|
+
const unpausedAt = readState(agent).turn_unpaused_at ?? 0;
|
|
247
|
+
const paused = until && until > Date.now() && Date.parse(ph.lastEventAt ?? "") > unpausedAt ? new Date(until).toISOString() : null;
|
|
248
|
+
return { turn: { running: ph.running, since: ph.running ? ph.startedAt : ph.lastEventAt }, process: ph.running ? turnProcess(thread) : null, paused_until: paused };
|
|
249
|
+
}
|
|
250
|
+
/** The Codex process running a turn of this thread (`codex exec resume <thread>`), from ps. */
|
|
251
|
+
export function turnProcess(thread, psOutput) {
|
|
252
|
+
const out = psOutput ?? (spawnSync("ps", ["-axo", "pid=,pcpu=,rss=,args="], { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 }).stdout ?? "");
|
|
253
|
+
for (const line of out.split("\n")) {
|
|
254
|
+
const m = /^\s*(\d+)\s+([\d.]+)\s+(\d+)\s+(.*)$/.exec(line);
|
|
255
|
+
if (m && /\bcodex\b/.test(m[4]) && m[4].includes(`exec resume ${thread}`) && !m[4].startsWith("/bin/sh"))
|
|
256
|
+
return { pid: Number(m[1]), cpu: Number(m[2]), rss_bytes: Number(m[3]) * 1024 };
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
229
260
|
/** The watcher's latest turn line (started, finished, FAILED, STOPPED, paused), for the report. */
|
|
230
261
|
function lastTurnLine(ref) {
|
|
231
262
|
const f = join(homedir(), ".bschat", "logs", `watch.${ref.replace("/", ".")}.err.log`);
|
|
@@ -253,6 +284,15 @@ export function codexSandbox(force = false) {
|
|
|
253
284
|
sandboxCache = { at: Date.now(), result };
|
|
254
285
|
return result;
|
|
255
286
|
}
|
|
287
|
+
/** Memory a new process could use: Linux's MemAvailable (free alone undercounts the page cache), else free. */
|
|
288
|
+
function memAvailable() {
|
|
289
|
+
if (platform() === "linux") {
|
|
290
|
+
const m = /^MemAvailable:\s+(\d+) kB/m.exec(readFileSync("/proc/meminfo", "utf8"));
|
|
291
|
+
if (m)
|
|
292
|
+
return Number(m[1]) * 1024;
|
|
293
|
+
}
|
|
294
|
+
return freemem();
|
|
295
|
+
}
|
|
256
296
|
/** What the operator needs to know about this machine, reported with every pass. */
|
|
257
297
|
export function machineFacts() {
|
|
258
298
|
const codex = spawnSync("codex", ["--version"], { encoding: "utf8" });
|
|
@@ -268,6 +308,7 @@ export function machineFacts() {
|
|
|
268
308
|
const req = "/etc/codex/requirements.toml";
|
|
269
309
|
return {
|
|
270
310
|
os: platform(), arch: arch(), hostname: hostname(), user: userInfo().username, cpus: cpus().length, mem_total_bytes: totalmem(),
|
|
311
|
+
load: loadavg().map((x) => Math.round(x * 100) / 100), mem_available_bytes: memAvailable(),
|
|
271
312
|
bschat: { version: CLI_VERSION, bin: requireInstall().bin },
|
|
272
313
|
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,
|
|
273
314
|
managed_hooks: existsSync(req) && readFileSync(req, "utf8").includes(CODEX_MANAGED_MARK),
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.63";
|