@saasontools/strauss-kb 0.1.10 → 0.1.11

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/dist/index.d.cts CHANGED
@@ -47,13 +47,29 @@ declare const kbVerifiedEventSchema: z.ZodObject<{
47
47
  *
48
48
  * Symbolic on purpose. These are written while the code is still moving: a
49
49
  * `line: 379` recorded at minute five is wrong by minute forty, but
50
- * `OrderService.cancel` survives every edit that does not rename it. A later
51
- * pass resolves symbols to line ranges once the change has settled, and records
52
- * that resolution as a `verified[]` entry.
50
+ * `OrderService.cancel` survives every edit that does not rename it. Once the
51
+ * change settles, a resolution pass (`anchor-resolver.ts`) stamps `hash`,
52
+ * `resolved_at`, and `lines`; drift detection later re-resolves and compares.
53
+ *
54
+ * `hash` is prefixed with the algorithm so a future one can coexist with
55
+ * stored values. `lines` exists because the anchor keeps a hash, not the text:
56
+ * without the line count at hash time, a drift report could say "changed" but
57
+ * never how much.
58
+ *
59
+ * `repo` and `ref` say *which* code, for bases that describe more than one
60
+ * repository. They are author-owned identity: a resolver stamps `hash`,
61
+ * `lines`, and `resolved_at`, and never writes these two. Both are optional and
62
+ * independent of each other, so every anchor written before they existed stays
63
+ * valid.
53
64
  */
54
65
  declare const kbAnchorSchema: z.ZodObject<{
55
66
  file: z.ZodString;
56
67
  symbol: z.ZodOptional<z.ZodString>;
68
+ repo: z.ZodOptional<z.ZodString>;
69
+ ref: z.ZodOptional<z.ZodString>;
70
+ hash: z.ZodOptional<z.ZodString>;
71
+ resolved_at: z.ZodOptional<z.ZodString>;
72
+ lines: z.ZodOptional<z.ZodNumber>;
57
73
  }, z.core.$strict>;
58
74
  declare const KB_RECORD_TYPES: readonly ["fact", "requirement", "constraint", "decision", "assumption", "open-question", "risk", "contract", "flow", "affected-system", "test-obligation", "source-note"];
59
75
  type KbRecordType = (typeof KB_RECORD_TYPES)[number];
@@ -103,6 +119,11 @@ declare const kbRecordFrontmatterSchema: z.ZodObject<{
103
119
  strauss_anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
104
120
  file: z.ZodString;
105
121
  symbol: z.ZodOptional<z.ZodString>;
122
+ repo: z.ZodOptional<z.ZodString>;
123
+ ref: z.ZodOptional<z.ZodString>;
124
+ hash: z.ZodOptional<z.ZodString>;
125
+ resolved_at: z.ZodOptional<z.ZodString>;
126
+ lines: z.ZodOptional<z.ZodNumber>;
106
127
  }, z.core.$strict>>>;
107
128
  strauss_verify: z.ZodOptional<z.ZodArray<z.ZodString>>;
108
129
  strauss_status: z.ZodDefault<z.ZodEnum<{
@@ -145,6 +166,104 @@ type KbRecord = {
145
166
  body: string;
146
167
  };
147
168
 
169
+ /**
170
+ * Resolves symbolic anchors to text and detects drift against stored hashes.
171
+ *
172
+ * Resolvers are pure — source string in, range out; only the file readers touch
173
+ * disk. Any shape the lexer cannot handle confidently returns `null` and is
174
+ * reported `unresolved` rather than guessed at.
175
+ */
176
+ type ResolvedSymbol = {
177
+ text: string;
178
+ /** 1-based, inclusive. */
179
+ startLine: number;
180
+ endLine: number;
181
+ };
182
+ interface AnchorResolver {
183
+ name: string;
184
+ resolve(source: string, symbol: string): ResolvedSymbol | null;
185
+ }
186
+ /** Why an anchor could not be compared. Never an error — always a finding. */
187
+ type AnchorUnresolvedReason = "file-missing" | "symbol-not-found" | "outside-repo" | "file-too-large" | "file-unreadable"
188
+ /**
189
+ * The anchor names a repository this root is not. Expected rather than
190
+ * wrong — a base describing several repositories resolves against one tree
191
+ * at a time — so it is never a drift finding and never reaches a reader as
192
+ * a warning. Multi-root resolution is SAA-709.
193
+ */
194
+ | "foreign-repo";
195
+ /**
196
+ * v1 heuristic resolver. A dotted symbol like `OrderService.cancel` matches on
197
+ * its last segment, with the parent used to scope the search: a candidate
198
+ * counts only if the parent name appears in the fifty lines above it, when any
199
+ * candidate satisfies that at all.
200
+ *
201
+ * Deterministic, and ambiguity is not resolved by guessing — two lines of
202
+ * equally good shape mean the resolver cannot tell which one the record meant,
203
+ * and it says so by returning `null`.
204
+ */
205
+ declare const regexResolver: AnchorResolver;
206
+ /** CRLF normalized to LF before hashing, so checkout style cannot read as drift. */
207
+ declare function hashAnchorText(text: string): string;
208
+ /**
209
+ * An anchor without a symbol is about the whole file; with one, the resolver
210
+ * decides. Source newlines are normalized first so line counts and hashes
211
+ * agree with `hashAnchorText`.
212
+ *
213
+ * A file's last line is the last line with content: a trailing newline is a
214
+ * terminator, not an empty line, and counting it would have made every
215
+ * whole-file anchor's `lines` one larger than the file.
216
+ */
217
+ declare function resolveAnchor(source: string, anchor: KbAnchor, resolver?: AnchorResolver): ResolvedSymbol | null;
218
+ type KbAnchorDriftEntry = {
219
+ file: string;
220
+ symbol?: string;
221
+ state: "match" | "drifted" | "unresolved";
222
+ storedHash: string;
223
+ currentHash?: string;
224
+ /** `null` when the anchor recorded no `lines` — size unknown, not zero. */
225
+ diffSize: number | null;
226
+ reason?: AnchorUnresolvedReason;
227
+ };
228
+ /**
229
+ * An anchor's `file` must stay inside the repository root — a record points
230
+ * at code, not at arbitrary files on the machine reading it. Bundles are
231
+ * data, so a traversal or absolute path here is untrusted input, not a bug
232
+ * in the caller. Returns the resolved path, or `null` when it escapes.
233
+ *
234
+ * Lexical only, and therefore not the whole containment check: see
235
+ * `readAnchorFile`, which re-tests the real path after following symlinks.
236
+ */
237
+ declare function anchorFilePath(repoRoot: string, file: string): string | null;
238
+ type AnchorRead = {
239
+ ok: true;
240
+ source: string;
241
+ } | {
242
+ ok: false;
243
+ reason: AnchorUnresolvedReason;
244
+ };
245
+ type AnchorFileReader = (file: string) => Promise<AnchorRead>;
246
+ /**
247
+ * Re-resolves every hash-carrying anchor and compares against the stored hash.
248
+ *
249
+ * Anchors without a `hash` are skipped; one naming another repository is
250
+ * reported `foreign-repo` and never read, and `origin` is asked for once per
251
+ * run, only when some anchor declares a `repo`. A missing file or unresolvable
252
+ * symbol is a finding (`unresolved`), never a throw. Each distinct file is read
253
+ * once per run; all checked entries are returned per record, callers filter.
254
+ *
255
+ * Three phases: collect the checkable anchors, read their distinct files with
256
+ * a bounded pool, then resolve and hash in record order — so the output does
257
+ * not depend on which read finished first.
258
+ */
259
+ declare function detectAnchorDrift(records: KbRecord[], options?: {
260
+ repoRoot?: string;
261
+ resolver?: AnchorResolver;
262
+ concurrency?: number;
263
+ /** Test seam: replaces the disk reader. */
264
+ reader?: AnchorFileReader;
265
+ }): Promise<Map<string, KbAnchorDriftEntry[]>>;
266
+
148
267
  /**
149
268
  * Why a matched record must not be read as a plain answer.
150
269
  *
@@ -189,6 +308,18 @@ type KbWarning =
189
308
  staleAfter: string;
190
309
  } | {
191
310
  kind: "unverified";
311
+ }
312
+ /** The code this record anchors to has changed since its hash was recorded —
313
+ * the record may describe code that no longer exists in that form. */
314
+ | {
315
+ kind: "drifted";
316
+ anchors: {
317
+ file: string;
318
+ symbol?: string;
319
+ /** `null` when the anchor recorded no line count — size unknown. */
320
+ diffSize: number | null;
321
+ reason?: string;
322
+ }[];
192
323
  };
193
324
  type KbStanding = "current" | "superseded" | "rejected" | "unsettled" | "open";
194
325
  type KbAdjudicated = {
@@ -205,7 +336,7 @@ type KbAdjudicated = {
205
336
  * invisible: the caller cannot tell it missed anything, so a dropped record is
206
337
  * worse than a flagged one — it turns a knowable gap into an unknowable one.
207
338
  */
208
- declare function adjudicate(hits: KbRecord[], bundle: KbRecord[], now?: Date): KbAdjudicated[];
339
+ declare function adjudicate(hits: KbRecord[], bundle: KbRecord[], now?: Date, anchorDrift?: Map<string, KbAnchorDriftEntry[]>): KbAdjudicated[];
209
340
  /**
210
341
  * Walks a supersession chain to whatever currently stands in its place.
211
342
  *
@@ -526,6 +657,14 @@ declare class KbStore {
526
657
  * timeouts.
527
658
  */
528
659
  setStatus(bundlePath: string, conceptId: string, status: KbRecordStatus, actor?: string): Promise<KbRecord>;
660
+ /**
661
+ * Replaces a record's anchors wholesale, preserving everything else.
662
+ *
663
+ * Wholesale rather than merged: the caller just resolved the anchors it is
664
+ * writing, so it holds the complete current set, and a merge would keep
665
+ * stale entries the resolution pass deliberately dropped.
666
+ */
667
+ updateAnchors(bundlePath: string, conceptId: string, anchors: KbAnchor[], actor?: string): Promise<KbRecord>;
529
668
  /**
530
669
  * Appends one `verified[]` event: who checked the record, when, and what the
531
670
  * check found. Append-only — prior events are history, and are spread into
@@ -563,8 +702,31 @@ declare class KbStore {
563
702
  query(bundlePath: string, text: string, options?: {
564
703
  type?: string;
565
704
  includeNonCurrent?: boolean;
705
+ repoRoot?: string;
566
706
  }): Promise<KbAdjudicated[]>;
567
707
  private rank;
708
+ /**
709
+ * Anchor drift over the records about to be handed back. Like the search
710
+ * index, this is an enrichment: a filesystem failure degrades to "no drift
711
+ * reported" rather than failing the read. Anchors without a stored hash are
712
+ * skipped inside `detectAnchorDrift`, so a base nobody has stamped pays no
713
+ * fs cost here. `repoRoot` defaults to the working directory — the CLI runs
714
+ * at the repo root, and the MCP server's cwd is the workspace.
715
+ *
716
+ * Public because `doctor` needs the same map with the same degradation: a
717
+ * sweep that failed to read the tree should report no drift, not fail.
718
+ *
719
+ * When no root was given and not one anchored file was found, the finding is
720
+ * discarded. A base read from somewhere other than the tree it describes
721
+ * misses every file at once, and that shape is far likelier to be a wrong
722
+ * default root than a repository where every anchored file was deleted on
723
+ * the same day. Reporting it would put a drift warning on every record in
724
+ * the base, which teaches a reader to ignore the warning — the one outcome
725
+ * worse than not having it. One file found anywhere makes the root
726
+ * plausible, and the misses become findings again; an explicit `repoRoot` is
727
+ * taken at its word either way.
728
+ */
729
+ detectDrift(records: KbRecord[], repoRoot?: string): Promise<Map<string, KbAnchorDriftEntry[]> | undefined>;
568
730
  /**
569
731
  * The whole base, adjudicated, when it is small enough to hand over.
570
732
  *
@@ -599,6 +761,7 @@ declare class KbStore {
599
761
  budgetTokens?: number;
600
762
  type?: string;
601
763
  all?: boolean;
764
+ repoRoot?: string;
602
765
  }): Promise<KbLoadResult>;
603
766
  /** How a position was arrived at, as a timeline. See `trace.ts`. */
604
767
  trace(bundlePath: string, seedId: string, options?: KbTraceOptions): Promise<KbTraceStep[]>;
@@ -842,6 +1005,11 @@ declare const composeInputSchema: z.ZodObject<{
842
1005
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
843
1006
  file: z.ZodString;
844
1007
  symbol: z.ZodOptional<z.ZodString>;
1008
+ repo: z.ZodOptional<z.ZodString>;
1009
+ ref: z.ZodOptional<z.ZodString>;
1010
+ hash: z.ZodOptional<z.ZodString>;
1011
+ resolved_at: z.ZodOptional<z.ZodString>;
1012
+ lines: z.ZodOptional<z.ZodNumber>;
845
1013
  }, z.core.$strict>>>;
846
1014
  sources: z.ZodOptional<z.ZodArray<z.ZodObject<{
847
1015
  id: z.ZodString;
@@ -1281,9 +1449,10 @@ declare function validateBundle(records: KbRecord[]): KbValidationProblem[];
1281
1449
  * decay silently, because a stale record reads exactly like a live one and a
1282
1450
  * question nobody answered reads exactly like one nobody asked.
1283
1451
  *
1284
- * Grouped and counted rather than merged into one list: the seven checks are
1285
- * seven different repairs — re-verify, re-date, answer, link, or supersede
1286
- * and a flat list of "problems" would leave the reader sorting them again.
1452
+ * Grouped and counted rather than merged into one list: the eight checks are
1453
+ * eight different repairs — re-verify, re-date, answer, link, supersede, or
1454
+ * re-anchor — and a flat list of "problems" would leave the reader sorting
1455
+ * them again.
1287
1456
  *
1288
1457
  * Every group is emitted even when empty. A check that found nothing and a
1289
1458
  * check that never ran look identical in a report that only lists findings,
@@ -1292,7 +1461,7 @@ declare function validateBundle(records: KbRecord[]): KbValidationProblem[];
1292
1461
  declare const DEFAULT_EXPIRING_DAYS = 30;
1293
1462
  declare const DEFAULT_UNVERIFIED_DAYS = 90;
1294
1463
  declare const DEFAULT_AGING_DAYS = 90;
1295
- declare const KB_DOCTOR_CHECKS: readonly ["expired", "expiring", "unverified", "aging", "orphaned", "broken-supersession", "superseded-but-cited"];
1464
+ declare const KB_DOCTOR_CHECKS: readonly ["expired", "expiring", "unverified", "aging", "orphaned", "broken-supersession", "superseded-but-cited", "drifted"];
1296
1465
  type KbDoctorCheck = (typeof KB_DOCTOR_CHECKS)[number];
1297
1466
  type KbDoctorFinding = {
1298
1467
  conceptId: string;
@@ -1317,7 +1486,7 @@ type KbDoctorReport = {
1317
1486
  recordCount: number;
1318
1487
  thresholds: KbDoctorThresholds;
1319
1488
  counts: Record<KbDoctorCheck, number>;
1320
- /** All seven, in `KB_DOCTOR_CHECKS` order, empty ones included. */
1489
+ /** All eight, in `KB_DOCTOR_CHECKS` order, empty ones included. */
1321
1490
  groups: KbDoctorGroup[];
1322
1491
  findingCount: number;
1323
1492
  healthy: boolean;
@@ -1330,6 +1499,13 @@ type KbDoctorOptions = {
1330
1499
  /** How long `open` or `proposed` may stand before `aging` reports it. */
1331
1500
  agingDays?: number;
1332
1501
  now?: Date;
1502
+ /**
1503
+ * Anchor drift, precomputed by the caller. `doctor` stays pure and sync for
1504
+ * the same reason `adjudicate` does — the filesystem work of re-resolving
1505
+ * anchors belongs to `detectAnchorDrift`, and a sweep with no map simply
1506
+ * reports the `drifted` check as clean rather than half-running it.
1507
+ */
1508
+ anchorDrift?: Map<string, KbAnchorDriftEntry[]>;
1333
1509
  };
1334
1510
  declare function doctor(bundle: KbRecord[], options?: KbDoctorOptions): KbDoctorReport;
1335
1511
 
@@ -1377,6 +1553,11 @@ declare const decisionInputSchema: z.ZodObject<{
1377
1553
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
1378
1554
  file: z.ZodString;
1379
1555
  symbol: z.ZodOptional<z.ZodString>;
1556
+ repo: z.ZodOptional<z.ZodString>;
1557
+ ref: z.ZodOptional<z.ZodString>;
1558
+ hash: z.ZodOptional<z.ZodString>;
1559
+ resolved_at: z.ZodOptional<z.ZodString>;
1560
+ lines: z.ZodOptional<z.ZodNumber>;
1380
1561
  }, z.core.$strict>>>;
1381
1562
  verify: z.ZodOptional<z.ZodArray<z.ZodString>>;
1382
1563
  relatedConceptIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1611,4 +1792,4 @@ declare function parseMarkdownWithFrontmatter<S extends z.ZodType>(text: string,
1611
1792
  frontmatter: ReturnType<S["safeParse"]>;
1612
1793
  };
1613
1794
 
1614
- export { BaseError, CONTEXT_BEGIN, CONTEXT_END, CONTEXT_PROFILES, type ComposeInput, type ComposedRecord, DECISION_TYPE, DEFAULT_AGING_DAYS, DEFAULT_EXPIRING_DAYS, DEFAULT_LOAD_BUDGET, DEFAULT_PACK_HOPS, DEFAULT_PACK_MAX_NODES, DEFAULT_UNVERIFIED_DAYS, type DecisionInput, type DiffFile, type DiffHunk, type DiffMatch, type ErrorDetails, type ErrorProps, ErrorTypes, Fault, INDEX_FILE, KB_COMMANDS, KB_COMMANDS_BY_NAME, KB_CONCEPT_ID_PATTERN, KB_CONFIDENCES, KB_DIR, KB_DOCTOR_CHECKS, KB_EDGE_KINDS, KB_MATERIALITIES, KB_RECORD_STATUSES, KB_RECORD_TYPES, KB_SLUG_PATTERN, type KbActorStamp, type KbAdjudicated, type KbAnchor, KbBaseFrozenError, type KbCatalogEntry, type KbCatalogResult, type KbCommand, type KbCommandContext, type KbContextBudgets, type KbContextOptions, type KbContextResult, type KbDoctorCheck, type KbDoctorFinding, type KbDoctorGroup, type KbDoctorOptions, type KbDoctorReport, type KbDoctorThresholds, type KbEdgeKind, KbInvalidConceptIdError, type KbLoadResult, type KbLogEntry, type KbLogReadResult, type KbLogger, type KbMergedPin, type KbMergedPins, KbMissingFlagValueError, type KbNeighbour, KbPackBudgetExceededError, type KbPackOptions, type KbPackResult, type KbPackedRecord, type KbPin, type KbPinLayer, type KbPinOptions, type KbPinResult, type KbPinStatus, KbPinsMalformedError, type KbPinsManifest, type KbRecord, KbRecordAlreadyExistsError, type KbRecordFrontmatter, KbRecordNotFoundError, type KbRecordStatus, type KbRecordType, type KbRecordTypeSpec, type KbSearchLogger, KbSelfVerificationError, type KbSource, type KbStanding, KbStore, type KbSupersededStub, type KbSyncResult, type KbTraceEdge, type KbTraceOptions, type KbTraceStep, type KbValidationProblem, type KbVerifiedEvent, type KbWarning, KbWriteConflictError, type KbWriteInput, LOG_FILE, type MatchOptions, NO_DECISION_SLUG, PINS_FILE, PINS_LOCAL_FILE, PIN_LAYERS, type QmdModule, RECORD_TYPES, SEARCH_INDEX_FILE, type SearchHit, type SearchOptions, type SymbolRange, TRACE_EDGES, adjudicate, assertBaseNotFrozen, buildContext, catalog, composeDecisionRecord, composeInputSchema, composeNoDecisionRecord, composeRecord, contextProfileBudgets, createKbMcpServer, decisionInputSchema, doctor, edgeNeighbours, indexIsStale, isKbRecordType, isNoDecisionRecord, kbActorStampSchema, kbAnchorSchema, kbConceptIdSchema, kbJsonSchemas, kbLogEntrySchema, kbRecordFrontmatterSchema, kbSourceSchema, kbVerifiedEventSchema, listPins, loadQmd, matchToDiff, mergedContextBudgets, neighbours, pack, parseLog, parseMarkdownWithFrontmatter, pinBase, readMergedPins, readPinsLayer, renderCatalogLine, renderIndex, renderIndexLine, renderLogEntry, resolveHeads, resolveHits, resolvePinPath, runKbCli, runKbMcpServer, searchBase, selectDecisions, splitMarkdownFrontmatter, stringifyMarkdownWithFrontmatter, syncInstructions, toHookJson, trace, unpinBase, validateBundle };
1795
+ export { type AnchorResolver, BaseError, CONTEXT_BEGIN, CONTEXT_END, CONTEXT_PROFILES, type ComposeInput, type ComposedRecord, DECISION_TYPE, DEFAULT_AGING_DAYS, DEFAULT_EXPIRING_DAYS, DEFAULT_LOAD_BUDGET, DEFAULT_PACK_HOPS, DEFAULT_PACK_MAX_NODES, DEFAULT_UNVERIFIED_DAYS, type DecisionInput, type DiffFile, type DiffHunk, type DiffMatch, type ErrorDetails, type ErrorProps, ErrorTypes, Fault, INDEX_FILE, KB_COMMANDS, KB_COMMANDS_BY_NAME, KB_CONCEPT_ID_PATTERN, KB_CONFIDENCES, KB_DIR, KB_DOCTOR_CHECKS, KB_EDGE_KINDS, KB_MATERIALITIES, KB_RECORD_STATUSES, KB_RECORD_TYPES, KB_SLUG_PATTERN, type KbActorStamp, type KbAdjudicated, type KbAnchor, type KbAnchorDriftEntry, KbBaseFrozenError, type KbCatalogEntry, type KbCatalogResult, type KbCommand, type KbCommandContext, type KbContextBudgets, type KbContextOptions, type KbContextResult, type KbDoctorCheck, type KbDoctorFinding, type KbDoctorGroup, type KbDoctorOptions, type KbDoctorReport, type KbDoctorThresholds, type KbEdgeKind, KbInvalidConceptIdError, type KbLoadResult, type KbLogEntry, type KbLogReadResult, type KbLogger, type KbMergedPin, type KbMergedPins, KbMissingFlagValueError, type KbNeighbour, KbPackBudgetExceededError, type KbPackOptions, type KbPackResult, type KbPackedRecord, type KbPin, type KbPinLayer, type KbPinOptions, type KbPinResult, type KbPinStatus, KbPinsMalformedError, type KbPinsManifest, type KbRecord, KbRecordAlreadyExistsError, type KbRecordFrontmatter, KbRecordNotFoundError, type KbRecordStatus, type KbRecordType, type KbRecordTypeSpec, type KbSearchLogger, KbSelfVerificationError, type KbSource, type KbStanding, KbStore, type KbSupersededStub, type KbSyncResult, type KbTraceEdge, type KbTraceOptions, type KbTraceStep, type KbValidationProblem, type KbVerifiedEvent, type KbWarning, KbWriteConflictError, type KbWriteInput, LOG_FILE, type MatchOptions, NO_DECISION_SLUG, PINS_FILE, PINS_LOCAL_FILE, PIN_LAYERS, type QmdModule, RECORD_TYPES, type ResolvedSymbol, SEARCH_INDEX_FILE, type SearchHit, type SearchOptions, type SymbolRange, TRACE_EDGES, adjudicate, anchorFilePath, assertBaseNotFrozen, buildContext, catalog, composeDecisionRecord, composeInputSchema, composeNoDecisionRecord, composeRecord, contextProfileBudgets, createKbMcpServer, decisionInputSchema, detectAnchorDrift, doctor, edgeNeighbours, hashAnchorText, indexIsStale, isKbRecordType, isNoDecisionRecord, kbActorStampSchema, kbAnchorSchema, kbConceptIdSchema, kbJsonSchemas, kbLogEntrySchema, kbRecordFrontmatterSchema, kbSourceSchema, kbVerifiedEventSchema, listPins, loadQmd, matchToDiff, mergedContextBudgets, neighbours, pack, parseLog, parseMarkdownWithFrontmatter, pinBase, readMergedPins, readPinsLayer, regexResolver, renderCatalogLine, renderIndex, renderIndexLine, renderLogEntry, resolveAnchor, resolveHeads, resolveHits, resolvePinPath, runKbCli, runKbMcpServer, searchBase, selectDecisions, splitMarkdownFrontmatter, stringifyMarkdownWithFrontmatter, syncInstructions, toHookJson, trace, unpinBase, validateBundle };
package/dist/index.d.ts CHANGED
@@ -47,13 +47,29 @@ declare const kbVerifiedEventSchema: z.ZodObject<{
47
47
  *
48
48
  * Symbolic on purpose. These are written while the code is still moving: a
49
49
  * `line: 379` recorded at minute five is wrong by minute forty, but
50
- * `OrderService.cancel` survives every edit that does not rename it. A later
51
- * pass resolves symbols to line ranges once the change has settled, and records
52
- * that resolution as a `verified[]` entry.
50
+ * `OrderService.cancel` survives every edit that does not rename it. Once the
51
+ * change settles, a resolution pass (`anchor-resolver.ts`) stamps `hash`,
52
+ * `resolved_at`, and `lines`; drift detection later re-resolves and compares.
53
+ *
54
+ * `hash` is prefixed with the algorithm so a future one can coexist with
55
+ * stored values. `lines` exists because the anchor keeps a hash, not the text:
56
+ * without the line count at hash time, a drift report could say "changed" but
57
+ * never how much.
58
+ *
59
+ * `repo` and `ref` say *which* code, for bases that describe more than one
60
+ * repository. They are author-owned identity: a resolver stamps `hash`,
61
+ * `lines`, and `resolved_at`, and never writes these two. Both are optional and
62
+ * independent of each other, so every anchor written before they existed stays
63
+ * valid.
53
64
  */
54
65
  declare const kbAnchorSchema: z.ZodObject<{
55
66
  file: z.ZodString;
56
67
  symbol: z.ZodOptional<z.ZodString>;
68
+ repo: z.ZodOptional<z.ZodString>;
69
+ ref: z.ZodOptional<z.ZodString>;
70
+ hash: z.ZodOptional<z.ZodString>;
71
+ resolved_at: z.ZodOptional<z.ZodString>;
72
+ lines: z.ZodOptional<z.ZodNumber>;
57
73
  }, z.core.$strict>;
58
74
  declare const KB_RECORD_TYPES: readonly ["fact", "requirement", "constraint", "decision", "assumption", "open-question", "risk", "contract", "flow", "affected-system", "test-obligation", "source-note"];
59
75
  type KbRecordType = (typeof KB_RECORD_TYPES)[number];
@@ -103,6 +119,11 @@ declare const kbRecordFrontmatterSchema: z.ZodObject<{
103
119
  strauss_anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
104
120
  file: z.ZodString;
105
121
  symbol: z.ZodOptional<z.ZodString>;
122
+ repo: z.ZodOptional<z.ZodString>;
123
+ ref: z.ZodOptional<z.ZodString>;
124
+ hash: z.ZodOptional<z.ZodString>;
125
+ resolved_at: z.ZodOptional<z.ZodString>;
126
+ lines: z.ZodOptional<z.ZodNumber>;
106
127
  }, z.core.$strict>>>;
107
128
  strauss_verify: z.ZodOptional<z.ZodArray<z.ZodString>>;
108
129
  strauss_status: z.ZodDefault<z.ZodEnum<{
@@ -145,6 +166,104 @@ type KbRecord = {
145
166
  body: string;
146
167
  };
147
168
 
169
+ /**
170
+ * Resolves symbolic anchors to text and detects drift against stored hashes.
171
+ *
172
+ * Resolvers are pure — source string in, range out; only the file readers touch
173
+ * disk. Any shape the lexer cannot handle confidently returns `null` and is
174
+ * reported `unresolved` rather than guessed at.
175
+ */
176
+ type ResolvedSymbol = {
177
+ text: string;
178
+ /** 1-based, inclusive. */
179
+ startLine: number;
180
+ endLine: number;
181
+ };
182
+ interface AnchorResolver {
183
+ name: string;
184
+ resolve(source: string, symbol: string): ResolvedSymbol | null;
185
+ }
186
+ /** Why an anchor could not be compared. Never an error — always a finding. */
187
+ type AnchorUnresolvedReason = "file-missing" | "symbol-not-found" | "outside-repo" | "file-too-large" | "file-unreadable"
188
+ /**
189
+ * The anchor names a repository this root is not. Expected rather than
190
+ * wrong — a base describing several repositories resolves against one tree
191
+ * at a time — so it is never a drift finding and never reaches a reader as
192
+ * a warning. Multi-root resolution is SAA-709.
193
+ */
194
+ | "foreign-repo";
195
+ /**
196
+ * v1 heuristic resolver. A dotted symbol like `OrderService.cancel` matches on
197
+ * its last segment, with the parent used to scope the search: a candidate
198
+ * counts only if the parent name appears in the fifty lines above it, when any
199
+ * candidate satisfies that at all.
200
+ *
201
+ * Deterministic, and ambiguity is not resolved by guessing — two lines of
202
+ * equally good shape mean the resolver cannot tell which one the record meant,
203
+ * and it says so by returning `null`.
204
+ */
205
+ declare const regexResolver: AnchorResolver;
206
+ /** CRLF normalized to LF before hashing, so checkout style cannot read as drift. */
207
+ declare function hashAnchorText(text: string): string;
208
+ /**
209
+ * An anchor without a symbol is about the whole file; with one, the resolver
210
+ * decides. Source newlines are normalized first so line counts and hashes
211
+ * agree with `hashAnchorText`.
212
+ *
213
+ * A file's last line is the last line with content: a trailing newline is a
214
+ * terminator, not an empty line, and counting it would have made every
215
+ * whole-file anchor's `lines` one larger than the file.
216
+ */
217
+ declare function resolveAnchor(source: string, anchor: KbAnchor, resolver?: AnchorResolver): ResolvedSymbol | null;
218
+ type KbAnchorDriftEntry = {
219
+ file: string;
220
+ symbol?: string;
221
+ state: "match" | "drifted" | "unresolved";
222
+ storedHash: string;
223
+ currentHash?: string;
224
+ /** `null` when the anchor recorded no `lines` — size unknown, not zero. */
225
+ diffSize: number | null;
226
+ reason?: AnchorUnresolvedReason;
227
+ };
228
+ /**
229
+ * An anchor's `file` must stay inside the repository root — a record points
230
+ * at code, not at arbitrary files on the machine reading it. Bundles are
231
+ * data, so a traversal or absolute path here is untrusted input, not a bug
232
+ * in the caller. Returns the resolved path, or `null` when it escapes.
233
+ *
234
+ * Lexical only, and therefore not the whole containment check: see
235
+ * `readAnchorFile`, which re-tests the real path after following symlinks.
236
+ */
237
+ declare function anchorFilePath(repoRoot: string, file: string): string | null;
238
+ type AnchorRead = {
239
+ ok: true;
240
+ source: string;
241
+ } | {
242
+ ok: false;
243
+ reason: AnchorUnresolvedReason;
244
+ };
245
+ type AnchorFileReader = (file: string) => Promise<AnchorRead>;
246
+ /**
247
+ * Re-resolves every hash-carrying anchor and compares against the stored hash.
248
+ *
249
+ * Anchors without a `hash` are skipped; one naming another repository is
250
+ * reported `foreign-repo` and never read, and `origin` is asked for once per
251
+ * run, only when some anchor declares a `repo`. A missing file or unresolvable
252
+ * symbol is a finding (`unresolved`), never a throw. Each distinct file is read
253
+ * once per run; all checked entries are returned per record, callers filter.
254
+ *
255
+ * Three phases: collect the checkable anchors, read their distinct files with
256
+ * a bounded pool, then resolve and hash in record order — so the output does
257
+ * not depend on which read finished first.
258
+ */
259
+ declare function detectAnchorDrift(records: KbRecord[], options?: {
260
+ repoRoot?: string;
261
+ resolver?: AnchorResolver;
262
+ concurrency?: number;
263
+ /** Test seam: replaces the disk reader. */
264
+ reader?: AnchorFileReader;
265
+ }): Promise<Map<string, KbAnchorDriftEntry[]>>;
266
+
148
267
  /**
149
268
  * Why a matched record must not be read as a plain answer.
150
269
  *
@@ -189,6 +308,18 @@ type KbWarning =
189
308
  staleAfter: string;
190
309
  } | {
191
310
  kind: "unverified";
311
+ }
312
+ /** The code this record anchors to has changed since its hash was recorded —
313
+ * the record may describe code that no longer exists in that form. */
314
+ | {
315
+ kind: "drifted";
316
+ anchors: {
317
+ file: string;
318
+ symbol?: string;
319
+ /** `null` when the anchor recorded no line count — size unknown. */
320
+ diffSize: number | null;
321
+ reason?: string;
322
+ }[];
192
323
  };
193
324
  type KbStanding = "current" | "superseded" | "rejected" | "unsettled" | "open";
194
325
  type KbAdjudicated = {
@@ -205,7 +336,7 @@ type KbAdjudicated = {
205
336
  * invisible: the caller cannot tell it missed anything, so a dropped record is
206
337
  * worse than a flagged one — it turns a knowable gap into an unknowable one.
207
338
  */
208
- declare function adjudicate(hits: KbRecord[], bundle: KbRecord[], now?: Date): KbAdjudicated[];
339
+ declare function adjudicate(hits: KbRecord[], bundle: KbRecord[], now?: Date, anchorDrift?: Map<string, KbAnchorDriftEntry[]>): KbAdjudicated[];
209
340
  /**
210
341
  * Walks a supersession chain to whatever currently stands in its place.
211
342
  *
@@ -526,6 +657,14 @@ declare class KbStore {
526
657
  * timeouts.
527
658
  */
528
659
  setStatus(bundlePath: string, conceptId: string, status: KbRecordStatus, actor?: string): Promise<KbRecord>;
660
+ /**
661
+ * Replaces a record's anchors wholesale, preserving everything else.
662
+ *
663
+ * Wholesale rather than merged: the caller just resolved the anchors it is
664
+ * writing, so it holds the complete current set, and a merge would keep
665
+ * stale entries the resolution pass deliberately dropped.
666
+ */
667
+ updateAnchors(bundlePath: string, conceptId: string, anchors: KbAnchor[], actor?: string): Promise<KbRecord>;
529
668
  /**
530
669
  * Appends one `verified[]` event: who checked the record, when, and what the
531
670
  * check found. Append-only — prior events are history, and are spread into
@@ -563,8 +702,31 @@ declare class KbStore {
563
702
  query(bundlePath: string, text: string, options?: {
564
703
  type?: string;
565
704
  includeNonCurrent?: boolean;
705
+ repoRoot?: string;
566
706
  }): Promise<KbAdjudicated[]>;
567
707
  private rank;
708
+ /**
709
+ * Anchor drift over the records about to be handed back. Like the search
710
+ * index, this is an enrichment: a filesystem failure degrades to "no drift
711
+ * reported" rather than failing the read. Anchors without a stored hash are
712
+ * skipped inside `detectAnchorDrift`, so a base nobody has stamped pays no
713
+ * fs cost here. `repoRoot` defaults to the working directory — the CLI runs
714
+ * at the repo root, and the MCP server's cwd is the workspace.
715
+ *
716
+ * Public because `doctor` needs the same map with the same degradation: a
717
+ * sweep that failed to read the tree should report no drift, not fail.
718
+ *
719
+ * When no root was given and not one anchored file was found, the finding is
720
+ * discarded. A base read from somewhere other than the tree it describes
721
+ * misses every file at once, and that shape is far likelier to be a wrong
722
+ * default root than a repository where every anchored file was deleted on
723
+ * the same day. Reporting it would put a drift warning on every record in
724
+ * the base, which teaches a reader to ignore the warning — the one outcome
725
+ * worse than not having it. One file found anywhere makes the root
726
+ * plausible, and the misses become findings again; an explicit `repoRoot` is
727
+ * taken at its word either way.
728
+ */
729
+ detectDrift(records: KbRecord[], repoRoot?: string): Promise<Map<string, KbAnchorDriftEntry[]> | undefined>;
568
730
  /**
569
731
  * The whole base, adjudicated, when it is small enough to hand over.
570
732
  *
@@ -599,6 +761,7 @@ declare class KbStore {
599
761
  budgetTokens?: number;
600
762
  type?: string;
601
763
  all?: boolean;
764
+ repoRoot?: string;
602
765
  }): Promise<KbLoadResult>;
603
766
  /** How a position was arrived at, as a timeline. See `trace.ts`. */
604
767
  trace(bundlePath: string, seedId: string, options?: KbTraceOptions): Promise<KbTraceStep[]>;
@@ -842,6 +1005,11 @@ declare const composeInputSchema: z.ZodObject<{
842
1005
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
843
1006
  file: z.ZodString;
844
1007
  symbol: z.ZodOptional<z.ZodString>;
1008
+ repo: z.ZodOptional<z.ZodString>;
1009
+ ref: z.ZodOptional<z.ZodString>;
1010
+ hash: z.ZodOptional<z.ZodString>;
1011
+ resolved_at: z.ZodOptional<z.ZodString>;
1012
+ lines: z.ZodOptional<z.ZodNumber>;
845
1013
  }, z.core.$strict>>>;
846
1014
  sources: z.ZodOptional<z.ZodArray<z.ZodObject<{
847
1015
  id: z.ZodString;
@@ -1281,9 +1449,10 @@ declare function validateBundle(records: KbRecord[]): KbValidationProblem[];
1281
1449
  * decay silently, because a stale record reads exactly like a live one and a
1282
1450
  * question nobody answered reads exactly like one nobody asked.
1283
1451
  *
1284
- * Grouped and counted rather than merged into one list: the seven checks are
1285
- * seven different repairs — re-verify, re-date, answer, link, or supersede
1286
- * and a flat list of "problems" would leave the reader sorting them again.
1452
+ * Grouped and counted rather than merged into one list: the eight checks are
1453
+ * eight different repairs — re-verify, re-date, answer, link, supersede, or
1454
+ * re-anchor — and a flat list of "problems" would leave the reader sorting
1455
+ * them again.
1287
1456
  *
1288
1457
  * Every group is emitted even when empty. A check that found nothing and a
1289
1458
  * check that never ran look identical in a report that only lists findings,
@@ -1292,7 +1461,7 @@ declare function validateBundle(records: KbRecord[]): KbValidationProblem[];
1292
1461
  declare const DEFAULT_EXPIRING_DAYS = 30;
1293
1462
  declare const DEFAULT_UNVERIFIED_DAYS = 90;
1294
1463
  declare const DEFAULT_AGING_DAYS = 90;
1295
- declare const KB_DOCTOR_CHECKS: readonly ["expired", "expiring", "unverified", "aging", "orphaned", "broken-supersession", "superseded-but-cited"];
1464
+ declare const KB_DOCTOR_CHECKS: readonly ["expired", "expiring", "unverified", "aging", "orphaned", "broken-supersession", "superseded-but-cited", "drifted"];
1296
1465
  type KbDoctorCheck = (typeof KB_DOCTOR_CHECKS)[number];
1297
1466
  type KbDoctorFinding = {
1298
1467
  conceptId: string;
@@ -1317,7 +1486,7 @@ type KbDoctorReport = {
1317
1486
  recordCount: number;
1318
1487
  thresholds: KbDoctorThresholds;
1319
1488
  counts: Record<KbDoctorCheck, number>;
1320
- /** All seven, in `KB_DOCTOR_CHECKS` order, empty ones included. */
1489
+ /** All eight, in `KB_DOCTOR_CHECKS` order, empty ones included. */
1321
1490
  groups: KbDoctorGroup[];
1322
1491
  findingCount: number;
1323
1492
  healthy: boolean;
@@ -1330,6 +1499,13 @@ type KbDoctorOptions = {
1330
1499
  /** How long `open` or `proposed` may stand before `aging` reports it. */
1331
1500
  agingDays?: number;
1332
1501
  now?: Date;
1502
+ /**
1503
+ * Anchor drift, precomputed by the caller. `doctor` stays pure and sync for
1504
+ * the same reason `adjudicate` does — the filesystem work of re-resolving
1505
+ * anchors belongs to `detectAnchorDrift`, and a sweep with no map simply
1506
+ * reports the `drifted` check as clean rather than half-running it.
1507
+ */
1508
+ anchorDrift?: Map<string, KbAnchorDriftEntry[]>;
1333
1509
  };
1334
1510
  declare function doctor(bundle: KbRecord[], options?: KbDoctorOptions): KbDoctorReport;
1335
1511
 
@@ -1377,6 +1553,11 @@ declare const decisionInputSchema: z.ZodObject<{
1377
1553
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
1378
1554
  file: z.ZodString;
1379
1555
  symbol: z.ZodOptional<z.ZodString>;
1556
+ repo: z.ZodOptional<z.ZodString>;
1557
+ ref: z.ZodOptional<z.ZodString>;
1558
+ hash: z.ZodOptional<z.ZodString>;
1559
+ resolved_at: z.ZodOptional<z.ZodString>;
1560
+ lines: z.ZodOptional<z.ZodNumber>;
1380
1561
  }, z.core.$strict>>>;
1381
1562
  verify: z.ZodOptional<z.ZodArray<z.ZodString>>;
1382
1563
  relatedConceptIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1611,4 +1792,4 @@ declare function parseMarkdownWithFrontmatter<S extends z.ZodType>(text: string,
1611
1792
  frontmatter: ReturnType<S["safeParse"]>;
1612
1793
  };
1613
1794
 
1614
- export { BaseError, CONTEXT_BEGIN, CONTEXT_END, CONTEXT_PROFILES, type ComposeInput, type ComposedRecord, DECISION_TYPE, DEFAULT_AGING_DAYS, DEFAULT_EXPIRING_DAYS, DEFAULT_LOAD_BUDGET, DEFAULT_PACK_HOPS, DEFAULT_PACK_MAX_NODES, DEFAULT_UNVERIFIED_DAYS, type DecisionInput, type DiffFile, type DiffHunk, type DiffMatch, type ErrorDetails, type ErrorProps, ErrorTypes, Fault, INDEX_FILE, KB_COMMANDS, KB_COMMANDS_BY_NAME, KB_CONCEPT_ID_PATTERN, KB_CONFIDENCES, KB_DIR, KB_DOCTOR_CHECKS, KB_EDGE_KINDS, KB_MATERIALITIES, KB_RECORD_STATUSES, KB_RECORD_TYPES, KB_SLUG_PATTERN, type KbActorStamp, type KbAdjudicated, type KbAnchor, KbBaseFrozenError, type KbCatalogEntry, type KbCatalogResult, type KbCommand, type KbCommandContext, type KbContextBudgets, type KbContextOptions, type KbContextResult, type KbDoctorCheck, type KbDoctorFinding, type KbDoctorGroup, type KbDoctorOptions, type KbDoctorReport, type KbDoctorThresholds, type KbEdgeKind, KbInvalidConceptIdError, type KbLoadResult, type KbLogEntry, type KbLogReadResult, type KbLogger, type KbMergedPin, type KbMergedPins, KbMissingFlagValueError, type KbNeighbour, KbPackBudgetExceededError, type KbPackOptions, type KbPackResult, type KbPackedRecord, type KbPin, type KbPinLayer, type KbPinOptions, type KbPinResult, type KbPinStatus, KbPinsMalformedError, type KbPinsManifest, type KbRecord, KbRecordAlreadyExistsError, type KbRecordFrontmatter, KbRecordNotFoundError, type KbRecordStatus, type KbRecordType, type KbRecordTypeSpec, type KbSearchLogger, KbSelfVerificationError, type KbSource, type KbStanding, KbStore, type KbSupersededStub, type KbSyncResult, type KbTraceEdge, type KbTraceOptions, type KbTraceStep, type KbValidationProblem, type KbVerifiedEvent, type KbWarning, KbWriteConflictError, type KbWriteInput, LOG_FILE, type MatchOptions, NO_DECISION_SLUG, PINS_FILE, PINS_LOCAL_FILE, PIN_LAYERS, type QmdModule, RECORD_TYPES, SEARCH_INDEX_FILE, type SearchHit, type SearchOptions, type SymbolRange, TRACE_EDGES, adjudicate, assertBaseNotFrozen, buildContext, catalog, composeDecisionRecord, composeInputSchema, composeNoDecisionRecord, composeRecord, contextProfileBudgets, createKbMcpServer, decisionInputSchema, doctor, edgeNeighbours, indexIsStale, isKbRecordType, isNoDecisionRecord, kbActorStampSchema, kbAnchorSchema, kbConceptIdSchema, kbJsonSchemas, kbLogEntrySchema, kbRecordFrontmatterSchema, kbSourceSchema, kbVerifiedEventSchema, listPins, loadQmd, matchToDiff, mergedContextBudgets, neighbours, pack, parseLog, parseMarkdownWithFrontmatter, pinBase, readMergedPins, readPinsLayer, renderCatalogLine, renderIndex, renderIndexLine, renderLogEntry, resolveHeads, resolveHits, resolvePinPath, runKbCli, runKbMcpServer, searchBase, selectDecisions, splitMarkdownFrontmatter, stringifyMarkdownWithFrontmatter, syncInstructions, toHookJson, trace, unpinBase, validateBundle };
1795
+ export { type AnchorResolver, BaseError, CONTEXT_BEGIN, CONTEXT_END, CONTEXT_PROFILES, type ComposeInput, type ComposedRecord, DECISION_TYPE, DEFAULT_AGING_DAYS, DEFAULT_EXPIRING_DAYS, DEFAULT_LOAD_BUDGET, DEFAULT_PACK_HOPS, DEFAULT_PACK_MAX_NODES, DEFAULT_UNVERIFIED_DAYS, type DecisionInput, type DiffFile, type DiffHunk, type DiffMatch, type ErrorDetails, type ErrorProps, ErrorTypes, Fault, INDEX_FILE, KB_COMMANDS, KB_COMMANDS_BY_NAME, KB_CONCEPT_ID_PATTERN, KB_CONFIDENCES, KB_DIR, KB_DOCTOR_CHECKS, KB_EDGE_KINDS, KB_MATERIALITIES, KB_RECORD_STATUSES, KB_RECORD_TYPES, KB_SLUG_PATTERN, type KbActorStamp, type KbAdjudicated, type KbAnchor, type KbAnchorDriftEntry, KbBaseFrozenError, type KbCatalogEntry, type KbCatalogResult, type KbCommand, type KbCommandContext, type KbContextBudgets, type KbContextOptions, type KbContextResult, type KbDoctorCheck, type KbDoctorFinding, type KbDoctorGroup, type KbDoctorOptions, type KbDoctorReport, type KbDoctorThresholds, type KbEdgeKind, KbInvalidConceptIdError, type KbLoadResult, type KbLogEntry, type KbLogReadResult, type KbLogger, type KbMergedPin, type KbMergedPins, KbMissingFlagValueError, type KbNeighbour, KbPackBudgetExceededError, type KbPackOptions, type KbPackResult, type KbPackedRecord, type KbPin, type KbPinLayer, type KbPinOptions, type KbPinResult, type KbPinStatus, KbPinsMalformedError, type KbPinsManifest, type KbRecord, KbRecordAlreadyExistsError, type KbRecordFrontmatter, KbRecordNotFoundError, type KbRecordStatus, type KbRecordType, type KbRecordTypeSpec, type KbSearchLogger, KbSelfVerificationError, type KbSource, type KbStanding, KbStore, type KbSupersededStub, type KbSyncResult, type KbTraceEdge, type KbTraceOptions, type KbTraceStep, type KbValidationProblem, type KbVerifiedEvent, type KbWarning, KbWriteConflictError, type KbWriteInput, LOG_FILE, type MatchOptions, NO_DECISION_SLUG, PINS_FILE, PINS_LOCAL_FILE, PIN_LAYERS, type QmdModule, RECORD_TYPES, type ResolvedSymbol, SEARCH_INDEX_FILE, type SearchHit, type SearchOptions, type SymbolRange, TRACE_EDGES, adjudicate, anchorFilePath, assertBaseNotFrozen, buildContext, catalog, composeDecisionRecord, composeInputSchema, composeNoDecisionRecord, composeRecord, contextProfileBudgets, createKbMcpServer, decisionInputSchema, detectAnchorDrift, doctor, edgeNeighbours, hashAnchorText, indexIsStale, isKbRecordType, isNoDecisionRecord, kbActorStampSchema, kbAnchorSchema, kbConceptIdSchema, kbJsonSchemas, kbLogEntrySchema, kbRecordFrontmatterSchema, kbSourceSchema, kbVerifiedEventSchema, listPins, loadQmd, matchToDiff, mergedContextBudgets, neighbours, pack, parseLog, parseMarkdownWithFrontmatter, pinBase, readMergedPins, readPinsLayer, regexResolver, renderCatalogLine, renderIndex, renderIndexLine, renderLogEntry, resolveAnchor, resolveHeads, resolveHits, resolvePinPath, runKbCli, runKbMcpServer, searchBase, selectDecisions, splitMarkdownFrontmatter, stringifyMarkdownWithFrontmatter, syncInstructions, toHookJson, trace, unpinBase, validateBundle };