@monoes/monomindcli 2.10.9 → 2.10.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/.claude/commands/mastermind/brain.md +14 -14
  2. package/.claude/commands/mastermind/help.md +2 -2
  3. package/.claude/commands/mastermind/master.md +24 -19
  4. package/.claude/commands/mastermind/memory.md +8 -8
  5. package/.claude/commands/mastermind/monoswarm.md +4 -4
  6. package/.claude/commands/mastermind.md +7 -7
  7. package/.claude/commands/truth/start.md +3 -3
  8. package/.claude/settings.json +0 -4
  9. package/.claude/skills/mastermind/SKILL.md +7 -16
  10. package/.claude/skills/mastermind/references/antigravity-tools.md +0 -62
  11. package/.claude/skills/mastermind/references/claude-code-tools.md +0 -52
  12. package/.claude/skills/mastermind/references/codex-tools.md +0 -66
  13. package/.claude/skills/mastermind/references/copilot-tools.md +0 -51
  14. package/.claude/skills/mastermind/references/gemini-tools.md +0 -65
  15. package/.claude/skills/mastermind/references/pi-tools.md +0 -30
  16. package/.claude/skills/mastermind-createorg/SKILL.md +3 -1
  17. package/.claude/skills/mastermind-debug/SKILL.md +3 -277
  18. package/.claude/skills/mastermind-design/SKILL.md +2 -0
  19. package/.claude/skills/mastermind-execute/SKILL.md +59 -103
  20. package/.claude/skills/mastermind-idea/SKILL.md +9 -2
  21. package/.claude/skills/mastermind-intake/SKILL.md +31 -7
  22. package/.claude/skills/mastermind-issue-detail/SKILL.md +70 -16
  23. package/.claude/skills/mastermind-issues/SKILL.md +111 -16
  24. package/.claude/skills/mastermind-liveness/SKILL.md +96 -26
  25. package/.claude/skills/mastermind-memory/SKILL.md +0 -316
  26. package/.claude/skills/mastermind-my-issues/SKILL.md +40 -8
  27. package/.claude/skills/mastermind-org/SKILL.md +1 -12
  28. package/.claude/skills/mastermind-plan/SKILL.md +7 -228
  29. package/.claude/skills/mastermind-plan-to-tasks/SKILL.md +132 -24
  30. package/.claude/skills/mastermind-protocol/SKILL.md +33 -22
  31. package/.claude/skills/mastermind-research/SKILL.md +0 -163
  32. package/.claude/skills/mastermind-review/SKILL.md +0 -228
  33. package/.claude/skills/mastermind-runorg/SKILL.md +22 -3
  34. package/.claude/skills/mastermind-skill-builder/SKILL.md +1 -1
  35. package/.claude/skills/mastermind-tasks/SKILL.md +5 -0
  36. package/.claude/skills/mastermind-techport/SKILL.md +1 -1
  37. package/.claude/skills/performance-analysis/SKILL.md +1 -1
  38. package/.claude/skills/verification-quality/SKILL.md +2 -3
  39. package/README.md +2 -2
  40. package/dist/src/commands/agent-exec.d.ts +2 -0
  41. package/dist/src/commands/agent-exec.d.ts.map +1 -1
  42. package/dist/src/commands/agent-exec.js +16 -0
  43. package/dist/src/commands/agent-exec.js.map +1 -1
  44. package/dist/src/commands/doc.js +2 -2
  45. package/dist/src/commands/doc.js.map +1 -1
  46. package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
  47. package/dist/src/commands/doctor-project-checks.js +20 -1
  48. package/dist/src/commands/doctor-project-checks.js.map +1 -1
  49. package/dist/src/commands/init-wizard.d.ts.map +1 -1
  50. package/dist/src/commands/init-wizard.js +6 -0
  51. package/dist/src/commands/init-wizard.js.map +1 -1
  52. package/dist/src/commands/init.d.ts.map +1 -1
  53. package/dist/src/commands/init.js +12 -2
  54. package/dist/src/commands/init.js.map +1 -1
  55. package/dist/src/commands/monograph.d.ts.map +1 -1
  56. package/dist/src/commands/monograph.js +11 -4
  57. package/dist/src/commands/monograph.js.map +1 -1
  58. package/dist/src/commands/org-observe.d.ts +2 -0
  59. package/dist/src/commands/org-observe.d.ts.map +1 -1
  60. package/dist/src/commands/org-observe.js +115 -6
  61. package/dist/src/commands/org-observe.js.map +1 -1
  62. package/dist/src/commands/org.d.ts +26 -0
  63. package/dist/src/commands/org.d.ts.map +1 -1
  64. package/dist/src/commands/org.js +186 -28
  65. package/dist/src/commands/org.js.map +1 -1
  66. package/dist/src/init/codex-generator.d.ts +5 -0
  67. package/dist/src/init/codex-generator.d.ts.map +1 -1
  68. package/dist/src/init/codex-generator.js +12 -3
  69. package/dist/src/init/codex-generator.js.map +1 -1
  70. package/dist/src/init/executor.d.ts.map +1 -1
  71. package/dist/src/init/executor.js +10 -9
  72. package/dist/src/init/executor.js.map +1 -1
  73. package/dist/src/init/settings-generator.d.ts.map +1 -1
  74. package/dist/src/init/settings-generator.js +0 -5
  75. package/dist/src/init/settings-generator.js.map +1 -1
  76. package/dist/src/init/write-codex.d.ts.map +1 -1
  77. package/dist/src/init/write-codex.js +6 -5
  78. package/dist/src/init/write-codex.js.map +1 -1
  79. package/dist/src/knowledge/document-pipeline.d.ts +5 -0
  80. package/dist/src/knowledge/document-pipeline.d.ts.map +1 -1
  81. package/dist/src/knowledge/document-pipeline.js +32 -16
  82. package/dist/src/knowledge/document-pipeline.js.map +1 -1
  83. package/dist/src/mcp-tools/hooks-routing.d.ts +9 -0
  84. package/dist/src/mcp-tools/hooks-routing.d.ts.map +1 -1
  85. package/dist/src/mcp-tools/hooks-routing.js +12 -1
  86. package/dist/src/mcp-tools/hooks-routing.js.map +1 -1
  87. package/dist/src/mcp-tools/knowledge-tools.d.ts.map +1 -1
  88. package/dist/src/mcp-tools/knowledge-tools.js +105 -13
  89. package/dist/src/mcp-tools/knowledge-tools.js.map +1 -1
  90. package/dist/src/mcp-tools/memory-tools.d.ts +13 -0
  91. package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
  92. package/dist/src/mcp-tools/memory-tools.js +257 -31
  93. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  94. package/dist/src/mcp-tools/monograph/health-tools.d.ts.map +1 -1
  95. package/dist/src/mcp-tools/monograph/health-tools.js +99 -42
  96. package/dist/src/mcp-tools/monograph/health-tools.js.map +1 -1
  97. package/dist/src/mcp-tools/monograph/impact-tools.d.ts.map +1 -1
  98. package/dist/src/mcp-tools/monograph/impact-tools.js +123 -51
  99. package/dist/src/mcp-tools/monograph/impact-tools.js.map +1 -1
  100. package/dist/src/mcp-tools/monograph/query-tools.d.ts.map +1 -1
  101. package/dist/src/mcp-tools/monograph/query-tools.js +113 -96
  102. package/dist/src/mcp-tools/monograph/query-tools.js.map +1 -1
  103. package/dist/src/mcp-tools/monograph/shared.d.ts +37 -4
  104. package/dist/src/mcp-tools/monograph/shared.d.ts.map +1 -1
  105. package/dist/src/mcp-tools/monograph/shared.js +75 -56
  106. package/dist/src/mcp-tools/monograph/shared.js.map +1 -1
  107. package/dist/src/memory/embedding-operations.d.ts.map +1 -1
  108. package/dist/src/memory/embedding-operations.js +9 -4
  109. package/dist/src/memory/embedding-operations.js.map +1 -1
  110. package/dist/src/memory/memory-bridge.d.ts +60 -1
  111. package/dist/src/memory/memory-bridge.d.ts.map +1 -1
  112. package/dist/src/memory/memory-bridge.js +185 -42
  113. package/dist/src/memory/memory-bridge.js.map +1 -1
  114. package/dist/src/memory/memory-kg.d.ts +495 -28
  115. package/dist/src/memory/memory-kg.d.ts.map +1 -1
  116. package/dist/src/memory/memory-kg.js +2186 -251
  117. package/dist/src/memory/memory-kg.js.map +1 -1
  118. package/dist/src/memory/query-router.d.ts +51 -0
  119. package/dist/src/memory/query-router.d.ts.map +1 -1
  120. package/dist/src/memory/query-router.js +38 -2
  121. package/dist/src/memory/query-router.js.map +1 -1
  122. package/dist/src/orgrt/agent-exec.d.ts +14 -0
  123. package/dist/src/orgrt/agent-exec.d.ts.map +1 -1
  124. package/dist/src/orgrt/agent-exec.js +88 -4
  125. package/dist/src/orgrt/agent-exec.js.map +1 -1
  126. package/dist/src/orgrt/agent-runner.d.ts +26 -1
  127. package/dist/src/orgrt/agent-runner.d.ts.map +1 -1
  128. package/dist/src/orgrt/agent-runner.js +73 -22
  129. package/dist/src/orgrt/agent-runner.js.map +1 -1
  130. package/dist/src/orgrt/antigravity-runner.d.ts +1 -1
  131. package/dist/src/orgrt/antigravity-runner.d.ts.map +1 -1
  132. package/dist/src/orgrt/antigravity-runner.js +36 -19
  133. package/dist/src/orgrt/antigravity-runner.js.map +1 -1
  134. package/dist/src/orgrt/approvals.d.ts +26 -2
  135. package/dist/src/orgrt/approvals.d.ts.map +1 -1
  136. package/dist/src/orgrt/approvals.js +67 -7
  137. package/dist/src/orgrt/approvals.js.map +1 -1
  138. package/dist/src/orgrt/broker.d.ts +21 -2
  139. package/dist/src/orgrt/broker.d.ts.map +1 -1
  140. package/dist/src/orgrt/broker.js +56 -8
  141. package/dist/src/orgrt/broker.js.map +1 -1
  142. package/dist/src/orgrt/bus.d.ts +8 -0
  143. package/dist/src/orgrt/bus.d.ts.map +1 -1
  144. package/dist/src/orgrt/bus.js +27 -0
  145. package/dist/src/orgrt/bus.js.map +1 -1
  146. package/dist/src/orgrt/checkpoint-ops.d.ts.map +1 -1
  147. package/dist/src/orgrt/checkpoint-ops.js +15 -5
  148. package/dist/src/orgrt/checkpoint-ops.js.map +1 -1
  149. package/dist/src/orgrt/checkpoint.d.ts +42 -4
  150. package/dist/src/orgrt/checkpoint.d.ts.map +1 -1
  151. package/dist/src/orgrt/checkpoint.js +75 -4
  152. package/dist/src/orgrt/checkpoint.js.map +1 -1
  153. package/dist/src/orgrt/codex-runner.d.ts +1 -1
  154. package/dist/src/orgrt/codex-runner.d.ts.map +1 -1
  155. package/dist/src/orgrt/codex-runner.js +50 -23
  156. package/dist/src/orgrt/codex-runner.js.map +1 -1
  157. package/dist/src/orgrt/copilot-runner.d.ts +24 -2
  158. package/dist/src/orgrt/copilot-runner.d.ts.map +1 -1
  159. package/dist/src/orgrt/copilot-runner.js +257 -157
  160. package/dist/src/orgrt/copilot-runner.js.map +1 -1
  161. package/dist/src/orgrt/cross-org.d.ts +10 -3
  162. package/dist/src/orgrt/cross-org.d.ts.map +1 -1
  163. package/dist/src/orgrt/cross-org.js +225 -10
  164. package/dist/src/orgrt/cross-org.js.map +1 -1
  165. package/dist/src/orgrt/crush-runner.d.ts +22 -2
  166. package/dist/src/orgrt/crush-runner.d.ts.map +1 -1
  167. package/dist/src/orgrt/crush-runner.js +227 -120
  168. package/dist/src/orgrt/crush-runner.js.map +1 -1
  169. package/dist/src/orgrt/daemon.d.ts +77 -7
  170. package/dist/src/orgrt/daemon.d.ts.map +1 -1
  171. package/dist/src/orgrt/daemon.js +989 -385
  172. package/dist/src/orgrt/daemon.js.map +1 -1
  173. package/dist/src/orgrt/decisions.d.ts +2 -2
  174. package/dist/src/orgrt/decisions.d.ts.map +1 -1
  175. package/dist/src/orgrt/decisions.js +90 -18
  176. package/dist/src/orgrt/decisions.js.map +1 -1
  177. package/dist/src/orgrt/grok-runner.d.ts +29 -3
  178. package/dist/src/orgrt/grok-runner.d.ts.map +1 -1
  179. package/dist/src/orgrt/grok-runner.js +286 -150
  180. package/dist/src/orgrt/grok-runner.js.map +1 -1
  181. package/dist/src/orgrt/kimicode-runner.d.ts +5 -5
  182. package/dist/src/orgrt/kimicode-runner.d.ts.map +1 -1
  183. package/dist/src/orgrt/kimicode-runner.js +53 -32
  184. package/dist/src/orgrt/kimicode-runner.js.map +1 -1
  185. package/dist/src/orgrt/mailbox.d.ts +15 -0
  186. package/dist/src/orgrt/mailbox.d.ts.map +1 -1
  187. package/dist/src/orgrt/mailbox.js +29 -1
  188. package/dist/src/orgrt/mailbox.js.map +1 -1
  189. package/dist/src/orgrt/migrate.d.ts.map +1 -1
  190. package/dist/src/orgrt/migrate.js +8 -5
  191. package/dist/src/orgrt/migrate.js.map +1 -1
  192. package/dist/src/orgrt/opencode-runner.d.ts +1 -1
  193. package/dist/src/orgrt/opencode-runner.d.ts.map +1 -1
  194. package/dist/src/orgrt/opencode-runner.js +29 -3
  195. package/dist/src/orgrt/opencode-runner.js.map +1 -1
  196. package/dist/src/orgrt/org-memory.d.ts +19 -3
  197. package/dist/src/orgrt/org-memory.d.ts.map +1 -1
  198. package/dist/src/orgrt/org-memory.js +110 -38
  199. package/dist/src/orgrt/org-memory.js.map +1 -1
  200. package/dist/src/orgrt/pi-rpc-runner.d.ts +3 -1
  201. package/dist/src/orgrt/pi-rpc-runner.d.ts.map +1 -1
  202. package/dist/src/orgrt/pi-rpc-runner.js +35 -3
  203. package/dist/src/orgrt/pi-rpc-runner.js.map +1 -1
  204. package/dist/src/orgrt/pi-runner.d.ts +25 -2
  205. package/dist/src/orgrt/pi-runner.d.ts.map +1 -1
  206. package/dist/src/orgrt/pi-runner.js +271 -152
  207. package/dist/src/orgrt/pi-runner.js.map +1 -1
  208. package/dist/src/orgrt/policy.d.ts +1 -0
  209. package/dist/src/orgrt/policy.d.ts.map +1 -1
  210. package/dist/src/orgrt/policy.js +199 -39
  211. package/dist/src/orgrt/policy.js.map +1 -1
  212. package/dist/src/orgrt/provider.d.ts +4 -0
  213. package/dist/src/orgrt/provider.d.ts.map +1 -1
  214. package/dist/src/orgrt/provider.js +16 -0
  215. package/dist/src/orgrt/provider.js.map +1 -1
  216. package/dist/src/orgrt/qwen-rpc-runner.d.ts +3 -1
  217. package/dist/src/orgrt/qwen-rpc-runner.d.ts.map +1 -1
  218. package/dist/src/orgrt/qwen-rpc-runner.js +35 -3
  219. package/dist/src/orgrt/qwen-rpc-runner.js.map +1 -1
  220. package/dist/src/orgrt/qwen-runner.d.ts +30 -3
  221. package/dist/src/orgrt/qwen-runner.d.ts.map +1 -1
  222. package/dist/src/orgrt/qwen-runner.js +282 -142
  223. package/dist/src/orgrt/qwen-runner.js.map +1 -1
  224. package/dist/src/orgrt/role-slot.d.ts +88 -0
  225. package/dist/src/orgrt/role-slot.d.ts.map +1 -0
  226. package/dist/src/orgrt/role-slot.js +133 -0
  227. package/dist/src/orgrt/role-slot.js.map +1 -0
  228. package/dist/src/orgrt/runtime-options.d.ts +17 -0
  229. package/dist/src/orgrt/runtime-options.d.ts.map +1 -0
  230. package/dist/src/orgrt/runtime-options.js +32 -0
  231. package/dist/src/orgrt/runtime-options.js.map +1 -0
  232. package/dist/src/orgrt/scheduler-integration.d.ts +11 -0
  233. package/dist/src/orgrt/scheduler-integration.d.ts.map +1 -1
  234. package/dist/src/orgrt/scheduler-integration.js +75 -17
  235. package/dist/src/orgrt/scheduler-integration.js.map +1 -1
  236. package/dist/src/orgrt/scheduler.d.ts +4 -0
  237. package/dist/src/orgrt/scheduler.d.ts.map +1 -1
  238. package/dist/src/orgrt/scheduler.js +7 -1
  239. package/dist/src/orgrt/scheduler.js.map +1 -1
  240. package/dist/src/orgrt/server.d.ts +8 -3
  241. package/dist/src/orgrt/server.d.ts.map +1 -1
  242. package/dist/src/orgrt/server.js +48 -13
  243. package/dist/src/orgrt/server.js.map +1 -1
  244. package/dist/src/orgrt/session.d.ts +26 -2
  245. package/dist/src/orgrt/session.d.ts.map +1 -1
  246. package/dist/src/orgrt/session.js +99 -5
  247. package/dist/src/orgrt/session.js.map +1 -1
  248. package/dist/src/orgrt/task-dag.d.ts +5 -0
  249. package/dist/src/orgrt/task-dag.d.ts.map +1 -1
  250. package/dist/src/orgrt/task-dag.js +41 -0
  251. package/dist/src/orgrt/task-dag.js.map +1 -1
  252. package/dist/src/orgrt/test-loop.js +2 -2
  253. package/dist/src/orgrt/test-loop.js.map +1 -1
  254. package/dist/src/orgrt/types.d.ts +14 -2
  255. package/dist/src/orgrt/types.d.ts.map +1 -1
  256. package/dist/src/orgrt/types.js +15 -1
  257. package/dist/src/orgrt/types.js.map +1 -1
  258. package/dist/src/orgrt/vercel-runner.d.ts.map +1 -1
  259. package/dist/src/orgrt/vercel-runner.js +4 -0
  260. package/dist/src/orgrt/vercel-runner.js.map +1 -1
  261. package/dist/src/ui/routes-org.mjs +27 -7
  262. package/dist/src/ui/server.mjs +82 -48
  263. package/dist/tsconfig.tsbuildinfo +1 -1
  264. package/package.json +2 -1
  265. package/dist/src/ui/data/mastermind-sessions.json +0 -1
@@ -10,21 +10,116 @@
10
10
  * feedback/frequency weighting for free — KG node ranking improves with use
11
11
  * automatically.
12
12
  *
13
- * Identity is deterministic and NAME-ONLY (cognee's Entity.identity_fields):
14
- * the entry KEY is `n:<normalized-name>`, so the same entity extracted from
15
- * any session merges idempotently via upsert regardless of assigned type.
16
- * Every write carries `origin_refs` so a bad ingest can be rolled back per
17
- * run/session.
13
+ * OWNERSHIP is carried by `KgScope`, not by the store path. Every org under
14
+ * one project root shares ONE org-memory store, so those namespaces would
15
+ * otherwise be a single pool that any org can read, merge into, and roll back.
16
+ * A scope suffixes every one of them (`kg:nodes:org:<org>`, …) and stamps the
17
+ * asserting org onto every origin ref, so an org's reads, writes, glossary and
18
+ * rollback all resolve through `kgNamespaces()` and can only reach what that
19
+ * org asserted. An absent scope means PROJECT-SHARED knowledge — a scope in
20
+ * its own right, not "all scopes". Crossing from an org into the shared graph
21
+ * is `kgPromote`, an explicit operation, never a side effect of learning.
18
22
  *
19
- * // monolean: graph traversal is in-process over a full kg:edges list —
20
- * // fine to ~10k edges; upgrade path is a real SQLite edges table with
21
- * // indexed src/dst columns if orgs outgrow that.
23
+ * IDENTITY is the (type, name) tuple, hashed length-prefixed so no component
24
+ * can bleed into its neighbour and no distinction is truncated away — the same
25
+ * injective-serialization discipline monograph's `symbolId`/`fileId` use, and
26
+ * for the same reason. Name-only identity made `Person:Alex` and `Service:Alex`
27
+ * one entity, and made two names that first differ at character 250 one entity
28
+ * as well. Keys stay per-namespace, so scope still lives in the NAMESPACE: two
29
+ * orgs asserting different facts about the same name produce the same id, and
30
+ * only separate namespaces keep them from overwriting each other.
31
+ *
32
+ * Name-only merging did buy something real — it stopped the same entity forking
33
+ * when the LLM said "Module" and the heuristic said "entity" — so that benefit
34
+ * is kept by a NAME INDEX (`kg:names`) rather than by a lossy key. Resolution
35
+ * goes through the index, never through a computed key: a generic assertion
36
+ * adopts the single same-name entity if there is exactly one, a typed assertion
37
+ * adopts a lone untyped one and promotes its type, and anything genuinely
38
+ * ambiguous becomes a separate entity with the alternatives REPORTED as
39
+ * candidates rather than silently merged.
40
+ *
41
+ * KNOWLEDGE IS CLAIMS, not a summary string. Each entity/edge/rule carries a
42
+ * `claims` ledger of per-origin description contributions; the stored
43
+ * `description` is DERIVED from it — the most recent contribution wins, because
44
+ * description length measures verbosity and not truth. That is what makes a
45
+ * correction expressible ("Now PostgreSQL" supersedes a longer MySQL blurb) and
46
+ * what makes rollback reversible: withdrawing an origin drops its contribution
47
+ * and RE-DERIVES the summary from the survivors, so the previous correct
48
+ * description comes back instead of a bad one being frozen in place.
49
+ * `origin_refs` remains, derived from the ledger, so provenance readers are
50
+ * unaffected. Support is never silently truncated: past `MAX_CLAIMS` the entry
51
+ * records `origins_dropped` and `provenance_complete:false`.
52
+ *
53
+ * EVIDENCE travels with the claim. Each contribution records how it was
54
+ * obtained — `asserted` when someone stated it, `heuristic` when
55
+ * `heuristicExtract` inferred it from two names sharing a sentence — and the
56
+ * element's standing is projected from its live claims, with one asserted claim
57
+ * outranking any number of guesses. A claim written before this recording
58
+ * leaves the projection UNKNOWN rather than voting: reading an unrecorded
59
+ * method as `asserted` would relabel the entire pre-existing graph as stated
60
+ * fact. Retrieval uses exactly this and the `conflict` flag to rank, and
61
+ * nothing else — source credibility and claim freshness need an evaluation set
62
+ * to tune against, and guessing at them is the overclaim this replaced.
63
+ *
64
+ * MIGRATION: nothing is re-keyed, deleted, or orphaned. An entry written under
65
+ * the old `n:<normalized-name>` scheme is still found — resolution falls back to
66
+ * probing the legacy key — and is then adopted IN PLACE under its existing key
67
+ * and registered in the name index. Legacy rows therefore keep working for
68
+ * search, stats, glossary and rollback, and keep their edges (whose keys embed
69
+ * the endpoint keys) intact. Only a genuinely NEW identity distinction — a
70
+ * second type for a name, or a name that differs only past the old truncation
71
+ * point — mints a new hashed id.
72
+ *
73
+ * // monolean: graph traversal is in-process over a paged kg:edges scan. The
74
+ * // bridge exposes no indexed adjacency (src/dst) or origin lookup, so every
75
+ * // neighbourhood/provenance question is a namespace scan; the upgrade path is
76
+ * // a real SQLite edges table with indexed src/dst/origin columns, which turns
77
+ * // these O(namespace) scans into O(matches). `kgStats` uses a real
78
+ * // `bridgeCountEntries` (SELECT COUNT(*) WHERE namespace = ?) instead of a
79
+ * // scan — that needs no history, a count is correct regardless of when a row
80
+ * // was written. Adjacency/origin, in contrast, is NOT filled in here: an
81
+ * // index built only from now on would silently miss every edge/claim written
82
+ * // before it existed (there is no legacy-key probe for an arbitrary historical
83
+ * // edge, unlike resolveEntity's single fallback key), so kgSearch/kgRollback
84
+ * // would go from an honest, complete scan to an INcomplete indexed answer —
85
+ * // a regression, not the fix. Closing this needs a real backfill/migration
86
+ * // decision (how to populate the index for existing namespaces, and how to
87
+ * // know when one is complete enough to trust), not more code here.
22
88
  *
23
89
  * @module v1/cli/memory/memory-kg
24
90
  */
25
91
  export declare const KG_NODES_NS = "kg:nodes";
26
92
  export declare const KG_EDGES_NS = "kg:edges";
27
93
  export declare const RULES_NS = "rules";
94
+ /** Name → entity index. Index rows are NOT claims, so they live outside the
95
+ * three claim namespaces: putting them in `kg:nodes` would make them seed
96
+ * candidates for `kgSearch` and rows in `kgStats`. */
97
+ export declare const KG_NAMES_NS = "kg:names";
98
+ /** Derived adjacency index namespace (K7). See `KgNamespaces.adj`. */
99
+ export declare const KG_ADJ_NS = "kg:adj";
100
+ /** Derived origin-support index namespace (K7). See `KgNamespaces.originIdx`. */
101
+ export declare const KG_ORIGIN_IDX_NS = "kg:origin-idx";
102
+ /** Derived-index status namespace (K7). See `KgNamespaces.indexStatus`. */
103
+ export declare const KG_INDEX_STATUS_NS = "kg:index-status";
104
+ /**
105
+ * Version of the identity scheme implemented by `entityId`/`edgeKey`/`ruleKey`.
106
+ *
107
+ * Bump when a derivation changes. Entries written under an older scheme are not
108
+ * orphaned: resolution probes the previous key shape and adopts the row in
109
+ * place (see `resolveEntity`), so a bump costs a second keyed lookup on the
110
+ * miss path rather than a migration.
111
+ *
112
+ * Version 1 was the name-only scheme (`n:<normalized-name>`, truncated to 200
113
+ * characters), under which `Person:Alex` and `Service:Alex` were one entity and
114
+ * two names first differing at character 250 were one entity.
115
+ */
116
+ export declare const KG_ID_VERSION = 2;
117
+ /** Mint an entity id from the full identity tuple.
118
+ *
119
+ * This MINTS; it does not RESOLVE. A caller that computes an id and writes to
120
+ * it bypasses the name index and re-forks the entities the index exists to
121
+ * keep together — every ingest path goes through `resolveEntity` instead. */
122
+ export declare function nodeKey(type: string, name: string): string;
28
123
  export interface KgNodeInput {
29
124
  name: string;
30
125
  /** Basic type, cognee-style ("Person", "Tool", "Service") — not over-specific. */
@@ -48,27 +143,137 @@ export interface KgIngestResult {
48
143
  nodesMerged: number;
49
144
  edgesAdded: number;
50
145
  edgesMerged: number;
146
+ /** Writes the bridge refused, one message each (capped at MAX_FAILURES).
147
+ * Non-empty ⇒ `success` is false and the counters describe only what
148
+ * actually persisted. */
149
+ failures?: string[];
51
150
  error?: string;
151
+ /** Items the payload asked for that this call refused. Present only when
152
+ * non-zero, so a caller who sent a clean payload sees a clean result. */
153
+ nodesRejected?: number;
154
+ edgesRejected?: number;
155
+ /** Items dropped because the payload exceeded the per-call cap. The cap has
156
+ * not changed; what has changed is that it is now REPORTED instead of being
157
+ * a silent `.slice()`. */
158
+ nodesTruncated?: number;
159
+ edgesTruncated?: number;
160
+ /** Why items were rejected, one message each (capped at MAX_FAILURES). */
161
+ rejections?: string[];
162
+ /** Endpoint entities created because an edge named them and they did not
163
+ * exist. Edge-only ingestion used to succeed with zero nodes and one edge,
164
+ * leaving a fact unreachable through both of its own endpoints. */
165
+ placeholders?: number;
166
+ /** Same-name entities this call did NOT merge with, one message each. A
167
+ * same-name match is a CANDIDATE, not a merge. */
168
+ ambiguities?: string[];
169
+ /** Elements whose support ledger hit `MAX_CLAIMS` on this call, so their
170
+ * oldest provenance was dropped. Never silent. */
171
+ provenanceTruncated?: number;
52
172
  }
53
173
  /** cognee DataPoint normalization: lowercase, spaces→_, strip apostrophes. */
54
174
  export declare function normalizeName(name: string): string;
55
- /** Identity is NAME-ONLY (cognee's Entity.identity_fields = ["name"]) — type
56
- * lives in metadata. Including type in the key forked the same entity when
57
- * the LLM said "Module" and the heuristic said "entity". */
58
- export declare function nodeKey(_type: string, name: string): string;
59
- /** Idempotently merge extracted nodes/edges into the KG. Same-name entities
60
- * collapse onto one node (deterministic key + upsert); origin_refs accumulate
61
- * so rollback can undo a single run's contribution. */
175
+ /** Who owns a set of graph facts. `org` absent = project-shared knowledge. */
176
+ export interface KgScope {
177
+ org?: string;
178
+ }
179
+ export interface KgNamespaces {
180
+ nodes: string;
181
+ edges: string;
182
+ rules: string;
183
+ /** Name → entity index backing `resolveEntity`. Holds no claims. */
184
+ names: string;
185
+ /** Derived adjacency index: entity id -> edge keys touching it (K7). Holds
186
+ * no claims either — every entry is rebuildable from `edges`. */
187
+ adj: string;
188
+ /** Derived origin-support index: origin ref -> {ns,key} refs it supports,
189
+ * across nodes/edges/rules (K7). Rebuildable from all three. */
190
+ originIdx: string;
191
+ /** This scope's derived-index build/readiness state (K7). One row. */
192
+ indexStatus: string;
193
+ }
194
+ /** The namespaces a scope owns. Every read and write in this module resolves
195
+ * through here, which is what makes ownership enforced rather than advisory:
196
+ * there is no code path that reaches an org's facts without naming that org,
197
+ * and none that reaches every org at once. */
198
+ export declare function kgNamespaces(scope?: KgScope): KgNamespaces;
199
+ /** Stamp the asserting org onto a provenance ref, so a claim's origin says WHO
200
+ * asserted it and not merely which run id — `run:m4x2` alone is ambiguous
201
+ * across orgs, and a promoted claim in the shared graph would otherwise carry
202
+ * an origin no one owns.
203
+ *
204
+ * Applied by the ingest/rollback entry points rather than by callers: a
205
+ * caller that forgets is exactly how ownership stopped being enforced. */
206
+ export declare function kgQualifyOrigin(originRef: string, scope?: KgScope): string;
207
+ /** How a claim came to exist.
208
+ *
209
+ * `asserted` — someone stated it: an LLM distillation, an explicit
210
+ * `memory_kg_ingest`, an org's `org_learn`.
211
+ * `heuristic` — `heuristicExtract` inferred it from two names appearing in one
212
+ * sentence. Nobody asserted it, and the module header has always called it
213
+ * lower-trust; until now nothing downstream could tell the two apart. */
214
+ export type KgExtractionMethod = 'asserted' | 'heuristic';
215
+ /** One origin's assertion about an element. An origin re-asserting replaces its
216
+ * own contribution — a run stands behind its latest word, not its first. */
217
+ export interface KgClaim {
218
+ origin: string;
219
+ description: string;
220
+ /** Assertion time, and the ordering that decides which claim is current. */
221
+ at: number;
222
+ /** Absent on rows written before extraction method was recorded. Absent means
223
+ * UNKNOWN, never `asserted` — defaulting an unrecorded method to the higher
224
+ * trust would relabel every old co-occurrence guess as a stated fact. */
225
+ method?: KgExtractionMethod;
226
+ }
227
+ /** An entity the name index knows about. */
228
+ export interface KgNameCandidate {
229
+ id: string;
230
+ /** Identity-bearing type bucket; '' for an entity asserted without a type. */
231
+ type: string;
232
+ }
233
+ /** Merge extracted nodes/edges into the KG.
234
+ *
235
+ * Identity is the (type, name) tuple resolved through the name index, so an
236
+ * entity is idempotent under re-extraction but two different things sharing a
237
+ * name stay two things. Each write adds this origin's CONTRIBUTION to the
238
+ * element's claim ledger, from which the description and `origin_refs` are
239
+ * derived — which is what lets a later ingest correct an earlier one and lets
240
+ * rollback put the earlier one back.
241
+ *
242
+ * The COMPLETE payload is validated before anything is written, and every edge
243
+ * endpoint is made to exist (as a placeholder entity when the caller named one
244
+ * that does not) before the edge lands. An edge whose endpoint could not be
245
+ * created is rejected rather than written: retrieval is seeded from nodes, so
246
+ * an edge with a missing endpoint is a fact that cannot be found through
247
+ * either of the things it is about.
248
+ *
249
+ * NOT ATOMIC — the memory bridge has no transaction primitive, so a failure
250
+ * part-way through leaves earlier writes persisted. The counters therefore
251
+ * report only what actually landed, `failures` lists what did not, and
252
+ * `success` is false whenever anything was refused. A partial ingest is safe
253
+ * to retry: every write is a keyed upsert. */
62
254
  export declare function kgIngest(options: {
63
255
  nodes: KgNodeInput[];
64
256
  edges?: KgEdgeInput[];
65
- /** Provenance: run id, session id, or doc hash this extraction came from. */
257
+ /** Provenance: run id, session id, or doc hash this extraction came from.
258
+ * Stored qualified by `scope` — see `kgQualifyOrigin`. */
66
259
  originRef: string;
260
+ /** Owner of these facts. Omit for project-shared knowledge. */
261
+ scope?: KgScope;
262
+ /** How this payload was produced. Defaults to `asserted`; `heuristicExtract`
263
+ * callers must pass `heuristic` so a co-occurrence guess is not stored as a
264
+ * stated fact. Recorded per origin, so the same element can hold a heuristic
265
+ * claim from one run and an asserted one from another. */
266
+ method?: KgExtractionMethod;
67
267
  dbPath?: string;
68
268
  }): Promise<KgIngestResult>;
69
269
  export interface RuleVerdict {
70
270
  rule: string;
71
- verdict: 'accepted' | 'already_known' | 'invalid';
271
+ /** `failed` — the candidate was fine, but a write the caller was told about
272
+ * did not land. It is neither `invalid` (which blames the caller's input)
273
+ * nor `accepted`/`already_known` (which claim the graph now holds it). Both
274
+ * of those used to be reported unconditionally, so a caller reading verdicts
275
+ * saw every rule land while the aggregate `accepted` count said zero. */
276
+ verdict: 'accepted' | 'already_known' | 'invalid' | 'failed';
72
277
  similarTo?: string;
73
278
  }
74
279
  /** Stage-2 of cognee's curator/writer distillation: the CALLER (an LLM agent)
@@ -76,13 +281,23 @@ export interface RuleVerdict {
76
281
  * near-identical rule exists (embedding dedup — deterministic keys can't
77
282
  * collapse paraphrases). Accepted rules are stored both as KG nodes
78
283
  * (node_set=rules) and as plain `rules`-namespace entries so the existing
79
- * injection/search surfaces pick them up with zero new plumbing. */
284
+ * injection/search surfaces pick them up with zero new plumbing.
285
+ *
286
+ * A candidate that dedups against an existing rule still ADDS its origin to
287
+ * that rule's support set: two independent runs asserting the same rule mean
288
+ * the rule survives either one being rolled back. Dropping the second origin
289
+ * (as this used to) made rollback of the FIRST run delete knowledge the
290
+ * second run independently vouched for.
291
+ *
292
+ * Like `kgIngest`, NOT atomic — see that function's note. */
80
293
  export declare function kgIngestRules(options: {
81
294
  rules: {
82
295
  rule: string;
83
296
  context?: string;
84
297
  }[];
85
298
  originRef: string;
299
+ /** Owner of these rules. Omit for project-shared knowledge. */
300
+ scope?: KgScope;
86
301
  dbPath?: string;
87
302
  /** Similarity above which a candidate is already_known (default 0.78 —
88
303
  * MiniLM paraphrases of the same rule commonly land 0.78-0.9; cognee's
@@ -92,12 +307,17 @@ export declare function kgIngestRules(options: {
92
307
  success: boolean;
93
308
  verdicts: RuleVerdict[];
94
309
  accepted: number;
310
+ failures?: string[];
95
311
  error?: string;
312
+ /** Candidates dropped by the per-call cap, reported rather than sliced away
313
+ * in silence. */
314
+ rulesTruncated?: number;
96
315
  }>;
97
316
  /** List stored rules (for injection or review). */
98
317
  export declare function kgListRules(options?: {
99
318
  dbPath?: string;
100
319
  limit?: number;
320
+ scope?: KgScope;
101
321
  }): Promise<{
102
322
  rule: string;
103
323
  key: string;
@@ -112,6 +332,18 @@ export interface KgSearchResult {
112
332
  target: string;
113
333
  fact: string;
114
334
  score: number;
335
+ /** How this edge came to exist. Absent means the edge predates method
336
+ * recording — not recorded, which is not the same as `asserted`. */
337
+ method?: KgExtractionMethod;
338
+ /** Live origins disagree about what this edge says. Present only when true. */
339
+ conflict?: boolean;
340
+ /** The edge's bridge entry id — feed this straight to `memory_feedback`
341
+ * (`bridgeApplyFeedback`/`bridgeRecordUsage`) to rate THIS relationship
342
+ * directly, rather than only the seed entity that surfaced it (K5). */
343
+ id: string;
344
+ /** The edge's stable graph key (`e:<hash>`, see `edgeKey`), for direct
345
+ * `bridgeGetEntry` lookup or diagnostics — distinct from `id` above. */
346
+ key: string;
115
347
  }[];
116
348
  seeds: {
117
349
  name: string;
@@ -120,33 +352,117 @@ export interface KgSearchResult {
120
352
  score: number;
121
353
  id: string;
122
354
  }[];
355
+ /** True when the edge scan did NOT cover the whole namespace — the scan hit
356
+ * `SEARCH_EDGE_SCAN_MAX`, or the backend became unreadable partway. A
357
+ * relationship that exists may be missing from `triplets`; absence here is
358
+ * not evidence of absence in the graph. */
359
+ truncated?: boolean;
360
+ /** Edge rows actually read, so a caller can see how close it ran to the cap. */
361
+ scannedEdges?: number;
362
+ /** What the seed retrieval ACTUALLY ran, straight from the bridge — never what
363
+ * was hoped for. `keyword-fallback` means the vector path was tried and did
364
+ * not serve these results. Absent only when the bridge reported nothing. */
365
+ method?: 'semantic' | 'keyword' | 'keyword-fallback';
366
+ /** Why the vector path did not serve the seeds (absent when it did). */
367
+ fallbackReason?: string;
123
368
  error?: string;
124
369
  }
125
- /** Vector-seed → neighborhood → triplet ranking (cognee's brute-force triplet
126
- * search, scaled down). Seed scores already carry the Phase 1 feedback blend. */
370
+ /** Seeded retrieval → neighborhood → triplet ranking (cognee's brute-force
371
+ * triplet search, scaled down). Seed scores already carry the Phase 1 feedback
372
+ * blend, and the seed retrieval may be vector or keyword — `method` on the
373
+ * result says which actually ran.
374
+ *
375
+ * Ranking weighs exactly two evidence signals, both read off the claim ledger:
376
+ * extraction method and description conflict. It deliberately does NOT model
377
+ * source credibility, claim freshness, or whether the relation itself answers
378
+ * the query — those need an evaluation set to tune against, and guessing at
379
+ * them would be the same overclaim this weighting exists to correct. */
127
380
  export declare function kgSearch(options: {
128
381
  query: string;
129
382
  dbPath?: string;
130
383
  limit?: number;
131
384
  nodeSet?: string;
385
+ /** Whose graph to search. Omit for project-shared knowledge; a scoped search
386
+ * never reaches another org's facts, and never the shared graph either. */
387
+ scope?: KgScope;
132
388
  }): Promise<KgSearchResult>;
133
389
  export declare function kgGlossary(options?: {
134
390
  dbPath?: string;
135
391
  limit?: number;
392
+ /** Whose entity names to offer. The coordinator glossary MUST be scoped:
393
+ * suggesting another org's entity names is how one org's claims get merged
394
+ * into another's graph under a shared name. */
395
+ scope?: KgScope;
136
396
  }): Promise<string[]>;
137
- /** Delete every node/edge/rule whose ONLY origin is `originRef`. Elements with
138
- * other origins survive (shared knowledge isn't destroyed by one bad run);
139
- * their origin lists retain the ref — acceptable residue.
140
- * // monolean: no origin-list rewrite — needs an update-by-id bridge API */
397
+ /** Withdraw `originRef`'s support from the graph: remove it from every
398
+ * node/edge/rule it backs, and delete the element once no origin remains.
399
+ *
400
+ * The withdrawn ref is REWRITTEN out of the surviving elements' origin lists,
401
+ * not left behind. Retaining it (as this used to) meant a second rollback saw
402
+ * a two-entry list and retained again — so an element could outlive the
403
+ * withdrawal of every origin that ever supported it.
404
+ *
405
+ * The scan is EXHAUSTIVE: it pages each namespace to the end rather than
406
+ * reading one capped list. A capped scan let an element past the cap keep a
407
+ * withdrawn origin while the caller was told the rollback succeeded.
408
+ *
409
+ * Collect-then-mutate is deliberate: deleting a row pulls every later row back
410
+ * one position, so a delete inside the page loop would make an advancing
411
+ * offset skip whatever slid into the gap. (Rewrites are no longer a hazard —
412
+ * the bridge's upsert reuses the existing entry id and preserves `createdAt`
413
+ * rather than re-inserting at the head of the default ordering — but this
414
+ * function deletes as well as rewrites.) Only origin-carrying entries are
415
+ * retained during the scan, so memory tracks the rollback's own footprint, not
416
+ * the namespace size. */
141
417
  export declare function kgRollback(options: {
142
418
  originRef: string;
419
+ /** Whose knowledge to withdraw from. A rollback can only reach the named
420
+ * scope's namespaces — an org's rollback is an ownership boundary, not just
421
+ * a label on the output. */
422
+ scope?: KgScope;
143
423
  dbPath?: string;
144
424
  }): Promise<{
145
425
  success: boolean;
146
426
  deleted: number;
147
427
  retained: number;
428
+ failures?: string[];
148
429
  error?: string;
430
+ /** Edges deleted because this rollback removed an endpoint they name. A
431
+ * relation between two things is not a fact once one of them is gone, and
432
+ * retrieval is node-seeded, so leaving them behind left unreachable rows
433
+ * claiming a graph that no longer exists. */
434
+ danglingEdgesRemoved?: number;
149
435
  }>;
436
+ export interface KgPromoteResult {
437
+ success: boolean;
438
+ nodes: number;
439
+ edges: number;
440
+ rules: number;
441
+ /** Origin the shared copy carries, so the promotion can be withdrawn on its
442
+ * own and the shared graph records who shared the claim. */
443
+ promotedAs: string;
444
+ failures?: string[];
445
+ error?: string;
446
+ }
447
+ /** Copy one origin's claims out of an org's scope into project-shared
448
+ * knowledge.
449
+ *
450
+ * Sharing is deliberate, never a side effect of learning: `kgIngest` under a
451
+ * scope only ever writes that org's namespaces, and this is the one path a
452
+ * claim takes across the boundary. The org keeps its own copy untouched — the
453
+ * shared copy is an INDEPENDENT assertion under `promoted:<org-ref>`, so
454
+ * rolling back either side leaves the other standing, and a shared claim
455
+ * always names the org that vouched for it.
456
+ *
457
+ * Like ingest, NOT atomic: the counters report what actually landed. */
458
+ export declare function kgPromote(options: {
459
+ /** The org-side ref to promote, unqualified (e.g. `run:m4x2`). */
460
+ originRef: string;
461
+ /** Owner the claims are promoted FROM. Promoting from the shared scope is a
462
+ * no-op and is refused rather than silently duplicating. */
463
+ from: KgScope;
464
+ dbPath?: string;
465
+ }): Promise<KgPromoteResult>;
150
466
  export interface ConsolidationCandidate {
151
467
  name: string;
152
468
  type: string;
@@ -157,26 +473,177 @@ export interface ConsolidationCandidate {
157
473
  }
158
474
  /** Entities whose descriptions are stale relative to their connectivity —
159
475
  * the LLM half runs in the LIVE agent: it rewrites each candidate's
160
- * description from the neighborhood facts and resubmits via memory_kg_ingest
161
- * (longer descriptions win on merge). No LLM here (fully local constraint). */
476
+ * description from the neighborhood facts and resubmits via memory_kg_ingest.
477
+ * A resubmission is a NEW contribution and therefore the current one, so a
478
+ * shorter but better-supported summary now wins; under "longest description
479
+ * wins" a consolidation that tightened the prose was silently discarded.
480
+ * No LLM here (fully local constraint). */
162
481
  export declare function kgConsolidateCandidates(options?: {
163
482
  dbPath?: string;
164
483
  /** Minimum edges for a node to qualify (default 3). */
165
484
  minEdges?: number;
166
485
  limit?: number;
486
+ scope?: KgScope;
167
487
  }): Promise<ConsolidationCandidate[]>;
488
+ /** Real counts, not page lengths. `bridgeListEntries.total` reports how many
489
+ * rows that one call returned, so the old capped list made a 10,001-node graph
490
+ * report exactly 10,000 forever.
491
+ *
492
+ * Tries a real indexed `SELECT COUNT(*) WHERE namespace = ?` first
493
+ * (`bridgeCountEntries`, K7) — cheap and exact, since every row in a KG
494
+ * namespace is exactly one node/edge/rule (the name index lives in its own
495
+ * namespace). Falls back to the paginated scan — one query per 1,000 rows,
496
+ * still exact — when the loaded bridge predates `bridgeCountEntries`, or a
497
+ * test double doesn't stub it. */
168
498
  export declare function kgStats(options?: {
169
499
  dbPath?: string;
500
+ /** Whose graph to measure. Counting every org's facts under one org's name
501
+ * is what made `org memory <name> stats` a fiction. */
502
+ scope?: KgScope;
170
503
  }): Promise<{
171
504
  nodes: number;
172
505
  edges: number;
173
506
  rules: number;
174
507
  }>;
508
+ export interface KgReferenceEdge {
509
+ key: string;
510
+ src: string;
511
+ dst: string;
512
+ relation: string;
513
+ originRefs: string[];
514
+ }
515
+ /** Complete, uncapped read of every edge touching `endpointId` (as either
516
+ * src or dst) and/or asserted by `originRef` — at least one filter is
517
+ * required. This is the ground truth an indexed adjacency/origin lookup
518
+ * (K7) must agree with once one exists: an exhaustive paged scan, the same
519
+ * mechanism `kgRollback` already trusts for origin withdrawal, so it never
520
+ * depends on an index and never inherits the old first-page cap.
521
+ *
522
+ * `truncated: true` means the scan did not finish — an incomplete answer,
523
+ * never an empty one. Callers comparing this against a future index must
524
+ * treat a truncated reference read as "unknown", not as "no matches". */
525
+ export declare function kgReferenceEdges(options: {
526
+ endpointId?: string;
527
+ originRef?: string;
528
+ scope?: KgScope;
529
+ dbPath?: string;
530
+ }): Promise<{
531
+ success: boolean;
532
+ edges: KgReferenceEdge[];
533
+ truncated?: boolean;
534
+ error?: string;
535
+ }>;
536
+ export type KgIndexState = 'absent' | 'building' | 'validating' | 'ready' | 'failed';
537
+ export interface KgIndexStatus {
538
+ state: KgIndexState;
539
+ schemaVersion: number;
540
+ /** Resume point for an interrupted `kgRebuildIndex`. */
541
+ cursor?: {
542
+ phase: 'nodes' | 'edges' | 'rules';
543
+ offset: number;
544
+ };
545
+ counts?: {
546
+ nodes: number;
547
+ edges: number;
548
+ rules: number;
549
+ };
550
+ startedAt?: number;
551
+ updatedAt?: number;
552
+ error?: string;
553
+ /** Only meaningful when `state === 'failed'`. True for a build-phase
554
+ * failure (the backend went unavailable mid-scan, or a dual-write hook
555
+ * hit an error after `ready`): everything already written is still
556
+ * correct, just incomplete, so the next call RESUMES from `cursor`. False
557
+ * for a validation-phase failure (the built index disagreed with an
558
+ * independent reference read): something already written is wrong, not
559
+ * merely incomplete, so the next call restarts a fresh scan — resuming
560
+ * would re-derive the same mistake instead of correcting it. */
561
+ resumable?: boolean;
562
+ }
563
+ /** This scope's derived-index build/readiness state. `absent` means no one
564
+ * has ever called `kgRebuildIndex` for it — every read behaves exactly as
565
+ * it did before this index existed. */
566
+ export declare function kgIndexStatus(options?: {
567
+ scope?: KgScope;
568
+ dbPath?: string;
569
+ }): Promise<KgIndexStatus>;
570
+ export interface KgRebuildResult {
571
+ success: boolean;
572
+ status: KgIndexStatus;
573
+ validation?: {
574
+ sampledEntities: number;
575
+ sampledOrigins: number;
576
+ full: boolean;
577
+ };
578
+ error?: string;
579
+ }
580
+ /** (Re)build a scope's derived index from canonical data — nodes, then
581
+ * edges, then rules, that fixed order, resuming from the last checkpointed
582
+ * `{phase, offset}` rather than restarting when a prior call was
583
+ * interrupted mid-build. Every write here (`addToAdj`/`addToOriginIndex`)
584
+ * is idempotent, so a page reprocessed after an interruption cannot
585
+ * duplicate an entry.
586
+ *
587
+ * A concurrent ingest/rollback during the build is safe, not just tolerated:
588
+ * the dual-write hooks run whenever state is not `absent`/`failed`, so a
589
+ * write made mid-build is captured whether or not the scan has reached that
590
+ * row yet — at worst twice, which idempotency absorbs for free. The one
591
+ * residual race (a row deleted between the scan reading it and the scan's
592
+ * own write landing) can leave a dangling ref in the index; it is never
593
+ * observable as wrong data, because every indexed READ
594
+ * (`kgIndexedEdgesByEndpoint`/`kgIndexedByOrigin`) returns `null` — and the
595
+ * caller falls back to the exhaustive scan — the instant it cannot resolve
596
+ * a ref it holds. This is the backend's real capability (single-row CAS,
597
+ * no cross-row transaction), used honestly rather than claiming atomicity
598
+ * it cannot provide.
599
+ *
600
+ * Ends in `validating`: samples up to `VALIDATE_SAMPLE` of the entities and
601
+ * origins the scan actually saw, and re-reads them through the just-built
602
+ * index, comparing against a FRESH, independent reference read
603
+ * (`kgReferenceEdges`/`collectByOrigin`) — not the in-memory data the build
604
+ * itself computed, which would only prove the build agrees with itself. A
605
+ * write that silently failed, or a concurrent change the dual-write hooks
606
+ * missed, is exactly what this catches before the index is ever trusted. */
607
+ export declare function kgRebuildIndex(options?: {
608
+ scope?: KgScope;
609
+ dbPath?: string;
610
+ }): Promise<KgRebuildResult>;
611
+ export interface KgIntegrityResult {
612
+ success: boolean;
613
+ edges: number;
614
+ /** Edges naming an endpoint that does not exist. Retrieval is node-seeded,
615
+ * so such an edge is a fact unreachable through either of the things it is
616
+ * about — it can only be found by a check like this one. */
617
+ dangling: {
618
+ key: string;
619
+ missing: string[];
620
+ }[];
621
+ /** True when the edge scan did not cover the namespace: absence of a dangling
622
+ * edge here is then not evidence that there is none. */
623
+ truncated?: boolean;
624
+ error?: string;
625
+ }
626
+ /** Verify that every edge's endpoints exist.
627
+ *
628
+ * `kgIngest` now creates missing endpoints before writing an edge and
629
+ * `kgRollback` removes edges whose endpoints it deleted, so a healthy graph
630
+ * reports nothing. This exists for graphs written before either rule, and as
631
+ * the check that says so rather than assuming it. */
632
+ export declare function kgIntegrityCheck(options?: {
633
+ dbPath?: string;
634
+ scope?: KgScope;
635
+ /** Dangling edges to report before stopping (default 100). */
636
+ limit?: number;
637
+ }): Promise<KgIntegrityResult>;
175
638
  /** Regex extraction for when no LLM is in the loop (memory-palace lineage):
176
639
  * proper-noun phrases and `code identifiers` become entities, sentence
177
- * co-occurrence becomes relates_to edges. Lower-trust by design — real
640
+ * co-occurrence becomes `mentioned_with` edges. Lower-trust by design — real
178
641
  * entity/relation quality comes from the LLM path (memory_kg_ingest called
179
- * by the live agent, or the org coordinator's org_learn tool). */
642
+ * by the live agent, or the org coordinator's org_learn tool).
643
+ *
644
+ * Callers MUST ingest this with `method: 'heuristic'`. "Lower-trust by design"
645
+ * was true and unenforced: nothing downstream could tell these edges from
646
+ * facts an agent stated, so ranking treated them identically. */
180
647
  export declare function heuristicExtract(text: string, opts?: {
181
648
  sourceName?: string;
182
649
  }): {