@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.
Files changed (36) hide show
  1. package/README.md +183 -60
  2. package/package.json +23 -11
  3. package/src/compaction/candidate.test.ts +9 -6
  4. package/src/compaction/candidate.ts +32 -2
  5. package/src/compaction/classifier.test.ts +67 -60
  6. package/src/compaction/classifier.ts +24 -22
  7. package/src/compaction/completion.test.ts +127 -49
  8. package/src/compaction/completion.ts +1 -3
  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 +104 -9
  12. package/src/compaction/digest.ts +96 -9
  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/rules.test.ts +253 -0
  18. package/src/compaction/rules.ts +188 -0
  19. package/src/compaction/settings.test.ts +105 -49
  20. package/src/compaction/settings.ts +53 -31
  21. package/src/compaction/settle.test.ts +370 -0
  22. package/src/compaction/settle.ts +109 -53
  23. package/src/core/deps.test.ts +1 -1
  24. package/src/core/domain.test.ts +42 -9
  25. package/src/core/domain.ts +73 -8
  26. package/src/core/persistence.test.ts +7 -7
  27. package/src/core/store.test.ts +116 -50
  28. package/src/core/store.ts +92 -31
  29. package/src/index.test.ts +209 -68
  30. package/src/index.ts +170 -48
  31. package/src/presentation/tool-metadata.test.ts +263 -48
  32. package/src/presentation/tool-metadata.ts +325 -102
  33. package/src/presentation/ui.test.ts +122 -7
  34. package/src/presentation/ui.ts +81 -18
  35. package/src/presentation/vim-settings.test.ts +98 -0
  36. package/src/presentation/vim-settings.ts +59 -0
@@ -0,0 +1,387 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { readFileSync, statSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { Context, Effect, Layer, Queue, Ref } from "effect";
5
+ import {
6
+ emptyFootprint,
7
+ fingerprintOf,
8
+ PRODUCING_TOOLS,
9
+ spanTextOf,
10
+ type BatchFootprint,
11
+ type FileProbe,
12
+ type WrittenPath,
13
+ } from "./observations.ts";
14
+
15
+ /**
16
+ * The batch footprint recorder.
17
+ *
18
+ * The event path is hot, so `capture` does one thing: project the event into a
19
+ * small record and fold it into the pending batch. It never reads the disk and
20
+ * never yields. `snapshot` drains the pending batch, reads each written file
21
+ * once through the injected `FileProbe`, and returns the ready facts; `consume`
22
+ * returns and clears them. A later event for a path supersedes an earlier one,
23
+ * and two paths derive independently. A path the probe cannot read is absent,
24
+ * and the resolver abstains on it.
25
+ *
26
+ * Deletions and workspace-wide symbol moves are not parsed: `deleted` stays
27
+ * empty, and the resolver reports those references as unresolved, which keeps
28
+ * the context.
29
+ */
30
+
31
+ // --------------------------------------------------------------------------
32
+ // Event projection
33
+ // --------------------------------------------------------------------------
34
+
35
+ /**
36
+ * The bounded projection of one tool event. The bridge builds it from pi's
37
+ * `tool_execution_start` and `tool_execution_end` events: the args are the
38
+ * call's `path` and `command`, and `details` is the tool result's `details`
39
+ * (the object that carries the unified `patch`).
40
+ */
41
+ export interface ToolEvent {
42
+ readonly phase: "start" | "end";
43
+ readonly toolName: string;
44
+ readonly args?: {
45
+ readonly path?: string;
46
+ readonly command?: string;
47
+ };
48
+ readonly details?: unknown;
49
+ }
50
+
51
+ /** One path the batch wrote, before the file is read. */
52
+ interface PendingWrite {
53
+ readonly kind: "write";
54
+ readonly path: string;
55
+ readonly spans: readonly string[];
56
+ }
57
+
58
+ /** One path the batch read. */
59
+ interface PendingRead {
60
+ readonly kind: "read";
61
+ readonly path: string;
62
+ }
63
+
64
+ /** One command the batch ran. */
65
+ interface PendingCommand {
66
+ readonly kind: "command";
67
+ readonly command: string;
68
+ }
69
+
70
+ type Pending = PendingWrite | PendingRead | PendingCommand;
71
+
72
+ /** One new-side hunk header of a unified patch: `@@ -a,b +c,d @@`. */
73
+ const HUNK = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
74
+
75
+ const textOf = (value: unknown): string => (typeof value === "string" ? value : "");
76
+
77
+ /**
78
+ * The new-side line range(s) a tool result touched, e.g. `["3-6", "20"]`.
79
+ * Mirrors `evals/evidence.ts` `lineRangesOf`, since the eval record and the
80
+ * live footprint must read the same patch shape. Four ranges is the cap.
81
+ */
82
+ export const newSideSpans = (details: unknown): readonly string[] => {
83
+ const patch = textOf((details as { readonly patch?: unknown } | undefined)?.patch);
84
+ const spans: string[] = [];
85
+ for (const line of patch.split("\n")) {
86
+ const match = HUNK.exec(line);
87
+ if (match === null) continue;
88
+ const start = Number(match[1]);
89
+ const count = match[2] === undefined ? 1 : Number(match[2]);
90
+ const end = count <= 1 ? start : start + count - 1;
91
+ spans.push(start === end ? String(start) : `${start}-${end}`);
92
+ }
93
+ if (spans.length > 0) return spans.slice(0, 4);
94
+ const first = (details as { readonly firstChangedLine?: unknown } | undefined)?.firstChangedLine;
95
+ return typeof first === "number" && Number.isFinite(first) ? [String(first)] : [];
96
+ };
97
+
98
+ /**
99
+ * Project one event into the record the batch holds, or undefined when the
100
+ * event names nothing the footprint records. A producing tool contributes a
101
+ * write only at the end phase, because only then does the result carry spans.
102
+ */
103
+ export const pendingOf = (event: ToolEvent): Pending | undefined => {
104
+ const path = event.args?.path;
105
+ const command = event.args?.command;
106
+ if (path !== undefined && PRODUCING_TOOLS.has(event.toolName)) {
107
+ if (event.phase !== "end") return undefined;
108
+ return { kind: "write", path, spans: newSideSpans(event.details) };
109
+ }
110
+ if (path !== undefined && event.toolName === "read") return { kind: "read", path };
111
+ if (command !== undefined) return { kind: "command", command };
112
+ return undefined;
113
+ };
114
+
115
+ // --------------------------------------------------------------------------
116
+ // Derived facts
117
+ // --------------------------------------------------------------------------
118
+
119
+ /** The batch captured but not yet derived, keyed by path. Last write wins. */
120
+ interface PendingBatch {
121
+ readonly writes: ReadonlyMap<string, PendingWrite>;
122
+ readonly reads: ReadonlySet<string>;
123
+ readonly commands: ReadonlySet<string>;
124
+ }
125
+
126
+ const emptyPending = (): PendingBatch => ({
127
+ writes: new Map(),
128
+ reads: new Set(),
129
+ commands: new Set(),
130
+ });
131
+
132
+ /** The derived facts, keyed by path. Insertion order is the order of derivation. */
133
+ interface Facts {
134
+ readonly wrote: ReadonlyMap<string, WrittenPath>;
135
+ readonly read: ReadonlySet<string>;
136
+ readonly commands: ReadonlySet<string>;
137
+ }
138
+
139
+ const emptyFacts = (): Facts => ({ wrote: new Map(), read: new Set(), commands: new Set() });
140
+
141
+ const footprintOf = (facts: Facts): BatchFootprint => ({
142
+ ...emptyFootprint(),
143
+ wrote: [...facts.wrote.values()],
144
+ read: [...facts.read],
145
+ commands: [...facts.commands],
146
+ });
147
+
148
+ /**
149
+ * The fingerprint of a written region: the whole file when no span is known,
150
+ * the declared ranges when there are any, and no fingerprint when the file is
151
+ * shorter than the ranges. A missing fingerprint never reports drift.
152
+ */
153
+ const fingerprintOfWrite = (text: string, spans: readonly string[]): string | undefined => {
154
+ if (spans.length === 0) return fingerprintOf(text);
155
+ const region = spanTextOf(text, spans.join(","));
156
+ return region === undefined ? undefined : fingerprintOf(region);
157
+ };
158
+
159
+ /** Read each written path once and derive its spans and fingerprint. */
160
+ const deriveWrites = (
161
+ probe: FileProbe,
162
+ writes: ReadonlyMap<string, PendingWrite>,
163
+ ): readonly WrittenPath[] => {
164
+ const derived: WrittenPath[] = [];
165
+ for (const [path, entry] of writes) {
166
+ let text: string | undefined;
167
+ try {
168
+ text = probe.read(path);
169
+ } catch {
170
+ // A path the probe cannot read is not ready; the resolver abstains on it.
171
+ text = undefined;
172
+ }
173
+ if (text === undefined) continue;
174
+ const fingerprint = fingerprintOfWrite(text, entry.spans);
175
+ derived.push({
176
+ path,
177
+ spans: entry.spans,
178
+ ...(fingerprint === undefined ? {} : { fingerprint }),
179
+ });
180
+ }
181
+ return derived;
182
+ };
183
+
184
+ // --------------------------------------------------------------------------
185
+ // The recorder service
186
+ // --------------------------------------------------------------------------
187
+
188
+ /** The recorder plus its background worker, for a caller that wants one. */
189
+ export interface FootprintRecorderParts {
190
+ readonly recorder: FootprintRecorder["Service"];
191
+ /** Drains the pending batch whenever capture signals new work. */
192
+ readonly worker: Effect.Effect<never>;
193
+ }
194
+
195
+ /**
196
+ * Build the recorder and a background drain worker. A test uses the recorder
197
+ * directly and drains it with `snapshot`; the layer forks the worker so
198
+ * production derives in the background as well.
199
+ */
200
+ export const makeFootprintRecorder = (probe: FileProbe): Effect.Effect<FootprintRecorderParts> =>
201
+ Effect.gen(function* () {
202
+ const pending = yield* Ref.make<PendingBatch>(emptyPending());
203
+ const facts = yield* Ref.make<Facts>(emptyFacts());
204
+ const signal = yield* Queue.unbounded<void>();
205
+
206
+ /**
207
+ * Take the pending batch in one step and turn it into facts. Atomically
208
+ * clearing first means two concurrent drains cannot double-read a path.
209
+ */
210
+ const drain = Ref.modify(pending, (current) => [current, emptyPending()]).pipe(
211
+ Effect.flatMap((batch) =>
212
+ Effect.sync(() => deriveWrites(probe, batch.writes)).pipe(
213
+ Effect.flatMap((derived) =>
214
+ Ref.update(facts, (current) => ({
215
+ wrote: new Map([
216
+ ...current.wrote,
217
+ ...derived.map((entry) => [entry.path, entry] as const),
218
+ ]),
219
+ read: new Set([...current.read, ...batch.reads]),
220
+ commands: new Set([...current.commands, ...batch.commands]),
221
+ })).pipe(
222
+ Effect.andThen(
223
+ derived.length === 0
224
+ ? Effect.void
225
+ : Effect.logDebug(
226
+ `tracker: footprint derived ${derived
227
+ .map(
228
+ (entry) =>
229
+ `${entry.path} [${entry.spans.join(",") || "all"}] ${entry.fingerprint ?? "no-fingerprint"}`,
230
+ )
231
+ .join(", ")}`,
232
+ ),
233
+ ),
234
+ ),
235
+ ),
236
+ ),
237
+ ),
238
+ );
239
+
240
+ const drainAll = Effect.gen(function* () {
241
+ // A signal per capture may collapse into one drain; loop until the batch
242
+ // is empty so nothing captured before the last signal is left behind.
243
+ let drained = false;
244
+ do {
245
+ const before = yield* Ref.get(pending);
246
+ drained = before.writes.size > 0 || before.reads.size > 0 || before.commands.size > 0;
247
+ yield* drain;
248
+ } while (drained);
249
+ });
250
+
251
+ const capture = Effect.fnUntraced(function* (event: ToolEvent) {
252
+ const entry = pendingOf(event);
253
+ if (entry === undefined) return;
254
+ yield* Ref.update(pending, (current) => {
255
+ if (entry.kind === "write") {
256
+ return { ...current, writes: new Map([...current.writes, [entry.path, entry]]) };
257
+ }
258
+ if (entry.kind === "read") {
259
+ return { ...current, reads: new Set([...current.reads, entry.path]) };
260
+ }
261
+ return { ...current, commands: new Set([...current.commands, entry.command]) };
262
+ });
263
+ yield* Queue.offer(signal, undefined);
264
+ });
265
+
266
+ const snapshot = drainAll.pipe(Effect.andThen(Ref.get(facts)), Effect.map(footprintOf));
267
+
268
+ const consume = snapshot.pipe(
269
+ Effect.flatMap((footprint) => Ref.set(facts, emptyFacts()).pipe(Effect.as(footprint))),
270
+ );
271
+
272
+ const worker = Effect.forever(
273
+ Effect.gen(function* () {
274
+ // Extra signals collapse into an empty drain, which is harmless.
275
+ yield* Queue.take(signal);
276
+ yield* drainAll;
277
+ }),
278
+ );
279
+
280
+ return {
281
+ recorder: FootprintRecorder.of({ capture, snapshot, consume }),
282
+ worker,
283
+ };
284
+ });
285
+
286
+ /**
287
+ * The batch footprint recorder. `capture` folds an event into the batch and
288
+ * never reads the disk; `snapshot` drains and returns the ready facts;
289
+ * `consume` returns and clears them.
290
+ */
291
+ export class FootprintRecorder extends Context.Service<
292
+ FootprintRecorder,
293
+ {
294
+ readonly capture: (event: ToolEvent) => Effect.Effect<void>;
295
+ readonly snapshot: Effect.Effect<BatchFootprint>;
296
+ readonly consume: Effect.Effect<BatchFootprint>;
297
+ }
298
+ >()("tracker/FootprintRecorder") {
299
+ static readonly layer = (probe: FileProbe): Layer.Layer<FootprintRecorder> =>
300
+ Layer.effect(
301
+ FootprintRecorder,
302
+ Effect.gen(function* () {
303
+ const parts = yield* makeFootprintRecorder(probe);
304
+ yield* Effect.forkScoped(parts.worker);
305
+ return parts.recorder;
306
+ }),
307
+ );
308
+ }
309
+
310
+ // --------------------------------------------------------------------------
311
+ // The production probe
312
+ // --------------------------------------------------------------------------
313
+
314
+ /** The bounds the production probe keeps on every disk read. */
315
+ export const PROBE_DEFAULTS = {
316
+ maxReadBytes: 256 * 1024,
317
+ findSymbolTimeoutMillis: 2_000,
318
+ findSymbolMaxPaths: 64,
319
+ findSymbolMaxBufferBytes: 1024 * 1024,
320
+ } as const;
321
+
322
+ export interface ProductionProbeOptions {
323
+ /** The workspace root every relative path resolves against. Defaults to cwd. */
324
+ readonly root?: string;
325
+ readonly maxReadBytes?: number;
326
+ readonly findSymbolTimeoutMillis?: number;
327
+ readonly findSymbolMaxPaths?: number;
328
+ }
329
+
330
+ /**
331
+ * The probe the product passes: one bounded `readFileSync` per path and one
332
+ * bounded `rg --files-with-matches` per symbol. Every failure — a missing
333
+ * `rg`, a nonzero exit, a timeout, a file over the size cap — returns an empty
334
+ * result, which resolves to `unresolved` and never compacts.
335
+ */
336
+ export const productionProbe = (options: ProductionProbeOptions = {}): FileProbe => {
337
+ const root = options.root ?? process.cwd();
338
+ const maxReadBytes = options.maxReadBytes ?? PROBE_DEFAULTS.maxReadBytes;
339
+ const findSymbolTimeoutMillis =
340
+ options.findSymbolTimeoutMillis ?? PROBE_DEFAULTS.findSymbolTimeoutMillis;
341
+ const findSymbolMaxPaths = options.findSymbolMaxPaths ?? PROBE_DEFAULTS.findSymbolMaxPaths;
342
+
343
+ return {
344
+ read: (path) => {
345
+ try {
346
+ const full = resolve(root, path);
347
+ const stat = statSync(full);
348
+ if (!stat.isFile() || stat.size > maxReadBytes) return undefined;
349
+ return readFileSync(full, "utf8");
350
+ } catch {
351
+ return undefined;
352
+ }
353
+ },
354
+ findSymbol: (symbol) => {
355
+ if (symbol.trim().length === 0) return [];
356
+ try {
357
+ const output = execFileSync(
358
+ "rg",
359
+ [
360
+ "--files-with-matches",
361
+ "--fixed-strings",
362
+ "--glob",
363
+ "!**/node_modules/**",
364
+ "--",
365
+ symbol,
366
+ ".",
367
+ ],
368
+ {
369
+ cwd: root,
370
+ timeout: findSymbolTimeoutMillis,
371
+ maxBuffer: PROBE_DEFAULTS.findSymbolMaxBufferBytes,
372
+ encoding: "utf8",
373
+ stdio: ["ignore", "pipe", "ignore"],
374
+ },
375
+ );
376
+ return output
377
+ .split("\n")
378
+ .map((line) => line.trim())
379
+ .filter((line) => line.length > 0)
380
+ .map((line) => line.replace(/^\.\//, ""))
381
+ .slice(0, findSymbolMaxPaths);
382
+ } catch {
383
+ return [];
384
+ }
385
+ },
386
+ };
387
+ };
@@ -0,0 +1,199 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import {
3
+ containsSymbol,
4
+ documentPathsOf,
5
+ emptyFootprint,
6
+ fingerprintOf,
7
+ knownTextOf,
8
+ producedTextOf,
9
+ resolveProduct,
10
+ resolveReference,
11
+ spanTextOf,
12
+ type BatchFootprint,
13
+ type FileProbe,
14
+ } from "./observations.ts";
15
+
16
+ /** A probe over a path-to-text map. `findSymbol` scans the same map. */
17
+ const probeOf = (files: Readonly<Record<string, string>>): FileProbe => ({
18
+ read: (path) => files[path],
19
+ findSymbol: (symbol) =>
20
+ Object.entries(files)
21
+ .filter(([, text]) => containsSymbol(text, symbol))
22
+ .map(([path]) => path),
23
+ });
24
+
25
+ const footprintWith = (overrides: Partial<BatchFootprint>): BatchFootprint => ({
26
+ ...emptyFootprint(),
27
+ ...overrides,
28
+ });
29
+
30
+ it("documentPathsOf dedupes paths and prefers the longest extension", () => {
31
+ assert.deepStrictEqual(documentPathsOf("see .qrspi/designs/a.md and src/b.jsonc, src/b.jsonc"), [
32
+ ".qrspi/designs/a.md",
33
+ "src/b.jsonc",
34
+ ]);
35
+ assert.deepStrictEqual(documentPathsOf("no paths here"), []);
36
+ });
37
+
38
+ it("knownTextOf joins the batch and the bounded record fields", () => {
39
+ const known = knownTextOf(
40
+ ["batch text"],
41
+ [
42
+ { kind: "tool-call", text: "{}", name: "write", args: { path: "src/written.ts" } },
43
+ { kind: "assistant", text: "prose" },
44
+ ],
45
+ );
46
+ assert.include(known, "batch text");
47
+ assert.include(known, "src/written.ts");
48
+ assert.include(known, "prose");
49
+ });
50
+
51
+ it("producedTextOf reads only write and edit call paths", () => {
52
+ const produced = producedTextOf([
53
+ { kind: "tool-call", text: "{}", name: "write", args: { path: "src/written.ts" } },
54
+ { kind: "tool-call", text: "{}", name: "edit", args: { path: "src/edited.ts" } },
55
+ { kind: "tool-call", text: "{}", name: "read", args: { path: "src/read.ts" } },
56
+ { kind: "tool-result", text: "src/result.ts" },
57
+ ]);
58
+ assert.include(produced, "src/written.ts");
59
+ assert.include(produced, "src/edited.ts");
60
+ assert.notInclude(produced, "src/read.ts");
61
+ assert.notInclude(produced, "src/result.ts");
62
+ });
63
+
64
+ it("fingerprintOf is stable and separates different text", () => {
65
+ assert.strictEqual(fingerprintOf("const a = 1;"), fingerprintOf("const a = 1;"));
66
+ assert.notStrictEqual(fingerprintOf("const a = 1;"), fingerprintOf("const a = 2;"));
67
+ });
68
+
69
+ it("spanTextOf reads one range and several, and rejects a short file", () => {
70
+ const text = ["one", "two", "three", "four"].join("\n");
71
+ assert.strictEqual(spanTextOf(text, "2"), "two");
72
+ assert.strictEqual(spanTextOf(text, "2-3"), "two\nthree");
73
+ assert.strictEqual(spanTextOf(text, "1,4"), "one\nfour");
74
+ assert.isUndefined(spanTextOf(text, "5"));
75
+ assert.isUndefined(spanTextOf(text, "3-2"));
76
+ assert.isUndefined(spanTextOf(text, "x"));
77
+ });
78
+
79
+ it("containsSymbol matches tokens, not substrings", () => {
80
+ assert.isTrue(containsSymbol("const route = 1;", "route"));
81
+ assert.isTrue(containsSymbol("route(x)", "route"));
82
+ assert.isFalse(containsSymbol("const router = 1;", "route"));
83
+ assert.isFalse(containsSymbol("", "route"));
84
+ });
85
+
86
+ it("a path reference is readable when the file exists", () => {
87
+ const resolved = resolveReference(
88
+ { kind: "path", path: "src/a.ts" },
89
+ emptyFootprint(),
90
+ probeOf({ "src/a.ts": "export {};" }),
91
+ );
92
+ assert.strictEqual(resolved.state, "readable");
93
+ });
94
+
95
+ it("a missing path is lost only when the batch removed it", () => {
96
+ const reference = { kind: "path", path: "src/a.ts" } as const;
97
+ assert.strictEqual(
98
+ resolveReference(reference, footprintWith({ deleted: [{ path: "src/a.ts" }] }), probeOf({}))
99
+ .state,
100
+ "lost",
101
+ );
102
+ assert.strictEqual(
103
+ resolveReference(reference, emptyFootprint(), probeOf({})).state,
104
+ "unresolved",
105
+ );
106
+ });
107
+
108
+ it("a declared span resolves against the recorded fingerprint", () => {
109
+ const reference = { kind: "path", path: "src/a.ts", span: "1-1" } as const;
110
+ const probe = probeOf({ "src/a.ts": "new" });
111
+ assert.strictEqual(
112
+ resolveReference(
113
+ reference,
114
+ footprintWith({
115
+ wrote: [{ path: "src/a.ts", spans: ["1-1"], fingerprint: fingerprintOf("old") }],
116
+ }),
117
+ probe,
118
+ ).state,
119
+ "drifted",
120
+ );
121
+ assert.strictEqual(
122
+ resolveReference(
123
+ reference,
124
+ footprintWith({
125
+ wrote: [{ path: "src/a.ts", spans: ["1-1"], fingerprint: fingerprintOf("new") }],
126
+ }),
127
+ probe,
128
+ ).state,
129
+ "readable",
130
+ );
131
+ });
132
+
133
+ it("a span past the end of the file is drifted", () => {
134
+ const resolved = resolveReference(
135
+ { kind: "path", path: "src/a.ts", span: "9" },
136
+ emptyFootprint(),
137
+ probeOf({ "src/a.ts": "one" }),
138
+ );
139
+ assert.strictEqual(resolved.state, "drifted");
140
+ });
141
+
142
+ it("a symbol resolves in the named file first, then one workspace file", () => {
143
+ const reference = { kind: "path", path: "src/a.ts", symbol: "route" } as const;
144
+ assert.strictEqual(
145
+ resolveReference(reference, emptyFootprint(), probeOf({ "src/a.ts": "route()" })).state,
146
+ "readable",
147
+ );
148
+ assert.strictEqual(
149
+ resolveReference(
150
+ reference,
151
+ emptyFootprint(),
152
+ probeOf({ "src/a.ts": "nothing", "src/b.ts": "route()" }),
153
+ ).state,
154
+ "readable",
155
+ );
156
+ });
157
+
158
+ it("a symbol found in two workspace files abstains", () => {
159
+ const reference = { kind: "path", path: "src/a.ts", symbol: "route" } as const;
160
+ assert.strictEqual(
161
+ resolveReference(
162
+ reference,
163
+ emptyFootprint(),
164
+ probeOf({ "src/a.ts": "nothing", "src/b.ts": "route()", "src/c.ts": "route()" }),
165
+ ).state,
166
+ "unresolved",
167
+ );
168
+ });
169
+
170
+ it("a symbol absent everywhere is lost when deleted, unresolved otherwise", () => {
171
+ const reference = { kind: "path", path: "src/a.ts", symbol: "gone" } as const;
172
+ const probe = probeOf({ "src/a.ts": "nothing" });
173
+ assert.strictEqual(
174
+ resolveReference(
175
+ reference,
176
+ footprintWith({ deleted: [{ path: "src/a.ts", symbol: "gone" }] }),
177
+ probe,
178
+ ).state,
179
+ "lost",
180
+ );
181
+ assert.strictEqual(resolveReference(reference, emptyFootprint(), probe).state, "unresolved");
182
+ });
183
+
184
+ it("a decision reference stays unresolved, because no check exists", () => {
185
+ const resolved = resolveReference(
186
+ { kind: "decision", topic: "storage shape" },
187
+ emptyFootprint(),
188
+ probeOf({}),
189
+ );
190
+ assert.strictEqual(resolved.state, "unresolved");
191
+ });
192
+
193
+ it("a product exists or is missing", () => {
194
+ assert.strictEqual(
195
+ resolveProduct({ path: "docs/plan.md" }, probeOf({ "docs/plan.md": "# Plan" })).state,
196
+ "exists",
197
+ );
198
+ assert.strictEqual(resolveProduct({ path: "docs/plan.md" }, probeOf({})).state, "missing");
199
+ });