benignswarm 0.12.115 → 0.12.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/antigravity.js +14 -4
- package/dist/args.js +2 -1
- package/dist/commands/admin.js +18 -6
- package/dist/commands/machine.js +178 -7
- package/dist/commands/operator.js +66 -1
- package/dist/commands/turn.js +31 -2
- package/dist/commands/watch.js +0 -1
- package/dist/commands/wu.js +29 -8
- package/dist/config.js +2 -2
- package/dist/directories.js +7 -178
- package/dist/harness.js +33 -5
- package/dist/help.js +13 -5
- package/dist/model-checks.js +307 -0
- package/dist/output.js +3 -4
- package/dist/state.js +3 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/antigravity.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { basename, delimiter, dirname, join } from "node:path";
|
|
4
|
+
import { basename, delimiter, dirname, join, sep } from "node:path";
|
|
5
5
|
import { configRoot } from "./config.js";
|
|
6
6
|
import { repoDirectory } from "./directories.js";
|
|
7
7
|
import { CliError } from "./errors.js";
|
|
@@ -60,11 +60,21 @@ export function antigravitySettings(sandbox, cwd, b9sHome, apiHost, extraWritabl
|
|
|
60
60
|
throw new CliError("usage", "the BenignSwarm API host is invalid for Antigravity sandbox permissions");
|
|
61
61
|
if (!b9sBin)
|
|
62
62
|
throw new CliError("not_installed", "the recorded b9s install path is required for Antigravity workspace-write");
|
|
63
|
-
|
|
63
|
+
// Antigravity runs the agent's commands in the outermost workspace folder. A workspace folder
|
|
64
|
+
// that contains the checkout (its parent, where unit worktrees and the clone's git data live)
|
|
65
|
+
// therefore moved every command out of the checkout: `git` found no repository and the start's
|
|
66
|
+
// own check failed. Such folders are granted by permission instead, and only folders beside the
|
|
67
|
+
// checkout are added as workspaces. Verified with agy 1.5.11: pwd is the checkout, git reaches
|
|
68
|
+
// origin, and a sibling worktree can be created.
|
|
69
|
+
const wanted = [...new Set([dirname(cwd), b9sHome, ...extraWritable])];
|
|
70
|
+
const containsCheckout = (dir) => cwd === dir || cwd.startsWith(dir.endsWith(sep) ? dir : dir + sep);
|
|
71
|
+
const around = wanted.filter(containsCheckout);
|
|
72
|
+
const beside = wanted.filter((dir) => !containsCheckout(dir));
|
|
73
|
+
const allow = [...new Set([...antigravitySandboxPermissions(apiHost, b9sHome, b9sBin, nodeBin, repoDirectory(cwd)), ...around.map((dir) => `write_file(${dir})`)])];
|
|
64
74
|
return [
|
|
65
75
|
"--sandbox", "--settings",
|
|
66
|
-
JSON.stringify({ enableTerminalSandbox: true, toolPermission: "proceed-in-sandbox", permissions: { allow
|
|
67
|
-
...
|
|
76
|
+
JSON.stringify({ enableTerminalSandbox: true, toolPermission: "proceed-in-sandbox", permissions: { allow } }),
|
|
77
|
+
...beside.flatMap((dir) => ["--add-dir", dir]),
|
|
68
78
|
];
|
|
69
79
|
}
|
|
70
80
|
export function antigravityTurnArgs(prompt, model, effort, timeoutSeconds, settings, conversation) {
|
package/dist/args.js
CHANGED
|
@@ -10,7 +10,7 @@ export const LIST_FLAGS = [
|
|
|
10
10
|
export const STRING_FLAGS = [
|
|
11
11
|
"as", "admin", "key", "url", "label", "model", "since", "limit", "after", "topic", "goal", "task",
|
|
12
12
|
"state", "blocked-on", "tags", "custom", "vendor", "role", "description", "permissions",
|
|
13
|
-
"cardinality", "assign-outside-qualifications", "machine", "idempotency-key", "dir", "confirm", "impact-revision", "type",
|
|
13
|
+
"cardinality", "assign-outside-qualifications", "judges", "machine", "idempotency-key", "dir", "confirm", "impact-revision", "type",
|
|
14
14
|
"name", "out", "token", "token-file", "prefix", "uses", "expires-hours", "skill-dir", "harness", "provider", "reply-to",
|
|
15
15
|
"event", "project", "projects", "post", "title", "body", "body-file", "handoff-to", "evidence", "agent",
|
|
16
16
|
"parent", "parent-item", "channel", "statuses", "assign", "if-status", "status", "exec", "interval",
|
|
@@ -22,6 +22,7 @@ export const STRING_FLAGS = [
|
|
|
22
22
|
"require-evidence", "default-approver", "merged-by", "integrator-role", "require-rebased", "require-merge-commit",
|
|
23
23
|
"require-pushed", "quiet", "summary", "meaning", "expert-role", "reviews", "works", "trials", "email",
|
|
24
24
|
"repeat", "summary-minutes", "churn", "unmet", "require-cited-changes", "checks-every", "propose", "waits-on",
|
|
25
|
+
"flow-summary", "flow-min-age", "flow-min-impact",
|
|
25
26
|
"sandbox", "thread", "turn-timeout", "turns-per-hour", "unproductive-per-hour", "turn-coalesce-seconds", "session", "operation",
|
|
26
27
|
"plain", "if-yes", "if-no", "ssh", "variant", "count", "min", "max", "needs", "min-ram", "exclude", "carry", "from",
|
|
27
28
|
"to-ssh", "ssh-from", "wait", "writable", "writable-root", "dsh", "agy", "for", "until", "reason", "at", "requires",
|
package/dist/commands/admin.js
CHANGED
|
@@ -11,7 +11,7 @@ import { milestoneWith, milestonesWith } from "./wu.js";
|
|
|
11
11
|
import { awayUntil } from "./agent.js";
|
|
12
12
|
import { agentMove, machineAdmin, poolAdmin, projectCheckoutAdmin, projectRepoAdmin } from "./machine-admin.js";
|
|
13
13
|
import { routingAdmin, runRequiredClassUpdate } from "./routing-admin.js";
|
|
14
|
-
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, textCheckAdmin, worktreeAdmin } from "./operator.js";
|
|
14
|
+
import { accountAdmin, answerAdmin, explainAdmin, keysAdmin, needsAdmin, notifierAdmin, processAdmin, skillAdmin, tagList, textCheckAdmin, turnJudgeAdmin, worktreeAdmin } from "./operator.js";
|
|
15
15
|
import { adminNotice } from "./notices.js";
|
|
16
16
|
import { cloudAdmin } from "./cloud-admin.js";
|
|
17
17
|
import { projectImageAdmin } from "./image-admin.js";
|
|
@@ -128,6 +128,9 @@ export async function admin(p, out) {
|
|
|
128
128
|
return notifierAdmin(p, out);
|
|
129
129
|
case "account":
|
|
130
130
|
return accountAdmin(p, out);
|
|
131
|
+
case "turn-judgment":
|
|
132
|
+
case "turn-judgments":
|
|
133
|
+
return turnJudgeAdmin(action, rest, p, out);
|
|
131
134
|
case "text-check":
|
|
132
135
|
return textCheckAdmin(action, p, out);
|
|
133
136
|
case "worktree":
|
|
@@ -446,12 +449,15 @@ async function role(action, rest, p, out) {
|
|
|
446
449
|
const base = proj ? `/projects/${proj}/roles` : "/roles";
|
|
447
450
|
if (action === "list") {
|
|
448
451
|
const r = await c.call("GET", base);
|
|
449
|
-
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 }));
|
|
450
|
-
out.print(table(rows, ["name", "scope", "reviews", "works", "trials", "assign_outside_qualifications", "cardinality", "projects", "post", "broadcast", "create_channels", "read_account_status"]), r);
|
|
452
|
+
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, judges: !!x.judges, 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 }));
|
|
453
|
+
out.print(table(rows, ["name", "scope", "reviews", "works", "trials", "assign_outside_qualifications", "judges", "cardinality", "projects", "post", "broadcast", "create_channels", "read_account_status"]), r);
|
|
451
454
|
}
|
|
452
455
|
else if (action === "create" && rest[0]) {
|
|
453
456
|
const permissions = permsFromFlags(p, !!proj) ?? { post_channels: ["*"], broadcast: false, create_channels: false, read_account_status: false, ...(proj ? {} : { projects: [] }) };
|
|
454
|
-
const
|
|
457
|
+
const judgesFlag = str(p.flags, "judges");
|
|
458
|
+
if (judgesFlag !== undefined && judgesFlag !== "yes" && judgesFlag !== "no")
|
|
459
|
+
throw new CliError("usage", "--judges must be yes or no");
|
|
460
|
+
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")) ?? [], ...(judgesFlag !== undefined ? { judges: judgesFlag === "yes" } : {}) });
|
|
455
461
|
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);
|
|
456
462
|
}
|
|
457
463
|
else if (action === "edit" && rest[0]) {
|
|
@@ -471,13 +477,19 @@ async function role(action, rest, p, out) {
|
|
|
471
477
|
const permissions = permsFromFlags(p, !!proj);
|
|
472
478
|
if (permissions)
|
|
473
479
|
body.permissions = permissions;
|
|
480
|
+
const judges = str(p.flags, "judges");
|
|
481
|
+
if (judges !== undefined) {
|
|
482
|
+
if (judges !== "yes" && judges !== "no")
|
|
483
|
+
throw new CliError("usage", "--judges must be yes or no");
|
|
484
|
+
body.judges = judges === "yes";
|
|
485
|
+
}
|
|
474
486
|
for (const q of ["reviews", "works", "trials"]) {
|
|
475
487
|
const v = tagList(str(p.flags, q));
|
|
476
488
|
if (v !== undefined)
|
|
477
489
|
body[q] = v;
|
|
478
490
|
}
|
|
479
491
|
if (!Object.keys(body).length)
|
|
480
|
-
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");
|
|
492
|
+
throw new CliError("usage", "role edit needs --description, --cardinality, --assign-outside-qualifications yes|no, --judges yes|no, --projects, --post, --broadcast, --create-channels, --read-account-status, --permissions, --reviews, --works or --trials");
|
|
481
493
|
const r = await c.call("PATCH", `${base}/${rest[0]}`, body);
|
|
482
494
|
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);
|
|
483
495
|
}
|
|
@@ -486,7 +498,7 @@ async function role(action, rest, p, out) {
|
|
|
486
498
|
out.print(`deleted role ${rest[0]}`, r);
|
|
487
499
|
}
|
|
488
500
|
else
|
|
489
|
-
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]");
|
|
501
|
+
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] [--judges yes|no] [--description d] [--cardinality one|many]");
|
|
490
502
|
}
|
|
491
503
|
async function workUnitAdmin(action, rest, p, out) {
|
|
492
504
|
if (action === "required-class" && rest[0] && /^\d+$/.test(rest[1] ?? "")) {
|
package/dist/commands/machine.js
CHANGED
|
@@ -18,7 +18,7 @@ import { installService, launchdFacts, launchdFactsLine, launchdGuidance, launch
|
|
|
18
18
|
import { CLI_VERSION } from "../version.js";
|
|
19
19
|
import { probeCapabilities } from "../capabilities.js";
|
|
20
20
|
import { diskSpaceNotice } from "../notices.js";
|
|
21
|
-
import { verifyClaudeProvider } from "../providers.js";
|
|
21
|
+
import { deepSeekKeyPath, verifyClaudeProvider } from "../providers.js";
|
|
22
22
|
import { busyTurnPause, DEFAULT_TURNS_PER_HOUR, DEFAULT_UNPRODUCTIVE_PER_HOUR, resumeTurnGuard, verificationUnavailable } from "../turn-guard.js";
|
|
23
23
|
import { defaultWorkspaceWritableRoots } from "../start-options.js";
|
|
24
24
|
import { antigravityPath, antigravitySandboxPermissions, antigravityTurnArgs, antigravityTurnEnv, parseAntigravityJson } from "../antigravity.js";
|
|
@@ -29,6 +29,7 @@ import { agentContainerName, agentContainerRunArgs, detectEc2Host, ensurePinnedI
|
|
|
29
29
|
import { machineEnvironmentChecks } from "../environment-checks.js";
|
|
30
30
|
import { machineResourceTelemetry, measuredWatcherServiceMemoryLimits, parsePageSize } from "../machine-telemetry.js";
|
|
31
31
|
import { macReadiness, macReadinessSteps } from "../macos-readiness.js";
|
|
32
|
+
import { collectModelChecksQueued, modelCheckRuntimeTuple, probeModelRunAsync } from "../model-checks.js";
|
|
32
33
|
import { authorizeWorktreeScope, redactProcessCommand, scanWorktreeProcesses } from "../machine-processes.js";
|
|
33
34
|
import { collectPruneProtection } from "../prune-protection.js";
|
|
34
35
|
import { runMachineDaemonLoop } from "../machine-daemon.js";
|
|
@@ -1665,6 +1666,8 @@ export async function reconcile(m, log, reportIntervalSeconds = 30, deps) {
|
|
|
1665
1666
|
const workSpace = volumeSpace(actualWorkdir, "workdir");
|
|
1666
1667
|
const facts = machineFacts([...providerChecks], {
|
|
1667
1668
|
workdir: actualWorkdir,
|
|
1669
|
+
modelsToCheck: me.models_to_check ?? [],
|
|
1670
|
+
modelRunProbe: deps?.modelRunProbe,
|
|
1668
1671
|
ec2Probe: () => onEc2,
|
|
1669
1672
|
...(imdsContainerProbe ? { containerImdsProbe: () => imdsContainerProbe } : {}),
|
|
1670
1673
|
...(hostContainerProbe ? { probes: { container: () => hostContainerProbe } } : {}),
|
|
@@ -2442,6 +2445,132 @@ function claudeReport(path = process.env.PATH ?? "", providersInUse = ["anthropi
|
|
|
2442
2445
|
}
|
|
2443
2446
|
return { ...f, sandbox: claudeSandboxCache.result, providers };
|
|
2444
2447
|
}
|
|
2448
|
+
const modelCheckCacheFile = () => join(configRoot(), "state", "model-checks.json");
|
|
2449
|
+
function readModelCheckCache() {
|
|
2450
|
+
try {
|
|
2451
|
+
const parsed = JSON.parse(readFileSync(modelCheckCacheFile(), "utf8"));
|
|
2452
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => {
|
|
2453
|
+
const value = entry[1];
|
|
2454
|
+
return !!value && (value.status === "ok" || value.status === "unsupported" || value.status === "unknown")
|
|
2455
|
+
&& typeof value.harness === "string" && typeof value.model === "string" && typeof value.cache_key === "string"
|
|
2456
|
+
// Legacy unknown entries may represent an unavailable login rather than a model run.
|
|
2457
|
+
// Do not let those suppress the first real probe after readiness recovers.
|
|
2458
|
+
&& (value.status !== "unknown" || value.probe_attempted === true);
|
|
2459
|
+
}));
|
|
2460
|
+
}
|
|
2461
|
+
catch {
|
|
2462
|
+
return {};
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
function writeModelCheckCache(cache) {
|
|
2466
|
+
mkdirSync(dirname(modelCheckCacheFile()), { recursive: true });
|
|
2467
|
+
writeFileSync(modelCheckCacheFile(), JSON.stringify(cache, null, 2) + "\n", { mode: 0o600 });
|
|
2468
|
+
}
|
|
2469
|
+
function jsonRecord(path) {
|
|
2470
|
+
try {
|
|
2471
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
2472
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2473
|
+
}
|
|
2474
|
+
catch {
|
|
2475
|
+
return null;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
function recordAt(value, key) {
|
|
2479
|
+
const nested = value?.[key];
|
|
2480
|
+
return nested && typeof nested === "object" && !Array.isArray(nested) ? nested : null;
|
|
2481
|
+
}
|
|
2482
|
+
function stableIdAt(value, keys) {
|
|
2483
|
+
for (const key of keys) {
|
|
2484
|
+
const id = value?.[key];
|
|
2485
|
+
if (typeof id === "string" && id.trim())
|
|
2486
|
+
return id.trim();
|
|
2487
|
+
}
|
|
2488
|
+
return null;
|
|
2489
|
+
}
|
|
2490
|
+
function jwtAccountSubject(token) {
|
|
2491
|
+
if (typeof token !== "string")
|
|
2492
|
+
return null;
|
|
2493
|
+
const parts = token.split(".");
|
|
2494
|
+
if (parts.length !== 3 || !parts[1])
|
|
2495
|
+
return null;
|
|
2496
|
+
try {
|
|
2497
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
2498
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
2499
|
+
return null;
|
|
2500
|
+
return stableIdAt(payload, ["sub", "account_id", "accountUuid", "user_id"]);
|
|
2501
|
+
}
|
|
2502
|
+
catch {
|
|
2503
|
+
return null;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
function accountIdentityFingerprint(namespace, identifiers) {
|
|
2507
|
+
const stable = [...new Set(identifiers.filter((value) => !!value))];
|
|
2508
|
+
return stable.length ? createHash("sha256").update(JSON.stringify([namespace, ...stable])).digest("hex") : null;
|
|
2509
|
+
}
|
|
2510
|
+
/** Hash stable OAuth account identifiers only; rotating access/refresh tokens are never identity. */
|
|
2511
|
+
export function claudeAccountFingerprintForModelCheck(credentialsFile = join(claudeHome(), ".credentials.json"), configFile = join(homedir(), ".claude.json")) {
|
|
2512
|
+
const credentials = jsonRecord(credentialsFile);
|
|
2513
|
+
const oauth = recordAt(credentials, "claudeAiOauth");
|
|
2514
|
+
const config = jsonRecord(configFile);
|
|
2515
|
+
const account = recordAt(config, "oauthAccount");
|
|
2516
|
+
const tokenAccount = recordAt(oauth, "oauthAccount");
|
|
2517
|
+
return accountIdentityFingerprint("claude-code", [
|
|
2518
|
+
jwtAccountSubject(oauth?.accessToken),
|
|
2519
|
+
stableIdAt(oauth, ["accountUuid", "account_id", "user_id"]),
|
|
2520
|
+
stableIdAt(tokenAccount, ["accountUuid", "account_id", "user_id"]),
|
|
2521
|
+
stableIdAt(account, ["accountUuid", "account_id", "user_id"]),
|
|
2522
|
+
stableIdAt(oauth, ["organizationUuid", "organization_id"]) ?? stableIdAt(account, ["organizationUuid", "organization_id"]),
|
|
2523
|
+
]);
|
|
2524
|
+
}
|
|
2525
|
+
/** Gemini's OAuth ID token subject is stable across access-token refreshes and never reported. */
|
|
2526
|
+
export function antigravityAccountFingerprintForModelCheck(credentialsFile = join(homedir(), ".gemini", "oauth_creds.json")) {
|
|
2527
|
+
const credentials = jsonRecord(credentialsFile);
|
|
2528
|
+
return accountIdentityFingerprint("antigravity", [
|
|
2529
|
+
jwtAccountSubject(credentials?.id_token),
|
|
2530
|
+
stableIdAt(credentials, ["account_id", "accountId", "user_id"]),
|
|
2531
|
+
]);
|
|
2532
|
+
}
|
|
2533
|
+
function accountFingerprintForModelCheck(harness, provider) {
|
|
2534
|
+
if (harness === "codex")
|
|
2535
|
+
return codexAccountFingerprint();
|
|
2536
|
+
if (harness === "claude-code" && provider === "deepseek") {
|
|
2537
|
+
try {
|
|
2538
|
+
return createHash("sha256").update(readFileSync(deepSeekKeyPath())).digest("hex");
|
|
2539
|
+
}
|
|
2540
|
+
catch {
|
|
2541
|
+
return null;
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
if (harness === "claude-code") {
|
|
2545
|
+
const credentialsFile = join(claudeHome(), ".credentials.json");
|
|
2546
|
+
const configFiles = [...new Set([join(claudeHome(), ".claude.json"), join(homedir(), ".claude.json")])];
|
|
2547
|
+
for (const configFile of configFiles) {
|
|
2548
|
+
const fingerprint = claudeAccountFingerprintForModelCheck(credentialsFile, configFile);
|
|
2549
|
+
if (fingerprint)
|
|
2550
|
+
return fingerprint;
|
|
2551
|
+
}
|
|
2552
|
+
return null;
|
|
2553
|
+
}
|
|
2554
|
+
if (harness === "antigravity") {
|
|
2555
|
+
for (const credentialsFile of [join(homedir(), ".gemini", "oauth_creds.json"), join(homedir(), ".gemini", "antigravity", "oauth_creds.json")]) {
|
|
2556
|
+
const fingerprint = antigravityAccountFingerprintForModelCheck(credentialsFile);
|
|
2557
|
+
if (fingerprint)
|
|
2558
|
+
return fingerprint;
|
|
2559
|
+
}
|
|
2560
|
+
return null;
|
|
2561
|
+
}
|
|
2562
|
+
const candidates = harness === "dsh"
|
|
2563
|
+
? [join(homedir(), ".config", "deepseek-harness", "auth.json"), join(homedir(), ".deepseek-harness", "auth.json")]
|
|
2564
|
+
: [];
|
|
2565
|
+
for (const path of candidates) {
|
|
2566
|
+
try {
|
|
2567
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
2568
|
+
}
|
|
2569
|
+
catch { /* try the next supported credential location */ }
|
|
2570
|
+
}
|
|
2571
|
+
const envCredential = harness === "dsh" ? process.env.DEEPSEEK_API_KEY ?? process.env.DSH_API_KEY : undefined;
|
|
2572
|
+
return envCredential ? createHash("sha256").update(envCredential).digest("hex") : null;
|
|
2573
|
+
}
|
|
2445
2574
|
/** What the operator needs to know about this machine, reported with every pass. */
|
|
2446
2575
|
export function machineFacts(providersInUse = ["anthropic"], workdirOrOpts, sessions = [], diskFloorPct = DEFAULT_CACHE_FLOOR_PCT) {
|
|
2447
2576
|
const opts = typeof workdirOrOpts === "object" && workdirOrOpts !== null ? workdirOrOpts : {};
|
|
@@ -2449,16 +2578,19 @@ export function machineFacts(providersInUse = ["anthropic"], workdirOrOpts, sess
|
|
|
2449
2578
|
const probes = opts.probes;
|
|
2450
2579
|
const path = process.env.PATH ?? "";
|
|
2451
2580
|
const env = { ...process.env, PATH: path };
|
|
2452
|
-
const
|
|
2581
|
+
const readCodexFacts = () => probes?.codex
|
|
2453
2582
|
? probes.codex()
|
|
2454
2583
|
: (() => {
|
|
2455
2584
|
const codex = spawnSync("codex", ["--version"], { encoding: "utf8", env });
|
|
2456
2585
|
const login = codex.status === 0 ? spawnSync("codex", ["login", "status"], { encoding: "utf8", env }) : null;
|
|
2457
2586
|
return 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), account_fingerprint: codexAccountFingerprint(), sandbox: codexSandbox(false, path) } : null;
|
|
2458
2587
|
})();
|
|
2459
|
-
const
|
|
2588
|
+
const codexFactsValue = readCodexFacts();
|
|
2589
|
+
const readDshFacts = () => (probes?.dsh ?? (() => dshFacts(platform(), path)))();
|
|
2590
|
+
const dsh = readDshFacts();
|
|
2460
2591
|
const probeAgent = antigravityProbeAgent(sessions);
|
|
2461
|
-
const
|
|
2592
|
+
const readAntigravityFacts = () => probes?.antigravity ? probes.antigravity(probeAgent) : antigravityFacts(path, readInstall()?.bin ?? null, probeAgent);
|
|
2593
|
+
const antigravity = readAntigravityFacts();
|
|
2462
2594
|
const homeSpace = volumeSpace(homedir(), "home");
|
|
2463
2595
|
const readTelemetryFile = (path) => { try {
|
|
2464
2596
|
return readFileSync(path, "utf8");
|
|
@@ -2488,7 +2620,23 @@ export function machineFacts(providersInUse = ["anthropic"], workdirOrOpts, sess
|
|
|
2488
2620
|
const telemetryAvailability = telemetry.metric_availability;
|
|
2489
2621
|
const volumeFloorPct = diskFloorPct;
|
|
2490
2622
|
const req = "/etc/codex/requirements.toml";
|
|
2491
|
-
const
|
|
2623
|
+
const fingerprint = (harness, provider) => accountFingerprintForModelCheck(harness, provider);
|
|
2624
|
+
const readClaudeFacts = () => (probes?.claude ?? (() => claudeReport(path, providersInUse)))();
|
|
2625
|
+
const withClaudeIdentity = (value) => {
|
|
2626
|
+
if (!value)
|
|
2627
|
+
return null;
|
|
2628
|
+
const providerReports = value.providers;
|
|
2629
|
+
return {
|
|
2630
|
+
...value,
|
|
2631
|
+
account_fingerprint: fingerprint("claude-code", "anthropic"),
|
|
2632
|
+
...(providerReports ? { providers: Object.fromEntries(Object.entries(providerReports).map(([provider, report]) => [
|
|
2633
|
+
provider, { ...report, account_fingerprint: fingerprint("claude-code", provider) },
|
|
2634
|
+
])) } : {}),
|
|
2635
|
+
};
|
|
2636
|
+
};
|
|
2637
|
+
const claude = withClaudeIdentity(readClaudeFacts());
|
|
2638
|
+
const dshWithIdentity = { ...dsh, account_fingerprint: fingerprint("dsh") };
|
|
2639
|
+
const antigravityWithIdentity = { ...antigravity, account_fingerprint: fingerprint("antigravity") };
|
|
2492
2640
|
const bootedAt = (opts.bootTime ?? bootTimeMs)();
|
|
2493
2641
|
const gitIdentity = (probes?.gitIdentity ?? (() => readGitIdentity()))();
|
|
2494
2642
|
const container = (probes?.container ?? (() => probeNestedSandbox()))();
|
|
@@ -2521,8 +2669,8 @@ export function machineFacts(providersInUse = ["anthropic"], workdirOrOpts, sess
|
|
|
2521
2669
|
codex: codexFactsValue,
|
|
2522
2670
|
"claude-code": claude,
|
|
2523
2671
|
claude_code: claude,
|
|
2524
|
-
dsh,
|
|
2525
|
-
antigravity,
|
|
2672
|
+
dsh: dshWithIdentity,
|
|
2673
|
+
antigravity: antigravityWithIdentity,
|
|
2526
2674
|
managed_hooks: managedHooks,
|
|
2527
2675
|
linger: platform() === "linux" ? lingerEnabled() : null,
|
|
2528
2676
|
disk_free_bytes: homeSpace?.freeBytes ?? null,
|
|
@@ -2541,6 +2689,29 @@ export function machineFacts(providersInUse = ["anthropic"], workdirOrOpts, sess
|
|
|
2541
2689
|
};
|
|
2542
2690
|
}))();
|
|
2543
2691
|
}
|
|
2692
|
+
const modelCache = readModelCheckCache();
|
|
2693
|
+
const readCurrentModelTuple = (request) => {
|
|
2694
|
+
if (request.harness === "codex")
|
|
2695
|
+
return modelCheckRuntimeTuple({ codex: readCodexFacts() }, request);
|
|
2696
|
+
if (request.harness === "claude-code") {
|
|
2697
|
+
const currentClaude = withClaudeIdentity(readClaudeFacts());
|
|
2698
|
+
return modelCheckRuntimeTuple({ "claude-code": currentClaude, claude_code: currentClaude }, request);
|
|
2699
|
+
}
|
|
2700
|
+
if (request.harness === "dsh") {
|
|
2701
|
+
return modelCheckRuntimeTuple({ dsh: { ...readDshFacts(), account_fingerprint: fingerprint("dsh") } }, request);
|
|
2702
|
+
}
|
|
2703
|
+
if (request.harness === "antigravity") {
|
|
2704
|
+
return modelCheckRuntimeTuple({ antigravity: { ...readAntigravityFacts(), account_fingerprint: fingerprint("antigravity") } }, request);
|
|
2705
|
+
}
|
|
2706
|
+
return { version: null, account: null, ready: false };
|
|
2707
|
+
};
|
|
2708
|
+
facts.model_checks = collectModelChecksQueued(opts.modelsToCheck ?? [], facts, modelCache, path, opts.modelRunProbe ?? probeModelRunAsync, (entry) => {
|
|
2709
|
+
const latest = readModelCheckCache();
|
|
2710
|
+
latest[entry.cache_key] = entry;
|
|
2711
|
+
writeModelCheckCache(latest);
|
|
2712
|
+
}, new Date(), readCurrentModelTuple);
|
|
2713
|
+
if ((opts.modelsToCheck ?? []).length)
|
|
2714
|
+
writeModelCheckCache(modelCache);
|
|
2544
2715
|
return facts;
|
|
2545
2716
|
}
|
|
2546
2717
|
/** Parse root (`/`) mount specification from `/etc/fstab` (or kernel cmdline fallback) for UUID/PARTUUID safety. */
|
|
@@ -244,6 +244,62 @@ export async function processAdmin(action, rest, p, out) {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
/** Decisions waiting on the operator, and answering them: the console banner from a terminal. */
|
|
247
|
+
/**
|
|
248
|
+
* Turn judgments (docs/TURN-JUDGE.md): what the independent judge decided about a paused session,
|
|
249
|
+
* and the operator's reasoned override. The packet is shown only here, never to agents.
|
|
250
|
+
*/
|
|
251
|
+
export async function turnJudgeAdmin(action, rest, p, out) {
|
|
252
|
+
const c = adminClient(p);
|
|
253
|
+
if (action === "list") {
|
|
254
|
+
const r = await c.call("GET", "/account/turn-judgments");
|
|
255
|
+
const rows = (r.judgments ?? []);
|
|
256
|
+
return out.print(rows.length ? table(rows.map((j) => ({
|
|
257
|
+
id: j.id, state: j.state, verdict: j.verdict ?? "-", confidence: j.confidence ?? "-", judge: j.judge?.name ?? "-",
|
|
258
|
+
session: j.session_id, created: j.created_at, override: j.override ? j.override.reason : "-",
|
|
259
|
+
})), ["id", "state", "verdict", "confidence", "judge", "session", "created", "override"]) : "no turn judgments", r);
|
|
260
|
+
}
|
|
261
|
+
if (action === "show") {
|
|
262
|
+
const id = rest[0];
|
|
263
|
+
if (!id)
|
|
264
|
+
throw new CliError("usage", "turn-judgment show <id>");
|
|
265
|
+
const r = await c.call("GET", `/account/turn-judgments/${id}`);
|
|
266
|
+
const j = r.judgment;
|
|
267
|
+
return out.print(packetLines(j), r);
|
|
268
|
+
}
|
|
269
|
+
if (action === "override") {
|
|
270
|
+
const id = rest[0];
|
|
271
|
+
if (!id)
|
|
272
|
+
throw new CliError("usage", 'turn-judgment override <id> --reason "why"');
|
|
273
|
+
const reason = str(p.flags, "reason");
|
|
274
|
+
if (!reason?.trim())
|
|
275
|
+
throw new CliError("usage", "override needs --reason, recorded in the audit history");
|
|
276
|
+
const r = await c.call("POST", `/account/turn-judgments/${id}/override`, { action: "resume", reason });
|
|
277
|
+
return out.print(`judgment ${id}: resumed by override (${reason.trim()})`, r);
|
|
278
|
+
}
|
|
279
|
+
throw new CliError("usage", "turn-judgment list | turn-judgment show <id> | turn-judgment override <id> --reason \"why\"");
|
|
280
|
+
}
|
|
281
|
+
function packetLines(j) {
|
|
282
|
+
const lines = [
|
|
283
|
+
`judgment ${j.id}: ${j.state} (${j.session_id}${j.project_id ? `, project ${j.project_id}` : ""})`,
|
|
284
|
+
`created ${j.created_at}${j.decided_at ? `, decided ${j.decided_at}` : ""}; triggers: ${(j.trigger_reasons ?? []).join(", ") || "-"}`,
|
|
285
|
+
`judge: ${j.judge ? `${j.judge.name ?? j.judge.agent_id} (${j.model_class ?? "model unknown"})` : "none"}${j.verdict ? `; verdict ${j.verdict} at confidence ${j.confidence ?? "?"}` : ""}`,
|
|
286
|
+
];
|
|
287
|
+
if (j.verdict_reason)
|
|
288
|
+
lines.push(`reason: ${j.verdict_reason}`);
|
|
289
|
+
if (j.status_reason)
|
|
290
|
+
lines.push(`status: ${j.status_reason}`);
|
|
291
|
+
if (j.grant_expires_at)
|
|
292
|
+
lines.push(`continuation grant: ${j.grant_turns_used} of 5 turns used, until ${j.grant_expires_at}`);
|
|
293
|
+
if (j.override)
|
|
294
|
+
lines.push(`overridden by ${j.override.by}: ${j.override.reason} (${j.override.at})`);
|
|
295
|
+
if (j.packet_hash)
|
|
296
|
+
lines.push(`packet hash: ${j.packet_hash}`);
|
|
297
|
+
if (j.packet)
|
|
298
|
+
lines.push(`packet:\n${JSON.stringify(j.packet, null, 2)}`);
|
|
299
|
+
else
|
|
300
|
+
lines.push("packet: expired or not retained");
|
|
301
|
+
return lines.join("\n");
|
|
302
|
+
}
|
|
247
303
|
export async function needsAdmin(p, out) {
|
|
248
304
|
const r = await adminClient(p).call("GET", "/account/needs");
|
|
249
305
|
if (!r.needs.length)
|
|
@@ -311,13 +367,22 @@ export async function notifierAdmin(p, out) {
|
|
|
311
367
|
const rep = intFlag(str(p.flags, "repeat"), "repeat");
|
|
312
368
|
if (rep !== undefined)
|
|
313
369
|
patch.repeat_minutes = rep;
|
|
370
|
+
const flowSummary = yesNo(str(p.flags, "flow-summary"), "flow-summary");
|
|
371
|
+
if (flowSummary !== undefined)
|
|
372
|
+
patch.flow_summary = flowSummary;
|
|
373
|
+
const flowAge = intFlag(str(p.flags, "flow-min-age"), "flow-min-age");
|
|
374
|
+
if (flowAge !== undefined)
|
|
375
|
+
patch.flow_min_age_minutes = flowAge;
|
|
376
|
+
const flowImpact = intFlag(str(p.flags, "flow-min-impact"), "flow-min-impact");
|
|
377
|
+
if (flowImpact !== undefined)
|
|
378
|
+
patch.flow_min_impact = flowImpact;
|
|
314
379
|
if (Object.keys(patch).length)
|
|
315
380
|
await c.call("PATCH", "/account/notifier", patch);
|
|
316
381
|
const r = await c.call("GET", "/account/notifier");
|
|
317
382
|
const n = r.notifier;
|
|
318
383
|
const l = n.last_delivery;
|
|
319
384
|
out.print([
|
|
320
|
-
`notifier agent: ${n.agent ?? "none"} · email: ${n.email ? (n.email_to === undefined ? "on (this server does not report the address; it predates the notifier fix)" : n.email_to ?? "(the account has no contact email)") : "off"} · repeat after ${n.repeat_minutes} min`,
|
|
385
|
+
`notifier agent: ${n.agent ?? "none"} · email: ${n.email ? (n.email_to === undefined ? "on (this server does not report the address; it predates the notifier fix)" : n.email_to ?? "(the account has no contact email)") : "off"} · repeat after ${n.repeat_minutes} min · Flow summary ${n.flow_summary ? `on (age ${n.flow_min_age_minutes} min or impact ${n.flow_min_impact})` : "off"}`,
|
|
321
386
|
l ? `last report ${l.at.slice(0, 16).replace("T", " ")} UTC (${l.project}, ${l.items} item${l.items === 1 ? "" : "s"})${l.agent ? `\n ${l.agent.ok ? "ok " : "FAIL"} ${l.agent.name}: ${l.agent.detail}` : ""}${l.email ? `\n ${l.email.ok ? "ok " : "FAIL"} email ${l.email.to}: ${l.email.detail}` : ""}` : "nothing reported yet",
|
|
322
387
|
].join("\n"), r);
|
|
323
388
|
}
|
package/dist/commands/turn.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { str } from "../args.js";
|
|
2
|
-
import { resolveAgentName } from "../config.js";
|
|
2
|
+
import { loadAgent, resolveAgentName } from "../config.js";
|
|
3
|
+
import { Client } from "../client.js";
|
|
3
4
|
import { readState, writeState } from "../state.js";
|
|
4
5
|
import { CliError } from "../errors.js";
|
|
5
6
|
/** Explicit, local turn-end note; the watcher sends it only as a bounded unverified excerpt. */
|
|
6
7
|
export async function turn(p, out) {
|
|
7
8
|
const name = resolveAgentName(str(p.flags, "as"));
|
|
8
9
|
const sub = p.positionals[1];
|
|
10
|
+
if (sub === "state")
|
|
11
|
+
return turnState(p, out, name);
|
|
9
12
|
if (sub !== "note")
|
|
10
|
-
throw new CliError("usage", 'turn note "short progress summary"');
|
|
13
|
+
throw new CliError("usage", 'turn note "short progress summary" | turn state [--session <id>]');
|
|
11
14
|
const state = readState(name);
|
|
12
15
|
const attempt = state.turn_guard?.turns.slice().reverse().find((item) => item.productive === null);
|
|
13
16
|
if (!attempt?.telemetry_enabled || !attempt.turn_id || !process.env.BSCHAT_MACHINE_SESSION_ID) {
|
|
@@ -19,3 +22,29 @@ export async function turn(p, out) {
|
|
|
19
22
|
writeState(name, { ...state, turn_note: note });
|
|
20
23
|
out.print("saved a turn-end note; it will be shown as unverified context in the account-scoped judgment packet", { saved: true });
|
|
21
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The candidate's own view of turn policy and any judgment holding it: the pause reason and the
|
|
27
|
+
* next action, never another session's packet or another account's records.
|
|
28
|
+
*/
|
|
29
|
+
async function turnState(p, out, name) {
|
|
30
|
+
const session = str(p.flags, "session") ?? process.env.BSCHAT_MACHINE_SESSION_ID;
|
|
31
|
+
if (!session)
|
|
32
|
+
throw new CliError("usage", "turn state needs --session <id> (a machine-managed session sets BSCHAT_MACHINE_SESSION_ID)");
|
|
33
|
+
const view = await Client.forAgent(loadAgent(name), undefined, { presence: false }).call("GET", `/agents/me/sessions/${session}/turn-state`);
|
|
34
|
+
const j = view.judgment;
|
|
35
|
+
const lines = [
|
|
36
|
+
`turn policy: ${view.enabled ? "on" : "off"}${view.capture_enabled ? ", judgment capture on" : ""}`,
|
|
37
|
+
`session: ${view.paused ? `paused (${view.state ?? "paused"})` : "runnable"}`,
|
|
38
|
+
];
|
|
39
|
+
if (j) {
|
|
40
|
+
lines.push(`judgment ${j.id ?? ""}: ${j.state ?? "unknown"}${j.trigger_reasons?.length ? ` from ${j.trigger_reasons.join(", ")}` : ""}`);
|
|
41
|
+
if (j.verdict)
|
|
42
|
+
lines.push(`verdict: ${j.verdict} (confidence ${j.confidence ?? "unknown"})${j.status_reason ? ` — ${j.status_reason}` : ""}${j.verdict_reason ? `: ${j.verdict_reason}` : ""}`);
|
|
43
|
+
if (j.grant_expires_at)
|
|
44
|
+
lines.push(`continuation: ${j.grant_turns_used ?? 0} of 5 turns used, until ${j.grant_expires_at}`);
|
|
45
|
+
lines.push(`next: ${j.next_action ?? "none"}`);
|
|
46
|
+
}
|
|
47
|
+
if (view.meter_hold)
|
|
48
|
+
lines.push(`unresolved turn usage: reservation ${view.meter_hold.reservation_id} (${view.meter_hold.meter_status}) — operator reconciliation`);
|
|
49
|
+
out.print(lines.join("\n"), view);
|
|
50
|
+
}
|
package/dist/commands/watch.js
CHANGED
|
@@ -726,7 +726,6 @@ export function estimatedTurnCostMicros(reservation, tokens) {
|
|
|
726
726
|
}
|
|
727
727
|
const TURN_RETRY_MS = 5 * 60_000;
|
|
728
728
|
const KEY_CHECK_MS = 5 * 60_000;
|
|
729
|
-
const MACHINE_PRESSURE_NOTICE_INTERVAL_MS = 30 * 60_000;
|
|
730
729
|
const GiB = 1024 ** 3;
|
|
731
730
|
let lastDiskRefusal = null;
|
|
732
731
|
/**
|
package/dist/commands/wu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import { lstatSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { bool, str } from "../args.js";
|
|
5
5
|
import { Client } from "../client.js";
|
|
@@ -1592,7 +1592,7 @@ export async function lock(p, out) {
|
|
|
1592
1592
|
const lockName = p.positionals[1];
|
|
1593
1593
|
if (cmd === "locks") {
|
|
1594
1594
|
const r = await client.call("GET", `/projects/${project}/locks`);
|
|
1595
|
-
out.print(r.locks.length ? r.locks.map((l) => `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${l.holder_name ? `held by ${l.holder_name}${l.unit ? ` (WU #${l.unit})` : ""} since ${l.acquired_at.slice(11, 16)} UTC` : "free"}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}`).join(", ")}` : ""}`).join("\n") : "No locks in this project. Take one with: b9s lock <name> [--unit n]", r);
|
|
1595
|
+
out.print(r.locks.length ? r.locks.map((l) => `${l.name}${l.machine ? ` on ${l.machine}` : " (shared)"}: ${l.holder_name ? `held by ${l.holder_name}${l.unit ? ` (WU #${l.unit})` : ""}${l.holder_legacy === 1 ? " (legacy, no token)" : l.holder_job_id ? ` job ${l.holder_job_id}` : ""}${l.note ? `: ${l.note}` : ""} since ${l.acquired_at.slice(11, 16)} UTC` : "free"}${l.waiting.length ? ` · waiting: ${l.waiting.map((w) => `${w.name}${w.unit ? ` (#${w.unit})` : ""}${w.legacy === 1 ? " (legacy, no token)" : w.job_id ? ` job ${w.job_id}` : ""}${w.note ? `: ${w.note}` : ""}`).join(", ")}` : ""}`).join("\n") : "No locks in this project. Take one with: b9s lock <name> [--unit n]", r);
|
|
1596
1596
|
return;
|
|
1597
1597
|
}
|
|
1598
1598
|
if (!lockName)
|
|
@@ -1606,24 +1606,45 @@ export async function lock(p, out) {
|
|
|
1606
1606
|
throw new CliError("usage", "--remove-empty is only valid with b9s unlock <name>");
|
|
1607
1607
|
if (cmd === "unlock") {
|
|
1608
1608
|
const removeEmpty = bool(p.flags, "remove-empty");
|
|
1609
|
-
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/release`, { shared: bool(p.flags, "shared"), machine: str(p.flags, "machine"), ...(removeEmpty ? { remove_empty: true } : {}) });
|
|
1609
|
+
const r = await client.call("POST", `/projects/${project}/locks/${lockName}/release`, { shared: bool(p.flags, "shared"), machine: str(p.flags, "machine"), ...(removeEmpty ? { remove_empty: true } : { job_token: str(p.flags, "token") }) });
|
|
1610
1610
|
if (removeEmpty) {
|
|
1611
1611
|
out.print(`${lockName} removed as an empty lock.`, r);
|
|
1612
1612
|
return;
|
|
1613
1613
|
}
|
|
1614
|
-
|
|
1614
|
+
const holder = r.lock.holder_name ? `held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}` : "free";
|
|
1615
|
+
out.print(r.action === "left_queue" ? `Left the ${lockName} queue; ${holder}.` : r.action === "released" ? `${lockName} released; ${holder}.` : `${lockName} state updated; ${holder}.`, r);
|
|
1615
1616
|
return;
|
|
1616
1617
|
}
|
|
1617
1618
|
if (str(p.flags, "machine") !== undefined)
|
|
1618
1619
|
throw new CliError("usage", "lock acquisition is scoped to the host running the CLI; --machine is only for unlock");
|
|
1619
1620
|
const unit = str(p.flags, "unit");
|
|
1620
1621
|
// Scoped to this machine unless --shared: the resource is this box's CPU and disk.
|
|
1621
|
-
const
|
|
1622
|
+
const token = str(p.flags, "token") ?? `b9sjob_${randomBytes(24).toString("hex")}`;
|
|
1623
|
+
const jobId = createHash("sha256").update(token).digest("hex").slice(0, 12);
|
|
1624
|
+
const machine = defaultMachine();
|
|
1625
|
+
const unlockCommand = `b9s unlock ${lockName}${bool(p.flags, "shared") ? " --shared" : ""} --token ${token}`;
|
|
1626
|
+
let r;
|
|
1627
|
+
try {
|
|
1628
|
+
r = await client.call("POST", `/projects/${project}/locks/${lockName}/acquire`, { unit: unit ? Number(unit) : null, ...(str(p.flags, "note") !== undefined ? { note: str(p.flags, "note") } : {}), shared: bool(p.flags, "shared"), machine, job_token: token });
|
|
1629
|
+
}
|
|
1630
|
+
catch (error) {
|
|
1631
|
+
if (error instanceof WrittenReceiptMismatchError) {
|
|
1632
|
+
error.actionResult = `Lock request wrote successfully; inspect the response. Job token: ${token}`;
|
|
1633
|
+
throw error;
|
|
1634
|
+
}
|
|
1635
|
+
if (error instanceof CliError) {
|
|
1636
|
+
error.message += `. Job token: ${token}. Inspect the lock before retrying if the outcome is uncertain.`;
|
|
1637
|
+
throw error;
|
|
1638
|
+
}
|
|
1639
|
+
throw new CliError("lock_acquisition_failed", `Lock request failed (${error instanceof Error ? error.message : String(error)}). Job token: ${token}. Inspect the lock before retrying if the outcome is uncertain.`);
|
|
1640
|
+
}
|
|
1641
|
+
if (r.job_token !== token)
|
|
1642
|
+
throw new CliError("lock_protocol_mismatch", `The server did not confirm job ownership; do not start work. Inspect the lock state. Job token: ${token}`);
|
|
1622
1643
|
out.print(r.maintenance
|
|
1623
|
-
? `${lockName} is not handed out now: ${r.maintenance}.
|
|
1644
|
+
? `${lockName} is not handed out now: ${r.maintenance}. Job ${jobId} is #${r.position} in line. Job token: ${token}. Leave the queue: ${unlockCommand}`
|
|
1624
1645
|
: r.acquired
|
|
1625
|
-
? `
|
|
1626
|
-
: `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""};
|
|
1646
|
+
? `Job ${jobId} holds ${lockName}${r.lock.machine ? ` on ${r.lock.machine}` : " (shared)"}${r.lock.unit ? ` for WU #${r.lock.unit}` : ""}. Job token: ${token}. Release it when done: ${unlockCommand}`
|
|
1647
|
+
: `${lockName} is held by ${r.lock.holder_name}${r.lock.unit ? ` (WU #${r.lock.unit})` : ""}; job ${jobId} is ${r.position === 1 ? "next" : `#${r.position} in line`}. Job token: ${token}. Leave the queue: ${unlockCommand}`, r);
|
|
1627
1648
|
}
|
|
1628
1649
|
/**
|
|
1629
1650
|
* b9s ask-operator "what you need from them" --plain ".." --blocks ".." --if-yes ".." --if-no ".." [--propose ".."]:
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { CliError } from "./errors.js";
|
|
4
|
-
import { findIdentityFile, readIdentityFile } from "./harness.js";
|
|
4
|
+
import { findIdentityFile, readIdentityFile, identityWalkStoppedAt } from "./harness.js";
|
|
5
5
|
import { resolveModelDetailed } from "./model.js";
|
|
6
6
|
import { readState, writeState } from "./state.js";
|
|
7
7
|
import { detectVendor } from "./vendor.js";
|
|
@@ -164,7 +164,7 @@ export function resolveAgentName(asFlag, env = process.env, cwd = process.cwd())
|
|
|
164
164
|
}
|
|
165
165
|
if (!name) {
|
|
166
166
|
const saved = listSaved("agents", env);
|
|
167
|
-
throw new CliError("no_identity",
|
|
167
|
+
throw new CliError("no_identity", `BSCHAT_AGENT is not set and --as was not given; b9s cannot tell which agent you are${identityWalkStoppedAt() ? ` (it looked for this checkout's identity file up to ${identityWalkStoppedAt()}, where it is not permitted to look)` : ""}`, saved.length
|
|
168
168
|
? `Saved identities on this machine: ${saved.join(", ")}. Ask the user which one is yours, then: export BSCHAT_AGENT=<project>/<name> (or run: b9s setup --as <project>/<name> to record it for this repo)`
|
|
169
169
|
: "No identities are saved here. Ask the account owner for an invite (an enrollment token) and run: npx -y benignswarm join --as <name> --token <bs_enroll_...>");
|
|
170
170
|
}
|