pi-straw-boss 0.87.1 → 0.87.2
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/server/main.mjs +9 -8
- package/package.json +1 -1
- package/prompts/main.md +1 -1
- package/prompts/planning.md +2 -2
- package/src/capacity.ts +6 -0
- package/src/index.ts +1 -1
- package/src/server/capops.ts +1 -11
- package/src/session.ts +3 -3
- package/src/workercap.ts +44 -49
package/dist/server/main.mjs
CHANGED
|
@@ -11941,6 +11941,15 @@ var JOBS = 50;
|
|
|
11941
11941
|
var DETAIL = 120;
|
|
11942
11942
|
var num2 = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi ? v : void 0;
|
|
11943
11943
|
var capDir = (boardDir) => join30(dirname10(boardDir), "capacity");
|
|
11944
|
+
function readBudget(stateDir) {
|
|
11945
|
+
let b;
|
|
11946
|
+
try {
|
|
11947
|
+
b = JSON.parse(readFileSync19(join30(stateDir, "config.json"), "utf8")).capacity?.budget;
|
|
11948
|
+
} catch {
|
|
11949
|
+
return void 0;
|
|
11950
|
+
}
|
|
11951
|
+
return typeof b === "number" && Number.isFinite(b) && b > 0 && b <= 1e3 ? b : void 0;
|
|
11952
|
+
}
|
|
11944
11953
|
var DEVICE = "_device.json";
|
|
11945
11954
|
var SENT = "_sent.json";
|
|
11946
11955
|
function writeJson2(dir, name2, value) {
|
|
@@ -22163,14 +22172,6 @@ function createCapWatch(d) {
|
|
|
22163
22172
|
}
|
|
22164
22173
|
|
|
22165
22174
|
// src/server/capops.ts
|
|
22166
|
-
function readBudget(stateDir) {
|
|
22167
|
-
try {
|
|
22168
|
-
const b = JSON.parse(readFileSync36(join47(stateDir, "config.json"), "utf8")).capacity?.budget;
|
|
22169
|
-
return typeof b === "number" && Number.isFinite(b) && b > 0 && b <= 1e3 ? b : void 0;
|
|
22170
|
-
} catch {
|
|
22171
|
-
return void 0;
|
|
22172
|
-
}
|
|
22173
|
-
}
|
|
22174
22175
|
function armedLoop(dir, session, now) {
|
|
22175
22176
|
if (!safeSession(session)) return false;
|
|
22176
22177
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.87.
|
|
3
|
+
"version": "0.87.2",
|
|
4
4
|
"description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/prompts/main.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
You are the main agent of Herdr tab {{tab}}, of kind {{duty}}: the boss works with you here.
|
|
2
2
|
|
|
3
|
-
- Dispatch: split work by owning app ({{dir}}/apps-config.md); a task is one worker's end-to-end work in one app, a todo before its worker starts ({{dir}}/planning.md: plan, anchors). Dependent tasks wait (`blockedBy`); parallel writers get worktrees under `~/.herdr/worktrees/<repo>/<branch>` (elsewhere
|
|
3
|
+
- Dispatch: split work by owning app ({{dir}}/apps-config.md); a task is one worker's end-to-end work in one app, a todo before its worker starts ({{dir}}/planning.md: plan, anchors). Dependent tasks wait (`blockedBy`); parallel writers get worktrees under `~/.herdr/worktrees/<repo>/<branch>` (elsewhere pi's trust prompt hangs it); work independent of your chain goes to subagents in parallel, on an unattended device within its capacity budget (`board_read` `capacity`; an API-bound worker's todo may set `metadata.points` 0.25). Idle with ready todos: dispatch them; none ready: take your next eligible work or report idle (`milestone`). A capacity notice on your work: dispatch its ready work now, or say why not (blocked, shared files, the boss): reply to whoever asked; sb's: board it.
|
|
4
4
|
- A result passing brief and anchor: todo `completed`, dispatch what it unblocked. A failed or cancelled task blocks its dependents: report them; settle the next step with the boss.
|
|
5
5
|
- Write to agents terse, caveman-style: point first; keep negations, numbers, paths, IDs, and quoted decisions verbatim; full sentences where a fragment could mislead; a brief still carries its goal, context, reasons with their cause, scope, what others own, and acceptance check, or workers redo work; a reader unsure restates it or asks.
|
|
6
6
|
- Brief workers in English: required behavior, the Reality anchor, the boss's authorizations quoted; cause and location are the worker's. End with: "When you need a decision these authorizations do not cover, or a rule you follow says to ask first, call `caller_ping` and stop." Answer pings via the boss; `subagent_resume`. Reviewed change: `boss_pair` worker and reviewer, brief both, dispatch both with `Thread: T<n>`; both results come when the thread closes; relay nothing.
|
package/prompts/planning.md
CHANGED
|
@@ -19,8 +19,8 @@ For fan-out and orchestrator-worker, one todo per task:
|
|
|
19
19
|
- `subject`: the required outcome.
|
|
20
20
|
- `owner`: the subagent's name, or `self`.
|
|
21
21
|
- `description`: the app, the worktree branch for a parallel writer, the anchor and who exercises it, and the exact artifact path a dependent will read.
|
|
22
|
-
- `blockedBy`: the tasks whose output or landed change this one needs; the rest run in parallel
|
|
23
|
-
- `metadata`: `{ "graph": "<a graph name from section 1, exactly>", "anchor": "...", "checkpoint": "own" | "<checkpoint todo id>", "points": <n> }`: its weight against the budget, as the boss or project weighs it (default 1).
|
|
22
|
+
- `blockedBy`: the tasks whose output or landed change this one needs; the rest run in parallel, on an unattended device within its capacity budget. Serialize only on a real dependency or shared files.
|
|
23
|
+
- `metadata`: `{ "graph": "<a graph name from section 1, exactly>", "anchor": "...", "checkpoint": "own" | "<checkpoint todo id>", "points": <n> }`: its weight against the budget, as the boss or project weighs it (default 1; 0.25 for a light, API-bound worker).
|
|
24
24
|
- Defer: `metadata.until` (ISO) or `metadata.waitsOn` (person). Your monitor, loop or `boss_watch` prevents stale notices.
|
|
25
25
|
|
|
26
26
|
## 3. Name the anchors
|
package/src/capacity.ts
CHANGED
|
@@ -54,6 +54,12 @@ export function pauseOf(data: unknown, now: number): { state: "paused"; pause: P
|
|
|
54
54
|
|
|
55
55
|
/** `<state dir>/capacity`, beside the board folder (whose listing the board's readers and purge own). */
|
|
56
56
|
export const capDir = (boardDir: string) => join(dirname(boardDir), "capacity");
|
|
57
|
+
/** `capacity.budget` of `<state dir>/config.json`: a number of points over 0 (at most 1000); none when it is unset or not such a number. Read at each call, so a change applies at once. */
|
|
58
|
+
export function readBudget(stateDir: string): number | undefined {
|
|
59
|
+
let b: unknown;
|
|
60
|
+
try { b = (JSON.parse(readFileSync(join(stateDir, "config.json"), "utf8")) as { capacity?: { budget?: unknown } }).capacity?.budget; } catch { return undefined; }
|
|
61
|
+
return typeof b === "number" && Number.isFinite(b) && b > 0 && b <= 1000 ? b : undefined;
|
|
62
|
+
}
|
|
57
63
|
const DEVICE = "_device.json", SENT = "_sent.json";
|
|
58
64
|
function writeJson(dir: string, name: string, value: unknown): void {
|
|
59
65
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
package/src/index.ts
CHANGED
|
@@ -108,7 +108,7 @@ export function createStrawBoss({ run: given, world: reading, api = herdrApi(),
|
|
|
108
108
|
closeSelf = createClosing(kit);
|
|
109
109
|
const control = createCloseMain(kit, { closeSelf, check: bridge.stashCheck, turn: bridge.turn });
|
|
110
110
|
const watch = createBossWatch(kit, { ask: cfg.ask ?? look?.ask, control, openTower: reach.openTower, remote: () => Boolean(link.remoteScope()) });
|
|
111
|
-
registerSession(kit, { mainDuty, integration: createIntegrationWatch(kit), runMode, briefing, roles, presence, membership, guard, host, reach, digest, control, startTower: createTower(kit, { membership, presence, tools, control, digest, roles, reach }) });
|
|
111
|
+
registerSession(kit, { mainDuty, attended: () => link.attended(), integration: createIntegrationWatch(kit), runMode, briefing, roles, presence, membership, guard, host, reach, digest, control, startTower: createTower(kit, { membership, presence, tools, control, digest, roles, reach }) });
|
|
112
112
|
trainGuard = registerTrainGuard(kit, cars.client, mainDuty);
|
|
113
113
|
mainDuty.trainOn(() => Boolean(trainGuard)); // a train's todo and MonitorCreate calls, and the integrator's train todos (nothing loads with the merge train off)
|
|
114
114
|
registerBoss(kit, { runMode, host, membership, reach, closeSelf, stashing: createStashing(kit, { host }), server: look, paths: createBossPaths(kit, { host, server: look, closeSelf, here: host.here }) });
|
package/src/server/capops.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
2
2
|
import { availableParallelism, homedir, loadavg } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { readEntries, safeSession } from "../board.ts";
|
|
5
|
-
import { capDir, type MainFacts } from "../capacity.ts";
|
|
5
|
+
import { capDir, type MainFacts, readBudget } from "../capacity.ts";
|
|
6
6
|
import { type HerdrRun, panes as herdrPanes, type Session, workspaces as herdrWorkspaces } from "../herdr.ts";
|
|
7
7
|
import { commanding, sessionMark, subagentsOfAll } from "../netdata.ts";
|
|
8
8
|
import { nameOf, netMembers } from "../reach.ts";
|
|
@@ -14,16 +14,6 @@ import type { Towers } from "./towers.ts";
|
|
|
14
14
|
// The server's side of the capacity watch (capwatch.ts): what it reads of this machine (pi-intercom's list, Herdr's panes, the board and capacity files, the load, `capacity.budget`), and whom it tells:
|
|
15
15
|
// the tower of the main's workspace (as the stall watch finds it), this device's standing main, and for `under` and `stale` the main itself. Kept out of main.ts, which carries a line budget.
|
|
16
16
|
|
|
17
|
-
/** `capacity.budget` of `<state dir>/config.json`: a number of points over 0 (at most 1000); none when it is unset or not such a number. */
|
|
18
|
-
export function readBudget(stateDir: string): number | undefined {
|
|
19
|
-
try {
|
|
20
|
-
const b = (JSON.parse(readFileSync(join(stateDir, "config.json"), "utf8")) as { capacity?: { budget?: unknown } }).capacity?.budget;
|
|
21
|
-
return typeof b === "number" && Number.isFinite(b) && b > 0 && b <= 1000 ? b : undefined;
|
|
22
|
-
} catch {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
17
|
/** pi-loop-monitor persists loops-<pi-session-id>.json. No mutating store import; consume only the active flag and expiry. */
|
|
28
18
|
export function armedLoop(dir: string, session: string, now: number): boolean {
|
|
29
19
|
if (!safeSession(session)) return false;
|
package/src/session.ts
CHANGED
|
@@ -33,7 +33,7 @@ const CHECKING = "Straw Boss is still asking Herdr whether this is a sub workspa
|
|
|
33
33
|
const UNPLACED = (why: string) => `Straw Boss could not tell whether this is a sub workspace: ${why}; it asks again`;
|
|
34
34
|
|
|
35
35
|
/** What the session does at its start, around each run, and at its end. */
|
|
36
|
-
export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles, presence, membership, guard, host, reach, digest, control, integration, startTower }: { mainDuty: MainDuty; runMode: RunMode; briefing: Briefing; roles: Roles; presence: Presence; membership: Membership; guard: Guard; host: ReturnType<typeof createHost>; reach: Reach; digest: Digest; control: Control; integration: IntegrationWatch; startTower(): Promise<void
|
|
36
|
+
export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles, presence, membership, guard, host, reach, digest, control, integration, startTower, attended }: { mainDuty: MainDuty; runMode: RunMode; briefing: Briefing; roles: Roles; presence: Presence; membership: Membership; guard: Guard; host: ReturnType<typeof createHost>; reach: Reach; digest: Digest; control: Control; integration: IntegrationWatch; startTower(): Promise<void>; /** Whether a person is at this device (the link's policy): the worker cap holds only on an unattended one. */ attended(): boolean }) {
|
|
37
37
|
const { pi, cfg, s, guiDir, me, role, tell } = kit;
|
|
38
38
|
const { run, env, version } = cfg;
|
|
39
39
|
const who = () => pi.getSessionName() || s.ownName || me().slice(0, 8);
|
|
@@ -325,7 +325,7 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
|
|
|
325
325
|
|
|
326
326
|
// A member that dispatches or resumes a subagent without promoting is promoted here, before the subagent starts, unless the tab already has a main.
|
|
327
327
|
// A tower only coordinates: it dispatches no subagent (one would outlive it with no one to take its result), and opens a main for the work instead.
|
|
328
|
-
const cap = createWorkerCap(
|
|
328
|
+
const cap = createWorkerCap(deviceRoom(guiDir, me, attended));
|
|
329
329
|
pi.on("turn_end", () => cap.settle());
|
|
330
330
|
pi.on("tool_call", async (event, ctx) => {
|
|
331
331
|
if (!SUBAGENT_TOOLS.includes(event.toolName) || runMode.active()) return;
|
|
@@ -346,7 +346,7 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
|
|
|
346
346
|
tell(`Straw Boss: ${(error as Error).message}`, "warning");
|
|
347
347
|
}
|
|
348
348
|
mainDuty.migrate(pi.getSessionName()); // the promotion above may have just made this an `integ <project>` main whose migration had not run
|
|
349
|
-
// No plan gates a worker (docs/specs/2026-11-23-lite-main.md §1)
|
|
349
|
+
// No plan gates a worker (docs/specs/2026-11-23-lite-main.md §1) and no count does: only an unattended device with a capacity budget holds one back, by its points (docs/specs/2026-11-24-capacity.md, The cap).
|
|
350
350
|
if (event.toolName === "subagent") return cap.admit(event.toolCallId, event.input, () => ctx.sessionManager.getBranch()); // the todo its `name` owns weighs it
|
|
351
351
|
});
|
|
352
352
|
|
package/src/workercap.ts
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { capDir, DEFAULT_POINTS, nameKey, readDevice } from "./capacity.ts";
|
|
2
|
+
import { capDir, DEFAULT_POINTS, nameKey, readBudget, readDevice } from "./capacity.ts";
|
|
3
3
|
import { createReservations, type Holder, type Reservations } from "./capres.ts";
|
|
4
4
|
import { dutyOfAgent } from "./duty.ts";
|
|
5
5
|
import { todosOf } from "./items.ts";
|
|
6
6
|
import { snapshotScan } from "./todo.ts";
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// Worker admission (docs/specs/2026-11-24-capacity.md, The cap). sb holds back no worker by count: on an attended device (the boss's own, who watches it) nothing gates a worker, and its
|
|
9
|
+
// `capacity.budget` only feeds the board and the capacity notices. On an unattended device the device's points gate `worker` subagents against `capacity.budget`, read from config.json at
|
|
10
|
+
// each admission (a change applies at once; none set: no cap, and no built-in figure). Scouts, planners, reviewers, and resumes are not workers and are never held.
|
|
11
11
|
|
|
12
|
-
export const WORKER_CAP = 4;
|
|
13
12
|
const REGISTRY = Symbol.for("pi-subagents/runtime");
|
|
14
13
|
|
|
15
|
-
/** The workers pi-herdr-agents runs for this process, or undefined when
|
|
16
|
-
function runningWorkers():
|
|
14
|
+
/** The names of the workers pi-herdr-agents runs for this process (its registry of the children it still waits on), or undefined when the registry cannot be read. */
|
|
15
|
+
function runningWorkers(): string[] | undefined {
|
|
17
16
|
const map = (globalThis as Record<symbol, { runningSubagents?: unknown } | undefined>)[REGISTRY]?.runningSubagents;
|
|
18
17
|
if (!(map instanceof Map)) return undefined;
|
|
19
|
-
|
|
20
|
-
for (const run of map.values()) if (dutyOfAgent((run as { agent?: unknown } | null)?.agent as string | undefined) === "worker") n++;
|
|
21
|
-
return n;
|
|
18
|
+
return [...map.values()].flatMap((run) => (dutyOfAgent((run as { agent?: string } | null)?.agent) === "worker" ? [String((run as { name?: unknown }).name ?? "")] : []));
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
/** The device's capacity as the sb server last wrote it (capacity.ts `readDevice`): points in use,
|
|
25
|
-
export interface Room { points: number;
|
|
26
|
-
/** What the cap reads of the device: its row, the reservations every main of it shares (capres.ts),
|
|
27
|
-
export interface DeviceSide { room(): Room | undefined; store: Reservations; session(): string | undefined }
|
|
21
|
+
/** The device's capacity as the sb server last wrote it (capacity.ts `readDevice`): points in use, when the row was sampled, and the mains it sampled with their running workers. */
|
|
22
|
+
export interface Room { points: number; at?: number; mains?: readonly { session: string; workers?: readonly string[] }[] }
|
|
23
|
+
/** What the cap reads of the device: its fresh row, the reservations every main of it shares (capres.ts), this main's session id, the budget now, and whether a person is at it. */
|
|
24
|
+
export interface DeviceSide { room(): Room | undefined; store: Reservations; session(): string | undefined; budget(): number | undefined; attended(): boolean }
|
|
28
25
|
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return { room: () => readDevice(dir, Date.now()), store: createReservations(dir, Date.now), session: me };
|
|
26
|
+
// A worker starts while the points in use, the points the device's reservations hold (launches of any main that no row shows yet), and its own fit the budget. Its reservation is written
|
|
27
|
+
// before the row and the sum are read, so two mains that launch at once see each other. The server samples only the mains of its own Herdr slot: a main the row does not list (another slot,
|
|
28
|
+
// not sampled yet) or any main while no fresh row exists still reserves device-wide, and adds its own running workers from its registry, which no row counts, in place of its own launched reservations.
|
|
29
|
+
/** The device row, reservations, and budget of the state folder `stateDir`, for the main whose session id `me` gives; `attended` says whether a person is at the device (the link's policy). */
|
|
30
|
+
export const deviceRoom = (stateDir: string, me: () => string | undefined, attended: () => boolean): DeviceSide => {
|
|
31
|
+
const dir = capDir(join(stateDir, "board"));
|
|
32
|
+
return { room: () => readDevice(dir, Date.now()), store: createReservations(dir, Date.now), session: me, budget: () => readBudget(stateDir), attended };
|
|
37
33
|
};
|
|
38
34
|
/** The row shows a launch: it lists the main's session with a running worker of the launch's (folded) name. */
|
|
39
35
|
const shows = (r: Room, h: Holder) => h.worker !== "" && (r.mains?.find((m) => m.session === h.session)?.workers ?? []).some((w) => nameKey(w) === h.worker);
|
|
36
|
+
const sum = (xs: readonly number[]) => xs.reduce((n, x) => n + x, 0);
|
|
40
37
|
|
|
41
|
-
export function createWorkerCap(
|
|
42
|
-
/** Worker calls admitted whose tool has not returned yet
|
|
43
|
-
const admitted = new Map<string, string
|
|
38
|
+
export function createWorkerCap(device?: DeviceSide) {
|
|
39
|
+
/** Worker calls admitted whose tool has not returned yet, each with its reservation's id. */
|
|
40
|
+
const admitted = new Map<string, string>();
|
|
44
41
|
const snapshotOf = snapshotScan();
|
|
45
42
|
/** The `metadata.points` of the main's own open todo whose `owner` is the subagent's `name` (read as capfill.ts reads the list), as the board's headroom weighs a ready todo; 1 without one. */
|
|
46
43
|
const weight = (name: unknown, branch?: () => readonly unknown[]): number => {
|
|
@@ -51,32 +48,30 @@ export function createWorkerCap(cap = WORKER_CAP, device?: DeviceSide) {
|
|
|
51
48
|
return (mine.find((t) => t.status === "in_progress") ?? mine[0])?.points ?? DEFAULT_POINTS;
|
|
52
49
|
};
|
|
53
50
|
return {
|
|
54
|
-
/** pi's `tool_call` for `subagent`: a refusal when `input.agent` is a worker
|
|
51
|
+
/** pi's `tool_call` for `subagent`: on an unattended device with a budget, a refusal when `input.agent` is a worker the device's points leave no room for. `branch`: the main's session entries, for the todo's weight. */
|
|
55
52
|
admit(toolCallId: string, input: unknown, branch?: () => readonly unknown[]): { block: true; reason: string } | undefined {
|
|
56
53
|
const { agent, name } = (input ?? {}) as { agent?: unknown; name?: unknown };
|
|
57
|
-
if (typeof agent !== "string" || dutyOfAgent(agent) !== "worker") return undefined;
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
else if (r.points + held + need > r.budget) {
|
|
72
|
-
device.store.drop(id);
|
|
73
|
-
return { block: true, reason: `sb: the device runs ${r.points} of its ${r.budget} capacity points, ${Math.round(held * 100) / 100} more held by launches it does not count yet: this worker needs ${need}. Wait for a result, then dispatch the next; a scout, a planner, or a reviewer may run now.` };
|
|
74
|
-
} else return void admitted.set(toolCallId, id);
|
|
54
|
+
if (typeof agent !== "string" || dutyOfAgent(agent) !== "worker" || !device || device.attended()) return undefined;
|
|
55
|
+
const budget = device.budget();
|
|
56
|
+
if (budget === undefined) return undefined;
|
|
57
|
+
const me = device.session() ?? "", need = weight(name, branch);
|
|
58
|
+
let id: string | undefined, used = 0, held = 0;
|
|
59
|
+
try {
|
|
60
|
+
id = device.store.add(need, { session: me, worker: typeof name === "string" ? nameKey(name) : "" });
|
|
61
|
+
const r = device.room(); // read after the reservation is published
|
|
62
|
+
const own = r?.mains?.some((m) => m.session === me) ? undefined : runningWorkers(); // no row counts this main's workers: its registry does
|
|
63
|
+
used = (r?.points ?? 0) + sum((own ?? []).map((w) => weight(w, branch)));
|
|
64
|
+
held = sum(device.store.live(r?.at ?? -Infinity, (h) => r !== undefined && shows(r, h)).filter((x) => x.id !== id && !(own && x.session === me && x.launched)).map((x) => x.points));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
try { if (id !== undefined) device.store.drop(id); } catch { /* it expires */ }
|
|
67
|
+
return { block: true, reason: `sb: the device's capacity reservation could not be written (${(error as Error).message}): no worker starts until it can.` };
|
|
75
68
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
if (used + held + need > budget) {
|
|
70
|
+
device.store.drop(id);
|
|
71
|
+
const pts = (n: number) => Math.round(n * 100) / 100;
|
|
72
|
+
return { block: true, reason: `sb: the device runs ${pts(used)} of its ${budget} capacity points, ${pts(held)} more held by launches it does not count yet: this worker needs ${need}. Wait for a result, then dispatch the next; a scout, a planner, or a reviewer may run now.` };
|
|
73
|
+
}
|
|
74
|
+
admitted.set(toolCallId, id);
|
|
80
75
|
return undefined;
|
|
81
76
|
},
|
|
82
77
|
/** pi's `tool_result` for `subagent`: the launch ended, and the registry holds the worker if it started. A reservation stays for a launch that returned, and goes for one that failed. */
|
|
@@ -87,7 +82,7 @@ export function createWorkerCap(cap = WORKER_CAP, device?: DeviceSide) {
|
|
|
87
82
|
},
|
|
88
83
|
/** The turn ended: every call of it has run, or was blocked by another extension, which leaves no result: its reservation goes. */
|
|
89
84
|
settle(): void {
|
|
90
|
-
for (const id of admitted.values()) if (
|
|
85
|
+
for (const id of admitted.values()) if (device) try { device.store.drop(id); } catch { /* it expires */ }
|
|
91
86
|
admitted.clear();
|
|
92
87
|
},
|
|
93
88
|
};
|