@hraness/kb 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/DISCLOSURE +43 -0
  2. package/LICENSE +21 -0
  3. package/README.md +545 -0
  4. package/dist/agent-context.js +35 -0
  5. package/dist/agent-guide-audit.js +18 -0
  6. package/dist/attachments.js +19 -0
  7. package/dist/authoring.js +33 -0
  8. package/dist/benchmark.js +19 -0
  9. package/dist/capture.js +49 -0
  10. package/dist/cli.js +3646 -0
  11. package/dist/clip/acquire.js +57 -0
  12. package/dist/clip/args.js +21 -0
  13. package/dist/clip/bounded-byte-buffer.js +9 -0
  14. package/dist/clip/browser-profiles.js +17 -0
  15. package/dist/clip/bundle-reader.js +11 -0
  16. package/dist/clip/cli.js +27 -0
  17. package/dist/clip/cookies.js +21 -0
  18. package/dist/clip/defuddle-worker.js +84 -0
  19. package/dist/clip/doctor.js +32 -0
  20. package/dist/clip/jobs.js +784 -0
  21. package/dist/clip/network-proxy.js +9 -0
  22. package/dist/clip/network.js +28 -0
  23. package/dist/clip/persist.js +30 -0
  24. package/dist/clip/refresh.js +11 -0
  25. package/dist/clip/terminal.js +11 -0
  26. package/dist/evaluation-builder.js +12238 -0
  27. package/dist/evaluation-kb.js +26 -0
  28. package/dist/evaluation.js +35 -0
  29. package/dist/git.js +39 -0
  30. package/dist/graph.js +39 -0
  31. package/dist/index-01jj6rbv.js +1103 -0
  32. package/dist/index-06c9ctr6.js +738 -0
  33. package/dist/index-0kavxzqj.js +2480 -0
  34. package/dist/index-1gwbassd.js +743 -0
  35. package/dist/index-1n418kb9.js +827 -0
  36. package/dist/index-1vrd1rmn.js +56 -0
  37. package/dist/index-1xxnjn0d.js +171 -0
  38. package/dist/index-3rm7cz6h.js +373 -0
  39. package/dist/index-3v2z4f0q.js +328 -0
  40. package/dist/index-48pz4jpc.js +392 -0
  41. package/dist/index-4j3tt0c3.js +234 -0
  42. package/dist/index-5n05se68.js +307 -0
  43. package/dist/index-5vwpzb5a.js +764 -0
  44. package/dist/index-6g2pv9d2.js +370 -0
  45. package/dist/index-7fzc32gf.js +712 -0
  46. package/dist/index-84x0vjjp.js +432 -0
  47. package/dist/index-adx6khj5.js +488 -0
  48. package/dist/index-b88v3vtm.js +805 -0
  49. package/dist/index-cv6fh7z5.js +462 -0
  50. package/dist/index-cxfrakt7.js +1067 -0
  51. package/dist/index-d13v9ckt.js +150 -0
  52. package/dist/index-dycjbhw2.js +1943 -0
  53. package/dist/index-dyqwejk5.js +531 -0
  54. package/dist/index-e5fbsywq.js +658 -0
  55. package/dist/index-f984hw45.js +927 -0
  56. package/dist/index-gh719d91.js +63 -0
  57. package/dist/index-hgve9rh2.js +2046 -0
  58. package/dist/index-hya40gb2.js +474 -0
  59. package/dist/index-j4zgmzjr.js +152 -0
  60. package/dist/index-jsmvyyvf.js +1166 -0
  61. package/dist/index-kh0pwvdd.js +1974 -0
  62. package/dist/index-mqx4nd6v.js +119 -0
  63. package/dist/index-mxxxytys.js +1254 -0
  64. package/dist/index-n5dd7r0v.js +711 -0
  65. package/dist/index-npg9z1a4.js +431 -0
  66. package/dist/index-pj501bh1.js +140 -0
  67. package/dist/index-qry4vhxk.js +1041 -0
  68. package/dist/index-s2gw5aw9.js +199 -0
  69. package/dist/index-vvdj6kca.js +70 -0
  70. package/dist/index-w2zc0vwa.js +571 -0
  71. package/dist/index-x3fthpsc.js +585 -0
  72. package/dist/index-zr53sf63.js +44 -0
  73. package/dist/index-zxdy5pby.js +2728 -0
  74. package/dist/index-zzhgcwyt.js +966 -0
  75. package/dist/index.js +453 -0
  76. package/dist/navigation.js +13 -0
  77. package/dist/pdf.js +85 -0
  78. package/dist/percolate.js +24 -0
  79. package/dist/portfolio.js +77 -0
  80. package/dist/query.js +29 -0
  81. package/dist/repository-memory.js +60 -0
  82. package/dist/sdk.js +36 -0
  83. package/dist/search-rules.js +34 -0
  84. package/dist/search.js +22 -0
  85. package/dist/semantic.js +39 -0
  86. package/dist/source-inbox.js +17 -0
  87. package/dist/untrusted-content.js +32 -0
  88. package/dist/url-intelligence.js +74 -0
  89. package/dist/workflow.js +23 -0
  90. package/dist/workflows/decision-context.js +20 -0
  91. package/dist/workflows/explain-change.js +8 -0
  92. package/dist/workflows/index.js +28 -0
  93. package/dist/workflows/plan-radar.js +10 -0
  94. package/package.json +409 -0
  95. package/skills/kb/AGENTS.md +19 -0
  96. package/skills/kb/SKILL.md +82 -0
  97. package/skills/kb/agents/openai.yaml +4 -0
  98. package/skills/kb/references/pdf-review.md +51 -0
  99. package/skills/kb/references/percolate.md +144 -0
  100. package/skills/kb/references/plan-structure.md +105 -0
  101. package/skills/kb/references/plan.md +115 -0
  102. package/skills/kb/references/query.md +231 -0
  103. package/skills/kb/references/refresh.md +133 -0
  104. package/skills/kb/references/save-pdf.md +125 -0
  105. package/skills/kb/references/save-url.md +178 -0
  106. package/skills/kb/references/url-authentication.md +75 -0
  107. package/skills/kb/references/url-platforms.md +25 -0
  108. package/src/agent-context.ts +1241 -0
  109. package/src/agent-guide-audit.ts +750 -0
  110. package/src/attachments.ts +723 -0
  111. package/src/authoring.ts +1725 -0
  112. package/src/benchmark.ts +362 -0
  113. package/src/capture.ts +68 -0
  114. package/src/cli.ts +3660 -0
  115. package/src/clip/acquire.ts +1273 -0
  116. package/src/clip/archive-today.ts +402 -0
  117. package/src/clip/args.ts +423 -0
  118. package/src/clip/assets.ts +262 -0
  119. package/src/clip/bounded-byte-buffer.ts +75 -0
  120. package/src/clip/browser-profiles.ts +372 -0
  121. package/src/clip/bundle-reader.ts +608 -0
  122. package/src/clip/capture.ts +1054 -0
  123. package/src/clip/cli.ts +181 -0
  124. package/src/clip/cookies.ts +512 -0
  125. package/src/clip/doctor.ts +1110 -0
  126. package/src/clip/extract.ts +868 -0
  127. package/src/clip/jobs.ts +959 -0
  128. package/src/clip/lib.ts +861 -0
  129. package/src/clip/media.ts +1474 -0
  130. package/src/clip/metadata-search-tool/Cargo.lock +2498 -0
  131. package/src/clip/metadata-search-tool/Cargo.toml +18 -0
  132. package/src/clip/metadata-search-tool/runner.ts +685 -0
  133. package/src/clip/metadata-search-tool/src/main.rs +389 -0
  134. package/src/clip/metadata-search.ts +687 -0
  135. package/src/clip/network-proxy.ts +627 -0
  136. package/src/clip/network.ts +950 -0
  137. package/src/clip/package-root.ts +54 -0
  138. package/src/clip/persist.ts +1472 -0
  139. package/src/clip/platforms.ts +1824 -0
  140. package/src/clip/refresh.ts +197 -0
  141. package/src/clip/structured.ts +432 -0
  142. package/src/clip/terminal.ts +197 -0
  143. package/src/clip/url-intelligence.ts +581 -0
  144. package/src/clip/url-metadata-backfill.ts +616 -0
  145. package/src/clip/url-metadata-cli.ts +251 -0
  146. package/src/clip/url-metadata.ts +1397 -0
  147. package/src/evaluation-analysis-v2.ts +1440 -0
  148. package/src/evaluation-builder.ts +2539 -0
  149. package/src/evaluation-corpus-authoring.ts +2052 -0
  150. package/src/evaluation-evidence.ts +1147 -0
  151. package/src/evaluation-execution-v2.ts +426 -0
  152. package/src/evaluation-implementation.ts +131 -0
  153. package/src/evaluation-kb-closure.ts +1430 -0
  154. package/src/evaluation-kb-runner-v2.ts +735 -0
  155. package/src/evaluation-kb-v2.ts +2567 -0
  156. package/src/evaluation-kb.ts +1018 -0
  157. package/src/evaluation-measurement-v2.ts +1462 -0
  158. package/src/evaluation-packing-v2.ts +452 -0
  159. package/src/evaluation-redaction.ts +28 -0
  160. package/src/evaluation-v2.ts +3857 -0
  161. package/src/evaluation.ts +1220 -0
  162. package/src/git.ts +1276 -0
  163. package/src/graph.ts +1487 -0
  164. package/src/index.ts +20 -0
  165. package/src/init.ts +123 -0
  166. package/src/navigation.ts +277 -0
  167. package/src/note-lock.ts +529 -0
  168. package/src/pdf/args.ts +202 -0
  169. package/src/pdf/capture.ts +298 -0
  170. package/src/pdf/cli.ts +159 -0
  171. package/src/pdf/extract.ts +303 -0
  172. package/src/pdf/layout.ts +618 -0
  173. package/src/pdf/markdown.ts +154 -0
  174. package/src/pdf/model.ts +234 -0
  175. package/src/pdf/ocr.ts +190 -0
  176. package/src/pdf/persist.ts +314 -0
  177. package/src/pdf/source.ts +135 -0
  178. package/src/pdf/tools.ts +146 -0
  179. package/src/pdf.ts +92 -0
  180. package/src/percolate.ts +877 -0
  181. package/src/portfolio-audit.ts +574 -0
  182. package/src/portfolio-identity.ts +162 -0
  183. package/src/portfolio-registry.ts +473 -0
  184. package/src/portfolio.ts +765 -0
  185. package/src/query.ts +646 -0
  186. package/src/repository-memory.ts +1150 -0
  187. package/src/sdk.ts +1452 -0
  188. package/src/search-rules.ts +712 -0
  189. package/src/search.ts +710 -0
  190. package/src/semantic-runtime.ts +1139 -0
  191. package/src/semantic.ts +2480 -0
  192. package/src/source-inbox.ts +232 -0
  193. package/src/untrusted-content.ts +401 -0
  194. package/src/url-intelligence.ts +104 -0
  195. package/src/vault.ts +636 -0
  196. package/src/workflow.ts +653 -0
  197. package/src/workflows/decision-context.ts +81 -0
  198. package/src/workflows/explain-change.ts +73 -0
  199. package/src/workflows/index.ts +3 -0
  200. package/src/workflows/plan-radar.ts +101 -0
@@ -0,0 +1,144 @@
1
+ # Percolate concepts and relationships
2
+
3
+ Keep the graph authored, local, and reviewable. `kb percolate` proposes
4
+ candidates from deterministic evidence; it never changes a note. Backlinks,
5
+ graph reports, and QMD results are derived views, while Markdown remains the
6
+ authority.
7
+
8
+ ## Locate the vault
9
+
10
+ - Resolve `<vault>` to the directory containing its authored or managed
11
+ `index.md` front door.
12
+ - Read the applicable repository and vault instructions before editing.
13
+ - Pass the resolved path to every `--root`.
14
+ - Identify the note or small neighborhood changed by the current task. Prefer a
15
+ bounded review to a vault-wide cleanup during parallel work.
16
+
17
+ ## Inspect candidates
18
+
19
+ Run percolation on the changed note when possible:
20
+
21
+ ```sh
22
+ kb percolate notes/example --root "$KB_ROOT" --limit 25 --json
23
+ ```
24
+
25
+ Run it without a note only when reviewing the whole vault:
26
+
27
+ ```sh
28
+ kb percolate --root "$KB_ROOT" --min-support 2 --limit 50 --json
29
+ ```
30
+
31
+ Treat each result as a prompt to open the cited notes and read the relevant
32
+ prose. Candidate kinds may include:
33
+
34
+ - a recurring tag with no maintained `type: concept` note;
35
+ - notes that share a concept or tag but have no explicit relationship;
36
+ - an exact title or alias mentioned without a contextual link;
37
+ - a self, reciprocal, malformed, broken, or ambiguous authored relationship.
38
+
39
+ For missing relationships, `support` counts independent shared tags or concept
40
+ neighbors; the evidence array shows the participating notes. The default
41
+ minimum of two therefore requires two shared signals, not merely both endpoints
42
+ of one tag match. Other candidate kinds count their natural unit: supporting
43
+ notes, mention occurrences, or authored hygiene evidence.
44
+
45
+ For a missing concept, use `suggestedId`. When `collidesWith` is non-null, the
46
+ natural ID is already an ordinary note, so KB chooses an unoccupied
47
+ `*-concept` ID. Read the occupied note before deciding whether to create the
48
+ suggested concept or promote and improve the existing note instead.
49
+
50
+ Semantic search may help discover evidence, but similarity is never enough to
51
+ author an edge.
52
+
53
+ ## Promote durable concepts
54
+
55
+ Create a concept only when the idea is likely to be reused and its definition
56
+ can be stated from the source material:
57
+
58
+ ```sh
59
+ kb note create notes/local-first \
60
+ --root "$KB_ROOT" \
61
+ --title "Local-first" \
62
+ --type concept \
63
+ --tag architecture \
64
+ --body '# Local-first
65
+
66
+ A concise reviewed definition grounded in the cited notes.'
67
+ ```
68
+
69
+ Write a concise definition and cite or link the notes that establish it.
70
+ Concepts are ordinary Markdown notes, so they can carry aliases, evidence,
71
+ context, and their own outbound relationships. Do not create a concept merely
72
+ to mirror every tag.
73
+
74
+ After promotion, rerun percolation on the cited non-concept notes. The new
75
+ concept may support relationships among its neighbors even when a run scoped to
76
+ the concept itself has no candidate:
77
+
78
+ ```sh
79
+ kb percolate notes/write-path --root "$KB_ROOT" --limit 25 --json
80
+ ```
81
+
82
+ ## Author typed relationships
83
+
84
+ Add a relationship from the note that owns the assertion:
85
+
86
+ ```sh
87
+ kb relation add notes/write-path supports notes/durable-agent-memory \
88
+ --root "$KB_ROOT"
89
+ ```
90
+
91
+ Use a specific lower-kebab-case predicate. A local target is an exact
92
+ vault-root note ID without `.md`. A reviewed cross-vault target is its stable
93
+ qualified identity, such as `kb://hraness/kb/document-id`; never use a checkout
94
+ path as cross-vault identity. Ground the assertion in nearby prose or evidence;
95
+ the frontmatter is an indexable statement, not a substitute for explanation.
96
+
97
+ List or remove relationships without editing reciprocal notes:
98
+
99
+ ```sh
100
+ kb relation list notes/write-path --root "$KB_ROOT" --json
101
+ kb relation remove notes/write-path supports notes/durable-agent-memory \
102
+ --root "$KB_ROOT"
103
+ ```
104
+
105
+ Never write inverse edges, generated backlinks, inferred transitive
106
+ relationships, or semantic-search scores into Markdown. Those are derived
107
+ views.
108
+
109
+ ## Query before concluding
110
+
111
+ Use exact structure to verify that the promoted graph says what the prose says:
112
+
113
+ ```sh
114
+ kb links notes/write-path --root "$KB_ROOT" --direction both --depth 2 --json
115
+ kb relation list notes/write-path --root "$KB_ROOT" --json
116
+ kb graph --root "$KB_ROOT" --json
117
+ ```
118
+
119
+ Prefer the note-scoped commands first. Use the whole-vault graph only when the
120
+ question spans several neighborhoods, and confirm returned IDs against their
121
+ Markdown notes before reporting a conclusion.
122
+
123
+ ## Finish under the vault's catalog mode
124
+
125
+ When working alone or integrating several lanes:
126
+
127
+ ```sh
128
+ kb refresh --root "$KB_ROOT"
129
+ kb check --root "$KB_ROOT"
130
+ ```
131
+
132
+ When several agents are editing different notes in a managed-catalog vault,
133
+ each lane should validate authored structure and local attachments without
134
+ rewriting the shared catalog:
135
+
136
+ ```sh
137
+ kb check --root "$KB_ROOT" --no-catalog
138
+ ```
139
+
140
+ The integrating agent runs one final managed refresh and normal check. In an
141
+ authored-catalog vault, refresh and check leave the front door untouched, while
142
+ `kb catalog --root "$KB_ROOT"` renders an exhaustive disposable inventory.
143
+ Resolve same-note Git conflicts from the prose and evidence; do not accept one
144
+ side's frontmatter mechanically.
@@ -0,0 +1,105 @@
1
+ # Durable KB plan structure
2
+
3
+ Use the smallest version that still makes execution and verification
4
+ unambiguous. Omit empty optional sections; do not pad a small change into a
5
+ program document.
6
+
7
+ ## Frontmatter
8
+
9
+ ```yaml
10
+ ---
11
+ title: Descriptive outcome
12
+ description: One sentence naming the change and dominant result.
13
+ type: plan
14
+ area: product-or-system
15
+ status: proposed
16
+ repository_scopes:
17
+ - packages/example
18
+ aliases:
19
+ - Short plan name
20
+ tags:
21
+ - migration
22
+ ---
23
+ ```
24
+
25
+ `type`, `area`, `status`, and a non-empty description are the stable plan query
26
+ surface. Use a kebab-case `area`. Add `repository_scopes` when the plan owns
27
+ repository work; each entry is one exact canonical repository-relative file or
28
+ directory path, without globs. Omit the field for plans with no code-path
29
+ ownership. Tags are optional facets, not a replacement for prose or links.
30
+
31
+ ## Core sections
32
+
33
+ ```md
34
+ # Descriptive outcome
35
+
36
+ ## Outcome
37
+
38
+ What will be true when this plan succeeds. Prefer observable behavior over a
39
+ list of files to edit.
40
+
41
+ ## Context
42
+
43
+ The present state, evidence, and reason the change is needed. Link the notes,
44
+ captures, code, or prior plans that carry necessary context.
45
+
46
+ ## Scope
47
+
48
+ ### In scope
49
+
50
+ - Work required for the outcome.
51
+
52
+ ### Non-goals
53
+
54
+ - Adjacent work deliberately excluded.
55
+
56
+ ## Constraints and decisions
57
+
58
+ - Constraints that shape the implementation.
59
+ - Decisions already made and why.
60
+ - Open questions whose answers can change the plan.
61
+
62
+ ## Plan
63
+
64
+ 1. A dependency-ordered phase with its concrete output.
65
+ 2. The next phase and its gate from the prior phase.
66
+
67
+ ## Verification
68
+
69
+ - Behavior or invariant → exact check, test, observation, or evidence.
70
+
71
+ ## Risks and recovery
72
+
73
+ - Failure mode → prevention, detection, and rollback or recovery.
74
+ ```
75
+
76
+ ## Sections that grow with the work
77
+
78
+ Add these when execution starts:
79
+
80
+ ```md
81
+ ## Execution evidence
82
+
83
+ - YYYY-MM-DD — Result, command or artifact, and what it proved.
84
+
85
+ ## Review findings
86
+
87
+ - Finding, disposition, and resulting plan or implementation change.
88
+
89
+ ## Result
90
+
91
+ What shipped or why work stopped, what was verified, and what intentionally
92
+ remains.
93
+
94
+ ## Durable memory
95
+
96
+ Link each reusable conclusion to the maintained note, guide, documentation, or
97
+ checked code contract that now owns it. If no conclusion warrants promotion,
98
+ state that no durable promotion was needed and explain why.
99
+ ```
100
+
101
+ Keep evidence compact but reproducible. A test name, checked invariant, or link
102
+ to an artifact is stronger than “validation passed.” Preserve superseded
103
+ decisions when they explain the final shape; mark their disposition instead of
104
+ silently deleting them. Require both Result and Durable memory when the status
105
+ becomes `completed`, `superseded`, or `cancelled`.
@@ -0,0 +1,115 @@
1
+ # Write a durable plan
2
+
3
+ Keep the plan useful before, during, and after execution. It is the coordination
4
+ record, not a disposable answer or a duplicate task tracker.
5
+
6
+ ## Find the plan's owner
7
+
8
+ 1. Resolve `<vault>` to the directory containing its authored or managed
9
+ `index.md` front door, then
10
+ set the shell-local `KB_ROOT` to that path (`KB_ROOT=kb` from a typical
11
+ repository root, or `KB_ROOT=.` from inside the vault). Read the vault's
12
+ `AGENTS.md` and the nearest guide under `<vault>/plans/`. Pass that resolved
13
+ root to every command; do not assume the starting directory is the vault.
14
+ 2. When the plan owns a repository path, resolve the repository root as
15
+ `KB_REPO` and load that path's current memory before a whole-vault search:
16
+
17
+ ```sh
18
+ kb context "<repository-path>" --root "$KB_ROOT" --repo "$KB_REPO"
19
+ ```
20
+
21
+ Use `--kind file` or `--kind directory` when an absent future path cannot be
22
+ classified from the filesystem. Read the inherited guides first, then the
23
+ applicable maintained knowledge, active plans, dated research, reports, and
24
+ separate historical-plan group.
25
+
26
+ 3. Search existing plans before creating one:
27
+
28
+ ```sh
29
+ kb list --root "$KB_ROOT" --where type=plan --sort area --json
30
+ kb search "the intended outcome" --root "$KB_ROOT" --json
31
+ ```
32
+
33
+ If `kb` is not installed, do not let retrieval tooling block the plan: use
34
+ `rg` or the available file search over `<vault>/plans/`, titles, aliases, and relevant
35
+ terms. If the directory is not an initialized hraness/kb vault, follow the
36
+ repository's existing planning convention instead of initializing one without
37
+ being asked. Semantic search writes only a derived local cache; when that cache
38
+ location is not writable, use exact search or point `XDG_CACHE_HOME` at a
39
+ writable cache directory.
40
+
41
+ 4. Update an existing plan when it already owns the outcome. Create a new file
42
+ only for independently executable work.
43
+ 5. Use `<vault>/plans/<descriptive-kebab-name>.md` unless the local guide already groups
44
+ plans by area. Do not reorganize older plans merely to impose a new tree.
45
+
46
+ ## Write from evidence
47
+
48
+ Read [the plan structure reference](plan-structure.md), then tailor it to
49
+ the work. Preserve these invariants:
50
+
51
+ - State one concrete outcome and the current status.
52
+ - Record what is known, what is assumed, and what remains to discover.
53
+ - Separate in-scope work from non-goals.
54
+ - Put constraints and decisions before the steps they shape.
55
+ - Make dependencies and ordering visible.
56
+ - Give each acceptance claim a verification method.
57
+ - Include rollback or recovery when a change can leave durable state behind.
58
+
59
+ Turn a missing implementation detail into an ordered discovery gate when the
60
+ outcome and authorization are already clear and the decision can be made from
61
+ in-scope evidence. Stop and request direction when the unknown would change the
62
+ intended outcome, expand authority or external coordination, or choose between
63
+ materially different products.
64
+
65
+ Use small frontmatter. Start with `type: plan`, a descriptive title and
66
+ one-sentence description, a kebab-case `area`, and one of `proposed`,
67
+ `accepted`, `in-progress`, `blocked`, `completed`, `superseded`, or `cancelled`.
68
+ When the plan owns work in a code repository, add `repository_scopes` with the
69
+ few exact canonical repository-relative files or directories it explains. Use
70
+ no globs. A future path is valid; update an active plan deliberately when code
71
+ moves instead of relying on inferred Git renames. Add aliases or tags only when
72
+ they help humans or structured queries.
73
+
74
+ ## Grow the same file during execution
75
+
76
+ - Change status when reality changes, not in anticipation.
77
+ - Check off completed work without deleting the original intent.
78
+ - Incorporate decisions, review findings, deviations, and command or test
79
+ evidence where a future reader can understand their consequence.
80
+ - When blocked, name the exact missing condition and the safe work already
81
+ completed.
82
+ - When a plan becomes `completed`, `superseded`, or `cancelled`, write a
83
+ non-empty `## Result` and `## Durable memory`. State what shipped or why work
84
+ stopped in Result. In Durable memory, link each reusable conclusion to the
85
+ maintained note, guide, documentation, or checked code contract that now owns
86
+ it. When nothing warrants promotion, say so explicitly and give the reason.
87
+ Retain the terminal plan as history.
88
+ - Do not create separate progress, review, or completion files for the same
89
+ plan.
90
+
91
+ ## Connect and verify
92
+
93
+ Add wikilinks or typed relationships only where the prose and evidence explain
94
+ a useful connection. Review the changed plan for reusable concepts before
95
+ refreshing:
96
+
97
+ ```sh
98
+ kb percolate "<plan-note-id>" --root "$KB_ROOT" --limit 25 --json
99
+ kb refresh --root "$KB_ROOT"
100
+ kb check --root "$KB_ROOT"
101
+ ```
102
+
103
+ Run those commands when the plan lives in an initialized hraness/kb vault. In a
104
+ repository-native planning directory, use that repository's own validation
105
+ instead. Review broken links first, then inspect orphan and mention advisories
106
+ in context. Promote only concepts likely to be reused, and ground every typed
107
+ relationship in the plan's prose. An independently useful plan may legitimately
108
+ remain an orphan in a new or sparse vault. Record that disposition mentally or
109
+ in the task handoff; do not manufacture links or relations merely to improve
110
+ graph counts.
111
+
112
+ In an authored-catalog vault, refresh leaves the front door unchanged and `kb
113
+ catalog --root "$KB_ROOT"` renders an exhaustive disposable inventory. In a
114
+ managed vault, independent edit lanes use `kb check --root "$KB_ROOT"
115
+ --no-catalog`; the integrating lane performs the single catalog refresh.
@@ -0,0 +1,231 @@
1
+ # Query the knowledge base
2
+
3
+ Use the cheapest precise view first, then broaden. Markdown files remain the
4
+ authority; search scores, metadata rows, and graph results are derived views.
5
+
6
+ ## Locate the vault
7
+
8
+ - Resolve `<vault>` to the directory containing its managed or authored `index.md`, then
9
+ set the shell-local `KB_ROOT` to that path (`KB_ROOT=kb` from a typical
10
+ repository root, or `KB_ROOT=.` from inside the vault).
11
+ - Resolve `<repository>` to the repository root when the question concerns a
12
+ repository path (`KB_REPO=.` from that root).
13
+ - Read the vault's applicable agent instructions and note conventions.
14
+ - Pass the resolved path to every `--root`; do not scan a repository root merely
15
+ because that is where the agent session started.
16
+
17
+ ## Choose the retrieval lane
18
+
19
+ - Repository file or directory: run `kb context` first. Read its inherited
20
+ guides root to nearest, then inspect its maintained knowledge, active plans,
21
+ dated research, reports, and separate historical-plan group. Open only useful
22
+ context hubs or records.
23
+ - Known frontmatter field or tag such as type, status, or area: use `kb list`.
24
+ - Known note title, path, or alias: use `kb links` or `kb backlinks`, which
25
+ resolve note identities before returning authored relationships.
26
+ - A whole-vault structural question or relationship audit: use `kb graph --json`,
27
+ then inspect the smallest relevant portion of its canonical output.
28
+ - A phrase, identity, or concept expressed with different vocabulary: use `kb search`, whose default hybrid result preserves exact and QMD evidence separately.
29
+ - Direct provenance for one note or repository path: use `kb history` or
30
+ `kb history search` without changing authored metadata or links.
31
+ - Recent captures awaiting maintained disposition: use the advisory `kb inbox` view.
32
+ - Broad orientation: read `index.md`, then follow the smallest useful link trail. Use `kb catalog` when an exhaustive disposable inventory is actually needed.
33
+ - A question spanning registered vaults: use `kb portfolio search` with a reviewed registry and explicit authorization. Use `kb portfolio audit` to assess IDs, duplicate authority, links, attachments, and provenance without repairing content.
34
+
35
+ ```sh
36
+ kb context src/parser.ts --root "$KB_ROOT" --repo "$KB_REPO"
37
+ kb list --root "$KB_ROOT" --scope src/parser --where type=plan --json
38
+ kb list --root "$KB_ROOT" --where type=plan --where status=in-progress --sort area --json
39
+ kb list --root "$KB_ROOT" --tag retrieval --sort title --json
40
+ kb backlinks "Plan title or path" --root "$KB_ROOT" --json
41
+ kb links "Plan title or path" --root "$KB_ROOT" --direction both --depth 1 --limit 25 --json
42
+ kb relation list "Plan title or path" --root "$KB_ROOT" --json
43
+ kb graph --root "$KB_ROOT" --json
44
+ kb search "why browser capture uses the current tab" --root "$KB_ROOT" --json
45
+ kb search "accepted ingestion plans" --root "$KB_ROOT" --where type=plan --where status=accepted --tag ingestion --json
46
+ kb search "notes/write-path" --root "$KB_ROOT" --mode exact --no-history --json
47
+ kb history "notes/write-path" --root "$KB_ROOT" --repo "$KB_REPO" --json
48
+ kb history search src/parser.ts --root "$KB_ROOT" --repo "$KB_REPO" --json
49
+ kb inbox --root "$KB_ROOT" --limit 25 --json
50
+ kb portfolio search "durable memory" --registry ./kb-portfolio.json --workspace .. --shared --json
51
+ kb portfolio audit --registry ./kb-portfolio.json --workspace .. --vault hraness/kb --vault 0thernet/jungle --strict --json
52
+ ```
53
+
54
+ Portfolio selection is an access decision. Prefer repeated `--vault owner/id`
55
+ for deliberate private or personal scope. `--shared` selects only public and
56
+ organization entries; `--all` exists only for audit. One operation is bounded
57
+ to 32 vaults and never silently truncates a larger registry-derived selection.
58
+ Open returned notes before concluding. Cross-vault scores are not compared;
59
+ federation uses deterministic reciprocal local rank and stable logical IDs.
60
+
61
+ When a reviewed consumer policy needs repeatable query shorthand, pass a strict
62
+ v1 rules file. An alias is recognized only as the first token and can add a
63
+ query, mode, metadata filters, tags, or repository scopes without discarding
64
+ caller constraints. Priority ordering is a separate opt-in:
65
+
66
+ ```sh
67
+ kb search "@active-plans parser" --root "$KB_ROOT" \
68
+ --rules ./search-rules.json --priority --json
69
+ kb portfolio search "@active-plans parser" \
70
+ --registry ./kb-portfolio.json --workspace .. --shared \
71
+ --rules ./search-rules.json --priority --json
72
+ ```
73
+
74
+ `--rules` alone enables aliases but retains relevance order. `--priority`
75
+ requires a rules file and requests `priority-then-relevance`; exact identities
76
+ still come first, and matching selected hits carry a rule trace. Keep this
77
+ policy beside the registry or repository that owns it. Rules do not grant
78
+ access, choose authority, author links, or mutate Markdown.
79
+
80
+ `kb context` prints hub and record summaries, not their bodies. Each record
81
+ states the exact `repository_scopes` declaration that matched, the match depth,
82
+ and whether that declaration currently names a file, directory, or absent
83
+ future or retired path. Current memory and terminal plans stay in separate
84
+ groups. Guides remain
85
+ the normative, always-loaded home for ownership, required commands,
86
+ prohibitions, invariants, and edit gates. Scope hubs are optional pull-based
87
+ rationale, history, examples, evidence, and links; they cannot override a guide
88
+ or become the only home of a load-bearing rule. Use `--kind file` or
89
+ `--kind directory` when `auto` cannot classify a missing target reliably.
90
+
91
+ Repeated filters use AND semantics. Metadata paths may be dotted. String and
92
+ tag comparisons are case-insensitive; array metadata matches by membership.
93
+ Missing sort values come last, with path as the deterministic tie-breaker.
94
+ `--where` addresses authored frontmatter only; it does not filter derived H1
95
+ titles or file paths. Unquoted `true`, `false`, `null`, and numeric filter
96
+ values are typed. Keep quotes inside the argument to match a string with the
97
+ same spelling, for example `--where 'external_id="9007199254740993"'`.
98
+ `--scope` is an exact, case-sensitive repository-scope filter rather than a
99
+ substring or area match. Use it when the desired authored path declaration is
100
+ known.
101
+
102
+ ## Use hybrid search as discovery
103
+
104
+ `kb search` first scans current Markdown for identity, phrase, metadata, tag,
105
+ and prose matches. By default it runs that exact lane alongside QMD's local
106
+ full-text and vector rankings, then combines the ranked lists while retaining
107
+ each lane's evidence. Exact title and alias identities stay ahead of broader
108
+ matches. The QMD path avoids query expansion and reranking models by default.
109
+
110
+ The first hybrid or semantic query downloads QMD's compact local embedding
111
+ model; later queries reuse the local cache. Prewarm explicitly when useful:
112
+
113
+ ```sh
114
+ kb index --root "$KB_ROOT"
115
+ ```
116
+
117
+ Use `--mode exact` for live model-free search, `--mode keyword` for QMD
118
+ full-text retrieval, or `--mode semantic` for its vector lane. Repeated
119
+ `--where`, `--has`, and `--tag` constraints are checked against the live
120
+ Markdown snapshot. QMD has no path-allowlist search in the pinned release, so a
121
+ selective semantic query over-fetches a bounded global window and reports a
122
+ degraded partial lane when that window cannot prove completeness. Treat every
123
+ retrieval rank as a lead, not a fact. Open the returned Markdown, read enough
124
+ surrounding context, and confirm claims against linked sources or capture
125
+ manifests.
126
+
127
+ Default search also returns bounded explicit graph context around the strongest
128
+ results. Supply `--related <note>` to seed a known neighborhood or `--no-graph`
129
+ when structure does not help. Search does no Git work unless provenance is
130
+ requested. Use `--history --repo <repository>` for optional recent per-note
131
+ provenance or `--require-history --repo <repository>` when the task cannot
132
+ proceed with a partial Git lane. `--no-history` remains an explicit compatibility
133
+ form. Graph neighbors and Git history remain separate from primary
134
+ text rank. They explain and expand candidates without becoming authored facts,
135
+ links, or recency boosts.
136
+
137
+ `kb history <note>` returns the bounded commit history already associated with
138
+ one resolved note. `kb history search <query-or-path>` searches the bounded Git
139
+ projection directly and retains hashes, subjects, matched paths, co-change
140
+ paths, and incomplete-detail diagnostics. Git co-change is historical evidence,
141
+ not permission to write a scope or relationship.
142
+
143
+ ## Reuse one snapshot in code mode
144
+
145
+ For several related queries, prefer one SDK session to repeated CLI process
146
+ startup:
147
+
148
+ ```ts
149
+ import { openKnowledgeBase, packUntrustedSearchContext } from "@hraness/kb/sdk";
150
+
151
+ const kb = await openKnowledgeBase({ root: "kb", repository: "." });
152
+ try {
153
+ const result = await kb.search({
154
+ query: "why browser capture uses the current tab",
155
+ graph: { depth: 1 },
156
+ history: "auto",
157
+ });
158
+ console.log(packUntrustedSearchContext(result).content);
159
+ } finally {
160
+ await kb.close();
161
+ }
162
+ ```
163
+
164
+ `grep`, `list`, `read`, `links`, `backlinks`, `search`, `history`, and
165
+ `searchHistory` share one confined read-only scan. QMD and Git initialize
166
+ lazily. The session does not watch Markdown or repository changes. Close it
167
+ before a write and open a new session after the final refresh and check.
168
+
169
+ Pass only ordinary plain objects and arrays from KB or parsed JSON into
170
+ `packUntrustedSearchContext`. A same-realm JavaScript `Proxy` is executable
171
+ code, not inert data; isolate or serialize it before projection.
172
+
173
+ When independent queries can run concurrently, compose them with
174
+ `defineWorkflow` and `runWorkflow` or import a packaged workflow. The runner
175
+ validates a finite acyclic graph, caps global concurrency, serializes QMD nodes,
176
+ and keeps Git concurrency bounded. Do not bypass those resource groups with
177
+ unbounded `Promise.all` calls. Custom workflows use the staged
178
+ `defineWorkflow<Input>("id").node(...).output(...)` builder so dependency
179
+ results and the final output remain typed.
180
+
181
+ ## Use focused structural views
182
+
183
+ `kb graph --json` returns the current resolved wikilinks, typed relationships,
184
+ diagnostics, and note-level connection counts without creating a second graph
185
+ store. Use it when a question spans the vault. Prefer `kb relation list`,
186
+ `kb backlinks`, or `kb links` when a known note gives you a narrower starting
187
+ point.
188
+
189
+ `kb links` is cycle-safe and requires an explicit traversal depth and result
190
+ limit. `kb relation list` separates authored outbound assertions from derived
191
+ inbound relationships while retaining canonical note IDs and source
192
+ provenance. Open the returned Markdown before treating an edge as correct: a
193
+ typed relationship records an authored assertion, not proof.
194
+
195
+ If a structural question is not covered by a named command, inspect the
196
+ bounded JSON graph in the agent or a short task-local script. Do not create or
197
+ commit a parallel graph database merely to answer one query. A recurring query
198
+ is evidence for a focused, tested command with an explicit output contract.
199
+
200
+ ## Combine meaning with structure
201
+
202
+ 1. For a repository-path question, use `kb context` before broader retrieval.
203
+ 2. Use default hybrid search to discover candidate identities when exact
204
+ structure does not answer the question. Read its lane evidence and partial
205
+ diagnostics before relying on the order.
206
+ 3. Use `kb list` to narrow by authored metadata such as `type`, `status`,
207
+ `area`, or `tags`.
208
+ 4. Use `kb links` at depth 1 to inspect immediate explicit relationships and
209
+ `kb backlinks` for a focused inbound view. Increase depth only when the
210
+ first neighborhood is insufficient. Traversal defaults to 50 notes and
211
+ reports truncation; lower `--limit` for tighter agent context or raise it
212
+ deliberately when a high-degree hub is genuinely relevant.
213
+ 5. Use `kb graph --json` only when the question genuinely spans multiple
214
+ neighborhoods; keep one-off processing task-local.
215
+ 6. Read the authoritative notes and cited captures before synthesizing.
216
+
217
+ A title match may identify a prerequisite, prior version, or supporting note
218
+ rather than the artifact that owns the current outcome. Confirm status and
219
+ ownership in the candidate Markdown before answering or editing it.
220
+
221
+ Do not infer an edge from semantic similarity, or a conclusion from a tag. Do
222
+ not write generated backlink sections into notes. If the query exposes stale
223
+ metadata or a broken link, repair the authored Markdown and finish with
224
+ `kb refresh --root "$KB_ROOT"` and `kb check --root "$KB_ROOT"`.
225
+ Close any open SDK session before that repair and reopen it after validation.
226
+
227
+ An authored `index.md` may declare `kb_catalog: authored`; refresh and check
228
+ then leave it untouched. `kb catalog --root "$KB_ROOT"` renders the exhaustive
229
+ inventory on demand. A managed vault keeps the original generated-catalog
230
+ behavior. Neither mode changes scanning, graph analysis, semantic indexing, or
231
+ attachment validation.