@monoes/monomindcli 2.16.11 → 2.16.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 (225) hide show
  1. package/.claude/agents/core/coder.md +1 -1
  2. package/.claude/agents/engineering/engineering-devops-automator.md +1 -1
  3. package/.claude/agents/github/repo-architect.md +1 -1
  4. package/.claude/agents/testing/production-validator.md +1 -1
  5. package/.claude/agents/testing/testing-tool-evaluator.md +1 -1
  6. package/.claude/commands/github/pr-manager.md +1 -1
  7. package/.claude/helpers/pick-rank.cjs +34 -4
  8. package/.claude/skills/monolean-audit/SKILL.md +1 -1
  9. package/dist/src/commands/cleanup-data.d.ts +30 -0
  10. package/dist/src/commands/cleanup-data.d.ts.map +1 -0
  11. package/dist/src/commands/cleanup-data.js +138 -0
  12. package/dist/src/commands/cleanup-data.js.map +1 -0
  13. package/dist/src/commands/cleanup-origin.d.ts +24 -0
  14. package/dist/src/commands/cleanup-origin.d.ts.map +1 -0
  15. package/dist/src/commands/cleanup-origin.js +67 -0
  16. package/dist/src/commands/cleanup-origin.js.map +1 -0
  17. package/dist/src/commands/cleanup-scratch.d.ts +43 -0
  18. package/dist/src/commands/cleanup-scratch.d.ts.map +1 -0
  19. package/dist/src/commands/cleanup-scratch.js +125 -0
  20. package/dist/src/commands/cleanup-scratch.js.map +1 -0
  21. package/dist/src/commands/cleanup.d.ts +2 -39
  22. package/dist/src/commands/cleanup.d.ts.map +1 -1
  23. package/dist/src/commands/cleanup.js +9 -296
  24. package/dist/src/commands/cleanup.js.map +1 -1
  25. package/dist/src/commands/doctor-gitignore-checks.d.ts +10 -0
  26. package/dist/src/commands/doctor-gitignore-checks.d.ts.map +1 -0
  27. package/dist/src/commands/doctor-gitignore-checks.js +141 -0
  28. package/dist/src/commands/doctor-gitignore-checks.js.map +1 -0
  29. package/dist/src/commands/doctor-helpers-checks.d.ts +10 -0
  30. package/dist/src/commands/doctor-helpers-checks.d.ts.map +1 -0
  31. package/dist/src/commands/doctor-helpers-checks.js +292 -0
  32. package/dist/src/commands/doctor-helpers-checks.js.map +1 -0
  33. package/dist/src/commands/doctor-memory-checks.d.ts +47 -0
  34. package/dist/src/commands/doctor-memory-checks.d.ts.map +1 -0
  35. package/dist/src/commands/doctor-memory-checks.js +298 -0
  36. package/dist/src/commands/doctor-memory-checks.js.map +1 -0
  37. package/dist/src/commands/doctor-monograph-checks.d.ts +9 -0
  38. package/dist/src/commands/doctor-monograph-checks.d.ts.map +1 -0
  39. package/dist/src/commands/doctor-monograph-checks.js +331 -0
  40. package/dist/src/commands/doctor-monograph-checks.js.map +1 -0
  41. package/dist/src/commands/doctor-project-checks.d.ts +7 -66
  42. package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
  43. package/dist/src/commands/doctor-project-checks.js +10 -1331
  44. package/dist/src/commands/doctor-project-checks.js.map +1 -1
  45. package/dist/src/commands/doctor-routing-checks.d.ts +10 -0
  46. package/dist/src/commands/doctor-routing-checks.d.ts.map +1 -0
  47. package/dist/src/commands/doctor-routing-checks.js +194 -0
  48. package/dist/src/commands/doctor-routing-checks.js.map +1 -0
  49. package/dist/src/commands/doctor-worker-checks.d.ts +17 -0
  50. package/dist/src/commands/doctor-worker-checks.d.ts.map +1 -0
  51. package/dist/src/commands/doctor-worker-checks.js +122 -0
  52. package/dist/src/commands/doctor-worker-checks.js.map +1 -0
  53. package/dist/src/commands/hooks-routing-commands.js +1 -1
  54. package/dist/src/commands/hooks-routing-commands.js.map +1 -1
  55. package/dist/src/commands/init.d.ts.map +1 -1
  56. package/dist/src/commands/init.js +6 -15
  57. package/dist/src/commands/init.js.map +1 -1
  58. package/dist/src/index.js +2 -2
  59. package/dist/src/index.js.map +1 -1
  60. package/dist/src/init/never-commit.d.ts +3 -3
  61. package/dist/src/init/types.d.ts +1 -1
  62. package/dist/src/init/types.js +1 -1
  63. package/dist/src/knowledge/document-store.js +1 -1
  64. package/dist/src/knowledge/document-store.js.map +1 -1
  65. package/dist/src/mcp-tools/hooks-edit-command.d.ts +10 -0
  66. package/dist/src/mcp-tools/hooks-edit-command.d.ts.map +1 -0
  67. package/dist/src/mcp-tools/hooks-edit-command.js +247 -0
  68. package/dist/src/mcp-tools/hooks-edit-command.js.map +1 -0
  69. package/dist/src/mcp-tools/hooks-learning.d.ts +9 -0
  70. package/dist/src/mcp-tools/hooks-learning.d.ts.map +1 -0
  71. package/dist/src/mcp-tools/hooks-learning.js +408 -0
  72. package/dist/src/mcp-tools/hooks-learning.js.map +1 -0
  73. package/dist/src/mcp-tools/hooks-metrics-list.d.ts +8 -0
  74. package/dist/src/mcp-tools/hooks-metrics-list.d.ts.map +1 -0
  75. package/dist/src/mcp-tools/hooks-metrics-list.js +205 -0
  76. package/dist/src/mcp-tools/hooks-metrics-list.js.map +1 -0
  77. package/dist/src/mcp-tools/hooks-route.d.ts +12 -0
  78. package/dist/src/mcp-tools/hooks-route.d.ts.map +1 -0
  79. package/dist/src/mcp-tools/hooks-route.js +251 -0
  80. package/dist/src/mcp-tools/hooks-route.js.map +1 -0
  81. package/dist/src/mcp-tools/hooks-routing.d.ts +6 -27
  82. package/dist/src/mcp-tools/hooks-routing.d.ts.map +1 -1
  83. package/dist/src/mcp-tools/hooks-routing.js +6 -1727
  84. package/dist/src/mcp-tools/hooks-routing.js.map +1 -1
  85. package/dist/src/mcp-tools/hooks-session.d.ts +9 -0
  86. package/dist/src/mcp-tools/hooks-session.d.ts.map +1 -0
  87. package/dist/src/mcp-tools/hooks-session.js +243 -0
  88. package/dist/src/mcp-tools/hooks-session.js.map +1 -0
  89. package/dist/src/mcp-tools/hooks-task.d.ts +17 -0
  90. package/dist/src/mcp-tools/hooks-task.d.ts.map +1 -0
  91. package/dist/src/mcp-tools/hooks-task.js +427 -0
  92. package/dist/src/mcp-tools/hooks-task.js.map +1 -0
  93. package/dist/src/mcp-tools/hooks-tools.d.ts +2 -1
  94. package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
  95. package/dist/src/mcp-tools/hooks-tools.js +2 -1
  96. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  97. package/dist/src/mcp-tools/memory-tools.js +1 -1
  98. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  99. package/dist/src/memory/bm25-index.d.ts +2 -2
  100. package/dist/src/memory/bm25-index.js +2 -2
  101. package/dist/src/memory/embedding-operations.js +2 -2
  102. package/dist/src/memory/embedding-operations.js.map +1 -1
  103. package/dist/src/memory/entity-name-key.d.ts +1 -1
  104. package/dist/src/memory/entity-name-key.js +1 -1
  105. package/dist/src/memory/hnsw-operations.d.ts +1 -1
  106. package/dist/src/memory/hnsw-operations.js +1 -1
  107. package/dist/src/memory/memory-bridge-backend.d.ts +43 -0
  108. package/dist/src/memory/memory-bridge-backend.d.ts.map +1 -0
  109. package/dist/src/memory/memory-bridge-backend.js +363 -0
  110. package/dist/src/memory/memory-bridge-backend.js.map +1 -0
  111. package/dist/src/memory/memory-bridge-core.d.ts +42 -0
  112. package/dist/src/memory/memory-bridge-core.d.ts.map +1 -0
  113. package/dist/src/memory/memory-bridge-core.js +126 -0
  114. package/dist/src/memory/memory-bridge-core.js.map +1 -0
  115. package/dist/src/memory/memory-bridge-entries.d.ts +131 -0
  116. package/dist/src/memory/memory-bridge-entries.d.ts.map +1 -0
  117. package/dist/src/memory/memory-bridge-entries.js +227 -0
  118. package/dist/src/memory/memory-bridge-entries.js.map +1 -0
  119. package/dist/src/memory/memory-bridge-feedback.d.ts +60 -0
  120. package/dist/src/memory/memory-bridge-feedback.d.ts.map +1 -0
  121. package/dist/src/memory/memory-bridge-feedback.js +118 -0
  122. package/dist/src/memory/memory-bridge-feedback.js.map +1 -0
  123. package/dist/src/memory/memory-bridge-paths.d.ts +123 -0
  124. package/dist/src/memory/memory-bridge-paths.d.ts.map +1 -0
  125. package/dist/src/memory/memory-bridge-paths.js +335 -0
  126. package/dist/src/memory/memory-bridge-paths.js.map +1 -0
  127. package/dist/src/memory/memory-bridge-search.d.ts +48 -0
  128. package/dist/src/memory/memory-bridge-search.d.ts.map +1 -0
  129. package/dist/src/memory/memory-bridge-search.js +383 -0
  130. package/dist/src/memory/memory-bridge-search.js.map +1 -0
  131. package/dist/src/memory/memory-bridge-sessions.d.ts +38 -0
  132. package/dist/src/memory/memory-bridge-sessions.d.ts.map +1 -0
  133. package/dist/src/memory/memory-bridge-sessions.js +109 -0
  134. package/dist/src/memory/memory-bridge-sessions.js.map +1 -0
  135. package/dist/src/memory/memory-bridge-store.d.ts +58 -0
  136. package/dist/src/memory/memory-bridge-store.d.ts.map +1 -0
  137. package/dist/src/memory/memory-bridge-store.js +201 -0
  138. package/dist/src/memory/memory-bridge-store.js.map +1 -0
  139. package/dist/src/memory/memory-bridge.d.ts +10 -438
  140. package/dist/src/memory/memory-bridge.d.ts.map +1 -1
  141. package/dist/src/memory/memory-bridge.js +14 -1787
  142. package/dist/src/memory/memory-bridge.js.map +1 -1
  143. package/dist/src/memory/memory-kg-claims.d.ts +52 -0
  144. package/dist/src/memory/memory-kg-claims.d.ts.map +1 -0
  145. package/dist/src/memory/memory-kg-claims.js +99 -0
  146. package/dist/src/memory/memory-kg-claims.js.map +1 -0
  147. package/dist/src/memory/memory-kg-index.d.ts +86 -0
  148. package/dist/src/memory/memory-kg-index.d.ts.map +1 -0
  149. package/dist/src/memory/memory-kg-index.js +256 -0
  150. package/dist/src/memory/memory-kg-index.js.map +1 -0
  151. package/dist/src/memory/memory-kg-ingest.d.ts +44 -0
  152. package/dist/src/memory/memory-kg-ingest.d.ts.map +1 -0
  153. package/dist/src/memory/memory-kg-ingest.js +361 -0
  154. package/dist/src/memory/memory-kg-ingest.js.map +1 -0
  155. package/dist/src/memory/memory-kg-model.d.ts +168 -0
  156. package/dist/src/memory/memory-kg-model.d.ts.map +1 -0
  157. package/dist/src/memory/memory-kg-model.js +158 -0
  158. package/dist/src/memory/memory-kg-model.js.map +1 -0
  159. package/dist/src/memory/memory-kg-names.d.ts +64 -0
  160. package/dist/src/memory/memory-kg-names.d.ts.map +1 -0
  161. package/dist/src/memory/memory-kg-names.js +187 -0
  162. package/dist/src/memory/memory-kg-names.js.map +1 -0
  163. package/dist/src/memory/memory-kg-promote.d.ts +79 -0
  164. package/dist/src/memory/memory-kg-promote.d.ts.map +1 -0
  165. package/dist/src/memory/memory-kg-promote.js +248 -0
  166. package/dist/src/memory/memory-kg-promote.js.map +1 -0
  167. package/dist/src/memory/memory-kg-rebuild.d.ts +77 -0
  168. package/dist/src/memory/memory-kg-rebuild.d.ts.map +1 -0
  169. package/dist/src/memory/memory-kg-rebuild.js +299 -0
  170. package/dist/src/memory/memory-kg-rebuild.js.map +1 -0
  171. package/dist/src/memory/memory-kg-rollback.d.ts +47 -0
  172. package/dist/src/memory/memory-kg-rollback.d.ts.map +1 -0
  173. package/dist/src/memory/memory-kg-rollback.js +193 -0
  174. package/dist/src/memory/memory-kg-rollback.js.map +1 -0
  175. package/dist/src/memory/memory-kg-rules.d.ts +64 -0
  176. package/dist/src/memory/memory-kg-rules.d.ts.map +1 -0
  177. package/dist/src/memory/memory-kg-rules.js +251 -0
  178. package/dist/src/memory/memory-kg-rules.js.map +1 -0
  179. package/dist/src/memory/memory-kg-scan.d.ts +118 -0
  180. package/dist/src/memory/memory-kg-scan.d.ts.map +1 -0
  181. package/dist/src/memory/memory-kg-scan.js +209 -0
  182. package/dist/src/memory/memory-kg-scan.js.map +1 -0
  183. package/dist/src/memory/memory-kg-search.d.ts +80 -0
  184. package/dist/src/memory/memory-kg-search.d.ts.map +1 -0
  185. package/dist/src/memory/memory-kg-search.js +239 -0
  186. package/dist/src/memory/memory-kg-search.js.map +1 -0
  187. package/dist/src/memory/memory-kg.d.ts +19 -547
  188. package/dist/src/memory/memory-kg.d.ts.map +1 -1
  189. package/dist/src/memory/memory-kg.js +10 -2389
  190. package/dist/src/memory/memory-kg.js.map +1 -1
  191. package/dist/src/orgrt/sandbox-stubs.d.ts +4 -0
  192. package/dist/src/orgrt/sandbox-stubs.d.ts.map +1 -1
  193. package/dist/src/orgrt/sandbox-stubs.js +12 -2
  194. package/dist/src/orgrt/sandbox-stubs.js.map +1 -1
  195. package/dist/src/ui/org-hil.mjs +1 -1
  196. package/dist/src/ui/routes-org-agents.mjs +318 -0
  197. package/dist/src/ui/routes-org-approvals.mjs +133 -0
  198. package/dist/src/ui/routes-org-config.mjs +459 -0
  199. package/dist/src/ui/routes-org-control.mjs +300 -0
  200. package/dist/src/ui/routes-org-files.mjs +172 -0
  201. package/dist/src/ui/routes-org-helpers.mjs +84 -0
  202. package/dist/src/ui/routes-org-knowledge.mjs +262 -0
  203. package/dist/src/ui/routes-org-lifecycle.mjs +224 -0
  204. package/dist/src/ui/routes-org-live.mjs +278 -0
  205. package/dist/src/ui/routes-org-mastermind.mjs +346 -0
  206. package/dist/src/ui/routes-org-planning.mjs +398 -0
  207. package/dist/src/ui/routes-org-runs.mjs +430 -0
  208. package/dist/src/ui/routes-org-status.mjs +342 -0
  209. package/dist/src/ui/routes-org-workflows.mjs +212 -0
  210. package/dist/src/ui/routes-org.mjs +26 -3847
  211. package/dist/src/ui/server.mjs +1 -1
  212. package/dist/src/utils/native-error.d.ts +1 -1
  213. package/dist/src/utils/native-error.js +1 -1
  214. package/dist/src/utils/paths.d.ts +2 -1
  215. package/dist/src/utils/paths.d.ts.map +1 -1
  216. package/dist/src/utils/paths.js +2 -1
  217. package/dist/src/utils/paths.js.map +1 -1
  218. package/dist/tsconfig.tsbuildinfo +1 -1
  219. package/org-skills/adversarial-reviewer/SKILL.md +1 -1
  220. package/org-skills/board-deck-builder/SKILL.md +1 -1
  221. package/org-skills/code-reviewer/SKILL.md +1 -1
  222. package/org-skills/debugging-wizard/SKILL.md +1 -1
  223. package/org-skills/scientific-thinking-literature-review/SKILL.md +1 -1
  224. package/org-skills/scientific-thinking-scholar-evaluation/SKILL.md +1 -1
  225. package/package.json +8 -8
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Memory Knowledge Graph — exhaustive paged namespace scans, write-failure
3
+ * reporting and CAS retry, per-origin collection, and the K7 reference edge
4
+ * lookup. Split out of memory-kg.ts, which re-exports the public symbols.
5
+ */
6
+ import { bridgeListEntries, type bridgeStoreEntry } from './memory-bridge.js';
7
+ import type { KgScope } from './memory-kg-model.js';
8
+ /** Rows per `bridgeListEntries` call while scanning a namespace.
9
+ *
10
+ * A single list call cannot return more than the backend's own 10,000-row
11
+ * ceiling (`MAX_QUERY_LIMIT` in sql-backend.ts), so the old `limit: MAX_LIST`
12
+ * scans were not "large enough to be safe" — they were exactly the point past
13
+ * which the graph goes silently invisible. Everything below pages instead.
14
+ *
15
+ * 1,000 balances the two costs: one page is at most ~1 MB even at the bridge's
16
+ * 16 KB value cap (typical KG entries are far smaller), and it takes a tenth
17
+ * of the round trips a 100-row page would. */
18
+ export declare const SCAN_PAGE = 1000;
19
+ /** Edge rows `kgSearch` will read before giving up and reporting `truncated`.
20
+ * Search is interactive and runs a full scan per query, so unlike rollback it
21
+ * keeps a ceiling — five times the old silent one, and now stated in the
22
+ * result rather than hidden. */
23
+ export declare const SEARCH_EDGE_SCAN_MAX = 50000;
24
+ export type ScannedEntry = NonNullable<Awaited<ReturnType<typeof bridgeListEntries>>>['entries'][number];
25
+ /** Page through an entire namespace, handing each page to `onPage` so callers
26
+ * fold as they go instead of materializing the namespace.
27
+ *
28
+ * `onPage` returning exactly `false` stops the scan early (only `kgSearch`
29
+ * does that); any other return value continues. Returns false when the backend
30
+ * was unavailable — an unreadable namespace must never be mistaken for an
31
+ * empty one.
32
+ *
33
+ * Callers that MUTATE what they find must collect during the scan and mutate
34
+ * afterwards: deleting a row pulls every later row back one position, so under
35
+ * an advancing offset the row that slid into the gap is never read. (The
36
+ * bridge's upsert no longer reorders — it reuses the existing entry id and
37
+ * preserves `createdAt` — so rewrites alone are safe; deletes are not, and
38
+ * both callers here delete.) */
39
+ export declare function scanNamespace(namespace: string, dbPath: string | undefined, onPage: (entries: ScannedEntry[]) => unknown): Promise<boolean>;
40
+ /** Delete every entry in `namespace`. Used only to reset a DERIVED-index
41
+ * namespace (`kg:adj`/`kg:origin-idx`) before a fresh `kgRebuildIndex` —
42
+ * never a canonical one. Collect-then-delete, same reason `kgRollback`
43
+ * does: deleting mid-scan pulls later rows back under an advancing offset.
44
+ * Returns false (nothing deleted) on an unreadable or partially-deletable
45
+ * namespace, so the caller never proceeds as if a clear that didn't fully
46
+ * happen did. */
47
+ export declare function clearNamespace(namespace: string, dbPath: string | undefined): Promise<boolean>;
48
+ /** Cap on reported failure messages — a dead backend fails every write, and a
49
+ * 500-entry failure list is noise, not signal. `error` carries the true count. */
50
+ export declare const MAX_FAILURES = 20;
51
+ /** Accumulates write failures across a multi-write operation. The memory
52
+ * bridge exposes no transaction primitive, so ingest CANNOT be atomic: some
53
+ * writes land and some do not. Rather than hide that, callers get exact
54
+ * counters for what persisted plus the failure list for what did not. */
55
+ export declare class FailureLog {
56
+ readonly messages: string[];
57
+ private count;
58
+ /** @returns true when the write failed (caller should not count it). */
59
+ add(res: Awaited<ReturnType<typeof bridgeStoreEntry>>, what: string): boolean;
60
+ note(message: string): void;
61
+ get failed(): boolean;
62
+ /** Summary for the result's `error` field; undefined when everything landed. */
63
+ summary(): string | undefined;
64
+ }
65
+ /** Attempts a compare-and-swap claim write, retrying while the bridge reports
66
+ * a version conflict (K5): a concurrent writer applied its own claim to the
67
+ * same row between our read and our write. `attempt()` must re-read,
68
+ * re-merge (via `applyClaim`), and re-attempt the write itself on every call
69
+ * — retrying with the SAME stale write would just lose the update again,
70
+ * the exact bug this exists to close.
71
+ *
72
+ * Exhausting `maxAttempts` under sustained contention is returned as-is (the
73
+ * last conflict response) rather than retried forever: the caller's
74
+ * `FailureLog` reports it as a real, visible failure — never a silent lost
75
+ * update — same as any other write the bridge refused. */
76
+ export declare function withCasRetry(attempt: () => Promise<Awaited<ReturnType<typeof bridgeStoreEntry>>>, maxAttempts?: number): Promise<Awaited<ReturnType<typeof bridgeStoreEntry>>>;
77
+ export declare function originsOf(entry: ScannedEntry): string[];
78
+ /** Every entry in `namespace` that `originRef` supports, collected by an
79
+ * EXHAUSTIVE paged scan. `covered` is false when the backend became
80
+ * unreadable partway — an incomplete answer, never an empty one.
81
+ *
82
+ * Collecting rather than streaming is required by the callers that mutate:
83
+ * deleting a row pulls later rows back, so an advancing offset would skip
84
+ * whatever slid into the gap. Only origin-carrying entries are retained, so
85
+ * memory tracks the operation's own footprint, not the namespace size. */
86
+ export declare function collectByOrigin(namespace: string, originRef: string, dbPath: string | undefined): Promise<{
87
+ entries: ScannedEntry[];
88
+ covered: boolean;
89
+ }>;
90
+ export interface KgReferenceEdge {
91
+ key: string;
92
+ src: string;
93
+ dst: string;
94
+ relation: string;
95
+ originRefs: string[];
96
+ }
97
+ /** Complete, uncapped read of every edge touching `endpointId` (as either
98
+ * src or dst) and/or asserted by `originRef` — at least one filter is
99
+ * required. This is the ground truth an indexed adjacency/origin lookup
100
+ * (K7) must agree with once one exists: an exhaustive paged scan, the same
101
+ * mechanism `kgRollback` already trusts for origin withdrawal, so it never
102
+ * depends on an index and never inherits the old first-page cap.
103
+ *
104
+ * `truncated: true` means the scan did not finish — an incomplete answer,
105
+ * never an empty one. Callers comparing this against a future index must
106
+ * treat a truncated reference read as "unknown", not as "no matches". */
107
+ export declare function kgReferenceEdges(options: {
108
+ endpointId?: string;
109
+ originRef?: string;
110
+ scope?: KgScope;
111
+ dbPath?: string;
112
+ }): Promise<{
113
+ success: boolean;
114
+ edges: KgReferenceEdge[];
115
+ truncated?: boolean;
116
+ error?: string;
117
+ }>;
118
+ //# sourceMappingURL=memory-kg-scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-kg-scan.d.ts","sourceRoot":"","sources":["../../../src/memory/memory-kg-scan.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD;;;;;;;;;+C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C,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAOvD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAGvD;AAED;;;;;;;2EAO2E;AAC3E,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAMxD;AAID,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;;;;0EAS0E;AAC1E,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,eAAe,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAiC/F"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Memory Knowledge Graph — exhaustive paged namespace scans, write-failure
3
+ * reporting and CAS retry, per-origin collection, and the K7 reference edge
4
+ * lookup. Split out of memory-kg.ts, which re-exports the public symbols.
5
+ */
6
+ import { bridgeDeleteEntry, bridgeListEntries } from './memory-bridge.js';
7
+ import { kgNamespaces, kgQualifyOrigin } from './memory-kg-model.js';
8
+ /** Rows per `bridgeListEntries` call while scanning a namespace.
9
+ *
10
+ * A single list call cannot return more than the backend's own 10,000-row
11
+ * ceiling (`MAX_QUERY_LIMIT` in sql-backend.ts), so the old `limit: MAX_LIST`
12
+ * scans were not "large enough to be safe" — they were exactly the point past
13
+ * which the graph goes silently invisible. Everything below pages instead.
14
+ *
15
+ * 1,000 balances the two costs: one page is at most ~1 MB even at the bridge's
16
+ * 16 KB value cap (typical KG entries are far smaller), and it takes a tenth
17
+ * of the round trips a 100-row page would. */
18
+ export const SCAN_PAGE = 1_000;
19
+ /** Edge rows `kgSearch` will read before giving up and reporting `truncated`.
20
+ * Search is interactive and runs a full scan per query, so unlike rollback it
21
+ * keeps a ceiling — five times the old silent one, and now stated in the
22
+ * result rather than hidden. */
23
+ export const SEARCH_EDGE_SCAN_MAX = 50_000;
24
+ /** Page through an entire namespace, handing each page to `onPage` so callers
25
+ * fold as they go instead of materializing the namespace.
26
+ *
27
+ * `onPage` returning exactly `false` stops the scan early (only `kgSearch`
28
+ * does that); any other return value continues. Returns false when the backend
29
+ * was unavailable — an unreadable namespace must never be mistaken for an
30
+ * empty one.
31
+ *
32
+ * Callers that MUTATE what they find must collect during the scan and mutate
33
+ * afterwards: deleting a row pulls every later row back one position, so under
34
+ * an advancing offset the row that slid into the gap is never read. (The
35
+ * bridge's upsert no longer reorders — it reuses the existing entry id and
36
+ * preserves `createdAt` — so rewrites alone are safe; deletes are not, and
37
+ * both callers here delete.) */
38
+ export async function scanNamespace(namespace, dbPath, onPage) {
39
+ for (let offset = 0;; offset += SCAN_PAGE) {
40
+ const res = await bridgeListEntries({ namespace, limit: SCAN_PAGE, offset, dbPath });
41
+ if (!res)
42
+ return false;
43
+ if (res.entries.length && onPage(res.entries) === false)
44
+ return true;
45
+ if (res.entries.length < SCAN_PAGE)
46
+ return true;
47
+ }
48
+ }
49
+ /** Delete every entry in `namespace`. Used only to reset a DERIVED-index
50
+ * namespace (`kg:adj`/`kg:origin-idx`) before a fresh `kgRebuildIndex` —
51
+ * never a canonical one. Collect-then-delete, same reason `kgRollback`
52
+ * does: deleting mid-scan pulls later rows back under an advancing offset.
53
+ * Returns false (nothing deleted) on an unreadable or partially-deletable
54
+ * namespace, so the caller never proceeds as if a clear that didn't fully
55
+ * happen did. */
56
+ export async function clearNamespace(namespace, dbPath) {
57
+ const doomed = [];
58
+ const covered = await scanNamespace(namespace, dbPath, (page) => {
59
+ for (const e of page)
60
+ doomed.push(e);
61
+ });
62
+ if (!covered)
63
+ return false;
64
+ let ok = true;
65
+ for (const e of doomed) {
66
+ const del = await bridgeDeleteEntry({ id: e.id, namespace, dbPath });
67
+ if (!del?.deleted)
68
+ ok = false;
69
+ }
70
+ return ok;
71
+ }
72
+ /** Cap on reported failure messages — a dead backend fails every write, and a
73
+ * 500-entry failure list is noise, not signal. `error` carries the true count. */
74
+ export const MAX_FAILURES = 20;
75
+ /** `bridgeStoreEntry` never throws: it returns `null` when no backend is
76
+ * reachable and `{ success: false, error }` when the write itself failed.
77
+ * Both look like success to an `await` that ignores the result, which is how
78
+ * the graph came to claim knowledge it had not persisted. Every write in this
79
+ * module goes through here.
80
+ *
81
+ * @returns a failure message, or null when the write landed. */
82
+ function storeFailure(res, what) {
83
+ if (!res)
84
+ return `${what}: memory backend unavailable`;
85
+ if (!res.success)
86
+ return `${what}: ${res.error ?? 'store rejected'}`;
87
+ return null;
88
+ }
89
+ /** Accumulates write failures across a multi-write operation. The memory
90
+ * bridge exposes no transaction primitive, so ingest CANNOT be atomic: some
91
+ * writes land and some do not. Rather than hide that, callers get exact
92
+ * counters for what persisted plus the failure list for what did not. */
93
+ export class FailureLog {
94
+ messages = [];
95
+ count = 0;
96
+ /** @returns true when the write failed (caller should not count it). */
97
+ add(res, what) {
98
+ const msg = storeFailure(res, what);
99
+ if (!msg)
100
+ return false;
101
+ this.count++;
102
+ if (this.messages.length < MAX_FAILURES)
103
+ this.messages.push(msg);
104
+ return true;
105
+ }
106
+ note(message) {
107
+ this.count++;
108
+ if (this.messages.length < MAX_FAILURES)
109
+ this.messages.push(message);
110
+ }
111
+ get failed() {
112
+ return this.count > 0;
113
+ }
114
+ /** Summary for the result's `error` field; undefined when everything landed. */
115
+ summary() {
116
+ if (!this.count)
117
+ return undefined;
118
+ return `${this.count} bridge operation(s) failed; graph state is partial`;
119
+ }
120
+ }
121
+ /** Attempts a compare-and-swap claim write, retrying while the bridge reports
122
+ * a version conflict (K5): a concurrent writer applied its own claim to the
123
+ * same row between our read and our write. `attempt()` must re-read,
124
+ * re-merge (via `applyClaim`), and re-attempt the write itself on every call
125
+ * — retrying with the SAME stale write would just lose the update again,
126
+ * the exact bug this exists to close.
127
+ *
128
+ * Exhausting `maxAttempts` under sustained contention is returned as-is (the
129
+ * last conflict response) rather than retried forever: the caller's
130
+ * `FailureLog` reports it as a real, visible failure — never a silent lost
131
+ * update — same as any other write the bridge refused. */
132
+ export async function withCasRetry(attempt, maxAttempts = 3) {
133
+ let res = null;
134
+ for (let i = 0; i < maxAttempts; i++) {
135
+ res = await attempt();
136
+ if (!res?.conflict)
137
+ return res;
138
+ }
139
+ return res;
140
+ }
141
+ export function originsOf(entry) {
142
+ const origins = (entry.metadata ?? {}).origin_refs;
143
+ return Array.isArray(origins) ? origins : [];
144
+ }
145
+ /** Every entry in `namespace` that `originRef` supports, collected by an
146
+ * EXHAUSTIVE paged scan. `covered` is false when the backend became
147
+ * unreadable partway — an incomplete answer, never an empty one.
148
+ *
149
+ * Collecting rather than streaming is required by the callers that mutate:
150
+ * deleting a row pulls later rows back, so an advancing offset would skip
151
+ * whatever slid into the gap. Only origin-carrying entries are retained, so
152
+ * memory tracks the operation's own footprint, not the namespace size. */
153
+ export async function collectByOrigin(namespace, originRef, dbPath) {
154
+ const entries = [];
155
+ const covered = await scanNamespace(namespace, dbPath, (page) => {
156
+ for (const e of page)
157
+ if (originsOf(e).includes(originRef))
158
+ entries.push(e);
159
+ });
160
+ return { entries, covered };
161
+ }
162
+ /** Complete, uncapped read of every edge touching `endpointId` (as either
163
+ * src or dst) and/or asserted by `originRef` — at least one filter is
164
+ * required. This is the ground truth an indexed adjacency/origin lookup
165
+ * (K7) must agree with once one exists: an exhaustive paged scan, the same
166
+ * mechanism `kgRollback` already trusts for origin withdrawal, so it never
167
+ * depends on an index and never inherits the old first-page cap.
168
+ *
169
+ * `truncated: true` means the scan did not finish — an incomplete answer,
170
+ * never an empty one. Callers comparing this against a future index must
171
+ * treat a truncated reference read as "unknown", not as "no matches". */
172
+ export async function kgReferenceEdges(options) {
173
+ if (!options.endpointId && !options.originRef) {
174
+ return { success: false, edges: [], error: 'endpointId or originRef is required' };
175
+ }
176
+ const ns = kgNamespaces(options.scope);
177
+ const originRef = options.originRef
178
+ ? kgQualifyOrigin(options.originRef, options.scope)
179
+ : undefined;
180
+ const edges = [];
181
+ try {
182
+ const covered = await scanNamespace(ns.edges, options.dbPath, (page) => {
183
+ for (const e of page) {
184
+ const md = (e.metadata ?? {});
185
+ if (md.kg !== 'edge')
186
+ continue;
187
+ const src = String(md.src ?? '');
188
+ const dst = String(md.dst ?? '');
189
+ if (options.endpointId && src !== options.endpointId && dst !== options.endpointId)
190
+ continue;
191
+ const originRefs = originsOf(e);
192
+ if (originRef && !originRefs.includes(originRef))
193
+ continue;
194
+ edges.push({
195
+ key: e.key,
196
+ src,
197
+ dst,
198
+ relation: String(md.relation ?? 'related_to'),
199
+ originRefs,
200
+ });
201
+ }
202
+ });
203
+ return { success: true, edges, ...(covered ? {} : { truncated: true }) };
204
+ }
205
+ catch (err) {
206
+ return { success: false, edges, error: err instanceof Error ? err.message : String(err) };
207
+ }
208
+ }
209
+ //# sourceMappingURL=memory-kg-scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-kg-scan.js","sourceRoot":"","sources":["../../../src/memory/memory-kg-scan.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,MAAM,oBAAoB,CAAC;AAEjG,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA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;gBAC3D,KAAK,CAAC,IAAI,CAAC;oBACT,GAAG,EAAE,CAAC,CAAC,GAAG;oBACV,GAAG;oBACH,GAAG;oBACH,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,IAAI,YAAY,CAAC;oBAC7C,UAAU;iBACX,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAC3E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5F,CAAC;AACH,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Memory Knowledge Graph — retrieval: kgSearch (seed nodes, neighbourhood
3
+ * expansion, evidence-aware ranking) and kgGlossary for extraction prompts.
4
+ * Split out of memory-kg.ts, which re-exports the public symbols.
5
+ */
6
+ import type { KgExtractionMethod } from './memory-kg-claims.js';
7
+ import type { KgScope } from './memory-kg-model.js';
8
+ export interface KgSearchResult {
9
+ success: boolean;
10
+ /** Rendered triplet lines, best first. */
11
+ context: string;
12
+ triplets: {
13
+ source: string;
14
+ relation: string;
15
+ target: string;
16
+ fact: string;
17
+ score: number;
18
+ /** How this edge came to exist. Absent means the edge predates method
19
+ * recording — not recorded, which is not the same as `asserted`. */
20
+ method?: KgExtractionMethod;
21
+ /** Live origins disagree about what this edge says. Present only when true. */
22
+ conflict?: boolean;
23
+ /** The edge's bridge entry id — feed this straight to `memory_feedback`
24
+ * (`bridgeApplyFeedback`/`bridgeRecordUsage`) to rate THIS relationship
25
+ * directly, rather than only the seed entity that surfaced it (K5). */
26
+ id: string;
27
+ /** The edge's stable graph key (`e:<hash>`, see `edgeKey`), for direct
28
+ * `bridgeGetEntry` lookup or diagnostics — distinct from `id` above. */
29
+ key: string;
30
+ }[];
31
+ seeds: {
32
+ name: string;
33
+ type: string;
34
+ description: string;
35
+ score: number;
36
+ id: string;
37
+ }[];
38
+ /** True when the edge scan did NOT cover the whole namespace — the scan hit
39
+ * `SEARCH_EDGE_SCAN_MAX`, or the backend became unreadable partway. A
40
+ * relationship that exists may be missing from `triplets`; absence here is
41
+ * not evidence of absence in the graph. */
42
+ truncated?: boolean;
43
+ /** Edge rows actually read, so a caller can see how close it ran to the cap. */
44
+ scannedEdges?: number;
45
+ /** What the seed retrieval ACTUALLY ran, straight from the bridge — never what
46
+ * was hoped for. `keyword-fallback` means the vector path was tried and did
47
+ * not serve these results. Absent only when the bridge reported nothing. */
48
+ method?: 'semantic' | 'keyword' | 'keyword-fallback';
49
+ /** Why the vector path did not serve the seeds (absent when it did). */
50
+ fallbackReason?: string;
51
+ error?: string;
52
+ }
53
+ /** Seeded retrieval → neighborhood → triplet ranking (cognee's brute-force
54
+ * triplet search, scaled down). Seed scores already carry the Phase 1 feedback
55
+ * blend, and the seed retrieval may be vector or keyword — `method` on the
56
+ * result says which actually ran.
57
+ *
58
+ * Ranking weighs exactly two evidence signals, both read off the claim ledger:
59
+ * extraction method and description conflict. It deliberately does NOT model
60
+ * source credibility, claim freshness, or whether the relation itself answers
61
+ * the query — those need an evaluation set to tune against, and guessing at
62
+ * them would be the same overclaim this weighting exists to correct. */
63
+ export declare function kgSearch(options: {
64
+ query: string;
65
+ dbPath?: string;
66
+ limit?: number;
67
+ nodeSet?: string;
68
+ /** Whose graph to search. Omit for project-shared knowledge; a scoped search
69
+ * never reaches another org's facts, and never the shared graph either. */
70
+ scope?: KgScope;
71
+ }): Promise<KgSearchResult>;
72
+ export declare function kgGlossary(options?: {
73
+ dbPath?: string;
74
+ limit?: number;
75
+ /** Whose entity names to offer. The coordinator glossary MUST be scoped:
76
+ * suggesting another org's entity names is how one org's claims get merged
77
+ * into another's graph under a shared name. */
78
+ scope?: KgScope;
79
+ }): Promise<string[]>;
80
+ //# sourceMappingURL=memory-kg-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-kg-search.d.ts","sourceRoot":"","sources":["../../../src/memory/memory-kg-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAOpD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd;6EACqE;QACrE,MAAM,CAAC,EAAE,kBAAkB,CAAC;QAC5B,+EAA+E;QAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;;gFAEwE;QACxE,EAAE,EAAE,MAAM,CAAC;QACX;iFACyE;QACzE,GAAG,EAAE,MAAM,CAAC;KACb,EAAE,CAAC;IACJ,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxF;;;gDAG4C;IAC5C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;iFAE6E;IAC7E,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,kBAAk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