benignswarm 0.12.116 → 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/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/help.js
CHANGED
|
@@ -121,14 +121,18 @@ Agent commands
|
|
|
121
121
|
b9s milestone verdict <key> --met --note ".." [--evidence a,b] | --gaps ".." [--units n,m] [--waive-informs ".."] the closure reviewer judges the exit against the evidence; gap units re-trigger the review when they close
|
|
122
122
|
b9s milestone gap-units <key> --units n,m name the units (on any slice) that address its last gaps verdict: stops the chase, re-reviews when they close
|
|
123
123
|
b9s milestone review <key> assigner or operator: request a closure review now (the steward does it when the last unit closes)
|
|
124
|
-
b9s lock <name> [--unit n] [--note ..] [--shared] take this machine's <name>
|
|
124
|
+
b9s lock <name> [--unit n] [--note ..] [--shared] [--token <job-token>] take this machine's <name> or queue a distinct job; --shared for a project-wide resource
|
|
125
125
|
acquisition queues through a machine maintenance drain/window and resumes after it
|
|
126
126
|
machine identity is this host's hostname plus its registered label, shared by all agents here
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
save the returned job token; reuse --token to check/retry the same job
|
|
128
|
+
b9s unlock <name> --token <job-token> [--machine <label>|--shared] | b9s locks
|
|
129
|
+
b9s unlock <name> --remove-empty [--machine <label>|--shared]
|
|
130
|
+
new agent jobs release by token; legacy jobs retain identity release; assigners/operators may release without a token
|
|
131
|
+
closing a unit does not release a new job's lock
|
|
132
|
+
assigners/operators can remove an empty scoped lock with --remove-empty
|
|
129
133
|
lock names acquire/list/release/show/status are reserved: use lock <name>, locks, or unlock <name> as suggested
|
|
130
134
|
project locks are separate from account-wide weighted machine-job permits; a lock never grants permit capacity
|
|
131
|
-
Machine placement shares capacity across the account's projects: session seats and granted job permits consume one safe-memory budget; queued work is shown separately. Operators can read GET /machines/:m/placement for the slot ceiling, headroom, and pressure/freshness
|
|
135
|
+
Machine placement shares capacity across the account's projects: session seats and granted job permits consume one safe-memory budget; queued work is shown separately. Operators can read GET /machines/:m/placement for the slot ceiling, headroom, and pressure/freshness readings. Current pressure is telemetry and does not gate admission; safe-memory budget, freshness, maintenance, quarantine and operator admission pause remain admission inputs.
|
|
132
136
|
b9s measures latest measure values, freshness and merges since each value
|
|
133
137
|
b9s measure show <name> definition history, values and runner requests
|
|
134
138
|
b9s measure run <name> --sha <commit> [--target branch] [--rerun] request a bounded runner unit
|
|
@@ -237,6 +241,7 @@ Machine placement shares capacity across the account's projects: session seats a
|
|
|
237
241
|
(b9s codex start is the same with --harness codex)
|
|
238
242
|
b9s unpause [--as <a>] lift a usage-limit pause now (the harness was switched to an account with quota)
|
|
239
243
|
b9s turn note "<short progress summary>" [--as <a>] save a 300-character turn-end excerpt for an enabled managed session; it is labelled unverified
|
|
244
|
+
b9s turn state [--session <id>] this session's turn policy, any judge pause/stop/continuation and the next action (never another session's packet)
|
|
240
245
|
b9s machine bootstrap --url <api> [--retrieve-ec2 | --token-file <path> | --token <bs_boot_...>] [--name <m>] retrieve (over TLS+IMDSv2/STS) and exchange a single-use cloud bootstrap token once, scrub it, and write mode-0600 credentials
|
|
241
246
|
b9s machine run [--interval seconds] | once | build-images | status | prepare [--agy-userns] [--print-apparmor] | service
|
|
242
247
|
default interval 30s, 1..3600; prepare checks harnesses; --agy-userns opts into an AppArmor
|
|
@@ -378,17 +383,20 @@ the returned object and warning, then exits 3. Inspect the object and do not ret
|
|
|
378
383
|
read-only state counts, waits, qualified worker/reviewer capacity, critical paths, attention, trends, freshness and coverage
|
|
379
384
|
b9s-admin role edit <name> [--project p] --reviews a,b --works c --trials d which tags a role reviews, works and trials ("*" all, "" none)
|
|
380
385
|
--assign-outside-qualifications yes|no allow assigners in this role to make reasoned ownership exceptions; dispatch stays qualified
|
|
386
|
+
--judges yes|no the turn-judge capability: this role may be chosen as the independent judge (docs/TURN-JUDGE.md)
|
|
381
387
|
b9s-admin needs decisions waiting on you (asks, unit questions, broken wake paths, alert failures)
|
|
382
388
|
b9s-admin answer <key> "decision" answer one; the asker is @mentioned
|
|
383
389
|
b9s-admin answer <key> --approve [--assign <agent>] [--note ".."] accept an ask proposal and name its action owner
|
|
384
390
|
b9s-admin answer <key> --approve [--note ".."] accept a unit-question proposal as written
|
|
385
391
|
b9s-admin explain <key> ask the agent to explain a decision in plain words (the console's Explain)
|
|
386
|
-
b9s-admin notifier [--agent name|none] [--email yes|no] [--repeat m] how you are reached away from the console, and the last report
|
|
392
|
+
b9s-admin notifier [--agent name|none] [--email yes|no] [--repeat m] [--flow-summary yes|no] [--flow-min-age m] [--flow-min-impact n] how you are reached away from the console, and the last report
|
|
387
393
|
b9s-admin account [--summary-minutes m] plan, usage and the account summary period
|
|
388
394
|
assistant stays opt-in: PATCH /account {"assistant_enabled":true|false}; GET /account/usage shows used, allowance, uncertain calls and reset date
|
|
389
395
|
session/admin clients use GET /assistant/conversations/:id/messages for paged history and GET/POST/DELETE /assistant/conversations; POST messages streams data and saves tool notices with assistant messages; old assistant messages have notices_available=false; operator must explicitly apply or discard (see operator skill)
|
|
390
396
|
POST /assistant/proposals/:id/apply|discard applies or discards the operator-reviewed draft (see operator skill)
|
|
391
397
|
b9s-admin worktree forget <project> <id> delete a stale worktree record (never the directory)
|
|
398
|
+
b9s-admin turn-judgment list|show <id> what the independent turn judge decided for a paused session (packet and audit only here)
|
|
399
|
+
b9s-admin turn-judgment override <id> --reason "why" resume a judged pause/stop; the reason is audited and never raises a budget
|
|
392
400
|
|
|
393
401
|
Machines (provisioned over your own ssh; a daemon on each runs the agent sessions you declare)
|
|
394
402
|
Account Mac leases and trusted TestFlight signing approvals are managed in Console → Machines → Mac fleet and signing; there is no CLI signing or App Store release command.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { antigravityTurnArgs, parseAntigravityJson } from "./antigravity.js";
|
|
4
|
+
import { claudeResultError, dshResultError } from "./harnesses.js";
|
|
5
|
+
import { claudeProviderEnv } from "./providers.js";
|
|
6
|
+
/** The cache is invalidated by any change to the harness binary, selected model, or login. */
|
|
7
|
+
export function modelCheckCacheKey(harness, harnessVersion, model, accountFingerprint) {
|
|
8
|
+
return JSON.stringify([harness, harnessVersion, model, accountFingerprint]);
|
|
9
|
+
}
|
|
10
|
+
function harnessFacts(report, harness, provider) {
|
|
11
|
+
const value = harness === "claude-code" ? report.claude_code ?? report[harness] : report[harness];
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
+
return null;
|
|
14
|
+
const facts = value;
|
|
15
|
+
const providerFacts = provider && facts.providers && typeof facts.providers === "object"
|
|
16
|
+
? facts.providers[provider] : null;
|
|
17
|
+
return providerFacts && typeof providerFacts === "object" && !Array.isArray(providerFacts)
|
|
18
|
+
? { ...facts, ...providerFacts }
|
|
19
|
+
: facts;
|
|
20
|
+
}
|
|
21
|
+
export function modelCheckRuntimeTuple(report, request) {
|
|
22
|
+
const facts = harnessFacts(report, request.harness, request.provider);
|
|
23
|
+
return {
|
|
24
|
+
version: typeof facts?.version === "string" && facts.version.trim() ? facts.version.trim() : null,
|
|
25
|
+
account: typeof facts?.account_fingerprint === "string" && facts.account_fingerprint ? facts.account_fingerprint : null,
|
|
26
|
+
ready: request.harness === "dsh" ? facts?.available === true
|
|
27
|
+
: request.harness === "antigravity" ? facts?.available === true && facts?.logged_in === true
|
|
28
|
+
: facts?.logged_in === true,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Runs each requested tuple once and returns cached, versioned results for the machine report. */
|
|
32
|
+
export function collectModelChecks(requests, report, cache, path, probe = probeModelRun, now = new Date()) {
|
|
33
|
+
const unique = new Map();
|
|
34
|
+
for (const request of requests)
|
|
35
|
+
if (request && typeof request.harness === "string" && typeof request.model === "string" && request.model.trim()) {
|
|
36
|
+
unique.set(JSON.stringify([request.harness, request.model, request.provider ?? "anthropic"]), request);
|
|
37
|
+
}
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const request of unique.values()) {
|
|
40
|
+
const facts = harnessFacts(report, request.harness, request.provider);
|
|
41
|
+
const version = typeof facts?.version === "string" && facts.version.trim() ? facts.version.trim() : null;
|
|
42
|
+
const account = typeof facts?.account_fingerprint === "string" && facts.account_fingerprint ? facts.account_fingerprint : null;
|
|
43
|
+
const key = modelCheckCacheKey(request.harness, version, request.model, account);
|
|
44
|
+
let entry = cache[key];
|
|
45
|
+
// Older releases cached readiness failures as unknown under the same tuple key. They did
|
|
46
|
+
// not test the model, so discard them and let a now-ready harness run the actual probe.
|
|
47
|
+
if (entry?.status === "unknown" && entry.probe_attempted !== true) {
|
|
48
|
+
delete cache[key];
|
|
49
|
+
entry = undefined;
|
|
50
|
+
}
|
|
51
|
+
if (!entry) {
|
|
52
|
+
const available = request.harness === "dsh" ? facts?.available === true
|
|
53
|
+
: request.harness === "antigravity" ? facts?.available === true && facts?.logged_in === true
|
|
54
|
+
: facts?.logged_in === true;
|
|
55
|
+
const probeAttempted = !!version && !!account && available;
|
|
56
|
+
const result = probeAttempted
|
|
57
|
+
? probe(request, { path, provider: request.provider, ...(typeof facts?.path === "string" ? { bin: facts.path } : {}) })
|
|
58
|
+
: { status: "unknown", message: !version ? "harness version is unavailable" : !account ? "harness account identity is unavailable" : !available ? "harness is not ready or logged in" : "model check unavailable" };
|
|
59
|
+
entry = {
|
|
60
|
+
cache_key: key, harness: request.harness, model: request.model, ...(request.provider ? { provider: request.provider } : {}), status: result.status,
|
|
61
|
+
message: result.message, harness_version: version, account_fingerprint: account, probe_attempted: probeAttempted,
|
|
62
|
+
checked_at: now.toISOString(),
|
|
63
|
+
};
|
|
64
|
+
// A readiness failure is temporary and did not test the model; keep it for this report
|
|
65
|
+
// only. Caching it would mask a later login/readiness recovery for the same tuple.
|
|
66
|
+
if (probeAttempted)
|
|
67
|
+
cache[key] = entry;
|
|
68
|
+
}
|
|
69
|
+
const { cache_key: _key, probe_attempted: _probeAttempted, ...fact } = entry;
|
|
70
|
+
if (request.provider)
|
|
71
|
+
fact.provider = request.provider;
|
|
72
|
+
out.push(fact);
|
|
73
|
+
}
|
|
74
|
+
return out.sort((a, b) => a.harness.localeCompare(b.harness) || a.model.localeCompare(b.model) || (a.provider ?? "").localeCompare(b.provider ?? ""));
|
|
75
|
+
}
|
|
76
|
+
const modelProbeQueue = [];
|
|
77
|
+
const modelProbePending = new Set();
|
|
78
|
+
const modelProbeCompleted = new Map();
|
|
79
|
+
let modelProbeQueueRunning = false;
|
|
80
|
+
function requestedModels(requests) {
|
|
81
|
+
const unique = new Map();
|
|
82
|
+
for (const request of requests)
|
|
83
|
+
if (request && typeof request.harness === "string" && typeof request.model === "string" && request.model.trim()) {
|
|
84
|
+
unique.set(JSON.stringify([request.harness, request.model, request.provider ?? "anthropic"]), request);
|
|
85
|
+
}
|
|
86
|
+
return [...unique.values()].sort((a, b) => a.harness.localeCompare(b.harness) || a.model.localeCompare(b.model) || (a.provider ?? "").localeCompare(b.provider ?? ""));
|
|
87
|
+
}
|
|
88
|
+
function availableForProbe(request, facts) {
|
|
89
|
+
return request.harness === "dsh" ? facts?.available === true
|
|
90
|
+
: request.harness === "antigravity" ? facts?.available === true && facts?.logged_in === true
|
|
91
|
+
: facts?.logged_in === true;
|
|
92
|
+
}
|
|
93
|
+
function modelCheckUnknown(request, version, account, message, now) {
|
|
94
|
+
return {
|
|
95
|
+
harness: request.harness, model: request.model, ...(request.provider ? { provider: request.provider } : {}), status: "unknown",
|
|
96
|
+
message, harness_version: version, account_fingerprint: account, checked_at: now.toISOString(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function tupleStillMatches(item) {
|
|
100
|
+
try {
|
|
101
|
+
const current = item.readTuple(item.request);
|
|
102
|
+
return current.ready && current.version === item.version && current.account === item.account;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function drainModelProbeQueue() {
|
|
109
|
+
if (modelProbeQueueRunning)
|
|
110
|
+
return;
|
|
111
|
+
modelProbeQueueRunning = true;
|
|
112
|
+
void (async () => {
|
|
113
|
+
try {
|
|
114
|
+
while (modelProbeQueue.length) {
|
|
115
|
+
const item = modelProbeQueue.shift();
|
|
116
|
+
if (!tupleStillMatches(item)) {
|
|
117
|
+
modelProbePending.delete(item.key);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
result = await item.probe(item.request, { path: item.path, provider: item.request.provider, ...(item.bin ? { bin: item.bin } : {}) });
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
result = { status: "unknown", message: error instanceof Error ? error.message.slice(0, 300) : "model probe failed" };
|
|
126
|
+
}
|
|
127
|
+
if (!tupleStillMatches(item)) {
|
|
128
|
+
modelProbePending.delete(item.key);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const entry = {
|
|
132
|
+
cache_key: item.key, harness: item.request.harness, model: item.request.model,
|
|
133
|
+
...(item.request.provider ? { provider: item.request.provider } : {}), status: result.status, message: result.message,
|
|
134
|
+
harness_version: item.version, account_fingerprint: item.account, probe_attempted: true, checked_at: new Date().toISOString(),
|
|
135
|
+
};
|
|
136
|
+
modelProbeCompleted.set(item.key, entry);
|
|
137
|
+
modelProbePending.delete(item.key);
|
|
138
|
+
try {
|
|
139
|
+
item.persist(entry);
|
|
140
|
+
}
|
|
141
|
+
catch { /* Keep the in-process result; a later report can persist it again. */ }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
modelProbeQueueRunning = false;
|
|
146
|
+
if (modelProbeQueue.length)
|
|
147
|
+
drainModelProbeQueue();
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Return immediately from the daemon report path. Cold model probes run one at a time in a
|
|
153
|
+
* background queue and their actual outcomes are persisted for a subsequent report.
|
|
154
|
+
*/
|
|
155
|
+
export function collectModelChecksQueued(requests, report, cache, path, probe = probeModelRunAsync, persist = () => { }, now = new Date(), readTuple = (request) => modelCheckRuntimeTuple(report, request)) {
|
|
156
|
+
const scheduled = [];
|
|
157
|
+
const out = requestedModels(requests).map((request) => {
|
|
158
|
+
const facts = harnessFacts(report, request.harness, request.provider);
|
|
159
|
+
const { version, account } = modelCheckRuntimeTuple(report, request);
|
|
160
|
+
const key = modelCheckCacheKey(request.harness, version, request.model, account);
|
|
161
|
+
let entry = modelProbeCompleted.get(key) ?? cache[key];
|
|
162
|
+
if (entry?.status === "unknown" && entry.probe_attempted !== true) {
|
|
163
|
+
delete cache[key];
|
|
164
|
+
modelProbeCompleted.delete(key);
|
|
165
|
+
entry = undefined;
|
|
166
|
+
}
|
|
167
|
+
if (entry) {
|
|
168
|
+
const { cache_key: _key, probe_attempted: _attempted, ...fact } = entry;
|
|
169
|
+
return fact;
|
|
170
|
+
}
|
|
171
|
+
if (!version || !account || !availableForProbe(request, facts)) {
|
|
172
|
+
const message = !version ? "harness version is unavailable" : !account ? "harness account identity is unavailable" : "harness is not ready or logged in";
|
|
173
|
+
return modelCheckUnknown(request, version, account, message, now);
|
|
174
|
+
}
|
|
175
|
+
if (!modelProbePending.has(key)) {
|
|
176
|
+
modelProbePending.add(key);
|
|
177
|
+
scheduled.push({
|
|
178
|
+
request, key, version, account, path,
|
|
179
|
+
...(typeof facts?.path === "string" ? { bin: facts.path } : {}), probe, persist,
|
|
180
|
+
readTuple,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return modelCheckUnknown(request, version, account, "model probe is queued or running; result will appear on a later machine report", now);
|
|
184
|
+
});
|
|
185
|
+
modelProbeQueue.push(...scheduled);
|
|
186
|
+
drainModelProbeQueue();
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
const MODEL_PROBE_TIMEOUT_MS = 120_000;
|
|
190
|
+
const MODEL_PROBE_MAX_BUFFER = 1024 * 1024;
|
|
191
|
+
const UNSUPPORTED_MODEL = /not supported|unsupported model|model.{0,40}(not available|unavailable)|not available for (?:this|your) account/i;
|
|
192
|
+
function probeInvocation(request, context) {
|
|
193
|
+
let env = { ...process.env, PATH: context.path };
|
|
194
|
+
if (request.harness === "claude-code" && context.provider === "deepseek") {
|
|
195
|
+
try {
|
|
196
|
+
env = { ...env, ...claudeProviderEnv("deepseek", context.providerRoot, request.model) };
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
return { error: error instanceof Error ? error.message.slice(0, 300) : "DeepSeek provider credentials are unavailable" };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const prompt = "Reply OK";
|
|
203
|
+
const args = request.harness === "codex"
|
|
204
|
+
? ["exec", "--model", request.model, "--sandbox", "read-only", "--skip-git-repo-check", prompt]
|
|
205
|
+
: request.harness === "claude-code"
|
|
206
|
+
? ["-p", prompt, "--model", request.model, "--output-format", "json"]
|
|
207
|
+
: request.harness === "dsh"
|
|
208
|
+
? ["--profile", "headless", "--json", "--model", request.model, "-"]
|
|
209
|
+
: request.harness === "antigravity"
|
|
210
|
+
? antigravityTurnArgs(prompt, request.model, undefined, 120, [])
|
|
211
|
+
: null;
|
|
212
|
+
if (!args)
|
|
213
|
+
return { error: `no model probe is configured for ${request.harness}` };
|
|
214
|
+
const bin = context.bin ?? (request.harness === "codex" ? "codex" : request.harness === "claude-code" ? "claude" : request.harness === "dsh" ? "dsh" : "agy");
|
|
215
|
+
return { invocation: {
|
|
216
|
+
bin, args, cwd: homedir(), input: request.harness === "dsh" ? prompt : "",
|
|
217
|
+
env: request.harness === "claude-code" && context.provider === "deepseek" ? { ...env, BSCHAT_PROVIDER: "deepseek" } : env,
|
|
218
|
+
} };
|
|
219
|
+
}
|
|
220
|
+
function classifyProbeResult(request, result) {
|
|
221
|
+
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`.trim();
|
|
222
|
+
const antigravityResult = request.harness === "antigravity" ? parseAntigravityJson(result.stdout ?? "") : null;
|
|
223
|
+
const dshCompleted = request.harness === "dsh" && (result.stdout ?? "").split(/\r?\n/).some((line) => {
|
|
224
|
+
try {
|
|
225
|
+
const event = JSON.parse(line);
|
|
226
|
+
return event.type === "final" && event.reason?.kind === "completed";
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
const harnessError = request.harness === "claude-code" ? claudeResultError(result.stdout ?? "")
|
|
233
|
+
: request.harness === "dsh" ? dshResultError(output) : null;
|
|
234
|
+
if (result.status === 0 && !harnessError
|
|
235
|
+
&& (request.harness !== "antigravity" || (antigravityResult?.status === "SUCCESS" && !!antigravityResult.conversation_id))
|
|
236
|
+
&& (request.harness !== "dsh" || dshCompleted))
|
|
237
|
+
return { status: "ok", message: null };
|
|
238
|
+
const lines = output.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
239
|
+
const unsupportedLine = lines.find((line) => UNSUPPORTED_MODEL.test(line));
|
|
240
|
+
const message = (harnessError ?? unsupportedLine ?? lines[0] ?? (result.error instanceof Error ? result.error.message : `exit ${result.status ?? "unknown"}`)).slice(0, 300);
|
|
241
|
+
const unsupported = UNSUPPORTED_MODEL.test(message) || lines.some((line) => UNSUPPORTED_MODEL.test(line));
|
|
242
|
+
return { status: unsupported ? "unsupported" : "unknown", message };
|
|
243
|
+
}
|
|
244
|
+
/** A bounded, read-only single-turn request; error text is kept short and never includes env data. */
|
|
245
|
+
export function probeModelRun(request, context, run = spawnSync) {
|
|
246
|
+
const built = probeInvocation(request, context);
|
|
247
|
+
if (!built.invocation)
|
|
248
|
+
return { status: "unknown", message: built.error ?? "model probe is unavailable" };
|
|
249
|
+
const result = run(built.invocation.bin, built.invocation.args, {
|
|
250
|
+
encoding: "utf8", timeout: MODEL_PROBE_TIMEOUT_MS, maxBuffer: MODEL_PROBE_MAX_BUFFER,
|
|
251
|
+
cwd: built.invocation.cwd,
|
|
252
|
+
env: built.invocation.env,
|
|
253
|
+
...(request.harness === "dsh" ? { input: built.invocation.input } : {}),
|
|
254
|
+
});
|
|
255
|
+
return classifyProbeResult(request, result);
|
|
256
|
+
}
|
|
257
|
+
/** Run a probe without blocking the machine report/reconcile loop. Probes are queued serially. */
|
|
258
|
+
export function probeModelRunAsync(request, context) {
|
|
259
|
+
const built = probeInvocation(request, context);
|
|
260
|
+
if (!built.invocation)
|
|
261
|
+
return Promise.resolve({ status: "unknown", message: built.error ?? "model probe is unavailable" });
|
|
262
|
+
const invocation = built.invocation;
|
|
263
|
+
return new Promise((resolve) => {
|
|
264
|
+
const child = spawn(invocation.bin, invocation.args, {
|
|
265
|
+
cwd: invocation.cwd, env: invocation.env, stdio: ["pipe", "pipe", "pipe"],
|
|
266
|
+
});
|
|
267
|
+
const stdout = [];
|
|
268
|
+
const stderr = [];
|
|
269
|
+
let bytes = 0;
|
|
270
|
+
let overflow = false;
|
|
271
|
+
let timedOut = false;
|
|
272
|
+
let settled = false;
|
|
273
|
+
let killTimer;
|
|
274
|
+
const timeout = setTimeout(() => {
|
|
275
|
+
timedOut = true;
|
|
276
|
+
child.kill("SIGTERM");
|
|
277
|
+
killTimer = setTimeout(() => child.kill("SIGKILL"), 2_000);
|
|
278
|
+
}, MODEL_PROBE_TIMEOUT_MS);
|
|
279
|
+
const finish = (result) => {
|
|
280
|
+
if (settled)
|
|
281
|
+
return;
|
|
282
|
+
settled = true;
|
|
283
|
+
clearTimeout(timeout);
|
|
284
|
+
if (killTimer)
|
|
285
|
+
clearTimeout(killTimer);
|
|
286
|
+
resolve(classifyProbeResult(request, result));
|
|
287
|
+
};
|
|
288
|
+
const collect = (target, chunk) => {
|
|
289
|
+
bytes += chunk.length;
|
|
290
|
+
if (bytes > MODEL_PROBE_MAX_BUFFER) {
|
|
291
|
+
overflow = true;
|
|
292
|
+
child.kill("SIGTERM");
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
target.push(chunk.toString("utf8"));
|
|
296
|
+
};
|
|
297
|
+
child.stdout.on("data", (chunk) => collect(stdout, chunk));
|
|
298
|
+
child.stderr.on("data", (chunk) => collect(stderr, chunk));
|
|
299
|
+
child.on("error", (error) => finish({ status: null, stdout: stdout.join(""), stderr: stderr.join(""), error }));
|
|
300
|
+
child.on("close", (status) => finish({
|
|
301
|
+
status: timedOut || overflow ? null : status,
|
|
302
|
+
stdout: stdout.join(""), stderr: stderr.join(""),
|
|
303
|
+
...(timedOut ? { error: new Error("model probe timed out after 120 seconds") } : overflow ? { error: new Error("model probe output exceeded 1 MiB") } : {}),
|
|
304
|
+
}));
|
|
305
|
+
child.stdin.end(invocation.input);
|
|
306
|
+
});
|
|
307
|
+
}
|
package/dist/output.js
CHANGED
|
@@ -51,9 +51,9 @@ export function fmtMessage(m) {
|
|
|
51
51
|
return `${m.created_at.slice(11, 19)} ${ch}${String(m.seq).padStart(5)} ${m.agent_name}${role}: ${m.body}`;
|
|
52
52
|
}
|
|
53
53
|
export function fmtStatus(s) {
|
|
54
|
-
const machineWaiting = s.
|
|
54
|
+
const machineWaiting = s.machine_job_waiting === true;
|
|
55
55
|
const parts = [
|
|
56
|
-
`${s.state === "benched" ? "BENCHED " : ""}${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.usage_limit_until ? ` (usage limit until ${s.usage_limit_until})` : machineWaiting
|
|
56
|
+
`${s.state === "benched" ? "BENCHED " : ""}${s.agent_name}${s.role_name ? `[${s.role_name}]` : ""}${s.away ? ` (away until ${s.away.until}: ${s.away.reason})` : s.usage_limit_until ? ` (usage limit until ${s.usage_limit_until})` : machineWaiting ? " (waiting: heavy machine permit)" : s.liveness === "quiet" ? " (quiet: harness went silent)" : s.liveness === "unknown" ? " (stale, harness unmonitored)" : s.liveness === "scheduled" ? ` (checks every ${s.checks_every} min, next ${(s.next_check_at ?? "").slice(11, 16)} UTC)` : s.liveness === "missed" ? ` (missed its ${s.checks_every}-min check)` : ""}`,
|
|
57
57
|
`state=${s.state ?? "-"}`,
|
|
58
58
|
s.goal ? `goal="${s.goal}"` : null,
|
|
59
59
|
s.task ? `task="${s.task}"` : null,
|
|
@@ -61,8 +61,7 @@ export function fmtStatus(s) {
|
|
|
61
61
|
`model=${s.model ?? "-"}`,
|
|
62
62
|
s.machine ? `machine=${s.machine}` : null,
|
|
63
63
|
s.machine_pressure ? `machine_health=${s.machine_pressure.state ?? "unknown"} (sample_age=${typeof s.machine_pressure.age_seconds === "number" ? `${Math.floor(s.machine_pressure.age_seconds)}s` : "unknown"}${s.machine_pressure.reasons?.length ? `; reasons=${s.machine_pressure.reasons.join(",")}` : ""})` : null,
|
|
64
|
-
|
|
65
|
-
machineWaiting && !s.machine_pressure.blocks_turns ? "machine_wait=heavy_permit" : null,
|
|
64
|
+
machineWaiting ? "machine_wait=heavy_permit" : null,
|
|
66
65
|
s.capabilities?.length ? `capabilities=${s.capabilities.map((c) => `${c.name}:${c.ready ? c.version ?? "ok" : c.error ?? "stale/unknown"}`).join(",")}` : null,
|
|
67
66
|
s.branch ? `branch=${s.branch}${s.dirty ? "*" : ""}@${s.head ?? "?"}` : null,
|
|
68
67
|
s.worktree ? `worktree=${s.worktree}` : null,
|
package/dist/state.js
CHANGED
|
@@ -33,7 +33,9 @@ export function readState(ref, env = process.env) {
|
|
|
33
33
|
// Never started over silently: cursors, wake numbers and follows live here.
|
|
34
34
|
throw new CliError("corrupt_state", `${p} is not valid JSON (${text.length} bytes): a write to it was cut short`, "Check free disk space on this machine, then repair the file or move it aside (the agent then starts from fresh cursors and its wake-up numbering restarts)");
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const current = saved;
|
|
37
|
+
delete current.machine_pressure_notice;
|
|
38
|
+
return { inbox_after: "", last_check: 0, ...current };
|
|
37
39
|
}
|
|
38
40
|
export function writeState(agent, state, env = process.env) {
|
|
39
41
|
const p = stateFilePath(agent, env);
|
|
@@ -79,8 +81,6 @@ export function destinationStateIsNewer(source, destination) {
|
|
|
79
81
|
return true;
|
|
80
82
|
if (destination.turn_guard && JSON.stringify(destination.turn_guard) !== JSON.stringify(source.turn_guard))
|
|
81
83
|
return true;
|
|
82
|
-
if (destination.machine_pressure_notice?.last_notice_at && greater(source.machine_pressure_notice?.last_notice_at, destination.machine_pressure_notice.last_notice_at))
|
|
83
|
-
return true;
|
|
84
84
|
for (const [channel, seq] of Object.entries(destination.channel_read ?? {})) {
|
|
85
85
|
if (seq > (source.channel_read?.[channel] ?? 0))
|
|
86
86
|
return true;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.117";
|