benignswarm 0.12.132 → 0.12.133
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/machine.js +4 -5
- package/dist/commands/watch.js +50 -13
- 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),
|
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
|
@@ -422,13 +422,37 @@ 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
|
+
}
|
|
425
446
|
/** Prepare an owned unit before launching its next turn, outside the harness sandbox. */
|
|
426
447
|
async function prepareTurnWorktree(name, binding, allowSuperseded = false) {
|
|
427
448
|
const creds = loadAgent(name);
|
|
428
|
-
|
|
429
|
-
|
|
449
|
+
const project = binding.project ?? creds.project;
|
|
450
|
+
if (!project)
|
|
451
|
+
throw new CliError("unit_worktree_prepare_failed", `cannot prepare WU #${binding.work_unit_number}: server did not identify its authorized project`);
|
|
452
|
+
if (creds.project && creds.project !== project)
|
|
453
|
+
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
454
|
const client = Client.forAgent(creds, undefined, { presence: false });
|
|
431
|
-
const base = `/projects/${encodeURIComponent(
|
|
455
|
+
const base = `/projects/${encodeURIComponent(project)}/work-units/${binding.work_unit_number}`;
|
|
432
456
|
try {
|
|
433
457
|
const record = await client.call("GET", base);
|
|
434
458
|
const unit = record.unit;
|
|
@@ -447,7 +471,7 @@ async function prepareTurnWorktree(name, binding, allowSuperseded = false) {
|
|
|
447
471
|
return null;
|
|
448
472
|
throw new Error(`assignment event ${binding.assignment_event_id} is no longer current`);
|
|
449
473
|
}
|
|
450
|
-
const process = await client.call("GET", `/projects/${encodeURIComponent(
|
|
474
|
+
const process = await client.call("GET", `/projects/${encodeURIComponent(project)}/process`);
|
|
451
475
|
const { prepareWorktreeForWatcher } = await import("./wu.js");
|
|
452
476
|
const prepared = prepareWorktreeForWatcher(binding.work_unit_number, unit, process.process?.definition, process.checkout?.exclude ?? []);
|
|
453
477
|
return { number: binding.work_unit_number, path: prepared.path, status: unit.status };
|
|
@@ -673,15 +697,28 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
673
697
|
...(u ? [`Run these, in order, to read it all:`, ...u.readCommands.map((c) => ` ${c}`)] : []),
|
|
674
698
|
`Reply in chat with b9s send, not here. Your role and the project's process: b9s me, b9s process.`,
|
|
675
699
|
];
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
700
|
+
let bindingResolution = null;
|
|
701
|
+
if (turnSink) {
|
|
702
|
+
try {
|
|
703
|
+
bindingResolution = await (dependencies.resolveWorkUnitBinding ?? resolveWatcherWorkUnitBinding)(name);
|
|
704
|
+
}
|
|
705
|
+
catch (error) {
|
|
706
|
+
log(`could not resolve the current work-unit binding: ${error.message}`);
|
|
707
|
+
bindingResolution = { binding: null, reason: "current work-unit assignment event is unavailable" };
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const assignmentDelivery = u ? formatUpdates(omitMeasuresAlreadyIn(recoveryPrompt, u), wakePrefix, wakeSuffix) : null;
|
|
711
|
+
// Telemetry is bound only by the authoritative unique-assignment resolver. Worktree
|
|
712
|
+
// preparation can also follow a server-linked assignment delivered in this wake: when
|
|
713
|
+
// multiple units are active, the turn remains unbound, but the explicitly delivered unit
|
|
714
|
+
// still determines its checkout (prepareTurnWorktree revalidates owner and event).
|
|
715
|
+
const deliveredBinding = u
|
|
716
|
+
? deliveredAssignmentBinding(u.turn_binding_candidates ?? [], assignmentDelivery?.delivery.selected_direct_ids ?? [])
|
|
680
717
|
: null;
|
|
681
|
-
const bindingToPrepare =
|
|
718
|
+
const bindingToPrepare = bindingResolution?.binding ?? deliveredBinding;
|
|
682
719
|
let preparedWorktree = null;
|
|
683
720
|
if (turnSink && bindingToPrepare) {
|
|
684
|
-
preparedWorktree = await (dependencies.prepareWorktree ?? prepareTurnWorktree)(name, bindingToPrepare
|
|
721
|
+
preparedWorktree = await (dependencies.prepareWorktree ?? prepareTurnWorktree)(name, bindingToPrepare);
|
|
685
722
|
if (preparedWorktree) {
|
|
686
723
|
wakePrefix.push(preparedWorktree.status === "assigned"
|
|
687
724
|
? `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 +733,7 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
696
733
|
// the acknowledgement, operator note, process pointer, read commands, and delivery body.
|
|
697
734
|
const line = wake;
|
|
698
735
|
debug(`wake: delivering ${u?.tier ?? "process"} activity as wake-up #${seq}`);
|
|
699
|
-
const workUnitBinding =
|
|
736
|
+
const workUnitBinding = bindingResolution?.binding ?? null;
|
|
700
737
|
let turnExec = exec;
|
|
701
738
|
let turnCwd;
|
|
702
739
|
if (turnSink && provider && dependencies.claudeRuntime?.sandbox === "workspace-write")
|
|
@@ -707,7 +744,7 @@ export async function wakeOnce(name, exec, unackedAfter, followDelay, log, model
|
|
|
707
744
|
const args = claudeSettings(runtime.sandbox, model, runtime.effort, cwd, configRoot(), runtime.writableRoots);
|
|
708
745
|
turnExec = turnExec.replace(CLAUDE_SETTINGS_PLACEHOLDER, args.map(shellQuote).join(" "));
|
|
709
746
|
}
|
|
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))) {
|
|
747
|
+
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
748
|
debug("no wake: delivery failed or turn guard denied the launch");
|
|
712
749
|
return { sent: false, recoveryBriefDelivered: false };
|
|
713
750
|
}
|
|
@@ -759,7 +796,7 @@ export async function deliver(name, exec, wake, summary, tier, total, log, prefi
|
|
|
759
796
|
beforeTurn?.();
|
|
760
797
|
const launchedAt = new Date().toISOString();
|
|
761
798
|
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 } }));
|
|
799
|
+
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
800
|
const startedTurn = (dependencies.startTurn ?? startTurn)(cmd, {
|
|
764
801
|
...env,
|
|
765
802
|
BSCHAT_AGENT: name,
|
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.133";
|