benignswarm 0.12.124 → 0.12.125
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/commands/codex-start.js +0 -2
- package/dist/commands/git-credential.js +41 -6
- package/dist/commands/lock-run.js +12 -0
- package/dist/commands/machine-admin.js +5 -2
- package/dist/commands/wu.js +2 -2
- package/dist/help.js +5 -4
- package/dist/install.js +25 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -166,8 +166,6 @@ export async function harnessStart(p, out, harness) {
|
|
|
166
166
|
? dshSettings(sandbox, process.cwd(), configRoot(), [...writable, ...ownWorktreeGitDir(process.cwd())])
|
|
167
167
|
: harness === "claude-code" ? claudeSettings(sandbox, model, effort, process.cwd(), configRoot(), writable) : [];
|
|
168
168
|
const providerEnv = { ...claudeTurnEnv(harness === "claude-code" ? provider : undefined, model), ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}) };
|
|
169
|
-
if ((harness === "claude-code" || harness === "antigravity") && sandbox === "workspace-write")
|
|
170
|
-
configureHttpsOriginForWorktree(process.cwd());
|
|
171
169
|
// 1. Who: enroll with the invite token, or use credentials already on this machine.
|
|
172
170
|
const lines = [];
|
|
173
171
|
const token = str(p.flags, "token");
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { accessSync, constants, existsSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { isAbsolute } from "node:path";
|
|
2
4
|
import { Client } from "../client.js";
|
|
3
5
|
import { loadAgent, resolveAgentName } from "../config.js";
|
|
4
6
|
import { CliError } from "../errors.js";
|
|
5
|
-
import { requireInstall } from "../install.js";
|
|
7
|
+
import { isLiveExecutable, requireInstall } from "../install.js";
|
|
8
|
+
import { str } from "../args.js";
|
|
6
9
|
function credentialInput(input) {
|
|
7
10
|
const result = {};
|
|
8
11
|
for (const line of input.split(/\r?\n/)) {
|
|
@@ -40,6 +43,12 @@ export async function credentialResponse(input, api) {
|
|
|
40
43
|
const credential = await api("POST", "", {});
|
|
41
44
|
return `username=${credential.username}\npassword=${credential.password}\n\n`;
|
|
42
45
|
}
|
|
46
|
+
function missingRepositoryPathHint(input) {
|
|
47
|
+
const request = credentialInput(input);
|
|
48
|
+
if (request.protocol !== "https" || request.host?.toLowerCase() !== "github.com" || request.path)
|
|
49
|
+
return null;
|
|
50
|
+
return "GitHub credential lookup has no repository path; set credential.https://github.com.useHttpPath true to send it";
|
|
51
|
+
}
|
|
43
52
|
export async function gitCredentialOperation(operation, input, api) {
|
|
44
53
|
if (operation === "store" || operation === "erase")
|
|
45
54
|
return "";
|
|
@@ -47,17 +56,22 @@ export async function gitCredentialOperation(operation, input, api) {
|
|
|
47
56
|
throw new CliError("usage", "git-credential get|store|erase");
|
|
48
57
|
return credentialResponse(input, api);
|
|
49
58
|
}
|
|
50
|
-
export async function gitCredential(p) {
|
|
59
|
+
export async function gitCredential(p, stdin = process.stdin) {
|
|
51
60
|
const operation = p.positionals[1];
|
|
52
61
|
const chunks = [];
|
|
53
|
-
for await (const chunk of
|
|
62
|
+
for await (const chunk of stdin)
|
|
54
63
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
55
64
|
const input = Buffer.concat(chunks).toString("utf8");
|
|
56
65
|
if (operation === "store" || operation === "erase")
|
|
57
66
|
return;
|
|
58
67
|
if (operation !== "get")
|
|
59
68
|
throw new CliError("usage", "git-credential get|store|erase");
|
|
60
|
-
const
|
|
69
|
+
const pathHint = missingRepositoryPathHint(input);
|
|
70
|
+
if (pathHint) {
|
|
71
|
+
process.stderr.write(`${pathHint}\n`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const agent = loadAgent(resolveAgentName(str(p.flags, "as")));
|
|
61
75
|
if (!agent.project)
|
|
62
76
|
throw new CliError("github_not_connected", "GitHub credential helper requires a project-scoped agent identity.");
|
|
63
77
|
const client = Client.forAgent(agent, undefined, { presence: false });
|
|
@@ -85,8 +99,26 @@ function gitConfig(cwd, args) {
|
|
|
85
99
|
throw new CliError("git_credential_config", (result.stderr ?? "").trim() || "could not configure the worktree Git credential helper");
|
|
86
100
|
}
|
|
87
101
|
function shellQuote(value) { return `'${value.replace(/'/g, `'\\''`)}'`; }
|
|
102
|
+
function credentialHelperInstall(install) {
|
|
103
|
+
if (!isLiveExecutable(install.node)) {
|
|
104
|
+
throw new CliError("recorded_node_missing", "the recorded b9s install has no live absolute Node runtime for its Git credential helper", "Run: b9s install --latest to refresh the recorded runtime before starting a linked GitHub worktree");
|
|
105
|
+
}
|
|
106
|
+
if (!isAbsolute(install.bin) || !existsSync(install.bin) || !statSync(install.bin).isFile()) {
|
|
107
|
+
throw new CliError("install_missing", `the recorded b9s script ${install.bin} is not an absolute live path`);
|
|
108
|
+
}
|
|
109
|
+
const script = realpathSync(install.bin);
|
|
110
|
+
try {
|
|
111
|
+
accessSync(script, constants.R_OK);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new CliError("install_missing", `the recorded b9s script ${script} is not readable`);
|
|
115
|
+
}
|
|
116
|
+
if (!isAbsolute(script) || !statSync(script).isFile())
|
|
117
|
+
throw new CliError("install_missing", `the recorded b9s script ${install.bin} did not resolve to an absolute file`);
|
|
118
|
+
return { node: realpathSync(install.node), script };
|
|
119
|
+
}
|
|
88
120
|
/** Adds the exact repo helper only when origin is the repository linked to this project. */
|
|
89
|
-
export async function configureGitCredentialForWorktree(cwd, creds, lookup,
|
|
121
|
+
export async function configureGitCredentialForWorktree(cwd, creds, lookup, installRecord) {
|
|
90
122
|
if (!creds.project)
|
|
91
123
|
return;
|
|
92
124
|
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
@@ -105,6 +137,9 @@ export async function configureGitCredentialForWorktree(cwd, creds, lookup, inst
|
|
|
105
137
|
return;
|
|
106
138
|
if (`${metadata.repository.owner}/${metadata.repository.name}`.toLowerCase() !== parsed.path)
|
|
107
139
|
return;
|
|
140
|
+
// Validate every executable before changing worktree config. A stale install must leave the
|
|
141
|
+
// SSH origin and extensions untouched so a failed start cannot strand Git mid-rewrite.
|
|
142
|
+
const helper = credentialHelperInstall(installRecord ?? requireInstall());
|
|
108
143
|
const enabled = spawnSync("git", ["config", "extensions.worktreeConfig", "true"], { cwd, encoding: "utf8" });
|
|
109
144
|
if (enabled.status !== 0)
|
|
110
145
|
throw new CliError("git_credential_config", (enabled.stderr ?? "").trim() || "could not enable per-worktree Git configuration");
|
|
@@ -120,7 +155,7 @@ export async function configureGitCredentialForWorktree(cwd, creds, lookup, inst
|
|
|
120
155
|
const repoUrl = `https://github.com/${parsed.credentialPath}`;
|
|
121
156
|
const helperKey = `credential.${repoUrl}.helper`;
|
|
122
157
|
gitConfig(cwd, ["--worktree", "--replace-all", helperKey, ""]);
|
|
123
|
-
gitConfig(cwd, ["--worktree", "--add", helperKey, `!${shellQuote(
|
|
158
|
+
gitConfig(cwd, ["--worktree", "--add", helperKey, `!${shellQuote(helper.node)} ${shellQuote(helper.script)} git-credential`]);
|
|
124
159
|
gitConfig(cwd, ["--worktree", "credential.https://github.com.useHttpPath", "true"]);
|
|
125
160
|
}
|
|
126
161
|
export async function gitCredentialMain(p) {
|
|
@@ -2,6 +2,18 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { constants } from "node:os";
|
|
3
3
|
import { CliError } from "../errors.js";
|
|
4
4
|
import { forgetLockJob, rememberLockJob } from "../lock-jobs.js";
|
|
5
|
+
/**
|
|
6
|
+
* How many times a lock-run call is repeated after a network failure or a 5xx. Every call carries
|
|
7
|
+
* the job's token, so a repeat is the same request. A release that failed once during a database
|
|
8
|
+
* overload left the lock held with no process behind it (two build hosts' suite locks sat held for
|
|
9
|
+
* 45 minutes), and a failed poll ended a job that was only waiting its turn. The release keeps
|
|
10
|
+
* trying for about two minutes, the others for about 40 seconds; after that the failure is
|
|
11
|
+
* reported as before, naming the job. If a release was applied and only its answer was lost, the
|
|
12
|
+
* repeat is refused (the job no longer holds the lock) and reported: the lock is free then.
|
|
13
|
+
*/
|
|
14
|
+
export function lockRunRetries(path) {
|
|
15
|
+
return path.endsWith("/release") ? 20 : 8;
|
|
16
|
+
}
|
|
5
17
|
/** What a listing shows for the command: one line, at most 200 characters. */
|
|
6
18
|
export function commandLabel(command) {
|
|
7
19
|
const line = command.join(" ").replace(/\s+/g, " ").trim();
|
|
@@ -756,7 +756,10 @@ export async function poolAdmin(action, rest, p, out, argv) {
|
|
|
756
756
|
const [project, name, slot] = parts.map(encodeURIComponent);
|
|
757
757
|
const reason = str(p.flags, "reason");
|
|
758
758
|
const r = await c.call("POST", `/projects/${project}/pools/${name}/slots/${slot}/stop`, reason === undefined ? {} : { reason });
|
|
759
|
-
|
|
759
|
+
const followUp = r.reconciliation?.complete === false
|
|
760
|
+
? ` Follow-up needed for: ${(r.reconciliation.failed_steps ?? []).join(", ")}.`
|
|
761
|
+
: "";
|
|
762
|
+
return out.print(`Suspended ${target}; its session stop was requested and the agent remains benched until restored.${followUp}`, r);
|
|
760
763
|
}
|
|
761
764
|
const KEPT_IN_PLACE = KEPT_IN_PLACE_RE;
|
|
762
765
|
const statusLines = (pool) => [
|
|
@@ -849,7 +852,7 @@ export async function poolAdmin(action, rest, p, out, argv) {
|
|
|
849
852
|
const endpoint = `${path(project, name)}/slots/${encodeURIComponent(slot)}/${action === "pin" || action === "unpin" ? "pin" : action === "suspend" ? "suspend" : "restore"}`;
|
|
850
853
|
return previewOrConfirm(project, name, action, { ...body, slot }, async (revision) => {
|
|
851
854
|
const r = await c.call(action === "pin" ? "PUT" : action === "unpin" ? "DELETE" : "POST", endpoint, { ...body, impact_revision: revision });
|
|
852
|
-
return out.print(`${project}/${name}/${slot}: ${action === "unpin" ? "pin cleared" : action === "restore" ? "slot restored" : action === "suspend" ? "slot suspended" : `pinned to ${machine}${until ? ` until ${until}` : ""}`}.`, r);
|
|
855
|
+
return out.print(`${project}/${name}/${slot}: ${action === "unpin" ? "pin cleared" : action === "restore" ? "slot restored" : action === "suspend" ? "slot suspended; the agent remains benched until restored" : `pinned to ${machine}${until ? ` until ${until}` : ""}`}.`, r);
|
|
853
856
|
});
|
|
854
857
|
}
|
|
855
858
|
if (action === "remove") {
|
package/dist/commands/wu.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { processDeps, runUnderLock } from "./lock-run.js";
|
|
1
|
+
import { processDeps, runUnderLock, lockRunRetries } from "./lock-run.js";
|
|
2
2
|
import { forgetLockJob, lockJobKey, lockJobsFile, rememberLockJob, savedLockJobs, tokenForRelease } from "../lock-jobs.js";
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
4
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
@@ -1655,7 +1655,7 @@ export async function lock(p, out) {
|
|
|
1655
1655
|
const shared = bool(p.flags, "shared");
|
|
1656
1656
|
const runToken = str(p.flags, "token") ?? `b9sjob_${randomBytes(24).toString("hex")}`;
|
|
1657
1657
|
const machine = defaultMachine();
|
|
1658
|
-
const deps = processDeps((method, path, body) => client.call(method, path, body), (line) => process.stderr.write(`[b9s] ${line}\n`));
|
|
1658
|
+
const deps = processDeps((method, path, body) => client.call(method, path, body, { retries: lockRunRetries(path) }), (line) => process.stderr.write(`[b9s] ${line}\n`));
|
|
1659
1659
|
try {
|
|
1660
1660
|
process.exitCode = await runUnderLock({
|
|
1661
1661
|
project, lock: runName, shared, machine, unit: runUnit ? Number(runUnit) : null, note: str(p.flags, "note"), command: p.rest, token: runToken,
|
package/dist/help.js
CHANGED
|
@@ -43,7 +43,7 @@ Agent commands
|
|
|
43
43
|
b9s logout --as <name>
|
|
44
44
|
b9s identities list saved identities on this machine
|
|
45
45
|
b9s me who am I, role, permissions, channels, standing rules and acknowledgment; --json includes your machine sessions
|
|
46
|
-
b9s git-credential get|store|erase
|
|
46
|
+
b9s git-credential get|store|erase linked GitHub helper; Git must send the repo path (credential.https://github.com.useHttpPath true)
|
|
47
47
|
b9s resume compact recovery brief: units, reviews, asks, slices, decisions, outcomes, process, standing rules and notices
|
|
48
48
|
b9s notice add --project <p> "<text>" [--until <time>] [--command-pattern <regex>]
|
|
49
49
|
assigner only: add a project notice; matching commands warn but continue
|
|
@@ -477,13 +477,14 @@ Pools (fixed or adaptive; the server names the agents and places them on machine
|
|
|
477
477
|
[--quota-substitution | --no-quota-substitution] allows another eligible variant after authoritative quota exhaustion
|
|
478
478
|
pool writes first show a server impact preview; confirm a fresh revision with --impact-revision <revision>
|
|
479
479
|
b9s-admin pool list [project] | show <project>/<name> | events <project>/<name> [--limit 1..100]
|
|
480
|
+
Console: Pools → pool details → Adaptive history and overrides.
|
|
480
481
|
Console → Pools shows account/project placement, slot work/session state, and machine headroom
|
|
481
482
|
b9s-admin pool pause|resume <project>/<name> [--reason <text>] pause only automatic scaling; sessions keep running
|
|
482
483
|
b9s-admin pool pin <project>/<name> <slot> --machine <name> [--until <ISO>] [--reason <text>] | unpin <project>/<name> <slot>
|
|
483
|
-
b9s-admin pool suspend|restore <project>/<name> <slot> [--reason <text>] [--note <text>]
|
|
484
|
+
b9s-admin pool suspend|restore <project>/<name> <slot> [--reason <text>] [--note <text>] suspended agents stay benched until restored; no replacement is created
|
|
484
485
|
b9s-admin pool remove <project>/<name> retires its agents; their units go back to the queue
|
|
485
|
-
Console
|
|
486
|
-
b9s-admin pool slot stop <project>/<pool>/<slot> [--reason text]
|
|
486
|
+
Console → Pools (WU #185) creates, edits, and retires pools with server impact previews and revision confirmation; repository and checkout defaults save separately and immediately.
|
|
487
|
+
b9s-admin pool slot stop <project>/<pool>/<slot> [--reason text] request session stop; the agent stays benched until restored
|
|
487
488
|
b9s-admin pool move <project>/<name> --from <source-machine> --to <destination-machine> [--carry note|thread] [--ssh-from local|<host>] [--to-ssh <host>]
|
|
488
489
|
verifies each source slot independently; unsafe slots stay placed with a reason
|
|
489
490
|
b9s-admin pool suggestions <project> [--status pending|accepted|rejected|superseded|all] inspect explicit non-mutating pool-weight suggestions
|
package/dist/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { accessSync, constants, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir, totalmem, userInfo } from "node:os";
|
|
4
|
-
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
5
|
import { configRoot } from "./config.js";
|
|
6
6
|
import { CliError } from "./errors.js";
|
|
7
7
|
import { writeFileAtomic } from "./shared-file.js";
|
|
@@ -52,6 +52,18 @@ function findExecutableOnPath(command, pathEnv) {
|
|
|
52
52
|
}
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
|
+
/** True only for a live absolute regular file that the current user can execute. */
|
|
56
|
+
export function isLiveExecutable(path) {
|
|
57
|
+
if (!path || !isAbsolute(path))
|
|
58
|
+
return false;
|
|
59
|
+
try {
|
|
60
|
+
accessSync(path, constants.X_OK);
|
|
61
|
+
return statSync(path).isFile();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
55
67
|
/**
|
|
56
68
|
* Provisions a container-local install.json pointing exclusively to the b9s executable on the
|
|
57
69
|
* container PATH (never capturing a host binary path). Idempotent when the existing record
|
|
@@ -59,7 +71,8 @@ function findExecutableOnPath(command, pathEnv) {
|
|
|
59
71
|
*/
|
|
60
72
|
export function provisionContainerInstallRecord(pathEnv = process.env.PATH ?? "") {
|
|
61
73
|
const existing = readInstall();
|
|
62
|
-
if (existing && existsSync(existing.bin) && basename(existing.bin) === "b9s" && existing.version === CLI_VERSION
|
|
74
|
+
if (existing && existsSync(existing.bin) && basename(existing.bin) === "b9s" && existing.version === CLI_VERSION
|
|
75
|
+
&& typeof existing.node === "string" && existsSync(existing.node)) {
|
|
63
76
|
return requireInstall();
|
|
64
77
|
}
|
|
65
78
|
const bin = findExecutableOnPath("b9s", pathEnv);
|
|
@@ -69,6 +82,7 @@ export function provisionContainerInstallRecord(pathEnv = process.env.PATH ?? ""
|
|
|
69
82
|
const npm = findExecutableOnPath("npm", pathEnv) ?? "npm";
|
|
70
83
|
const record = {
|
|
71
84
|
bin,
|
|
85
|
+
node: process.execPath,
|
|
72
86
|
npm,
|
|
73
87
|
version: CLI_VERSION,
|
|
74
88
|
installed_at: new Date().toISOString(),
|
|
@@ -158,7 +172,7 @@ export function latestPublished(npm) {
|
|
|
158
172
|
* the running Node when it is missing or older, and records it. Progress goes to stderr so a
|
|
159
173
|
* JSON caller's stdout stays clean. A failed install throws: nothing is recorded.
|
|
160
174
|
*/
|
|
161
|
-
export function ensureInstall(version, log, npmOverride) {
|
|
175
|
+
export function ensureInstall(version, log, npmOverride, nodeOverride = process.execPath) {
|
|
162
176
|
const npm = npmOverride ?? ownNpm();
|
|
163
177
|
const env = npmEnv(npm);
|
|
164
178
|
const pre = spawnSync(npm, ["prefix", "-g"], { encoding: "utf8", timeout: 30_000, env });
|
|
@@ -181,7 +195,7 @@ export function ensureInstall(version, log, npmOverride) {
|
|
|
181
195
|
// Record the npm in the global prefix's bin (a stable link, e.g. /opt/homebrew/bin/npm) rather than
|
|
182
196
|
// the resolved runtime path, which names a versioned folder that a Node upgrade removes.
|
|
183
197
|
const stableNpm = join(pre.stdout.trim(), "bin", "npm");
|
|
184
|
-
const rec = { bin, npm: existsSync(stableNpm) ? stableNpm : npm, version: binVersion(bin), installed_at: new Date().toISOString() };
|
|
198
|
+
const rec = { bin, node: nodeOverride, npm: existsSync(stableNpm) ? stableNpm : npm, version: binVersion(bin), installed_at: new Date().toISOString() };
|
|
185
199
|
// Replaced in one step: every b9s command on the machine reads this record, and an upgrade runs
|
|
186
200
|
// this once per agent at the same moment. A reader never sees it half-written.
|
|
187
201
|
writeFileAtomic(installFile(), JSON.stringify(rec, null, 2) + "\n");
|
|
@@ -195,7 +209,7 @@ export function ensureInstall(version, log, npmOverride) {
|
|
|
195
209
|
export function ensureMachineInstall(version, log) {
|
|
196
210
|
const previous = readInstall();
|
|
197
211
|
if (!previous)
|
|
198
|
-
return ensureInstall(version, log, ownNpm());
|
|
212
|
+
return ensureInstall(version, log, ownNpm(), process.execPath);
|
|
199
213
|
if (!previous.npm || !existsSync(previous.npm)) {
|
|
200
214
|
throw new CliError("recorded_npm_missing", `the recorded install npm ${previous.npm || "(missing)"} is unavailable`, `Run ${previous.bin} install --latest from the Node installation you want this machine to use`);
|
|
201
215
|
}
|
|
@@ -213,7 +227,12 @@ export function ensureMachineInstall(version, log) {
|
|
|
213
227
|
if (/^\d+\.\d+\.\d+$/.test(previous.version) && cmp(previous.version, version) > 0) {
|
|
214
228
|
throw new CliError("recorded_install_newer", `the recorded b9s ${previous.version} at ${previous.bin} is newer than this CLI ${version}`, `Run ${previous.bin} install --latest from the Node installation you want this machine to use`);
|
|
215
229
|
}
|
|
216
|
-
|
|
230
|
+
// A Node upgrade may remove the versioned runtime path recorded by the prior install. The
|
|
231
|
+
// currently running CLI is the runtime that can refresh this install; persist its resolved,
|
|
232
|
+
// live executable rather than carrying the dead path forward.
|
|
233
|
+
const recordedNodeIsLive = isLiveExecutable(previous.node);
|
|
234
|
+
const node = recordedNodeIsLive ? previous.node : realpathSync(process.execPath);
|
|
235
|
+
return ensureInstall(version, log, previous.npm, node);
|
|
217
236
|
}
|
|
218
237
|
/** Creates b9s-named shell links beside aliases of the same recorded install, without replacing another copy. */
|
|
219
238
|
export function ensureCommandLinks(installBin) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.125";
|