@theokit/sdk-memory 0.4.0 → 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.
- package/CHANGELOG.md +22 -0
- package/dist/index.cjs +106 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -223
- package/dist/index.js.map +1 -1
- package/dist/internal/active-memory/active-memory.d.ts.map +1 -1
- package/dist/internal/dreaming/dreaming-diary.d.ts +6 -61
- package/dist/internal/dreaming/dreaming-diary.d.ts.map +1 -1
- package/dist/internal/index/index-db.d.ts +0 -7
- package/dist/internal/index/index-db.d.ts.map +1 -1
- package/dist/internal/index/index-manager.d.ts +9 -1
- package/dist/internal/index/index-manager.d.ts.map +1 -1
- package/dist/internal/index/lance-index.d.ts +3 -6
- package/dist/internal/index/lance-index.d.ts.map +1 -1
- package/dist/internal/index/migrate-sqlite-to-lance.d.ts +5 -0
- package/dist/internal/index/migrate-sqlite-to-lance.d.ts.map +1 -1
- package/dist/internal/store/markdown-store.d.ts +1 -1
- package/dist/internal/store/markdown-store.d.ts.map +1 -1
- package/dist/internal/store/session-loader.d.ts +3 -27
- package/dist/internal/store/session-loader.d.ts.map +1 -1
- package/dist/internal/store/session-summary-writer.d.ts +6 -53
- package/dist/internal/store/session-summary-writer.d.ts.map +1 -1
- package/dist/internal/store/transcript-store.d.ts +3 -45
- package/dist/internal/store/transcript-store.d.ts.map +1 -1
- package/dist/internal/store/wiki-loader.d.ts +3 -32
- package/dist/internal/store/wiki-loader.d.ts.map +1 -1
- package/dist/internal/tools.d.ts +3 -1
- package/dist/internal/tools.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog — @theokit/sdk-memory
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6410e27: The satellite follows the SDK's single memory-root resolver (#463).
|
|
8
|
+
|
|
9
|
+
`Memory.runDreamingSweep` routes through this package whenever it is installed, so a satellite that
|
|
10
|
+
kept deriving `<cwd>/.theokit/memory` on its own would have reverted `memory.directory` to the
|
|
11
|
+
default for exactly the consumers who installed it — the failure this package's own store shim was
|
|
12
|
+
written to end, one release later.
|
|
13
|
+
|
|
14
|
+
Its path helpers now take a resolved `MemoryRoot` like the SDK's: `sessionsDir`, `wikiDir`,
|
|
15
|
+
`diaryPath`, `defaultIndexPath`, `lanceStoragePath`, `collectMarkdownFiles`, `discoverSessionFiles`,
|
|
16
|
+
`discoverWikiFiles`, `persistActiveMemoryTranscript` and `createMemoryGetTool` (`cwd` → `root`).
|
|
17
|
+
`SessionSummaryInput.cwd` becomes `memoryRoot`. `memoryDir` and `memoryWriteDir` are gone from the
|
|
18
|
+
re-export; `resolveMemoryRoot`, `projectMemoryDir`, `memoryReadRoots`, `asMemoryRoot` and
|
|
19
|
+
`MemoryRoot` replace them. `migrateSqliteToLance` and the Lance index accept the root.
|
|
20
|
+
|
|
21
|
+
Two more copies of the layout literal were found the same way the SDK's were — by the type error,
|
|
22
|
+
not by a search: `index-db.ts` and `lance-index.ts` each spelled `.theokit/memory` out again
|
|
23
|
+
instead of calling the shared helper.
|
|
24
|
+
|
|
3
25
|
## 0.4.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -244,24 +244,14 @@ function createInMemoryMarkdownProvider() {
|
|
|
244
244
|
async function listNotes(cwd) {
|
|
245
245
|
let entries = [];
|
|
246
246
|
try {
|
|
247
|
-
entries = await promises.readdir(memoryStore.notesDir(cwd));
|
|
247
|
+
entries = await promises.readdir(memoryStore.notesDir(memoryStore.resolveMemoryRoot(cwd)));
|
|
248
248
|
} catch {
|
|
249
249
|
return [];
|
|
250
250
|
}
|
|
251
|
-
return entries.filter((name) => name.endsWith(".md")).map((name) => ({
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
async function persistActiveMemoryTranscript(cwd, transcript) {
|
|
256
|
-
try {
|
|
257
|
-
const dir = path.join(memoryStore.memoryDir(cwd), "transcripts", "active-memory");
|
|
258
|
-
const file = path.join(dir, `${transcript.runId}.json`);
|
|
259
|
-
await persistence.atomicWriteJson(file, transcript);
|
|
260
|
-
} catch (cause) {
|
|
261
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
262
|
-
process.stderr.write(`[theokit-sdk] active-memory transcript persist failed: ${message}
|
|
263
|
-
`);
|
|
264
|
-
}
|
|
251
|
+
return entries.filter((name) => name.endsWith(".md")).map((name) => ({
|
|
252
|
+
slug: name.replace(/\.md$/, ""),
|
|
253
|
+
path: path.join(memoryStore.notesDir(memoryStore.resolveMemoryRoot(cwd)), name)
|
|
254
|
+
}));
|
|
265
255
|
}
|
|
266
256
|
|
|
267
257
|
// src/internal/active-memory/active-memory.ts
|
|
@@ -404,7 +394,7 @@ async function finalize(args, queryMode, result) {
|
|
|
404
394
|
};
|
|
405
395
|
args.cache?.set(args.userText, queryMode, result, tenantCtx);
|
|
406
396
|
if (args.persistTranscripts === true && args.cwd !== void 0) {
|
|
407
|
-
await persistActiveMemoryTranscript(args.cwd, {
|
|
397
|
+
await memoryStore.persistActiveMemoryTranscript(memoryStore.resolveMemoryRoot(args.cwd), {
|
|
408
398
|
runId: args.runId ?? `run-${Date.now()}`,
|
|
409
399
|
startedAtMs: Date.now() - result.durationMs,
|
|
410
400
|
userText: args.userText,
|
|
@@ -1086,47 +1076,6 @@ ${bullet}
|
|
|
1086
1076
|
return `${raw.slice(0, insertAt)}
|
|
1087
1077
|
${bullet}${raw.slice(insertAt)}`;
|
|
1088
1078
|
}
|
|
1089
|
-
function diaryPath(cwd) {
|
|
1090
|
-
return path.join(memoryStore.memoryDir(cwd), "dream-diary.md");
|
|
1091
|
-
}
|
|
1092
|
-
function renderDiaryEntry(entry) {
|
|
1093
|
-
const stamp = new Date(entry.timestampMs).toISOString();
|
|
1094
|
-
const hash = entryHash(entry).slice(0, 8);
|
|
1095
|
-
return [
|
|
1096
|
-
`## ${stamp}`,
|
|
1097
|
-
"",
|
|
1098
|
-
`- entry-hash: ${hash}`,
|
|
1099
|
-
`- facts before: ${entry.factsBefore}`,
|
|
1100
|
-
`- facts after: ${entry.factsAfter}`,
|
|
1101
|
-
`- duplicates removed: ${entry.duplicatesRemoved}`,
|
|
1102
|
-
`- clusters created: ${entry.clustersCreated}`,
|
|
1103
|
-
`- notes written: ${entry.notesWritten}`,
|
|
1104
|
-
""
|
|
1105
|
-
].join("\n");
|
|
1106
|
-
}
|
|
1107
|
-
async function appendDiaryEntry(cwd, entry) {
|
|
1108
|
-
const path = diaryPath(cwd);
|
|
1109
|
-
let raw = "";
|
|
1110
|
-
try {
|
|
1111
|
-
raw = await promises.readFile(path, "utf8");
|
|
1112
|
-
} catch {
|
|
1113
|
-
raw = "# Dream Diary\n\n";
|
|
1114
|
-
}
|
|
1115
|
-
const next = `${raw.endsWith("\n") ? raw : `${raw}
|
|
1116
|
-
`}${renderDiaryEntry(entry)}`;
|
|
1117
|
-
await persistence.replaceFileAtomic(path, next);
|
|
1118
|
-
}
|
|
1119
|
-
function entryHash(entry) {
|
|
1120
|
-
return crypto.createHash("sha256").update(
|
|
1121
|
-
[
|
|
1122
|
-
entry.factsBefore,
|
|
1123
|
-
entry.factsAfter,
|
|
1124
|
-
entry.duplicatesRemoved,
|
|
1125
|
-
entry.clustersCreated,
|
|
1126
|
-
entry.notesWritten
|
|
1127
|
-
].join("|")
|
|
1128
|
-
).digest("hex");
|
|
1129
|
-
}
|
|
1130
1079
|
|
|
1131
1080
|
// src/internal/dreaming/dreaming-phases.ts
|
|
1132
1081
|
var DEFAULT_DEDUP_THRESHOLD = 0.95;
|
|
@@ -1248,7 +1197,7 @@ async function runInner(options) {
|
|
|
1248
1197
|
notesWritten,
|
|
1249
1198
|
diaryEntryHash: void 0
|
|
1250
1199
|
};
|
|
1251
|
-
await appendDiaryEntry(options.cwd, {
|
|
1200
|
+
await memoryStore.appendDiaryEntry(memoryStore.resolveMemoryRoot(options.cwd), {
|
|
1252
1201
|
timestampMs,
|
|
1253
1202
|
factsBefore: result.factsBefore,
|
|
1254
1203
|
factsAfter: result.factsAfter,
|
|
@@ -1266,7 +1215,7 @@ async function runInner(options) {
|
|
|
1266
1215
|
}
|
|
1267
1216
|
async function writeConsolidatedNotes(cwd, clusters, timestampMs) {
|
|
1268
1217
|
if (clusters.length === 0) return 0;
|
|
1269
|
-
const notesDir3 = path.join(memoryStore.
|
|
1218
|
+
const notesDir3 = path.join(memoryStore.resolveMemoryRoot(cwd), "notes");
|
|
1270
1219
|
await promises.mkdir(notesDir3, { recursive: true });
|
|
1271
1220
|
const isoSlug = new Date(timestampMs).toISOString().replace(/[^\dT]/g, "-");
|
|
1272
1221
|
const file = path.join(notesDir3, `dreamed-${isoSlug}.md`);
|
|
@@ -1339,9 +1288,6 @@ async function openMemoryDb(opts) {
|
|
|
1339
1288
|
}
|
|
1340
1289
|
});
|
|
1341
1290
|
}
|
|
1342
|
-
function defaultIndexPath(cwd) {
|
|
1343
|
-
return path.join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
1344
|
-
}
|
|
1345
1291
|
var HEADING_RE = /^(#{1,6})\s+(.+?)\s*$/;
|
|
1346
1292
|
function chunkMarkdown(text, options = {}) {
|
|
1347
1293
|
const maxChars = options.maxChars ?? 800;
|
|
@@ -1417,91 +1363,6 @@ function findWordBoundarySplit(text, maxChars) {
|
|
|
1417
1363
|
}
|
|
1418
1364
|
return maxChars;
|
|
1419
1365
|
}
|
|
1420
|
-
var MAX_TURN_CHARS = 2e3;
|
|
1421
|
-
function sessionsDir(cwd) {
|
|
1422
|
-
return path.join(memoryStore.memoryDir(cwd), "sessions");
|
|
1423
|
-
}
|
|
1424
|
-
function sessionSummaryPath(cwd, runId) {
|
|
1425
|
-
return path.join(sessionsDir(cwd), `${sanitizeRunId2(runId)}.md`);
|
|
1426
|
-
}
|
|
1427
|
-
function sanitizeRunId2(runId) {
|
|
1428
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
1429
|
-
}
|
|
1430
|
-
function truncate2(text) {
|
|
1431
|
-
if (text.length <= MAX_TURN_CHARS) return text;
|
|
1432
|
-
return `${text.slice(0, MAX_TURN_CHARS)}\u2026`;
|
|
1433
|
-
}
|
|
1434
|
-
async function writeSessionSummary(input) {
|
|
1435
|
-
if (input.status !== "finished") return;
|
|
1436
|
-
const path = sessionSummaryPath(input.cwd, input.runId);
|
|
1437
|
-
await promises.mkdir(sessionsDir(input.cwd), { recursive: true });
|
|
1438
|
-
const safeUser = redactSecrets(truncate2(input.userText));
|
|
1439
|
-
const safeAssistant = redactSecrets(truncate2(input.assistantText));
|
|
1440
|
-
const iso = new Date(input.at).toISOString();
|
|
1441
|
-
const body = [
|
|
1442
|
-
"---",
|
|
1443
|
-
`runId: ${input.runId}`,
|
|
1444
|
-
`agentId: ${input.agentId}`,
|
|
1445
|
-
`at: ${iso}`,
|
|
1446
|
-
`status: ${input.status}`,
|
|
1447
|
-
"---",
|
|
1448
|
-
"",
|
|
1449
|
-
"## User",
|
|
1450
|
-
"",
|
|
1451
|
-
safeUser,
|
|
1452
|
-
"",
|
|
1453
|
-
"## Assistant",
|
|
1454
|
-
"",
|
|
1455
|
-
safeAssistant,
|
|
1456
|
-
""
|
|
1457
|
-
].join("\n");
|
|
1458
|
-
await persistence.replaceFileAtomic(path, body);
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
// src/internal/store/session-loader.ts
|
|
1462
|
-
async function discoverSessionFiles(cwd) {
|
|
1463
|
-
let entries;
|
|
1464
|
-
try {
|
|
1465
|
-
entries = await promises.readdir(sessionsDir(cwd));
|
|
1466
|
-
} catch {
|
|
1467
|
-
return [];
|
|
1468
|
-
}
|
|
1469
|
-
const root = memoryStore.memoryDir(cwd);
|
|
1470
|
-
return entries.filter((entry) => entry.endsWith(".md")).map((entry) => {
|
|
1471
|
-
const absolutePath = path.join(sessionsDir(cwd), entry);
|
|
1472
|
-
return {
|
|
1473
|
-
absolutePath,
|
|
1474
|
-
relPath: relativeToRoot(root, absolutePath)
|
|
1475
|
-
};
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
function relativeToRoot(root, absolutePath) {
|
|
1479
|
-
if (absolutePath.startsWith(`${root}/`)) return absolutePath.slice(root.length + 1);
|
|
1480
|
-
return absolutePath;
|
|
1481
|
-
}
|
|
1482
|
-
function wikiDir(cwd) {
|
|
1483
|
-
return path.join(memoryStore.memoryDir(cwd), "wiki");
|
|
1484
|
-
}
|
|
1485
|
-
async function discoverWikiFiles(cwd) {
|
|
1486
|
-
let entries;
|
|
1487
|
-
try {
|
|
1488
|
-
entries = await promises.readdir(wikiDir(cwd));
|
|
1489
|
-
} catch {
|
|
1490
|
-
return [];
|
|
1491
|
-
}
|
|
1492
|
-
const root = memoryStore.memoryDir(cwd);
|
|
1493
|
-
return entries.filter((entry) => entry.endsWith(".md")).map((entry) => ({
|
|
1494
|
-
absolutePath: path.join(wikiDir(cwd), entry),
|
|
1495
|
-
relPath: path.join("wiki", entry)
|
|
1496
|
-
})).map((file) => ({
|
|
1497
|
-
absolutePath: file.absolutePath,
|
|
1498
|
-
relPath: relativeToRoot2(root, file.absolutePath)
|
|
1499
|
-
}));
|
|
1500
|
-
}
|
|
1501
|
-
function relativeToRoot2(root, absolutePath) {
|
|
1502
|
-
if (absolutePath.startsWith(`${root}/`)) return absolutePath.slice(root.length + 1);
|
|
1503
|
-
return absolutePath;
|
|
1504
|
-
}
|
|
1505
1366
|
function requireLance() {
|
|
1506
1367
|
try {
|
|
1507
1368
|
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
@@ -1524,7 +1385,7 @@ var LanceIndex = class _LanceIndex {
|
|
|
1524
1385
|
embeddingDim;
|
|
1525
1386
|
static async open(opts) {
|
|
1526
1387
|
const lance = requireLance();
|
|
1527
|
-
const storagePath = opts.storagePath ??
|
|
1388
|
+
const storagePath = opts.storagePath ?? memoryStore.lanceStoragePath(opts.memoryRoot ?? memoryStore.resolveMemoryRoot(opts.cwd));
|
|
1528
1389
|
fs.mkdirSync(storagePath, { recursive: true });
|
|
1529
1390
|
const conn = await lance.connect(storagePath);
|
|
1530
1391
|
const dim = opts.embedding.dimension;
|
|
@@ -1626,9 +1487,6 @@ function isLanceAvailable() {
|
|
|
1626
1487
|
return false;
|
|
1627
1488
|
}
|
|
1628
1489
|
}
|
|
1629
|
-
function lanceStoragePath(cwd) {
|
|
1630
|
-
return path.join(cwd, ".theokit", "memory", "lance");
|
|
1631
|
-
}
|
|
1632
1490
|
|
|
1633
1491
|
// src/internal/index/memory-index.ts
|
|
1634
1492
|
function parseSearchOptions(options = {}) {
|
|
@@ -1828,12 +1686,12 @@ async function embedMissingChunks(args) {
|
|
|
1828
1686
|
|
|
1829
1687
|
// src/internal/index/index-manager.ts
|
|
1830
1688
|
var IndexManager = class _IndexManager {
|
|
1831
|
-
constructor(
|
|
1832
|
-
this.
|
|
1689
|
+
constructor(memoryRoot, db, embedding) {
|
|
1690
|
+
this.memoryRoot = memoryRoot;
|
|
1833
1691
|
this.db = db;
|
|
1834
1692
|
this.embedding = embedding;
|
|
1835
1693
|
}
|
|
1836
|
-
|
|
1694
|
+
memoryRoot;
|
|
1837
1695
|
db;
|
|
1838
1696
|
embedding;
|
|
1839
1697
|
lastSyncMs;
|
|
@@ -1846,9 +1704,10 @@ var IndexManager = class _IndexManager {
|
|
|
1846
1704
|
}
|
|
1847
1705
|
/** Internal SQLite-path open. Renamed from previous public `open`. */
|
|
1848
1706
|
static async openSqliteInternal(opts) {
|
|
1849
|
-
const
|
|
1707
|
+
const memoryRoot = opts.memoryRoot ?? memoryStore.resolveMemoryRoot(opts.cwd);
|
|
1708
|
+
const filePath = opts.filePath ?? memoryStore.defaultIndexPath(memoryStore.projectMemoryDir(opts.cwd));
|
|
1850
1709
|
const db = await openMemoryDb({ filePath });
|
|
1851
|
-
const manager = new _IndexManager(
|
|
1710
|
+
const manager = new _IndexManager(memoryRoot, db, opts.embedding);
|
|
1852
1711
|
if (opts.embedding !== void 0) await manager.initVectorBackend(opts.embedding);
|
|
1853
1712
|
return manager;
|
|
1854
1713
|
}
|
|
@@ -1869,7 +1728,7 @@ var IndexManager = class _IndexManager {
|
|
|
1869
1728
|
}
|
|
1870
1729
|
/** Walk the memory corpus + (re)index changed files. */
|
|
1871
1730
|
async sync() {
|
|
1872
|
-
const files = await collectMarkdownFiles(this.
|
|
1731
|
+
const files = await memoryStore.collectMarkdownFiles(this.memoryRoot);
|
|
1873
1732
|
let filesUpdated = 0;
|
|
1874
1733
|
let chunksWritten = 0;
|
|
1875
1734
|
const existingByPath = this.loadFilesIndex();
|
|
@@ -2066,45 +1925,6 @@ function blendScores(hit, vectorScore, weights) {
|
|
|
2066
1925
|
...vectorScore > 0 ? { vectorScore } : {}
|
|
2067
1926
|
};
|
|
2068
1927
|
}
|
|
2069
|
-
async function collectMarkdownFiles(cwd) {
|
|
2070
|
-
const root = memoryStore.memoryDir(cwd);
|
|
2071
|
-
const results = [];
|
|
2072
|
-
try {
|
|
2073
|
-
await promises.stat(memoryStore.memoryMdPath(cwd));
|
|
2074
|
-
results.push({
|
|
2075
|
-
absolutePath: memoryStore.memoryMdPath(cwd),
|
|
2076
|
-
relPath: path.relative(root, memoryStore.memoryMdPath(cwd)),
|
|
2077
|
-
source: "memory"
|
|
2078
|
-
});
|
|
2079
|
-
} catch {
|
|
2080
|
-
}
|
|
2081
|
-
try {
|
|
2082
|
-
const entries = await promises.readdir(memoryStore.notesDir(cwd));
|
|
2083
|
-
for (const entry of entries) {
|
|
2084
|
-
if (!entry.endsWith(".md")) continue;
|
|
2085
|
-
const abs = path.join(memoryStore.notesDir(cwd), entry);
|
|
2086
|
-
results.push({ absolutePath: abs, relPath: path.relative(root, abs), source: "memory" });
|
|
2087
|
-
}
|
|
2088
|
-
} catch {
|
|
2089
|
-
}
|
|
2090
|
-
const wikiFiles = await discoverWikiFiles(cwd);
|
|
2091
|
-
for (const wiki of wikiFiles) {
|
|
2092
|
-
results.push({
|
|
2093
|
-
absolutePath: wiki.absolutePath,
|
|
2094
|
-
relPath: wiki.relPath,
|
|
2095
|
-
source: "wiki"
|
|
2096
|
-
});
|
|
2097
|
-
}
|
|
2098
|
-
const sessionFiles = await discoverSessionFiles(cwd);
|
|
2099
|
-
for (const session of sessionFiles) {
|
|
2100
|
-
results.push({
|
|
2101
|
-
absolutePath: session.absolutePath,
|
|
2102
|
-
relPath: session.relPath,
|
|
2103
|
-
source: "sessions"
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2106
|
-
return results;
|
|
2107
|
-
}
|
|
2108
1928
|
function sha256(text) {
|
|
2109
1929
|
return crypto.createHash("sha256").update(text).digest("hex");
|
|
2110
1930
|
}
|
|
@@ -2112,30 +1932,14 @@ function truncateSnippet(text) {
|
|
|
2112
1932
|
const max = 500;
|
|
2113
1933
|
return text.length <= max ? text : `${text.slice(0, max)}\u2026`;
|
|
2114
1934
|
}
|
|
2115
|
-
async function readAllSqliteFacts(cwd) {
|
|
2116
|
-
const dbPath = defaultIndexPath(cwd);
|
|
2117
|
-
if (!fs.existsSync(dbPath)) return [];
|
|
2118
|
-
const db = await openMemoryDb({ filePath: dbPath });
|
|
2119
|
-
try {
|
|
2120
|
-
const stmt = db.prepare("SELECT id, path, source, start_line, end_line, text FROM chunks");
|
|
2121
|
-
const rows = stmt.all();
|
|
2122
|
-
return rows.map((r) => ({
|
|
2123
|
-
...r,
|
|
2124
|
-
namespace: "default",
|
|
2125
|
-
scope: "agent",
|
|
2126
|
-
user_id: "default"
|
|
2127
|
-
}));
|
|
2128
|
-
} finally {
|
|
2129
|
-
db.close();
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
1935
|
function nfcEqual(a, b) {
|
|
2133
1936
|
return a.normalize("NFC") === b.normalize("NFC");
|
|
2134
1937
|
}
|
|
2135
1938
|
async function migrateSqliteToLance(opts) {
|
|
2136
1939
|
const cwd = opts.cwd;
|
|
2137
|
-
const
|
|
2138
|
-
const
|
|
1940
|
+
const memoryRoot = memoryStore.resolveMemoryRoot(cwd, { directory: opts.directory });
|
|
1941
|
+
const finalPath = memoryStore.lanceStoragePath(memoryRoot);
|
|
1942
|
+
const newPath = path.join(memoryRoot, "lance-new");
|
|
2139
1943
|
const rawLog = opts.logger ?? ((m) => console.log(m));
|
|
2140
1944
|
const log = (m) => rawLog(redactSecrets(m));
|
|
2141
1945
|
if (fs.existsSync(finalPath)) {
|
|
@@ -2149,7 +1953,7 @@ async function migrateSqliteToLance(opts) {
|
|
|
2149
1953
|
fs.rmSync(newPath, { recursive: true, force: true });
|
|
2150
1954
|
}
|
|
2151
1955
|
log(`Reading SQLite facts from ${cwd}/.theokit/memory/index.sqlite ...`);
|
|
2152
|
-
const sqliteFacts = await readAllSqliteFacts(
|
|
1956
|
+
const sqliteFacts = await memoryStore.readAllSqliteFacts(memoryRoot);
|
|
2153
1957
|
log(`SQLite has ${sqliteFacts.length} facts.`);
|
|
2154
1958
|
if (sqliteFacts.length === 0) {
|
|
2155
1959
|
return {
|
|
@@ -2293,7 +2097,7 @@ async function migrateLegacyJson(cwd, config) {
|
|
|
2293
2097
|
if (!await fileExists(jsonPath)) {
|
|
2294
2098
|
return { migrated: false, factCount: 0, reason: "no-legacy-json" };
|
|
2295
2099
|
}
|
|
2296
|
-
if (await fileExists(memoryStore.memoryMdPath(cwd))) {
|
|
2100
|
+
if (await fileExists(memoryStore.memoryMdPath(memoryStore.resolveMemoryRoot(cwd)))) {
|
|
2297
2101
|
process.stderr.write(
|
|
2298
2102
|
`[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
|
|
2299
2103
|
`
|
|
@@ -2379,7 +2183,7 @@ function createMemorySearchTool(opts) {
|
|
|
2379
2183
|
};
|
|
2380
2184
|
}
|
|
2381
2185
|
function createMemoryGetTool(opts) {
|
|
2382
|
-
const memoryRoot = path.resolve(
|
|
2186
|
+
const memoryRoot = path.resolve(opts.root);
|
|
2383
2187
|
return {
|
|
2384
2188
|
name: "memory_get",
|
|
2385
2189
|
description: GET_DESCRIPTION,
|
|
@@ -2448,6 +2252,18 @@ function isPathInside(root, candidate) {
|
|
|
2448
2252
|
return candidate === root || candidate.startsWith(normalizedRoot);
|
|
2449
2253
|
}
|
|
2450
2254
|
|
|
2255
|
+
Object.defineProperty(exports, "MEMORY_INDEX_MAX_BYTES", {
|
|
2256
|
+
enumerable: true,
|
|
2257
|
+
get: function () { return memoryStore.MEMORY_INDEX_MAX_BYTES; }
|
|
2258
|
+
});
|
|
2259
|
+
Object.defineProperty(exports, "MEMORY_INDEX_MAX_LINES", {
|
|
2260
|
+
enumerable: true,
|
|
2261
|
+
get: function () { return memoryStore.MEMORY_INDEX_MAX_LINES; }
|
|
2262
|
+
});
|
|
2263
|
+
Object.defineProperty(exports, "appendDiaryEntry", {
|
|
2264
|
+
enumerable: true,
|
|
2265
|
+
get: function () { return memoryStore.appendDiaryEntry; }
|
|
2266
|
+
});
|
|
2451
2267
|
Object.defineProperty(exports, "appendFact", {
|
|
2452
2268
|
enumerable: true,
|
|
2453
2269
|
get: function () { return memoryStore.appendFact; }
|
|
@@ -2456,26 +2272,70 @@ Object.defineProperty(exports, "appendFactToMarkdown", {
|
|
|
2456
2272
|
enumerable: true,
|
|
2457
2273
|
get: function () { return memoryStore.appendFactToMarkdown; }
|
|
2458
2274
|
});
|
|
2275
|
+
Object.defineProperty(exports, "asMemoryRoot", {
|
|
2276
|
+
enumerable: true,
|
|
2277
|
+
get: function () { return memoryStore.asMemoryRoot; }
|
|
2278
|
+
});
|
|
2459
2279
|
Object.defineProperty(exports, "claudeProjectMemoryDir", {
|
|
2460
2280
|
enumerable: true,
|
|
2461
2281
|
get: function () { return memoryStore.claudeProjectMemoryDir; }
|
|
2462
2282
|
});
|
|
2463
|
-
Object.defineProperty(exports, "
|
|
2283
|
+
Object.defineProperty(exports, "collectMarkdownFiles", {
|
|
2284
|
+
enumerable: true,
|
|
2285
|
+
get: function () { return memoryStore.collectMarkdownFiles; }
|
|
2286
|
+
});
|
|
2287
|
+
Object.defineProperty(exports, "defaultIndexPath", {
|
|
2288
|
+
enumerable: true,
|
|
2289
|
+
get: function () { return memoryStore.defaultIndexPath; }
|
|
2290
|
+
});
|
|
2291
|
+
Object.defineProperty(exports, "diaryPath", {
|
|
2464
2292
|
enumerable: true,
|
|
2465
|
-
get: function () { return memoryStore.
|
|
2293
|
+
get: function () { return memoryStore.diaryPath; }
|
|
2294
|
+
});
|
|
2295
|
+
Object.defineProperty(exports, "discoverSessionFiles", {
|
|
2296
|
+
enumerable: true,
|
|
2297
|
+
get: function () { return memoryStore.discoverSessionFiles; }
|
|
2298
|
+
});
|
|
2299
|
+
Object.defineProperty(exports, "discoverWikiFiles", {
|
|
2300
|
+
enumerable: true,
|
|
2301
|
+
get: function () { return memoryStore.discoverWikiFiles; }
|
|
2302
|
+
});
|
|
2303
|
+
Object.defineProperty(exports, "entryHash", {
|
|
2304
|
+
enumerable: true,
|
|
2305
|
+
get: function () { return memoryStore.entryHash; }
|
|
2306
|
+
});
|
|
2307
|
+
Object.defineProperty(exports, "indexBudgetWarning", {
|
|
2308
|
+
enumerable: true,
|
|
2309
|
+
get: function () { return memoryStore.indexBudgetWarning; }
|
|
2310
|
+
});
|
|
2311
|
+
Object.defineProperty(exports, "lanceStoragePath", {
|
|
2312
|
+
enumerable: true,
|
|
2313
|
+
get: function () { return memoryStore.lanceStoragePath; }
|
|
2466
2314
|
});
|
|
2467
2315
|
Object.defineProperty(exports, "memoryMdPath", {
|
|
2468
2316
|
enumerable: true,
|
|
2469
2317
|
get: function () { return memoryStore.memoryMdPath; }
|
|
2470
2318
|
});
|
|
2471
|
-
Object.defineProperty(exports, "
|
|
2319
|
+
Object.defineProperty(exports, "memoryReadRoots", {
|
|
2472
2320
|
enumerable: true,
|
|
2473
|
-
get: function () { return memoryStore.
|
|
2321
|
+
get: function () { return memoryStore.memoryReadRoots; }
|
|
2474
2322
|
});
|
|
2475
2323
|
Object.defineProperty(exports, "notesDir", {
|
|
2476
2324
|
enumerable: true,
|
|
2477
2325
|
get: function () { return memoryStore.notesDir; }
|
|
2478
2326
|
});
|
|
2327
|
+
Object.defineProperty(exports, "persistActiveMemoryTranscript", {
|
|
2328
|
+
enumerable: true,
|
|
2329
|
+
get: function () { return memoryStore.persistActiveMemoryTranscript; }
|
|
2330
|
+
});
|
|
2331
|
+
Object.defineProperty(exports, "projectMemoryDir", {
|
|
2332
|
+
enumerable: true,
|
|
2333
|
+
get: function () { return memoryStore.projectMemoryDir; }
|
|
2334
|
+
});
|
|
2335
|
+
Object.defineProperty(exports, "readAllSqliteFacts", {
|
|
2336
|
+
enumerable: true,
|
|
2337
|
+
get: function () { return memoryStore.readAllSqliteFacts; }
|
|
2338
|
+
});
|
|
2479
2339
|
Object.defineProperty(exports, "readFacts", {
|
|
2480
2340
|
enumerable: true,
|
|
2481
2341
|
get: function () { return memoryStore.readFacts; }
|
|
@@ -2484,6 +2344,30 @@ Object.defineProperty(exports, "readFactsFromMarkdown", {
|
|
|
2484
2344
|
enumerable: true,
|
|
2485
2345
|
get: function () { return memoryStore.readFactsFromMarkdown; }
|
|
2486
2346
|
});
|
|
2347
|
+
Object.defineProperty(exports, "renderDiaryEntry", {
|
|
2348
|
+
enumerable: true,
|
|
2349
|
+
get: function () { return memoryStore.renderDiaryEntry; }
|
|
2350
|
+
});
|
|
2351
|
+
Object.defineProperty(exports, "resolveMemoryRoot", {
|
|
2352
|
+
enumerable: true,
|
|
2353
|
+
get: function () { return memoryStore.resolveMemoryRoot; }
|
|
2354
|
+
});
|
|
2355
|
+
Object.defineProperty(exports, "sessionSummaryPath", {
|
|
2356
|
+
enumerable: true,
|
|
2357
|
+
get: function () { return memoryStore.sessionSummaryPath; }
|
|
2358
|
+
});
|
|
2359
|
+
Object.defineProperty(exports, "sessionsDir", {
|
|
2360
|
+
enumerable: true,
|
|
2361
|
+
get: function () { return memoryStore.sessionsDir; }
|
|
2362
|
+
});
|
|
2363
|
+
Object.defineProperty(exports, "wikiDir", {
|
|
2364
|
+
enumerable: true,
|
|
2365
|
+
get: function () { return memoryStore.wikiDir; }
|
|
2366
|
+
});
|
|
2367
|
+
Object.defineProperty(exports, "writeSessionSummary", {
|
|
2368
|
+
enumerable: true,
|
|
2369
|
+
get: function () { return memoryStore.writeSessionSummary; }
|
|
2370
|
+
});
|
|
2487
2371
|
Object.defineProperty(exports, "createOpenAiCompatibleRuntime", {
|
|
2488
2372
|
enumerable: true,
|
|
2489
2373
|
get: function () { return memoryAdapters.createOpenAiCompatibleRuntime; }
|
|
@@ -2511,7 +2395,6 @@ exports.META_KEY_PROVIDER_ID = META_KEY_PROVIDER_ID;
|
|
|
2511
2395
|
exports.PRAGMA_STATEMENTS = PRAGMA_STATEMENTS;
|
|
2512
2396
|
exports.SCHEMA_STATEMENTS = SCHEMA_STATEMENTS;
|
|
2513
2397
|
exports.VALID_BACKENDS = VALID_BACKENDS;
|
|
2514
|
-
exports.appendDiaryEntry = appendDiaryEntry;
|
|
2515
2398
|
exports.assertValidBackend = assertValidBackend;
|
|
2516
2399
|
exports.azureOpenAiMemoryEmbeddingProviderAdapter = azureOpenAiMemoryEmbeddingProviderAdapter;
|
|
2517
2400
|
exports.buildErrorMetadata = buildErrorMetadata;
|
|
@@ -2524,19 +2407,13 @@ exports.createMemorySearchTool = createMemorySearchTool;
|
|
|
2524
2407
|
exports.createVectorIndex = createVectorIndex;
|
|
2525
2408
|
exports.deepPhase = deepPhase;
|
|
2526
2409
|
exports.deepinfraMemoryEmbeddingProviderAdapter = deepinfraMemoryEmbeddingProviderAdapter;
|
|
2527
|
-
exports.defaultIndexPath = defaultIndexPath;
|
|
2528
|
-
exports.diaryPath = diaryPath;
|
|
2529
|
-
exports.discoverSessionFiles = discoverSessionFiles;
|
|
2530
|
-
exports.discoverWikiFiles = discoverWikiFiles;
|
|
2531
2410
|
exports.dropVectorIndex = dropVectorIndex;
|
|
2532
2411
|
exports.embedMissingChunks = embedMissingChunks;
|
|
2533
|
-
exports.entryHash = entryHash;
|
|
2534
2412
|
exports.geminiMemoryEmbeddingProviderAdapter = geminiMemoryEmbeddingProviderAdapter;
|
|
2535
2413
|
exports.identityMatches = identityMatches;
|
|
2536
2414
|
exports.isLanceAvailable = isLanceAvailable;
|
|
2537
2415
|
exports.isSqliteVecLoaded = isSqliteVecLoaded;
|
|
2538
2416
|
exports.jinaMemoryEmbeddingProviderAdapter = jinaMemoryEmbeddingProviderAdapter;
|
|
2539
|
-
exports.lanceStoragePath = lanceStoragePath;
|
|
2540
2417
|
exports.legacyMemoryJsonPath = legacyMemoryJsonPath;
|
|
2541
2418
|
exports.lightPhase = lightPhase;
|
|
2542
2419
|
exports.listNotes = listNotes;
|
|
@@ -2553,23 +2430,17 @@ exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProv
|
|
|
2553
2430
|
exports.packVector = packVector;
|
|
2554
2431
|
exports.parseRetryAfter = parseRetryAfter;
|
|
2555
2432
|
exports.parseSearchOptions = parseSearchOptions;
|
|
2556
|
-
exports.persistActiveMemoryTranscript = persistActiveMemoryTranscript;
|
|
2557
2433
|
exports.readEmbeddingIdentity = readEmbeddingIdentity;
|
|
2558
2434
|
exports.readMemoryFileBounded = readMemoryFileBounded;
|
|
2559
2435
|
exports.redactSecrets = redactSecrets;
|
|
2560
2436
|
exports.remPhase = remPhase;
|
|
2561
|
-
exports.renderDiaryEntry = renderDiaryEntry;
|
|
2562
2437
|
exports.resetMigrationStateForTests = resetMigrationStateForTests;
|
|
2563
2438
|
exports.runActiveMemory = runActiveMemory;
|
|
2564
2439
|
exports.runDreamingSweep = runDreamingSweep;
|
|
2565
|
-
exports.sessionSummaryPath = sessionSummaryPath;
|
|
2566
|
-
exports.sessionsDir = sessionsDir;
|
|
2567
2440
|
exports.truncateRaw = truncateRaw;
|
|
2568
2441
|
exports.upsertEmbedding = upsertEmbedding;
|
|
2569
2442
|
exports.vectorSearch = vectorSearch;
|
|
2570
2443
|
exports.voyageMemoryEmbeddingProviderAdapter = voyageMemoryEmbeddingProviderAdapter;
|
|
2571
|
-
exports.wikiDir = wikiDir;
|
|
2572
2444
|
exports.writeEmbeddingIdentity = writeEmbeddingIdentity;
|
|
2573
|
-
exports.writeSessionSummary = writeSessionSummary;
|
|
2574
2445
|
//# sourceMappingURL=index.cjs.map
|
|
2575
2446
|
//# sourceMappingURL=index.cjs.map
|