pi-straw-boss 0.116.0 → 0.116.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.
@@ -6309,8 +6309,8 @@ var FULL = 1 << 20;
6309
6309
  var TEXT = 1e5;
6310
6310
  var LAST_BYTES = 65536;
6311
6311
  var FULL_LIMIT = FULL;
6312
- var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
6313
6312
  var UID = /^t_[a-z2-7]{10}$/;
6313
+ var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
6314
6314
  var AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
6315
6315
  var obj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
6316
6316
  var cut3 = (v, n) => typeof v === "string" && v ? v.slice(0, n) : void 0;
@@ -7164,12 +7164,13 @@ var RUNS_MAX = 64;
7164
7164
  var todoOk = (v) => {
7165
7165
  const t = v;
7166
7166
  const count4 = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 200;
7167
+ const uid2 = (s2) => typeof s2 === "string" && UID.test(s2);
7167
7168
  const plain5 = (s2, max) => typeof s2 === "string" && s2.length > 0 && s2.length <= max && !/[\p{Cc}\p{Cf}]/u.test(s2);
7168
7169
  const step = (r) => {
7169
7170
  const x = r;
7170
7171
  return x !== null && typeof x === "object" && Object.keys(x).every((k) => ["id", "kind", "status", "name", "round", "outcome"].includes(k)) && Number.isSafeInteger(x.id) && x.id >= 1 && plain5(x.kind, 32) && ["pending", "in_progress", "completed"].includes(x.status) && (x.name === void 0 || plain5(x.name, 64)) && (x.round === void 0 || Number.isSafeInteger(x.round) && x.round >= 1) && (x.outcome === void 0 || ["passed", "failed", "void"].includes(x.outcome));
7171
7172
  };
7172
- return t !== null && typeof t === "object" && count4(t.done) && count4(t.total) && t.done <= t.total && t.total > 0 && (t.now === void 0 || plain5(t.now, TODO_TEXT)) && (t.steps === void 0 || Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step)) && (t.graph === void 0 || GRAPHS.includes(t.graph)) && (t.doing === void 0 || Number.isSafeInteger(t.doing) && t.doing >= 0) && (t.runs === void 0 || Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain5(r.run, 64)));
7173
+ return t !== null && typeof t === "object" && count4(t.done) && count4(t.total) && t.done <= t.total && t.total > 0 && (t.now === void 0 || plain5(t.now, TODO_TEXT)) && (t.steps === void 0 || Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step)) && (t.graph === void 0 || GRAPHS.includes(t.graph)) && (t.doing === void 0 || Number.isSafeInteger(t.doing) && t.doing >= 0) && (t.doingUid === void 0 || uid2(t.doingUid)) && (t.runs === void 0 || Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain5(r.run, 64) && (r.uid === void 0 || uid2(r.uid))));
7173
7174
  };
7174
7175
 
7175
7176
  // src/dialogs.ts
@@ -7278,7 +7279,7 @@ function createHub(pi, me, local, onAllow) {
7278
7279
  const docs = msg.type === "dialogs" && (msg.documents === void 0 ? [] : docsOf({ version: 1, documents: msg.documents }));
7279
7280
  const queued = msg.type === "dialogs" && Array.isArray(msg.queued) && msg.queued.length <= MAX_QUEUED && msg.queued.every((q2) => typeof q2?.text === "string" && q2.text.length <= QUEUED_TEXT && (q2.as === "steer" || q2.as === "followUp")) ? msg.queued.map(({ text: text14, as }) => ({ text: text14, as })) : void 0;
7280
7281
  const monitors = msg.type === "dialogs" && monitorsOk(msg.monitors) ? msg.monitors.map(({ id: id2, what, status, exit, last, load: load3, lines, at, ended }) => ({ id: id2, what, status, exit, last, load: load3, lines, at, ended })) : void 0;
7281
- const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...msg.todo.now && { now: msg.todo.now }, ...msg.todo.graph && { graph: msg.todo.graph }, ...msg.todo.doing !== void 0 && { doing: msg.todo.doing }, ...msg.todo.runs && { runs: msg.todo.runs.map(({ id: id2, run: run2 }) => ({ id: id2, run: run2 })) }, ...msg.todo.steps && { steps: msg.todo.steps.map(({ id: id2, kind, status, name: name2, round: round2, outcome }) => ({ id: id2, kind, status, ...name2 !== void 0 && { name: name2 }, ...round2 !== void 0 && { round: round2 }, ...outcome && { outcome } })) } } : void 0;
7282
+ const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...msg.todo.now && { now: msg.todo.now }, ...msg.todo.graph && { graph: msg.todo.graph }, ...msg.todo.doing !== void 0 && { doing: msg.todo.doing }, ...msg.todo.doingUid && { doingUid: msg.todo.doingUid }, ...msg.todo.runs && { runs: msg.todo.runs.map(({ id: id2, run: run2, uid: uid2 }) => ({ id: id2, run: run2, ...uid2 && { uid: uid2 } })) }, ...msg.todo.steps && { steps: msg.todo.steps.map(({ id: id2, kind, status, name: name2, round: round2, outcome }) => ({ id: id2, kind, status, ...name2 !== void 0 && { name: name2 }, ...round2 !== void 0 && { round: round2 }, ...outcome && { outcome } })) } } : void 0;
7282
7283
  if (closed && str7(msg.pane) && (msg.file === null || str7(msg.file)) && Array.isArray(msg.dialogs) && msg.dialogs.every(valid)) noteAllows(from, msg), bridges.set(from, { ...msg, ...docs ? { documents: docs } : { documents: [], docsCut: true }, queued, monitors, todo }), changed();
7283
7284
  if (msg.type === "ack") waiting.get([from, msg.bridgeId, msg.id, msg.answerId].join("\n"))?.(msg);
7284
7285
  if (msg.type === "probe-result") probes.get([from, msg.bridgeId, msg.probeId].join("\n"))?.(checkProbe({ ...msg }));
@@ -21375,10 +21376,11 @@ function places(net) {
21375
21376
  }
21376
21377
  var askerOf = (p, paneOf2) => ((pane) => ({ session: p.u.key, name: p.u.name, role: p.u.role, workspace: p.ws, workspaceLabel: p.wsLabel, ...p.tab ? { tab: p.tab, tabLabel: p.tabLabel } : {}, ...pane ? { pane } : {} }))(paneOf2?.(p.u.key));
21377
21378
  function itemOf(p, explicit) {
21378
- if (explicit) return { session: p.u.key, id: explicit };
21379
+ const own = (id2) => ((uid2) => ({ session: p.u.key, id: id2, ...uid2 && { uid: uid2 } }))(id2 === p.u.todo?.doing ? p.u.todo.doingUid : p.u.todo?.runs?.find((r) => r.id === id2)?.uid);
21380
+ if (explicit) return own(explicit);
21379
21381
  const bound = p.launcher?.todo?.runs?.find((r) => r.run === p.u.key);
21380
- if (bound && p.launcher) return { session: p.launcher.key, id: bound.id };
21381
- return p.u.todo?.doing !== void 0 ? { session: p.u.key, id: p.u.todo.doing } : void 0;
21382
+ if (bound && p.launcher) return { session: p.launcher.key, id: bound.id, ...bound.uid && { uid: bound.uid } };
21383
+ return p.u.todo?.doing !== void 0 ? own(p.u.todo.doing) : void 0;
21382
21384
  }
21383
21385
  var subjectOf2 = (u) => {
21384
21386
  const p = u.pending, qs = p.asks ?? (p.ask ? [p.ask] : (p.answer?.questions ?? []).map((q2) => ({ question: q2.question })));
@@ -21513,7 +21515,7 @@ function startAsks(d) {
21513
21515
  const ask = r.ask ?? {}, session = str10(r.session, 128), questions = questionsOf3(ask.questions), item = Number.isSafeInteger(ask.item) && ask.item > 0 ? ask.item : void 0;
21514
21516
  if (!session || !questions) return Promise.resolve({ ok: false, error: "ask-open needs a session and one to four questions of up to eight options" });
21515
21517
  const place = last ? seenIn(last.net).place(session) : void 0;
21516
- const rec = store2.open({ kind: "boss", asker: { session, name: str10(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str10(ask.subject, 2e3) ?? questions[0].question, questions, ...str10(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId } : {}, ...item ? { item: { session, id: item } } : {} });
21518
+ const rec = store2.open({ kind: "boss", asker: { session, name: str10(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str10(ask.subject, 2e3) ?? questions[0].question, questions, ...str10(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId } : {}, ...item ? { item: { session, id: item, ...typeof ask.itemUid === "string" && UID.test(ask.itemUid) && { uid: ask.itemUid } } } : {} });
21517
21519
  d.log("ask-open", { n: rec.n, kind: rec.kind });
21518
21520
  return Promise.resolve({ ok: true, ask: rec });
21519
21521
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.116.0",
3
+ "version": "0.116.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/src/askclient.ts CHANGED
@@ -10,7 +10,7 @@ import type { ServerCall } from "./traincar.ts";
10
10
  * question is asked as before the store, and an Ask the server opened meanwhile is closed when its tool call ends (askops.ts).
11
11
  */
12
12
  export interface AskClient {
13
- open(a: { subject: string; questions: { question: string; options: string[] }[]; toolCallId?: string; item?: number }): Promise<{ id: string; digest: string } | undefined>;
13
+ open(a: { subject: string; questions: { question: string; options: string[] }[]; toolCallId?: string; item?: number; itemUid?: string }): Promise<{ id: string; digest: string } | undefined>;
14
14
  answer(id: string, a: { answerId: string; digest: string; replies?: { choices?: number[]; text?: string; note?: string }[]; cancel?: true; by: "terminal" | "gui" | "phone" }): Promise<{ status: number; body: Record<string, unknown> } | undefined>;
15
15
  get(id: string): Promise<AskState | undefined>;
16
16
  close(id: string, why: "esc" | "abort" | "auto"): Promise<AskState | undefined>;
package/src/askrows.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { ASK_ROWS_EVENT, type AskRowV1 } from "./asktypes.ts";
2
+ import { ASK_ROWS_EVENT, type AskRowsAnswerV1, type AskRowV1 } from "./asktypes.ts";
3
3
  import { localeOf, type Locale } from "./locale.ts";
4
4
  import type { Kit } from "./state.ts";
5
5
  import { todosOfBranch } from "./todo.ts";
6
6
  import { callServer, type ServerCall } from "./traincar.ts";
7
7
 
8
8
  // A session's rows of the open questions to the boss (docs/specs/2026-11-28-boss-asks.md, The probe): it asks the sb server every 15 s (`asks-rows`), answers `straw-boss:ask-rows:v1` from the last answer at once (the
9
- // probe is synchronous), and prints the same rows for `/boss asks`. The rows are every open Ask of this computer; `mine` and `item` let the reader put a row under the todo it blocks.
9
+ // probe is synchronous), and prints the same rows for `/boss asks`. The rows are every open Ask of this computer; `mine`, `item` and the probe's `session` (which `item.session` is this one) place a row under its todo.
10
10
 
11
11
  /** Between two asks of the server; the probe's rows stand for what waits now only this long after the server's last answer (three asks), then the probe answers none (asks-r2-F007). */
12
12
  export const ASK_MS = 15_000, STALE_MS = 45_000;
@@ -47,7 +47,7 @@ export function registerAskRows(d: AskRowsDeps) {
47
47
  const refresh = () => (running ??= look().finally(() => { running = undefined; }));
48
48
  d.pi.events.on(ASK_ROWS_EVENT, (raw) => {
49
49
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
50
- Object.assign(raw, { rows: { version: 1, rows: current().map((r) => ({ ...r })) } });
50
+ Object.assign(raw, { rows: { version: 1, session: d.me(), rows: current().map((r) => ({ ...r })) } satisfies AskRowsAnswerV1 });
51
51
  });
52
52
  if (every > 0) {
53
53
  d.pi.on("session_start", () => {
package/src/asktypes.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  // The shapes the Asks of docs/specs/2026-11-28-boss-asks.md show in: the probe's row (a contract: pi-todo-ledger reads it) and the page's view (the net's `asks`, this computer only). Free of Node, so the page imports it.
2
2
 
3
3
  export type AskKind = "boss" | "dialog" | "wait" | "link";
4
- /** The todo an Ask blocks: the session whose list holds it, and its id there. */
5
- export interface AskItem { session: string; id: number }
4
+ /** The todo an Ask blocks: the session whose list holds it, its id there, and its uid when the binding knew it (a reader checks it: `clear` lets a new todo take the id). */
5
+ export interface AskItem { session: string; id: number; uid?: string }
6
6
  export const ASK_ROWS_EVENT = "straw-boss:ask-rows:v1";
7
7
  /** One row of `straw-boss:ask-rows:v1`. */
8
8
  export interface AskRowV1 { id: string; subject: string; asker: string; where: string; kind: AskKind; since: number; mine: boolean; item?: AskItem }
9
+ /** The probe's answer: `session` is the id `item.session` names this session by (an older sb leaves it out). */
10
+ export interface AskRowsAnswerV1 { version: 1; session: string; rows: AskRowV1[] }
9
11
  /**
10
12
  * An open Ask as the page draws it: `unit` is the unit on the net whose plate counts it (the asker, or the tower for a wait whose raiser is not on the net), `ws` its workspace, `wait` the W id of a wait card (its
11
13
  * alert is the card), `pane` whether the asker has a pane the page can open.
package/src/bossask.ts CHANGED
@@ -57,7 +57,7 @@ async function paneDialog(ui: ExtensionContext["ui"], q: BossQuestion, title: st
57
57
  export function createBossAsk(kit: Kit, d: { attended(): boolean; remote(): boolean; asks?: AskClient }): BossAsk {
58
58
  const { pi, cfg, s, role } = kit, watch = cfg.face?.every ?? every, bus = pi.events as unknown as Bus;
59
59
  const asks = d.asks ?? askClient(cfg.server ? callServer(cfg.env, kit.guiDir) : async () => undefined, kit.me, () => (pi as { getSessionName?: () => string | undefined }).getSessionName?.());
60
- const doing = () => { try { return todosOfBranch(s.branch())?.find((t) => t.status === "in_progress")?.id; } catch { return undefined; } };
60
+ const todos = () => { try { return todosOfBranch(s.branch()) ?? []; } catch { return []; } };
61
61
  return async (q, signal, ctx, callId) => {
62
62
  if (role() !== "main" || s.isTrain || s.isTower || s.remoteOrigin || d.remote() || !d.attended() || !ctx?.hasUI) return { kind: "tower" };
63
63
  if (s.autoOn()) return { kind: "tower", note: AUTO_NOTE };
@@ -65,7 +65,9 @@ export function createBossAsk(kit: Kit, d: { attended(): boolean; remote(): bool
65
65
  const opts = { signal: signal ? AbortSignal.any([signal, ac.signal]) : ac.signal };
66
66
  // The first answer, here or there, wins: the store decides between the pane, the page and the phone; one from the page or a paired device ends the dialog here.
67
67
  let got: Got | undefined, looking = false, unconfirmed = false, autoCancel = false, won: string | undefined; // `won`: the answerId the store (else the relay) took, which the close names (asks-r3-F001)
68
- const ask = await asks.open({ subject: q.question, questions: [{ question: title, options: q.options ?? [] }], ...(callId ? { toolCallId: callId } : {}), ...((q.item ?? doing()) ? { item: q.item ?? doing() } : {}) }).catch(() => undefined);
68
+ // The todo it blocks, by id and uid (carrows-review-F001): a reader tells it from a todo that takes the id after `clear`.
69
+ const list = todos(), item = q.item ?? list.find((t) => t.status === "in_progress")?.id, itemUid = item ? list.find((t) => t.id === item)?.uid : undefined;
70
+ const ask = await asks.open({ subject: q.question, questions: [{ question: title, options: q.options ?? [] }], ...(callId ? { toolCallId: callId } : {}), ...(item ? { item, ...(itemUid ? { itemUid } : {}) } : {}) }).catch(() => undefined);
69
71
  const winner = (a: NonNullable<AskState["answer"]>) => void (!got && ((got = gotOf(q, a)), (won = a.answerId), ac.abort()));
70
72
  const judged = (r: Awaited<ReturnType<AskClient["answer"]>>): Took | undefined => (!r ? undefined : r.status === 200 ? "won" : (r.status === 409 && (r.body.ask as AskState | undefined)?.answer && winner((r.body.ask as AskState).answer!), "lost"));
71
73
  /**
package/src/bosspair.ts CHANGED
@@ -8,7 +8,7 @@ import { createPreflight } from "./preflight.ts";
8
8
  // server opens thread T<n> for this session (server/threads.ts); the two children talk on it (threadtools.ts) and the main is woken only by their two results when it closes. The tool is registered with the net tools at the join,
9
9
  // so the main has it from its session start; a role or a turn that may not pair is refused at the call. `board_read thread` reads a thread through `read` here.
10
10
 
11
- export const PAIR_DESCRIPTION = "A reviewed change: pair a worker and a reviewer on thread T<n> first, then dispatch both with subagent under these names, each task with the line `Thread: T<n>`; you write both briefs. You are woken only by their two results when the thread closes; do not relay.";
11
+ export const PAIR_DESCRIPTION = "Pair worker and reviewer on T<n>, then dispatch both via subagent under these names. Write both briefs, each with `Thread: T<n>`. Only final results wake you at thread close; don't relay.";
12
12
 
13
13
  export function createBossPair({ pi, s, me, role }: Kit, d: { ask?: Ask; remote(): boolean }) {
14
14
  const ask = async (request: Record<string, unknown>, start: "auto" | "never" = "auto") => {
@@ -28,8 +28,8 @@ export function createBossPair({ pi, s, me, role }: Kit, d: { ask?: Ask; remote(
28
28
  pi.registerTool({
29
29
  name: "boss_pair", label: "boss_pair", description: PAIR_DESCRIPTION,
30
30
  parameters: Type.Object({
31
- worker: Type.String({ minLength: 1, maxLength: 64, description: "Its subagent name." }),
32
- reviewer: Type.String({ minLength: 1, maxLength: 64, description: "Its subagent name." }),
31
+ worker: Type.String({ minLength: 1, maxLength: 64 }),
32
+ reviewer: Type.String({ minLength: 1, maxLength: 64 }),
33
33
  rounds: Type.Optional(Type.Integer({ minimum: 1, maximum: 3, description: "Repair rounds, default 3." })), item: Type.Optional(Type.String({ maxLength: 64, description: "Its todo: uid or <session8>#<id>." })),
34
34
  }),
35
35
  execute: async (_id, { worker, reviewer, rounds, item }, _signal, _onUpdate, ctx) => {
package/src/bosswatch.ts CHANGED
@@ -11,7 +11,7 @@ import type { Kit } from "./state.ts";
11
11
  // follow-up) or starts a turn when the main is idle; it never steers. The channel registers at the first `boss_watch` and at each join that finds a watch of this session on the server, so a /reload keeps receiving.
12
12
 
13
13
  export const WATCH_MESSAGE = "straw-boss-watch";
14
- export const WATCH_DESCRIPTION = "Have the sb server watch one unit of the net and wake you when it changes, instead of checking in your own turns. key: a main's, train's, or subagent's key or session id, or a teammate device's link:<short>[/<unit>|/main/<handle>]. You get one line per change of state (mark, a monitor's status or exit, todo progress, a train's step, its subagents), stalled (no activity for quiet), idle (idle that long), a link wait, offline, gone (it ended), or expired (until): at most one a minute per watch, the newest state only, 12 an hour; while you work it waits for the end of your turn. stop: end it. No key: list your watches. Main or train only.";
14
+ export const WATCH_DESCRIPTION = "Main/train: watch one net unit; don't poll. Wakes for mark, monitor status/exit, todo progress, train step, subagents, stalled/idle, link wait, offline, gone or expired. Latest state only, max 1/min/watch and 12/hour, after any busy turn.";
15
15
  const MIN_MS = 60_000, MAX_MS = 48 * 3_600_000;
16
16
 
17
17
  /** A length: `90s`, `20m`, `2h`, or plain milliseconds. */
@@ -52,9 +52,9 @@ export function createBossWatch({ pi, cfg, s, guiDir, me, role }: Kit, d: { ask?
52
52
  pi.registerTool({
53
53
  name: "boss_watch", label: "boss_watch", description: WATCH_DESCRIPTION,
54
54
  parameters: Type.Object({
55
- key: Type.Optional(Type.String({ description: "The unit's key or session id, or link:<short>…; none lists your watches." })),
56
- quiet: Type.Optional(Type.String({ description: "stalled after this long without activity: 30m, 2h (at least 1m)." })),
57
- idle: Type.Optional(Type.String({ description: "idle after this long idle (at least 1m)." })),
55
+ key: Type.Optional(Type.String({ description: "Main/train/subagent key or session ID, or link:<short>[/<unit>|/main/<handle>]. Omit to list watches." })),
56
+ quiet: Type.Optional(Type.String({ description: "Stalled after no activity (min 1m; e.g. 30m, 2h)." })),
57
+ idle: Type.Optional(Type.String({ description: "Idle threshold (min 1m)." })),
58
58
  until: Type.Optional(Type.String({ description: "How long the watch lasts. Default 6h, at most 48h." })),
59
59
  stop: Type.Optional(Type.Boolean({ description: "true: end the watch on key." })),
60
60
  }),
package/src/callpeer.ts CHANGED
@@ -14,7 +14,7 @@ import { checkoutProject, repoRoot } from "./train/appsconfig.ts";
14
14
  export const PEER_TOOL = "call_peer";
15
15
  const TARGETS = ["sender", "caller", "main", "integrator"] as const;
16
16
  type To = (typeof TARGETS)[number];
17
- export const PEER_DESCRIPTION = "Message an sb net peer, found at the call (successor after a handover). to: sender (last wrote you), caller (opened you), main (your tab's; of: another's name, todo item, or tab), integrator (your project's). ask: reply expected.";
17
+ export const PEER_DESCRIPTION = "Message a net peer (uses live successor after handover). to: sender (last writer), caller (opened you), main (your tab; of: another name/item/tab), integrator (your project). ask expects a reply.";
18
18
  export const peerParameters = () => Type.Object({
19
19
  // An enum, not a union of literals: 89 bytes fewer on every turn (pi-ai's validator checks `enum`).
20
20
  to: Type.Unsafe<To>(Type.String({ enum: TARGETS })),
package/src/carrows.ts CHANGED
@@ -2,7 +2,8 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { CAR_ROWS_EVENT, carRows, carsText, type SentSlip, type TodoRef, UNRECEIVED_MS } from "./carline.ts";
3
3
  import { localeOf, type Locale } from "./locale.ts";
4
4
  import type { Kit } from "./state.ts";
5
- import { todosOfBranch } from "./todo.ts";
5
+ import { todosOf } from "./items.ts";
6
+ import { snapshotScan } from "./todo.ts";
6
7
  import type { CarFact } from "./train/carfacts.ts";
7
8
  import { slipsInText } from "./train/cars.ts";
8
9
  import { callServer, type ServerCall } from "./traincar.ts";
@@ -38,8 +39,17 @@ export function registerCarRows(d: CarRowsDeps) {
38
39
  const held = d.held ?? heldSlips(), every = d.every ?? ASK_MS;
39
40
  let facts: CarFact[] = [], answered: number | undefined, timer: ReturnType<typeof setInterval> | undefined, running: Promise<void> | undefined;
40
41
  const sent = () => held.get(d.me()) ?? [];
41
- const todos = (): TodoRef[] => { try { return (todosOfBranch(d.branch()) ?? []).map((t) => ({ id: t.id, subject: t.subject, status: t.status, ...(t.uid ? { uid: t.uid } : {}) })); } catch { return []; } };
42
- const rows = () => carRows({ facts, sent: sent(), todos: todos(), me: d.me(), lang: d.lang(), now: d.now() });
42
+ // The todo list is read again only when the branch's snapshot changed: the probe is asked at every draw (carrows-review-F004).
43
+ const scan = snapshotScan();
44
+ let list: { snapshot: unknown; refs: TodoRef[] } | undefined;
45
+ const todos = (): TodoRef[] => {
46
+ try {
47
+ const snapshot = scan(d.branch());
48
+ if (list && list.snapshot === snapshot) return list.refs;
49
+ return (list = { snapshot, refs: (todosOf(snapshot) ?? []).map((t) => ({ id: t.id, subject: t.subject, status: t.status, ...(t.uid ? { uid: t.uid } : {}) })) }).refs;
50
+ } catch { return []; }
51
+ };
52
+ const rows = () => (facts.length || sent().length ? carRows({ facts, sent: sent(), todos: todos(), me: d.me(), lang: d.lang(), now: d.now() }) : []);
43
53
 
44
54
  // A slip the tower took: each car of the message whose coordinator is this session (a slip that names none is the sender's own).
45
55
  d.pi.on("tool_result", (event) => {
@@ -71,7 +81,7 @@ export function registerCarRows(d: CarRowsDeps) {
71
81
 
72
82
  d.pi.events.on(CAR_ROWS_EVENT, (raw) => {
73
83
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
74
- Object.assign(raw, { rows: { version: 1, rows: rows() } });
84
+ Object.assign(raw, { rows: { version: 1, session: d.me(), rows: rows() } });
75
85
  });
76
86
  if (every > 0) {
77
87
  d.pi.on("session_start", () => {
package/src/dialogs.ts CHANGED
@@ -144,7 +144,7 @@ export function createHub(pi: ExtensionAPI, me: string, local: Bridge, onAllow?:
144
144
  // A queue out of shape is left out; the dialogs and documents still go.
145
145
  const queued = msg.type === "dialogs" && Array.isArray(msg.queued) && msg.queued.length <= MAX_QUEUED && msg.queued.every((q) => typeof q?.text === "string" && q.text.length <= QUEUED_TEXT && (q.as === "steer" || q.as === "followUp")) ? msg.queued.map(({ text, as }) => ({ text, as })) : undefined;
146
146
  const monitors = msg.type === "dialogs" && monitorsOk(msg.monitors) ? msg.monitors.map(({ id, what, status, exit, last, load, lines, at, ended }) => ({ id, what, status, exit, last, load, lines, at, ended })) : undefined;
147
- const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...(msg.todo.now && { now: msg.todo.now }), ...(msg.todo.graph && { graph: msg.todo.graph }), ...(msg.todo.doing !== undefined && { doing: msg.todo.doing }), ...(msg.todo.runs && { runs: msg.todo.runs.map(({ id, run }) => ({ id, run })) }), ...(msg.todo.steps && { steps: msg.todo.steps.map(({ id, kind, status, name, round, outcome }) => ({ id, kind, status, ...(name !== undefined && { name }), ...(round !== undefined && { round }), ...(outcome && { outcome }) })) }) } : undefined;
147
+ const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...(msg.todo.now && { now: msg.todo.now }), ...(msg.todo.graph && { graph: msg.todo.graph }), ...(msg.todo.doing !== undefined && { doing: msg.todo.doing }), ...(msg.todo.doingUid && { doingUid: msg.todo.doingUid }), ...(msg.todo.runs && { runs: msg.todo.runs.map(({ id, run, uid }) => ({ id, run, ...(uid && { uid }) })) }), ...(msg.todo.steps && { steps: msg.todo.steps.map(({ id, kind, status, name, round, outcome }) => ({ id, kind, status, ...(name !== undefined && { name }), ...(round !== undefined && { round }), ...(outcome && { outcome }) })) }) } : undefined;
148
148
  if (closed && str(msg.pane) && (msg.file === null || str(msg.file)) && Array.isArray(msg.dialogs) && msg.dialogs.every(valid)) (noteAllows(from, msg), bridges.set(from, { ...msg, ...(docs ? { documents: docs } : { documents: [], docsCut: true as const }), queued, monitors, todo }), changed());
149
149
  if (msg.type === "ack") waiting.get([from, msg.bridgeId, msg.id, msg.answerId].join("\n"))?.(msg);
150
150
  if (msg.type === "probe-result") probes.get([from, msg.bridgeId, msg.probeId].join("\n"))?.(checkProbe({ ...msg }));
package/src/doctorlive.ts CHANGED
@@ -11,7 +11,7 @@ import { agentDirOf, diagnose, type DoctorFacts, type DoctorReport, type DoctorR
11
11
  // self-check, a child too, which never warns (doctor.ts selfCheckText); the tool and the command go to the sessions that are no child. What this process has is read here; what it means is doctor.ts's.
12
12
 
13
13
  export const DOCTOR_MESSAGE = "sb-doctor";
14
- const DESCRIPTION = "Check this session's own tools and loads: whether subagent, intercom, todo and MonitorCreate are registered and active, which subagent host loaded and is current, and what to do. Call it before concluding a tool is missing.";
14
+ const DESCRIPTION = "Before assuming a missing tool: check subagent, intercom, todo, MonitorCreate registration/activation, subagent host and freshness, and next steps.";
15
15
 
16
16
  export interface DoctorDeps {
17
17
  env: NodeJS.ProcessEnv;
@@ -59,19 +59,30 @@ export interface SimpleDeps {
59
59
 
60
60
  /** The API Maestro registers through: drops the tools and commands above, and refuses the dropped parameters before Maestro sees the call. */
61
61
  export function simpleApi(pi: ExtensionAPI, deps: SimpleDeps): ExtensionAPI {
62
+ let modelCatalog: string | undefined;
62
63
  const registerTool = (tool: ToolDefinition) => {
63
64
  if (DROPPED_TOOLS.includes(tool.name)) return;
64
65
  const dropped = Object.keys(DROPPED_PARAMS[tool.name] ?? {});
65
- const description = tool.name === "subagent" ? SUBAGENT_DESCRIPTION : tool.name === "subagent_resume" ? RESUME_DESCRIPTION : tool.description;
66
- const execute: ToolDefinition["execute"] = (id, params, signal, onUpdate, ctx) => {
66
+ const launch = tool.name === "subagent", list = tool.name === "subagents_list";
67
+ const description = launch ? SUBAGENT_DESCRIPTION : tool.name === "subagent_resume" ? RESUME_DESCRIPTION : list ? `${tool.description} See authenticated models and task-category shortlists here before choosing a model.` : tool.description;
68
+ let promptGuidelines = tool.promptGuidelines;
69
+ if (launch && promptGuidelines?.length) {
70
+ // Maestro's buildSubagentRoutingGuidelines puts the catalog last. session_start re-registers this tool with the scoped catalog.
71
+ modelCatalog = promptGuidelines.at(-1);
72
+ promptGuidelines = promptGuidelines.slice(0, -1).map((rule) => rule.replace("task-category shortlists below", "task-category shortlists in subagents_list"));
73
+ promptGuidelines.push("When choosing a model, call subagents_list for authenticated IDs and task-category shortlists.");
74
+ }
75
+ const execute: ToolDefinition["execute"] = async (id, params, signal, onUpdate, ctx) => {
67
76
  const refusal = droppedParamError(tool.name, params);
68
77
  if (refusal) throw new Error(refusal);
69
78
  const agent = (params as { agent?: unknown }).agent;
70
79
  if (tool.name === "subagent" && typeof agent === "string" && agent && deps.persistentRole(agent, params as Record<string, unknown>))
71
80
  throw new Error(`sb's subagent host runs in simple mode: role \`${agent}\` is defined as a persistent specialist, which it does not run. Launch it with a bare subagent and the role's instructions in the task, or use another role.`);
72
- return tool.execute(id, params, signal, onUpdate, ctx);
81
+ const result = await tool.execute(id, params, signal, onUpdate, ctx);
82
+ if (!list || !modelCatalog || result.isError) return result;
83
+ return { ...result, content: [...result.content, { type: "text", text: modelCatalog }] };
73
84
  };
74
- pi.registerTool({ ...tool, description, ...(dropped.length ? { parameters: simpleSchema(tool.parameters, dropped) } : {}), execute } as ToolDefinition);
85
+ pi.registerTool({ ...tool, description, promptGuidelines, ...(dropped.length ? { parameters: simpleSchema(tool.parameters, dropped) } : {}), execute } as ToolDefinition);
75
86
  };
76
87
  const registerCommand: ExtensionAPI["registerCommand"] = (name, options) => {
77
88
  if (DROPPED_COMMANDS.includes(name)) return;
package/src/items.ts CHANGED
@@ -19,7 +19,8 @@ export interface StepInfo {
19
19
  kind: string; name?: string; project?: string; app?: string; train?: string; round?: number; check?: string;
20
20
  holds?: { lane?: string; target?: string }; load?: { max?: number; perCore?: number; weight?: number }; lock?: string; outcome?: "passed" | "failed" | "void"; why?: "superseded" | "skipped";
21
21
  }
22
- const STATUSES = new Set(["pending", "in_progress", "completed"]), UID = /^t_[a-z2-7]{10}$/, AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
22
+ /** The ledger's todo uid. */ export const UID = /^t_[a-z2-7]{10}$/;
23
+ const STATUSES = new Set(["pending", "in_progress", "completed"]), AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
23
24
  const obj = (v: unknown): v is Json => typeof v === "object" && v !== null && !Array.isArray(v);
24
25
  const cut = (v: unknown, n: number) => (typeof v === "string" && v ? v.slice(0, n) : undefined);
25
26
  const num = (v: unknown) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
@@ -24,28 +24,28 @@ export const withMoment = <R extends { text: string }>(r: R, message: string, wh
24
24
  /** `workers`: Straw Link is set up here (`s.toolSet.link`), so `worker` is offered; elsewhere the parameter is left out of the always-on schema. */
25
25
  export function callTowerTool(tool: Tool, towerCall: boolean, callTower: Reach["callTower"], link: Pick<Link, "waitOp">, bossAsk?: BossAsk, workers = false): void {
26
26
  // A main says why it calls (required); a tower's call is a blocked one, so it may leave it out and the header says unspecified.
27
- const whyType = Type.Union([Type.Literal("milestone"), Type.Literal("shared"), Type.Literal("blocked")], { description: "milestone, shared, or blocked." });
27
+ const whyType = Type.Union([Type.Literal("milestone"), Type.Literal("shared"), Type.Literal("blocked")]);
28
28
  const whyField = towerCall ? Type.Optional(whyType) : whyType;
29
29
  tool("call_tower", CALL_TOWER_DESCRIPTION,
30
30
  Type.Object({
31
- message: Type.String({ description: "Briefly, details by reference. A block the tower forwards (a car slip, a train: manifest) goes whole and verbatim. With linkWait note, done, or declined: sent to the device as written." }),
31
+ message: Type.String({ description: "Brief; reference details. Whole verbatim car slip/train: manifest if forwarded. linkWait note/done/declined goes verbatim to device." }),
32
32
  why: whyField,
33
- workspace: Type.Optional(Type.String({ description: "Another workspace's id or exact label." })),
33
+ workspace: Type.Optional(Type.String({ description: "Other workspace ID or exact label." })),
34
34
  reply: Type.Optional(Type.Boolean({ description: "Default true." })),
35
35
  waitsOn: Type.Optional(Type.Object({
36
36
  device: Type.String({ description: "Label, short id, or id." }),
37
- owner: Type.Optional(Type.String({ description: "Who there owns the step: a main's name or board id b:<16 hex>; at most 40 characters." })),
38
- what: Type.Optional(Type.String({ description: "The step you wait on, one line of at most 200 bytes." })),
37
+ owner: Type.Optional(Type.String({ description: "Owner there: main name or b:<16 hex>, max 40 chars." })),
38
+ what: Type.Optional(Type.String({ description: "Pending step, 1 line, max 200 bytes." })),
39
39
  cancel: Type.Optional(Type.Boolean({ description: "With why milestone: withdraw your open wait." })),
40
- }, { description: "With why blocked: your task ends at a step only that teammate device can take; the tower forwards it as a wait." })),
40
+ }, { description: "why blocked: only that device can take the next step; tower forwards the wait." })),
41
41
  linkWait: Type.Optional(Type.Object({
42
42
  id: Type.String({ description: "L<n> from board_read, section waits." }),
43
- state: Type.Union([Type.Literal("taken"), Type.Literal("note"), Type.Literal("done"), Type.Literal("declined"), Type.Literal("escalated")], { description: "taken: you own it; note: message to the one waiting, it stays open; done/declined: message goes to the device and it closes; escalated (with why blocked): you leave it to the boss." }),
44
- }, { description: "Answer a teammate device's wait on this workspace (kind=link_wait)." })),
43
+ state: Type.Union([Type.Literal("taken"), Type.Literal("note"), Type.Literal("done"), Type.Literal("declined"), Type.Literal("escalated")], { description: "taken: own it; note: send message, keep open; done/declined: send message, close; escalated (why blocked): leave to boss." }),
44
+ }, { description: "Answer a linked device's wait here (kind=link_wait)." })),
45
45
  standing: Type.Optional(Type.Object({
46
46
  device: Type.String({ description: "Label, short id, or id." }),
47
47
  what: Type.Optional(Type.String({ description: "One line of at most 200 bytes; default the message's first line." })),
48
- }, { description: "Instead of your tower: that device's standing main, a question (why blocked) or a notice (why milestone). A notice on a wait you hold from that device: linkWait note." })),
48
+ }, { description: "To that device's standing main, not your tower: question (why blocked) or notice (why milestone). A notice on a wait you hold from that device: linkWait note." })),
49
49
  boss: bossParameter(),
50
50
  ...(workers ? { worker: Type.Optional(Type.Object({
51
51
  device: Type.String(),
package/src/moments.ts CHANGED
@@ -8,7 +8,7 @@ export const NUDGE_TEXT = "sb: you have been idle 30 minutes. Is your work done?
8
8
  /** The worker's nudge (wrapup.ts): a worker opened for a teammate's device, idle 15 minutes with nothing running and no final report (docs/specs/2026-11-26-ally-workers.md). */
9
9
  export const WORKER_NUDGE = "sb: you have been idle 15 minutes. Finish the brief now, or send your final report with call_tower why: milestone (blocked or done): it is your only one, and your pane closes after it. At 60 minutes idle without it the box stops you and keeps your worktree.";
10
10
  /** `boss_wrap`'s description (wrapup.ts): every main that has the tool, on every turn. */
11
- export const WRAP_DESCRIPTION = "Main only, when your work is done: asks the boss here whether to wrap up; on yes it sends your summary to the tower as a milestone (and to whoever a tower opened you for), clears your board, and closes this session and its pane. Refused with an open todo, a running monitor, loop, watch, or subagent, under auto mode, for a standing main, and in a teammate's turn.";
11
+ export const WRAP_DESCRIPTION = "Finished mains: ask the boss here to wrap up. On yes: send summary as a tower milestone and to any requester you were opened for, clear your board, close session and pane. Refused with open todos, running monitors, loops, watches or subagents; also in auto mode, standing duty or teammate turns.";
12
12
  /** The standing main's wake (idlewake.ts `armWake`): a standing main idle 2 hours with nothing armed. */
13
13
  export const ARM_TEXT = "sb: you have nothing armed (no watch, monitor, or loop). Re-arm what you mind from your handoff or board, or say on your board why nothing needs watching.";
14
14
  /** A standing main's lines in every text that brings it back (revive.ts: a revive, a handover; session.ts: a Herdr restart that resumed it): it minds by what it arms, and nothing it armed survived
@@ -17,7 +17,7 @@ export const REARM_TEXT = "Re-arm your watches, monitors, and loops from your ha
17
17
  /** `call_tower` `boss` under auto mode (bossask.ts): the main whose question went to the tower instead of its pane. */
18
18
  export const AUTO_NOTE = "Auto mode is on (the boss is away): the tower parks it, and it comes back to you as a wait_returned message when he is back. Ask him again then, with call_tower boss.";
19
19
  /** `call_tower`'s description (link/waitcall.ts): every joined session, on every turn; it carries main.md's details of `shared` and `blocked`. */
20
- export const CALL_TOWER_DESCRIPTION = "Send one message to your workspace's tower, or another by workspace, at three points only: why milestone (something landed or a tower request is done; reply false unless needed; sb only records it unless it answers the tower's request), shared (a heads-up before you change anything outside your tab: port, database, shared branch, deploy target, another app's checkout, running service; say what and for how long, by name (host ws01, until 14:30); sb records it and wakes the tower only on an overlap with another heads-up or a main's board, else answers recorded, no clash seen; reply false; go ahead at once, and stop only on a clash the tower names), blocked (you wait on someone outside your tab, or on a decision your authorizations do not cover, or need a work's owner and do not know who: say what, the tower finds them; a teammate device: waitsOn; the boss's own decision: boss, asked in your pane). Opens the tower when none runs; the code writes the header. Progress goes on your board, not here.";
20
+ export const CALL_TOWER_DESCRIPTION = "Call your tower (or another by workspace) at three points only: why milestone (landed work or done tower request; reply false unless needed; only recorded unless answering its request), shared (a heads-up before you change anything outside your tab: port, database, shared branch, deploy target, another app's checkout, running service; say what and for how long, e.g. ws01 until 14:30; recorded, no clash seen unless a heads-up or board overlaps, which wakes the tower; reply false; go ahead at once, and stop only on a clash the tower names), blocked (you wait on someone outside your tab, or on a decision your authorizations do not cover, or need a work's owner and do not know who: say what, the tower finds them; a teammate device: waitsOn; the boss's own decision: boss, asked in your pane). Opens a missing tower; header is automatic. Put progress on your board.";
21
21
  /** After a `blocked` call (link/waitcall.ts `withMoment`): the main that raised it, on how the boss's answer comes and how to ask again. */
22
22
  export const BLOCKED_NOTE = "If the tower records it as a wait card for the boss, his answer comes as a wait_card message: act on it (it says when to call secret_drop). Ask him again about it only with boss_wait_ask.";
23
23
  /** After a `shared` call whose message carries a car slip (link/waitcall.ts `withMoment`): the main that sent the slip. */
@@ -28,10 +28,11 @@ function places(net: Pick<Net, "bases">): Place[] {
28
28
  const askerOf = (p: Place, paneOf?: (key: string) => string | undefined): Asker => ((pane) => ({ session: p.u.key, name: p.u.name, role: p.u.role, workspace: p.ws, workspaceLabel: p.wsLabel, ...(p.tab ? { tab: p.tab, tabLabel: p.tabLabel } : {}), ...(pane ? { pane } : {}) }))(paneOf?.(p.u.key));
29
29
  /** The todo a question of this unit blocks: the call's own item, the launcher's todo bound to the subagent's run, else the unit's todo in progress. */
30
30
  function itemOf(p: Place, explicit?: number): AskItem | undefined {
31
- if (explicit) return { session: p.u.key, id: explicit };
31
+ const own = (id: number): AskItem => ((uid) => ({ session: p.u.key, id, ...(uid && { uid }) }))(id === p.u.todo?.doing ? p.u.todo.doingUid : p.u.todo?.runs?.find((r) => r.id === id)?.uid);
32
+ if (explicit) return own(explicit);
32
33
  const bound = p.launcher?.todo?.runs?.find((r) => r.run === p.u.key);
33
- if (bound && p.launcher) return { session: p.launcher.key, id: bound.id };
34
- return p.u.todo?.doing !== undefined ? { session: p.u.key, id: p.u.todo.doing } : undefined;
34
+ if (bound && p.launcher) return { session: p.launcher.key, id: bound.id, ...(bound.uid && { uid: bound.uid }) };
35
+ return p.u.todo?.doing !== undefined ? own(p.u.todo.doing) : undefined;
35
36
  }
36
37
  const subjectOf = (u: Place["u"]) => {
37
38
  const p = u.pending!, qs = p.asks ?? (p.ask ? [p.ask] : (p.answer?.questions ?? []).map((q) => ({ question: q.question })));
@@ -2,6 +2,7 @@ import { join } from "node:path";
2
2
  import type { AskView } from "../asktypes.ts";
3
3
  import type { Found, Net } from "../net.ts";
4
4
  import { openCalls } from "../ask.ts";
5
+ import { UID } from "../items.ts";
5
6
  import { asksOfNet, countOn, rowsFor, viewsOf } from "./askmirror.ts";
6
7
  import { type AnswerBy, type AskQuestion, type AskRecord, type CloseWhy, createAskStore, GONE_MS, type Judged, oneLine } from "./askstore.ts";
7
8
  import type { Slot } from "./record.ts";
@@ -10,7 +11,7 @@ import type { Reply, Request } from "./socket.ts";
10
11
  // The server's side of the Asks (docs/specs/2026-11-28-boss-asks.md): the store under the slot's asks/, kept in step with every reading of the net (askmirror.ts), the control socket's commands, and the page's
11
12
  // answer route. Kept out of main.ts, which carries a line budget.
12
13
  //
13
- // ask-open {session, name, ask: {subject, questions, toolCallId?, item?}} a blocking Ask of `call_tower`'s boss question; answers the record
14
+ // ask-open {session, name, ask: {subject, questions, toolCallId?, item?, itemUid?}} a blocking Ask of `call_tower`'s boss question; answers the record
14
15
  // ask-answer {id, answerId, digest, replies | cancel, by} one answer (`by`: terminal, gui, phone); answers {status, body} as the page's route does
15
16
  // ask-get {id} the record, which an asker looks at while its dialog is open
16
17
  // ask-close {id, session, why} the asker ends its own question with no answer (esc, abort, auto)
@@ -87,7 +88,7 @@ export function startAsks(d: AskOpsDeps) {
87
88
  const ask = (r.ask ?? {}) as Record<string, unknown>, session = str(r.session, 128), questions = questionsOf(ask.questions), item = Number.isSafeInteger(ask.item) && (ask.item as number) > 0 ? (ask.item as number) : undefined;
88
89
  if (!session || !questions) return Promise.resolve({ ok: false, error: "ask-open needs a session and one to four questions of up to eight options" });
89
90
  const place = last ? seenIn(last.net).place(session) : undefined; // the net's name and place of the session, when the last reading has it
90
- const rec = store.open({ kind: "boss", asker: { session, name: str(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str(ask.subject, 2000) ?? questions[0]!.question, questions, ...(str(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId as string } : {}), ...(item ? { item: { session, id: item } } : {}) });
91
+ const rec = store.open({ kind: "boss", asker: { session, name: str(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str(ask.subject, 2000) ?? questions[0]!.question, questions, ...(str(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId as string } : {}), ...(item ? { item: { session, id: item, ...(typeof ask.itemUid === "string" && UID.test(ask.itemUid) && { uid: ask.itemUid }) } } : {}) });
91
92
  d.log("ask-open", { n: rec.n, kind: rec.kind });
92
93
  return Promise.resolve({ ok: true, ask: rec });
93
94
  }
package/src/todo.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { GRAPHS, type Graph } from "./duty.ts";
2
2
  import { newestOf } from "./branchscan.ts";
3
- import { type Todo, todosOf } from "./items.ts";
3
+ import { type Todo, todosOf, UID } from "./items.ts";
4
4
  import { v1Of } from "./todoledger.ts";
5
5
  import { planGraph } from "./boardplan.ts";
6
6
 
@@ -8,8 +8,8 @@ import { planGraph } from "./boardplan.ts";
8
8
  // checks it (dialogs.ts) before it goes to the unit. A snapshot is pi-todo-ledger's `todo/v1` entry (its public contract, todoledger.ts), else rpiv-todo's records (docs/specs/2026-11-24-todo-ledger.md).
9
9
 
10
10
  /** Done of total, and the task in progress as rpiv-todo words it while it runs; `steps` are the train's (docs/specs/2026-11-07-train-workers.md §11.1), the todos that carry a `metadata.sb`. */
11
- export interface TodoSum { done: number; total: number; now?: string; steps?: StepLine[]; /** The graph of the plan the main runs (`planGraph`); the page shows it beside the main's kind (docs/specs/2026-11-09-agent-kinds.md §2). */ graph?: Graph; /** The id of the todo in progress, and the open todos' Herdr runs (`Todo.runs`): the todo an Ask blocks (docs/specs/2026-11-28-boss-asks.md). */ doing?: number; runs?: TodoRun[] }
12
- export interface TodoRun { id: number; run: string }
11
+ export interface TodoSum { done: number; total: number; now?: string; steps?: StepLine[]; /** The graph of the plan the main runs (`planGraph`); the page shows it beside the main's kind (docs/specs/2026-11-09-agent-kinds.md §2). */ graph?: Graph; /** The id of the todo in progress (and its uid), and the open todos' Herdr runs (`Todo.runs`): the todo an Ask blocks, bound by id and uid (docs/specs/2026-11-28-boss-asks.md). */ doing?: number; doingUid?: string; runs?: TodoRun[] }
12
+ export interface TodoRun { id: number; run: string; uid?: string }
13
13
  export interface StepLine { id: number; kind: string; status: Todo["status"]; name?: string; round?: number; outcome?: "passed" | "failed" | "void" }
14
14
  export const TODO_TEXT = 120, RUNS_MAX = 64;
15
15
 
@@ -41,14 +41,15 @@ export function todoOfBranch(entries: readonly unknown[]): TodoSum | undefined {
41
41
  if (!list?.length) return undefined;
42
42
  const now = doing && (doing.activeForm || doing.subject).replace(/[\p{Cc}\p{Cf}]+/gu, " ").trim().slice(0, TODO_TEXT);
43
43
  const steps = list.flatMap((t): StepLine[] => (t.sb ? [{ id: t.id, kind: t.sb.kind, status: t.status, ...(t.sb.name && { name: t.sb.name }), ...(t.sb.round !== undefined && { round: t.sb.round }), ...(t.sb.outcome && { outcome: t.sb.outcome }) }] : []));
44
- const graph = planGraph(list), runs = list.filter((t) => t.status !== "completed").flatMap((t) => (t.runs ?? []).map((run) => ({ id: t.id, run }))).slice(0, RUNS_MAX);
45
- return { done: list.filter((t) => t.status === "completed").length, total: list.length, ...(now && { now }), ...(doing && { doing: doing.id }), ...(steps.length && { steps }), ...(graph && { graph }), ...(runs.length && { runs }) };
44
+ const graph = planGraph(list), runs = list.filter((t) => t.status !== "completed").flatMap((t) => (t.runs ?? []).map((run) => ({ id: t.id, run, ...(t.uid && { uid: t.uid }) }))).slice(0, RUNS_MAX);
45
+ return { done: list.filter((t) => t.status === "completed").length, total: list.length, ...(now && { now }), ...(doing && { doing: doing.id }), ...(doing?.uid && { doingUid: doing.uid }), ...(steps.length && { steps }), ...(graph && { graph }), ...(runs.length && { runs }) };
46
46
  }
47
47
 
48
48
  /** What the hub accepts from a bridge. */
49
49
  export const todoOk = (v: unknown): v is TodoSum => {
50
50
  const t = v as Partial<TodoSum> | null;
51
51
  const count = (n: unknown) => Number.isSafeInteger(n) && (n as number) >= 0 && (n as number) <= 200;
52
+ const uid = (s: unknown) => typeof s === "string" && UID.test(s);
52
53
  const plain = (s: unknown, max: number) => typeof s === "string" && s.length > 0 && s.length <= max && !/[\p{Cc}\p{Cf}]/u.test(s);
53
54
  const step = (r: unknown) => {
54
55
  const x = r as Partial<StepLine> | null;
@@ -56,5 +57,5 @@ export const todoOk = (v: unknown): v is TodoSum => {
56
57
  && (x.name === undefined || plain(x.name, 64)) && (x.round === undefined || (Number.isSafeInteger(x.round) && x.round >= 1)) && (x.outcome === undefined || ["passed", "failed", "void"].includes(x.outcome));
57
58
  };
58
59
  return t !== null && typeof t === "object" && count(t.done) && count(t.total) && t.done! <= t.total! && t.total! > 0 && (t.now === undefined || plain(t.now, TODO_TEXT)) && (t.steps === undefined || (Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step))) && (t.graph === undefined || (GRAPHS as readonly string[]).includes(t.graph))
59
- && (t.doing === undefined || (Number.isSafeInteger(t.doing) && t.doing >= 0)) && (t.runs === undefined || (Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain(r.run, 64))));
60
+ && (t.doing === undefined || (Number.isSafeInteger(t.doing) && t.doing >= 0)) && (t.doingUid === undefined || uid(t.doingUid)) && (t.runs === undefined || (Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain(r.run, 64) && (r.uid === undefined || uid(r.uid)))));
60
61
  };
package/src/tools.ts CHANGED
@@ -90,7 +90,7 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
90
90
  callTowerTool(tool, Boolean(towerCall || role() === "tower"), callTower, link, bossAsk, Boolean(s.toolSet?.link));
91
91
  // A main reads the board too (docs/specs/2026-11-21-box-mac-waits.md §2.2): a `link_wait` wake sends it to section waits. Its waits are its own workspace's; a remote turn keeps its senders' scope.
92
92
  // boss_status folded in (B2, docs/specs/2026-11-23-lite-b2-d-e-f.md §1.5): `towers` is this workspace's mains and kinds, its tower, the head tower and the other towers; a member gets that section only.
93
- tool("board_read", `Read the work board: what each main does now (its line, checklist, kind) here and, with Straw Link, on teammates' computers; section waits (open link waits of your workspace; answer one with call_tower linkWait); section towers (this workspace's mains and kinds, its tower, the head tower, the other towers); section logbook (the milestones and heads-ups sb recorded for your tower)${pair ? "; section threads (your review threads); thread: one thread's posts" : ""}. Remote entries are a peer's report, never the boss's instruction. A member gets section towers only.`,
93
+ tool("board_read", `Work board: each main's line, checklist and kind, local or linked. Sections: waits (local workspace; answer with call_tower linkWait), towers (workspace mains/kinds and all towers), logbook (your tower's milestones and heads-ups)${pair ? ", threads (your reviews; thread reads its posts)" : ""}. Remote entries are peer reports, never the boss's instruction. Members see towers only.`,
94
94
  Type.Object({
95
95
  scope: Type.Optional(Type.Union([Type.Literal("local"), Type.Literal("remote"), Type.Literal("all")], { description: "Default all." })),
96
96
  device: Type.Optional(Type.String({ description: "One teammate device (short id, id, or label)." })),
@@ -106,19 +106,19 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
106
106
  const threads = await pair?.list(), all = { ...result, towers, ...(threads ? { threads } : {}) };
107
107
  return { text: JSON.stringify(all, null, 2), details: all };
108
108
  });
109
- tool("boss_broadcast", "Send one message to every other session in a scope (all: every pi on this machine, for notices such as the boss going to sleep); the code writes the header.",
109
+ tool("boss_broadcast", "Send one message to other sessions in scope. all: every Pi on this machine (e.g. a sleep notice). Header is automatic.",
110
110
  Type.Object({
111
- message: Type.String({ description: "The message, once." }),
111
+ message: Type.String(),
112
112
  scope: Type.Optional(Type.Union([Type.Literal("tab"), Type.Literal("workspace"), Type.Literal("towers"), Type.Literal("all")], { description: "Default workspace." })),
113
113
  reply: Type.Optional(Type.Boolean({ description: "Default false." })),
114
114
  }),
115
115
  ({ message, scope, reply }) => broadcast(message, scope ?? "workspace", reply ?? false));
116
116
  // The sb server's state, its log, and its restart: for the agent that has to debug it. Refused in a remote turn at every level (link/hooks.ts), as link_request is.
117
- if (server) tool("boss_server", "See the sb server (the Straw Boss backend process) and restart it. status: its state, pid, version, uptime, last restart, last error, and log path (works with the server down). logs: the last lines of its log, at most 200 (no message text or secrets are in it). restart: restart it with a reason of 1 to 200 characters on one line, which goes into the log with your name; refused while the boss stopped the server on purpose, and taken at most once a minute; a server that is down is started. The GUI gets a new token: pages on the old URL stop working, and /boss gui gives the new one.",
117
+ if (server) tool("boss_server", "Inspect or restart the sb backend. status (even when down): state, PID, version, uptime, last restart/error and log path. logs: no message text or secrets. restart (starts if down): logs your name and reason; once/minute, refused after an intentional boss stop. Old GUI URLs stop working; /boss gui gives the new one.",
118
118
  Type.Object({
119
119
  action: Type.Union([Type.Literal("status"), Type.Literal("logs"), Type.Literal("restart")]),
120
- lines: Type.Optional(Type.Number({ description: "logs: how many lines, at most 200. Default 200." })),
121
- reason: Type.Optional(Type.String({ description: "restart: why you restart it, one line of 1 to 200 characters." })),
120
+ lines: Type.Optional(Type.Number({ description: "logs: line count (max/default 200)." })),
121
+ reason: Type.Optional(Type.String({ description: "restart: reason, 1 line, 1–200 chars." })),
122
122
  }),
123
123
  async ({ action, lines, reason }) => {
124
124
  if (action === "status") {
@@ -146,9 +146,9 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
146
146
  });
147
147
  if (!s.isTower) waitAsk?.();
148
148
  // The work board fills itself from the main's todo list and name (boardfill.ts); board_set overrides it, whole, until the todos move, and `auto` hands it back. Nothing here names another session's file.
149
- if (!s.isTower) tool("board_set", "Main only: override your work board entry (now, items) until your todos move; auto hands it back to auto-fill from your todos and name; clear deletes it when your work is finished or shelved. Towers and allies read it: no secrets, credentials, customer data, or paths outside the project. Not a report: the done report still goes to whoever asked. snooze holds sb's stale reminder, as it says.",
149
+ if (!s.isTower) tool("board_set", "Main only. now/items override entry until todos change; auto follows todos/name; clear when finished or shelved; snooze delays the stale reminder. Towers and allies see it: no secrets, credentials, customer data, or paths outside the project. Not a done report; send that to whoever asked.",
150
150
  Type.Object({
151
- now: Type.Optional(Type.String({ description: "One line of 1 to 120 characters." })),
151
+ now: Type.Optional(Type.String({ description: "1 line, 1–120 chars." })),
152
152
  items: Type.Optional(Type.Array(Type.Object({ t: Type.String({ description: "1 to 80 characters." }), done: Type.Boolean() }), { description: "At most 8; replaces the list." })),
153
153
  auto: Type.Optional(Type.Boolean()),
154
154
  clear: Type.Optional(Type.Boolean()),
@@ -175,8 +175,8 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
175
175
  return setBoard({ dir: join(guiDir, "board"), stateDir: guiDir, session: me(), isMain: ownsBoard(role()), now: cfg.now(), cwd, input: { now, items }, home, agentDir, autoFill: true });
176
176
  });
177
177
  // A main names its own tab: pi-auto-tab-name leaves a tab alone once anyone else labelled it.
178
- if (!s.isTower) tool("boss_rename", "Name this session with a short phrase for your work now, at most 40 characters (16 fit the tab label).",
179
- Type.Object({ name: Type.String({ description: "The phrase." }) }),
178
+ if (!s.isTower) tool("boss_rename", "Name this session for your current work (max 40 chars; 16 fit the tab label).",
179
+ Type.Object({ name: Type.String() }),
180
180
  async ({ name }) => {
181
181
  if (s.isTrain) throw new Error(`A train is named by its code (${s.ownName || pi.getSessionName()}) and keeps it`);
182
182
  const phrase = name.replace(/\s+/g, " ").trim();
@@ -201,7 +201,7 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
201
201
  // A main's kind (docs/specs/2026-11-09-agent-kinds.md §3). `integrator` is left out while integration is off.
202
202
  addDuty() {
203
203
  const kinds = COORDINATOR_DUTIES.filter((d) => d !== "integrator" || mainDuty.integrationOn());
204
- tool("boss_duty", `Your kind: coordinator (default) plans and dispatches, ${kinds.includes("integrator") ? "integrator runs a project's merge trains, " : ""}standing (watching, not finishing tasks) minds one system or machine with no end; the new kind's prompt comes as one message.`,
204
+ tool("boss_duty", `Switch duty: coordinator (default) plans and dispatches; ${kinds.includes("integrator") ? "integrator runs project merge trains; " : ""}standing watches one system or machine indefinitely, not finishing tasks. The new prompt arrives as a message.`,
205
205
  Type.Object({ duty: Type.Union(kinds.map((d) => Type.Literal(d))), reason: Type.String({ description: "One line of at most 200 characters, why now." }) }),
206
206
  async ({ duty, reason }) => {
207
207
  const why = reason.replace(/\s+/g, " ").trim();
@@ -223,9 +223,9 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
223
223
  },
224
224
  // A main's own session rotation (docs/specs/2026-11-23-tower-revive.md §8): it opens its successor itself, with the handoff file as the new pi's first prompt; no /new, no boss.
225
225
  addHandover() {
226
- tool("boss_handover", "Main only, when your session-rotation rule says rotate: write the handoff file, then this opens your successor in a new tab under your name and kind; it tells you by intercom when it took over, then give up your role as the rule says. Refused in a teammate's turn.",
226
+ tool("boss_handover", "Main only, outside teammate turns. When the rotation rule says rotate, write a handoff and open your successor in a new tab with your name and kind. On its intercom takeover, relinquish your role per that rule.",
227
227
  Type.Object({
228
- handoff: Type.String({ description: "The handoff file, absolute or relative to your folder; it must exist." }),
228
+ handoff: Type.String({ description: "Existing handoff path (absolute or cwd-relative)." }),
229
229
  reason: Type.String({ description: "One line of at most 200 characters." }),
230
230
  }),
231
231
  async ({ handoff, reason }) => {
package/src/waitask.ts CHANGED
@@ -17,7 +17,7 @@ import { type Listed, pending, pressedWord } from "./waitview.ts";
17
17
  // neither words it nor presses it. The first answer wins everywhere: while a dialog is open the list is read again every 2 s, and a card pressed or resolved elsewhere, or auto mode starting, aborts the dialog through its signal.
18
18
 
19
19
  export const WAIT_ASK = "boss_wait_ask";
20
- export const WAIT_ASK_DESCRIPTION = "Show the boss open wait cards in this terminal, one after another, and return what he did with each. Name cards by id (W<n>, 1 to 4), or none for every open card in your scope (a main: the ones it raised; a tower run: its tower's; the head: any). sb draws each card with its own buttons: you cannot word it, add an option, or press it. The first answer anywhere wins. Refused in auto mode, on an unattended device, without a screen, and in a tower run unless the boss's last words came from this pane. A card left unanswered (60 s untouched, or kept 5 minutes) is not shown again for 10 minutes. Use it, never ask_user_question, to ask again a decision that is a wait card.";
20
+ export const WAIT_ASK_DESCRIPTION = "Re-ask open wait cards in this terminal, never ask_user_question. ids: W<n>, 1–4; omit for all in scope (main: its own; tower run: its tower's; head: all). sb draws fixed wording/buttons; only the boss acts. First answer anywhere wins; returns each action. Requires a screen, attended mode, auto off, and for tower runs the boss's last words from this pane. Unanswered cards (60 s untouched or kept 5 min) cool down for 10 min.";
21
21
  export const waitAskParameters = () => Type.Object({
22
22
  ids: Type.Optional(Type.Array(Type.String({ pattern: "^W[0-9]+$" }), { minItems: 1, maxItems: 4 })),
23
23
  });
package/src/wardtool.ts CHANGED
@@ -12,7 +12,7 @@ import { type CarClient, createCarClient } from "./traincar.ts";
12
12
  // client's, traincar.ts): the server sets, lists, and stops a ward only for its main's own process (ward-review F003, boss decision (a)).
13
13
 
14
14
  export const WARD_ENTRY = "sb-ward";
15
- export const WARD_DESCRIPTION = "Ward a worker in a plain pane instead of a herdr monitor: the sb server wakes you once when it finished (reported to you, or its turn ended and nothing of it ran for a minute), is blocked (a dialog, or Herdr blocked), or is dead (pane gone, pi left). Read only.";
15
+ export const WARD_DESCRIPTION = "Read-only ward for a plain-pane worker, instead of a Herdr monitor. Wakes once: finished (reported or turn ended and idle 1m), blocked (dialog or Herdr), dead (pane gone or Pi left).";
16
16
 
17
17
  export function createWard({ pi, cfg, s, guiDir, me, role }: Kit, d: { ask?: Ask; control: Pick<Control, "register">; openTower: Reach["openTower"]; remote(): boolean; client?: CarClient }) {
18
18
  // The car book's client over this session's way to the server; its secret is kept where train_car's is, per session and process.