@yugenlab/vaayu 0.1.1 → 0.1.3
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/LICENSE +1 -1
- package/README.md +1 -1
- package/chunks/{chunk-E5A3SCDJ.js → chunk-6556EKOB.js} +2 -2
- package/chunks/{chunk-H76V36OF.js → chunk-7UOXFHEB.js} +6 -6
- package/chunks/{chunk-KDRROLVN.js → chunk-D3RVJGO7.js} +2 -2
- package/chunks/{chunk-HAPVUJ6A.js → chunk-DOQMEQ5S.js} +9 -7
- package/chunks/{chunk-YSU3BWV6.js → chunk-IGBRBFXX.js} +2 -2
- package/chunks/{chunk-JZU37VQ5.js → chunk-LVE2EOOH.js} +10 -8
- package/chunks/{chunk-L7JICQBW.js → chunk-NHRBVSN3.js} +6 -4
- package/chunks/chunk-OBYBBGHA.js +545 -0
- package/chunks/{chunk-ITIVYGUG.js → chunk-PJEYJQ2C.js} +7 -5
- package/chunks/{chunk-S4TBVCL2.js → chunk-S2HDNNC7.js} +6 -4
- package/chunks/{chunk-URGEODS5.js → chunk-TEQKXGIK.js} +5 -5
- package/chunks/chunk-U62ABYKD.js +123 -0
- package/chunks/{chunk-KC6NRZ7U.js → chunk-UZ6OIVEC.js} +1 -1
- package/chunks/{chunk-U6OLJ36B.js → chunk-YJRXLRTE.js} +21 -122
- package/chunks/{chunk-IIET2K6D.js → chunk-YSC77CKZ.js} +494 -674
- package/chunks/{consolidation-indexer-TOTTDZXW.js → consolidation-indexer-CD6DS2HO.js} +7 -6
- package/chunks/{day-consolidation-NKO63HZQ.js → day-consolidation-U3X6P4ZG.js} +3 -3
- package/chunks/graphrag-LAZSXLLI.js +14 -0
- package/chunks/{hierarchical-temporal-search-ZD46UMKR.js → hierarchical-temporal-search-ETXYYJZK.js} +2 -2
- package/chunks/hybrid-search-TX6T3KYH.js +20 -0
- package/chunks/{memory-store-KNJPMBLQ.js → memory-store-A6WOWLWC.js} +3 -3
- package/chunks/periodic-consolidation-4MACZE6S.js +11 -0
- package/chunks/{recall-GMVHWQWW.js → recall-IUPQCBYP.js} +6 -5
- package/chunks/search-HHSVHBXC.js +19 -0
- package/chunks/{session-store-XKPGKXUS.js → session-store-NDUDYAC7.js} +5 -4
- package/chunks/{src-QAXOD5SB.js → src-ZAKUL232.js} +55 -41
- package/chunks/vasana-engine-G6BPOFX7.js +10 -0
- package/gateway.js +396 -87
- package/package.json +1 -1
- package/chunks/graphrag-ZI2FSU7S.js +0 -13
- package/chunks/hybrid-search-ZVLZVGFS.js +0 -19
- package/chunks/periodic-consolidation-BPKOZDGB.js +0 -10
- package/chunks/search-7HZETVMZ.js +0 -18
|
@@ -1,26 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDayFilePath,
|
|
3
|
+
listDayFiles
|
|
4
|
+
} from "./chunk-7UOXFHEB.js";
|
|
1
5
|
import {
|
|
2
6
|
PRESERVATION_RATIOS,
|
|
3
7
|
RecallEngine,
|
|
4
8
|
STREAM_ORDER,
|
|
5
9
|
StreamManager
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
cosineSimilarity,
|
|
9
|
-
estimateTokens
|
|
10
|
-
} from "./chunk-JAWZ7ANC.js";
|
|
10
|
+
} from "./chunk-LVE2EOOH.js";
|
|
11
11
|
import {
|
|
12
12
|
createSession,
|
|
13
13
|
listSessions,
|
|
14
14
|
loadSession,
|
|
15
15
|
saveSession
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-NHRBVSN3.js";
|
|
17
|
+
import {
|
|
18
|
+
cosineSimilarity,
|
|
19
|
+
estimateTokens
|
|
20
|
+
} from "./chunk-JAWZ7ANC.js";
|
|
17
21
|
import {
|
|
18
22
|
DatabaseManager
|
|
19
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-U62ABYKD.js";
|
|
20
24
|
import {
|
|
21
25
|
SessionError,
|
|
22
26
|
getChitraguptaHome
|
|
23
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-UZ6OIVEC.js";
|
|
24
28
|
|
|
25
29
|
// ../chitragupta/packages/smriti/src/session-export.ts
|
|
26
30
|
function exportSessionToJson(session) {
|
|
@@ -224,6 +228,339 @@ function validateExportedSession(data) {
|
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
230
|
|
|
231
|
+
// ../chitragupta/packages/smriti/src/cross-machine-sync.ts
|
|
232
|
+
import fs from "node:fs";
|
|
233
|
+
import os from "node:os";
|
|
234
|
+
import path from "node:path";
|
|
235
|
+
import crypto from "node:crypto";
|
|
236
|
+
var SNAPSHOT_VERSION = 1;
|
|
237
|
+
var ENTRY_SEPARATOR = "\n---\n\n";
|
|
238
|
+
function sha256(content) {
|
|
239
|
+
return crypto.createHash("sha256").update(content, "utf-8").digest("hex");
|
|
240
|
+
}
|
|
241
|
+
function toPortablePath(absPath, home) {
|
|
242
|
+
const rel = path.relative(home, absPath);
|
|
243
|
+
if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
244
|
+
throw new SessionError(`Path escapes Chitragupta home: ${absPath}`);
|
|
245
|
+
}
|
|
246
|
+
return rel.split(path.sep).join("/");
|
|
247
|
+
}
|
|
248
|
+
function resolveSnapshotPath(relPath, home) {
|
|
249
|
+
const normalizedRel = relPath.replaceAll("\\", "/");
|
|
250
|
+
const abs = path.resolve(home, normalizedRel);
|
|
251
|
+
const homeWithSep = home.endsWith(path.sep) ? home : `${home}${path.sep}`;
|
|
252
|
+
if (abs !== home && !abs.startsWith(homeWithSep)) {
|
|
253
|
+
throw new SessionError(`Snapshot path escapes Chitragupta home: ${relPath}`);
|
|
254
|
+
}
|
|
255
|
+
return abs;
|
|
256
|
+
}
|
|
257
|
+
function listMemoryFiles(memoryRoot) {
|
|
258
|
+
if (!fs.existsSync(memoryRoot)) return [];
|
|
259
|
+
const stack = [memoryRoot];
|
|
260
|
+
const files = [];
|
|
261
|
+
while (stack.length > 0) {
|
|
262
|
+
const current = stack.pop();
|
|
263
|
+
let entries = [];
|
|
264
|
+
try {
|
|
265
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
266
|
+
} catch {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
for (const entry of entries) {
|
|
270
|
+
const full = path.join(current, entry.name);
|
|
271
|
+
if (entry.isDirectory()) {
|
|
272
|
+
stack.push(full);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
276
|
+
files.push(full);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return files.sort();
|
|
281
|
+
}
|
|
282
|
+
function readSyncState(home) {
|
|
283
|
+
const statePath = path.join(home, "sync-state.json");
|
|
284
|
+
try {
|
|
285
|
+
if (!fs.existsSync(statePath)) return {};
|
|
286
|
+
const raw = fs.readFileSync(statePath, "utf-8");
|
|
287
|
+
const parsed = JSON.parse(raw);
|
|
288
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
289
|
+
} catch {
|
|
290
|
+
return {};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function writeSyncState(home, patch) {
|
|
294
|
+
const statePath = path.join(home, "sync-state.json");
|
|
295
|
+
const next = { ...readSyncState(home), ...patch };
|
|
296
|
+
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
297
|
+
fs.writeFileSync(statePath, JSON.stringify(next, null, " "), "utf-8");
|
|
298
|
+
}
|
|
299
|
+
function splitMemory(content) {
|
|
300
|
+
const normalized = content.replaceAll("\r\n", "\n");
|
|
301
|
+
const parts = normalized.split(ENTRY_SEPARATOR);
|
|
302
|
+
if (parts.length <= 1) {
|
|
303
|
+
return { header: normalized.trimEnd(), entries: [] };
|
|
304
|
+
}
|
|
305
|
+
const header = (parts[0] ?? "").trimEnd();
|
|
306
|
+
const entries = parts.slice(1).map((entry) => entry.trim()).filter(Boolean);
|
|
307
|
+
return { header, entries };
|
|
308
|
+
}
|
|
309
|
+
function mergeMemory(localContent, remoteContent) {
|
|
310
|
+
const localTrimmed = localContent.trim();
|
|
311
|
+
const remoteTrimmed = remoteContent.trim();
|
|
312
|
+
if (!localTrimmed) return remoteTrimmed ? `${remoteTrimmed}
|
|
313
|
+
` : "";
|
|
314
|
+
if (!remoteTrimmed) return localContent.endsWith("\n") ? localContent : `${localContent}
|
|
315
|
+
`;
|
|
316
|
+
if (localContent === remoteContent) return localContent;
|
|
317
|
+
const local = splitMemory(localContent);
|
|
318
|
+
const remote = splitMemory(remoteContent);
|
|
319
|
+
if (local.entries.length === 0 && remote.entries.length === 0) {
|
|
320
|
+
if (localContent.includes(remoteContent)) return localContent;
|
|
321
|
+
if (remoteContent.includes(localContent)) return remoteContent;
|
|
322
|
+
return `${localContent.trimEnd()}
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
${remoteContent.trim()}
|
|
327
|
+
`;
|
|
328
|
+
}
|
|
329
|
+
const header = local.header || remote.header || "# Memory";
|
|
330
|
+
const seen = /* @__PURE__ */ new Set();
|
|
331
|
+
const mergedEntries = [];
|
|
332
|
+
for (const entry of [...local.entries, ...remote.entries]) {
|
|
333
|
+
const key = sha256(entry.replace(/\s+/g, " ").trim().toLowerCase());
|
|
334
|
+
if (seen.has(key)) continue;
|
|
335
|
+
seen.add(key);
|
|
336
|
+
mergedEntries.push(entry.trim());
|
|
337
|
+
}
|
|
338
|
+
let merged = header.trimEnd();
|
|
339
|
+
if (mergedEntries.length > 0) {
|
|
340
|
+
merged += ENTRY_SEPARATOR + mergedEntries.join(ENTRY_SEPARATOR);
|
|
341
|
+
}
|
|
342
|
+
if (!merged.endsWith("\n")) merged += "\n";
|
|
343
|
+
return merged;
|
|
344
|
+
}
|
|
345
|
+
function assertSnapshot(value) {
|
|
346
|
+
if (!value || typeof value !== "object") {
|
|
347
|
+
throw new SessionError("Invalid sync snapshot: expected object");
|
|
348
|
+
}
|
|
349
|
+
const snapshot = value;
|
|
350
|
+
if (snapshot.version !== SNAPSHOT_VERSION) {
|
|
351
|
+
throw new SessionError(`Unsupported sync snapshot version: ${String(snapshot.version)}`);
|
|
352
|
+
}
|
|
353
|
+
if (typeof snapshot.exportedAt !== "string") {
|
|
354
|
+
throw new SessionError("Invalid sync snapshot: missing exportedAt");
|
|
355
|
+
}
|
|
356
|
+
if (!Array.isArray(snapshot.files)) {
|
|
357
|
+
throw new SessionError("Invalid sync snapshot: missing files array");
|
|
358
|
+
}
|
|
359
|
+
for (const file of snapshot.files) {
|
|
360
|
+
if (!file || typeof file !== "object") {
|
|
361
|
+
throw new SessionError("Invalid sync snapshot: file entry must be object");
|
|
362
|
+
}
|
|
363
|
+
const entry = file;
|
|
364
|
+
if (typeof entry.path !== "string" || !entry.path) {
|
|
365
|
+
throw new SessionError("Invalid sync snapshot: file.path must be non-empty string");
|
|
366
|
+
}
|
|
367
|
+
if (entry.kind !== "day" && entry.kind !== "memory") {
|
|
368
|
+
throw new SessionError(`Invalid sync snapshot: unsupported kind for ${String(entry.path)}`);
|
|
369
|
+
}
|
|
370
|
+
if (typeof entry.content !== "string" || typeof entry.sha256 !== "string") {
|
|
371
|
+
throw new SessionError(`Invalid sync snapshot: content/hash missing for ${entry.path}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function createCrossMachineSnapshot(options) {
|
|
376
|
+
const includeDays = options?.includeDays ?? true;
|
|
377
|
+
const includeMemory = options?.includeMemory ?? true;
|
|
378
|
+
if (!includeDays && !includeMemory) {
|
|
379
|
+
throw new SessionError("Snapshot must include at least one category: days or memory");
|
|
380
|
+
}
|
|
381
|
+
const home = getChitraguptaHome();
|
|
382
|
+
const files = [];
|
|
383
|
+
if (includeDays) {
|
|
384
|
+
let dates = listDayFiles();
|
|
385
|
+
if (typeof options?.maxDays === "number" && Number.isFinite(options.maxDays)) {
|
|
386
|
+
dates = dates.slice(0, Math.max(0, Math.floor(options.maxDays)));
|
|
387
|
+
}
|
|
388
|
+
for (const date of dates) {
|
|
389
|
+
const absPath = getDayFilePath(date);
|
|
390
|
+
if (!fs.existsSync(absPath)) continue;
|
|
391
|
+
try {
|
|
392
|
+
const content = fs.readFileSync(absPath, "utf-8");
|
|
393
|
+
const stat = fs.statSync(absPath);
|
|
394
|
+
files.push({
|
|
395
|
+
path: toPortablePath(absPath, home),
|
|
396
|
+
kind: "day",
|
|
397
|
+
content,
|
|
398
|
+
sha256: sha256(content),
|
|
399
|
+
bytes: Buffer.byteLength(content, "utf-8"),
|
|
400
|
+
mtimeMs: stat.mtimeMs
|
|
401
|
+
});
|
|
402
|
+
} catch {
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (includeMemory) {
|
|
407
|
+
const memoryRoot = path.join(home, "memory");
|
|
408
|
+
for (const absPath of listMemoryFiles(memoryRoot)) {
|
|
409
|
+
try {
|
|
410
|
+
const content = fs.readFileSync(absPath, "utf-8");
|
|
411
|
+
const stat = fs.statSync(absPath);
|
|
412
|
+
files.push({
|
|
413
|
+
path: toPortablePath(absPath, home),
|
|
414
|
+
kind: "memory",
|
|
415
|
+
content,
|
|
416
|
+
sha256: sha256(content),
|
|
417
|
+
bytes: Buffer.byteLength(content, "utf-8"),
|
|
418
|
+
mtimeMs: stat.mtimeMs
|
|
419
|
+
});
|
|
420
|
+
} catch {
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
version: SNAPSHOT_VERSION,
|
|
426
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
427
|
+
source: {
|
|
428
|
+
machine: os.hostname(),
|
|
429
|
+
platform: `${process.platform}-${process.arch}`,
|
|
430
|
+
home
|
|
431
|
+
},
|
|
432
|
+
files
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function writeCrossMachineSnapshot(snapshot, outputPath) {
|
|
436
|
+
assertSnapshot(snapshot);
|
|
437
|
+
const resolved = path.resolve(outputPath);
|
|
438
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
439
|
+
fs.writeFileSync(resolved, JSON.stringify(snapshot, null, " "), "utf-8");
|
|
440
|
+
writeSyncState(getChitraguptaHome(), {
|
|
441
|
+
lastExportAt: snapshot.exportedAt,
|
|
442
|
+
lastExportPath: resolved
|
|
443
|
+
});
|
|
444
|
+
return resolved;
|
|
445
|
+
}
|
|
446
|
+
function readCrossMachineSnapshot(snapshotPath) {
|
|
447
|
+
const resolved = path.resolve(snapshotPath);
|
|
448
|
+
const raw = fs.readFileSync(resolved, "utf-8");
|
|
449
|
+
const parsed = JSON.parse(raw);
|
|
450
|
+
assertSnapshot(parsed);
|
|
451
|
+
return parsed;
|
|
452
|
+
}
|
|
453
|
+
function getCrossMachineSyncStatus() {
|
|
454
|
+
const home = getChitraguptaHome();
|
|
455
|
+
const state = readSyncState(home);
|
|
456
|
+
const daysCount = listDayFiles().length;
|
|
457
|
+
const memoryCount = listMemoryFiles(path.join(home, "memory")).length;
|
|
458
|
+
return {
|
|
459
|
+
home,
|
|
460
|
+
daysCount,
|
|
461
|
+
memoryCount,
|
|
462
|
+
...state
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function writeTextFile(filePath, content) {
|
|
466
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
467
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
468
|
+
}
|
|
469
|
+
function createConflictPath(conflictRoot, relPath) {
|
|
470
|
+
const ext = path.extname(relPath);
|
|
471
|
+
const base = ext ? relPath.slice(0, -ext.length) : relPath;
|
|
472
|
+
const remoteName = `${base}.remote${ext || ".md"}`;
|
|
473
|
+
return path.join(conflictRoot, remoteName);
|
|
474
|
+
}
|
|
475
|
+
function importCrossMachineSnapshot(source, options) {
|
|
476
|
+
const snapshot = typeof source === "string" ? readCrossMachineSnapshot(source) : source;
|
|
477
|
+
assertSnapshot(snapshot);
|
|
478
|
+
const home = getChitraguptaHome();
|
|
479
|
+
const strategy = options?.strategy ?? "safe";
|
|
480
|
+
const dryRun = options?.dryRun ?? false;
|
|
481
|
+
const importedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
482
|
+
const conflictRoot = path.join(home, "sync-conflicts", importedAt.replace(/[:.]/g, "-"));
|
|
483
|
+
const totals = {
|
|
484
|
+
files: snapshot.files.length,
|
|
485
|
+
created: 0,
|
|
486
|
+
updated: 0,
|
|
487
|
+
merged: 0,
|
|
488
|
+
skipped: 0,
|
|
489
|
+
conflicts: 0,
|
|
490
|
+
errors: 0
|
|
491
|
+
};
|
|
492
|
+
const changedPaths = [];
|
|
493
|
+
const conflictPaths = [];
|
|
494
|
+
const errorPaths = [];
|
|
495
|
+
for (const file of snapshot.files) {
|
|
496
|
+
try {
|
|
497
|
+
const contentHash = sha256(file.content);
|
|
498
|
+
if (contentHash !== file.sha256) {
|
|
499
|
+
totals.errors += 1;
|
|
500
|
+
errorPaths.push(file.path);
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const targetPath = resolveSnapshotPath(file.path, home);
|
|
504
|
+
if (!fs.existsSync(targetPath)) {
|
|
505
|
+
if (!dryRun) writeTextFile(targetPath, file.content);
|
|
506
|
+
totals.created += 1;
|
|
507
|
+
changedPaths.push(file.path);
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const localContent = fs.readFileSync(targetPath, "utf-8");
|
|
511
|
+
if (localContent === file.content || sha256(localContent) === file.sha256) {
|
|
512
|
+
totals.skipped += 1;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (file.kind === "memory") {
|
|
516
|
+
const merged = mergeMemory(localContent, file.content);
|
|
517
|
+
if (merged === localContent) {
|
|
518
|
+
totals.skipped += 1;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (!dryRun) writeTextFile(targetPath, merged);
|
|
522
|
+
totals.merged += 1;
|
|
523
|
+
changedPaths.push(file.path);
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (strategy === "preferRemote") {
|
|
527
|
+
if (!dryRun) writeTextFile(targetPath, file.content);
|
|
528
|
+
totals.updated += 1;
|
|
529
|
+
changedPaths.push(file.path);
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
if (strategy === "preferLocal") {
|
|
533
|
+
totals.skipped += 1;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
const conflictPath = createConflictPath(conflictRoot, file.path);
|
|
537
|
+
if (!dryRun) writeTextFile(conflictPath, file.content);
|
|
538
|
+
totals.conflicts += 1;
|
|
539
|
+
conflictPaths.push(toPortablePath(conflictPath, home));
|
|
540
|
+
} catch {
|
|
541
|
+
totals.errors += 1;
|
|
542
|
+
errorPaths.push(file.path);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (!dryRun) {
|
|
546
|
+
writeSyncState(home, {
|
|
547
|
+
lastImportAt: importedAt,
|
|
548
|
+
lastImportSource: snapshot.source.machine,
|
|
549
|
+
lastImportTotals: totals
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
importedAt,
|
|
554
|
+
sourceExportedAt: snapshot.exportedAt,
|
|
555
|
+
strategy,
|
|
556
|
+
dryRun,
|
|
557
|
+
totals,
|
|
558
|
+
changedPaths,
|
|
559
|
+
conflictPaths,
|
|
560
|
+
errorPaths
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
227
564
|
// ../chitragupta/packages/smriti/src/branch.ts
|
|
228
565
|
function branchSession(sessionId, project, branchName, fromTurn) {
|
|
229
566
|
const original = loadSession(sessionId, project);
|
|
@@ -738,13 +1075,13 @@ function writeDeltaMarkdown(delta) {
|
|
|
738
1075
|
}
|
|
739
1076
|
|
|
740
1077
|
// ../chitragupta/packages/smriti/src/compactor.ts
|
|
741
|
-
import
|
|
742
|
-
import
|
|
1078
|
+
import fs2 from "fs";
|
|
1079
|
+
import path2 from "path";
|
|
743
1080
|
function getCompactionDir() {
|
|
744
|
-
return
|
|
1081
|
+
return path2.join(getChitraguptaHome(), "smriti", "compaction");
|
|
745
1082
|
}
|
|
746
1083
|
function getDeltaDir() {
|
|
747
|
-
return
|
|
1084
|
+
return path2.join(getChitraguptaHome(), "smriti", "deltas");
|
|
748
1085
|
}
|
|
749
1086
|
function updateIdentityStream(streamManager, signals) {
|
|
750
1087
|
if (signals.identity.length === 0) return;
|
|
@@ -926,17 +1263,17 @@ var SessionCompactor = class {
|
|
|
926
1263
|
saveDelta(delta) {
|
|
927
1264
|
try {
|
|
928
1265
|
const dir = getDeltaDir();
|
|
929
|
-
|
|
930
|
-
const filePath =
|
|
1266
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
1267
|
+
const filePath = path2.join(dir, `${delta.sessionId}.md`);
|
|
931
1268
|
const markdown = writeDeltaMarkdown(delta);
|
|
932
|
-
|
|
1269
|
+
fs2.writeFileSync(filePath, markdown, "utf-8");
|
|
933
1270
|
} catch {
|
|
934
1271
|
}
|
|
935
1272
|
}
|
|
936
1273
|
saveMixingMatrix(sessionId, mixingMatrix, signals) {
|
|
937
1274
|
try {
|
|
938
1275
|
const dir = getCompactionDir();
|
|
939
|
-
|
|
1276
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
940
1277
|
const data = {
|
|
941
1278
|
sessionId,
|
|
942
1279
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -955,8 +1292,8 @@ var SessionCompactor = class {
|
|
|
955
1292
|
flow: signals.flow.slice(0, 10)
|
|
956
1293
|
}
|
|
957
1294
|
};
|
|
958
|
-
const filePath =
|
|
959
|
-
|
|
1295
|
+
const filePath = path2.join(dir, `${sessionId}.json`);
|
|
1296
|
+
fs2.writeFileSync(filePath, JSON.stringify(data, null, " "), "utf-8");
|
|
960
1297
|
} catch {
|
|
961
1298
|
}
|
|
962
1299
|
}
|
|
@@ -1552,10 +1889,10 @@ function computeSimilarity(a, b) {
|
|
|
1552
1889
|
}
|
|
1553
1890
|
|
|
1554
1891
|
// ../chitragupta/packages/smriti/src/checkpoint.ts
|
|
1555
|
-
import
|
|
1556
|
-
import
|
|
1892
|
+
import fs3 from "node:fs";
|
|
1893
|
+
import path3 from "node:path";
|
|
1557
1894
|
import { randomUUID } from "node:crypto";
|
|
1558
|
-
var DEFAULT_CHECKPOINT_DIR =
|
|
1895
|
+
var DEFAULT_CHECKPOINT_DIR = path3.join(".chitragupta", "checkpoints");
|
|
1559
1896
|
var DEFAULT_INTERVAL = 3e4;
|
|
1560
1897
|
var DEFAULT_MAX_CHECKPOINTS = 5;
|
|
1561
1898
|
var CHECKPOINT_EXT = ".json";
|
|
@@ -1585,16 +1922,16 @@ var CheckpointManager = class {
|
|
|
1585
1922
|
*/
|
|
1586
1923
|
async save(sessionId, data) {
|
|
1587
1924
|
const sessionDir = this.sessionDir(sessionId);
|
|
1588
|
-
await
|
|
1925
|
+
await fs3.promises.mkdir(sessionDir, { recursive: true });
|
|
1589
1926
|
const timestamp = Date.now();
|
|
1590
1927
|
const uuid = randomUUID().slice(0, 8);
|
|
1591
1928
|
const filename = `${timestamp}-${uuid}${CHECKPOINT_EXT}`;
|
|
1592
|
-
const filePath =
|
|
1929
|
+
const filePath = path3.join(sessionDir, filename);
|
|
1593
1930
|
const tmpPath = filePath + ".tmp";
|
|
1594
1931
|
const json = JSON.stringify(data, null, 2);
|
|
1595
1932
|
const sizeBytes = Buffer.byteLength(json, "utf-8");
|
|
1596
|
-
await
|
|
1597
|
-
await
|
|
1933
|
+
await fs3.promises.writeFile(tmpPath, json, "utf-8");
|
|
1934
|
+
await fs3.promises.rename(tmpPath, filePath);
|
|
1598
1935
|
await this.prune(sessionId);
|
|
1599
1936
|
return {
|
|
1600
1937
|
id: `${timestamp}-${uuid}`,
|
|
@@ -1614,7 +1951,7 @@ var CheckpointManager = class {
|
|
|
1614
1951
|
for (const cp of checkpoints) {
|
|
1615
1952
|
try {
|
|
1616
1953
|
const filePath = this.checkpointPath(sessionId, cp);
|
|
1617
|
-
const raw = await
|
|
1954
|
+
const raw = await fs3.promises.readFile(filePath, "utf-8");
|
|
1618
1955
|
const data = JSON.parse(raw);
|
|
1619
1956
|
if (data.version === 1 && data.sessionId === sessionId) {
|
|
1620
1957
|
return data;
|
|
@@ -1631,10 +1968,10 @@ var CheckpointManager = class {
|
|
|
1631
1968
|
*/
|
|
1632
1969
|
list(sessionId) {
|
|
1633
1970
|
const sessionDir = this.sessionDir(sessionId);
|
|
1634
|
-
if (!
|
|
1971
|
+
if (!fs3.existsSync(sessionDir)) return [];
|
|
1635
1972
|
let entries;
|
|
1636
1973
|
try {
|
|
1637
|
-
entries =
|
|
1974
|
+
entries = fs3.readdirSync(sessionDir);
|
|
1638
1975
|
} catch {
|
|
1639
1976
|
return [];
|
|
1640
1977
|
}
|
|
@@ -1643,22 +1980,22 @@ var CheckpointManager = class {
|
|
|
1643
1980
|
if (entry.endsWith(".tmp")) continue;
|
|
1644
1981
|
const parsed = parseCheckpointFilename(entry);
|
|
1645
1982
|
if (!parsed) continue;
|
|
1646
|
-
const filePath =
|
|
1983
|
+
const filePath = path3.join(sessionDir, entry);
|
|
1647
1984
|
let size = 0;
|
|
1648
1985
|
let turnCount = 0;
|
|
1649
1986
|
try {
|
|
1650
|
-
const stat =
|
|
1987
|
+
const stat = fs3.statSync(filePath);
|
|
1651
1988
|
size = stat.size;
|
|
1652
|
-
const fd =
|
|
1989
|
+
const fd = fs3.openSync(filePath, "r");
|
|
1653
1990
|
const buf = Buffer.alloc(Math.min(size, 512));
|
|
1654
|
-
|
|
1655
|
-
|
|
1991
|
+
fs3.readSync(fd, buf, 0, buf.length, 0);
|
|
1992
|
+
fs3.closeSync(fd);
|
|
1656
1993
|
const snippet = buf.toString("utf-8");
|
|
1657
1994
|
const turnMatch = snippet.match(/"turns"\s*:\s*\[/);
|
|
1658
1995
|
if (turnMatch) {
|
|
1659
1996
|
if (size < 1048576) {
|
|
1660
1997
|
try {
|
|
1661
|
-
const full =
|
|
1998
|
+
const full = fs3.readFileSync(filePath, "utf-8");
|
|
1662
1999
|
const obj = JSON.parse(full);
|
|
1663
2000
|
turnCount = obj.turns?.length ?? 0;
|
|
1664
2001
|
} catch {
|
|
@@ -1692,7 +2029,7 @@ var CheckpointManager = class {
|
|
|
1692
2029
|
for (const cp of toRemove) {
|
|
1693
2030
|
try {
|
|
1694
2031
|
const filePath = this.checkpointPath(sessionId, cp);
|
|
1695
|
-
await
|
|
2032
|
+
await fs3.promises.unlink(filePath);
|
|
1696
2033
|
removed++;
|
|
1697
2034
|
} catch {
|
|
1698
2035
|
}
|
|
@@ -1731,24 +2068,24 @@ var CheckpointManager = class {
|
|
|
1731
2068
|
*/
|
|
1732
2069
|
async deleteAll(sessionId) {
|
|
1733
2070
|
const sessionDir = this.sessionDir(sessionId);
|
|
1734
|
-
if (!
|
|
2071
|
+
if (!fs3.existsSync(sessionDir)) return;
|
|
1735
2072
|
try {
|
|
1736
|
-
await
|
|
2073
|
+
await fs3.promises.rm(sessionDir, { recursive: true, force: true });
|
|
1737
2074
|
} catch {
|
|
1738
2075
|
}
|
|
1739
2076
|
}
|
|
1740
2077
|
// ─── Private ──────────────────────────────────────────────────────────────
|
|
1741
2078
|
sessionDir(sessionId) {
|
|
1742
|
-
return
|
|
2079
|
+
return path3.join(this.dir, sessionId);
|
|
1743
2080
|
}
|
|
1744
2081
|
checkpointPath(sessionId, cp) {
|
|
1745
|
-
return
|
|
2082
|
+
return path3.join(this.sessionDir(sessionId), `${cp.id}${CHECKPOINT_EXT}`);
|
|
1746
2083
|
}
|
|
1747
2084
|
};
|
|
1748
2085
|
|
|
1749
2086
|
// ../chitragupta/packages/smriti/src/consolidation.ts
|
|
1750
|
-
import
|
|
1751
|
-
import
|
|
2087
|
+
import fs4 from "fs";
|
|
2088
|
+
import path4 from "path";
|
|
1752
2089
|
var DEFAULT_CONFIG = {
|
|
1753
2090
|
minObservations: 2,
|
|
1754
2091
|
decayRatePerDay: 0.01,
|
|
@@ -2036,11 +2373,11 @@ var ConsolidationEngine = class {
|
|
|
2036
2373
|
*/
|
|
2037
2374
|
save() {
|
|
2038
2375
|
const dir = this.getStoragePath();
|
|
2039
|
-
|
|
2040
|
-
const rulesPath =
|
|
2041
|
-
const historyPath =
|
|
2042
|
-
|
|
2043
|
-
|
|
2376
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
2377
|
+
const rulesPath = path4.join(dir, "rules.json");
|
|
2378
|
+
const historyPath = path4.join(dir, "history.json");
|
|
2379
|
+
fs4.writeFileSync(rulesPath, JSON.stringify(this.getRules(), null, " "), "utf-8");
|
|
2380
|
+
fs4.writeFileSync(historyPath, JSON.stringify(this.history, null, " "), "utf-8");
|
|
2044
2381
|
}
|
|
2045
2382
|
/**
|
|
2046
2383
|
* Load previously persisted rules and history from disk.
|
|
@@ -2048,11 +2385,11 @@ var ConsolidationEngine = class {
|
|
|
2048
2385
|
*/
|
|
2049
2386
|
load() {
|
|
2050
2387
|
const dir = this.getStoragePath();
|
|
2051
|
-
const rulesPath =
|
|
2052
|
-
const historyPath =
|
|
2053
|
-
if (
|
|
2388
|
+
const rulesPath = path4.join(dir, "rules.json");
|
|
2389
|
+
const historyPath = path4.join(dir, "history.json");
|
|
2390
|
+
if (fs4.existsSync(rulesPath)) {
|
|
2054
2391
|
try {
|
|
2055
|
-
const data = JSON.parse(
|
|
2392
|
+
const data = JSON.parse(fs4.readFileSync(rulesPath, "utf-8"));
|
|
2056
2393
|
this.rules.clear();
|
|
2057
2394
|
for (const rule of data) {
|
|
2058
2395
|
this.rules.set(rule.id, rule);
|
|
@@ -2063,10 +2400,10 @@ var ConsolidationEngine = class {
|
|
|
2063
2400
|
this.rules.clear();
|
|
2064
2401
|
}
|
|
2065
2402
|
}
|
|
2066
|
-
if (
|
|
2403
|
+
if (fs4.existsSync(historyPath)) {
|
|
2067
2404
|
try {
|
|
2068
2405
|
this.history = JSON.parse(
|
|
2069
|
-
|
|
2406
|
+
fs4.readFileSync(historyPath, "utf-8")
|
|
2070
2407
|
);
|
|
2071
2408
|
} catch (err) {
|
|
2072
2409
|
process.stderr.write(`[consolidation] corrupted history.json, starting fresh: ${err instanceof Error ? err.message : err}
|
|
@@ -2457,7 +2794,7 @@ var ConsolidationEngine = class {
|
|
|
2457
2794
|
* @returns Absolute path to the consolidation storage directory.
|
|
2458
2795
|
*/
|
|
2459
2796
|
getStoragePath() {
|
|
2460
|
-
return this.config.storagePath ??
|
|
2797
|
+
return this.config.storagePath ?? path4.join(getChitraguptaHome(), "consolidation");
|
|
2461
2798
|
}
|
|
2462
2799
|
};
|
|
2463
2800
|
function extractSentenceContaining(text, index) {
|
|
@@ -3009,8 +3346,8 @@ var AnveshanaEngine = class {
|
|
|
3009
3346
|
};
|
|
3010
3347
|
|
|
3011
3348
|
// ../chitragupta/packages/smriti/src/smaran.ts
|
|
3012
|
-
import
|
|
3013
|
-
import
|
|
3349
|
+
import fs5 from "fs";
|
|
3350
|
+
import path5 from "path";
|
|
3014
3351
|
var DEFAULT_CONFIG3 = {
|
|
3015
3352
|
maxEntries: 1e3,
|
|
3016
3353
|
defaultDecayDays: 90,
|
|
@@ -3039,7 +3376,7 @@ var SmaranStore = class {
|
|
|
3039
3376
|
SMARAN_HARD_CEILINGS.recallLimit
|
|
3040
3377
|
)
|
|
3041
3378
|
};
|
|
3042
|
-
this.storagePath = this.config.storagePath ??
|
|
3379
|
+
this.storagePath = this.config.storagePath ?? path5.join(getChitraguptaHome(), "smaran");
|
|
3043
3380
|
}
|
|
3044
3381
|
// ─── Core CRUD ────────────────────────────────────────────────────────
|
|
3045
3382
|
/**
|
|
@@ -3308,11 +3645,11 @@ var SmaranStore = class {
|
|
|
3308
3645
|
this.loaded = true;
|
|
3309
3646
|
}
|
|
3310
3647
|
loadAll() {
|
|
3311
|
-
if (!
|
|
3312
|
-
const files =
|
|
3648
|
+
if (!fs5.existsSync(this.storagePath)) return;
|
|
3649
|
+
const files = fs5.readdirSync(this.storagePath).filter((f) => f.endsWith(".md"));
|
|
3313
3650
|
for (const file of files) {
|
|
3314
3651
|
try {
|
|
3315
|
-
const content =
|
|
3652
|
+
const content = fs5.readFileSync(path5.join(this.storagePath, file), "utf-8");
|
|
3316
3653
|
const entry = this.fromMarkdown(content);
|
|
3317
3654
|
if (entry) {
|
|
3318
3655
|
this.entries.set(entry.id, entry);
|
|
@@ -3327,15 +3664,15 @@ var SmaranStore = class {
|
|
|
3327
3664
|
}
|
|
3328
3665
|
}
|
|
3329
3666
|
saveEntry(entry) {
|
|
3330
|
-
|
|
3331
|
-
const filePath =
|
|
3667
|
+
fs5.mkdirSync(this.storagePath, { recursive: true });
|
|
3668
|
+
const filePath = path5.join(this.storagePath, `${entry.id}.md`);
|
|
3332
3669
|
const content = this.toMarkdown(entry);
|
|
3333
|
-
|
|
3670
|
+
fs5.writeFileSync(filePath, content, { encoding: "utf-8", mode: 384 });
|
|
3334
3671
|
}
|
|
3335
3672
|
deleteFile(id) {
|
|
3336
|
-
const filePath =
|
|
3673
|
+
const filePath = path5.join(this.storagePath, `${id}.md`);
|
|
3337
3674
|
try {
|
|
3338
|
-
if (
|
|
3675
|
+
if (fs5.existsSync(filePath)) fs5.unlinkSync(filePath);
|
|
3339
3676
|
} catch {
|
|
3340
3677
|
}
|
|
3341
3678
|
}
|
|
@@ -3581,9 +3918,9 @@ function cleanContent(content) {
|
|
|
3581
3918
|
}
|
|
3582
3919
|
|
|
3583
3920
|
// ../chitragupta/packages/smriti/src/identity-context.ts
|
|
3584
|
-
import
|
|
3585
|
-
import
|
|
3586
|
-
import
|
|
3921
|
+
import fs6 from "fs";
|
|
3922
|
+
import path6 from "path";
|
|
3923
|
+
import os2 from "os";
|
|
3587
3924
|
var DEFAULT_INCLUDE = ["soul", "identity", "personality", "user"];
|
|
3588
3925
|
var FILE_NAMES = {
|
|
3589
3926
|
soul: ["SOUL.md", "soul.md"],
|
|
@@ -3691,7 +4028,7 @@ var IdentityContext = class {
|
|
|
3691
4028
|
const fileNames = FILE_NAMES[type];
|
|
3692
4029
|
for (const dir of searchDirs) {
|
|
3693
4030
|
for (const name of fileNames) {
|
|
3694
|
-
const filePath =
|
|
4031
|
+
const filePath = path6.join(dir, name);
|
|
3695
4032
|
const content = readFileSafe(filePath);
|
|
3696
4033
|
if (content) return { type, path: filePath, content };
|
|
3697
4034
|
}
|
|
@@ -3704,13 +4041,13 @@ var IdentityContext = class {
|
|
|
3704
4041
|
dirs.push(this.config.projectPath);
|
|
3705
4042
|
let current = this.config.projectPath;
|
|
3706
4043
|
for (let i = 0; i < 3; i++) {
|
|
3707
|
-
const parent =
|
|
4044
|
+
const parent = path6.dirname(current);
|
|
3708
4045
|
if (parent === current) break;
|
|
3709
4046
|
dirs.push(parent);
|
|
3710
4047
|
current = parent;
|
|
3711
4048
|
}
|
|
3712
4049
|
}
|
|
3713
|
-
dirs.push(
|
|
4050
|
+
dirs.push(os2.homedir());
|
|
3714
4051
|
return dirs;
|
|
3715
4052
|
}
|
|
3716
4053
|
typeLabel(type) {
|
|
@@ -3730,8 +4067,8 @@ var IdentityContext = class {
|
|
|
3730
4067
|
};
|
|
3731
4068
|
function readFileSafe(filePath) {
|
|
3732
4069
|
try {
|
|
3733
|
-
if (
|
|
3734
|
-
const content =
|
|
4070
|
+
if (fs6.existsSync(filePath)) {
|
|
4071
|
+
const content = fs6.readFileSync(filePath, "utf-8");
|
|
3735
4072
|
if (content.trim().length > 0) return content;
|
|
3736
4073
|
}
|
|
3737
4074
|
} catch {
|
|
@@ -3743,7 +4080,7 @@ function stripFrontmatter(content) {
|
|
|
3743
4080
|
return fmMatch ? content.slice(fmMatch[0].length) : content;
|
|
3744
4081
|
}
|
|
3745
4082
|
|
|
3746
|
-
// ../chitragupta/packages/smriti/src/
|
|
4083
|
+
// ../chitragupta/packages/smriti/src/svapna-consolidation.ts
|
|
3747
4084
|
var FNV_OFFSET2 = 2166136261;
|
|
3748
4085
|
var FNV_PRIME2 = 16777619;
|
|
3749
4086
|
function fnv1a3(input) {
|
|
@@ -3755,543 +4092,6 @@ function fnv1a3(input) {
|
|
|
3755
4092
|
return hash.toString(16).padStart(8, "0");
|
|
3756
4093
|
}
|
|
3757
4094
|
var DEFAULT_CONFIG4 = {
|
|
3758
|
-
lambda: 50,
|
|
3759
|
-
changePointThreshold: 0.3,
|
|
3760
|
-
stabilityWindow: 5,
|
|
3761
|
-
windowSize: 20,
|
|
3762
|
-
holdoutTrainRatio: 0.7,
|
|
3763
|
-
accuracyThreshold: 0.6,
|
|
3764
|
-
decayHalfLifeMs: 30 * 864e5,
|
|
3765
|
-
promotionMinProjects: 3,
|
|
3766
|
-
maxRunLength: 200,
|
|
3767
|
-
priorMu: 0,
|
|
3768
|
-
priorKappa: 1,
|
|
3769
|
-
priorAlpha: 1,
|
|
3770
|
-
anomalyRevertWindow: 3,
|
|
3771
|
-
anomalyConfirmRatio: 0.5
|
|
3772
|
-
};
|
|
3773
|
-
var HARD_CEILINGS = {
|
|
3774
|
-
windowSize: 500,
|
|
3775
|
-
maxRunLength: 2e3,
|
|
3776
|
-
stabilityWindow: 100
|
|
3777
|
-
};
|
|
3778
|
-
function logsumexp2(xs) {
|
|
3779
|
-
if (xs.length === 0) return -Infinity;
|
|
3780
|
-
const m = Math.max(...xs);
|
|
3781
|
-
if (m === -Infinity) return -Infinity;
|
|
3782
|
-
let s = 0;
|
|
3783
|
-
for (let i = 0; i < xs.length; i++) s += Math.exp(xs[i] - m);
|
|
3784
|
-
return m + Math.log(s);
|
|
3785
|
-
}
|
|
3786
|
-
function lgamma(z) {
|
|
3787
|
-
const c = [
|
|
3788
|
-
0.9999999999998099,
|
|
3789
|
-
676.5203681218851,
|
|
3790
|
-
-1259.1392167224028,
|
|
3791
|
-
771.3234287776531,
|
|
3792
|
-
-176.6150291621406,
|
|
3793
|
-
12.507343278686905,
|
|
3794
|
-
-0.13857109526572012,
|
|
3795
|
-
9984369578019572e-21,
|
|
3796
|
-
15056327351493116e-23
|
|
3797
|
-
];
|
|
3798
|
-
if (z < 0.5) return Math.log(Math.PI / Math.sin(Math.PI * z)) - lgamma(1 - z);
|
|
3799
|
-
z -= 1;
|
|
3800
|
-
let x = c[0];
|
|
3801
|
-
for (let i = 1; i < 9; i++) x += c[i] / (z + i);
|
|
3802
|
-
const t = z + 7.5;
|
|
3803
|
-
return 0.5 * Math.log(2 * Math.PI) + (z + 0.5) * Math.log(t) - t + Math.log(x);
|
|
3804
|
-
}
|
|
3805
|
-
function logStudentT(x, nu, mu, sigma) {
|
|
3806
|
-
const safeSigma = sigma > 1e-15 ? sigma : 1e-15;
|
|
3807
|
-
const z = (x - mu) / safeSigma;
|
|
3808
|
-
return lgamma((nu + 1) / 2) - lgamma(nu / 2) - 0.5 * Math.log(nu * Math.PI * safeSigma * safeSigma) - (nu + 1) / 2 * Math.log(1 + z * z / nu);
|
|
3809
|
-
}
|
|
3810
|
-
var VasanaEngine = class {
|
|
3811
|
-
cfg;
|
|
3812
|
-
states = /* @__PURE__ */ new Map();
|
|
3813
|
-
obs = /* @__PURE__ */ new Map();
|
|
3814
|
-
cache = /* @__PURE__ */ new Map();
|
|
3815
|
-
constructor(config) {
|
|
3816
|
-
const merged = { ...DEFAULT_CONFIG4, ...config };
|
|
3817
|
-
for (const [k, ceil] of Object.entries(HARD_CEILINGS)) {
|
|
3818
|
-
const key = k;
|
|
3819
|
-
if (typeof merged[key] === "number" && typeof ceil === "number")
|
|
3820
|
-
merged[key] = Math.min(merged[key], ceil);
|
|
3821
|
-
}
|
|
3822
|
-
this.cfg = merged;
|
|
3823
|
-
}
|
|
3824
|
-
// ── Core API ─────────────────────────────────────────────────────────
|
|
3825
|
-
/** Observe a samskara: extract features and update BOCPD state per dimension. */
|
|
3826
|
-
observe(samskara) {
|
|
3827
|
-
for (const [feat, val] of this.extractFeatures(samskara)) {
|
|
3828
|
-
if (!this.states.has(feat)) this.states.set(feat, this.initState());
|
|
3829
|
-
const buf = this.obs.get(feat) ?? [];
|
|
3830
|
-
buf.push(val);
|
|
3831
|
-
if (buf.length > this.cfg.windowSize) buf.splice(0, buf.length - this.cfg.windowSize);
|
|
3832
|
-
this.obs.set(feat, buf);
|
|
3833
|
-
this.updateBOCPD(feat, val);
|
|
3834
|
-
}
|
|
3835
|
-
}
|
|
3836
|
-
/** Run crystallization: stability check, holdout validation, vasana upsert. */
|
|
3837
|
-
crystallize(project) {
|
|
3838
|
-
const now = Date.now();
|
|
3839
|
-
const res = { created: [], reinforced: [], pending: [], changePoints: [], anomalies: [], timestamp: now };
|
|
3840
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3841
|
-
const rows = db.prepare(
|
|
3842
|
-
`SELECT id, session_id, pattern_type, pattern_content, observation_count,
|
|
3843
|
-
confidence, pramana_type, project, created_at, updated_at
|
|
3844
|
-
FROM samskaras WHERE project = ? OR project IS NULL
|
|
3845
|
-
ORDER BY updated_at DESC LIMIT ?`
|
|
3846
|
-
).all(project, this.cfg.windowSize * 10);
|
|
3847
|
-
for (const [key, ids] of this.clusterSamskaras(rows)) {
|
|
3848
|
-
const feat = `cluster:${key}`;
|
|
3849
|
-
const st = this.states.get(feat);
|
|
3850
|
-
if (!st) {
|
|
3851
|
-
res.pending.push(key);
|
|
3852
|
-
continue;
|
|
3853
|
-
}
|
|
3854
|
-
const deviation = this.classifyDeviation(st);
|
|
3855
|
-
if (deviation === "change-point") {
|
|
3856
|
-
st.stableCount = 0;
|
|
3857
|
-
res.changePoints.push(key);
|
|
3858
|
-
continue;
|
|
3859
|
-
}
|
|
3860
|
-
if (deviation === "anomaly") {
|
|
3861
|
-
res.anomalies.push(key);
|
|
3862
|
-
continue;
|
|
3863
|
-
}
|
|
3864
|
-
st.stableCount++;
|
|
3865
|
-
if (st.stableCount < this.cfg.stabilityWindow) {
|
|
3866
|
-
res.pending.push(key);
|
|
3867
|
-
continue;
|
|
3868
|
-
}
|
|
3869
|
-
const o = this.obs.get(feat) ?? [];
|
|
3870
|
-
if (o.length < 4) {
|
|
3871
|
-
res.pending.push(key);
|
|
3872
|
-
continue;
|
|
3873
|
-
}
|
|
3874
|
-
const acc = this.holdoutValidation(o);
|
|
3875
|
-
if (acc < this.cfg.accuracyThreshold) {
|
|
3876
|
-
res.pending.push(key);
|
|
3877
|
-
continue;
|
|
3878
|
-
}
|
|
3879
|
-
const stability = this.stabilityScore(st);
|
|
3880
|
-
const valence = this.assignValence(rows.filter((r) => ids.has(r.id)));
|
|
3881
|
-
const vid = fnv1a3(key + ":" + project);
|
|
3882
|
-
const existing = this.loadVasana(vid);
|
|
3883
|
-
if (existing) {
|
|
3884
|
-
existing.strength = Math.min(1, existing.strength + 0.1);
|
|
3885
|
-
existing.stability = stability;
|
|
3886
|
-
existing.reinforcementCount++;
|
|
3887
|
-
existing.lastActivated = now;
|
|
3888
|
-
existing.predictiveAccuracy = acc;
|
|
3889
|
-
existing.updatedAt = now;
|
|
3890
|
-
this.saveVasana(existing);
|
|
3891
|
-
res.reinforced.push(existing);
|
|
3892
|
-
} else {
|
|
3893
|
-
const rep = rows.find((r) => ids.has(r.id));
|
|
3894
|
-
const v = {
|
|
3895
|
-
id: vid,
|
|
3896
|
-
tendency: key.replace(/:/g, "-"),
|
|
3897
|
-
description: rep?.pattern_content ?? key,
|
|
3898
|
-
strength: 0.5 + acc * 0.3,
|
|
3899
|
-
stability,
|
|
3900
|
-
valence,
|
|
3901
|
-
sourceSamskaras: [...ids],
|
|
3902
|
-
reinforcementCount: 1,
|
|
3903
|
-
lastActivated: now,
|
|
3904
|
-
predictiveAccuracy: acc,
|
|
3905
|
-
project,
|
|
3906
|
-
createdAt: now,
|
|
3907
|
-
updatedAt: now
|
|
3908
|
-
};
|
|
3909
|
-
this.saveVasana(v);
|
|
3910
|
-
res.created.push(v);
|
|
3911
|
-
}
|
|
3912
|
-
}
|
|
3913
|
-
return res;
|
|
3914
|
-
}
|
|
3915
|
-
/** Reinforce with diminishing returns: delta = 0.1 / (1 + ln(1 + count)). */
|
|
3916
|
-
reinforce(vasanaId) {
|
|
3917
|
-
const v = this.loadVasana(vasanaId);
|
|
3918
|
-
if (!v) return;
|
|
3919
|
-
v.strength = Math.min(1, v.strength + 0.1 / (1 + Math.log(1 + v.reinforcementCount)));
|
|
3920
|
-
v.reinforcementCount++;
|
|
3921
|
-
v.lastActivated = v.updatedAt = Date.now();
|
|
3922
|
-
this.saveVasana(v);
|
|
3923
|
-
}
|
|
3924
|
-
/** Weaken by fixed decrement. */
|
|
3925
|
-
weaken(vasanaId) {
|
|
3926
|
-
const v = this.loadVasana(vasanaId);
|
|
3927
|
-
if (!v) return;
|
|
3928
|
-
v.strength = Math.max(0, v.strength - 0.15);
|
|
3929
|
-
v.updatedAt = Date.now();
|
|
3930
|
-
this.saveVasana(v);
|
|
3931
|
-
}
|
|
3932
|
-
/** Get vasanas for a project (includes global), sorted by strength desc. */
|
|
3933
|
-
getVasanas(project, topK = 20) {
|
|
3934
|
-
const rows = DatabaseManager.instance().get("agent").prepare(
|
|
3935
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
3936
|
-
project,created_at,updated_at,last_activated,activation_count
|
|
3937
|
-
FROM vasanas WHERE project=? OR project IS NULL OR project='__global__'
|
|
3938
|
-
ORDER BY strength DESC LIMIT ?`
|
|
3939
|
-
).all(project, topK);
|
|
3940
|
-
return rows.map((r) => this.toVasana(r));
|
|
3941
|
-
}
|
|
3942
|
-
/** Promote project vasanas to global when found in >= promotionMinProjects. */
|
|
3943
|
-
promoteToGlobal() {
|
|
3944
|
-
const now = Date.now();
|
|
3945
|
-
const res = { promoted: [], projectSources: {}, timestamp: now };
|
|
3946
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3947
|
-
const rows = db.prepare(
|
|
3948
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
3949
|
-
project,created_at,updated_at,last_activated,activation_count
|
|
3950
|
-
FROM vasanas WHERE project IS NOT NULL AND project!='__global__' AND strength>=0.4
|
|
3951
|
-
ORDER BY name`
|
|
3952
|
-
).all();
|
|
3953
|
-
const byName = /* @__PURE__ */ new Map();
|
|
3954
|
-
for (const r of rows) {
|
|
3955
|
-
const k = r.name.toLowerCase();
|
|
3956
|
-
byName.set(k, [...byName.get(k) ?? [], r]);
|
|
3957
|
-
}
|
|
3958
|
-
for (const [tendency, group] of byName) {
|
|
3959
|
-
const projects = new Set(group.map((r) => r.project));
|
|
3960
|
-
if (projects.size < this.cfg.promotionMinProjects) continue;
|
|
3961
|
-
if (db.prepare(`SELECT 1 FROM vasanas WHERE name=? AND (project IS NULL OR project='__global__')`).get(tendency)) continue;
|
|
3962
|
-
const allSrc = [];
|
|
3963
|
-
for (const r of group) allSrc.push(...jsonArr(r.source_samskaras));
|
|
3964
|
-
const votes = { positive: 0, negative: 0, neutral: 0 };
|
|
3965
|
-
for (const r of group) votes[r.valence]++;
|
|
3966
|
-
const valence = ["positive", "negative", "neutral"].reduce((a, b) => votes[a] >= votes[b] ? a : b);
|
|
3967
|
-
const gv = {
|
|
3968
|
-
id: fnv1a3(tendency + ":__global__"),
|
|
3969
|
-
tendency,
|
|
3970
|
-
description: group[0].description,
|
|
3971
|
-
strength: group.reduce((s, r) => s + r.strength, 0) / group.length,
|
|
3972
|
-
stability: Math.max(...group.map((r) => r.stability)),
|
|
3973
|
-
valence,
|
|
3974
|
-
sourceSamskaras: [...new Set(allSrc)],
|
|
3975
|
-
reinforcementCount: group.reduce((s, r) => s + r.activation_count, 0),
|
|
3976
|
-
lastActivated: now,
|
|
3977
|
-
predictiveAccuracy: Math.max(...group.map((r) => r.stability)),
|
|
3978
|
-
project: "__global__",
|
|
3979
|
-
createdAt: now,
|
|
3980
|
-
updatedAt: now
|
|
3981
|
-
};
|
|
3982
|
-
this.saveVasana(gv);
|
|
3983
|
-
res.promoted.push(gv);
|
|
3984
|
-
res.projectSources[tendency] = [...projects];
|
|
3985
|
-
}
|
|
3986
|
-
return res;
|
|
3987
|
-
}
|
|
3988
|
-
/** Exponential decay: strength *= exp(-ln2 * elapsed / halfLife). Deletes below 0.01. */
|
|
3989
|
-
decay(halfLifeMs) {
|
|
3990
|
-
const hl = halfLifeMs ?? this.cfg.decayHalfLifeMs;
|
|
3991
|
-
const now = Date.now();
|
|
3992
|
-
const db = DatabaseManager.instance().get("agent");
|
|
3993
|
-
const rows = db.prepare(`SELECT id, strength, last_activated FROM vasanas`).all();
|
|
3994
|
-
let deleted = 0;
|
|
3995
|
-
for (const r of rows) {
|
|
3996
|
-
const elapsed = now - (r.last_activated ?? now);
|
|
3997
|
-
if (elapsed <= 0) continue;
|
|
3998
|
-
const s = r.strength * Math.exp(-Math.LN2 * elapsed / hl);
|
|
3999
|
-
if (s < 0.01) {
|
|
4000
|
-
db.prepare(`DELETE FROM vasanas WHERE id=?`).run(r.id);
|
|
4001
|
-
deleted++;
|
|
4002
|
-
} else db.prepare(`UPDATE vasanas SET strength=?,updated_at=? WHERE id=?`).run(s, now, r.id);
|
|
4003
|
-
}
|
|
4004
|
-
return deleted;
|
|
4005
|
-
}
|
|
4006
|
-
/** Persist BOCPD state (run-length distributions + observations) to SQLite. */
|
|
4007
|
-
persist() {
|
|
4008
|
-
const json = JSON.stringify({
|
|
4009
|
-
features: Object.fromEntries(this.states),
|
|
4010
|
-
observations: Object.fromEntries(this.obs)
|
|
4011
|
-
});
|
|
4012
|
-
DatabaseManager.instance().get("agent").prepare(
|
|
4013
|
-
`INSERT OR REPLACE INTO consolidation_rules
|
|
4014
|
-
(id, category, rule_text, confidence, source_sessions, created_at, updated_at, hit_count, project)
|
|
4015
|
-
VALUES ((SELECT id FROM consolidation_rules WHERE category='bocpd_state' AND project='__vasana_engine__'),
|
|
4016
|
-
'bocpd_state',?,1.0,NULL,?,?,1,'__vasana_engine__')`
|
|
4017
|
-
).run(json, Date.now(), Date.now());
|
|
4018
|
-
}
|
|
4019
|
-
/** Restore BOCPD state from SQLite. No-op if nothing persisted. */
|
|
4020
|
-
restore() {
|
|
4021
|
-
const row = DatabaseManager.instance().get("agent").prepare(
|
|
4022
|
-
`SELECT rule_text FROM consolidation_rules
|
|
4023
|
-
WHERE category='bocpd_state' AND project='__vasana_engine__' LIMIT 1`
|
|
4024
|
-
).get();
|
|
4025
|
-
if (!row) return;
|
|
4026
|
-
try {
|
|
4027
|
-
const s = JSON.parse(row.rule_text);
|
|
4028
|
-
this.states = new Map(Object.entries(s.features));
|
|
4029
|
-
this.obs = new Map(Object.entries(s.observations).map(([k, v]) => [k, Array.isArray(v) ? v : []]));
|
|
4030
|
-
} catch (err) {
|
|
4031
|
-
process.stderr.write(`[vasana-engine] restore() failed to parse BOCPD state: ${err instanceof Error ? err.message : err}
|
|
4032
|
-
`);
|
|
4033
|
-
this.states.clear();
|
|
4034
|
-
this.obs.clear();
|
|
4035
|
-
}
|
|
4036
|
-
}
|
|
4037
|
-
// ── BOCPD Core (Adams & MacKay 2007) ─────────────────────────────────
|
|
4038
|
-
initState() {
|
|
4039
|
-
return {
|
|
4040
|
-
logR: [0],
|
|
4041
|
-
// P(r=0) = 1
|
|
4042
|
-
stats: [{
|
|
4043
|
-
mu: this.cfg.priorMu,
|
|
4044
|
-
kappa: this.cfg.priorKappa,
|
|
4045
|
-
alpha: this.cfg.priorAlpha,
|
|
4046
|
-
beta: this.cfg.priorAlpha
|
|
4047
|
-
}],
|
|
4048
|
-
stableCount: 0,
|
|
4049
|
-
totalObs: 0,
|
|
4050
|
-
recentCpProbs: []
|
|
4051
|
-
};
|
|
4052
|
-
}
|
|
4053
|
-
/**
|
|
4054
|
-
* Online BOCPD update for one observation on one feature dimension.
|
|
4055
|
-
*
|
|
4056
|
-
* 1. Predictive P(x_t | r) via Student-t with Normal-Gamma sufficient stats
|
|
4057
|
-
* 2. Growth: P(r_t=r+1) = P(x|r) * P(r) * (1-H)
|
|
4058
|
-
* 3. Change-point: P(r_t=0) = sum_r P(x|r) * P(r) * H
|
|
4059
|
-
* 4. Normalize, update sufficient stats, prune low-probability tails
|
|
4060
|
-
*/
|
|
4061
|
-
updateBOCPD(feat, x) {
|
|
4062
|
-
const st = this.states.get(feat);
|
|
4063
|
-
const logH = -Math.log(this.cfg.lambda);
|
|
4064
|
-
const log1H = Math.log(1 - 1 / this.cfg.lambda);
|
|
4065
|
-
const n = st.logR.length;
|
|
4066
|
-
const lpp = new Array(n);
|
|
4067
|
-
for (let r = 0; r < n; r++) {
|
|
4068
|
-
const s = st.stats[r];
|
|
4069
|
-
lpp[r] = logStudentT(x, 2 * s.alpha, s.mu, Math.sqrt(s.beta * (s.kappa + 1) / (s.alpha * s.kappa)));
|
|
4070
|
-
}
|
|
4071
|
-
const cpTerms = new Array(n);
|
|
4072
|
-
const newLR = new Array(n + 1);
|
|
4073
|
-
for (let r = 0; r < n; r++) {
|
|
4074
|
-
newLR[r + 1] = lpp[r] + st.logR[r] + log1H;
|
|
4075
|
-
cpTerms[r] = lpp[r] + st.logR[r] + logH;
|
|
4076
|
-
}
|
|
4077
|
-
newLR[0] = logsumexp2(cpTerms);
|
|
4078
|
-
const logZ = logsumexp2(newLR);
|
|
4079
|
-
for (let i = 0; i <= n; i++) newLR[i] -= logZ;
|
|
4080
|
-
const newS = new Array(n + 1);
|
|
4081
|
-
newS[0] = {
|
|
4082
|
-
mu: this.cfg.priorMu,
|
|
4083
|
-
kappa: this.cfg.priorKappa,
|
|
4084
|
-
alpha: this.cfg.priorAlpha,
|
|
4085
|
-
beta: this.cfg.priorAlpha
|
|
4086
|
-
};
|
|
4087
|
-
for (let r = 0; r < n; r++) {
|
|
4088
|
-
const p = st.stats[r];
|
|
4089
|
-
const k = p.kappa + 1;
|
|
4090
|
-
const dx = x - p.mu;
|
|
4091
|
-
newS[r + 1] = {
|
|
4092
|
-
mu: (p.kappa * p.mu + x) / k,
|
|
4093
|
-
kappa: k,
|
|
4094
|
-
alpha: p.alpha + 0.5,
|
|
4095
|
-
beta: p.beta + 0.5 * p.kappa * dx * dx / k
|
|
4096
|
-
};
|
|
4097
|
-
}
|
|
4098
|
-
if (newLR.length > this.cfg.maxRunLength) {
|
|
4099
|
-
const idx = newLR.map((lp, i) => ({ lp, i })).sort((a, b) => b.lp - a.lp);
|
|
4100
|
-
const keep = new Set(idx.slice(0, this.cfg.maxRunLength).map((e) => e.i));
|
|
4101
|
-
const pR = [], pS = [];
|
|
4102
|
-
for (let i = 0; i <= n; i++) if (keep.has(i)) {
|
|
4103
|
-
pR.push(newLR[i]);
|
|
4104
|
-
pS.push(newS[i]);
|
|
4105
|
-
}
|
|
4106
|
-
const norm = logsumexp2(pR);
|
|
4107
|
-
for (let i = 0; i < pR.length; i++) pR[i] -= norm;
|
|
4108
|
-
st.logR = pR;
|
|
4109
|
-
st.stats = pS;
|
|
4110
|
-
} else {
|
|
4111
|
-
st.logR = newLR;
|
|
4112
|
-
st.stats = newS;
|
|
4113
|
-
}
|
|
4114
|
-
st.totalObs++;
|
|
4115
|
-
const cpProb = st.logR.length > 0 ? Math.exp(st.logR[0]) : 0;
|
|
4116
|
-
if (!st.recentCpProbs) st.recentCpProbs = [];
|
|
4117
|
-
st.recentCpProbs.push(cpProb);
|
|
4118
|
-
if (st.recentCpProbs.length > this.cfg.anomalyRevertWindow) {
|
|
4119
|
-
st.recentCpProbs.shift();
|
|
4120
|
-
}
|
|
4121
|
-
}
|
|
4122
|
-
/**
|
|
4123
|
-
* Classify a deviation as change-point, anomaly, or stable.
|
|
4124
|
-
*
|
|
4125
|
-
* Joint anomaly/change-point discrimination (arxiv 2508.06385):
|
|
4126
|
-
* - If P(r=0) > threshold and persists across the revert window → change-point
|
|
4127
|
-
* - If P(r=0) > threshold but reverts within the window → anomaly (one-off)
|
|
4128
|
-
* - Otherwise → stable
|
|
4129
|
-
*/
|
|
4130
|
-
classifyDeviation(st) {
|
|
4131
|
-
if (st.logR.length === 0) return "stable";
|
|
4132
|
-
const cpProb = Math.exp(st.logR[0]);
|
|
4133
|
-
if (cpProb <= this.cfg.changePointThreshold) return "stable";
|
|
4134
|
-
const recent = st.recentCpProbs ?? [cpProb];
|
|
4135
|
-
const exceedCount = recent.filter((p) => p > this.cfg.changePointThreshold).length;
|
|
4136
|
-
const ratio = exceedCount / Math.max(1, recent.length);
|
|
4137
|
-
if (recent.length >= this.cfg.anomalyRevertWindow && ratio >= this.cfg.anomalyConfirmRatio) {
|
|
4138
|
-
return "change-point";
|
|
4139
|
-
}
|
|
4140
|
-
return "anomaly";
|
|
4141
|
-
}
|
|
4142
|
-
isChangePoint(st) {
|
|
4143
|
-
return this.classifyDeviation(st) === "change-point";
|
|
4144
|
-
}
|
|
4145
|
-
stabilityScore(st) {
|
|
4146
|
-
if (st.logR.length === 0) return 0;
|
|
4147
|
-
return Math.max(0, Math.min(1, 1 - Math.exp(st.logR[0])));
|
|
4148
|
-
}
|
|
4149
|
-
// ── Feature Extraction & Validation ──────────────────────────────────
|
|
4150
|
-
extractFeatures(s) {
|
|
4151
|
-
const f = /* @__PURE__ */ new Map();
|
|
4152
|
-
const tMap = {
|
|
4153
|
-
"tool-sequence": 0.2,
|
|
4154
|
-
preference: 0.4,
|
|
4155
|
-
decision: 0.6,
|
|
4156
|
-
correction: 0.8,
|
|
4157
|
-
convention: 1
|
|
4158
|
-
};
|
|
4159
|
-
f.set(`type:${s.patternType}`, tMap[s.patternType] ?? 0.5);
|
|
4160
|
-
f.set("confidence", s.confidence);
|
|
4161
|
-
f.set("log_obs", Math.min(1, Math.log(1 + s.observationCount) / Math.log(101)));
|
|
4162
|
-
const ch = parseInt(fnv1a3(s.patternContent), 16);
|
|
4163
|
-
f.set(`cluster:${s.patternType}:${fnv1a3(s.patternContent)}`, ch / 4294967295);
|
|
4164
|
-
return f;
|
|
4165
|
-
}
|
|
4166
|
-
/** 70/30 holdout: fraction of test points within 1.5 sigma of train mean. */
|
|
4167
|
-
holdoutValidation(obs) {
|
|
4168
|
-
if (obs.length < 4) return 0;
|
|
4169
|
-
const si = Math.floor(obs.length * this.cfg.holdoutTrainRatio);
|
|
4170
|
-
const train = obs.slice(0, si), test = obs.slice(si);
|
|
4171
|
-
if (!train.length || !test.length) return 0;
|
|
4172
|
-
const mu = train.reduce((a, b) => a + b, 0) / train.length;
|
|
4173
|
-
const std = Math.sqrt(train.reduce((a, v) => a + (v - mu) ** 2, 0) / train.length + 1e-10);
|
|
4174
|
-
let ok = 0;
|
|
4175
|
-
for (const v of test) if (Math.abs(v - mu) <= 1.5 * std) ok++;
|
|
4176
|
-
return ok / test.length;
|
|
4177
|
-
}
|
|
4178
|
-
assignValence(rows) {
|
|
4179
|
-
let pos = 0, neg = 0;
|
|
4180
|
-
for (const r of rows) {
|
|
4181
|
-
if (r.pattern_type === "correction") neg += r.confidence;
|
|
4182
|
-
else if (r.pattern_type !== "tool-sequence" || r.confidence > 0.6)
|
|
4183
|
-
pos += r.confidence * (r.pattern_type === "tool-sequence" ? 0.5 : 1);
|
|
4184
|
-
}
|
|
4185
|
-
const tot = pos + neg;
|
|
4186
|
-
if (tot < 0.1) return "neutral";
|
|
4187
|
-
return pos / tot > 0.6 ? "positive" : neg / tot > 0.6 ? "negative" : "neutral";
|
|
4188
|
-
}
|
|
4189
|
-
clusterSamskaras(rows) {
|
|
4190
|
-
const m = /* @__PURE__ */ new Map();
|
|
4191
|
-
for (const r of rows) {
|
|
4192
|
-
const k = `${r.pattern_type}:${fnv1a3(r.pattern_content.toLowerCase().trim().replace(/\s+/g, " "))}`;
|
|
4193
|
-
const s = m.get(k) ?? /* @__PURE__ */ new Set();
|
|
4194
|
-
s.add(r.id);
|
|
4195
|
-
m.set(k, s);
|
|
4196
|
-
}
|
|
4197
|
-
return m;
|
|
4198
|
-
}
|
|
4199
|
-
// ── SQLite Helpers ───────────────────────────────────────────────────
|
|
4200
|
-
// Schema mapping: Vasana.tendency→name, sourceSamskaras→source_samskaras(JSON),
|
|
4201
|
-
// reinforcementCount→activation_count, lastActivated→last_activated
|
|
4202
|
-
saveVasana(v) {
|
|
4203
|
-
const db = DatabaseManager.instance().get("agent");
|
|
4204
|
-
const existing = db.prepare(
|
|
4205
|
-
`SELECT id FROM vasanas WHERE name=? AND (project=? OR (project IS NULL AND ?='__global__'))`
|
|
4206
|
-
).get(v.tendency, v.project, v.project);
|
|
4207
|
-
if (existing) {
|
|
4208
|
-
db.prepare(
|
|
4209
|
-
`UPDATE vasanas SET description=?,valence=?,strength=?,stability=?,
|
|
4210
|
-
source_samskaras=?,updated_at=?,last_activated=?,activation_count=? WHERE id=?`
|
|
4211
|
-
).run(
|
|
4212
|
-
v.description,
|
|
4213
|
-
v.valence,
|
|
4214
|
-
v.strength,
|
|
4215
|
-
v.stability,
|
|
4216
|
-
JSON.stringify(v.sourceSamskaras),
|
|
4217
|
-
v.updatedAt,
|
|
4218
|
-
v.lastActivated,
|
|
4219
|
-
v.reinforcementCount,
|
|
4220
|
-
existing.id
|
|
4221
|
-
);
|
|
4222
|
-
} else {
|
|
4223
|
-
db.prepare(
|
|
4224
|
-
`INSERT INTO vasanas (name,description,valence,strength,stability,source_samskaras,
|
|
4225
|
-
project,created_at,updated_at,last_activated,activation_count) VALUES (?,?,?,?,?,?,?,?,?,?,?)`
|
|
4226
|
-
).run(
|
|
4227
|
-
v.tendency,
|
|
4228
|
-
v.description,
|
|
4229
|
-
v.valence,
|
|
4230
|
-
v.strength,
|
|
4231
|
-
v.stability,
|
|
4232
|
-
JSON.stringify(v.sourceSamskaras),
|
|
4233
|
-
v.project === "__global__" ? null : v.project,
|
|
4234
|
-
v.createdAt,
|
|
4235
|
-
v.updatedAt,
|
|
4236
|
-
v.lastActivated,
|
|
4237
|
-
v.reinforcementCount
|
|
4238
|
-
);
|
|
4239
|
-
}
|
|
4240
|
-
this.cache.set(v.id, v);
|
|
4241
|
-
}
|
|
4242
|
-
loadVasana(vid) {
|
|
4243
|
-
if (this.cache.has(vid)) return this.cache.get(vid);
|
|
4244
|
-
const rows = DatabaseManager.instance().get("agent").prepare(
|
|
4245
|
-
`SELECT id,name,description,valence,strength,stability,source_samskaras,
|
|
4246
|
-
project,created_at,updated_at,last_activated,activation_count FROM vasanas`
|
|
4247
|
-
).all();
|
|
4248
|
-
for (const r of rows) {
|
|
4249
|
-
const v = this.toVasana(r);
|
|
4250
|
-
this.cache.set(v.id, v);
|
|
4251
|
-
}
|
|
4252
|
-
return this.cache.get(vid) ?? null;
|
|
4253
|
-
}
|
|
4254
|
-
toVasana(r) {
|
|
4255
|
-
const proj = r.project ?? "__global__";
|
|
4256
|
-
return {
|
|
4257
|
-
id: fnv1a3(r.name + ":" + proj),
|
|
4258
|
-
tendency: r.name,
|
|
4259
|
-
description: r.description,
|
|
4260
|
-
strength: r.strength,
|
|
4261
|
-
stability: r.stability,
|
|
4262
|
-
valence: r.valence,
|
|
4263
|
-
sourceSamskaras: jsonArr(r.source_samskaras),
|
|
4264
|
-
reinforcementCount: r.activation_count,
|
|
4265
|
-
lastActivated: r.last_activated ?? r.updated_at,
|
|
4266
|
-
predictiveAccuracy: r.stability,
|
|
4267
|
-
project: proj,
|
|
4268
|
-
createdAt: r.created_at,
|
|
4269
|
-
updatedAt: r.updated_at
|
|
4270
|
-
};
|
|
4271
|
-
}
|
|
4272
|
-
};
|
|
4273
|
-
function jsonArr(s) {
|
|
4274
|
-
if (!s) return [];
|
|
4275
|
-
try {
|
|
4276
|
-
const p = JSON.parse(s);
|
|
4277
|
-
return Array.isArray(p) ? p : [];
|
|
4278
|
-
} catch {
|
|
4279
|
-
return [];
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4282
|
-
|
|
4283
|
-
// ../chitragupta/packages/smriti/src/svapna-consolidation.ts
|
|
4284
|
-
var FNV_OFFSET3 = 2166136261;
|
|
4285
|
-
var FNV_PRIME3 = 16777619;
|
|
4286
|
-
function fnv1a4(input) {
|
|
4287
|
-
let hash = FNV_OFFSET3;
|
|
4288
|
-
for (let i = 0; i < input.length; i++) {
|
|
4289
|
-
hash ^= input.charCodeAt(i);
|
|
4290
|
-
hash = Math.imul(hash, FNV_PRIME3) >>> 0;
|
|
4291
|
-
}
|
|
4292
|
-
return hash.toString(16).padStart(8, "0");
|
|
4293
|
-
}
|
|
4294
|
-
var DEFAULT_CONFIG5 = {
|
|
4295
4095
|
maxSessionsPerCycle: 50,
|
|
4296
4096
|
surpriseThreshold: 0.7,
|
|
4297
4097
|
minPatternFrequency: 3,
|
|
@@ -4317,10 +4117,10 @@ function buildToolFingerprint(toolNames2) {
|
|
|
4317
4117
|
const fingerprint = /* @__PURE__ */ new Set();
|
|
4318
4118
|
if (toolNames2.length === 0) return fingerprint;
|
|
4319
4119
|
for (const name of toolNames2) {
|
|
4320
|
-
fingerprint.add(
|
|
4120
|
+
fingerprint.add(fnv1a3(`u:${name}`));
|
|
4321
4121
|
}
|
|
4322
4122
|
for (let i = 0; i < toolNames2.length - 1; i++) {
|
|
4323
|
-
fingerprint.add(
|
|
4123
|
+
fingerprint.add(fnv1a3(`b:${toolNames2[i]}:${toolNames2[i + 1]}`));
|
|
4324
4124
|
}
|
|
4325
4125
|
return fingerprint;
|
|
4326
4126
|
}
|
|
@@ -4412,7 +4212,7 @@ var SvapnaConsolidation = class {
|
|
|
4412
4212
|
* @param db - Optional DatabaseManager instance (uses singleton if omitted).
|
|
4413
4213
|
*/
|
|
4414
4214
|
constructor(config, db) {
|
|
4415
|
-
this.config = { ...
|
|
4215
|
+
this.config = { ...DEFAULT_CONFIG4, ...config };
|
|
4416
4216
|
this.db = db ?? DatabaseManager.instance();
|
|
4417
4217
|
this.cycleId = `svapna-${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
4418
4218
|
}
|
|
@@ -4737,7 +4537,7 @@ var SvapnaConsolidation = class {
|
|
|
4737
4537
|
for (const cluster of clusters) {
|
|
4738
4538
|
if (cluster.sessionIds.size < 2) continue;
|
|
4739
4539
|
const tendency = this.slugify(cluster.representative);
|
|
4740
|
-
const vasanaId =
|
|
4540
|
+
const vasanaId = fnv1a3(`${tendency}:${this.config.project}`);
|
|
4741
4541
|
const existing = agentDb.prepare("SELECT id, strength, activation_count FROM vasanas WHERE name = ? AND (project = ? OR project IS NULL)").get(tendency, this.config.project);
|
|
4742
4542
|
if (existing) {
|
|
4743
4543
|
const newStrength = Math.min(1, existing.strength + 0.1);
|
|
@@ -4916,7 +4716,7 @@ var SvapnaConsolidation = class {
|
|
|
4916
4716
|
});
|
|
4917
4717
|
}
|
|
4918
4718
|
const vidhiName = this.slugify(ngramKey.replace(/ -> /g, "-then-"));
|
|
4919
|
-
const vidhiId =
|
|
4719
|
+
const vidhiId = fnv1a3(`${vidhiName}:${this.config.project}`);
|
|
4920
4720
|
const existing = agentDb.prepare("SELECT id FROM vidhis WHERE id = ?").get(vidhiId);
|
|
4921
4721
|
if (existing) continue;
|
|
4922
4722
|
const vidhi = {
|
|
@@ -5221,8 +5021,8 @@ var SvapnaConsolidation = class {
|
|
|
5221
5021
|
};
|
|
5222
5022
|
|
|
5223
5023
|
// ../chitragupta/packages/smriti/src/vidhi-engine.ts
|
|
5224
|
-
var
|
|
5225
|
-
var
|
|
5024
|
+
var FNV_OFFSET3 = 2166136261;
|
|
5025
|
+
var FNV_PRIME3 = 16777619;
|
|
5226
5026
|
var ACTION_VERBS = /* @__PURE__ */ new Set([
|
|
5227
5027
|
"add",
|
|
5228
5028
|
"create",
|
|
@@ -5288,24 +5088,24 @@ var ACTION_VERBS = /* @__PURE__ */ new Set([
|
|
|
5288
5088
|
"scaffold",
|
|
5289
5089
|
"bootstrap"
|
|
5290
5090
|
]);
|
|
5291
|
-
var
|
|
5091
|
+
var DEFAULT_CONFIG5 = {
|
|
5292
5092
|
minSessions: 3,
|
|
5293
5093
|
minSuccessRate: 0.8,
|
|
5294
5094
|
minSequenceLength: 2,
|
|
5295
5095
|
maxSequenceLength: 5
|
|
5296
5096
|
};
|
|
5297
|
-
function
|
|
5298
|
-
let hash =
|
|
5097
|
+
function fnv1a4(str) {
|
|
5098
|
+
let hash = FNV_OFFSET3;
|
|
5299
5099
|
for (let i = 0; i < str.length; i++) {
|
|
5300
5100
|
hash ^= str.charCodeAt(i);
|
|
5301
|
-
hash = hash *
|
|
5101
|
+
hash = hash * FNV_PRIME3 >>> 0;
|
|
5302
5102
|
}
|
|
5303
5103
|
return hash.toString(16).padStart(8, "0");
|
|
5304
5104
|
}
|
|
5305
5105
|
var VidhiEngine = class {
|
|
5306
5106
|
_config;
|
|
5307
5107
|
constructor(config) {
|
|
5308
|
-
this._config = { ...
|
|
5108
|
+
this._config = { ...DEFAULT_CONFIG5, ...config };
|
|
5309
5109
|
}
|
|
5310
5110
|
// ─── Public API ───────────────────────────────────────────────────
|
|
5311
5111
|
/**
|
|
@@ -5598,7 +5398,7 @@ var VidhiEngine = class {
|
|
|
5598
5398
|
_buildVidhi(agg) {
|
|
5599
5399
|
const now = Date.now();
|
|
5600
5400
|
const name = this._generateName(agg.toolNames);
|
|
5601
|
-
const id =
|
|
5401
|
+
const id = fnv1a4(name + "|" + this._config.project);
|
|
5602
5402
|
const parameterSchema = {};
|
|
5603
5403
|
const steps = [];
|
|
5604
5404
|
for (let stepIdx = 0; stepIdx < agg.toolNames.length; stepIdx++) {
|
|
@@ -6056,13 +5856,13 @@ var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
|
6056
5856
|
"over",
|
|
6057
5857
|
"after"
|
|
6058
5858
|
]);
|
|
6059
|
-
var
|
|
6060
|
-
var
|
|
6061
|
-
function
|
|
6062
|
-
let hash =
|
|
5859
|
+
var FNV_OFFSET4 = 2166136261;
|
|
5860
|
+
var FNV_PRIME4 = 16777619;
|
|
5861
|
+
function fnv1a5(input) {
|
|
5862
|
+
let hash = FNV_OFFSET4;
|
|
6063
5863
|
for (let i = 0; i < input.length; i++) {
|
|
6064
5864
|
hash ^= input.charCodeAt(i);
|
|
6065
|
-
hash = Math.imul(hash,
|
|
5865
|
+
hash = Math.imul(hash, FNV_PRIME4) >>> 0;
|
|
6066
5866
|
}
|
|
6067
5867
|
return hash.toString(16).padStart(8, "0");
|
|
6068
5868
|
}
|
|
@@ -6079,7 +5879,7 @@ function jaccardSimilarity2(a, b) {
|
|
|
6079
5879
|
return union === 0 ? 0 : intersection / union;
|
|
6080
5880
|
}
|
|
6081
5881
|
var DAY_MS = 864e5;
|
|
6082
|
-
var
|
|
5882
|
+
var DEFAULT_CONFIG6 = {
|
|
6083
5883
|
decayHalfLife: 7 * DAY_MS,
|
|
6084
5884
|
// 7 days
|
|
6085
5885
|
minStrength: 0.01,
|
|
@@ -6091,7 +5891,7 @@ var DEFAULT_CONFIG7 = {
|
|
|
6091
5891
|
diminishingAlpha: 0.3,
|
|
6092
5892
|
frequencyDecayBeta: 0.5
|
|
6093
5893
|
};
|
|
6094
|
-
var
|
|
5894
|
+
var HARD_CEILINGS = {
|
|
6095
5895
|
maxTraces: 5e4,
|
|
6096
5896
|
minDecayHalfLife: 36e5,
|
|
6097
5897
|
// 1 hour minimum
|
|
@@ -6105,16 +5905,16 @@ var AkashaField = class {
|
|
|
6105
5905
|
reinforcedBy = /* @__PURE__ */ new Map();
|
|
6106
5906
|
constructor(config) {
|
|
6107
5907
|
this.config = {
|
|
6108
|
-
...
|
|
5908
|
+
...DEFAULT_CONFIG6,
|
|
6109
5909
|
...config,
|
|
6110
5910
|
// Clamp to hard ceilings
|
|
6111
5911
|
maxTraces: Math.min(
|
|
6112
|
-
config?.maxTraces ??
|
|
6113
|
-
|
|
5912
|
+
config?.maxTraces ?? DEFAULT_CONFIG6.maxTraces,
|
|
5913
|
+
HARD_CEILINGS.maxTraces
|
|
6114
5914
|
),
|
|
6115
5915
|
decayHalfLife: Math.max(
|
|
6116
|
-
config?.decayHalfLife ??
|
|
6117
|
-
|
|
5916
|
+
config?.decayHalfLife ?? DEFAULT_CONFIG6.decayHalfLife,
|
|
5917
|
+
HARD_CEILINGS.minDecayHalfLife
|
|
6118
5918
|
)
|
|
6119
5919
|
};
|
|
6120
5920
|
}
|
|
@@ -6134,8 +5934,8 @@ var AkashaField = class {
|
|
|
6134
5934
|
* @returns The created StigmergicTrace.
|
|
6135
5935
|
*/
|
|
6136
5936
|
leave(agentId, type, topic, content, metadata) {
|
|
6137
|
-
const truncatedContent = content.length >
|
|
6138
|
-
const id = `aks-${
|
|
5937
|
+
const truncatedContent = content.length > HARD_CEILINGS.maxContentSize ? content.slice(0, HARD_CEILINGS.maxContentSize) : content;
|
|
5938
|
+
const id = `aks-${fnv1a5(agentId + ":" + type + ":" + topic + ":" + truncatedContent)}`;
|
|
6139
5939
|
const now = Date.now();
|
|
6140
5940
|
const trace = {
|
|
6141
5941
|
id,
|
|
@@ -6589,7 +6389,7 @@ var DEFAULT_SCALE_WEIGHTS = {
|
|
|
6589
6389
|
quarter: 0.08,
|
|
6590
6390
|
year: 0.07
|
|
6591
6391
|
};
|
|
6592
|
-
var
|
|
6392
|
+
var HARD_CEILINGS2 = {
|
|
6593
6393
|
/** Minimum half-life: 1 second. Anything faster is meaningless. */
|
|
6594
6394
|
minDecayRate: 1e3,
|
|
6595
6395
|
/** Maximum half-life: 10 years. Beyond this, nothing decays. */
|
|
@@ -6636,8 +6436,8 @@ var KalaChakra = class {
|
|
|
6636
6436
|
if (config.decayRates[scale] !== void 0) {
|
|
6637
6437
|
this._decayRates[scale] = clamp(
|
|
6638
6438
|
config.decayRates[scale],
|
|
6639
|
-
|
|
6640
|
-
|
|
6439
|
+
HARD_CEILINGS2.minDecayRate,
|
|
6440
|
+
HARD_CEILINGS2.maxDecayRate
|
|
6641
6441
|
);
|
|
6642
6442
|
}
|
|
6643
6443
|
}
|
|
@@ -6647,8 +6447,8 @@ var KalaChakra = class {
|
|
|
6647
6447
|
if (config.scaleWeights[scale] !== void 0) {
|
|
6648
6448
|
this._scaleWeights[scale] = clamp(
|
|
6649
6449
|
config.scaleWeights[scale],
|
|
6650
|
-
|
|
6651
|
-
|
|
6450
|
+
HARD_CEILINGS2.minWeight,
|
|
6451
|
+
HARD_CEILINGS2.maxWeight
|
|
6652
6452
|
);
|
|
6653
6453
|
}
|
|
6654
6454
|
}
|
|
@@ -6890,8 +6690,8 @@ var KalaChakra = class {
|
|
|
6890
6690
|
if (typeof data.decayRates[scale] === "number") {
|
|
6891
6691
|
this._decayRates[scale] = clamp(
|
|
6892
6692
|
data.decayRates[scale],
|
|
6893
|
-
|
|
6894
|
-
|
|
6693
|
+
HARD_CEILINGS2.minDecayRate,
|
|
6694
|
+
HARD_CEILINGS2.maxDecayRate
|
|
6895
6695
|
);
|
|
6896
6696
|
}
|
|
6897
6697
|
}
|
|
@@ -6901,8 +6701,8 @@ var KalaChakra = class {
|
|
|
6901
6701
|
if (typeof data.scaleWeights[scale] === "number") {
|
|
6902
6702
|
this._scaleWeights[scale] = clamp(
|
|
6903
6703
|
data.scaleWeights[scale],
|
|
6904
|
-
|
|
6905
|
-
|
|
6704
|
+
HARD_CEILINGS2.minWeight,
|
|
6705
|
+
HARD_CEILINGS2.maxWeight
|
|
6906
6706
|
);
|
|
6907
6707
|
}
|
|
6908
6708
|
}
|
|
@@ -6943,13 +6743,13 @@ function mondayOfISOWeek(isoYear, isoWeekNum) {
|
|
|
6943
6743
|
}
|
|
6944
6744
|
|
|
6945
6745
|
// ../chitragupta/packages/smriti/src/pancha-vritti.ts
|
|
6946
|
-
var
|
|
6947
|
-
var
|
|
6948
|
-
function
|
|
6949
|
-
let hash =
|
|
6746
|
+
var FNV_OFFSET5 = 2166136261;
|
|
6747
|
+
var FNV_PRIME5 = 16777619;
|
|
6748
|
+
function fnv1a6(input) {
|
|
6749
|
+
let hash = FNV_OFFSET5;
|
|
6950
6750
|
for (let i = 0; i < input.length; i++) {
|
|
6951
6751
|
hash ^= input.charCodeAt(i);
|
|
6952
|
-
hash = Math.imul(hash,
|
|
6752
|
+
hash = Math.imul(hash, FNV_PRIME5);
|
|
6953
6753
|
}
|
|
6954
6754
|
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
6955
6755
|
}
|
|
@@ -6967,13 +6767,13 @@ var VRITTI_CONFIDENCE_WEIGHTS = {
|
|
|
6967
6767
|
vikalpa: 0.5,
|
|
6968
6768
|
viparyaya: 0.3
|
|
6969
6769
|
};
|
|
6970
|
-
var
|
|
6770
|
+
var DEFAULT_CONFIG7 = {
|
|
6971
6771
|
maxClassifications: 5e3,
|
|
6972
6772
|
minConfidence: 0.4,
|
|
6973
6773
|
snippetMaxLength: 200,
|
|
6974
6774
|
confidenceWeights: { ...VRITTI_CONFIDENCE_WEIGHTS }
|
|
6975
6775
|
};
|
|
6976
|
-
var
|
|
6776
|
+
var HARD_CEILINGS3 = {
|
|
6977
6777
|
maxClassifications: 5e4,
|
|
6978
6778
|
snippetMaxLength: 1e3
|
|
6979
6779
|
};
|
|
@@ -7101,23 +6901,23 @@ var PanchaVritti = class {
|
|
|
7101
6901
|
totalReclassified = 0;
|
|
7102
6902
|
constructor(config) {
|
|
7103
6903
|
const merged = {
|
|
7104
|
-
...
|
|
6904
|
+
...DEFAULT_CONFIG7,
|
|
7105
6905
|
...config,
|
|
7106
6906
|
confidenceWeights: {
|
|
7107
|
-
...
|
|
6907
|
+
...DEFAULT_CONFIG7.confidenceWeights,
|
|
7108
6908
|
...config?.confidenceWeights
|
|
7109
6909
|
}
|
|
7110
6910
|
};
|
|
7111
|
-
if (typeof
|
|
6911
|
+
if (typeof HARD_CEILINGS3.maxClassifications === "number") {
|
|
7112
6912
|
merged.maxClassifications = Math.min(
|
|
7113
6913
|
merged.maxClassifications,
|
|
7114
|
-
|
|
6914
|
+
HARD_CEILINGS3.maxClassifications
|
|
7115
6915
|
);
|
|
7116
6916
|
}
|
|
7117
|
-
if (typeof
|
|
6917
|
+
if (typeof HARD_CEILINGS3.snippetMaxLength === "number") {
|
|
7118
6918
|
merged.snippetMaxLength = Math.min(
|
|
7119
6919
|
merged.snippetMaxLength,
|
|
7120
|
-
|
|
6920
|
+
HARD_CEILINGS3.snippetMaxLength
|
|
7121
6921
|
);
|
|
7122
6922
|
}
|
|
7123
6923
|
this.cfg = merged;
|
|
@@ -7151,7 +6951,7 @@ var PanchaVritti = class {
|
|
|
7151
6951
|
prePatterns.push("context:error-flag");
|
|
7152
6952
|
}
|
|
7153
6953
|
if (content.trim().length === 0) {
|
|
7154
|
-
const id2 =
|
|
6954
|
+
const id2 = fnv1a6("nidra:" + now.toString());
|
|
7155
6955
|
const classification2 = {
|
|
7156
6956
|
id: id2,
|
|
7157
6957
|
type: "nidra",
|
|
@@ -7227,7 +7027,7 @@ var PanchaVritti = class {
|
|
|
7227
7027
|
if (winnerConfidence < this.cfg.minConfidence) {
|
|
7228
7028
|
winnerPatterns.push("low-confidence");
|
|
7229
7029
|
}
|
|
7230
|
-
const id =
|
|
7030
|
+
const id = fnv1a6(winnerType + ":" + content.slice(0, 100) + ":" + now.toString());
|
|
7231
7031
|
const classification = {
|
|
7232
7032
|
id,
|
|
7233
7033
|
type: winnerType,
|
|
@@ -7469,16 +7269,16 @@ async function recall(query, options) {
|
|
|
7469
7269
|
}
|
|
7470
7270
|
async function searchHybrid(query, project, limit) {
|
|
7471
7271
|
try {
|
|
7472
|
-
const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-
|
|
7272
|
+
const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-TX6T3KYH.js");
|
|
7473
7273
|
let recallEngine = null;
|
|
7474
7274
|
let graphEngine = null;
|
|
7475
7275
|
try {
|
|
7476
|
-
const { RecallEngine: RecallEngine2 } = await import("./recall-
|
|
7276
|
+
const { RecallEngine: RecallEngine2 } = await import("./recall-IUPQCBYP.js");
|
|
7477
7277
|
recallEngine = new RecallEngine2();
|
|
7478
7278
|
} catch {
|
|
7479
7279
|
}
|
|
7480
7280
|
try {
|
|
7481
|
-
const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-
|
|
7281
|
+
const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-LAZSXLLI.js");
|
|
7482
7282
|
graphEngine = new GraphRAGEngine2();
|
|
7483
7283
|
} catch {
|
|
7484
7284
|
}
|
|
@@ -7516,8 +7316,8 @@ async function searchHybrid(query, project, limit) {
|
|
|
7516
7316
|
}
|
|
7517
7317
|
async function searchTurns(query, project) {
|
|
7518
7318
|
try {
|
|
7519
|
-
const { searchSessions: searchSessions2 } = await import("./search-
|
|
7520
|
-
const { loadSession: loadSession2 } = await import("./session-store-
|
|
7319
|
+
const { searchSessions: searchSessions2 } = await import("./search-HHSVHBXC.js");
|
|
7320
|
+
const { loadSession: loadSession2 } = await import("./session-store-NDUDYAC7.js");
|
|
7521
7321
|
const metas = searchSessions2(query, project);
|
|
7522
7322
|
const results = [];
|
|
7523
7323
|
for (const meta of metas.slice(0, 10)) {
|
|
@@ -7563,7 +7363,7 @@ async function searchTurns(query, project) {
|
|
|
7563
7363
|
}
|
|
7564
7364
|
async function searchMemoryLayer(query) {
|
|
7565
7365
|
try {
|
|
7566
|
-
const { searchMemory: searchMemory2 } = await import("./search-
|
|
7366
|
+
const { searchMemory: searchMemory2 } = await import("./search-HHSVHBXC.js");
|
|
7567
7367
|
const results = searchMemory2(query);
|
|
7568
7368
|
return results.slice(0, 5).map((r) => ({
|
|
7569
7369
|
score: Math.min((r.relevance ?? 0.5) + 0.1, 1),
|
|
@@ -7577,7 +7377,7 @@ async function searchMemoryLayer(query) {
|
|
|
7577
7377
|
}
|
|
7578
7378
|
async function searchDayFileLayer(query, limit) {
|
|
7579
7379
|
try {
|
|
7580
|
-
const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-
|
|
7380
|
+
const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-ETXYYJZK.js");
|
|
7581
7381
|
const results = await hierarchicalTemporalSearch2(query, { limit });
|
|
7582
7382
|
if (results.length > 0) {
|
|
7583
7383
|
return results.map((r) => ({
|
|
@@ -7592,7 +7392,7 @@ async function searchDayFileLayer(query, limit) {
|
|
|
7592
7392
|
} catch {
|
|
7593
7393
|
}
|
|
7594
7394
|
try {
|
|
7595
|
-
const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-
|
|
7395
|
+
const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-U3X6P4ZG.js");
|
|
7596
7396
|
const results = searchDayFiles2(query, { limit });
|
|
7597
7397
|
return results.map((r) => ({
|
|
7598
7398
|
score: 0.5,
|
|
@@ -7623,7 +7423,7 @@ async function loadProviderContext(project, options) {
|
|
|
7623
7423
|
let projectMemory = "";
|
|
7624
7424
|
let recentContext = "";
|
|
7625
7425
|
try {
|
|
7626
|
-
const { getMemory: getMemory2 } = await import("./memory-store-
|
|
7426
|
+
const { getMemory: getMemory2 } = await import("./memory-store-A6WOWLWC.js");
|
|
7627
7427
|
globalFacts = getMemory2({ type: "global" });
|
|
7628
7428
|
if (globalFacts.length > maxLen / 3) {
|
|
7629
7429
|
globalFacts = globalFacts.slice(0, maxLen / 3) + "\n...(truncated)";
|
|
@@ -7632,7 +7432,7 @@ async function loadProviderContext(project, options) {
|
|
|
7632
7432
|
}
|
|
7633
7433
|
if (project) {
|
|
7634
7434
|
try {
|
|
7635
|
-
const { getMemory: getMemory2 } = await import("./memory-store-
|
|
7435
|
+
const { getMemory: getMemory2 } = await import("./memory-store-A6WOWLWC.js");
|
|
7636
7436
|
projectMemory = getMemory2({ type: "project", path: project });
|
|
7637
7437
|
if (projectMemory.length > maxLen / 3) {
|
|
7638
7438
|
projectMemory = projectMemory.slice(0, maxLen / 3) + "\n...(truncated)";
|
|
@@ -7640,8 +7440,20 @@ async function loadProviderContext(project, options) {
|
|
|
7640
7440
|
} catch {
|
|
7641
7441
|
}
|
|
7642
7442
|
}
|
|
7443
|
+
let vasanaContext = "";
|
|
7643
7444
|
try {
|
|
7644
|
-
const {
|
|
7445
|
+
const { VasanaEngine: VasanaEngine2 } = await import("./vasana-engine-G6BPOFX7.js");
|
|
7446
|
+
const engine = new VasanaEngine2();
|
|
7447
|
+
const vasanas = engine.getVasanas(project ?? "__global__", 5);
|
|
7448
|
+
if (vasanas.length > 0) {
|
|
7449
|
+
vasanaContext = vasanas.map(
|
|
7450
|
+
(v) => `- ${v.tendency} (strength: ${(v.strength * 100).toFixed(0)}%): ${v.description}`
|
|
7451
|
+
).join("\n");
|
|
7452
|
+
}
|
|
7453
|
+
} catch {
|
|
7454
|
+
}
|
|
7455
|
+
try {
|
|
7456
|
+
const { listSessions: listSessions2, loadSession: loadSession2 } = await import("./session-store-NDUDYAC7.js");
|
|
7645
7457
|
const sessions = project ? listSessions2(project).slice(0, recentLimit) : listSessions2().slice(0, recentLimit);
|
|
7646
7458
|
const summaries = [];
|
|
7647
7459
|
for (const meta of sessions) {
|
|
@@ -7675,6 +7487,10 @@ async function loadProviderContext(project, options) {
|
|
|
7675
7487
|
parts.push("## Recent Sessions\n" + recentContext.trim());
|
|
7676
7488
|
itemCount += recentContext.split("\n").filter((l) => l.trim()).length;
|
|
7677
7489
|
}
|
|
7490
|
+
if (vasanaContext.trim()) {
|
|
7491
|
+
parts.push("## Behavioral Patterns\n" + vasanaContext.trim());
|
|
7492
|
+
itemCount += vasanaContext.split("\n").filter((l) => l.trim()).length;
|
|
7493
|
+
}
|
|
7678
7494
|
const assembled = parts.join("\n\n");
|
|
7679
7495
|
return {
|
|
7680
7496
|
globalFacts: globalFacts.trim(),
|
|
@@ -7690,6 +7506,11 @@ export {
|
|
|
7690
7506
|
exportSessionToMarkdown,
|
|
7691
7507
|
importSessionFromJson,
|
|
7692
7508
|
detectExportFormat,
|
|
7509
|
+
createCrossMachineSnapshot,
|
|
7510
|
+
writeCrossMachineSnapshot,
|
|
7511
|
+
readCrossMachineSnapshot,
|
|
7512
|
+
getCrossMachineSyncStatus,
|
|
7513
|
+
importCrossMachineSnapshot,
|
|
7693
7514
|
branchSession,
|
|
7694
7515
|
getSessionTree,
|
|
7695
7516
|
sinkhornKnopp,
|
|
@@ -7713,7 +7534,6 @@ export {
|
|
|
7713
7534
|
detectMemoryIntent,
|
|
7714
7535
|
detectCategory,
|
|
7715
7536
|
IdentityContext,
|
|
7716
|
-
VasanaEngine,
|
|
7717
7537
|
SvapnaConsolidation,
|
|
7718
7538
|
VidhiEngine,
|
|
7719
7539
|
AkashaField,
|
|
@@ -7725,4 +7545,4 @@ export {
|
|
|
7725
7545
|
recall,
|
|
7726
7546
|
loadProviderContext
|
|
7727
7547
|
};
|
|
7728
|
-
//# sourceMappingURL=chunk-
|
|
7548
|
+
//# sourceMappingURL=chunk-YSC77CKZ.js.map
|