@saasontools/strauss-kb 0.1.12 → 0.1.13

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/mcp-main.cjs CHANGED
@@ -79,6 +79,10 @@ var kbAnchorSchema = import_zod.z.object({
79
79
  /** Line count of the text the hash was taken over. */
80
80
  lines: import_zod.z.number().int().positive().optional()
81
81
  }).strict();
82
+ var kbLinkSchema = import_zod.z.object({
83
+ target: import_zod.z.string().min(1),
84
+ rel: import_zod.z.string().min(1)
85
+ }).passthrough();
82
86
  var KB_RECORD_TYPES = [
83
87
  "fact",
84
88
  "requirement",
@@ -130,6 +134,10 @@ var kbRecordFrontmatterSchema = import_zod.z.object({
130
134
  // strauss extensions — see the module comment.
131
135
  strauss_anchors: import_zod.z.array(kbAnchorSchema).optional(),
132
136
  strauss_verify: import_zod.z.array(import_zod.z.string().min(1)).optional(),
137
+ // Typed causal edges, source → target, living on the source. `A depends_on
138
+ // B` means A needs B, so `kb_impact` walks these inbound: what breaks if B
139
+ // changes is whatever declared a dependence on it.
140
+ strauss_links: import_zod.z.array(kbLinkSchema).optional(),
133
141
  // Total after parsing, tolerant before it. Our producers must supply a
134
142
  // status — an absent one would leave every reader inventing its own default
135
143
  // — but OKF calls a concept carrying only `type` fully conformant, so
@@ -214,8 +222,70 @@ var RECORD_TYPES = {
214
222
  function isKbRecordType(value) {
215
223
  return Object.prototype.hasOwnProperty.call(RECORD_TYPES, value);
216
224
  }
225
+ var KB_LINK_RELS = [
226
+ "depends_on",
227
+ "constrains",
228
+ "informs",
229
+ "blocks",
230
+ "invalidates",
231
+ "verified_by",
232
+ "satisfies",
233
+ "related_to"
234
+ ];
235
+ var LINK_RELS = {
236
+ depends_on: {
237
+ purpose: "The source needs the target to hold; the source breaks if the target changes",
238
+ phrase: "Depends on",
239
+ dependant: "source"
240
+ },
241
+ constrains: {
242
+ purpose: "The source bounds what the target may do; the target breaks if the constraint changes",
243
+ phrase: "Constrains",
244
+ dependant: "target"
245
+ },
246
+ informs: {
247
+ purpose: "The source shaped the target without binding it; the target is what needs revisiting",
248
+ phrase: "Informs",
249
+ dependant: "target"
250
+ },
251
+ blocks: {
252
+ purpose: "The target cannot proceed until the source is settled; the target is what waits",
253
+ phrase: "Blocks",
254
+ dependant: "target"
255
+ },
256
+ invalidates: {
257
+ purpose: "The source makes the target no longer hold; the target is what stops holding",
258
+ phrase: "Invalidates",
259
+ dependant: "target"
260
+ },
261
+ verified_by: {
262
+ purpose: "The target is the check that confirms the source; the source's confirmation moves with it",
263
+ phrase: "Verified by",
264
+ dependant: "source"
265
+ },
266
+ satisfies: {
267
+ purpose: "The source discharges the target's requirement; the source must change if the requirement does",
268
+ phrase: "Satisfies",
269
+ dependant: "source"
270
+ },
271
+ related_to: {
272
+ purpose: "A pointer worth following, with no claim of dependence",
273
+ phrase: "Relates to",
274
+ dependant: null
275
+ }
276
+ };
277
+ var KB_CAUSAL_LINK_RELS = KB_LINK_RELS.filter(
278
+ (rel) => LINK_RELS[rel].dependant !== null
279
+ );
280
+ function isKbLinkRel(value) {
281
+ return Object.prototype.hasOwnProperty.call(LINK_RELS, value);
282
+ }
217
283
 
218
284
  // src/compose.ts
285
+ var composeLinkSchema = import_zod2.z.object({
286
+ target: kbConceptIdSchema,
287
+ rel: import_zod2.z.enum(KB_LINK_RELS)
288
+ }).strict();
219
289
  var composeInputSchema = import_zod2.z.object({
220
290
  slug: import_zod2.z.string().min(1),
221
291
  /** One line, in the reader's terms. Becomes OKF `title`. */
@@ -242,6 +312,18 @@ var composeInputSchema = import_zod2.z.object({
242
312
  tags: import_zod2.z.array(import_zod2.z.string().min(1)).optional(),
243
313
  /** Concept ids this record relates to; rendered as body links. */
244
314
  relatedConceptIds: import_zod2.z.array(kbConceptIdSchema).optional(),
315
+ /**
316
+ * Typed causal edges, source → target: `{ target: "fact.b", rel:
317
+ * "depends_on" }` on record A says A needs B. Stored in frontmatter and
318
+ * also rendered as one prose sentence each, so the meaning survives a
319
+ * reader that knows only OKF. The vocabulary goes into the description from
320
+ * the same table the walk uses, so `kb_schema` emits it.
321
+ */
322
+ links: import_zod2.z.array(composeLinkSchema).max(64).optional().describe(
323
+ `Typed causal edges, source \u2192 target \u2014 a link on this record says this record <rel> the target. ${KB_LINK_RELS.map(
324
+ (rel) => `${rel}: ${LINK_RELS[rel].purpose}`
325
+ ).join("; ")}.`
326
+ ),
245
327
  /** Concept ids this record replaces. The store settles the backlinks. */
246
328
  supersedes: import_zod2.z.array(kbConceptIdSchema).max(32).optional(),
247
329
  materiality: import_zod2.z.enum(KB_MATERIALITIES).optional(),
@@ -281,6 +363,15 @@ function composeRecord(type, input, writtenBy, writtenAt) {
281
363
  if (parsed.owner) frontmatter.strauss_owner = parsed.owner;
282
364
  if (parsed.supersedes?.length)
283
365
  frontmatter.strauss_supersedes = parsed.supersedes;
366
+ const selfLink = parsed.links?.find(
367
+ (link2) => link2.target === `${type}.${parsed.slug}`
368
+ );
369
+ if (selfLink) {
370
+ throw new Error(
371
+ `kb: ${type}.${parsed.slug} cannot ${selfLink.rel} itself \u2014 a link must name another record`
372
+ );
373
+ }
374
+ if (parsed.links?.length) frontmatter.strauss_links = parsed.links;
284
375
  const blocks = [];
285
376
  for (const heading of spec.sections) {
286
377
  const text = sections[heading];
@@ -292,6 +383,11 @@ ${text}`);
292
383
  for (const related of parsed.relatedConceptIds ?? []) {
293
384
  blocks.push(`Relates to [${related}](${related}.md).`);
294
385
  }
386
+ for (const link2 of parsed.links ?? []) {
387
+ blocks.push(
388
+ `${LINK_RELS[link2.rel].phrase} [${link2.target}](${link2.target}.md).`
389
+ );
390
+ }
295
391
  if (parsed.sources?.length) {
296
392
  blocks.push(
297
393
  parsed.sources.map((source) => `[^${source.id}]: ${source.title ?? source.resource}`).join("\n")
@@ -314,7 +410,7 @@ var decisionInputSchema = composeInputSchema.omit({ sections: true }).extend({
314
410
  impact: import_zod3.z.string().min(1).optional()
315
411
  }).strict();
316
412
  function composeDecisionRecord(input, writtenBy, writtenAt) {
317
- const { alternative, impact, ...rest } = input;
413
+ const { alternative, impact: impact2, ...rest } = input;
318
414
  return composeRecord(
319
415
  DECISION_TYPE,
320
416
  {
@@ -323,7 +419,7 @@ function composeDecisionRecord(input, writtenBy, writtenAt) {
323
419
  Decision: input.title,
324
420
  Rationale: input.why,
325
421
  ...alternative ? { Rejected: alternative } : {},
326
- ...impact ? { Impact: impact } : {}
422
+ ...impact2 ? { Impact: impact2 } : {}
327
423
  }
328
424
  },
329
425
  writtenBy,
@@ -905,6 +1001,23 @@ var KbPackBudgetExceededError = class extends BaseError {
905
1001
  budgetTokens;
906
1002
  excluded;
907
1003
  };
1004
+ var KbUnknownLinkRelError = class extends BaseError {
1005
+ constructor(rel, expected) {
1006
+ super({
1007
+ message: `kb: ${rel} is not a rel a walk can follow \u2014 expected one of ${expected.join(", ")}`,
1008
+ errorType: "KbUnknownLinkRel" /* KbUnknownLinkRel */,
1009
+ code: 400,
1010
+ fault: "User" /* User */,
1011
+ retriable: false,
1012
+ reportToUser: true,
1013
+ details: { rel, expected: expected.join(", ") }
1014
+ });
1015
+ this.rel = rel;
1016
+ this.expected = expected;
1017
+ }
1018
+ rel;
1019
+ expected;
1020
+ };
908
1021
  var KbMissingFlagValueError = class extends BaseError {
909
1022
  constructor(flag) {
910
1023
  super({
@@ -1436,8 +1549,20 @@ var answerCommand = define({
1436
1549
  }
1437
1550
  });
1438
1551
 
1439
- // src/commands/catalog.ts
1552
+ // src/commands/backlinks.ts
1440
1553
  var import_zod8 = require("zod");
1554
+ var backlinksCommand = define({
1555
+ name: "backlinks",
1556
+ tool: "kb_backlinks",
1557
+ usage: "backlinks <concept-id>",
1558
+ description: "Who points at this record: every inbound typed causal link (`strauss_links`), one hop, every rel including `related_to`, each with its rel and the standing of the record that made it. Use it when you need the exact edges \u2014 reviewing or renaming a record.",
1559
+ input: import_zod8.z.object({ bundlePath, conceptId }),
1560
+ fromArgv: (argv, path) => ({ bundlePath: path, conceptId: argv[1] }),
1561
+ run: async ({ store }, { bundlePath: path, conceptId: id }) => store.backlinks(path, id)
1562
+ });
1563
+
1564
+ // src/commands/catalog.ts
1565
+ var import_zod9 = require("zod");
1441
1566
 
1442
1567
  // src/adjudicate.ts
1443
1568
  var STANDING = {
@@ -1597,9 +1722,9 @@ var catalogCommand = define({
1597
1722
  tool: "kb_catalog",
1598
1723
  usage: "catalog [type]",
1599
1724
  description: "Lists every record as one line \u2014 concept id, type, title, standing, and a stale flag \u2014 at roughly thirty tokens each. Pick this over kb_load once kb_load refuses: kb_catalog never refuses. Superseded records show only their replacement; fetch bodies with kb_load, kb_pack, kb_query, or kb_trace.",
1600
- input: import_zod8.z.object({
1725
+ input: import_zod9.z.object({
1601
1726
  bundlePath,
1602
- type: import_zod8.z.enum(KB_RECORD_TYPES).optional()
1727
+ type: import_zod9.z.enum(KB_RECORD_TYPES).optional()
1603
1728
  }),
1604
1729
  fromArgv: (argv, path) => ({
1605
1730
  bundlePath: path,
@@ -1654,7 +1779,7 @@ function count(value, noun) {
1654
1779
  }
1655
1780
 
1656
1781
  // src/commands/context.ts
1657
- var import_zod9 = require("zod");
1782
+ var import_zod10 = require("zod");
1658
1783
 
1659
1784
  // src/kb-context.ts
1660
1785
  var import_promises3 = require("fs/promises");
@@ -1920,20 +2045,20 @@ var contextCommand = define({
1920
2045
  tool: "kb_context",
1921
2046
  usage: "context [--profile NAME] [--budget N] [--full-under N] [--format json] [--event NAME]",
1922
2047
  description: "The pinned-base index block, for injection at every context birth \u2014 startup, clear, resume, and after compaction. An index, not the content: concept ids, titles and standing, with the bodies left behind kb_load at the point of use. Emits nothing when nothing is pinned. Refuses with the list of bases and their sizes rather than truncating past its budget. Budgets resolve most-specific-first: explicit flags, then the workspace manifests' `context` tables (per profile, over their `default`), then the built-in profile (session-start, compact, turn), then package defaults \u2014 so a repo tunes its own numbers in .strauss/kb-pins.json without touching hook commands. Like kb_schema and kb_types this takes no bundlePath \u2014 it reads the workspace pin manifests, because which bases a session should see is workspace state, not a property of one base.",
1923
- input: import_zod9.z.object({
1924
- budgetTokens: import_zod9.z.number().int().positive().optional().describe(
2048
+ input: import_zod10.z.object({
2049
+ budgetTokens: import_zod10.z.number().int().positive().optional().describe(
1925
2050
  "Ceiling on the whole emitted block; past it the command refuses with a list of bases rather than truncating. Defaults to 4000."
1926
2051
  ),
1927
- fullUnderTokens: import_zod9.z.number().int().positive().optional().describe(
2052
+ fullUnderTokens: import_zod10.z.number().int().positive().optional().describe(
1928
2053
  "Per-base rendering threshold, applied before the budget: a base whose complete load fits under this arrives as full records instead of index lines, and the whole block still answers to budgetTokens. Off by default \u2014 index-only is the safe default at a context birth, because injected bodies outlive the qualifiers on them; the session-start profile opts tiny bases in at 1500."
1929
2054
  ),
1930
- profile: import_zod9.z.string().optional().describe(
2055
+ profile: import_zod10.z.string().optional().describe(
1931
2056
  "Named budget set: built-ins are session-start (full-under 1500), compact and turn (budget 2500); the manifests' `context` tables override per repo. Unknown names fall through to defaults rather than failing."
1932
2057
  ),
1933
- format: import_zod9.z.enum(["markdown", "json"]).optional().describe(
2058
+ format: import_zod10.z.enum(["markdown", "json"]).optional().describe(
1934
2059
  "CLI envelope for hook protocols that require strict JSON on stdout. MCP callers omit this \u2014 the block itself is identical."
1935
2060
  ),
1936
- event: import_zod9.z.string().optional().describe(
2061
+ event: import_zod10.z.string().optional().describe(
1937
2062
  "hookEventName stamped into the JSON envelope. Only meaningful with format=json."
1938
2063
  )
1939
2064
  }),
@@ -1969,11 +2094,12 @@ var contextCommand = define({
1969
2094
  });
1970
2095
 
1971
2096
  // src/commands/doctor.ts
1972
- var import_zod10 = require("zod");
2097
+ var import_zod11 = require("zod");
1973
2098
 
1974
2099
  // src/kb-edges.ts
1975
2100
  var KB_EDGE_KINDS = [
1976
2101
  "body-link",
2102
+ "typed-link",
1977
2103
  "supersession",
1978
2104
  "anchor",
1979
2105
  "source"
@@ -1982,10 +2108,11 @@ var BODY_LINK_TARGET = new RegExp(
1982
2108
  `\\]\\((${KB_CONCEPT_ID_PATTERN.source.replace(/^\^|\$$/g, "")})\\.md\\)`,
1983
2109
  "g"
1984
2110
  );
1985
- function neighbours(from, bundle, kinds = KB_EDGE_KINDS) {
2111
+ var DEFAULT_TYPED_LINK_RELS = KB_LINK_RELS;
2112
+ function neighbours(from, bundle, kinds = KB_EDGE_KINDS, linkRels = DEFAULT_TYPED_LINK_RELS) {
1986
2113
  const found = /* @__PURE__ */ new Map();
1987
2114
  for (const kind of kinds) {
1988
- for (const record of edgeNeighbours(from, bundle, kind)) {
2115
+ for (const record of edgeNeighbours(from, bundle, kind, linkRels)) {
1989
2116
  const existing = found.get(record.conceptId);
1990
2117
  if (existing) {
1991
2118
  if (!existing.via.includes(kind)) existing.via.push(kind);
@@ -1996,7 +2123,7 @@ function neighbours(from, bundle, kinds = KB_EDGE_KINDS) {
1996
2123
  }
1997
2124
  return [...found.values()];
1998
2125
  }
1999
- function edgeNeighbours(from, bundle, kind) {
2126
+ function edgeNeighbours(from, bundle, kind, linkRels = DEFAULT_TYPED_LINK_RELS) {
2000
2127
  switch (kind) {
2001
2128
  // A link whose target is not in the bundle is legal per compose.ts —
2002
2129
  // records are routinely written before the ones they point at exist — so
@@ -2010,6 +2137,21 @@ function edgeNeighbours(from, bundle, kind) {
2010
2137
  (candidate) => candidate.conceptId !== from.conceptId && targets.has(candidate.conceptId)
2011
2138
  );
2012
2139
  }
2140
+ // Outbound only, like `body-link`, and for the same reason: this is what
2141
+ // the record declares about itself. A missing target is legal — the walk
2142
+ // skips it, and `kb_validate` is what reports it as a warning. A rel
2143
+ // outside `linkRels` is skipped too, which is how an unknown rel stays
2144
+ // untraversable everywhere rather than one walk at a time.
2145
+ case "typed-link": {
2146
+ const allowed = new Set(linkRels);
2147
+ const targets = new Set(
2148
+ (from.frontmatter.strauss_links ?? []).filter((link2) => allowed.has(link2.rel)).map((link2) => link2.target)
2149
+ );
2150
+ if (!targets.size) return [];
2151
+ return bundle.filter(
2152
+ (candidate) => candidate.conceptId !== from.conceptId && targets.has(candidate.conceptId)
2153
+ );
2154
+ }
2013
2155
  // Both directions and both pointers: `supersede()` writes the pair, but a
2014
2156
  // hand-edit can leave one side behind, and a walk trusting one pointer
2015
2157
  // would miss a replacement the bundle openly declares.
@@ -2051,7 +2193,7 @@ function anchorsTouch(left, right) {
2051
2193
  function validateBundle(records) {
2052
2194
  const byId = new Map(records.map((record) => [record.conceptId, record]));
2053
2195
  const problems = [];
2054
- const report = (check, conceptId2, note) => problems.push({ check, conceptId: conceptId2, note });
2196
+ const report = (check, conceptId2, note, severity = "error") => problems.push({ check, conceptId: conceptId2, note, severity });
2055
2197
  for (const record of records) {
2056
2198
  const { conceptId: conceptId2, frontmatter: fm } = record;
2057
2199
  if (!isKbRecordType(fm.type)) {
@@ -2075,6 +2217,36 @@ function validateBundle(records) {
2075
2217
  report("supersedes", conceptId2, `${old} is not marked superseded`);
2076
2218
  }
2077
2219
  }
2220
+ for (const link2 of fm.strauss_links ?? []) {
2221
+ if (!isKbLinkRel(link2.rel)) {
2222
+ report(
2223
+ "link_rel",
2224
+ conceptId2,
2225
+ `unknown rel "${link2.rel}" on link to ${link2.target} \u2014 expected one of ${KB_LINK_RELS.join(", ")}`
2226
+ );
2227
+ }
2228
+ if (!KB_CONCEPT_ID_PATTERN.test(link2.target)) {
2229
+ report(
2230
+ "link_target",
2231
+ conceptId2,
2232
+ `target "${link2.target}" is not a valid concept id \u2014 expected <type>.<slug>, both kebab-case`
2233
+ );
2234
+ } else if (link2.target === conceptId2) {
2235
+ report(
2236
+ "link_target",
2237
+ conceptId2,
2238
+ `links to itself (${link2.rel})`,
2239
+ "warning"
2240
+ );
2241
+ } else if (!byId.has(link2.target)) {
2242
+ report(
2243
+ "link_target",
2244
+ conceptId2,
2245
+ `target ${link2.target} is not in the bundle`,
2246
+ "warning"
2247
+ );
2248
+ }
2249
+ }
2078
2250
  if (fm.strauss_assumption && fm.sources?.length) {
2079
2251
  report("assumption", conceptId2, "marked an assumption but cites sources");
2080
2252
  }
@@ -2351,13 +2523,13 @@ function ageInDays(record, now) {
2351
2523
  }
2352
2524
 
2353
2525
  // src/commands/doctor.ts
2354
- var days = (what, fallback) => import_zod10.z.number().int().positive().optional().describe(`${what} Defaults to ${fallback}.`);
2526
+ var days = (what, fallback) => import_zod11.z.number().int().positive().optional().describe(`${what} Defaults to ${fallback}.`);
2355
2527
  var doctorCommand = define({
2356
2528
  name: "doctor",
2357
2529
  tool: "kb_doctor",
2358
2530
  usage: "doctor [--expiring-days N] [--unverified-days N] [--aging-days N] [--repo-root PATH] [--strict]",
2359
2531
  description: "Read-only health sweep: expired, expiring, unverified, aging, orphaned, broken-supersession, superseded-but-cited, drifted anchors. Every group is reported even when empty; nothing is written or re-stamped. Use it when picking up a base you have not touched in a while; kb_validate only checks that pointers between records agree.",
2360
- input: import_zod10.z.object({
2532
+ input: import_zod11.z.object({
2361
2533
  bundlePath,
2362
2534
  repoRoot: REPO_ROOT,
2363
2535
  expiringDays: days(
@@ -2372,7 +2544,7 @@ var doctorCommand = define({
2372
2544
  "How long a record may stay `open` or `proposed` before `aging` reports it, in days.",
2373
2545
  DEFAULT_AGING_DAYS
2374
2546
  ),
2375
- strict: import_zod10.z.boolean().optional().describe(
2547
+ strict: import_zod11.z.boolean().optional().describe(
2376
2548
  "Turn an expired record into a non-zero exit for the CLI. No effect on the report itself."
2377
2549
  )
2378
2550
  }),
@@ -2447,14 +2619,47 @@ function render2(result) {
2447
2619
  return lines.join("\n");
2448
2620
  }
2449
2621
 
2622
+ // src/commands/impact.ts
2623
+ var import_zod12 = require("zod");
2624
+ var impactCommand = define({
2625
+ name: "impact",
2626
+ tool: "kb_impact",
2627
+ usage: "impact <concept-id> [--depth N] [--rels a,b]",
2628
+ description: "What breaks if this record changes: its transitive set of dependants, each with its standing. Each rel declares which of its ends depends on the other, and the walk follows each rel in its own direction. Naming `related_to` or an unknown rel in `rels` is an error. kb_backlinks gives one flat hop.",
2629
+ input: import_zod12.z.object({
2630
+ bundlePath,
2631
+ conceptId,
2632
+ depth: import_zod12.z.number().int().positive().optional().describe(
2633
+ "Hops out from the record. Unbounded when omitted; a walk this cuts reports truncated: true."
2634
+ ),
2635
+ rels: import_zod12.z.array(import_zod12.z.enum(KB_CAUSAL_LINK_RELS)).optional().describe(
2636
+ "Narrow which rels the walk follows. Defaults to every rel that carries a dependence \u2014 all but related_to."
2637
+ )
2638
+ }),
2639
+ fromArgv: (argv, path) => {
2640
+ const depth = argvFlag(argv, "--depth");
2641
+ const rels = argvFlag(argv, "--rels");
2642
+ return {
2643
+ bundlePath: path,
2644
+ conceptId: argv[1],
2645
+ ...depth ? { depth: Number(depth) } : {},
2646
+ ...rels ? { rels: rels.split(",").filter(Boolean) } : {}
2647
+ };
2648
+ },
2649
+ run: async ({ store }, { bundlePath: path, conceptId: id, depth, rels }) => store.impact(path, id, {
2650
+ ...depth !== void 0 ? { depth } : {},
2651
+ ...rels?.length ? { rels } : {}
2652
+ })
2653
+ });
2654
+
2450
2655
  // src/commands/list.ts
2451
- var import_zod11 = require("zod");
2656
+ var import_zod13 = require("zod");
2452
2657
  var listCommand = define({
2453
2658
  name: "list",
2454
2659
  tool: "kb_list",
2455
2660
  usage: "list [type]",
2456
2661
  description: "Every record, optionally narrowed to one type. Use kb_query when you have a question; this is for enumerating.",
2457
- input: import_zod11.z.object({ bundlePath, type: import_zod11.z.enum(KB_RECORD_TYPES).optional() }),
2662
+ input: import_zod13.z.object({ bundlePath, type: import_zod13.z.enum(KB_RECORD_TYPES).optional() }),
2458
2663
  fromArgv: (argv, path) => ({ bundlePath: path, type: argv[1] }),
2459
2664
  run: async ({ store }, { bundlePath: path, type }) => (await store.list(path, type)).map((record) => ({
2460
2665
  conceptId: record.conceptId,
@@ -2466,17 +2671,17 @@ var listCommand = define({
2466
2671
  });
2467
2672
 
2468
2673
  // src/commands/load.ts
2469
- var import_zod12 = require("zod");
2674
+ var import_zod14 = require("zod");
2470
2675
  var loadCommand = define({
2471
2676
  name: "load",
2472
2677
  tool: "kb_load",
2473
2678
  usage: "load [type] [--budget N | --all] [--repo-root PATH]",
2474
2679
  description: "Loads the whole knowledge base at once, each record with its standing. Superseded records arrive as stubs; rejected and open records arrive whole. Refuses past the token budget \u2014 call kb_catalog, kb_pack on it; `all` bypasses the budget. Never read record files directly. Cache-stable; `digest` is the base's content stamp \u2014 hooks use it to tell you when to reload.",
2475
- input: import_zod12.z.object({
2680
+ input: import_zod14.z.object({
2476
2681
  bundlePath,
2477
- type: import_zod12.z.enum(KB_RECORD_TYPES).optional(),
2478
- budgetTokens: import_zod12.z.number().int().positive().optional().describe("Approximate token ceiling. Defaults to 25000."),
2479
- all: import_zod12.z.boolean().optional().describe(
2682
+ type: import_zod14.z.enum(KB_RECORD_TYPES).optional(),
2683
+ budgetTokens: import_zod14.z.number().int().positive().optional().describe("Approximate token ceiling. Defaults to 25000."),
2684
+ all: import_zod14.z.boolean().optional().describe(
2480
2685
  "Loads the entire base regardless of size, bypassing the token budget; mutually exclusive with budgetTokens."
2481
2686
  ),
2482
2687
  repoRoot: REPO_ROOT
@@ -2518,25 +2723,25 @@ var loadCommand = define({
2518
2723
  });
2519
2724
 
2520
2725
  // src/commands/log.ts
2521
- var import_zod13 = require("zod");
2726
+ var import_zod15 = require("zod");
2522
2727
  var logCommand = define({
2523
2728
  name: "log",
2524
2729
  tool: "kb_log",
2525
2730
  usage: "log",
2526
2731
  description: "What touched what, and when. The only artifact here that cannot be reconstructed from the records, so malformed lines are reported rather than repaired.",
2527
- input: import_zod13.z.object({ bundlePath }),
2732
+ input: import_zod15.z.object({ bundlePath }),
2528
2733
  fromArgv: (_argv, path) => ({ bundlePath: path }),
2529
2734
  run: ({ store }, { bundlePath: path }) => store.readLog(path)
2530
2735
  });
2531
2736
 
2532
2737
  // src/commands/no-decision.ts
2533
- var import_zod14 = require("zod");
2738
+ var import_zod16 = require("zod");
2534
2739
  var noDecisionCommand = define({
2535
2740
  name: "no-decision",
2536
2741
  tool: "kb_no_decision",
2537
2742
  usage: "no-decision <reason...>",
2538
2743
  description: 'Claim in one sentence that there was nothing to decide. Gating on "did you write a decision?" rewards writing a junk one; gating on "did you answer?" does not, so silence has to be expressible. Idempotent \u2014 restating it is not a collision.',
2539
- input: import_zod14.z.object({ bundlePath, reason: import_zod14.z.string().min(1) }),
2744
+ input: import_zod16.z.object({ bundlePath, reason: import_zod16.z.string().min(1) }),
2540
2745
  fromArgv: (argv, path) => ({
2541
2746
  bundlePath: path,
2542
2747
  reason: argv.slice(1).join(" ").trim()
@@ -2553,20 +2758,20 @@ var noDecisionCommand = define({
2553
2758
  });
2554
2759
 
2555
2760
  // src/commands/pack.ts
2556
- var import_zod15 = require("zod");
2761
+ var import_zod17 = require("zod");
2557
2762
  var packCommand = define({
2558
2763
  name: "pack",
2559
2764
  tool: "kb_pack",
2560
2765
  usage: "pack <conceptId> [--hops N] [--max-nodes N] [--budget N]",
2561
2766
  description: "The bounded neighbourhood around one record: everything within `hops` of the root, ranked and cut to `maxNodes`, with every cut record named under Excluded \u2014 a named gap is knowable, a silent one is not. Prefer this over kb_load when the base is too large to hold whole and the work centres on one record; prefer it over kb_query when the question needs the governed neighbourhood \u2014 what was settled and what binds near this record \u2014 rather than a lookup by wording. Superseded records arrive as name, replacement and date stubs exactly as kb_load emits them: their bodies no longer hold, and kb_trace has the history. Refuses outright rather than truncating when the pack would exceed its token budget \u2014 a partial pack is indistinguishable from a complete one \u2014 reporting the record count and every already-cut id so the caller can lower hops or maxNodes, or raise the budget. The header carries the bundle, root, budget and a timestamp; everything below the header is byte-identical across runs over an unchanged base, so two packs can be diffed and a changed byte means changed knowledge. This tool (with kb_load, kb_query and kb_trace) is the only supported way to read a base; a raw file read bypasses supersession resolution and returns replaced records as if current.",
2562
- input: import_zod15.z.object({
2767
+ input: import_zod17.z.object({
2563
2768
  bundlePath,
2564
2769
  conceptId,
2565
- hops: import_zod15.z.number().int().positive().optional().describe("How far from the root the walk may reach. Defaults to 2."),
2566
- maxNodes: import_zod15.z.number().int().positive().optional().describe(
2770
+ hops: import_zod17.z.number().int().positive().optional().describe("How far from the root the walk may reach. Defaults to 2."),
2771
+ maxNodes: import_zod17.z.number().int().positive().optional().describe(
2567
2772
  "How many records the pack may hold, root included. Defaults to 20."
2568
2773
  ),
2569
- budgetTokens: import_zod15.z.number().int().positive().optional().describe(
2774
+ budgetTokens: import_zod17.z.number().int().positive().optional().describe(
2570
2775
  "Approximate token ceiling over what is actually emitted. Defaults to 25000."
2571
2776
  )
2572
2777
  }),
@@ -2653,22 +2858,22 @@ function warningLabel(warning) {
2653
2858
  }
2654
2859
 
2655
2860
  // src/commands/pin.ts
2656
- var import_zod16 = require("zod");
2861
+ var import_zod18 = require("zod");
2657
2862
  var pinCommand = define({
2658
2863
  name: "pin",
2659
2864
  tool: "kb_pin",
2660
2865
  usage: "pin [bundle-path] [--mode full|index] [--profiles a,b] [--local|--user] [--frozen|--unfreeze]",
2661
2866
  description: "Pin a base into a workspace pin manifest, so `context` surfaces it at every context birth. Three layers, nearest wins: the committed project manifest (.strauss/kb-pins.json, the default), `--local` (.strauss/kb-pins.local.json, personal and gitignored), and `--user` (~/.strauss/kb-pins.json, every workspace). Idempotent \u2014 re-pinning changes nothing unless --mode, --profiles, or --frozen/--unfreeze are given, which update just those fields. `--mode full` preloads the whole base into the block regardless of the full-under threshold; `--mode index` never upgrades. `--profiles` scopes the pin to named context profiles. `--frozen` marks the base concluded: write commands against it refuse and `context` labels it read-only. A path with no records yet succeeds with a warning; bases are routinely pinned before they are populated. Pins are workspace state: the pinned base itself is never touched.",
2662
- input: import_zod16.z.object({
2867
+ input: import_zod18.z.object({
2663
2868
  bundlePath,
2664
- mode: import_zod16.z.enum(["full", "index"]).optional().describe(
2869
+ mode: import_zod18.z.enum(["full", "index"]).optional().describe(
2665
2870
  "full: always emit this base's records whole (still under the block budget); index: never upgrade. Absent: the profile's full-under threshold decides."
2666
2871
  ),
2667
- profiles: import_zod16.z.array(import_zod16.z.string()).optional().describe("Context profiles this pin surfaces in. Absent: all of them."),
2668
- layer: import_zod16.z.enum(["project", "local", "user"]).optional().describe(
2872
+ profiles: import_zod18.z.array(import_zod18.z.string()).optional().describe("Context profiles this pin surfaces in. Absent: all of them."),
2873
+ layer: import_zod18.z.enum(["project", "local", "user"]).optional().describe(
2669
2874
  "Which manifest to write: project (committed, default), local (personal, gitignored), user (~/.strauss, every workspace)."
2670
2875
  ),
2671
- frozen: import_zod16.z.boolean().optional().describe(
2876
+ frozen: import_zod18.z.boolean().optional().describe(
2672
2877
  "true: the base is concluded \u2014 writes against it refuse while pinned. false: lift a freeze."
2673
2878
  )
2674
2879
  }),
@@ -2697,29 +2902,29 @@ var pinCommand = define({
2697
2902
  });
2698
2903
 
2699
2904
  // src/commands/pins.ts
2700
- var import_zod17 = require("zod");
2905
+ var import_zod19 = require("zod");
2701
2906
  var pinsCommand = define({
2702
2907
  name: "pins",
2703
2908
  tool: "kb_pins",
2704
2909
  usage: "pins",
2705
2910
  description: "Every pinned base across the manifest layers, each with its layer and whether it currently resolves to readable records. Reads the workspace manifests rather than any one base, like kb_context.",
2706
- input: import_zod17.z.object({}),
2911
+ input: import_zod19.z.object({}),
2707
2912
  fromArgv: () => ({}),
2708
2913
  run: ({ store }) => listPins(store, process.cwd())
2709
2914
  });
2710
2915
 
2711
2916
  // src/commands/query.ts
2712
- var import_zod18 = require("zod");
2917
+ var import_zod20 = require("zod");
2713
2918
  var queryCommand = define({
2714
2919
  name: "query",
2715
2920
  tool: "kb_query",
2716
2921
  usage: "query <text...> [--repo-root PATH]",
2717
2922
  description: "Search; every hit carries its standing. Flagged, never filtered: a superseded hit returns with its replacement, a rejected one is marked. Prefer kb_load when the base fits its budget \u2014 a full read beats search. Results are volatile: place them at the tail, not the cached prefix. Never read record files directly.",
2718
- input: import_zod18.z.object({
2923
+ input: import_zod20.z.object({
2719
2924
  bundlePath,
2720
- text: import_zod18.z.string().optional(),
2721
- type: import_zod18.z.enum(KB_RECORD_TYPES).optional(),
2722
- includeNonCurrent: import_zod18.z.boolean().optional(),
2925
+ text: import_zod20.z.string().optional(),
2926
+ type: import_zod20.z.enum(KB_RECORD_TYPES).optional(),
2927
+ includeNonCurrent: import_zod20.z.boolean().optional(),
2723
2928
  repoRoot: REPO_ROOT
2724
2929
  }),
2725
2930
  // `--repo-root` is a flag, so its value must not fall into the search text.
@@ -2751,27 +2956,27 @@ var queryCommand = define({
2751
2956
  });
2752
2957
 
2753
2958
  // src/commands/read-index.ts
2754
- var import_zod19 = require("zod");
2959
+ var import_zod21 = require("zod");
2755
2960
  var readIndexCommand = define({
2756
2961
  name: "index",
2757
2962
  tool: "kb_index",
2758
2963
  usage: "index",
2759
2964
  description: "The index, rebuilt if it disagrees with the records. One call gives the whole shape of the base: title, type, status, and description per record. The cheap re-orientation call after compaction or deep in a long session \u2014 a few hundred tokens; call it (or kb_context, when bases are pinned) first, then kb_load or fetch by concept id.",
2760
- input: import_zod19.z.object({ bundlePath }),
2965
+ input: import_zod21.z.object({ bundlePath }),
2761
2966
  fromArgv: (_argv, path) => ({ bundlePath: path }),
2762
2967
  run: ({ store }, { bundlePath: path }) => store.readIndex(path)
2763
2968
  });
2764
2969
 
2765
2970
  // src/commands/schema.ts
2766
- var import_zod22 = require("zod");
2971
+ var import_zod24 = require("zod");
2767
2972
 
2768
2973
  // src/json-schema.ts
2769
- var import_zod21 = require("zod");
2974
+ var import_zod23 = require("zod");
2770
2975
 
2771
2976
  // src/kb-log.ts
2772
- var import_zod20 = require("zod");
2977
+ var import_zod22 = require("zod");
2773
2978
  var LOG_FILE = "log.jsonl";
2774
- var kbLogEntrySchema = import_zod20.z.object({
2979
+ var kbLogEntrySchema = import_zod22.z.object({
2775
2980
  // Validated, not just `min(1)`: `at` is a sort key (see `parseLog`
2776
2981
  // below), and a value that isn't actually chronological — a Unix
2777
2982
  // timestamp, a human-typed date, garbage — would sort wrong without
@@ -2780,12 +2985,12 @@ var kbLogEntrySchema = import_zod20.z.object({
2780
2985
  // and rejects everything else, including a non-`Z` offset — so a
2781
2986
  // malformed `at` is reported the same way a malformed line already is,
2782
2987
  // rather than silently sorting into the wrong place.
2783
- at: import_zod20.z.iso.datetime(),
2784
- by: import_zod20.z.string().min(1),
2785
- operation: import_zod20.z.string().min(1),
2786
- conceptId: import_zod20.z.string().min(1),
2988
+ at: import_zod22.z.iso.datetime(),
2989
+ by: import_zod22.z.string().min(1),
2990
+ operation: import_zod22.z.string().min(1),
2991
+ conceptId: import_zod22.z.string().min(1),
2787
2992
  /** Second concept id, where the operation relates two — supersession. */
2788
- target: import_zod20.z.string().min(1).optional()
2993
+ target: import_zod22.z.string().min(1).optional()
2789
2994
  }).strict();
2790
2995
  function renderLogEntry(entry) {
2791
2996
  return `${JSON.stringify(kbLogEntrySchema.parse(entry))}
@@ -2823,11 +3028,11 @@ function parseLog(raw) {
2823
3028
  // src/json-schema.ts
2824
3029
  function kbJsonSchemas() {
2825
3030
  return {
2826
- recordFrontmatter: import_zod21.z.toJSONSchema(kbRecordFrontmatterSchema, {
3031
+ recordFrontmatter: import_zod23.z.toJSONSchema(kbRecordFrontmatterSchema, {
2827
3032
  io: "input"
2828
3033
  }),
2829
- composeInput: import_zod21.z.toJSONSchema(composeInputSchema, { io: "input" }),
2830
- logEntry: import_zod21.z.toJSONSchema(kbLogEntrySchema, { io: "input" })
3034
+ composeInput: import_zod23.z.toJSONSchema(composeInputSchema, { io: "input" }),
3035
+ logEntry: import_zod23.z.toJSONSchema(kbLogEntrySchema, { io: "input" })
2831
3036
  };
2832
3037
  }
2833
3038
 
@@ -2837,22 +3042,22 @@ var schemaCommand = define({
2837
3042
  tool: "kb_schema",
2838
3043
  usage: "schema",
2839
3044
  description: "JSON Schema for the frontmatter, the write input, and log entries \u2014 generated from the code that enforces them, so it cannot drift from what a write will accept.",
2840
- input: import_zod22.z.object({}),
3045
+ input: import_zod24.z.object({}),
2841
3046
  fromArgv: () => ({}),
2842
3047
  run: () => Promise.resolve(kbJsonSchemas())
2843
3048
  });
2844
3049
 
2845
3050
  // src/commands/status.ts
2846
- var import_zod23 = require("zod");
3051
+ var import_zod25 = require("zod");
2847
3052
  var statusCommand = define({
2848
3053
  name: "status",
2849
3054
  tool: "kb_status",
2850
3055
  usage: "status <concept-id> <status>",
2851
3056
  description: "Move a record's status, leaving everything else alone. Uses a compare-and-swap, so a concurrent change fails loudly rather than being overwritten.",
2852
- input: import_zod23.z.object({
3057
+ input: import_zod25.z.object({
2853
3058
  bundlePath,
2854
3059
  conceptId,
2855
- status: import_zod23.z.enum(KB_RECORD_STATUSES)
3060
+ status: import_zod25.z.enum(KB_RECORD_STATUSES)
2856
3061
  }),
2857
3062
  fromArgv: (argv, path) => ({
2858
3063
  bundlePath: path,
@@ -2867,13 +3072,13 @@ var statusCommand = define({
2867
3072
  });
2868
3073
 
2869
3074
  // src/commands/supersede.ts
2870
- var import_zod24 = require("zod");
3075
+ var import_zod26 = require("zod");
2871
3076
  var supersedeCommand = define({
2872
3077
  name: "supersede",
2873
3078
  tool: "kb_supersede",
2874
3079
  usage: "supersede <concept-id> <replacement-id>",
2875
3080
  description: "Mark a record superseded by another, linking both directions. Use this rather than editing a record whose meaning changed \u2014 a record that quietly becomes something else invalidates every reference to it, and the earlier understanding is what a later trace needs.",
2876
- input: import_zod24.z.object({ bundlePath, conceptId, replacementId: conceptId }),
3081
+ input: import_zod26.z.object({ bundlePath, conceptId, replacementId: conceptId }),
2877
3082
  fromArgv: (argv, path) => ({
2878
3083
  bundlePath: path,
2879
3084
  conceptId: argv[1],
@@ -2887,16 +3092,16 @@ var supersedeCommand = define({
2887
3092
  });
2888
3093
 
2889
3094
  // src/commands/sync-instructions.ts
2890
- var import_zod25 = require("zod");
3095
+ var import_zod27 = require("zod");
2891
3096
  var syncInstructionsCommand = define({
2892
3097
  name: "sync-instructions",
2893
3098
  usage: "sync-instructions <file> [--profile NAME] [--budget N] [--full-under N]",
2894
3099
  description: "Idempotently plant the `context` block between sentinel comments in an instruction file (AGENTS.md, CLAUDE.md), creating the block when absent and leaving everything outside the sentinels alone. CLI-only: this is file plumbing for runtimes whose instruction files are re-read where their conversations are not, not an agent capability \u2014 the capability is kb_context.",
2895
- input: import_zod25.z.object({
2896
- file: import_zod25.z.string().min(1).describe("The instruction file to edit in place."),
2897
- budgetTokens: import_zod25.z.number().int().positive().optional(),
2898
- fullUnderTokens: import_zod25.z.number().int().positive().optional(),
2899
- profile: import_zod25.z.string().optional()
3100
+ input: import_zod27.z.object({
3101
+ file: import_zod27.z.string().min(1).describe("The instruction file to edit in place."),
3102
+ budgetTokens: import_zod27.z.number().int().positive().optional(),
3103
+ fullUnderTokens: import_zod27.z.number().int().positive().optional(),
3104
+ profile: import_zod27.z.string().optional()
2900
3105
  }),
2901
3106
  fromArgv: (argv) => {
2902
3107
  const budget = argvFlag(argv, "--budget");
@@ -2922,10 +3127,15 @@ var syncInstructionsCommand = define({
2922
3127
  });
2923
3128
 
2924
3129
  // src/commands/trace.ts
2925
- var import_zod26 = require("zod");
3130
+ var import_zod28 = require("zod");
2926
3131
 
2927
3132
  // src/trace.ts
2928
- var TRACE_EDGES = ["supersession", "anchor", "source"];
3133
+ var TRACE_EDGES = [
3134
+ "typed-link",
3135
+ "supersession",
3136
+ "anchor",
3137
+ "source"
3138
+ ];
2929
3139
  function trace(seedId, bundle, options = {}) {
2930
3140
  const edges = options.edges?.length ? options.edges : TRACE_EDGES;
2931
3141
  const maxDepth = options.depth ?? 3;
@@ -2940,7 +3150,12 @@ function trace(seedId, bundle, options = {}) {
2940
3150
  const next = [];
2941
3151
  for (const from of frontier) {
2942
3152
  for (const edge of edges) {
2943
- for (const record of edgeNeighbours(from, bundle, edge)) {
3153
+ for (const record of edgeNeighbours(
3154
+ from,
3155
+ bundle,
3156
+ edge,
3157
+ KB_CAUSAL_LINK_RELS
3158
+ )) {
2944
3159
  const existing = reached.get(record.conceptId);
2945
3160
  if (existing) {
2946
3161
  if (existing.depth > 0 && !existing.via.includes(edge)) {
@@ -2968,11 +3183,11 @@ var traceCommand = define({
2968
3183
  tool: "kb_trace",
2969
3184
  usage: "trace <concept-id> [edges...]",
2970
3185
  description: 'How a position was arrived at, as a timeline ordered by when each record was written. Deliberately includes rejected, draft, and superseded records \u2014 in a history those are the content, not noise. Follows supersession, shared code anchors, and shared sources. Use when the question is "why is this the way it is" rather than "what do we hold now". This tool (with kb_load and kb_query) is the only supported way to read a base; a raw file read bypasses supersession resolution and returns replaced records as if current.',
2971
- input: import_zod26.z.object({
3186
+ input: import_zod28.z.object({
2972
3187
  bundlePath,
2973
3188
  conceptId,
2974
- edges: import_zod26.z.array(import_zod26.z.enum(TRACE_EDGES)).optional(),
2975
- depth: import_zod26.z.number().int().positive().optional()
3189
+ edges: import_zod28.z.array(import_zod28.z.enum(TRACE_EDGES)).optional(),
3190
+ depth: import_zod28.z.number().int().positive().optional()
2976
3191
  }),
2977
3192
  fromArgv: (argv, path) => ({
2978
3193
  bundlePath: path,
@@ -2994,53 +3209,56 @@ var traceCommand = define({
2994
3209
  });
2995
3210
 
2996
3211
  // src/commands/types.ts
2997
- var import_zod27 = require("zod");
3212
+ var import_zod29 = require("zod");
2998
3213
  var typesCommand = define({
2999
3214
  name: "types",
3000
3215
  tool: "kb_types",
3001
3216
  usage: "types",
3002
3217
  description: "The twelve record types with their purpose, body sections, and starting status. Read this before writing rather than guessing headings \u2014 a section the type does not define is rejected.",
3003
- input: import_zod27.z.object({}),
3218
+ input: import_zod29.z.object({}),
3004
3219
  fromArgv: () => ({}),
3005
3220
  run: () => Promise.resolve(RECORD_TYPES)
3006
3221
  });
3007
3222
 
3008
3223
  // src/commands/unpin.ts
3009
- var import_zod28 = require("zod");
3224
+ var import_zod30 = require("zod");
3010
3225
  var unpinCommand = define({
3011
3226
  name: "unpin",
3012
3227
  tool: "kb_unpin",
3013
3228
  usage: "unpin [bundle-path]",
3014
3229
  description: "Remove a base from every pin manifest layer that holds it \u2014 project, local, and user \u2014 because unpinned means gone, not still injected from another file. Reports which layers were touched.",
3015
- input: import_zod28.z.object({ bundlePath }),
3230
+ input: import_zod30.z.object({ bundlePath }),
3016
3231
  fromArgv: (argv, path) => ({ bundlePath: argv[1] ?? path }),
3017
3232
  run: (_ctx, { bundlePath: path }) => unpinBase(process.cwd(), path)
3018
3233
  });
3019
3234
 
3020
3235
  // src/commands/validate.ts
3021
- var import_zod29 = require("zod");
3236
+ var import_zod31 = require("zod");
3022
3237
  var validateCommand = define({
3023
3238
  name: "validate",
3024
3239
  tool: "kb_validate",
3025
3240
  usage: "validate",
3026
- description: "Check pointers no single record can see: supersession links that disagree between the two records, and assumptions that cite sources. Per-record shape is enforced on every read, so a problem here means someone edited a file by hand.",
3027
- input: import_zod29.z.object({ bundlePath }),
3241
+ description: "Check pointers no single record can see: supersession links that disagree between the two records, typed causal links, and assumptions that cite sources. Each finding carries a severity: errors fail the exit code, warnings do not.",
3242
+ input: import_zod31.z.object({ bundlePath }),
3028
3243
  fromArgv: (_argv, path) => ({ bundlePath: path }),
3029
3244
  run: async ({ store }, { bundlePath: path }) => validateBundle(await store.list(path)),
3030
- failsWhen: (result) => Array.isArray(result) && result.length > 0
3245
+ // Warnings never fail the exit code; every other severity does.
3246
+ failsWhen: (result) => Array.isArray(result) && result.some(
3247
+ (problem) => problem.severity !== "warning"
3248
+ )
3031
3249
  });
3032
3250
 
3033
3251
  // src/commands/verify.ts
3034
- var import_zod30 = require("zod");
3252
+ var import_zod32 = require("zod");
3035
3253
  var verifyCommand = define({
3036
3254
  name: "verify",
3037
3255
  tool: "kb_verify",
3038
3256
  usage: "verify <concept-id> --note <text>",
3039
3257
  description: "Append one verified[] event \u2014 who checked the record, when, and what the check found. Appends only; prior events are never rewritten. A record's own generator is refused unless the actor is human: re-reading your own output is not an independent check.",
3040
- input: import_zod30.z.object({
3258
+ input: import_zod32.z.object({
3041
3259
  bundlePath,
3042
3260
  conceptId,
3043
- note: import_zod30.z.string().refine((s) => s.trim().length > 0, {
3261
+ note: import_zod32.z.string().refine((s) => s.trim().length > 0, {
3044
3262
  message: "note must say what the check found"
3045
3263
  })
3046
3264
  }),
@@ -3060,7 +3278,7 @@ var verifyCommand = define({
3060
3278
  });
3061
3279
 
3062
3280
  // src/commands/write.ts
3063
- var import_zod31 = require("zod");
3281
+ var import_zod33 = require("zod");
3064
3282
  var writeCommand = define({
3065
3283
  name: "write",
3066
3284
  tool: "kb_write",
@@ -3074,9 +3292,9 @@ var writeCommand = define({
3074
3292
  "- Prefer a new record over overloading an existing one, and keep each short. A record nobody finishes reading is not durable memory.",
3075
3293
  "- Records are never deleted; supersede instead, so the earlier reasoning stays inspectable."
3076
3294
  ].join("\n"),
3077
- input: import_zod31.z.object({
3295
+ input: import_zod33.z.object({
3078
3296
  bundlePath,
3079
- type: import_zod31.z.enum(KB_RECORD_TYPES),
3297
+ type: import_zod33.z.enum(KB_RECORD_TYPES),
3080
3298
  input: composeInputSchema
3081
3299
  }),
3082
3300
  fromArgv: async (argv, path, stdin) => ({
@@ -3100,7 +3318,7 @@ var writeCommand = define({
3100
3318
  });
3101
3319
 
3102
3320
  // src/commands/write-decision.ts
3103
- var import_zod32 = require("zod");
3321
+ var import_zod34 = require("zod");
3104
3322
  var writeDecisionCommand = define({
3105
3323
  name: "write-decision",
3106
3324
  tool: "kb_write_decision",
@@ -3113,7 +3331,7 @@ var writeDecisionCommand = define({
3113
3331
  "- `alternative` is what you turned down and why, not a list of everything considered.",
3114
3332
  "- A reference to material you read goes in `sources`; a reference to code goes in `anchors`; a reference to another record goes in `relatedConceptIds`."
3115
3333
  ].join("\n"),
3116
- input: import_zod32.z.object({ bundlePath, input: decisionInputSchema }),
3334
+ input: import_zod34.z.object({ bundlePath, input: decisionInputSchema }),
3117
3335
  fromArgv: async (_argv, path, stdin) => ({
3118
3336
  bundlePath: path,
3119
3337
  input: JSON.parse(await stdin())
@@ -3148,6 +3366,8 @@ var KB_COMMANDS = [
3148
3366
  packCommand,
3149
3367
  queryCommand,
3150
3368
  traceCommand,
3369
+ impactCommand,
3370
+ backlinksCommand,
3151
3371
  listCommand,
3152
3372
  readIndexCommand,
3153
3373
  logCommand,
@@ -3368,6 +3588,141 @@ function typeRank(record) {
3368
3588
  return index === -1 ? TYPE_PRIORITY.length : index;
3369
3589
  }
3370
3590
 
3591
+ // src/kb-links/inbound.ts
3592
+ function inboundIndex(bundle) {
3593
+ const byTarget = /* @__PURE__ */ new Map();
3594
+ for (const record of bundle) {
3595
+ for (const link2 of record.frontmatter.strauss_links ?? []) {
3596
+ if (link2.target === record.conceptId) continue;
3597
+ const edges = byTarget.get(link2.target) ?? [];
3598
+ if (edges.some(
3599
+ (edge) => edge.from === record.conceptId && edge.rel === link2.rel
3600
+ )) {
3601
+ continue;
3602
+ }
3603
+ edges.push({ from: record.conceptId, rel: link2.rel });
3604
+ byTarget.set(link2.target, edges);
3605
+ }
3606
+ }
3607
+ return byTarget;
3608
+ }
3609
+
3610
+ // src/kb-links/backlinks.ts
3611
+ function backlinks(targetId, bundle) {
3612
+ const byId = new Map(bundle.map((record) => [record.conceptId, record]));
3613
+ if (!byId.has(targetId)) throw new KbRecordNotFoundError(targetId);
3614
+ const standingOf = new Map(
3615
+ adjudicate(bundle, bundle).map((hit) => [hit.record.conceptId, hit])
3616
+ );
3617
+ const rows = [];
3618
+ for (const edge of inboundIndex(bundle).get(targetId) ?? []) {
3619
+ const record = byId.get(edge.from);
3620
+ if (!record) continue;
3621
+ const hit = standingOf.get(edge.from);
3622
+ rows.push({
3623
+ ...edge,
3624
+ title: record.frontmatter.title ?? null,
3625
+ standing: hit?.standing ?? "unsettled",
3626
+ warnings: hit?.warnings ?? []
3627
+ });
3628
+ }
3629
+ return {
3630
+ target: targetId,
3631
+ backlinks: rows.sort(
3632
+ (left, right) => left.from.localeCompare(right.from) || left.rel.localeCompare(right.rel)
3633
+ )
3634
+ };
3635
+ }
3636
+
3637
+ // src/kb-links/impact.ts
3638
+ function impact(targetId, bundle, options = {}) {
3639
+ const byId = new Map(bundle.map((record) => [record.conceptId, record]));
3640
+ if (!byId.has(targetId)) throw new KbRecordNotFoundError(targetId);
3641
+ const rels = resolveRels(options.rels);
3642
+ const maxDepth = options.depth ?? Number.POSITIVE_INFINITY;
3643
+ const inbound = inboundIndex(bundle);
3644
+ const standingOf = new Map(
3645
+ adjudicate(bundle, bundle).map((hit) => [hit.record.conceptId, hit])
3646
+ );
3647
+ const reached = /* @__PURE__ */ new Map();
3648
+ const stopped = [];
3649
+ let frontier = [targetId];
3650
+ let depth = 0;
3651
+ while (frontier.length && depth < maxDepth) {
3652
+ depth += 1;
3653
+ const next = [];
3654
+ const consider = (dependantId, edge) => {
3655
+ if (dependantId === targetId) return;
3656
+ const existing = reached.get(dependantId);
3657
+ if (existing) {
3658
+ if (!hasEdge(existing.via, edge)) existing.via.push(edge);
3659
+ return;
3660
+ }
3661
+ const record = byId.get(dependantId);
3662
+ if (!record) return;
3663
+ const hit = standingOf.get(dependantId);
3664
+ const entry = {
3665
+ conceptId: dependantId,
3666
+ title: record.frontmatter.title ?? null,
3667
+ standing: hit?.standing ?? "unsettled",
3668
+ warnings: hit?.warnings ?? [],
3669
+ depth,
3670
+ via: [edge]
3671
+ };
3672
+ reached.set(dependantId, entry);
3673
+ if (entry.standing === "superseded" || entry.standing === "rejected") {
3674
+ stopped.push(dependantId);
3675
+ return;
3676
+ }
3677
+ next.push(dependantId);
3678
+ };
3679
+ for (const id of frontier) {
3680
+ for (const edge of inbound.get(id) ?? []) {
3681
+ if (!rels.has(edge.rel)) continue;
3682
+ if (dependantEnd(edge.rel) !== "source") continue;
3683
+ consider(edge.from, { source: edge.from, target: id, rel: edge.rel });
3684
+ }
3685
+ for (const link2 of byId.get(id)?.frontmatter.strauss_links ?? []) {
3686
+ if (!rels.has(link2.rel)) continue;
3687
+ if (dependantEnd(link2.rel) !== "target") continue;
3688
+ if (link2.target === id) continue;
3689
+ consider(link2.target, {
3690
+ source: id,
3691
+ target: link2.target,
3692
+ rel: link2.rel
3693
+ });
3694
+ }
3695
+ }
3696
+ frontier = next;
3697
+ }
3698
+ return {
3699
+ root: targetId,
3700
+ impacted: [...reached.values()].sort(
3701
+ (left, right) => left.depth - right.depth || left.conceptId.localeCompare(right.conceptId)
3702
+ ),
3703
+ stopped: stopped.sort(),
3704
+ truncated: frontier.length > 0,
3705
+ unexpanded: [...frontier].sort()
3706
+ };
3707
+ }
3708
+ function resolveRels(rels) {
3709
+ if (!rels?.length) return new Set(KB_CAUSAL_LINK_RELS);
3710
+ for (const rel of rels) {
3711
+ if (!isKbLinkRel(rel) || LINK_RELS[rel].dependant === null) {
3712
+ throw new KbUnknownLinkRelError(rel, KB_CAUSAL_LINK_RELS);
3713
+ }
3714
+ }
3715
+ return new Set(rels);
3716
+ }
3717
+ function dependantEnd(rel) {
3718
+ return isKbLinkRel(rel) ? LINK_RELS[rel].dependant : null;
3719
+ }
3720
+ function hasEdge(edges, edge) {
3721
+ return edges.some(
3722
+ (existing) => existing.source === edge.source && existing.target === edge.target && existing.rel === edge.rel
3723
+ );
3724
+ }
3725
+
3371
3726
  // src/kb-gitattributes.ts
3372
3727
  var GITATTRIBUTES_FILE = ".gitattributes";
3373
3728
  var UNION_MERGE_LINE = `${LOG_FILE} text eol=lf merge=union`;
@@ -3771,6 +4126,14 @@ ${answer}
3771
4126
  async pack(bundlePath2, rootId, options = {}) {
3772
4127
  return pack(await this.list(bundlePath2), rootId, options);
3773
4128
  }
4129
+ /** What breaks if this record changes. See `kb-links/impact.ts`. */
4130
+ async impact(bundlePath2, targetId, options = {}) {
4131
+ return impact(targetId, await this.list(bundlePath2), options);
4132
+ }
4133
+ /** Who points at this record, one hop. See `kb-links/backlinks.ts`. */
4134
+ async backlinks(bundlePath2, targetId) {
4135
+ return backlinks(targetId, await this.list(bundlePath2));
4136
+ }
3774
4137
  /**
3775
4138
  * The stored index, rebuilt if it disagrees with the records.
3776
4139
  *
@@ -4091,7 +4454,7 @@ function bundleDigest(records, superseded) {
4091
4454
  }
4092
4455
 
4093
4456
  // src/version.ts
4094
- var VERSION = true ? "0.1.12" : "0.0.0-dev";
4457
+ var VERSION = true ? "0.1.13" : "0.0.0-dev";
4095
4458
 
4096
4459
  // src/mcp.ts
4097
4460
  function createKbMcpServer() {