benignswarm 0.12.88 → 0.12.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.js +3 -3
- package/dist/brief.js +7 -2
- package/dist/commands/admin.js +22 -4
- package/dist/commands/codex-start.js +14 -6
- package/dist/commands/machine-admin.js +24 -14
- package/dist/commands/machine.js +30 -7
- package/dist/commands/watch.js +19 -7
- package/dist/commands/wu.js +89 -19
- package/dist/git.js +19 -0
- package/dist/help.js +22 -13
- package/dist/providers.js +84 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -2,9 +2,9 @@ import { parseArgs } from "node:util";
|
|
|
2
2
|
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
|
-
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", "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", "dsh", "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"];
|
|
5
|
+
export const LIST_FLAGS = ["tags", "projects", "evidence", "statuses", "depends-on", "default-tags", "units", "waits-on", "needs", "exclude", "remove", "post", "harness", "variant", "requires", "reworks"];
|
|
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", "assign-outside-qualifications", "machine", "dir", "confirm", "type", "name", "out", "token", "prefix", "uses", "expires-hours", "skill-dir", "harness", "provider", "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", "dsh", "for", "until", "reason", "at", "requires", "priority", "informs", "amend", "waive-informs", "text", "kind", "claim", "decision", "sha", "value", "expect", "expectations", "reworks"];
|
|
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", "no-source"];
|
|
8
8
|
export function parse(argv) {
|
|
9
9
|
const options = {};
|
|
10
10
|
for (const f of STRING_FLAGS)
|
package/dist/brief.js
CHANGED
|
@@ -38,15 +38,20 @@ export async function fetchRecoveryBrief(nameOrRef) {
|
|
|
38
38
|
return { ...response.brief, notices: active.notices };
|
|
39
39
|
}
|
|
40
40
|
export function formatRecoveryBrief(brief) {
|
|
41
|
+
const scope = (base, amendments, omitted = 0) => [
|
|
42
|
+
...(base ? [`\n base scope: ${base}`] : []),
|
|
43
|
+
...(amendments ?? []).map((amendment) => `\n amendment ${amendment.at} ${amendment.author}: ${amendment.text}`),
|
|
44
|
+
...(omitted ? [`\n ${omitted} older scope amendments omitted`] : []),
|
|
45
|
+
].join("");
|
|
41
46
|
const lines = [`[b9s] Resume brief for ${brief.agent}`, `Role: ${brief.role}`];
|
|
42
47
|
if (brief.projects.length)
|
|
43
48
|
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
49
|
lines.push("Questions waiting on you:");
|
|
45
50
|
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"]));
|
|
46
51
|
lines.push("Units:");
|
|
47
|
-
lines.push(...(brief.units.length ? brief.units.map((u) => ` [${u.state}] ${u.project} WU #${u.number} ${u.title} — ${u.next}`) : [" none"]));
|
|
52
|
+
lines.push(...(brief.units.length ? brief.units.map((u) => ` [${u.state}] ${u.project} WU #${u.number} ${u.title}${scope(u.base_scope, u.scope_amendments, u.scope_amendments_omitted)} — ${u.next}`) : [" none"]));
|
|
48
53
|
lines.push("Reviews waiting on you:");
|
|
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"]));
|
|
54
|
+
lines.push(...(brief.reviews.length ? brief.reviews.map((r) => ` ${r.project} ${r.slice ? `slice ${r.slice}` : `WU #${r.number}`} ${r.title}${scope(r.base_scope, r.scope_amendments, r.scope_amendments_omitted)} — ${r.next}`) : [" none"]));
|
|
50
55
|
lines.push("Open asks:");
|
|
51
56
|
lines.push(...(brief.asks.length ? brief.asks.slice(0, 10).map((a) => ` ${a.project} ask ${a.id}: ${a.question} (${a.blocks}) — ${a.next}`) : [" none"]));
|
|
52
57
|
lines.push("Slices:");
|
package/dist/commands/admin.js
CHANGED
|
@@ -68,6 +68,8 @@ export async function admin(p, out) {
|
|
|
68
68
|
return agent(action, rest, p, out);
|
|
69
69
|
case "role":
|
|
70
70
|
return role(action, rest, p, out);
|
|
71
|
+
case "wu":
|
|
72
|
+
return workUnitAdmin(action, rest, p, out);
|
|
71
73
|
case "channel":
|
|
72
74
|
return channel(action, rest, p, out);
|
|
73
75
|
case "enroll":
|
|
@@ -278,8 +280,8 @@ async function role(action, rest, p, out) {
|
|
|
278
280
|
const base = proj ? `/projects/${proj}/roles` : "/roles";
|
|
279
281
|
if (action === "list") {
|
|
280
282
|
const r = await c.call("GET", base);
|
|
281
|
-
const rows = r.roles.map((x) => ({ name: x.name, scope: x.project_id ? "project" : "account", reviews: (x.reviews ?? []).join(",") || "-", works: (x.works ?? []).join(",") || "-", trials: (x.trials ?? []).join(",") || "-", cardinality: x.cardinality, projects: x.project_id ? "(own)" : (x.permissions.projects ?? []).join(",") || "(none)", post: x.permissions.post_channels.join(","), broadcast: x.permissions.broadcast, create_channels: x.permissions.create_channels, read_account_status: x.permissions.read_account_status }));
|
|
282
|
-
out.print(table(rows, ["name", "scope", "reviews", "works", "trials", "cardinality", "projects", "post", "broadcast", "create_channels", "read_account_status"]), r);
|
|
283
|
+
const rows = r.roles.map((x) => ({ name: x.name, scope: x.project_id ? "project" : "account", reviews: (x.reviews ?? []).join(",") || "-", works: (x.works ?? []).join(",") || "-", trials: (x.trials ?? []).join(",") || "-", assign_outside_qualifications: !!x.assign_outside_qualifications, cardinality: x.cardinality, projects: x.project_id ? "(own)" : (x.permissions.projects ?? []).join(",") || "(none)", post: x.permissions.post_channels.join(","), broadcast: x.permissions.broadcast, create_channels: x.permissions.create_channels, read_account_status: x.permissions.read_account_status }));
|
|
284
|
+
out.print(table(rows, ["name", "scope", "reviews", "works", "trials", "assign_outside_qualifications", "cardinality", "projects", "post", "broadcast", "create_channels", "read_account_status"]), r);
|
|
283
285
|
}
|
|
284
286
|
else if (action === "create" && rest[0]) {
|
|
285
287
|
const permissions = permsFromFlags(p, !!proj) ?? { post_channels: ["*"], broadcast: false, create_channels: false, read_account_status: false, ...(proj ? {} : { projects: [] }) };
|
|
@@ -294,6 +296,12 @@ async function role(action, rest, p, out) {
|
|
|
294
296
|
const card = str(p.flags, "cardinality");
|
|
295
297
|
if (card !== undefined)
|
|
296
298
|
body.cardinality = card;
|
|
299
|
+
const assignOutside = str(p.flags, "assign-outside-qualifications");
|
|
300
|
+
if (assignOutside !== undefined) {
|
|
301
|
+
if (assignOutside !== "yes" && assignOutside !== "no")
|
|
302
|
+
throw new CliError("usage", "--assign-outside-qualifications must be yes or no");
|
|
303
|
+
body.assign_outside_qualifications = assignOutside === "yes";
|
|
304
|
+
}
|
|
297
305
|
const permissions = permsFromFlags(p, !!proj);
|
|
298
306
|
if (permissions)
|
|
299
307
|
body.permissions = permissions;
|
|
@@ -303,7 +311,7 @@ async function role(action, rest, p, out) {
|
|
|
303
311
|
body[q] = v;
|
|
304
312
|
}
|
|
305
313
|
if (!Object.keys(body).length)
|
|
306
|
-
throw new CliError("usage", "role edit needs --description, --cardinality, --projects, --post, --broadcast, --create-channels, --read-account-status, --permissions, --reviews, --works or --trials");
|
|
314
|
+
throw new CliError("usage", "role edit needs --description, --cardinality, --assign-outside-qualifications yes|no, --projects, --post, --broadcast, --create-channels, --read-account-status, --permissions, --reviews, --works or --trials");
|
|
307
315
|
const r = await c.call("PATCH", `${base}/${rest[0]}`, body);
|
|
308
316
|
out.print(`updated role ${r.role.name}: reviews=${(r.role.reviews ?? []).join(",") || "-"} works=${(r.role.works ?? []).join(",") || "-"} trials=${(r.role.trials ?? []).join(",") || "-"} projects=${r.role.permissions.projects.join(",") || "(none)"} post=${r.role.permissions.post_channels.join(",")} broadcast=${r.role.permissions.broadcast}`, r);
|
|
309
317
|
}
|
|
@@ -312,7 +320,17 @@ async function role(action, rest, p, out) {
|
|
|
312
320
|
out.print(`deleted role ${rest[0]}`, r);
|
|
313
321
|
}
|
|
314
322
|
else
|
|
315
|
-
throw new CliError("usage", "admin role create|edit|list|delete <name> [--project p] [--projects a,b|*] [--post ch1,ch2] [--broadcast] [--create-channels] [--read-account-status] [--description d] [--cardinality one|many]");
|
|
323
|
+
throw new CliError("usage", "admin role create|edit|list|delete <name> [--project p] [--projects a,b|*] [--post ch1,ch2] [--broadcast] [--create-channels] [--read-account-status] [--assign-outside-qualifications yes|no] [--description d] [--cardinality one|many]");
|
|
324
|
+
}
|
|
325
|
+
async function workUnitAdmin(action, rest, p, out) {
|
|
326
|
+
if (action !== "assign" || !rest[0] || !/^\d+$/.test(rest[1] ?? ""))
|
|
327
|
+
throw new CliError("usage", 'b9s-admin wu assign <project> <n> --to <agent> [--reason "why"]');
|
|
328
|
+
const to = str(p.flags, "to");
|
|
329
|
+
if (!to)
|
|
330
|
+
throw new CliError("usage", 'b9s-admin wu assign <project> <n> --to <agent> [--reason "why"]');
|
|
331
|
+
const reason = str(p.flags, "reason");
|
|
332
|
+
const r = await adminClient(p).call("POST", `/projects/${rest[0]}/work-units/${Number(rest[1])}/assign`, { to, ...(reason === undefined ? {} : { reason }) });
|
|
333
|
+
out.print(`WU #${r.unit.number} reassigned to ${r.unit.owner_name || r.unit.preferred_name}${r.unit.status === "queued" ? "; queued until they are free" : ""}.`, r);
|
|
316
334
|
}
|
|
317
335
|
async function channel(action, rest, p, out) {
|
|
318
336
|
const c = adminClient(p);
|
|
@@ -14,6 +14,7 @@ import { join } from "./join.js";
|
|
|
14
14
|
import { installWatcherService } from "./watch.js";
|
|
15
15
|
import { randomUUID } from "node:crypto";
|
|
16
16
|
import { HARNESS_BIN, HARNESS_LABEL, claudeResultError, claudeResultFile, claudeSettings, claudeTranscript, dshPath, dshResultError, dshSessionFromEvents, dshSettings, dshTurnLog } from "../harnesses.js";
|
|
17
|
+
import { claudeTurnEnv } from "../providers.js";
|
|
17
18
|
const SANDBOXES = ["read-only", "workspace-write", "danger-full-access"];
|
|
18
19
|
/**
|
|
19
20
|
* `b9s start` (and `b9s codex start`): one command that brings an agent up on this machine
|
|
@@ -50,6 +51,13 @@ export async function harnessStart(p, out, harness) {
|
|
|
50
51
|
const dshOverride = str(p.flags, "dsh");
|
|
51
52
|
if (harness !== "dsh" && dshOverride)
|
|
52
53
|
throw new CliError("usage", "--dsh is only valid with --harness dsh");
|
|
54
|
+
const providerName = str(p.flags, "provider") ?? "anthropic";
|
|
55
|
+
if (providerName !== "anthropic" && providerName !== "deepseek")
|
|
56
|
+
throw new CliError("usage", "--provider must be anthropic or deepseek");
|
|
57
|
+
const provider = providerName;
|
|
58
|
+
if (provider === "deepseek" && harness !== "claude-code")
|
|
59
|
+
throw new CliError("usage", "--provider deepseek requires --harness claude-code");
|
|
60
|
+
const model = str(p.flags, "model") ?? (provider === "deepseek" ? "deepseek-flash" : undefined);
|
|
53
61
|
const bin = harness === "dsh"
|
|
54
62
|
? dshPath(dshOverride)
|
|
55
63
|
: which(HARNESS_BIN[harness], harness === "codex" ? "install the Codex CLI (npm i -g @openai/codex)" : "install Claude Code (npm i -g @anthropic-ai/claude-code)");
|
|
@@ -57,7 +65,6 @@ export async function harnessStart(p, out, harness) {
|
|
|
57
65
|
throw new CliError("not_found", "DeepSeek Harness CLI dsh was not found; install DeepSeek Harness or pass --dsh <path>");
|
|
58
66
|
if (harness === "dsh" && !existsSync(bin))
|
|
59
67
|
throw new CliError("not_found", `DeepSeek Harness CLI ${bin} does not exist; pass --dsh <path> to its runtime/cli/bin/dsh`);
|
|
60
|
-
const model = str(p.flags, "model");
|
|
61
68
|
const effort = str(p.flags, "effort");
|
|
62
69
|
const adopt = str(p.flags, "thread") ?? str(p.flags, "session");
|
|
63
70
|
// The machine's toolchain and job folders a sandboxed agent may also write (b9s-admin machine writable).
|
|
@@ -70,6 +77,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
70
77
|
: harness === "dsh"
|
|
71
78
|
? dshSettings(sandbox, process.cwd(), configRoot(), [...writable, ...ownWorktreeGitDir(process.cwd())])
|
|
72
79
|
: claudeSettings(sandbox, model, effort, process.cwd(), configRoot(), writable);
|
|
80
|
+
const providerEnv = claudeTurnEnv(harness === "claude-code" ? provider : undefined, model);
|
|
73
81
|
// 1. Who: enroll with the invite token, or use credentials already on this machine.
|
|
74
82
|
const lines = [];
|
|
75
83
|
const token = str(p.flags, "token");
|
|
@@ -135,7 +143,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
135
143
|
else {
|
|
136
144
|
// Claude Code takes the session id from us, so nothing has to be read back from its output.
|
|
137
145
|
session = randomUUID();
|
|
138
|
-
await startClaudeSession(bin, ["-p", prompt, ...settings, "--session-id", session, "--output-format", "json"], firstTurnLog, ref, session);
|
|
146
|
+
await startClaudeSession(bin, ["-p", prompt, ...settings, "--session-id", session, "--output-format", "json"], firstTurnLog, ref, session, providerEnv);
|
|
139
147
|
lines.push(`Started Claude Code session ${session}; its first turn (reading its role and inbox) is running, result: ${firstTurnLog}`);
|
|
140
148
|
}
|
|
141
149
|
}
|
|
@@ -164,7 +172,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
164
172
|
// volume had 750 GB free, and which empties /tmp at every boot.
|
|
165
173
|
const tmp = sessionTmpDir(process.cwd(), creds.agent);
|
|
166
174
|
mkdirSync(tmp, { recursive: true });
|
|
167
|
-
installWatcherService(ref, exec, interval, Number(str(p.flags, "follow-delay") ?? "300"), { TMPDIR: tmp }, undefined, { json: false, print: (h) => watcherOut.push(h) }, bool(p.flags, "prune"), { harness, session, timeout: turnTimeout });
|
|
175
|
+
installWatcherService(ref, exec, interval, Number(str(p.flags, "follow-delay") ?? "300"), { TMPDIR: tmp }, undefined, { json: false, print: (h) => watcherOut.push(h) }, bool(p.flags, "prune"), { harness, session, timeout: turnTimeout, provider, model });
|
|
168
176
|
const wl = watcherOut.join("\n").split("\n");
|
|
169
177
|
lines.push(wl[0].replace(/^Wrote /, "Watcher: wrote "), ...wl.filter((l) => l.startsWith("Linger is off")));
|
|
170
178
|
// 5. Hooks.
|
|
@@ -186,7 +194,7 @@ export async function harnessStart(p, out, harness) {
|
|
|
186
194
|
lines.push(harness === "dsh"
|
|
187
195
|
? `DeepSeek Harness failures, including balance or rate limits, are recorded and retried after the ordinary 5-minute backoff; no reset time is inferred from their text.`
|
|
188
196
|
: `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}`);
|
|
189
|
-
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 });
|
|
197
|
+
out.print(lines.join("\n"), { agent: ref, harness, provider, thread: session, session, sandbox, model: model ?? null, effort: effort ?? null, exec, first_turn_log: firstTurnLog, untrusted_hooks: missing });
|
|
190
198
|
}
|
|
191
199
|
export const dshStartArgs = (settings) => ["--profile", "headless", "--json", ...settings, "-"];
|
|
192
200
|
export const dshResumeArgs = (session, settings) => ["--profile", "headless", "--json", "--session-id", session, ...settings, "-"];
|
|
@@ -232,9 +240,9 @@ export async function startDshSession(bin, args, logPath, agent, prompt) {
|
|
|
232
240
|
* minutes; this command does not wait for it) and returns once its transcript exists, or fails
|
|
233
241
|
* with Claude Code's own error when it exits first.
|
|
234
242
|
*/
|
|
235
|
-
async function startClaudeSession(bin, args, logPath, agent, session) {
|
|
243
|
+
async function startClaudeSession(bin, args, logPath, agent, session, providerEnv) {
|
|
236
244
|
const fd = openSync(logPath, "w");
|
|
237
|
-
const child = spawn(bin, args, { stdio: ["ignore", fd, fd], detached: true, cwd: process.cwd(), env: { ...process.env, BSCHAT_AGENT: agent } });
|
|
245
|
+
const child = spawn(bin, args, { stdio: ["ignore", fd, fd], detached: true, cwd: process.cwd(), env: { ...process.env, BSCHAT_AGENT: agent, ...providerEnv } });
|
|
238
246
|
closeSync(fd);
|
|
239
247
|
let exited = null;
|
|
240
248
|
child.on("exit", (code) => { exited = code ?? 1; });
|
|
@@ -132,8 +132,10 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
132
132
|
`${m.name}: last report ${m.last_report_at ?? "never"}; labels ${(m.labels ?? []).join(", ") || "(none)"}; slots ${m.slots ?? "auto"}; writable ${(m.writable ?? []).join(", ") || "-"}; workdir ${rep.workdir ?? m.workdir ?? "~/bschat"}${rep.workdir_free_bytes ? ` (${Math.round(rep.workdir_free_bytes / 1e9)} GB free)` : ""}`,
|
|
133
133
|
rep.os ? ` ${rep.os}/${rep.arch} ${rep.hostname} as ${rep.user}; ${rep.cpus ?? "?"} CPUs, ${rep.mem_total_bytes ? `${Math.round(rep.mem_total_bytes / 1024 ** 3)} GB RAM` : "? RAM"}; b9s ${rep.bschat?.version}; codex ${rep.codex ? `${rep.codex.version}, ${rep.codex.logged_in ? "logged in" : "NOT logged in"}, sandbox ${rep.codex.sandbox ? (rep.codex.sandbox.ok ? "ok" : `FAILS (${rep.codex.sandbox.error})`) : "?"}` : "missing"}; hooks ${rep.managed_hooks ? "managed by policy" : "user-level"}; linger ${rep.linger ?? "n/a"}; disk free ${rep.disk_free_bytes ? `${Math.round(rep.disk_free_bytes / 1e9)} GB` : "?"}` : " (no report yet: is its daemon running?)",
|
|
134
134
|
];
|
|
135
|
-
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", thread: s.thread ?? "-", sandbox: s.sandbox, model: s.model ?? "-", dir: s.dir || s.reported?.dir || "(auto)", error: s.reported?.error ?? s.reported?.detail ?? "", last_turn: (s.reported?.last_turn ?? "").replace(/^\S+ b9s watch\[[^\]]+\]: /, "") }));
|
|
136
|
-
|
|
135
|
+
const rows = m.sessions.map((s) => ({ agent: s.agent, pool: s.pool ?? "-", desired: s.desired, state: s.reported?.state ?? "-", thread: s.thread ?? "-", harness: s.harness, provider: s.provider ?? "anthropic", sandbox: s.sandbox, model: s.model ?? "-", dir: s.dir || s.reported?.dir || "(auto)", error: s.reported?.error ?? s.reported?.detail ?? "", last_turn: (s.reported?.last_turn ?? "").replace(/^\S+ b9s watch\[[^\]]+\]: /, "") }));
|
|
136
|
+
const providers = rep.claude_code?.providers ?? {};
|
|
137
|
+
const providerLines = Object.entries(providers).map(([provider, check]) => ` Claude Code ${provider}: ${check.logged_in ? "verified" : `NOT verified (${check.reason ?? "unknown reason"})`}`);
|
|
138
|
+
return out.print([...head, ...providerLines, rows.length ? table(rows, ["agent", "pool", "desired", "state", "thread", "harness", "provider", "sandbox", "model", "dir", "error", "last_turn"]) : " no sessions"].join("\n"), r);
|
|
137
139
|
}
|
|
138
140
|
if (action === "maintenance") {
|
|
139
141
|
// A window on the machine: no new turns from 15 min before, its agents away until it ends.
|
|
@@ -197,13 +199,13 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
197
199
|
if (sub === "add") {
|
|
198
200
|
const turnTimeout = str(p.flags, "turn-timeout");
|
|
199
201
|
const body = {
|
|
200
|
-
project, agent, harness: str(p.flags, "harness") ?? "codex", dir: str(p.flags, "dir"), sandbox: str(p.flags, "sandbox"),
|
|
202
|
+
project, agent, harness: str(p.flags, "harness") ?? "codex", provider: str(p.flags, "provider") ?? "anthropic", dir: str(p.flags, "dir"), sandbox: str(p.flags, "sandbox"),
|
|
201
203
|
model: str(p.flags, "model"), effort: str(p.flags, "effort"), thread: str(p.flags, "thread"),
|
|
202
204
|
...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
|
|
203
205
|
create: bool(p.flags, "create"), role: str(p.flags, "role"),
|
|
204
206
|
};
|
|
205
207
|
const r = await c.call("POST", `/machines/${machineName}/sessions`, body);
|
|
206
|
-
return out.print(`Declared ${r.session.agent} on ${machineName} (${r.session.harness}, ${r.session.sandbox}, ${r.session.dir}). Its daemon starts it within 30 s: b9s-admin machine show ${machineName}`, r);
|
|
208
|
+
return out.print(`Declared ${r.session.agent} on ${machineName} (${r.session.harness}/${r.session.provider}, ${r.session.sandbox}, ${r.session.dir}). Its daemon starts it within 30 s: b9s-admin machine show ${machineName}`, r);
|
|
207
209
|
}
|
|
208
210
|
if (sub === "stop" || sub === "start") {
|
|
209
211
|
const r = await c.call("PATCH", `/machines/${machineName}/sessions/${project}/${agent}`, { desired: sub === "stop" ? "stopped" : "running" });
|
|
@@ -216,12 +218,14 @@ export async function machineAdmin(action, rest, p, out) {
|
|
|
216
218
|
}
|
|
217
219
|
throw new CliError("usage", "machine add <name> --ssh <host> | list | show <name> | remove <name> | session add|stop|start|remove <machine> <project>/<agent>");
|
|
218
220
|
}
|
|
219
|
-
/** `[tag=]harness:model[:effort][*weight]`, e.g. `luna=
|
|
221
|
+
/** `[tag=]harness:model[:effort][*weight][@provider]`, e.g. `luna=claude-code:deepseek-flash@deepseek`. */
|
|
220
222
|
export function parseVariant(spec) {
|
|
221
|
-
const m = /^(?:([a-z0-9][a-z0-9-]*)=)?([a-z0-9-]+)(?::([
|
|
223
|
+
const m = /^(?:([a-z0-9][a-z0-9-]*)=)?([a-z0-9-]+)(?::([^:*@]+))?(?::([^:*@]+))?(?:\*(\d+))?(?:@(anthropic|deepseek))?$/.exec(spec.trim());
|
|
222
224
|
if (!m)
|
|
223
|
-
throw new CliError("usage", `--variant ${spec}: expected [tag=]harness:model[:effort][*weight], e.g. luna=
|
|
224
|
-
|
|
225
|
+
throw new CliError("usage", `--variant ${spec}: expected [tag=]harness:model[:effort][*weight][@provider], e.g. luna=claude-code:deepseek-flash@deepseek`);
|
|
226
|
+
if (m[6] === "deepseek" && m[2] !== "claude-code")
|
|
227
|
+
throw new CliError("usage", "@deepseek requires the claude-code harness");
|
|
228
|
+
return { ...(m[1] ? { tag: m[1] } : {}), harness: m[2], ...(m[3] ? { model: m[3] } : {}), ...(m[4] ? { effort: m[4] } : {}), ...(m[5] ? { weight: Number(m[5]) } : {}), ...(m[6] ? { provider: m[6] } : {}) };
|
|
225
229
|
}
|
|
226
230
|
/** Every value of a repeatable flag (the parser keeps the last; read them from argv). */
|
|
227
231
|
export function repeated(argv, flag) {
|
|
@@ -241,7 +245,7 @@ export function repeated(argv, flag) {
|
|
|
241
245
|
export async function poolAdmin(action, rest, p, out, argv) {
|
|
242
246
|
const c = adminClient(p);
|
|
243
247
|
const statusLines = (pool) => [
|
|
244
|
-
`${pool.project}/${pool.name}: ${pool.count} × role ${pool.role ?? "(none)"}, ${pool.sandbox}; variants ${pool.variants.map((v) => `${v.tag}=${v.harness}:${v.model ?? "default"}${v.effort ? `:${v.effort}` : ""}${v.weight > 1 ? `*${v.weight}` : ""}`).join(", ")}${pool.needs?.labels?.length ? `; needs ${pool.needs.labels.join(", ")}` : ""}${pool.needs?.min_ram_gb ? `; min ${pool.needs.min_ram_gb} GB` : ""}`,
|
|
248
|
+
`${pool.project}/${pool.name}: ${pool.count} × role ${pool.role ?? "(none)"}, ${pool.sandbox}; variants ${pool.variants.map((v) => `${v.tag}=${v.harness}:${v.model ?? "default"}${v.effort ? `:${v.effort}` : ""}${v.weight > 1 ? `*${v.weight}` : ""}${v.provider && v.provider !== "anthropic" ? `@${v.provider}` : ""}`).join(", ")}${pool.needs?.labels?.length ? `; needs ${pool.needs.labels.join(", ")}` : ""}${pool.needs?.min_ram_gb ? `; min ${pool.needs.min_ram_gb} GB` : ""}`,
|
|
245
249
|
...(pool.status?.placed ?? []).map((x) => ` ${x.agent.padEnd(32)} on ${x.machine}`),
|
|
246
250
|
...(pool.status?.unplaced ?? []).map((x) => ` ${x.agent.padEnd(32)} NOT PLACED: ${x.reason}`),
|
|
247
251
|
];
|
|
@@ -250,7 +254,7 @@ export async function poolAdmin(action, rest, p, out, argv) {
|
|
|
250
254
|
const variants = repeated(argv, "variant").map(parseVariant);
|
|
251
255
|
const count = Number(str(p.flags, "count"));
|
|
252
256
|
if (!project || !name || !variants.length || !Number.isInteger(count))
|
|
253
|
-
throw new CliError("usage", "pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight] [--variant ...] --count <n> --sandbox <read-only|workspace-write|danger-full-access> [--needs label,label] [--min-ram GB] [--turn-timeout min]");
|
|
257
|
+
throw new CliError("usage", "pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...] --count <n> --sandbox <read-only|workspace-write|danger-full-access> [--needs label,label] [--min-ram GB] [--turn-timeout min]");
|
|
254
258
|
const needs = { ...(str(p.flags, "needs") ? { labels: str(p.flags, "needs").split(",").map((x) => x.trim()).filter(Boolean) } : {}), ...(str(p.flags, "min-ram") ? { min_ram_gb: Number(str(p.flags, "min-ram")) } : {}) };
|
|
255
259
|
const tt = str(p.flags, "turn-timeout");
|
|
256
260
|
const r = await c.call("PUT", `/projects/${project}/pools/${name}`, { role: str(p.flags, "role") ?? null, variants, count, sandbox: str(p.flags, "sandbox"), needs, ...(tt ? { turn_timeout: Number(tt) } : {}) });
|
|
@@ -340,7 +344,7 @@ function on(host, command, input) {
|
|
|
340
344
|
return ssh(host, command, input);
|
|
341
345
|
}
|
|
342
346
|
/**
|
|
343
|
-
* agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir path|auto] [--model m] [--effort e]
|
|
347
|
+
* agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir path|auto] [--harness codex|claude-code] [--provider anthropic|deepseek] [--model m] [--effort e]
|
|
344
348
|
* [--carry note|thread] [--from local|<ssh host>] [--to-ssh <host>] [--thread id] [--wait min] [--force]
|
|
345
349
|
*
|
|
346
350
|
* The agent (name, role, record, units, chat) is on the server and does not move; its harness
|
|
@@ -354,10 +358,16 @@ export async function agentMove(rest, p, out) {
|
|
|
354
358
|
const [project, agent] = ref.split("/");
|
|
355
359
|
const to = str(p.flags, "to");
|
|
356
360
|
const sandbox = str(p.flags, "sandbox");
|
|
361
|
+
const harness = str(p.flags, "harness") ?? "codex";
|
|
362
|
+
const provider = str(p.flags, "provider") ?? "anthropic";
|
|
357
363
|
const carry = str(p.flags, "carry") ?? "note";
|
|
358
364
|
const from = str(p.flags, "from");
|
|
359
365
|
if (!project || !agent || !to || !sandbox)
|
|
360
|
-
throw new CliError("usage", "agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--carry note|thread] [--from local|<ssh host>] [--model m] [--effort e] [--wait min] [--force]");
|
|
366
|
+
throw new CliError("usage", "agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--harness codex|claude-code] [--provider anthropic|deepseek] [--carry note|thread] [--from local|<ssh host>] [--model m] [--effort e] [--wait min] [--force]");
|
|
367
|
+
if (provider !== "anthropic" && provider !== "deepseek")
|
|
368
|
+
throw new CliError("usage", "--provider must be anthropic or deepseek");
|
|
369
|
+
if (provider === "deepseek" && harness !== "claude-code")
|
|
370
|
+
throw new CliError("usage", "--provider deepseek requires --harness claude-code");
|
|
361
371
|
if (carry !== "note" && carry !== "thread")
|
|
362
372
|
throw new CliError("usage", "--carry note (a resume note it writes now) or thread (its Codex thread, copied)");
|
|
363
373
|
if (carry === "thread" && (str(p.flags, "harness") ?? "codex") !== "codex")
|
|
@@ -465,11 +475,11 @@ export async function agentMove(rest, p, out) {
|
|
|
465
475
|
// 3. The new machine runs it; every other key stops working.
|
|
466
476
|
const turnTimeout = str(p.flags, "turn-timeout");
|
|
467
477
|
const r = await c.call("POST", `/machines/${to}/sessions`, {
|
|
468
|
-
project, agent, move: true, harness
|
|
478
|
+
project, agent, move: true, harness, provider, dir: str(p.flags, "dir") ?? "auto", sandbox,
|
|
469
479
|
model, effort, ...(thread ? { thread } : {}), ...(turnTimeout ? { turn_timeout: Number(turnTimeout) } : {}),
|
|
470
480
|
});
|
|
471
481
|
return out.print([
|
|
472
|
-
`${ref} now runs on ${to} (${r.session.sandbox}, ${r.session.dir || "automatic checkout"}${thread ? `, thread ${thread}` : ", a fresh
|
|
482
|
+
`${ref} now runs on ${to} (${r.session.harness}/${r.session.provider}, ${r.session.sandbox}, ${r.session.dir || "automatic checkout"}${thread ? `, thread ${thread}` : ", a fresh session"}); its daemon starts it within 30 s.`,
|
|
473
483
|
r.moved_from.length ? `Its session on ${r.moved_from.join(", ")} was removed.` : null,
|
|
474
484
|
`${r.revoked_keys} key(s) elsewhere revoked: a watcher left running there stops and removes itself. Archive its old thread in the Codex app so nobody types into that copy.`,
|
|
475
485
|
problems.length ? `Left behind (--force): ${problems.join("; ")}` : null,
|
package/dist/commands/machine.js
CHANGED
|
@@ -15,6 +15,7 @@ import { installService, lingerEnabled, MACHINE_LABEL, machineDaemonPath, remove
|
|
|
15
15
|
import { CLI_VERSION } from "../version.js";
|
|
16
16
|
import { probeCapabilities } from "../capabilities.js";
|
|
17
17
|
import { diskSpaceNotice } from "../notices.js";
|
|
18
|
+
import { verifyClaudeProvider } from "../providers.js";
|
|
18
19
|
export const machineFile = () => join(configRoot(), "machine.json");
|
|
19
20
|
export function loadMachine() {
|
|
20
21
|
const f = machineFile();
|
|
@@ -35,7 +36,7 @@ function writeMachineState(s) {
|
|
|
35
36
|
* 3: turns get TMPDIR beside the checkout instead of the system's /tmp.
|
|
36
37
|
*/
|
|
37
38
|
const START_REV = 3;
|
|
38
|
-
export const sessionFingerprint = (s, writable = []) => JSON.stringify([s.harness, s.dir, s.sandbox, s.model, s.effort, s.turn_timeout, ...(writable.length ? [writable] : []), ...(START_REV > 1 ? [`rev${START_REV}`] : [])]);
|
|
39
|
+
export const sessionFingerprint = (s, writable = []) => JSON.stringify([s.harness, ...(s.provider && s.provider !== "anthropic" ? [s.provider] : []), s.dir, s.sandbox, s.model, s.effort, s.turn_timeout, ...(writable.length ? [writable] : []), ...(START_REV > 1 ? [`rev${START_REV}`] : [])]);
|
|
39
40
|
export const watchLabelOf = (ref) => `${WATCH_LABEL_PREFIX}${ref.replace("/", ".")}`;
|
|
40
41
|
/**
|
|
41
42
|
* During a maintenance drain or window, a session that would be started fresh (no known thread, so
|
|
@@ -55,6 +56,7 @@ export function maintenanceReport(drain, sessions) {
|
|
|
55
56
|
export function startArgs(s, thread, writable = []) {
|
|
56
57
|
return [
|
|
57
58
|
"start", "--harness", s.harness, "--as", s.agent, "--sandbox", s.sandbox, "--turn-timeout", String(s.turn_timeout), "--json",
|
|
59
|
+
...((s.provider ?? "anthropic") === "deepseek" ? ["--provider", "deepseek"] : []),
|
|
58
60
|
...(s.model ? ["--model", s.model] : []),
|
|
59
61
|
...(s.effort ? ["--effort", s.effort] : []),
|
|
60
62
|
...(thread ? ["--thread", thread] : []),
|
|
@@ -69,6 +71,14 @@ export async function reconcile(m, log) {
|
|
|
69
71
|
const client = Client.raw(m.url, m.key);
|
|
70
72
|
const me = await client.call("GET", "/machines/me");
|
|
71
73
|
const desired = me.sessions;
|
|
74
|
+
const providerChecks = new Set(["anthropic"]);
|
|
75
|
+
for (const provider of me.provider_checks ?? []) {
|
|
76
|
+
if (provider === "anthropic" || provider === "deepseek")
|
|
77
|
+
providerChecks.add(provider);
|
|
78
|
+
}
|
|
79
|
+
for (const s of desired)
|
|
80
|
+
if (s.harness === "claude-code" && (s.provider === "anthropic" || s.provider === "deepseek"))
|
|
81
|
+
providerChecks.add(s.provider);
|
|
72
82
|
const projects = me.projects ?? [];
|
|
73
83
|
const workdir = me.machine?.workdir ?? null;
|
|
74
84
|
const writable = me.machine?.writable ?? [];
|
|
@@ -104,6 +114,10 @@ export async function reconcile(m, log) {
|
|
|
104
114
|
}
|
|
105
115
|
if (!TURN_HARNESSES.includes(s.harness))
|
|
106
116
|
throw new Error(`harness ${s.harness} is not supported by this b9s ${CLI_VERSION}`);
|
|
117
|
+
if (s.provider && s.provider !== "anthropic" && s.provider !== "deepseek")
|
|
118
|
+
throw new Error(`provider ${s.provider} is not supported by this b9s ${CLI_VERSION}`);
|
|
119
|
+
if ((s.provider ?? "anthropic") === "deepseek" && s.harness !== "claude-code")
|
|
120
|
+
throw new Error("provider deepseek requires harness claude-code");
|
|
107
121
|
if (!s.dir) {
|
|
108
122
|
// A pool session: the daemon makes the checkout (clone once per machine, a worktree per agent).
|
|
109
123
|
const c = ensureCheckout(s, log, workdir);
|
|
@@ -190,7 +204,7 @@ export async function reconcile(m, log) {
|
|
|
190
204
|
writeMachineState(state);
|
|
191
205
|
const clones = refreshClones(workdir, [...new Set(desired.filter((s) => !s.dir && s.project && s.desired === "running").map((s) => s.project))], log);
|
|
192
206
|
const report = {
|
|
193
|
-
...machineFacts(), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones,
|
|
207
|
+
...machineFacts([...providerChecks]), workdir: workdir ?? join(homedir(), "bschat"), workdir_free_bytes: freeBytes(workdir ?? homedir()), clones,
|
|
194
208
|
// The daemon's own confirmation that it is holding turns back, and how many are still running.
|
|
195
209
|
maintenance: maintenanceReport(drainingUntil(), out),
|
|
196
210
|
};
|
|
@@ -530,16 +544,23 @@ function memAvailable() {
|
|
|
530
544
|
}
|
|
531
545
|
/** Claude Code's version, login and sandbox; the sandbox check runs at most every 10 min. */
|
|
532
546
|
let claudeSandboxCache = null;
|
|
533
|
-
function claudeReport(path = process.env.PATH ?? "") {
|
|
547
|
+
function claudeReport(path = process.env.PATH ?? "", providersInUse = ["anthropic"]) {
|
|
534
548
|
const f = claudeFacts(undefined, path);
|
|
535
549
|
if (!f)
|
|
536
550
|
return null;
|
|
537
551
|
if (!claudeSandboxCache || claudeSandboxCache.path !== path || Date.now() - claudeSandboxCache.at > 10 * 60_000)
|
|
538
552
|
claudeSandboxCache = { at: Date.now(), result: claudeSandbox(path), path };
|
|
539
|
-
|
|
553
|
+
const providers = {};
|
|
554
|
+
for (const provider of providersInUse) {
|
|
555
|
+
const check = provider === "anthropic"
|
|
556
|
+
? { logged_in: f.logged_in, reason: f.verified.error }
|
|
557
|
+
: verifyClaudeProvider(provider);
|
|
558
|
+
providers[provider] = { ...check, sandbox: claudeSandboxCache.result };
|
|
559
|
+
}
|
|
560
|
+
return { ...f, sandbox: claudeSandboxCache.result, providers };
|
|
540
561
|
}
|
|
541
562
|
/** What the operator needs to know about this machine, reported with every pass. */
|
|
542
|
-
export function machineFacts() {
|
|
563
|
+
export function machineFacts(providersInUse = ["anthropic"]) {
|
|
543
564
|
const path = process.env.PATH ?? "";
|
|
544
565
|
const env = { ...process.env, PATH: path };
|
|
545
566
|
const codex = spawnSync("codex", ["--version"], { encoding: "utf8", env });
|
|
@@ -554,6 +575,7 @@ export function machineFacts() {
|
|
|
554
575
|
diskFree = null;
|
|
555
576
|
}
|
|
556
577
|
const req = "/etc/codex/requirements.toml";
|
|
578
|
+
const claude = claudeReport(path, providersInUse);
|
|
557
579
|
return {
|
|
558
580
|
os: platform(), arch: arch(), hostname: hostname(), user: userInfo().username, cpus: cpus().length, mem_total_bytes: totalmem(),
|
|
559
581
|
load: loadavg().map((x) => Math.round(x * 100) / 100), mem_available_bytes: memAvailable(),
|
|
@@ -562,7 +584,8 @@ export function machineFacts() {
|
|
|
562
584
|
daemon_path: path,
|
|
563
585
|
bschat: { version: CLI_VERSION, bin: requireInstall().bin },
|
|
564
586
|
codex: codex.status === 0 ? { version: codex.stdout.trim(), logged_in: login?.status === 0 && /logged in/i.test(`${login.stdout}${login.stderr}`), login: `${login?.stdout ?? ""}${login?.stderr ?? ""}`.trim().slice(0, 200), sandbox: codexSandbox(false, path) } : null,
|
|
565
|
-
"claude-code":
|
|
587
|
+
"claude-code": claude,
|
|
588
|
+
claude_code: claude,
|
|
566
589
|
dsh,
|
|
567
590
|
managed_hooks: existsSync(req) && isCodexManagedRequirements(readFileSync(req, "utf8")),
|
|
568
591
|
linger: platform() === "linux" ? lingerEnabled() : null,
|
|
@@ -704,7 +727,7 @@ export async function machine(p, out) {
|
|
|
704
727
|
const state = readMachineState();
|
|
705
728
|
const rows = desired.map((s) => {
|
|
706
729
|
const w = watcherServices().find((x) => x.label === watchLabelOf(s.agent));
|
|
707
|
-
return `${s.agent.padEnd(32)} desired ${s.desired.padEnd(8)} watcher ${w ? (serviceActive(w) ? "active" : "inactive") : "none"} thread ${state.sessions[s.id]?.thread ?? s.thread ?? "-"} ${s.dir}`;
|
|
730
|
+
return `${s.agent.padEnd(32)} desired ${s.desired.padEnd(8)} watcher ${w ? (serviceActive(w) ? "active" : "inactive") : "none"} ${s.harness}/${s.provider ?? "anthropic"} thread ${state.sessions[s.id]?.thread ?? s.thread ?? "-"} ${s.dir}`;
|
|
708
731
|
});
|
|
709
732
|
return out.print([`machine ${m.name} (${m.url})`, ...rows, rows.length ? "" : "no sessions declared"].join("\n"), { machine: m.name, sessions: desired, local: state });
|
|
710
733
|
}
|
package/dist/commands/watch.js
CHANGED
|
@@ -16,6 +16,7 @@ import { heartbeatIfActive, resolveActivitySource } from "../heartbeat.js";
|
|
|
16
16
|
import { scanProject, unitWorktrees } from "./worktrees.js";
|
|
17
17
|
import { formatBytes, freeSpaceProbe, pruneReport, removePrunable } from "../git.js";
|
|
18
18
|
import { CliError } from "../errors.js";
|
|
19
|
+
import { claudeTurnEnv } from "../providers.js";
|
|
19
20
|
import { acquireWatchLock } from "../lock.js";
|
|
20
21
|
import { formatUpdates, gatherUpdates, reportDelivery } from "./hook.js";
|
|
21
22
|
import { readState, writeState } from "../state.js";
|
|
@@ -83,7 +84,15 @@ export async function watch(p, out) {
|
|
|
83
84
|
const session = (str(p.flags, "session") ?? (harness === "codex" ? thread : null))?.toLowerCase();
|
|
84
85
|
if (!session)
|
|
85
86
|
throw new CliError("usage", `--turn with --harness ${harness} needs --session <id>: the session its turns continue`);
|
|
86
|
-
|
|
87
|
+
const providerName = str(p.flags, "provider") ?? "anthropic";
|
|
88
|
+
if (providerName !== "anthropic" && providerName !== "deepseek")
|
|
89
|
+
throw new CliError("usage", "--provider must be anthropic or deepseek");
|
|
90
|
+
if (providerName === "deepseek" && harness !== "claude-code")
|
|
91
|
+
throw new CliError("usage", "--provider deepseek requires --harness claude-code");
|
|
92
|
+
turn = { harness, session, timeout: turnTimeout, provider: providerName, model: str(p.flags, "model") };
|
|
93
|
+
}
|
|
94
|
+
else if (p.flags.provider !== undefined) {
|
|
95
|
+
throw new CliError("usage", "--provider is only used with --turn --harness claude-code");
|
|
87
96
|
}
|
|
88
97
|
if (bool(p.flags, "launchd") || bool(p.flags, "service")) {
|
|
89
98
|
if (!exec)
|
|
@@ -229,7 +238,7 @@ export async function watch(p, out) {
|
|
|
229
238
|
try {
|
|
230
239
|
if (probe)
|
|
231
240
|
await turnStep(ctl, probe, turnTimeout, log, async (sink) => {
|
|
232
|
-
const result = await wakeOnce(name, exec, unackedAfter, followDelay, log, str(p.flags, "model"), once, sink, !resumeBriefDelivered, turn?.harness === "dsh", () => probe.beginTurn?.());
|
|
241
|
+
const result = await wakeOnce(name, exec, unackedAfter, followDelay, log, turn?.model ?? str(p.flags, "model"), once, sink, !resumeBriefDelivered, turn?.harness === "claude-code" && turn.provider === "deepseek" ? turn.provider : undefined, turn?.harness === "dsh", () => probe.beginTurn?.());
|
|
233
242
|
resumeBriefDelivered = resumeBriefDelivered || result.recoveryBriefDelivered;
|
|
234
243
|
}, name);
|
|
235
244
|
else {
|
|
@@ -318,7 +327,7 @@ async function waitIntervalOrStop(ms, stopped) {
|
|
|
318
327
|
if (timer)
|
|
319
328
|
clearTimeout(timer);
|
|
320
329
|
}
|
|
321
|
-
async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once, turnSink, includeResumeBrief = false, turnStdin = false, beforeTurn) {
|
|
330
|
+
async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once, turnSink, includeResumeBrief = false, provider, turnStdin = false, beforeTurn) {
|
|
322
331
|
const state = readState(name);
|
|
323
332
|
const pending = state.watch_pending;
|
|
324
333
|
if (pending) {
|
|
@@ -405,7 +414,7 @@ async function wakeOnce(name, exec, unackedAfter, followDelay, log, model, once,
|
|
|
405
414
|
// `{summary}` commands get the same bounded prompt as `{text}`: this wrapper itself contains
|
|
406
415
|
// the acknowledgement, operator note, process pointer, read commands, and delivery body.
|
|
407
416
|
const line = wake;
|
|
408
|
-
if (!(await deliver(name, exec, wake, line, u ? u.tier : "process", total, log, operatorNew ? "operator message; " : "", seq, turnSink, payload?.delivery.by_kind ?? u?.delivery.by_kind, turnStdin, beforeTurn)))
|
|
417
|
+
if (!(await deliver(name, exec, wake, line, u ? u.tier : "process", total, log, operatorNew ? "operator message; " : "", seq, turnSink, payload?.delivery.by_kind ?? u?.delivery.by_kind, provider, model, turnStdin, beforeTurn)))
|
|
409
418
|
return { sent: false, recoveryBriefDelivered: false };
|
|
410
419
|
writeState(name, {
|
|
411
420
|
...readState(name),
|
|
@@ -430,7 +439,7 @@ async function recoveryBriefText(name, log) {
|
|
|
430
439
|
}
|
|
431
440
|
}
|
|
432
441
|
/** Runs the wake command (or prints the wake-up without one). False when the command failed: nothing was delivered. */
|
|
433
|
-
async function deliver(name, exec, wake, summary, tier, total, log, prefix, seq, turnSink, kinds = {}, turnStdin = false, beforeTurn) {
|
|
442
|
+
export async function deliver(name, exec, wake, summary, tier, total, log, prefix, seq, turnSink, kinds = {}, provider, model, turnStdin = false, beforeTurn, dependencies = {}) {
|
|
434
443
|
if (!exec) {
|
|
435
444
|
process.stdout.write(wake + "\n");
|
|
436
445
|
return true;
|
|
@@ -442,8 +451,11 @@ async function deliver(name, exec, wake, summary, tier, total, log, prefix, seq,
|
|
|
442
451
|
// it started, and reports how it ended.
|
|
443
452
|
log(`${prefix}[${tier}] starting turn #${seq}: ${summary}`);
|
|
444
453
|
// The agent's own b9s calls in the turn know who they are without any repo file.
|
|
454
|
+
// Provider credentials are read only when spawning the turn and are never persisted in the
|
|
455
|
+
// launchd/systemd service or its command line.
|
|
456
|
+
const providerEnv = claudeTurnEnv(provider, model, dependencies.providerRoot);
|
|
445
457
|
beforeTurn?.();
|
|
446
|
-
turnSink(startTurn(cmd, { ...env, BSCHAT_AGENT: name }, seq, turnStdin ? wake : undefined));
|
|
458
|
+
turnSink((dependencies.startTurn ?? startTurn)(cmd, { ...env, BSCHAT_AGENT: name, ...providerEnv }, seq, turnStdin ? wake : undefined));
|
|
447
459
|
}
|
|
448
460
|
else {
|
|
449
461
|
log(`${prefix}[${tier}] queueing wake-up: ${summary}`);
|
|
@@ -752,7 +764,7 @@ function installLaunchd(name, exec, interval, followDelay, extraEnv, activity, o
|
|
|
752
764
|
bindSession(sess.kind, sess.id, name);
|
|
753
765
|
out.print(`Wrote ${path} and (re)loaded it: the watcher is running ${program[0]}.${Object.keys(extraEnv).length ? `\nCaptured env: ${Object.keys(extraEnv).join(", ")} (re-run this command if the harness restarts and these change)` : ""}\nStop it: launchctl bootout gui/$(id -u)/${label}\nLogs: ${logDir}/watch.${slug}.*.log\nCheck it: b9s doctor\nThe watcher runs from ${process.cwd()} so the repo identity file applies.`, { plist: path, label, program: program[0] });
|
|
754
766
|
}
|
|
755
|
-
const turnArgs = (t) => (t ? ["--turn", "--turn-timeout", String(t.timeout), "--harness", t.harness, "--session", t.session] : []);
|
|
767
|
+
const turnArgs = (t) => (t ? ["--turn", "--turn-timeout", String(t.timeout), "--harness", t.harness, "--session", t.session, ...(t.provider === "deepseek" ? ["--provider", t.provider] : []), ...(t.model ? ["--model", t.model] : [])] : []);
|
|
756
768
|
function escapeXml(s) {
|
|
757
769
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
758
770
|
}
|
package/dist/commands/wu.js
CHANGED
|
@@ -7,7 +7,7 @@ import { readState } from "../state.js";
|
|
|
7
7
|
import { codexRollout, sessionsOf } from "../sessions.js";
|
|
8
8
|
import { sessionUsage } from "../usage.js";
|
|
9
9
|
import { CliError } from "../errors.js";
|
|
10
|
-
import { branchAndHead, commitAtTime, ensureReviewWorktree, ensureWorktree, fetchRef, findRemoteCommitBranch, formatRemoteCommitFailure, formatRemoteCommitSuccess, fullSha, isAncestor, removeWorktreeIfClean, repoName, repoParent, verifyMergedCommit, worktreeForBranch } from "../git.js";
|
|
10
|
+
import { branchAndHead, commitAtTime, ensureReviewWorktree, ensureWorktree, fetchRef, findRemoteCommitBranch, formatRemoteCommitFailure, formatRemoteCommitSuccess, fullSha, isAncestor, removeWorktreeIfClean, repoName, repoParent, verifyMergedCommit, verifyNoCommitsBeyondTarget, worktreeForBranch } from "../git.js";
|
|
11
11
|
import { resolve } from "node:path";
|
|
12
12
|
import { table } from "../output.js";
|
|
13
13
|
export function scopeEditFromArgs(p) {
|
|
@@ -102,7 +102,17 @@ export function changedPathsAgainstTarget(target, cwd = process.cwd()) {
|
|
|
102
102
|
return diff.stdout.split("\0").filter((path) => path.length > 0);
|
|
103
103
|
}
|
|
104
104
|
export function submitPayload(fields, hasReviewRules, target, cwd = process.cwd()) {
|
|
105
|
-
|
|
105
|
+
const paths = changedPathsAgainstTarget(target, cwd);
|
|
106
|
+
const directories = {}, fileKinds = {};
|
|
107
|
+
for (const path of paths) {
|
|
108
|
+
const slash = path.lastIndexOf("/");
|
|
109
|
+
const directory = slash < 0 ? "(root)" : path.slice(0, path.indexOf("/"));
|
|
110
|
+
const basename = path.slice(slash + 1), dot = basename.lastIndexOf(".");
|
|
111
|
+
const kind = dot <= 0 ? "(no extension)" : basename.slice(dot).toLowerCase();
|
|
112
|
+
directories[directory] = (directories[directory] ?? 0) + 1;
|
|
113
|
+
fileKinds[kind] = (fileKinds[kind] ?? 0) + 1;
|
|
114
|
+
}
|
|
115
|
+
return { ...fields, changed_paths: hasReviewRules ? paths : [], changed_path_summary: { total: paths.length, by_directory: directories, by_file_kind: fileKinds, paths: paths.slice(0, 200), truncated: paths.length > 200 } };
|
|
106
116
|
}
|
|
107
117
|
export function branchValueIdsAtHead(values, head) {
|
|
108
118
|
if (!head)
|
|
@@ -157,6 +167,11 @@ export async function wu(p, out) {
|
|
|
157
167
|
}
|
|
158
168
|
return items;
|
|
159
169
|
};
|
|
170
|
+
const afterUnits = () => list("after").map((item) => {
|
|
171
|
+
if (!/^\d+$/.test(item) || Number(item) < 1)
|
|
172
|
+
throw new CliError("usage", `--after expects comma-separated work unit numbers, got ${JSON.stringify(item)}`);
|
|
173
|
+
return Number(item);
|
|
174
|
+
});
|
|
160
175
|
const num = () => {
|
|
161
176
|
const n = Number(p.positionals[2]);
|
|
162
177
|
if (!Number.isInteger(n) || n < 1)
|
|
@@ -165,7 +180,8 @@ export async function wu(p, out) {
|
|
|
165
180
|
};
|
|
166
181
|
const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
|
|
167
182
|
const fmt = (u) => {
|
|
168
|
-
const
|
|
183
|
+
const waitList = Array.isArray(u.waits_on) ? u.waits_on : u.waiting_on ? [u.waiting_on] : [];
|
|
184
|
+
const flags = [u.assigned_by ? `assigned by ${u.assigned_by}` : null, u.preferred_name ? `reserved for ${u.preferred_name}${u.hold ? " until free" : ""}` : null, u.hold && u.status === "assigned" ? "held" : null, waitList.length ? `waits on ${waitList.map((n) => `#${n}`).join(", ")}` : null, u.review_wait ? `waiting on ${u.review_wait.type === "unit" ? `WU #${u.review_wait.target}` : u.review_wait.type === "ask" ? `ask ${u.review_wait.target}` : u.review_wait.type === "machine" ? `machine ${u.review_wait.target}` : u.review_wait.type === "text" ? u.review_wait.target : "evidence"} for ${Math.max(0, Math.round((Date.now() - Date.parse(u.review_wait.started_at)) / 60000))} min` : null, u.milestone ? `milestone ${u.milestone}` : null, u.target ? `lands in ${u.target}` : null, u.replay_of ? "REPLAY" : null, u.trial_tags?.length ? `trial on ${u.trial_tags.map((t) => `#${t}`).join(" ")}` : null].filter(Boolean).join(" · ");
|
|
169
185
|
const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
|
|
170
186
|
const approvals = u.approvals.map((a) => a.name).join(", ");
|
|
171
187
|
return [
|
|
@@ -177,7 +193,8 @@ export async function wu(p, out) {
|
|
|
177
193
|
u.question ? ` QUESTION for ${u.question.level === "expert" ? `a ${u.question.roles.join(" or ")}` : "the operator"} (asked by ${u.question.asked_by}${u.question.passed_by ? `, passed up by ${u.question.passed_by}` : ""}): ${u.question.text}` : null,
|
|
178
194
|
u.evidence_claims?.total ? ` evidence claims: ${u.evidence_claims.confirmed} confirmed / ${u.evidence_claims.refuted} refuted / ${u.evidence_claims.unchecked} unchecked\n${u.evidence_claims.items.map((claim) => ` [${claim.state}] ${claim.filename}: ${claim.claim}${claim.verifier_name ? ` — ${claim.verifier_name}${claim.note ? `: ${claim.note}` : ""}` : ""}`).join("\n")}` : null,
|
|
179
195
|
` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.worktree ? ` in ${u.worktree.replace(/^\/(Users|home)\/[^/]+\//, "~/")}` : ""}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
|
|
180
|
-
u.scope ? ` scope: ${u.scope}` : null,
|
|
196
|
+
(u.base_scope ?? u.scope) ? ` scope: ${u.base_scope ?? u.scope}` : null,
|
|
197
|
+
u.scope_amendments?.length ? ` scope amendments:\n${u.scope_amendments.map((amendment) => ` ${amendment.at} ${amendment.author}: ${amendment.text}`).join("\n")}` : null,
|
|
181
198
|
].filter(Boolean).join("\n");
|
|
182
199
|
};
|
|
183
200
|
const processDef = async () => (await client.call("GET", `/projects/${project}/process`)).process.definition;
|
|
@@ -217,13 +234,17 @@ export async function wu(p, out) {
|
|
|
217
234
|
case "open": {
|
|
218
235
|
const title = p.positionals.slice(2).join(" ").trim();
|
|
219
236
|
if (!title)
|
|
220
|
-
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id]');
|
|
237
|
+
throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--after <n>[,<m>]] [--tier routine|careful|expert] [--evidence id]');
|
|
221
238
|
const unitTags = list("tags");
|
|
222
239
|
const scope = await scopeText();
|
|
223
240
|
// The unit exists first (it needs its number for the branch name), then its worktree is made
|
|
224
241
|
// and recorded exactly as `wu start` would; --here keeps the current checkout.
|
|
225
|
-
const r = await client.call("POST", base, { title, scope, tags: unitTags, requires: list("requires"), evidence: list("evidence"), min_tier: str(p.flags, "tier"), force: bool(p.flags, "force"), ...branchAndHead(), worktree: process.cwd(), target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null });
|
|
242
|
+
const r = await client.call("POST", base, { title, scope, tags: unitTags, requires: list("requires"), evidence: list("evidence"), after: afterUnits(), reworks: list("reworks").map(Number), min_tier: str(p.flags, "tier"), force: bool(p.flags, "force"), ...branchAndHead(), worktree: process.cwd(), target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null });
|
|
226
243
|
const n = r.unit.number;
|
|
244
|
+
if (r.unit.waiting_on != null) {
|
|
245
|
+
out.print(`${fmt(r.unit)}\nWait until ${r.unit.waits_on.map((on) => `WU #${on}`).join(", ")} closes, then start with: b9s wu start ${n}`, r);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
227
248
|
const { path, branch, mode } = prepareWorktree(n, r.unit, await processDef(), p, await checkoutExclude());
|
|
228
249
|
const where = branchAndHead(path);
|
|
229
250
|
const s = await client.call("POST", `${base}/${n}/start`, { branch: branch ?? where.branch, head: where.head, worktree: path, mode });
|
|
@@ -245,27 +266,33 @@ export async function wu(p, out) {
|
|
|
245
266
|
return;
|
|
246
267
|
}
|
|
247
268
|
const to = str(p.flags, "to");
|
|
269
|
+
const reason = str(p.flags, "reason");
|
|
248
270
|
if (!to)
|
|
249
|
-
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
271
|
+
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--after <n>[,<m>]] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
250
272
|
const existingNumber = Number(p.positionals[2]);
|
|
251
273
|
if (Number.isInteger(existingNumber) && existingNumber > 0 && p.positionals.length === 3) {
|
|
252
|
-
|
|
274
|
+
if (p.flags.after !== undefined)
|
|
275
|
+
throw new CliError("usage", "--after applies when creating a unit; use b9s wu wait to change an existing unit's wait");
|
|
276
|
+
const r = await client.call("POST", `${base}/${existingNumber}/assign`, { to, ...(reason === undefined ? {} : { reason }) });
|
|
253
277
|
out.print(fmt(r.unit), r);
|
|
254
278
|
return;
|
|
255
279
|
}
|
|
256
280
|
const title = p.positionals.slice(2).join(" ").trim();
|
|
257
281
|
if (!title)
|
|
258
|
-
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
282
|
+
throw new CliError("usage", 'wu assign "<title>" --to <agent|auto|queue> --scope "<what it covers and does not>" [--scope-file <path> | --scope-from <n>] [--tags a,b] [--after <n>[,<m>]] [--tier routine|careful|expert] [--evidence id] [--replay-of <n>]');
|
|
259
283
|
const scope = await scopeText();
|
|
260
284
|
const replay = str(p.flags, "replay-of");
|
|
261
|
-
const r = await client.call("POST", `${base}/assign`, { to, title, scope, tags: unitTags, requires: list("requires"), evidence: list("evidence"), replay_of: replay ? Number(replay) : null, branch: str(p.flags, "branch") ?? null, target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null, min_tier: str(p.flags, "tier"), hold: !!p.flags.hold, force: bool(p.flags, "force") });
|
|
285
|
+
const r = await client.call("POST", `${base}/assign`, { to, title, scope, tags: unitTags, requires: list("requires"), evidence: list("evidence"), after: afterUnits(), replay_of: replay ? Number(replay) : null, reworks: list("reworks").map(Number), branch: str(p.flags, "branch") ?? null, target: str(p.flags, "target") ?? null, milestone: str(p.flags, "milestone") ?? null, min_tier: str(p.flags, "tier"), hold: !!p.flags.hold, force: bool(p.flags, "force"), ...(reason === undefined ? {} : { reason }) });
|
|
262
286
|
out.print(`${fmt(r.unit)}\n${assignmentDisposition(r.unit, to)}${r.warnings?.length ? `\nScope warnings:\n${r.warnings.map((w) => `- ${w}`).join("\n")}` : ""}`, r);
|
|
263
287
|
return;
|
|
264
288
|
}
|
|
265
289
|
case "take": {
|
|
266
290
|
// Pull a queued unit: for yourself (qualified by works or trial), or for someone with --to (assigners).
|
|
267
291
|
const to = str(p.flags, "to") ?? null;
|
|
268
|
-
const
|
|
292
|
+
const reason = str(p.flags, "reason");
|
|
293
|
+
if (reason !== undefined && !to)
|
|
294
|
+
throw new CliError("usage", 'wu take <n> --to <agent> --reason "why" is only for an assigner handing work to a named agent');
|
|
295
|
+
const r = await client.call("POST", `${base}/${num()}/take`, { to, ...(reason === undefined ? {} : { reason }) });
|
|
269
296
|
out.print(`${fmt(r.unit)}\n${to ? `Handed to ${r.unit.owner_name}.` : `Yours. Start it: b9s wu start ${r.unit.number}`}`, r);
|
|
270
297
|
return;
|
|
271
298
|
}
|
|
@@ -310,7 +337,7 @@ export async function wu(p, out) {
|
|
|
310
337
|
throw new CliError("usage", 'wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] (a planning unit needs one of them)');
|
|
311
338
|
const waits = str(p.flags, "waits-on");
|
|
312
339
|
const r = await client.call("POST", `${base}/${num()}/decline`, { note, ...(waits ? { waits_on: waits.split(",").map((k) => k.trim()).filter(Boolean) } : {}), ...(bool(p.flags, "defer") ? { defer: true } : {}) });
|
|
313
|
-
out.print(fmt(r.unit)
|
|
340
|
+
out.print(`Declined; now ${r.unit.status}.\n${fmt(r.unit)}`, r);
|
|
314
341
|
return;
|
|
315
342
|
}
|
|
316
343
|
case "submit": {
|
|
@@ -477,16 +504,44 @@ export async function wu(p, out) {
|
|
|
477
504
|
out.print(fmt(r.unit), r);
|
|
478
505
|
return;
|
|
479
506
|
}
|
|
507
|
+
case "kind": {
|
|
508
|
+
const kind = str(p.flags, "kind");
|
|
509
|
+
const reason = str(p.flags, "reason");
|
|
510
|
+
if (!kind || !reason)
|
|
511
|
+
throw new CliError("usage", 'wu kind <n> --kind <product_change|enabling_tooling|diagnosis_audit|documentation|rework|needs_classification> --reason "why"');
|
|
512
|
+
const r = await client.call("POST", `${base}/${num()}/kind`, { kind, reason });
|
|
513
|
+
out.print(fmt(r.unit), r);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
480
516
|
case "done": {
|
|
481
517
|
const def = await processDef();
|
|
482
518
|
const merged = str(p.flags, "merged") ?? null;
|
|
519
|
+
const noSource = bool(p.flags, "no-source");
|
|
520
|
+
const evidence = list("evidence");
|
|
521
|
+
if (noSource && merged)
|
|
522
|
+
throw new CliError("usage", "--merged and --no-source are mutually exclusive");
|
|
523
|
+
if (!noSource && evidence.length)
|
|
524
|
+
throw new CliError("usage", "--evidence on wu done requires --no-source");
|
|
483
525
|
const unit = (await client.call("GET", `${base}/${num()}`)).unit;
|
|
484
526
|
const landsIn = unit.target ?? def.merge.target_branch;
|
|
485
527
|
let verifiedRemoteTarget = null;
|
|
528
|
+
let noCommitsBeyondTarget = false;
|
|
486
529
|
if (unit.replay_of) {
|
|
487
530
|
// A replay is an evaluation: it closes without merging (the server records it as evaluated).
|
|
488
|
-
if (merged)
|
|
489
|
-
throw new CliError("usage", `WU #${num()} is a replay, compared and never merged: close it without --merged`);
|
|
531
|
+
if (merged || noSource)
|
|
532
|
+
throw new CliError("usage", `WU #${num()} is a replay, compared and never merged: close it without --merged or --no-source`);
|
|
533
|
+
}
|
|
534
|
+
else if (noSource) {
|
|
535
|
+
if (!evidence.length)
|
|
536
|
+
throw new CliError("usage", "--no-source requires at least one --evidence id");
|
|
537
|
+
if (unit.branch) {
|
|
538
|
+
const check = verifyNoCommitsBeyondTarget(unit.branch, landsIn, process.cwd(), def.merge.require_pushed);
|
|
539
|
+
if (check.on === null)
|
|
540
|
+
throw new CliError("unknown_commit", `cannot verify ${unit.branch} against ${check.ref}`, `Fetch the branch and ${landsIn} in the project repository, then retry`);
|
|
541
|
+
if (!check.on)
|
|
542
|
+
throw new CliError("has_commits", `${unit.branch} has commits not contained by ${check.ref}; --no-source is only for work with no commits beyond its target`);
|
|
543
|
+
noCommitsBeyondTarget = true;
|
|
544
|
+
}
|
|
490
545
|
}
|
|
491
546
|
else if (merged) {
|
|
492
547
|
// Where pushes are required the remote target is the truth, not this machine's copy of it.
|
|
@@ -513,7 +568,7 @@ export async function wu(p, out) {
|
|
|
513
568
|
else if (def.merge.require_merge_commit) {
|
|
514
569
|
throw new CliError("usage", `this project's process requires the merge commit: b9s wu done ${num()} --merged <sha>`);
|
|
515
570
|
}
|
|
516
|
-
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
|
|
571
|
+
const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged, ...(noSource ? { no_source: true, evidence, no_commits_beyond_target: noCommitsBeyondTarget } : {}) });
|
|
517
572
|
out.print(fmt(r.unit) + (verifiedRemoteTarget ? `\nverified on ${verifiedRemoteTarget}` : "") + cleanupUnitWorktree(r.unit.worktree, def, !!p.flags["keep-worktree"]), r);
|
|
518
573
|
return;
|
|
519
574
|
}
|
|
@@ -629,6 +684,10 @@ export async function wu(p, out) {
|
|
|
629
684
|
}
|
|
630
685
|
/** Queued units have no owner; ask the API to reject before any local worktree is made. */
|
|
631
686
|
export async function preflightQueuedStart(client, base, n, unit) {
|
|
687
|
+
if (unit.waiting_on != null) {
|
|
688
|
+
const waits = unit.waits_on?.length ? unit.waits_on : [unit.waiting_on];
|
|
689
|
+
throw new CliError("unit_waiting", `work unit #${n} waits on ${waits.map((on) => `#${on}`).join(", ")}; start it after those units close`);
|
|
690
|
+
}
|
|
632
691
|
if (unit.status === "queued")
|
|
633
692
|
await client.call("POST", `${base}/${n}/start`, {});
|
|
634
693
|
}
|
|
@@ -761,7 +820,7 @@ export async function milestones(p, out) {
|
|
|
761
820
|
*/
|
|
762
821
|
export async function milestonesWith(client, project, sub, p, out) {
|
|
763
822
|
if (sub === "export") {
|
|
764
|
-
const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, ...(m.source ? { source: m.source } : {}), depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], ...(m.priority !== null && m.priority !== undefined ? { priority: m.priority } : {}) }));
|
|
823
|
+
const list = (await client.call("GET", `/projects/${project}/milestones`)).milestones.map((m) => ({ key: m.key, title: m.title, exit: m.exit, expectations: m.expectations ?? [], ...(m.source ? { source: m.source } : {}), depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], ...(m.priority !== null && m.priority !== undefined ? { priority: m.priority } : {}) }));
|
|
765
824
|
const text = JSON.stringify(list, null, 2) + "\n";
|
|
766
825
|
const file = str(p.flags, "out");
|
|
767
826
|
if (file) {
|
|
@@ -834,17 +893,28 @@ export async function milestoneWith(client, project, sub, key, p, out, decisionP
|
|
|
834
893
|
const dependencies = [...deps.map((key) => ({ key, kind: "blocks" })), ...informs.map((key) => ({ key, kind: "informs" }))];
|
|
835
894
|
const exit = str(p.flags, "exit") ?? existing?.exit ?? "";
|
|
836
895
|
const source = str(p.flags, "source") ?? existing?.source ?? "";
|
|
896
|
+
let expectations = existing?.expectations ?? [];
|
|
897
|
+
if (str(p.flags, "expectations") !== undefined) {
|
|
898
|
+
try {
|
|
899
|
+
expectations = JSON.parse(str(p.flags, "expectations"));
|
|
900
|
+
}
|
|
901
|
+
catch {
|
|
902
|
+
throw new CliError("usage", "--expectations must be a JSON list of {measure, direction?, value?, checkpoint?: closure}");
|
|
903
|
+
}
|
|
904
|
+
if (!Array.isArray(expectations))
|
|
905
|
+
throw new CliError("usage", "--expectations must be a JSON list of expectation objects");
|
|
906
|
+
}
|
|
837
907
|
const default_tags = str(p.flags, "default-tags") !== undefined ? (str(p.flags, "default-tags") ?? "").split(",").map((s) => s.trim().replace(/^#/, "")).filter(Boolean) : existing?.default_tags ?? [];
|
|
838
908
|
// --priority <n> (higher first) or none; the steward asks for units only on the highest-priority ready slices.
|
|
839
909
|
const pr = str(p.flags, "priority");
|
|
840
910
|
if (pr !== undefined && pr !== "none" && !/^-?\d+$/.test(pr))
|
|
841
911
|
throw new CliError("usage", "--priority takes a whole number (higher first) or none");
|
|
842
912
|
const priority = pr === undefined ? existing?.priority ?? null : pr === "none" ? null : Number(pr);
|
|
843
|
-
const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, source: m.source ?? "", depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], priority: m.priority ?? null }));
|
|
913
|
+
const next = cur.map((m) => ({ key: m.key, title: m.title, exit: m.exit, expectations: m.expectations ?? [], source: m.source ?? "", depends_on: m.dependencies ?? m.depends_on, default_tags: m.default_tags ?? [], priority: m.priority ?? null }));
|
|
844
914
|
if (existing)
|
|
845
|
-
Object.assign(next.find((m) => m.key === key), { title, exit, source, depends_on: dependencies, default_tags, priority });
|
|
915
|
+
Object.assign(next.find((m) => m.key === key), { title, exit, expectations, source, depends_on: dependencies, default_tags, priority });
|
|
846
916
|
else
|
|
847
|
-
next.push({ key, title, exit, source, depends_on: dependencies, default_tags, priority });
|
|
917
|
+
next.push({ key, title, exit, expectations, source, depends_on: dependencies, default_tags, priority });
|
|
848
918
|
const r = await client.call("PUT", `/projects/${project}/milestones`, { milestones: next });
|
|
849
919
|
const m = r.milestones.find((x) => x.key === key);
|
|
850
920
|
out.print(`${sub === "add" ? "Added" : "Updated"} milestone ${m.key}: ${m.title} [${m.ready ? "ready" : `waits on ${m.waiting_on.join(", ")}`}]${!m.exit && !m.depends_on.length ? " (container: never chased)" : ""}`, r);
|
package/dist/git.js
CHANGED
|
@@ -71,6 +71,25 @@ export function isAncestor(ancestor, ref, cwd = process.cwd()) {
|
|
|
71
71
|
const r = spawnSync("git", ["merge-base", "--is-ancestor", ancestor, ref], { cwd, stdio: "ignore" });
|
|
72
72
|
return r.status === 0;
|
|
73
73
|
}
|
|
74
|
+
/** Confirm an evidence-only unit branch contains no commits missing from its configured target. */
|
|
75
|
+
export function verifyNoCommitsBeyondTarget(branch, target, cwd = process.cwd(), requirePushed = false) {
|
|
76
|
+
if (requirePushed) {
|
|
77
|
+
const ref = `origin/${target}`;
|
|
78
|
+
const fetched = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
|
|
79
|
+
if (!fetched)
|
|
80
|
+
return { on: null, ref };
|
|
81
|
+
return { on: isAncestor(branch, ref, cwd), ref };
|
|
82
|
+
}
|
|
83
|
+
const local = isAncestor(branch, target, cwd);
|
|
84
|
+
if (local === true)
|
|
85
|
+
return { on: true, ref: target };
|
|
86
|
+
const ref = `origin/${target}`;
|
|
87
|
+
const fetched = spawnSync("git", ["fetch", "--quiet", "origin", `+refs/heads/${target}:refs/remotes/origin/${target}`], { cwd, encoding: "utf8", timeout: 120_000 }).status === 0;
|
|
88
|
+
if (!fetched)
|
|
89
|
+
return { on: local, ref: target };
|
|
90
|
+
const remote = isAncestor(branch, ref, cwd);
|
|
91
|
+
return remote === true ? { on: true, ref } : { on: remote, ref };
|
|
92
|
+
}
|
|
74
93
|
/** Branch and short head of the worktree at cwd, or nulls outside a repo. */
|
|
75
94
|
export function branchAndHead(cwd = process.cwd()) {
|
|
76
95
|
const a = collectAuto({ model: undefined, machine: "", cwd });
|
package/dist/help.js
CHANGED
|
@@ -20,6 +20,8 @@ GET /account/usage reports used and allowed micro-dollars, uncertain calls and t
|
|
|
20
20
|
Session/admin clients can use GET /assistant/conversations, GET /assistant/conversations/:id/messages (paged history with saved tool notices), POST /assistant/conversations/:id/messages (SSE), and DELETE /assistant/conversations/:id. Old assistant messages report notices_available=false. The assistant can draft changes; POST /assistant/proposals/:id/apply or /discard is the operator's explicit action. See the agent/operator skill API reference for events and tools.
|
|
21
21
|
Free and paid accounts without a live Stripe subscription use the UTC calendar month; subscribed paid accounts reset at current_period_end.
|
|
22
22
|
|
|
23
|
+
GitHub repository links are managed by the account owner through the browser session API: POST /github/connect, GET /github/callback, GET /github/repositories, and POST/GET/DELETE /projects/:p/github-link. App setup steps are in the operator skill (packages/skill-admin/references/setup.md). Hosted merge remains disabled; this connection unit's stand-in ruleset test is accepted, and a separate live GitHub bypass-change check is required before enablement.
|
|
24
|
+
|
|
23
25
|
Agent commands
|
|
24
26
|
b9s login --as <name> --key <bs_agent_...> [--url <api>] [--label <machine-label>]
|
|
25
27
|
b9s logout --as <name>
|
|
@@ -42,19 +44,23 @@ Agent commands
|
|
|
42
44
|
b9s follow <channel> | unfollow <channel> | following followed channels' new messages are injected by the hook;
|
|
43
45
|
other channels appear as a one-line unread digest
|
|
44
46
|
b9s process the project's process: tag vocabulary, reviewers, wake-path warnings, scope templates, requirements, agreements
|
|
45
|
-
b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
|
|
47
|
+
b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
|
|
46
48
|
worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
|
|
47
49
|
process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
|
|
48
|
-
b9s wu
|
|
50
|
+
b9s wu open "<title>" --scope "..." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--reworks n,m] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--evidence id[,id...]] [--target <branch>] [--here] open a work unit in its own
|
|
51
|
+
worktree; tags come from the vocabulary; --target is the branch it lands in (default: the
|
|
52
|
+
process target), e.g. a lane branch; wu target <n> <branch|default> changes it before review
|
|
53
|
+
b9s wu assign "<title>" --to <agent|auto|queue> --scope ".." [--scope-file <path> | --scope-from <n>] [--tags a,b] [--reworks n,m] [--after <n>[,<m>]] [--tier routine|careful|expert] [--requires cap,cap] [--force] [--replay-of n] [--template] [--reason "why"] hand out a unit (assigner roles);
|
|
49
54
|
--to auto picks the active qualified worker with the lightest load; it queues when nobody fits,
|
|
50
55
|
reports why candidates were passed over, and the sweep chases it;
|
|
51
56
|
--to queue waits deliberately; naming a busy worker reserves it for them (theirs when free,
|
|
52
57
|
anyone's after the takeover window); --hold keeps it assigned to them however long it takes;
|
|
53
58
|
--template --tags a,b prints the scope skeleton; --force records missing required sections, including for queue.
|
|
54
|
-
b9s wu assign <n> --to <agent>
|
|
55
|
-
b9s wu take <n> [--to <agent>]
|
|
59
|
+
b9s wu assign <n> --to <agent> [--reason "why"] reassign an assigned or queued unit in place
|
|
60
|
+
b9s wu take <n> [--to <agent>] [--reason "why"] pull a unit or hand it to someone
|
|
61
|
+
reason is required when an assigner uses its assign_outside_qualifications role capability
|
|
56
62
|
b9s wu next take the oldest queued unit you qualify for
|
|
57
|
-
b9s wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] decline an assignment; a steward planning unit
|
|
63
|
+
b9s wu decline <n> --note "why" [--waits-on <milestone,...> | --defer] decline and requeue an assignment (use wu abandon to close); a steward planning unit
|
|
58
64
|
("Advance milestone X") needs the plan decision: what X waits on, or defer X
|
|
59
65
|
b9s wu start <n> [--branch b | --here] take it up: makes ../<repo>-wu<n> on branch wu/<n>-<slug> (replays: from the
|
|
60
66
|
target as of the original); a worktree left half-written by an interrupted
|
|
@@ -65,7 +71,7 @@ Agent commands
|
|
|
65
71
|
b9s milestones the plan's slices: ready or waiting on which, units done/total; wu open|assign --milestone <key>
|
|
66
72
|
b9s milestones set --file plan.json define or replace the plan (assigner roles or the operator): a JSON list of
|
|
67
73
|
{key, title, exit, depends_on, default_tags}; existing keys keep their status; cycles are refused
|
|
68
|
-
b9s milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--default-tags a,b] [--priority n|none] add one slice (assigner
|
|
74
|
+
b9s milestone add <key> --title ".." [--exit ".."] [--source "docs/plan.md#b0"] [--depends-on a,b] [--informs c,d] [--default-tags a,b] [--priority n|none] [--expectations '<JSON list>'] add one slice (assigner
|
|
69
75
|
roles or the operator); --source is where the full brief lives, read only when planning the slice;
|
|
70
76
|
no exit and no dependencies makes a container for ongoing work; milestone edit (or set) <key> amends;
|
|
71
77
|
--priority <n|none> (higher first): the steward asks for units only on the top ready slices
|
|
@@ -106,7 +112,7 @@ Agent commands
|
|
|
106
112
|
owner or reviewer: pause review on a named blocker; reviewer may record a partial verdict
|
|
107
113
|
b9s wu scope <n> --scope ".." | --scope-file <path> | --scope-from <n> --note ".." assigner or operator: replace the full scope; recorded and announced
|
|
108
114
|
b9s wu scope <n> --replace "<old>" "<new>" --note ".." replace one exact, unique substring of the scope
|
|
109
|
-
b9s wu scope <n> --append ".." --note ".."
|
|
115
|
+
b9s wu scope <n> --append ".." --note ".." add a dated scope amendment (up to 2000 chars); the base scope stays capped at 4000
|
|
110
116
|
b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]
|
|
111
117
|
b9s ask-operator --amend <id> ["new question"] [--plain ".."] [--blocks ".."] [--if-yes ".."] [--if-no ".."] [--propose ".."] amend your own open ask
|
|
112
118
|
b9s ask-operator refuses a second ask naming the same WU; use --amend <id>. Account needs group asks/questions by unit and can answer several together.
|
|
@@ -115,10 +121,11 @@ Agent commands
|
|
|
115
121
|
b9s explain <ask-id> "..." the operator asked you (Explain) to put your request in plain words
|
|
116
122
|
b9s wu explain <n> "..." the same for a unit's question waiting on the operator
|
|
117
123
|
b9s wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
|
|
124
|
+
b9s wu kind <n> --kind <kind> --reason "why" assigner/operator overrides the progress-view kind, with an audit event
|
|
118
125
|
b9s wu hold <n> --note ".." operator or assigner: no verdict and no merge until the owner resubmits;
|
|
119
126
|
wu release <n> [--note ..] lifts it earlier
|
|
120
127
|
b9s wu evidence replace <n> <old> <new> [--note ".."] owner replaces attached evidence; old id is retained in the unit history
|
|
121
|
-
b9s wu done <n> --merged <sha> [--keep-worktree] after approval;
|
|
128
|
+
b9s wu done <n> --merged <sha> | --no-source --evidence id[,id...] [--keep-worktree] after approval; no-source closes an evidence-only unit without a merge SHA and checks its branch has no commits beyond the target
|
|
122
129
|
b9s wu show <n> [--scope-only] show the full unit or only its scope for scripts
|
|
123
130
|
b9s wu abandon <n> [--note ..] wu list [--all] for state and timeline
|
|
124
131
|
b9s worktrees prune [--yes] [--archive] remove clean worktrees whose work landed or whose unit is closed (dry run without --yes);
|
|
@@ -146,7 +153,7 @@ Agent commands
|
|
|
146
153
|
b9s doctor every b9s on this machine and who runs which (PATH, npx caches, this repo's
|
|
147
154
|
hook and instructions, each watcher's plist versus what launchd runs), with fixes
|
|
148
155
|
b9s codex hooks | bind <thread-id> | sync install b9s's Codex hooks (~/.codex/hooks.json) and say which thread is you
|
|
149
|
-
b9s start --harness codex|claude-code|dsh --as <a> --sandbox <mode> [--token t] [--thread id] [--model m] [--effort e] [--dsh path]
|
|
156
|
+
b9s start --harness codex|claude-code|dsh --as <a> --sandbox <mode> [--provider anthropic|deepseek] [--token t] [--thread id] [--model m] [--effort e] [--dsh path]
|
|
150
157
|
run an agent headless: enroll, start or adopt its session, turn-mode watcher
|
|
151
158
|
(b9s codex start is the same with --harness codex)
|
|
152
159
|
b9s unpause [--as <a>] lift a usage-limit pause now (the harness was switched to an account with quota)
|
|
@@ -228,8 +235,9 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
|
|
|
228
235
|
pin a notice to every agent on a machine or in a project
|
|
229
236
|
b9s-admin notice list | remove <id> list or remove a machine/project notice
|
|
230
237
|
b9s-admin role create <name> [--project p] [--description d] [--broadcast] [--create-channels] [--read-account-status] [--permissions '{json}'] [--cardinality one|many]
|
|
231
|
-
b9s-admin role edit <name> [--project p] [--projects a,b|*] [--post c1,c2] [--broadcast] [--create-channels] [--read-account-status] [--description d] [--cardinality one|many]
|
|
238
|
+
b9s-admin role edit <name> [--project p] [--projects a,b|*] [--post c1,c2] [--broadcast] [--create-channels] [--read-account-status] [--assign-outside-qualifications yes|no] [--description d] [--cardinality one|many]
|
|
232
239
|
b9s-admin role list [--project p]
|
|
240
|
+
b9s-admin wu assign <project> <n> --to <agent> [--reason "why"] operator: reassign a unit in place
|
|
233
241
|
b9s-admin role delete <name> [--project p]
|
|
234
242
|
b9s-admin channel create|delete <project> <name>
|
|
235
243
|
b9s-admin keys [create | revoke <id>] list admin and agent keys; create shows a new admin key once
|
|
@@ -245,6 +253,7 @@ b9s-admin login (approve it in your signed-in browser); the session lasts 30 day
|
|
|
245
253
|
b9s-admin milestone <project> add|edit <key> --title .. [--exit ..] [--source ..] [--depends-on a,b] [--informs c,d] [--default-tags a,b] one slice in, the rest untouched
|
|
246
254
|
b9s-admin milestone <project> show|review|reopen <key> | decide <key> "ruling" --unit n | close <key> --note .. [--abandon|--defer] | verdict <key> --met|--gaps .. | gap-units <key> --units n,m
|
|
247
255
|
b9s-admin role edit <name> [--project p] --reviews a,b --works c --trials d which tags a role reviews, works and trials ("*" all, "" none)
|
|
256
|
+
--assign-outside-qualifications yes|no allow assigners in this role to make reasoned ownership exceptions; dispatch stays qualified
|
|
248
257
|
b9s-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
|
|
249
258
|
b9s-admin answer <key> "decision" answer one; the asker is @mentioned
|
|
250
259
|
b9s-admin answer <key> --approve [--assign <agent>] [--note ".."] accept an ask proposal and name its action owner
|
|
@@ -266,10 +275,10 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
266
275
|
b9s-admin machine list | show <name> | remove <name>
|
|
267
276
|
b9s-admin machine maintenance <name> --at <ISO | HH:MM> --for <30m | 2h> | --cancel a window: no new turns from
|
|
268
277
|
15 min before, its agents away until the machine reports back after booting
|
|
269
|
-
b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access>
|
|
278
|
+
b9s-admin machine session add <machine> <project>/<agent> --dir <checkout> --sandbox <read-only|workspace-write|danger-full-access> [--harness codex|claude-code] [--provider anthropic|deepseek]
|
|
270
279
|
[--create --role <role>] [--model m] [--effort e] [--thread <id>] [--turn-timeout min]
|
|
271
280
|
b9s-admin machine session stop|start|remove <machine> <project>/<agent>
|
|
272
|
-
b9s-admin agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--carry note|thread]
|
|
281
|
+
b9s-admin agent move <project>/<agent> --to <machine> --sandbox <mode> [--dir <path>|auto] [--harness codex|claude-code] [--provider anthropic|deepseek] [--carry note|thread]
|
|
273
282
|
[--from local|<ssh host>] [--model m] [--effort e] [--wait min] [--force]
|
|
274
283
|
run an existing agent on a provisioned machine: refuses unpushed unit work (checked on
|
|
275
284
|
--from), carries its context as a resume note or its Codex thread, revokes other keys
|
|
@@ -281,7 +290,7 @@ Machines (provisioned over your own ssh; a daemon on each runs the agent session
|
|
|
281
290
|
Pools (a role, variants and a count; the server names the agents and places them on machines)
|
|
282
291
|
b9s-admin project repo <project> <git url | none> what machines clone for the project's pool sessions
|
|
283
292
|
b9s-admin project checkout <project> --exclude <path,path | none> paths new worktrees leave out (sparse checkout), e.g. logs/
|
|
284
|
-
b9s-admin pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight] [--variant ...]
|
|
293
|
+
b9s-admin pool set <project>/<name> --role <role> --variant [tag=]harness:model[:effort][*weight][@anthropic|deepseek] [--variant ...]
|
|
285
294
|
--count <n> --sandbox <mode> [--needs label,label] [--min-ram GB] [--turn-timeout min]
|
|
286
295
|
slots are agents named <name>-<tag>-<n>; fewer retires the extra ones
|
|
287
296
|
b9s-admin pool list [project] | show <project>/<name> | remove <project>/<name>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { CliError } from "./errors.js";
|
|
7
|
+
import { claudeResultError } from "./harnesses.js";
|
|
8
|
+
const MAX_AGE_MS = 6 * 60 * 60_000;
|
|
9
|
+
const checks = new Map();
|
|
10
|
+
export const deepSeekKeyRoot = () => join(homedir(), ".b9s");
|
|
11
|
+
export const deepSeekKeyPath = (root = deepSeekKeyRoot()) => join(root, "providers", "deepseek.key");
|
|
12
|
+
/** The key never appears in argv, watcher settings, or diagnostics. */
|
|
13
|
+
export function claudeProviderEnv(provider, root = deepSeekKeyRoot(), model = "deepseek-flash") {
|
|
14
|
+
if (provider === "anthropic")
|
|
15
|
+
return {};
|
|
16
|
+
const path = deepSeekKeyPath(root);
|
|
17
|
+
let key;
|
|
18
|
+
try {
|
|
19
|
+
const mode = statSync(path).mode & 0o777;
|
|
20
|
+
if (mode !== 0o600)
|
|
21
|
+
throw new CliError("provider_key_permissions", `${path} must have mode 600 (currently ${mode.toString(8).padStart(3, "0")})`, `Run: chmod 600 ${path}`);
|
|
22
|
+
key = readFileSync(path, "utf8").trim();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code === "ENOENT")
|
|
26
|
+
throw new CliError("provider_key_missing", `DeepSeek provider key file is missing: ${path}`, `Create ${path} with your DeepSeek API key, then run: chmod 600 ${path}`);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
if (!key)
|
|
30
|
+
throw new CliError("provider_key_empty", `DeepSeek provider key file is empty: ${path}`);
|
|
31
|
+
return {
|
|
32
|
+
ANTHROPIC_BASE_URL: "https://api.deepseek.com/anthropic",
|
|
33
|
+
ANTHROPIC_AUTH_TOKEN: key,
|
|
34
|
+
ANTHROPIC_MODEL: model,
|
|
35
|
+
ANTHROPIC_SMALL_FAST_MODEL: model,
|
|
36
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** The credentials and selected model for one Claude Code turn; Anthropic keeps its own env. */
|
|
40
|
+
export function claudeTurnEnv(provider, model, root) {
|
|
41
|
+
return provider ? claudeProviderEnv(provider, root, model) : {};
|
|
42
|
+
}
|
|
43
|
+
function keyFingerprint(provider, root) {
|
|
44
|
+
if (provider === "anthropic")
|
|
45
|
+
return "anthropic-session-auth";
|
|
46
|
+
const path = deepSeekKeyPath(root);
|
|
47
|
+
try {
|
|
48
|
+
const mode = statSync(path).mode & 0o777;
|
|
49
|
+
if (mode !== 0o600)
|
|
50
|
+
return `mode:${mode}`;
|
|
51
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return error.code === "ENOENT" ? "missing" : `unreadable:${error.code ?? "error"}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Make one tiny provider call when first used, after its key changes, or every six hours. */
|
|
58
|
+
export function verifyClaudeProvider(provider, root = deepSeekKeyRoot(), nowMs = Date.now(), run = spawnSync) {
|
|
59
|
+
const fingerprint = keyFingerprint(provider, root);
|
|
60
|
+
const cacheKey = `${root}\0${provider}`;
|
|
61
|
+
const cached = checks.get(cacheKey);
|
|
62
|
+
if (cached?.fingerprint === fingerprint && nowMs - cached.at < MAX_AGE_MS)
|
|
63
|
+
return cached.result;
|
|
64
|
+
let result;
|
|
65
|
+
let secret;
|
|
66
|
+
const safeReason = (reason) => secret ? reason.replaceAll(secret, "[redacted]") : reason;
|
|
67
|
+
try {
|
|
68
|
+
const env = claudeProviderEnv(provider, root, "deepseek-flash");
|
|
69
|
+
secret = env.ANTHROPIC_AUTH_TOKEN;
|
|
70
|
+
const checked = run("claude", ["-p", "--output-format", "json", ...(env.ANTHROPIC_MODEL ? ["--model", env.ANTHROPIC_MODEL] : []), "Reply with exactly OK."], {
|
|
71
|
+
encoding: "utf8", timeout: 60_000, cwd: homedir(), env: { ...process.env, ...env, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1" }, maxBuffer: 64 * 1024,
|
|
72
|
+
});
|
|
73
|
+
const outputError = claudeResultError(checked.stdout ?? "");
|
|
74
|
+
result = checked.status === 0 && !outputError
|
|
75
|
+
? { logged_in: true }
|
|
76
|
+
: { logged_in: false, reason: safeReason(outputError ?? `Claude Code provider verification failed (exit ${checked.status ?? "unknown"})`).slice(0, 400) };
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
result = { logged_in: false, reason: safeReason(error.message).slice(0, 400) };
|
|
80
|
+
}
|
|
81
|
+
checks.set(cacheKey, { fingerprint, at: nowMs, result });
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
export function clearProviderChecksForTests() { checks.clear(); }
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.89";
|