@ftrdotdev/pi-tracker 0.7.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.
- package/CHANGELOG.md +369 -0
- package/README.md +88 -9
- package/package.json +27 -16
- package/src/compaction/candidate.test.ts +66 -125
- package/src/compaction/classifier.test.ts +22 -2
- package/src/compaction/classifier.ts +35 -22
- package/src/compaction/completion.test.ts +24 -16
- package/src/compaction/completion.ts +1 -1
- package/src/compaction/decision-record.test.ts +1 -1
- package/src/compaction/decision-record.ts +1 -1
- package/src/compaction/digest.test.ts +34 -34
- package/src/compaction/footprint.ts +2 -4
- package/src/compaction/settings.test.ts +5 -1
- package/src/compaction/settings.ts +1 -1
- package/src/compaction/settle.test.ts +50 -10
- package/src/compaction/settle.ts +5 -5
- package/src/core/deps.test.ts +128 -109
- package/src/core/deps.ts +3 -2
- package/src/core/domain.test.ts +99 -68
- package/src/core/domain.ts +16 -10
- package/src/core/persistence.test.ts +18 -19
- package/src/core/persistence.ts +4 -3
- package/src/core/store.test.ts +129 -167
- package/src/core/store.ts +77 -57
- package/src/harness-collection.test.ts +75 -0
- package/src/index.test.ts +59 -17
- package/src/index.ts +63 -64
- package/src/layers.test.ts +101 -0
- package/src/layers.ts +46 -0
- package/src/presentation/tool-metadata.test.ts +36 -38
- package/src/presentation/tool-metadata.ts +127 -130
- package/src/presentation/ui.test.ts +128 -67
- package/src/presentation/ui.ts +68 -20
- package/src/presentation/vim-settings.test.ts +101 -0
- package/src/presentation/vim-settings.ts +59 -0
package/src/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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";
|
|
5
|
-
import
|
|
6
|
-
import { Effect, Layer, ManagedRuntime, Option, Result } from "effect";
|
|
4
|
+
import { makeBorderedBox, VimRouter } from "@ftrdotdev/pi-tui";
|
|
5
|
+
import { Effect, Option, Result } from "effect";
|
|
7
6
|
import { join } from "node:path";
|
|
8
|
-
import { ClassifierGateway } from "./compaction/classifier.ts";
|
|
9
7
|
import { CompletionObserver } from "./compaction/completion.ts";
|
|
10
8
|
import { DECISION_CUSTOM_TYPE, encodeDecisionRecord } from "./compaction/decision-record.ts";
|
|
11
9
|
import { FootprintRecorder, productionProbe, type ToolEvent } from "./compaction/footprint.ts";
|
|
@@ -18,10 +16,7 @@ import {
|
|
|
18
16
|
import { TodoItem, TodoList, TrackerState, emptyState, encodeState } from "./core/domain.ts";
|
|
19
17
|
import { TrackerPersistence } from "./core/persistence.ts";
|
|
20
18
|
import { SMART_COMPACTION_CUSTOM_TYPE } from "./compaction/pointer.ts";
|
|
21
|
-
import {
|
|
22
|
-
SMART_COMPACTION_CONFIG_FILE,
|
|
23
|
-
SmartCompactionSettingsService,
|
|
24
|
-
} from "./compaction/settings.ts";
|
|
19
|
+
import { SMART_COMPACTION_CONFIG_FILE } from "./compaction/settings.ts";
|
|
25
20
|
import { SettleDecider } from "./compaction/settle.ts";
|
|
26
21
|
import { TrackerError, TrackerStore, type ItemSpec, type UpdateItemPatch } from "./core/store.ts";
|
|
27
22
|
import {
|
|
@@ -42,9 +37,8 @@ import {
|
|
|
42
37
|
readinessSuffix,
|
|
43
38
|
type TrackerUiAction,
|
|
44
39
|
} from "./presentation/ui.ts";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const CUSTOM_TYPE = "tracker/state";
|
|
40
|
+
import { VimSettingsService } from "./presentation/vim-settings.ts";
|
|
41
|
+
import { CUSTOM_TYPE, makeTrackerRuntime } from "./layers.ts";
|
|
48
42
|
|
|
49
43
|
// --------------------------------------------------------------------------
|
|
50
44
|
// Effect bridge
|
|
@@ -74,6 +68,10 @@ const withFootprintRecorder = <A, E>(
|
|
|
74
68
|
f: (recorder: FootprintRecorder["Service"]) => Effect.Effect<A, E>,
|
|
75
69
|
): Effect.Effect<A, E, FootprintRecorder> => Effect.flatMap(FootprintRecorder, f);
|
|
76
70
|
|
|
71
|
+
const withVimSettings = <A, E>(
|
|
72
|
+
f: (settings: VimSettingsService["Service"]) => Effect.Effect<A, E>,
|
|
73
|
+
): Effect.Effect<A, E, VimSettingsService> => Effect.flatMap(VimSettingsService, f);
|
|
74
|
+
|
|
77
75
|
/** The bounded `path`/`command` projection of a tool call's arguments. */
|
|
78
76
|
const boundedArgsOf = (value: unknown): ToolEvent["args"] => {
|
|
79
77
|
if (typeof value !== "object" || value === null) return undefined;
|
|
@@ -100,6 +98,18 @@ const requireParam = <T>(value: T | undefined, name: string): T => {
|
|
|
100
98
|
return value;
|
|
101
99
|
};
|
|
102
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Render one loose `title` field for the call summary. Args can come from failed
|
|
103
|
+
* validation, so a non-string title renders empty instead of `[object Object]`.
|
|
104
|
+
*/
|
|
105
|
+
const looseTitle = (entry: unknown): string => {
|
|
106
|
+
if (typeof entry === "object" && entry !== null) {
|
|
107
|
+
const title = (entry as { readonly title?: unknown }).title;
|
|
108
|
+
return typeof title === "string" || typeof title === "number" ? String(title) : "";
|
|
109
|
+
}
|
|
110
|
+
return typeof entry === "string" ? entry : "";
|
|
111
|
+
};
|
|
112
|
+
|
|
103
113
|
/** Project the tool's item objects onto the store's item specs. */
|
|
104
114
|
const toItemSpecs = (items: readonly TrackerItemSpec[]): ItemSpec[] =>
|
|
105
115
|
items.map((item) => ({
|
|
@@ -118,22 +128,14 @@ export default function (pi: ExtensionAPI): void {
|
|
|
118
128
|
// The settings path is resolved inside the factory, so a test can point
|
|
119
129
|
// ENV_AGENT_DIR at a temp directory before `tracker(api)` runs.
|
|
120
130
|
const probe = productionProbe();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
SettleDecider.layer(probe).pipe(
|
|
130
|
-
Layer.provideMerge(Layer.mergeAll(TrackerStore.layer, decisionServices)),
|
|
131
|
-
Layer.provideMerge(
|
|
132
|
-
TrackerPersistence.layer((encoded) => pi.appendEntry(CUSTOM_TYPE, encoded)),
|
|
133
|
-
),
|
|
134
|
-
Layer.provide(NodeFileSystem.layer),
|
|
135
|
-
),
|
|
136
|
-
);
|
|
131
|
+
// One shared config path: the smart-compaction reader and the vim reader both
|
|
132
|
+
// read `tui.json`, owned by the TUI package.
|
|
133
|
+
const configPath = join(getAgentDir(), SMART_COMPACTION_CONFIG_FILE);
|
|
134
|
+
const runtime = makeTrackerRuntime({
|
|
135
|
+
appendEntry: (type, data) => pi.appendEntry(type, data),
|
|
136
|
+
configPath,
|
|
137
|
+
probe,
|
|
138
|
+
});
|
|
137
139
|
|
|
138
140
|
/** Mirror of the store state, read by the widget and tool renderers. */
|
|
139
141
|
let state: TrackerState = emptyState();
|
|
@@ -315,7 +317,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
315
317
|
ctx.ui.notify("tracker: saved state could not be decoded — starting empty", "warning");
|
|
316
318
|
state = emptyState();
|
|
317
319
|
} else {
|
|
318
|
-
state =
|
|
320
|
+
state = Result.getSuccess(result).pipe(Option.getOrThrow);
|
|
319
321
|
}
|
|
320
322
|
}
|
|
321
323
|
await runtime.runPromise(withStore((store) => store.reset(state)));
|
|
@@ -399,7 +401,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
399
401
|
if (decision.kind !== "compact") return;
|
|
400
402
|
// The run signal can fire after the verdict, while the classifier is the
|
|
401
403
|
// last thing between here and compaction. An abort keeps the context.
|
|
402
|
-
if (ctx.signal?.aborted) return;
|
|
404
|
+
if (ctx.signal?.aborted ?? false) return;
|
|
403
405
|
const pointer = decision.pointer;
|
|
404
406
|
// Delivery comes from pi's completion contract, which fires only after
|
|
405
407
|
// compaction has finished. `deliver` is idempotent, so a double callback
|
|
@@ -541,7 +543,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
541
543
|
text = "Active list cleared (widget hidden)";
|
|
542
544
|
} else {
|
|
543
545
|
const list = current.lists.find((l) => l.id === params.list_id);
|
|
544
|
-
text = `Active list: ${list ? list.name : `#${params.list_id}`}`;
|
|
546
|
+
text = `Active list: ${list !== undefined ? list.name : `#${params.list_id}`}`;
|
|
545
547
|
}
|
|
546
548
|
break;
|
|
547
549
|
}
|
|
@@ -550,7 +552,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
550
552
|
const list = current.lists.find((l) => l.id === params.list_id);
|
|
551
553
|
details.list = list;
|
|
552
554
|
details.items = items;
|
|
553
|
-
const listName = list ? list.name : `#${params.list_id}`;
|
|
555
|
+
const listName = list !== undefined ? list.name : `#${params.list_id}`;
|
|
554
556
|
// The store assigned each new item its id; report those.
|
|
555
557
|
const ids = items.map((item) => `${listName}:${item.id}`);
|
|
556
558
|
text =
|
|
@@ -575,18 +577,18 @@ export default function (pi: ExtensionAPI): void {
|
|
|
575
577
|
batch !== undefined
|
|
576
578
|
? batch.map((p) => ({
|
|
577
579
|
id: p.item_id,
|
|
578
|
-
title: p.title,
|
|
579
|
-
description: p.description,
|
|
580
|
-
done: p.done,
|
|
581
|
-
deps: p.deps,
|
|
580
|
+
...(p.title === undefined ? {} : { title: p.title }),
|
|
581
|
+
...(p.description === undefined ? {} : { description: p.description }),
|
|
582
|
+
...(p.done === undefined ? {} : { done: p.done }),
|
|
583
|
+
...(p.deps === undefined ? {} : { deps: p.deps }),
|
|
582
584
|
}))
|
|
583
585
|
: [
|
|
584
586
|
{
|
|
585
587
|
id: params.item_id ?? "?",
|
|
586
|
-
|
|
587
|
-
description: params.description,
|
|
588
|
-
done: params.done,
|
|
589
|
-
deps: params.deps,
|
|
588
|
+
...(typeof params.title === "string" ? { title: params.title } : {}),
|
|
589
|
+
...(params.description === undefined ? {} : { description: params.description }),
|
|
590
|
+
...(params.done === undefined ? {} : { done: params.done }),
|
|
591
|
+
...(params.deps === undefined ? {} : { deps: params.deps }),
|
|
590
592
|
},
|
|
591
593
|
];
|
|
592
594
|
const parts = items.map((item, i) => {
|
|
@@ -638,7 +640,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
638
640
|
pi.registerTool({
|
|
639
641
|
...TRACKER_TOOL_METADATA,
|
|
640
642
|
|
|
641
|
-
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
643
|
+
async execute(_toolCallId, params: TrackerToolParams, _signal, _onUpdate, ctx) {
|
|
642
644
|
const action = params.action;
|
|
643
645
|
// Error-nudging gate: reject incorrect calls (missing required fields,
|
|
644
646
|
// unknown fields, mixed update_items forms) with a precise message that
|
|
@@ -663,10 +665,10 @@ export default function (pi: ExtensionAPI): void {
|
|
|
663
665
|
|
|
664
666
|
const result = await runtime.runPromise(Effect.result(program));
|
|
665
667
|
if (Result.isFailure(result)) {
|
|
666
|
-
const failure =
|
|
668
|
+
const failure = Result.getFailure(result).pipe(Option.getOrThrow);
|
|
667
669
|
return toolError(action, failure.message);
|
|
668
670
|
}
|
|
669
|
-
const value =
|
|
671
|
+
const value = Result.getSuccess(result).pipe(Option.getOrThrow);
|
|
670
672
|
// `list` reports the store state it just read; a mutation reports the
|
|
671
673
|
// state it persisted. Both are authoritative, so no result depends on
|
|
672
674
|
// the widget mirror.
|
|
@@ -677,34 +679,19 @@ export default function (pi: ExtensionAPI): void {
|
|
|
677
679
|
renderCall(args, theme, _context) {
|
|
678
680
|
// Args can come from failed validation too, so read them loosely.
|
|
679
681
|
const raw = args as unknown as Record<string, unknown>;
|
|
680
|
-
const action =
|
|
682
|
+
const action = typeof raw.action === "string" ? raw.action : "list";
|
|
681
683
|
let text =
|
|
682
684
|
theme.style("tracker ", { fg: "toolTitle", bold: true }) + theme.fg("muted", action);
|
|
683
685
|
if (typeof raw.name === "string") text += ` ${theme.fg("dim", `"${raw.name}"`)}`;
|
|
684
686
|
if (typeof raw.title === "string") {
|
|
685
687
|
text += ` ${theme.fg("dim", `"${raw.title}"`)}`;
|
|
686
688
|
} else if (Array.isArray(raw.title)) {
|
|
687
|
-
text += ` ${theme.fg(
|
|
688
|
-
"dim",
|
|
689
|
-
raw.title
|
|
690
|
-
.map((entry) =>
|
|
691
|
-
typeof entry === "string"
|
|
692
|
-
? `"${entry}"`
|
|
693
|
-
: `"${String((entry as { title?: unknown }).title ?? "")}"`,
|
|
694
|
-
)
|
|
695
|
-
.join(" "),
|
|
696
|
-
)}`;
|
|
689
|
+
text += ` ${theme.fg("dim", raw.title.map((entry) => `"${looseTitle(entry)}"`).join(" "))}`;
|
|
697
690
|
}
|
|
698
691
|
if (Array.isArray(raw.initial_items)) {
|
|
699
692
|
text += ` ${theme.fg(
|
|
700
693
|
"dim",
|
|
701
|
-
raw.initial_items
|
|
702
|
-
.map((entry) =>
|
|
703
|
-
typeof entry === "string"
|
|
704
|
-
? `"${entry}"`
|
|
705
|
-
: `"${String((entry as { title?: unknown }).title ?? "")}"`,
|
|
706
|
-
)
|
|
707
|
-
.join(" "),
|
|
694
|
+
raw.initial_items.map((entry) => `"${looseTitle(entry)}"`).join(" "),
|
|
708
695
|
)}`;
|
|
709
696
|
}
|
|
710
697
|
if (Array.isArray(raw.items)) text += ` ${theme.fg("accent", `${raw.items.length} items`)}`;
|
|
@@ -716,16 +703,16 @@ export default function (pi: ExtensionAPI): void {
|
|
|
716
703
|
|
|
717
704
|
renderResult(result, { expanded }, theme, _context) {
|
|
718
705
|
const details = result.details as TrackerToolDetails | undefined;
|
|
719
|
-
if (
|
|
706
|
+
if (details === undefined) {
|
|
720
707
|
const text = result.content[0];
|
|
721
708
|
return new Text(text?.type === "text" ? text.text : "", 0, 0);
|
|
722
709
|
}
|
|
723
|
-
if (details.error) {
|
|
710
|
+
if (details.error !== undefined && details.error !== "") {
|
|
724
711
|
return new Text(theme.fg("error", `Error: ${details.error}`), 0, 0);
|
|
725
712
|
}
|
|
726
713
|
if (details.action === "list") {
|
|
727
714
|
const snapshot = details.snapshot;
|
|
728
|
-
if (
|
|
715
|
+
if (snapshot === undefined || snapshot.lists.length === 0) {
|
|
729
716
|
return new Text(theme.fg("dim", "No lists"), 0, 0);
|
|
730
717
|
}
|
|
731
718
|
const parts: string[] = [];
|
|
@@ -772,7 +759,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
772
759
|
): Promise<string | null> => {
|
|
773
760
|
const result = await runtime.runPromise(Effect.result(uiActionProgram(action)));
|
|
774
761
|
if (Result.isFailure(result)) {
|
|
775
|
-
return
|
|
762
|
+
return Result.getFailure(result).pipe(Option.getOrThrow).message;
|
|
776
763
|
}
|
|
777
764
|
await applyMutation(ctx);
|
|
778
765
|
return null;
|
|
@@ -785,6 +772,17 @@ export default function (pi: ExtensionAPI): void {
|
|
|
785
772
|
ctx.ui.notify("/tracker requires interactive mode", "error");
|
|
786
773
|
return;
|
|
787
774
|
}
|
|
775
|
+
// Read the shared `vim` toggle and build the gated router once, before
|
|
776
|
+
// the modal opens: h/j/k/l then work only when vim mode is on, and the
|
|
777
|
+
// overlay's help line reports which keys are live.
|
|
778
|
+
const vimEnabled = await runtime.runPromise(withVimSettings((settings) => settings.load));
|
|
779
|
+
const vim = {
|
|
780
|
+
router: Effect.service(VimRouter).pipe(
|
|
781
|
+
Effect.provide(VimRouter.make(() => vimEnabled)),
|
|
782
|
+
Effect.runSync,
|
|
783
|
+
),
|
|
784
|
+
enabled: vimEnabled,
|
|
785
|
+
};
|
|
788
786
|
await ctx.ui.custom<void>((tui, theme, _kb, done) => {
|
|
789
787
|
// The overlay content is framed by the same house rounded box as the
|
|
790
788
|
// widget. makeBorderedBox's own cache is disabled so an overlay
|
|
@@ -796,6 +794,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
796
794
|
requestRender: () => tui.requestRender(),
|
|
797
795
|
onAction: (action) => runUiAction(ctx, action),
|
|
798
796
|
onClose: () => done(),
|
|
797
|
+
vim,
|
|
799
798
|
});
|
|
800
799
|
const framed = makeBorderedBox(overlay, theme, {
|
|
801
800
|
label: "Tracker",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { containsSymbol, type FileProbe } from "./compaction/observations.ts";
|
|
4
|
+
import { emptyState, encodeState } from "./core/domain.ts";
|
|
5
|
+
import { TrackerPersistence } from "./core/persistence.ts";
|
|
6
|
+
import { TrackerStore } from "./core/store.ts";
|
|
7
|
+
import { CUSTOM_TYPE, makeTrackerRuntime, type TrackerRuntimeDeps } from "./layers.ts";
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// makeTrackerRuntime — the tracker package's one composition point. Moving the
|
|
11
|
+
// graph out of the bridge must not change what it serves (Slice 7).
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
/** A probe over a path-to-text map, the same double the settle tests use. */
|
|
15
|
+
const probeOf = (files: Readonly<Record<string, string>>): FileProbe => ({
|
|
16
|
+
read: (path) => files[path],
|
|
17
|
+
findSymbol: (symbol) =>
|
|
18
|
+
Object.entries(files)
|
|
19
|
+
.filter(([, text]) => containsSymbol(text, symbol))
|
|
20
|
+
.map(([path]) => path),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const depsOver = (
|
|
24
|
+
appendEntry: (type: string, data: unknown) => void,
|
|
25
|
+
probe: FileProbe = probeOf({}),
|
|
26
|
+
): TrackerRuntimeDeps => ({
|
|
27
|
+
appendEntry,
|
|
28
|
+
configPath: "/tmp/x/compaction.json",
|
|
29
|
+
probe,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it.effect("the composed runtime serves the store and the decision services", () => {
|
|
33
|
+
// Arrange
|
|
34
|
+
const runtime = makeTrackerRuntime(depsOver(() => {}));
|
|
35
|
+
|
|
36
|
+
// Act
|
|
37
|
+
const program = Effect.flatMap(TrackerStore, (store) => store.createList("Work"));
|
|
38
|
+
|
|
39
|
+
// Assert
|
|
40
|
+
return Effect.promise(() => runtime.runPromise(program)).pipe(
|
|
41
|
+
Effect.tap((list) => Effect.sync(() => assert.strictEqual(list.id, 1))),
|
|
42
|
+
Effect.asVoid,
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.effect("the persistence layer keeps its injected append boundary", () => {
|
|
47
|
+
// Arrange: a recording append, one state to round-trip.
|
|
48
|
+
const appends: Array<{ type: string; data: unknown }> = [];
|
|
49
|
+
const runtime = makeTrackerRuntime(
|
|
50
|
+
depsOver((type, data) => {
|
|
51
|
+
appends.push({ type, data });
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
const state = emptyState();
|
|
55
|
+
|
|
56
|
+
// Act
|
|
57
|
+
const program = Effect.gen(function* () {
|
|
58
|
+
const persistence = yield* TrackerPersistence;
|
|
59
|
+
yield* persistence.save(state);
|
|
60
|
+
return yield* persistence.restore(encodeState(state));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Assert: exactly one append, and the restored state matches.
|
|
64
|
+
return Effect.promise(() => runtime.runPromise(program)).pipe(
|
|
65
|
+
Effect.tap((restored) =>
|
|
66
|
+
Effect.sync(() => {
|
|
67
|
+
assert.strictEqual(appends.length, 1);
|
|
68
|
+
assert.strictEqual(appends[0]?.type, CUSTOM_TYPE);
|
|
69
|
+
assert.deepStrictEqual(restored, state);
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
Effect.asVoid,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("the factory builds nothing until first use", () => {
|
|
77
|
+
// Arrange: recording boundary doubles, but no runPromise.
|
|
78
|
+
const calls: string[] = [];
|
|
79
|
+
const appends: string[] = [];
|
|
80
|
+
const probe: FileProbe = {
|
|
81
|
+
read: (path) => {
|
|
82
|
+
calls.push(path);
|
|
83
|
+
return undefined;
|
|
84
|
+
},
|
|
85
|
+
findSymbol: (symbol) => {
|
|
86
|
+
calls.push(symbol);
|
|
87
|
+
return [];
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Act
|
|
92
|
+
makeTrackerRuntime(
|
|
93
|
+
depsOver((type) => {
|
|
94
|
+
appends.push(type);
|
|
95
|
+
}, probe),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Assert: the runtime is lazy, so construction touched nothing.
|
|
99
|
+
assert.deepStrictEqual(calls, []);
|
|
100
|
+
assert.deepStrictEqual(appends, []);
|
|
101
|
+
});
|
package/src/layers.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
2
|
+
import { Layer, ManagedRuntime } from "effect";
|
|
3
|
+
import { ClassifierGateway } from "./compaction/classifier.ts";
|
|
4
|
+
import { CompletionObserver } from "./compaction/completion.ts";
|
|
5
|
+
import { FootprintRecorder } from "./compaction/footprint.ts";
|
|
6
|
+
import type { FileProbe } from "./compaction/observations.ts";
|
|
7
|
+
import { SmartCompactionSettingsService } from "./compaction/settings.ts";
|
|
8
|
+
import { SettleDecider } from "./compaction/settle.ts";
|
|
9
|
+
import { TrackerPersistence } from "./core/persistence.ts";
|
|
10
|
+
import { TrackerStore } from "./core/store.ts";
|
|
11
|
+
import { VimSettingsService } from "./presentation/vim-settings.ts";
|
|
12
|
+
|
|
13
|
+
/** Custom-entry type used to persist the tracker state in the session. */
|
|
14
|
+
export const CUSTOM_TYPE = "tracker/state";
|
|
15
|
+
|
|
16
|
+
/** The boundary inputs the tracker bridge supplies (append, config path, probe). */
|
|
17
|
+
export interface TrackerRuntimeDeps {
|
|
18
|
+
readonly appendEntry: (type: string, data: unknown) => void;
|
|
19
|
+
readonly configPath: string;
|
|
20
|
+
readonly probe: FileProbe;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Every decision service, composed once from the bridge's boundary inputs. */
|
|
24
|
+
const decisionServices = (deps: TrackerRuntimeDeps) =>
|
|
25
|
+
Layer.mergeAll(
|
|
26
|
+
CompletionObserver.layer,
|
|
27
|
+
ClassifierGateway.layer,
|
|
28
|
+
FootprintRecorder.layer(deps.probe),
|
|
29
|
+
SmartCompactionSettingsService.make(deps.configPath),
|
|
30
|
+
VimSettingsService.make(deps.configPath),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The tracker package's one composition point: the store, the decision services
|
|
35
|
+
* and the injected persistence append, built lazily on first use.
|
|
36
|
+
*/
|
|
37
|
+
export const makeTrackerRuntime = (deps: TrackerRuntimeDeps) =>
|
|
38
|
+
ManagedRuntime.make(
|
|
39
|
+
SettleDecider.layer(deps.probe).pipe(
|
|
40
|
+
Layer.provideMerge(Layer.mergeAll(TrackerStore.layer, decisionServices(deps))),
|
|
41
|
+
Layer.provideMerge(
|
|
42
|
+
TrackerPersistence.layer((encoded) => deps.appendEntry(CUSTOM_TYPE, encoded)),
|
|
43
|
+
),
|
|
44
|
+
Layer.provide(NodeFileSystem.layer),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
import { TodoItem, TodoList, TrackerState
|
|
2
|
+
import { compile } from "@earendil-works/pi-schema";
|
|
3
|
+
import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
|
|
4
4
|
import {
|
|
5
5
|
TOOL_ACTIONS,
|
|
6
6
|
TRACKER_TOOL_METADATA,
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
validateTrackerCall,
|
|
13
13
|
} from "./tool-metadata.ts";
|
|
14
14
|
|
|
15
|
+
const paramsCheck = compile(TrackerToolParams);
|
|
16
|
+
|
|
15
17
|
describe("tracker tool parameter schema", () => {
|
|
16
18
|
it("accepts valid parameters for every action", () => {
|
|
17
19
|
const valid: Array<Record<string, unknown>> = [
|
|
@@ -48,59 +50,55 @@ describe("tracker tool parameter schema", () => {
|
|
|
48
50
|
{ action: "remove_item", item_id: "Work:2" },
|
|
49
51
|
];
|
|
50
52
|
for (const params of valid) {
|
|
51
|
-
expect(
|
|
53
|
+
expect(paramsCheck.check(params), JSON.stringify(params)).toBe(true);
|
|
52
54
|
}
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
it("rejects unknown actions", () => {
|
|
56
|
-
expect(
|
|
57
|
-
expect(
|
|
58
|
+
expect(paramsCheck.check({ action: "bogus" })).toBe(false);
|
|
59
|
+
expect(paramsCheck.check({})).toBe(false);
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
it("rejects wrong parameter types", () => {
|
|
61
63
|
expect(
|
|
62
|
-
|
|
64
|
+
paramsCheck.check({
|
|
63
65
|
action: "add_items",
|
|
64
66
|
list_id: "one",
|
|
65
67
|
items: [{ title: "x" }],
|
|
66
68
|
}),
|
|
67
69
|
).toBe(false);
|
|
68
|
-
expect(
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
72
|
-
Value.Check(TrackerToolParams, { action: "add_items", list_id: 1, items: [1, "x"] }),
|
|
73
|
-
).toBe(false);
|
|
70
|
+
expect(paramsCheck.check({ action: "create_list", name: 42 })).toBe(false);
|
|
71
|
+
expect(paramsCheck.check({ action: "create_list", activate: "yes" })).toBe(false);
|
|
72
|
+
expect(paramsCheck.check({ action: "update_items", done: "yes" })).toBe(false);
|
|
73
|
+
expect(paramsCheck.check({ action: "add_items", list_id: 1, items: [1, "x"] })).toBe(false);
|
|
74
74
|
expect(
|
|
75
|
-
|
|
75
|
+
paramsCheck.check({
|
|
76
76
|
action: "update_items",
|
|
77
77
|
list_id: 1,
|
|
78
78
|
items: [{ item_id: 1, done: "yes" }],
|
|
79
79
|
}),
|
|
80
80
|
).toBe(false);
|
|
81
81
|
expect(
|
|
82
|
-
|
|
82
|
+
paramsCheck.check({
|
|
83
83
|
// index inside the batch is the old positional field; patch objects are strict.
|
|
84
84
|
action: "update_items",
|
|
85
85
|
list_id: 1,
|
|
86
86
|
items: [{ index: 1, done: true }],
|
|
87
87
|
}),
|
|
88
88
|
).toBe(false);
|
|
89
|
-
expect(
|
|
89
|
+
expect(paramsCheck.check({ action: "update_items", item_id: 2 })).toBe(false); // ids are strings
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it("rejects empty batch arrays", () => {
|
|
93
|
-
expect(
|
|
93
|
+
expect(paramsCheck.check({ action: "add_items", list_id: 1, items: [] })).toBe(false);
|
|
94
|
+
expect(paramsCheck.check({ action: "update_items", items: [] })).toBe(false);
|
|
95
|
+
expect(paramsCheck.check({ action: "create_list", name: "Work", initial_items: [] })).toBe(
|
|
94
96
|
false,
|
|
95
97
|
);
|
|
96
|
-
expect(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
).toBe(false);
|
|
100
|
-
expect(
|
|
101
|
-
Value.Check(TrackerToolParams, { action: "create_list", name: "Work", initial_items: [1] }),
|
|
102
|
-
).toBe(false);
|
|
103
|
-
expect(Value.Check(TrackerToolParams, { action: "set_active", list_id: "one" })).toBe(false);
|
|
98
|
+
expect(paramsCheck.check({ action: "create_list", name: "Work", initial_items: [1] })).toBe(
|
|
99
|
+
false,
|
|
100
|
+
);
|
|
101
|
+
expect(paramsCheck.check({ action: "set_active", list_id: "one" })).toBe(false);
|
|
104
102
|
});
|
|
105
103
|
});
|
|
106
104
|
|
|
@@ -376,7 +374,7 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
376
374
|
},
|
|
377
375
|
];
|
|
378
376
|
for (const call of calls) {
|
|
379
|
-
expect(
|
|
377
|
+
expect(paramsCheck.check(call), JSON.stringify(call)).toBe(true);
|
|
380
378
|
expect(validateTrackerCall(call).ok, JSON.stringify(call)).toBe(true);
|
|
381
379
|
}
|
|
382
380
|
});
|
|
@@ -420,7 +418,7 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
420
418
|
{ action: "update_items", list_id: 1, items: [{ item_id: "Work:2", deps: ["Work:1"] }] },
|
|
421
419
|
];
|
|
422
420
|
for (const call of valid) {
|
|
423
|
-
expect(
|
|
421
|
+
expect(paramsCheck.check(call), JSON.stringify(call)).toBe(true);
|
|
424
422
|
const result = validateTrackerCall(call);
|
|
425
423
|
expect(result.ok, JSON.stringify(call)).toBe(true);
|
|
426
424
|
}
|
|
@@ -448,7 +446,7 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
448
446
|
|
|
449
447
|
it("rejects a batch entry that carries both an item_id and a stray index", () => {
|
|
450
448
|
expect(
|
|
451
|
-
|
|
449
|
+
paramsCheck.check({
|
|
452
450
|
action: "update_items",
|
|
453
451
|
list_id: 1,
|
|
454
452
|
items: [{ item_id: "Work:1", index: 1, deps: [] }],
|
|
@@ -490,24 +488,24 @@ describe("blockedDoneNote (advisory done-blocked guard)", () => {
|
|
|
490
488
|
deps: ReadonlyArray<readonly string[]>,
|
|
491
489
|
done: readonly number[],
|
|
492
490
|
): TrackerState =>
|
|
493
|
-
|
|
494
|
-
...emptyState(),
|
|
491
|
+
TrackerState.make({
|
|
495
492
|
lists: [
|
|
496
|
-
|
|
493
|
+
TodoList.make({
|
|
497
494
|
id: 1,
|
|
498
495
|
name: "Work",
|
|
499
496
|
nextItemId: deps.length + 1,
|
|
500
|
-
items: deps.map(
|
|
501
|
-
(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}),
|
|
497
|
+
items: deps.map((itemDeps, index) =>
|
|
498
|
+
TodoItem.make({
|
|
499
|
+
id: index + 1,
|
|
500
|
+
title: `item ${index + 1}`,
|
|
501
|
+
done: done.includes(index),
|
|
502
|
+
deps: itemDeps,
|
|
503
|
+
}),
|
|
508
504
|
),
|
|
509
505
|
}),
|
|
510
506
|
],
|
|
507
|
+
activeListId: null,
|
|
508
|
+
nextListId: 1,
|
|
511
509
|
});
|
|
512
510
|
|
|
513
511
|
it("notes the done dependents of a reopened item", () => {
|