pi-todo-ledger 0.7.1 → 0.7.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/README.md CHANGED
@@ -49,6 +49,11 @@ Use `metadata.herdr.id` to resolve or message the worker by its run key.
49
49
  Use a name with `/boss send` only if it matches the name Straw Boss shows; a launch named `API worker` may appear there as `api-worker`.
50
50
  You can still set `owner` by hand.
51
51
 
52
+ The panel lists each task's live bound runs under it.
53
+ A run that belongs to no task, such as a scout sent out on the side, is listed under an `Other workers` group (`其他 worker` in zh-TW) after the tasks, in the same row format; the panel shows that group even when the list is empty.
54
+ The panel claims every run row it paints, so the host's Subagents box shows only the runs the panel does not.
55
+ See [docs/overlay.md](docs/overlay.md#other-workers).
56
+
52
57
  `/todos` and the panel's full view indent each open task under its first unfinished blocker; the panel's default focus view lists tasks flat and names every unfinished blocker after the subject. Both show the owner as `@owner`.
53
58
  To mark a task as waiting for someone, set `metadata.waitsOn` to their name; to defer it until a particular time, set `metadata.until` to an ISO timestamp, e.g. `2027-01-15T09:00:00+08:00`.
54
59
  An open task shows `⏸` with the name or the future deadline in local time.
package/docs/overlay.md CHANGED
@@ -10,7 +10,7 @@ The widget is mounted above the Pi editor under the key `rpiv-todos`, the key rp
10
10
  | Stage | Condition |
11
11
  | --- | --- |
12
12
  | Created | At the first session start that has a UI. A headless session never creates it. |
13
- | Registered | Only while at least one overlay-visible task exists. The widget unregisters itself when the list empties, and re-registers when a task reappears. |
13
+ | Registered | While at least one overlay-visible task exists, or the run host lists a run of this session (see [Other workers](#other-workers)). The widget unregisters itself when both are gone, and re-registers when a task or a run appears. With no task, a refresh after a `subagent` or `subagent_resume` call, or at the end of a turn, finds the new run. |
14
14
  | Bound | Only the foreground session's overlay is refreshed. A detached or child session has its own task state and never rebinds or repaints the foreground panel. |
15
15
  | Disposed | On the foreground session's shutdown. A child session shutting down leaves the overlay alone. |
16
16
 
@@ -39,8 +39,9 @@ Rows come in this order, until the row budget runs out:
39
39
  1. the heading;
40
40
  2. every task in progress, each followed by its run rows;
41
41
  3. the next two open tasks in display order, or the next three when nothing is in progress;
42
- 4. completed tasks from the current turn, only if rows are left after the run rows;
43
- 5. one summary row counting the hidden tasks in progress, pending, and completed, in that order, such as `+1 in progress, 5 pending, 2 completed` (`+1 進行中、5 待處理、2 已完成` in zh-TW). Zero counts are left out, and with nothing hidden there is no summary row.
42
+ 4. the [Other workers](#other-workers) group, with the rows the tasks and their runs leave;
43
+ 5. completed tasks from the current turn, only if rows are left after the group; they are drawn above the group, but get their rows after it;
44
+ 6. one summary row counting the hidden tasks in progress, pending, and completed, then the hidden other workers, in that order, such as `+1 in progress, 5 pending, 2 completed, 2 workers` (`+1 進行中、5 待處理、2 已完成、2 worker` in zh-TW). Zero counts are left out, and with nothing hidden there is no summary row.
44
45
 
45
46
  The summary row ends with a dim hint that names the panel key and the state it switches to next; see [Switching views](#switching-views).
46
47
 
@@ -99,6 +100,39 @@ The panel asks the Subagents widget to hide a run only once it knows the run's r
99
100
 
100
101
  Collapsing the panel, or the run leaving the panel, returns the run to the Subagents widget.
101
102
 
103
+ ## Other workers
104
+
105
+ An agent often sends out a run that belongs to no todo item: a quick scout, a reviewer, a one-off check.
106
+ The panel lists this session's runs that no task on the panel is bound to as one group, after the task rows and before the summary row:
107
+
108
+ ```text
109
+ ● Todos (0/3)
110
+ ├─ ◐ #1 API
111
+ │ └ api-worker · astra · 執行中 5s
112
+ ├─ ◐ #2 UI
113
+ │ └ ui-worker · astra · 執行中 42s
114
+ ├─ ○ #3 Docs
115
+ ├─ 其他 worker
116
+ │ ├ scout-x · astra · 執行中 3s
117
+ │ └ ◇ scout-y · sol · 閒置 1m
118
+ └─ ctrl+shift+t 完整
119
+ ```
120
+
121
+ - The heading row reads `Other workers` (`其他 worker` in zh-TW), in muted text. The group is normal work, not a warning, so it has no warning colour or icon.
122
+ - Each run row has the format of a bound run row: the idle and waiting marks, the time in the current state, and the claim marker. A run waiting for a reply keeps the warning colour it has under a task.
123
+ - Runs appear in the host's order.
124
+ - A run counts as bound when its id is in the `metadata.herdr.runs` of a task the panel shows. A run bound to a completed task that has faded out, or to a deleted one, joins the group.
125
+ - When a run gets bound to a task, it moves under that task on the next frame and leaves the group, so it is never drawn twice.
126
+ - With no task at all, the panel still shows its heading and the group.
127
+
128
+ The group follows the row budget:
129
+
130
+ - In the focus view, tasks in progress, the next tasks and their runs come first. The group gets the rows left: its heading and as many runs as fit, or nothing when fewer than two rows are left. The runs that do not fit are added to the summary row as `+2 workers` (`+2 worker` in zh-TW), or after the task counts, as in `+5 待處理、2 worker`.
131
+ - In the full view, the group follows the tree and lists every run within `maxWidgetLines`; the rest are counted in the summary row, as in `+3 more (3 pending), 2 workers`.
132
+ - In the collapsed view, the closing row counts the group before the key hint: `└─ +2 worker · ctrl+shift+t 焦點`.
133
+
134
+ The panel claims a group row the way it claims a bound run row: only a row painted in full, checked by its exact line in the fullscreen layout. A row cut by the width, clipped by the layout, covered by a popup, or folded into the summary stays unclaimed, so the Subagents widget keeps showing that run. When no ledger claims a run, the host's own widget is the fallback that shows it.
135
+
102
136
  ## Overflow
103
137
 
104
138
  The content-row budget is `maxWidgetLines` (default `12`), and the heading counts
@@ -131,7 +165,7 @@ session resets that tracking, so a fresh session shows the full list again.
131
165
 
132
166
  1. focus view;
133
167
  2. full view;
134
- 3. collapsed: the heading and one dim hint row, `└─ ctrl+shift+t focus`.
168
+ 3. collapsed: the heading and one dim hint row, `└─ ctrl+shift+t focus`, which starts with the count of [other workers](#other-workers) when there are any.
135
169
 
136
170
  The panel starts in the state `view` names, `"focus"` unless you set `"full"`,
137
171
  and the next press continues the cycle from there: from `"full"` it goes to
@@ -146,8 +180,8 @@ the hint takes its own closing `└─` row, and only when the row budget has a
146
180
  to spare, so it never pushes a task out. The hint always shows the configured
147
181
  key.
148
182
 
149
- Collapsing hides the run rows, so the panel releases its claim on them; the
150
- Subagents widget can show them again. In the focus and full views the panel
183
+ Collapsing hides the run rows, including the Other workers group, so the panel
184
+ releases its claim on them; the Subagents widget can show them again. In the focus and full views the panel
151
185
  claims the run rows it actually paints, as described under
152
186
  [Worker runs under a task](#worker-runs-under-a-task).
153
187
 
@@ -179,8 +213,8 @@ tasks. Tombstoned tasks are never listed.
179
213
 
180
214
  ## Localization
181
215
 
182
- The overlay heading, both summary rows, the key hint, the `/todos`
183
- section headers, and the status words all localize through
216
+ The overlay heading, both summary rows, the key hint, the Other workers heading and
217
+ count, the run states, the `/todos` section headers, and the status words all localize through
184
218
  [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n)
185
219
  when that package is installed. Bundled locales: `de`, `en`, `es`, `fr`, `pt`,
186
220
  `pt-BR`, `ru`, `uk`, `zh` (Simplified), and `zh-TW` (Traditional).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-todo-ledger",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "A todo list for pi agents with a public bookkeeping contract: snapshot entries, change events, and namespace validators. Fork of @juicesharp/rpiv-todo",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -51,6 +51,7 @@ import {
51
51
  } from "./state/store.ts";
52
52
  import { registerTodosCommand, registerTodoTool, TOOL_NAME } from "./todo.ts";
53
53
  import type { TodoOverlay } from "./todo-overlay.ts";
54
+ import { RUN_ROWS_EVENT } from "./view/live-runs.ts";
54
55
 
55
56
  // Held in a variable so the type checker does not require the optional peer.
56
57
  const I18N_LOADER: string = "@juicesharp/rpiv-i18n/loader";
@@ -159,17 +160,30 @@ export default function (
159
160
  let uiCtx: ExtensionUIContext | undefined;
160
161
  let lifecycleGeneration = 0;
161
162
 
163
+ // The host's run-rows probe. Without a claim it only reads this session's runs.
164
+ const queryRuns = (p: object) => pi.events.emit(RUN_ROWS_EVENT, p);
165
+ /** Whether the host lists any run of this session: such runs show on the panel even with no task. */
166
+ const hostHasRuns = (): boolean => {
167
+ const p: { rows?: { rows?: unknown } } = {};
168
+ try {
169
+ queryRuns(p);
170
+ } catch {
171
+ return false;
172
+ }
173
+ return Array.isArray(p.rows?.rows) && p.rows.rows.length > 0;
174
+ };
175
+
162
176
  async function updateTodoOverlay(
163
177
  resetCompletedDisplayState = false,
164
178
  generation = lifecycleGeneration,
165
179
  ): Promise<void> {
166
180
  const hasVisibleTasks = getRenderState().tasks.some((task) => task.status !== "deleted");
167
- if (!uiCtx || (!todoOverlay && !hasVisibleTasks)) return;
181
+ if (!uiCtx || (!todoOverlay && !hasVisibleTasks && !hostHasRuns())) return;
168
182
 
169
183
  const { TodoOverlay } = await loadTodoOverlay();
170
184
  if (generation !== lifecycleGeneration || !uiCtx) return;
171
185
 
172
- todoOverlay ??= new TodoOverlay(p => pi.events.emit('pi-herdr-agents:run-rows:v1', p));
186
+ todoOverlay ??= new TodoOverlay(queryRuns);
173
187
  todoOverlay.setUICtx(uiCtx);
174
188
  if (resetCompletedDisplayState) todoOverlay.resetCompletedDisplayState();
175
189
  todoOverlay.update();
@@ -309,14 +323,12 @@ export default function (
309
323
  }
310
324
  });
311
325
 
312
- // Reads getTodos() at render time; do NOT call replayFromBranch here
313
- // (branch is stale — message_end runs after tool_execution_end).
314
- pi.on("tool_execution_end", async (event) => {
315
- if ((event.toolName !== TOOL_NAME && event.toolName !== "subagent") || event.isError) return;
326
+ // A refresh after something that may change the list or this session's runs.
327
+ const refresh = async (): Promise<void> => {
316
328
  try {
317
329
  await updateTodoOverlay();
318
330
  } catch (e) {
319
- // The tool itself succeeded — a transient overlay-load failure only
331
+ // The tool or turn itself succeeded — a transient overlay-load failure only
320
332
  // costs this one refresh, and the loader's cleared memo lets the next
321
333
  // update retry. Don't surface that as an extension error. The latched
322
334
  // stale-namespace error still propagates: it never self-heals, and the
@@ -324,8 +336,19 @@ export default function (
324
336
  if (isStaleOverlayModuleError(e)) throw e;
325
337
  console.warn(`[pi-todo-ledger] overlay refresh failed (will retry on next update): ${formatError(e)}`);
326
338
  }
339
+ };
340
+
341
+ // Reads getTodos() at render time; do NOT call replayFromBranch here
342
+ // (branch is stale — message_end runs after tool_execution_end). A launch or
343
+ // resume may start a run bound to no task, which the panel shows too.
344
+ pi.on("tool_execution_end", async (event) => {
345
+ if (event.isError || ![TOOL_NAME, "subagent", "subagent_resume"].includes(event.toolName)) return;
346
+ await refresh();
327
347
  });
328
348
 
349
+ // Runs can also start without a tool call of this session; the end of a turn picks them up.
350
+ pi.on("agent_end", refresh);
351
+
329
352
  // Evaluate the lazy graph after startup while Pi's boot-time dependency paths
330
353
  // are still stable. This loads no widget and constructs no overlay; those stay
331
354
  // deferred until a foreground session has visible tasks. A rejected pre-warm
@@ -13,6 +13,9 @@
13
13
  "overlay.next.full": "voll",
14
14
  "overlay.next.collapsed": "einklappen",
15
15
  "overlay.collapsed": "eingeklappt",
16
+ "overlay.others": "Weitere Worker",
17
+ "overlay.worker.one": "Worker",
18
+ "overlay.worker.other": "Worker",
16
19
 
17
20
  "command.no_todos": "Noch keine Todos. Bitte den Agenten, welche hinzuzufügen!",
18
21
  "command.requires_interactive": "/todos erfordert den interaktiven Modus",
@@ -12,6 +12,9 @@
12
12
  "overlay.next.collapsed": "collapse",
13
13
  "overlay.collapsed": "collapsed",
14
14
  "overlay.separator": ", ",
15
+ "overlay.others": "Other workers",
16
+ "overlay.worker.one": "worker",
17
+ "overlay.worker.other": "workers",
15
18
 
16
19
  "command.no_todos": "No todos yet. Ask the agent to add some!",
17
20
  "command.requires_interactive": "/todos requires interactive mode",
@@ -13,6 +13,9 @@
13
13
  "overlay.next.full": "completo",
14
14
  "overlay.next.collapsed": "contraer",
15
15
  "overlay.collapsed": "contraído",
16
+ "overlay.others": "Otros workers",
17
+ "overlay.worker.one": "worker",
18
+ "overlay.worker.other": "workers",
16
19
 
17
20
  "command.no_todos": "Sin tareas aún. ¡Pídele al agente que añada algunas!",
18
21
  "command.requires_interactive": "/todos requiere modo interactivo",
@@ -13,6 +13,9 @@
13
13
  "overlay.next.full": "complet",
14
14
  "overlay.next.collapsed": "réduire",
15
15
  "overlay.collapsed": "réduit",
16
+ "overlay.others": "Autres workers",
17
+ "overlay.worker.one": "worker",
18
+ "overlay.worker.other": "workers",
16
19
 
17
20
  "command.no_todos": "Pas encore de tâches. Demandez à l'agent d'en ajouter !",
18
21
  "command.requires_interactive": "/todos nécessite le mode interactif",
@@ -13,6 +13,9 @@
13
13
  "overlay.next.full": "completo",
14
14
  "overlay.next.collapsed": "recolher",
15
15
  "overlay.collapsed": "recolhido",
16
+ "overlay.others": "Outros workers",
17
+ "overlay.worker.one": "worker",
18
+ "overlay.worker.other": "workers",
16
19
 
17
20
  "command.no_todos": "Nenhuma tarefa ainda. Peça ao agente para adicionar algumas!",
18
21
  "command.requires_interactive": "/todos requer modo interativo",
@@ -13,6 +13,9 @@
13
13
  "overlay.next.full": "completo",
14
14
  "overlay.next.collapsed": "recolher",
15
15
  "overlay.collapsed": "recolhido",
16
+ "overlay.others": "Outros workers",
17
+ "overlay.worker.one": "worker",
18
+ "overlay.worker.other": "workers",
16
19
 
17
20
  "command.no_todos": "Sem tarefas ainda. Peça ao agente para adicionar algumas!",
18
21
  "command.requires_interactive": "/todos requer modo interativo",
@@ -13,6 +13,11 @@
13
13
  "overlay.next.full": "полностью",
14
14
  "overlay.next.collapsed": "свернуть",
15
15
  "overlay.collapsed": "свёрнуто",
16
+ "overlay.others": "Другие воркеры",
17
+ "overlay.worker.one": "воркер",
18
+ "overlay.worker.few": "воркера",
19
+ "overlay.worker.many": "воркеров",
20
+ "overlay.worker.other": "воркера",
16
21
 
17
22
  "command.no_todos": "Задач пока нет. Попросите агента добавить!",
18
23
  "command.requires_interactive": "/todos требует интерактивного режима",
@@ -13,6 +13,11 @@
13
13
  "overlay.next.full": "повністю",
14
14
  "overlay.next.collapsed": "згорнути",
15
15
  "overlay.collapsed": "згорнуто",
16
+ "overlay.others": "Інші воркери",
17
+ "overlay.worker.one": "воркер",
18
+ "overlay.worker.few": "воркери",
19
+ "overlay.worker.many": "воркерів",
20
+ "overlay.worker.other": "воркера",
16
21
 
17
22
  "command.no_todos": "Завдань поки немає. Попросіть агента додати!",
18
23
  "command.requires_interactive": "/todos потребує інтерактивного режиму",
@@ -11,6 +11,8 @@
11
11
  "overlay.next.collapsed": "收合",
12
12
  "overlay.collapsed": "已收合",
13
13
  "overlay.separator": "、",
14
+ "overlay.others": "其他 worker",
15
+ "overlay.worker.other": "worker",
14
16
  "command.no_todos": "目前沒有待辦事項。",
15
17
  "command.requires_interactive": "/todos 需要互動模式",
16
18
  "command.section.pending": "── 待處理 ──",
@@ -14,6 +14,8 @@
14
14
  "overlay.next.collapsed": "收起",
15
15
  "overlay.collapsed": "已折叠",
16
16
  "overlay.separator": "、",
17
+ "overlay.others": "其他 worker",
18
+ "overlay.worker.other": "worker",
17
19
 
18
20
  "command.no_todos": "暂无任务。可以让 agent 添加一些!",
19
21
  "command.requires_interactive": "/todos 需要交互模式",
@@ -96,6 +96,18 @@ export const t: ScopeFn = (key, fallback) => {
96
96
  return scopeImpl(key, fallback);
97
97
  };
98
98
 
99
+ /** `2 workers`, `2 worker` (zh-TW): the word follows the locale's plural rule; a category the locale lacks uses `other`. */
100
+ export function formatWorkerCount(n: number): string {
101
+ let category = "other";
102
+ try {
103
+ category = new Intl.PluralRules(/^[a-z]{2,3}(?=$|[-_.@])/.exec(renderLocale())?.[0] ?? "en").select(n);
104
+ } catch {
105
+ /* unknown locale: other */
106
+ }
107
+ const word = t(`overlay.worker.${category}`, "") || t("overlay.worker.other", n === 1 ? "worker" : "workers");
108
+ return `${n} ${word}`;
109
+ }
110
+
99
111
  const STATUS_LABEL_PENDING = "pending";
100
112
  const STATUS_LABEL_IN_PROGRESS = "in progress";
101
113
  const STATUS_LABEL_COMPLETED = "completed";
@@ -28,7 +28,7 @@ import {
28
28
  type OverlayView,
29
29
  resolveCollapseKey,
30
30
  } from "./config.ts";
31
- import { formatStatusLabel, t } from "./state/i18n-bridge.ts";
31
+ import { formatStatusLabel, formatWorkerCount, t } from "./state/i18n-bridge.ts";
32
32
  import {
33
33
  selectHasActive,
34
34
  selectOverlayLayout,
@@ -51,6 +51,7 @@ const OVERLAY_MORE = "more";
51
51
  const OVERLAY_KEY_HINT = "{key} {next}";
52
52
  const OVERLAY_COLLAPSED = "collapsed";
53
53
  const OVERLAY_SEPARATOR = ", ";
54
+ const OVERLAY_OTHERS = "Other workers";
54
55
 
55
56
  /** What the panel shows: one of the two views, or the two-line collapsed state. */
56
57
  type PanelState = OverlayView | "collapsed";
@@ -59,6 +60,18 @@ const NEXT_STATE: Record<PanelState, PanelState> = { focus: "full", full: "colla
59
60
  /** English names of the state the key goes to next, as the hint shows them. */
60
61
  const NEXT_STATE_NAME: Record<PanelState, string> = { focus: "focus", full: "full", collapsed: "collapse" };
61
62
 
63
+ /** Run rows drawn on one frame, for the claim bookkeeping. */
64
+ interface Frame {
65
+ /** Inline: runs drawn whole. */
66
+ drawn: string[];
67
+ /** Fullscreen: runs drawn whole, with their marked line. */
68
+ marked: Map<string, string>;
69
+ ticking: boolean;
70
+ }
71
+
72
+ /** Runs of the Other workers group that fit `rows`: the heading and at least one run, or none. */
73
+ const groupFit = (rows: number, runs: number) => (runs > 0 && rows >= 2 ? Math.min(runs, rows - 1) : 0);
74
+
62
75
  /** What one frame's row drawing needs, shared by the full and focus views. */
63
76
  interface DrawContext {
64
77
  theme: Theme;
@@ -66,6 +79,8 @@ interface DrawContext {
66
79
  truncate: (line: string) => string;
67
80
  bound: Map<number, ReturnType<typeof history>>;
68
81
  live: ReturnType<typeof liveRows>;
82
+ /** Live runs of this session bound to no task on the panel, in the host's order. */
83
+ others: RunRow[];
69
84
  showIds: boolean;
70
85
  now: number;
71
86
  evidence: "inline" | "screen" | undefined;
@@ -212,7 +227,8 @@ export class TodoOverlay {
212
227
  const snapshot = this.getSnapshot();
213
228
  const visible = this.selectOverlayTasks(snapshot);
214
229
 
215
- if (visible.length === 0) {
230
+ // With no task to show, the panel stays for this session's runs (the Other workers group).
231
+ if (visible.length === 0 && !liveRows(this.query)?.size) {
216
232
  this.finishFrame([]);
217
233
  if (this.widgetRegistered) {
218
234
  this.uiCtx.setWidget(WIDGET_KEY, undefined);
@@ -344,7 +360,9 @@ export class TodoOverlay {
344
360
  private renderWidget(theme: Theme, width: number): string[] {
345
361
  const snapshot = this.getSnapshot();
346
362
  const overlayTasks = this.selectOverlayTasks(snapshot);
347
- if (overlayTasks.length === 0) {
363
+ // Every state asks the host: runs bound to no task join the Other workers group, or its count.
364
+ const live = liveRows(this.query);
365
+ if (overlayTasks.length === 0 && !live?.size) {
348
366
  this.finishFrame([]);
349
367
  return [];
350
368
  }
@@ -352,9 +370,8 @@ export class TodoOverlay {
352
370
  overlayTasks.map((t) => [t.id, history(t.metadata?.herdr)] as const),
353
371
  );
354
372
  const hasRuns = [...bound.values()].some((h) => h.runs.length > 0);
355
- // Ask the host only when some todo has bound runs and the tree is shown.
356
- const live =
357
- hasRuns && this.current() !== "collapsed" ? liveRows(this.query) : undefined;
373
+ const boundIds = new Set([...bound.values()].flatMap((h) => h.runs.map((r) => r.id)));
374
+ const others = [...(live?.values() ?? [])].filter((r) => !boundIds.has(r.id));
358
375
 
359
376
  const plan = planView(overlayTasks);
360
377
  // Keep completed rows in their old slots; fill open slots in display order before budgeting.
@@ -367,7 +384,7 @@ export class TodoOverlay {
367
384
  truncateToWidth(line, width, "…");
368
385
  const counts = selectTodoCounts(overlayState);
369
386
  const hasActive = selectHasActive(overlayState);
370
- const showIds = !!live?.size || selectShowTaskIds(overlayState);
387
+ const showIds = (hasRuns && !!live?.size) || selectShowTaskIds(overlayState);
371
388
 
372
389
  const headingColor = hasActive ? "accent" : "dim";
373
390
  const headingIcon = hasActive ? "●" : "○";
@@ -379,20 +396,31 @@ export class TodoOverlay {
379
396
  `${theme.fg(headingColor, headingIcon)} ${theme.fg(headingColor, headingText)}${graph}`,
380
397
  );
381
398
 
399
+ const draw: DrawContext = {
400
+ theme,
401
+ width,
402
+ truncate,
403
+ bound,
404
+ live,
405
+ others,
406
+ showIds,
407
+ now: Date.now(),
408
+ evidence: this.evidence(),
409
+ };
410
+
382
411
  // Collapsed view: just the heading + a dim "└─" hint naming the next state,
383
- // then the trailing spacer. Short-circuit before the budget math and the
384
- // completed-display tracking — nothing is shown to track, and skipping the
385
- // tracking when nothing is rendered is correctness, not optimization. The
386
- // "off" sentinel is reachable here mid-session (config edited after the
387
- // shortcut was bound and the overlay collapsed) — render a static collapsed
388
- // label instead of advertising an unbound key.
412
+ // after the count of other workers, then the trailing spacer. Short-circuit
413
+ // before the budget math and the completed-display tracking — nothing is
414
+ // shown to track, and skipping the tracking when nothing is rendered is
415
+ // correctness, not optimization. The "off" sentinel is reachable here
416
+ // mid-session (config edited after the shortcut was bound and the overlay
417
+ // collapsed) — render a static collapsed label instead of advertising an
418
+ // unbound key. Nothing is claimed; the tick keeps the count current.
389
419
  if (this.current() === "collapsed") {
390
- this.finishFrame([]);
420
+ this.finishFrame([], others.length > 0);
391
421
  const hint = this.keyHint() ?? t("overlay.collapsed", OVERLAY_COLLAPSED);
392
- return this.withTrailingSpacer([
393
- heading,
394
- truncate(`${theme.fg("dim", "└─")} ${theme.fg("dim", hint)}`),
395
- ]);
422
+ const count = others.length ? `+${formatWorkerCount(others.length)}` : undefined;
423
+ return this.withTrailingSpacer([heading, this.closingRow(draw, count, hint)]);
396
424
  }
397
425
 
398
426
  // Budget for content rows below the heading (tasks, run rows, summary). The
@@ -404,16 +432,6 @@ export class TodoOverlay {
404
432
  this.uiCtx?.getToolsExpanded?.() === true
405
433
  ? Infinity
406
434
  : getMaxWidgetLines() - 1;
407
- const draw: DrawContext = {
408
- theme,
409
- width,
410
- truncate,
411
- bound,
412
- live,
413
- showIds,
414
- now: Date.now(),
415
- evidence: this.evidence(),
416
- };
417
435
  const body =
418
436
  this.current() === "full"
419
437
  ? this.fullBody(overlayState, plan, bodyBudget, draw)
@@ -433,7 +451,7 @@ export class TodoOverlay {
433
451
  return this.withTrailingSpacer([heading, ...body]);
434
452
  }
435
453
 
436
- /** The whole dependency tree, budgeted by selectOverlayLayout (the `"full"` view). */
454
+ /** The whole dependency tree, budgeted by selectOverlayLayout (the `"full"` view), then the Other workers group. */
437
455
  private fullBody(
438
456
  overlayState: { tasks: Task[]; nextId: number },
439
457
  plan: ReturnType<typeof planView>,
@@ -443,42 +461,67 @@ export class TodoOverlay {
443
461
  const layout = selectOverlayLayout(overlayState, bodyBudget);
444
462
  const overflow = layout.hiddenCompleted + layout.truncatedTail;
445
463
  const hint = this.keyHint();
464
+ const others = draw.others.length;
446
465
  // With nothing to summarize, the hint takes its own row only when one is spare.
447
- const needed = layout.visible.reduce((n, task) => n + 1 + this.children(task, draw).length, 0);
466
+ const needed =
467
+ layout.visible.reduce((n, task) => n + 1 + this.children(task, draw).length, 0) +
468
+ (others ? 1 + others : 0);
448
469
  const hintRow = overflow === 0 && hint !== undefined && needed < bodyBudget;
449
- const spare = bodyBudget - layout.visible.length - Number(overflow > 0 || hintRow);
470
+ let spare = bodyBudget - layout.visible.length - Number(overflow > 0 || hintRow);
471
+ // The group gets the rows the bound runs leave; a group cut short needs the summary row.
472
+ let rest = spare - this.boundRows(layout.visible, spare, draw);
473
+ let summarized = overflow > 0;
474
+ let group = others;
475
+ if (1 + others > rest) {
476
+ if (!summarized && rest > 0) {
477
+ summarized = true;
478
+ rest--;
479
+ }
480
+ group = groupFit(rest, others);
481
+ }
482
+ spare -= group ? 1 + group : 0;
483
+ const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
450
484
  const lines = this.drawTasks(
451
485
  layout.visible.map((task) => ({ task, row: plan.rows.get(task.id) })),
452
486
  spare,
453
- overflow === 0 && !hintRow,
487
+ !summarized && !hintRow && !group,
454
488
  draw,
489
+ frame,
455
490
  );
491
+ lines.push(...this.drawGroup(draw.others.slice(0, group), !summarized && !hintRow, draw, frame));
492
+ this.endFrame(frame, draw);
456
493
  if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
457
- if (overflow === 0) return lines;
494
+ if (!summarized) return lines;
458
495
 
459
- const overflowParts: string[] = [];
460
- if (layout.hiddenCompleted > 0)
461
- overflowParts.push(
462
- `${layout.hiddenCompleted} ${formatStatusLabel("completed")}`,
496
+ const parts: string[] = [];
497
+ if (overflow > 0) {
498
+ const overflowParts: string[] = [];
499
+ if (layout.hiddenCompleted > 0)
500
+ overflowParts.push(
501
+ `${layout.hiddenCompleted} ${formatStatusLabel("completed")}`,
502
+ );
503
+ if (layout.truncatedTail > 0)
504
+ overflowParts.push(
505
+ `${layout.truncatedTail} ${formatStatusLabel("pending")}`,
506
+ );
507
+ const more = t("overlay.more", OVERLAY_MORE);
508
+ parts.push(
509
+ overflowParts.length > 0
510
+ ? `+${overflow} ${more} (${overflowParts.join(", ")})`
511
+ : `+${overflow} ${more}`,
463
512
  );
464
- if (layout.truncatedTail > 0)
465
- overflowParts.push(
466
- `${layout.truncatedTail} ${formatStatusLabel("pending")}`,
467
- );
468
- const more = t("overlay.more", OVERLAY_MORE);
469
- const summary =
470
- overflowParts.length > 0
471
- ? `+${overflow} ${more} (${overflowParts.join(", ")})`
472
- : `+${overflow} ${more}`;
473
- lines.push(this.closingRow(draw, summary, hint));
513
+ }
514
+ if (group < others) parts.push(`${parts.length ? "" : "+"}${formatWorkerCount(others - group)}`);
515
+ lines.push(this.closingRow(draw, parts.join(t("overlay.separator", OVERLAY_SEPARATOR)), hint));
474
516
  return lines;
475
517
  }
476
518
 
477
519
  /**
478
520
  * The focus view (default): in-progress tasks with their runs, the next open
479
- * tasks (two, or three when nothing is in progress), then this turn's completed
480
- * rows if room is left, and one summary row counting whatever is hidden. Rows are
481
- * flat, so every unfinished blocker goes to the `⛓` tail.
521
+ * tasks (two, or three when nothing is in progress), the Other workers group,
522
+ * then this turn's completed rows if room is left, and one summary row counting
523
+ * whatever is hidden. Completed rows are drawn before the group but get rows
524
+ * after it. Rows are flat, so every unfinished blocker goes to the `⛓` tail.
482
525
  */
483
526
  private focusBody(
484
527
  overlayTasks: Task[],
@@ -491,21 +534,22 @@ export class TodoOverlay {
491
534
  const completed = overlayTasks.filter((t) => t.status === "completed");
492
535
  const next = pending.slice(0, inProgress.length ? 2 : 3);
493
536
  const total = inProgress.length + pending.length + completed.length;
537
+ const others = draw.others.length;
494
538
 
495
539
  // Task rows first, in priority order; runs take the spare rows in display order;
496
- // completed rows get what is left. The summary row is reserved only when needed.
540
+ // the group and then completed rows get what is left. The summary row is reserved only when needed.
497
541
  const fit = (slots: number) => {
498
542
  const core = [...inProgress, ...next].slice(0, slots);
499
- let spare = slots - core.length;
500
- for (const task of core) {
501
- const n = this.children(task, draw).length;
502
- if (n <= spare) spare -= n;
503
- }
543
+ let spare = slots - core.length - this.boundRows(core, slots - core.length, draw);
544
+ const group = groupFit(spare, others);
545
+ spare -= group ? 1 + group : 0;
504
546
  const done = completed.slice(0, spare);
505
- return { core, done, spare: slots - core.length - done.length, left: spare - done.length };
547
+ const rows = core.length + done.length + (group ? 1 + group : 0);
548
+ return { core, done, group, spare: slots - rows, left: spare - done.length };
506
549
  };
507
550
  let shown = fit(bodyBudget);
508
- let summarized = shown.core.length + shown.done.length < total;
551
+ const summarized =
552
+ shown.core.length + shown.done.length < total || shown.group < others;
509
553
  if (summarized) shown = fit(bodyBudget - 1);
510
554
  // With nothing to summarize, the hint takes its own row only when one is spare;
511
555
  // one row less leaves the same layout then.
@@ -524,12 +568,16 @@ export class TodoOverlay {
524
568
  }
525
569
  : undefined;
526
570
  };
571
+ const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
527
572
  const lines = this.drawTasks(
528
573
  [...shown.core, ...shown.done].map((task) => ({ task, row: flat(task) })),
529
574
  shown.spare,
530
- !summarized && !hintRow,
575
+ !summarized && !hintRow && !shown.group,
531
576
  draw,
577
+ frame,
532
578
  );
579
+ lines.push(...this.drawGroup(draw.others.slice(0, shown.group), !summarized && !hintRow, draw, frame));
580
+ this.endFrame(frame, draw);
533
581
  if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
534
582
  if (!summarized) return lines;
535
583
 
@@ -544,6 +592,7 @@ export class TodoOverlay {
544
592
  )
545
593
  .filter(([n]) => n > 0)
546
594
  .map(([n, status]) => `${n} ${formatStatusLabel(status)}`);
595
+ if (shown.group < others) parts.push(formatWorkerCount(others - shown.group));
547
596
  const summary = `+${parts.join(t("overlay.separator", OVERLAY_SEPARATOR))}`;
548
597
  lines.push(this.closingRow(draw, summary, hint));
549
598
  return lines;
@@ -555,22 +604,73 @@ export class TodoOverlay {
555
604
  return runs.flatMap((r) => draw.live?.get(r.id) ?? []);
556
605
  }
557
606
 
607
+ /** Rows the tasks' runs take from `spare`, given in display order to each task whose runs all fit, as drawTasks does. */
608
+ private boundRows(tasks: readonly Task[], spare: number, draw: DrawContext): number {
609
+ let used = 0;
610
+ for (const task of tasks) {
611
+ const n = this.children(task, draw).length;
612
+ if (used + n <= spare) used += n;
613
+ }
614
+ return used;
615
+ }
616
+
617
+ /** End the frame's claim bookkeeping; a group folded into the summary keeps the tick so its count stays current. */
618
+ private endFrame(frame: Frame, draw: DrawContext) {
619
+ this.finishFrame(frame.drawn, frame.ticking || draw.others.length > 0, frame.marked);
620
+ }
621
+
622
+ /**
623
+ * One run row under `branch`. A run waiting for a reply stands out; idle and
624
+ * running rows stay dim, and so does the tree. Only a row shown in full is
625
+ * claimed; a truncated one carries no marker.
626
+ */
627
+ private drawRun(lines: string[], r: RunRow, branch: string, draw: DrawContext, frame: Frame) {
628
+ const { theme, width, truncate, now, evidence } = draw;
629
+ const line =
630
+ runState(r) === "waiting"
631
+ ? theme.fg("dim", branch) + theme.fg("warning", runLine(r, now))
632
+ : theme.fg("dim", branch + runLine(r, now));
633
+ const whole = visibleWidth(line) <= width;
634
+ frame.ticking = true;
635
+ if (whole && evidence === "screen") {
636
+ const marked = line + this.marker(r.id);
637
+ frame.marked.set(r.id, marked);
638
+ lines.push(marked);
639
+ } else {
640
+ lines.push(truncate(line));
641
+ if (whole && evidence === "inline") frame.drawn.push(r.id);
642
+ }
643
+ }
644
+
645
+ /**
646
+ * The Other workers group: a heading row, then this session's runs bound to no
647
+ * task, drawn and claimed like bound run rows. `closed` means it ends the panel.
648
+ */
649
+ private drawGroup(runs: RunRow[], closed: boolean, draw: DrawContext, frame: Frame): string[] {
650
+ if (!runs.length) return [];
651
+ const { theme, truncate } = draw;
652
+ const lines = [
653
+ truncate(`${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted", t("overlay.others", OVERLAY_OTHERS))}`),
654
+ ];
655
+ for (const [j, r] of runs.entries())
656
+ this.drawRun(lines, r, `${closed ? " " : "│"} ${j === runs.length - 1 ? "└" : "├"} `, draw, frame);
657
+ return lines;
658
+ }
659
+
558
660
  /**
559
661
  * Draw task rows and, where `spare` rows remain, their run rows; a task whose
560
- * runs do not fit shows `· N runs`. Ends the frame's claim bookkeeping. `closed`
561
- * means no summary row follows, so the last task row takes `└─`.
662
+ * runs do not fit shows `· N runs`. `closed` means nothing follows, so the last
663
+ * task row takes `└─`.
562
664
  */
563
665
  private drawTasks(
564
666
  entries: { task: Task; row?: PlanRow }[],
565
667
  spare: number,
566
668
  closed: boolean,
567
669
  draw: DrawContext,
670
+ frame: Frame,
568
671
  ): string[] {
569
- const { theme, width, truncate, live, showIds, now, evidence } = draw;
672
+ const { theme, truncate, live, showIds } = draw;
570
673
  const lines: string[] = [];
571
- const drawn: string[] = [];
572
- let ticking = false;
573
- const marked = new Map<string, string>();
574
674
  for (const [i, { task, row }] of entries.entries()) {
575
675
  const { older } = draw.bound.get(task.id) ?? history(undefined);
576
676
  const children = this.children(task, draw);
@@ -590,28 +690,10 @@ export class TodoOverlay {
590
690
  );
591
691
  if (!fits) continue;
592
692
  spare -= children.length;
593
- for (const [j, r] of children.entries()) {
594
- const indent = " ".repeat(row?.depth ?? 0);
595
- const branch = `${last ? " " : "│"} ${indent}${j === children.length - 1 ? "└" : "├"} `;
596
- // A run waiting for a reply stands out; idle and running rows stay dim. The tree stays dim.
597
- const childLine =
598
- runState(r) === "waiting"
599
- ? theme.fg("dim", branch) + theme.fg("warning", runLine(r, now))
600
- : theme.fg("dim", branch + runLine(r, now));
601
- const whole = visibleWidth(childLine) <= width;
602
- ticking = true;
603
- // Only a row shown in full is claimed; a truncated one carries no marker.
604
- if (whole && evidence === "screen") {
605
- const line = childLine + this.marker(r.id);
606
- marked.set(r.id, line);
607
- lines.push(line);
608
- } else {
609
- lines.push(truncate(childLine));
610
- if (whole && evidence === "inline") drawn.push(r.id);
611
- }
612
- }
693
+ const indent = " ".repeat(row?.depth ?? 0);
694
+ for (const [j, r] of children.entries())
695
+ this.drawRun(lines, r, `${last ? " " : "│"} ${indent}${j === children.length - 1 ? "└" : "├"} `, draw, frame);
613
696
  }
614
- this.finishFrame(drawn, ticking, marked);
615
697
  return lines;
616
698
  }
617
699
 
@@ -9,6 +9,8 @@ export interface RunRow {
9
9
  phase: { kind: string; label?: string; since?: number };
10
10
  cancel?: string;
11
11
  }
12
+ /** The host's run-rows event (pi-herdr-agents, and pi-straw-boss after the move): the probe and the claim. */
13
+ export const RUN_ROWS_EVENT = "pi-herdr-agents:run-rows:v1";
12
14
  export interface Probe {
13
15
  claim?: { by: string; ids: string[] };
14
16
  rows?: { version: 1; rows: RunRow[] };