pi-todo-ledger 0.8.2 → 0.10.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/CONTRACT.md +38 -2
- package/README.md +2 -0
- package/docs/overlay.md +51 -6
- package/package.json +1 -1
- package/src/index.ts +35 -6
- package/src/ledger/finish-call.ts +22 -1
- package/src/ledger/herdr-owner.ts +2 -2
- package/src/ledger/herdr-runs.ts +20 -0
- package/src/ledger/herdr-spend.ts +133 -0
- package/src/ledger/spend.ts +103 -0
- package/src/locales/zh-TW.json +4 -0
- package/src/state/replay.ts +14 -0
- package/src/state/session-lock.ts +5 -0
- package/src/todo-overlay.ts +122 -151
- package/src/tool/response-envelope.ts +3 -0
- package/src/view/allot.ts +178 -0
- package/src/view/sb-rows.ts +144 -0
package/src/state/replay.ts
CHANGED
|
@@ -90,3 +90,17 @@ export function replayFromBranch(ctx: { sessionManager: { getBranch(): Iterable<
|
|
|
90
90
|
fromV1 ?? fromLegacyEntries ?? fromToolResults ?? { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId }
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The list the session's live branch holds now, as `replayFromBranch` reads it, from its newest valid `todo/v1` snapshot when there is one (a walk back from the
|
|
96
|
+
* leaf, which validates that one snapshot only). A writer that must commit onto the branch pi is on at this moment reads this, not the live slot: pi moves the leaf
|
|
97
|
+
* before its `session_tree` handlers replay the slot.
|
|
98
|
+
*/
|
|
99
|
+
export function listOnBranch(ctx: { sessionManager: { getBranch(): Iterable<unknown> } }): TaskState {
|
|
100
|
+
const branch = Array.from(ctx.sessionManager.getBranch());
|
|
101
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
102
|
+
const e = branch[i] as { type?: string; customType?: string; data?: unknown };
|
|
103
|
+
if (e?.type === "custom" && e.customType === SNAPSHOT_ENTRY_TYPE && isSnapshotV1(e.data)) return stateOf(e.data);
|
|
104
|
+
}
|
|
105
|
+
return replayFromBranch({ sessionManager: { getBranch: () => branch } });
|
|
106
|
+
}
|
|
@@ -21,3 +21,8 @@ export function withSessionLock<T>(sessionId: string, fn: () => Promise<T>): Pro
|
|
|
21
21
|
});
|
|
22
22
|
return run;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
/** Whether a call of the session is running or queued: a synchronous writer must queue behind it, else the call commits a list read before the write. */
|
|
26
|
+
export function sessionBusy(sessionId: string): boolean {
|
|
27
|
+
return tails.has(sessionId);
|
|
28
|
+
}
|
package/src/todo-overlay.ts
CHANGED
|
@@ -41,7 +41,9 @@ 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,
|
|
44
|
+
import { liveRows, runLine, type Query, type RunRow } from "./view/live-runs.ts";
|
|
45
|
+
import { attribute, budget, children, type Group, type Live, mostActive, type RowsContext, runsOf } from "./view/allot.ts";
|
|
46
|
+
import { askLine, askRows, carLine, carRows, type SbQuery } from "./view/sb-rows.ts";
|
|
45
47
|
|
|
46
48
|
const WIDGET_KEY = "rpiv-todos";
|
|
47
49
|
|
|
@@ -51,7 +53,6 @@ const OVERLAY_MORE = "more";
|
|
|
51
53
|
const OVERLAY_KEY_HINT = "{key} {next}";
|
|
52
54
|
const OVERLAY_COLLAPSED = "collapsed";
|
|
53
55
|
const OVERLAY_SEPARATOR = ", ";
|
|
54
|
-
const OVERLAY_OTHERS = "Other workers";
|
|
55
56
|
|
|
56
57
|
/** What the panel shows: one of the two views, or the two-line collapsed state. */
|
|
57
58
|
type PanelState = OverlayView | "collapsed";
|
|
@@ -69,41 +70,18 @@ interface Frame {
|
|
|
69
70
|
ticking: boolean;
|
|
70
71
|
}
|
|
71
72
|
|
|
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
|
-
|
|
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
73
|
/** Narrowest left part (branch, glyph, id, start of the subject) a compact row keeps before its run. */
|
|
90
74
|
const COMPACT_MIN_LEFT = 12;
|
|
91
75
|
|
|
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
|
-
|
|
97
76
|
/** What one frame's row drawing needs, shared by the full and focus views. */
|
|
98
|
-
interface DrawContext {
|
|
77
|
+
interface DrawContext extends RowsContext {
|
|
99
78
|
theme: Theme;
|
|
100
79
|
width: number;
|
|
101
80
|
truncate: (line: string) => string;
|
|
102
|
-
bound: Map<number, ReturnType<typeof history>>;
|
|
103
|
-
live: ReturnType<typeof liveRows>;
|
|
104
81
|
/** Live runs of this session bound to no task on the panel, in the host's order. */
|
|
105
82
|
others: RunRow[];
|
|
106
|
-
|
|
83
|
+
/** The groups of the frame, as the allotment gave them rows. */
|
|
84
|
+
groups: { group: Group; n: number }[];
|
|
107
85
|
showIds: boolean;
|
|
108
86
|
now: number;
|
|
109
87
|
evidence: "inline" | "screen" | undefined;
|
|
@@ -111,6 +89,26 @@ interface DrawContext {
|
|
|
111
89
|
compact: boolean;
|
|
112
90
|
}
|
|
113
91
|
|
|
92
|
+
/** A live row's words: a run as the host's row, a car as sb words it, an ask with its question. `grouped`: under the asks' heading. */
|
|
93
|
+
function liveText(l: Live, draw: DrawContext, grouped: boolean): string {
|
|
94
|
+
const fg = (color: Parameters<Theme["fg"]>[0], text: string) => draw.theme.fg(color, text);
|
|
95
|
+
if (l.kind === "run") return runLine(l.run, draw.now, fg);
|
|
96
|
+
return l.kind === "car" ? carLine(l.car, draw.now, fg) : askLine(l.ask, draw.now, fg, grouped);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** `2 waiting on you`, as the collapsed panel and the summary count the asks. */
|
|
100
|
+
const askCount = (n: number) => t("overlay.asks.count", "{n} waiting on you").replace("{n}", String(n));
|
|
101
|
+
|
|
102
|
+
/** What each group leaves out, for the summary row: workers, asks, or cars by their group. */
|
|
103
|
+
function groupsLeft(groups: readonly { group: Group; n: number }[]): string[] {
|
|
104
|
+
return groups
|
|
105
|
+
.filter(({ group, n }) => n < group.rows.length)
|
|
106
|
+
.map(({ group, n }) => {
|
|
107
|
+
const k = group.rows.length - n;
|
|
108
|
+
return group.kind === "run" ? formatWorkerCount(k) : group.kind === "ask" ? `⏸ ${askCount(k)}` : `${k} ${group.title}`;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
114
112
|
export class TodoOverlay {
|
|
115
113
|
private uiCtx: ExtensionUIContext | undefined;
|
|
116
114
|
private widgetRegistered = false;
|
|
@@ -130,8 +128,10 @@ export class TodoOverlay {
|
|
|
130
128
|
private readonly nonce = Math.random().toString(36).slice(2, 10);
|
|
131
129
|
private tick?: ReturnType<typeof setInterval>;
|
|
132
130
|
private query?: Query;
|
|
133
|
-
|
|
131
|
+
private sb?: SbQuery;
|
|
132
|
+
constructor(query?: Query, sb?: SbQuery) {
|
|
134
133
|
this.query = query;
|
|
134
|
+
this.sb = sb;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
private sendClaim(ids: string[]) {
|
|
@@ -252,8 +252,8 @@ export class TodoOverlay {
|
|
|
252
252
|
const snapshot = this.getSnapshot();
|
|
253
253
|
const visible = this.selectOverlayTasks(snapshot);
|
|
254
254
|
|
|
255
|
-
// With no task to show, the panel stays for this session's runs (the Other workers group).
|
|
256
|
-
if (visible.length === 0 && !liveRows(this.query)?.size) {
|
|
255
|
+
// With no task to show, the panel stays for this session's runs (the Other workers group), cars and asks.
|
|
256
|
+
if (visible.length === 0 && !liveRows(this.query)?.size && !carRows(this.sb).rows.length && !askRows(this.sb).rows.length) {
|
|
257
257
|
this.finishFrame([]);
|
|
258
258
|
if (this.widgetRegistered) {
|
|
259
259
|
this.uiCtx.setWidget(WIDGET_KEY, undefined);
|
|
@@ -387,7 +387,9 @@ export class TodoOverlay {
|
|
|
387
387
|
const overlayTasks = this.selectOverlayTasks(snapshot);
|
|
388
388
|
// Every state asks the host: runs bound to no task join the Other workers group, or its count.
|
|
389
389
|
const live = liveRows(this.query);
|
|
390
|
-
|
|
390
|
+
const cars = carRows(this.sb);
|
|
391
|
+
const asks = askRows(this.sb);
|
|
392
|
+
if (overlayTasks.length === 0 && !live?.size && !cars.rows.length && !asks.rows.length) {
|
|
391
393
|
this.finishFrame([]);
|
|
392
394
|
return [];
|
|
393
395
|
}
|
|
@@ -409,7 +411,8 @@ export class TodoOverlay {
|
|
|
409
411
|
truncateToWidth(line, width, "…");
|
|
410
412
|
const counts = selectTodoCounts(overlayState);
|
|
411
413
|
const hasActive = selectHasActive(overlayState);
|
|
412
|
-
const
|
|
414
|
+
const owners = attribute(overlayTasks, cars, asks);
|
|
415
|
+
const showIds = (hasRuns && !!live?.size) || owners.size > 0 || selectShowTaskIds(overlayState);
|
|
413
416
|
|
|
414
417
|
const headingColor = hasActive ? "accent" : "dim";
|
|
415
418
|
const headingIcon = hasActive ? "●" : "○";
|
|
@@ -427,8 +430,12 @@ export class TodoOverlay {
|
|
|
427
430
|
truncate,
|
|
428
431
|
bound,
|
|
429
432
|
live,
|
|
433
|
+
cars: cars.rows,
|
|
434
|
+
asks,
|
|
430
435
|
others,
|
|
436
|
+
groups: [],
|
|
431
437
|
runOwners: new Map([...bound].flatMap(([id, h]) => h.runs.map(r => [r.id, id] as const))),
|
|
438
|
+
owners,
|
|
432
439
|
showIds,
|
|
433
440
|
now: Date.now(),
|
|
434
441
|
evidence: this.evidence(),
|
|
@@ -444,9 +451,13 @@ export class TodoOverlay {
|
|
|
444
451
|
// collapsed) — render a static collapsed label instead of advertising an
|
|
445
452
|
// unbound key. Nothing is claimed; the tick keeps the count current.
|
|
446
453
|
if (this.current() === "collapsed") {
|
|
447
|
-
this.finishFrame([], others.length > 0);
|
|
454
|
+
this.finishFrame([], others.length > 0 || asks.rows.length > 0);
|
|
448
455
|
const hint = this.keyHint() ?? t("overlay.collapsed", OVERLAY_COLLAPSED);
|
|
449
|
-
const
|
|
456
|
+
const counts = [
|
|
457
|
+
others.length ? `+${formatWorkerCount(others.length)}` : "",
|
|
458
|
+
asks.rows.length ? `⏸ ${askCount(asks.rows.length)}` : "",
|
|
459
|
+
].filter(Boolean);
|
|
460
|
+
const count = counts.length ? counts.join(t("overlay.separator", OVERLAY_SEPARATOR)) : undefined;
|
|
450
461
|
return this.withTrailingSpacer([heading, this.closingRow(draw, count, hint)]);
|
|
451
462
|
}
|
|
452
463
|
|
|
@@ -478,7 +489,7 @@ export class TodoOverlay {
|
|
|
478
489
|
return this.withTrailingSpacer([heading, ...body]);
|
|
479
490
|
}
|
|
480
491
|
|
|
481
|
-
/** The whole dependency tree, budgeted by rank (see allot), then the
|
|
492
|
+
/** The whole dependency tree, budgeted by rank (see view/allot.ts), then the groups (the `"full"` view). */
|
|
482
493
|
private fullBody(
|
|
483
494
|
overlayState: { tasks: Task[]; nextId: number },
|
|
484
495
|
plan: ReturnType<typeof planView>,
|
|
@@ -486,16 +497,16 @@ export class TodoOverlay {
|
|
|
486
497
|
draw: DrawContext,
|
|
487
498
|
): string[] {
|
|
488
499
|
const all = [...selectVisibleTasks(overlayState)];
|
|
489
|
-
const { shown, summarized, hintRow, hint
|
|
500
|
+
const { shown, summarized, hintRow, hint } = this.budgeted(all, all.length, bodyBudget, draw);
|
|
490
501
|
const frame: Frame = { drawn: [], marked: new Map(), ticking: false };
|
|
491
502
|
const lines = this.drawTasks(
|
|
492
503
|
shown.shown.map((task) => ({ task, row: plan.rows.get(task.id) })),
|
|
493
504
|
shown.withRuns,
|
|
494
|
-
!summarized && !hintRow && !shown.
|
|
505
|
+
!summarized && !hintRow && !shown.groups.some((g) => g.n),
|
|
495
506
|
draw,
|
|
496
507
|
frame,
|
|
497
508
|
);
|
|
498
|
-
lines.push(...this.
|
|
509
|
+
lines.push(...this.drawGroups(shown.groups, !summarized && !hintRow, draw, frame));
|
|
499
510
|
this.endFrame(frame, draw);
|
|
500
511
|
if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
|
|
501
512
|
if (!summarized) return lines;
|
|
@@ -511,16 +522,16 @@ export class TodoOverlay {
|
|
|
511
522
|
const more = t("overlay.more", OVERLAY_MORE);
|
|
512
523
|
parts.push(`+${overflow} ${more} (${overflowParts.map(([n, status]) => `${n} ${formatStatusLabel(status)}`).join(", ")})`);
|
|
513
524
|
}
|
|
514
|
-
|
|
525
|
+
for (const left of groupsLeft(shown.groups)) parts.push(`${parts.length ? "" : "+"}${left}`);
|
|
515
526
|
lines.push(this.closingRow(draw, parts.join(t("overlay.separator", OVERLAY_SEPARATOR)), hint));
|
|
516
527
|
return lines;
|
|
517
528
|
}
|
|
518
529
|
|
|
519
530
|
/**
|
|
520
531
|
* The focus view (default): in-progress tasks with their runs, the next open
|
|
521
|
-
* tasks (two, or three when nothing is in progress), the
|
|
522
|
-
*
|
|
523
|
-
*
|
|
532
|
+
* tasks (two, or three when nothing is in progress), the groups, then this
|
|
533
|
+
* turn's completed rows, budgeted by rank (see view/allot.ts), and one summary row
|
|
534
|
+
* counting whatever is hidden. Completed rows are drawn before the groups.
|
|
524
535
|
* Rows are flat, so every unfinished blocker goes to the `⛓` tail.
|
|
525
536
|
*/
|
|
526
537
|
private focusBody(
|
|
@@ -534,7 +545,7 @@ export class TodoOverlay {
|
|
|
534
545
|
const completed = overlayTasks.filter((t) => t.status === "completed");
|
|
535
546
|
const next = pending.slice(0, inProgress.length ? 2 : 3);
|
|
536
547
|
const total = inProgress.length + pending.length + completed.length;
|
|
537
|
-
const { shown, summarized, hintRow, hint
|
|
548
|
+
const { shown, summarized, hintRow, hint } = this.budgeted(
|
|
538
549
|
[...inProgress, ...next, ...completed],
|
|
539
550
|
total,
|
|
540
551
|
bodyBudget,
|
|
@@ -556,11 +567,11 @@ export class TodoOverlay {
|
|
|
556
567
|
const lines = this.drawTasks(
|
|
557
568
|
shown.shown.map((task) => ({ task, row: flat(task) })),
|
|
558
569
|
shown.withRuns,
|
|
559
|
-
!summarized && !hintRow && !shown.
|
|
570
|
+
!summarized && !hintRow && !shown.groups.some((g) => g.n),
|
|
560
571
|
draw,
|
|
561
572
|
frame,
|
|
562
573
|
);
|
|
563
|
-
lines.push(...this.
|
|
574
|
+
lines.push(...this.drawGroups(shown.groups, !summarized && !hintRow, draw, frame));
|
|
564
575
|
this.endFrame(frame, draw);
|
|
565
576
|
if (hintRow) lines.push(this.closingRow(draw, undefined, hint));
|
|
566
577
|
if (!summarized) return lines;
|
|
@@ -576,90 +587,28 @@ export class TodoOverlay {
|
|
|
576
587
|
)
|
|
577
588
|
.filter(([n]) => n > 0)
|
|
578
589
|
.map(([n, status]) => `${n} ${formatStatusLabel(status)}`);
|
|
579
|
-
|
|
590
|
+
parts.push(...groupsLeft(shown.groups));
|
|
580
591
|
const summary = `+${parts.join(t("overlay.separator", OVERLAY_SEPARATOR))}`;
|
|
581
592
|
lines.push(this.closingRow(draw, summary, hint));
|
|
582
593
|
return lines;
|
|
583
594
|
}
|
|
584
595
|
|
|
585
|
-
private groupCandidates(visible: readonly Task[], draw: DrawContext): RunRow[] {
|
|
586
|
-
const ids = new Set(visible.map(task => task.id));
|
|
587
|
-
return [...(draw.live?.values() ?? [])].filter(run => !ids.has(draw.runOwners.get(run.id) ?? -1));
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/** Live run rows bound to a task (empty when the host gave no rows). */
|
|
591
|
-
private children(task: Task, draw: DrawContext): RunRow[] {
|
|
592
|
-
const { runs } = draw.bound.get(task.id) ?? history(undefined);
|
|
593
|
-
return runs.flatMap((r) => draw.live?.get(r.id) ?? []);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
596
|
/**
|
|
597
|
-
*
|
|
598
|
-
*
|
|
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.
|
|
597
|
+
* The allotment for `budget` rows (see `budget` in view/allot.ts). With nothing to summarize, the hint takes its own
|
|
598
|
+
* row only when one is spare. Sets `draw.groups` and `draw.compact`.
|
|
606
599
|
*/
|
|
607
|
-
private
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
}
|
|
623
|
-
}
|
|
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;
|
|
600
|
+
private budgeted(candidates: readonly Task[], total: number, rows: number, draw: DrawContext) {
|
|
601
|
+
const { shown, summarized, compact } = budget(candidates, total, rows, draw);
|
|
602
|
+
draw.compact = compact;
|
|
603
|
+
draw.groups = shown.groups;
|
|
655
604
|
const hint = this.keyHint();
|
|
656
605
|
const hintRow = !summarized && hint !== undefined && shown.left > 0;
|
|
657
|
-
return { shown, summarized, hintRow, hint
|
|
606
|
+
return { shown, summarized, hintRow, hint };
|
|
658
607
|
}
|
|
659
608
|
|
|
660
609
|
/** End the frame's claim bookkeeping; a group folded into the summary keeps the tick so its count stays current. */
|
|
661
610
|
private endFrame(frame: Frame, draw: DrawContext) {
|
|
662
|
-
this.finishFrame(frame.drawn, frame.ticking || draw.
|
|
611
|
+
this.finishFrame(frame.drawn, frame.ticking || draw.groups.length > 0, frame.marked);
|
|
663
612
|
}
|
|
664
613
|
|
|
665
614
|
/**
|
|
@@ -681,29 +630,41 @@ export class TodoOverlay {
|
|
|
681
630
|
}
|
|
682
631
|
}
|
|
683
632
|
|
|
633
|
+
/** One live row under the dim tree branch: a run as drawRun draws it, a car or an ask as sb words it. `grouped`: under the asks' heading. */
|
|
634
|
+
private drawLive(lines: string[], l: Live, branch: string, draw: DrawContext, frame: Frame, grouped = false) {
|
|
635
|
+
if (l.kind === "run") return this.drawRun(lines, l.run, branch, draw, frame);
|
|
636
|
+
frame.ticking = true;
|
|
637
|
+
lines.push(draw.truncate(draw.theme.fg("dim", branch) + liveText(l, draw, grouped)));
|
|
638
|
+
}
|
|
639
|
+
|
|
684
640
|
/**
|
|
685
|
-
* A compact row: `left` (a task row or
|
|
686
|
-
*
|
|
687
|
-
* stays whole. A row shown in full claims every run it stands for; one cut into
|
|
688
|
-
*
|
|
689
|
-
* In
|
|
641
|
+
* A compact row: `left` (a task row or a group heading), then ` ⟶ ` and the live row
|
|
642
|
+
* that most wants attention, then `+N` for the others. The left part is cut first, so the
|
|
643
|
+
* live row stays whole. A row shown in full claims every run it stands for; one cut into
|
|
644
|
+
* the live row, or with no room for the left part, carries no marker and claims none.
|
|
645
|
+
* In a group (`group`), a row of a hidden task carries its task number.
|
|
690
646
|
*/
|
|
691
|
-
private drawCompact(lines: string[], left: string,
|
|
692
|
-
const { theme, width, truncate,
|
|
693
|
-
const lead = mostActive(
|
|
694
|
-
const owner = draw.runOwners.get(lead.id);
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
647
|
+
private drawCompact(lines: string[], left: string, rows: Live[], draw: DrawContext, frame: Frame, group?: Group) {
|
|
648
|
+
const { theme, width, truncate, evidence } = draw;
|
|
649
|
+
const lead = mostActive(rows);
|
|
650
|
+
const owner = lead.kind === "run" ? draw.runOwners.get(lead.run.id) : draw.owners.get(lead.key);
|
|
651
|
+
const head = theme.fg("dim", " ⟶ ") + (group && owner !== undefined ? `#${owner} ` : "");
|
|
652
|
+
const tail = rows.length > 1 ? theme.fg("dim", ` +${rows.length - 1}`) : "";
|
|
653
|
+
// sb's words can run long (a question, a return's reason): only they are cut, never the `+N` that stands for the runs
|
|
654
|
+
// the row claims (carrows-review-F002). A run row is short and stays whole to be claimed. With no room even for the
|
|
655
|
+
// count, nothing is cut here: the row is then cut whole below, and claims nothing.
|
|
656
|
+
let text = liveText(lead, draw, group?.kind === "ask");
|
|
657
|
+
const textRoom = width - COMPACT_MIN_LEFT - visibleWidth(head) - visibleWidth(tail);
|
|
658
|
+
if (lead.kind !== "run" && textRoom > 0 && visibleWidth(text) > textRoom) text = truncateToWidth(text, textRoom, "…");
|
|
659
|
+
const right = head + text + tail;
|
|
700
660
|
const room = width - visibleWidth(right);
|
|
701
661
|
const roomy = visibleWidth(left) <= room || room >= COMPACT_MIN_LEFT;
|
|
702
662
|
const line = roomy ? truncateToWidth(left, Math.max(room, 0), "…") + right : truncate(left + right);
|
|
703
663
|
const whole = roomy && visibleWidth(line) <= width;
|
|
664
|
+
const runs = runsOf(rows);
|
|
704
665
|
frame.ticking = true;
|
|
705
|
-
if (whole && evidence === "screen") {
|
|
706
|
-
const marked = line + this.marker(lead.
|
|
666
|
+
if (whole && runs.length && evidence === "screen") {
|
|
667
|
+
const marked = line + this.marker(lead.key);
|
|
707
668
|
for (const r of runs) frame.marked.set(r.id, marked);
|
|
708
669
|
lines.push(marked);
|
|
709
670
|
} else {
|
|
@@ -712,27 +673,36 @@ export class TodoOverlay {
|
|
|
712
673
|
}
|
|
713
674
|
}
|
|
714
675
|
|
|
676
|
+
/** The groups that got rows, each a heading then its rows; `closed` means the last one ends the panel. */
|
|
677
|
+
private drawGroups(groups: { group: Group; n: number }[], closed: boolean, draw: DrawContext, frame: Frame): string[] {
|
|
678
|
+
const drawn = groups.filter((g) => g.n > 0);
|
|
679
|
+
return drawn.flatMap(({ group, n }, i) => this.drawGroup(group, n, closed && i === drawn.length - 1, draw, frame));
|
|
680
|
+
}
|
|
681
|
+
|
|
715
682
|
/**
|
|
716
|
-
*
|
|
717
|
-
*
|
|
683
|
+
* A group: a heading row, then its first `n` rows, runs drawn and claimed like bound run rows, and a row of a todo
|
|
684
|
+
* that has no row with that todo's number. `closed` means it ends the panel.
|
|
718
685
|
*/
|
|
719
|
-
private drawGroup(
|
|
720
|
-
if (!runs.length) return [];
|
|
686
|
+
private drawGroup(group: Group, n: number, closed: boolean, draw: DrawContext, frame: Frame): string[] {
|
|
721
687
|
const { theme, truncate } = draw;
|
|
722
|
-
const heading = `${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted",
|
|
688
|
+
const heading = `${theme.fg("dim", closed ? "└─" : "├─")} ${theme.fg("muted", group.title)}`;
|
|
723
689
|
if (draw.compact) {
|
|
724
690
|
const lines: string[] = [];
|
|
725
|
-
this.drawCompact(lines, heading,
|
|
691
|
+
this.drawCompact(lines, heading, group.rows, draw, frame, group);
|
|
726
692
|
return lines;
|
|
727
693
|
}
|
|
728
694
|
const lines = [truncate(heading)];
|
|
729
|
-
|
|
730
|
-
|
|
695
|
+
const rows = group.rows.slice(0, n);
|
|
696
|
+
for (const [j, l] of rows.entries()) {
|
|
697
|
+
const owner = l.kind === "run" ? draw.runOwners.get(l.run.id) : draw.owners.get(l.key);
|
|
698
|
+
const branch = `${closed ? " " : "│"} ${j === rows.length - 1 ? "└" : "├"} ${owner !== undefined ? `#${owner} ` : ""}`;
|
|
699
|
+
this.drawLive(lines, l, branch, draw, frame, group.kind === "ask");
|
|
700
|
+
}
|
|
731
701
|
return lines;
|
|
732
702
|
}
|
|
733
703
|
|
|
734
704
|
/**
|
|
735
|
-
* Draw task rows and, for the tasks in `withRuns`, their
|
|
705
|
+
* Draw task rows and, for the tasks in `withRuns`, their live rows; any other task
|
|
736
706
|
* with live runs shows `· N runs`. `closed` means nothing follows, so the last
|
|
737
707
|
* task row takes `└─`.
|
|
738
708
|
*/
|
|
@@ -747,26 +717,27 @@ export class TodoOverlay {
|
|
|
747
717
|
const lines: string[] = [];
|
|
748
718
|
for (const [i, { task, row }] of entries.entries()) {
|
|
749
719
|
const { older } = draw.bound.get(task.id) ?? history(undefined);
|
|
750
|
-
const
|
|
751
|
-
const
|
|
720
|
+
const rows = children(task, draw);
|
|
721
|
+
const runs = runsOf(rows);
|
|
722
|
+
const fits = !rows.length || withRuns.has(task);
|
|
752
723
|
const last = closed && i === entries.length - 1;
|
|
753
724
|
const display =
|
|
754
|
-
fits &&
|
|
725
|
+
fits && runs.some((r) => r.name === task.owner)
|
|
755
726
|
? { ...task, owner: undefined }
|
|
756
727
|
: task;
|
|
757
|
-
const count = !fits
|
|
758
|
-
? ` · ${
|
|
728
|
+
const count = !fits && runs.length
|
|
729
|
+
? ` · ${runs.length} ${t("run.count", "runs")}`
|
|
759
730
|
: "";
|
|
760
731
|
const taskLine = `${theme.fg("dim", last ? "└─" : "├─")} ${formatPlanTaskLine(display, theme, showIds, row)}${count}${older && live ? ` +${older}` : ""}`;
|
|
761
|
-
if (fits &&
|
|
762
|
-
this.drawCompact(lines, taskLine,
|
|
732
|
+
if (fits && rows.length && draw.compact) {
|
|
733
|
+
this.drawCompact(lines, taskLine, rows, draw, frame);
|
|
763
734
|
continue;
|
|
764
735
|
}
|
|
765
736
|
lines.push(truncate(taskLine));
|
|
766
737
|
if (!fits) continue;
|
|
767
738
|
const indent = " ".repeat(row?.depth ?? 0);
|
|
768
|
-
for (const [j,
|
|
769
|
-
this.
|
|
739
|
+
for (const [j, l] of rows.entries())
|
|
740
|
+
this.drawLive(lines, l, `${last ? " " : "│"} ${indent}${j === rows.length - 1 ? "└" : "├"} `, draw, frame);
|
|
770
741
|
}
|
|
771
742
|
return lines;
|
|
772
743
|
}
|
|
@@ -2,6 +2,7 @@ import type { TaskState } from "../state/state.ts";
|
|
|
2
2
|
import type { Op } from "../state/state-reducer.ts";
|
|
3
3
|
import { deriveBlocks } from "../state/task-graph.ts";
|
|
4
4
|
import { isOpen, resultSuffix } from "../view/task-labels.ts";
|
|
5
|
+
import { spendLine } from "../ledger/spend.ts";
|
|
5
6
|
import { sanitizeTerminalText } from "./sanitize.ts";
|
|
6
7
|
import type { Task, TaskAction, TaskDetails, TaskMutationParams } from "./types.ts";
|
|
7
8
|
|
|
@@ -60,6 +61,8 @@ function formatGetLines(task: Task, state: TaskState): string {
|
|
|
60
61
|
if (task.points !== undefined) lines.push(` points: ${task.points}`);
|
|
61
62
|
if (task.anchor) lines.push(` anchor: ${sanitizeTerminalText(task.anchor)}`);
|
|
62
63
|
if (task.graph) lines.push(` graph: ${task.graph}`);
|
|
64
|
+
const spend = spendLine((task.metadata?.herdr as { spend?: unknown } | undefined)?.spend);
|
|
65
|
+
if (spend) lines.push(` spend: ${spend}`);
|
|
63
66
|
for (const e of task.evidence ?? []) {
|
|
64
67
|
const sha = e.sha ? ` @${sanitizeTerminalText(e.sha)}` : "";
|
|
65
68
|
lines.push(` evidence: ${e.result} ${sanitizeTerminalText(e.command)}${sha} (${sanitizeTerminalText(e.at)})`);
|