benignswarm 0.12.132 → 0.12.134
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/commands/hook.js +1 -0
- package/dist/commands/lock-run.js +51 -11
- package/dist/commands/machine.js +4 -5
- package/dist/commands/watch.js +73 -15
- package/dist/commands/wu.js +2 -1
- package/dist/help.js +1 -1
- package/dist/turn-binding.js +15 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/hook.js
CHANGED
|
@@ -376,6 +376,7 @@ export async function gatherUpdates(name, opts) {
|
|
|
376
376
|
rendered: lines[index],
|
|
377
377
|
work_unit_number: message.work_unit_number,
|
|
378
378
|
assignment_event_id: message.assignment_event_id,
|
|
379
|
+
project: message.project,
|
|
379
380
|
})) : [];
|
|
380
381
|
const directTimes = [
|
|
381
382
|
...messages.filter(isDirectMessage).map((message) => message.created_at),
|
|
@@ -19,6 +19,14 @@ export function commandLabel(command) {
|
|
|
19
19
|
const line = command.join(" ").replace(/\s+/g, " ").trim();
|
|
20
20
|
return line.length <= 200 ? line : `${line.slice(0, 197)}...`;
|
|
21
21
|
}
|
|
22
|
+
function shellQuote(value) {
|
|
23
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
24
|
+
}
|
|
25
|
+
function unlockCommand(o) {
|
|
26
|
+
const project = o.projectSelection ? ` --project ${shellQuote(o.projectSelection)}` : "";
|
|
27
|
+
const scope = o.shared ? " --shared" : ` --machine ${shellQuote(o.machine)}`;
|
|
28
|
+
return `b9s --as ${shellQuote(o.identity)} unlock ${shellQuote(o.lock)} --job ${shellQuote(o.jobId)}${scope}${project}`;
|
|
29
|
+
}
|
|
22
30
|
export async function runUnderLock(o, deps) {
|
|
23
31
|
const now = deps.now ?? Date.now;
|
|
24
32
|
const label = commandLabel(o.command);
|
|
@@ -26,12 +34,13 @@ export async function runUnderLock(o, deps) {
|
|
|
26
34
|
const acquireBody = { unit: o.unit, note: o.note ?? label, shared: o.shared, machine: o.machine, job_token: o.token, lock_run: true };
|
|
27
35
|
const release = async (completion) => {
|
|
28
36
|
try {
|
|
29
|
-
await deps.call("POST", `${base}/release`, { shared: o.shared, machine: o.shared ? undefined : o.machine, job_token: o.token, ...completion });
|
|
37
|
+
const result = await deps.call("POST", `${base}/release`, { shared: o.shared, machine: o.shared ? undefined : o.machine, job_token: o.token, ...completion });
|
|
38
|
+
forgetLockJob(o.jobsFile, o.jobsKey, o.token);
|
|
39
|
+
return result;
|
|
30
40
|
}
|
|
31
41
|
catch (error) {
|
|
32
|
-
throw new CliError("lock_release_failed", `job ${o.jobId} could not release ${o.lock} (${error instanceof Error ? error.message : String(error)})`, `Release it:
|
|
42
|
+
throw new CliError("lock_release_failed", `job ${o.jobId} could not release ${o.lock} (${error instanceof Error ? error.message : String(error)})`, `Release it: ${unlockCommand(o)}`);
|
|
33
43
|
}
|
|
34
|
-
forgetLockJob(o.jobsFile, o.jobsKey, o.token);
|
|
35
44
|
};
|
|
36
45
|
let r = await deps.call("POST", `${base}/acquire`, acquireBody);
|
|
37
46
|
if (r.job_token !== o.token)
|
|
@@ -59,7 +68,11 @@ export async function runUnderLock(o, deps) {
|
|
|
59
68
|
deps.log(`job ${o.jobId} holds ${o.lock}; running: ${label}`);
|
|
60
69
|
const result = await deps.run(o.command);
|
|
61
70
|
code = typeof result === "number" ? result : result.exit_code;
|
|
62
|
-
await release(typeof result === "number" ? { exit_code: code } : { exit_code: code, ...(result.verified_baseline_sha ? { verified_baseline_sha: result.verified_baseline_sha } : {}), ...(result.tested_tree_sha ? { tested_tree_sha: result.tested_tree_sha } : {}) });
|
|
71
|
+
const released = await release(typeof result === "number" ? { exit_code: code } : { exit_code: code, ...(result.gate_output ? { gate_output: true } : {}), ...(result.verified_baseline_sha ? { verified_baseline_sha: result.verified_baseline_sha } : {}), ...(result.tested_tree_sha ? { tested_tree_sha: result.tested_tree_sha } : {}) });
|
|
72
|
+
if (released.gate_receipt?.recorded === false) {
|
|
73
|
+
const configured = released.gate_receipt.configured_command;
|
|
74
|
+
deps.log(`Gate receipt not recorded: ${released.gate_receipt.reason ?? "the reported gate result was refused"}.${configured ? ` Use the configured command: ${configured}` : " No complete gate command is configured."}`);
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
catch (error) {
|
|
65
78
|
if (!error || !(error instanceof CliError) || error.code !== "lock_release_failed")
|
|
@@ -89,20 +102,47 @@ export function processDeps(call, log) {
|
|
|
89
102
|
}),
|
|
90
103
|
run: (command) => new Promise((resolve, reject) => {
|
|
91
104
|
const child = spawn(command[0], command.slice(1), { stdio: ["inherit", "pipe", "inherit"] });
|
|
92
|
-
let
|
|
105
|
+
let tail = "";
|
|
106
|
+
let gateOutput = false;
|
|
107
|
+
let baseline;
|
|
108
|
+
let testedTree;
|
|
109
|
+
const consumeLines = (text, final = false) => {
|
|
110
|
+
const lines = (tail + text).split(/\r?\n/);
|
|
111
|
+
const incomplete = lines.pop() ?? "";
|
|
112
|
+
if (final) {
|
|
113
|
+
tail = "";
|
|
114
|
+
if (incomplete)
|
|
115
|
+
lines.push(incomplete);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
tail = incomplete.slice(-2048);
|
|
119
|
+
}
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
if (/^gate:/i.test(line))
|
|
122
|
+
gateOutput = true;
|
|
123
|
+
const baselineMatch = line.match(/^gate: verified baseline ([0-9a-f]{40})\s*$/i);
|
|
124
|
+
// The gate's header is authoritative. Tests run later in the same process
|
|
125
|
+
// may print fixture marker lines; they must not replace the real SHAs.
|
|
126
|
+
if (baselineMatch && !baseline)
|
|
127
|
+
baseline = baselineMatch[1].toLowerCase();
|
|
128
|
+
const treeMatch = line.match(/^gate: tested tree ([0-9a-f]{40})\s*$/i);
|
|
129
|
+
if (treeMatch && !testedTree)
|
|
130
|
+
testedTree = treeMatch[1].toLowerCase();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
93
133
|
child.stdout?.on("data", (chunk) => {
|
|
94
134
|
process.stdout.write(chunk);
|
|
95
|
-
|
|
96
|
-
output += chunk.toString("utf8").slice(0, 8192 - output.length);
|
|
135
|
+
consumeLines(chunk.toString("utf8"));
|
|
97
136
|
});
|
|
98
137
|
forward = (signal) => { child.kill(signal); };
|
|
99
138
|
child.once("error", (error) => { forward = undefined; reject(new CliError("command_not_started", `could not start ${command[0]}: ${error.message}`)); });
|
|
100
|
-
|
|
139
|
+
// `close` follows stdout's `end`, so the final marker lines have been
|
|
140
|
+
// consumed before we construct the receipt sent with the lock release.
|
|
141
|
+
child.once("close", (code, signal) => {
|
|
101
142
|
forward = undefined;
|
|
143
|
+
consumeLines("", true);
|
|
102
144
|
const exit_code = code ?? 128 + (signal ? constants.signals[signal] ?? 0 : 0);
|
|
103
|
-
|
|
104
|
-
const testedTree = output.match(/^gate: tested tree ([0-9a-f]{40})\s*$/im)?.[1]?.toLowerCase();
|
|
105
|
-
resolve({ exit_code, ...(baseline ? { verified_baseline_sha: baseline } : {}), ...(testedTree ? { tested_tree_sha: testedTree } : {}) });
|
|
145
|
+
resolve({ exit_code, ...(gateOutput ? { gate_output: true } : {}), ...(baseline ? { verified_baseline_sha: baseline } : {}), ...(testedTree ? { tested_tree_sha: testedTree } : {}) });
|
|
106
146
|
});
|
|
107
147
|
}),
|
|
108
148
|
dispose: () => { for (const signal of signals)
|
package/dist/commands/machine.js
CHANGED
|
@@ -25,7 +25,7 @@ import { busyTurnPause, DEFAULT_TURNS_PER_HOUR, DEFAULT_UNPRODUCTIVE_PER_HOUR, r
|
|
|
25
25
|
import { defaultWorkspaceWritableRoots } from "../start-options.js";
|
|
26
26
|
import { antigravityPath, antigravitySandboxPermissions, antigravityTurnArgs, antigravityTurnEnv, parseAntigravityJson } from "../antigravity.js";
|
|
27
27
|
import { bootTimeMs } from "../boot-time.js";
|
|
28
|
-
import {
|
|
28
|
+
import { observedTurnBindingFields } from "../turn-binding.js";
|
|
29
29
|
import { DEFAULT_CACHE_FLOOR_PCT, manageBuildCaches } from "../build-caches.js";
|
|
30
30
|
import { imageCacheBaseDir, imageCacheProjectRoot, projectsWithImageCaches } from "../image-caches.js";
|
|
31
31
|
import { agentContainerName, agentContainerRunArgs, detectEc2Host, ensurePinnedImagePulled, isolatedBuildCommand, isolatedDevcontainerBuildCommand, isolatedImagePullCommands, isolatedSubprocessEnv, probeContainerImdsIsolation, networklessRuntimeWrapper, parseContainerRuntimeVersion, probeImdsIsolation, probeNestedSandbox, readGitIdentity, resolveSessionSecretDelivery, resolveWritableMounts, validateDevcontainerSpec, BUILD_SECRET_KEY_NAME_RE, BUILD_SECRET_CONTENT_RE, containsBuildSecretMaterial, sanitizeBuildDiagnosticText, } from "../container.js";
|
|
@@ -119,7 +119,7 @@ export function turnFaultSessionFields(fault, agent) {
|
|
|
119
119
|
const binding = agent ? readState(agent).watch_turn_binding : undefined;
|
|
120
120
|
return {
|
|
121
121
|
turn_fault_at: new Date(fault.at).toISOString(),
|
|
122
|
-
...(binding?.started_at ? { work_unit_number: binding.work_unit_number, assignment_event_id: binding.assignment_event_id } : {}),
|
|
122
|
+
...(binding?.started_at ? { work_unit_number: binding.work_unit_number, assignment_event_id: binding.assignment_event_id, work_unit_binding_reason: binding.reason ?? null } : {}),
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
const syncRunner = (cmd, args, opts) => spawnSync(cmd, args, { encoding: "utf8", timeout: opts?.timeout ?? 180_000, cwd: opts?.cwd, env: opts?.env });
|
|
@@ -2079,12 +2079,11 @@ function turnFacts(agent, harness, thread, turnCap = DEFAULT_TURNS_PER_HOUR) {
|
|
|
2079
2079
|
const until = !ph.running ? probeFor(harness, thread, agent).limitUntil(ph.lastError) : null;
|
|
2080
2080
|
const unpausedAt = readState(agent).turn_unpaused_at ?? 0;
|
|
2081
2081
|
const paused = until && until > Date.now() && Date.parse(ph.lastErrorAt ?? "") > unpausedAt ? new Date(until).toISOString() : null;
|
|
2082
|
-
const binding =
|
|
2082
|
+
const binding = observedTurnBindingFields(ph.startedAt, savedBinding);
|
|
2083
2083
|
return { turn: {
|
|
2084
2084
|
running: ph.running,
|
|
2085
2085
|
since: ph.startedAt,
|
|
2086
|
-
|
|
2087
|
-
assignment_event_id: binding?.assignment_event_id ?? null,
|
|
2086
|
+
...binding,
|
|
2088
2087
|
...(!ph.running && !ph.lastError && ph.startedAt ? { completed_at: ph.lastEventAt } : {}),
|
|
2089
2088
|
...(!ph.running && ph.lastError && ph.lastErrorAt ? { turn_fault_at: ph.lastErrorAt, error: ph.lastError } : {}),
|
|
2090
2089
|
}, process: ph.running ? turnProcess(thread, harness, undefined, agent) : null, paused_until: paused, pause_started_at: paused ? ph.lastErrorAt : null, turn_guard: busyTurnPause(readState(agent).turn_guard, turnCap, Date.now()), ...(harness === "codex" ? { usage_account_fingerprint: accountFingerprint } : {}) };
|
package/dist/commands/watch.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createHash } from "node:crypto";
|
|
|
10
10
|
import { homedir, totalmem, userInfo } from "node:os";
|
|
11
11
|
import { basename, dirname, join } from "node:path";
|
|
12
12
|
import { bool, str } from "../args.js";
|
|
13
|
-
import { configRoot, loadAgent, resolveAgentName } from "../config.js";
|
|
13
|
+
import { agentRef, configRoot, loadAgent, resolveAgentName } from "../config.js";
|
|
14
14
|
import { Client } from "../client.js";
|
|
15
15
|
import { heartbeatIfActive, reportWatcherHeartbeat, resolveActivitySource } from "../heartbeat.js";
|
|
16
16
|
import { scanProject, unitWorktrees } from "./worktrees.js";
|
|
@@ -422,13 +422,58 @@ async function waitIntervalOrStop(ms, stopped) {
|
|
|
422
422
|
if (timer)
|
|
423
423
|
clearTimeout(timer);
|
|
424
424
|
}
|
|
425
|
+
/** Bind only when the server says this identity has exactly one active owner assignment. */
|
|
426
|
+
export async function resolveWatcherWorkUnitBinding(name) {
|
|
427
|
+
const creds = loadAgent(name);
|
|
428
|
+
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
429
|
+
try {
|
|
430
|
+
const result = await client.call("GET", "/agents/me/work-unit-binding");
|
|
431
|
+
if (result.binding && Number.isSafeInteger(result.binding.work_unit_number) && Number(result.binding.work_unit_number) > 0
|
|
432
|
+
&& typeof result.binding.assignment_event_id === "string" && result.binding.assignment_event_id
|
|
433
|
+
&& typeof result.binding.project === "string" && result.binding.project) {
|
|
434
|
+
return { binding: { work_unit_number: Number(result.binding.work_unit_number), assignment_event_id: result.binding.assignment_event_id, project: result.binding.project }, reason: null };
|
|
435
|
+
}
|
|
436
|
+
if (result.reason === "agent has no in-progress work unit" || result.reason === "agent has multiple in-progress work units"
|
|
437
|
+
|| result.reason === "current work-unit assignment event is unavailable") {
|
|
438
|
+
return { binding: null, reason: result.reason };
|
|
439
|
+
}
|
|
440
|
+
return { binding: null, reason: "current work-unit assignment event is unavailable" };
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
return { binding: null, reason: "current work-unit assignment event is unavailable" };
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Runs `work` with BSCHAT_AGENT naming this watcher's agent, then puts the environment back.
|
|
448
|
+
* The watcher is started with --as, so its own environment carries no identity; the git it runs
|
|
449
|
+
* to prepare a unit worktree calls the b9s credential helper as a child process, which can only
|
|
450
|
+
* learn who it is from the environment. Without this every fetch for a linked repository failed
|
|
451
|
+
* with no_identity and the watcher exited before any turn (0.12.133).
|
|
452
|
+
*/
|
|
453
|
+
export function withAgentEnv(ref, work) {
|
|
454
|
+
const had = Object.prototype.hasOwnProperty.call(process.env, "BSCHAT_AGENT");
|
|
455
|
+
const before = process.env.BSCHAT_AGENT;
|
|
456
|
+
process.env.BSCHAT_AGENT = ref;
|
|
457
|
+
try {
|
|
458
|
+
return work();
|
|
459
|
+
}
|
|
460
|
+
finally {
|
|
461
|
+
if (had)
|
|
462
|
+
process.env.BSCHAT_AGENT = before;
|
|
463
|
+
else
|
|
464
|
+
delete process.env.BSCHAT_AGENT;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
425
467
|
/** Prepare an owned unit before launching its next turn, outside the harness sandbox. */
|
|
426
468
|
async function prepareTurnWorktree(name, binding, allowSuperseded = false) {
|
|
427
469
|
const creds = loadAgent(name);
|
|
428
|
-
|
|
429
|
-
|
|
470
|
+
const project = binding.project ?? creds.project;
|
|
471
|
+
if (!project)
|
|
472
|
+
throw new CliError("unit_worktree_prepare_failed", `cannot prepare WU #${binding.work_unit_number}: server did not identify its authorized project`);
|
|
473
|
+
if (creds.project && creds.project !== project)
|
|
474
|
+
throw new CliError("unit_worktree_prepare_failed", `cannot prepare WU #${binding.work_unit_number}: server project ${project} does not match ${name}'s project ${creds.project}`);
|
|
430
475
|
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
431
|
-
const base = `/projects/${encodeURIComponent(
|
|
476
|
+
const base = `/projects/${encodeURIComponent(project)}/work-units/${binding.work_unit_number}`;
|
|
432
477
|
try {
|
|
433
478
|
const record = await client.call("GET", base);
|
|
434
479
|
const unit = record.unit;
|
|
@@ -447,9 +492,9 @@ async function prepareTurnWorktree(name, binding, allowSuperseded = false) {
|
|
|
447
492
|
return null;
|
|
448
493
|
throw new Error(`assignment event ${binding.assignment_event_id} is no longer current`);
|
|
449
494
|
}
|
|
450
|
-
const process = await client.call("GET", `/projects/${encodeURIComponent(
|
|
495
|
+
const process = await client.call("GET", `/projects/${encodeURIComponent(project)}/process`);
|
|
451
496
|
const { prepareWorktreeForWatcher } = await import("./wu.js");
|
|
452
|
-
const prepared = prepareWorktreeForWatcher(binding.work_unit_number, unit, process.process?.definition, process.checkout?.exclude ?? []);
|
|
497
|
+
const prepared = withAgentEnv(agentRef(creds), () => prepareWorktreeForWatcher(binding.work_unit_number, unit, process.process?.definition, process.checkout?.exclude ?? []));
|
|
453
498
|
return { number: binding.work_unit_number, path: prepared.path, status: unit.status };
|
|
454
499
|
}
|
|
455
500
|
catch (error) {
|
|
@@ -673,15 +718,28 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
673
718
|
...(u ? [`Run these, in order, to read it all:`, ...u.readCommands.map((c) => ` ${c}`)] : []),
|
|
674
719
|
`Reply in chat with b9s send, not here. Your role and the project's process: b9s me, b9s process.`,
|
|
675
720
|
];
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
721
|
+
let bindingResolution = null;
|
|
722
|
+
if (turnSink) {
|
|
723
|
+
try {
|
|
724
|
+
bindingResolution = await (dependencies.resolveWorkUnitBinding ?? resolveWatcherWorkUnitBinding)(name);
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
log(`could not resolve the current work-unit binding: ${error.message}`);
|
|
728
|
+
bindingResolution = { binding: null, reason: "current work-unit assignment event is unavailable" };
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const assignmentDelivery = u ? formatUpdates(omitMeasuresAlreadyIn(recoveryPrompt, u), wakePrefix, wakeSuffix) : null;
|
|
732
|
+
// Telemetry is bound only by the authoritative unique-assignment resolver. Worktree
|
|
733
|
+
// preparation can also follow a server-linked assignment delivered in this wake: when
|
|
734
|
+
// multiple units are active, the turn remains unbound, but the explicitly delivered unit
|
|
735
|
+
// still determines its checkout (prepareTurnWorktree revalidates owner and event).
|
|
736
|
+
const deliveredBinding = u
|
|
737
|
+
? deliveredAssignmentBinding(u.turn_binding_candidates ?? [], assignmentDelivery?.delivery.selected_direct_ids ?? [])
|
|
680
738
|
: null;
|
|
681
|
-
const bindingToPrepare =
|
|
739
|
+
const bindingToPrepare = bindingResolution?.binding ?? deliveredBinding;
|
|
682
740
|
let preparedWorktree = null;
|
|
683
741
|
if (turnSink && bindingToPrepare) {
|
|
684
|
-
preparedWorktree = await (dependencies.prepareWorktree ?? prepareTurnWorktree)(name, bindingToPrepare
|
|
742
|
+
preparedWorktree = await (dependencies.prepareWorktree ?? prepareTurnWorktree)(name, bindingToPrepare);
|
|
685
743
|
if (preparedWorktree) {
|
|
686
744
|
wakePrefix.push(preparedWorktree.status === "assigned"
|
|
687
745
|
? `The watcher prepared WU #${preparedWorktree.number}'s worktree at ${preparedWorktree.path}. Run b9s wu start ${preparedWorktree.number} from this checkout to record the start, then work in that path.`
|
|
@@ -696,7 +754,7 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
696
754
|
// the acknowledgement, operator note, process pointer, read commands, and delivery body.
|
|
697
755
|
const line = wake;
|
|
698
756
|
debug(`wake: delivering ${u?.tier ?? "process"} activity as wake-up #${seq}`);
|
|
699
|
-
const workUnitBinding =
|
|
757
|
+
const workUnitBinding = bindingResolution?.binding ?? null;
|
|
700
758
|
let turnExec = exec;
|
|
701
759
|
let turnCwd;
|
|
702
760
|
if (turnSink && provider && dependencies.claudeRuntime?.sandbox === "workspace-write")
|
|
@@ -707,7 +765,7 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
707
765
|
const args = claudeSettings(runtime.sandbox, model, runtime.effort, cwd, configRoot(), runtime.writableRoots);
|
|
708
766
|
turnExec = turnExec.replace(CLAUDE_SETTINGS_PLACEHOLDER, args.map(shellQuote).join(" "));
|
|
709
767
|
}
|
|
710
|
-
if (!(await deliver(name, turnExec, wake, line, u ? u.tier : "process", total, log, operatorNew ? "operator message; " : "", seq, turnSink, payload?.delivery.by_kind ?? u?.delivery.by_kind, provider, model, turnStdin, beforeTurn, { ...(dependencies.startTurn ? { startTurn: dependencies.startTurn } : {}), sessionId, workUnitBinding, ...(turnCwd ? { cwd: turnCwd } : {}) }, allowTurn))) {
|
|
768
|
+
if (!(await deliver(name, turnExec, wake, line, u ? u.tier : "process", total, log, operatorNew ? "operator message; " : "", seq, turnSink, payload?.delivery.by_kind ?? u?.delivery.by_kind, provider, model, turnStdin, beforeTurn, { ...(dependencies.startTurn ? { startTurn: dependencies.startTurn } : {}), sessionId, workUnitBinding, workUnitBindingReason: bindingResolution?.reason ?? null, ...(turnCwd ? { cwd: turnCwd } : {}) }, allowTurn))) {
|
|
711
769
|
debug("no wake: delivery failed or turn guard denied the launch");
|
|
712
770
|
return { sent: false, recoveryBriefDelivered: false };
|
|
713
771
|
}
|
|
@@ -759,7 +817,7 @@ export async function deliver(name, exec, wake, summary, tier, total, log, prefi
|
|
|
759
817
|
beforeTurn?.();
|
|
760
818
|
const launchedAt = new Date().toISOString();
|
|
761
819
|
const binding = dependencies.workUnitBinding ?? null;
|
|
762
|
-
updateState(name, (onDisk) => ({ ...onDisk, watch_turn_binding: { launched_at: launchedAt, started_at: null, work_unit_number: binding?.work_unit_number ?? null, assignment_event_id: binding?.assignment_event_id ?? null } }));
|
|
820
|
+
updateState(name, (onDisk) => ({ ...onDisk, watch_turn_binding: { launched_at: launchedAt, started_at: null, work_unit_number: binding?.work_unit_number ?? null, assignment_event_id: binding?.assignment_event_id ?? null, reason: binding ? null : dependencies.workUnitBindingReason ?? "agent has no in-progress work unit" } }));
|
|
763
821
|
const startedTurn = (dependencies.startTurn ?? startTurn)(cmd, {
|
|
764
822
|
...env,
|
|
765
823
|
BSCHAT_AGENT: name,
|
package/dist/commands/wu.js
CHANGED
|
@@ -1702,7 +1702,8 @@ export async function lock(p, out) {
|
|
|
1702
1702
|
const deps = processDeps((method, path, body) => client.call(method, path, body, { retries: lockRunRetries(path) }), (line) => process.stderr.write(`[b9s] ${line}\n`));
|
|
1703
1703
|
try {
|
|
1704
1704
|
process.exitCode = await runUnderLock({
|
|
1705
|
-
project,
|
|
1705
|
+
project, identity: agentRef(creds), projectSelection: creds.project ? undefined : project,
|
|
1706
|
+
lock: runName, shared, machine, unit: runUnit ? Number(runUnit) : null, note: str(p.flags, "note"), command: p.rest, token: runToken,
|
|
1706
1707
|
jobId: createHash("sha256").update(runToken).digest("hex").slice(0, 12),
|
|
1707
1708
|
jobsFile: lockJobsFile(creds.project ? `${creds.project}.${creds.agent}` : `account.${creds.agent}`), jobsKey: lockJobKey(project, runName, shared ? null : machine),
|
|
1708
1709
|
}, deps);
|
package/dist/help.js
CHANGED
|
@@ -131,7 +131,7 @@ Agent commands
|
|
|
131
131
|
acquisition queues through a machine maintenance drain/window and resumes after it
|
|
132
132
|
machine identity is this host's hostname plus its registered label, shared by all agents here
|
|
133
133
|
save the returned job token; reuse --token to check/retry the same job
|
|
134
|
-
b9s lock run <name> [--unit n] [--note ..] [--shared] [--token <job-token>] -- <command> poll until granted, run
|
|
134
|
+
b9s lock run <name> [--unit n] [--note ..] [--shared] [--token <job-token>] -- <command> poll until granted, run and release; gate receipt outcome is separate and does not change the command exit code
|
|
135
135
|
polls every 15s; stale waiters are skipped after 60s with a process notice; later polls reap unreported holders idle 60s
|
|
136
136
|
b9s locks shows waiter poll age; reported-command holders do not expire
|
|
137
137
|
b9s unlock <name> [--job <id> | --token <job-token>] [--machine <label>|--shared] | b9s locks shows lock-run waiters' last-poll age; on this host the job token is kept for you
|
package/dist/turn-binding.js
CHANGED
|
@@ -4,6 +4,16 @@ export function bindingForObservedTurn(startedAt, saved) {
|
|
|
4
4
|
return null;
|
|
5
5
|
return { work_unit_number: Number(saved.work_unit_number), assignment_event_id: saved.assignment_event_id };
|
|
6
6
|
}
|
|
7
|
+
/** Emit the daemon's explicit binding (or its non-attribution reason) only for this exact turn start. */
|
|
8
|
+
export function observedTurnBindingFields(startedAt, saved) {
|
|
9
|
+
const binding = bindingForObservedTurn(startedAt, saved);
|
|
10
|
+
const sameTurn = !!startedAt && saved?.started_at === startedAt;
|
|
11
|
+
return {
|
|
12
|
+
work_unit_number: binding?.work_unit_number ?? null,
|
|
13
|
+
assignment_event_id: binding?.assignment_event_id ?? null,
|
|
14
|
+
work_unit_binding_reason: binding ? null : sameTurn ? saved?.reason ?? null : null,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
/** Accept only server-linked assignment events whose message IDs the final budget retained. */
|
|
8
18
|
export function deliveredAssignmentBinding(messages, selectedMessageIds) {
|
|
9
19
|
const selected = new Set(selectedMessageIds);
|
|
@@ -14,7 +24,11 @@ export function deliveredAssignmentBinding(messages, selectedMessageIds) {
|
|
|
14
24
|
if (!Number.isSafeInteger(message.work_unit_number) || Number(message.work_unit_number) < 1
|
|
15
25
|
|| typeof message.assignment_event_id !== "string" || !message.assignment_event_id)
|
|
16
26
|
continue;
|
|
17
|
-
const binding = {
|
|
27
|
+
const binding = {
|
|
28
|
+
work_unit_number: Number(message.work_unit_number),
|
|
29
|
+
assignment_event_id: message.assignment_event_id,
|
|
30
|
+
...(typeof message.project === "string" && message.project ? { project: message.project } : {}),
|
|
31
|
+
};
|
|
18
32
|
candidates.set(`${binding.work_unit_number}\0${binding.assignment_event_id}`, binding);
|
|
19
33
|
}
|
|
20
34
|
return candidates.size === 1 ? [...candidates.values()][0] : null;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.134";
|