benignswarm 0.12.128 → 0.12.129

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 CHANGED
@@ -22,7 +22,7 @@ export const STRING_FLAGS = [
22
22
  "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit",
23
23
  "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email",
24
24
  "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on",
25
- "flow-summary", "flow-min-age", "flow-min-impact",
25
+ "flow-summary", "flow-min-age", "flow-min-impact", "checkout", "api", "nonce",
26
26
  "sandbox", "thread", "turn-timeout", "turns-per-hour", "unproductive-per-hour", "turn-coalesce-seconds", "session", "operation",
27
27
  "plain", "if-yes", "if-no", "ssh", "variant", "count", "min", "max", "needs", "min-ram", "exclude", "carry", "from",
28
28
  "to-ssh", "ssh-from", "wait", "writable", "writable-root", "dsh", "agy", "for", "until", "reason", "at", "requires",
@@ -0,0 +1,55 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { str } from "../args.js";
4
+ import { CliError } from "../errors.js";
5
+ import { describeFinding, describeProbe, evaluateProbe, expectedFor, runSandboxProbe, writeProbeResult } from "../sandbox-probe.js";
6
+ /**
7
+ * What the sandbox this command runs in really allows.
8
+ *
9
+ * b9s sandbox probe [--checkout <dir>] [--api <host>] [--out <file>] [--nonce <id>]
10
+ * measure, from inside the sandbox: where commands run, which tools are there, what git can
11
+ * do, which hosts answer, and what is writable. Records facts and judges nothing.
12
+ * b9s sandbox check <file> --harness <h> --sandbox <mode>
13
+ * compare a probe's result with what is expected of that harness and mode; exits 1 on a
14
+ * difference, naming each one.
15
+ *
16
+ * Neither needs an identity or a server call of its own: a session start runs the probe before
17
+ * anything else is trusted.
18
+ */
19
+ export async function sandbox(p, out) {
20
+ const sub = p.positionals[1];
21
+ if (sub === "probe") {
22
+ const nonce = str(p.flags, "nonce") ?? randomBytes(6).toString("hex");
23
+ const result = await runSandboxProbe({ nonce, checkout: str(p.flags, "checkout"), apiHost: str(p.flags, "api") });
24
+ const file = str(p.flags, "out");
25
+ if (file)
26
+ writeProbeResult(file, result);
27
+ out.print(`${describeProbe(result)}${file ? `\nwritten to ${file}` : ""}`, result);
28
+ return;
29
+ }
30
+ if (sub === "check") {
31
+ const file = p.positionals[2];
32
+ const harness = str(p.flags, "harness");
33
+ const mode = str(p.flags, "sandbox");
34
+ if (!file || !harness || !mode)
35
+ throw new CliError("usage", "sandbox check <file> --harness <codex|claude-code|dsh|antigravity> --sandbox <workspace-write|danger-full-access>");
36
+ let result;
37
+ try {
38
+ result = JSON.parse(readFileSync(file, "utf8"));
39
+ }
40
+ catch (e) {
41
+ throw new CliError("probe_unreadable", `cannot read a probe result from ${file}: ${e.message}`);
42
+ }
43
+ if (result?.schema !== 1 || !result.checks)
44
+ throw new CliError("probe_unreadable", `${file} is not a sandbox probe result`);
45
+ const verdict = evaluateProbe(result, expectedFor(harness, mode));
46
+ const lines = verdict.ok
47
+ ? [`sandbox as expected for ${harness} ${mode} (${verdict.unjudged.length} recorded without a verdict)`]
48
+ : [`sandbox differs from what is expected for ${harness} ${mode}:`, ...verdict.failures.map((f) => ` - ${describeFinding(f)}`)];
49
+ out.print(lines.join("\n"), { harness, sandbox: mode, ...verdict });
50
+ if (!verdict.ok)
51
+ throw new CliError("sandbox_differs", `${verdict.failures.length} sandbox check${verdict.failures.length === 1 ? "" : "s"} differ from what is expected`);
52
+ return;
53
+ }
54
+ throw new CliError("usage", "sandbox probe [--checkout <dir>] [--api <host>] [--out <file>] | sandbox check <file> --harness <h> --sandbox <mode>");
55
+ }
package/dist/help.js CHANGED
@@ -225,6 +225,11 @@ Machine placement enforces configured session slots and reports machine pressure
225
225
  restart services on that install without waiting on one stop, and report failures
226
226
  b9s install [<version> | --latest] make or upgrade this machine's one b9s (join does it once), repair PATH aliases,
227
227
  restart services resolving to it; other installs are left alone and named
228
+ b9s sandbox probe [--checkout <dir>] [--api <host>] [--out <file>]
229
+ what the sandbox this runs in really allows: where commands run, which tools
230
+ are there, what git can do, which hosts answer, what is writable; facts only
231
+ b9s sandbox check <file> --harness <h> --sandbox <mode>
232
+ compare a probe result with what is expected of that harness; exits 1 on a difference
228
233
  b9s doctor every b9s on this machine and who runs which (PATH, npx caches, this repo's
229
234
  hook and instructions, each watcher's plist versus what launchd runs), with fixes;
230
235
  --json also includes structured sandbox, writable-root, PATH, disk and state checks
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ import { harnessStart } from "./commands/codex-start.js";
18
18
  import { turnHarness } from "./harnesses.js";
19
19
  import { machine } from "./commands/machine.js";
20
20
  import { doctor, install } from "./commands/install.js";
21
+ import { sandbox } from "./commands/sandbox.js";
21
22
  import { warnIfForeignCopy } from "./install.js";
22
23
  import { processCmd, record, wu, milestones, milestone, lock, askOperator, explainAsk } from "./commands/wu.js";
23
24
  import { worktrees } from "./commands/worktrees.js";
@@ -95,6 +96,7 @@ const COMMANDS = {
95
96
  // `update` is the word people reach for: the same as install, latest unless a version is named.
96
97
  update: (p, out) => install(p.positionals[1] ? p : { ...p, flags: { ...p.flags, latest: true } }, out),
97
98
  doctor,
99
+ sandbox,
98
100
  wu,
99
101
  process: processCmd,
100
102
  rule: standingRuleCommand,
@@ -120,7 +122,7 @@ const COMMANDS = {
120
122
  // These commands establish identity, own their startup validation, or inspect/change only local
121
123
  // machine state. Their dispatch must run before any notice lookup attempts to load an agent.
122
124
  const NOTICE_PREFLIGHT_EXEMPT_COMMANDS = new Set([
123
- "join", "setup", "login", "logout", "identities", "skill", "hook", "machine", "install", "doctor", "update", "version", "admin", "start", "git-credential", "templates",
125
+ "join", "setup", "login", "logout", "identities", "skill", "hook", "machine", "install", "doctor", "sandbox", "update", "version", "admin", "start", "git-credential", "templates",
124
126
  ]);
125
127
  let invokedCommand;
126
128
  async function main(argv) {
@@ -0,0 +1,233 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { closeSync, existsSync, mkdirSync, openSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { delimiter, dirname, join } from "node:path";
5
+ import { configRoot } from "./config.js";
6
+ import { CliError } from "./errors.js";
7
+ import { CLI_VERSION } from "./version.js";
8
+ export const PROBE_CHECKS = [
9
+ "cwd_is_checkout", "origin_is_https",
10
+ "tool_node", "tool_npm", "tool_npx", "tool_git", "tool_b9s",
11
+ "git_branch", "git_object", "git_worktree", "git_remote_read",
12
+ "net_api", "net_other_host",
13
+ "write_checkout", "write_checkout_parent", "write_b9s_home",
14
+ "write_git_config", "write_git_hooks", "write_home", "write_node_install",
15
+ ];
16
+ const clip = (text) => text.trim().replace(/\s+/g, " ").slice(0, 300);
17
+ const NONCE_RE = /^[a-z0-9]{6,40}$/;
18
+ function run(cmd, args, cwd, env, timeoutMs = 20_000) {
19
+ const r = spawnSync(cmd, args, { cwd, env, encoding: "utf8", timeout: timeoutMs, maxBuffer: 1024 * 1024 });
20
+ return { status: r.error ? null : r.status, out: (r.stdout ?? "").trim(), err: r.error ? r.error.message : (r.stderr ?? "").trim() };
21
+ }
22
+ function observe(action) {
23
+ try {
24
+ const value = action();
25
+ return value === undefined ? { ok: true } : { ok: true, value };
26
+ }
27
+ catch (e) {
28
+ return { ok: false, detail: clip(e.message) };
29
+ }
30
+ }
31
+ /** Where a command would be found on PATH, the way a shell resolves it; null when it is not there. */
32
+ export function onPath(name, env) {
33
+ for (const dir of (env.PATH ?? "").split(delimiter).filter(Boolean)) {
34
+ const candidate = join(dir, name);
35
+ if (existsSync(candidate))
36
+ return candidate;
37
+ }
38
+ return null;
39
+ }
40
+ function tool(name, versionArgs, cwd, env) {
41
+ const path = onPath(name, env);
42
+ if (!path)
43
+ return { ok: false, detail: "not on PATH" };
44
+ if (!versionArgs)
45
+ return { ok: true, value: path };
46
+ const v = run(path, versionArgs, cwd, env, 15_000);
47
+ // A command that is listed but cannot run (a link whose target the sandbox hides) is not usable.
48
+ if (v.status !== 0)
49
+ return { ok: false, value: path, detail: clip(v.err || `exited ${v.status ?? "without a status"}`) };
50
+ return { ok: true, value: path, detail: clip(v.out.split("\n")[0] ?? "") };
51
+ }
52
+ /** Creates a uniquely named file and removes it; succeeds only when both worked. */
53
+ function createAndRemove(dir, nonce) {
54
+ const path = join(dir, `.b9s-probe-${nonce}`);
55
+ return observe(() => {
56
+ closeSync(openSync(path, "wx"));
57
+ unlinkSync(path);
58
+ });
59
+ }
60
+ async function reach(url, timeoutMs = 10_000) {
61
+ try {
62
+ const res = await fetch(url, { method: "GET", signal: AbortSignal.timeout(timeoutMs), redirect: "manual" });
63
+ return { ok: true, detail: `HTTP ${res.status}` };
64
+ }
65
+ catch (e) {
66
+ const cause = e.cause?.message;
67
+ return { ok: false, detail: clip(cause ? `${e.message}: ${cause}` : e.message) };
68
+ }
69
+ }
70
+ export async function runSandboxProbe(options) {
71
+ const env = options.env ?? process.env;
72
+ const cwd = options.cwd ?? process.cwd();
73
+ const nonce = options.nonce;
74
+ if (!NONCE_RE.test(nonce))
75
+ throw new CliError("usage", "the probe nonce must be 6 to 40 lowercase letters or digits");
76
+ const git = (args, timeoutMs) => run("git", args, cwd, env, timeoutMs);
77
+ const read = (args) => { const r = git(args); return r.status === 0 && r.out ? r.out : null; };
78
+ const toplevel = read(["rev-parse", "--show-toplevel"]);
79
+ const gitDir = read(["rev-parse", "--absolute-git-dir"]);
80
+ const commonDir = read(["rev-parse", "--path-format=absolute", "--git-common-dir"]);
81
+ const originConfigured = read(["config", "--get", "remote.origin.url"]);
82
+ const originEffective = read(["remote", "get-url", "origin"]);
83
+ const checks = Object.fromEntries(PROBE_CHECKS.map((id) => [id, null]));
84
+ checks.cwd_is_checkout = options.checkout
85
+ ? cwd === options.checkout && toplevel === options.checkout
86
+ ? { ok: true, value: cwd }
87
+ : { ok: false, value: cwd, detail: clip(`expected ${options.checkout}; the repository here is ${toplevel ?? "none"}`) }
88
+ : null;
89
+ checks.origin_is_https = originEffective === null
90
+ ? { ok: false, detail: "no origin remote is readable here" }
91
+ : { ok: /^https:\/\//.test(originEffective), value: originEffective.replace(/\/\/[^@/]*@/, "//") };
92
+ checks.tool_node = tool("node", ["--version"], cwd, env);
93
+ checks.tool_npm = tool("npm", ["--version"], cwd, env);
94
+ checks.tool_npx = tool("npx", ["--version"], cwd, env);
95
+ checks.tool_git = tool("git", ["--version"], cwd, env);
96
+ checks.tool_b9s = tool("b9s", null, cwd, env);
97
+ if (toplevel) {
98
+ const ref = `refs/heads/b9s-probe-${nonce}`;
99
+ checks.git_branch = observe(() => {
100
+ const made = git(["update-ref", ref, "HEAD"]);
101
+ if (made.status !== 0)
102
+ throw new Error(made.err || "git update-ref failed");
103
+ const gone = git(["update-ref", "-d", ref]);
104
+ if (gone.status !== 0)
105
+ throw new Error(`created ${ref} but could not delete it: ${gone.err}`);
106
+ });
107
+ // A commit object from the current tree: proves the object store takes a write without touching
108
+ // the index, the working tree or any branch, and without running the repository's hooks.
109
+ checks.git_object = observe(() => {
110
+ const made = run("git", ["-c", "user.name=b9s probe", "-c", "user.email=probe@invalid", "commit-tree", "HEAD^{tree}", "-p", "HEAD", "-m", `b9s sandbox probe ${nonce}`], cwd, env);
111
+ if (made.status !== 0 || !/^[0-9a-f]{40,64}$/.test(made.out))
112
+ throw new Error(made.err || "git commit-tree failed");
113
+ return made.out.slice(0, 12);
114
+ });
115
+ const sibling = join(dirname(toplevel), `.b9s-probe-${nonce}`);
116
+ checks.git_worktree = observe(() => {
117
+ const made = git(["worktree", "add", "--detach", "--no-checkout", sibling, "HEAD"], 60_000);
118
+ if (made.status !== 0)
119
+ throw new Error(made.err || "git worktree add failed");
120
+ const gone = git(["worktree", "remove", "--force", sibling]);
121
+ if (gone.status !== 0) {
122
+ rmSync(sibling, { recursive: true, force: true });
123
+ git(["worktree", "prune"]);
124
+ throw new Error(`added a worktree but could not remove it: ${gone.err}`);
125
+ }
126
+ });
127
+ const remote = git(["ls-remote", "origin", "HEAD"], 30_000);
128
+ // Exit 0 is the remote answering; a remote whose HEAD names no branch yet answers with nothing.
129
+ checks.git_remote_read = remote.status === 0
130
+ ? { ok: true }
131
+ : { ok: false, detail: clip(remote.err || `git ls-remote origin exited ${remote.status ?? "without a status"}`) };
132
+ checks.write_checkout = createAndRemove(toplevel, nonce);
133
+ checks.write_checkout_parent = createAndRemove(dirname(toplevel), nonce);
134
+ }
135
+ if (commonDir) {
136
+ // Opened for appending and closed: shows whether it could be changed without changing it.
137
+ checks.write_git_config = observe(() => { closeSync(openSync(join(commonDir, "config"), "a")); });
138
+ const hooks = join(commonDir, "hooks");
139
+ checks.write_git_hooks = existsSync(hooks) ? createAndRemove(hooks, nonce) : observe(() => { mkdirSync(hooks); rmSync(hooks, { recursive: true }); });
140
+ }
141
+ const b9sHome = configRoot(env);
142
+ checks.write_b9s_home = existsSync(b9sHome) ? createAndRemove(b9sHome, nonce) : { ok: false, detail: `${b9sHome} does not exist` };
143
+ checks.write_home = createAndRemove(env.HOME || homedir(), nonce);
144
+ checks.write_node_install = createAndRemove(dirname(process.execPath), nonce);
145
+ checks.net_api = options.apiHost ? await reach(`https://${options.apiHost}/onboard`) : null;
146
+ checks.net_other_host = await reach(`https://${options.otherHost ?? "example.com"}/`);
147
+ return {
148
+ schema: 1, nonce, at: new Date().toISOString(), cli_version: CLI_VERSION, platform: process.platform,
149
+ cwd, checkout: options.checkout ?? null,
150
+ git: { toplevel, git_dir: gitDir, common_dir: commonDir, origin_configured: originConfigured?.replace(/\/\/[^@/]*@/, "//") ?? null, origin_effective: originEffective?.replace(/\/\/[^@/]*@/, "//") ?? null },
151
+ checks,
152
+ };
153
+ }
154
+ export function writeProbeResult(path, result) {
155
+ mkdirSync(dirname(path), { recursive: true });
156
+ writeFileSync(path, `${JSON.stringify(result, null, 2)}\n`, { mode: 0o600 });
157
+ }
158
+ const ACCEPTED_GIT = "accepted limit (2026-11-19): the clone's shared git folder is writable under the checkout's parent; see docs/REMOTE-MACHINES.md";
159
+ const UNMEASURED = "not measured for this harness yet";
160
+ export function expectedFor(harness, sandbox) {
161
+ const works = { expected: "works" };
162
+ const base = {
163
+ cwd_is_checkout: works, origin_is_https: { expected: "any", note: UNMEASURED },
164
+ tool_node: works, tool_npm: works, tool_npx: works, tool_git: works, tool_b9s: works,
165
+ git_branch: works, git_object: works, git_worktree: works, git_remote_read: works,
166
+ net_api: works, net_other_host: { expected: "any", note: UNMEASURED },
167
+ write_checkout: works, write_checkout_parent: works, write_b9s_home: works,
168
+ write_git_config: { expected: "any", note: ACCEPTED_GIT }, write_git_hooks: { expected: "any", note: ACCEPTED_GIT },
169
+ write_home: { expected: "any", note: UNMEASURED }, write_node_install: { expected: "any", note: UNMEASURED },
170
+ };
171
+ if (sandbox === "danger-full-access") {
172
+ // No sandbox: only that the session is where it should be and can work is checked.
173
+ return { ...base, write_git_config: { expected: "any", note: "no sandbox" }, write_git_hooks: { expected: "any", note: "no sandbox" }, write_home: { expected: "any", note: "no sandbox" }, write_node_install: { expected: "any", note: "no sandbox" }, net_other_host: { expected: "any", note: "no sandbox" }, origin_is_https: { expected: "any", note: "no sandbox" } };
174
+ }
175
+ if (sandbox !== "workspace-write")
176
+ throw new CliError("usage", `no sandbox expectations for ${sandbox}`);
177
+ if (harness === "antigravity") {
178
+ // Measured with agy 1.5.12 on Linux, 2026-11-19: the terminal sandbox reaches only allow-listed
179
+ // hosts over an HTTP proxy (an SSH origin cannot resolve), and the Node installation is mounted
180
+ // read-only.
181
+ return { ...base, origin_is_https: works, write_node_install: { expected: "refused" } };
182
+ }
183
+ if (harness === "claude-code") {
184
+ // Its sandbox proxies HTTP(S) only, so an SSH origin cannot be reached (the reason b9s start
185
+ // rewrites it per worktree). The rest is not measured with this probe yet.
186
+ return { ...base, origin_is_https: works };
187
+ }
188
+ if (harness === "codex" || harness === "dsh")
189
+ return base;
190
+ throw new CliError("usage", `no sandbox expectations for harness ${harness}`);
191
+ }
192
+ /** A check that was expected and could not be run is a failure: not knowing is not passing. */
193
+ export function evaluateProbe(result, expected) {
194
+ const failures = [];
195
+ const unjudged = [];
196
+ for (const check of PROBE_CHECKS) {
197
+ const seen = result.checks[check];
198
+ const want = expected[check];
199
+ const observed = seen === null || seen === undefined ? "not run" : seen.ok ? "works" : "refused";
200
+ const detail = seen?.detail ?? seen?.value;
201
+ if (want.expected === "any") {
202
+ unjudged.push({ check, expected: "any", observed, ...(detail ? { detail } : {}), ...(want.note ? { note: want.note } : {}) });
203
+ continue;
204
+ }
205
+ if (observed !== want.expected)
206
+ failures.push({ check, expected: want.expected, observed, ...(detail ? { detail } : {}) });
207
+ }
208
+ return { ok: failures.length === 0, failures, unjudged };
209
+ }
210
+ const LABEL = {
211
+ cwd_is_checkout: "commands run in the agent's checkout",
212
+ origin_is_https: "origin is reached over HTTPS",
213
+ tool_node: "node runs", tool_npm: "npm runs", tool_npx: "npx runs", tool_git: "git runs", tool_b9s: "b9s is on PATH",
214
+ git_branch: "git can create a branch", git_object: "git can write a commit object", git_worktree: "git can add a worktree beside the checkout", git_remote_read: "git can read origin",
215
+ net_api: "the BenignSwarm API is reachable", net_other_host: "a host outside the allow-list is reachable",
216
+ write_checkout: "the checkout is writable", write_checkout_parent: "the checkout's parent is writable", write_b9s_home: "b9s's own folder is writable",
217
+ write_git_config: "the clone's git config is writable", write_git_hooks: "the clone's git hooks are writable",
218
+ write_home: "the home folder is writable", write_node_install: "the Node installation is writable",
219
+ };
220
+ export function describeFinding(f) {
221
+ const want = f.expected === "works" ? "should work" : "should be refused";
222
+ const got = f.observed === "works" ? "it works" : f.observed === "refused" ? "it is refused" : "the check could not run";
223
+ return `${LABEL[f.check]}: ${want}, but ${got}${f.detail ? ` (${f.detail})` : ""}`;
224
+ }
225
+ export function describeProbe(result) {
226
+ const lines = [`sandbox probe ${result.nonce} at ${result.at} (b9s ${result.cli_version}, ${result.platform})`, ` ran in ${result.cwd}${result.checkout ? `; expected ${result.checkout}` : ""}`];
227
+ for (const check of PROBE_CHECKS) {
228
+ const seen = result.checks[check];
229
+ const state = seen === null ? "not run" : seen.ok ? "yes" : "no";
230
+ lines.push(` ${state.padEnd(7)} ${LABEL[check]}${seen?.detail ? ` (${seen.detail})` : seen?.value ? ` (${seen.value})` : ""}`);
231
+ }
232
+ return lines.join("\n");
233
+ }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.128";
1
+ export const CLI_VERSION = "0.12.129";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.128",
3
+ "version": "0.12.129",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {