@theokit/sdk-memory 0.1.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 (99) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +201 -0
  3. package/README.md +86 -0
  4. package/dist/in-memory-provider.d.ts +38 -0
  5. package/dist/in-memory-provider.d.ts.map +1 -0
  6. package/dist/index.cjs +2585 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +40 -0
  9. package/dist/index.d.ts +40 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +2500 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/internal/active-memory-cache.d.ts +49 -0
  14. package/dist/internal/active-memory-cache.d.ts.map +1 -0
  15. package/dist/internal/active-memory-types.d.ts +30 -0
  16. package/dist/internal/active-memory-types.d.ts.map +1 -0
  17. package/dist/internal/active-memory.d.ts +108 -0
  18. package/dist/internal/active-memory.d.ts.map +1 -0
  19. package/dist/internal/adapter-catalog.d.ts +82 -0
  20. package/dist/internal/adapter-catalog.d.ts.map +1 -0
  21. package/dist/internal/adapter-http-error.d.ts +63 -0
  22. package/dist/internal/adapter-http-error.d.ts.map +1 -0
  23. package/dist/internal/batch-encoder.d.ts +30 -0
  24. package/dist/internal/batch-encoder.d.ts.map +1 -0
  25. package/dist/internal/chunk-markdown.d.ts +66 -0
  26. package/dist/internal/chunk-markdown.d.ts.map +1 -0
  27. package/dist/internal/circuit-breaker.d.ts +36 -0
  28. package/dist/internal/circuit-breaker.d.ts.map +1 -0
  29. package/dist/internal/composite-scorer.d.ts +19 -0
  30. package/dist/internal/composite-scorer.d.ts.map +1 -0
  31. package/dist/internal/deepinfra-embedding.d.ts +25 -0
  32. package/dist/internal/deepinfra-embedding.d.ts.map +1 -0
  33. package/dist/internal/dreaming-diary.d.ts +38 -0
  34. package/dist/internal/dreaming-diary.d.ts.map +1 -0
  35. package/dist/internal/dreaming-phases.d.ts +43 -0
  36. package/dist/internal/dreaming-phases.d.ts.map +1 -0
  37. package/dist/internal/dreaming-run.d.ts +49 -0
  38. package/dist/internal/dreaming-run.d.ts.map +1 -0
  39. package/dist/internal/embedding-adapter.d.ts +57 -0
  40. package/dist/internal/embedding-adapter.d.ts.map +1 -0
  41. package/dist/internal/embedding-cache.d.ts +16 -0
  42. package/dist/internal/embedding-cache.d.ts.map +1 -0
  43. package/dist/internal/index-db.d.ts +50 -0
  44. package/dist/internal/index-db.d.ts.map +1 -0
  45. package/dist/internal/index-manager-contract.d.ts +70 -0
  46. package/dist/internal/index-manager-contract.d.ts.map +1 -0
  47. package/dist/internal/index-manager-dispatch.d.ts +36 -0
  48. package/dist/internal/index-manager-dispatch.d.ts.map +1 -0
  49. package/dist/internal/index-manager.d.ts +94 -0
  50. package/dist/internal/index-manager.d.ts.map +1 -0
  51. package/dist/internal/index-schema.d.ts +35 -0
  52. package/dist/internal/index-schema.d.ts.map +1 -0
  53. package/dist/internal/lance-index.d.ts +70 -0
  54. package/dist/internal/lance-index.d.ts.map +1 -0
  55. package/dist/internal/lance-memory-adapter.d.ts +102 -0
  56. package/dist/internal/lance-memory-adapter.d.ts.map +1 -0
  57. package/dist/internal/markdown-store.d.ts +17 -0
  58. package/dist/internal/markdown-store.d.ts.map +1 -0
  59. package/dist/internal/memory-index.d.ts +68 -0
  60. package/dist/internal/memory-index.d.ts.map +1 -0
  61. package/dist/internal/memory-scope.d.ts +21 -0
  62. package/dist/internal/memory-scope.d.ts.map +1 -0
  63. package/dist/internal/memory-types.d.ts +95 -0
  64. package/dist/internal/memory-types.d.ts.map +1 -0
  65. package/dist/internal/migrate-sqlite-to-lance.d.ts +49 -0
  66. package/dist/internal/migrate-sqlite-to-lance.d.ts.map +1 -0
  67. package/dist/internal/migration.d.ts +10 -0
  68. package/dist/internal/migration.d.ts.map +1 -0
  69. package/dist/internal/mistral-embedding.d.ts +23 -0
  70. package/dist/internal/mistral-embedding.d.ts.map +1 -0
  71. package/dist/internal/ollama-embedding.d.ts +48 -0
  72. package/dist/internal/ollama-embedding.d.ts.map +1 -0
  73. package/dist/internal/openai-compatible.d.ts +24 -0
  74. package/dist/internal/openai-compatible.d.ts.map +1 -0
  75. package/dist/internal/openai-embedding.d.ts +34 -0
  76. package/dist/internal/openai-embedding.d.ts.map +1 -0
  77. package/dist/internal/openrouter-embedding.d.ts +25 -0
  78. package/dist/internal/openrouter-embedding.d.ts.map +1 -0
  79. package/dist/internal/query-analyzer.d.ts +16 -0
  80. package/dist/internal/query-analyzer.d.ts.map +1 -0
  81. package/dist/internal/reader.d.ts +64 -0
  82. package/dist/internal/reader.d.ts.map +1 -0
  83. package/dist/internal/session-loader.d.ts +25 -0
  84. package/dist/internal/session-loader.d.ts.map +1 -0
  85. package/dist/internal/session-summary-writer.d.ts +43 -0
  86. package/dist/internal/session-summary-writer.d.ts.map +1 -0
  87. package/dist/internal/sqlite-vec-loader.d.ts +62 -0
  88. package/dist/internal/sqlite-vec-loader.d.ts.map +1 -0
  89. package/dist/internal/tools.d.ts +44 -0
  90. package/dist/internal/tools.d.ts.map +1 -0
  91. package/dist/internal/transcript-store.d.ts +36 -0
  92. package/dist/internal/transcript-store.d.ts.map +1 -0
  93. package/dist/internal/vec-index.d.ts +81 -0
  94. package/dist/internal/vec-index.d.ts.map +1 -0
  95. package/dist/internal/voyage-embedding.d.ts +23 -0
  96. package/dist/internal/voyage-embedding.d.ts.map +1 -0
  97. package/dist/internal/wiki-loader.d.ts +24 -0
  98. package/dist/internal/wiki-loader.d.ts.map +1 -0
  99. package/package.json +74 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,112 @@
1
+ # Changelog — @theokit/sdk-memory
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Security (drift sync — iter 112/114/115, 2026-06-09)
6
+
7
+ Three security/perf hardenings shipped in `@theokit/sdk`'s
8
+ `internal/memory/` copies AFTER Stage 3 source-move completed
9
+ (iter 44-75) were silently absent from `@theokit/sdk-memory`'s
10
+ hybrid copies. Per ADR 0002 Stage 4 byte-equivalence invariant,
11
+ they have now been synced. Consumers routing through
12
+ `@theokit/sdk-memory` get the hardened behavior. The drift detector
13
+ (iter 93) caught each gap and flipped to PASS after the sync.
14
+
15
+ - **T4.9 — cross-tenant cache-key collision (iter 112)** —
16
+ `active-memory-cache.ts`'s `cacheKey` now accepts an optional
17
+ `TenantContext` (`namespace`/`userId`/`scope`) and NUL-separates
18
+ every key part. Pre-sync, two users sharing a process with the
19
+ same query could receive each other's cached result (DR4 finding
20
+ #9 — CRITICAL cross-tenant data leak).
21
+
22
+ - **T4.6 — dreaming O(N²) sweep cap (iter 114)** —
23
+ `dreaming-phases.ts`'s `remPhase` accepts an optional
24
+ `maxFactsPerSweep` (default 500) and deterministically
25
+ subsamples when input exceeds the cap. Pre-sync, a 5000-fact
26
+ sweep ran 12.5M cosine-similarity comparisons (unacceptable).
27
+
28
+ - **T5.2 — Lance SQL escape hardening (iter 115)** —
29
+ `lance-index.ts`'s `escapeSqlValue` now rejects NUL bytes,
30
+ C0 control chars, and DEL via `ConfigurationError({code:
31
+ 'sql_injection_blocked'})`, and escapes backslashes (`\` →
32
+ `\\`) in addition to single quotes. Pre-sync, only `'` → `''`
33
+ was applied — `\'` could escape the closing quote on engines
34
+ that interpret backslash-escapes.
35
+
36
+ ### Added (Stage 3 source-move COMPLETE — iter 44-75, 2026-06-08 → 2026-06-09)
37
+
38
+ 38/38 source files from sdk-core's `internal/memory/*` now have
39
+ canonical hybrid copies in this package. sdk-core retains its copies
40
+ for v1.x back-compat; consumers installing this package get the
41
+ canonical surface that sdk-core's Stage 4 routing delegates to.
42
+
43
+ **Closed clusters:**
44
+ - Dreaming (iter 54+59+60): `dreaming-phases.ts`, `dreaming-diary.ts`,
45
+ `dreaming-run.ts` + `active-memory-types.ts` (iter 48)
46
+ - Sessions (iter 61+62): `session-summary-writer.ts`, `session-loader.ts`
47
+ - Storage (iter 53+55-58+62): `markdown-store.ts`, `chunk-markdown.ts`,
48
+ `reader.ts`, `transcript-store.ts`, `wiki-loader.ts`
49
+ - Index (iter 47+49-50+65-72): `index-manager-contract.ts`,
50
+ `index-schema.ts`, `memory-index.ts`, `index-db.ts`,
51
+ `sqlite-vec-loader.ts`, `vec-index.ts`, `lance-index.ts`,
52
+ `lance-memory-adapter.ts`, `index-manager-dispatch.ts`,
53
+ `index-manager.ts`
54
+ - Migration (iter 63+71): `migration.ts`, `migrate-sqlite-to-lance.ts`
55
+ - Adapters (iter 45+46+73+74): `embedding-adapter.ts`,
56
+ `embedding-cache.ts`, `openai-compatible.ts` + inlined
57
+ `adapter-http-error.ts` + 6 provider adapters
58
+ (openai/mistral/openrouter/voyage/deepinfra/ollama) +
59
+ `adapter-catalog.ts`
60
+ - Core (iter 44+51+52+64+75): `circuit-breaker.ts`,
61
+ `active-memory-cache.ts`, `memory-types.ts`, `tools.ts`,
62
+ `active-memory.ts`
63
+
64
+ **Optional peers** (sdk-memory dynamically loads when present):
65
+ - `better-sqlite3` (iter 65)
66
+ - `sqlite-vec` (iter 66)
67
+ - `@lancedb/lancedb` (iter 68)
68
+
69
+ **287 GREEN tests** across 38 files document every move's behavior;
70
+ **zero unexpected drift** between sdk-core and sdk-memory copies
71
+ (verified by the Stage 3 drift detector, iter 93).
72
+
73
+ ### Added (Phase 1 Stage 3 prep — iter 33-35, 2026-06-08)
74
+ - `createInMemoryMarkdownProvider.recordSessionSummary` ships REAL
75
+ filesystem-backed impl (was no-op). Writes
76
+ `${cwd}/.theokit/memory/sessions/${sanitizeRunId(runId)}.md` via
77
+ `replaceFileAtomic` imported from `@theokit/sdk/internal/persistence`
78
+ (ADR-008 sub-path resolution). Mirrors sdk-core's legacy
79
+ `writeSessionSummary` semantics — YAML frontmatter + User/Assistant
80
+ sections, 2000-char truncation, runId sanitization.
81
+ - `runActivePass()` now reads previously-written session summaries
82
+ from disk + substring-matches against the user message — closes
83
+ the "write but never read" gap. In-process Map facts AND disk-recall
84
+ hits both contribute to `systemPromptAdditions`. Capped at 5 hits
85
+ per pass.
86
+ - NEW LLM-facing tool: `memory_search(query)` — surfaced in
87
+ `buildTools` alongside `memory_remember`. The LLM can explicitly
88
+ query the disk sessions corpus when the user references past
89
+ conversations. Returns JSON `{ok, count, results: [{id, snippet}]}`.
90
+
91
+ ### Changed (Phase 1 physical Stage 1 — iter 19, 2026-06-08)
92
+ - `createInMemoryMarkdownProvider` now implements the new optional
93
+ `sync(handle)` port method (no-op for the in-process impl — facts
94
+ are written synchronously to the Map at handler-call time; nothing
95
+ to re-index post-run). Future LanceDB-backed impl will fire
96
+ `IndexManager.sync()` here. Back-compat preserved: existing impls
97
+ that omit `sync` are still valid per the optional-method spec.
98
+
99
+ ## [0.1.0] — 2026-06-08
100
+
101
+ ### Added
102
+ - Initial release. Consumes the `MemoryProvider` port from `@theokit/sdk@>=1.7.0`
103
+ (SDK 2.0 Phase 1 / T1.6).
104
+ - `createInMemoryMarkdownProvider()` — first concrete impl. In-process
105
+ fact store; LLM-facing `memory_remember` tool; `runActivePass()` emits
106
+ `systemPromptAdditions` for recalled facts; full lifecycle compliance.
107
+
108
+ ### Notes
109
+ - LanceDB / embeddings / circuit-breaker / dreaming-sweep deferred to future
110
+ versions. This release ships the package foundation + a working impl so
111
+ the SDK 2.0 cohort can publish (Phase 7).
112
+ - `peerDependency`: `@theokit/sdk >= 1.7.0` (where the port was shipped).
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 usetheo.dev
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @theokit/sdk-memory
2
+
3
+ Memory subsystem for [`@theokit/sdk`](https://www.npmjs.com/package/@theokit/sdk).
4
+ Implements the kernel-facing `MemoryProvider` port (SDK 2.0 Phase 1 / T1.1 —
5
+ Hexagonal Architecture / SOLID Dependency Inversion).
6
+
7
+ ```ts
8
+ import { Agent } from "@theokit/sdk";
9
+ import { createInMemoryMarkdownProvider } from "@theokit/sdk-memory";
10
+
11
+ const agent = await Agent.create({
12
+ agentId: "support-bot",
13
+ model: { id: "anthropic/claude-3-5-haiku-latest" },
14
+ memoryProvider: createInMemoryMarkdownProvider(),
15
+ // ...other options
16
+ });
17
+ ```
18
+
19
+ ## What ships today (Unreleased, post v0.1.0)
20
+
21
+ `createInMemoryMarkdownProvider()` is now a real cross-session recall
22
+ provider with the full canonical memory surface:
23
+
24
+ | Method | What it does |
25
+ |---|---|
26
+ | `init(opts)` | Captures `cwd` for disk paths; sets up per-agent in-process Map. |
27
+ | `buildTools()` | Surfaces **2 LLM-facing tools**: `memory_remember(content)` + `memory_search(query)`. |
28
+ | `runActivePass()` | Combines in-process facts (this session's Map) AND disk-recalled session summaries (previous sessions, substring-matched against user message). Up to 5 hits. |
29
+ | `recordSessionSummary()` | Real filesystem write to `${cwd}/.theokit/memory/sessions/${runId}.md`. Atomic via sdk-core's `replaceFileAtomic`. Same semantics as sdk-core's legacy `writeSessionSummary`. |
30
+ | `sync()` | No-op (in-process Map writes are synchronous). |
31
+ | `dispose()` | Clears in-process Map. Disk artefacts persist by design (cross-session recall). |
32
+
33
+ LLM-facing tools surfaced via `buildTools`:
34
+
35
+ - **`memory_remember(content)`** — the LLM writes a fact to the
36
+ per-session Map. Useful for "remember this for the rest of this
37
+ conversation" use cases.
38
+ - **`memory_search(query)`** — the LLM queries previously-written
39
+ session summaries on disk. Returns up to 5 short snippets as JSON.
40
+ Useful when the user asks about something from a past conversation.
41
+
42
+ ## What's coming (future versions)
43
+
44
+ - `createLanceMemoryProvider(...)` — persistent LanceDB-backed store
45
+ with **embedding-based ANN recall** (replaces the current substring
46
+ matcher) via OpenAI / Ollama / Voyage embedding adapters.
47
+ - Circuit-breaker + active-memory cache for hot-path resilience.
48
+ - Multi-adapter fan-out (write to multiple stores; merge-dedup recall).
49
+ - Dreaming sweep + memory revisions.
50
+
51
+ ## Cross-package coupling: `@theokit/sdk/internal/persistence`
52
+
53
+ sdk-memory's `recordSessionSummary` consumes
54
+ `replaceFileAtomic` from sdk-core via the
55
+ `@theokit/sdk/internal/persistence` sub-path (per ADR-008). The sub-path
56
+ is internal API — semver-exempt; may break in patch releases. Pin both
57
+ packages to the same SemVer minor when upgrading sdk-core.
58
+
59
+ The cross-package import keeps the **single-process mutex Map invariant**
60
+ intact (one module instance shared across packages — both writers
61
+ serialize against the same registry).
62
+
63
+ ## Architecture
64
+
65
+ This package is a **port consumer**, not a kernel mod. The contract
66
+ lives in `@theokit/sdk/internal/runtime/memory-provider.ts` and is
67
+ exposed to consumers via:
68
+
69
+ ```ts
70
+ import type {
71
+ MemoryProvider,
72
+ MemoryProviderHandle,
73
+ MemoryProviderInitOptions,
74
+ ActiveMemoryPassArgs,
75
+ ActiveMemoryPassResult,
76
+ } from "@theokit/sdk";
77
+ ```
78
+
79
+ The agent loop calls the port's four lifecycle methods at well-defined
80
+ hook points (init / buildTools / runActivePass / dispose). Your impl
81
+ fulfills the contract; sdk-core never imports this package directly —
82
+ that's the seam that makes the split possible.
83
+
84
+ ## License
85
+
86
+ Apache-2.0 © useTheo
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `createInMemoryMarkdownProvider` — first concrete `MemoryProvider`
3
+ * impl shipped in `@theokit/sdk-memory` (SDK 2.0 Phase 1 / T1.6).
4
+ *
5
+ * Goal: prove the contract works end-to-end with a real (non-no-op)
6
+ * impl WITHOUT pulling LanceDB / embedding / circuit-breaker infrastructure.
7
+ * That richer impl lands in subsequent iters.
8
+ *
9
+ * Semantics:
10
+ * - Stores recalled facts in a per-agent in-process Map.
11
+ * - `runActivePass()` returns the facts plus a `systemPromptAdditions`
12
+ * string that joins fact contents with newlines (so the LLM sees
13
+ * them in the system slot).
14
+ * - `buildTools()` surfaces a `memory_remember(content)` tool the LLM
15
+ * can call to persist a fact mid-conversation.
16
+ * - `recordSessionSummary()` writes a markdown summary to
17
+ * `${cwd}/.theokit/memory/sessions/${runId}.md` (real disk write
18
+ * via `@theokit/sdk/internal/persistence` per ADR-008).
19
+ * - `dispose()` clears the handle's per-agent map (releases memory).
20
+ *
21
+ * @public
22
+ */
23
+ import type { MemoryProvider } from "@theokit/sdk";
24
+ /**
25
+ * Build a fresh `MemoryProvider` whose facts live in-process. The
26
+ * returned provider is independent — call `createInMemoryMarkdownProvider()`
27
+ * per agent OR share across agents (each `init()` gets its own state).
28
+ *
29
+ * Iter 33: `recordSessionSummary()` writes session-summary markdown
30
+ * files to disk under `${cwd}/.theokit/memory/sessions/`.
31
+ * Iter 34: `runActivePass()` reads back those summaries + substring-
32
+ * matches against the user message for genuine cross-session recall.
33
+ *
34
+ * Future LanceDB-backed impl will replace the substring match with
35
+ * semantic-similarity ANN over embedding vectors.
36
+ */
37
+ export declare function createInMemoryMarkdownProvider(): MemoryProvider;
38
+ //# sourceMappingURL=in-memory-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-provider.d.ts","sourceRoot":"","sources":["../src/in-memory-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EASV,cAAc,EAMf,MAAM,cAAc,CAAC;AAyRtB;;;;;;;;;;;;GAYG;AACH,wBAAgB,8BAA8B,IAAI,cAAc,CAoE/D"}