benignswarm 0.12.118 → 0.12.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.js +1 -1
- package/dist/commands/wu.js +10 -2
- package/dist/help.js +2 -2
- package/dist/lock-jobs.js +68 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -11,7 +11,7 @@ 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
13
|
"cardinality", "assign-outside-qualifications", "judges", "machine", "idempotency-key", "dir", "confirm", "impact-revision", "type",
|
|
14
|
-
"name", "out", "token", "token-file", "prefix", "uses", "expires-hours", "skill-dir", "harness", "provider", "reply-to",
|
|
14
|
+
"name", "out", "token", "token-file", "job", "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",
|
|
17
17
|
"requeue-after", "unacked-after", "category", "command", "command-pattern", "follow-delay", "startup-jitter-seconds", "env", "scope",
|
package/dist/commands/wu.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { forgetLockJob, lockJobKey, lockJobsFile, rememberLockJob, savedLockJobs, tokenForRelease } from "../lock-jobs.js";
|
|
1
2
|
import { spawnSync } from "node:child_process";
|
|
2
3
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
3
4
|
import { lstatSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -1606,7 +1607,13 @@ export async function lock(p, out) {
|
|
|
1606
1607
|
throw new CliError("usage", "--remove-empty is only valid with b9s unlock <name>");
|
|
1607
1608
|
if (cmd === "unlock") {
|
|
1608
1609
|
const removeEmpty = bool(p.flags, "remove-empty");
|
|
1609
|
-
|
|
1610
|
+
// The job's token is kept on this machine at acquisition; typing it is only needed elsewhere.
|
|
1611
|
+
const jobsFile = lockJobsFile(creds.project ? `${creds.project}.${creds.agent}` : `account.${creds.agent}`);
|
|
1612
|
+
const jobsKey = lockJobKey(project, lockName, bool(p.flags, "shared") ? null : str(p.flags, "machine") ?? defaultMachine());
|
|
1613
|
+
const releaseToken = removeEmpty ? undefined : str(p.flags, "token") ?? tokenForRelease(savedLockJobs(jobsFile, jobsKey), str(p.flags, "job"), lockName);
|
|
1614
|
+
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: releaseToken }) });
|
|
1615
|
+
if (releaseToken !== undefined)
|
|
1616
|
+
forgetLockJob(jobsFile, jobsKey, releaseToken);
|
|
1610
1617
|
if (removeEmpty) {
|
|
1611
1618
|
out.print(`${lockName} removed as an empty lock.`, r);
|
|
1612
1619
|
return;
|
|
@@ -1622,7 +1629,7 @@ export async function lock(p, out) {
|
|
|
1622
1629
|
const token = str(p.flags, "token") ?? `b9sjob_${randomBytes(24).toString("hex")}`;
|
|
1623
1630
|
const jobId = createHash("sha256").update(token).digest("hex").slice(0, 12);
|
|
1624
1631
|
const machine = defaultMachine();
|
|
1625
|
-
const unlockCommand = `b9s unlock ${lockName}${bool(p.flags, "shared") ? " --shared" : ""} --token ${token}`;
|
|
1632
|
+
const unlockCommand = `b9s unlock ${lockName}${bool(p.flags, "shared") ? " --shared" : ""} (from this machine; elsewhere add --token ${token})`;
|
|
1626
1633
|
let r;
|
|
1627
1634
|
try {
|
|
1628
1635
|
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 });
|
|
@@ -1640,6 +1647,7 @@ export async function lock(p, out) {
|
|
|
1640
1647
|
}
|
|
1641
1648
|
if (r.job_token !== token)
|
|
1642
1649
|
throw new CliError("lock_protocol_mismatch", `The server did not confirm job ownership; do not start work. Inspect the lock state. Job token: ${token}`);
|
|
1650
|
+
rememberLockJob(lockJobsFile(creds.project ? `${creds.project}.${creds.agent}` : `account.${creds.agent}`), lockJobKey(project, lockName, bool(p.flags, "shared") ? null : machine), { job: jobId, token, at: new Date().toISOString() });
|
|
1643
1651
|
out.print(r.maintenance
|
|
1644
1652
|
? `${lockName} is not handed out now: ${r.maintenance}. Job ${jobId} is #${r.position} in line. Job token: ${token}. Leave the queue: ${unlockCommand}`
|
|
1645
1653
|
: r.acquired
|
package/dist/help.js
CHANGED
|
@@ -35,7 +35,7 @@ Work-unit open, start, submit and close endpoints accept context fill and compac
|
|
|
35
35
|
GET /projects/:p/context-policy/comparison reports descriptive project-scoped policy aggregates by build/review mode, tag, and exact event-stamped class. Reviewer event counts are separate from replay-cluster uncertainty; turn token usage stays unknown. Clear-cohort units need their own server-verified clear event and a later start by the same actor. Results are not causal or paired; the console view is WU #299.
|
|
36
36
|
Test results expose GET /projects/:p/test-flaky-signals?target_key=<encoded> and GET /projects/:p/frontier-progress?target_key=<encoded>&period_days=30. These are descriptive, target-specific views; mixed outcomes never waive failures or change expectations. See packages/skill/references/api.md.
|
|
37
37
|
GET /projects/:p/work-units/:n/cost reports recorded worker, review and rework session tokens across superseded units; GET /projects/:p/stats includes finished-unit model costs. Incomplete or overlapping windows remain explicit, and token-weight prices are estimates. GET /projects/:p/agents/me/usage-cursor gives the caller's session boundary. See packages/skill/references/api.md.
|
|
38
|
-
Build dispatch checks role qualifications, capabilities, holds, reservations and operator-only required_class first, then ranks eligible workers by routing_policy weights, build quality guardrail, weakest-tag tie-break and build exploration budget, falling back when the preferred class is busy and recording route_decision / dispatch_reasons on units and events. Operators set/clear hard required_class with an audited reason via POST /projects/:p/work-units/:n/required-class (or tag definitions) and inspect cleared legacy min_tier rows via GET /projects/:p/routing/tier-migration (never guessing class mappings). Console routing controls are WU #244; CLI routing view/controls are WU #242.
|
|
38
|
+
Build dispatch checks role qualifications, capabilities, holds, reservations and operator-only required_class first, then ranks eligible workers by routing_policy weights, build quality guardrail, weakest-tag tie-break and build exploration budget, falling back when the preferred class is busy and recording route_decision / dispatch_reasons on units and events. Agent listings/status and work-unit/vocabulary JSON omit retired tier fields; submission history retains its stamped tier as historical evidence. Operators set/clear hard required_class with an audited reason via POST /projects/:p/work-units/:n/required-class (or tag definitions) and inspect cleared legacy min_tier rows via GET /projects/:p/routing/tier-migration (never guessing class mappings). Console routing controls are WU #244; CLI routing view/controls are WU #242.
|
|
39
39
|
Review routing ranks only independent qualified reviewers (excluding owner, prior builders, same-worktree occupants, and forbidden_dependent_roles), preserves trial/expert/mandatory_reviewer blockers, supports paired comparisons and head-to-head verdicts (POST /projects/:p/work-units/:n/compare, closing non-selected units as compared), and exposes GET /projects/:p/review-routing. Console routing controls are WU #244; CLI routing view/controls are WU #242. See packages/skill/references/api.md for field validation and response shapes.
|
|
40
40
|
|
|
41
41
|
Agent commands
|
|
@@ -126,7 +126,7 @@ Agent commands
|
|
|
126
126
|
acquisition queues through a machine maintenance drain/window and resumes after it
|
|
127
127
|
machine identity is this host's hostname plus its registered label, shared by all agents here
|
|
128
128
|
save the returned job token; reuse --token to check/retry the same job
|
|
129
|
-
b9s unlock <name> --token <job-token> [--machine <label>|--shared] | b9s locks
|
|
129
|
+
b9s unlock <name> [--job <id> | --token <job-token>] [--machine <label>|--shared] | b9s locks on the machine that took it the job's token is kept for you
|
|
130
130
|
b9s unlock <name> --remove-empty [--machine <label>|--shared]
|
|
131
131
|
new agent jobs release by token; legacy jobs retain identity release; assigners/operators may release without a token
|
|
132
132
|
closing a unit does not release a new job's lock
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { configDirectory } from "./directories.js";
|
|
4
|
+
import { CliError } from "./errors.js";
|
|
5
|
+
const KEEP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
6
|
+
export function lockJobsFile(agentRef, root = configDirectory()) {
|
|
7
|
+
return join(root, "state", `lock-jobs.${agentRef.replace(/[^A-Za-z0-9._-]/g, ".")}.json`);
|
|
8
|
+
}
|
|
9
|
+
export const lockJobKey = (project, lock, machine) => JSON.stringify([project, lock, machine ?? ""]);
|
|
10
|
+
function read(file) {
|
|
11
|
+
if (!existsSync(file))
|
|
12
|
+
return {};
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new CliError("corrupt_state", `${file} is not valid JSON; move it aside, then release held locks with their tokens or ask an assigner`);
|
|
19
|
+
}
|
|
20
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
21
|
+
throw new CliError("corrupt_state", `${file} does not hold lock jobs; move it aside`);
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
function write(file, store) {
|
|
25
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
26
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
27
|
+
writeFileSync(temporary, JSON.stringify(store), { mode: 0o600 });
|
|
28
|
+
chmodSync(temporary, 0o600);
|
|
29
|
+
renameSync(temporary, file);
|
|
30
|
+
}
|
|
31
|
+
export function savedLockJobs(file, key) {
|
|
32
|
+
return read(file)[key] ?? [];
|
|
33
|
+
}
|
|
34
|
+
export function rememberLockJob(file, key, entry, nowMs = Date.now()) {
|
|
35
|
+
const store = read(file);
|
|
36
|
+
for (const k of Object.keys(store)) {
|
|
37
|
+
store[k] = store[k].filter((e) => nowMs - Date.parse(e.at) < KEEP_MS);
|
|
38
|
+
if (!store[k].length)
|
|
39
|
+
delete store[k];
|
|
40
|
+
}
|
|
41
|
+
store[key] = [...(store[key] ?? []).filter((e) => e.job !== entry.job), entry];
|
|
42
|
+
write(file, store);
|
|
43
|
+
}
|
|
44
|
+
export function forgetLockJob(file, key, token) {
|
|
45
|
+
const store = read(file);
|
|
46
|
+
if (!store[key])
|
|
47
|
+
return;
|
|
48
|
+
store[key] = store[key].filter((e) => e.token !== token);
|
|
49
|
+
if (!store[key].length)
|
|
50
|
+
delete store[key];
|
|
51
|
+
write(file, store);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The token to release with when none was typed: the one saved job, or the one named by --job.
|
|
55
|
+
* Several saved jobs without --job is refused by name; nothing is guessed. No saved job returns
|
|
56
|
+
* undefined, which leaves the release to the server's own rules (an assigner, a legacy holder).
|
|
57
|
+
*/
|
|
58
|
+
export function tokenForRelease(saved, job, lock) {
|
|
59
|
+
if (job !== undefined) {
|
|
60
|
+
const match = saved.find((e) => e.job === job);
|
|
61
|
+
if (!match)
|
|
62
|
+
throw new CliError("unknown_lock_job", `no saved job ${job} for ${lock} on this machine${saved.length ? `; saved: ${saved.map((e) => e.job).join(", ")}` : ""}`, "Pass --token <job-token>, or ask an assigner to release it");
|
|
63
|
+
return match.token;
|
|
64
|
+
}
|
|
65
|
+
if (saved.length > 1)
|
|
66
|
+
throw new CliError("ambiguous_lock_job", `this agent has ${saved.length} saved jobs for ${lock} on this machine: ${saved.map((e) => `${e.job} (${e.at})`).join(", ")}`, `Name one: b9s unlock ${lock} --job <id>`);
|
|
67
|
+
return saved[0]?.token;
|
|
68
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.119";
|