benignswarm 0.12.82 → 0.12.83
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/admin-index.js +6 -2
- package/dist/args.js +3 -3
- package/dist/brief.js +42 -8
- package/dist/client.js +4 -4
- package/dist/commands/admin.js +55 -16
- package/dist/commands/agent.js +33 -9
- package/dist/commands/antigravity.js +2 -2
- package/dist/commands/codex-start.js +17 -17
- package/dist/commands/codex.js +6 -6
- package/dist/commands/evidence.js +16 -1
- package/dist/commands/goal.js +5 -5
- package/dist/commands/hook.js +125 -57
- package/dist/commands/install.js +34 -28
- package/dist/commands/join.js +15 -14
- package/dist/commands/lists.js +2 -2
- package/dist/commands/machine-admin.js +56 -28
- package/dist/commands/machine.js +53 -29
- package/dist/commands/measures.js +191 -0
- package/dist/commands/notices.js +53 -0
- package/dist/commands/operator.js +68 -25
- package/dist/commands/retire.js +2 -2
- package/dist/commands/wake.js +4 -4
- package/dist/commands/watch.js +75 -28
- package/dist/commands/worktrees.js +4 -4
- package/dist/commands/wu.js +168 -61
- package/dist/config.js +11 -11
- package/dist/directories.js +83 -0
- package/dist/env-aliases.js +10 -0
- package/dist/git.js +2 -2
- package/dist/harness.js +91 -37
- package/dist/harnesses.js +5 -4
- package/dist/help.js +208 -183
- package/dist/index.js +37 -3
- package/dist/install.js +27 -19
- package/dist/legacy-alias.js +32 -0
- package/dist/notices.js +107 -0
- package/dist/output.js +2 -1
- package/dist/sessions.js +1 -1
- package/dist/update.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -3
package/dist/admin-index.js
CHANGED
|
@@ -6,8 +6,12 @@ import { ADMIN_HELP } from "./help.js";
|
|
|
6
6
|
import { AGENT_ORIENTATION } from "./commands/operator.js";
|
|
7
7
|
import { makeOut } from "./output.js";
|
|
8
8
|
import { CLI_VERSION } from "./version.js";
|
|
9
|
-
|
|
9
|
+
import { applyEnvAliases } from "./env-aliases.js";
|
|
10
|
+
import { warnLegacyAlias } from "./legacy-alias.js";
|
|
11
|
+
/** b9s-admin: the operator binary. Agents use b9s, whose help never lists these. */
|
|
10
12
|
async function main(argv) {
|
|
13
|
+
warnLegacyAlias();
|
|
14
|
+
applyEnvAliases();
|
|
11
15
|
// For an AI agent driving this tool: what it is, and how to load the operator skill. Checked
|
|
12
16
|
// before parsing because --agent also takes a value elsewhere (notifier --agent <name>).
|
|
13
17
|
if (argv[0] === "--agent") {
|
|
@@ -17,7 +21,7 @@ async function main(argv) {
|
|
|
17
21
|
const p = parse(argv);
|
|
18
22
|
const out = makeOut(bool(p.flags, "json"));
|
|
19
23
|
if (bool(p.flags, "version")) {
|
|
20
|
-
process.stdout.write(`
|
|
24
|
+
process.stdout.write(`b9s-admin ${CLI_VERSION}\n`);
|
|
21
25
|
return 0;
|
|
22
26
|
}
|
|
23
27
|
if (!p.positionals[0] || bool(p.flags, "help")) {
|
package/dist/args.js
CHANGED
|
@@ -3,8 +3,8 @@ import { CliError } from "./errors.js";
|
|
|
3
3
|
// These options accept comma-separated collections, so repeating them should
|
|
4
4
|
// append another collection instead of discarding earlier values.
|
|
5
5
|
export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "default-tags", "units", "waits-on", "needs", "exclude", "remove", "post", "harness", "variant", "requires"];
|
|
6
|
-
export const STRING_FLAGS = ["as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task", "state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions", "cardinality", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "reply-to", "event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent", "parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval", "requeue-after", "unacked-after", "category", "command", "follow-delay", "env", "scope", "append", "pr", "note", "add", "remove", "merged", "tag", "activity", "max-unanswered", "to", "replay-of", "branch", "effort", "by", "target", "milestone", "file", "exit", "depends-on", "default-tags", "source", "
|
|
7
|
-
export const BOOL_FLAGS = ["latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "scope-only", "unread", "pending", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor", "cancel"];
|
|
6
|
+
export const STRING_FLAGS = ["as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task", "state", "blocked-on", "tags", "custom", "vendor", "role", "tier", "description", "permissions", "cardinality", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "reply-to", "event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent", "parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval", "requeue-after", "unacked-after", "category", "command", "command-pattern", "follow-delay", "env", "scope", "scope-file", "scope-from", "append", "pr", "note", "add", "remove", "merged", "tag", "activity", "max-unanswered", "to", "replay-of", "branch", "effort", "by", "target", "milestone", "file", "exit", "depends-on", "default-tags", "source", "on", "partial", "question", "ruling", "gaps", "unit", "units", "blocks", "sla", "takeover", "max-open", "max-in-progress", "require-scope", "require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit", "require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email", "repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on", "sandbox", "thread", "turn-timeout", "session", "plain", "if-yes", "if-no", "ssh", "variant", "count", "needs", "min-ram", "exclude", "carry", "from", "to-ssh", "wait", "writable", "for", "until", "reason", "at", "requires", "priority", "informs", "amend", "waive-informs", "text", "kind", "claim", "decision", "sha", "value", "expect"];
|
|
7
|
+
export const BOOL_FLAGS = ["latest", "no-restart", "json", "follow", "account", "help", "version", "broadcast", "create-channels", "read-account-status", "replace-key", "mentions-me", "no-skill", "replace", "template", "scope-only", "unread", "pending", "force", "no-hooks", "yes", "open", "bind-here", "peek", "once", "launchd", "full", "no-bind", "all", "here", "keep-worktree", "prune", "abandon", "defer", "hold", "clear", "met", "shared", "archive", "approve", "turn", "service", "print-hooks", "create", "rotate", "codex-userns", "bwrap-userns", "print-apparmor", "cancel", "rerun", "confirmed", "refuted"];
|
|
8
8
|
export function parse(argv) {
|
|
9
9
|
const options = {};
|
|
10
10
|
for (const f of STRING_FLAGS)
|
|
@@ -30,7 +30,7 @@ export function parse(argv) {
|
|
|
30
30
|
catch (e) {
|
|
31
31
|
if (e instanceof CliError)
|
|
32
32
|
throw e;
|
|
33
|
-
throw new CliError("usage", e.message, "Run:
|
|
33
|
+
throw new CliError("usage", e.message, "Run: b9s --help");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
export function str(flags, k) {
|
package/dist/brief.js
CHANGED
|
@@ -1,30 +1,64 @@
|
|
|
1
1
|
import { Client } from "./client.js";
|
|
2
2
|
import { loadAgent, resolveAgentName } from "./config.js";
|
|
3
|
+
export function formatOutcomeMeasures(measures = [], omitted = 0) {
|
|
4
|
+
const rows = measures.slice(0, 6).map((m) => {
|
|
5
|
+
const value = m.value === null || m.value === "unknown" ? "unknown" : `${String(m.value)}${m.unit ? ` ${m.unit}` : ""}`;
|
|
6
|
+
const target = m.target && typeof m.target === "object" ? (() => {
|
|
7
|
+
const t = m.target;
|
|
8
|
+
return t.op ? `${t.op} ${String(t.value ?? "unknown")}` : String(t.value ?? "unknown");
|
|
9
|
+
})() : "unknown";
|
|
10
|
+
const trend = m.trend.length ? m.trend.map(String).join(" ← ") : "no history";
|
|
11
|
+
const freshness = m.freshness === "unknown" ? "freshness unknown" : m.freshness === "stale" ? `stale, ${m.merges_since ?? "?"} merges since` : "current";
|
|
12
|
+
const where = m.slices.length ? `slice ${m.slices.join(",")}` : "project";
|
|
13
|
+
const firstFailingStep = m.first_failing_step?.replace(/\s+/g, " ").trim();
|
|
14
|
+
const fail = m.status === "failing" || m.status === "regressed" ? `; ${m.status}${firstFailingStep ? ` at ${firstFailingStep}` : ""}${m.suspect_range ? `; suspect ${m.suspect_range.from_sha ?? "?"}..${m.suspect_range.to_sha ?? "?"}` : ""}` : m.status === "unknown" ? "; unknown" : "";
|
|
15
|
+
return `Outcome measure ${m.project}/${where} ${m.name}: ${value}; target ${target}; trend ${trend}; ${freshness}${fail}`;
|
|
16
|
+
});
|
|
17
|
+
if (omitted > 0 && rows.length)
|
|
18
|
+
rows[rows.length - 1] += `; ${omitted} more omitted`;
|
|
19
|
+
return rows;
|
|
20
|
+
}
|
|
21
|
+
export function outcomeMeasureSnapshot(measures = [], omitted = 0) {
|
|
22
|
+
return JSON.stringify({ measures: measures.map((m) => ({
|
|
23
|
+
project: m.project, name: m.name, slices: m.slices, definition_version: m.definition_version,
|
|
24
|
+
value: m.value, unit: m.unit, target: m.target, trend: m.trend, tested_sha: m.tested_sha,
|
|
25
|
+
status: m.status, first_failing_step: m.first_failing_step, suspect_range: m.suspect_range,
|
|
26
|
+
})), omitted });
|
|
27
|
+
}
|
|
3
28
|
export async function fetchRecoveryBrief(nameOrRef) {
|
|
4
29
|
const name = resolveAgentName(nameOrRef);
|
|
5
30
|
const creds = loadAgent(name);
|
|
6
|
-
const
|
|
7
|
-
|
|
31
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
32
|
+
const [response, active] = await Promise.all([
|
|
33
|
+
client.call("GET", "/agents/me/brief"),
|
|
34
|
+
client.call("GET", "/agents/me/notices"),
|
|
35
|
+
]);
|
|
36
|
+
if (!Array.isArray(active.notices))
|
|
37
|
+
throw new Error("GET /agents/me/notices returned no notices array");
|
|
38
|
+
return { ...response.brief, notices: active.notices };
|
|
8
39
|
}
|
|
9
40
|
export function formatRecoveryBrief(brief) {
|
|
10
|
-
const lines = [`[
|
|
41
|
+
const lines = [`[b9s] Resume brief for ${brief.agent}`, `Role: ${brief.role}`];
|
|
11
42
|
if (brief.projects.length)
|
|
12
43
|
lines.push(`Process: ${brief.projects.map((p) => `${p.name} ${p.process} (${Array.isArray(p.changed_since_last_read) ? `changed since you last read: ${p.changed_since_last_read.join("; ")}` : p.changed_since_last_read})`).join("; ")}`);
|
|
44
|
+
lines.push("Questions waiting on you:");
|
|
45
|
+
lines.push(...(brief.questions.length ? brief.questions.map((q) => ` ${q.project} WU #${q.number} (${q.age_minutes ?? 0} min ago): ${q.question} — ${q.next}`) : [" none"]));
|
|
13
46
|
lines.push("Units:");
|
|
14
47
|
lines.push(...(brief.units.length ? brief.units.map((u) => ` [${u.state}] ${u.project} WU #${u.number} ${u.title} — ${u.next}`) : [" none"]));
|
|
15
48
|
lines.push("Reviews waiting on you:");
|
|
16
49
|
lines.push(...(brief.reviews.length ? brief.reviews.map((r) => ` ${r.project} ${r.slice ? `slice ${r.slice}` : `WU #${r.number}`} ${r.title} — ${r.next}`) : [" none"]));
|
|
17
|
-
lines.push("Open
|
|
18
|
-
lines.push(...
|
|
19
|
-
if (!brief.questions.length && !brief.asks.length)
|
|
20
|
-
lines.push(" none");
|
|
50
|
+
lines.push("Open asks:");
|
|
51
|
+
lines.push(...(brief.asks.length ? brief.asks.slice(0, 10).map((a) => ` ${a.project} ask ${a.id}: ${a.question} (${a.blocks}) — ${a.next}`) : [" none"]));
|
|
21
52
|
lines.push("Slices:");
|
|
22
53
|
lines.push(...(brief.slices.length ? brief.slices.map((s) => ` ${s.project} ${s.key}: ${s.title} — ${s.next}`) : [" none"]));
|
|
23
54
|
lines.push("Recent decisions:");
|
|
24
55
|
lines.push(...(brief.decisions.length ? brief.decisions.map((d) => ` ${d.project} ${d.slice} WU #${d.unit} (${d.source}): ${d.ruling}`) : [" none"]));
|
|
56
|
+
lines.push("Current notices:");
|
|
57
|
+
lines.push(...(brief.notices?.length ? brief.notices.map((n) => ` [${n.scope} ${n.scope_name}] ${n.text}`) : [" none"]));
|
|
58
|
+
lines.push(...formatOutcomeMeasures(brief.measures, brief.measures_omitted));
|
|
25
59
|
return lines.join("\n");
|
|
26
60
|
}
|
|
27
|
-
export const recoveryBriefUnavailableText = "[
|
|
61
|
+
export const recoveryBriefUnavailableText = "[b9s] Recovery brief unavailable after compaction. Run b9s resume to retrieve the current agent state.";
|
|
28
62
|
export function recoveryBriefWasDelivered(brief, sent) {
|
|
29
63
|
return !!brief && sent;
|
|
30
64
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError } from "./errors.js";
|
|
2
2
|
import { collectAuto } from "./git.js";
|
|
3
3
|
import { resolveEffort } from "./model.js";
|
|
4
|
-
import {
|
|
4
|
+
import { cliUserAgent } from "./legacy-alias.js";
|
|
5
5
|
import { noteServerVersions } from "./update.js";
|
|
6
6
|
export class Client {
|
|
7
7
|
url;
|
|
@@ -32,7 +32,7 @@ export class Client {
|
|
|
32
32
|
return new Client(url, key, null);
|
|
33
33
|
}
|
|
34
34
|
headers() {
|
|
35
|
-
const h = { authorization: `Bearer ${this.key}`, "user-agent":
|
|
35
|
+
const h = { authorization: `Bearer ${this.key}`, "user-agent": cliUserAgent() };
|
|
36
36
|
if (this.auto)
|
|
37
37
|
h["x-bschat-auto"] = JSON.stringify(this.auto);
|
|
38
38
|
if (this.machineIdentity)
|
|
@@ -71,13 +71,13 @@ export class Client {
|
|
|
71
71
|
}
|
|
72
72
|
if (!res.ok) {
|
|
73
73
|
if (res.status >= 500 && attempt < retries) {
|
|
74
|
-
process.stderr.write(`
|
|
74
|
+
process.stderr.write(`b9s: ${method} ${path} failed (${res.status}${json?.reference ? `, reference ${json.reference}` : ""}); retrying\n`);
|
|
75
75
|
await backoff(attempt);
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
78
|
const err = json;
|
|
79
79
|
const hint = res.status >= 500
|
|
80
|
-
? `This is a platform failure, not something to fix on your side. Do not retry in a loop. Report it once:
|
|
80
|
+
? `This is a platform failure, not something to fix on your side. Do not retry in a loop. Report it once: b9s feedback "<what you were doing>${err.reference ? ` ref ${err.reference}` : ""}" and carry on with other work.`
|
|
81
81
|
: undefined;
|
|
82
82
|
throw new CliError(err.error ?? `http_${res.status}`, err.message ?? text, hint);
|
|
83
83
|
}
|
package/dist/commands/admin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cliUserAgent } from "../legacy-alias.js";
|
|
2
2
|
import { bool, need, str } from "../args.js";
|
|
3
3
|
import { Client } from "../client.js";
|
|
4
4
|
import { DEFAULT_URL, forgetAdmin, loadAdmin, resolveAdminName, saveAdmin } from "../config.js";
|
|
@@ -9,7 +9,8 @@ import { table } from "../output.js";
|
|
|
9
9
|
import { milestoneWith, milestonesWith } from "./wu.js";
|
|
10
10
|
import { awayUntil } from "./agent.js";
|
|
11
11
|
import { agentMove, machineAdmin, poolAdmin, projectCheckoutAdmin, projectRepoAdmin } from "./machine-admin.js";
|
|
12
|
-
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, worktreeAdmin } from "./operator.js";
|
|
12
|
+
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, textCheckAdmin, worktreeAdmin } from "./operator.js";
|
|
13
|
+
import { adminNotice } from "./notices.js";
|
|
13
14
|
function adminClient(p) {
|
|
14
15
|
return Client.forAdmin(loadAdmin(resolveAdminName(str(p.flags, "admin"))));
|
|
15
16
|
}
|
|
@@ -22,7 +23,7 @@ export async function admin(p, out) {
|
|
|
22
23
|
return browserLogin(url, str(p.flags, "email") ?? null, str(p.flags, "as") ?? "default", out);
|
|
23
24
|
const nick = str(p.flags, "as");
|
|
24
25
|
if (!nick)
|
|
25
|
-
throw new CliError("usage", "
|
|
26
|
+
throw new CliError("usage", "b9s-admin login (approve in your browser) or, for scripts and CI: --as <nickname> --key <bs_admin_...>");
|
|
26
27
|
const key = need(p.flags, "key");
|
|
27
28
|
if (!key.startsWith("bs_admin_"))
|
|
28
29
|
throw new CliError("usage", "admin login expects an admin key (bs_admin_...)");
|
|
@@ -39,7 +40,7 @@ export async function admin(p, out) {
|
|
|
39
40
|
if (creds.key.startsWith("bs_cli_"))
|
|
40
41
|
await Client.raw(creds.url, creds.key).call("POST", "/auth/cli/logout", {});
|
|
41
42
|
forgetAdmin(nick);
|
|
42
|
-
out.print(`Signed out ${nick}${creds.key.startsWith("bs_cli_") ? " and ended its session" : " (an admin key stays valid until revoked:
|
|
43
|
+
out.print(`Signed out ${nick}${creds.key.startsWith("bs_cli_") ? " and ended its session" : " (an admin key stays valid until revoked: b9s-admin keys revoke <id>)"}.`, { signed_out: nick });
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
46
|
case "signup": {
|
|
@@ -48,11 +49,11 @@ export async function admin(p, out) {
|
|
|
48
49
|
const [name, email] = [action, rest[0]];
|
|
49
50
|
if (!name || !email)
|
|
50
51
|
throw new CliError("usage", "admin signup --url <api> --key <signup-code> <account-name> <email>");
|
|
51
|
-
const res = await fetch(`${url}/accounts`, { method: "POST", headers: { "content-type": "application/json", "x-signup-code": code, "user-agent":
|
|
52
|
+
const res = await fetch(`${url}/accounts`, { method: "POST", headers: { "content-type": "application/json", "x-signup-code": code, "user-agent": cliUserAgent() }, body: JSON.stringify({ name, email }) });
|
|
52
53
|
const json = await res.json();
|
|
53
54
|
if (!res.ok)
|
|
54
55
|
throw new CliError(json.error, json.message);
|
|
55
|
-
out.print(`Account ${json.account.name} created.\nAdmin key (shown once): ${json.admin_key}\nNext:
|
|
56
|
+
out.print(`Account ${json.account.name} created.\nAdmin key (shown once): ${json.admin_key}\nNext: b9s-admin login --as ${name} --key ${json.admin_key} --url ${url}`, json);
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
case "project":
|
|
@@ -76,19 +77,21 @@ export async function admin(p, out) {
|
|
|
76
77
|
case "process":
|
|
77
78
|
return processAdmin(action, rest, p, out);
|
|
78
79
|
case "milestones": {
|
|
79
|
-
//
|
|
80
|
+
// b9s-admin milestones <project> [export [--out f] | set --file f]
|
|
80
81
|
if (!action)
|
|
81
82
|
throw new CliError("usage", "milestones <project> [export [--out plan.json] | set --file plan.json]");
|
|
82
83
|
return milestonesWith(adminClient(p), action, rest[0], p, out);
|
|
83
84
|
}
|
|
84
85
|
case "milestone": {
|
|
85
|
-
//
|
|
86
|
+
// b9s-admin milestone <project> add|edit|show|decide|close|reopen|review|verdict|gap-units <key> ...
|
|
86
87
|
if (!action)
|
|
87
88
|
throw new CliError("usage", "milestone <project> <add|edit|show|decide|close|reopen|review|verdict|gap-units> <key> ...");
|
|
88
89
|
return milestoneWith(adminClient(p), action, rest[0], rest[1], p, out, rest.slice(2));
|
|
89
90
|
}
|
|
90
91
|
case "needs":
|
|
91
92
|
return needsAdmin(p, out);
|
|
93
|
+
case "notice":
|
|
94
|
+
return adminNotice(action, rest, p, out);
|
|
92
95
|
case "answer":
|
|
93
96
|
return answerAdmin([action, ...rest].filter((x) => x !== undefined), p, out);
|
|
94
97
|
case "explain":
|
|
@@ -97,6 +100,8 @@ export async function admin(p, out) {
|
|
|
97
100
|
return notifierAdmin(p, out);
|
|
98
101
|
case "account":
|
|
99
102
|
return accountAdmin(p, out);
|
|
103
|
+
case "text-check":
|
|
104
|
+
return textCheckAdmin(action, p, out);
|
|
100
105
|
case "worktree":
|
|
101
106
|
return worktreeAdmin(action, rest, p, out);
|
|
102
107
|
case "machine":
|
|
@@ -116,7 +121,7 @@ export async function admin(p, out) {
|
|
|
116
121
|
return;
|
|
117
122
|
}
|
|
118
123
|
default:
|
|
119
|
-
throw new CliError("usage", `unknown admin command ${group ?? ""}`, "Run:
|
|
124
|
+
throw new CliError("usage", `unknown admin command ${group ?? ""}`, "Run: b9s --help");
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
async function project(action, rest, p, out) {
|
|
@@ -140,8 +145,28 @@ async function agent(action, rest, p, out) {
|
|
|
140
145
|
const c = adminClient(p);
|
|
141
146
|
if (bool(p.flags, "account"))
|
|
142
147
|
return accountAgent(action, rest, p, out, c);
|
|
148
|
+
if ((action === "bench" || action === "unbench") && rest[0]) {
|
|
149
|
+
const ref = rest[0];
|
|
150
|
+
const slash = ref.indexOf("/");
|
|
151
|
+
if (slash < 1 || slash === ref.length - 1 || ref.indexOf("/", slash + 1) !== -1)
|
|
152
|
+
throw new CliError("usage", `agent ${action} <project>/<agent>${action === "bench" ? " [--note <text>]" : ""}`);
|
|
153
|
+
const project = ref.slice(0, slash), name = ref.slice(slash + 1);
|
|
154
|
+
const note = str(p.flags, "note");
|
|
155
|
+
const r = await c.call("POST", `/projects/${project}/agents/${name}/${action}`, action === "bench" && note !== undefined ? { note } : {});
|
|
156
|
+
out.print(action === "bench" ? `benched ${ref}${r.released_units?.length ? `; released units ${r.released_units.join(", ")}` : ""}` : `unbenched ${ref}`, r);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
143
159
|
const [proj, name, extra] = rest;
|
|
144
|
-
if (
|
|
160
|
+
if (action === "tier" && proj && name && !extra) {
|
|
161
|
+
const slash = proj.indexOf("/");
|
|
162
|
+
if (slash < 1 || slash === proj.length - 1 || proj.indexOf("/", slash + 1) !== -1)
|
|
163
|
+
throw new CliError("usage", "agent tier <project>/<agent> <routine|careful|expert>");
|
|
164
|
+
if (!["routine", "careful", "expert"].includes(name))
|
|
165
|
+
throw new CliError("usage", "tier must be routine, careful, or expert");
|
|
166
|
+
const r = await c.call("PATCH", `/projects/${proj.slice(0, slash)}/agents/${proj.slice(slash + 1)}`, { tier: name });
|
|
167
|
+
out.print(`agent ${proj} tier is now ${r.tier}`, r);
|
|
168
|
+
}
|
|
169
|
+
else if ((action === "away" || action === "back") && proj && !name) {
|
|
145
170
|
const slash = proj.indexOf("/");
|
|
146
171
|
if (slash < 1 || slash === proj.length - 1 || proj.indexOf("/", slash + 1) !== -1)
|
|
147
172
|
throw new CliError("usage", `agent ${action} <project>/<agent>${action === "away" ? " --for <duration>|--until <ISO> --reason <why>" : ""}`);
|
|
@@ -155,7 +180,7 @@ async function agent(action, rest, p, out) {
|
|
|
155
180
|
}
|
|
156
181
|
else if (action === "list" && proj) {
|
|
157
182
|
const r = await c.call("GET", `/projects/${proj}/agents`);
|
|
158
|
-
out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "active_keys", "created_at"]), r);
|
|
183
|
+
out.print(table(r.agents, ["name", "scope", "vendor", "role_name", "tier", "benched_at", "benched_by", "active_keys", "created_at"]), r);
|
|
159
184
|
}
|
|
160
185
|
else if (action === "create" && proj && name) {
|
|
161
186
|
const r = await c.call("POST", `/projects/${proj}/agents`, { name, vendor: need(p.flags, "vendor"), role: str(p.flags, "role") ?? null, machine: str(p.flags, "machine") ?? null });
|
|
@@ -178,13 +203,21 @@ async function agent(action, rest, p, out) {
|
|
|
178
203
|
out.print(`deleted agent ${name}`, r);
|
|
179
204
|
}
|
|
180
205
|
else
|
|
181
|
-
throw new CliError("usage", "admin agent create|list|role|rotate-key|delete ...", "Run:
|
|
206
|
+
throw new CliError("usage", "admin agent create|list|role|tier <project>/<agent> <tier>|rotate-key|bench|unbench|delete ...", "Run: b9s --help");
|
|
182
207
|
}
|
|
183
208
|
async function accountAgent(action, rest, p, out, c) {
|
|
184
209
|
const [name, extra] = rest;
|
|
210
|
+
if ((action === "bench" || action === "unbench") && name) {
|
|
211
|
+
if (name.includes("/"))
|
|
212
|
+
throw new CliError("usage", `agent ${action} --account <agent>${action === "bench" ? " [--note <text>]" : ""}`);
|
|
213
|
+
const note = str(p.flags, "note");
|
|
214
|
+
const r = await c.call("POST", `/agents/${name}/${action}`, action === "bench" && note !== undefined ? { note } : {});
|
|
215
|
+
out.print(`${action === "bench" ? "benched" : "unbenched"} account/${name}${r.released_units?.length ? `; released units ${r.released_units.join(", ")}` : ""}`, r);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
185
218
|
if (action === "list") {
|
|
186
219
|
const r = await c.call("GET", "/agents");
|
|
187
|
-
out.print(table(r.agents, ["name", "vendor", "role_name", "active_keys", "created_at"]), r);
|
|
220
|
+
out.print(table(r.agents, ["name", "vendor", "role_name", "tier", "benched_at", "benched_by", "active_keys", "created_at"]), r);
|
|
188
221
|
}
|
|
189
222
|
else if (action === "create" && name) {
|
|
190
223
|
const r = await c.call("POST", "/agents", { name, vendor: need(p.flags, "vendor"), role: need(p.flags, "role"), machine: str(p.flags, "machine") ?? null });
|
|
@@ -194,6 +227,12 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
194
227
|
const r = await c.call("PATCH", `/agents/${name}`, { role: extra });
|
|
195
228
|
out.print(`agent ${name} role is now ${r.role_name}`, r);
|
|
196
229
|
}
|
|
230
|
+
else if (action === "tier" && name && extra) {
|
|
231
|
+
if (!["routine", "careful", "expert"].includes(extra))
|
|
232
|
+
throw new CliError("usage", "tier must be routine, careful, or expert");
|
|
233
|
+
const r = await c.call("PATCH", `/agents/${name}`, { tier: extra });
|
|
234
|
+
out.print(`agent ${name} tier is now ${r.tier}`, r);
|
|
235
|
+
}
|
|
197
236
|
else if (action === "rotate-key" && name) {
|
|
198
237
|
const r = await c.call("POST", `/agents/${name}/keys`, { machine: str(p.flags, "machine") ?? null });
|
|
199
238
|
out.print(`previous keys revoked. New key shown once.\nPaste this into the agent's instructions:\n\n${r.instructions}`, r);
|
|
@@ -203,7 +242,7 @@ async function accountAgent(action, rest, p, out, c) {
|
|
|
203
242
|
out.print(`deleted account agent ${name}`, r);
|
|
204
243
|
}
|
|
205
244
|
else
|
|
206
|
-
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | role <name> <role> | rotate-key <name> | delete <name>");
|
|
245
|
+
throw new CliError("usage", "admin agent --account create <name> --vendor v --role r | list | role <name> <role> | tier <name> <tier> | rotate-key <name> | bench|unbench <name> | delete <name>");
|
|
207
246
|
}
|
|
208
247
|
function permsFromFlags(p, projectScoped) {
|
|
209
248
|
const raw = str(p.flags, "permissions");
|
|
@@ -245,7 +284,7 @@ async function role(action, rest, p, out) {
|
|
|
245
284
|
else if (action === "create" && rest[0]) {
|
|
246
285
|
const permissions = permsFromFlags(p, !!proj) ?? { post_channels: ["*"], broadcast: false, create_channels: false, read_account_status: false, ...(proj ? {} : { projects: [] }) };
|
|
247
286
|
const r = await c.call("POST", base, { name: rest[0], description: str(p.flags, "description") ?? "", permissions, cardinality: str(p.flags, "cardinality") ?? "many", reviews: tagList(str(p.flags, "reviews")) ?? [], works: tagList(str(p.flags, "works")) ?? [], trials: tagList(str(p.flags, "trials")) ?? [] });
|
|
248
|
-
out.print(`created ${proj ? "project" : "account"} role ${r.role.name}${!proj ? ` (projects: ${r.role.permissions.projects.join(",") || "none; set with:
|
|
287
|
+
out.print(`created ${proj ? "project" : "account"} role ${r.role.name}${!proj ? ` (projects: ${r.role.permissions.projects.join(",") || "none; set with: b9s-admin role edit ${r.role.name} --projects a,b or '*'"})` : ""}`, r);
|
|
249
288
|
}
|
|
250
289
|
else if (action === "edit" && rest[0]) {
|
|
251
290
|
const body = {};
|
|
@@ -333,7 +372,7 @@ async function enroll(action, rest, p, out) {
|
|
|
333
372
|
*/
|
|
334
373
|
async function browserLogin(url, email, nick, out) {
|
|
335
374
|
const post = async (path, body) => {
|
|
336
|
-
const res = await fetch(`${url}${path}`, { method: "POST", headers: { "content-type": "application/json", "user-agent":
|
|
375
|
+
const res = await fetch(`${url}${path}`, { method: "POST", headers: { "content-type": "application/json", "user-agent": cliUserAgent() }, body: JSON.stringify(body) });
|
|
337
376
|
const json = await res.json().catch(() => ({}));
|
|
338
377
|
return { status: res.status, json };
|
|
339
378
|
};
|
package/dist/commands/agent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
4
|
import { bool, need, str } from "../args.js";
|
|
5
5
|
import { Client } from "../client.js";
|
|
6
6
|
import { agentRef, DEFAULT_URL, listSaved, loadAgent, removeAgent, resolveAgentName, resolveModel, saveAgent } from "../config.js";
|
|
@@ -23,7 +23,7 @@ export function projectOf(p, creds) {
|
|
|
23
23
|
return creds.project;
|
|
24
24
|
const v = str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
|
|
25
25
|
if (!v)
|
|
26
|
-
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; this command needs --project <name> (or BSCHAT_PROJECT)`, "See your accessible projects with:
|
|
26
|
+
throw new CliError("no_project", `${creds.agent} is an account-scoped agent; this command needs --project <name> (or BSCHAT_PROJECT)`, "See your accessible projects with: b9s me");
|
|
27
27
|
return v;
|
|
28
28
|
}
|
|
29
29
|
export async function login(p, out) {
|
|
@@ -33,13 +33,13 @@ export async function login(p, out) {
|
|
|
33
33
|
const name = asFlag.includes("/") ? asFlag.slice(asFlag.indexOf("/") + 1) : asFlag;
|
|
34
34
|
const key = need(p.flags, "key");
|
|
35
35
|
if (!key.startsWith("bs_agent_"))
|
|
36
|
-
throw new CliError("usage", "login expects an agent key (bs_agent_...). Operators sign in with
|
|
36
|
+
throw new CliError("usage", "login expects an agent key (bs_agent_...). Operators sign in with b9s-admin login.");
|
|
37
37
|
const url = (str(p.flags, "url") ?? process.env.BSCHAT_URL ?? DEFAULT_URL).replace(/\/$/, "");
|
|
38
38
|
const me = await Client.raw(url, key).call("GET", "/me");
|
|
39
39
|
if (me.kind !== "agent")
|
|
40
40
|
throw new CliError("bad_key", "key is not an agent key");
|
|
41
41
|
if (me.agent.name !== name) {
|
|
42
|
-
throw new CliError("identity_mismatch", `this key belongs to agent "${me.agent.name}", not "${name}"`, `Run:
|
|
42
|
+
throw new CliError("identity_mismatch", `this key belongs to agent "${me.agent.name}", not "${name}"`, `Run: b9s login --as ${me.agent.name} --key ...`);
|
|
43
43
|
}
|
|
44
44
|
const project = me.project ? me.project.name : null;
|
|
45
45
|
const path = saveAgent({ url, key, account: me.project ? me.project.id : "", project, agent: name, vendor: me.agent.vendor, machine: defaultMachine(str(p.flags, "label")) });
|
|
@@ -67,6 +67,7 @@ export async function me(p, out) {
|
|
|
67
67
|
const r = await client.call("GET", "/me");
|
|
68
68
|
const lines = [
|
|
69
69
|
`agent: ${r.agent.name} (${r.agent.vendor})`,
|
|
70
|
+
`tier: ${r.agent.tier ?? "routine"}`,
|
|
70
71
|
r.scope === "account" ? `scope: account-wide; projects: ${r.projects.length ? r.projects.map((x) => x.name).join(", ") : "(none allowed by your role)"}` : `project: ${r.project.name}`,
|
|
71
72
|
`role: ${r.role ? `${r.role.name} [${r.role.scope} scope, cardinality ${r.role.cardinality}]` : "(none)"}${r.role_name_unresolved ? ` (assigned role ${r.role_name_unresolved} no longer exists)` : ""}`,
|
|
72
73
|
r.role?.description ? `\n${r.role.description}\n` : "",
|
|
@@ -188,7 +189,7 @@ export async function send(p, out) {
|
|
|
188
189
|
body = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
189
190
|
}
|
|
190
191
|
if (!channel || !body.trim())
|
|
191
|
-
throw new CliError("usage", 'send <channel> <message...> | send <channel> --body-file notes.md | echo "..." |
|
|
192
|
+
throw new CliError("usage", 'send <channel> <message...> | send <channel> --body-file notes.md | echo "..." | b9s send <channel> --body-file -');
|
|
192
193
|
if (/\\n/.test(body) && !body.includes("\n")) {
|
|
193
194
|
throw new CliError("escaped_newlines", "the message contains literal backslash-n sequences but no real newlines; it would render as one dense block", "Write the message to a file and send it with --body-file, pipe it on stdin with --body-file -, or use real newlines (in bash: $'line1\\nline2').");
|
|
194
195
|
}
|
|
@@ -209,7 +210,28 @@ export async function send(p, out) {
|
|
|
209
210
|
if (last !== undefined && last >= r.message.seq - 1)
|
|
210
211
|
writeState(agentRef(creds), { ...st, channel_read: { ...(st.channel_read ?? {}), [key]: r.message.seq } });
|
|
211
212
|
}
|
|
212
|
-
|
|
213
|
+
let hint = "";
|
|
214
|
+
if (body.trimEnd().endsWith("?")) {
|
|
215
|
+
try {
|
|
216
|
+
const response = await fetch(`${creds.url}/projects/${encodeURIComponent(project)}/work-units?agent=${encodeURIComponent(creds.agent)}`, { headers: client.headers() });
|
|
217
|
+
if (response.ok) {
|
|
218
|
+
const data = await response.json();
|
|
219
|
+
const units = Array.isArray(data.units) ? data.units : [];
|
|
220
|
+
const owned = units.find((unit) => {
|
|
221
|
+
if (unit.owner_name !== creds.agent || typeof unit.assigned_by !== "string" || unit.assigned_by === "operator")
|
|
222
|
+
return false;
|
|
223
|
+
const escaped = unit.assigned_by.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
224
|
+
return new RegExp(`(^|[^\\w])@${escaped}(?![\\w-])`).test(body);
|
|
225
|
+
});
|
|
226
|
+
if (owned)
|
|
227
|
+
hint = `\nQuestion about WU #${owned.number} for @${owned.assigned_by}: try b9s wu ask ${owned.number}`;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
// A hint lookup is best effort; it must never undo a successful chat post.
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
out.print(`sent #${channel} seq ${r.message.seq}${r.message.reply_to_seq ? ` (reply to #${r.message.reply_to_seq})` : ""}${r.message.mentions.length ? ` (mentions ${r.message.mentions.length})` : ""}${hint}`, r);
|
|
213
235
|
}
|
|
214
236
|
export async function read(p, out) {
|
|
215
237
|
const channel = p.positionals[1];
|
|
@@ -355,7 +377,7 @@ export async function skill(p, out) {
|
|
|
355
377
|
return;
|
|
356
378
|
}
|
|
357
379
|
if (sub === "install") {
|
|
358
|
-
const dir = str(p.flags, "dir") ?? join(process.cwd(), ".claude", "skills", "
|
|
380
|
+
const dir = str(p.flags, "dir") ?? join(process.cwd(), ".claude", "skills", "b9s");
|
|
359
381
|
const main = await fetchText("/skill/SKILL.md");
|
|
360
382
|
const api = await fetchText("/skill/references/api.md");
|
|
361
383
|
const watchers = await fetchText("/skill/references/watchers.md");
|
|
@@ -367,6 +389,8 @@ export async function skill(p, out) {
|
|
|
367
389
|
writeFileSync(join(dir, "references", "watchers.md"), watchers);
|
|
368
390
|
writeFileSync(join(dir, "references", "process.md"), processGuide);
|
|
369
391
|
writeFileSync(join(dir, "references", "continuity.md"), continuity);
|
|
392
|
+
if (resolve(dir) === resolve(process.cwd(), ".claude", "skills", "b9s"))
|
|
393
|
+
rmSync(join(process.cwd(), ".claude", "skills", "bschat"), { recursive: true, force: true });
|
|
370
394
|
out.print(`Installed skill to ${dir}`, { dir });
|
|
371
395
|
return;
|
|
372
396
|
}
|
|
@@ -405,7 +429,7 @@ export function formatActivityEvent(e, accountWide) {
|
|
|
405
429
|
const first = String(e.summary.body ?? "").split("\n").find((l) => l.trim()) ?? "";
|
|
406
430
|
return `${pfx}${e.summary.scope} summary ${String(e.summary.period_start).slice(11, 16)} to ${String(e.summary.period_end).slice(11, 16)} UTC: ${first.slice(0, 200)}`;
|
|
407
431
|
}
|
|
408
|
-
default: return `${pfx}${e.kind} event (this CLI version does not know this kind;
|
|
432
|
+
default: return `${pfx}${e.kind} event (this CLI version does not know this kind; b9s activity --json shows the full record, and a newer CLI may format it)`;
|
|
409
433
|
}
|
|
410
434
|
}
|
|
411
435
|
/** The feed: activity collapsed into stories (units, chat runs, status runs, evidence runs, steward summaries). */
|
|
@@ -3,8 +3,8 @@ import { agentRef, loadAgent, resolveAgentName } from "../config.js";
|
|
|
3
3
|
import { bindConversation, syncFromWatchers } from "../sessions.js";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* b9s antigravity bind <conversation-id> [--as <agent>] this Antigravity conversation is you: its hook delivers to you
|
|
7
|
+
* b9s antigravity sync bind every conversation an installed watcher wakes
|
|
8
8
|
*/
|
|
9
9
|
export async function antigravity(p, out) {
|
|
10
10
|
const sub = p.positionals[1];
|
|
@@ -8,7 +8,7 @@ import { CliError } from "../errors.js";
|
|
|
8
8
|
import { requireInstall } from "../install.js";
|
|
9
9
|
import { bindSession, codexArchivedRollout, codexRollout } from "../sessions.js";
|
|
10
10
|
import { codexHooksPath } from "./codex.js";
|
|
11
|
-
import {
|
|
11
|
+
import { isCodexManagedRequirements } from "../harness.js";
|
|
12
12
|
import { readState, writeState } from "../state.js";
|
|
13
13
|
import { join } from "./join.js";
|
|
14
14
|
import { installWatcherService } from "./watch.js";
|
|
@@ -16,14 +16,14 @@ import { randomUUID } from "node:crypto";
|
|
|
16
16
|
import { HARNESS_BIN, HARNESS_LABEL, claudeResultError, claudeResultFile, claudeSettings, claudeTranscript } from "../harnesses.js";
|
|
17
17
|
const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
|
|
18
18
|
/**
|
|
19
|
-
* `
|
|
19
|
+
* `b9s start` (and `b9s codex start`): one command that brings an agent up on this machine
|
|
20
20
|
* headless, with no app involved, so it works the same over ssh on a remote machine. It enrolls the
|
|
21
21
|
* agent (with an invite token), starts its session with an onboarding turn, binds it so the hooks
|
|
22
22
|
* deliver to it, and installs a turn-mode watcher that runs each later turn itself (Codex: `codex exec
|
|
23
23
|
* resume`; Claude Code: `claude -p --resume`). `--thread` adopts an existing session instead. Learned
|
|
24
24
|
* from the Codex app's queue silently not delivering wake-ups (fabricbios luna-worker, ten hours).
|
|
25
25
|
*
|
|
26
|
-
*
|
|
26
|
+
* b9s start --harness codex|claude-code --as <name> --sandbox <mode> [--token bs_enroll_...]
|
|
27
27
|
* [--thread <id>] [--model m] [--effort e] [--turn-timeout 180] [--interval 30] [--prune]
|
|
28
28
|
*/
|
|
29
29
|
export async function codexStart(p, out) {
|
|
@@ -51,7 +51,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
51
51
|
const model = str(p.flags, "model");
|
|
52
52
|
const effort = str(p.flags, "effort");
|
|
53
53
|
const adopt = str(p.flags, "thread") ?? str(p.flags, "session");
|
|
54
|
-
// The machine's toolchain and job folders a sandboxed agent may also write (
|
|
54
|
+
// The machine's toolchain and job folders a sandboxed agent may also write (b9s-admin machine writable).
|
|
55
55
|
const writable = (str(p.flags, "writable") ?? "").split(",").map((w) => w.trim()).filter(Boolean).map((w) => (w.startsWith("~/") ? joinPath(homedir(), w.slice(2)) : w));
|
|
56
56
|
if (writable.some((w) => !w.startsWith("/")))
|
|
57
57
|
throw new CliError("usage", "--writable takes absolute or ~/ paths, comma separated");
|
|
@@ -92,14 +92,14 @@ export async function harnessStart(p, out, harness) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
|
-
const logDir = joinPath(
|
|
95
|
+
const logDir = joinPath(configRoot(), "logs");
|
|
96
96
|
mkdirSync(logDir, { recursive: true });
|
|
97
97
|
firstTurnLog = joinPath(logDir, `${harness}.${ref.replace("/", ".")}.first-turn.${harness === "codex" ? "jsonl" : "json"}`);
|
|
98
98
|
const prompt = [
|
|
99
|
-
`[
|
|
99
|
+
`[b9s] You are ${ref}, a BenignSwarm agent, started headless by \`b9s ${cmd}\`; nobody is typing to you.`,
|
|
100
100
|
`Your watcher starts a turn for you whenever something needs you, so end your turn when nothing is left to do.`,
|
|
101
|
-
`Now: run \`
|
|
102
|
-
`If you ran on another machine before, read your latest note first: \`
|
|
101
|
+
`Now: run \`b9s me\`, \`b9s process\` and \`b9s inbox --unread\`, then do what your role and inbox ask.`,
|
|
102
|
+
`If you ran on another machine before, read your latest note first: \`b9s handoffs --agent ${creds.agent}\` (your units, branches and chat are on the server as before).`,
|
|
103
103
|
].join("\n");
|
|
104
104
|
if (harness === "codex") {
|
|
105
105
|
session = await startThread(bin, ["exec", "--json", ...settings, prompt], firstTurnLog, ref);
|
|
@@ -139,17 +139,17 @@ export async function harnessStart(p, out, harness) {
|
|
|
139
139
|
// 5. Hooks.
|
|
140
140
|
let missing = [];
|
|
141
141
|
if (harness === "codex") {
|
|
142
|
-
// A headless turn cannot show Codex's trust prompt, and
|
|
142
|
+
// A headless turn cannot show Codex's trust prompt, and b9s never pre-approves it.
|
|
143
143
|
missing = untrustedHooks();
|
|
144
144
|
lines.push(missing.length
|
|
145
|
-
? `Codex has not trusted
|
|
146
|
-
: `Codex has trust entries for
|
|
145
|
+
? `Codex has not trusted b9s's hooks (${missing.join(", ")}) on this machine, so turns run without them: no standing rules at session start, no continuing when work arrives mid-turn. Wake-ups still work. To trust them, run \`codex\` once in a terminal here and approve the hooks when it asks.`
|
|
146
|
+
: `Codex has trust entries for b9s's hooks here. If they changed since they were trusted, Codex skips them until approved again in an interactive \`codex\`.`);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
149
|
-
lines.push(`Claude Code runs
|
|
149
|
+
lines.push(`Claude Code runs b9s's hooks from this checkout's .claude/settings.local.json (written by join).`);
|
|
150
150
|
}
|
|
151
|
-
lines.push(`Follow it: tail -f ~/.
|
|
152
|
-
lines.push(`If the ${label} account hits its usage limit, the watcher pauses turns until the time ${label} gives; after switching to an account with quota, resume at once:
|
|
151
|
+
lines.push(`Follow it: tail -f ~/.b9s/logs/watch.${ref.replace("/", ".")}.err.log; ${harness === "codex" ? `read its thread with codex resume ${session}` : `read its transcript under ~/.claude/projects (session ${session})`} only while no turn is running.`);
|
|
152
|
+
lines.push(`If the ${label} account hits its usage limit, the watcher pauses turns until the time ${label} gives; after switching to an account with quota, resume at once: b9s unpause --as ${ref}`);
|
|
153
153
|
out.print(lines.join("\n"), { agent: ref, harness, thread: session, session, sandbox, model: model ?? null, effort: effort ?? null, exec, first_turn_log: firstTurnLog, untrusted_hooks: missing });
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
@@ -179,7 +179,7 @@ async function startClaudeSession(bin, args, logPath, agent, session) {
|
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* The Codex settings a headless turn runs with. Under workspace-write the agent still has to reach
|
|
182
|
-
* the API and write its own
|
|
182
|
+
* the API and write its own b9s state (~/.b9s), and `wu start` puts unit worktrees beside the
|
|
183
183
|
* checkout, so those two places are writable and the network is on; nothing else is.
|
|
184
184
|
*/
|
|
185
185
|
export function codexSettings(sandbox, model, effort, cwd, bschatHome, extraWritable = []) {
|
|
@@ -247,10 +247,10 @@ export function threadFromExecJson(text) {
|
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
249
249
|
* bschat's hook events with no trust entry in Codex's config.toml (`[hooks.state."<hooks.json>:<event>:0:0"]`),
|
|
250
|
-
* or none when they are in Codex's administrator layer (
|
|
250
|
+
* or none when they are in Codex's administrator layer (b9s-admin machine add), trusted by policy.
|
|
251
251
|
*/
|
|
252
252
|
export function untrustedHooks(configText = readCodexConfig(), hooksPath = codexHooksPath(), requirements = readRequirements()) {
|
|
253
|
-
if (requirements
|
|
253
|
+
if (isCodexManagedRequirements(requirements))
|
|
254
254
|
return [];
|
|
255
255
|
return ["session_start", "user_prompt_submit", "post_tool_use", "stop"].filter((e) => !configText.includes(`[hooks.state."${hooksPath}:${e}:0:0"]`));
|
|
256
256
|
}
|
package/dist/commands/codex.js
CHANGED
|
@@ -10,11 +10,11 @@ import { bindSession, syncFromWatchers } from "../sessions.js";
|
|
|
10
10
|
import { codexStart } from "./codex-start.js";
|
|
11
11
|
import { readState, writeState } from "../state.js";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* b9s codex hooks install b9s's hooks in ~/.codex/hooks.json (this machine's Codex)
|
|
14
|
+
* b9s codex bind <thread-id> [--as a] this Codex thread is you: its hooks deliver to you
|
|
15
|
+
* b9s codex sync bind every thread an installed watcher wakes
|
|
16
|
+
* b9s codex start --as a --sandbox m run the agent headless: enroll, start or adopt its thread, turn-mode watcher
|
|
17
|
+
* b9s codex unpause [--as a] lift a usage-limit pause now (Codex switched to an account with quota)
|
|
18
18
|
*/
|
|
19
19
|
export async function codex(p, out) {
|
|
20
20
|
const sub = p.positionals[1];
|
|
@@ -32,7 +32,7 @@ export async function codex(p, out) {
|
|
|
32
32
|
mkdirSync(dirname(path), { recursive: true });
|
|
33
33
|
writeFileSync(path, JSON.stringify(withCodexHooks(doc, requireInstall().bin), null, 2) + "\n");
|
|
34
34
|
const bound = syncFromWatchers().filter((b) => b.kind === "codex");
|
|
35
|
-
out.print(`Wrote
|
|
35
|
+
out.print(`Wrote b9s's hooks to ${path} (SessionStart, UserPromptSubmit, PostToolUse, Stop).\nCodex asks you to trust new hooks the next time a session starts: approve them there.\nThreads bound from watchers: ${bound.length ? bound.map((b) => `${b.conversation} -> ${b.agent}`).join(", ") : "none"}. Any other Codex session gets nothing from them.`, { path, bound });
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
if (sub === "bind") {
|