@ftrdotdev/pi-tracker 0.8.0 → 0.9.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.
@@ -3,9 +3,19 @@
3
3
  * contract, and the prompt-facing strings. Everything here is free of runtime
4
4
  * state; behavior (execute and rendering) lives in index.ts.
5
5
  */
6
- import { StringEnum } from "@earendil-works/pi-ai";
7
- import { Type } from "typebox";
8
- import type { Static } from "typebox";
6
+ import {
7
+ arr,
8
+ bool,
9
+ lit,
10
+ num,
11
+ obj,
12
+ oneOf,
13
+ opt,
14
+ str,
15
+ union,
16
+ type Schema,
17
+ type Static,
18
+ } from "@earendil-works/pi-schema";
9
19
  import { dependentsOf, formatItemRef, parseItemRef, unsatisfiedDeps } from "../core/deps.ts";
10
20
  import type { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
11
21
  import type { EncodedState } from "../core/persistence.ts";
@@ -23,6 +33,15 @@ export const TOOL_ACTIONS = [
23
33
 
24
34
  export type TrackerToolAction = (typeof TOOL_ACTIONS)[number];
25
35
 
36
+ /**
37
+ * The action enum keeps an explicit `type: "string"`. Some providers reject an
38
+ * enum without a type, and TypeBox's `StringEnum` existed for that reason.
39
+ */
40
+ const actionSchema: Schema<TrackerToolAction> = {
41
+ type: "string",
42
+ ...oneOf(TOOL_ACTIONS, { description: "Tracker operation to perform" }),
43
+ };
44
+
26
45
  export const TRACKER_TOOL_NAME = "tracker";
27
46
  export const TRACKER_TOOL_LABEL = "Tracker";
28
47
 
@@ -30,96 +49,72 @@ export const TRACKER_TOOL_LABEL = "Tracker";
30
49
  * How an item is declared when it is created: bare text, or an object that
31
50
  * also carries the same-list items it must wait for.
32
51
  */
33
- const depsSchema = Type.Array(
34
- Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }),
35
- { description: "Same-list items that must be done before this one." },
36
- );
52
+ const depsSchema = arr(str({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
53
+ description: "Same-list items that must be done before this one.",
54
+ });
37
55
 
38
56
  /** The item-title cap. Enforced only at the tool input, never persisted. */
39
57
  export const TITLE_LIMIT = 200;
40
58
 
41
- const titleField = Type.String({
59
+ const titleField = str({
42
60
  description:
43
61
  "Item title: one short action line (max 200 characters). Move longer detail into 'description'.",
44
62
  });
45
63
 
46
- const descriptionField = Type.String({
64
+ const descriptionField = str({
47
65
  description:
48
66
  "Optional: the longer explanation of the item. Put the essential detail in the first paragraph.",
49
67
  });
50
68
 
51
69
  /** A declared reference: a path (optionally narrowed to a symbol or span) or a decision topic. */
52
- const referenceSchema = Type.Union([
53
- Type.Object(
54
- {
55
- kind: Type.Literal("path"),
56
- path: Type.String({ description: "The file path this item must read next." }),
57
- symbol: Type.Optional(Type.String({ description: "A symbol inside the path." })),
58
- span: Type.Optional(Type.String({ description: 'A line span, e.g. "12-14" or "12".' })),
59
- },
60
- { additionalProperties: false },
61
- ),
62
- Type.Object(
63
- {
64
- kind: Type.Literal("decision"),
65
- topic: Type.String({ description: "The decision the item depends on." }),
66
- },
67
- { additionalProperties: false },
68
- ),
70
+ const referenceSchema = union([
71
+ obj({
72
+ kind: lit("path"),
73
+ path: str({ description: "The file path this item must read next." }),
74
+ symbol: opt(str({ description: "A symbol inside the path." })),
75
+ span: opt(str({ description: 'A line span, e.g. "12-14" or "12".' })),
76
+ }),
77
+ obj({
78
+ kind: lit("decision"),
79
+ topic: str({ description: "The decision the item depends on." }),
80
+ }),
69
81
  ]);
70
82
 
71
- const refsSchema = Type.Array(referenceSchema, {
83
+ const refsSchema = arr(referenceSchema, {
72
84
  description:
73
85
  "Optional: the files, symbols, regions, or decisions this item must read after the completed item finishes.",
74
86
  });
75
87
 
76
- const producesSchema = Type.Array(
77
- Type.Object(
78
- { path: Type.String({ description: "A document the item will write." }) },
79
- { additionalProperties: false },
80
- ),
81
- { description: "Optional: every document this item will write." },
82
- );
88
+ const producesSchema = arr(obj({ path: str({ description: "A document the item will write." }) }), {
89
+ description: "Optional: every document this item will write.",
90
+ });
83
91
 
84
92
  /** One new item, as the strict item object both add paths accept. */
85
- const ItemObjectSchema = Type.Object(
86
- {
87
- title: titleField,
88
- description: Type.Optional(descriptionField),
89
- refs: Type.Optional(refsSchema),
90
- produces: Type.Optional(producesSchema),
91
- deps: Type.Optional(depsSchema),
92
- },
93
- // Item objects are strict: a typo inside one fails here.
94
- { additionalProperties: false },
95
- );
93
+ const ItemObjectSchema = obj({
94
+ title: titleField,
95
+ description: opt(descriptionField),
96
+ refs: opt(refsSchema),
97
+ produces: opt(producesSchema),
98
+ deps: opt(depsSchema),
99
+ });
96
100
 
97
101
  /** One `update_items` patch: the item id plus the fields to replace. */
98
- const UpdatePatchSchema = Type.Object(
99
- {
100
- item_id: Type.String({
102
+ const UpdatePatchSchema = obj({
103
+ item_id: str({
104
+ description: 'The id of the item within list_id, as shown by the list action (e.g. "Work:2").',
105
+ }),
106
+ title: opt(str({ description: "Replacement title for the item." })),
107
+ description: opt(str({ description: "Replacement description for the item." })),
108
+ refs: opt(refsSchema),
109
+ produces: opt(producesSchema),
110
+ done: opt(bool({ description: "true marks the item done, false reopens it." })),
111
+ deps: opt(
112
+ arr(str({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
101
113
  description:
102
- 'The id of the item within list_id, as shown by the list action (e.g. "Work:2").',
114
+ "Replacement dependency set for this item. Pass [] to clear. Must not form a cycle.",
103
115
  }),
104
- title: Type.Optional(Type.String({ description: "Replacement title for the item." })),
105
- description: Type.Optional(
106
- Type.String({ description: "Replacement description for the item." }),
107
- ),
108
- refs: Type.Optional(refsSchema),
109
- produces: Type.Optional(producesSchema),
110
- done: Type.Optional(
111
- Type.Boolean({ description: "true marks the item done, false reopens it." }),
112
- ),
113
- deps: Type.Optional(
114
- Type.Array(Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
115
- description:
116
- "Replacement dependency set for this item. Pass [] to clear. Must not form a cycle.",
117
- }),
118
- ),
119
- },
120
- // Patch objects are strict: a typo inside an item update fails here.
121
- { additionalProperties: false },
122
- );
116
+ ),
117
+ });
123
118
 
124
119
  /** One item to add, as the tool accepts it. */
125
120
  export type TrackerItemSpec = Static<typeof ItemObjectSchema>;
@@ -135,61 +130,63 @@ export type TrackerUpdatePatch = Static<typeof UpdatePatchSchema>;
135
130
  * receives a precise, actionable error message instead of a generic schema
136
131
  * rejection.
137
132
  */
138
- export const TrackerToolParams = Type.Object({
139
- action: StringEnum(TOOL_ACTIONS, { description: "Tracker operation to perform" }),
140
- list_id: Type.Optional(
141
- Type.Number({
142
- description:
143
- "List id, as shown by the list action. Required for delete_list, add_items, and for update_items' items={...} batch; optional for set_active (omit to deselect).",
144
- }),
145
- ),
146
- item_id: Type.Optional(
147
- Type.String({
148
- description:
149
- 'Item id, as shown by the list action: listName:id (e.g. "Work:2"). Ids are permanent: removing an item does not change the other ids. Required for update_items (scalar form) and remove_item.',
150
- }),
151
- ),
152
- name: Type.Optional(
153
- Type.String({ description: "Name for the new list. Required for create_list." }),
154
- ),
155
- initial_items: Type.Optional(
156
- Type.Array(ItemObjectSchema, {
157
- description:
158
- "For create_list: initial items, each {title, description?, refs?, produces?, deps?}, added when the list is created.",
159
- minItems: 1,
160
- }),
161
- ),
162
- activate: Type.Optional(
163
- Type.Boolean({
164
- description:
165
- "For create_list: switch the active list to the new list (defaults to true; pass false to keep the current active list).",
166
- }),
167
- ),
168
- title: Type.Optional(
169
- Type.String({
170
- description: "For update_items: the replacement title for the item (max 200 characters).",
171
- }),
172
- ),
173
- description: Type.Optional(descriptionField),
174
- refs: Type.Optional(refsSchema),
175
- produces: Type.Optional(producesSchema),
176
- done: Type.Optional(
177
- Type.Boolean({ description: "For update_items: true marks the item done, false reopens it." }),
178
- ),
179
- deps: Type.Optional(
180
- Type.Array(Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
181
- description:
182
- "For update_items: the replacement dependency set (same-list items that must be done first). Pass [] to clear. Must not form a cycle.",
183
- }),
184
- ),
185
- items: Type.Optional(
186
- Type.Array(Type.Union([ItemObjectSchema, UpdatePatchSchema]), {
187
- description:
188
- "For add_items: the item objects to add, each {title, description?, refs?, produces?, deps?}. For update_items: the item patches, each with an item_id.",
189
- minItems: 1,
190
- }),
191
- ),
192
- });
133
+ export const TrackerToolParams = obj(
134
+ {
135
+ action: actionSchema,
136
+ list_id: opt(
137
+ num({
138
+ description:
139
+ "List id, as shown by the list action. Required for delete_list, add_items, and for update_items' items={...} batch; optional for set_active (omit to deselect).",
140
+ }),
141
+ ),
142
+ item_id: opt(
143
+ str({
144
+ description:
145
+ 'Item id, as shown by the list action: listName:id (e.g. "Work:2"). Ids are permanent: removing an item does not change the other ids. Required for update_items (scalar form) and remove_item.',
146
+ }),
147
+ ),
148
+ name: opt(str({ description: "Name for the new list. Required for create_list." })),
149
+ initial_items: opt(
150
+ arr(ItemObjectSchema, {
151
+ description:
152
+ "For create_list: initial items, each {title, description?, refs?, produces?, deps?}, added when the list is created.",
153
+ minItems: 1,
154
+ }),
155
+ ),
156
+ activate: opt(
157
+ bool({
158
+ description:
159
+ "For create_list: switch the active list to the new list (defaults to true; pass false to keep the current active list).",
160
+ }),
161
+ ),
162
+ title: opt(
163
+ str({
164
+ description: "For update_items: the replacement title for the item (max 200 characters).",
165
+ }),
166
+ ),
167
+ description: opt(descriptionField),
168
+ refs: opt(refsSchema),
169
+ produces: opt(producesSchema),
170
+ done: opt(
171
+ bool({ description: "For update_items: true marks the item done, false reopens it." }),
172
+ ),
173
+ deps: opt(
174
+ arr(str({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
175
+ description:
176
+ "For update_items: the replacement dependency set (same-list items that must be done first). Pass [] to clear. Must not form a cycle.",
177
+ }),
178
+ ),
179
+ items: opt(
180
+ arr(union([ItemObjectSchema, UpdatePatchSchema]), {
181
+ description:
182
+ "For add_items: the item objects to add, each {title, description?, refs?, produces?, deps?}. For update_items: the item patches, each with an item_id.",
183
+ minItems: 1,
184
+ }),
185
+ ),
186
+ },
187
+ // Unknown top-level fields are tolerated and reported by `validateTrackerCall`.
188
+ { open: true },
189
+ );
193
190
 
194
191
  export type TrackerToolParams = Static<typeof TrackerToolParams>;
195
192
 
@@ -484,15 +481,15 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
484
481
  /** Structured result payload attached to tool calls, consumed by the renderers. */
485
482
  export interface TrackerToolDetails {
486
483
  action: TrackerToolAction;
487
- error?: string;
488
- listId?: number;
484
+ error?: string | undefined;
485
+ listId?: number | undefined;
489
486
  /** `listName:id`, as shown by the list action. */
490
- itemId?: string;
491
- list?: TodoList;
487
+ itemId?: string | undefined;
488
+ list?: TodoList | undefined;
492
489
  /** Items affected by an add_items/update_items call, in creation/patch order. */
493
- items?: TodoItem[];
490
+ items?: TodoItem[] | undefined;
494
491
  /** Full state snapshot, only for the `list` action (for rendering). */
495
- snapshot?: EncodedState;
492
+ snapshot?: EncodedState | undefined;
496
493
  }
497
494
 
498
495
  /**
@@ -586,7 +583,7 @@ export const doneMarkReminder = (
586
583
  patches: readonly { readonly done?: boolean }[],
587
584
  openRemaining?: number,
588
585
  ): string | null => {
589
- const doneCount = patches.filter((patch) => patch.done === true).length;
586
+ const doneCount = patches.filter((patch) => patch.done ?? false).length;
590
587
  // Only the terminal batch — two or more done marks with nothing left open —
591
588
  // is flagged. Batches that finish several items while other work remains are
592
589
  // normal mid-turn progress and stay quiet. When the post-call open count is
@@ -1,5 +1,5 @@
1
- import { assert, it } from "@effect/vitest";
2
- import type { Theme } from "@earendil-works/pi-coding-agent";
1
+ import { assert, it, vi } from "@effect/vitest";
2
+ import { themeDouble } from "@ftrdotdev/pi-test-kit";
3
3
  import { visibleWidth } from "@earendil-works/pi-tui";
4
4
  import { VimRouter } from "@ftrdotdev/pi-tui";
5
5
  import { Effect } from "effect";
@@ -17,32 +17,26 @@ import {
17
17
 
18
18
  /**
19
19
  * Identity theme: styles pass text through unchanged, so render output is
20
- * plain text that assertions can search. The overlay and widget only use
21
- * `fg`, `bold`, `strikethrough` and `style`, which this stub covers.
20
+ * plain text that assertions can search.
22
21
  */
23
- const identityTheme = {
24
- fg: (_color: string, text: string): string => text,
25
- bold: (text: string): string => text,
26
- strikethrough: (text: string): string => text,
27
- style: (text: string): string => text,
28
- } as unknown as Theme;
22
+ const identityTheme = themeDouble();
29
23
 
30
24
  /** A realistic two-list state: Work is the active list. */
31
25
  const twoListState = (): TrackerState =>
32
- new TrackerState({
26
+ TrackerState.make({
33
27
  lists: [
34
- new TodoList({
28
+ TodoList.make({
35
29
  id: 1,
36
30
  name: "Work",
37
31
  items: [
38
- new TodoItem({ title: "write plan", done: true }),
39
- new TodoItem({ title: "implement tracker", done: false }),
32
+ TodoItem.make({ title: "write plan", done: true }),
33
+ TodoItem.make({ title: "implement tracker", done: false }),
40
34
  ],
41
35
  }),
42
- new TodoList({
36
+ TodoList.make({
43
37
  id: 2,
44
38
  name: "Home",
45
- items: [new TodoItem({ title: "water plants", done: false })],
39
+ items: [TodoItem.make({ title: "water plants", done: false })],
46
40
  }),
47
41
  ],
48
42
  activeListId: 1,
@@ -65,7 +59,7 @@ interface OverlayHarness {
65
59
 
66
60
  /** Build a real `VimRouter` service gated on `enabled`. */
67
61
  const vimRouter = (enabled: boolean): VimRouter["Service"] =>
68
- Effect.runSync(Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => enabled))));
62
+ Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => enabled)), Effect.runSync);
69
63
 
70
64
  /**
71
65
  * Build an overlay over a scripted state. `onAction` mirrors the real
@@ -86,7 +80,11 @@ const makeOverlay = (
86
80
  onAction: async (action) => {
87
81
  actions.push(action);
88
82
  if (action.type === "setActive") {
89
- current = new TrackerState({ ...current, activeListId: action.listId });
83
+ current = TrackerState.make({
84
+ lists: current.lists,
85
+ activeListId: action.listId,
86
+ nextListId: current.nextListId,
87
+ });
90
88
  }
91
89
  return null;
92
90
  },
@@ -96,22 +94,19 @@ const makeOverlay = (
96
94
  return { overlay, actions };
97
95
  };
98
96
 
99
- /** Flush the microtask queue so fire-and-forget `runAction` continuations land. */
100
- const flushAsync = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0));
101
-
102
97
  // --------------------------------------------------------------------------
103
98
  // Interactive overlay: items pane follows the focused list
104
99
  // --------------------------------------------------------------------------
105
100
 
106
101
  it("overlay renders a multi-line description as separate lines", () => {
107
- const list = new TodoList({
102
+ const list = TodoList.make({
108
103
  id: 1,
109
104
  name: "Work",
110
105
  items: [
111
- new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
106
+ TodoItem.make({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
112
107
  ],
113
108
  });
114
- const h = makeOverlay(new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 }));
109
+ const h = makeOverlay(TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 }));
115
110
  const lines = h.overlay.render(80);
116
111
  assert.equal(
117
112
  lines.some((line) => line.includes("\n")),
@@ -147,9 +142,10 @@ it("enter commits the focused list as active and opens its items", async () => {
147
142
  const h = makeOverlay(twoListState());
148
143
  h.overlay.handleInput("\x1b[B"); // focus Home
149
144
  h.overlay.handleInput("\r"); // commit
150
- await flushAsync();
151
145
 
152
- assert.deepStrictEqual(h.actions, [{ type: "setActive", listId: 2 }]);
146
+ await vi.waitFor(() => {
147
+ assert.deepStrictEqual(h.actions, [{ type: "setActive", listId: 2 }]);
148
+ });
153
149
  const text = h.overlay.render(80).join("\n");
154
150
  assert.match(text, /Items — Home/);
155
151
  assert.match(text, /water plants/);
@@ -268,18 +264,22 @@ it("widget renders the active list's items", () => {
268
264
  });
269
265
 
270
266
  it("widget renders nothing when no list is active (bridge hides it)", () => {
271
- const state = new TrackerState({ ...twoListState(), activeListId: null });
267
+ const state = TrackerState.make({
268
+ lists: twoListState().lists,
269
+ activeListId: null,
270
+ nextListId: twoListState().nextListId,
271
+ });
272
272
  assert.deepStrictEqual(renderTrackerWidget(state, identityTheme, 40), []);
273
273
  });
274
274
 
275
275
  it("widget shows a dimmed description line truncated to the width", () => {
276
276
  const description = "x".repeat(120);
277
- const list = new TodoList({
277
+ const list = TodoList.make({
278
278
  id: 1,
279
279
  name: "Work",
280
- items: [new TodoItem({ id: 1, title: "long item", description, done: false })],
280
+ items: [TodoItem.make({ id: 1, title: "long item", description, done: false })],
281
281
  });
282
- const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
282
+ const state = TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 });
283
283
  const width = 40;
284
284
  const lines = renderTrackerWidget(state, identityTheme, width);
285
285
  const text = lines.join("\n");
@@ -291,14 +291,14 @@ it("widget shows a dimmed description line truncated to the width", () => {
291
291
  });
292
292
 
293
293
  it("widget collapses a multi-line description into one line", () => {
294
- const list = new TodoList({
294
+ const list = TodoList.make({
295
295
  id: 1,
296
296
  name: "Work",
297
297
  items: [
298
- new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
298
+ TodoItem.make({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
299
299
  ],
300
300
  });
301
- const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
301
+ const state = TrackerState.make({ lists: [list], activeListId: 1, nextListId: 2 });
302
302
  const lines = renderTrackerWidget(state, identityTheme, 60);
303
303
  assert.equal(
304
304
  lines.some((line) => line.includes("\n")),
@@ -329,13 +329,12 @@ it("widget survives the setWidget bridge wrapper (render/invalidate handed off b
329
329
 
330
330
  /** A list of `count` items; the first `done` items are done. */
331
331
  const listOfCount = (count: number, done: number): TodoList =>
332
- new TodoList({
332
+ TodoList.make({
333
333
  id: 1,
334
334
  name: "Work",
335
335
  nextItemId: count + 1,
336
- items: Array.from(
337
- { length: count },
338
- (_, index) => new TodoItem({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
336
+ items: Array.from({ length: count }, (_, index) =>
337
+ TodoItem.make({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
339
338
  ),
340
339
  });
341
340
 
@@ -347,23 +346,22 @@ const listWithDeps = (
347
346
  deps: ReadonlyArray<readonly string[]>,
348
347
  done: readonly number[] = [],
349
348
  ): TodoList =>
350
- new TodoList({
349
+ TodoList.make({
351
350
  id: 1,
352
351
  name: "Work",
353
352
  nextItemId: deps.length + 1,
354
- items: deps.map(
355
- (itemDeps, index) =>
356
- new TodoItem({
357
- id: index + 1,
358
- title: `item ${index + 1}`,
359
- done: done.includes(index),
360
- deps: itemDeps,
361
- }),
353
+ items: deps.map((itemDeps, index) =>
354
+ TodoItem.make({
355
+ id: index + 1,
356
+ title: `item ${index + 1}`,
357
+ done: done.includes(index),
358
+ deps: itemDeps,
359
+ }),
362
360
  ),
363
361
  });
364
362
 
365
363
  const stateWith = (list: TodoList): TrackerState =>
366
- new TrackerState({ lists: [list], activeListId: list.id, nextListId: 2 });
364
+ TrackerState.make({ lists: [list], activeListId: list.id, nextListId: 2 });
367
365
 
368
366
  const shownIndexes = (rows: readonly WidgetRow[]): number[] =>
369
367
  rows.flatMap((row) => (row.kind === "item" ? [row.index] : []));
@@ -537,19 +535,17 @@ it("a dependency-free list renders exactly as before", () => {
537
535
  it("planner anchors on the first ready item, not the first open item", () => {
538
536
  // Item 1 is done; item 2 waits for item 30. The first open item is item 2
539
537
  // and the first ready item is item 3.
540
- const list = new TodoList({
538
+ const list = TodoList.make({
541
539
  id: 1,
542
540
  name: "Work",
543
541
  nextItemId: 31,
544
- items: Array.from(
545
- { length: 30 },
546
- (_, index) =>
547
- new TodoItem({
548
- id: index + 1,
549
- title: `item ${index + 1}`,
550
- done: index === 0,
551
- deps: index === 1 ? ["Work:30"] : [],
552
- }),
542
+ items: Array.from({ length: 30 }, (_, index) =>
543
+ TodoItem.make({
544
+ id: index + 1,
545
+ title: `item ${index + 1}`,
546
+ done: index === 0,
547
+ deps: index === 1 ? ["Work:30"] : [],
548
+ }),
553
549
  ),
554
550
  });
555
551
  // Item 2 sits last in the derived order, after everything it waits for.
@@ -585,11 +581,13 @@ it("annotates a done item whose dependency is open again in the overlay", () =>
585
581
  it("paints the selected overlay row with the selection background", () => {
586
582
  // Marker theme: `style()` records the background token so the test can see
587
583
  // the selection paint without a real terminal theme.
588
- const markerTheme = {
589
- ...identityTheme,
590
- style: (text: string, options: { bg?: string }) =>
591
- options.bg === undefined ? text : `[${options.bg}]${text}[/${options.bg}]`,
592
- } as unknown as Theme;
584
+ const markerTheme = themeDouble({
585
+ style: (text, options) => {
586
+ // Only a background token is marked; a concrete terminal color is not.
587
+ const bg = typeof options.bg === "string" ? options.bg : undefined;
588
+ return bg === undefined ? text : `[${bg}]${text}[/${bg}]`;
589
+ },
590
+ });
593
591
  const overlay = makeTrackerOverlay({
594
592
  getState: () => twoListState(),
595
593
  theme: markerTheme,
@@ -622,8 +620,9 @@ const makeCopyOverlay = (): { overlay: TrackerOverlayHandle; copied: string[] }
622
620
  it("copies the selected list and reports it (c in the lists pane)", async () => {
623
621
  const { overlay, copied } = makeCopyOverlay();
624
622
  overlay.handleInput("c");
625
- await flushAsync();
626
- assert.deepStrictEqual(copied, ["Work"]);
623
+ await vi.waitFor(() => {
624
+ assert.deepStrictEqual(copied, ["Work"]);
625
+ });
627
626
  assert.ok(overlay.render(80).some((line) => line.includes("Copied")));
628
627
  });
629
628
 
@@ -631,9 +630,10 @@ it("copies the selected item reference and text (c in the items pane)", async ()
631
630
  const { overlay, copied } = makeCopyOverlay();
632
631
  overlay.handleInput("\t"); // switch to the items pane
633
632
  overlay.handleInput("c");
634
- await flushAsync();
635
- assert.strictEqual(copied.length, 1);
636
- assert.match(copied[0]!, /^Work:\d+ /);
633
+ await vi.waitFor(() => {
634
+ assert.strictEqual(copied.length, 1);
635
+ assert.match(copied[0]!, /^Work:\d+ /);
636
+ });
637
637
  });
638
638
 
639
639
  it("moves the selection on wheel events", () => {