@ftrdotdev/pi-tracker 0.5.1 → 0.6.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/src/index.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
2
3
  import { Text } from "@earendil-works/pi-tui";
3
4
  import { makeBorderedBox } from "@ftrdotdev/pi-tui";
5
+ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
4
6
  import { Effect, Layer, ManagedRuntime, Option, Result } from "effect";
7
+ import { join } from "node:path";
8
+ import { ClassifierGateway } from "./compaction/classifier.ts";
9
+ import { CompletionObserver } from "./compaction/completion.ts";
5
10
  import {
6
11
  formatItemRef,
7
12
  parseItemRef,
8
13
  type DependencyItem,
9
14
  type DependencyListView,
10
- } from "./deps.ts";
11
- import { TodoItem, TodoList, TrackerState, emptyState, encodeState } from "./domain.ts";
12
- import { TrackerPersistence } from "./persistence.ts";
13
- import { TrackerError, TrackerStore, type ItemSpec, type UpdateItemPatch } from "./store.ts";
15
+ } from "./core/deps.ts";
16
+ import { TodoItem, TodoList, TrackerState, emptyState, encodeState } from "./core/domain.ts";
17
+ import { TrackerPersistence } from "./core/persistence.ts";
18
+ import { SMART_COMPACTION_CUSTOM_TYPE } from "./compaction/pointer.ts";
19
+ import { SMART_COMPACTION_CONFIG_FILE, SmartCompactionSettingsService } from "./compaction/settings.ts";
20
+ import { SettleDecider } from "./compaction/settle.ts";
21
+ import { TrackerError, TrackerStore, type ItemSpec, type UpdateItemPatch } from "./core/store.ts";
14
22
  import {
15
23
  TRACKER_TOOL_METADATA,
16
24
  blockedDoneNote,
@@ -19,14 +27,14 @@ import {
19
27
  type TrackerToolAction,
20
28
  type TrackerToolDetails,
21
29
  type TrackerToolParams,
22
- } from "./tool-metadata.ts";
30
+ } from "./presentation/tool-metadata.ts";
23
31
  import {
24
32
  displayList,
25
33
  makeTrackerOverlay,
26
34
  makeTrackerWidget,
27
35
  readinessSuffix,
28
36
  type TrackerUiAction,
29
- } from "./ui.ts";
37
+ } from "./presentation/ui.ts";
30
38
 
31
39
  /** Custom-entry type used to persist the tracker state in the session. */
32
40
  const CUSTOM_TYPE = "tracker/state";
@@ -47,6 +55,14 @@ const withPersistence = <A, E>(
47
55
  f: (persistence: TrackerPersistence["Service"]) => Effect.Effect<A, E>,
48
56
  ): Effect.Effect<A, E, TrackerPersistence> => Effect.flatMap(TrackerPersistence, f);
49
57
 
58
+ const withCompletionObserver = <A, E>(
59
+ f: (observer: CompletionObserver["Service"]) => Effect.Effect<A, E>,
60
+ ): Effect.Effect<A, E, CompletionObserver> => Effect.flatMap(CompletionObserver, f);
61
+
62
+ const withSettleDecider = <A, E>(
63
+ f: (decider: SettleDecider["Service"]) => Effect.Effect<A, E>,
64
+ ): Effect.Effect<A, E, SettleDecider> => Effect.flatMap(SettleDecider, f);
65
+
50
66
  /** Throw for a missing required tool parameter; caught in `execute`. */
51
67
  const requireParam = <T>(value: T | undefined, name: string): T => {
52
68
  if (value === undefined) throw new Error(`${name} is required for this tracker action`);
@@ -71,11 +87,21 @@ const toItemSpecs = (raw: NonNullable<TrackerToolParams["text"]>): ItemSpec[] =>
71
87
  // --------------------------------------------------------------------------
72
88
 
73
89
  export default function (pi: ExtensionAPI): void {
90
+ // The settings path is resolved inside the factory, so a test can point
91
+ // ENV_AGENT_DIR at a temp directory before `tracker(api)` runs.
92
+ const decisionServices = Layer.mergeAll(
93
+ CompletionObserver.layer,
94
+ ClassifierGateway.layer,
95
+ SmartCompactionSettingsService.make(join(getAgentDir(), SMART_COMPACTION_CONFIG_FILE)),
96
+ );
97
+
74
98
  const runtime = ManagedRuntime.make(
75
- TrackerStore.layer.pipe(
99
+ SettleDecider.layer.pipe(
100
+ Layer.provideMerge(Layer.mergeAll(TrackerStore.layer, decisionServices)),
76
101
  Layer.provideMerge(
77
102
  TrackerPersistence.layer((encoded) => pi.appendEntry(CUSTOM_TYPE, encoded)),
78
103
  ),
104
+ Layer.provide(NodeFileSystem.layer),
79
105
  ),
80
106
  );
81
107
 
@@ -183,6 +209,12 @@ export default function (pi: ExtensionAPI): void {
183
209
  const applyMutation = (ctx: ExtensionContext): Promise<TrackerState> =>
184
210
  enqueue(async () => {
185
211
  const next = await runtime.runPromise(withStore((store) => store.state));
212
+ // Record the transition before the mirror moves, so the observer sees the
213
+ // true pre-mutation state. Every mutation runs this, so a later mutation
214
+ // that completes nothing still refreshes the live snapshot.
215
+ await runtime.runPromise(
216
+ withCompletionObserver((observer) => observer.record(state, next)),
217
+ );
186
218
  state = next;
187
219
  await runtime.runPromise(
188
220
  withPersistence((p) => p.save(next)).pipe(
@@ -265,6 +297,58 @@ export default function (pi: ExtensionAPI): void {
265
297
  await runtime.dispose();
266
298
  });
267
299
 
300
+ // --- Smart compaction ---------------------------------------------------
301
+
302
+ /**
303
+ * Pi rethrows the provider's abort error on cancellation, so the error text
304
+ * is not a reliable signal. `session_compact_failed` fires first and carries
305
+ * the fact.
306
+ */
307
+ let compactionAborted = false;
308
+ pi.on("session_compact_failed", (event) => {
309
+ compactionAborted = event.aborted;
310
+ });
311
+
312
+ pi.on("agent_before_settle", async (event, ctx) => {
313
+ const decision = await runtime.runPromise(
314
+ withSettleDecider((decider) =>
315
+ decider.decide({
316
+ registry: ctx.modelRegistry,
317
+ outcome: event.outcome,
318
+ signal: ctx.signal,
319
+ }),
320
+ ),
321
+ );
322
+ if (decision.kind !== "compact") return;
323
+ // The run signal can fire after the verdict, while the classifier is the
324
+ // last thing between here and compaction. An abort keeps the context.
325
+ if (ctx.signal?.aborted) return;
326
+ const pointer = decision.pointer;
327
+ // Delivery comes from pi's completion contract, which fires only after
328
+ // compaction has finished. `deliver` is idempotent, so a double callback
329
+ // cannot start two turns.
330
+ let resumed = false;
331
+ const deliver = () => {
332
+ if (resumed) return;
333
+ resumed = true;
334
+ pi.sendMessage(
335
+ { customType: SMART_COMPACTION_CUSTOM_TYPE, content: pointer, display: true },
336
+ { triggerTurn: true },
337
+ );
338
+ };
339
+ compactionAborted = false;
340
+ ctx.compact({
341
+ onComplete: () => deliver(),
342
+ onError: (error) => {
343
+ // Compaction failed, but the run already stopped and the context is
344
+ // intact, so the pointer still resumes the work. A user cancellation
345
+ // is different: nothing is resumed.
346
+ ctx.ui.notify(`tracker: smart compaction failed: ${error.message}`, "warning");
347
+ if (!compactionAborted) deliver();
348
+ },
349
+ });
350
+ });
351
+
268
352
  // --- Tool ---------------------------------------------------------------
269
353
 
270
354
  /**
@@ -513,7 +597,8 @@ export default function (pi: ExtensionAPI): void {
513
597
  // Args can come from failed validation too, so read them loosely.
514
598
  const raw = args as unknown as Record<string, unknown>;
515
599
  const action = String(raw.action ?? "list");
516
- let text = theme.fg("toolTitle", theme.bold("tracker ")) + theme.fg("muted", action);
600
+ let text =
601
+ theme.style("tracker ", { fg: "toolTitle", bold: true }) + theme.fg("muted", action);
517
602
  if (typeof raw.name === "string") text += ` ${theme.fg("dim", `"${raw.name}"`)}`;
518
603
  if (typeof raw.text === "string") {
519
604
  text += ` ${theme.fg("dim", `"${raw.text}"`)}`;
@@ -619,6 +704,7 @@ export default function (pi: ExtensionAPI): void {
619
704
  render: (width) => framed.render(width),
620
705
  invalidate: () => framed.invalidate(),
621
706
  handleInput: (data) => overlay.handleInput(data),
707
+ handleMouse: (event) => overlay.handleMouse(event),
622
708
  };
623
709
  });
624
710
  },
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { Value } from "typebox/value";
3
- import { TodoItem, TodoList, TrackerState, emptyState } from "./domain.ts";
3
+ import { TodoItem, TodoList, TrackerState, emptyState } from "../core/domain.ts";
4
4
  import {
5
5
  TOOL_ACTIONS,
6
6
  TRACKER_TOOL_METADATA,
@@ -6,9 +6,9 @@
6
6
  import { StringEnum } from "@earendil-works/pi-ai";
7
7
  import { Type } from "typebox";
8
8
  import type { Static } from "typebox";
9
- import { dependentsOf, formatItemRef, parseItemRef, unsatisfiedDeps } from "./deps.ts";
10
- import type { TodoItem, TodoList, TrackerState } from "./domain.ts";
11
- import type { EncodedState } from "./persistence.ts";
9
+ import { dependentsOf, formatItemRef, parseItemRef, unsatisfiedDeps } from "../core/deps.ts";
10
+ import type { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
11
+ import type { EncodedState } from "../core/persistence.ts";
12
12
 
13
13
  /** Tracker tool actions, in the same order as the store operations. */
14
14
  export const TOOL_ACTIONS = [
@@ -1,8 +1,8 @@
1
1
  import { assert, it } from "@effect/vitest";
2
2
  import type { Theme } from "@earendil-works/pi-coding-agent";
3
3
  import { visibleWidth } from "@earendil-works/pi-tui";
4
- import { orderedItems } from "./deps.ts";
5
- import { TodoItem, TodoList, TrackerState } from "./domain.ts";
4
+ import { orderedItems } from "../core/deps.ts";
5
+ import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
6
6
  import {
7
7
  makeTrackerOverlay,
8
8
  makeTrackerWidget,
@@ -16,12 +16,13 @@ import {
16
16
  /**
17
17
  * Identity theme: styles pass text through unchanged, so render output is
18
18
  * plain text that assertions can search. The overlay and widget only use
19
- * `fg`, `bold` and `strikethrough`, which this stub covers.
19
+ * `fg`, `bold`, `strikethrough` and `style`, which this stub covers.
20
20
  */
21
21
  const identityTheme = {
22
22
  fg: (_color: string, text: string): string => text,
23
23
  bold: (text: string): string => text,
24
24
  strikethrough: (text: string): string => text,
25
+ style: (text: string): string => text,
25
26
  } as unknown as Theme;
26
27
 
27
28
  /** A realistic two-list state: Work is the active list. */
@@ -465,3 +466,67 @@ it("annotates a done item whose dependency is open again in the overlay", () =>
465
466
  assert.match(text, /\(waiting on #Work:1\)/);
466
467
  notContain(text, "blocked by");
467
468
  });
469
+
470
+ it("paints the selected overlay row with the selection background", () => {
471
+ // Marker theme: `style()` records the background token so the test can see
472
+ // the selection paint without a real terminal theme.
473
+ const markerTheme = {
474
+ ...identityTheme,
475
+ style: (text: string, options: { bg?: string }) =>
476
+ options.bg === undefined ? text : `[${options.bg}]${text}[/${options.bg}]`,
477
+ } as unknown as Theme;
478
+ const overlay = makeTrackerOverlay({
479
+ getState: () => twoListState(),
480
+ theme: markerTheme,
481
+ requestRender: () => {},
482
+ onAction: async () => null,
483
+ onClose: () => {},
484
+ });
485
+ // The lists pane opens with the first list selected, so its row carries the
486
+ // background and unselected rows do not.
487
+ const lines = overlay.render(80);
488
+ assert.strictEqual(lines.filter((line) => line.includes("[selectedBg]")).length, 1);
489
+ });
490
+
491
+ /** Overlay with a recording clipboard, so copy tests never touch the OS. */
492
+ const makeCopyOverlay = (): { overlay: TrackerOverlayHandle; copied: string[] } => {
493
+ const copied: string[] = [];
494
+ const overlay = makeTrackerOverlay({
495
+ getState: () => twoListState(),
496
+ theme: identityTheme,
497
+ requestRender: () => {},
498
+ onAction: async () => null,
499
+ onClose: () => {},
500
+ copyText: async (text) => {
501
+ copied.push(text);
502
+ },
503
+ });
504
+ return { overlay, copied };
505
+ };
506
+
507
+ it("copies the selected list and reports it (c in the lists pane)", async () => {
508
+ const { overlay, copied } = makeCopyOverlay();
509
+ overlay.handleInput("c");
510
+ await flushAsync();
511
+ assert.deepStrictEqual(copied, ["Work"]);
512
+ assert.ok(overlay.render(80).some((line) => line.includes("Copied")));
513
+ });
514
+
515
+ it("copies the selected item reference and text (c in the items pane)", async () => {
516
+ const { overlay, copied } = makeCopyOverlay();
517
+ overlay.handleInput("\t"); // switch to the items pane
518
+ overlay.handleInput("c");
519
+ await flushAsync();
520
+ assert.strictEqual(copied.length, 1);
521
+ assert.match(copied[0]!, /^Work:\d+ /);
522
+ });
523
+
524
+ it("moves the selection on wheel events", () => {
525
+ const h = makeOverlay(twoListState());
526
+ assert.ok(h.overlay.render(80).join("\n").includes("→ ● Work"));
527
+ h.overlay.handleMouse({
528
+ type: "wheel",
529
+ wheelDelta: 1,
530
+ } as Parameters<TrackerOverlayHandle["handleMouse"]>[0]);
531
+ assert.ok(h.overlay.render(80).join("\n").includes("→ Home"));
532
+ });
@@ -1,6 +1,12 @@
1
- import type { Theme } from "@earendil-works/pi-coding-agent";
1
+ import { copyToClipboard, type Theme } from "@earendil-works/pi-coding-agent";
2
2
  import type { Component } from "@earendil-works/pi-tui";
3
- import { Key, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
3
+ import {
4
+ Key,
5
+ matchesKey,
6
+ truncateToWidth,
7
+ visibleWidth,
8
+ type TuiMouseEvent,
9
+ } from "@earendil-works/pi-tui";
4
10
  import { makeBorderedBox } from "@ftrdotdev/pi-tui";
5
11
  import {
6
12
  firstReadyIndex,
@@ -9,9 +15,9 @@ import {
9
15
  type DependencyItem,
10
16
  type DependencyList,
11
17
  type DependencyListView,
12
- } from "./deps.ts";
13
- import type { TodoItem, TodoList, TrackerState } from "./domain.ts";
14
- import type { UpdateItemPatch } from "./store.ts";
18
+ } from "../core/deps.ts";
19
+ import type { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
20
+ import type { UpdateItemPatch } from "../core/store.ts";
15
21
 
16
22
  const MAX_LISTS = 8;
17
23
  const MAX_ITEMS = 12;
@@ -22,6 +28,9 @@ const MARKER_WIDTH = 2;
22
28
  const clamp = (value: number, min: number, max: number): number =>
23
29
  Math.min(Math.max(value, min), max);
24
30
 
31
+ /** Positive modulo, so a wheel step past either end wraps. */
32
+ const wrap = (value: number, count: number): number => ((value % count) + count) % count;
33
+
25
34
  // --------------------------------------------------------------------------
26
35
  // Widget pane (ctx.ui.setWidget)
27
36
  // --------------------------------------------------------------------------
@@ -36,7 +45,8 @@ const widgetLabel =
36
45
  (theme: Theme): string => {
37
46
  const done = list.items.filter((item) => item.done).length;
38
47
  return (
39
- theme.fg("accent", theme.bold(list.name)) + theme.fg("dim", ` (${done}/${list.items.length})`)
48
+ theme.style(list.name, { fg: "accent", bold: true }) +
49
+ theme.fg("dim", ` (${done}/${list.items.length})`)
40
50
  );
41
51
  };
42
52
 
@@ -192,7 +202,9 @@ const widgetRows =
192
202
  const item = view.list.items[row.index]!;
193
203
  const blocked = (view.ready[row.index]?.blockers.length ?? 0) > 0;
194
204
  const marker = itemMarker(item, blocked, row.index === current, theme);
195
- const text = item.done ? theme.fg("muted", theme.strikethrough(item.text)) : item.text;
205
+ const text = item.done
206
+ ? theme.style(item.text, { fg: "muted", strikethrough: true })
207
+ : item.text;
196
208
  rows.push(` ${marker}${text}`);
197
209
  }
198
210
  return rows;
@@ -261,6 +273,8 @@ export interface TrackerOverlayOptions {
261
273
  readonly onAction: (action: TrackerUiAction) => Promise<string | null>;
262
274
  /** Close the overlay. */
263
275
  readonly onClose: () => void;
276
+ /** Write text to the clipboard. Defaults to pi's `copyToClipboard`. */
277
+ readonly copyText?: (text: string) => Promise<void>;
264
278
  }
265
279
 
266
280
  /** The interactive overlay surface: render + input + cache invalidation. */
@@ -268,6 +282,8 @@ export interface TrackerOverlayHandle {
268
282
  readonly render: (width: number) => string[];
269
283
  readonly invalidate: () => void;
270
284
  readonly handleInput: (data: string) => void;
285
+ /** Move the cursor on wheel events; other mouse events are ignored. */
286
+ readonly handleMouse: (event: TuiMouseEvent) => { handled: boolean } | undefined;
271
287
  }
272
288
 
273
289
  /**
@@ -287,6 +303,8 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
287
303
  let itemIndex = 0;
288
304
  let input: InputMode | null = null;
289
305
  let error: string | null = null;
306
+ let notice: string | null = null;
307
+ const writeClipboard = options.copyText ?? copyToClipboard;
290
308
 
291
309
  // Render cache (tui.md "Performance"): lines are reused while the inputs
292
310
  // (width, state snapshot, overlay state) are unchanged.
@@ -307,6 +325,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
307
325
  if (matchesKey(data, Key.tab) || matchesKey(data, Key.shift("tab"))) {
308
326
  mode = mode === "lists" ? "items" : "lists";
309
327
  error = null;
328
+ notice = null;
310
329
  syncCursors();
311
330
  options.requestRender();
312
331
  return;
@@ -315,10 +334,32 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
315
334
  const handled = mode === "lists" ? handleListsKey(data, state) : handleItemsKey(data, state);
316
335
  if (handled) {
317
336
  error = null;
337
+ notice = null;
318
338
  options.requestRender();
319
339
  }
320
340
  };
321
341
 
342
+ const handleMouse = (event: TuiMouseEvent): { handled: boolean } | undefined => {
343
+ if (event.type !== "wheel") return undefined;
344
+ const delta = event.wheelDelta ?? 0;
345
+ if (delta === 0 || input) return { handled: delta !== 0 };
346
+ // pi normalizes wheel events to logical lines (the renderer applies
347
+ // `WheelScrollAccelerator`), so the delta is the step count directly.
348
+ const step = Math.abs(delta);
349
+ const direction = delta > 0 ? step : -step;
350
+ const state = options.getState();
351
+ if (mode === "lists") {
352
+ const count = state.lists.length;
353
+ if (count > 0) listIndex = wrap(listIndex + direction, count);
354
+ } else {
355
+ const list = activeList(state);
356
+ const count = list ? orderedItems(list).length : 0;
357
+ if (count > 0) itemIndex = wrap(itemIndex + direction, count);
358
+ }
359
+ options.requestRender();
360
+ return { handled: true };
361
+ };
362
+
322
363
  const render = (width: number): string[] => {
323
364
  const theme = options.theme;
324
365
  const state = options.getState();
@@ -335,7 +376,9 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
335
376
 
336
377
  // Lists pane
337
378
  const listsHeader =
338
- mode === "lists" ? theme.fg("accent", theme.bold("Lists")) : theme.fg("muted", "Lists");
379
+ mode === "lists"
380
+ ? theme.style("Lists", { fg: "accent", bold: true })
381
+ : theme.fg("muted", "Lists");
339
382
  lines.push(truncateToWidth(` ${listsHeader}`, width));
340
383
 
341
384
  if (state.lists.length === 0) {
@@ -353,9 +396,12 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
353
396
  const name = isActive ? `${theme.fg("success", "● ")}${list.name}` : list.name;
354
397
  if (selected) {
355
398
  lines.push(
356
- truncateToWidth(
357
- ` ${theme.fg("accent", "→ ")}${theme.fg("accent", name)}${counts}`,
358
- width,
399
+ theme.style(
400
+ truncateToWidth(
401
+ ` ${theme.fg("accent", "→ ")}${theme.fg("accent", name)}${counts}`,
402
+ width,
403
+ ),
404
+ { bg: "selectedBg" },
359
405
  ),
360
406
  );
361
407
  } else {
@@ -376,12 +422,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
376
422
 
377
423
  // Items pane
378
424
  const activeListFor = activeList(state);
379
- const itemsHeader = theme.fg(
380
- mode === "items" ? "accent" : "muted",
381
- mode === "items"
382
- ? theme.bold(`Items — ${activeListFor?.name ?? "(no list)"}`)
383
- : `Items — ${activeListFor?.name ?? "(no list)"}`,
384
- );
425
+ const itemsTitle = `Items — ${activeListFor?.name ?? "(no list)"}`;
426
+ const itemsHeader = theme.style(itemsTitle, {
427
+ fg: mode === "items" ? "accent" : "muted",
428
+ bold: mode === "items",
429
+ });
385
430
  lines.push(truncateToWidth(` ${itemsHeader}`, width));
386
431
 
387
432
  if (!activeListFor) {
@@ -399,8 +444,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
399
444
  const prefix = selected ? theme.fg("accent", "→ ") : " ";
400
445
  const blocker = readinessSuffix(item.done, view.ready[index]?.blockers ?? []);
401
446
  const check = itemMarker(item, blocker !== "", false, theme);
402
- const text = item.done ? theme.fg("muted", theme.strikethrough(item.text)) : item.text;
403
- lines.push(truncateToWidth(`${prefix}${check}${text}${blocker}`, width));
447
+ const text = item.done
448
+ ? theme.style(item.text, { fg: "muted", strikethrough: true })
449
+ : item.text;
450
+ const row = truncateToWidth(`${prefix}${check}${text}${blocker}`, width);
451
+ lines.push(selected ? theme.style(row, { bg: "selectedBg" }) : row);
404
452
  }
405
453
  if (activeListFor.items.length > MAX_ITEMS) {
406
454
  lines.push(
@@ -426,14 +474,17 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
426
474
  } else if (error) {
427
475
  lines.push("");
428
476
  lines.push(truncateToWidth(` ${theme.fg("warning", `! ${error}`)}`, width));
477
+ } else if (notice) {
478
+ lines.push("");
479
+ lines.push(truncateToWidth(` ${theme.fg("success", `✓ ${notice}`)}`, width));
429
480
  }
430
481
 
431
482
  // Help
432
483
  lines.push("");
433
484
  const help =
434
485
  mode === "lists"
435
- ? "[tab] items · [n] new · [d] delete · [space] toggle · [↑↓] move · [enter] active · [esc] close"
436
- : "[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [↑↓] move · [esc] close";
486
+ ? "[tab] items · [n] new · [d] delete · [c] copy · [space] toggle · [↑↓] move · [enter] active · [esc] close"
487
+ : "[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [c] copy · [↑↓] move · [esc] close";
437
488
  lines.push(truncateToWidth(` ${theme.fg("dim", help)}`, width));
438
489
 
439
490
  cachedWidth = width;
@@ -457,7 +508,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
457
508
  */
458
509
  const thisSignature = (): string => {
459
510
  const inputPart = input === null ? "" : `${input.kind}:${input.buffer}`;
460
- return `${mode}:${listIndex}:${itemIndex}:${error ?? ""}:${inputPart}`;
511
+ return `${mode}:${listIndex}:${itemIndex}:${error ?? ""}:${notice ?? ""}:${inputPart}`;
461
512
  };
462
513
 
463
514
  const activeList = (state: TrackerState): TodoList | undefined => {
@@ -470,6 +521,19 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
470
521
  return state.lists.find((list) => list.id === state.activeListId);
471
522
  };
472
523
 
524
+ const copyText = (text: string, label: string): void => {
525
+ void writeClipboard(text).then(
526
+ () => {
527
+ notice = `Copied ${label}`;
528
+ options.requestRender();
529
+ },
530
+ (cause: unknown) => {
531
+ error = `Copy failed: ${cause instanceof Error ? cause.message : String(cause)}`;
532
+ options.requestRender();
533
+ },
534
+ );
535
+ };
536
+
473
537
  const handleListsKey = (data: string, state: TrackerState): boolean => {
474
538
  const lists = state.lists;
475
539
  if (lists.length === 0) {
@@ -504,6 +568,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
504
568
  void runAction({ type: "deleteList", listId: list.id });
505
569
  return true;
506
570
  }
571
+ if (data === "c") {
572
+ const list = lists[listIndex]!;
573
+ copyText(list.name, `list "${list.name}"`);
574
+ return true;
575
+ }
507
576
  if (data === " " || matchesKey(data, Key.space)) {
508
577
  // Toggle the highlighted list: selecting another list makes it active,
509
578
  // toggling the already-active list deselects it (hiding the widget).
@@ -569,6 +638,12 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
569
638
  input = { kind: "newList", buffer: "" };
570
639
  return true;
571
640
  }
641
+ if (data === "c") {
642
+ const item = items[itemIndex];
643
+ if (!item) return true;
644
+ copyText(`${list.name}:${item.id} ${item.text}`, `item "${item.text}"`);
645
+ return true;
646
+ }
572
647
  return false;
573
648
  };
574
649
 
@@ -621,5 +696,5 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
621
696
  itemIndex = items.length === 0 ? 0 : clamp(itemIndex, 0, items.length - 1);
622
697
  };
623
698
 
624
- return { render, invalidate, handleInput };
699
+ return { render, invalidate, handleInput, handleMouse };
625
700
  };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes