@saasontools/strauss-kb 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ARCHITECTURE.md CHANGED
@@ -72,6 +72,23 @@ replacement's first log format was `·`-delimited, with a splitter to read it
72
72
  back. Both are gone: the log is JSONL and the schema is emitted from Zod, so
73
73
  `strauss-kb schema` is the contract rather than a description of one.
74
74
 
75
+ ## Anchor resolution
76
+
77
+ A fresh stamp is a baseline nobody has checked, so only a run where every
78
+ checkable anchor already matched appends `verified[]`.
79
+
80
+ The v1 resolver is regex-based, biased so a wrong answer loses to no answer: a
81
+ span short of the code it claims hashes as stable while that code moves. It
82
+ ranks by shape, scopes a dotted symbol to its parent, captures by brace depth or
83
+ Python indentation, and returns `null` otherwise. A pure `AnchorResolver`
84
+ interface admits a tree-sitter replacement.
85
+
86
+ Repository identity is normalised and compared, not parsed: an invented format
87
+ would reject correct values from unseen hosts.
88
+
89
+ Not one anchored file found under a default root is a wrong root, so its
90
+ findings are dropped.
91
+
75
92
  ## Cross-worktree log safety
76
93
 
77
94
  `log.jsonl` is append-only and the one artifact nothing can rebuild, so how it
package/README.md CHANGED
@@ -150,15 +150,15 @@ human-verified event carries.
150
150
  Anything prefixed `strauss_` is this package's extension, namespaced so a later
151
151
  OKF version defining the same name cannot collide:
152
152
 
153
- | Key | Meaning |
154
- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
155
- | `strauss_status` | `draft`, `proposed`, `accepted`, `open`, `resolved`, `rejected`, `superseded`. Parses with a default of `draft`. |
156
- | `strauss_supersedes` / `strauss_superseded_by` | Both directions of a supersession, written together. |
157
- | `strauss_anchors` | `{ file, symbol? }` — where the record attaches in the code. Symbolic, because a line number written mid-change is wrong by the end of it. |
158
- | `strauss_assumption` | The claim has no source, said as a field rather than as a fake entry in `sources`. |
159
- | `strauss_answered` | Who resolved an open question, and when. |
160
- | `strauss_verify` | Checks that would confirm the record still holds. |
161
- | `strauss_materiality` / `strauss_confidence` / `strauss_owner` | `blocking`/`important`/`non-blocking`, `low`/`medium`/`high`, and a name. |
153
+ | Key | Meaning |
154
+ | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | `strauss_status` | `draft`, `proposed`, `accepted`, `open`, `resolved`, `rejected`, `superseded`. Parses with a default of `draft`. |
156
+ | `strauss_supersedes` / `strauss_superseded_by` | Both directions of a supersession, written together. |
157
+ | `strauss_anchors` | `{ file, symbol?, hash?, lines?, resolved_at? }` — where the record attaches in the code, and optionally what that code looked like when it did. See [Anchors and drift](#anchors-and-drift). |
158
+ | `strauss_assumption` | The claim has no source, said as a field rather than as a fake entry in `sources`. |
159
+ | `strauss_answered` | Who resolved an open question, and when. |
160
+ | `strauss_verify` | Checks that would confirm the record still holds. |
161
+ | `strauss_materiality` / `strauss_confidence` / `strauss_owner` | `blocking`/`important`/`non-blocking`, `low`/`medium`/`high`, and a name. |
162
162
 
163
163
  Edges are markdown links in the body, as OKF specifies — untyped, with the kind
164
164
  conveyed by the surrounding prose. Broken links are legal: records are routinely
@@ -244,6 +244,55 @@ decide (an idempotent `decision.none` record). It exists for workflow gates:
244
244
  "did you write a decision?" rewards writing a junk one, "did you answer?"
245
245
  does not — so silence has to be expressible.
246
246
 
247
+ ## Anchors and drift
248
+
249
+ An anchor names where a record attaches in the code: a `file`, optionally a
250
+ `symbol` — symbolic, because a line number written mid-change is wrong by the
251
+ end of it. Five optional fields extend it:
252
+
253
+ | Field | Meaning |
254
+ | ------------- | ---------------------------------------------------------------------------------------------------------------- |
255
+ | `hash` | `sha256:<hex>` over the anchored text, algorithm-prefixed. |
256
+ | `lines` | Line count the hash covered. |
257
+ | `resolved_at` | When the anchor last resolved. |
258
+ | `repo` | Which repository — remote URL or short name. Absent means this base's own repository. |
259
+ | `ref` | Git rev the evidence was taken at. Recorded but unused until [SAA-709](https://linear.app/saason/issue/SAA-709). |
260
+
261
+ `hash`, `lines`, and `resolved_at` are **measured** — a resolution pass stamps
262
+ them; `repo` and `ref` are **author-owned identity** and a resolution pass
263
+ never writes them.
264
+
265
+ `anchor-resolve <concept-id>` (`kb_anchor_resolve`) is `verify`'s mechanical
266
+ counterpart: it checks the anchored code against the working tree
267
+ (`--repo-root` when the base is not inside it). Per anchor:
268
+
269
+ - **stamped** — no hash yet; hash, line count, and timestamp are written.
270
+ - **match** — unchanged; nothing written. `--restamp` re-dates on purpose.
271
+ - **drifted** — hash changed. Baseline kept unless `--rebaseline`.
272
+ - **unresolved** — not comparable, with a reason. A finding, not an error.
273
+
274
+ An anchor naming another `repo` is skipped: never read, stamped, or counted.
275
+
276
+ An anchor must not read outside the repository it describes, checked lexically
277
+ and again on the real path after symlinks.
278
+
279
+ Exit code is non-zero on **drifted**, or on **unresolved** for an anchor that
280
+ carries a hash; unstamped and foreign anchors never fail.
281
+
282
+ A fully clean run — every checkable anchor `match`, none stamped this run —
283
+ appends a `verified[]` event.
284
+
285
+ Symbol resolution is a v1 heuristic; ties and unclosed blocks return
286
+ `unresolved`.
287
+
288
+ Drift also surfaces on read: `kb_load` and `kb_query` attach a
289
+ `{ kind: "drifted" }` warning, and `kb_doctor` lists every drifted anchor
290
+ base-wide — all three take `--repo-root`. With no `--repo-root` given, a run
291
+ that finds not one anchored file drops the finding as a wrong root; an explicit
292
+ `--repo-root` is taken at its word.
293
+
294
+ Details: [specification](https://saasontools.github.io/strauss-agent-tools/specification).
295
+
247
296
  ## CLI
248
297
 
249
298
  ```
@@ -256,17 +305,21 @@ strauss-kb [--bundle PATH] <command> [args]
256
305
  supersede <concept-id> <replacement-id> Mark a record superseded, linking both directions.
257
306
  answer <concept-id> <answer...> Resolve an open question and append the answer.
258
307
  verify <concept-id> --note <text> Append a verified[] event — who checked, when, and what the check found.
259
- load [type] [--budget N | --all] Hand over the whole base, each record with its standing.
308
+ anchor-resolve <concept-id> [--repo-root <path>] [--rebaseline] [--restamp]
309
+ Resolve anchors against the working tree: stamp, or report drift.
310
+ load [type] [--budget N | --all] [--repo-root PATH]
311
+ Hand over the whole base, each record with its standing.
312
+ catalog [type] Every record in one line — id, type, title, standing, stale flag.
260
313
  pack <conceptId> [--hops N] [--max-nodes N] [--budget N]
261
314
  The bounded neighbourhood around one record, every cut named.
262
- query <text...> Search; every match arrives flagged with its standing.
315
+ query <text...> [--repo-root PATH] Search; every match arrives flagged with its standing.
263
316
  trace <concept-id> [edges...] How a position was arrived at, as a timeline.
264
317
  list [type] Every record, optionally narrowed to one type.
265
318
  index The index, rebuilt if it disagrees with the records.
266
319
  log What touched what, and when.
267
320
  validate Cross-record checks. Exits 1 when it reports a problem.
268
- doctor [--expiring-days N] [--unverified-days N] [--aging-days N] [--strict]
269
- Health sweep: what expired, went unconfirmed, aged, or was orphaned.
321
+ doctor [--expiring-days N] [--unverified-days N] [--aging-days N] [--repo-root PATH] [--strict]
322
+ Health sweep: what expired, went unconfirmed, aged, was orphaned, or drifted.
270
323
  schema JSON Schema for the format.
271
324
  types The twelve types, their sections and initial status.
272
325
  pin [bundle-path] [flags] Pin a base. --mode, --profiles, --frozen; --local/--user pick the layer.
@@ -281,15 +334,19 @@ strauss-kb [--bundle PATH] <command> [args]
281
334
  STRAUSS_KB_ACTOR names the writer in the log
282
335
  ```
283
336
 
284
- Results go to stdout as JSON — `index` and `pack` are markdown, which is what
337
+ Results go to stdout as JSON — `index`, `catalog` and `pack` are markdown, which is what
285
338
  they are, and `doctor` prints a table unless `--json` asks for the object
286
339
  behind it. `--json` is refused rather than ignored on the commands that have
287
340
  only one form, since a flag that quietly does nothing reads as one that
288
341
  worked; `--` ends flag parsing, for the verbs that end in free prose. Errors
289
- go to stderr and exit 1. `validate` and `doctor --strict` are the commands
290
- whose exit code is not just "did it run": a check that reports a problem
291
- succeeded as a command and failed as a check, so it exits 1 with its findings
292
- on stdout.
342
+ go to stderr and exit 1. `validate`, `anchor-resolve`, and `doctor --strict`
343
+ are the commands whose exit code is not just "did it run": a check that
344
+ reports a problem succeeded as a command and failed as a check, so each exits
345
+ 1 with its findings on stdout.
346
+
347
+ A flag accepts either spelling — `--budget 4000` or `--budget=4000` — and a
348
+ flag given no value is an error rather than a silent fallback to the default,
349
+ so a trailing typo cannot look like success.
293
350
 
294
351
  ```bash
295
352
  strauss-kb --bundle .strauss/kb write fact <<'JSON'
@@ -310,9 +367,9 @@ strauss-kb validate || echo "problems above"
310
367
 
311
368
  `strauss-kb-mcp` speaks stdio and takes no API key and no required environment.
312
369
  Every CLI verb is a tool: `kb_write`, `kb_write_decision`, `kb_no_decision`,
313
- `kb_status`, `kb_supersede`, `kb_answer`, `kb_verify`, `kb_load`, `kb_pack`, `kb_query`,
314
- `kb_trace`, `kb_list`, `kb_index`, `kb_log`, `kb_validate`, `kb_doctor`,
315
- `kb_schema`, `kb_types`,
370
+ `kb_status`, `kb_supersede`, `kb_answer`, `kb_verify`, `kb_anchor_resolve`,
371
+ `kb_load`, `kb_catalog`, `kb_pack`, `kb_query`, `kb_trace`, `kb_list`,
372
+ `kb_index`, `kb_log`, `kb_validate`, `kb_doctor`, `kb_schema`, `kb_types`,
316
373
  `kb_pin`, `kb_unpin`, `kb_pins`, `kb_context`. Most tools take a `bundlePath`;
317
374
  `kb_schema` and `kb_types` describe the format rather than any one base, and
318
375
  `kb_pins` and `kb_context` read the workspace pin manifests instead. The one
@@ -350,7 +407,7 @@ const hits = await store.query(".strauss/kb", "cache key");
350
407
  for (const hit of hits) {
351
408
  hit.standing; // current | superseded | rejected | unsettled | open
352
409
  hit.heads; // where the supersession chain ends
353
- hit.warnings; // rejected, broken-chain, forked-chain, stale, unverified…
410
+ hit.warnings; // rejected, broken-chain, forked-chain, stale, unverified, drifted
354
411
  }
355
412
  ```
356
413
 
@@ -396,40 +453,66 @@ Read for a question, not for a session: a base loaded at the start of a long
396
453
  conversation is summarised away by the end of it, and reloading costs about
397
454
  three thousand tokens. Read it again at the point of use.
398
455
 
399
- `load` refuses rather than truncating when a base exceeds its budget (25,000
400
- tokens by default). A truncated base is indistinguishable from a complete one,
401
- so a caller would answer "that was never decided" from a slice it did not know
402
- was a slice. `context` refuses the same way at its own, tighter budget (4,000
403
- by default). Superseded records come back as name, replacement and date only —
404
- their bodies no longer hold, and a body read later in a long session outlives
405
- the qualifier that said so. `trace` still reaches them by id.
406
-
407
- `--all` (`all: true` over MCP) is the escape hatch: it bypasses the refusal
408
- outright and hands back the entire bundle whatever its size. A loaded result
409
- carries `tokensLoaded`, the same estimate the budget is held against, and
410
- `budgetTokens: null` marks that no ceiling was applied; `--all` is mutually
411
- exclusive with `--budget`. That refusal is the guardrail an agent needs so a
412
- wide base does not silently consume its whole context; `--all` is for a
413
- deliberate operator who has decided the size is worth the tokens, not a
414
- setting to reach for by default. A reader that does not actually need every
415
- record is better served by a narrower `type` filter or a `query` than by
416
- turning the guardrail off.
417
-
418
- **Pack is the middle rung.** Under budget, load the base whole perfect
419
- recall beats any ranking. Over budget, when the work centres on a record you
420
- can name, `pack` hands over that record's bounded neighbourhood instead:
421
- everything within `--hops` of the root, walked over the base's edges — body
422
- links (a `relatedConceptIds` entry is stored as one), supersession in both
423
- directions, shared code anchors, and shared sources ranked and cut to
424
- `--max-nodes`. Standing travels with it: superseded neighbours arrive as the
425
- same name, replacement and date stubs `load` emits. Every record the cut
426
- dropped is named under Excluded, because a named gap is knowable and a silent
427
- one is not, and past its own token budget `pack` refuses exactly as `load`
428
- does naming what was already cut, so the caller can narrow the walk or
429
- raise the ceiling. Below the header, the only place a timestamp appears, the
430
- output is byte-identical across runs over an unchanged base: two packs diff,
431
- and a changed byte means changed knowledge. With neither a budget problem nor
432
- a root record in hand, the question is a point lookup, and that is `query`.
456
+ **The three rungs, in one rule.** While the base fits the budget, `load` it
457
+ whole. Once `load` refuses, `catalog` then `pack` the record that matters. For
458
+ a lookup by wording, `query`.
459
+
460
+ ```bash
461
+ strauss-kb load # under the budget: everything, with standing
462
+ strauss-kb catalog # past it: one line per record, ~30 tokens each
463
+ strauss-kb pack decision.cursor-v2 # then the neighbourhood around the one that matters
464
+ strauss-kb query cursor pagination # or a point lookup by wording
465
+ ```
466
+
467
+ A whole read gives perfect recall and can say _no record answers this_, which
468
+ no ranker can. `catalog` keeps that at a fraction of the cost by naming every
469
+ record instead of every body; `query` gives up both, returning its nearest hit
470
+ whatever the distance.
471
+
472
+ `load` refuses rather than truncating past its token budget (`--budget` /
473
+ `budgetTokens`, 25,000 by default, held against the estimated size of what is
474
+ handed back) — a truncated base reads as a complete one, so a caller would
475
+ answer "never decided" from a slice it did not know was a slice. `context`
476
+ refuses the same way at its own, tighter budget (4,000 by default). Superseded
477
+ records come back as name, replacement and date only; `trace` still reaches
478
+ them by id.
479
+
480
+ A refusal reports `approxTokens` against `budgetTokens` and carries a `message`
481
+ naming the budget and the next calls. A successful load reports `budgetTokens`
482
+ too, so a caller can see how close it came before crossing the line.
483
+
484
+ `--all` (`all: true` over MCP) bypasses the budget and hands back the entire
485
+ bundle regardless of size. A loaded result carries `tokensLoaded`, and
486
+ `budgetTokens: null` marks that no ceiling applied; `--all` is mutually
487
+ exclusive with `--budget`. It is for an operator who has decided the size is
488
+ worth the tokens a narrower `type` filter, `catalog`, or `query` fits better
489
+ when it is not.
490
+
491
+ **Catalog is the rung that keeps the base knowable.** One line per record —
492
+ concept id, type, title, standing, stale flag — sorted by type then title, at
493
+ roughly thirty tokens each, so a base far past `load`'s budget still fits in
494
+ one call. Superseded records show the replacement in place of a body. The
495
+ header sums record counts by standing and reports staleness separately (a
496
+ current record can be stale). Bodies live in `load`, `pack`, and `trace`.
497
+
498
+ `catalog` alone has no ceiling and never refuses — cost is linear at roughly
499
+ thirty tokens a record (a thousand-record base is about 30k, five thousand
500
+ about 150k); narrow with `type` at that scale. Output is deterministic given
501
+ a fixed clock — no timestamp, ordering total down to the concept id — so two
502
+ catalogs of an unchanged base diff to nothing except a stale flag flipping as
503
+ `stale_after` passes. Pass an explicit `now` (library callers) to hold
504
+ byte-equality across that boundary.
505
+
506
+ **Pack is the middle rung.** Under the budget, load the base whole. Past it, when the work centres on a record you can name (`catalog` is how you
507
+ name it), `pack` hands over that record's bounded neighbourhood: everything
508
+ within `--hops` of the root, walked over the base's edges — body links (a
509
+ `relatedConceptIds` entry is one), supersession in both directions, shared
510
+ code anchors, and shared sources — ranked and cut to `--max-nodes`. Standing
511
+ travels with it: superseded neighbours arrive as the same stubs `load` emits.
512
+ Every dropped record is named under Excluded, and past its own token budget
513
+ `pack` refuses exactly as `load` does. Output is byte-identical across runs
514
+ over an unchanged base below the header. With neither a size problem nor a
515
+ root record in hand, the question is a point lookup — `query`.
433
516
 
434
517
  **Flag, never filter.** `query` returns every hit with its standing, because a
435
518
  filtered result set is invisible — the caller cannot tell it missed anything.
@@ -473,20 +556,25 @@ it asks only whether pointers between records agree.
473
556
  | `orphaned` | No other record links to it, by body link or supersession. |
474
557
  | `broken-supersession` | A chain that does not resolve: no replacement, a missing one, a cycle, a fork. |
475
558
  | `superseded-but-cited` | A record that still holds, whose body links to one that does not. |
559
+ | `drifted` | A hash-carrying anchor whose code moved, or whose file or symbol is gone. |
560
+
561
+ Pass `doctor --repo-root PATH` when the base does not sit inside the tree it
562
+ describes; without it the sweep looks under the working directory.
476
563
 
477
- The last check's name is for its common case: a rejected target counts too, and
478
- is the worse half — a superseded record at least names its replacement, while a
479
- rejected one is a well-formed assertion of what someone decided _not_ to do,
480
- cited by a record the reader trusts.
564
+ `superseded-but-cited`'s name is for its common case: a rejected target counts
565
+ too, and is the worse half — a superseded record at least names its
566
+ replacement, while a rejected one is a well-formed assertion of what someone
567
+ decided _not_ to do, cited by a record the reader trusts.
481
568
 
482
569
  ```bash
483
570
  strauss-kb doctor # the table
484
571
  strauss-kb doctor --json # the object behind it
485
572
  strauss-kb doctor --strict # exit 1 if anything has expired
486
573
  strauss-kb doctor --unverified-days 30 # a stricter confirmation window
574
+ strauss-kb doctor --repo-root ../app # where the anchored source lives
487
575
  ```
488
576
 
489
- All seven groups are reported even when empty. A check that found nothing and
577
+ All eight groups are reported even when empty. A check that found nothing and
490
578
  a check that never ran look identical in a report that only lists findings,
491
579
  which is the whole value of a sweep.
492
580
 
@@ -522,8 +610,13 @@ Judgments the checks make, worth knowing before reading a report:
522
610
  record left `accepted` while naming a replacement was hand-edited — and
523
611
  adjudication reads it as current no matter what the pointer says, which is
524
612
  what makes it worth naming.
613
+ - **`drifted` reports and never repairs.** It reads the same comparison
614
+ `kb_load` and `kb_query` do, so the sweep and the read paths cannot disagree
615
+ about what drift is. Unresolvable anchors ride in this group rather than a
616
+ ninth check, anchors carrying no hash are never read, and `--strict` does not
617
+ gate on drift.
525
618
 
526
- `--strict` gates on expiry alone. The other six report debt a reader decides
619
+ `--strict` gates on expiry alone. The other seven report debt a reader decides
527
620
  about; an expired record is the base itself saying it would stop standing
528
621
  behind something, which is the one finding a pipeline can act on without a
529
622
  judgment call.
@@ -2,7 +2,7 @@ import {
2
2
  KB_COMMANDS,
3
3
  KbStore,
4
4
  VERSION
5
- } from "./chunk-OFDWRMY6.js";
5
+ } from "./chunk-OVRQCQ6P.js";
6
6
 
7
7
  // src/mcp.ts
8
8
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -46,4 +46,4 @@ export {
46
46
  createKbMcpServer,
47
47
  runKbMcpServer
48
48
  };
49
- //# sourceMappingURL=chunk-MWWDD23L.js.map
49
+ //# sourceMappingURL=chunk-CWWXMD35.js.map
@@ -4,7 +4,7 @@ import {
4
4
  KB_DIR,
5
5
  KbStore,
6
6
  VERSION
7
- } from "./chunk-OFDWRMY6.js";
7
+ } from "./chunk-OVRQCQ6P.js";
8
8
 
9
9
  // src/cli.ts
10
10
  import { join } from "path";
@@ -112,4 +112,4 @@ function usage() {
112
112
  export {
113
113
  runKbCli
114
114
  };
115
- //# sourceMappingURL=chunk-KVEEISYQ.js.map
115
+ //# sourceMappingURL=chunk-I3WW4F6X.js.map