tsunami-memory 1.0.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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +501 -0
  3. package/README.zh-CN.md +485 -0
  4. package/package.json +46 -0
  5. package/server/api.ts +125 -0
  6. package/server/mcp.ts +221 -0
  7. package/src/bun_memory_store.ts +340 -0
  8. package/src/classifier_keywords.ts +115 -0
  9. package/src/core/project_state.ts +88 -0
  10. package/src/index.ts +54 -0
  11. package/src/legacy_compat/tsunami_compat.ts +22 -0
  12. package/src/legacy_compat/tsunami_legacy_identity.ts +13 -0
  13. package/src/legacy_compat/tsunami_legacy_taxonomy.ts +197 -0
  14. package/src/memory_audit.ts +32 -0
  15. package/src/memory_conflict_resolver.ts +14 -0
  16. package/src/memory_fabric.ts +31 -0
  17. package/src/memory_manager.ts +10 -0
  18. package/src/memory_promotion.ts +22 -0
  19. package/src/memory_recovery.ts +14 -0
  20. package/src/memory_runtime.ts +7 -0
  21. package/src/migration.ts +163 -0
  22. package/src/provider.ts +68 -0
  23. package/src/runtime/checkpoints/durable_recovery.ts +24 -0
  24. package/src/runtime/paths.ts +11 -0
  25. package/src/storm/basins.ts +57 -0
  26. package/src/storm/boundary.ts +52 -0
  27. package/src/storm/budget.ts +42 -0
  28. package/src/storm/center.ts +396 -0
  29. package/src/storm/confidence.ts +88 -0
  30. package/src/storm/coverage.ts +44 -0
  31. package/src/storm/directive.ts +94 -0
  32. package/src/storm/gate.ts +43 -0
  33. package/src/storm/helpers.ts +172 -0
  34. package/src/storm/horizon.ts +52 -0
  35. package/src/storm/intake.ts +80 -0
  36. package/src/storm/mode.ts +21 -0
  37. package/src/storm/pressure.ts +56 -0
  38. package/src/storm/readiness.ts +29 -0
  39. package/src/storm/saturation.ts +45 -0
  40. package/src/storm/selection.ts +49 -0
  41. package/src/storm/signals.ts +105 -0
  42. package/src/storm/types.ts +216 -0
  43. package/src/tsunami_bun_backend.ts +705 -0
  44. package/src/tsunami_chinese_dialect.ts +19 -0
  45. package/src/tsunami_classifier.ts +137 -0
  46. package/src/tsunami_client.ts +710 -0
  47. package/src/tsunami_execution_gate.ts +232 -0
  48. package/src/tsunami_graph_runtime.ts +359 -0
  49. package/src/tsunami_identity.ts +35 -0
  50. package/src/tsunami_routing.ts +169 -0
  51. package/src/tsunami_runtime_graph_sync.ts +17 -0
  52. package/src/tsunami_schema.ts +403 -0
  53. package/src/tsunami_storage_paths.ts +8 -0
  54. package/src/tsunami_storm_center.ts +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lilShawtty-byte
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,501 @@
1
+ <p align="center">
2
+ <img src="./assets/tsunami-banner.png" width="100%" alt="TSUNAMI Banner"/>
3
+ </p>
4
+
5
+ <h1 align="center">🌊 TSUNAMI</h1>
6
+
7
+ <p align="center">
8
+ <strong>Oceanic Memory Runtime for AI Agents</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ Bun-native • Storm-centered context engine • Hot + cold retrieval • Knowledge graph sync
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="https://img.shields.io/badge/Bun-1.0%2B-fbf0df?style=for-the-badge&logo=bun&logoColor=000" alt="Bun"/>
17
+ <img src="https://img.shields.io/badge/SQLite-FTS5-003B57?style=for-the-badge&logo=sqlite&logoColor=white" alt="SQLite"/>
18
+ <img src="https://img.shields.io/badge/MCP-Compatible-7C3AED?style=for-the-badge" alt="MCP"/>
19
+ <img src="https://img.shields.io/badge/Zero%20Deps-blue?style=for-the-badge" alt="Zero Deps"/>
20
+ <img src="https://img.shields.io/badge/License-MIT-10B981?style=for-the-badge" alt="MIT"/>
21
+ </p>
22
+
23
+ <p align="center">
24
+ <a href="README.zh-CN.md">中文文档</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ <div align="center">
30
+
31
+ ## Why TSUNAMI?
32
+
33
+ </div>
34
+
35
+ Most AI memory systems are **flat**, **stateless**, and **context-fragile**.
36
+
37
+ TSUNAMI treats memory as **flowing currents** — not static text, but **momentum**. Each memory carries energy, creates pressure, links to evidence, and feeds into a live storm center that models the agent's cognitive state in real time.
38
+
39
+ > Instead of storing text, TSUNAMI models **momentum**.
40
+
41
+ ---
42
+
43
+ <div align="center">
44
+
45
+ ## 🌊 Architecture
46
+
47
+ </div>
48
+
49
+ ```mermaid
50
+ graph TD
51
+ TSUNAMI["🌊 TSUNAMI Runtime"]
52
+
53
+ TSUNAMI --> Basin["Basin<br/>Topic Areas"]
54
+ TSUNAMI --> Storm["🌀 Storm Center<br/>Context Engine"]
55
+ TSUNAMI --> Hot["⚡ Hot Retrieval<br/>SQLite FTS5"]
56
+ TSUNAMI --> Cold["❄️ Cold Retrieval<br/>Semantic Graph"]
57
+ TSUNAMI --> Graph["🧠 Knowledge Graph<br/>Triple Store"]
58
+
59
+ Basin --> Project["project"]
60
+ Basin --> Feedback["feedback"]
61
+ Basin --> Reference["reference"]
62
+ Basin --> User["user"]
63
+
64
+ Storm --> Signals["Signal Energy"]
65
+ Storm --> Pressure["Pressure Score"]
66
+ Storm --> Gate["Execution Gate"]
67
+ Storm --> Budget["Budget Control"]
68
+
69
+ Hot --> FTS5["Sub-ms Full-text"]
70
+ Cold --> Traversal["Graph Traversal"]
71
+
72
+ Graph --> Sync["Cross-session Sync"]
73
+ Graph --> Conflict["Conflict Detection"]
74
+ Graph --> Evidence["Evidence Linking"]
75
+
76
+ style TSUNAMI fill:#0d3b66,stroke:#1a73e8,color:#e8f4f8
77
+ style Storm fill:#1a237e,stroke:#5c6bc0,color:#e8eaf6
78
+ style Basin fill:#0d3b66,stroke:#1a73e8,color:#e8f4f8
79
+ style Hot fill:#01579b,stroke:#0288d1,color:#e1f5fe
80
+ style Cold fill:#01579b,stroke:#0288d1,color:#e1f5fe
81
+ style Graph fill:#004d40,stroke:#00897b,color:#e0f2f1
82
+ ```
83
+
84
+ ---
85
+
86
+ <div align="center">
87
+
88
+ ## 🧩 Core Systems
89
+
90
+ </div>
91
+
92
+ <table>
93
+ <tr>
94
+ <td width="50%">
95
+
96
+ ### 🌀 Storm Center
97
+
98
+ **Active signal convergence engine.**
99
+
100
+ The Storm Center continuously evaluates the agent's context — measuring signal energy, calculating pressure scores, detecting storm modes, and issuing execution gates. It's a real-time cognitive dashboard that tells the agent *what matters right now*.
101
+
102
+ - Pressure analysis with multi-factor scoring
103
+ - Execution gating: `proceed` / `guarded` / `hold`
104
+ - Confidence and readiness assessment
105
+ - Budget allocation per task
106
+
107
+ </td>
108
+ <td width="50%">
109
+
110
+ ### 🌊 Basin & Current Flow
111
+
112
+ **Topic-oriented memory streams.**
113
+
114
+ Memories flow through basins (topic areas) as currents shift. Each basin tracks an active focus, and the system automatically classifies new memories into the correct basin/current pair. Context isn't stored — it *flows*.
115
+
116
+ - 6 basins: epicenter, surface, faultline, abyss, surge, harbor
117
+ - 24 named currents with taxonomy mapping
118
+ - Automatic text classification
119
+ - Legacy wing/room compatibility
120
+
121
+ </td>
122
+ </tr>
123
+
124
+ <tr>
125
+ <td width="50%">
126
+
127
+ ### ⚡ Hot + Cold Retrieval
128
+
129
+ **Dual-path recall engine.**
130
+
131
+ Hot retrieval hits SQLite FTS5 for sub-millisecond full-text search. Cold retrieval traverses the knowledge graph for semantic, relational discovery. Both paths are always available and context-weighted.
132
+
133
+ - FTS5 full-text search (sub-millisecond)
134
+ - Knowledge graph BFS traversal
135
+ - Tunnel discovery between wings
136
+ - Temporal validity tracking on all triples
137
+
138
+ </td>
139
+ <td width="50%">
140
+
141
+ ### 🧠 Runtime Graph Sync
142
+
143
+ **Persistent distributed cognition.**
144
+
145
+ Memories don't exist in isolation — they form a graph. Every memory can be linked to evidence, connected across sessions, and checked for conflicts. The graph syncs automatically with each write.
146
+
147
+ - Cross-session memory continuity
148
+ - Conflict detection with confidence adjustment
149
+ - Evidence linking to files, conversations, and configs
150
+ - Triple-store with confidence, validity, and provenance
151
+
152
+ </td>
153
+ </tr>
154
+ </table>
155
+
156
+ ---
157
+
158
+ <div align="center">
159
+
160
+ ## ⚡ Quick Start
161
+
162
+ </div>
163
+
164
+ ```bash
165
+ bun install
166
+ ```
167
+
168
+ ```typescript
169
+ import {
170
+ tsunamiAdd, tsunamiSearch,
171
+ buildTsunamiStormCenter, formatTsunamiStormCenterText,
172
+ } from './src/index.ts';
173
+
174
+ // Store a memory
175
+ const id = await tsunamiAdd('project', 'tasks', 'Completed API refactor', 5);
176
+
177
+ // Full-text search — sub-millisecond FTS5
178
+ const hits = await tsunamiSearch('refactor', 'project', undefined, 5);
179
+
180
+ // Storm center — real-time context analysis
181
+ const storm = buildTsunamiStormCenter({ query: 'continue work' });
182
+ console.log(formatTsunamiStormCenterText(storm));
183
+ ```
184
+
185
+ > Zero external dependencies. No server needed. SQLite ships with Bun.
186
+ > Want HTTP or MCP access? See [Interfaces](#-interfaces) below.
187
+
188
+ > Zero external runtime dependencies. SQLite is built into Bun.
189
+
190
+ ---
191
+
192
+ <div align="center">
193
+
194
+ ## 🔌 Interfaces
195
+
196
+ </div>
197
+
198
+ TSUNAMI exposes three interfaces. Choose the one that fits your stack.
199
+
200
+ ---
201
+
202
+ ### 🤖 MCP Tools — Claude Code, Cursor, Windsurf
203
+
204
+ Configure once in `~/.claude/mcp.json`:
205
+
206
+ ```json
207
+ {
208
+ "mcpServers": {
209
+ "tsunami": {
210
+ "command": "bun",
211
+ "args": ["run", "/absolute/path/to/TSUNAMI/server/mcp.ts"],
212
+ "env": { "TSUNAMI_HOME": "~/.tsunami" }
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ > Replace `/absolute/path/to/TSUNAMI` with `pwd` if running from the repo, or the actual install path.
219
+
220
+ The MCP server starts automatically. Eight tools available:
221
+
222
+ <details open>
223
+ <summary><strong>🌀 tsunami_storm</strong> — Build storm center context</summary>
224
+
225
+ ```json
226
+ { "query": "continue the API work" }
227
+ ```
228
+
229
+ Returns flow direction, storm mode, pressure level, execution gate, budget, and prioritized action directive.
230
+
231
+ </details>
232
+
233
+ <details>
234
+ <summary><strong>🌊 tsunami_add</strong> — Store a memory</summary>
235
+
236
+ ```json
237
+ { "content": "Decided to use Redis for caching", "wing": "decision", "energy": 4 }
238
+ ```
239
+
240
+ Returns a unique `bunmem_xxx` ID. Supports Chinese, emoji, any Unicode.
241
+
242
+ </details>
243
+
244
+ <details>
245
+ <summary><strong>🔍 tsunami_search</strong> — FTS5 full-text search</summary>
246
+
247
+ ```json
248
+ { "query": "Redis cache", "wing": "project", "limit": 5 }
249
+ ```
250
+
251
+ Sub-millisecond SQLite FTS5 search with optional wing/room filtering.
252
+
253
+ </details>
254
+
255
+ <details>
256
+ <summary><strong>📋 tsunami_recall</strong> — Context-aware recall</summary>
257
+
258
+ ```json
259
+ { "wing": "project", "limit": 10 }
260
+ ```
261
+
262
+ Pulls recent memories by topic, ordered by importance and recency.
263
+
264
+ </details>
265
+
266
+ <details>
267
+ <summary><strong>📜 tsunami_timeline</strong> — Chronological feed</summary>
268
+
269
+ ```json
270
+ { "limit": 20 }
271
+ ```
272
+
273
+ All memories in time order.
274
+
275
+ </details>
276
+
277
+ <details>
278
+ <summary><strong>📓 tsunami_diary</strong> — Session log</summary>
279
+
280
+ ```json
281
+ { "entry": "Today I built the auth module", "agent": "claude" }
282
+ ```
283
+
284
+ Auto-timestamped diary entries.
285
+
286
+ </details>
287
+
288
+ <details>
289
+ <summary><strong>📊 tsunami_status</strong> — System health</summary>
290
+
291
+ ```json
292
+ {}
293
+ ```
294
+
295
+ Memory counts, wing stats, backend info.
296
+
297
+ </details>
298
+
299
+ <details>
300
+ <summary><strong>🗂️ tsunami_wings</strong> — Topic taxonomy</summary>
301
+
302
+ ```json
303
+ {}
304
+ ```
305
+
306
+ All basins/wings with entry counts.
307
+
308
+ </details>
309
+
310
+ ---
311
+
312
+ ### 🌐 HTTP API — Any language
313
+
314
+ ```bash
315
+ TSUNAMI_PORT=18904 TSUNAMI_HOME=~/.tsunami bun run server/api.ts
316
+ ```
317
+
318
+ | Method | Endpoint | Purpose |
319
+ |--------|----------|---------|
320
+ | `POST` | `/add` | 🌊 Store memory |
321
+ | `GET` | `/search` | 🔍 FTS5 full-text search |
322
+ | `GET` | `/recall` | 📋 Context recall |
323
+ | `GET` | `/storm` | 🌀 Build storm center |
324
+ | `GET` | `/status` | 📊 System health |
325
+ | `GET` | `/timeline` | 📜 Time-ordered feed |
326
+ | `POST` | `/diary` | 📓 Session log |
327
+ | `GET` | `/health` | ✅ Liveness check |
328
+
329
+ <table>
330
+ <tr><td width="33%">
331
+
332
+ **Shell**
333
+
334
+ ```bash
335
+ curl -X POST localhost:18904/add \
336
+ -H 'Content-Type: application/json' \
337
+ -d '{"wing":"project",
338
+ "content":"Refactored auth",
339
+ "energy":4}'
340
+ ```
341
+
342
+ </td><td width="33%">
343
+
344
+ **Python**
345
+
346
+ ```python
347
+ import requests
348
+ r = requests.post(
349
+ 'http://localhost:18904/add',
350
+ json={'wing': 'feedback',
351
+ 'content': 'User prefers dark mode',
352
+ 'energy': 5}
353
+ )
354
+ ```
355
+
356
+ </td><td width="33%">
357
+
358
+ **TypeScript**
359
+
360
+ ```typescript
361
+ const r = await fetch(
362
+ 'http://localhost:18904/add', {
363
+ method: 'POST',
364
+ headers: {'Content-Type': 'application/json'},
365
+ body: JSON.stringify({
366
+ wing: 'reference',
367
+ content: 'Bun sqlite API docs',
368
+ energy: 3})
369
+ });
370
+ ```
371
+
372
+ </td></tr>
373
+ </table>
374
+
375
+ ---
376
+
377
+ ### 📦 TypeScript SDK — Programmatic
378
+
379
+ ```typescript
380
+ import {
381
+ tsunamiAdd, tsunamiSearch, tsunamiRecall,
382
+ tsunamiKgAdd, tsunamiKgQuery,
383
+ buildTsunamiStormCenter, formatTsunamiStormCenterText,
384
+ buildTsunamiExecutionGate, applyTsunamiExecutionGateToTool,
385
+ classifyMemory,
386
+ } from './src/index.ts';
387
+
388
+ const id = await tsunamiAdd('project', 'tasks', 'Completed API refactor', 5);
389
+ const hits = await tsunamiSearch('refactor', 'project', undefined, 10);
390
+
391
+ const storm = buildTsunamiStormCenter({
392
+ projectDir: './my-project',
393
+ query: 'continue work',
394
+ });
395
+ console.log(formatTsunamiStormCenterText(storm));
396
+ ```
397
+
398
+ ---
399
+
400
+ <div align="center">
401
+
402
+ ## 🤖 Automatic Memory
403
+
404
+ </div>
405
+
406
+ TSUNAMI operations are explicit by default — you decide when to store or recall. For hands-free memory, wire it into Claude Code hooks.
407
+
408
+ **Prerequisite:** HTTP API running as a daemon (`bun run server/api.ts &` or PM2/launchd).
409
+
410
+ ### Session-Start · Context Injection
411
+
412
+ Claude wakes up with full storm center context:
413
+
414
+ ```json
415
+ {
416
+ "hooks": {
417
+ "SessionStart": [{
418
+ "matcher": "",
419
+ "hooks": [{
420
+ "type": "command",
421
+ "command": "STORM=$(curl -s 'http://localhost:18904/storm' | python3 -c \"import sys,json; d=json.load(sys.stdin); t=d.get('storm',{}).get('text',''); print(t[:3000])\" 2>/dev/null); if [ -n \"$STORM\" ]; then echo \"$STORM\"; fi"
422
+ }]
423
+ }]
424
+ }
425
+ }
426
+ ```
427
+
428
+ ### Session-End · Auto-Diary
429
+
430
+ Each session is logged automatically:
431
+
432
+ ```json
433
+ {
434
+ "hooks": {
435
+ "Stop": [{
436
+ "matcher": "",
437
+ "hooks": [{
438
+ "type": "command",
439
+ "command": "curl -s -X POST http://localhost:18904/diary -H 'Content-Type: application/json' -d '{\"entry\":\"Session ended\",\"agent\":\"claude\",\"wing\":\"session\",\"importance\":3}' > /dev/null 2>&1"
440
+ }]
441
+ }]
442
+ }
443
+ }
444
+ ```
445
+
446
+ ### Every Turn · Decision Capture
447
+
448
+ Keywords like `decide`, `merge`, `deploy`, `发布`, `上线` auto-archive to the decision basin:
449
+
450
+ ```json
451
+ {
452
+ "hooks": {
453
+ "UserPromptSubmit": [{
454
+ "matcher": "",
455
+ "hooks": [{
456
+ "type": "command",
457
+ "command": "PROMPT=$(cat); if echo \"$PROMPT\" | grep -qiE 'decid|chose|finaliz|merge|deploy|releas|shipp|决定|选择|合并|部署|发布|上线'; then curl -s -X POST http://localhost:18904/add -H 'Content-Type: application/json' -d \"{\\\"wing\\\":\\\"decision\\\",\\\"content\\\":\\\"$(echo $PROMPT | tr '\\\"' ' ' | head -c 500)\\\",\\\"energy\\\":4}\" > /dev/null 2>&1; fi"
458
+ }]
459
+ }]
460
+ }
461
+ }
462
+ ```
463
+
464
+ ---
465
+
466
+ <div align="center">
467
+
468
+ ## ⚙️ Configuration
469
+
470
+ </div>
471
+
472
+ | Variable | Default | Description |
473
+ |----------|---------|-------------|
474
+ | `TSUNAMI_HOME` | `.tsunami` | Storage directory |
475
+ | `TSUNAMI_PORT` | `18904` | HTTP API port |
476
+ | `TSUNAMI_STORM_THRESHOLD` | `0.7` | Min energy for storm signal |
477
+ | `TSUNAMI_BUDGET_STEPS` | `99` | Default execution step budget |
478
+
479
+ ---
480
+
481
+ ---
482
+
483
+ <div align="center">
484
+
485
+ ## 🧹 Legacy Compatibility
486
+
487
+ </div>
488
+
489
+ The `legacy_compat/` directory and Python wrapper fallback in `tsunami_client.ts` exist to maintain compile-time compatibility with code extracted from a larger Python-based monorepo. These paths are **disabled by default** and are scheduled for removal in v2.0. New integrations should use the Bun-native SDK, HTTP API, or MCP tools exclusively.
490
+
491
+ ---
492
+
493
+ <div align="center">
494
+
495
+ ## 📄 License
496
+
497
+ </div>
498
+
499
+ <p align="center">
500
+ MIT © TSUNAMI Memory System
501
+ </p>