@ftrdotdev/pi-tracker 0.7.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 +83 -9
- package/package.json +18 -11
- package/src/compaction/settle.ts +4 -4
- package/src/index.test.ts +37 -0
- package/src/index.ts +22 -2
- package/src/presentation/ui.test.ts +62 -1
- package/src/presentation/ui.ts +48 -3
- package/src/presentation/vim-settings.test.ts +98 -0
- package/src/presentation/vim-settings.ts +59 -0
package/README.md
CHANGED
|
@@ -160,6 +160,9 @@ pane for editing.
|
|
|
160
160
|
| ------- | -------------------------------------- |
|
|
161
161
|
| `tab` | Switch between the lists and the items |
|
|
162
162
|
| `↑` `↓` | Move the cursor |
|
|
163
|
+
| `←` `→` | Switch panes |
|
|
164
|
+
| `j` `k` | Move the cursor (vim on) |
|
|
165
|
+
| `h` `l` | Switch panes (vim on) |
|
|
163
166
|
| `enter` | Select a list and open its items |
|
|
164
167
|
| `space` | Toggle the active list |
|
|
165
168
|
| `n` | Create a list |
|
|
@@ -170,6 +173,11 @@ pane for editing.
|
|
|
170
173
|
| `r` | Remove an item |
|
|
171
174
|
| `esc` | Close the view |
|
|
172
175
|
|
|
176
|
+
The `j` `k` `h` `l` keys are the vim navigation motions, and they are live
|
|
177
|
+
only when `vim` is on in the shared `tui.json`. The overlay reads that toggle
|
|
178
|
+
when it opens and shows the vim keys in its help line only when they are
|
|
179
|
+
active. Arrows always work.
|
|
180
|
+
|
|
173
181
|
### The widget
|
|
174
182
|
|
|
175
183
|
The widget shows the active list above the editor. It appears when a list is
|
|
@@ -296,15 +304,81 @@ Registration lives in `package.json` under the `pi` field:
|
|
|
296
304
|
|
|
297
305
|
## Development
|
|
298
306
|
|
|
299
|
-
| Command
|
|
300
|
-
|
|
|
301
|
-
| `bun run test`
|
|
302
|
-
| `bun run test:watch`
|
|
303
|
-
| `bun run typecheck`
|
|
304
|
-
| `bun run lint`
|
|
305
|
-
| `bun run eval:harvest`
|
|
306
|
-
| `bun run eval:
|
|
307
|
-
| `bun run eval:
|
|
307
|
+
| Command | Purpose |
|
|
308
|
+
| ------------------------- | ---------------------------------------------------------- |
|
|
309
|
+
| `bun run test` | Run the test suite (vitest + @effect/vitest) |
|
|
310
|
+
| `bun run test:watch` | Run the test suite in watch mode |
|
|
311
|
+
| `bun run typecheck` | Type check with `tsc --noEmit` |
|
|
312
|
+
| `bun run lint` | Lint with oxlint |
|
|
313
|
+
| `bun run eval:harvest` | Harvest the frozen legacy corpus from local sessions |
|
|
314
|
+
| `bun run eval:harvest:v2` | Harvest only declared-format cases into `evals/data/v2` |
|
|
315
|
+
| `bun run eval:facts` | Freeze the declared facts and print the pre-flight verdict |
|
|
316
|
+
| `bun run eval:sample` | Draw the seeded, quota-based label sample |
|
|
317
|
+
| `bun run eval:review` | Render the corpus as a markdown review pack |
|
|
318
|
+
| `bun run eval:label` | Label the sample in a terminal |
|
|
319
|
+
| `bun run eval:audit` | Replay sampled facts against today's disk |
|
|
320
|
+
| `bun run eval:rules` | Print the rule tables and the promotion gate |
|
|
321
|
+
| `bun run eval:promote` | Add a measured row to `ACCEPTED_RULES` (v2 only) |
|
|
322
|
+
| `bun run eval:answers` | Freeze classifier answers for the sampled heads |
|
|
323
|
+
| `bun run eval:score` | Score a frozen answer file against the labels |
|
|
324
|
+
| `bun run eval:freeze` | Freeze the labeled corpus and write `report.md` |
|
|
325
|
+
|
|
326
|
+
### Eval corpora
|
|
327
|
+
|
|
328
|
+
There are two corpora, and they measure different populations.
|
|
329
|
+
|
|
330
|
+
- `evals/data` is frozen. It holds 1,446 legacy cases and 1,385 labels in three
|
|
331
|
+
timestamp passes (`pass1`, `pass2`, `pass3`). It never measured a declared
|
|
332
|
+
row, so `eval:rules --out evals/data` checks only that the frozen floor
|
|
333
|
+
(`names-batch-output`, `no-visible-link`) is still accepted and names any rule
|
|
334
|
+
this corpus never measured. Do not re-harvest it.
|
|
335
|
+
- `evals/data/v2` is the declared corpus. A case is declared when its raw
|
|
336
|
+
snapshot holds any item with a `description`, `refs`, or `produces` key. The
|
|
337
|
+
gate scores one candidate per decision: the **declared head**, the head
|
|
338
|
+
candidate that carries at least one `refs` or `produces` entry. A head with a
|
|
339
|
+
description only is a control. The gate measures each row against the control
|
|
340
|
+
subset, in two explicit passes (`v2-a`, `v2-b`), and prints `base: thin (n)`
|
|
341
|
+
below 30 controls.
|
|
342
|
+
|
|
343
|
+
Run the declared pipeline in order:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
bun run eval:harvest:v2 --out evals/data/v2 --evidence evals/data/v2-evidence
|
|
347
|
+
bun run eval:facts --out evals/data/v2 --evidence evals/data/v2-evidence
|
|
348
|
+
bun run eval:sample --out evals/data/v2 --seed 7 --evidence evals/data/v2-evidence
|
|
349
|
+
bun run eval:label --out evals/data/v2 --pilot
|
|
350
|
+
bun run eval:label --out evals/data/v2 --pass v2-a
|
|
351
|
+
bun run eval:label --out evals/data/v2 --pass v2-b
|
|
352
|
+
bun run eval:audit --out evals/data/v2 --seed 7 --evidence evals/data/v2-evidence
|
|
353
|
+
bun run eval:rules --out evals/data/v2 --evidence evals/data/v2-evidence
|
|
354
|
+
bun run eval:freeze --out evals/data/v2 --evidence evals/data/v2-evidence
|
|
355
|
+
bun run eval:freeze --out evals/data/v2 --evidence evals/data/v2-evidence --report
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
The pilot sitting labels the 20 pilot cases as ordinary `pilot`-pass labels.
|
|
359
|
+
Each later sitting opens with ten blind repeats of them, written with
|
|
360
|
+
`pilot: true` and excluded from the gate; self-agreement below 90% discards the
|
|
361
|
+
sitting. The pilot never enters the gate.
|
|
362
|
+
|
|
363
|
+
`eval:facts` ends with the pre-flight verdict. When no behavior-changing row can
|
|
364
|
+
reach 10 firings per pass it prints `STOP:` and exits non-zero, so the label run
|
|
365
|
+
never starts against a corpus that cannot promote.
|
|
366
|
+
|
|
367
|
+
`eval:promote --out evals/data/v2` is additive: it writes the union of the
|
|
368
|
+
frozen old floor and the v2 accepted set, minus any row named by an explicit
|
|
369
|
+
`--remove`, minus any row two audit mismatches block. It refuses any corpus whose
|
|
370
|
+
manifest is not the declared format. An abstain row is reported, never promoted.
|
|
371
|
+
|
|
372
|
+
`evals/data/v2-evidence/` is a local audit trail, ignored by git: the manifest,
|
|
373
|
+
the sample ids, the gate cells, the audit rows, and `report.md`. The harvest,
|
|
374
|
+
sample, and audit steps replace each session file name with a stable
|
|
375
|
+
`session-<hash>` alias before they write there, the manifest keeps only list-name
|
|
376
|
+
counts, and the session root becomes `<SESSION-ROOT>`. `evals/data/v2/cases.jsonl`,
|
|
377
|
+
`facts.jsonl`, and `answers.*` stay local because they hold session text.
|
|
378
|
+
|
|
379
|
+
`evals/.gitignore` ignores all of `evals/data/` except `evals/data/synthetic/`.
|
|
380
|
+
`evals/privacy.test.ts` fails when git tracks any other file under `evals/data/`,
|
|
381
|
+
or a legacy `data-v2/` or `v2-evidence/` path.
|
|
308
382
|
|
|
309
383
|
## Project structure
|
|
310
384
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftrdotdev/pi-tracker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Session-persistent todolist extension for Pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect",
|
|
@@ -38,6 +38,13 @@
|
|
|
38
38
|
"test": "vitest run",
|
|
39
39
|
"test:watch": "vitest",
|
|
40
40
|
"eval:harvest": "bun evals/harvest.ts",
|
|
41
|
+
"eval:harvest:v2": "bun evals/harvest.ts --format declared",
|
|
42
|
+
"eval:facts": "bun evals/facts.ts",
|
|
43
|
+
"eval:sample": "bun evals/sample.ts",
|
|
44
|
+
"eval:audit": "bun evals/audit.ts",
|
|
45
|
+
"eval:answers": "bun evals/answers.ts",
|
|
46
|
+
"eval:score": "bun evals/score.ts",
|
|
47
|
+
"eval:freeze": "bun evals/freeze.ts",
|
|
41
48
|
"eval:review": "bun evals/review.ts",
|
|
42
49
|
"eval:label": "bun evals/label.ts",
|
|
43
50
|
"eval:rules": "bun evals/rules.ts",
|
|
@@ -48,21 +55,21 @@
|
|
|
48
55
|
"typecheck": "tsc --noEmit"
|
|
49
56
|
},
|
|
50
57
|
"dependencies": {
|
|
51
|
-
"@effect/platform-node": "4.
|
|
52
|
-
"@effect/platform-node-shared": "4.
|
|
53
|
-
"@ftrdotdev/pi-tui": "^0.
|
|
54
|
-
"effect": "4.
|
|
58
|
+
"@effect/platform-node": "4.1.1",
|
|
59
|
+
"@effect/platform-node-shared": "4.1.1",
|
|
60
|
+
"@ftrdotdev/pi-tui": "^0.8.0",
|
|
61
|
+
"effect": "4.1.1"
|
|
55
62
|
},
|
|
56
63
|
"devDependencies": {
|
|
57
|
-
"@earendil-works/pi-tui": "1.
|
|
58
|
-
"@effect/tsgo": "0.
|
|
59
|
-
"@effect/vitest": "4.
|
|
64
|
+
"@earendil-works/pi-tui": "1.4.0",
|
|
65
|
+
"@effect/tsgo": "0.63.0",
|
|
66
|
+
"@effect/vitest": "4.1.1",
|
|
60
67
|
"@types/bun": "latest",
|
|
61
68
|
"oxfmt": "^0.63.0",
|
|
62
|
-
"oxlint": "1.
|
|
63
|
-
"oxlint-tsgolint": "7.0.
|
|
69
|
+
"oxlint": "1.90.0",
|
|
70
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
64
71
|
"typescript": "7.0.2",
|
|
65
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^5.0.5"
|
|
66
73
|
},
|
|
67
74
|
"peerDependencies": {
|
|
68
75
|
"@earendil-works/pi-ai": "*",
|
package/src/compaction/settle.ts
CHANGED
|
@@ -119,10 +119,10 @@ export class SettleDecider extends Context.Service<
|
|
|
119
119
|
if (routed.verdict === "compact") {
|
|
120
120
|
return withRecord(SETTLE_DECISION.compact(resumePointer(head)));
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
// An observe-only row is reported through the decision record, not
|
|
123
|
+
// the console: Effect's default logger writes to stdout, which pi's
|
|
124
|
+
// TUI redirects to stderr, and the differential renderer never
|
|
125
|
+
// repaints those rows, so a log line would stick in the editor area.
|
|
126
126
|
const verdict = yield* gateway.verdict({
|
|
127
127
|
registry: input.registry,
|
|
128
128
|
enabled: values.enabled,
|
package/src/index.test.ts
CHANGED
|
@@ -240,6 +240,29 @@ const renderList = (
|
|
|
240
240
|
.join("\n")
|
|
241
241
|
.replace(/\s+/g, " ");
|
|
242
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Capture everything the tracker's Effect logger writes while `body` runs.
|
|
245
|
+
* Vitest's console proxy defeats `vi.spyOn`, so replace the methods directly.
|
|
246
|
+
*/
|
|
247
|
+
const captureConsole = async (body: () => Promise<void>): Promise<string[]> => {
|
|
248
|
+
const lines: string[] = [];
|
|
249
|
+
const originalLog = console.log;
|
|
250
|
+
const originalError = console.error;
|
|
251
|
+
console.log = (...args: unknown[]) => {
|
|
252
|
+
lines.push(args.map(String).join(" "));
|
|
253
|
+
};
|
|
254
|
+
console.error = (...args: unknown[]) => {
|
|
255
|
+
lines.push(args.map(String).join(" "));
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
await body();
|
|
259
|
+
} finally {
|
|
260
|
+
console.log = originalLog;
|
|
261
|
+
console.error = originalError;
|
|
262
|
+
}
|
|
263
|
+
return lines;
|
|
264
|
+
};
|
|
265
|
+
|
|
243
266
|
describe("tracker tool bridge", () => {
|
|
244
267
|
it("returns an affected-items array for the scalar update_items form", async () => {
|
|
245
268
|
const harness = await makeHarness();
|
|
@@ -655,6 +678,20 @@ describe("tracker smart-compaction bridge", () => {
|
|
|
655
678
|
expect(harness.compacts).toHaveLength(0);
|
|
656
679
|
});
|
|
657
680
|
|
|
681
|
+
it("writes nothing to the console when an observe-only rule asks the classifier", async () => {
|
|
682
|
+
// The fired row is reported through the decision record. A console log
|
|
683
|
+
// would bypass pi's differential renderer and stick in the editor area.
|
|
684
|
+
const harness = await makeHarness({
|
|
685
|
+
registry: compactRegistry(0.1),
|
|
686
|
+
config: { smartCompaction: { enabled: true } },
|
|
687
|
+
});
|
|
688
|
+
await completeFirst(harness);
|
|
689
|
+
|
|
690
|
+
const lines = await captureConsole(() => harness.settle());
|
|
691
|
+
|
|
692
|
+
expect(lines).toEqual([]);
|
|
693
|
+
});
|
|
694
|
+
|
|
658
695
|
it("a raised needsContextProbabilityThreshold compacts an answer the default would keep", async () => {
|
|
659
696
|
const harness = await makeHarness({
|
|
660
697
|
registry: compactRegistry(0.6),
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Text } from "@earendil-works/pi-tui";
|
|
4
|
-
import { makeBorderedBox } from "@ftrdotdev/pi-tui";
|
|
4
|
+
import { makeBorderedBox, VimRouter } from "@ftrdotdev/pi-tui";
|
|
5
5
|
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
6
6
|
import { Effect, Layer, ManagedRuntime, Option, Result } from "effect";
|
|
7
7
|
import { join } from "node:path";
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
readinessSuffix,
|
|
43
43
|
type TrackerUiAction,
|
|
44
44
|
} from "./presentation/ui.ts";
|
|
45
|
+
import { VimSettingsService } from "./presentation/vim-settings.ts";
|
|
45
46
|
|
|
46
47
|
/** Custom-entry type used to persist the tracker state in the session. */
|
|
47
48
|
const CUSTOM_TYPE = "tracker/state";
|
|
@@ -74,6 +75,10 @@ const withFootprintRecorder = <A, E>(
|
|
|
74
75
|
f: (recorder: FootprintRecorder["Service"]) => Effect.Effect<A, E>,
|
|
75
76
|
): Effect.Effect<A, E, FootprintRecorder> => Effect.flatMap(FootprintRecorder, f);
|
|
76
77
|
|
|
78
|
+
const withVimSettings = <A, E>(
|
|
79
|
+
f: (settings: VimSettingsService["Service"]) => Effect.Effect<A, E>,
|
|
80
|
+
): Effect.Effect<A, E, VimSettingsService> => Effect.flatMap(VimSettingsService, f);
|
|
81
|
+
|
|
77
82
|
/** The bounded `path`/`command` projection of a tool call's arguments. */
|
|
78
83
|
const boundedArgsOf = (value: unknown): ToolEvent["args"] => {
|
|
79
84
|
if (typeof value !== "object" || value === null) return undefined;
|
|
@@ -118,11 +123,15 @@ export default function (pi: ExtensionAPI): void {
|
|
|
118
123
|
// The settings path is resolved inside the factory, so a test can point
|
|
119
124
|
// ENV_AGENT_DIR at a temp directory before `tracker(api)` runs.
|
|
120
125
|
const probe = productionProbe();
|
|
126
|
+
// One shared config path: the smart-compaction reader and the vim reader both
|
|
127
|
+
// read `tui.json`, owned by the TUI package.
|
|
128
|
+
const configPath = join(getAgentDir(), SMART_COMPACTION_CONFIG_FILE);
|
|
121
129
|
const decisionServices = Layer.mergeAll(
|
|
122
130
|
CompletionObserver.layer,
|
|
123
131
|
ClassifierGateway.layer,
|
|
124
132
|
FootprintRecorder.layer(probe),
|
|
125
|
-
SmartCompactionSettingsService.make(
|
|
133
|
+
SmartCompactionSettingsService.make(configPath),
|
|
134
|
+
VimSettingsService.make(configPath),
|
|
126
135
|
);
|
|
127
136
|
|
|
128
137
|
const runtime = ManagedRuntime.make(
|
|
@@ -785,6 +794,16 @@ export default function (pi: ExtensionAPI): void {
|
|
|
785
794
|
ctx.ui.notify("/tracker requires interactive mode", "error");
|
|
786
795
|
return;
|
|
787
796
|
}
|
|
797
|
+
// Read the shared `vim` toggle and build the gated router once, before
|
|
798
|
+
// the modal opens: h/j/k/l then work only when vim mode is on, and the
|
|
799
|
+
// overlay's help line reports which keys are live.
|
|
800
|
+
const vimEnabled = await runtime.runPromise(withVimSettings((settings) => settings.load));
|
|
801
|
+
const vim = {
|
|
802
|
+
router: Effect.runSync(
|
|
803
|
+
Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => vimEnabled))),
|
|
804
|
+
),
|
|
805
|
+
enabled: vimEnabled,
|
|
806
|
+
};
|
|
788
807
|
await ctx.ui.custom<void>((tui, theme, _kb, done) => {
|
|
789
808
|
// The overlay content is framed by the same house rounded box as the
|
|
790
809
|
// widget. makeBorderedBox's own cache is disabled so an overlay
|
|
@@ -796,6 +815,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
796
815
|
requestRender: () => tui.requestRender(),
|
|
797
816
|
onAction: (action) => runUiAction(ctx, action),
|
|
798
817
|
onClose: () => done(),
|
|
818
|
+
vim,
|
|
799
819
|
});
|
|
800
820
|
const framed = makeBorderedBox(overlay, theme, {
|
|
801
821
|
label: "Tracker",
|
|
@@ -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 {
|
|
@@ -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
|
};
|
|
@@ -156,6 +166,57 @@ it("items pane follows the active list in items mode (preview is not a commit)",
|
|
|
156
166
|
assert.match(text, /write plan/);
|
|
157
167
|
});
|
|
158
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
|
+
|
|
159
220
|
// --------------------------------------------------------------------------
|
|
160
221
|
// Render caching (tui.md "Performance" / "Invalidation and Theme Changes")
|
|
161
222
|
// --------------------------------------------------------------------------
|
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,
|
|
@@ -286,6 +286,11 @@ export interface TrackerOverlayOptions {
|
|
|
286
286
|
readonly onClose: () => void;
|
|
287
287
|
/** Write text to the clipboard. Defaults to pi's `copyToClipboard`. */
|
|
288
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 };
|
|
289
294
|
}
|
|
290
295
|
|
|
291
296
|
/** The interactive overlay surface: render + input + cache invalidation. */
|
|
@@ -342,6 +347,14 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
342
347
|
return;
|
|
343
348
|
}
|
|
344
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
|
+
}
|
|
345
358
|
const handled = mode === "lists" ? handleListsKey(data, state) : handleItemsKey(data, state);
|
|
346
359
|
if (handled) {
|
|
347
360
|
error = null;
|
|
@@ -499,10 +512,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
499
512
|
|
|
500
513
|
// Help
|
|
501
514
|
lines.push("");
|
|
515
|
+
const move = options.vim?.enabled ? "[↑↓←→/hjkl] move" : "[↑↓←→] move";
|
|
502
516
|
const help =
|
|
503
517
|
mode === "lists"
|
|
504
|
-
?
|
|
505
|
-
:
|
|
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`;
|
|
506
520
|
lines.push(truncateToWidth(` ${theme.fg("dim", help)}`, width));
|
|
507
521
|
|
|
508
522
|
cachedWidth = width;
|
|
@@ -552,6 +566,27 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
552
566
|
);
|
|
553
567
|
};
|
|
554
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
|
+
|
|
555
590
|
const handleListsKey = (data: string, state: TrackerState): boolean => {
|
|
556
591
|
const lists = state.lists;
|
|
557
592
|
if (lists.length === 0) {
|
|
@@ -569,6 +604,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
569
604
|
listIndex = (listIndex + 1) % lists.length;
|
|
570
605
|
return true;
|
|
571
606
|
}
|
|
607
|
+
if (matchesKey(data, Key.right)) {
|
|
608
|
+
mode = "items";
|
|
609
|
+
syncCursors();
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
572
612
|
if (matchesKey(data, Key.enter)) {
|
|
573
613
|
const list = lists[listIndex]!;
|
|
574
614
|
void runAction({ type: "setActive", listId: list.id }, () => {
|
|
@@ -622,6 +662,11 @@ export const makeTrackerOverlay = (options: TrackerOverlayOptions): TrackerOverl
|
|
|
622
662
|
if (items.length > 0) itemIndex = (itemIndex + 1) % items.length;
|
|
623
663
|
return true;
|
|
624
664
|
}
|
|
665
|
+
if (matchesKey(data, Key.left)) {
|
|
666
|
+
mode = "lists";
|
|
667
|
+
syncCursors();
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
625
670
|
if (matchesKey(data, Key.enter) || data === "x") {
|
|
626
671
|
const item = items[itemIndex];
|
|
627
672
|
if (!item) return true;
|
|
@@ -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
|
+
}
|