@saasontools/strauss-kb 0.1.12 → 0.1.14
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/ARCHITECTURE.md +54 -50
- package/README.md +172 -420
- package/dist/{chunk-33ZCBEUV.js → chunk-43KALLFU.js} +482 -122
- package/dist/chunk-43KALLFU.js.map +1 -0
- package/dist/{chunk-F2U2YLWV.js → chunk-MBXNCZ4V.js} +2 -2
- package/dist/{chunk-EXKK2KUN.js → chunk-PYA5E7FL.js} +2 -2
- package/dist/cli-main.cjs +480 -132
- package/dist/cli-main.cjs.map +1 -1
- package/dist/cli-main.js +2 -2
- package/dist/index.cjs +559 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +279 -13
- package/dist/index.d.ts +279 -13
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp-main.cjs +480 -132
- package/dist/mcp-main.cjs.map +1 -1
- package/dist/mcp-main.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-33ZCBEUV.js.map +0 -1
- /package/dist/{chunk-F2U2YLWV.js.map → chunk-MBXNCZ4V.js.map} +0 -0
- /package/dist/{chunk-EXKK2KUN.js.map → chunk-PYA5E7FL.js.map} +0 -0
package/dist/cli-main.cjs
CHANGED
|
@@ -78,6 +78,10 @@ var kbAnchorSchema = import_zod.z.object({
|
|
|
78
78
|
/** Line count of the text the hash was taken over. */
|
|
79
79
|
lines: import_zod.z.number().int().positive().optional()
|
|
80
80
|
}).strict();
|
|
81
|
+
var kbLinkSchema = import_zod.z.object({
|
|
82
|
+
target: import_zod.z.string().min(1),
|
|
83
|
+
rel: import_zod.z.string().min(1)
|
|
84
|
+
}).passthrough();
|
|
81
85
|
var KB_RECORD_TYPES = [
|
|
82
86
|
"fact",
|
|
83
87
|
"requirement",
|
|
@@ -129,6 +133,10 @@ var kbRecordFrontmatterSchema = import_zod.z.object({
|
|
|
129
133
|
// strauss extensions — see the module comment.
|
|
130
134
|
strauss_anchors: import_zod.z.array(kbAnchorSchema).optional(),
|
|
131
135
|
strauss_verify: import_zod.z.array(import_zod.z.string().min(1)).optional(),
|
|
136
|
+
// Typed causal edges, source → target, living on the source. `A depends_on
|
|
137
|
+
// B` means A needs B, so `kb_impact` walks these inbound: what breaks if B
|
|
138
|
+
// changes is whatever declared a dependence on it.
|
|
139
|
+
strauss_links: import_zod.z.array(kbLinkSchema).optional(),
|
|
132
140
|
// Total after parsing, tolerant before it. Our producers must supply a
|
|
133
141
|
// status — an absent one would leave every reader inventing its own default
|
|
134
142
|
// — but OKF calls a concept carrying only `type` fully conformant, so
|
|
@@ -213,8 +221,70 @@ var RECORD_TYPES = {
|
|
|
213
221
|
function isKbRecordType(value) {
|
|
214
222
|
return Object.prototype.hasOwnProperty.call(RECORD_TYPES, value);
|
|
215
223
|
}
|
|
224
|
+
var KB_LINK_RELS = [
|
|
225
|
+
"depends_on",
|
|
226
|
+
"constrains",
|
|
227
|
+
"informs",
|
|
228
|
+
"blocks",
|
|
229
|
+
"invalidates",
|
|
230
|
+
"verified_by",
|
|
231
|
+
"satisfies",
|
|
232
|
+
"related_to"
|
|
233
|
+
];
|
|
234
|
+
var LINK_RELS = {
|
|
235
|
+
depends_on: {
|
|
236
|
+
purpose: "The source needs the target to hold; the source breaks if the target changes",
|
|
237
|
+
phrase: "Depends on",
|
|
238
|
+
dependant: "source"
|
|
239
|
+
},
|
|
240
|
+
constrains: {
|
|
241
|
+
purpose: "The source bounds what the target may do; the target breaks if the constraint changes",
|
|
242
|
+
phrase: "Constrains",
|
|
243
|
+
dependant: "target"
|
|
244
|
+
},
|
|
245
|
+
informs: {
|
|
246
|
+
purpose: "The source shaped the target without binding it; the target is what needs revisiting",
|
|
247
|
+
phrase: "Informs",
|
|
248
|
+
dependant: "target"
|
|
249
|
+
},
|
|
250
|
+
blocks: {
|
|
251
|
+
purpose: "The target cannot proceed until the source is settled; the target is what waits",
|
|
252
|
+
phrase: "Blocks",
|
|
253
|
+
dependant: "target"
|
|
254
|
+
},
|
|
255
|
+
invalidates: {
|
|
256
|
+
purpose: "The source makes the target no longer hold; the target is what stops holding",
|
|
257
|
+
phrase: "Invalidates",
|
|
258
|
+
dependant: "target"
|
|
259
|
+
},
|
|
260
|
+
verified_by: {
|
|
261
|
+
purpose: "The target is the check that confirms the source; the source's confirmation moves with it",
|
|
262
|
+
phrase: "Verified by",
|
|
263
|
+
dependant: "source"
|
|
264
|
+
},
|
|
265
|
+
satisfies: {
|
|
266
|
+
purpose: "The source discharges the target's requirement; the source must change if the requirement does",
|
|
267
|
+
phrase: "Satisfies",
|
|
268
|
+
dependant: "source"
|
|
269
|
+
},
|
|
270
|
+
related_to: {
|
|
271
|
+
purpose: "A pointer worth following, with no claim of dependence",
|
|
272
|
+
phrase: "Relates to",
|
|
273
|
+
dependant: null
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
var KB_CAUSAL_LINK_RELS = KB_LINK_RELS.filter(
|
|
277
|
+
(rel) => LINK_RELS[rel].dependant !== null
|
|
278
|
+
);
|
|
279
|
+
function isKbLinkRel(value) {
|
|
280
|
+
return Object.prototype.hasOwnProperty.call(LINK_RELS, value);
|
|
281
|
+
}
|
|
216
282
|
|
|
217
283
|
// src/compose.ts
|
|
284
|
+
var composeLinkSchema = import_zod2.z.object({
|
|
285
|
+
target: kbConceptIdSchema,
|
|
286
|
+
rel: import_zod2.z.enum(KB_LINK_RELS)
|
|
287
|
+
}).strict();
|
|
218
288
|
var composeInputSchema = import_zod2.z.object({
|
|
219
289
|
slug: import_zod2.z.string().min(1),
|
|
220
290
|
/** One line, in the reader's terms. Becomes OKF `title`. */
|
|
@@ -241,6 +311,18 @@ var composeInputSchema = import_zod2.z.object({
|
|
|
241
311
|
tags: import_zod2.z.array(import_zod2.z.string().min(1)).optional(),
|
|
242
312
|
/** Concept ids this record relates to; rendered as body links. */
|
|
243
313
|
relatedConceptIds: import_zod2.z.array(kbConceptIdSchema).optional(),
|
|
314
|
+
/**
|
|
315
|
+
* Typed causal edges, source → target: `{ target: "fact.b", rel:
|
|
316
|
+
* "depends_on" }` on record A says A needs B. Stored in frontmatter and
|
|
317
|
+
* also rendered as one prose sentence each, so the meaning survives a
|
|
318
|
+
* reader that knows only OKF. The vocabulary goes into the description from
|
|
319
|
+
* the same table the walk uses, so `kb_schema` emits it.
|
|
320
|
+
*/
|
|
321
|
+
links: import_zod2.z.array(composeLinkSchema).max(64).optional().describe(
|
|
322
|
+
`Typed causal edges, source \u2192 target \u2014 a link on this record says this record <rel> the target. ${KB_LINK_RELS.map(
|
|
323
|
+
(rel) => `${rel}: ${LINK_RELS[rel].purpose}`
|
|
324
|
+
).join("; ")}.`
|
|
325
|
+
),
|
|
244
326
|
/** Concept ids this record replaces. The store settles the backlinks. */
|
|
245
327
|
supersedes: import_zod2.z.array(kbConceptIdSchema).max(32).optional(),
|
|
246
328
|
materiality: import_zod2.z.enum(KB_MATERIALITIES).optional(),
|
|
@@ -280,6 +362,15 @@ function composeRecord(type, input, writtenBy, writtenAt) {
|
|
|
280
362
|
if (parsed.owner) frontmatter.strauss_owner = parsed.owner;
|
|
281
363
|
if (parsed.supersedes?.length)
|
|
282
364
|
frontmatter.strauss_supersedes = parsed.supersedes;
|
|
365
|
+
const selfLink = parsed.links?.find(
|
|
366
|
+
(link2) => link2.target === `${type}.${parsed.slug}`
|
|
367
|
+
);
|
|
368
|
+
if (selfLink) {
|
|
369
|
+
throw new Error(
|
|
370
|
+
`kb: ${type}.${parsed.slug} cannot ${selfLink.rel} itself \u2014 a link must name another record`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
if (parsed.links?.length) frontmatter.strauss_links = parsed.links;
|
|
283
374
|
const blocks = [];
|
|
284
375
|
for (const heading of spec.sections) {
|
|
285
376
|
const text = sections[heading];
|
|
@@ -291,6 +382,11 @@ ${text}`);
|
|
|
291
382
|
for (const related of parsed.relatedConceptIds ?? []) {
|
|
292
383
|
blocks.push(`Relates to [${related}](${related}.md).`);
|
|
293
384
|
}
|
|
385
|
+
for (const link2 of parsed.links ?? []) {
|
|
386
|
+
blocks.push(
|
|
387
|
+
`${LINK_RELS[link2.rel].phrase} [${link2.target}](${link2.target}.md).`
|
|
388
|
+
);
|
|
389
|
+
}
|
|
294
390
|
if (parsed.sources?.length) {
|
|
295
391
|
blocks.push(
|
|
296
392
|
parsed.sources.map((source) => `[^${source.id}]: ${source.title ?? source.resource}`).join("\n")
|
|
@@ -313,7 +409,7 @@ var decisionInputSchema = composeInputSchema.omit({ sections: true }).extend({
|
|
|
313
409
|
impact: import_zod3.z.string().min(1).optional()
|
|
314
410
|
}).strict();
|
|
315
411
|
function composeDecisionRecord(input, writtenBy, writtenAt) {
|
|
316
|
-
const { alternative, impact, ...rest } = input;
|
|
412
|
+
const { alternative, impact: impact2, ...rest } = input;
|
|
317
413
|
return composeRecord(
|
|
318
414
|
DECISION_TYPE,
|
|
319
415
|
{
|
|
@@ -322,7 +418,7 @@ function composeDecisionRecord(input, writtenBy, writtenAt) {
|
|
|
322
418
|
Decision: input.title,
|
|
323
419
|
Rationale: input.why,
|
|
324
420
|
...alternative ? { Rejected: alternative } : {},
|
|
325
|
-
...
|
|
421
|
+
...impact2 ? { Impact: impact2 } : {}
|
|
326
422
|
}
|
|
327
423
|
},
|
|
328
424
|
writtenBy,
|
|
@@ -904,6 +1000,23 @@ var KbPackBudgetExceededError = class extends BaseError {
|
|
|
904
1000
|
budgetTokens;
|
|
905
1001
|
excluded;
|
|
906
1002
|
};
|
|
1003
|
+
var KbUnknownLinkRelError = class extends BaseError {
|
|
1004
|
+
constructor(rel, expected) {
|
|
1005
|
+
super({
|
|
1006
|
+
message: `kb: ${rel} is not a rel a walk can follow \u2014 expected one of ${expected.join(", ")}`,
|
|
1007
|
+
errorType: "KbUnknownLinkRel" /* KbUnknownLinkRel */,
|
|
1008
|
+
code: 400,
|
|
1009
|
+
fault: "User" /* User */,
|
|
1010
|
+
retriable: false,
|
|
1011
|
+
reportToUser: true,
|
|
1012
|
+
details: { rel, expected: expected.join(", ") }
|
|
1013
|
+
});
|
|
1014
|
+
this.rel = rel;
|
|
1015
|
+
this.expected = expected;
|
|
1016
|
+
}
|
|
1017
|
+
rel;
|
|
1018
|
+
expected;
|
|
1019
|
+
};
|
|
907
1020
|
var KbMissingFlagValueError = class extends BaseError {
|
|
908
1021
|
constructor(flag) {
|
|
909
1022
|
super({
|
|
@@ -1421,7 +1534,7 @@ var answerCommand = define({
|
|
|
1421
1534
|
name: "answer",
|
|
1422
1535
|
tool: "kb_answer",
|
|
1423
1536
|
usage: "answer <concept-id> <answer...>",
|
|
1424
|
-
description: "Resolve an open question:
|
|
1537
|
+
description: "Resolve an open question: set status, stamp who and when, append an Answer section. If the answer overturns a decision or assumption, supersede that record explicitly.",
|
|
1425
1538
|
input: import_zod7.z.object({ bundlePath, conceptId, answer: import_zod7.z.string().min(1) }),
|
|
1426
1539
|
fromArgv: (argv, path) => ({
|
|
1427
1540
|
bundlePath: path,
|
|
@@ -1435,8 +1548,20 @@ var answerCommand = define({
|
|
|
1435
1548
|
}
|
|
1436
1549
|
});
|
|
1437
1550
|
|
|
1438
|
-
// src/commands/
|
|
1551
|
+
// src/commands/backlinks.ts
|
|
1439
1552
|
var import_zod8 = require("zod");
|
|
1553
|
+
var backlinksCommand = define({
|
|
1554
|
+
name: "backlinks",
|
|
1555
|
+
tool: "kb_backlinks",
|
|
1556
|
+
usage: "backlinks <concept-id>",
|
|
1557
|
+
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.",
|
|
1558
|
+
input: import_zod8.z.object({ bundlePath, conceptId }),
|
|
1559
|
+
fromArgv: (argv, path) => ({ bundlePath: path, conceptId: argv[1] }),
|
|
1560
|
+
run: async ({ store }, { bundlePath: path, conceptId: id }) => store.backlinks(path, id)
|
|
1561
|
+
});
|
|
1562
|
+
|
|
1563
|
+
// src/commands/catalog.ts
|
|
1564
|
+
var import_zod9 = require("zod");
|
|
1440
1565
|
|
|
1441
1566
|
// src/adjudicate.ts
|
|
1442
1567
|
var STANDING = {
|
|
@@ -1596,9 +1721,9 @@ var catalogCommand = define({
|
|
|
1596
1721
|
tool: "kb_catalog",
|
|
1597
1722
|
usage: "catalog [type]",
|
|
1598
1723
|
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.",
|
|
1599
|
-
input:
|
|
1724
|
+
input: import_zod9.z.object({
|
|
1600
1725
|
bundlePath,
|
|
1601
|
-
type:
|
|
1726
|
+
type: import_zod9.z.enum(KB_RECORD_TYPES).optional()
|
|
1602
1727
|
}),
|
|
1603
1728
|
fromArgv: (argv, path) => ({
|
|
1604
1729
|
bundlePath: path,
|
|
@@ -1653,7 +1778,7 @@ function count(value, noun) {
|
|
|
1653
1778
|
}
|
|
1654
1779
|
|
|
1655
1780
|
// src/commands/context.ts
|
|
1656
|
-
var
|
|
1781
|
+
var import_zod10 = require("zod");
|
|
1657
1782
|
|
|
1658
1783
|
// src/kb-context.ts
|
|
1659
1784
|
var import_promises3 = require("fs/promises");
|
|
@@ -1918,21 +2043,21 @@ var contextCommand = define({
|
|
|
1918
2043
|
name: "context",
|
|
1919
2044
|
tool: "kb_context",
|
|
1920
2045
|
usage: "context [--profile NAME] [--budget N] [--full-under N] [--format json] [--event NAME]",
|
|
1921
|
-
description: "
|
|
1922
|
-
input:
|
|
1923
|
-
budgetTokens:
|
|
2046
|
+
description: "Index block of pinned bases (ids, titles, standing) for injection at context birth. Takes no bundlePath \u2014 reads the workspace pin manifests. Empty when nothing is pinned; refuses over budget rather than truncating. Budget precedence: flags, then the manifest `context[profile]` over `context.default`, then the built-in profile, then package defaults.",
|
|
2047
|
+
input: import_zod10.z.object({
|
|
2048
|
+
budgetTokens: import_zod10.z.number().int().positive().optional().describe(
|
|
1924
2049
|
"Ceiling on the whole emitted block; past it the command refuses with a list of bases rather than truncating. Defaults to 4000."
|
|
1925
2050
|
),
|
|
1926
|
-
fullUnderTokens:
|
|
2051
|
+
fullUnderTokens: import_zod10.z.number().int().positive().optional().describe(
|
|
1927
2052
|
"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."
|
|
1928
2053
|
),
|
|
1929
|
-
profile:
|
|
2054
|
+
profile: import_zod10.z.string().optional().describe(
|
|
1930
2055
|
"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."
|
|
1931
2056
|
),
|
|
1932
|
-
format:
|
|
2057
|
+
format: import_zod10.z.enum(["markdown", "json"]).optional().describe(
|
|
1933
2058
|
"CLI envelope for hook protocols that require strict JSON on stdout. MCP callers omit this \u2014 the block itself is identical."
|
|
1934
2059
|
),
|
|
1935
|
-
event:
|
|
2060
|
+
event: import_zod10.z.string().optional().describe(
|
|
1936
2061
|
"hookEventName stamped into the JSON envelope. Only meaningful with format=json."
|
|
1937
2062
|
)
|
|
1938
2063
|
}),
|
|
@@ -1968,11 +2093,12 @@ var contextCommand = define({
|
|
|
1968
2093
|
});
|
|
1969
2094
|
|
|
1970
2095
|
// src/commands/doctor.ts
|
|
1971
|
-
var
|
|
2096
|
+
var import_zod11 = require("zod");
|
|
1972
2097
|
|
|
1973
2098
|
// src/kb-edges.ts
|
|
1974
2099
|
var KB_EDGE_KINDS = [
|
|
1975
2100
|
"body-link",
|
|
2101
|
+
"typed-link",
|
|
1976
2102
|
"supersession",
|
|
1977
2103
|
"anchor",
|
|
1978
2104
|
"source"
|
|
@@ -1981,10 +2107,11 @@ var BODY_LINK_TARGET = new RegExp(
|
|
|
1981
2107
|
`\\]\\((${KB_CONCEPT_ID_PATTERN.source.replace(/^\^|\$$/g, "")})\\.md\\)`,
|
|
1982
2108
|
"g"
|
|
1983
2109
|
);
|
|
1984
|
-
|
|
2110
|
+
var DEFAULT_TYPED_LINK_RELS = KB_LINK_RELS;
|
|
2111
|
+
function neighbours(from, bundle, kinds = KB_EDGE_KINDS, linkRels = DEFAULT_TYPED_LINK_RELS) {
|
|
1985
2112
|
const found = /* @__PURE__ */ new Map();
|
|
1986
2113
|
for (const kind of kinds) {
|
|
1987
|
-
for (const record of edgeNeighbours(from, bundle, kind)) {
|
|
2114
|
+
for (const record of edgeNeighbours(from, bundle, kind, linkRels)) {
|
|
1988
2115
|
const existing = found.get(record.conceptId);
|
|
1989
2116
|
if (existing) {
|
|
1990
2117
|
if (!existing.via.includes(kind)) existing.via.push(kind);
|
|
@@ -1995,7 +2122,7 @@ function neighbours(from, bundle, kinds = KB_EDGE_KINDS) {
|
|
|
1995
2122
|
}
|
|
1996
2123
|
return [...found.values()];
|
|
1997
2124
|
}
|
|
1998
|
-
function edgeNeighbours(from, bundle, kind) {
|
|
2125
|
+
function edgeNeighbours(from, bundle, kind, linkRels = DEFAULT_TYPED_LINK_RELS) {
|
|
1999
2126
|
switch (kind) {
|
|
2000
2127
|
// A link whose target is not in the bundle is legal per compose.ts —
|
|
2001
2128
|
// records are routinely written before the ones they point at exist — so
|
|
@@ -2009,6 +2136,21 @@ function edgeNeighbours(from, bundle, kind) {
|
|
|
2009
2136
|
(candidate) => candidate.conceptId !== from.conceptId && targets.has(candidate.conceptId)
|
|
2010
2137
|
);
|
|
2011
2138
|
}
|
|
2139
|
+
// Outbound only, like `body-link`, and for the same reason: this is what
|
|
2140
|
+
// the record declares about itself. A missing target is legal — the walk
|
|
2141
|
+
// skips it, and `kb_validate` is what reports it as a warning. A rel
|
|
2142
|
+
// outside `linkRels` is skipped too, which is how an unknown rel stays
|
|
2143
|
+
// untraversable everywhere rather than one walk at a time.
|
|
2144
|
+
case "typed-link": {
|
|
2145
|
+
const allowed = new Set(linkRels);
|
|
2146
|
+
const targets = new Set(
|
|
2147
|
+
(from.frontmatter.strauss_links ?? []).filter((link2) => allowed.has(link2.rel)).map((link2) => link2.target)
|
|
2148
|
+
);
|
|
2149
|
+
if (!targets.size) return [];
|
|
2150
|
+
return bundle.filter(
|
|
2151
|
+
(candidate) => candidate.conceptId !== from.conceptId && targets.has(candidate.conceptId)
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2012
2154
|
// Both directions and both pointers: `supersede()` writes the pair, but a
|
|
2013
2155
|
// hand-edit can leave one side behind, and a walk trusting one pointer
|
|
2014
2156
|
// would miss a replacement the bundle openly declares.
|
|
@@ -2050,7 +2192,7 @@ function anchorsTouch(left, right) {
|
|
|
2050
2192
|
function validateBundle(records) {
|
|
2051
2193
|
const byId = new Map(records.map((record) => [record.conceptId, record]));
|
|
2052
2194
|
const problems = [];
|
|
2053
|
-
const report = (check, conceptId2, note) => problems.push({ check, conceptId: conceptId2, note });
|
|
2195
|
+
const report = (check, conceptId2, note, severity = "error") => problems.push({ check, conceptId: conceptId2, note, severity });
|
|
2054
2196
|
for (const record of records) {
|
|
2055
2197
|
const { conceptId: conceptId2, frontmatter: fm } = record;
|
|
2056
2198
|
if (!isKbRecordType(fm.type)) {
|
|
@@ -2074,6 +2216,36 @@ function validateBundle(records) {
|
|
|
2074
2216
|
report("supersedes", conceptId2, `${old} is not marked superseded`);
|
|
2075
2217
|
}
|
|
2076
2218
|
}
|
|
2219
|
+
for (const link2 of fm.strauss_links ?? []) {
|
|
2220
|
+
if (!isKbLinkRel(link2.rel)) {
|
|
2221
|
+
report(
|
|
2222
|
+
"link_rel",
|
|
2223
|
+
conceptId2,
|
|
2224
|
+
`unknown rel "${link2.rel}" on link to ${link2.target} \u2014 expected one of ${KB_LINK_RELS.join(", ")}`
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
if (!KB_CONCEPT_ID_PATTERN.test(link2.target)) {
|
|
2228
|
+
report(
|
|
2229
|
+
"link_target",
|
|
2230
|
+
conceptId2,
|
|
2231
|
+
`target "${link2.target}" is not a valid concept id \u2014 expected <type>.<slug>, both kebab-case`
|
|
2232
|
+
);
|
|
2233
|
+
} else if (link2.target === conceptId2) {
|
|
2234
|
+
report(
|
|
2235
|
+
"link_target",
|
|
2236
|
+
conceptId2,
|
|
2237
|
+
`links to itself (${link2.rel})`,
|
|
2238
|
+
"warning"
|
|
2239
|
+
);
|
|
2240
|
+
} else if (!byId.has(link2.target)) {
|
|
2241
|
+
report(
|
|
2242
|
+
"link_target",
|
|
2243
|
+
conceptId2,
|
|
2244
|
+
`target ${link2.target} is not in the bundle`,
|
|
2245
|
+
"warning"
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2077
2249
|
if (fm.strauss_assumption && fm.sources?.length) {
|
|
2078
2250
|
report("assumption", conceptId2, "marked an assumption but cites sources");
|
|
2079
2251
|
}
|
|
@@ -2350,13 +2522,13 @@ function ageInDays(record, now) {
|
|
|
2350
2522
|
}
|
|
2351
2523
|
|
|
2352
2524
|
// src/commands/doctor.ts
|
|
2353
|
-
var days = (what, fallback) =>
|
|
2525
|
+
var days = (what, fallback) => import_zod11.z.number().int().positive().optional().describe(`${what} Defaults to ${fallback}.`);
|
|
2354
2526
|
var doctorCommand = define({
|
|
2355
2527
|
name: "doctor",
|
|
2356
2528
|
tool: "kb_doctor",
|
|
2357
2529
|
usage: "doctor [--expiring-days N] [--unverified-days N] [--aging-days N] [--repo-root PATH] [--strict]",
|
|
2358
2530
|
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.",
|
|
2359
|
-
input:
|
|
2531
|
+
input: import_zod11.z.object({
|
|
2360
2532
|
bundlePath,
|
|
2361
2533
|
repoRoot: REPO_ROOT,
|
|
2362
2534
|
expiringDays: days(
|
|
@@ -2371,7 +2543,7 @@ var doctorCommand = define({
|
|
|
2371
2543
|
"How long a record may stay `open` or `proposed` before `aging` reports it, in days.",
|
|
2372
2544
|
DEFAULT_AGING_DAYS
|
|
2373
2545
|
),
|
|
2374
|
-
strict:
|
|
2546
|
+
strict: import_zod11.z.boolean().optional().describe(
|
|
2375
2547
|
"Turn an expired record into a non-zero exit for the CLI. No effect on the report itself."
|
|
2376
2548
|
)
|
|
2377
2549
|
}),
|
|
@@ -2446,14 +2618,47 @@ function render2(result) {
|
|
|
2446
2618
|
return lines.join("\n");
|
|
2447
2619
|
}
|
|
2448
2620
|
|
|
2621
|
+
// src/commands/impact.ts
|
|
2622
|
+
var import_zod12 = require("zod");
|
|
2623
|
+
var impactCommand = define({
|
|
2624
|
+
name: "impact",
|
|
2625
|
+
tool: "kb_impact",
|
|
2626
|
+
usage: "impact <concept-id> [--depth N] [--rels a,b]",
|
|
2627
|
+
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.",
|
|
2628
|
+
input: import_zod12.z.object({
|
|
2629
|
+
bundlePath,
|
|
2630
|
+
conceptId,
|
|
2631
|
+
depth: import_zod12.z.number().int().positive().optional().describe(
|
|
2632
|
+
"Hops out from the record. Unbounded when omitted; a walk this cuts reports truncated: true."
|
|
2633
|
+
),
|
|
2634
|
+
rels: import_zod12.z.array(import_zod12.z.enum(KB_CAUSAL_LINK_RELS)).optional().describe(
|
|
2635
|
+
"Narrow which rels the walk follows. Defaults to every rel that carries a dependence \u2014 all but related_to."
|
|
2636
|
+
)
|
|
2637
|
+
}),
|
|
2638
|
+
fromArgv: (argv, path) => {
|
|
2639
|
+
const depth = argvFlag(argv, "--depth");
|
|
2640
|
+
const rels = argvFlag(argv, "--rels");
|
|
2641
|
+
return {
|
|
2642
|
+
bundlePath: path,
|
|
2643
|
+
conceptId: argv[1],
|
|
2644
|
+
...depth ? { depth: Number(depth) } : {},
|
|
2645
|
+
...rels ? { rels: rels.split(",").filter(Boolean) } : {}
|
|
2646
|
+
};
|
|
2647
|
+
},
|
|
2648
|
+
run: async ({ store }, { bundlePath: path, conceptId: id, depth, rels }) => store.impact(path, id, {
|
|
2649
|
+
...depth !== void 0 ? { depth } : {},
|
|
2650
|
+
...rels?.length ? { rels } : {}
|
|
2651
|
+
})
|
|
2652
|
+
});
|
|
2653
|
+
|
|
2449
2654
|
// src/commands/list.ts
|
|
2450
|
-
var
|
|
2655
|
+
var import_zod13 = require("zod");
|
|
2451
2656
|
var listCommand = define({
|
|
2452
2657
|
name: "list",
|
|
2453
2658
|
tool: "kb_list",
|
|
2454
2659
|
usage: "list [type]",
|
|
2455
|
-
description: "Every record, optionally
|
|
2456
|
-
input:
|
|
2660
|
+
description: "Every record, optionally one type. For enumerating; use kb_query for a question.",
|
|
2661
|
+
input: import_zod13.z.object({ bundlePath, type: import_zod13.z.enum(KB_RECORD_TYPES).optional() }),
|
|
2457
2662
|
fromArgv: (argv, path) => ({ bundlePath: path, type: argv[1] }),
|
|
2458
2663
|
run: async ({ store }, { bundlePath: path, type }) => (await store.list(path, type)).map((record) => ({
|
|
2459
2664
|
conceptId: record.conceptId,
|
|
@@ -2465,17 +2670,17 @@ var listCommand = define({
|
|
|
2465
2670
|
});
|
|
2466
2671
|
|
|
2467
2672
|
// src/commands/load.ts
|
|
2468
|
-
var
|
|
2673
|
+
var import_zod14 = require("zod");
|
|
2469
2674
|
var loadCommand = define({
|
|
2470
2675
|
name: "load",
|
|
2471
2676
|
tool: "kb_load",
|
|
2472
2677
|
usage: "load [type] [--budget N | --all] [--repo-root PATH]",
|
|
2473
|
-
description: "
|
|
2474
|
-
input:
|
|
2678
|
+
description: "Load the whole base, each record with its standing \u2014 call it first, at the point of use, since compaction drops it. Superseded records arrive as stubs; kb_trace has the history. Over budget it refuses: kb_catalog, then kb_pack, or narrow with `type`; `all` bypasses. Never read record files directly \u2014 only kb_* tools resolve supersession. `digest` stamps the base's content, so hooks know when to reload.",
|
|
2679
|
+
input: import_zod14.z.object({
|
|
2475
2680
|
bundlePath,
|
|
2476
|
-
type:
|
|
2477
|
-
budgetTokens:
|
|
2478
|
-
all:
|
|
2681
|
+
type: import_zod14.z.enum(KB_RECORD_TYPES).optional(),
|
|
2682
|
+
budgetTokens: import_zod14.z.number().int().positive().optional().describe("Approximate token ceiling. Defaults to 25000."),
|
|
2683
|
+
all: import_zod14.z.boolean().optional().describe(
|
|
2479
2684
|
"Loads the entire base regardless of size, bypassing the token budget; mutually exclusive with budgetTokens."
|
|
2480
2685
|
),
|
|
2481
2686
|
repoRoot: REPO_ROOT
|
|
@@ -2517,25 +2722,25 @@ var loadCommand = define({
|
|
|
2517
2722
|
});
|
|
2518
2723
|
|
|
2519
2724
|
// src/commands/log.ts
|
|
2520
|
-
var
|
|
2725
|
+
var import_zod15 = require("zod");
|
|
2521
2726
|
var logCommand = define({
|
|
2522
2727
|
name: "log",
|
|
2523
2728
|
tool: "kb_log",
|
|
2524
2729
|
usage: "log",
|
|
2525
|
-
description: "
|
|
2526
|
-
input:
|
|
2730
|
+
description: "Who touched what, and when. Append-only; malformed lines are reported, never repaired.",
|
|
2731
|
+
input: import_zod15.z.object({ bundlePath }),
|
|
2527
2732
|
fromArgv: (_argv, path) => ({ bundlePath: path }),
|
|
2528
2733
|
run: ({ store }, { bundlePath: path }) => store.readLog(path)
|
|
2529
2734
|
});
|
|
2530
2735
|
|
|
2531
2736
|
// src/commands/no-decision.ts
|
|
2532
|
-
var
|
|
2737
|
+
var import_zod16 = require("zod");
|
|
2533
2738
|
var noDecisionCommand = define({
|
|
2534
2739
|
name: "no-decision",
|
|
2535
2740
|
tool: "kb_no_decision",
|
|
2536
2741
|
usage: "no-decision <reason...>",
|
|
2537
|
-
description:
|
|
2538
|
-
input:
|
|
2742
|
+
description: "Record in one sentence that a piece of work had nothing to decide. Idempotent.",
|
|
2743
|
+
input: import_zod16.z.object({ bundlePath, reason: import_zod16.z.string().min(1) }),
|
|
2539
2744
|
fromArgv: (argv, path) => ({
|
|
2540
2745
|
bundlePath: path,
|
|
2541
2746
|
reason: argv.slice(1).join(" ").trim()
|
|
@@ -2552,20 +2757,20 @@ var noDecisionCommand = define({
|
|
|
2552
2757
|
});
|
|
2553
2758
|
|
|
2554
2759
|
// src/commands/pack.ts
|
|
2555
|
-
var
|
|
2760
|
+
var import_zod17 = require("zod");
|
|
2556
2761
|
var packCommand = define({
|
|
2557
2762
|
name: "pack",
|
|
2558
2763
|
tool: "kb_pack",
|
|
2559
2764
|
usage: "pack <conceptId> [--hops N] [--max-nodes N] [--budget N]",
|
|
2560
|
-
description: "
|
|
2561
|
-
input:
|
|
2765
|
+
description: "Bounded neighbourhood around one record: within `hops`, ranked, cut to `maxNodes`, with every cut record named under Excluded. Use when the base is over kb_load's budget and the work centres on a record you can name. Refuses over budget rather than truncating. Everything below the header is byte-stable across runs. Resolves supersession like kb_load.",
|
|
2766
|
+
input: import_zod17.z.object({
|
|
2562
2767
|
bundlePath,
|
|
2563
2768
|
conceptId,
|
|
2564
|
-
hops:
|
|
2565
|
-
maxNodes:
|
|
2769
|
+
hops: import_zod17.z.number().int().positive().optional().describe("How far from the root the walk may reach. Defaults to 2."),
|
|
2770
|
+
maxNodes: import_zod17.z.number().int().positive().optional().describe(
|
|
2566
2771
|
"How many records the pack may hold, root included. Defaults to 20."
|
|
2567
2772
|
),
|
|
2568
|
-
budgetTokens:
|
|
2773
|
+
budgetTokens: import_zod17.z.number().int().positive().optional().describe(
|
|
2569
2774
|
"Approximate token ceiling over what is actually emitted. Defaults to 25000."
|
|
2570
2775
|
)
|
|
2571
2776
|
}),
|
|
@@ -2652,22 +2857,22 @@ function warningLabel(warning) {
|
|
|
2652
2857
|
}
|
|
2653
2858
|
|
|
2654
2859
|
// src/commands/pin.ts
|
|
2655
|
-
var
|
|
2860
|
+
var import_zod18 = require("zod");
|
|
2656
2861
|
var pinCommand = define({
|
|
2657
2862
|
name: "pin",
|
|
2658
2863
|
tool: "kb_pin",
|
|
2659
2864
|
usage: "pin [bundle-path] [--mode full|index] [--profiles a,b] [--local|--user] [--frozen|--unfreeze]",
|
|
2660
|
-
description: "Pin a base into a workspace
|
|
2661
|
-
input:
|
|
2865
|
+
description: "Pin a base into a workspace manifest so kb_context surfaces it. Layers, nearest wins: project `.strauss/kb-pins.json` (default), `--local` (personal, gitignored), `--user` (`~/.strauss`). Idempotent; `--mode full|index`, `--profiles`, `--frozen`/`--unfreeze` update only those fields. A path with no records pins with a warning. Never touches the base itself.",
|
|
2866
|
+
input: import_zod18.z.object({
|
|
2662
2867
|
bundlePath,
|
|
2663
|
-
mode:
|
|
2868
|
+
mode: import_zod18.z.enum(["full", "index"]).optional().describe(
|
|
2664
2869
|
"full: always emit this base's records whole (still under the block budget); index: never upgrade. Absent: the profile's full-under threshold decides."
|
|
2665
2870
|
),
|
|
2666
|
-
profiles:
|
|
2667
|
-
layer:
|
|
2871
|
+
profiles: import_zod18.z.array(import_zod18.z.string()).optional().describe("Context profiles this pin surfaces in. Absent: all of them."),
|
|
2872
|
+
layer: import_zod18.z.enum(["project", "local", "user"]).optional().describe(
|
|
2668
2873
|
"Which manifest to write: project (committed, default), local (personal, gitignored), user (~/.strauss, every workspace)."
|
|
2669
2874
|
),
|
|
2670
|
-
frozen:
|
|
2875
|
+
frozen: import_zod18.z.boolean().optional().describe(
|
|
2671
2876
|
"true: the base is concluded \u2014 writes against it refuse while pinned. false: lift a freeze."
|
|
2672
2877
|
)
|
|
2673
2878
|
}),
|
|
@@ -2696,29 +2901,29 @@ var pinCommand = define({
|
|
|
2696
2901
|
});
|
|
2697
2902
|
|
|
2698
2903
|
// src/commands/pins.ts
|
|
2699
|
-
var
|
|
2904
|
+
var import_zod19 = require("zod");
|
|
2700
2905
|
var pinsCommand = define({
|
|
2701
2906
|
name: "pins",
|
|
2702
2907
|
tool: "kb_pins",
|
|
2703
2908
|
usage: "pins",
|
|
2704
|
-
description: "Every pinned base across the manifest layers,
|
|
2705
|
-
input:
|
|
2909
|
+
description: "Every pinned base across the manifest layers, with its layer and whether it resolves to records. Takes no bundlePath.",
|
|
2910
|
+
input: import_zod19.z.object({}),
|
|
2706
2911
|
fromArgv: () => ({}),
|
|
2707
2912
|
run: ({ store }) => listPins(store, process.cwd())
|
|
2708
2913
|
});
|
|
2709
2914
|
|
|
2710
2915
|
// src/commands/query.ts
|
|
2711
|
-
var
|
|
2916
|
+
var import_zod20 = require("zod");
|
|
2712
2917
|
var queryCommand = define({
|
|
2713
2918
|
name: "query",
|
|
2714
2919
|
tool: "kb_query",
|
|
2715
2920
|
usage: "query <text...> [--repo-root PATH]",
|
|
2716
2921
|
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.",
|
|
2717
|
-
input:
|
|
2922
|
+
input: import_zod20.z.object({
|
|
2718
2923
|
bundlePath,
|
|
2719
|
-
text:
|
|
2720
|
-
type:
|
|
2721
|
-
includeNonCurrent:
|
|
2924
|
+
text: import_zod20.z.string().optional(),
|
|
2925
|
+
type: import_zod20.z.enum(KB_RECORD_TYPES).optional(),
|
|
2926
|
+
includeNonCurrent: import_zod20.z.boolean().optional(),
|
|
2722
2927
|
repoRoot: REPO_ROOT
|
|
2723
2928
|
}),
|
|
2724
2929
|
// `--repo-root` is a flag, so its value must not fall into the search text.
|
|
@@ -2750,27 +2955,27 @@ var queryCommand = define({
|
|
|
2750
2955
|
});
|
|
2751
2956
|
|
|
2752
2957
|
// src/commands/read-index.ts
|
|
2753
|
-
var
|
|
2958
|
+
var import_zod21 = require("zod");
|
|
2754
2959
|
var readIndexCommand = define({
|
|
2755
2960
|
name: "index",
|
|
2756
2961
|
tool: "kb_index",
|
|
2757
2962
|
usage: "index",
|
|
2758
|
-
description: "The index
|
|
2759
|
-
input:
|
|
2963
|
+
description: "The index \u2014 title, type, status, description per record \u2014 rebuilt if stale. Cheapest re-orientation after compaction: call it (or kb_context) first, then kb_load or fetch by id.",
|
|
2964
|
+
input: import_zod21.z.object({ bundlePath }),
|
|
2760
2965
|
fromArgv: (_argv, path) => ({ bundlePath: path }),
|
|
2761
2966
|
run: ({ store }, { bundlePath: path }) => store.readIndex(path)
|
|
2762
2967
|
});
|
|
2763
2968
|
|
|
2764
2969
|
// src/commands/schema.ts
|
|
2765
|
-
var
|
|
2970
|
+
var import_zod24 = require("zod");
|
|
2766
2971
|
|
|
2767
2972
|
// src/json-schema.ts
|
|
2768
|
-
var
|
|
2973
|
+
var import_zod23 = require("zod");
|
|
2769
2974
|
|
|
2770
2975
|
// src/kb-log.ts
|
|
2771
|
-
var
|
|
2976
|
+
var import_zod22 = require("zod");
|
|
2772
2977
|
var LOG_FILE = "log.jsonl";
|
|
2773
|
-
var kbLogEntrySchema =
|
|
2978
|
+
var kbLogEntrySchema = import_zod22.z.object({
|
|
2774
2979
|
// Validated, not just `min(1)`: `at` is a sort key (see `parseLog`
|
|
2775
2980
|
// below), and a value that isn't actually chronological — a Unix
|
|
2776
2981
|
// timestamp, a human-typed date, garbage — would sort wrong without
|
|
@@ -2779,12 +2984,12 @@ var kbLogEntrySchema = import_zod20.z.object({
|
|
|
2779
2984
|
// and rejects everything else, including a non-`Z` offset — so a
|
|
2780
2985
|
// malformed `at` is reported the same way a malformed line already is,
|
|
2781
2986
|
// rather than silently sorting into the wrong place.
|
|
2782
|
-
at:
|
|
2783
|
-
by:
|
|
2784
|
-
operation:
|
|
2785
|
-
conceptId:
|
|
2987
|
+
at: import_zod22.z.iso.datetime(),
|
|
2988
|
+
by: import_zod22.z.string().min(1),
|
|
2989
|
+
operation: import_zod22.z.string().min(1),
|
|
2990
|
+
conceptId: import_zod22.z.string().min(1),
|
|
2786
2991
|
/** Second concept id, where the operation relates two — supersession. */
|
|
2787
|
-
target:
|
|
2992
|
+
target: import_zod22.z.string().min(1).optional()
|
|
2788
2993
|
}).strict();
|
|
2789
2994
|
function renderLogEntry(entry) {
|
|
2790
2995
|
return `${JSON.stringify(kbLogEntrySchema.parse(entry))}
|
|
@@ -2822,11 +3027,11 @@ function parseLog(raw) {
|
|
|
2822
3027
|
// src/json-schema.ts
|
|
2823
3028
|
function kbJsonSchemas() {
|
|
2824
3029
|
return {
|
|
2825
|
-
recordFrontmatter:
|
|
3030
|
+
recordFrontmatter: import_zod23.z.toJSONSchema(kbRecordFrontmatterSchema, {
|
|
2826
3031
|
io: "input"
|
|
2827
3032
|
}),
|
|
2828
|
-
composeInput:
|
|
2829
|
-
logEntry:
|
|
3033
|
+
composeInput: import_zod23.z.toJSONSchema(composeInputSchema, { io: "input" }),
|
|
3034
|
+
logEntry: import_zod23.z.toJSONSchema(kbLogEntrySchema, { io: "input" })
|
|
2830
3035
|
};
|
|
2831
3036
|
}
|
|
2832
3037
|
|
|
@@ -2835,23 +3040,23 @@ var schemaCommand = define({
|
|
|
2835
3040
|
name: "schema",
|
|
2836
3041
|
tool: "kb_schema",
|
|
2837
3042
|
usage: "schema",
|
|
2838
|
-
description: "JSON Schema for
|
|
2839
|
-
input:
|
|
3043
|
+
description: "JSON Schema for frontmatter, write input, and log entries, generated from the enforcing code.",
|
|
3044
|
+
input: import_zod24.z.object({}),
|
|
2840
3045
|
fromArgv: () => ({}),
|
|
2841
3046
|
run: () => Promise.resolve(kbJsonSchemas())
|
|
2842
3047
|
});
|
|
2843
3048
|
|
|
2844
3049
|
// src/commands/status.ts
|
|
2845
|
-
var
|
|
3050
|
+
var import_zod25 = require("zod");
|
|
2846
3051
|
var statusCommand = define({
|
|
2847
3052
|
name: "status",
|
|
2848
3053
|
tool: "kb_status",
|
|
2849
3054
|
usage: "status <concept-id> <status>",
|
|
2850
|
-
description: "Move a record's status
|
|
2851
|
-
input:
|
|
3055
|
+
description: "Move a record's status. Compare-and-swap: a concurrent change fails instead of being overwritten.",
|
|
3056
|
+
input: import_zod25.z.object({
|
|
2852
3057
|
bundlePath,
|
|
2853
3058
|
conceptId,
|
|
2854
|
-
status:
|
|
3059
|
+
status: import_zod25.z.enum(KB_RECORD_STATUSES)
|
|
2855
3060
|
}),
|
|
2856
3061
|
fromArgv: (argv, path) => ({
|
|
2857
3062
|
bundlePath: path,
|
|
@@ -2866,13 +3071,13 @@ var statusCommand = define({
|
|
|
2866
3071
|
});
|
|
2867
3072
|
|
|
2868
3073
|
// src/commands/supersede.ts
|
|
2869
|
-
var
|
|
3074
|
+
var import_zod26 = require("zod");
|
|
2870
3075
|
var supersedeCommand = define({
|
|
2871
3076
|
name: "supersede",
|
|
2872
3077
|
tool: "kb_supersede",
|
|
2873
3078
|
usage: "supersede <concept-id> <replacement-id>",
|
|
2874
|
-
description: "Mark a record superseded by another,
|
|
2875
|
-
input:
|
|
3079
|
+
description: "Mark a record superseded by another, linked in both directions. Use instead of editing a record whose meaning changed.",
|
|
3080
|
+
input: import_zod26.z.object({ bundlePath, conceptId, replacementId: conceptId }),
|
|
2876
3081
|
fromArgv: (argv, path) => ({
|
|
2877
3082
|
bundlePath: path,
|
|
2878
3083
|
conceptId: argv[1],
|
|
@@ -2886,16 +3091,16 @@ var supersedeCommand = define({
|
|
|
2886
3091
|
});
|
|
2887
3092
|
|
|
2888
3093
|
// src/commands/sync-instructions.ts
|
|
2889
|
-
var
|
|
3094
|
+
var import_zod27 = require("zod");
|
|
2890
3095
|
var syncInstructionsCommand = define({
|
|
2891
3096
|
name: "sync-instructions",
|
|
2892
3097
|
usage: "sync-instructions <file> [--profile NAME] [--budget N] [--full-under N]",
|
|
2893
|
-
description: "
|
|
2894
|
-
input:
|
|
2895
|
-
file:
|
|
2896
|
-
budgetTokens:
|
|
2897
|
-
fullUnderTokens:
|
|
2898
|
-
profile:
|
|
3098
|
+
description: "CLI-only: plant the kb_context block between sentinel comments in AGENTS.md or CLAUDE.md, idempotently.",
|
|
3099
|
+
input: import_zod27.z.object({
|
|
3100
|
+
file: import_zod27.z.string().min(1).describe("The instruction file to edit in place."),
|
|
3101
|
+
budgetTokens: import_zod27.z.number().int().positive().optional(),
|
|
3102
|
+
fullUnderTokens: import_zod27.z.number().int().positive().optional(),
|
|
3103
|
+
profile: import_zod27.z.string().optional()
|
|
2899
3104
|
}),
|
|
2900
3105
|
fromArgv: (argv) => {
|
|
2901
3106
|
const budget = argvFlag(argv, "--budget");
|
|
@@ -2921,10 +3126,15 @@ var syncInstructionsCommand = define({
|
|
|
2921
3126
|
});
|
|
2922
3127
|
|
|
2923
3128
|
// src/commands/trace.ts
|
|
2924
|
-
var
|
|
3129
|
+
var import_zod28 = require("zod");
|
|
2925
3130
|
|
|
2926
3131
|
// src/trace.ts
|
|
2927
|
-
var TRACE_EDGES = [
|
|
3132
|
+
var TRACE_EDGES = [
|
|
3133
|
+
"typed-link",
|
|
3134
|
+
"supersession",
|
|
3135
|
+
"anchor",
|
|
3136
|
+
"source"
|
|
3137
|
+
];
|
|
2928
3138
|
function trace(seedId, bundle, options = {}) {
|
|
2929
3139
|
const edges = options.edges?.length ? options.edges : TRACE_EDGES;
|
|
2930
3140
|
const maxDepth = options.depth ?? 3;
|
|
@@ -2939,7 +3149,12 @@ function trace(seedId, bundle, options = {}) {
|
|
|
2939
3149
|
const next = [];
|
|
2940
3150
|
for (const from of frontier) {
|
|
2941
3151
|
for (const edge of edges) {
|
|
2942
|
-
for (const record of edgeNeighbours(
|
|
3152
|
+
for (const record of edgeNeighbours(
|
|
3153
|
+
from,
|
|
3154
|
+
bundle,
|
|
3155
|
+
edge,
|
|
3156
|
+
KB_CAUSAL_LINK_RELS
|
|
3157
|
+
)) {
|
|
2943
3158
|
const existing = reached.get(record.conceptId);
|
|
2944
3159
|
if (existing) {
|
|
2945
3160
|
if (existing.depth > 0 && !existing.via.includes(edge)) {
|
|
@@ -2966,12 +3181,12 @@ var traceCommand = define({
|
|
|
2966
3181
|
name: "trace",
|
|
2967
3182
|
tool: "kb_trace",
|
|
2968
3183
|
usage: "trace <concept-id> [edges...]",
|
|
2969
|
-
description: '
|
|
2970
|
-
input:
|
|
3184
|
+
description: 'Timeline of how a position was reached, ordered by write time, following supersession, shared anchors and shared sources. Includes rejected, draft and superseded records \u2014 in a history they are the content. For "why is it like this"; kb_load answers "what holds now".',
|
|
3185
|
+
input: import_zod28.z.object({
|
|
2971
3186
|
bundlePath,
|
|
2972
3187
|
conceptId,
|
|
2973
|
-
edges:
|
|
2974
|
-
depth:
|
|
3188
|
+
edges: import_zod28.z.array(import_zod28.z.enum(TRACE_EDGES)).optional(),
|
|
3189
|
+
depth: import_zod28.z.number().int().positive().optional()
|
|
2975
3190
|
}),
|
|
2976
3191
|
fromArgv: (argv, path) => ({
|
|
2977
3192
|
bundlePath: path,
|
|
@@ -2993,53 +3208,56 @@ var traceCommand = define({
|
|
|
2993
3208
|
});
|
|
2994
3209
|
|
|
2995
3210
|
// src/commands/types.ts
|
|
2996
|
-
var
|
|
3211
|
+
var import_zod29 = require("zod");
|
|
2997
3212
|
var typesCommand = define({
|
|
2998
3213
|
name: "types",
|
|
2999
3214
|
tool: "kb_types",
|
|
3000
3215
|
usage: "types",
|
|
3001
3216
|
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.",
|
|
3002
|
-
input:
|
|
3217
|
+
input: import_zod29.z.object({}),
|
|
3003
3218
|
fromArgv: () => ({}),
|
|
3004
3219
|
run: () => Promise.resolve(RECORD_TYPES)
|
|
3005
3220
|
});
|
|
3006
3221
|
|
|
3007
3222
|
// src/commands/unpin.ts
|
|
3008
|
-
var
|
|
3223
|
+
var import_zod30 = require("zod");
|
|
3009
3224
|
var unpinCommand = define({
|
|
3010
3225
|
name: "unpin",
|
|
3011
3226
|
tool: "kb_unpin",
|
|
3012
3227
|
usage: "unpin [bundle-path]",
|
|
3013
|
-
description: "Remove a base from every
|
|
3014
|
-
input:
|
|
3228
|
+
description: "Remove a base from every manifest layer that holds it. Reports the layers touched.",
|
|
3229
|
+
input: import_zod30.z.object({ bundlePath }),
|
|
3015
3230
|
fromArgv: (argv, path) => ({ bundlePath: argv[1] ?? path }),
|
|
3016
3231
|
run: (_ctx, { bundlePath: path }) => unpinBase(process.cwd(), path)
|
|
3017
3232
|
});
|
|
3018
3233
|
|
|
3019
3234
|
// src/commands/validate.ts
|
|
3020
|
-
var
|
|
3235
|
+
var import_zod31 = require("zod");
|
|
3021
3236
|
var validateCommand = define({
|
|
3022
3237
|
name: "validate",
|
|
3023
3238
|
tool: "kb_validate",
|
|
3024
3239
|
usage: "validate",
|
|
3025
|
-
description: "Check pointers no single record can see: supersession links that disagree between the two records, and assumptions that cite sources.
|
|
3026
|
-
input:
|
|
3240
|
+
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.",
|
|
3241
|
+
input: import_zod31.z.object({ bundlePath }),
|
|
3027
3242
|
fromArgv: (_argv, path) => ({ bundlePath: path }),
|
|
3028
3243
|
run: async ({ store }, { bundlePath: path }) => validateBundle(await store.list(path)),
|
|
3029
|
-
|
|
3244
|
+
// Warnings never fail the exit code; every other severity does.
|
|
3245
|
+
failsWhen: (result) => Array.isArray(result) && result.some(
|
|
3246
|
+
(problem) => problem.severity !== "warning"
|
|
3247
|
+
)
|
|
3030
3248
|
});
|
|
3031
3249
|
|
|
3032
3250
|
// src/commands/verify.ts
|
|
3033
|
-
var
|
|
3251
|
+
var import_zod32 = require("zod");
|
|
3034
3252
|
var verifyCommand = define({
|
|
3035
3253
|
name: "verify",
|
|
3036
3254
|
tool: "kb_verify",
|
|
3037
3255
|
usage: "verify <concept-id> --note <text>",
|
|
3038
|
-
description: "Append
|
|
3039
|
-
input:
|
|
3256
|
+
description: "Append a verified[] event: who checked, when, and what was found. Append-only. A record's own generator is refused unless the actor is `human:`-prefixed.",
|
|
3257
|
+
input: import_zod32.z.object({
|
|
3040
3258
|
bundlePath,
|
|
3041
3259
|
conceptId,
|
|
3042
|
-
note:
|
|
3260
|
+
note: import_zod32.z.string().refine((s) => s.trim().length > 0, {
|
|
3043
3261
|
message: "note must say what the check found"
|
|
3044
3262
|
})
|
|
3045
3263
|
}),
|
|
@@ -3059,23 +3277,15 @@ var verifyCommand = define({
|
|
|
3059
3277
|
});
|
|
3060
3278
|
|
|
3061
3279
|
// src/commands/write.ts
|
|
3062
|
-
var
|
|
3280
|
+
var import_zod33 = require("zod");
|
|
3063
3281
|
var writeCommand = define({
|
|
3064
3282
|
name: "write",
|
|
3065
3283
|
tool: "kb_write",
|
|
3066
3284
|
usage: "write <type> < record.json",
|
|
3067
|
-
description:
|
|
3068
|
-
|
|
3069
|
-
"",
|
|
3070
|
-
"Judgment the tool cannot enforce for you:",
|
|
3071
|
-
"- An unsourced claim is an `assumption` record with assumption: true, never a `fact` with a vague source. The distinction is what lets a later reader separate what was established from what was guessed.",
|
|
3072
|
-
"- When two records conflict, say so in a `risk`, an `open-question`, or a superseding `decision`. Quietly picking a winner destroys the disagreement, which is usually the useful part.",
|
|
3073
|
-
"- Prefer a new record over overloading an existing one, and keep each short. A record nobody finishes reading is not durable memory.",
|
|
3074
|
-
"- Records are never deleted; supersede instead, so the earlier reasoning stays inspectable."
|
|
3075
|
-
].join("\n"),
|
|
3076
|
-
input: import_zod31.z.object({
|
|
3285
|
+
description: "Write one record. Search first \u2014 a duplicate concept id is rejected, not overwritten; kb_types lists each type's sections. An unsourced claim is an `assumption` with assumption: true, never a vague `fact`. Conflicting records get a `risk`, `open-question`, or superseding `decision`. Prefer a new short record over overloading one. Never delete; supersede.",
|
|
3286
|
+
input: import_zod33.z.object({
|
|
3077
3287
|
bundlePath,
|
|
3078
|
-
type:
|
|
3288
|
+
type: import_zod33.z.enum(KB_RECORD_TYPES),
|
|
3079
3289
|
input: composeInputSchema
|
|
3080
3290
|
}),
|
|
3081
3291
|
fromArgv: async (argv, path, stdin) => ({
|
|
@@ -3099,20 +3309,13 @@ var writeCommand = define({
|
|
|
3099
3309
|
});
|
|
3100
3310
|
|
|
3101
3311
|
// src/commands/write-decision.ts
|
|
3102
|
-
var
|
|
3312
|
+
var import_zod34 = require("zod");
|
|
3103
3313
|
var writeDecisionCommand = define({
|
|
3104
3314
|
name: "write-decision",
|
|
3105
3315
|
tool: "kb_write_decision",
|
|
3106
3316
|
usage: "write-decision < decision.json",
|
|
3107
|
-
description:
|
|
3108
|
-
|
|
3109
|
-
"",
|
|
3110
|
-
"What belongs in one:",
|
|
3111
|
-
'- Record a decision when a later reader would otherwise "simplify" the constraint away. If the diff already answers the question, there is nothing here to write.',
|
|
3112
|
-
"- `alternative` is what you turned down and why, not a list of everything considered.",
|
|
3113
|
-
"- A reference to material you read goes in `sources`; a reference to code goes in `anchors`; a reference to another record goes in `relatedConceptIds`."
|
|
3114
|
-
].join("\n"),
|
|
3115
|
-
input: import_zod32.z.object({ bundlePath, input: decisionInputSchema }),
|
|
3317
|
+
description: "Write a decision, with `alternative` (what was rejected and why) and `impact` as fields. Record one when a later reader would otherwise simplify the constraint away; skip when the diff already answers it. `sources` for material read, `anchors` for code, `relatedConceptIds` for records.",
|
|
3318
|
+
input: import_zod34.z.object({ bundlePath, input: decisionInputSchema }),
|
|
3116
3319
|
fromArgv: async (_argv, path, stdin) => ({
|
|
3117
3320
|
bundlePath: path,
|
|
3118
3321
|
input: JSON.parse(await stdin())
|
|
@@ -3147,6 +3350,8 @@ var KB_COMMANDS = [
|
|
|
3147
3350
|
packCommand,
|
|
3148
3351
|
queryCommand,
|
|
3149
3352
|
traceCommand,
|
|
3353
|
+
impactCommand,
|
|
3354
|
+
backlinksCommand,
|
|
3150
3355
|
listCommand,
|
|
3151
3356
|
readIndexCommand,
|
|
3152
3357
|
logCommand,
|
|
@@ -3367,6 +3572,141 @@ function typeRank(record) {
|
|
|
3367
3572
|
return index === -1 ? TYPE_PRIORITY.length : index;
|
|
3368
3573
|
}
|
|
3369
3574
|
|
|
3575
|
+
// src/kb-links/inbound.ts
|
|
3576
|
+
function inboundIndex(bundle) {
|
|
3577
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
3578
|
+
for (const record of bundle) {
|
|
3579
|
+
for (const link2 of record.frontmatter.strauss_links ?? []) {
|
|
3580
|
+
if (link2.target === record.conceptId) continue;
|
|
3581
|
+
const edges = byTarget.get(link2.target) ?? [];
|
|
3582
|
+
if (edges.some(
|
|
3583
|
+
(edge) => edge.from === record.conceptId && edge.rel === link2.rel
|
|
3584
|
+
)) {
|
|
3585
|
+
continue;
|
|
3586
|
+
}
|
|
3587
|
+
edges.push({ from: record.conceptId, rel: link2.rel });
|
|
3588
|
+
byTarget.set(link2.target, edges);
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
return byTarget;
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
// src/kb-links/backlinks.ts
|
|
3595
|
+
function backlinks(targetId, bundle) {
|
|
3596
|
+
const byId = new Map(bundle.map((record) => [record.conceptId, record]));
|
|
3597
|
+
if (!byId.has(targetId)) throw new KbRecordNotFoundError(targetId);
|
|
3598
|
+
const standingOf = new Map(
|
|
3599
|
+
adjudicate(bundle, bundle).map((hit) => [hit.record.conceptId, hit])
|
|
3600
|
+
);
|
|
3601
|
+
const rows = [];
|
|
3602
|
+
for (const edge of inboundIndex(bundle).get(targetId) ?? []) {
|
|
3603
|
+
const record = byId.get(edge.from);
|
|
3604
|
+
if (!record) continue;
|
|
3605
|
+
const hit = standingOf.get(edge.from);
|
|
3606
|
+
rows.push({
|
|
3607
|
+
...edge,
|
|
3608
|
+
title: record.frontmatter.title ?? null,
|
|
3609
|
+
standing: hit?.standing ?? "unsettled",
|
|
3610
|
+
warnings: hit?.warnings ?? []
|
|
3611
|
+
});
|
|
3612
|
+
}
|
|
3613
|
+
return {
|
|
3614
|
+
target: targetId,
|
|
3615
|
+
backlinks: rows.sort(
|
|
3616
|
+
(left, right) => left.from.localeCompare(right.from) || left.rel.localeCompare(right.rel)
|
|
3617
|
+
)
|
|
3618
|
+
};
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
// src/kb-links/impact.ts
|
|
3622
|
+
function impact(targetId, bundle, options = {}) {
|
|
3623
|
+
const byId = new Map(bundle.map((record) => [record.conceptId, record]));
|
|
3624
|
+
if (!byId.has(targetId)) throw new KbRecordNotFoundError(targetId);
|
|
3625
|
+
const rels = resolveRels(options.rels);
|
|
3626
|
+
const maxDepth = options.depth ?? Number.POSITIVE_INFINITY;
|
|
3627
|
+
const inbound = inboundIndex(bundle);
|
|
3628
|
+
const standingOf = new Map(
|
|
3629
|
+
adjudicate(bundle, bundle).map((hit) => [hit.record.conceptId, hit])
|
|
3630
|
+
);
|
|
3631
|
+
const reached = /* @__PURE__ */ new Map();
|
|
3632
|
+
const stopped = [];
|
|
3633
|
+
let frontier = [targetId];
|
|
3634
|
+
let depth = 0;
|
|
3635
|
+
while (frontier.length && depth < maxDepth) {
|
|
3636
|
+
depth += 1;
|
|
3637
|
+
const next = [];
|
|
3638
|
+
const consider = (dependantId, edge) => {
|
|
3639
|
+
if (dependantId === targetId) return;
|
|
3640
|
+
const existing = reached.get(dependantId);
|
|
3641
|
+
if (existing) {
|
|
3642
|
+
if (!hasEdge(existing.via, edge)) existing.via.push(edge);
|
|
3643
|
+
return;
|
|
3644
|
+
}
|
|
3645
|
+
const record = byId.get(dependantId);
|
|
3646
|
+
if (!record) return;
|
|
3647
|
+
const hit = standingOf.get(dependantId);
|
|
3648
|
+
const entry = {
|
|
3649
|
+
conceptId: dependantId,
|
|
3650
|
+
title: record.frontmatter.title ?? null,
|
|
3651
|
+
standing: hit?.standing ?? "unsettled",
|
|
3652
|
+
warnings: hit?.warnings ?? [],
|
|
3653
|
+
depth,
|
|
3654
|
+
via: [edge]
|
|
3655
|
+
};
|
|
3656
|
+
reached.set(dependantId, entry);
|
|
3657
|
+
if (entry.standing === "superseded" || entry.standing === "rejected") {
|
|
3658
|
+
stopped.push(dependantId);
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
next.push(dependantId);
|
|
3662
|
+
};
|
|
3663
|
+
for (const id of frontier) {
|
|
3664
|
+
for (const edge of inbound.get(id) ?? []) {
|
|
3665
|
+
if (!rels.has(edge.rel)) continue;
|
|
3666
|
+
if (dependantEnd(edge.rel) !== "source") continue;
|
|
3667
|
+
consider(edge.from, { source: edge.from, target: id, rel: edge.rel });
|
|
3668
|
+
}
|
|
3669
|
+
for (const link2 of byId.get(id)?.frontmatter.strauss_links ?? []) {
|
|
3670
|
+
if (!rels.has(link2.rel)) continue;
|
|
3671
|
+
if (dependantEnd(link2.rel) !== "target") continue;
|
|
3672
|
+
if (link2.target === id) continue;
|
|
3673
|
+
consider(link2.target, {
|
|
3674
|
+
source: id,
|
|
3675
|
+
target: link2.target,
|
|
3676
|
+
rel: link2.rel
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
frontier = next;
|
|
3681
|
+
}
|
|
3682
|
+
return {
|
|
3683
|
+
root: targetId,
|
|
3684
|
+
impacted: [...reached.values()].sort(
|
|
3685
|
+
(left, right) => left.depth - right.depth || left.conceptId.localeCompare(right.conceptId)
|
|
3686
|
+
),
|
|
3687
|
+
stopped: stopped.sort(),
|
|
3688
|
+
truncated: frontier.length > 0,
|
|
3689
|
+
unexpanded: [...frontier].sort()
|
|
3690
|
+
};
|
|
3691
|
+
}
|
|
3692
|
+
function resolveRels(rels) {
|
|
3693
|
+
if (!rels?.length) return new Set(KB_CAUSAL_LINK_RELS);
|
|
3694
|
+
for (const rel of rels) {
|
|
3695
|
+
if (!isKbLinkRel(rel) || LINK_RELS[rel].dependant === null) {
|
|
3696
|
+
throw new KbUnknownLinkRelError(rel, KB_CAUSAL_LINK_RELS);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
return new Set(rels);
|
|
3700
|
+
}
|
|
3701
|
+
function dependantEnd(rel) {
|
|
3702
|
+
return isKbLinkRel(rel) ? LINK_RELS[rel].dependant : null;
|
|
3703
|
+
}
|
|
3704
|
+
function hasEdge(edges, edge) {
|
|
3705
|
+
return edges.some(
|
|
3706
|
+
(existing) => existing.source === edge.source && existing.target === edge.target && existing.rel === edge.rel
|
|
3707
|
+
);
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3370
3710
|
// src/kb-gitattributes.ts
|
|
3371
3711
|
var GITATTRIBUTES_FILE = ".gitattributes";
|
|
3372
3712
|
var UNION_MERGE_LINE = `${LOG_FILE} text eol=lf merge=union`;
|
|
@@ -3770,6 +4110,14 @@ ${answer}
|
|
|
3770
4110
|
async pack(bundlePath2, rootId, options = {}) {
|
|
3771
4111
|
return pack(await this.list(bundlePath2), rootId, options);
|
|
3772
4112
|
}
|
|
4113
|
+
/** What breaks if this record changes. See `kb-links/impact.ts`. */
|
|
4114
|
+
async impact(bundlePath2, targetId, options = {}) {
|
|
4115
|
+
return impact(targetId, await this.list(bundlePath2), options);
|
|
4116
|
+
}
|
|
4117
|
+
/** Who points at this record, one hop. See `kb-links/backlinks.ts`. */
|
|
4118
|
+
async backlinks(bundlePath2, targetId) {
|
|
4119
|
+
return backlinks(targetId, await this.list(bundlePath2));
|
|
4120
|
+
}
|
|
3773
4121
|
/**
|
|
3774
4122
|
* The stored index, rebuilt if it disagrees with the records.
|
|
3775
4123
|
*
|
|
@@ -4090,7 +4438,7 @@ function bundleDigest(records, superseded) {
|
|
|
4090
4438
|
}
|
|
4091
4439
|
|
|
4092
4440
|
// src/version.ts
|
|
4093
|
-
var VERSION = true ? "0.1.
|
|
4441
|
+
var VERSION = true ? "0.1.14" : "0.0.0-dev";
|
|
4094
4442
|
|
|
4095
4443
|
// src/cli.ts
|
|
4096
4444
|
async function runKbCli(argv) {
|