tsunami-memory 1.0.0 → 1.0.2
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.
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/package.json +3 -3
- package/src/bun_memory_store.ts +1 -27
- package/src/db.ts +41 -0
- package/src/storm/basins.ts +1 -0
- package/src/storm/boundary.ts +1 -0
- package/src/storm/directive.ts +1 -0
- package/src/storm/helpers.ts +8 -1
- package/src/storm/horizon.ts +1 -0
- package/src/storm/pressure.ts +2 -0
- package/src/storm/readiness.ts +2 -1
- package/src/storm/signals.ts +2 -0
- package/src/storm/types.ts +10 -4
- package/src/tsunami_graph_runtime.ts +1 -15
package/README.md
CHANGED
|
@@ -162,14 +162,14 @@ Memories don't exist in isolation — they form a graph. Every memory can be lin
|
|
|
162
162
|
</div>
|
|
163
163
|
|
|
164
164
|
```bash
|
|
165
|
-
bun
|
|
165
|
+
bun add tsunami-memory
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
```typescript
|
|
169
169
|
import {
|
|
170
170
|
tsunamiAdd, tsunamiSearch,
|
|
171
171
|
buildTsunamiStormCenter, formatTsunamiStormCenterText,
|
|
172
|
-
} from '
|
|
172
|
+
} from 'tsunami-memory';
|
|
173
173
|
|
|
174
174
|
// Store a memory
|
|
175
175
|
const id = await tsunamiAdd('project', 'tasks', 'Completed API refactor', 5);
|
|
@@ -383,7 +383,7 @@ import {
|
|
|
383
383
|
buildTsunamiStormCenter, formatTsunamiStormCenterText,
|
|
384
384
|
buildTsunamiExecutionGate, applyTsunamiExecutionGateToTool,
|
|
385
385
|
classifyMemory,
|
|
386
|
-
} from '
|
|
386
|
+
} from 'tsunami-memory';
|
|
387
387
|
|
|
388
388
|
const id = await tsunamiAdd('project', 'tasks', 'Completed API refactor', 5);
|
|
389
389
|
const hits = await tsunamiSearch('refactor', 'project', undefined, 10);
|
package/README.zh-CN.md
CHANGED
|
@@ -162,14 +162,14 @@ graph TD
|
|
|
162
162
|
</div>
|
|
163
163
|
|
|
164
164
|
```bash
|
|
165
|
-
bun
|
|
165
|
+
bun add tsunami-memory
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
```typescript
|
|
169
169
|
import {
|
|
170
170
|
tsunamiAdd, tsunamiSearch,
|
|
171
171
|
buildTsunamiStormCenter, formatTsunamiStormCenterText,
|
|
172
|
-
} from '
|
|
172
|
+
} from 'tsunami-memory';
|
|
173
173
|
|
|
174
174
|
// 存储记忆
|
|
175
175
|
const id = await tsunamiAdd('project', 'tasks', '完成了认证模块的 API 重构', 5);
|
|
@@ -379,7 +379,7 @@ import {
|
|
|
379
379
|
buildTsunamiStormCenter, formatTsunamiStormCenterText,
|
|
380
380
|
buildTsunamiExecutionGate, applyTsunamiExecutionGateToTool,
|
|
381
381
|
classifyMemory,
|
|
382
|
-
} from '
|
|
382
|
+
} from 'tsunami-memory';
|
|
383
383
|
|
|
384
384
|
const id = await tsunamiAdd('project', 'tasks', '完成认证模块重构', 5);
|
|
385
385
|
const hits = await tsunamiSearch('重构', 'project', undefined, 10);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsunami-memory",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "TSUNAMI — Bun-native oceanic memory system with basin/current flow, storm center, hot+cold retrieval, knowledge graph sync, and evidence linking.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
],
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/lilShawtty-byte/Tsunami-Memory.git"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/lilShawtty-byte/Tsunami-Memory/issues"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
19
|
"scripts": {
|
package/src/bun_memory_store.ts
CHANGED
|
@@ -5,36 +5,10 @@
|
|
|
5
5
|
* and content fingerprinting for deduplication. Schema managed by migration runner.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
10
|
-
import { dirname } from 'path';
|
|
8
|
+
import { getDb } from './db';
|
|
11
9
|
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
12
|
-
import { runMigrations, getMigrations } from './migration';
|
|
13
10
|
export { BUN_MEMORY_DB_PATH };
|
|
14
11
|
|
|
15
|
-
// ── Database initialization ──────────────────────────────────
|
|
16
|
-
|
|
17
|
-
function ensureDbDir(): void {
|
|
18
|
-
const dir = dirname(BUN_MEMORY_DB_PATH);
|
|
19
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let _db: Database | null = null;
|
|
23
|
-
|
|
24
|
-
function getDb(): Database {
|
|
25
|
-
if (_db) return _db;
|
|
26
|
-
ensureDbDir();
|
|
27
|
-
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
28
|
-
_db.run('PRAGMA journal_mode = WAL');
|
|
29
|
-
const applied = runMigrations(_db, getMigrations());
|
|
30
|
-
if (applied > 0) {
|
|
31
|
-
// First-run or upgrade — log for observability
|
|
32
|
-
const v = (_db.prepare('SELECT MAX(version) as v FROM schema_version').get() as any)?.v ?? 0;
|
|
33
|
-
console.log(`[TSUNAMI] migrations applied: ${applied}, now at v${v}`);
|
|
34
|
-
}
|
|
35
|
-
return _db;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
12
|
// ── ID Generation ────────────────────────────────────────────
|
|
39
13
|
|
|
40
14
|
function generateId(): string {
|
package/src/db.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TSUNAMI shared database connection.
|
|
3
|
+
*
|
|
4
|
+
* Single WAL-mode SQLite connection shared by all modules.
|
|
5
|
+
* Schema is managed by the migration runner.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Database } from 'bun:sqlite';
|
|
9
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
10
|
+
import { dirname } from 'node:path';
|
|
11
|
+
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
12
|
+
import { runMigrations, getMigrations } from './migration';
|
|
13
|
+
|
|
14
|
+
let _db: Database | null = null;
|
|
15
|
+
|
|
16
|
+
/** Get or create the shared database connection. Thread-safe via module-level singleton. */
|
|
17
|
+
export function getDb(): Database {
|
|
18
|
+
if (_db) return _db;
|
|
19
|
+
|
|
20
|
+
const dir = dirname(BUN_MEMORY_DB_PATH);
|
|
21
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
22
|
+
|
|
23
|
+
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
24
|
+
_db.run('PRAGMA journal_mode = WAL');
|
|
25
|
+
|
|
26
|
+
const applied = runMigrations(_db, getMigrations());
|
|
27
|
+
if (applied > 0) {
|
|
28
|
+
const v = (_db.prepare('SELECT MAX(version) as v FROM schema_version').get() as any)?.v ?? 0;
|
|
29
|
+
console.log(`[TSUNAMI] migrations applied: ${applied}, now at v${v}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return _db;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Close the database connection. Mainly useful in tests. */
|
|
36
|
+
export function closeDb(): void {
|
|
37
|
+
if (_db) {
|
|
38
|
+
_db.close();
|
|
39
|
+
_db = null;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/storm/basins.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Storm center — supporting basin analysis
|
|
2
2
|
import { classifyTsunamiText } from '../tsunami_classifier';
|
|
3
|
+
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
3
4
|
import type { TsunamiStormCenter } from './types';
|
|
4
5
|
|
|
5
6
|
export function buildSupportingBasins(input: {
|
package/src/storm/boundary.ts
CHANGED
package/src/storm/directive.ts
CHANGED
package/src/storm/helpers.ts
CHANGED
|
@@ -4,7 +4,14 @@ import { basename, join } from 'node:path';
|
|
|
4
4
|
import { listProjectWikiPages } from '../core/project_state';
|
|
5
5
|
import type { ProjectHandoffRecord, ProjectTaskThread } from '../core/project_state';
|
|
6
6
|
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
7
|
-
import type { TsunamiStormCenterCurrent } from './types';
|
|
7
|
+
import type { TsunamiStormCenterCurrent, TsunamiStormCenter } from './types';
|
|
8
|
+
|
|
9
|
+
type TsunamiFallbackDocSupport = {
|
|
10
|
+
anchors: TsunamiStormCenter['anchors'];
|
|
11
|
+
evidence: TsunamiStormCenter['evidence'];
|
|
12
|
+
mainlineTitle?: string;
|
|
13
|
+
mainlineSummary?: string;
|
|
14
|
+
};
|
|
8
15
|
|
|
9
16
|
const TSUNAMI_STORM_RETRY_DELAYS_MS = [8, 18, 36] as const;
|
|
10
17
|
|
package/src/storm/horizon.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TsunamiStormPressure, TsunamiStormReadiness, TsunamiStormBoundary, TsunamiStormCenterStormMode, TsunamiStormHorizon } from './types';
|
|
2
|
+
import type { TsunamiStormCenter } from './types';
|
|
2
3
|
|
|
3
4
|
export function buildStormHorizon(input: {
|
|
4
5
|
stormPressure?: TsunamiStormPressure;
|
package/src/storm/pressure.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { TsunamiStormCenterCurrentMix, TsunamiStormCenterStormMode, TsunamiStormPressure } from './types';
|
|
2
|
+
import type { TsunamiStormCenter } from './types';
|
|
3
|
+
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
2
4
|
|
|
3
5
|
export function buildStormPressure(input: {
|
|
4
6
|
currentMix: TsunamiStormCenterCurrentMix[];
|
package/src/storm/readiness.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
2
|
+
import type { TsunamiStormReadiness, TsunamiStormCenter } from './types';
|
|
2
3
|
|
|
3
4
|
export function buildStormReadiness(input: {
|
|
4
5
|
hasMainline: boolean;
|
package/src/storm/signals.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Storm center — signal analysis
|
|
2
2
|
import { clampEnergy, safeTrim, buildProjectNode, buildTaskThreadNode, buildHandoffNode, buildAnchorNode, buildRecoveryNode } from './helpers';
|
|
3
|
+
import type { ProjectTaskThread, ProjectHandoffRecord } from '../core/project_state';
|
|
4
|
+
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
3
5
|
import type { StormCurrentKind, TsunamiStormCenterCurrent, TsunamiStormCenterCurrentMix, TsunamiStormCenter } from './types';
|
|
4
6
|
|
|
5
7
|
export function buildCurrents(input: {
|
package/src/storm/types.ts
CHANGED
|
@@ -3,6 +3,12 @@ import type { ProjectHandoffRecord, ProjectTaskThread } from '../core/project_st
|
|
|
3
3
|
import type { DurableRecoveryRecord } from '../runtime/checkpoints/durable_recovery';
|
|
4
4
|
import type { TsunamiRuntimeGraphSyncSummary } from '../tsunami_runtime_graph_sync';
|
|
5
5
|
|
|
6
|
+
// Forward-declare return types used in TsunamiStormCenter — these are stubs
|
|
7
|
+
// since the real implementations live in stub modules; this keeps types.ts clean.
|
|
8
|
+
type WikiEvidenceSnippet = { snippetId: string; pageId: string; title: string; sourcePath?: string; sourceRef?: string; quote: string; tags: string[] };
|
|
9
|
+
type MemoryIssue = { code: string; severity?: string; detail?: string };
|
|
10
|
+
type MemoryRepairSuggestion = { title: string; priority?: string; detail?: string };
|
|
11
|
+
|
|
6
12
|
export type BuildStormCenterOpts = {
|
|
7
13
|
projectDir?: string;
|
|
8
14
|
query?: string;
|
|
@@ -13,7 +19,7 @@ export type BuildStormCenterOpts = {
|
|
|
13
19
|
relationLimit?: number;
|
|
14
20
|
};
|
|
15
21
|
|
|
16
|
-
type StormCurrentKind =
|
|
22
|
+
export type StormCurrentKind =
|
|
17
23
|
| 'primary_thread'
|
|
18
24
|
| 'handoff'
|
|
19
25
|
| 'anchor'
|
|
@@ -169,7 +175,7 @@ export type TsunamiStormCenter = {
|
|
|
169
175
|
confidence: number;
|
|
170
176
|
tags: string[];
|
|
171
177
|
}>;
|
|
172
|
-
evidence:
|
|
178
|
+
evidence: WikiEvidenceSnippet[];
|
|
173
179
|
graph: {
|
|
174
180
|
project: Record<string, unknown>[];
|
|
175
181
|
thread: Record<string, unknown>[];
|
|
@@ -177,8 +183,8 @@ export type TsunamiStormCenter = {
|
|
|
177
183
|
anchor: Record<string, unknown>[];
|
|
178
184
|
recovery: Record<string, unknown>[];
|
|
179
185
|
};
|
|
180
|
-
issues:
|
|
181
|
-
repairSuggestions:
|
|
186
|
+
issues: MemoryIssue[];
|
|
187
|
+
repairSuggestions: MemoryRepairSuggestion[];
|
|
182
188
|
currents: TsunamiStormCenterCurrent[];
|
|
183
189
|
currentMix: TsunamiStormCenterCurrentMix[];
|
|
184
190
|
stormMode?: TsunamiStormCenterStormMode;
|
|
@@ -6,21 +6,7 @@
|
|
|
6
6
|
* BFS traversal, and cross-wing tunnel discovery.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
11
|
-
import { runMigrations, getMigrations } from './migration';
|
|
12
|
-
|
|
13
|
-
// ── Database initialization ──────────────────────────────────
|
|
14
|
-
|
|
15
|
-
let _db: Database | null = null;
|
|
16
|
-
|
|
17
|
-
function getDb(): Database {
|
|
18
|
-
if (_db) return _db;
|
|
19
|
-
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
20
|
-
_db.run('PRAGMA journal_mode = WAL');
|
|
21
|
-
runMigrations(_db, getMigrations()); // idempotent — applies only pending
|
|
22
|
-
return _db;
|
|
23
|
-
}
|
|
9
|
+
import { getDb } from './db';
|
|
24
10
|
|
|
25
11
|
// ── ID Generation ────────────────────────────────────────────
|
|
26
12
|
|