benignswarm 0.12.100 → 0.12.102
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/antigravity.js +49 -6
- package/dist/args.js +2 -2
- package/dist/client.js +27 -5
- package/dist/commands/codex-start.js +17 -8
- package/dist/commands/install.js +18 -1
- package/dist/commands/join.js +14 -23
- package/dist/commands/machine-admin.js +184 -41
- package/dist/commands/machine.js +50 -27
- package/dist/commands/watch.js +85 -6
- package/dist/harness.js +78 -6
- package/dist/help.js +13 -6
- package/dist/machine-daemon.js +58 -0
- package/dist/output.js +3 -1
- package/dist/startup-jitter.js +22 -0
- package/dist/state.js +80 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/antigravity.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { basename, dirname, join } from "node:path";
|
|
4
|
+
import { basename, delimiter, dirname, join } from "node:path";
|
|
5
5
|
import { configRoot } from "./config.js";
|
|
6
|
+
import { repoDirectory } from "./directories.js";
|
|
6
7
|
import { CliError } from "./errors.js";
|
|
7
8
|
export function antigravityTotalTokens(usage) {
|
|
8
9
|
if (!usage)
|
|
@@ -14,7 +15,41 @@ export function antigravityTotalTokens(usage) {
|
|
|
14
15
|
export const antigravityLog = (ref) => join(configRoot(), "logs", `antigravity.${ref.replace("/", ".")}.jsonl`);
|
|
15
16
|
export const antigravityConversationDb = (id, home = homedir()) => join(home, ".gemini", "antigravity-cli", "conversations", `${id}.db`);
|
|
16
17
|
const shq = (s) => (/^[\w./=:@-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`);
|
|
17
|
-
|
|
18
|
+
function b9sPackageRoot(bin) {
|
|
19
|
+
let dir = dirname(realpathSync(bin));
|
|
20
|
+
for (;;) {
|
|
21
|
+
const manifest = join(dir, "package.json");
|
|
22
|
+
if (existsSync(manifest)) {
|
|
23
|
+
try {
|
|
24
|
+
if (JSON.parse(readFileSync(manifest, "utf8")).name === "benignswarm")
|
|
25
|
+
return dir;
|
|
26
|
+
}
|
|
27
|
+
catch { /* continue up to the package root */ }
|
|
28
|
+
}
|
|
29
|
+
const parent = dirname(dir);
|
|
30
|
+
if (parent === dir)
|
|
31
|
+
break;
|
|
32
|
+
dir = parent;
|
|
33
|
+
}
|
|
34
|
+
throw new CliError("install_package_missing", `cannot find the benignswarm package containing recorded b9s install ${bin}`);
|
|
35
|
+
}
|
|
36
|
+
export function antigravitySandboxPermissions(apiHost, b9sHome, b9sBin, nodeBin = process.execPath, skillRoot) {
|
|
37
|
+
const packageRoot = b9sPackageRoot(b9sBin);
|
|
38
|
+
const allow = [
|
|
39
|
+
`read_url(${apiHost})`, "read_url(github.com)", "command(b9s)",
|
|
40
|
+
`read_file(${b9sBin})`, `read_file(${realpathSync(b9sBin)})`, `read_file(${nodeBin})`, `read_file(${packageRoot})`,
|
|
41
|
+
`write_file(${b9sHome})`,
|
|
42
|
+
];
|
|
43
|
+
if (skillRoot) {
|
|
44
|
+
allow.push(`read_file(${join(skillRoot, "identity.json")})`);
|
|
45
|
+
for (const file of ["SKILL.md", "references/api.md", "references/watchers.md", "references/process.md", "references/continuity.md"]) {
|
|
46
|
+
allow.push(`read_file(${join(skillRoot, file)})`);
|
|
47
|
+
}
|
|
48
|
+
allow.push(`read_file(${join(dirname(skillRoot), ".agents", "rules", "bschat.md")})`);
|
|
49
|
+
}
|
|
50
|
+
return [...new Set(allow)];
|
|
51
|
+
}
|
|
52
|
+
export function antigravitySettings(sandbox, cwd, b9sHome, apiHost, extraWritable = [], b9sBin, nodeBin = process.execPath) {
|
|
18
53
|
if (sandbox === "read-only")
|
|
19
54
|
throw new CliError("unsupported", "Antigravity has no read-only permission mode; use workspace-write or danger-full-access");
|
|
20
55
|
if (sandbox === "danger-full-access")
|
|
@@ -23,10 +58,12 @@ export function antigravitySettings(sandbox, cwd, b9sHome, apiHost, extraWritabl
|
|
|
23
58
|
throw new CliError("usage", `unknown sandbox ${sandbox}`);
|
|
24
59
|
if (!/^[a-z0-9.-]+(?::\d+)?$/i.test(apiHost))
|
|
25
60
|
throw new CliError("usage", "the BenignSwarm API host is invalid for Antigravity sandbox permissions");
|
|
61
|
+
if (!b9sBin)
|
|
62
|
+
throw new CliError("not_installed", "the recorded b9s install path is required for Antigravity workspace-write");
|
|
26
63
|
const dirs = [...new Set([dirname(cwd), b9sHome, ...extraWritable])];
|
|
27
64
|
return [
|
|
28
65
|
"--sandbox", "--settings",
|
|
29
|
-
JSON.stringify({ enableTerminalSandbox: true, toolPermission: "proceed-in-sandbox", permissions: { allow:
|
|
66
|
+
JSON.stringify({ enableTerminalSandbox: true, toolPermission: "proceed-in-sandbox", permissions: { allow: antigravitySandboxPermissions(apiHost, b9sHome, b9sBin, nodeBin, repoDirectory(cwd)) } }),
|
|
30
67
|
...dirs.flatMap((dir) => ["--add-dir", dir]),
|
|
31
68
|
];
|
|
32
69
|
}
|
|
@@ -66,8 +103,14 @@ export function recordAntigravityTurn(path, record) {
|
|
|
66
103
|
appendFileSync(path, `${JSON.stringify(record)}\n`, { mode: 0o600 });
|
|
67
104
|
}
|
|
68
105
|
/** Explicit markers let commands launched by this turn inherit only this harness's sandbox workaround. */
|
|
69
|
-
export function
|
|
70
|
-
return
|
|
106
|
+
export function antigravityPath(b9sBin, path = process.env.PATH ?? "") {
|
|
107
|
+
return [...new Set([dirname(b9sBin), dirname(process.execPath), ...path.split(delimiter).filter(Boolean)])].join(delimiter);
|
|
108
|
+
}
|
|
109
|
+
export function antigravityTurnEnv(sandbox, b9sBin) {
|
|
110
|
+
if (sandbox !== "workspace-write")
|
|
111
|
+
return { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox };
|
|
112
|
+
const path = b9sBin ? antigravityPath(b9sBin) : [...new Set([dirname(process.execPath), ...(process.env.PATH ?? "").split(delimiter).filter(Boolean)])].join(delimiter);
|
|
113
|
+
return { BSCHAT_HARNESS: "antigravity", BSCHAT_ANTIGRAVITY_SANDBOX: sandbox, PATH: path };
|
|
71
114
|
}
|
|
72
115
|
export function runAntigravityTurn(bin, args, logPath, cwd, agent, expectedConversation, run = spawnSync, envOverride = {}) {
|
|
73
116
|
const started = new Date().toISOString();
|
package/dist/args.js
CHANGED
|
@@ -14,7 +14,7 @@ export const STRING_FLAGS = [
|
|
|
14
14
|
"name", "out", "token", "token-file", "prefix", "uses", "expires-hours", "skill-dir", "harness", "provider", "reply-to",
|
|
15
15
|
"event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent",
|
|
16
16
|
"parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval",
|
|
17
|
-
"requeue-after", "unacked-after", "category", "command", "command-pattern", "follow-delay", "env", "scope",
|
|
17
|
+
"requeue-after", "unacked-after", "category", "command", "command-pattern", "follow-delay", "startup-jitter-seconds", "env", "scope",
|
|
18
18
|
"scope-file", "scope-from", "append", "pr", "note", "note-file", "add", "remove", "merged", "tag",
|
|
19
19
|
"activity", "max-unanswered", "to", "replay-of", "branch", "effort", "max-budget-usd", "by", "target", "lands-with",
|
|
20
20
|
"milestone", "file", "exit", "depends-on", "default-tags", "source", "on", "partial", "question", "ruling",
|
|
@@ -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
|
-
"sandbox", "thread", "turn-timeout", "turns-per-hour", "unproductive-per-hour", "turn-coalesce-seconds", "session",
|
|
25
|
+
"sandbox", "thread", "turn-timeout", "turns-per-hour", "unproductive-per-hour", "turn-coalesce-seconds", "session", "operation",
|
|
26
26
|
"plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from",
|
|
27
27
|
"to-ssh", "wait", "writable", "writable-root", "dsh", "agy", "for", "until", "reason", "at", "requires",
|
|
28
28
|
"priority", "informs", "amend", "waive-informs", "text", "kind", "claim", "decision", "sha", "value", "expect",
|
package/dist/client.js
CHANGED
|
@@ -256,12 +256,14 @@ export class Client {
|
|
|
256
256
|
auto;
|
|
257
257
|
agentName;
|
|
258
258
|
machineIdentity;
|
|
259
|
-
|
|
259
|
+
requestOptions;
|
|
260
|
+
constructor(url, key, auto, agentName, machineIdentity, requestOptions = {}) {
|
|
260
261
|
this.url = url;
|
|
261
262
|
this.key = key;
|
|
262
263
|
this.auto = auto;
|
|
263
264
|
this.agentName = agentName;
|
|
264
265
|
this.machineIdentity = machineIdentity;
|
|
266
|
+
this.requestOptions = requestOptions;
|
|
265
267
|
}
|
|
266
268
|
/**
|
|
267
269
|
* presence: send the X-Bschat-Auto header, which refreshes the agent's automatic status and
|
|
@@ -275,8 +277,18 @@ export class Client {
|
|
|
275
277
|
static forAdmin(c) {
|
|
276
278
|
return new Client(c.url, c.key, null);
|
|
277
279
|
}
|
|
278
|
-
static raw(url, key) {
|
|
279
|
-
return new Client(url, key, null);
|
|
280
|
+
static raw(url, key, requestOptions = {}) {
|
|
281
|
+
return new Client(url, key, null, undefined, null, requestOptions);
|
|
282
|
+
}
|
|
283
|
+
requestSignal(external) {
|
|
284
|
+
const signals = [this.requestOptions.signal, external].filter((signal) => Boolean(signal));
|
|
285
|
+
const timeout = this.requestOptions.requestTimeoutMs ? AbortSignal.timeout(this.requestOptions.requestTimeoutMs) : undefined;
|
|
286
|
+
if (timeout)
|
|
287
|
+
signals.push(timeout);
|
|
288
|
+
return { signal: signals.length > 1 ? AbortSignal.any(signals) : signals[0], timeout };
|
|
289
|
+
}
|
|
290
|
+
timeoutError(method, path) {
|
|
291
|
+
return new CliError("request_timeout", `${method} ${path} timed out after ${this.requestOptions.requestTimeoutMs}ms`);
|
|
280
292
|
}
|
|
281
293
|
headers() {
|
|
282
294
|
const h = { authorization: `Bearer ${this.key}`, "user-agent": cliUserAgent() };
|
|
@@ -317,18 +329,28 @@ export class Client {
|
|
|
317
329
|
const retries = opts.retries ?? 0;
|
|
318
330
|
for (let attempt = 0;; attempt++) {
|
|
319
331
|
let res;
|
|
332
|
+
let text;
|
|
333
|
+
const startedAt = Date.now();
|
|
334
|
+
const { signal, timeout } = this.requestSignal(opts.signal);
|
|
335
|
+
this.requestOptions.onRequest?.({ phase: "start", method, path });
|
|
320
336
|
try {
|
|
321
|
-
res = await fetch(this.url + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal
|
|
337
|
+
res = await fetch(this.url + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal });
|
|
338
|
+
text = await res.text();
|
|
322
339
|
}
|
|
323
340
|
catch (e) {
|
|
341
|
+
this.requestOptions.onRequest?.({ phase: "end", method, path, durationMs: Date.now() - startedAt, error: timeout?.aborted ? "timeout" : e.message });
|
|
342
|
+
if (timeout?.aborted)
|
|
343
|
+
throw this.timeoutError(method, path);
|
|
344
|
+
if (this.requestOptions.signal?.aborted || opts.signal?.aborted)
|
|
345
|
+
throw new CliError("request_aborted", `${method} ${path} aborted before completion`);
|
|
324
346
|
if (attempt < retries) {
|
|
325
347
|
await backoff(attempt);
|
|
326
348
|
continue;
|
|
327
349
|
}
|
|
328
350
|
throw new CliError("network", `could not reach ${this.url}: ${e.message}`);
|
|
329
351
|
}
|
|
352
|
+
this.requestOptions.onRequest?.({ phase: "end", method, path, durationMs: Date.now() - startedAt });
|
|
330
353
|
noteServerVersions(res.headers, this.agentName);
|
|
331
|
-
const text = await res.text();
|
|
332
354
|
let json;
|
|
333
355
|
try {
|
|
334
356
|
json = JSON.parse(text);
|
|
@@ -18,6 +18,7 @@ import { HARNESS_BIN, HARNESS_LABEL, assertClaudeSelfCheck, claudeCodePath, clau
|
|
|
18
18
|
import { claudeTurnEnv } from "../providers.js";
|
|
19
19
|
import { DEFAULT_TURNS_PER_HOUR, DEFAULT_UNPRODUCTIVE_PER_HOUR, MAX_TURNS_PER_HOUR } from "../turn-guard.js";
|
|
20
20
|
import { DEFAULT_TURN_COALESCE_SECONDS, MAX_TURN_COALESCE_SECONDS } from "../turn.js";
|
|
21
|
+
import { DEFAULT_WATCH_STARTUP_JITTER_SECONDS, MAX_WATCH_STARTUP_JITTER_SECONDS } from "../startup-jitter.js";
|
|
21
22
|
import { antigravityConversationDb, antigravityLog, antigravityResumeCommand, antigravitySettings, antigravityTotalTokens, antigravityTurnArgs, antigravityTurnEnv, runAntigravityTurn } from "../antigravity.js";
|
|
22
23
|
import { configureGitCredentialForWorktree } from "./git-credential.js";
|
|
23
24
|
const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
|
|
@@ -31,7 +32,7 @@ export const DEFAULT_CLAUDE_MAX_BUDGET_USD = 1;
|
|
|
31
32
|
* from the Codex app's queue silently not delivering wake-ups (fabricbios luna-worker, ten hours).
|
|
32
33
|
*
|
|
33
34
|
* b9s start --harness codex|claude-code|dsh|antigravity --as <name> --sandbox <mode> [--token bs_enroll_...]
|
|
34
|
-
* [--thread <id>] [--model m] [--effort e] [--turn-timeout 180] [--interval 30] [--prune] [--dsh <path>] [--agy <path>]
|
|
35
|
+
* [--thread <id>] [--model m] [--effort e] [--turn-timeout 180] [--interval 30] [--startup-jitter-seconds 0..60] [--prune] [--dsh <path>] [--agy <path>]
|
|
35
36
|
*/
|
|
36
37
|
export async function codexStart(p, out) {
|
|
37
38
|
return harnessStart(p, out, "codex");
|
|
@@ -99,6 +100,10 @@ export async function harnessStart(p, out, harness) {
|
|
|
99
100
|
const interval = Number(str(p.flags, "interval") ?? "30");
|
|
100
101
|
if (!Number.isInteger(interval) || interval < 5)
|
|
101
102
|
throw new CliError("usage", "--interval must be an integer number of seconds, at least 5");
|
|
103
|
+
const startupJitterSeconds = Number(str(p.flags, "startup-jitter-seconds") ?? String(DEFAULT_WATCH_STARTUP_JITTER_SECONDS));
|
|
104
|
+
if (!Number.isInteger(startupJitterSeconds) || startupJitterSeconds < 0 || startupJitterSeconds > MAX_WATCH_STARTUP_JITTER_SECONDS) {
|
|
105
|
+
throw new CliError("usage", `--startup-jitter-seconds must be a whole number from 0 to ${MAX_WATCH_STARTUP_JITTER_SECONDS}`);
|
|
106
|
+
}
|
|
102
107
|
if (!inContainer && process.platform !== "darwin" && process.platform !== "linux")
|
|
103
108
|
throw new CliError("unsupported", `${cmd} installs its watcher with launchd (macOS) or systemd (Linux)`);
|
|
104
109
|
const dshOverride = str(p.flags, "dsh");
|
|
@@ -166,8 +171,11 @@ export async function harnessStart(p, out, harness) {
|
|
|
166
171
|
await configureGitCredentialForWorktree(process.cwd(), creds);
|
|
167
172
|
if (creds.vendor && creds.vendor !== harness)
|
|
168
173
|
throw new CliError("vendor_mismatch", `${ref} is saved as ${creds.vendor}, not ${harness}`);
|
|
169
|
-
if (harness === "antigravity")
|
|
170
|
-
|
|
174
|
+
if (harness === "antigravity") {
|
|
175
|
+
if (inContainer)
|
|
176
|
+
provisionContainerInstallRecord();
|
|
177
|
+
settings = antigravitySettings(sandbox, process.cwd(), configRoot(), new URL(creds.url).host, [...writable, ...ownWorktreeGitDir(process.cwd())], requireInstall().bin);
|
|
178
|
+
}
|
|
171
179
|
const priorState = readState(ref);
|
|
172
180
|
if (priorState.turn_guard?.fault) {
|
|
173
181
|
const fault = priorState.turn_guard.fault;
|
|
@@ -217,7 +225,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
217
225
|
lines.push(`Adopted Antigravity conversation ${session}. Do not resume it elsewhere while the watcher runs it: two clients on one conversation conflict.`);
|
|
218
226
|
}
|
|
219
227
|
if (harness === "antigravity" && sandbox === "workspace-write")
|
|
220
|
-
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
228
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox, install.bin), unproductivePerHour);
|
|
221
229
|
}
|
|
222
230
|
}
|
|
223
231
|
else {
|
|
@@ -252,12 +260,12 @@ export async function harnessStart(p, out, harness) {
|
|
|
252
260
|
lines.push(`Started DeepSeek Harness session ${session}; its first turn (reading its role and inbox) is running, event log: ${firstTurnLog}`);
|
|
253
261
|
}
|
|
254
262
|
else if (harness === "antigravity") {
|
|
255
|
-
const started = runAntigravityTurn(bin, antigravityTurnArgs(prompt, model, effort, turnTimeout * 60, settings), firstTurnLog, process.cwd(), ref, undefined, undefined, antigravityTurnEnv(sandbox));
|
|
263
|
+
const started = runAntigravityTurn(bin, antigravityTurnArgs(prompt, model, effort, turnTimeout * 60, settings), firstTurnLog, process.cwd(), ref, undefined, undefined, antigravityTurnEnv(sandbox, install.bin));
|
|
256
264
|
session = started.conversation;
|
|
257
265
|
await completePendingTurnGuard(ref, probeFor(harness, session, ref), (message) => diagnostic.push(message), started.output, antigravityTokenTotal(started.record.result?.usage));
|
|
258
266
|
lines.push(`Started Antigravity conversation ${session}; its first turn (reading its role and inbox) completed, JSON turn log: ${firstTurnLog}`);
|
|
259
267
|
if (sandbox === "workspace-write")
|
|
260
|
-
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox), unproductivePerHour);
|
|
268
|
+
await runAntigravitySandboxSelfCheck(ref, bin, settings, process.cwd(), session, model, effort, turnTimeout * 60, firstTurnLog, turnsPerHour, antigravityTurnEnv(sandbox, install.bin), unproductivePerHour);
|
|
261
269
|
}
|
|
262
270
|
else {
|
|
263
271
|
// Claude Code takes the session id from us, so nothing has to be read back from its output.
|
|
@@ -308,7 +316,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
308
316
|
mkdirSync(tmp, { recursive: true });
|
|
309
317
|
const followDelay = Number(str(p.flags, "follow-delay") ?? "300");
|
|
310
318
|
const prune = bool(p.flags, "prune");
|
|
311
|
-
watcherEnv = { TMPDIR: tmp, ...(machineSessionId ? { BSCHAT_MACHINE_SESSION_ID: machineSessionId } : {}), ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? {
|
|
319
|
+
watcherEnv = { TMPDIR: tmp, ...(machineSessionId ? { BSCHAT_MACHINE_SESSION_ID: machineSessionId } : {}), ...(harness === "claude-code" ? claudeSandboxEnv(sandbox) : {}), ...(harness === "antigravity" ? { ...antigravityTurnEnv(sandbox, install.bin), BSCHAT_MODEL: model, ...(effort ? { BSCHAT_EFFORT: effort } : {}) } : {}) };
|
|
312
320
|
const turnSpec = { harness, session, timeout: turnTimeout, turnsPerHour, unproductivePerHour, coalesceSeconds: turnCoalesceSeconds, provider, model, ...(machineSessionId ? { machineSessionId } : {}) };
|
|
313
321
|
if (inContainer) {
|
|
314
322
|
const sess = sessionOfExec(exec);
|
|
@@ -334,12 +342,13 @@ export async function harnessStart(p, out, harness) {
|
|
|
334
342
|
"--exec", exec,
|
|
335
343
|
"--interval", String(interval),
|
|
336
344
|
"--follow-delay", String(followDelay),
|
|
345
|
+
"--startup-jitter-seconds", String(startupJitterSeconds),
|
|
337
346
|
...(prune ? ["--prune"] : []),
|
|
338
347
|
...turnArgs(turnSpec),
|
|
339
348
|
];
|
|
340
349
|
}
|
|
341
350
|
else {
|
|
342
|
-
installWatcherService(ref, exec, interval, followDelay, watcherEnv, undefined, { json: false, print: (h) => watcherOut.push(h) }, prune, turnSpec);
|
|
351
|
+
installWatcherService(ref, exec, interval, followDelay, watcherEnv, undefined, { json: false, print: (h) => watcherOut.push(h) }, prune, turnSpec, startupJitterSeconds);
|
|
343
352
|
const wl = watcherOut.join("\n").split("\n");
|
|
344
353
|
lines.push(wl[0].replace(/^Wrote /, "Watcher: wrote "), ...wl.filter((l) => l.startsWith("Linger is off")));
|
|
345
354
|
}
|
package/dist/commands/install.js
CHANGED
|
@@ -6,7 +6,7 @@ import { bool } from "../args.js";
|
|
|
6
6
|
import { CliError } from "../errors.js";
|
|
7
7
|
import { binVersion, ensureCommandLinks, ensureInstall, latestPublished, lingerEnabled, readInstall, restartInstallServices, watcherServices } from "../install.js";
|
|
8
8
|
import { CLI_VERSION } from "../version.js";
|
|
9
|
-
import { refreshInstalledHooks } from "../harness.js";
|
|
9
|
+
import { CODEX_REQUIREMENTS_PATH, codexHooksDuplicateWithManagedPolicy, reconcileCodexHooks, refreshInstalledHooks } from "../harness.js";
|
|
10
10
|
import { configRoot } from "../config.js";
|
|
11
11
|
import { defaultWorkspaceWritableRoots } from "../start-options.js";
|
|
12
12
|
import { machineEnvironmentChecks } from "../environment-checks.js";
|
|
@@ -28,6 +28,9 @@ export async function install(p, out) {
|
|
|
28
28
|
lines.push(`Updated PATH links: ${aliases.created.join(", ")}`);
|
|
29
29
|
if (aliases.conflicts.length)
|
|
30
30
|
lines.push(`Could not add PATH links: ${aliases.conflicts.join(", ")}`);
|
|
31
|
+
const managedCodex = reconcileCodexHooks(rec.bin, false);
|
|
32
|
+
if (managedCodex.managed && managedCodex.changed && managedCodex.path)
|
|
33
|
+
lines.push(`Removed duplicate Codex hook registration from ${managedCodex.path}; ${CODEX_REQUIREMENTS_PATH} already registers it.`);
|
|
31
34
|
const refreshedHooks = bool(p.flags, "latest") ? refreshInstalledHooks(process.cwd(), rec.bin) : [];
|
|
32
35
|
if (refreshedHooks.length)
|
|
33
36
|
lines.push(`Updated harness hooks: ${refreshedHooks.join(", ")}`);
|
|
@@ -166,6 +169,20 @@ export async function doctor(_p, out) {
|
|
|
166
169
|
checks.push({ ok: true, what: `npx caches hold ${npx.length} cop${npx.length === 1 ? "y" : "ies"} (${[...new Set(npx)].sort().join(", ")}); only commands that still say npx use them` });
|
|
167
170
|
// This repo's hook and instructions.
|
|
168
171
|
const root = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf8" }).stdout?.trim() || process.cwd();
|
|
172
|
+
if (existsSync(CODEX_REQUIREMENTS_PATH) && existsSync(join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "hooks.json"))) {
|
|
173
|
+
const requirements = readFileSync(CODEX_REQUIREMENTS_PATH, "utf8");
|
|
174
|
+
const codexPath = join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "hooks.json");
|
|
175
|
+
try {
|
|
176
|
+
const doc = JSON.parse(readFileSync(codexPath, "utf8"));
|
|
177
|
+
if (codexHooksDuplicateWithManagedPolicy(requirements, doc))
|
|
178
|
+
checks.push({ ok: false, what: `b9s Codex hook is registered by both ${CODEX_REQUIREMENTS_PATH} and ${codexPath}`, fix: "b9s setup --as <your agent> (removes only b9s's duplicate user hook entries)" });
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (error instanceof CliError)
|
|
182
|
+
throw error;
|
|
183
|
+
throw new CliError("bad_settings", `${codexPath} is not valid JSON; fix it or remove it`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
169
186
|
const sp = join(root, ".claude", "settings.local.json");
|
|
170
187
|
if (existsSync(sp)) {
|
|
171
188
|
const hooks = JSON.stringify(JSON.parse(readFileSync(sp, "utf8")).hooks ?? {});
|
package/dist/commands/join.js
CHANGED
|
@@ -2,13 +2,12 @@ import { cliUserAgent } from "../legacy-alias.js";
|
|
|
2
2
|
import { need, str, bool } from "../args.js";
|
|
3
3
|
import { agentRef, DEFAULT_URL, loadAgent, resolveModel, saveAgent } from "../config.js";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
-
import { existsSync,
|
|
6
|
-
import {
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { join as pathJoin } from "node:path";
|
|
7
7
|
import { CliError } from "../errors.js";
|
|
8
8
|
import { defaultMachine } from "../git.js";
|
|
9
9
|
import { ensureInstall, readInstall } from "../install.js";
|
|
10
|
-
import {
|
|
11
|
-
import { claudeCheckoutOwner, claudeCheckoutTaken, withCodexHooks, HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
|
|
10
|
+
import { claudeCheckoutOwner, claudeCheckoutTaken, reconcileCodexHooks, HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
|
|
12
11
|
import { detectVendor } from "../vendor.js";
|
|
13
12
|
import { CLI_VERSION } from "../version.js";
|
|
14
13
|
import { assertEnrolledStartProject } from "../start-options.js";
|
|
@@ -61,6 +60,11 @@ export async function setup(p, out) {
|
|
|
61
60
|
const written = [];
|
|
62
61
|
for (const h of harnessList(p, vendor))
|
|
63
62
|
written.push(...installForHarness(root, h, files, ref, creds.url, inst.bin));
|
|
63
|
+
if (harnessList(p, vendor).includes("codex")) {
|
|
64
|
+
const codex = reconcileCodexHooks(inst.bin, false);
|
|
65
|
+
if (codex.managed && codex.changed && codex.path)
|
|
66
|
+
written.push(codex.path);
|
|
67
|
+
}
|
|
64
68
|
const uniq = [...new Set(written)];
|
|
65
69
|
const selfTest = harnessList(p, vendor).includes("claude-code") ? verifyClaudeHook(root, ref) : null;
|
|
66
70
|
out.print(`b9s ${inst.version} for this machine: ${inst.bin}\nRecorded ${vendor} -> ${ref} in ${idPath}\nWrote: ${uniq.join(", ")}${selfTest ? `\n${selfTest}` : ""}`, { install: inst, identity: idPath, written: uniq, hook_verified: !!selfTest });
|
|
@@ -122,8 +126,9 @@ export async function join(p, out, expectedProject) {
|
|
|
122
126
|
written = [...new Set(written)];
|
|
123
127
|
}
|
|
124
128
|
const selfTest = !noBind && !bool(p.flags, "no-skill") && harnessList(p, vendor).includes("claude-code") ? verifyClaudeHook(root, ref) : null;
|
|
125
|
-
const
|
|
126
|
-
const
|
|
129
|
+
const codexHook = vendor === "codex" ? reconcileCodexHooks(inst.bin, true) : null;
|
|
130
|
+
const codexHookPath = codexHook && !codexHook.managed ? codexHook.path : null;
|
|
131
|
+
const hasLocalHook = !!selfTest || !!codexHook || written.some((file) => file.endsWith(".agents/hooks.json"));
|
|
127
132
|
const wakePathWarnings = hasLocalHook ? [] : (json.wake_path_warnings ?? []);
|
|
128
133
|
const human = [
|
|
129
134
|
json.project
|
|
@@ -144,7 +149,9 @@ export async function join(p, out, expectedProject) {
|
|
|
144
149
|
json.revived && json.resume ? `--- ${json.resume.title} ---\n${json.resume.body}\n---${json.resume.evidence.length ? `\nevidence: ${json.resume.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}` : null,
|
|
145
150
|
json.revived && json.resume ? `Read it before doing anything else.` : null,
|
|
146
151
|
``,
|
|
147
|
-
vendor === "codex" ?
|
|
152
|
+
vendor === "codex" ? (codexHook?.managed
|
|
153
|
+
? `Codex: b9s's hooks are managed once by /etc/codex/requirements.toml; duplicate user hook entries were removed. They deliver your mentions and assignments inside your thread once b9s knows which thread is you: b9s codex bind <thread-id>, or a watcher (b9s watch --launchd), which is still what wakes you when you are idle.`
|
|
154
|
+
: `Codex: b9s's hooks are in ${codexHookPath} (approve them when Codex asks); they deliver your mentions and assignments inside your thread once b9s knows which thread is you: b9s codex bind <thread-id>, or a watcher (b9s watch --launchd), which is still what wakes you when you are idle.`) : vendor === "antigravity" ? `Antigravity: .agents/hooks.json now delivers your mentions and assignments inside your conversation, once b9s knows which conversation is you: b9s antigravity bind <conversation-id> (the folder name under ~/.gemini/antigravity/brain/ holding your artifacts). A watcher (b9s watch --launchd) also binds it, and is still what wakes you when you are idle.` : vendor !== "claude-code" ? `No hook exists for ${vendor}: you will not be told about replies unless you run a watcher. See the skill's "Knowing when someone talks to you" section (b9s watch --launchd).` : null,
|
|
148
155
|
`Next: b9s me && b9s who && b9s inbox && b9s handoffs --open`,
|
|
149
156
|
].filter((l) => l !== null).join("\n");
|
|
150
157
|
out.print(human, { install: inst, agent: json.agent, project: json.project, saved: path, identity: idPath, bound: !noBind, written, wake_path_warnings: wakePathWarnings, revived: !!json.revived, resume: json.resume ?? null, export: { BSCHAT_AGENT: ref } });
|
|
@@ -202,19 +209,3 @@ function writeIdentityDryRun(root, vendor, name, replace) {
|
|
|
202
209
|
throw new CliError("identity_exists", `${p} already maps ${vendor} to agent "${existing.name}"`, `Two ${vendor} agents share this checkout. Join with --no-bind and address yourself per call (b9s --as ${name} ...), or --replace to make "${name}" this checkout's default instead of "${existing.name}".`);
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
|
-
/** Merges b9s's hooks into this machine's ~/.codex/hooks.json; returns its path. */
|
|
206
|
-
function installCodexHooks(bin) {
|
|
207
|
-
const path = codexHooksPath();
|
|
208
|
-
let doc = {};
|
|
209
|
-
if (existsSync(path)) {
|
|
210
|
-
try {
|
|
211
|
-
doc = JSON.parse(readFileSync(path, "utf8"));
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
throw new CliError("bad_settings", `${path} is not valid JSON; fix it or remove it`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
218
|
-
writeFileSync(path, JSON.stringify(withCodexHooks(doc, bin), null, 2) + "\n");
|
|
219
|
-
return path;
|
|
220
|
-
}
|