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/directories.js
CHANGED
|
@@ -1,186 +1,15 @@
|
|
|
1
|
-
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readdirSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
2
1
|
import { homedir } from "node:os";
|
|
3
2
|
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
catch (error) {
|
|
10
|
-
const code = error.code;
|
|
11
|
-
if (code === "ENOENT" || code === "ENOTDIR")
|
|
12
|
-
return null;
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function directory(path) { return maybeLstat(path)?.isDirectory() ?? false; }
|
|
17
|
-
function present(path) { return maybeLstat(path) !== null; }
|
|
18
|
-
function treeEntries(root) {
|
|
19
|
-
const entries = new Map();
|
|
20
|
-
const visit = (path, relative) => {
|
|
21
|
-
const st = lstatSync(path);
|
|
22
|
-
if (st.isDirectory()) {
|
|
23
|
-
for (const name of readdirSync(path).sort())
|
|
24
|
-
visit(join(path, name), relative ? relative + "/" + name : name);
|
|
25
|
-
}
|
|
26
|
-
else if (st.isFile())
|
|
27
|
-
entries.set(relative, { kind: "file", path, size: st.size });
|
|
28
|
-
else if (st.isSymbolicLink())
|
|
29
|
-
entries.set(relative, { kind: "symlink", target: readlinkSync(path) });
|
|
30
|
-
else
|
|
31
|
-
entries.set(relative, { kind: "other", mode: st.mode });
|
|
32
|
-
};
|
|
33
|
-
visit(root, "");
|
|
34
|
-
return entries;
|
|
35
|
-
}
|
|
36
|
-
function sameFileBytes(left, right, size) {
|
|
37
|
-
const a = openSync(left, "r");
|
|
38
|
-
let b;
|
|
39
|
-
try {
|
|
40
|
-
b = openSync(right, "r");
|
|
41
|
-
const leftChunk = Buffer.allocUnsafe(64 * 1024);
|
|
42
|
-
const rightChunk = Buffer.allocUnsafe(64 * 1024);
|
|
43
|
-
let position = 0;
|
|
44
|
-
while (position < size) {
|
|
45
|
-
const expected = Math.min(leftChunk.length, size - position);
|
|
46
|
-
const nLeft = readSync(a, leftChunk, 0, expected, position);
|
|
47
|
-
const nRight = readSync(b, rightChunk, 0, expected, position);
|
|
48
|
-
if (nLeft !== nRight || nLeft === 0 || !leftChunk.subarray(0, nLeft).equals(rightChunk.subarray(0, nRight)))
|
|
49
|
-
return false;
|
|
50
|
-
position += nLeft;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
closeSync(a);
|
|
56
|
-
if (b !== undefined)
|
|
57
|
-
closeSync(b);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function differingFiles(left, right) {
|
|
61
|
-
const a = treeEntries(left);
|
|
62
|
-
const b = treeEntries(right);
|
|
63
|
-
return [...new Set([...a.keys(), ...b.keys()])].sort().filter((name) => {
|
|
64
|
-
const x = a.get(name);
|
|
65
|
-
const y = b.get(name);
|
|
66
|
-
if (!x || !y || x.kind !== y.kind)
|
|
67
|
-
return true;
|
|
68
|
-
if (x.kind === "file" && y.kind === "file")
|
|
69
|
-
return x.size !== y.size || !sameFileBytes(x.path, y.path, x.size);
|
|
70
|
-
if (x.kind === "symlink" && y.kind === "symlink")
|
|
71
|
-
return x.target !== y.target;
|
|
72
|
-
return x.kind === "other" && y.kind === "other" && x.mode !== y.mode;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function shellQuote(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
|
|
76
|
-
function conflictHint(current, old, currentName) {
|
|
77
|
-
let backup = old + ".conflict";
|
|
78
|
-
for (let n = 2; existsSync(backup); n++)
|
|
79
|
-
backup = old + ".conflict-" + n;
|
|
80
|
-
return "After reviewing the differences, keep " + current + " as the active copy and preserve the other at " + backup + ": mv -- " + shellQuote(old) + " " + shellQuote(backup) + " && ln -s -- " + shellQuote(currentName) + " " + shellQuote(old);
|
|
81
|
-
}
|
|
82
|
-
function conflictFiles(current, old, names, currentName) {
|
|
83
|
-
const details = names.map((name) => {
|
|
84
|
-
const a = join(current, name);
|
|
85
|
-
const b = join(old, name);
|
|
86
|
-
return (present(a) ? a : a + " (missing)") + " <> " + (present(b) ? b : b + " (missing)");
|
|
87
|
-
});
|
|
88
|
-
return new CliError("directory_conflict", "both " + current + " and " + old + " are real directories with different files: " + details.join("; "), conflictHint(current, old, currentName));
|
|
89
|
-
}
|
|
90
|
-
let quarantineSequence = 0;
|
|
91
|
-
function quarantinePath(old) {
|
|
92
|
-
let path;
|
|
93
|
-
do {
|
|
94
|
-
path = old + ".b9s-migrating-" + process.pid + "-" + quarantineSequence++;
|
|
95
|
-
} while (existsSync(path));
|
|
96
|
-
return path;
|
|
97
|
-
}
|
|
98
|
-
/** Resolve a renamed state directory, preserving old paths through a symlink. */
|
|
99
|
-
export function renamedDirectory(parent, currentName, oldName, report = true) {
|
|
100
|
-
const current = join(parent, currentName);
|
|
101
|
-
const old = join(parent, oldName);
|
|
102
|
-
const currentDir = directory(current);
|
|
103
|
-
const oldDir = directory(old);
|
|
104
|
-
const currentExists = present(current);
|
|
105
|
-
const oldExists = present(old);
|
|
106
|
-
if (currentDir && oldDir) {
|
|
107
|
-
const different = differingFiles(current, old);
|
|
108
|
-
if (different.length)
|
|
109
|
-
throw conflictFiles(current, old, different, currentName);
|
|
110
|
-
const quarantine = quarantinePath(old);
|
|
111
|
-
renameSync(old, quarantine);
|
|
112
|
-
const changedDuringMove = differingFiles(current, quarantine);
|
|
113
|
-
if (changedDuringMove.length) {
|
|
114
|
-
if (!present(old))
|
|
115
|
-
renameSync(quarantine, old);
|
|
116
|
-
throw conflictFiles(current, present(old) ? old : quarantine, changedDuringMove, currentName);
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
symlinkSync(currentName, old, "dir");
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
if (!present(old))
|
|
123
|
-
renameSync(quarantine, old);
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
rmSync(quarantine, { recursive: true });
|
|
127
|
-
if (report)
|
|
128
|
-
process.stderr.write("[b9s] kept identical " + current + "; removed duplicate " + old + "; " + oldName + " now links to " + currentName + "\n");
|
|
129
|
-
}
|
|
130
|
-
else if (!currentExists && oldDir) {
|
|
131
|
-
renameSync(old, current);
|
|
132
|
-
symlinkSync(currentName, old, "dir");
|
|
133
|
-
if (report)
|
|
134
|
-
process.stderr.write(`[b9s] moved ${old} to ${current}; ${oldName} now links to ${currentName}\n`);
|
|
135
|
-
}
|
|
136
|
-
else if (currentExists && oldDir) {
|
|
137
|
-
throw new CliError("directory_conflict", `${current} and ${old} both exist, but ${current} is not a directory; refusing to move or replace either path`);
|
|
138
|
-
}
|
|
139
|
-
else if (currentExists && !currentDir) {
|
|
140
|
-
throw new CliError("directory_conflict", `${current} exists but is not a directory; refusing to use it as b9s state`);
|
|
141
|
-
}
|
|
142
|
-
else if (oldExists && !currentDir) {
|
|
143
|
-
throw new CliError("directory_conflict", `${old} exists but is not a directory; refusing to replace it with a ${oldName} compatibility link`);
|
|
144
|
-
}
|
|
145
|
-
else if (oldExists && currentDir) {
|
|
146
|
-
try {
|
|
147
|
-
const st = lstatSync(old);
|
|
148
|
-
if (!st.isSymbolicLink())
|
|
149
|
-
throw new Error("not a symbolic link");
|
|
150
|
-
const resolved = realpathSync(old);
|
|
151
|
-
if (resolved !== realpathSync(current))
|
|
152
|
-
throw new Error("points elsewhere");
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
throw new CliError("directory_conflict", `both ${current} and ${old} exist and ${old} is not a symlink to ${current}; refusing to choose`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return current;
|
|
159
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* Where b9s keeps its state. The names are fixed: ~/.b9s for the machine and <checkout>/.b9s for a
|
|
5
|
+
* checkout. Nothing is discovered, inspected or migrated here, so a session sandbox that grants
|
|
6
|
+
* these two folders grants everything b9s reads to find them.
|
|
7
|
+
*/
|
|
160
8
|
export function configDirectory(env = process.env) {
|
|
161
9
|
if (env.BSCHAT_HOME !== undefined || env.B9S_HOME !== undefined)
|
|
162
10
|
return env.BSCHAT_HOME ?? env.B9S_HOME;
|
|
163
|
-
|
|
164
|
-
return renamedDirectory(home, ".b9s", ".bschat");
|
|
11
|
+
return join(env.HOME ?? homedir(), ".b9s");
|
|
165
12
|
}
|
|
166
13
|
export function repoDirectory(root) {
|
|
167
|
-
|
|
168
|
-
const oldPath = join(root, ".bschat");
|
|
169
|
-
const currentBefore = maybeLstat(currentPath);
|
|
170
|
-
const oldBefore = maybeLstat(oldPath);
|
|
171
|
-
const migration = oldBefore?.isDirectory() === true && currentBefore === null;
|
|
172
|
-
const identicalCopies = oldBefore?.isDirectory() === true && currentBefore?.isDirectory() === true;
|
|
173
|
-
const compatibilityLink = oldBefore?.isSymbolicLink() === true && currentBefore?.isDirectory() === true;
|
|
174
|
-
const current = renamedDirectory(root, ".b9s", ".bschat");
|
|
175
|
-
if ((migration || identicalCopies || compatibilityLink) && existsSync(join(root, ".git"))) {
|
|
176
|
-
const ignore = join(root, ".gitignore");
|
|
177
|
-
const contents = existsSync(ignore) ? readFileSync(ignore, "utf8") : "";
|
|
178
|
-
const lines = contents.split("\n");
|
|
179
|
-
const missing = [".b9s/", ".bschat"].filter((entry) => !lines.includes(entry));
|
|
180
|
-
if (missing.length) {
|
|
181
|
-
const prefix = contents && !contents.endsWith("\n") ? `${contents}\n` : contents;
|
|
182
|
-
writeFileSync(ignore, `${prefix}${prefix ? "\n" : ""}# b9s (per-checkout agent state)\n${missing.join("\n")}\n`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return current;
|
|
14
|
+
return join(root, ".b9s");
|
|
186
15
|
}
|
package/dist/harness.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { shellPath } from "./install.js";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { basename, dirname, join } from "node:path";
|
|
@@ -17,13 +17,41 @@ export function normalizeVendor(v) {
|
|
|
17
17
|
return VENDOR_ALIASES[v.toLowerCase()] ?? v.toLowerCase();
|
|
18
18
|
}
|
|
19
19
|
export const IDENTITY_FILE = join(".b9s", "identity.json");
|
|
20
|
-
/**
|
|
20
|
+
/** Where the last walk had to stop because the process may not look in a folder; null when it reached the top. */
|
|
21
|
+
let identityWalkDenied = null;
|
|
22
|
+
export function identityWalkStoppedAt() { return identityWalkDenied; }
|
|
23
|
+
/** Whether `dir` holds an identity file. "denied": this process may not look there. */
|
|
24
|
+
function identityFileIn(dir) {
|
|
25
|
+
try {
|
|
26
|
+
return statSync(join(dir, IDENTITY_FILE)).isFile();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
const code = error.code;
|
|
30
|
+
if (code === "EPERM" || code === "EACCES")
|
|
31
|
+
return "denied";
|
|
32
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
33
|
+
return false;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Walks up from cwd to find the repo-local identity file (.b9s/identity.json). The walk only
|
|
39
|
+
* looks; it resolves and migrates nothing. It used to resolve a state directory in every ancestor,
|
|
40
|
+
* which inspected the home folder from inside a session sandbox and failed there. A folder the
|
|
41
|
+
* process may not look in ends the walk: an identity file it cannot read is not one it can use,
|
|
42
|
+
* and the place is kept for the error a caller raises when it needed a name and found none.
|
|
43
|
+
*/
|
|
21
44
|
export function findIdentityFile(start = process.cwd()) {
|
|
45
|
+
identityWalkDenied = null;
|
|
22
46
|
let dir = start;
|
|
23
47
|
for (;;) {
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
48
|
+
const here = identityFileIn(dir);
|
|
49
|
+
if (here === true)
|
|
50
|
+
return join(dir, IDENTITY_FILE);
|
|
51
|
+
if (here === "denied") {
|
|
52
|
+
identityWalkDenied = dir;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
27
55
|
const parent = dirname(dir);
|
|
28
56
|
if (parent === dir)
|
|
29
57
|
return null;
|
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;
|