@ftrdotdev/pi-tracker 0.5.2 → 0.7.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.
Files changed (39) hide show
  1. package/README.md +136 -46
  2. package/package.json +8 -2
  3. package/src/compaction/candidate.test.ts +191 -0
  4. package/src/compaction/candidate.ts +105 -0
  5. package/src/compaction/classifier.test.ts +422 -0
  6. package/src/compaction/classifier.ts +198 -0
  7. package/src/compaction/completion.test.ts +257 -0
  8. package/src/compaction/completion.ts +94 -0
  9. package/src/compaction/decision-record.test.ts +91 -0
  10. package/src/compaction/decision-record.ts +101 -0
  11. package/src/compaction/digest.test.ts +185 -0
  12. package/src/compaction/digest.ts +158 -0
  13. package/src/compaction/footprint.test.ts +135 -0
  14. package/src/compaction/footprint.ts +387 -0
  15. package/src/compaction/observations.test.ts +199 -0
  16. package/src/compaction/observations.ts +348 -0
  17. package/src/compaction/pointer.test.ts +26 -0
  18. package/src/compaction/pointer.ts +15 -0
  19. package/src/compaction/rules.test.ts +253 -0
  20. package/src/compaction/rules.ts +188 -0
  21. package/src/compaction/settings.test.ts +315 -0
  22. package/src/compaction/settings.ts +185 -0
  23. package/src/compaction/settle.test.ts +370 -0
  24. package/src/compaction/settle.ts +150 -0
  25. package/src/{deps.test.ts → core/deps.test.ts} +1 -1
  26. package/src/{domain.test.ts → core/domain.test.ts} +42 -9
  27. package/src/{domain.ts → core/domain.ts} +73 -8
  28. package/src/{persistence.test.ts → core/persistence.test.ts} +7 -7
  29. package/src/{store.test.ts → core/store.test.ts} +116 -50
  30. package/src/{store.ts → core/store.ts} +92 -31
  31. package/src/index.test.ts +728 -84
  32. package/src/index.ts +237 -49
  33. package/src/{tool-metadata.test.ts → presentation/tool-metadata.test.ts} +264 -49
  34. package/src/presentation/tool-metadata.ts +675 -0
  35. package/src/{ui.test.ts → presentation/ui.test.ts} +128 -9
  36. package/src/{ui.ts → presentation/ui.ts} +123 -30
  37. package/src/tool-metadata.ts +0 -452
  38. /package/src/{deps.ts → core/deps.ts} +0 -0
  39. /package/src/{persistence.ts → core/persistence.ts} +0 -0
@@ -0,0 +1,257 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import { Effect, Option } from "effect";
3
+ import { CompletionObserver, completedInActiveList } from "./completion.ts";
4
+ import { TodoItem, TodoList, TrackerState } from "../core/domain.ts";
5
+
6
+ interface ItemSpec {
7
+ readonly id: number;
8
+ readonly done: boolean;
9
+ readonly deps?: readonly string[];
10
+ }
11
+
12
+ const list = (id: number, name: string, items: readonly ItemSpec[]): TodoList =>
13
+ new TodoList({
14
+ id,
15
+ name,
16
+ items: items.map(
17
+ (item) =>
18
+ new TodoItem({
19
+ id: item.id,
20
+ title: `item ${item.id}`,
21
+ done: item.done,
22
+ deps: [...(item.deps ?? [])],
23
+ }),
24
+ ),
25
+ nextItemId: items.reduce((max, item) => Math.max(max, item.id), 0) + 1,
26
+ });
27
+
28
+ const state = (
29
+ lists: readonly TodoList[],
30
+ activeListId: number | null,
31
+ nextListId = lists.length + 1,
32
+ ): TrackerState => new TrackerState({ lists: [...lists], activeListId, nextListId });
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // completedInActiveList
36
+ // ---------------------------------------------------------------------------
37
+
38
+ it("completedInActiveList returns every item that transitioned from open to done, in list order", () => {
39
+ const before = state(
40
+ [
41
+ list(1, "Work", [
42
+ { id: 1, done: false },
43
+ { id: 3, done: false },
44
+ ]),
45
+ ],
46
+ 1,
47
+ );
48
+ const after = state(
49
+ [
50
+ list(1, "Work", [
51
+ { id: 1, done: true },
52
+ { id: 3, done: true },
53
+ ]),
54
+ ],
55
+ 1,
56
+ );
57
+ assert.deepStrictEqual(completedInActiveList(before, after), [1, 3]);
58
+ });
59
+
60
+ it("completedInActiveList returns a single id for a single completion", () => {
61
+ const before = state([list(1, "Work", [{ id: 1, done: false }])], 1);
62
+ const after = state([list(1, "Work", [{ id: 1, done: true }])], 1);
63
+ assert.deepStrictEqual(completedInActiveList(before, after), [1]);
64
+ });
65
+
66
+ it("completedInActiveList ignores an item that was already done", () => {
67
+ const before = state([list(1, "Work", [{ id: 1, done: true }])], 1);
68
+ const after = state([list(1, "Work", [{ id: 1, done: true }])], 1);
69
+ assert.deepStrictEqual(completedInActiveList(before, after), []);
70
+ });
71
+
72
+ it("completedInActiveList ignores a completion in a list that is not active", () => {
73
+ const before = state(
74
+ [list(1, "Work", [{ id: 1, done: false }]), list(2, "Other", [{ id: 1, done: false }])],
75
+ 1,
76
+ );
77
+ const after = state(
78
+ [list(1, "Work", [{ id: 1, done: false }]), list(2, "Other", [{ id: 1, done: true }])],
79
+ 1,
80
+ );
81
+ assert.deepStrictEqual(completedInActiveList(before, after), []);
82
+ });
83
+
84
+ // ---------------------------------------------------------------------------
85
+ // CompletionObserver
86
+ // ---------------------------------------------------------------------------
87
+
88
+ const withObserver = <A, E>(
89
+ program: Effect.Effect<A, E, CompletionObserver>,
90
+ ): Effect.Effect<A, E> => program.pipe(Effect.provide(CompletionObserver.layer));
91
+
92
+ it.effect("CompletionObserver record folds successive mutations into one batch", () =>
93
+ withObserver(
94
+ Effect.gen(function* () {
95
+ const observer = yield* CompletionObserver;
96
+ const s0 = state(
97
+ [
98
+ list(1, "Work", [
99
+ { id: 1, done: false },
100
+ { id: 3, done: false },
101
+ ]),
102
+ ],
103
+ 1,
104
+ );
105
+ const s1 = state(
106
+ [
107
+ list(1, "Work", [
108
+ { id: 1, done: true },
109
+ { id: 3, done: false },
110
+ ]),
111
+ ],
112
+ 1,
113
+ );
114
+ const s2 = state(
115
+ [
116
+ list(1, "Work", [
117
+ { id: 1, done: true },
118
+ { id: 3, done: true },
119
+ ]),
120
+ ],
121
+ 1,
122
+ );
123
+ yield* observer.record(s0, s1);
124
+ yield* observer.record(s1, s2);
125
+ const batch = Option.getOrThrow(yield* observer.consume);
126
+ assert.deepStrictEqual(batch.completedItemIds, [1, 3]);
127
+ assert.deepStrictEqual(
128
+ batch.list.items.map((item) => item.done),
129
+ [true, true],
130
+ );
131
+ }),
132
+ ),
133
+ );
134
+
135
+ it.effect(
136
+ "CompletionObserver record refreshes the snapshot when a later mutation completes nothing",
137
+ () =>
138
+ withObserver(
139
+ Effect.gen(function* () {
140
+ const observer = yield* CompletionObserver;
141
+ const s0 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
142
+ const s1 = state([list(1, "Work", [{ id: 1, done: true }])], 1);
143
+ const s2 = state(
144
+ [
145
+ list(1, "Work", [
146
+ { id: 1, done: true },
147
+ { id: 2, done: false },
148
+ ]),
149
+ ],
150
+ 1,
151
+ );
152
+ yield* observer.record(s0, s1);
153
+ yield* observer.record(s1, s2);
154
+ const batch = Option.getOrThrow(yield* observer.consume);
155
+ assert.deepStrictEqual(batch.completedItemIds, [1]);
156
+ assert.deepStrictEqual(
157
+ batch.list.items.map((item) => item.id),
158
+ [1, 2],
159
+ );
160
+ }),
161
+ ),
162
+ );
163
+
164
+ it.effect("CompletionObserver record drops a completed item that was reopened before settle", () =>
165
+ withObserver(
166
+ Effect.gen(function* () {
167
+ const observer = yield* CompletionObserver;
168
+ const s0 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
169
+ const s1 = state([list(1, "Work", [{ id: 1, done: true }])], 1);
170
+ const s2 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
171
+ yield* observer.record(s0, s1);
172
+ yield* observer.record(s1, s2);
173
+ assert.strictEqual(Option.isNone(yield* observer.consume), true);
174
+ }),
175
+ ),
176
+ );
177
+
178
+ it.effect("CompletionObserver record drops a completed item that was removed before settle", () =>
179
+ withObserver(
180
+ Effect.gen(function* () {
181
+ const observer = yield* CompletionObserver;
182
+ const s0 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
183
+ const s1 = state([list(1, "Work", [{ id: 1, done: true }])], 1);
184
+ const s2 = state([list(1, "Work", [])], 1);
185
+ yield* observer.record(s0, s1);
186
+ yield* observer.record(s1, s2);
187
+ assert.strictEqual(Option.isNone(yield* observer.consume), true);
188
+ }),
189
+ ),
190
+ );
191
+
192
+ it.effect(
193
+ "CompletionObserver record clears the batch when the active list changes without a completion",
194
+ () =>
195
+ withObserver(
196
+ Effect.gen(function* () {
197
+ const observer = yield* CompletionObserver;
198
+ const s0 = state(
199
+ [list(1, "Work", [{ id: 1, done: false }]), list(2, "Other", [{ id: 1, done: false }])],
200
+ 1,
201
+ );
202
+ const s1 = state(
203
+ [list(1, "Work", [{ id: 1, done: true }]), list(2, "Other", [{ id: 1, done: false }])],
204
+ 1,
205
+ );
206
+ const s2 = state(
207
+ [list(1, "Work", [{ id: 1, done: true }]), list(2, "Other", [{ id: 1, done: false }])],
208
+ 2,
209
+ );
210
+ yield* observer.record(s0, s1);
211
+ yield* observer.record(s1, s2);
212
+ assert.strictEqual(Option.isNone(yield* observer.consume), true);
213
+ }),
214
+ ),
215
+ );
216
+
217
+ it.effect(
218
+ "CompletionObserver record starts a fresh batch when a completion arrives in a different active list",
219
+ () =>
220
+ withObserver(
221
+ Effect.gen(function* () {
222
+ const observer = yield* CompletionObserver;
223
+ const s0 = state(
224
+ [list(1, "Work", [{ id: 1, done: false }]), list(2, "Other", [{ id: 1, done: false }])],
225
+ 1,
226
+ );
227
+ const s1 = state(
228
+ [list(1, "Work", [{ id: 1, done: true }]), list(2, "Other", [{ id: 1, done: false }])],
229
+ 1,
230
+ );
231
+ const s2 = state(
232
+ [list(1, "Work", [{ id: 1, done: true }]), list(2, "Other", [{ id: 1, done: true }])],
233
+ 2,
234
+ );
235
+ yield* observer.record(s0, s1);
236
+ yield* observer.record(s1, s2);
237
+ const batch = Option.getOrThrow(yield* observer.consume);
238
+ assert.deepStrictEqual(batch.completedItemIds, [1]);
239
+ assert.strictEqual(batch.list.name, "Other");
240
+ }),
241
+ ),
242
+ );
243
+
244
+ it.effect("CompletionObserver consume clears the record", () =>
245
+ withObserver(
246
+ Effect.gen(function* () {
247
+ const observer = yield* CompletionObserver;
248
+ const s0 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
249
+ const s1 = state([list(1, "Work", [{ id: 1, done: true }])], 1);
250
+ yield* observer.record(s0, s1);
251
+ const first = yield* observer.consume;
252
+ const second = yield* observer.consume;
253
+ assert.strictEqual(Option.isSome(first), true);
254
+ assert.strictEqual(Option.isNone(second), true);
255
+ }),
256
+ ),
257
+ );
@@ -0,0 +1,94 @@
1
+ import { Context, Effect, Layer, Option, Ref } from "effect";
2
+ import type { TodoList, TrackerState } from "../core/domain.ts";
3
+
4
+ /**
5
+ * Completion detection and the pending-completion record.
6
+ *
7
+ * The record is in-memory only and never persisted. It carries the active list
8
+ * as it stands and every item that transitioned open → done since the last
9
+ * decision, as a batch. The batch is referenced prior work; the decision's
10
+ * subject is always the next unfinished candidate.
11
+ */
12
+
13
+ /** The completions a settle decision may act on. In memory only, never persisted. */
14
+ export interface PendingCompletion {
15
+ /** The active list as it stands now; refreshed on every same-list mutation. */
16
+ readonly list: TodoList;
17
+ /** Every item that transitioned open → done since the last decision, in list order. */
18
+ readonly completedItemIds: readonly number[];
19
+ }
20
+
21
+ /**
22
+ * Ids of active-list items that transitioned open → done, in list order. Empty
23
+ * when none. Only the active list is consulted, and a completion in another
24
+ * list contributes nothing.
25
+ */
26
+ export const completedInActiveList = (
27
+ before: TrackerState,
28
+ after: TrackerState,
29
+ ): readonly number[] => {
30
+ if (after.activeListId === null) return [];
31
+ const activeAfter = after.lists.find((list) => list.id === after.activeListId);
32
+ if (activeAfter === undefined) return [];
33
+ const activeBefore = before.lists.find((list) => list.id === after.activeListId);
34
+ const doneBefore = new Set(
35
+ (activeBefore?.items ?? []).filter((item) => item.done).map((item) => item.id),
36
+ );
37
+ return activeAfter.items
38
+ .filter((item) => item.done && !doneBefore.has(item.id))
39
+ .map((item) => item.id);
40
+ };
41
+
42
+ /**
43
+ * Live-record fold: refresh the snapshot from `after`; keep the previously
44
+ * completed ids that are still done and present; add the new ones. A different
45
+ * active list (or none) clears the record. An empty result clears it too, so a
46
+ * reopen or removal between the completion and the settle cannot leave a
47
+ * stale batch behind.
48
+ */
49
+ const mergeLiveBatch = (
50
+ current: Option.Option<PendingCompletion>,
51
+ after: TrackerState,
52
+ newlyCompleted: readonly number[],
53
+ ): Option.Option<PendingCompletion> => {
54
+ if (after.activeListId === null) return Option.none();
55
+ const list = after.lists.find((candidate) => candidate.id === after.activeListId);
56
+ if (list === undefined) return Option.none();
57
+
58
+ const previousIds =
59
+ Option.isSome(current) && current.value.list.id === list.id
60
+ ? current.value.completedItemIds
61
+ : [];
62
+ const tracked = new Set<number>([...previousIds, ...newlyCompleted]);
63
+ const completedItemIds = list.items
64
+ .filter((item) => item.done && tracked.has(item.id))
65
+ .map((item) => item.id);
66
+ return completedItemIds.length === 0 ? Option.none() : Option.some({ list, completedItemIds });
67
+ };
68
+
69
+ export class CompletionObserver extends Context.Service<
70
+ CompletionObserver,
71
+ {
72
+ readonly record: (before: TrackerState, after: TrackerState) => Effect.Effect<void>;
73
+ /** Read and clear in one step, so one completion set yields one decision. */
74
+ readonly consume: Effect.Effect<Option.Option<PendingCompletion>>;
75
+ }
76
+ >()("tracker/CompletionObserver") {
77
+ static readonly layer: Layer.Layer<CompletionObserver> = Layer.effect(
78
+ CompletionObserver,
79
+ Effect.gen(function* () {
80
+ const pending = yield* Ref.make(Option.none<PendingCompletion>());
81
+ const record = Effect.fnUntraced(function* (before: TrackerState, after: TrackerState) {
82
+ const newlyCompleted = completedInActiveList(before, after);
83
+ // A mutation in a different active list (or a deselect/delete) clears
84
+ // the record. Otherwise the snapshot follows the current list, and ids
85
+ // that were reopened or removed drop out; an empty result clears it.
86
+ yield* Ref.update(pending, (current) => mergeLiveBatch(current, after, newlyCompleted));
87
+ });
88
+ return CompletionObserver.of({
89
+ record,
90
+ consume: Ref.modify(pending, (current) => [current, Option.none<PendingCompletion>()]),
91
+ });
92
+ }),
93
+ );
94
+ }
@@ -0,0 +1,91 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import { Effect } from "effect";
3
+ import {
4
+ DECISION_CUSTOM_TYPE,
5
+ buildDecisionRecord,
6
+ decodeDecisionRecord,
7
+ encodeDecisionRecord,
8
+ type DecisionRecord,
9
+ } from "./decision-record.ts";
10
+ import type { ResolvedProduct, ResolvedReference } from "./observations.ts";
11
+
12
+ const reference = (
13
+ value: ResolvedReference["reference"],
14
+ state: ResolvedReference["state"],
15
+ ): ResolvedReference => ({ reference: value, state });
16
+
17
+ const product = (path: string, state: ResolvedProduct["state"]): ResolvedProduct => ({
18
+ product: { path },
19
+ state,
20
+ });
21
+
22
+ const input = (overrides: {
23
+ readonly references?: readonly ResolvedReference[];
24
+ readonly products?: readonly ResolvedProduct[];
25
+ }): Parameters<typeof buildDecisionRecord>[0] => ({
26
+ rule: "reference-is-readable",
27
+ verdict: "compact",
28
+ candidateRef: "Work:2",
29
+ references: overrides.references ?? [],
30
+ products: overrides.products ?? [],
31
+ });
32
+
33
+ it("the custom-entry type is the reliance-decision carrier", () => {
34
+ assert.strictEqual(DECISION_CUSTOM_TYPE, "tracker/reliance-decision");
35
+ });
36
+
37
+ it("a decision records the fired row and the resolved states", () => {
38
+ const record = buildDecisionRecord(
39
+ input({
40
+ references: [reference({ kind: "path", path: "src/a.ts", symbol: "route" }, "readable")],
41
+ products: [product("docs/plan.md", "missing")],
42
+ }),
43
+ )!;
44
+ assert.deepStrictEqual(record, {
45
+ rule: "reference-is-readable",
46
+ verdict: "compact",
47
+ candidateRef: "Work:2",
48
+ references: [{ kind: "path", path: "src/a.ts", symbol: "route", state: "readable" }],
49
+ products: [{ path: "docs/plan.md", state: "missing" }],
50
+ });
51
+ assert.notInclude(JSON.stringify(record), "transcript");
52
+ });
53
+
54
+ it("a decision with no declarations records no decision entry", () => {
55
+ assert.isUndefined(buildDecisionRecord(input({})));
56
+ });
57
+
58
+ it("a decision reference rides as a topic, not as an archived claim", () => {
59
+ const record = buildDecisionRecord(
60
+ input({ references: [reference({ kind: "decision", topic: "storage shape" }, "unresolved")] }),
61
+ )!;
62
+ assert.deepStrictEqual(record.references, [
63
+ { kind: "decision", topic: "storage shape", state: "unresolved" },
64
+ ]);
65
+ assert.notInclude(JSON.stringify(record), "archived");
66
+ });
67
+
68
+ it("a record round-trips through the codec", () => {
69
+ const record = buildDecisionRecord(
70
+ input({ references: [reference({ kind: "path", path: "src/a.ts" }, "drifted")] }),
71
+ )!;
72
+ const decoded = Effect.runSync(decodeDecisionRecord(encodeDecisionRecord(record)));
73
+ assert.deepStrictEqual(decoded as DecisionRecord, record);
74
+ });
75
+
76
+ it("a record caps references at eight and products at four", () => {
77
+ const references = Array.from({ length: 10 }, (_value, index) =>
78
+ reference({ kind: "path", path: `src/f${index}.ts` }, "readable"),
79
+ );
80
+ const products = Array.from({ length: 6 }, (_value, index) =>
81
+ product(`src/p${index}.ts`, "exists"),
82
+ );
83
+ const record = buildDecisionRecord(input({ references, products }))!;
84
+ assert.strictEqual(record.references.length, 8);
85
+ assert.strictEqual(record.products.length, 4);
86
+ });
87
+
88
+ it("a malformed record fails to decode", () => {
89
+ const exit = Effect.runSync(Effect.exit(decodeDecisionRecord({ rule: 42 })));
90
+ assert.strictEqual(exit._tag, "Failure");
91
+ });
@@ -0,0 +1,101 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { REFERENCE_CAP, PRODUCT_CAP } from "./digest.ts";
3
+ import type { ResolvedProduct, ResolvedReference } from "./observations.ts";
4
+ import type { RuleVerdict } from "./rules.ts";
5
+
6
+ /**
7
+ * The live decision record.
8
+ *
9
+ * One compact custom session entry per settle decision, appended only when the
10
+ * candidate declared a reference or a product. It carries the raw rule row,
11
+ * the raw verdict, the candidate reference, and the resolved states, all
12
+ * bounded by the digest's caps. Nothing else from the decision enters: no
13
+ * transcript text, no batch prose, no item body beyond the reference.
14
+ *
15
+ * The eval harvest reads this entry back into its case, so a declared row's
16
+ * real coverage can be measured without a second classifier call.
17
+ */
18
+
19
+ /** The custom-entry type the bridge appends for one settle decision. */
20
+ export const DECISION_CUSTOM_TYPE = "tracker/reliance-decision";
21
+
22
+ /** Every declared reference state the record may carry. */
23
+ const referenceState = Schema.Literals(["readable", "lost", "drifted", "unresolved"]);
24
+
25
+ /** Every declared product state the record may carry. */
26
+ const productState = Schema.Literals(["exists", "missing"]);
27
+
28
+ /** One resolved reference, flattened to the fields its kind owns. */
29
+ const recordReference = Schema.Struct({
30
+ kind: Schema.Literals(["path", "decision"]),
31
+ path: Schema.optional(Schema.String),
32
+ symbol: Schema.optional(Schema.String),
33
+ span: Schema.optional(Schema.String),
34
+ topic: Schema.optional(Schema.String),
35
+ state: referenceState,
36
+ });
37
+
38
+ /** One resolved product. */
39
+ const recordProduct = Schema.Struct({
40
+ path: Schema.String,
41
+ state: productState,
42
+ });
43
+
44
+ /** The stored shape of one decision record. */
45
+ export const decisionRecordSchema = Schema.Struct({
46
+ rule: Schema.String,
47
+ verdict: Schema.Literals(["keep", "compact", "abstain"]),
48
+ candidateRef: Schema.String,
49
+ references: Schema.Array(recordReference),
50
+ products: Schema.Array(recordProduct),
51
+ });
52
+
53
+ export type DecisionRecord = Schema.Schema.Type<typeof decisionRecordSchema>;
54
+
55
+ const referenceOf = (entry: ResolvedReference): DecisionRecord["references"][number] =>
56
+ entry.reference.kind === "decision"
57
+ ? { kind: "decision", topic: entry.reference.topic, state: entry.state }
58
+ : {
59
+ kind: "path",
60
+ path: entry.reference.path,
61
+ ...(entry.reference.symbol === undefined ? {} : { symbol: entry.reference.symbol }),
62
+ ...(entry.reference.span === undefined ? {} : { span: entry.reference.span }),
63
+ state: entry.state,
64
+ };
65
+
66
+ /**
67
+ * Build the record for one decision, or undefined when the candidate declared
68
+ * nothing. The caps match the digest, so the entry stays compact.
69
+ */
70
+ export const buildDecisionRecord = (input: {
71
+ readonly rule: string;
72
+ readonly verdict: RuleVerdict;
73
+ readonly candidateRef: string;
74
+ readonly references: readonly ResolvedReference[];
75
+ readonly products: readonly ResolvedProduct[];
76
+ }): DecisionRecord | undefined => {
77
+ if (input.references.length === 0 && input.products.length === 0) return undefined;
78
+ return {
79
+ rule: input.rule,
80
+ verdict: input.verdict,
81
+ candidateRef: input.candidateRef,
82
+ references: input.references.slice(0, REFERENCE_CAP).map(referenceOf),
83
+ products: input.products.slice(0, PRODUCT_CAP).map((entry) => ({
84
+ path: entry.product.path,
85
+ state: entry.state,
86
+ })),
87
+ };
88
+ };
89
+
90
+ /** Encode a record into its plain JSON shape, throwing on a malformed value. */
91
+ export const encodeDecisionRecord = (record: DecisionRecord): unknown =>
92
+ Schema.encodeSync(decisionRecordSchema)(record);
93
+
94
+ /**
95
+ * Decode an untrusted session entry into a record. Unknown extra keys are
96
+ * ignored, so a newer writer does not break an older reader.
97
+ */
98
+ export const decodeDecisionRecord = (
99
+ snapshot: unknown,
100
+ ): Effect.Effect<DecisionRecord, Schema.SchemaError> =>
101
+ Schema.decodeUnknownEffect(decisionRecordSchema, { onExcessProperty: "ignore" })(snapshot);