pi-todo-ledger 0.8.0 → 0.8.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/docs/overlay.md CHANGED
@@ -34,18 +34,18 @@ The panel opens in the focus view. It shows what is being worked on and what com
34
34
  └─ +5 待處理 · ctrl+shift+t 完整
35
35
  ```
36
36
 
37
- Rows come in this order, until the row budget runs out:
37
+ Rows are drawn in this order:
38
38
 
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. 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;
42
+ 4. completed tasks from the current turn;
43
+ 5. the [Other workers](#other-workers) group;
44
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.
45
45
 
46
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).
47
47
 
48
- `maxWidgetLines` is a hard cap here too: tasks in progress that do not fit are counted in the summary, and run rows that do not fit fold into `· N runs`.
48
+ `maxWidgetLines` is a hard cap here too. Rows 2 to 5 share the budget by [rank](#overflow): run rows and the group come before the next open tasks, tasks in progress that do not fit are counted in the summary, and run rows that do not fit fold into `· N runs`.
49
49
  Rows are flat, so the `⛓` tail lists every unfinished blocker of a task; `⏸`, owners, and the other marks are the same as in the full view.
50
50
  Pi's tool-output expansion mode lifts the row cap but keeps this selection. Press the panel key for the tree below, set `"view": "full"` (see [configuration.md](./configuration.md#view)) to start there, or use `/todos` to see everything once.
51
51
 
@@ -127,8 +127,8 @@ The group follows the task rows. It includes unbound runs and runs whose task is
127
127
 
128
128
  The group follows the row budget:
129
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`.
130
+ - In both views, tasks in progress and their runs come first, then the group, then the pending and completed tasks without a live run (see [Overflow](#overflow)). The group gets its heading and as many runs as fit, or nothing when fewer than two rows are left.
131
+ - 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` in the focus view and `+3 more (3 pending), 2 workers` in the full view.
132
132
  - In the collapsed view, the closing row counts the group before the key hint: `└─ +2 worker · ctrl+shift+t 焦點`.
133
133
 
134
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.
@@ -136,20 +136,62 @@ The panel claims a group row the way it claims a bound run row: only a row paint
136
136
  ## Overflow
137
137
 
138
138
  The content-row budget is `maxWidgetLines` (default `12`), and the heading counts
139
- against it. The focus view applies it as described [above](#focus-view). In the
140
- full view, when there are more tasks than fit:
139
+ against it. When the rows do not all fit, one row is reserved for the summary,
140
+ and both views hand out the rest by rank, in display order within each rank:
141
141
 
142
- 1. one row is reserved for the summary line;
143
- 2. completed tasks are dropped first, newest first — the oldest completed rows
144
- are the last completed rows to go;
145
- 3. if the unfinished tasks alone still overflow, the tail of that list is
146
- truncated;
147
- 4. the last row becomes `+N more (X completed, Y pending)`.
142
+ 1. task rows of the tasks in progress;
143
+ 2. live run rows, all runs of one task together, with that task's row when it has
144
+ none yet; a task in progress whose runs do not fit keeps its row and shows
145
+ `· N runs`;
146
+ 3. the [Other workers](#other-workers) group, holding the live runs whose task got no row;
147
+ 4. open tasks with no live run;
148
+ 5. completed tasks with no live run, oldest first.
149
+
150
+ Rows keep their display order whatever their rank: the full view still draws the
151
+ tree, and the focus view its flat list. The focus view ranks only the tasks it
152
+ selects (in progress, the next open ones, and this turn's completed ones). In the
153
+ full view the last row becomes `+N more (X completed, Y in progress, Z pending)`,
154
+ leaving out zero counts.
155
+
156
+ Ranking run rows above open tasks keeps the workers under their todos, so the
157
+ panel can claim them and the Subagents widget lists only what is left.
158
+
159
+ ### Compact mode
160
+
161
+ When some live run would still get no row of its own, the panel switches to
162
+ compact mode for that frame. A task's runs then share the task's row, and the
163
+ Other workers group takes one row:
164
+
165
+ ```text
166
+ ● Todos (54/71)
167
+ ├─ ◐ #35 Final BitD UAT round for the boss
168
+ ├─ ◐ #55 S3 地圖 tab on core Table Maps, BitD map retired ⟶ coremaptab-ui · opus · 執行中 4m
169
+ ├─ ○ #57 S4 map ports + two-way claims ↔ turf sync
170
+ ├─ ◐ #56 F1 faction tracker storage (migration 198) ⟶ factionsdb-build · opus · 執行中 21m
171
+ ├─ ◐ #65 EP sheet: centering, morph grid, 更換義體, Select, pictures
172
+ ├─ ◐ #66 Site-wide: native selects → shared Select, then lint guard ⟶ selectsweep-ui · opus · 執行中 39m
173
+ ├─ ◐ #67 EP rules book: add Flexbot Confidential + Rules Primer; Flexbot … ⟶ epbooks-build · opus · 執行中 30m
174
+ ├─ ◐ #68 EP scenarios: 心智獵人, 小心WMD, 異噬, 超企業劫案, 奈米任務 ⟶ epscen-review · opus · 審查中 6m +2
175
+ ├─ ◐ #70 Table session: reading dialogs dock to the workspace pane, chat stays usable
176
+ ├─ 其他 worker ⟶ skald-scout · opus · 執行中 3m +1
177
+ └─ +62 項未顯示 (54 已完成, 8 待處理) · ctrl+shift+t 收合
178
+ ```
179
+
180
+ - After ` ⟶ ` comes the most active run (working, then waiting for a reply, then
181
+ other states, idle last; the host's order breaks ties), in the run row format,
182
+ then `+N` for the task's other live runs.
183
+ - A narrow row cuts the task part with `…` first, so the run stays whole.
184
+ - The ranks above still apply; runs simply cost no rows, and the group costs one.
185
+ A task with no live run keeps its plain row.
186
+ - A compact row painted in full claims every run it stands for, `+N` included,
187
+ through the same inline or screen check as a run row. A row cut into its run,
188
+ or with fewer than 12 columns left for the task, claims none.
189
+ - When every run fits on its own row, the panel keeps the two-row layout.
148
190
 
149
191
  In the full view, Pi's tool-output expansion shortcut (`ctrl+o` by default)
150
192
  expands the widget to show every task. Collapsing Pi's tool output reapplies the configured
151
- row budget. Unfinished work is therefore the last thing to disappear in the
152
- compact view. See [configuration.md](./configuration.md#maxwidgetlines) for the
193
+ row budget. Unfinished work is therefore the last thing to disappear under the
194
+ row budget. See [configuration.md](./configuration.md#maxwidgetlines) for the
153
195
  budget's floor and reload semantics.
154
196
 
155
197
  ## Completed tasks fading out
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-todo-ledger",
3
- "version": "0.8.0",
3
+ "version": "0.8.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",
@@ -60,41 +60,6 @@ export function selectTaskSubjectById(state: TaskState, id: number): string | un
60
60
  return state.tasks.find((t) => t.id === id)?.subject;
61
61
  }
62
62
 
63
- /**
64
- * Overlay layout decision. Encapsulates the "drop completed first, then
65
- * truncate non-completed tail" rule. `budget` is the body-slot count (caller passes
66
- * `getMaxWidgetLines() - 1` to reserve the heading row); on overflow the
67
- * selector reserves one more slot internally for the summary row. Returns
68
- * the visible task slice plus the overflow summary parts.
69
- */
70
- export interface OverlayLayout {
71
- visible: readonly Task[];
72
- hiddenCompleted: number;
73
- truncatedTail: number;
74
- }
75
- export function selectOverlayLayout(state: TaskState, budget: number): OverlayLayout {
76
- const all = selectVisibleTasks(state);
77
- if (all.length <= budget) {
78
- return { visible: all, hiddenCompleted: 0, truncatedTail: 0 };
79
- }
80
- const innerBudget = budget - 1;
81
- const nonCompleted = all.filter((t) => t.status !== "completed");
82
- const totalCompleted = all.length - nonCompleted.length;
83
- if (nonCompleted.length <= innerBudget) {
84
- const kept = new Set<Task>(nonCompleted);
85
- for (const t of all) {
86
- if (kept.size >= innerBudget) break;
87
- if (t.status === "completed") kept.add(t);
88
- }
89
- const visible = all.filter((t) => kept.has(t));
90
- const shownCompleted = visible.filter((t) => t.status === "completed").length;
91
- return { visible, hiddenCompleted: totalCompleted - shownCompleted, truncatedTail: 0 };
92
- }
93
- const visible = nonCompleted.slice(0, innerBudget);
94
- const truncatedTail = nonCompleted.length - innerBudget;
95
- return { visible, hiddenCompleted: totalCompleted, truncatedTail };
96
- }
97
-
98
63
  /**
99
64
  * Helper: whether any visible task is `pending` or `in_progress`. The overlay
100
65
  * uses this to pick the heading icon (`accent`+`●` vs `dim`+`○`).
@@ -31,9 +31,9 @@ import {
31
31
  import { formatStatusLabel, formatWorkerCount, t } from "./state/i18n-bridge.ts";
32
32
  import {
33
33
  selectHasActive,
34
- selectOverlayLayout,
35
34
  selectShowTaskIds,
36
35
  selectTodoCounts,
36
+ selectVisibleTasks,
37
37
  } from "./state/selectors.ts";
38
38
  import { getRenderState } from "./state/store.ts";
39
39
  import { formatPlanTaskLine } from "./view/format.ts";
@@ -41,7 +41,7 @@ import { type PlanRow, planView } from "./view/plan.ts";
41
41
  import type { Task } from "./tool/types.ts";
42
42
 
43
43
  import { history } from "./ledger/herdr-runs.ts";
44
- import { liveRows, runLine, type Query, type RunRow } from "./view/live-runs.ts";
44
+ import { liveRows, runLine, runState, type Query, type RunRow } from "./view/live-runs.ts";
45
45
 
46
46
  const WIDGET_KEY = "rpiv-todos";
47
47
 
@@ -72,6 +72,28 @@ interface Frame {
72
72
  /** Runs of the Other workers group that fit `rows`: the heading and at least one run, or none. */
73
73
  const groupFit = (rows: number, runs: number) => (runs > 0 && rows >= 2 ? Math.min(runs, rows - 1) : 0);
74
74
 
75
+ /** The rows one budget gives, decided by rank (see TodoOverlay.allot). */
76
+ interface Allotment {
77
+ /** Tasks that get a row, in display order. */
78
+ shown: Task[];
79
+ /** Shown tasks whose run rows are drawn; any other shown task with runs counts them on its row. */
80
+ withRuns: Set<Task>;
81
+ /** The Other workers group: live runs of this session whose task has no row. */
82
+ workers: RunRow[];
83
+ /** How many of `workers` get a row under the group heading. */
84
+ group: number;
85
+ /** Rows the budget leaves unused. */
86
+ left: number;
87
+ }
88
+
89
+ /** Narrowest left part (branch, glyph, id, start of the subject) a compact row keeps before its run. */
90
+ const COMPACT_MIN_LEFT = 12;
91
+
92
+ /** How a run ranks for the one spot on a compact row: working, then waiting for a reply, then the rest, idle last. */
93
+ const ACTIVITY: Record<string, number> = { running: 0, waiting: 1, idle: 3 };
94
+ const mostActive = (runs: readonly RunRow[]) =>
95
+ runs.reduce((best, r) => ((ACTIVITY[runState(r) ?? ""] ?? 2) < (ACTIVITY[runState(best) ?? ""] ?? 2) ? r : best));
96
+
75
97
  /** What one frame's row drawing needs, shared by the full and focus views. */
76
98
  interface DrawContext {
77
99
  theme: Theme;
@@ -85,6 +107,8 @@ interface DrawContext {
85
107
  showIds: boolean;
86
108
  now: number;
87
109
  evidence: "inline" | "screen" | undefined;
110
+ /** Compact mode: a task's runs, and the Other workers group, share one row with it (see budgeted). */
111
+ compact: boolean;
88
112
  }
89
113
 
90
114
  export class TodoOverlay {
@@ -408,6 +432,7 @@ export class TodoOverlay {
408
432
  showIds,
409
433
  now: Date.now(),
410
434
  evidence: this.evidence(),
435
+ compact: false,
411
436
  };
412
437
 
413
438
  // Collapsed view: just the heading + a dim "└─" hint naming the next state,
@@ -453,68 +478,40 @@ export class TodoOverlay {
453
478
  return this.withTrailingSpacer([heading, ...body]);
454
479
  }
455
480
 
456
- /** The whole dependency tree, budgeted by selectOverlayLayout (the `"full"` view), then the Other workers group. */
481
+ /** The whole dependency tree, budgeted by rank (see allot), then the Other workers group (the `"full"` view). */
457
482
  private fullBody(
458
483
  overlayState: { tasks: Task[]; nextId: number },
459
484
  plan: ReturnType<typeof planView>,
460
485
  bodyBudget: number,
461
486
  draw: DrawContext,
462
487
  ): string[] {
463
- const layout = selectOverlayLayout(overlayState, bodyBudget);
464
- const overflow = layout.hiddenCompleted + layout.truncatedTail;
465
- const hint = this.keyHint();
466
- draw.others = this.groupCandidates(layout.visible, draw);
467
- const others = draw.others.length;
468
- // With nothing to summarize, the hint takes its own row only when one is spare.
469
- const needed =
470
- layout.visible.reduce((n, task) => n + 1 + this.children(task, draw).length, 0) +
471
- (others ? 1 + others : 0);
472
- const hintRow = overflow === 0 && hint !== undefined && needed < bodyBudget;
473
- let spare = bodyBudget - layout.visible.length - Number(overflow > 0 || hintRow);
474
- // The group gets the rows the bound runs leave; a group cut short needs the summary row.
475
- let rest = spare - this.boundRows(layout.visible, spare, draw);
476
- let summarized = overflow > 0;
477
- let group = others;
478
- if (1 + others > rest) {
479
- if (!summarized && rest > 0) {
480
- summarized = true;
481
- rest--;
482
- }
483
- group = groupFit(rest, others);
484
- }
485
- spare -= group ? 1 + group : 0;
488
+ const all = [...selectVisibleTasks(overlayState)];
489
+ const { shown, summarized, hintRow, hint, others } = this.budgeted(all, all.length, bodyBudget, draw);
486
490
  const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
487
491
  const lines = this.drawTasks(
488
- layout.visible.map((task) => ({ task, row: plan.rows.get(task.id) })),
489
- spare,
490
- !summarized && !hintRow && !group,
492
+ shown.shown.map((task) => ({ task, row: plan.rows.get(task.id) })),
493
+ shown.withRuns,
494
+ !summarized && !hintRow && !shown.group,
491
495
  draw,
492
496
  frame,
493
497
  );
494
- lines.push(...this.drawGroup(draw.others.slice(0, group), !summarized && !hintRow, draw, frame));
498
+ lines.push(...this.drawGroup(draw.others.slice(0, shown.group), !summarized && !hintRow, draw, frame));
495
499
  this.endFrame(frame, draw);
496
500
  if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
497
501
  if (!summarized) return lines;
498
502
 
499
503
  const parts: string[] = [];
504
+ const isShown = new Set(shown.shown);
505
+ const hiddenBy = (status: string) => all.filter((task) => task.status === status && !isShown.has(task)).length;
506
+ const overflowParts = (["completed", "in_progress", "pending"] as const)
507
+ .map((status) => [hiddenBy(status), status] as const)
508
+ .filter(([n]) => n > 0);
509
+ const overflow = overflowParts.reduce((sum, [n]) => sum + n, 0);
500
510
  if (overflow > 0) {
501
- const overflowParts: string[] = [];
502
- if (layout.hiddenCompleted > 0)
503
- overflowParts.push(
504
- `${layout.hiddenCompleted} ${formatStatusLabel("completed")}`,
505
- );
506
- if (layout.truncatedTail > 0)
507
- overflowParts.push(
508
- `${layout.truncatedTail} ${formatStatusLabel("pending")}`,
509
- );
510
511
  const more = t("overlay.more", OVERLAY_MORE);
511
- parts.push(
512
- overflowParts.length > 0
513
- ? `+${overflow} ${more} (${overflowParts.join(", ")})`
514
- : `+${overflow} ${more}`,
515
- );
512
+ parts.push(`+${overflow} ${more} (${overflowParts.map(([n, status]) => `${n} ${formatStatusLabel(status)}`).join(", ")})`);
516
513
  }
517
- if (group < others) parts.push(`${parts.length ? "" : "+"}${formatWorkerCount(others - group)}`);
514
+ if (shown.group < others) parts.push(`${parts.length ? "" : "+"}${formatWorkerCount(others - shown.group)}`);
518
515
  lines.push(this.closingRow(draw, parts.join(t("overlay.separator", OVERLAY_SEPARATOR)), hint));
519
516
  return lines;
520
517
  }
@@ -522,9 +519,9 @@ export class TodoOverlay {
522
519
  /**
523
520
  * The focus view (default): in-progress tasks with their runs, the next open
524
521
  * tasks (two, or three when nothing is in progress), the Other workers group,
525
- * then this turn's completed rows if room is left, and one summary row counting
526
- * whatever is hidden. Completed rows are drawn before the group but get rows
527
- * after it. Rows are flat, so every unfinished blocker goes to the `⛓` tail.
522
+ * then this turn's completed rows, budgeted by rank (see allot), and one summary
523
+ * row counting whatever is hidden. Completed rows are drawn before the group.
524
+ * Rows are flat, so every unfinished blocker goes to the `⛓` tail.
528
525
  */
529
526
  private focusBody(
530
527
  overlayTasks: Task[],
@@ -537,33 +534,12 @@ export class TodoOverlay {
537
534
  const completed = overlayTasks.filter((t) => t.status === "completed");
538
535
  const next = pending.slice(0, inProgress.length ? 2 : 3);
539
536
  const total = inProgress.length + pending.length + completed.length;
540
-
541
- // Task rows first, in priority order; runs take the spare rows in display order;
542
- // the group and then completed rows get what is left. The summary row is reserved only when needed.
543
- const fit = (slots: number) => {
544
- const core = [...inProgress, ...next].slice(0, slots);
545
- let spare = slots - core.length - this.boundRows(core, slots - core.length, draw);
546
- const candidates = this.groupCandidates([...core, ...completed], draw);
547
- const initialGroup = groupFit(spare, candidates.length);
548
- const possibleDone = completed.slice(0, spare - (initialGroup ? 1 + initialGroup : 0));
549
- const workers = this.groupCandidates([...core, ...possibleDone], draw);
550
- const group = groupFit(spare, workers.length);
551
- spare -= group ? 1 + group : 0;
552
- const done = completed.slice(0, spare);
553
- const rows = core.length + done.length + (group ? 1 + group : 0);
554
- return { core, done, group, workers: this.groupCandidates([...core, ...done], draw), spare: slots - rows, left: spare - done.length };
555
- };
556
- let shown = fit(bodyBudget);
557
- const summarized =
558
- shown.core.length + shown.done.length < total || shown.group < shown.workers.length;
559
- if (summarized) shown = fit(bodyBudget - 1);
560
- draw.others = shown.workers;
561
- const others = shown.workers.length;
562
- // With nothing to summarize, the hint takes its own row only when one is spare;
563
- // one row less leaves the same layout then.
564
- const hint = this.keyHint();
565
- const hintRow = !summarized && hint !== undefined && shown.left > 0;
566
- if (hintRow) shown = { ...shown, spare: shown.spare - 1 };
537
+ const { shown, summarized, hintRow, hint, others } = this.budgeted(
538
+ [...inProgress, ...next, ...completed],
539
+ total,
540
+ bodyBudget,
541
+ draw,
542
+ );
567
543
 
568
544
  const openIds = new Set(plan.ordered.map((t) => t.id));
569
545
  const flat = (task: Task): PlanRow | undefined => {
@@ -578,8 +554,8 @@ export class TodoOverlay {
578
554
  };
579
555
  const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
580
556
  const lines = this.drawTasks(
581
- [...shown.core, ...shown.done].map((task) => ({ task, row: flat(task) })),
582
- shown.spare,
557
+ shown.shown.map((task) => ({ task, row: flat(task) })),
558
+ shown.withRuns,
583
559
  !summarized && !hintRow && !shown.group,
584
560
  draw,
585
561
  frame,
@@ -589,7 +565,7 @@ export class TodoOverlay {
589
565
  if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
590
566
  if (!summarized) return lines;
591
567
 
592
- const isShown = new Set([...shown.core, ...shown.done]);
568
+ const isShown = new Set(shown.shown);
593
569
  const hidden = (list: Task[]) => list.filter((t) => !isShown.has(t)).length;
594
570
  const parts = (
595
571
  [
@@ -617,14 +593,68 @@ export class TodoOverlay {
617
593
  return runs.flatMap((r) => draw.live?.get(r.id) ?? []);
618
594
  }
619
595
 
620
- /** Rows the tasks' runs take from `spare`, given in display order to each task whose runs all fit, as drawTasks does. */
621
- private boundRows(tasks: readonly Task[], spare: number, draw: DrawContext): number {
596
+ /**
597
+ * Give `slots` rows to the candidates (in display order) by rank:
598
+ * 1. in-progress task rows;
599
+ * 2. live run rows, all of one task's together, with that task's row when it has none yet;
600
+ * 3. the Other workers group, holding every live run whose task got no row;
601
+ * 4. open tasks without a live run;
602
+ * 5. completed tasks without a live run.
603
+ * A task with live runs that missed rank 2 gets no row, so its runs join the group.
604
+ * An in-progress task whose runs do not fit keeps its row and counts them.
605
+ * `compact`: runs take no rows of their own, and the group takes one row.
606
+ */
607
+ private allot(candidates: readonly Task[], slots: number, draw: DrawContext, compact: boolean): Allotment {
608
+ const chosen = new Set<Task>();
609
+ const withRuns = new Set<Task>();
622
610
  let used = 0;
623
- for (const task of tasks) {
624
- const n = this.children(task, draw).length;
625
- if (used + n <= spare) used += n;
611
+ const take = (rows: number) => {
612
+ if (used + rows > slots) return false;
613
+ used += rows;
614
+ return true;
615
+ };
616
+ for (const task of candidates) if (task.status === "in_progress" && take(1)) chosen.add(task);
617
+ for (const task of candidates) {
618
+ const runs = this.children(task, draw).length;
619
+ if (runs && take((compact ? 0 : runs) + Number(!chosen.has(task)))) {
620
+ chosen.add(task);
621
+ withRuns.add(task);
622
+ }
626
623
  }
627
- return used;
624
+ const workers = this.groupCandidates([...chosen], draw);
625
+ const group = compact ? (workers.length && take(1) ? workers.length : 0) : groupFit(slots - used, workers.length);
626
+ if (!compact) used += group ? 1 + group : 0;
627
+ for (const done of [false, true])
628
+ for (const task of candidates)
629
+ if ((task.status === "completed") === done && !chosen.has(task) && !this.children(task, draw).length && take(1))
630
+ chosen.add(task);
631
+ return { shown: candidates.filter((task) => chosen.has(task)), withRuns, workers, group, left: slots - used };
632
+ }
633
+
634
+ /**
635
+ * The allotment for `budget` rows, keeping one for the summary when anything of
636
+ * `total` tasks or the group is left out. With nothing to summarize, the hint takes
637
+ * its own row only when one is spare. When some live run would get no row of its
638
+ * own, the panel switches to compact mode (each run joins its task's row, the group
639
+ * takes one row). Sets `draw.others` to the group and `draw.compact`.
640
+ */
641
+ private budgeted(candidates: readonly Task[], total: number, budget: number, draw: DrawContext) {
642
+ const cut = (a: Allotment) => a.shown.length < total || a.group < a.workers.length;
643
+ const fit = (compact: boolean) => {
644
+ const first = this.allot(candidates, budget, draw, compact);
645
+ return cut(first)
646
+ ? { shown: this.allot(candidates, budget - 1, draw, compact), summarized: true }
647
+ : { shown: first, summarized: false };
648
+ };
649
+ let { shown, summarized } = fit(false);
650
+ draw.compact =
651
+ shown.group < shown.workers.length ||
652
+ shown.shown.some((task) => this.children(task, draw).length > 0 && !shown.withRuns.has(task));
653
+ if (draw.compact) ({ shown, summarized } = fit(true));
654
+ draw.others = shown.workers;
655
+ const hint = this.keyHint();
656
+ const hintRow = !summarized && hint !== undefined && shown.left > 0;
657
+ return { shown, summarized, hintRow, hint, others: shown.workers.length };
628
658
  }
629
659
 
630
660
  /** End the frame's claim bookkeeping; a group folded into the summary keeps the tick so its count stays current. */
@@ -651,6 +681,37 @@ export class TodoOverlay {
651
681
  }
652
682
  }
653
683
 
684
+ /**
685
+ * A compact row: `left` (a task row or the group heading), then ` ⟶ ` and the most
686
+ * active of `runs`, then `+N` for the others. The left part is cut first, so the run
687
+ * stays whole. A row shown in full claims every run it stands for; one cut into the
688
+ * run, or with no room for the left part, carries no marker and claims none.
689
+ * In the group (`group`), a run of a hidden task carries its task number.
690
+ */
691
+ private drawCompact(lines: string[], left: string, runs: RunRow[], draw: DrawContext, frame: Frame, group = false) {
692
+ const { theme, width, truncate, now, evidence } = draw;
693
+ const lead = mostActive(runs);
694
+ const owner = draw.runOwners.get(lead.id);
695
+ const right =
696
+ theme.fg("dim", " ⟶ ") +
697
+ (group && owner !== undefined ? `#${owner} ` : "") +
698
+ runLine(lead, now, (color, text) => theme.fg(color, text)) +
699
+ (runs.length > 1 ? theme.fg("dim", ` +${runs.length - 1}`) : "");
700
+ const room = width - visibleWidth(right);
701
+ const roomy = visibleWidth(left) <= room || room >= COMPACT_MIN_LEFT;
702
+ const line = roomy ? truncateToWidth(left, Math.max(room, 0), "…") + right : truncate(left + right);
703
+ const whole = roomy && visibleWidth(line) <= width;
704
+ frame.ticking = true;
705
+ if (whole && evidence === "screen") {
706
+ const marked = line + this.marker(lead.id);
707
+ for (const r of runs) frame.marked.set(r.id, marked);
708
+ lines.push(marked);
709
+ } else {
710
+ lines.push(truncate(line));
711
+ if (whole && evidence === "inline") frame.drawn.push(...runs.map((r) => r.id));
712
+ }
713
+ }
714
+
654
715
  /**
655
716
  * The Other workers group: a heading row, then this session's runs bound to no
656
717
  * task, drawn and claimed like bound run rows. `closed` means it ends the panel.
@@ -658,22 +719,26 @@ export class TodoOverlay {
658
719
  private drawGroup(runs: RunRow[], closed: boolean, draw: DrawContext, frame: Frame): string[] {
659
720
  if (!runs.length) return [];
660
721
  const { theme, truncate } = draw;
661
- const lines = [
662
- truncate(`${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted", t("overlay.others", OVERLAY_OTHERS))}`),
663
- ];
722
+ const heading = `${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted", t("overlay.others", OVERLAY_OTHERS))}`;
723
+ if (draw.compact) {
724
+ const lines: string[] = [];
725
+ this.drawCompact(lines, heading, runs, draw, frame, true);
726
+ return lines;
727
+ }
728
+ const lines = [truncate(heading)];
664
729
  for (const [j, r] of runs.entries())
665
730
  this.drawRun(lines, r, `${closed ? " " : "│"} ${j === runs.length - 1 ? "└" : "├"} ${draw.runOwners.has(r.id) ? `#${draw.runOwners.get(r.id)} ` : ''}`, draw, frame);
666
731
  return lines;
667
732
  }
668
733
 
669
734
  /**
670
- * Draw task rows and, where `spare` rows remain, their run rows; a task whose
671
- * runs do not fit shows `· N runs`. `closed` means nothing follows, so the last
735
+ * Draw task rows and, for the tasks in `withRuns`, their run rows; any other task
736
+ * with live runs shows `· N runs`. `closed` means nothing follows, so the last
672
737
  * task row takes `└─`.
673
738
  */
674
739
  private drawTasks(
675
740
  entries: { task: Task; row?: PlanRow }[],
676
- spare: number,
741
+ withRuns: ReadonlySet<Task>,
677
742
  closed: boolean,
678
743
  draw: DrawContext,
679
744
  frame: Frame,
@@ -683,7 +748,7 @@ export class TodoOverlay {
683
748
  for (const [i, { task, row }] of entries.entries()) {
684
749
  const { older } = draw.bound.get(task.id) ?? history(undefined);
685
750
  const children = this.children(task, draw);
686
- const fits = children.length <= spare;
751
+ const fits = !children.length || withRuns.has(task);
687
752
  const last = closed && i === entries.length - 1;
688
753
  const display =
689
754
  fits && children.some((r) => r.name === task.owner)
@@ -692,13 +757,13 @@ export class TodoOverlay {
692
757
  const count = !fits
693
758
  ? ` · ${children.length} ${t("run.count", "runs")}`
694
759
  : "";
695
- lines.push(
696
- truncate(
697
- `${theme.fg("dim", last ? "└─" : "├─")} ${formatPlanTaskLine(display, theme, showIds, row)}${count}${older && live ? ` +${older}` : ""}`,
698
- ),
699
- );
760
+ const taskLine = `${theme.fg("dim", last ? "└─" : "├─")} ${formatPlanTaskLine(display, theme, showIds, row)}${count}${older && live ? ` +${older}` : ""}`;
761
+ if (fits && children.length && draw.compact) {
762
+ this.drawCompact(lines, taskLine, children, draw, frame);
763
+ continue;
764
+ }
765
+ lines.push(truncate(taskLine));
700
766
  if (!fits) continue;
701
- spare -= children.length;
702
767
  const indent = " ".repeat(row?.depth ?? 0);
703
768
  for (const [j, r] of children.entries())
704
769
  this.drawRun(lines, r, `${last ? " " : "│"} ${indent}${j === children.length - 1 ? "└" : "├"} `, draw, frame);
package/src/todo.ts CHANGED
@@ -56,20 +56,13 @@ export { TOOL_NAME } from "./tool/types.ts";
56
56
  // Tool registration
57
57
  // ---------------------------------------------------------------------------
58
58
 
59
- export const DEFAULT_PROMPT_SNIPPET = "Manage a task list to track multi-step progress";
59
+ export const DEFAULT_PROMPT_SNIPPET = "Track multi-step work in a task list";
60
60
  export const DEFAULT_PROMPT_GUIDELINES: string[] = [
61
- "Use `todo` for complex work with 3+ steps, when the user gives you a list of tasks, or immediately after receiving new instructions to capture requirements. Skip it for single trivial tasks and purely conversational requests.",
62
- "When starting a task from the todo list, mark it in_progress BEFORE beginning work. Mark it completed IMMEDIATELY when done — never batch completions. Exactly one task in_progress at a time.",
63
- "Never mark a task completed if tests are failing, the implementation is partial, or you hit unresolved errors — keep it in_progress and create a new task for the blocker instead.",
64
- "Task status is a 4-state machine: pending → in_progress → completed, plus deleted as a tombstone. Pass activeForm (present-continuous label, e.g. 'researching existing tool') when marking in_progress.",
65
- 'To change a task\'s status, call update with the task id and the target status, e.g. {"action":"update","id":3,"status":"completed"} or {"action":"update","id":3,"status":"in_progress","activeForm":"writing tests"}. status is the field that changes the task; an update without a mutable field (status or another) is rejected.',
66
- "Use blockedBy to express dependencies (A is blocked by B). On create, pass blockedBy as the initial set. On update, use addBlockedBy / removeBlockedBy (additive merge — do not resend the full array). Cycles are rejected.",
67
- "To create several independent tasks at once, pass create with tasks: [{subject}, ...]. Do not also pass subject. tasks[] cannot blockedBy each other (ids do not exist until the call commits); create the prerequisite first, then the dependent with blockedBy. Dependency chains stay single-create.",
68
- "Use import with a snapshot file path, or session (an earlier session's id), to restore a handed-over list into an empty session list.",
69
- "list hides tombstoned (deleted) tasks by default; pass includeDeleted:true to see them. Pass status to filter by a single status.",
70
- "Subject must be short and imperative (e.g. 'Research existing tool'); description is for long-form detail. activeForm is a present-continuous label shown while in_progress.",
71
- "Optional bookkeeping fields: points (effort, 0 to 10), anchor (the check that shows the task is done, e.g. a test command), and evidence (runs of checks, each {command, sha?, result: pass|fail, at?}). On update, points and anchor replace; evidence is appended, never replaced.",
72
- "When a task waits on something outside your control (a person, CI, a train, a release window), mark it with waitsOn (what it waits on) and, if known, until (ISO time); it shows ⏸ and reminders leave it alone while it waits. To end a wait early, clear every field you set (waitsOn: null, until: null), since an until left in place keeps the task waiting; completing the task clears both.",
61
+ "Use todo for work with 3+ steps, a user task list, or immediately on new instructions to capture requirements. Skip single trivial tasks and conversation.",
62
+ "Mark one task in_progress before starting (with activeForm); mark it completed immediately when done, never in batches. With failing tests, partial work or unresolved errors, keep it in_progress and create a blocker task.",
63
+ "Set status with update and id: pending → in_progress → completed; deleted is a tombstone. update needs a mutable field.",
64
+ "For dependencies, create prerequisites first, then dependents with blockedBy. Update via addBlockedBy/removeBlockedBy, not a full set; cycles are rejected.",
65
+ "On external waits (person, CI, train, release window), set waitsOn and, if known, until. End a wait early with waitsOn: null and until: null for the fields you set; a future until still holds the wait.",
73
66
  ];
74
67
 
75
68
  export function registerTodoTool(pi: ExtensionAPI, finish: FinishCall): void {
@@ -77,8 +70,7 @@ export function registerTodoTool(pi: ExtensionAPI, finish: FinishCall): void {
77
70
  pi.registerTool({
78
71
  name: TOOL_NAME,
79
72
  label: TOOL_LABEL,
80
- description:
81
- "Manage a task list for tracking multi-step progress. Actions: create (new task, or several independent tasks at once via tasks[]), update (change status/fields/dependencies), list (all tasks, optionally filtered by status), get (single task details), delete (tombstone), clear (reset all), import (restore a snapshot file into an empty list). Status: pending → in_progress → completed, plus deleted tombstone. Use this to plan and track multi-step work like research, design, and implementation.",
73
+ description: "Track a plan and its progress: create, update, list, get, delete (tombstone), clear (reset all), or import a handoff into an empty list.",
82
74
  promptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,
83
75
  promptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,
84
76
  parameters: TodoParamsSchema,
package/src/tool/types.ts CHANGED
@@ -151,135 +151,57 @@ export interface TaskMutationParams {
151
151
  }
152
152
 
153
153
  // ---------------------------------------------------------------------------
154
- // TypeBox parameter schema — every `description` doubles as LLM-facing prompt
155
- // copy. Field order and wording are pinned by registration tests.
154
+ // TypeBox parameter schema. Descriptions are prompt text: document shared
155
+ // fields once, on the top-level property rather than in each batch item.
156
156
  // ---------------------------------------------------------------------------
157
157
 
158
- const PointsSchema = (description: string) =>
159
- Type.Number({ minimum: POINTS_MIN, maximum: POINTS_MAX, description });
160
-
161
- const AnchorSchema = (description: string) => Type.String({ minLength: 1, description });
162
-
163
- const EvidenceInputSchema = Type.Object({
164
- ref: Type.Optional(Type.String({ minLength: 1, maxLength: 64, pattern: "^\\S*$", description: "Run or child:<id>" })),
165
- command: Type.String({ minLength: 1, description: "The check that ran, e.g. 'npm test -- replay'" }),
166
- sha: Type.Optional(Type.String({ description: "Revision the check ran on, e.g. a git commit SHA" })),
167
- result: StringEnum(["pass", "fail"] as const, { description: "How the run ended" }),
168
- at: Type.Optional(Type.String({ description: "ISO 8601 time of the run. Default: now" })),
169
- });
170
-
171
- const EvidenceSchema = (description: string) => Type.Array(EvidenceInputSchema, { description });
172
-
173
- const WAITS_ON_TEXT =
174
- "What this task waits on (a person, CI, a train to end); it shows ⏸, and close and stale reminders leave the task alone while it waits. Completing or deleting the task clears it; to end a wait early, clear both waitsOn and until";
175
- const UNTIL_TEXT = "ISO 8601 time the task waits until, e.g. 2027-01-15T09:00:00+08:00; once it passes, an until-only wait ends";
158
+ const PointsSchema = Type.Number({ minimum: POINTS_MIN, maximum: POINTS_MAX });
159
+ const AnchorSchema = Type.String({ minLength: 1 });
160
+ const EvidenceSchema = Type.Array(Type.Object({
161
+ ref: Type.Optional(Type.String({ minLength: 1, maxLength: 64, pattern: "^\\S*$" })),
162
+ command: Type.String({ minLength: 1 }),
163
+ sha: Type.Optional(Type.String()),
164
+ result: StringEnum(["pass", "fail"] as const),
165
+ at: Type.Optional(Type.String()),
166
+ }));
176
167
 
177
168
  const CreateTaskInputSchema = Type.Object({
178
- subject: Type.String({ description: "Task subject line" }),
179
- description: Type.Optional(Type.String({ description: "Long-form task description" })),
180
- activeForm: Type.Optional(
181
- Type.String({
182
- description: "Present-continuous spinner label shown while status is in_progress (e.g. 'writing tests')",
183
- }),
184
- ),
185
- blockedBy: Type.Optional(
186
- Type.Array(Type.Number(), {
187
- description:
188
- "Existing task ids this item waits on. Cannot name another item in this same batch; create the prerequisite first, then the dependent with blockedBy.",
189
- }),
190
- ),
191
- owner: Type.Optional(Type.String({ description: "Agent/owner assigned to this task" })),
192
- metadata: Type.Optional(
193
- Type.Record(Type.String(), Type.Unknown(), {
194
- description: "Arbitrary metadata",
195
- }),
196
- ),
197
- points: Type.Optional(PointsSchema("Effort points, 0 to 10")),
198
- anchor: Type.Optional(AnchorSchema("The check that shows this task is done, e.g. a test command")),
169
+ subject: Type.String(),
170
+ description: Type.Optional(Type.String()),
171
+ activeForm: Type.Optional(Type.String()),
172
+ blockedBy: Type.Optional(Type.Array(Type.Number())),
173
+ owner: Type.Optional(Type.String()),
174
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
175
+ points: Type.Optional(PointsSchema),
176
+ anchor: Type.Optional(AnchorSchema),
199
177
  graph: Type.Optional(Type.String()),
200
- evidence: Type.Optional(EvidenceSchema("Check runs already recorded for this task")),
201
- waitsOn: Type.Optional(Type.String({ minLength: 1, description: WAITS_ON_TEXT })),
202
- until: Type.Optional(Type.String({ description: UNTIL_TEXT })),
178
+ evidence: Type.Optional(EvidenceSchema),
179
+ waitsOn: Type.Optional(Type.String({ minLength: 1 })),
180
+ until: Type.Optional(Type.String()),
203
181
  });
204
182
 
205
183
  export const TodoParamsSchema = Type.Object({
206
184
  action: StringEnum(["create", "update", "list", "get", "delete", "clear", "import"] as const),
207
- path: Type.Optional(Type.String({ description: "Snapshot file (import only); relative to the session cwd" })),
208
- session: Type.Optional(Type.String({ description: "Or a session id, id prefix, or .jsonl (import only)" })),
209
- subject: Type.Optional(
210
- Type.String({
211
- description: "Task subject line (required for create unless tasks[] is set)",
212
- }),
213
- ),
214
- description: Type.Optional(Type.String({ description: "Long-form task description" })),
215
- activeForm: Type.Optional(
216
- Type.String({
217
- description: "Present-continuous spinner label shown while status is in_progress (e.g. 'writing tests')",
218
- }),
219
- ),
220
- status: Type.Optional(
221
- StringEnum(["pending", "in_progress", "completed", "deleted"] as const, {
222
- description:
223
- "Set this task's status (update): one of pending, in_progress, completed, deleted. When action is list, filters returned tasks by this status.",
224
- }),
225
- ),
226
- blockedBy: Type.Optional(
227
- Type.Array(Type.Number(), {
228
- description: "Initial blockedBy ids (create only)",
229
- }),
230
- ),
231
- addBlockedBy: Type.Optional(
232
- Type.Array(Type.Number(), {
233
- description: "Task ids to add to blockedBy (update only, additive merge)",
234
- }),
235
- ),
236
- removeBlockedBy: Type.Optional(
237
- Type.Array(Type.Number(), {
238
- description: "Task ids to remove from blockedBy (update only, additive merge)",
239
- }),
240
- ),
241
- owner: Type.Optional(Type.String({ description: "Agent/owner assigned to this task" })),
242
- metadata: Type.Optional(
243
- Type.Record(Type.String(), Type.Unknown(), {
244
- description: "Arbitrary metadata; pass null value for a key to delete that key on update",
245
- }),
246
- ),
247
- points: Type.Optional(PointsSchema("Effort points, 0 to 10 (create or update; update replaces)")),
248
- anchor: Type.Optional(
249
- AnchorSchema(
250
- "The check that shows this task is done, e.g. a test command (create or update; update replaces)",
251
- ),
252
- ),
253
- graph: Type.Optional(
254
- Type.Union([Type.String(), Type.Null()], {
255
- description: "single-loop, fan-out/fan-in, or orchestrator-worker; null clears",
256
- }),
257
- ),
258
- evidence: Type.Optional(
259
- EvidenceSchema(
260
- "Check runs to record: the initial list on create; on update, appended to the task's evidence (never replaced or removed)",
261
- ),
262
- ),
263
- waitsOn: Type.Optional(
264
- Type.Union([Type.String({ minLength: 1 }), Type.Null()], { description: `${WAITS_ON_TEXT}; null clears (update)` }),
265
- ),
266
- until: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: `${UNTIL_TEXT}; null clears (update)` })),
267
- id: Type.Optional(
268
- Type.Number({
269
- description: "Task id (required for update, get, delete)",
270
- }),
271
- ),
272
- includeDeleted: Type.Optional(
273
- Type.Boolean({
274
- description: "If true, list action returns deleted (tombstoned) tasks as well. Default: false.",
275
- }),
276
- ),
277
- tasks: Type.Optional(
278
- Type.Array(CreateTaskInputSchema, {
279
- description:
280
- "Batch create: independent tasks in one call, one-of with subject. The whole list is validated then committed together. Items cannot blockedBy each other; create the prerequisite first, then the dependent with blockedBy.",
281
- }),
282
- ),
185
+ path: Type.Optional(Type.String({ description: "Import snapshot, cwd-relative." })),
186
+ session: Type.Optional(Type.String({ description: "Import alternative: session ID, unique prefix or .jsonl." })),
187
+ subject: Type.Optional(Type.String({ description: "Short imperative title (create, unless tasks is set)." })),
188
+ description: Type.Optional(Type.String({ description: "Long-form detail." })),
189
+ activeForm: Type.Optional(Type.String({ description: "Present-continuous in_progress label, e.g. 'writing tests'." })),
190
+ status: Type.Optional(StringEnum(["pending", "in_progress", "completed", "deleted"] as const, { description: "Set on update; filter on list." })),
191
+ blockedBy: Type.Optional(Type.Array(Type.Number(), { description: "Existing prerequisite IDs (create)." })),
192
+ addBlockedBy: Type.Optional(Type.Array(Type.Number(), { description: "Update: add prerequisite IDs." })),
193
+ removeBlockedBy: Type.Optional(Type.Array(Type.Number(), { description: "Update: drop prerequisite IDs." })),
194
+ owner: Type.Optional(Type.String()),
195
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Update: null drops that key." })),
196
+ points: Type.Optional({ ...PointsSchema, description: "Effort; update replaces." }),
197
+ anchor: Type.Optional({ ...AnchorSchema, description: "Completion check, e.g. test command; update replaces." }),
198
+ graph: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "single-loop, fan-out/fan-in or orchestrator-worker; null clears." })),
199
+ evidence: Type.Optional({ ...EvidenceSchema, description: "Check runs: update only appends. ref: run or child:<id>; sha: tested revision; at: ISO 8601 (default now)." }),
200
+ waitsOn: Type.Optional(Type.Union([Type.String({ minLength: 1 }), Type.Null()], { description: "What is pending. Wait shows ⏸, suppresses close/stale reminders; complete/delete clears it. null clears on update." })),
201
+ until: Type.Optional(Type.Union([Type.String(), Type.Null()], { description: "ISO 8601 deadline; an until-only wait ends then. null clears on update." })),
202
+ id: Type.Optional(Type.Number({ description: "Required for update/get/delete." })),
203
+ includeDeleted: Type.Optional(Type.Boolean({ description: "list: include tombstones (default false)." })),
204
+ tasks: Type.Optional(Type.Array(CreateTaskInputSchema, { description: "Atomic batch create instead of subject; same fields, no dependencies within the batch." })),
283
205
  });
284
206
 
285
207
  export type TodoParams = Static<typeof TodoParamsSchema>;