pi-straw-boss 0.75.2 → 0.76.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.75.2",
3
+ "version": "0.76.0",
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",
@@ -3,7 +3,7 @@
3
3
  You are the integrator of one project: the main that places the cars mains send it, for each app with an `integration` field ({{dir}}/apps-config.md), on trains. A departed train runs on its own in a `train` session the tower opens; you do not supervise it. Follow pi-anchorloop's `integrating` skill and `deploying` skill, bound by the Seam bindings in your role prompt. sb refuses your `train` todos when the installed pi-anchorloop is older than 2.11.0: `call_tower` with `why=blocked` naming pi-anchorloop 2.11.0 or newer; depart nothing.
4
4
 
5
5
  - The project's skill is `integration.skill` (the headings of `integrating`'s Project skill contract). sb reads apps.json and refuses a `train` todo for an app whose `stages` still list the old uat stage or whose cars show less than `integration.accept`: depart nothing, `why=blocked`, naming the field.
6
- - A car slip arrives forwarded by the tower; its `coordinator` is a session id and must equal the forward's `fwd-from`. At receipt run `train check` as your main prompt gives it, with `--accept <evidence>` (`none` for a slip that says `accept: none`) `--app-accept <integration.accept> --slip <slip>` (absolute paths) and check that `auth` covers every `strict` target in `deploy`.
6
+ - A car slip arrives forwarded by the tower; its `coordinator` is a session id and must equal the forward's `fwd-from`. At receipt run `train check` as your main prompt gives it, with `--accept <evidence>` (`none` for a slip that says `accept: none`) `--app-accept <integration.accept> --slip <slip>` (absolute paths) and check that `auth` covers every `strict` target in `deploy`. An `origin=remote:` forward's `auth` covers only `strict` targets its device's boss granted; else `why=blocked`, naming car and target.
7
7
  - The train runs no acceptance. A car that asks it for UAT, e2e, or any acceptance is returned with: `sb: the train runs no acceptance: car <ticket> asks for <what> (<where>); rewrite its acceptance criteria and run them before loading, then send the evidence in accept:`.
8
8
  - Set each car's fate with `train_car`: `received` (`train`, `departs`) or `returned` (the reason). A slip with no tower forward (queued before 0.65.0) cannot be received: `why=blocked` naming the car, for the tower to have it sent again. The sb server sends the notice; never send a slip's sender a notice yourself. One `train` todo per forming train (`metadata.sb`, `v`: 1, `project`, `app`, `train` (the code, `YYYY-MM-DD-<letters>`), `kind: "train"`, `spec.cars` rows as the slips give them): `in_progress` first (sb holds it until each `received` notice is told) and only then the manifest's call, `completed` on the tower's answer with `result`: `outcome: passed`, the train's `session`, `at`; or `failed`, the `refusal`, `at`.
9
9
  - Place cars by `departs` and by the `strict` targets their `auth` covers. Depart under `integration.maxTrains`.
package/src/boardfill.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { join } from "node:path";
2
2
  import { ENDED_MS, finished, readEntries, removeEntry, writeEntry } from "./board.ts";
3
3
  import { type Derived, deriveBoard } from "./boardauto.ts";
4
- import { BOARD_ENTRY, seedBoard, withdrawnKey } from "./boardseed.ts";
4
+ import { BOARD_ENTRY, seedBoard, withdrawnScan } from "./boardseed.ts";
5
5
  import type { Kit } from "./state.ts";
6
6
  import { ownsBoard } from "./trainrole.ts";
7
- import { todosOfBranch } from "./todo.ts";
7
+ import { todosOf } from "./items.ts";
8
+ import { snapshotScan } from "./todo.ts";
8
9
 
9
10
  // The work board fills itself (docs/specs/2026-10-25-straw-link.md, Work board, Auto-fill): the main's own session turns its todo list and its name into its entry and writes it
10
11
  // with `writeEntry`, as `board_set` does, marked `src: "todo"`. The server takes no part. boardauto.ts is the derivation and the scrub.
@@ -26,7 +27,9 @@ export function createBoardFill({ pi, cfg, s, guiDir, me, role, tell }: Kit): Bo
26
27
  const name = pi.getSessionName()?.trim() ?? "";
27
28
  return name === me() || name === me().slice(0, 8) ? "" : name;
28
29
  };
29
- const derive = () => deriveBoard({ name: named(), todos: todosOfBranch(branchOf()), root: ctx?.cwd ?? process.cwd() });
30
+ // The refresh runs at every tool call and walked the branch from the leaf for the todo snapshot each time (the whole branch in a session that keeps no todo list). That walk is incremental now (branchscan.ts): the snapshot is found once and then looked for only in what was appended; so is the withdrawal, which is read only while seeding and at a session start. pi's own `getBranch()` still walks the history at every call.
31
+ const snapshotOf = snapshotScan(), withdrawnKey = withdrawnScan();
32
+ const derive = () => deriveBoard({ name: named(), todos: todosOf(snapshotOf(branchOf())), root: ctx?.cwd ?? process.cwd() });
30
33
  const branchOf = (): readonly unknown[] => {
31
34
  try { return ctx?.sessionManager?.getBranch() ?? []; } catch { return []; } // a replaced session's context throws
32
35
  };
package/src/boardseed.ts CHANGED
@@ -1,17 +1,21 @@
1
1
  import { type Entry, finished } from "./board.ts";
2
2
  import type { Derived } from "./boardauto.ts";
3
+ import { newestOf } from "./branchscan.ts";
3
4
 
4
5
  /** The custom entry a main keeps in its session when it withdraws the line for a derived entry (`board_set { clear }`, or a finished list's 30 minutes): a /reload reads it back, so the line is not written again. */
5
6
  export const BOARD_ENTRY = "straw-boss-board";
6
7
 
8
+ const withdrawnOf = (entry: unknown): string | undefined => { const e = entry as { type?: string; customType?: string; data?: { cleared?: unknown } }; return e.type === "custom" && e.customType === BOARD_ENTRY && typeof e.data?.cleared === "string" ? e.data.cleared : undefined; };
7
9
  /** The key of the newest withdrawal the session branch holds. */
8
10
  export function withdrawnKey(branch: readonly unknown[]): string | undefined {
9
11
  for (let i = branch.length - 1; i >= 0; i--) {
10
- const e = branch[i] as { type?: string; customType?: string; data?: { cleared?: unknown } };
11
- if (e.type === "custom" && e.customType === BOARD_ENTRY && typeof e.data?.cleared === "string") return e.data.cleared;
12
+ const key = withdrawnOf(branch[i]);
13
+ if (key !== undefined) return key;
12
14
  }
13
15
  return undefined;
14
16
  }
17
+ /** `withdrawnKey` for a reader that asks again as its branch grows: each call walks only what was appended since the last (branchscan.ts). */
18
+ export const withdrawnScan = (): ((branch: readonly unknown[]) => string | undefined) => newestOf(withdrawnOf);
15
19
 
16
20
  /** What the auto-fill starts from on its first refresh after a start or /reload: `last` (the key it believes is written or withdrawn) and `doneAt` (when a finished line was written). */
17
21
  export interface Seed { last?: string; doneAt?: number }
@@ -0,0 +1,18 @@
1
+ // A session branch read again and again (the work board's refresh runs at every tool call): what a reader looks for in it is found once, and the reader's own walk then covers only the entries appended since. That is the reader's walk alone: pi builds the branch from the leaf to the root at every `getBranch()`, so a refresh still costs the length of the history there.
2
+
3
+ /**
4
+ * The newest entry of a branch for which `pick` gives a value, as a full walk from the leaf would find it. The reader remembers the leaf it read last and what it found: a branch that still holds that entry
5
+ * at that place has the same entries before it (an entry has one parent, so the path from the root to it is one), and only what follows it is walked. Any other branch (the leaf moved to another branch of the
6
+ * tree or back to an ancestor, a new session) is walked whole. pi hands a new array at each `getBranch()`, with the same entry objects, so entries are compared by identity.
7
+ */
8
+ export function newestOf<T>(pick: (entry: unknown) => T | undefined): (branch: readonly unknown[]) => T | undefined {
9
+ let length = 0, leaf: unknown, found: T | undefined;
10
+ return (branch) => {
11
+ const grown = length === 0 || (branch.length >= length && branch[length - 1] === leaf);
12
+ let hit: T | undefined;
13
+ for (let i = branch.length - 1; i >= (grown ? length : 0) && hit === undefined; i--) hit = pick(branch[i]);
14
+ found = hit ?? (grown ? found : undefined);
15
+ [length, leaf] = [branch.length, branch[branch.length - 1]];
16
+ return found;
17
+ };
18
+ }
package/src/exe.mjs CHANGED
@@ -82,7 +82,7 @@ const signalGroup = (pid, signal) => {
82
82
  * `execFile` with a deadline that holds (`options.deadline`, in ms). execFile's own `timeout` sends one SIGTERM and calls back when the program has ended, so a program that does not end on SIGTERM holds the
83
83
  * callback for as long as it lives (todo #155: a `herdr agent start` given 35 s called back 61 minutes later). Here `done` is called at the deadline at the latest. A program that had ended by then, with a copy
84
84
  * of its stdout or stderr still open somewhere, is told by its own exit status, as execFile tells it. One still running is cut off: the error is marked as execFile marks a timeout (`killed`, `signal: "SIGTERM"`,
85
- * no exit code), with what was read so far, and the program is ended behind the call by SIGTERM, then SIGKILL after `options.grace` (2 s). Where there are process groups it starts as the leader of its own
85
+ * no exit code; an overflow of `maxBuffer` is marked as execFile marks that: its code, `killed: false`, no signal), with what was read so far, and the program is ended behind the call by SIGTERM, then SIGKILL after `options.grace` (2 s). Where there are process groups it starts as the leader of its own
86
86
  * (`detached`) and both signals go to the group, so what it started ends with it; on Windows they end the program alone. Output is read as UTF-8 text, and more than `maxBuffer` of it cuts the program off too.
87
87
  * `options.group: false` is for a program whose children are meant to stay (an opener and the file manager it started): it runs in the caller's group, and the signals end it alone.
88
88
  * @param {string} file
@@ -108,10 +108,10 @@ function execFileByDeadline(file, args, options, done) {
108
108
  const failure = (what, marks) => Object.assign(new Error(`${what}: ${cmd}${stderr ? `\n${stderr}` : ""}`), { cmd, ...marks });
109
109
  /** @param {{ code: number | null, signal: NodeJS.Signals | null }} status */
110
110
  const byStatus = ({ code, signal }) => settle(code === 0 ? null : failure("Command failed", { code, killed: false, signal }));
111
- /** @param {string} what @param {string | null} code */
112
- const cutOff = (what, code) => {
111
+ /** @param {string} what @param {string | null} code @param {boolean} timedOut a timeout is marked as execFile marks one; an overflow is marked as execFile marks it (a code, no `killed`, no signal), though the program behind the call is ended too */
112
+ const cutOff = (what, code, timedOut) => {
113
113
  if (settled) return;
114
- settle(failure(what, { code, killed: true, signal: "SIGTERM" }));
114
+ settle(failure(what, timedOut ? { code, killed: true, signal: "SIGTERM" } : { code, killed: false, signal: null }));
115
115
  if (ended) return; // it left by itself: what it left behind is not signalled, and its group's id may be another program's by now
116
116
  /** @param {NodeJS.Signals} signal */
117
117
  const send = (signal) => (alone || child.pid === undefined ? child.kill(signal) : signalGroup(child.pid, signal));
@@ -120,9 +120,9 @@ function execFileByDeadline(file, args, options, done) {
120
120
  // The leader gone and nothing left in its group: there is nothing to kill at the grace.
121
121
  child.once("exit", () => (alone || child.pid === undefined || !signalGroup(child.pid, 0)) && clearTimeout(hard));
122
122
  };
123
- const timer = setTimeout(() => (ended ? byStatus(ended) : cutOff(`Command timed out after ${options.deadline} ms`, null)), options.deadline);
124
- child.stdout?.setEncoding("utf8").on("data", (chunk) => (stdout += chunk).length > limit && cutOff("stdout maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER"));
125
- child.stderr?.setEncoding("utf8").on("data", (chunk) => (stderr += chunk).length > limit && cutOff("stderr maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER"));
123
+ const timer = setTimeout(() => (ended ? byStatus(ended) : cutOff(`Command timed out after ${options.deadline} ms`, null, true)), options.deadline);
124
+ child.stdout?.setEncoding("utf8").on("data", (chunk) => (stdout += chunk).length > limit && cutOff("stdout maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER", false));
125
+ child.stderr?.setEncoding("utf8").on("data", (chunk) => (stderr += chunk).length > limit && cutOff("stderr maxBuffer length exceeded", "ERR_CHILD_PROCESS_STDIO_MAXBUFFER", false));
126
126
  child.on("error", settle); // the program could not be started; after the call has ended, a signal that could not be sent
127
127
  child.once("exit", (code, signal) => (ended = { code, signal }));
128
128
  child.once("close", (code, signal) => byStatus({ code, signal }));
@@ -29,6 +29,7 @@ import { operateWire, type OperateWire } from "./operatewire.ts";
29
29
  import { createLog, tailLog } from "./log.ts";
30
30
  import { type Cars, carsReply, startCars } from "./carops.ts";
31
31
  import { procsReply, startProcs, type StartProcs } from "./procsops.ts";
32
+ import { startStall, type StartStall } from "./stallops.ts";
32
33
  import { gateRun, type RunInfo } from "./rungate.ts";
33
34
  import type { ServerTools } from "./runtools.ts";
34
35
  import {
@@ -112,6 +113,8 @@ export interface ServerOptions {
112
113
  towers?: Partial<TowersOptions>;
113
114
  /** Replaces the owner registry's seams (the process table, the kill sequence, the tick), for tests. */
114
115
  procs?: StartProcs["over"];
116
+ /** The stall watch's seams (stallops.ts), for tests: without them a test run has no watch. */
117
+ stall?: StartStall["over"];
115
118
  touchMs?: number;
116
119
  brokerMs?: number;
117
120
  herdrGoneMs?: number;
@@ -627,7 +630,9 @@ export async function runServer(o: ServerOptions): Promise<ServerHandle> {
627
630
  log.line("herdr-takeover");
628
631
  void towers?.takeover().catch((error: Error) => recordError("towers", error.message));
629
632
  }, () => (log.line("herdr-lost", { at: Date.now() }), towers?.runs.herdrLost())));
630
- procs = startProcs({ dir: slot.dir, stateDir: slot.stateDir, env, pid, platform, now, log: (event, facts) => log.line(event, facts), run: cfg.run, events: cfg.events, ...(o.procs ? { over: o.procs } : {}), stops, timers, leaving: () => Boolean(leaving) || phase === "stopping" || phase === "restarting" });
633
+ // The stall watch (stallwatch.ts): a pi that froze is told to its workspace's tower from the registry's tick; it signals nothing.
634
+ const stall = startStall({ dir: slot.dir, stateDir: slot.stateDir, pid, platform, now, log: (event, facts) => log.line(event, facts), run: cfg.run, sessions: () => (client?.isConnected() ? client.listSessions() : Promise.reject(new Error("pi-intercom is not connected"))), towers: () => towers, ...(o.stall ? { over: o.stall } : {}) });
635
+ procs = startProcs({ dir: slot.dir, stateDir: slot.stateDir, env, pid, platform, now, log: (event, facts) => log.line(event, facts), run: cfg.run, events: cfg.events, ...(stall ? { watch: (table) => stall.sample(table) } : {}), ...(o.procs ? { over: o.procs } : {}), stops, timers, leaving: () => Boolean(leaving) || phase === "stopping" || phase === "restarting" });
631
636
  let downSince: number | undefined;
632
637
  const herdrUp = o.herdrUp ?? (() => herdrListens({ slot, platform }));
633
638
  timers.push(setInterval(() => void herdrUp().then((up) => {
@@ -59,6 +59,8 @@ export interface ProcsDeps {
59
59
  reap?: (refs: readonly Ref[]) => Promise<KillReport>;
60
60
  /** Pids that must outlive any reap: this server. */
61
61
  self?: number[];
62
+ /** Gets the table of each tick (the stall watch, stallwatch.ts): it runs behind the tick, which never waits for it. */
63
+ watch?: (table: readonly Proc[]) => Promise<void>;
62
64
  ownUid?: number;
63
65
  platform?: NodeJS.Platform;
64
66
  }
@@ -278,6 +280,7 @@ export function createProcs(d: ProcsDeps): Procs {
278
280
  async function takeTick(): Promise<void> {
279
281
  const table = await read();
280
282
  if (!table) return;
283
+ void d.watch?.(table).catch((error: Error) => d.log("procs-error", { text: `the tick's watch failed: ${String(error?.message).slice(0, 160)}` }));
281
284
  await lookAtWorkspaces();
282
285
  let changed = false;
283
286
  for (const r of [...owners.values()]) {
@@ -46,6 +46,8 @@ export interface StartProcs {
46
46
  log(event: string, facts: Record<string, number | string | boolean>): void;
47
47
  run: HerdrRun;
48
48
  events: HerdrEvents;
49
+ /** The stall watch (stallops.ts), which samples the table of each tick. */
50
+ watch?: ProcsDeps["watch"];
49
51
  /** The seams of a test (the process table, the kill sequence, the tick); the registry reads no table of this machine in a test run unless the test gives one. */
50
52
  over?: Partial<ProcsDeps> & { tickMs?: number };
51
53
  stops: (() => void)[];
@@ -66,7 +68,7 @@ export function startProcs(o: StartProcs): Procs {
66
68
  protect: (table) => protectedSet(table, { run: o.run, stateDir: o.stateDir, agentDir: o.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), self: o.pid }),
67
69
  panes: async () => (await herdrPanes(o.run)).map((p) => ({ pane_id: p.pane_id, ...(p.terminal_id ? { terminal_id: p.terminal_id } : {}), ...(p.cwd ? { cwd: p.cwd } : {}), ...(p.workspace_id ? { workspace_id: p.workspace_id } : {}) })),
68
70
  workspaces: async () => (await herdrWorkspaces(o.run)).flatMap((w) => (w.worktree?.is_linked_worktree && w.worktree.checkout_path ? [{ workspace_id: w.workspace_id, checkout_path: w.worktree.checkout_path }] : [])),
69
- ...quiet, ...o.over,
71
+ ...(o.watch ? { watch: o.watch } : {}), ...quiet, ...o.over,
70
72
  });
71
73
  if (o.platform === "win32") return procs;
72
74
  try {
@@ -1582,13 +1582,14 @@ export function createRuns(o: RunsOptions) {
1582
1582
  poke(svc);
1583
1583
  return written;
1584
1584
  },
1585
- /** A late outcome of something a run sent after the run ended: a notice event for the next run. */
1586
- notice(workspace: string, text: string, key: string) {
1585
+ /** A late outcome of something a run sent after the run ended, or a notice the server raises (the stall watch): a notice event for the next run. False when the server stands in for no tower there. */
1586
+ notice(workspace: string, text: string, key: string): boolean {
1587
1587
  const svc = services.get(workspace);
1588
- if (!svc) return;
1589
- if (waitingOf(svc).some((e) => e.kind === "notice" && e.messageId === key)) return;
1588
+ if (!svc) return false;
1589
+ if (waitingOf(svc).some((e) => e.kind === "notice" && e.messageId === key)) return true;
1590
1590
  append(slot, svc.ref.record(), { kind: "notice", text, at: iso(now()), messageId: key });
1591
1591
  poke(svc);
1592
+ return true;
1592
1593
  },
1593
1594
  /** The service is held because the standing pane runs a program of the boss's: it is Retried by itself once the pane is free (standing.ts). */
1594
1595
  paneBusy(workspace: string) {
@@ -0,0 +1,73 @@
1
+ import { statSync } from "node:fs";
2
+ import { openCalls } from "../ask.ts";
3
+ import { type HerdrRun, isSub, panes as herdrPanes, parentOf, type Session, type Workspace, workspaces as herdrWorkspaces } from "../herdr.ts";
4
+ import { createStallWatch, type Flag, readStallWatch, type StallDeps, type StallWatch } from "./stallwatch.ts";
5
+ import { inTestRun } from "./testguard.ts";
6
+ import { towerRunsEnabled } from "./towerruns.ts";
7
+ import type { Towers } from "./towers.ts";
8
+
9
+ // The server's side of the stall watch (stallwatch.ts): what it reads of this machine (pi-intercom's list, Herdr's panes, the session files) and the tower it tells. Kept out of main.ts, which carries a line budget.
10
+
11
+ export interface StartStall {
12
+ /** The slot's folder and the state folder (`config.json`). */
13
+ dir: string;
14
+ stateDir: string;
15
+ pid: number;
16
+ platform: NodeJS.Platform;
17
+ now(): number;
18
+ log(event: string, facts: Record<string, number | string | boolean>): void;
19
+ run: HerdrRun;
20
+ /** pi-intercom's list as the server's own connection sees it; rejects while it is not connected. */
21
+ sessions(): Promise<Session[]>;
22
+ towers(): Pick<Towers, "status" | "head" | "runs"> | undefined;
23
+ /** The seams of a test; in a test run there is no watch without them (it would read the panes of a fake Herdr every minute). */
24
+ over?: Partial<StallDeps>;
25
+ }
26
+
27
+ /**
28
+ * The workspace whose tower hears of a session in `workspace`: its own when the server stands in for a tower there, its parent's for a sub workspace (which never has a tower), else the head tower's;
29
+ * none when there is neither.
30
+ */
31
+ export function stallTarget(workspace: string | undefined, all: readonly Workspace[], served: readonly string[], head: string | undefined): string | undefined {
32
+ const asked = all.find((w) => w.workspace_id === workspace), target = asked && isSub(asked) ? parentOf([...all], asked) : asked;
33
+ return target && served.includes(target.workspace_id) ? target.workspace_id : head;
34
+ }
35
+
36
+ /** The notice is one event in the tower's queue: a key that is still waiting there is not queued twice. */
37
+ export async function tellTower(flag: Flag, run: HerdrRun, towers: ReturnType<StartStall["towers"]>): Promise<boolean> {
38
+ if (!towers) return false;
39
+ const to = stallTarget(flag.workspace, await herdrWorkspaces(run).catch(() => []), towers.status().map((r) => r.workspace), towers.head.status()?.workspace);
40
+ return to !== undefined && towers.runs.notice(to, flag.text, `stall:${flag.pid}:${flag.started}:${flag.kind}:${flag.told}`);
41
+ }
42
+
43
+ /** The watch of this server, or none: on Windows (there is no process table), and in a test run without seams. */
44
+ export function startStall(o: StartStall): StallWatch | undefined {
45
+ if (o.platform === "win32" || (inTestRun() && !o.over)) return undefined;
46
+ let noTower = false;
47
+ return createStallWatch({
48
+ dir: o.dir, now: o.now, log: o.log, self: [o.pid], config: () => readStallWatch(o.stateDir),
49
+ sessions: async () => (await o.sessions()).flatMap((s) => {
50
+ // SAFETY: pi-intercom's list carries each session's pid (its `SessionInfo`); herdr.ts names only the fields the net reads.
51
+ const pid = (s as { pid?: unknown }).pid;
52
+ // The pane is the one the broker found the session in at this list (`current`). A location it could not resolve carries the pane the session was started in, which a move has renamed since: no pane then.
53
+ const at = s.herdrLocation?.status === "current" ? s.herdrLocation : undefined;
54
+ return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 1 ? [{ id: s.id, ...(s.name ? { name: s.name } : {}), pid, ...(at?.paneId ? { pane: at.paneId } : {}), ...(at?.workspace?.id ? { workspace: at.workspace.id } : {}) }] : [];
55
+ }),
56
+ panes: async () => (await herdrPanes(o.run)).map((p) => ({ pane: p.pane_id, ...(p.terminal_id ? { terminal: p.terminal_id } : {}), ...(p.workspace_id ? { workspace: p.workspace_id } : {}), pi: p.agent === "pi", working: p.agent_status === "working", ...(p.agent_session?.value ? { file: p.agent_session.value } : {}), ...(p.tokens?.sb_role ? { role: p.tokens.sb_role } : {}) })),
57
+ paneProcs: async (pane) => {
58
+ const info = (JSON.parse(await o.run(["pane", "process-info", "--pane", pane])) as { result?: { process_info?: { shell_pid?: unknown; foreground_processes?: { pid?: unknown; name?: unknown; argv0?: unknown }[] } } }).result?.process_info;
59
+ if (!info) return undefined;
60
+ const word = (v: unknown) => (typeof v === "string" ? { v } : undefined);
61
+ return { ...(typeof info.shell_pid === "number" ? { shell: info.shell_pid } : {}), foreground: (info.foreground_processes ?? []).flatMap((p) => (typeof p.pid === "number" && p.pid > 1 ? [{ pid: p.pid, ...(word(p.name) ? { name: word(p.name)!.v } : {}), ...(word(p.argv0) ? { argv0: word(p.argv0)!.v } : {}) }] : [])) };
62
+ },
63
+ mtime: (file) => { try { return statSync(file).mtimeMs; } catch { return undefined; } },
64
+ openCalls: async (file) => { const found = await openCalls(file); return found === "cut" ? undefined : found.length; },
65
+ // With `towerRuns.enabled: false` the towers are resident pi sessions and the server stands in for none, so nobody is told: the log says so once, and each incident is in it as `stall-untold`.
66
+ tell: async (flag) => {
67
+ if (towerRunsEnabled(o.stateDir)) return (noTower = false), tellTower(flag, o.run, o.towers());
68
+ if (!noTower) (noTower = true), o.log("stall-no-tower", { text: "towerRuns.enabled is off in config.json, so the server stands in for no tower: the stall watch tells nobody, and its incidents are in this log only" });
69
+ return false;
70
+ },
71
+ ...o.over,
72
+ });
73
+ }