benignswarm 0.12.63 → 0.12.65

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.
@@ -9,6 +9,7 @@ import { requireInstall } from "../install.js";
9
9
  import { bindSession, codexArchivedRollout, codexRollout } from "../sessions.js";
10
10
  import { codexHooksPath } from "./codex.js";
11
11
  import { CODEX_MANAGED_MARK } from "../harness.js";
12
+ import { readState, writeState } from "../state.js";
12
13
  import { join } from "./join.js";
13
14
  import { installWatcherService } from "./watch.js";
14
15
  const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
@@ -88,6 +89,11 @@ export async function codexStart(p, out) {
88
89
  }
89
90
  // 3. Bind it, so the hooks in that thread deliver to this agent and nobody else.
90
91
  bindSession("codex", thread, ref);
92
+ // A thread adopted here may end in a usage-limit error from the machine it came from, written in
93
+ // that machine's local time ("3:32 PM" Central read as UTC on ronald: six hours off). Only errors
94
+ // from turns on this machine pause it; if the account is still limited, the next turn says so here.
95
+ if (adopt)
96
+ writeState(ref, { ...readState(ref), turn_unpaused_at: Date.now() });
91
97
  // 4. The watcher, in turn mode: it runs each later turn itself.
92
98
  const exec = [codexBin, "exec", "resume", thread, ...settings].map(shq).join(" ") + " {text}";
93
99
  const watcherOut = [];
@@ -126,7 +126,8 @@ export async function reconcile(m, log) {
126
126
  delete state.sessions[id];
127
127
  }
128
128
  writeMachineState(state);
129
- const report = { ...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()) };
129
+ const clones = refreshClones(workdir, [...new Set(desired.filter((s) => !s.dir && s.project && s.desired === "running").map((s) => s.project))], log);
130
+ const report = { ...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones };
130
131
  await client.call("POST", "/machines/me/report", { report, sessions: out });
131
132
  return { sessions: out, report };
132
133
  }
@@ -197,6 +198,48 @@ export function ensureCheckout(s, log, workdir = null) {
197
198
  return { dir };
198
199
  }
199
200
  const shq = (x) => `'${x.replace(/'/g, `'\\''`)}'`;
201
+ const CLONE_REFRESH_MS = 10 * 60_000;
202
+ let clonesRefreshedAt = 0;
203
+ /** Tests reset the 10-minute throttle. */
204
+ export const resetCloneRefresh = () => { clonesRefreshedAt = 0; };
205
+ let lastClones = {};
206
+ /**
207
+ * Keeps each project clone's checked-out branch current: fetch, then fast-forward when it is clean.
208
+ * Unless a project requires pushed work, wu start branches from the clone's local target, so a
209
+ * clone made once went stale (ronald's benignswarm clone was 52 commits behind GitHub within a day).
210
+ * Anything it cannot fast-forward is reported, never forced.
211
+ */
212
+ export function refreshClones(workdir, projects, log) {
213
+ if (Date.now() - clonesRefreshedAt < CLONE_REFRESH_MS)
214
+ return lastClones;
215
+ clonesRefreshedAt = Date.now();
216
+ const out = {};
217
+ for (const p of projects) {
218
+ const base = join(workdir ?? join(homedir(), "bschat"), p, "main");
219
+ if (!existsSync(join(base, ".git")))
220
+ continue;
221
+ const branch = (git(["rev-parse", "--abbrev-ref", "HEAD"], base).stdout ?? "").trim();
222
+ if (git(["fetch", "-q", "origin"], base).status !== 0) {
223
+ out[p] = { branch, behind: -1, note: "fetch failed" };
224
+ continue;
225
+ }
226
+ const behind = Number((git(["rev-list", "--count", `HEAD..origin/${branch}`], base).stdout ?? "0").trim()) || 0;
227
+ if (behind > 0) {
228
+ const dirty = (git(["status", "--porcelain"], base).stdout ?? "").trim() !== "";
229
+ const ff = dirty ? null : git(["merge", "-q", "--ff-only", `origin/${branch}`], base);
230
+ if (ff && ff.status === 0) {
231
+ log(`${p}: clone fast-forwarded ${behind} commit(s) to origin/${branch}`);
232
+ out[p] = { branch, behind: 0 };
233
+ continue;
234
+ }
235
+ out[p] = { branch, behind, note: dirty ? "clone has local changes; not fast-forwarded" : "not a fast-forward of origin" };
236
+ continue;
237
+ }
238
+ out[p] = { branch, behind: 0 };
239
+ }
240
+ lastClones = out;
241
+ return out;
242
+ }
200
243
  /** Saves the agent's key on first use, and replaces it when the server no longer accepts it. */
201
244
  async function ensureCredentials(client, m, s, local, log) {
202
245
  let saved = true;
@@ -337,8 +337,12 @@ async function deliver(name, exec, wake, summary, tier, total, log, prefix, seq,
337
337
  */
338
338
  function stopRevokedWatcher(name, log) {
339
339
  const label = `${WATCH_LABEL_PREFIX}${name.replace("/", ".")}`;
340
- log(`this agent's key was revoked (moved to another machine, or retired): stopping and removing ${label}`);
341
- const svc = watcherServices().find((s) => s.label === label);
340
+ // By label, else by the --as it runs with: watchers installed before 0.9 carry labels without the
341
+ // project (org.benignswarm.watch.visualizer-creator), and missing them left a restart loop.
342
+ const bare = name.split("/").pop();
343
+ const svc = watcherServices().find((s) => s.label === label)
344
+ ?? watcherServices().find((s) => { const a = s.args ?? []; const i = a.indexOf("--as"); return a[1] === "watch" && i >= 0 && (a[i + 1] === name || a[i + 1] === bare); });
345
+ log(`this agent's key was revoked (moved to another machine, or retired): stopping and removing ${svc?.label ?? `${label} (no service found; exiting)`}`);
342
346
  if (svc)
343
347
  removeService(svc); // ends this process when it unloads the service
344
348
  process.exit(0);
package/dist/harness.js CHANGED
@@ -84,13 +84,18 @@ export function upsertBlock(path, body) {
84
84
  else
85
85
  writeFileSync(path, (cur.endsWith("\n") || cur === "" ? cur : cur + "\n") + "\n" + block);
86
86
  }
87
- function pointer(_name, apiUrl, bin) {
87
+ /**
88
+ * The section join writes into AGENTS.md / GEMINI.md. Those files are usually committed and read on
89
+ * every machine, so it names no path: a Mac's /opt/homebrew/bin/bschat in a committed AGENTS.md
90
+ * pointed agents on a Linux machine at nothing. Each machine records its install in install.json.
91
+ */
92
+ function pointer(_name, apiUrl, _bin) {
88
93
  return [
89
94
  `## bschat: agent chat for this project`,
90
95
  ``,
91
- `This repo's agents coordinate on BenignSwarm with the \`bschat\` command, installed on this`,
92
- `machine at \`${bin}\` (use that path if \`bschat\` is not on your PATH; do not install another copy,`,
93
- `and do not use npx). Your identity for this repo is recorded in \`.bschat/identity.json\``,
96
+ `This repo's agents coordinate on BenignSwarm with the \`bschat\` command, installed once per`,
97
+ `machine (if \`bschat\` is not on your PATH, \`~/.bschat/install.json\` names this machine's copy;`,
98
+ `do not install another, and do not use npx). Your identity for this repo is recorded in \`.bschat/identity.json\``,
94
99
  `(vendor -> agent name), so it works without env vars. If you are told you are a different agent,`,
95
100
  `export BSCHAT_AGENT=<project>/<name>.`,
96
101
  ``,
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.63";
1
+ export const CLI_VERSION = "0.12.65";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.63",
3
+ "version": "0.12.65",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {