@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/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { mkdir, readdir, readFile, stat, access, unlink } from 'fs/promises';
|
|
2
|
-
import { join, resolve
|
|
2
|
+
import { join, resolve } from 'path';
|
|
3
3
|
import { Security } from '@theokit/sdk';
|
|
4
|
-
import { replaceFileAtomic,
|
|
5
|
-
import { notesDir,
|
|
6
|
-
export { appendFact, appendFactToMarkdown, claudeProjectMemoryDir,
|
|
4
|
+
import { replaceFileAtomic, withCwdMutex, openSqliteResilient, sanitizeFts5Query } from '@theokit/sdk/persistence';
|
|
5
|
+
import { notesDir, resolveMemoryRoot, persistActiveMemoryTranscript, readFactsFromMarkdown, appendDiaryEntry, lanceStoragePath, defaultIndexPath, projectMemoryDir, collectMarkdownFiles, readAllSqliteFacts, memoryMdPath, appendFactToMarkdown } from '@theokit/sdk/internal/memory-store';
|
|
6
|
+
export { MEMORY_INDEX_MAX_BYTES, MEMORY_INDEX_MAX_LINES, appendDiaryEntry, appendFact, appendFactToMarkdown, asMemoryRoot, claudeProjectMemoryDir, collectMarkdownFiles, defaultIndexPath, diaryPath, discoverSessionFiles, discoverWikiFiles, entryHash, indexBudgetWarning, lanceStoragePath, memoryMdPath, memoryReadRoots, notesDir, persistActiveMemoryTranscript, projectMemoryDir, readAllSqliteFacts, readFacts, readFactsFromMarkdown, renderDiaryEntry, resolveMemoryRoot, sessionSummaryPath, sessionsDir, wikiDir, writeSessionSummary } from '@theokit/sdk/internal/memory-store';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
8
8
|
import { createOpenAiCompatibleRuntime } from '@theokit/sdk/internal/memory-adapters';
|
|
9
9
|
export { createOpenAiCompatibleRuntime } from '@theokit/sdk/internal/memory-adapters';
|
|
@@ -243,24 +243,14 @@ function createInMemoryMarkdownProvider() {
|
|
|
243
243
|
async function listNotes(cwd) {
|
|
244
244
|
let entries = [];
|
|
245
245
|
try {
|
|
246
|
-
entries = await readdir(notesDir(cwd));
|
|
246
|
+
entries = await readdir(notesDir(resolveMemoryRoot(cwd)));
|
|
247
247
|
} catch {
|
|
248
248
|
return [];
|
|
249
249
|
}
|
|
250
|
-
return entries.filter((name) => name.endsWith(".md")).map((name) => ({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
async function persistActiveMemoryTranscript(cwd, transcript) {
|
|
255
|
-
try {
|
|
256
|
-
const dir = join(memoryDir(cwd), "transcripts", "active-memory");
|
|
257
|
-
const file = join(dir, `${transcript.runId}.json`);
|
|
258
|
-
await atomicWriteJson(file, transcript);
|
|
259
|
-
} catch (cause) {
|
|
260
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
261
|
-
process.stderr.write(`[theokit-sdk] active-memory transcript persist failed: ${message}
|
|
262
|
-
`);
|
|
263
|
-
}
|
|
250
|
+
return entries.filter((name) => name.endsWith(".md")).map((name) => ({
|
|
251
|
+
slug: name.replace(/\.md$/, ""),
|
|
252
|
+
path: join(notesDir(resolveMemoryRoot(cwd)), name)
|
|
253
|
+
}));
|
|
264
254
|
}
|
|
265
255
|
|
|
266
256
|
// src/internal/active-memory/active-memory.ts
|
|
@@ -403,7 +393,7 @@ async function finalize(args, queryMode, result) {
|
|
|
403
393
|
};
|
|
404
394
|
args.cache?.set(args.userText, queryMode, result, tenantCtx);
|
|
405
395
|
if (args.persistTranscripts === true && args.cwd !== void 0) {
|
|
406
|
-
await persistActiveMemoryTranscript(args.cwd, {
|
|
396
|
+
await persistActiveMemoryTranscript(resolveMemoryRoot(args.cwd), {
|
|
407
397
|
runId: args.runId ?? `run-${Date.now()}`,
|
|
408
398
|
startedAtMs: Date.now() - result.durationMs,
|
|
409
399
|
userText: args.userText,
|
|
@@ -1085,47 +1075,6 @@ ${bullet}
|
|
|
1085
1075
|
return `${raw.slice(0, insertAt)}
|
|
1086
1076
|
${bullet}${raw.slice(insertAt)}`;
|
|
1087
1077
|
}
|
|
1088
|
-
function diaryPath(cwd) {
|
|
1089
|
-
return join(memoryDir(cwd), "dream-diary.md");
|
|
1090
|
-
}
|
|
1091
|
-
function renderDiaryEntry(entry) {
|
|
1092
|
-
const stamp = new Date(entry.timestampMs).toISOString();
|
|
1093
|
-
const hash = entryHash(entry).slice(0, 8);
|
|
1094
|
-
return [
|
|
1095
|
-
`## ${stamp}`,
|
|
1096
|
-
"",
|
|
1097
|
-
`- entry-hash: ${hash}`,
|
|
1098
|
-
`- facts before: ${entry.factsBefore}`,
|
|
1099
|
-
`- facts after: ${entry.factsAfter}`,
|
|
1100
|
-
`- duplicates removed: ${entry.duplicatesRemoved}`,
|
|
1101
|
-
`- clusters created: ${entry.clustersCreated}`,
|
|
1102
|
-
`- notes written: ${entry.notesWritten}`,
|
|
1103
|
-
""
|
|
1104
|
-
].join("\n");
|
|
1105
|
-
}
|
|
1106
|
-
async function appendDiaryEntry(cwd, entry) {
|
|
1107
|
-
const path = diaryPath(cwd);
|
|
1108
|
-
let raw = "";
|
|
1109
|
-
try {
|
|
1110
|
-
raw = await readFile(path, "utf8");
|
|
1111
|
-
} catch {
|
|
1112
|
-
raw = "# Dream Diary\n\n";
|
|
1113
|
-
}
|
|
1114
|
-
const next = `${raw.endsWith("\n") ? raw : `${raw}
|
|
1115
|
-
`}${renderDiaryEntry(entry)}`;
|
|
1116
|
-
await replaceFileAtomic(path, next);
|
|
1117
|
-
}
|
|
1118
|
-
function entryHash(entry) {
|
|
1119
|
-
return createHash("sha256").update(
|
|
1120
|
-
[
|
|
1121
|
-
entry.factsBefore,
|
|
1122
|
-
entry.factsAfter,
|
|
1123
|
-
entry.duplicatesRemoved,
|
|
1124
|
-
entry.clustersCreated,
|
|
1125
|
-
entry.notesWritten
|
|
1126
|
-
].join("|")
|
|
1127
|
-
).digest("hex");
|
|
1128
|
-
}
|
|
1129
1078
|
|
|
1130
1079
|
// src/internal/dreaming/dreaming-phases.ts
|
|
1131
1080
|
var DEFAULT_DEDUP_THRESHOLD = 0.95;
|
|
@@ -1247,7 +1196,7 @@ async function runInner(options) {
|
|
|
1247
1196
|
notesWritten,
|
|
1248
1197
|
diaryEntryHash: void 0
|
|
1249
1198
|
};
|
|
1250
|
-
await appendDiaryEntry(options.cwd, {
|
|
1199
|
+
await appendDiaryEntry(resolveMemoryRoot(options.cwd), {
|
|
1251
1200
|
timestampMs,
|
|
1252
1201
|
factsBefore: result.factsBefore,
|
|
1253
1202
|
factsAfter: result.factsAfter,
|
|
@@ -1265,7 +1214,7 @@ async function runInner(options) {
|
|
|
1265
1214
|
}
|
|
1266
1215
|
async function writeConsolidatedNotes(cwd, clusters, timestampMs) {
|
|
1267
1216
|
if (clusters.length === 0) return 0;
|
|
1268
|
-
const notesDir3 = join(
|
|
1217
|
+
const notesDir3 = join(resolveMemoryRoot(cwd), "notes");
|
|
1269
1218
|
await mkdir(notesDir3, { recursive: true });
|
|
1270
1219
|
const isoSlug = new Date(timestampMs).toISOString().replace(/[^\dT]/g, "-");
|
|
1271
1220
|
const file = join(notesDir3, `dreamed-${isoSlug}.md`);
|
|
@@ -1338,9 +1287,6 @@ async function openMemoryDb(opts) {
|
|
|
1338
1287
|
}
|
|
1339
1288
|
});
|
|
1340
1289
|
}
|
|
1341
|
-
function defaultIndexPath(cwd) {
|
|
1342
|
-
return join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
|
|
1343
|
-
}
|
|
1344
1290
|
var HEADING_RE = /^(#{1,6})\s+(.+?)\s*$/;
|
|
1345
1291
|
function chunkMarkdown(text, options = {}) {
|
|
1346
1292
|
const maxChars = options.maxChars ?? 800;
|
|
@@ -1416,91 +1362,6 @@ function findWordBoundarySplit(text, maxChars) {
|
|
|
1416
1362
|
}
|
|
1417
1363
|
return maxChars;
|
|
1418
1364
|
}
|
|
1419
|
-
var MAX_TURN_CHARS = 2e3;
|
|
1420
|
-
function sessionsDir(cwd) {
|
|
1421
|
-
return join(memoryDir(cwd), "sessions");
|
|
1422
|
-
}
|
|
1423
|
-
function sessionSummaryPath(cwd, runId) {
|
|
1424
|
-
return join(sessionsDir(cwd), `${sanitizeRunId2(runId)}.md`);
|
|
1425
|
-
}
|
|
1426
|
-
function sanitizeRunId2(runId) {
|
|
1427
|
-
return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
|
|
1428
|
-
}
|
|
1429
|
-
function truncate2(text) {
|
|
1430
|
-
if (text.length <= MAX_TURN_CHARS) return text;
|
|
1431
|
-
return `${text.slice(0, MAX_TURN_CHARS)}\u2026`;
|
|
1432
|
-
}
|
|
1433
|
-
async function writeSessionSummary(input) {
|
|
1434
|
-
if (input.status !== "finished") return;
|
|
1435
|
-
const path = sessionSummaryPath(input.cwd, input.runId);
|
|
1436
|
-
await mkdir(sessionsDir(input.cwd), { recursive: true });
|
|
1437
|
-
const safeUser = redactSecrets(truncate2(input.userText));
|
|
1438
|
-
const safeAssistant = redactSecrets(truncate2(input.assistantText));
|
|
1439
|
-
const iso = new Date(input.at).toISOString();
|
|
1440
|
-
const body = [
|
|
1441
|
-
"---",
|
|
1442
|
-
`runId: ${input.runId}`,
|
|
1443
|
-
`agentId: ${input.agentId}`,
|
|
1444
|
-
`at: ${iso}`,
|
|
1445
|
-
`status: ${input.status}`,
|
|
1446
|
-
"---",
|
|
1447
|
-
"",
|
|
1448
|
-
"## User",
|
|
1449
|
-
"",
|
|
1450
|
-
safeUser,
|
|
1451
|
-
"",
|
|
1452
|
-
"## Assistant",
|
|
1453
|
-
"",
|
|
1454
|
-
safeAssistant,
|
|
1455
|
-
""
|
|
1456
|
-
].join("\n");
|
|
1457
|
-
await replaceFileAtomic(path, body);
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
// src/internal/store/session-loader.ts
|
|
1461
|
-
async function discoverSessionFiles(cwd) {
|
|
1462
|
-
let entries;
|
|
1463
|
-
try {
|
|
1464
|
-
entries = await readdir(sessionsDir(cwd));
|
|
1465
|
-
} catch {
|
|
1466
|
-
return [];
|
|
1467
|
-
}
|
|
1468
|
-
const root = memoryDir(cwd);
|
|
1469
|
-
return entries.filter((entry) => entry.endsWith(".md")).map((entry) => {
|
|
1470
|
-
const absolutePath = join(sessionsDir(cwd), entry);
|
|
1471
|
-
return {
|
|
1472
|
-
absolutePath,
|
|
1473
|
-
relPath: relativeToRoot(root, absolutePath)
|
|
1474
|
-
};
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
function relativeToRoot(root, absolutePath) {
|
|
1478
|
-
if (absolutePath.startsWith(`${root}/`)) return absolutePath.slice(root.length + 1);
|
|
1479
|
-
return absolutePath;
|
|
1480
|
-
}
|
|
1481
|
-
function wikiDir(cwd) {
|
|
1482
|
-
return join(memoryDir(cwd), "wiki");
|
|
1483
|
-
}
|
|
1484
|
-
async function discoverWikiFiles(cwd) {
|
|
1485
|
-
let entries;
|
|
1486
|
-
try {
|
|
1487
|
-
entries = await readdir(wikiDir(cwd));
|
|
1488
|
-
} catch {
|
|
1489
|
-
return [];
|
|
1490
|
-
}
|
|
1491
|
-
const root = memoryDir(cwd);
|
|
1492
|
-
return entries.filter((entry) => entry.endsWith(".md")).map((entry) => ({
|
|
1493
|
-
absolutePath: join(wikiDir(cwd), entry),
|
|
1494
|
-
relPath: join("wiki", entry)
|
|
1495
|
-
})).map((file) => ({
|
|
1496
|
-
absolutePath: file.absolutePath,
|
|
1497
|
-
relPath: relativeToRoot2(root, file.absolutePath)
|
|
1498
|
-
}));
|
|
1499
|
-
}
|
|
1500
|
-
function relativeToRoot2(root, absolutePath) {
|
|
1501
|
-
if (absolutePath.startsWith(`${root}/`)) return absolutePath.slice(root.length + 1);
|
|
1502
|
-
return absolutePath;
|
|
1503
|
-
}
|
|
1504
1365
|
function requireLance() {
|
|
1505
1366
|
try {
|
|
1506
1367
|
const r = createRequire(import.meta.url);
|
|
@@ -1523,7 +1384,7 @@ var LanceIndex = class _LanceIndex {
|
|
|
1523
1384
|
embeddingDim;
|
|
1524
1385
|
static async open(opts) {
|
|
1525
1386
|
const lance = requireLance();
|
|
1526
|
-
const storagePath = opts.storagePath ??
|
|
1387
|
+
const storagePath = opts.storagePath ?? lanceStoragePath(opts.memoryRoot ?? resolveMemoryRoot(opts.cwd));
|
|
1527
1388
|
mkdirSync(storagePath, { recursive: true });
|
|
1528
1389
|
const conn = await lance.connect(storagePath);
|
|
1529
1390
|
const dim = opts.embedding.dimension;
|
|
@@ -1625,9 +1486,6 @@ function isLanceAvailable() {
|
|
|
1625
1486
|
return false;
|
|
1626
1487
|
}
|
|
1627
1488
|
}
|
|
1628
|
-
function lanceStoragePath(cwd) {
|
|
1629
|
-
return join(cwd, ".theokit", "memory", "lance");
|
|
1630
|
-
}
|
|
1631
1489
|
|
|
1632
1490
|
// src/internal/index/memory-index.ts
|
|
1633
1491
|
function parseSearchOptions(options = {}) {
|
|
@@ -1827,12 +1685,12 @@ async function embedMissingChunks(args) {
|
|
|
1827
1685
|
|
|
1828
1686
|
// src/internal/index/index-manager.ts
|
|
1829
1687
|
var IndexManager = class _IndexManager {
|
|
1830
|
-
constructor(
|
|
1831
|
-
this.
|
|
1688
|
+
constructor(memoryRoot, db, embedding) {
|
|
1689
|
+
this.memoryRoot = memoryRoot;
|
|
1832
1690
|
this.db = db;
|
|
1833
1691
|
this.embedding = embedding;
|
|
1834
1692
|
}
|
|
1835
|
-
|
|
1693
|
+
memoryRoot;
|
|
1836
1694
|
db;
|
|
1837
1695
|
embedding;
|
|
1838
1696
|
lastSyncMs;
|
|
@@ -1845,9 +1703,10 @@ var IndexManager = class _IndexManager {
|
|
|
1845
1703
|
}
|
|
1846
1704
|
/** Internal SQLite-path open. Renamed from previous public `open`. */
|
|
1847
1705
|
static async openSqliteInternal(opts) {
|
|
1848
|
-
const
|
|
1706
|
+
const memoryRoot = opts.memoryRoot ?? resolveMemoryRoot(opts.cwd);
|
|
1707
|
+
const filePath = opts.filePath ?? defaultIndexPath(projectMemoryDir(opts.cwd));
|
|
1849
1708
|
const db = await openMemoryDb({ filePath });
|
|
1850
|
-
const manager = new _IndexManager(
|
|
1709
|
+
const manager = new _IndexManager(memoryRoot, db, opts.embedding);
|
|
1851
1710
|
if (opts.embedding !== void 0) await manager.initVectorBackend(opts.embedding);
|
|
1852
1711
|
return manager;
|
|
1853
1712
|
}
|
|
@@ -1868,7 +1727,7 @@ var IndexManager = class _IndexManager {
|
|
|
1868
1727
|
}
|
|
1869
1728
|
/** Walk the memory corpus + (re)index changed files. */
|
|
1870
1729
|
async sync() {
|
|
1871
|
-
const files = await collectMarkdownFiles(this.
|
|
1730
|
+
const files = await collectMarkdownFiles(this.memoryRoot);
|
|
1872
1731
|
let filesUpdated = 0;
|
|
1873
1732
|
let chunksWritten = 0;
|
|
1874
1733
|
const existingByPath = this.loadFilesIndex();
|
|
@@ -2065,45 +1924,6 @@ function blendScores(hit, vectorScore, weights) {
|
|
|
2065
1924
|
...vectorScore > 0 ? { vectorScore } : {}
|
|
2066
1925
|
};
|
|
2067
1926
|
}
|
|
2068
|
-
async function collectMarkdownFiles(cwd) {
|
|
2069
|
-
const root = memoryDir(cwd);
|
|
2070
|
-
const results = [];
|
|
2071
|
-
try {
|
|
2072
|
-
await stat(memoryMdPath(cwd));
|
|
2073
|
-
results.push({
|
|
2074
|
-
absolutePath: memoryMdPath(cwd),
|
|
2075
|
-
relPath: relative(root, memoryMdPath(cwd)),
|
|
2076
|
-
source: "memory"
|
|
2077
|
-
});
|
|
2078
|
-
} catch {
|
|
2079
|
-
}
|
|
2080
|
-
try {
|
|
2081
|
-
const entries = await readdir(notesDir(cwd));
|
|
2082
|
-
for (const entry of entries) {
|
|
2083
|
-
if (!entry.endsWith(".md")) continue;
|
|
2084
|
-
const abs = join(notesDir(cwd), entry);
|
|
2085
|
-
results.push({ absolutePath: abs, relPath: relative(root, abs), source: "memory" });
|
|
2086
|
-
}
|
|
2087
|
-
} catch {
|
|
2088
|
-
}
|
|
2089
|
-
const wikiFiles = await discoverWikiFiles(cwd);
|
|
2090
|
-
for (const wiki of wikiFiles) {
|
|
2091
|
-
results.push({
|
|
2092
|
-
absolutePath: wiki.absolutePath,
|
|
2093
|
-
relPath: wiki.relPath,
|
|
2094
|
-
source: "wiki"
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
const sessionFiles = await discoverSessionFiles(cwd);
|
|
2098
|
-
for (const session of sessionFiles) {
|
|
2099
|
-
results.push({
|
|
2100
|
-
absolutePath: session.absolutePath,
|
|
2101
|
-
relPath: session.relPath,
|
|
2102
|
-
source: "sessions"
|
|
2103
|
-
});
|
|
2104
|
-
}
|
|
2105
|
-
return results;
|
|
2106
|
-
}
|
|
2107
1927
|
function sha256(text) {
|
|
2108
1928
|
return createHash("sha256").update(text).digest("hex");
|
|
2109
1929
|
}
|
|
@@ -2111,30 +1931,14 @@ function truncateSnippet(text) {
|
|
|
2111
1931
|
const max = 500;
|
|
2112
1932
|
return text.length <= max ? text : `${text.slice(0, max)}\u2026`;
|
|
2113
1933
|
}
|
|
2114
|
-
async function readAllSqliteFacts(cwd) {
|
|
2115
|
-
const dbPath = defaultIndexPath(cwd);
|
|
2116
|
-
if (!existsSync(dbPath)) return [];
|
|
2117
|
-
const db = await openMemoryDb({ filePath: dbPath });
|
|
2118
|
-
try {
|
|
2119
|
-
const stmt = db.prepare("SELECT id, path, source, start_line, end_line, text FROM chunks");
|
|
2120
|
-
const rows = stmt.all();
|
|
2121
|
-
return rows.map((r) => ({
|
|
2122
|
-
...r,
|
|
2123
|
-
namespace: "default",
|
|
2124
|
-
scope: "agent",
|
|
2125
|
-
user_id: "default"
|
|
2126
|
-
}));
|
|
2127
|
-
} finally {
|
|
2128
|
-
db.close();
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
1934
|
function nfcEqual(a, b) {
|
|
2132
1935
|
return a.normalize("NFC") === b.normalize("NFC");
|
|
2133
1936
|
}
|
|
2134
1937
|
async function migrateSqliteToLance(opts) {
|
|
2135
1938
|
const cwd = opts.cwd;
|
|
2136
|
-
const
|
|
2137
|
-
const
|
|
1939
|
+
const memoryRoot = resolveMemoryRoot(cwd, { directory: opts.directory });
|
|
1940
|
+
const finalPath = lanceStoragePath(memoryRoot);
|
|
1941
|
+
const newPath = join(memoryRoot, "lance-new");
|
|
2138
1942
|
const rawLog = opts.logger ?? ((m) => console.log(m));
|
|
2139
1943
|
const log = (m) => rawLog(redactSecrets(m));
|
|
2140
1944
|
if (existsSync(finalPath)) {
|
|
@@ -2148,7 +1952,7 @@ async function migrateSqliteToLance(opts) {
|
|
|
2148
1952
|
rmSync(newPath, { recursive: true, force: true });
|
|
2149
1953
|
}
|
|
2150
1954
|
log(`Reading SQLite facts from ${cwd}/.theokit/memory/index.sqlite ...`);
|
|
2151
|
-
const sqliteFacts = await readAllSqliteFacts(
|
|
1955
|
+
const sqliteFacts = await readAllSqliteFacts(memoryRoot);
|
|
2152
1956
|
log(`SQLite has ${sqliteFacts.length} facts.`);
|
|
2153
1957
|
if (sqliteFacts.length === 0) {
|
|
2154
1958
|
return {
|
|
@@ -2292,7 +2096,7 @@ async function migrateLegacyJson(cwd, config) {
|
|
|
2292
2096
|
if (!await fileExists(jsonPath)) {
|
|
2293
2097
|
return { migrated: false, factCount: 0, reason: "no-legacy-json" };
|
|
2294
2098
|
}
|
|
2295
|
-
if (await fileExists(memoryMdPath(cwd))) {
|
|
2099
|
+
if (await fileExists(memoryMdPath(resolveMemoryRoot(cwd)))) {
|
|
2296
2100
|
process.stderr.write(
|
|
2297
2101
|
`[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
|
|
2298
2102
|
`
|
|
@@ -2378,7 +2182,7 @@ function createMemorySearchTool(opts) {
|
|
|
2378
2182
|
};
|
|
2379
2183
|
}
|
|
2380
2184
|
function createMemoryGetTool(opts) {
|
|
2381
|
-
const memoryRoot = resolve(
|
|
2185
|
+
const memoryRoot = resolve(opts.root);
|
|
2382
2186
|
return {
|
|
2383
2187
|
name: "memory_get",
|
|
2384
2188
|
description: GET_DESCRIPTION,
|
|
@@ -2447,6 +2251,6 @@ function isPathInside(root, candidate) {
|
|
|
2447
2251
|
return candidate === root || candidate.startsWith(normalizedRoot);
|
|
2448
2252
|
}
|
|
2449
2253
|
|
|
2450
|
-
export { ActiveMemoryCache, CircuitBreaker, DEFAULT_AZURE_OPENAI_EMBEDDING_MODEL, DEFAULT_COHERE_EMBEDDING_MODEL, DEFAULT_DEEPINFRA_EMBEDDING_MODEL, DEFAULT_GEMINI_EMBEDDING_MODEL, DEFAULT_JINA_EMBEDDING_MODEL, DEFAULT_MEMORY_READ_LINES, DEFAULT_MISTRAL_EMBEDDING_MODEL, DEFAULT_OLLAMA_EMBEDDING_MODEL, DEFAULT_OPENAI_EMBEDDING_MODEL, DEFAULT_OPENROUTER_EMBEDDING_MODEL, DEFAULT_VOYAGE_EMBEDDING_MODEL, IndexManager, LanceIndex, LanceMemoryAdapter, MEMORY_EMBEDDING_ADAPTERS, META_KEY_DIMENSION, META_KEY_MODEL, META_KEY_PROVIDER_ID, PRAGMA_STATEMENTS, SCHEMA_STATEMENTS, VALID_BACKENDS,
|
|
2254
|
+
export { ActiveMemoryCache, CircuitBreaker, DEFAULT_AZURE_OPENAI_EMBEDDING_MODEL, DEFAULT_COHERE_EMBEDDING_MODEL, DEFAULT_DEEPINFRA_EMBEDDING_MODEL, DEFAULT_GEMINI_EMBEDDING_MODEL, DEFAULT_JINA_EMBEDDING_MODEL, DEFAULT_MEMORY_READ_LINES, DEFAULT_MISTRAL_EMBEDDING_MODEL, DEFAULT_OLLAMA_EMBEDDING_MODEL, DEFAULT_OPENAI_EMBEDDING_MODEL, DEFAULT_OPENROUTER_EMBEDDING_MODEL, DEFAULT_VOYAGE_EMBEDDING_MODEL, IndexManager, LanceIndex, LanceMemoryAdapter, MEMORY_EMBEDDING_ADAPTERS, META_KEY_DIMENSION, META_KEY_MODEL, META_KEY_PROVIDER_ID, PRAGMA_STATEMENTS, SCHEMA_STATEMENTS, VALID_BACKENDS, assertValidBackend, azureOpenAiMemoryEmbeddingProviderAdapter, buildErrorMetadata, chunkMarkdown, cohereMemoryEmbeddingProviderAdapter, createCategorizedMemory, createInMemoryMarkdownProvider, createMemoryGetTool, createMemorySearchTool, createVectorIndex, deepPhase, deepinfraMemoryEmbeddingProviderAdapter, dropVectorIndex, embedMissingChunks, geminiMemoryEmbeddingProviderAdapter, identityMatches, isLanceAvailable, isSqliteVecLoaded, jinaMemoryEmbeddingProviderAdapter, legacyMemoryJsonPath, lightPhase, listNotes, loadSqliteVecExtension, mapOpenAICompatibleError, migrateLegacyJson, migrateSqliteToLance, mistralMemoryEmbeddingProviderAdapter, ollamaMemoryEmbeddingProviderAdapter, openAiMemoryEmbeddingProviderAdapter, openLanceIndex, openMemoryDb, openRouterMemoryEmbeddingProviderAdapter, packVector, parseRetryAfter, parseSearchOptions, readEmbeddingIdentity, readMemoryFileBounded, redactSecrets, remPhase, resetMigrationStateForTests, runActiveMemory, runDreamingSweep, truncateRaw, upsertEmbedding, vectorSearch, voyageMemoryEmbeddingProviderAdapter, writeEmbeddingIdentity };
|
|
2451
2255
|
//# sourceMappingURL=index.js.map
|
|
2452
2256
|
//# sourceMappingURL=index.js.map
|