@ftrdotdev/pi-tracker 0.6.0 → 0.8.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/README.md +183 -60
- package/package.json +23 -11
- package/src/compaction/candidate.test.ts +9 -6
- package/src/compaction/candidate.ts +32 -2
- package/src/compaction/classifier.test.ts +67 -60
- package/src/compaction/classifier.ts +24 -22
- package/src/compaction/completion.test.ts +127 -49
- package/src/compaction/completion.ts +1 -3
- package/src/compaction/decision-record.test.ts +91 -0
- package/src/compaction/decision-record.ts +101 -0
- package/src/compaction/digest.test.ts +104 -9
- package/src/compaction/digest.ts +96 -9
- package/src/compaction/footprint.test.ts +135 -0
- package/src/compaction/footprint.ts +387 -0
- package/src/compaction/observations.test.ts +199 -0
- package/src/compaction/observations.ts +348 -0
- package/src/compaction/rules.test.ts +253 -0
- package/src/compaction/rules.ts +188 -0
- package/src/compaction/settings.test.ts +105 -49
- package/src/compaction/settings.ts +53 -31
- package/src/compaction/settle.test.ts +370 -0
- package/src/compaction/settle.ts +109 -53
- package/src/core/deps.test.ts +1 -1
- package/src/core/domain.test.ts +42 -9
- package/src/core/domain.ts +73 -8
- package/src/core/persistence.test.ts +7 -7
- package/src/core/store.test.ts +116 -50
- package/src/core/store.ts +92 -31
- package/src/index.test.ts +209 -68
- package/src/index.ts +170 -48
- package/src/presentation/tool-metadata.test.ts +263 -48
- package/src/presentation/tool-metadata.ts +325 -102
- package/src/presentation/ui.test.ts +122 -7
- package/src/presentation/ui.ts +81 -18
- package/src/presentation/vim-settings.test.ts +98 -0
- package/src/presentation/vim-settings.ts +59 -0
|
@@ -1,6 +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 { VimRouter } from "@ftrdotdev/pi-tui";
|
|
5
|
+
import { Effect } from "effect";
|
|
4
6
|
import { orderedItems } from "../core/deps.ts";
|
|
5
7
|
import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
|
|
6
8
|
import {
|
|
@@ -33,14 +35,14 @@ const twoListState = (): TrackerState =>
|
|
|
33
35
|
id: 1,
|
|
34
36
|
name: "Work",
|
|
35
37
|
items: [
|
|
36
|
-
new TodoItem({
|
|
37
|
-
new TodoItem({
|
|
38
|
+
new TodoItem({ title: "write plan", done: true }),
|
|
39
|
+
new TodoItem({ title: "implement tracker", done: false }),
|
|
38
40
|
],
|
|
39
41
|
}),
|
|
40
42
|
new TodoList({
|
|
41
43
|
id: 2,
|
|
42
44
|
name: "Home",
|
|
43
|
-
items: [new TodoItem({
|
|
45
|
+
items: [new TodoItem({ title: "water plants", done: false })],
|
|
44
46
|
}),
|
|
45
47
|
],
|
|
46
48
|
activeListId: 1,
|
|
@@ -61,13 +63,20 @@ interface OverlayHarness {
|
|
|
61
63
|
readonly actions: TrackerUiAction[];
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
/** Build a real `VimRouter` service gated on `enabled`. */
|
|
67
|
+
const vimRouter = (enabled: boolean): VimRouter["Service"] =>
|
|
68
|
+
Effect.runSync(Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => enabled))));
|
|
69
|
+
|
|
64
70
|
/**
|
|
65
71
|
* Build an overlay over a scripted state. `onAction` mirrors the real
|
|
66
72
|
* bridge's `set_active` handling (the only action the tests exercise), so
|
|
67
73
|
* the snapshot passed to `getState` follows the same object-identity rules
|
|
68
74
|
* as the live mirror in `src/index.ts`.
|
|
69
75
|
*/
|
|
70
|
-
const makeOverlay = (
|
|
76
|
+
const makeOverlay = (
|
|
77
|
+
initial: TrackerState,
|
|
78
|
+
vim?: { readonly router: VimRouter["Service"]; readonly enabled: boolean },
|
|
79
|
+
): OverlayHarness => {
|
|
71
80
|
let current = initial;
|
|
72
81
|
const actions: TrackerUiAction[] = [];
|
|
73
82
|
const overlay = makeTrackerOverlay({
|
|
@@ -82,6 +91,7 @@ const makeOverlay = (initial: TrackerState): OverlayHarness => {
|
|
|
82
91
|
return null;
|
|
83
92
|
},
|
|
84
93
|
onClose: () => {},
|
|
94
|
+
...(vim === undefined ? {} : { vim }),
|
|
85
95
|
});
|
|
86
96
|
return { overlay, actions };
|
|
87
97
|
};
|
|
@@ -93,6 +103,25 @@ const flushAsync = (): Promise<void> => new Promise((resolve) => setTimeout(reso
|
|
|
93
103
|
// Interactive overlay: items pane follows the focused list
|
|
94
104
|
// --------------------------------------------------------------------------
|
|
95
105
|
|
|
106
|
+
it("overlay renders a multi-line description as separate lines", () => {
|
|
107
|
+
const list = new TodoList({
|
|
108
|
+
id: 1,
|
|
109
|
+
name: "Work",
|
|
110
|
+
items: [
|
|
111
|
+
new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
const h = makeOverlay(new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 }));
|
|
115
|
+
const lines = h.overlay.render(80);
|
|
116
|
+
assert.equal(
|
|
117
|
+
lines.some((line) => line.includes("\n")),
|
|
118
|
+
false,
|
|
119
|
+
);
|
|
120
|
+
const text = lines.join("\n");
|
|
121
|
+
assert.include(text, "first line");
|
|
122
|
+
assert.include(text, "second line");
|
|
123
|
+
});
|
|
124
|
+
|
|
96
125
|
it("previews the focused list's items while navigating the lists pane", () => {
|
|
97
126
|
const h = makeOverlay(twoListState());
|
|
98
127
|
const text = () => h.overlay.render(80).join("\n");
|
|
@@ -137,6 +166,57 @@ it("items pane follows the active list in items mode (preview is not a commit)",
|
|
|
137
166
|
assert.match(text, /write plan/);
|
|
138
167
|
});
|
|
139
168
|
|
|
169
|
+
// --------------------------------------------------------------------------
|
|
170
|
+
// Vim navigation (h/j/k/l) behind the vim toggle
|
|
171
|
+
// --------------------------------------------------------------------------
|
|
172
|
+
|
|
173
|
+
it("hjkl moves the list cursor and switches panes when vim is on", () => {
|
|
174
|
+
const h = makeOverlay(twoListState(), { router: vimRouter(true), enabled: true });
|
|
175
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
176
|
+
|
|
177
|
+
// j previews the next list; k returns to the previous one.
|
|
178
|
+
h.overlay.handleInput("j");
|
|
179
|
+
assert.match(text(), /Items — Home/);
|
|
180
|
+
h.overlay.handleInput("k");
|
|
181
|
+
assert.match(text(), /Items — Work/);
|
|
182
|
+
|
|
183
|
+
// l opens the items pane; h returns to the lists pane.
|
|
184
|
+
h.overlay.handleInput("l");
|
|
185
|
+
assert.match(text(), /\[tab\] lists/);
|
|
186
|
+
h.overlay.handleInput("h");
|
|
187
|
+
assert.match(text(), /\[tab\] items/);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("hjkl is inert when the vim toggle is off", () => {
|
|
191
|
+
const h = makeOverlay(twoListState(), { router: vimRouter(false), enabled: false });
|
|
192
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
193
|
+
|
|
194
|
+
h.overlay.handleInput("j");
|
|
195
|
+
assert.match(text(), /Items — Work/);
|
|
196
|
+
h.overlay.handleInput("l");
|
|
197
|
+
assert.match(text(), /\[tab\] items/); // still lists mode
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("arrow left and right switch panes", () => {
|
|
201
|
+
const h = makeOverlay(twoListState());
|
|
202
|
+
const text = () => h.overlay.render(80).join("\n");
|
|
203
|
+
|
|
204
|
+
h.overlay.handleInput("\x1b[C"); // right
|
|
205
|
+
assert.match(text(), /\[tab\] lists/);
|
|
206
|
+
h.overlay.handleInput("\x1b[D"); // left
|
|
207
|
+
assert.match(text(), /\[tab\] items/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("help shows hjkl only when vim is on", () => {
|
|
211
|
+
const off = makeOverlay(twoListState(), { router: vimRouter(false), enabled: false });
|
|
212
|
+
const offText = off.overlay.render(200).join("\n");
|
|
213
|
+
assert.match(offText, /\[↑↓←→\] move/);
|
|
214
|
+
assert.equal(offText.includes("hjkl"), false);
|
|
215
|
+
|
|
216
|
+
const on = makeOverlay(twoListState(), { router: vimRouter(true), enabled: true });
|
|
217
|
+
assert.match(on.overlay.render(200).join("\n"), /\[↑↓←→\/hjkl\] move/);
|
|
218
|
+
});
|
|
219
|
+
|
|
140
220
|
// --------------------------------------------------------------------------
|
|
141
221
|
// Render caching (tui.md "Performance" / "Invalidation and Theme Changes")
|
|
142
222
|
// --------------------------------------------------------------------------
|
|
@@ -192,6 +272,41 @@ it("widget renders nothing when no list is active (bridge hides it)", () => {
|
|
|
192
272
|
assert.deepStrictEqual(renderTrackerWidget(state, identityTheme, 40), []);
|
|
193
273
|
});
|
|
194
274
|
|
|
275
|
+
it("widget shows a dimmed description line truncated to the width", () => {
|
|
276
|
+
const description = "x".repeat(120);
|
|
277
|
+
const list = new TodoList({
|
|
278
|
+
id: 1,
|
|
279
|
+
name: "Work",
|
|
280
|
+
items: [new TodoItem({ id: 1, title: "long item", description, done: false })],
|
|
281
|
+
});
|
|
282
|
+
const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
283
|
+
const width = 40;
|
|
284
|
+
const lines = renderTrackerWidget(state, identityTheme, width);
|
|
285
|
+
const text = lines.join("\n");
|
|
286
|
+
assert.include(text, "long item");
|
|
287
|
+
notContain(text, description);
|
|
288
|
+
const descriptionLine = lines.find((line) => line.includes("x"));
|
|
289
|
+
assert.isDefined(descriptionLine);
|
|
290
|
+
assert.isAtMost(visibleWidth(descriptionLine!), width);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("widget collapses a multi-line description into one line", () => {
|
|
294
|
+
const list = new TodoList({
|
|
295
|
+
id: 1,
|
|
296
|
+
name: "Work",
|
|
297
|
+
items: [
|
|
298
|
+
new TodoItem({ id: 1, title: "multi", description: "first line\nsecond line", done: false }),
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
const state = new TrackerState({ lists: [list], activeListId: 1, nextListId: 2 });
|
|
302
|
+
const lines = renderTrackerWidget(state, identityTheme, 60);
|
|
303
|
+
assert.equal(
|
|
304
|
+
lines.some((line) => line.includes("\n")),
|
|
305
|
+
false,
|
|
306
|
+
);
|
|
307
|
+
assert.include(lines.join("\n"), "first line second line");
|
|
308
|
+
});
|
|
309
|
+
|
|
195
310
|
it("widget survives the setWidget bridge wrapper (render/invalidate handed off by reference)", () => {
|
|
196
311
|
// Mirrors the tracker bridge: `return { render: widget.render, invalidate: widget.invalidate }`.
|
|
197
312
|
// pi calls render as a method of the wrapper; closure components carry no
|
|
@@ -220,7 +335,7 @@ const listOfCount = (count: number, done: number): TodoList =>
|
|
|
220
335
|
nextItemId: count + 1,
|
|
221
336
|
items: Array.from(
|
|
222
337
|
{ length: count },
|
|
223
|
-
(_, index) => new TodoItem({ id: index + 1,
|
|
338
|
+
(_, index) => new TodoItem({ id: index + 1, title: `item ${index + 1}`, done: index < done }),
|
|
224
339
|
),
|
|
225
340
|
});
|
|
226
341
|
|
|
@@ -240,7 +355,7 @@ const listWithDeps = (
|
|
|
240
355
|
(itemDeps, index) =>
|
|
241
356
|
new TodoItem({
|
|
242
357
|
id: index + 1,
|
|
243
|
-
|
|
358
|
+
title: `item ${index + 1}`,
|
|
244
359
|
done: done.includes(index),
|
|
245
360
|
deps: itemDeps,
|
|
246
361
|
}),
|
|
@@ -431,7 +546,7 @@ it("planner anchors on the first ready item, not the first open item", () => {
|
|
|
431
546
|
(_, index) =>
|
|
432
547
|
new TodoItem({
|
|
433
548
|
id: index + 1,
|
|
434
|
-
|
|
549
|
+
title: `item ${index + 1}`,
|
|
435
550
|
done: index === 0,
|
|
436
551
|
deps: index === 1 ? ["Work:30"] : [],
|
|
437
552
|
}),
|
package/src/presentation/ui.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
visibleWidth,
|
|
8
8
|
type TuiMouseEvent,
|
|
9
9
|
} from "@earendil-works/pi-tui";
|
|
10
|
-
import { makeBorderedBox } from "@ftrdotdev/pi-tui";
|
|
10
|
+
import { makeBorderedBox, type NavigationIntent, type VimRouter } from "@ftrdotdev/pi-tui";
|
|
11
11
|
import {
|
|
12
12
|
firstReadyIndex,
|
|
13
13
|
orderedItems,
|
|
@@ -202,10 +202,21 @@ const widgetRows =
|
|
|
202
202
|
const item = view.list.items[row.index]!;
|
|
203
203
|
const blocked = (view.ready[row.index]?.blockers.length ?? 0) > 0;
|
|
204
204
|
const marker = itemMarker(item, blocked, row.index === current, theme);
|
|
205
|
-
const
|
|
206
|
-
? theme.style(item.
|
|
207
|
-
: item.
|
|
208
|
-
rows.push(` ${marker}${
|
|
205
|
+
const title = item.done
|
|
206
|
+
? theme.style(item.title, { fg: "muted", strikethrough: true })
|
|
207
|
+
: item.title;
|
|
208
|
+
rows.push(` ${marker}${title}`);
|
|
209
|
+
if (item.description.length > 0) {
|
|
210
|
+
// The widget row is one line, so a multi-line description collapses
|
|
211
|
+
// to single spaces before it is truncated.
|
|
212
|
+
const description = item.description.replace(/\s+/g, " ").trim();
|
|
213
|
+
rows.push(
|
|
214
|
+
truncateToWidth(
|
|
215
|
+
`${" ".repeat(2 + MARKER_WIDTH)}${theme.fg("dim", description)}`,
|
|
216
|
+
Math.max(0, _width),
|
|
217
|
+
),
|
|
218
|
+
);
|
|
219
|
+
}
|
|
209
220
|
}
|
|
210
221
|
return rows;
|
|
211
222
|
};
|
|
@@ -251,7 +262,7 @@ export type TrackerUiAction =
|
|
|
251
262
|
| { readonly type: "createList"; readonly name: string }
|
|
252
263
|
| { readonly type: "deleteList"; readonly listId: number }
|
|
253
264
|
| { readonly type: "setActive"; readonly listId: number | null }
|
|
254
|
-
| { readonly type: "addItem"; readonly listId: number; readonly
|
|
265
|
+
| { readonly type: "addItem"; readonly listId: number; readonly title: string }
|
|
255
266
|
| { readonly type: "updateItem"; readonly itemId: string; readonly patch: UpdateItemPatch }
|
|
256
267
|
| { readonly type: "removeItem"; readonly itemId: string };
|
|
257
268
|
|
|
@@ -275,6 +286,11 @@ export interface TrackerOverlayOptions {
|
|
|
275
286
|
readonly onClose: () => void;
|
|
276
287
|
/** Write text to the clipboard. Defaults to pi's `copyToClipboard`. */
|
|
277
288
|
readonly copyText?: (text: string) => Promise<void>;
|
|
289
|
+
/**
|
|
290
|
+
* The shared vim navigation router, gated on the `vim` toggle by the bridge.
|
|
291
|
+
* When omitted the overlay is arrow-only. `enabled` drives the help line.
|
|
292
|
+
*/
|
|
293
|
+
readonly vim?: { readonly router: VimRouter["Service"]; readonly enabled: boolean };
|
|
278
294
|
}
|
|
279
295
|
|
|
280
296
|
/** The interactive overlay surface: render + input + cache invalidation. */
|
|
@@ -331,6 +347,14 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
331
347
|
return;
|
|
332
348
|
}
|
|
333
349
|
const state = options.getState();
|
|
350
|
+
const intent = options.vim?.router.decodeNavigation(data);
|
|
351
|
+
if (intent !== undefined) {
|
|
352
|
+
applyNavigation(intent, state);
|
|
353
|
+
error = null;
|
|
354
|
+
notice = null;
|
|
355
|
+
options.requestRender();
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
334
358
|
const handled = mode === "lists" ? handleListsKey(data, state) : handleItemsKey(data, state);
|
|
335
359
|
if (handled) {
|
|
336
360
|
error = null;
|
|
@@ -444,11 +468,18 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
444
468
|
const prefix = selected ? theme.fg("accent", "→ ") : " ";
|
|
445
469
|
const blocker = readinessSuffix(item.done, view.ready[index]?.blockers ?? []);
|
|
446
470
|
const check = itemMarker(item, blocker !== "", false, theme);
|
|
447
|
-
const
|
|
448
|
-
? theme.style(item.
|
|
449
|
-
: item.
|
|
450
|
-
const row = truncateToWidth(`${prefix}${check}${
|
|
471
|
+
const title = item.done
|
|
472
|
+
? theme.style(item.title, { fg: "muted", strikethrough: true })
|
|
473
|
+
: item.title;
|
|
474
|
+
const row = truncateToWidth(`${prefix}${check}${title}${blocker}`, width);
|
|
451
475
|
lines.push(selected ? theme.style(row, { bg: "selectedBg" }) : row);
|
|
476
|
+
if (item.description.length > 0) {
|
|
477
|
+
// The overlay shows the full description; each source line becomes
|
|
478
|
+
// its own row so no embedded newline reaches the renderer.
|
|
479
|
+
for (const descriptionLine of item.description.split("\n")) {
|
|
480
|
+
lines.push(truncateToWidth(` ${theme.fg("dim", descriptionLine)}`, width));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
452
483
|
}
|
|
453
484
|
if (activeListFor.items.length > MAX_ITEMS) {
|
|
454
485
|
lines.push(
|
|
@@ -467,8 +498,8 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
467
498
|
input.kind === "newList"
|
|
468
499
|
? "New list name"
|
|
469
500
|
: input.kind === "addItem"
|
|
470
|
-
? "Item
|
|
471
|
-
: "Edit item
|
|
501
|
+
? "Item title"
|
|
502
|
+
: "Edit item title";
|
|
472
503
|
lines.push(truncateToWidth(` ${theme.fg("accent", `${prompt}:`)} ${input.buffer}▌`, width));
|
|
473
504
|
lines.push(truncateToWidth(` ${theme.fg("dim", "enter confirm · esc cancel")}`, width));
|
|
474
505
|
} else if (error) {
|
|
@@ -481,10 +512,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
481
512
|
|
|
482
513
|
// Help
|
|
483
514
|
lines.push("");
|
|
515
|
+
const move = options.vim?.enabled ? "[↑↓←→/hjkl] move" : "[↑↓←→] move";
|
|
484
516
|
const help =
|
|
485
517
|
mode === "lists"
|
|
486
|
-
?
|
|
487
|
-
:
|
|
518
|
+
? `[tab] items · [n] new · [d] delete · [c] copy · [space] toggle · ${move} · [enter] active · [esc] close`
|
|
519
|
+
: `[tab] lists · [a] add · [x] toggle · [e] edit · [r] remove · [c] copy · ${move} · [esc] close`;
|
|
488
520
|
lines.push(truncateToWidth(` ${theme.fg("dim", help)}`, width));
|
|
489
521
|
|
|
490
522
|
cachedWidth = width;
|
|
@@ -534,6 +566,27 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
534
566
|
);
|
|
535
567
|
};
|
|
536
568
|
|
|
569
|
+
/**
|
|
570
|
+
* Apply a router movement intent. Up/down move the cursor of the focused
|
|
571
|
+
* pane; left/right switch panes, so h/l mirror Tab.
|
|
572
|
+
*/
|
|
573
|
+
const applyNavigation = (intent: NavigationIntent, state: TrackerState): void => {
|
|
574
|
+
if (intent.dir === "up" || intent.dir === "down") {
|
|
575
|
+
const step = intent.dir === "down" ? 1 : -1;
|
|
576
|
+
if (mode === "lists") {
|
|
577
|
+
const count = state.lists.length;
|
|
578
|
+
if (count > 0) listIndex = wrap(listIndex + step, count);
|
|
579
|
+
} else {
|
|
580
|
+
const list = activeList(state);
|
|
581
|
+
const count = list ? orderedItems(list).length : 0;
|
|
582
|
+
if (count > 0) itemIndex = wrap(itemIndex + step, count);
|
|
583
|
+
}
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
mode = intent.dir === "right" ? "items" : "lists";
|
|
587
|
+
syncCursors();
|
|
588
|
+
};
|
|
589
|
+
|
|
537
590
|
const handleListsKey = (data: string, state: TrackerState): boolean => {
|
|
538
591
|
const lists = state.lists;
|
|
539
592
|
if (lists.length === 0) {
|
|
@@ -551,6 +604,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
551
604
|
listIndex = (listIndex + 1) % lists.length;
|
|
552
605
|
return true;
|
|
553
606
|
}
|
|
607
|
+
if (matchesKey(data, Key.right)) {
|
|
608
|
+
mode = "items";
|
|
609
|
+
syncCursors();
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
554
612
|
if (matchesKey(data, Key.enter)) {
|
|
555
613
|
const list = lists[listIndex]!;
|
|
556
614
|
void runAction({ type: "setActive", listId: list.id }, () => {
|
|
@@ -604,6 +662,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
604
662
|
if (items.length > 0) itemIndex = (itemIndex + 1) % items.length;
|
|
605
663
|
return true;
|
|
606
664
|
}
|
|
665
|
+
if (matchesKey(data, Key.left)) {
|
|
666
|
+
mode = "lists";
|
|
667
|
+
syncCursors();
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
607
670
|
if (matchesKey(data, Key.enter) || data === "x") {
|
|
608
671
|
const item = items[itemIndex];
|
|
609
672
|
if (!item) return true;
|
|
@@ -624,7 +687,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
624
687
|
input = {
|
|
625
688
|
kind: "editItem",
|
|
626
689
|
itemId: `${list.name}:${item.id}`,
|
|
627
|
-
buffer: item.
|
|
690
|
+
buffer: item.title,
|
|
628
691
|
};
|
|
629
692
|
return true;
|
|
630
693
|
}
|
|
@@ -641,7 +704,7 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
641
704
|
if (data === "c") {
|
|
642
705
|
const item = items[itemIndex];
|
|
643
706
|
if (!item) return true;
|
|
644
|
-
copyText(`${list.name}:${item.id} ${item.
|
|
707
|
+
copyText(`${list.name}:${item.id} ${item.title}`, `item "${item.title}"`);
|
|
645
708
|
return true;
|
|
646
709
|
}
|
|
647
710
|
return false;
|
|
@@ -659,11 +722,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
659
722
|
current.kind === "newList"
|
|
660
723
|
? { type: "createList", name: current.buffer }
|
|
661
724
|
: current.kind === "addItem"
|
|
662
|
-
? { type: "addItem", listId: current.listId,
|
|
725
|
+
? { type: "addItem", listId: current.listId, title: current.buffer }
|
|
663
726
|
: {
|
|
664
727
|
type: "updateItem",
|
|
665
728
|
itemId: current.itemId,
|
|
666
|
-
patch: {
|
|
729
|
+
patch: { title: current.buffer },
|
|
667
730
|
};
|
|
668
731
|
void runAction(action);
|
|
669
732
|
} else if (matchesKey(data, Key.backspace)) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { Effect, PlatformError } from "effect";
|
|
3
|
+
import * as FileSystem from "effect/FileSystem";
|
|
4
|
+
import { readVimEnabled, VimSettingsService } from "./vim-settings.ts";
|
|
5
|
+
|
|
6
|
+
const TEST_PATH = "/tmp/tracker-vim-test/tui.json";
|
|
7
|
+
|
|
8
|
+
interface MemFs {
|
|
9
|
+
readonly fs: Partial<FileSystem.FileSystem>;
|
|
10
|
+
readonly files: Map<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function makeMemFs(init: Record<string, string> = {}): MemFs {
|
|
14
|
+
const files = new Map<string, string>(Object.entries(init));
|
|
15
|
+
const fs: Partial<FileSystem.FileSystem> = {
|
|
16
|
+
readFileString: (path) =>
|
|
17
|
+
files.has(path)
|
|
18
|
+
? Effect.succeed(files.get(path)!)
|
|
19
|
+
: Effect.fail(
|
|
20
|
+
PlatformError.systemError({
|
|
21
|
+
_tag: "NotFound",
|
|
22
|
+
module: "FileSystem",
|
|
23
|
+
method: "readFileString",
|
|
24
|
+
pathOrDescriptor: path,
|
|
25
|
+
description: "No such file",
|
|
26
|
+
}),
|
|
27
|
+
),
|
|
28
|
+
};
|
|
29
|
+
return { fs, files };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const load = (): Effect.Effect<boolean, never, VimSettingsService> =>
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
const service = yield* VimSettingsService;
|
|
35
|
+
return yield* service.load;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const runWithMem = (
|
|
39
|
+
mem: MemFs,
|
|
40
|
+
program: Effect.Effect<boolean, never, VimSettingsService>,
|
|
41
|
+
): Effect.Effect<boolean, never> =>
|
|
42
|
+
program.pipe(Effect.provide(VimSettingsService.layerTest(TEST_PATH, mem.fs)));
|
|
43
|
+
|
|
44
|
+
it.effect("load returns off when the file is missing", () =>
|
|
45
|
+
Effect.gen(function* () {
|
|
46
|
+
const enabled = yield* runWithMem(makeMemFs(), load());
|
|
47
|
+
assert.strictEqual(enabled, false);
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
it.effect("load returns on when the file stores vim true", () =>
|
|
52
|
+
Effect.gen(function* () {
|
|
53
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: true }) });
|
|
54
|
+
const enabled = yield* runWithMem(mem, load());
|
|
55
|
+
assert.strictEqual(enabled, true);
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
it.effect("load returns off when the file stores vim false", () =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: false }) });
|
|
62
|
+
const enabled = yield* runWithMem(mem, load());
|
|
63
|
+
assert.strictEqual(enabled, false);
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
it.effect("load returns off when vim is not a boolean", () =>
|
|
68
|
+
Effect.gen(function* () {
|
|
69
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: "yes" }) });
|
|
70
|
+
const enabled = yield* runWithMem(mem, load());
|
|
71
|
+
assert.strictEqual(enabled, false);
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
it.effect("load returns off when the file is not valid JSON", () =>
|
|
76
|
+
Effect.gen(function* () {
|
|
77
|
+
const mem = makeMemFs({ [TEST_PATH]: "not json{" });
|
|
78
|
+
const enabled = yield* runWithMem(mem, load());
|
|
79
|
+
assert.strictEqual(enabled, false);
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
it.effect("load returns off when the file is not an object", () =>
|
|
84
|
+
Effect.gen(function* () {
|
|
85
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify([true]) });
|
|
86
|
+
const enabled = yield* runWithMem(mem, load());
|
|
87
|
+
assert.strictEqual(enabled, false);
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
it("readVimEnabled reads only a boolean vim key", () => {
|
|
92
|
+
assert.strictEqual(readVimEnabled({ vim: true }), true);
|
|
93
|
+
assert.strictEqual(readVimEnabled({ vim: false }), false);
|
|
94
|
+
assert.strictEqual(readVimEnabled({ vim: 1 }), false);
|
|
95
|
+
assert.strictEqual(readVimEnabled({}), false);
|
|
96
|
+
assert.strictEqual(readVimEnabled(null), false);
|
|
97
|
+
assert.strictEqual(readVimEnabled("vim"), false);
|
|
98
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option, Predicate, Schema } from "effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The tracker's reader of the shared TUI settings file's `vim` toggle. The
|
|
6
|
+
* toggle gates h/j/k/l navigation in the `/tracker` overlay. It fails closed:
|
|
7
|
+
* a missing, unreadable, or malformed value reads as off, so the overlay keeps
|
|
8
|
+
* its arrow-only behavior.
|
|
9
|
+
*
|
|
10
|
+
* The file is owned by `packages/tui/src/config.ts`; the tracker only reads the
|
|
11
|
+
* one key. The caller passes the path, so the tracker never re-declares the
|
|
12
|
+
* file name.
|
|
13
|
+
*/
|
|
14
|
+
export const VIM_KEY = "vim";
|
|
15
|
+
|
|
16
|
+
const FileSchema = Schema.fromJsonString(Schema.Unknown);
|
|
17
|
+
const BooleanSchema = Schema.Boolean;
|
|
18
|
+
|
|
19
|
+
/** The `vim` boolean, or `false` when the value is absent or not a boolean. */
|
|
20
|
+
export const readVimEnabled = (parsed: unknown): boolean => {
|
|
21
|
+
if (!Predicate.isObject(parsed)) return false;
|
|
22
|
+
const raw = Predicate.hasProperty(VIM_KEY)(parsed) ? parsed[VIM_KEY] : undefined;
|
|
23
|
+
return Option.getOrElse(Schema.decodeUnknownOption(BooleanSchema)(raw), () => false);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class VimSettingsService extends Context.Service<
|
|
27
|
+
VimSettingsService,
|
|
28
|
+
{
|
|
29
|
+
readonly path: string;
|
|
30
|
+
/** Never fails: every read, parse, or shape problem yields `false` (off). */
|
|
31
|
+
readonly load: Effect.Effect<boolean>;
|
|
32
|
+
}
|
|
33
|
+
>()("tracker/VimSettings") {
|
|
34
|
+
static make(path: string): Layer.Layer<VimSettingsService, never, FileSystem.FileSystem> {
|
|
35
|
+
return Layer.effect(
|
|
36
|
+
VimSettingsService,
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
const fs = yield* FileSystem.FileSystem;
|
|
39
|
+
const load = Effect.gen(function* () {
|
|
40
|
+
const raw = yield* fs.readFileString(path);
|
|
41
|
+
// `Schema.Unknown` accepts any JSON value; `readVimEnabled` narrows it.
|
|
42
|
+
const parsed = yield* Schema.decodeEffect(FileSchema)(raw);
|
|
43
|
+
return readVimEnabled(parsed);
|
|
44
|
+
}).pipe(
|
|
45
|
+
Effect.catchCause(() =>
|
|
46
|
+
Effect.logWarning("tracker: vim setting unreadable, using off").pipe(Effect.as(false)),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
return VimSettingsService.of({ path, load });
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static readonly layerTest = (
|
|
55
|
+
path: string,
|
|
56
|
+
fileSystem: Partial<FileSystem.FileSystem>,
|
|
57
|
+
): Layer.Layer<VimSettingsService> =>
|
|
58
|
+
VimSettingsService.make(path).pipe(Layer.provide(FileSystem.layerNoop(fileSystem)));
|
|
59
|
+
}
|