@graphorin/memory 0.5.0

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 (287) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +401 -0
  4. package/dist/conflict/index.d.ts +3 -0
  5. package/dist/conflict/index.js +7 -0
  6. package/dist/conflict/locale-packs/en.js +262 -0
  7. package/dist/conflict/locale-packs/en.js.map +1 -0
  8. package/dist/conflict/locale-packs/index.js +4 -0
  9. package/dist/conflict/locale-packs/types.d.ts +103 -0
  10. package/dist/conflict/locale-packs/types.d.ts.map +1 -0
  11. package/dist/conflict/locale-packs/types.js +55 -0
  12. package/dist/conflict/locale-packs/types.js.map +1 -0
  13. package/dist/conflict/pipeline.d.ts +35 -0
  14. package/dist/conflict/pipeline.d.ts.map +1 -0
  15. package/dist/conflict/pipeline.js +257 -0
  16. package/dist/conflict/pipeline.js.map +1 -0
  17. package/dist/conflict/stages/helpers.js +66 -0
  18. package/dist/conflict/stages/helpers.js.map +1 -0
  19. package/dist/conflict/stages/stage1-exact-dedup.js +21 -0
  20. package/dist/conflict/stages/stage1-exact-dedup.js.map +1 -0
  21. package/dist/conflict/stages/stage2-embedding-three-zone.js +37 -0
  22. package/dist/conflict/stages/stage2-embedding-three-zone.js.map +1 -0
  23. package/dist/conflict/stages/stage3-heuristic-regex.js +45 -0
  24. package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -0
  25. package/dist/conflict/stages/stage4-subject-predicate.js +31 -0
  26. package/dist/conflict/stages/stage4-subject-predicate.js.map +1 -0
  27. package/dist/conflict/stages/stage5-defer-to-deep.js +22 -0
  28. package/dist/conflict/stages/stage5-defer-to-deep.js.map +1 -0
  29. package/dist/conflict/types.d.ts +222 -0
  30. package/dist/conflict/types.d.ts.map +1 -0
  31. package/dist/conflict/types.js +50 -0
  32. package/dist/conflict/types.js.map +1 -0
  33. package/dist/consolidator/budget.d.ts +1 -0
  34. package/dist/consolidator/budget.js +214 -0
  35. package/dist/consolidator/budget.js.map +1 -0
  36. package/dist/consolidator/decay.d.ts +35 -0
  37. package/dist/consolidator/decay.d.ts.map +1 -0
  38. package/dist/consolidator/decay.js +91 -0
  39. package/dist/consolidator/decay.js.map +1 -0
  40. package/dist/consolidator/dlq.js +58 -0
  41. package/dist/consolidator/dlq.js.map +1 -0
  42. package/dist/consolidator/errors.d.ts +54 -0
  43. package/dist/consolidator/errors.d.ts.map +1 -0
  44. package/dist/consolidator/errors.js +67 -0
  45. package/dist/consolidator/errors.js.map +1 -0
  46. package/dist/consolidator/idempotency.d.ts +1 -0
  47. package/dist/consolidator/idempotency.js +22 -0
  48. package/dist/consolidator/idempotency.js.map +1 -0
  49. package/dist/consolidator/index.d.ts +34 -0
  50. package/dist/consolidator/index.d.ts.map +1 -0
  51. package/dist/consolidator/index.js +163 -0
  52. package/dist/consolidator/index.js.map +1 -0
  53. package/dist/consolidator/lock.d.ts +2 -0
  54. package/dist/consolidator/lock.js +89 -0
  55. package/dist/consolidator/lock.js.map +1 -0
  56. package/dist/consolidator/noise-filter.d.ts +2 -0
  57. package/dist/consolidator/noise-filter.js +173 -0
  58. package/dist/consolidator/noise-filter.js.map +1 -0
  59. package/dist/consolidator/phases/deep.d.ts +4 -0
  60. package/dist/consolidator/phases/deep.js +198 -0
  61. package/dist/consolidator/phases/deep.js.map +1 -0
  62. package/dist/consolidator/phases/induce.d.ts +154 -0
  63. package/dist/consolidator/phases/induce.d.ts.map +1 -0
  64. package/dist/consolidator/phases/induce.js +253 -0
  65. package/dist/consolidator/phases/induce.js.map +1 -0
  66. package/dist/consolidator/phases/light.d.ts +4 -0
  67. package/dist/consolidator/phases/light.js +99 -0
  68. package/dist/consolidator/phases/light.js.map +1 -0
  69. package/dist/consolidator/phases/reflect.js +287 -0
  70. package/dist/consolidator/phases/reflect.js.map +1 -0
  71. package/dist/consolidator/phases/standard.d.ts +8 -0
  72. package/dist/consolidator/phases/standard.js +499 -0
  73. package/dist/consolidator/phases/standard.js.map +1 -0
  74. package/dist/consolidator/reconcile.js +192 -0
  75. package/dist/consolidator/reconcile.js.map +1 -0
  76. package/dist/consolidator/runtime.d.ts +62 -0
  77. package/dist/consolidator/runtime.d.ts.map +1 -0
  78. package/dist/consolidator/runtime.js +580 -0
  79. package/dist/consolidator/runtime.js.map +1 -0
  80. package/dist/consolidator/scheduler.d.ts +111 -0
  81. package/dist/consolidator/scheduler.d.ts.map +1 -0
  82. package/dist/consolidator/scheduler.js +71 -0
  83. package/dist/consolidator/scheduler.js.map +1 -0
  84. package/dist/consolidator/triggers.d.ts +40 -0
  85. package/dist/consolidator/triggers.d.ts.map +1 -0
  86. package/dist/consolidator/triggers.js +94 -0
  87. package/dist/consolidator/triggers.js.map +1 -0
  88. package/dist/consolidator/types.d.ts +397 -0
  89. package/dist/consolidator/types.d.ts.map +1 -0
  90. package/dist/consolidator/types.js +117 -0
  91. package/dist/consolidator/types.js.map +1 -0
  92. package/dist/context-engine/annotations.d.ts +118 -0
  93. package/dist/context-engine/annotations.d.ts.map +1 -0
  94. package/dist/context-engine/annotations.js +102 -0
  95. package/dist/context-engine/annotations.js.map +1 -0
  96. package/dist/context-engine/auto-recall.d.ts +52 -0
  97. package/dist/context-engine/auto-recall.d.ts.map +1 -0
  98. package/dist/context-engine/auto-recall.js +41 -0
  99. package/dist/context-engine/auto-recall.js.map +1 -0
  100. package/dist/context-engine/compaction/clear-tool-results.d.ts +55 -0
  101. package/dist/context-engine/compaction/clear-tool-results.d.ts.map +1 -0
  102. package/dist/context-engine/compaction/clear-tool-results.js +97 -0
  103. package/dist/context-engine/compaction/clear-tool-results.js.map +1 -0
  104. package/dist/context-engine/compaction/compactor.d.ts +52 -0
  105. package/dist/context-engine/compaction/compactor.d.ts.map +1 -0
  106. package/dist/context-engine/compaction/compactor.js +196 -0
  107. package/dist/context-engine/compaction/compactor.js.map +1 -0
  108. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts +15 -0
  109. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts.map +1 -0
  110. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js +27 -0
  111. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js.map +1 -0
  112. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts +18 -0
  113. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts.map +1 -0
  114. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js +47 -0
  115. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js.map +1 -0
  116. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts +15 -0
  117. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts.map +1 -0
  118. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js +32 -0
  119. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js.map +1 -0
  120. package/dist/context-engine/compaction/hooks/types.d.ts +42 -0
  121. package/dist/context-engine/compaction/hooks/types.d.ts.map +1 -0
  122. package/dist/context-engine/compaction/index.d.ts +9 -0
  123. package/dist/context-engine/compaction/index.js +9 -0
  124. package/dist/context-engine/compaction/templates/summary-9-section.d.ts +84 -0
  125. package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -0
  126. package/dist/context-engine/compaction/templates/summary-9-section.js +84 -0
  127. package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -0
  128. package/dist/context-engine/compaction/thresholds.d.ts +68 -0
  129. package/dist/context-engine/compaction/thresholds.d.ts.map +1 -0
  130. package/dist/context-engine/compaction/thresholds.js +63 -0
  131. package/dist/context-engine/compaction/thresholds.js.map +1 -0
  132. package/dist/context-engine/compaction/types.d.ts +202 -0
  133. package/dist/context-engine/compaction/types.d.ts.map +1 -0
  134. package/dist/context-engine/engine.d.ts +258 -0
  135. package/dist/context-engine/engine.d.ts.map +1 -0
  136. package/dist/context-engine/engine.js +424 -0
  137. package/dist/context-engine/engine.js.map +1 -0
  138. package/dist/context-engine/index.d.ts +68 -0
  139. package/dist/context-engine/index.d.ts.map +1 -0
  140. package/dist/context-engine/index.js +24 -0
  141. package/dist/context-engine/locale-packs/en.d.ts +14 -0
  142. package/dist/context-engine/locale-packs/en.d.ts.map +1 -0
  143. package/dist/context-engine/locale-packs/en.js +87 -0
  144. package/dist/context-engine/locale-packs/en.js.map +1 -0
  145. package/dist/context-engine/locale-packs/index.js +4 -0
  146. package/dist/context-engine/locale-packs/resolver.d.ts +41 -0
  147. package/dist/context-engine/locale-packs/resolver.d.ts.map +1 -0
  148. package/dist/context-engine/locale-packs/resolver.js +119 -0
  149. package/dist/context-engine/locale-packs/resolver.js.map +1 -0
  150. package/dist/context-engine/locale-packs/types.d.ts +119 -0
  151. package/dist/context-engine/locale-packs/types.d.ts.map +1 -0
  152. package/dist/context-engine/locale-packs/types.js +24 -0
  153. package/dist/context-engine/locale-packs/types.js.map +1 -0
  154. package/dist/context-engine/metadata.d.ts +40 -0
  155. package/dist/context-engine/metadata.d.ts.map +1 -0
  156. package/dist/context-engine/metadata.js +66 -0
  157. package/dist/context-engine/metadata.js.map +1 -0
  158. package/dist/context-engine/preambles/inbound-en.d.ts +20 -0
  159. package/dist/context-engine/preambles/inbound-en.d.ts.map +1 -0
  160. package/dist/context-engine/preambles/inbound-en.js +23 -0
  161. package/dist/context-engine/preambles/inbound-en.js.map +1 -0
  162. package/dist/context-engine/privacy-filter.d.ts +108 -0
  163. package/dist/context-engine/privacy-filter.d.ts.map +1 -0
  164. package/dist/context-engine/privacy-filter.js +113 -0
  165. package/dist/context-engine/privacy-filter.js.map +1 -0
  166. package/dist/context-engine/templates/base-en.d.ts +19 -0
  167. package/dist/context-engine/templates/base-en.d.ts.map +1 -0
  168. package/dist/context-engine/templates/base-en.js +22 -0
  169. package/dist/context-engine/templates/base-en.js.map +1 -0
  170. package/dist/context-engine/templates/composer.d.ts +55 -0
  171. package/dist/context-engine/templates/composer.d.ts.map +1 -0
  172. package/dist/context-engine/templates/composer.js +51 -0
  173. package/dist/context-engine/templates/composer.js.map +1 -0
  174. package/dist/context-engine/token-budget.d.ts +99 -0
  175. package/dist/context-engine/token-budget.d.ts.map +1 -0
  176. package/dist/context-engine/token-budget.js +211 -0
  177. package/dist/context-engine/token-budget.js.map +1 -0
  178. package/dist/context-engine/token-counter.d.ts +54 -0
  179. package/dist/context-engine/token-counter.d.ts.map +1 -0
  180. package/dist/context-engine/token-counter.js +81 -0
  181. package/dist/context-engine/token-counter.js.map +1 -0
  182. package/dist/errors/index.d.ts +171 -0
  183. package/dist/errors/index.d.ts.map +1 -0
  184. package/dist/errors/index.js +206 -0
  185. package/dist/errors/index.js.map +1 -0
  186. package/dist/facade.d.ts +278 -0
  187. package/dist/facade.d.ts.map +1 -0
  188. package/dist/facade.js +265 -0
  189. package/dist/facade.js.map +1 -0
  190. package/dist/graph/entity-resolver.d.ts +135 -0
  191. package/dist/graph/entity-resolver.d.ts.map +1 -0
  192. package/dist/graph/entity-resolver.js +202 -0
  193. package/dist/graph/entity-resolver.js.map +1 -0
  194. package/dist/graph/index.d.ts +1 -0
  195. package/dist/index.d.ts +103 -0
  196. package/dist/index.d.ts.map +1 -0
  197. package/dist/index.js +95 -0
  198. package/dist/index.js.map +1 -0
  199. package/dist/internal/contextualize.d.ts +14 -0
  200. package/dist/internal/contextualize.d.ts.map +1 -0
  201. package/dist/internal/contextualize.js +110 -0
  202. package/dist/internal/contextualize.js.map +1 -0
  203. package/dist/internal/embedder-binding.js +50 -0
  204. package/dist/internal/embedder-binding.js.map +1 -0
  205. package/dist/internal/id.js +24 -0
  206. package/dist/internal/id.js.map +1 -0
  207. package/dist/internal/injection-heuristics.js +64 -0
  208. package/dist/internal/injection-heuristics.js.map +1 -0
  209. package/dist/internal/spans.js +35 -0
  210. package/dist/internal/spans.js.map +1 -0
  211. package/dist/internal/storage-adapter.d.ts +742 -0
  212. package/dist/internal/storage-adapter.d.ts.map +1 -0
  213. package/dist/migration/embedder-migration.d.ts +124 -0
  214. package/dist/migration/embedder-migration.d.ts.map +1 -0
  215. package/dist/migration/embedder-migration.js +109 -0
  216. package/dist/migration/embedder-migration.js.map +1 -0
  217. package/dist/migration/index.d.ts +2 -0
  218. package/dist/migration/index.js +3 -0
  219. package/dist/search/explain.d.ts +74 -0
  220. package/dist/search/explain.d.ts.map +1 -0
  221. package/dist/search/explain.js +50 -0
  222. package/dist/search/explain.js.map +1 -0
  223. package/dist/search/index.d.ts +6 -0
  224. package/dist/search/index.js +6 -0
  225. package/dist/search/iterative.d.ts +223 -0
  226. package/dist/search/iterative.d.ts.map +1 -0
  227. package/dist/search/iterative.js +330 -0
  228. package/dist/search/iterative.js.map +1 -0
  229. package/dist/search/query-transform.d.ts +112 -0
  230. package/dist/search/query-transform.d.ts.map +1 -0
  231. package/dist/search/query-transform.js +184 -0
  232. package/dist/search/query-transform.js.map +1 -0
  233. package/dist/search/rrf.d.ts +95 -0
  234. package/dist/search/rrf.d.ts.map +1 -0
  235. package/dist/search/rrf.js +166 -0
  236. package/dist/search/rrf.js.map +1 -0
  237. package/dist/search/types.d.ts +50 -0
  238. package/dist/search/types.d.ts.map +1 -0
  239. package/dist/tiers/episodic-memory.d.ts +142 -0
  240. package/dist/tiers/episodic-memory.d.ts.map +1 -0
  241. package/dist/tiers/episodic-memory.js +254 -0
  242. package/dist/tiers/episodic-memory.js.map +1 -0
  243. package/dist/tiers/index.d.ts +8 -0
  244. package/dist/tiers/index.js +9 -0
  245. package/dist/tiers/insight-memory.d.ts +71 -0
  246. package/dist/tiers/insight-memory.d.ts.map +1 -0
  247. package/dist/tiers/insight-memory.js +133 -0
  248. package/dist/tiers/insight-memory.js.map +1 -0
  249. package/dist/tiers/procedural-memory.d.ts +147 -0
  250. package/dist/tiers/procedural-memory.d.ts.map +1 -0
  251. package/dist/tiers/procedural-memory.js +267 -0
  252. package/dist/tiers/procedural-memory.js.map +1 -0
  253. package/dist/tiers/semantic-memory.d.ts +461 -0
  254. package/dist/tiers/semantic-memory.d.ts.map +1 -0
  255. package/dist/tiers/semantic-memory.js +631 -0
  256. package/dist/tiers/semantic-memory.js.map +1 -0
  257. package/dist/tiers/session-memory.d.ts +117 -0
  258. package/dist/tiers/session-memory.d.ts.map +1 -0
  259. package/dist/tiers/session-memory.js +163 -0
  260. package/dist/tiers/session-memory.js.map +1 -0
  261. package/dist/tiers/shared-memory.d.ts +29 -0
  262. package/dist/tiers/shared-memory.d.ts.map +1 -0
  263. package/dist/tiers/shared-memory.js +58 -0
  264. package/dist/tiers/shared-memory.js.map +1 -0
  265. package/dist/tiers/working-memory.d.ts +129 -0
  266. package/dist/tiers/working-memory.d.ts.map +1 -0
  267. package/dist/tiers/working-memory.js +229 -0
  268. package/dist/tiers/working-memory.js.map +1 -0
  269. package/dist/tools/block-tools.d.ts +98 -0
  270. package/dist/tools/block-tools.d.ts.map +1 -0
  271. package/dist/tools/block-tools.js +114 -0
  272. package/dist/tools/block-tools.js.map +1 -0
  273. package/dist/tools/fact-tools.d.ts +294 -0
  274. package/dist/tools/fact-tools.d.ts.map +1 -0
  275. package/dist/tools/fact-tools.js +293 -0
  276. package/dist/tools/fact-tools.js.map +1 -0
  277. package/dist/tools/index.d.ts +35 -0
  278. package/dist/tools/index.d.ts.map +1 -0
  279. package/dist/tools/index.js +36 -0
  280. package/dist/tools/index.js.map +1 -0
  281. package/dist/tools/recall-tools.d.ts +209 -0
  282. package/dist/tools/recall-tools.d.ts.map +1 -0
  283. package/dist/tools/recall-tools.js +170 -0
  284. package/dist/tools/recall-tools.js.map +1 -0
  285. package/dist/tools/types.d.ts +40 -0
  286. package/dist/tools/types.d.ts.map +1 -0
  287. package/package.json +119 -0
@@ -0,0 +1,36 @@
1
+ import { createBlockAppendTool, createBlockReplaceTool, createBlockRethinkTool } from "./block-tools.js";
2
+ import { createFactForgetTool, createFactHistoryTool, createFactRememberTool, createFactSearchTool, createFactSupersedeTool, createFactValidateTool } from "./fact-tools.js";
3
+ import { createConversationSearchTool, createDeepRecallTool, createRecallEpisodesTool } from "./recall-tools.js";
4
+
5
+ //#region src/tools/index.ts
6
+ /**
7
+ * Build the canonical eleven-memory-tool array. Order is stable —
8
+ * consumers can rely on the indices for snapshot tests. `fact_history`
9
+ * (P0-2) and `fact_validate` (P1-4) are appended last so the original
10
+ * nine indices are unchanged. With `{ includeDeepRecall: true }` the
11
+ * gated `deep_recall` tool (P2-4) is appended as a twelfth, after the
12
+ * stable eleven.
13
+ *
14
+ * @stable
15
+ */
16
+ function buildMemoryTools(deps, options = {}) {
17
+ const tools = [
18
+ createBlockAppendTool(deps),
19
+ createBlockReplaceTool(deps),
20
+ createBlockRethinkTool(deps),
21
+ createFactRememberTool(deps),
22
+ createFactSearchTool(deps),
23
+ createFactSupersedeTool(deps),
24
+ createFactForgetTool(deps),
25
+ createRecallEpisodesTool(deps),
26
+ createConversationSearchTool(deps),
27
+ createFactHistoryTool(deps),
28
+ createFactValidateTool(deps)
29
+ ];
30
+ if (options.includeDeepRecall === true) tools.push(createDeepRecallTool(deps));
31
+ return Object.freeze(tools);
32
+ }
33
+
34
+ //#endregion
35
+ export { buildMemoryTools, createBlockAppendTool, createBlockReplaceTool, createBlockRethinkTool, createConversationSearchTool, createDeepRecallTool, createFactForgetTool, createFactHistoryTool, createFactRememberTool, createFactSearchTool, createFactSupersedeTool, createFactValidateTool, createRecallEpisodesTool };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["tools: Tool[]"],"sources":["../../src/tools/index.ts"],"sourcesContent":["/**\n * Eleven memory tools registered with `@graphorin/tools` by the\n * `createMemory()` facade — plus an opt-in twelfth, `deep_recall` (P2-4),\n * appended only when iterative retrieval is configured. Each factory\n * takes a {@link MemoryToolDeps} bundle so consumers can scope the tool\n * surface (per-tier ACL, scope resolver, etc.) without rebuilding the\n * underlying memory facade.\n *\n * @packageDocumentation\n */\n\nimport type { Tool } from '@graphorin/core';\nimport {\n createBlockAppendTool,\n createBlockReplaceTool,\n createBlockRethinkTool,\n} from './block-tools.js';\nimport {\n createFactForgetTool,\n createFactHistoryTool,\n createFactRememberTool,\n createFactSearchTool,\n createFactSupersedeTool,\n createFactValidateTool,\n} from './fact-tools.js';\nimport {\n createConversationSearchTool,\n createDeepRecallTool,\n createRecallEpisodesTool,\n} from './recall-tools.js';\nimport type { MemoryToolDeps } from './types.js';\n\nexport {\n createBlockAppendTool,\n createBlockReplaceTool,\n createBlockRethinkTool,\n} from './block-tools.js';\nexport {\n createFactForgetTool,\n createFactHistoryTool,\n createFactRememberTool,\n createFactSearchTool,\n createFactSupersedeTool,\n createFactValidateTool,\n} from './fact-tools.js';\nexport {\n createConversationSearchTool,\n createDeepRecallTool,\n createRecallEpisodesTool,\n} from './recall-tools.js';\nexport type { MemoryToolDeps, ScopeResolver } from './types.js';\n\n/**\n * Options for {@link buildMemoryTools}.\n *\n * @stable\n */\nexport interface BuildMemoryToolsOptions {\n /**\n * Append the gated `deep_recall` tool (P2-4) as a twelfth tool. The\n * facade sets this only when `iterativeRetrieval` is configured, so the\n * default tool surface stays at the canonical eleven. Default `false`.\n */\n readonly includeDeepRecall?: boolean;\n}\n\n/**\n * Build the canonical eleven-memory-tool array. Order is stable —\n * consumers can rely on the indices for snapshot tests. `fact_history`\n * (P0-2) and `fact_validate` (P1-4) are appended last so the original\n * nine indices are unchanged. With `{ includeDeepRecall: true }` the\n * gated `deep_recall` tool (P2-4) is appended as a twelfth, after the\n * stable eleven.\n *\n * @stable\n */\nexport function buildMemoryTools(\n deps: MemoryToolDeps,\n options: BuildMemoryToolsOptions = {},\n): ReadonlyArray<Tool> {\n const tools: Tool[] = [\n createBlockAppendTool(deps) as Tool,\n createBlockReplaceTool(deps) as Tool,\n createBlockRethinkTool(deps) as Tool,\n createFactRememberTool(deps) as Tool,\n createFactSearchTool(deps) as Tool,\n createFactSupersedeTool(deps) as Tool,\n createFactForgetTool(deps) as Tool,\n createRecallEpisodesTool(deps) as Tool,\n createConversationSearchTool(deps) as Tool,\n createFactHistoryTool(deps) as Tool,\n createFactValidateTool(deps) as Tool,\n ];\n if (options.includeDeepRecall === true) {\n tools.push(createDeepRecallTool(deps) as Tool);\n }\n return Object.freeze(tools);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4EA,SAAgB,iBACd,MACA,UAAmC,EAAE,EAChB;CACrB,MAAMA,QAAgB;EACpB,sBAAsB,KAAK;EAC3B,uBAAuB,KAAK;EAC5B,uBAAuB,KAAK;EAC5B,uBAAuB,KAAK;EAC5B,qBAAqB,KAAK;EAC1B,wBAAwB,KAAK;EAC7B,qBAAqB,KAAK;EAC1B,yBAAyB,KAAK;EAC9B,6BAA6B,KAAK;EAClC,sBAAsB,KAAK;EAC3B,uBAAuB,KAAK;EAC7B;AACD,KAAI,QAAQ,sBAAsB,KAChC,OAAM,KAAK,qBAAqB,KAAK,CAAS;AAEhD,QAAO,OAAO,OAAO,MAAM"}
@@ -0,0 +1,209 @@
1
+ import { MemoryToolDeps } from "./types.js";
2
+ import { Tool } from "@graphorin/core";
3
+ import { z } from "zod";
4
+
5
+ //#region src/tools/recall-tools.d.ts
6
+ declare const recallEpisodesInputSchema: z.ZodObject<{
7
+ query: z.ZodString;
8
+ topK: z.ZodOptional<z.ZodNumber>;
9
+ dateRange: z.ZodOptional<z.ZodObject<{
10
+ from: z.ZodOptional<z.ZodString>;
11
+ to: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ from?: string | undefined;
14
+ to?: string | undefined;
15
+ }, {
16
+ from?: string | undefined;
17
+ to?: string | undefined;
18
+ }>>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ query: string;
21
+ topK?: number | undefined;
22
+ dateRange?: {
23
+ from?: string | undefined;
24
+ to?: string | undefined;
25
+ } | undefined;
26
+ }, {
27
+ query: string;
28
+ topK?: number | undefined;
29
+ dateRange?: {
30
+ from?: string | undefined;
31
+ to?: string | undefined;
32
+ } | undefined;
33
+ }>;
34
+ declare const recallEpisodesOutputSchema: z.ZodObject<{
35
+ episodes: z.ZodArray<z.ZodObject<{
36
+ episodeId: z.ZodString;
37
+ summary: z.ZodString;
38
+ score: z.ZodNumber;
39
+ startedAt: z.ZodString;
40
+ endedAt: z.ZodString;
41
+ /** Trust-provenance tag (MST-10) — synthesized episodes say so. */
42
+ provenance: z.ZodOptional<z.ZodString>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ episodeId: string;
45
+ summary: string;
46
+ score: number;
47
+ startedAt: string;
48
+ endedAt: string;
49
+ provenance?: string | undefined;
50
+ }, {
51
+ episodeId: string;
52
+ summary: string;
53
+ score: number;
54
+ startedAt: string;
55
+ endedAt: string;
56
+ provenance?: string | undefined;
57
+ }>, "many">;
58
+ }, "strip", z.ZodTypeAny, {
59
+ episodes: {
60
+ episodeId: string;
61
+ summary: string;
62
+ score: number;
63
+ startedAt: string;
64
+ endedAt: string;
65
+ provenance?: string | undefined;
66
+ }[];
67
+ }, {
68
+ episodes: {
69
+ episodeId: string;
70
+ summary: string;
71
+ score: number;
72
+ startedAt: string;
73
+ endedAt: string;
74
+ provenance?: string | undefined;
75
+ }[];
76
+ }>;
77
+ type RecallEpisodesInput = z.infer<typeof recallEpisodesInputSchema>;
78
+ type RecallEpisodesOutput = z.infer<typeof recallEpisodesOutputSchema>;
79
+ declare const conversationSearchInputSchema: z.ZodObject<{
80
+ query: z.ZodString;
81
+ topK: z.ZodOptional<z.ZodNumber>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ query: string;
84
+ topK?: number | undefined;
85
+ }, {
86
+ query: string;
87
+ topK?: number | undefined;
88
+ }>;
89
+ declare const conversationSearchOutputSchema: z.ZodObject<{
90
+ matches: z.ZodArray<z.ZodObject<{
91
+ messageId: z.ZodString;
92
+ score: z.ZodNumber;
93
+ }, "strip", z.ZodTypeAny, {
94
+ score: number;
95
+ messageId: string;
96
+ }, {
97
+ score: number;
98
+ messageId: string;
99
+ }>, "many">;
100
+ }, "strip", z.ZodTypeAny, {
101
+ matches: {
102
+ score: number;
103
+ messageId: string;
104
+ }[];
105
+ }, {
106
+ matches: {
107
+ score: number;
108
+ messageId: string;
109
+ }[];
110
+ }>;
111
+ type ConversationSearchInput = z.infer<typeof conversationSearchInputSchema>;
112
+ type ConversationSearchOutput = z.infer<typeof conversationSearchOutputSchema>;
113
+ declare const deepRecallInputSchema: z.ZodObject<{
114
+ query: z.ZodString;
115
+ topK: z.ZodOptional<z.ZodNumber>;
116
+ maxIterations: z.ZodOptional<z.ZodNumber>;
117
+ asOf: z.ZodOptional<z.ZodString>;
118
+ }, "strip", z.ZodTypeAny, {
119
+ query: string;
120
+ topK?: number | undefined;
121
+ maxIterations?: number | undefined;
122
+ asOf?: string | undefined;
123
+ }, {
124
+ query: string;
125
+ topK?: number | undefined;
126
+ maxIterations?: number | undefined;
127
+ asOf?: string | undefined;
128
+ }>;
129
+ declare const deepRecallOutputSchema: z.ZodObject<{
130
+ hits: z.ZodArray<z.ZodObject<{
131
+ factId: z.ZodString;
132
+ text: z.ZodString;
133
+ score: z.ZodNumber;
134
+ sensitivity: z.ZodEnum<["public", "internal", "secret"]>;
135
+ /** Trust-provenance tag (MST-10) — synthesized facts say so. */
136
+ provenance: z.ZodOptional<z.ZodString>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ score: number;
139
+ factId: string;
140
+ text: string;
141
+ sensitivity: "public" | "internal" | "secret";
142
+ provenance?: string | undefined;
143
+ }, {
144
+ score: number;
145
+ factId: string;
146
+ text: string;
147
+ sensitivity: "public" | "internal" | "secret";
148
+ provenance?: string | undefined;
149
+ }>, "many">;
150
+ sufficient: z.ZodBoolean;
151
+ abstained: z.ZodBoolean;
152
+ iterations: z.ZodNumber;
153
+ }, "strip", z.ZodTypeAny, {
154
+ hits: {
155
+ score: number;
156
+ factId: string;
157
+ text: string;
158
+ sensitivity: "public" | "internal" | "secret";
159
+ provenance?: string | undefined;
160
+ }[];
161
+ sufficient: boolean;
162
+ abstained: boolean;
163
+ iterations: number;
164
+ }, {
165
+ hits: {
166
+ score: number;
167
+ factId: string;
168
+ text: string;
169
+ sensitivity: "public" | "internal" | "secret";
170
+ provenance?: string | undefined;
171
+ }[];
172
+ sufficient: boolean;
173
+ abstained: boolean;
174
+ iterations: number;
175
+ }>;
176
+ type DeepRecallInput = z.infer<typeof deepRecallInputSchema>;
177
+ type DeepRecallOutput = z.infer<typeof deepRecallOutputSchema>;
178
+ /**
179
+ * `recall_episodes` — triple-signal episode retrieval (recency ×
180
+ * relevance × importance).
181
+ *
182
+ * @stable
183
+ */
184
+ declare function createRecallEpisodesTool(deps: MemoryToolDeps): Tool<RecallEpisodesInput, RecallEpisodesOutput>;
185
+ /**
186
+ * `conversation_search` — FTS5 search over the active session
187
+ * messages.
188
+ *
189
+ * @stable
190
+ */
191
+ declare function createConversationSearchTool(deps: MemoryToolDeps): Tool<ConversationSearchInput, ConversationSearchOutput>;
192
+ /**
193
+ * `deep_recall` — gated, multi-pass ("deep") recall over the user's
194
+ * factual memory for HARD questions (P2-4). A local difficulty gate keeps
195
+ * simple lookups single-shot; only queries judged hard trigger a
196
+ * grade-and-reformulate loop (bounded by `maxIterations`, hard-capped at
197
+ * 5), widening to one-hop graph expansion on reformulation passes. The
198
+ * output reports `abstained: true` when memory was insufficient even
199
+ * after reformulating — the agent should then say it lacks the
200
+ * information rather than guess. Registered only when the facade is
201
+ * created with `iterativeRetrieval`; otherwise it degrades to a single
202
+ * pass, so prefer the cheaper `fact_search` for ordinary lookups.
203
+ *
204
+ * @stable
205
+ */
206
+ declare function createDeepRecallTool(deps: MemoryToolDeps): Tool<DeepRecallInput, DeepRecallOutput>;
207
+ //#endregion
208
+ export { createConversationSearchTool, createDeepRecallTool, createRecallEpisodesTool };
209
+ //# sourceMappingURL=recall-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall-tools.d.ts","names":[],"sources":["../../src/tools/recall-tools.ts"],"sourcesContent":[],"mappings":";;;;;cAKM,2BAAyB,CAAA,CAAA;;EAAzB,IAAA,eAAA,YASJ,CAAA;;;;;;;;;;;;EAT6B,KAAA,EAAA,MAAA;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A,EAAA;IAAI,KAAA,EAAA,MAAA;;;;;;;;;KApIF,uBAAA,GAA0B,CAAA,CAAE,aAAa;KACzC,wBAAA,GAA2B,CAAA,CAAE,aAAa;cAGzC,uBAAqB,CAAA,CAAA;;;;;;;;;;;;;;;;cAMrB,wBAAsB,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgBvB,eAAA,GAAkB,CAAA,CAAE,aAAa;KACjC,gBAAA,GAAmB,CAAA,CAAE,aAAa;;;;;;;iBAQvB,wBAAA,OACR,iBACL,KAAK,qBAAqB;;;;;;;iBAiDb,4BAAA,OACR,iBACL,KAAK,yBAAyB;;;;;;;;;;;;;;;iBA0CjB,oBAAA,OACR,iBACL,KAAK,iBAAiB"}
@@ -0,0 +1,170 @@
1
+ import { tool } from "@graphorin/tools";
2
+ import { z } from "zod";
3
+
4
+ //#region src/tools/recall-tools.ts
5
+ const recallEpisodesInputSchema = z.object({
6
+ query: z.string().min(1).max(1024),
7
+ topK: z.number().int().positive().max(20).optional(),
8
+ dateRange: z.object({
9
+ from: z.string().datetime().optional(),
10
+ to: z.string().datetime().optional()
11
+ }).optional()
12
+ });
13
+ const recallEpisodesOutputSchema = z.object({ episodes: z.array(z.object({
14
+ episodeId: z.string(),
15
+ summary: z.string(),
16
+ score: z.number(),
17
+ startedAt: z.string(),
18
+ endedAt: z.string(),
19
+ provenance: z.string().optional()
20
+ })) });
21
+ const conversationSearchInputSchema = z.object({
22
+ query: z.string().min(1).max(1024),
23
+ topK: z.number().int().positive().max(20).optional()
24
+ });
25
+ const conversationSearchOutputSchema = z.object({ matches: z.array(z.object({
26
+ messageId: z.string(),
27
+ score: z.number()
28
+ })) });
29
+ const deepRecallSensitivityEnum = z.enum([
30
+ "public",
31
+ "internal",
32
+ "secret"
33
+ ]);
34
+ const deepRecallInputSchema = z.object({
35
+ query: z.string().min(1).max(1024),
36
+ topK: z.number().int().positive().max(50).optional(),
37
+ maxIterations: z.number().int().min(1).max(5).optional(),
38
+ asOf: z.string().datetime().optional()
39
+ });
40
+ const deepRecallOutputSchema = z.object({
41
+ hits: z.array(z.object({
42
+ factId: z.string(),
43
+ text: z.string(),
44
+ score: z.number(),
45
+ sensitivity: deepRecallSensitivityEnum,
46
+ provenance: z.string().optional()
47
+ })),
48
+ sufficient: z.boolean(),
49
+ abstained: z.boolean(),
50
+ iterations: z.number().int()
51
+ });
52
+ /**
53
+ * `recall_episodes` — triple-signal episode retrieval (recency ×
54
+ * relevance × importance).
55
+ *
56
+ * @stable
57
+ */
58
+ function createRecallEpisodesTool(deps) {
59
+ return tool({
60
+ name: "recall_episodes",
61
+ description: "Recall summarized episodes (multi-message stretches of past activity) matching a natural-language query. Combines vector relevance, time-decay recency, and the per-episode importance score. Use for long-horizon recall ('the last time we discussed X').",
62
+ inputSchema: recallEpisodesInputSchema,
63
+ outputSchema: recallEpisodesOutputSchema,
64
+ sideEffectClass: "read-only",
65
+ sandboxPolicy: "none",
66
+ sensitivity: "internal",
67
+ memoryGuardTier: "pure",
68
+ tags: ["memory", "episodic"],
69
+ async execute(input, ctx) {
70
+ const scope = await deps.resolveScope(ctx);
71
+ const dateRange = input.dateRange !== void 0 ? {
72
+ ...input.dateRange.from !== void 0 ? { from: input.dateRange.from } : {},
73
+ ...input.dateRange.to !== void 0 ? { to: input.dateRange.to } : {}
74
+ } : void 0;
75
+ return { episodes: (await deps.episodic.search(scope, input.query, {
76
+ ...input.topK !== void 0 ? { topK: input.topK } : {},
77
+ ...dateRange !== void 0 ? { dateRange } : {},
78
+ signal: ctx.signal
79
+ })).map((hit) => ({
80
+ episodeId: hit.record.id,
81
+ summary: hit.record.summary,
82
+ score: hit.score,
83
+ startedAt: hit.record.startedAt,
84
+ endedAt: hit.record.endedAt,
85
+ ...hit.record.provenance !== void 0 ? { provenance: hit.record.provenance } : {}
86
+ })) };
87
+ }
88
+ });
89
+ }
90
+ /**
91
+ * `conversation_search` — FTS5 search over the active session
92
+ * messages.
93
+ *
94
+ * @stable
95
+ */
96
+ function createConversationSearchTool(deps) {
97
+ return tool({
98
+ name: "conversation_search",
99
+ description: "Search the active session message log by natural-language query. Returns up to `topK` matched messages with their stable id and BM25 score.",
100
+ inputSchema: conversationSearchInputSchema,
101
+ outputSchema: conversationSearchOutputSchema,
102
+ sideEffectClass: "read-only",
103
+ sandboxPolicy: "none",
104
+ sensitivity: "internal",
105
+ memoryGuardTier: "pure",
106
+ tags: ["memory", "session"],
107
+ async execute(input, ctx) {
108
+ const scope = await deps.resolveScope(ctx);
109
+ return { matches: (await deps.session.search(scope, input.query, {
110
+ ...input.topK !== void 0 ? { topK: input.topK } : {},
111
+ signal: ctx.signal
112
+ })).map((hit) => ({
113
+ messageId: hit.record.id,
114
+ score: hit.score
115
+ })) };
116
+ }
117
+ });
118
+ }
119
+ /**
120
+ * `deep_recall` — gated, multi-pass ("deep") recall over the user's
121
+ * factual memory for HARD questions (P2-4). A local difficulty gate keeps
122
+ * simple lookups single-shot; only queries judged hard trigger a
123
+ * grade-and-reformulate loop (bounded by `maxIterations`, hard-capped at
124
+ * 5), widening to one-hop graph expansion on reformulation passes. The
125
+ * output reports `abstained: true` when memory was insufficient even
126
+ * after reformulating — the agent should then say it lacks the
127
+ * information rather than guess. Registered only when the facade is
128
+ * created with `iterativeRetrieval`; otherwise it degrades to a single
129
+ * pass, so prefer the cheaper `fact_search` for ordinary lookups.
130
+ *
131
+ * @stable
132
+ */
133
+ function createDeepRecallTool(deps) {
134
+ return tool({
135
+ name: "deep_recall",
136
+ description: "Multi-pass ('deep') recall over the user's long-term factual memory for HARD multi-hop or temporal questions one search can't answer (e.g. 'who recommended the book the person I met in Tbilisi mentioned?'). A difficulty gate keeps simple lookups single-shot; hard questions trigger a bounded grade-and-reformulate loop. If `abstained` is true the memory was insufficient even after reformulating — tell the user you don't have enough stored to answer and DO NOT guess. Prefer the cheaper fact_search for ordinary lookups.",
137
+ inputSchema: deepRecallInputSchema,
138
+ outputSchema: deepRecallOutputSchema,
139
+ sideEffectClass: "read-only",
140
+ sandboxPolicy: "none",
141
+ sensitivity: "internal",
142
+ memoryGuardTier: "pure",
143
+ tags: ["memory", "semantic"],
144
+ async execute(input, ctx) {
145
+ const scope = await deps.resolveScope(ctx);
146
+ const result = await deps.semantic.searchIterative(scope, input.query, {
147
+ ...input.topK !== void 0 ? { topK: input.topK } : {},
148
+ ...input.maxIterations !== void 0 ? { maxIterations: input.maxIterations } : {},
149
+ ...input.asOf !== void 0 ? { asOf: input.asOf } : {},
150
+ signal: ctx.signal
151
+ });
152
+ return {
153
+ hits: result.hits.map((hit) => ({
154
+ factId: hit.record.id,
155
+ text: hit.record.text,
156
+ score: hit.score,
157
+ sensitivity: hit.record.sensitivity,
158
+ ...hit.record.provenance !== void 0 ? { provenance: hit.record.provenance } : {}
159
+ })),
160
+ sufficient: result.sufficient,
161
+ abstained: result.abstained,
162
+ iterations: result.iterations
163
+ };
164
+ }
165
+ });
166
+ }
167
+
168
+ //#endregion
169
+ export { createConversationSearchTool, createDeepRecallTool, createRecallEpisodesTool };
170
+ //# sourceMappingURL=recall-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall-tools.js","names":[],"sources":["../../src/tools/recall-tools.ts"],"sourcesContent":["import type { Tool } from '@graphorin/core';\nimport { tool } from '@graphorin/tools';\nimport { z } from 'zod';\nimport type { MemoryToolDeps } from './types.js';\n\nconst recallEpisodesInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n dateRange: z\n .object({\n from: z.string().datetime().optional(),\n to: z.string().datetime().optional(),\n })\n .optional(),\n});\nconst recallEpisodesOutputSchema = z.object({\n episodes: z.array(\n z.object({\n episodeId: z.string(),\n summary: z.string(),\n score: z.number(),\n startedAt: z.string(),\n endedAt: z.string(),\n /** Trust-provenance tag (MST-10) — synthesized episodes say so. */\n provenance: z.string().optional(),\n }),\n ),\n});\n\ntype RecallEpisodesInput = z.infer<typeof recallEpisodesInputSchema>;\ntype RecallEpisodesOutput = z.infer<typeof recallEpisodesOutputSchema>;\n\nconst conversationSearchInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n});\nconst conversationSearchOutputSchema = z.object({\n matches: z.array(\n z.object({\n messageId: z.string(),\n score: z.number(),\n }),\n ),\n});\n\ntype ConversationSearchInput = z.infer<typeof conversationSearchInputSchema>;\ntype ConversationSearchOutput = z.infer<typeof conversationSearchOutputSchema>;\n\nconst deepRecallSensitivityEnum = z.enum(['public', 'internal', 'secret']);\nconst deepRecallInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(50).optional(),\n maxIterations: z.number().int().min(1).max(5).optional(),\n asOf: z.string().datetime().optional(),\n});\nconst deepRecallOutputSchema = z.object({\n hits: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n score: z.number(),\n sensitivity: deepRecallSensitivityEnum,\n /** Trust-provenance tag (MST-10) — synthesized facts say so. */\n provenance: z.string().optional(),\n }),\n ),\n sufficient: z.boolean(),\n abstained: z.boolean(),\n iterations: z.number().int(),\n});\n\ntype DeepRecallInput = z.infer<typeof deepRecallInputSchema>;\ntype DeepRecallOutput = z.infer<typeof deepRecallOutputSchema>;\n\n/**\n * `recall_episodes` — triple-signal episode retrieval (recency ×\n * relevance × importance).\n *\n * @stable\n */\nexport function createRecallEpisodesTool(\n deps: MemoryToolDeps,\n): Tool<RecallEpisodesInput, RecallEpisodesOutput> {\n return tool<RecallEpisodesInput, RecallEpisodesOutput>({\n name: 'recall_episodes',\n description:\n \"Recall summarized episodes (multi-message stretches of past activity) matching a natural-language query. Combines vector relevance, time-decay recency, and the per-episode importance score. Use for long-horizon recall ('the last time we discussed X').\",\n inputSchema: recallEpisodesInputSchema,\n outputSchema: recallEpisodesOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'episodic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const dateRange =\n input.dateRange !== undefined\n ? {\n ...(input.dateRange.from !== undefined ? { from: input.dateRange.from } : {}),\n ...(input.dateRange.to !== undefined ? { to: input.dateRange.to } : {}),\n }\n : undefined;\n const hits = await deps.episodic.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(dateRange !== undefined ? { dateRange } : {}),\n signal: ctx.signal,\n });\n return {\n episodes: hits.map((hit) => ({\n episodeId: hit.record.id,\n summary: hit.record.summary,\n score: hit.score,\n startedAt: hit.record.startedAt,\n endedAt: hit.record.endedAt,\n // MST-10: surface origin so a consumer can tell a synthesized\n // (consolidator-extracted) episode from a first-party record —\n // recalled text re-enters the model as trusted tool output.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n })),\n };\n },\n });\n}\n\n/**\n * `conversation_search` — FTS5 search over the active session\n * messages.\n *\n * @stable\n */\nexport function createConversationSearchTool(\n deps: MemoryToolDeps,\n): Tool<ConversationSearchInput, ConversationSearchOutput> {\n return tool<ConversationSearchInput, ConversationSearchOutput>({\n name: 'conversation_search',\n description:\n 'Search the active session message log by natural-language query. Returns up to `topK` matched messages with their stable id and BM25 score.',\n inputSchema: conversationSearchInputSchema,\n outputSchema: conversationSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'session'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.session.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n signal: ctx.signal,\n });\n return {\n matches: hits.map((hit) => ({\n messageId: hit.record.id,\n score: hit.score,\n })),\n };\n },\n });\n}\n\n/**\n * `deep_recall` — gated, multi-pass (\"deep\") recall over the user's\n * factual memory for HARD questions (P2-4). A local difficulty gate keeps\n * simple lookups single-shot; only queries judged hard trigger a\n * grade-and-reformulate loop (bounded by `maxIterations`, hard-capped at\n * 5), widening to one-hop graph expansion on reformulation passes. The\n * output reports `abstained: true` when memory was insufficient even\n * after reformulating — the agent should then say it lacks the\n * information rather than guess. Registered only when the facade is\n * created with `iterativeRetrieval`; otherwise it degrades to a single\n * pass, so prefer the cheaper `fact_search` for ordinary lookups.\n *\n * @stable\n */\nexport function createDeepRecallTool(\n deps: MemoryToolDeps,\n): Tool<DeepRecallInput, DeepRecallOutput> {\n return tool<DeepRecallInput, DeepRecallOutput>({\n name: 'deep_recall',\n description:\n \"Multi-pass ('deep') recall over the user's long-term factual memory for HARD multi-hop or temporal questions one search can't answer (e.g. 'who recommended the book the person I met in Tbilisi mentioned?'). A difficulty gate keeps simple lookups single-shot; hard questions trigger a bounded grade-and-reformulate loop. If `abstained` is true the memory was insufficient even after reformulating — tell the user you don't have enough stored to answer and DO NOT guess. Prefer the cheaper fact_search for ordinary lookups.\",\n inputSchema: deepRecallInputSchema,\n outputSchema: deepRecallOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const result = await deps.semantic.searchIterative(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(input.maxIterations !== undefined ? { maxIterations: input.maxIterations } : {}),\n ...(input.asOf !== undefined ? { asOf: input.asOf } : {}),\n signal: ctx.signal,\n });\n return {\n hits: result.hits.map((hit) => ({\n factId: hit.record.id,\n text: hit.record.text,\n score: hit.score,\n sensitivity: hit.record.sensitivity,\n // MST-10: origin annotation, mirroring fact_search.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n })),\n sufficient: result.sufficient,\n abstained: result.abstained,\n iterations: result.iterations,\n };\n },\n });\n}\n"],"mappings":";;;;AAKA,MAAM,4BAA4B,EAAE,OAAO;CACzC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAA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AAE;IACH,YAAY,OAAO;IACnB,WAAW,OAAO;IAClB,YAAY,OAAO;IACpB;;EAEJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { EpisodicMemory } from "../tiers/episodic-memory.js";
2
+ import { SemanticMemory } from "../tiers/semantic-memory.js";
3
+ import { ProceduralMemory } from "../tiers/procedural-memory.js";
4
+ import { SessionMemory } from "../tiers/session-memory.js";
5
+ import { SharedMemory } from "../tiers/shared-memory.js";
6
+ import { WorkingMemory } from "../tiers/working-memory.js";
7
+ import * as _graphorin_core0 from "@graphorin/core";
8
+ import { SessionScope } from "@graphorin/core";
9
+
10
+ //#region src/tools/types.d.ts
11
+
12
+ /**
13
+ * Resolver that produces the live {@link SessionScope} for the tool
14
+ * call from the surrounding agent run context. The agent runtime
15
+ * (Phase 12) supplies a closure that reads `RunContext` directly;
16
+ * standalone callers can pass a fixed scope.
17
+ *
18
+ * @stable
19
+ */
20
+ type ScopeResolver = (ctx: _graphorin_core0.ToolExecutionContext<unknown>) => SessionScope | Promise<SessionScope>;
21
+ /**
22
+ * Dependency bundle threaded into every memory tool. Exposed
23
+ * separately from the {@link Tool} surface so the executor can scope
24
+ * the dependencies per call without leaking the wider memory facade
25
+ * into the tool author surface.
26
+ *
27
+ * @stable
28
+ */
29
+ interface MemoryToolDeps {
30
+ readonly working: WorkingMemory;
31
+ readonly session: SessionMemory;
32
+ readonly episodic: EpisodicMemory;
33
+ readonly semantic: SemanticMemory;
34
+ readonly procedural: ProceduralMemory;
35
+ readonly shared: SharedMemory;
36
+ readonly resolveScope: ScopeResolver;
37
+ }
38
+ //#endregion
39
+ export { MemoryToolDeps, ScopeResolver };
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAgBA;;;;;AAE2B,KAFf,aAAA,GAEe,CAAA,GAAA,EAFF,gBAAA,CACQ,oBACN,CAAA,OAAA,CAAA,EAAA,GAAtB,YAAsB,GAAP,OAAO,CAAC,YAAD,CAAA;AAU3B;;;;;;;;AAOsC,UAPrB,cAAA,CAOqB;oBANlB;oBACA;qBACC;qBACA;uBACE;mBACJ;yBACM"}
package/package.json ADDED
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "@graphorin/memory",
3
+ "version": "0.5.0",
4
+ "description": "Six-tier memory system for the Graphorin framework: createMemory() facade with working / session / episodic / semantic / procedural / shared sub-modules, eleven memory tools wired into @graphorin/tools, hybrid vector + FTS5 search composed through Reciprocal Rank Fusion (k=60 default) with a pluggable reranker hook, a multi-stage conflict resolution pipeline (exact dedup → embedding three-zone → heuristic regex → subject/predicate → defer-to-deep) with an English locale pack default + plug-in locales, an embedder migration runner with three coexistence policies (lock-on-first / multi-active / auto-migrate), per-record embedder_id enforcement, multi-agent attribution, append-only writes with soft-delete + supersede semantics, default-on bi-temporal storage, provenance + quarantine safety gate for synthesized memory, AISpan emission for every operation, and tier-aware memory-modification guard wiring.",
5
+ "license": "MIT",
6
+ "author": "Oleksiy Stepurenko",
7
+ "homepage": "https://github.com/o-stepper/graphorin/tree/main/packages/memory",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/o-stepper/graphorin.git",
11
+ "directory": "packages/memory"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/o-stepper/graphorin/issues"
15
+ },
16
+ "keywords": [
17
+ "graphorin",
18
+ "ai",
19
+ "agents",
20
+ "framework",
21
+ "memory",
22
+ "long-term-memory",
23
+ "working-memory",
24
+ "session-memory",
25
+ "episodic-memory",
26
+ "semantic-memory",
27
+ "procedural-memory",
28
+ "shared-memory",
29
+ "rrf",
30
+ "hybrid-search",
31
+ "rerank",
32
+ "conflict-resolution",
33
+ "embedder-migration",
34
+ "bi-temporal",
35
+ "multi-agent"
36
+ ],
37
+ "type": "module",
38
+ "engines": {
39
+ "node": ">=22.0.0"
40
+ },
41
+ "main": "./dist/index.js",
42
+ "module": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "import": "./dist/index.js"
48
+ },
49
+ "./facade": {
50
+ "types": "./dist/facade.d.ts",
51
+ "import": "./dist/facade.js"
52
+ },
53
+ "./tiers": {
54
+ "types": "./dist/tiers/index.d.ts",
55
+ "import": "./dist/tiers/index.js"
56
+ },
57
+ "./tools": {
58
+ "types": "./dist/tools/index.d.ts",
59
+ "import": "./dist/tools/index.js"
60
+ },
61
+ "./search": {
62
+ "types": "./dist/search/index.d.ts",
63
+ "import": "./dist/search/index.js"
64
+ },
65
+ "./conflict": {
66
+ "types": "./dist/conflict/index.d.ts",
67
+ "import": "./dist/conflict/index.js"
68
+ },
69
+ "./migration": {
70
+ "types": "./dist/migration/index.d.ts",
71
+ "import": "./dist/migration/index.js"
72
+ },
73
+ "./errors": {
74
+ "types": "./dist/errors/index.d.ts",
75
+ "import": "./dist/errors/index.js"
76
+ },
77
+ "./package.json": "./package.json"
78
+ },
79
+ "files": [
80
+ "dist",
81
+ "README.md",
82
+ "CHANGELOG.md",
83
+ "LICENSE"
84
+ ],
85
+ "dependencies": {
86
+ "@graphorin/core": "0.5.0",
87
+ "@graphorin/observability": "0.5.0",
88
+ "@graphorin/security": "0.5.0",
89
+ "@graphorin/tools": "0.5.0"
90
+ },
91
+ "peerDependencies": {
92
+ "zod": "^3.23.0 || ^4.0.0"
93
+ },
94
+ "peerDependenciesMeta": {
95
+ "zod": {
96
+ "optional": false
97
+ }
98
+ },
99
+ "publishConfig": {
100
+ "access": "public",
101
+ "provenance": true
102
+ },
103
+ "devDependencies": {
104
+ "@types/better-sqlite3": "^7.6.13",
105
+ "better-sqlite3": "^12.9.0",
106
+ "fast-check": "^3.23.0",
107
+ "zod": "^3.25.0",
108
+ "@graphorin/store-sqlite": "0.5.0",
109
+ "@graphorin/embedder-transformersjs": "0.5.0",
110
+ "@graphorin/triggers": "0.5.0"
111
+ },
112
+ "scripts": {
113
+ "build": "tsdown",
114
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",
115
+ "test": "vitest run",
116
+ "lint": "biome check .",
117
+ "clean": "rimraf dist .turbo *.tsbuildinfo"
118
+ }
119
+ }