@yugenlab/vaayu 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/chunks/{agentic-tool-loop-2FZK72JO.js → agentic-tool-loop-O3NUV7KG.js} +1 -1
  2. package/chunks/{chunk-UZ6OIVEC.js → chunk-2OBLQJYJ.js} +1 -1
  3. package/chunks/{chunk-O4KV7TFP.js → chunk-3AYSJ7WB.js} +30 -18
  4. package/chunks/{chunk-U62ABYKD.js → chunk-67DXWEKG.js} +3 -3
  5. package/chunks/{chunk-6556EKOB.js → chunk-7AYYXHYZ.js} +25 -24
  6. package/chunks/{chunk-JGI4SDWS.js → chunk-7XV5ISV7.js} +7 -5
  7. package/chunks/{chunk-JAWZ7ANC.js → chunk-A3HOZBC5.js} +11 -7
  8. package/chunks/{chunk-VJHNE47S.js → chunk-D46QTN3G.js} +63 -82
  9. package/chunks/{chunk-PRXQW76U.js → chunk-EG37M4QL.js} +17 -6
  10. package/chunks/{chunk-77725AR7.js → chunk-F6RNEGFX.js} +82 -53
  11. package/chunks/{chunk-MJ74G5RB.js → chunk-G2QREGXK.js} +2 -2
  12. package/chunks/{chunk-AS3DJFY3.js → chunk-JZTFJE7M.js} +39 -39
  13. package/chunks/{chunk-OT4G2L46.js → chunk-LJUEMPLG.js} +202 -154
  14. package/chunks/{chunk-C76USAC5.js → chunk-QFGAB4XD.js} +13 -5
  15. package/chunks/{chunk-M7THR63C.js → chunk-QV4GPIPT.js} +74 -65
  16. package/chunks/{chunk-YJRXLRTE.js → chunk-V2ZIKDN4.js} +9 -8
  17. package/chunks/{chunk-AGK3A7R7.js → chunk-VCUJES75.js} +791 -677
  18. package/chunks/{chunk-N22M7D4P.js → chunk-W4PVGBUH.js} +86 -97
  19. package/chunks/{chunk-TND3MU4Z.js → chunk-Z576WVLG.js} +74 -66
  20. package/chunks/{chunk-HIYHTWFW.js → chunk-ZYY6N3SP.js} +90 -118
  21. package/chunks/{consolidation-indexer-VKQ6DNU3.js → consolidation-indexer-VIWOP6VO.js} +8 -8
  22. package/chunks/{day-consolidation-BH3QU2SZ.js → day-consolidation-HMHSXIOM.js} +4 -4
  23. package/chunks/{src-Y3TGMINC.js → dist-CY5NX2IK.js} +17 -17
  24. package/chunks/graphrag-T2QWNX57.js +14 -0
  25. package/chunks/{hierarchical-temporal-search-PVHVA3NZ.js → hierarchical-temporal-search-U6DG74IR.js} +2 -2
  26. package/chunks/hybrid-search-BYTXCOXP.js +20 -0
  27. package/chunks/{memory-store-A6WOWLWC.js → memory-store-LEERUQGL.js} +3 -3
  28. package/chunks/periodic-consolidation-D6SSKZ7H.js +11 -0
  29. package/chunks/{postgres-WLH3D5HG.js → postgres-7GZDDX77.js} +2 -2
  30. package/chunks/{recall-ZNL4DJ2L.js → recall-LNRQVATQ.js} +7 -7
  31. package/chunks/search-BIODUW2P.js +19 -0
  32. package/chunks/{session-store-3BRPGC6P.js → session-store-O3TS7DUY.js} +5 -5
  33. package/chunks/{sqlite-DHUQGPR5.js → sqlite-7BC4DJTN.js} +2 -2
  34. package/chunks/{vasana-engine-MU25OQ23.js → vasana-engine-BJFHJVGM.js} +4 -4
  35. package/gateway.js +31592 -24973
  36. package/package.json +1 -1
  37. package/pair-cli.js +1 -1
  38. package/chunks/graphrag-D7OXWAWD.js +0 -14
  39. package/chunks/hybrid-search-G2NAJKJ7.js +0 -20
  40. package/chunks/periodic-consolidation-LMYMNS4Q.js +0 -11
  41. package/chunks/search-35JMSGUT.js +0 -19
@@ -1,32 +1,32 @@
1
1
  import {
2
2
  getDayFilePath,
3
3
  listDayFiles
4
- } from "./chunk-77725AR7.js";
4
+ } from "./chunk-F6RNEGFX.js";
5
5
  import {
6
6
  PRESERVATION_RATIOS,
7
7
  RecallEngine,
8
8
  STREAM_ORDER,
9
9
  StreamManager
10
- } from "./chunk-VJHNE47S.js";
10
+ } from "./chunk-D46QTN3G.js";
11
11
  import {
12
12
  createSession,
13
13
  listSessions,
14
14
  loadSession,
15
15
  saveSession
16
- } from "./chunk-HIYHTWFW.js";
16
+ } from "./chunk-ZYY6N3SP.js";
17
17
  import {
18
18
  cosineSimilarity,
19
19
  estimateTokens
20
- } from "./chunk-JAWZ7ANC.js";
20
+ } from "./chunk-A3HOZBC5.js";
21
21
  import {
22
22
  DatabaseManager
23
- } from "./chunk-U62ABYKD.js";
23
+ } from "./chunk-67DXWEKG.js";
24
24
  import {
25
25
  SessionError,
26
26
  getChitraguptaHome
27
- } from "./chunk-UZ6OIVEC.js";
27
+ } from "./chunk-2OBLQJYJ.js";
28
28
 
29
- // ../chitragupta/packages/smriti/src/session-export.ts
29
+ // ../chitragupta/packages/smriti/dist/session-export.js
30
30
  function exportSessionToJson(session) {
31
31
  const messages = session.turns.map((turn) => {
32
32
  const msg = {
@@ -34,8 +34,10 @@ function exportSessionToJson(session) {
34
34
  content: turn.content,
35
35
  turnNumber: turn.turnNumber
36
36
  };
37
- if (turn.agent) msg.agent = turn.agent;
38
- if (turn.model) msg.model = turn.model;
37
+ if (turn.agent)
38
+ msg.agent = turn.agent;
39
+ if (turn.model)
40
+ msg.model = turn.model;
39
41
  if (turn.toolCalls && turn.toolCalls.length > 0) {
40
42
  msg.toolCalls = turn.toolCalls.map((tc) => {
41
43
  const exported = {
@@ -43,7 +45,8 @@ function exportSessionToJson(session) {
43
45
  input: tc.input,
44
46
  result: tc.result
45
47
  };
46
- if (tc.isError) exported.isError = true;
48
+ if (tc.isError)
49
+ exported.isError = true;
47
50
  return exported;
48
51
  });
49
52
  }
@@ -157,8 +160,10 @@ function importSessionFromJson(data) {
157
160
  role: msg.role,
158
161
  content: msg.content
159
162
  };
160
- if (msg.agent) turn.agent = msg.agent;
161
- if (msg.model) turn.model = msg.model;
163
+ if (msg.agent)
164
+ turn.agent = msg.agent;
165
+ if (msg.model)
166
+ turn.model = msg.model;
162
167
  if (msg.toolCalls && msg.toolCalls.length > 0) {
163
168
  turn.toolCalls = msg.toolCalls.map((tc) => {
164
169
  const toolCall = {
@@ -166,7 +171,8 @@ function importSessionFromJson(data) {
166
171
  input: tc.input,
167
172
  result: tc.result
168
173
  };
169
- if (tc.isError) toolCall.isError = true;
174
+ if (tc.isError)
175
+ toolCall.isError = true;
170
176
  return toolCall;
171
177
  });
172
178
  }
@@ -228,13 +234,13 @@ function validateExportedSession(data) {
228
234
  }
229
235
  }
230
236
 
231
- // ../chitragupta/packages/smriti/src/cross-machine-sync.ts
237
+ // ../chitragupta/packages/smriti/dist/cross-machine-sync.js
232
238
  import fs2 from "node:fs";
233
239
  import os from "node:os";
234
240
  import path2 from "node:path";
235
241
  import crypto2 from "node:crypto";
236
242
 
237
- // ../chitragupta/packages/smriti/src/sync-import.ts
243
+ // ../chitragupta/packages/smriti/dist/sync-import.js
238
244
  import fs from "node:fs";
239
245
  import path from "node:path";
240
246
  import crypto from "node:crypto";
@@ -288,16 +294,21 @@ function splitMemory(content) {
288
294
  function mergeMemory(localContent, remoteContent) {
289
295
  const localTrimmed = localContent.trim();
290
296
  const remoteTrimmed = remoteContent.trim();
291
- if (!localTrimmed) return remoteTrimmed ? `${remoteTrimmed}
297
+ if (!localTrimmed)
298
+ return remoteTrimmed ? `${remoteTrimmed}
292
299
  ` : "";
293
- if (!remoteTrimmed) return localContent.endsWith("\n") ? localContent : `${localContent}
300
+ if (!remoteTrimmed)
301
+ return localContent.endsWith("\n") ? localContent : `${localContent}
294
302
  `;
295
- if (localContent === remoteContent) return localContent;
303
+ if (localContent === remoteContent)
304
+ return localContent;
296
305
  const local = splitMemory(localContent);
297
306
  const remote = splitMemory(remoteContent);
298
307
  if (local.entries.length === 0 && remote.entries.length === 0) {
299
- if (localContent.includes(remoteContent)) return localContent;
300
- if (remoteContent.includes(localContent)) return remoteContent;
308
+ if (localContent.includes(remoteContent))
309
+ return localContent;
310
+ if (remoteContent.includes(localContent))
311
+ return remoteContent;
301
312
  return `${localContent.trimEnd()}
302
313
 
303
314
  ---
@@ -310,7 +321,8 @@ ${remoteContent.trim()}
310
321
  const mergedEntries = [];
311
322
  for (const entry of [...local.entries, ...remote.entries]) {
312
323
  const key = sha256(entry.replace(/\s+/g, " ").trim().toLowerCase());
313
- if (seen.has(key)) continue;
324
+ if (seen.has(key))
325
+ continue;
314
326
  seen.add(key);
315
327
  mergedEntries.push(entry.trim());
316
328
  }
@@ -318,13 +330,15 @@ ${remoteContent.trim()}
318
330
  if (mergedEntries.length > 0) {
319
331
  merged += ENTRY_SEPARATOR + mergedEntries.join(ENTRY_SEPARATOR);
320
332
  }
321
- if (!merged.endsWith("\n")) merged += "\n";
333
+ if (!merged.endsWith("\n"))
334
+ merged += "\n";
322
335
  return merged;
323
336
  }
324
337
  function readSyncState(home) {
325
338
  const statePath = path.join(home, "sync-state.json");
326
339
  try {
327
- if (!fs.existsSync(statePath)) return {};
340
+ if (!fs.existsSync(statePath))
341
+ return {};
328
342
  const raw = fs.readFileSync(statePath, "utf-8");
329
343
  const parsed = JSON.parse(raw);
330
344
  return parsed && typeof parsed === "object" ? parsed : {};
@@ -368,7 +382,8 @@ function importCrossMachineSnapshot(source, options) {
368
382
  }
369
383
  const targetPath = resolveSnapshotPath(file.path, home);
370
384
  if (!fs.existsSync(targetPath)) {
371
- if (!dryRun) writeTextFile(targetPath, file.content);
385
+ if (!dryRun)
386
+ writeTextFile(targetPath, file.content);
372
387
  totals.created += 1;
373
388
  changedPaths.push(file.path);
374
389
  continue;
@@ -384,13 +399,15 @@ function importCrossMachineSnapshot(source, options) {
384
399
  totals.skipped += 1;
385
400
  continue;
386
401
  }
387
- if (!dryRun) writeTextFile(targetPath, merged);
402
+ if (!dryRun)
403
+ writeTextFile(targetPath, merged);
388
404
  totals.merged += 1;
389
405
  changedPaths.push(file.path);
390
406
  continue;
391
407
  }
392
408
  if (strategy === "preferRemote") {
393
- if (!dryRun) writeTextFile(targetPath, file.content);
409
+ if (!dryRun)
410
+ writeTextFile(targetPath, file.content);
394
411
  totals.updated += 1;
395
412
  changedPaths.push(file.path);
396
413
  continue;
@@ -400,7 +417,8 @@ function importCrossMachineSnapshot(source, options) {
400
417
  continue;
401
418
  }
402
419
  const conflictPath = createConflictPath(conflictRoot, file.path);
403
- if (!dryRun) writeTextFile(conflictPath, file.content);
420
+ if (!dryRun)
421
+ writeTextFile(conflictPath, file.content);
404
422
  totals.conflicts += 1;
405
423
  conflictPaths.push(toPortablePath(conflictPath, home));
406
424
  } catch {
@@ -458,7 +476,7 @@ function assertSnapshot(value) {
458
476
  }
459
477
  }
460
478
 
461
- // ../chitragupta/packages/smriti/src/cross-machine-sync.ts
479
+ // ../chitragupta/packages/smriti/dist/cross-machine-sync.js
462
480
  var SNAPSHOT_VERSION2 = 1;
463
481
  function sha2562(content) {
464
482
  return crypto2.createHash("sha256").update(content, "utf-8").digest("hex");
@@ -471,7 +489,8 @@ function toPortablePath2(absPath, home) {
471
489
  return rel.split(path2.sep).join("/");
472
490
  }
473
491
  function listMemoryFiles(memoryRoot) {
474
- if (!fs2.existsSync(memoryRoot)) return [];
492
+ if (!fs2.existsSync(memoryRoot))
493
+ return [];
475
494
  const stack = [memoryRoot];
476
495
  const files = [];
477
496
  while (stack.length > 0) {
@@ -498,7 +517,8 @@ function listMemoryFiles(memoryRoot) {
498
517
  function readSyncState2(home) {
499
518
  const statePath = path2.join(home, "sync-state.json");
500
519
  try {
501
- if (!fs2.existsSync(statePath)) return {};
520
+ if (!fs2.existsSync(statePath))
521
+ return {};
502
522
  const raw = fs2.readFileSync(statePath, "utf-8");
503
523
  const parsed = JSON.parse(raw);
504
524
  return parsed && typeof parsed === "object" ? parsed : {};
@@ -557,7 +577,8 @@ function createCrossMachineSnapshot(options) {
557
577
  }
558
578
  for (const date of dates) {
559
579
  const absPath = getDayFilePath(date);
560
- if (!fs2.existsSync(absPath)) continue;
580
+ if (!fs2.existsSync(absPath))
581
+ continue;
561
582
  try {
562
583
  const content = fs2.readFileSync(absPath, "utf-8");
563
584
  const stat = fs2.statSync(absPath);
@@ -633,16 +654,14 @@ function getCrossMachineSyncStatus() {
633
654
  };
634
655
  }
635
656
 
636
- // ../chitragupta/packages/smriti/src/branch.ts
657
+ // ../chitragupta/packages/smriti/dist/branch.js
637
658
  function branchSession(sessionId, project, branchName, fromTurn) {
638
659
  const original = loadSession(sessionId, project);
639
660
  let turnsToKeep = original.turns;
640
661
  if (fromTurn !== void 0) {
641
662
  turnsToKeep = original.turns.filter((t) => t.turnNumber <= fromTurn);
642
663
  if (turnsToKeep.length === 0 && original.turns.length > 0) {
643
- throw new SessionError(
644
- `No turns found at or before turn ${fromTurn} in session ${sessionId}`
645
- );
664
+ throw new SessionError(`No turns found at or before turn ${fromTurn} in session ${sessionId}`);
646
665
  }
647
666
  }
648
667
  const branched = createSession({
@@ -735,7 +754,7 @@ function createSyntheticRoot(project) {
735
754
  };
736
755
  }
737
756
 
738
- // ../chitragupta/packages/smriti/src/sinkhorn-knopp.ts
757
+ // ../chitragupta/packages/smriti/dist/sinkhorn-knopp.js
739
758
  function sinkhornKnopp(matrix, maxIterations = 100, epsilon = 1e-6) {
740
759
  const n = matrix.length;
741
760
  if (n === 0) {
@@ -748,7 +767,8 @@ function sinkhornKnopp(matrix, maxIterations = 100, epsilon = 1e-6) {
748
767
  const A = matrix.map((row) => [...row]);
749
768
  for (let i = 0; i < n; i++) {
750
769
  for (let j = 0; j < m; j++) {
751
- if (A[i][j] < 0) A[i][j] = 0;
770
+ if (A[i][j] < 0)
771
+ A[i][j] = 0;
752
772
  }
753
773
  }
754
774
  for (let i = 0; i < n; i++) {
@@ -797,7 +817,8 @@ function sinkhornKnopp(matrix, maxIterations = 100, epsilon = 1e-6) {
797
817
  for (let i = 0; i < n; i++) {
798
818
  const rowSum = A[i].reduce((s, v) => s + v, 0);
799
819
  const dev = Math.abs(rowSum - 1);
800
- if (dev > maxDeviation2) maxDeviation2 = dev;
820
+ if (dev > maxDeviation2)
821
+ maxDeviation2 = dev;
801
822
  }
802
823
  for (let j = 0; j < m; j++) {
803
824
  let colSum = 0;
@@ -805,7 +826,8 @@ function sinkhornKnopp(matrix, maxIterations = 100, epsilon = 1e-6) {
805
826
  colSum += A[i][j];
806
827
  }
807
828
  const dev = Math.abs(colSum - 1);
808
- if (dev > maxDeviation2) maxDeviation2 = dev;
829
+ if (dev > maxDeviation2)
830
+ maxDeviation2 = dev;
809
831
  }
810
832
  if (maxDeviation2 < epsilon) {
811
833
  converged = true;
@@ -856,7 +878,8 @@ function buildAffinityMatrix(signals) {
856
878
  }
857
879
  function computeTokenBudgets(mixingMatrix, totalBudget, preservationRatios = PRESERVATION_RATIOS) {
858
880
  const n = mixingMatrix.length;
859
- if (n === 0) return [];
881
+ if (n === 0)
882
+ return [];
860
883
  const weights = [];
861
884
  for (let j = 0; j < n; j++) {
862
885
  let colSum = 0;
@@ -879,7 +902,8 @@ function computeTokenBudgets(mixingMatrix, totalBudget, preservationRatios = PRE
879
902
  let remainder = totalBudget - allocated;
880
903
  const sortedIndices = preservationRatios.map((r, i) => ({ ratio: r, index: i })).sort((a, b) => b.ratio - a.ratio).map((x) => x.index);
881
904
  for (const idx of sortedIndices) {
882
- if (remainder <= 0) break;
905
+ if (remainder <= 0)
906
+ break;
883
907
  budgets[idx] += 1;
884
908
  remainder -= 1;
885
909
  }
@@ -892,7 +916,7 @@ function allocateBudgets(signals, totalBudget) {
892
916
  return { budgets, mixingMatrix, converged };
893
917
  }
894
918
 
895
- // ../chitragupta/packages/smriti/src/compactor-signals.ts
919
+ // ../chitragupta/packages/smriti/dist/compactor-signals.js
896
920
  var OLLAMA_ENDPOINT = process.env.OLLAMA_HOST ?? "http://localhost:11434";
897
921
  var GENERATION_MODEL = "llama3.2";
898
922
  function configureCompactorSignals(options) {
@@ -948,7 +972,8 @@ function keywordExtractSignals(session) {
948
972
  break;
949
973
  }
950
974
  }
951
- if (matched) continue;
975
+ if (matched)
976
+ continue;
952
977
  for (const pattern of PROJECT_PATTERNS) {
953
978
  if (pattern.test(sentence)) {
954
979
  signals.projects.push(sentence.slice(0, 200));
@@ -956,7 +981,8 @@ function keywordExtractSignals(session) {
956
981
  break;
957
982
  }
958
983
  }
959
- if (matched) continue;
984
+ if (matched)
985
+ continue;
960
986
  for (const pattern of TASK_PATTERNS) {
961
987
  if (pattern.test(sentence)) {
962
988
  signals.tasks.push(sentence.slice(0, 200));
@@ -964,7 +990,8 @@ function keywordExtractSignals(session) {
964
990
  break;
965
991
  }
966
992
  }
967
- if (matched) continue;
993
+ if (matched)
994
+ continue;
968
995
  for (const pattern of FLOW_PATTERNS) {
969
996
  if (pattern.test(sentence)) {
970
997
  signals.flow.push(sentence.slice(0, 200));
@@ -1146,7 +1173,7 @@ function writeDeltaMarkdown(delta) {
1146
1173
  return lines.join("\n");
1147
1174
  }
1148
1175
 
1149
- // ../chitragupta/packages/smriti/src/compactor.ts
1176
+ // ../chitragupta/packages/smriti/dist/compactor.js
1150
1177
  import fs3 from "fs";
1151
1178
  import path3 from "path";
1152
1179
  function getCompactionDir() {
@@ -1156,12 +1183,14 @@ function getDeltaDir() {
1156
1183
  return path3.join(getChitraguptaHome(), "smriti", "deltas");
1157
1184
  }
1158
1185
  function updateIdentityStream(streamManager, signals) {
1159
- if (signals.identity.length === 0) return;
1186
+ if (signals.identity.length === 0)
1187
+ return;
1160
1188
  const entry = signals.identity.map((s) => `- ${s}`).join("\n");
1161
1189
  streamManager.append("identity", entry);
1162
1190
  }
1163
1191
  function updateProjectsStream(streamManager, signals, session) {
1164
- if (signals.projects.length === 0) return;
1192
+ if (signals.projects.length === 0)
1193
+ return;
1165
1194
  const parts = [];
1166
1195
  parts.push(`### Session: ${session.meta.title}`);
1167
1196
  parts.push("");
@@ -1171,7 +1200,8 @@ function updateProjectsStream(streamManager, signals, session) {
1171
1200
  streamManager.append("projects", parts.join("\n"));
1172
1201
  }
1173
1202
  function updateTasksStream(streamManager, signals) {
1174
- if (signals.tasks.length === 0) return;
1203
+ if (signals.tasks.length === 0)
1204
+ return;
1175
1205
  const parts = [];
1176
1206
  const newTasks = [];
1177
1207
  const completed = [];
@@ -1371,11 +1401,12 @@ var SessionCompactor = class {
1371
1401
  }
1372
1402
  };
1373
1403
 
1374
- // ../chitragupta/packages/smriti/src/sinkhorn-budget.ts
1404
+ // ../chitragupta/packages/smriti/dist/sinkhorn-budget.js
1375
1405
  function computeTokenBudgetsMHC(chunks, totalBudget) {
1376
1406
  const result = /* @__PURE__ */ new Map();
1377
1407
  const n = chunks.length;
1378
- if (n === 0) return result;
1408
+ if (n === 0)
1409
+ return result;
1379
1410
  if (n === 1) {
1380
1411
  result.set(chunks[0].id, totalBudget);
1381
1412
  return result;
@@ -1396,7 +1427,8 @@ function computeTokenBudgetsMHC(chunks, totalBudget) {
1396
1427
  const importanceAff = Math.max(ci.importance, cj.importance);
1397
1428
  const topicBonus = ci.topic && cj.topic && ci.topic === cj.topic ? TOPIC_BONUS : 0;
1398
1429
  row[j] = W_RECENCY * recencyAff + W_RELEVANCE * relevanceAff + W_IMPORTANCE * importanceAff + W_TOPIC * topicBonus;
1399
- if (row[j] < 1e-6) row[j] = 1e-6;
1430
+ if (row[j] < 1e-6)
1431
+ row[j] = 1e-6;
1400
1432
  }
1401
1433
  affinity.push(row);
1402
1434
  }
@@ -1413,13 +1445,15 @@ function computeTokenBudgetsMHC(chunks, totalBudget) {
1413
1445
  let rawTotal = 0;
1414
1446
  for (let i = 0; i < n; i++) {
1415
1447
  let rowSum = 0;
1416
- for (let j = 0; j < n; j++) rowSum += dsMatrix[i][j];
1448
+ for (let j = 0; j < n; j++)
1449
+ rowSum += dsMatrix[i][j];
1417
1450
  rawBudgets[i] = rowSum * composites[i];
1418
1451
  rawTotal += rawBudgets[i];
1419
1452
  }
1420
1453
  if (rawTotal === 0) {
1421
1454
  const equal = Math.floor(totalBudget / n);
1422
- for (let i = 0; i < n; i++) result.set(chunks[i].id, equal);
1455
+ for (let i = 0; i < n; i++)
1456
+ result.set(chunks[i].id, equal);
1423
1457
  let rem = totalBudget - equal * n;
1424
1458
  for (let i = 0; rem > 0; i++, rem--) {
1425
1459
  result.set(chunks[i].id, (result.get(chunks[i].id) ?? 0) + 1);
@@ -1435,7 +1469,8 @@ function computeTokenBudgetsMHC(chunks, totalBudget) {
1435
1469
  let remainder = totalBudget - allocated;
1436
1470
  const sortedIndices = composites.map((c, i) => ({ composite: c, index: i })).sort((a, b) => b.composite - a.composite).map((x) => x.index);
1437
1471
  for (const idx of sortedIndices) {
1438
- if (remainder <= 0) break;
1472
+ if (remainder <= 0)
1473
+ break;
1439
1474
  const id = chunks[idx].id;
1440
1475
  result.set(id, (result.get(id) ?? 0) + 1);
1441
1476
  remainder--;
@@ -1443,15 +1478,19 @@ function computeTokenBudgetsMHC(chunks, totalBudget) {
1443
1478
  return result;
1444
1479
  }
1445
1480
 
1446
- // ../chitragupta/packages/smriti/src/sinkhorn-accelerated.ts
1481
+ // ../chitragupta/packages/smriti/dist/sinkhorn-accelerated.js
1447
1482
  function logsumexp(arr) {
1448
- if (arr.length === 0) return -Infinity;
1449
- if (arr.length === 1) return arr[0];
1483
+ if (arr.length === 0)
1484
+ return -Infinity;
1485
+ if (arr.length === 1)
1486
+ return arr[0];
1450
1487
  let maxVal = -Infinity;
1451
1488
  for (let i = 0; i < arr.length; i++) {
1452
- if (arr[i] > maxVal) maxVal = arr[i];
1489
+ if (arr[i] > maxVal)
1490
+ maxVal = arr[i];
1453
1491
  }
1454
- if (maxVal === -Infinity) return -Infinity;
1492
+ if (maxVal === -Infinity)
1493
+ return -Infinity;
1455
1494
  let sumExp = 0;
1456
1495
  for (let i = 0; i < arr.length; i++) {
1457
1496
  sumExp += Math.exp(arr[i] - maxVal);
@@ -1483,16 +1522,20 @@ function linearSKStep(A) {
1483
1522
  const m = A[0].length;
1484
1523
  for (let i = 0; i < n; i++) {
1485
1524
  let rowSum = 0;
1486
- for (let j = 0; j < m; j++) rowSum += A[i][j];
1525
+ for (let j = 0; j < m; j++)
1526
+ rowSum += A[i][j];
1487
1527
  if (rowSum > 0) {
1488
- for (let j = 0; j < m; j++) A[i][j] /= rowSum;
1528
+ for (let j = 0; j < m; j++)
1529
+ A[i][j] /= rowSum;
1489
1530
  }
1490
1531
  }
1491
1532
  for (let j = 0; j < m; j++) {
1492
1533
  let colSum = 0;
1493
- for (let i = 0; i < n; i++) colSum += A[i][j];
1534
+ for (let i = 0; i < n; i++)
1535
+ colSum += A[i][j];
1494
1536
  if (colSum > 0) {
1495
- for (let i = 0; i < n; i++) A[i][j] /= colSum;
1537
+ for (let i = 0; i < n; i++)
1538
+ A[i][j] /= colSum;
1496
1539
  }
1497
1540
  }
1498
1541
  }
@@ -1502,15 +1545,19 @@ function maxDeviation(A) {
1502
1545
  let maxDev = 0;
1503
1546
  for (let i = 0; i < n; i++) {
1504
1547
  let rowSum = 0;
1505
- for (let j = 0; j < m; j++) rowSum += A[i][j];
1548
+ for (let j = 0; j < m; j++)
1549
+ rowSum += A[i][j];
1506
1550
  const dev = Math.abs(rowSum - 1);
1507
- if (dev > maxDev) maxDev = dev;
1551
+ if (dev > maxDev)
1552
+ maxDev = dev;
1508
1553
  }
1509
1554
  for (let j = 0; j < m; j++) {
1510
1555
  let colSum = 0;
1511
- for (let i = 0; i < n; i++) colSum += A[i][j];
1556
+ for (let i = 0; i < n; i++)
1557
+ colSum += A[i][j];
1512
1558
  const dev = Math.abs(colSum - 1);
1513
- if (dev > maxDev) maxDev = dev;
1559
+ if (dev > maxDev)
1560
+ maxDev = dev;
1514
1561
  }
1515
1562
  return maxDev;
1516
1563
  }
@@ -1547,18 +1594,25 @@ function sinkhornAccelerated(matrix, opts) {
1547
1594
  const initialEps = opts?.initialEpsilon ?? 0.01;
1548
1595
  const halvingInterval = opts?.epsilonHalvingInterval ?? 10;
1549
1596
  const n = matrix.length;
1550
- if (n === 0) return { result: [], iterations: 0, converged: true };
1597
+ if (n === 0)
1598
+ return { result: [], iterations: 0, converged: true };
1551
1599
  const m = matrix[0].length;
1552
- if (m === 0) return { result: matrix.map(() => []), iterations: 0, converged: true };
1600
+ if (m === 0)
1601
+ return { result: matrix.map(() => []), iterations: 0, converged: true };
1553
1602
  const A = matrix.map((row) => row.map((v) => Math.max(v, 0)));
1554
1603
  for (let i = 0; i < n; i++) {
1555
1604
  const rowSum = A[i].reduce((s, v) => s + v, 0);
1556
- if (rowSum === 0) for (let j = 0; j < m; j++) A[i][j] = 1 / m;
1605
+ if (rowSum === 0)
1606
+ for (let j = 0; j < m; j++)
1607
+ A[i][j] = 1 / m;
1557
1608
  }
1558
1609
  for (let j = 0; j < m; j++) {
1559
1610
  let colSum = 0;
1560
- for (let i = 0; i < n; i++) colSum += A[i][j];
1561
- if (colSum === 0) for (let i = 0; i < n; i++) A[i][j] = 1 / n;
1611
+ for (let i = 0; i < n; i++)
1612
+ colSum += A[i][j];
1613
+ if (colSum === 0)
1614
+ for (let i = 0; i < n; i++)
1615
+ A[i][j] = 1 / n;
1562
1616
  }
1563
1617
  let currentEps = useAdaptiveEps ? initialEps : targetEpsilon;
1564
1618
  let iterations = 0;
@@ -1594,7 +1648,8 @@ function sinkhornAccelerated(matrix, opts) {
1594
1648
  const working = useNesterov ? nesterovExtrapolate(current, previous, k) : cloneMatrix(current);
1595
1649
  for (let i = 0; i < n; i++) {
1596
1650
  for (let j = 0; j < m; j++) {
1597
- if (working[i][j] < 1e-15) working[i][j] = 1e-15;
1651
+ if (working[i][j] < 1e-15)
1652
+ working[i][j] = 1e-15;
1598
1653
  }
1599
1654
  }
1600
1655
  previous = cloneMatrix(current);
@@ -1609,7 +1664,7 @@ function sinkhornAccelerated(matrix, opts) {
1609
1664
  return { result: current, iterations, converged };
1610
1665
  }
1611
1666
 
1612
- // ../chitragupta/packages/smriti/src/stream-extractor.ts
1667
+ // ../chitragupta/packages/smriti/dist/stream-extractor.js
1613
1668
  var IDENTITY_PATTERNS2 = [
1614
1669
  /\bi (?:prefer|like|want|hate|always|never|use)\b/i,
1615
1670
  /\b(?:my|our) (?:preference|style|convention|workflow|setup)\b/i,
@@ -1650,7 +1705,8 @@ var TASK_PATTERNS2 = [
1650
1705
  function scorePatterns(text, patterns) {
1651
1706
  let hits = 0;
1652
1707
  for (const pattern of patterns) {
1653
- if (pattern.test(text)) hits++;
1708
+ if (pattern.test(text))
1709
+ hits++;
1654
1710
  }
1655
1711
  return hits;
1656
1712
  }
@@ -1663,7 +1719,8 @@ function extractSignals(turn) {
1663
1719
  };
1664
1720
  const sentences = splitSentences(turn.content);
1665
1721
  for (const sentence of sentences) {
1666
- if (sentence.trim().length < 5) continue;
1722
+ if (sentence.trim().length < 5)
1723
+ continue;
1667
1724
  const identityScore = scorePatterns(sentence, IDENTITY_PATTERNS2);
1668
1725
  const projectScore = scorePatterns(sentence, PROJECT_PATTERNS2);
1669
1726
  const taskScore = scorePatterns(sentence, TASK_PATTERNS2);
@@ -1700,10 +1757,14 @@ function classifyContent(text) {
1700
1757
  const projectScore = scorePatterns(text, PROJECT_PATTERNS2);
1701
1758
  const taskScore = scorePatterns(text, TASK_PATTERNS2);
1702
1759
  const maxScore = Math.max(identityScore, projectScore, taskScore);
1703
- if (maxScore === 0) return "flow";
1704
- if (identityScore === maxScore) return "identity";
1705
- if (projectScore === maxScore) return "projects";
1706
- if (taskScore === maxScore) return "tasks";
1760
+ if (maxScore === 0)
1761
+ return "flow";
1762
+ if (identityScore === maxScore)
1763
+ return "identity";
1764
+ if (projectScore === maxScore)
1765
+ return "projects";
1766
+ if (taskScore === maxScore)
1767
+ return "tasks";
1707
1768
  return "flow";
1708
1769
  }
1709
1770
  function extractSignalsFromTurns(turns) {
@@ -1728,11 +1789,12 @@ function splitSentences(text) {
1728
1789
  return sentences;
1729
1790
  }
1730
1791
 
1731
- // ../chitragupta/packages/smriti/src/graphrag-adaptive-scoring.ts
1792
+ // ../chitragupta/packages/smriti/dist/graphrag-adaptive-scoring.js
1732
1793
  function sampleBeta(alpha, beta) {
1733
1794
  const x = sampleGamma(alpha);
1734
1795
  const y = sampleGamma(beta);
1735
- if (x + y === 0) return 0.5;
1796
+ if (x + y === 0)
1797
+ return 0.5;
1736
1798
  return x / (x + y);
1737
1799
  }
1738
1800
  function sampleGamma(shape) {
@@ -1752,8 +1814,10 @@ function sampleGamma(shape) {
1752
1814
  v = v * v * v;
1753
1815
  const u = Math.random();
1754
1816
  const zSq = z * z;
1755
- if (u < 1 - 0.0331 * (zSq * zSq)) return d * v;
1756
- if (Math.log(u) < 0.5 * zSq + d * (1 - v + Math.log(v))) return d * v;
1817
+ if (u < 1 - 0.0331 * (zSq * zSq))
1818
+ return d * v;
1819
+ if (Math.log(u) < 0.5 * zSq + d * (1 - v + Math.log(v)))
1820
+ return d * v;
1757
1821
  }
1758
1822
  }
1759
1823
  function gaussianRandom() {
@@ -1819,7 +1883,8 @@ var AdaptiveScorer = class {
1819
1883
  */
1820
1884
  recordFeedback(queryId, accepted) {
1821
1885
  const dominant = this.queryDominants.get(queryId);
1822
- if (!dominant) return;
1886
+ if (!dominant)
1887
+ return;
1823
1888
  const record = {
1824
1889
  timestamp: Date.now(),
1825
1890
  accepted,
@@ -1883,7 +1948,8 @@ var AdaptiveScorer = class {
1883
1948
  const rawPagerank = sampleBeta(this.pagerankAlpha, this.pagerankBeta);
1884
1949
  const rawText = sampleBeta(this.textAlpha, this.textBeta);
1885
1950
  const total = rawCosine + rawPagerank + rawText;
1886
- if (total === 0) return { ...FIXED_WEIGHTS };
1951
+ if (total === 0)
1952
+ return { ...FIXED_WEIGHTS };
1887
1953
  return {
1888
1954
  cosine: rawCosine / total,
1889
1955
  pagerank: rawPagerank / total,
@@ -1927,7 +1993,8 @@ var AdaptiveScorer = class {
1927
1993
  }
1928
1994
  };
1929
1995
  function mmrRerank(scored, lambda = 0.7, topK = 10) {
1930
- if (scored.length <= 1 || topK <= 0) return scored.slice(0, topK);
1996
+ if (scored.length <= 1 || topK <= 0)
1997
+ return scored.slice(0, topK);
1931
1998
  const k = Math.min(topK, scored.length);
1932
1999
  const selected = [];
1933
2000
  const remaining = [...scored];
@@ -1941,7 +2008,8 @@ function mmrRerank(scored, lambda = 0.7, topK = 10) {
1941
2008
  let maxSim = 0;
1942
2009
  for (const sel of selected) {
1943
2010
  const sim = computeSimilarity(candidate, sel);
1944
- if (sim > maxSim) maxSim = sim;
2011
+ if (sim > maxSim)
2012
+ maxSim = sim;
1945
2013
  }
1946
2014
  const mmr = lambda * candidate.finalScore - (1 - lambda) * maxSim;
1947
2015
  if (mmr > bestMMR) {
@@ -1962,7 +2030,7 @@ function computeSimilarity(a, b) {
1962
2030
  return Math.max(0, cosineSimilarity(vecA, vecB));
1963
2031
  }
1964
2032
 
1965
- // ../chitragupta/packages/smriti/src/checkpoint.ts
2033
+ // ../chitragupta/packages/smriti/dist/checkpoint.js
1966
2034
  import fs4 from "node:fs";
1967
2035
  import path4 from "node:path";
1968
2036
  import { randomUUID } from "node:crypto";
@@ -1971,13 +2039,16 @@ var DEFAULT_INTERVAL = 3e4;
1971
2039
  var DEFAULT_MAX_CHECKPOINTS = 5;
1972
2040
  var CHECKPOINT_EXT = ".json";
1973
2041
  function parseCheckpointFilename(filename) {
1974
- if (!filename.endsWith(CHECKPOINT_EXT)) return null;
2042
+ if (!filename.endsWith(CHECKPOINT_EXT))
2043
+ return null;
1975
2044
  const base = filename.slice(0, -CHECKPOINT_EXT.length);
1976
2045
  const dashIdx = base.indexOf("-");
1977
- if (dashIdx === -1) return null;
2046
+ if (dashIdx === -1)
2047
+ return null;
1978
2048
  const timestamp = Number(base.slice(0, dashIdx));
1979
2049
  const uuid = base.slice(dashIdx + 1);
1980
- if (Number.isNaN(timestamp) || !uuid) return null;
2050
+ if (Number.isNaN(timestamp) || !uuid)
2051
+ return null;
1981
2052
  return { timestamp, uuid };
1982
2053
  }
1983
2054
  var CheckpointManager = class {
@@ -2021,7 +2092,8 @@ var CheckpointManager = class {
2021
2092
  */
2022
2093
  async load(sessionId) {
2023
2094
  const checkpoints = this.list(sessionId);
2024
- if (checkpoints.length === 0) return null;
2095
+ if (checkpoints.length === 0)
2096
+ return null;
2025
2097
  for (const cp of checkpoints) {
2026
2098
  try {
2027
2099
  const filePath = this.checkpointPath(sessionId, cp);
@@ -2042,7 +2114,8 @@ var CheckpointManager = class {
2042
2114
  */
2043
2115
  list(sessionId) {
2044
2116
  const sessionDir = this.sessionDir(sessionId);
2045
- if (!fs4.existsSync(sessionDir)) return [];
2117
+ if (!fs4.existsSync(sessionDir))
2118
+ return [];
2046
2119
  let entries;
2047
2120
  try {
2048
2121
  entries = fs4.readdirSync(sessionDir);
@@ -2051,9 +2124,11 @@ var CheckpointManager = class {
2051
2124
  }
2052
2125
  const checkpoints = [];
2053
2126
  for (const entry of entries) {
2054
- if (entry.endsWith(".tmp")) continue;
2127
+ if (entry.endsWith(".tmp"))
2128
+ continue;
2055
2129
  const parsed = parseCheckpointFilename(entry);
2056
- if (!parsed) continue;
2130
+ if (!parsed)
2131
+ continue;
2057
2132
  const filePath = path4.join(sessionDir, entry);
2058
2133
  let size = 0;
2059
2134
  let turnCount = 0;
@@ -2097,7 +2172,8 @@ var CheckpointManager = class {
2097
2172
  */
2098
2173
  async prune(sessionId) {
2099
2174
  const all = this.list(sessionId);
2100
- if (all.length <= this.maxCheckpoints) return 0;
2175
+ if (all.length <= this.maxCheckpoints)
2176
+ return 0;
2101
2177
  const toRemove = all.slice(this.maxCheckpoints);
2102
2178
  let removed = 0;
2103
2179
  for (const cp of toRemove) {
@@ -2142,7 +2218,8 @@ var CheckpointManager = class {
2142
2218
  */
2143
2219
  async deleteAll(sessionId) {
2144
2220
  const sessionDir = this.sessionDir(sessionId);
2145
- if (!fs4.existsSync(sessionDir)) return;
2221
+ if (!fs4.existsSync(sessionDir))
2222
+ return;
2146
2223
  try {
2147
2224
  await fs4.promises.rm(sessionDir, { recursive: true, force: true });
2148
2225
  } catch {
@@ -2157,11 +2234,11 @@ var CheckpointManager = class {
2157
2234
  }
2158
2235
  };
2159
2236
 
2160
- // ../chitragupta/packages/smriti/src/consolidation.ts
2237
+ // ../chitragupta/packages/smriti/dist/consolidation.js
2161
2238
  import fs5 from "fs";
2162
2239
  import path5 from "path";
2163
2240
 
2164
- // ../chitragupta/packages/smriti/src/consolidation-phases.ts
2241
+ // ../chitragupta/packages/smriti/dist/consolidation-phases.js
2165
2242
  var PREFERENCE_PATTERNS = [
2166
2243
  /\bi prefer\b/i,
2167
2244
  /\balways use\b/i,
@@ -2255,7 +2332,8 @@ function detectToolSequences(sessions, minObservations) {
2255
2332
  const ngramEvidence = /* @__PURE__ */ new Map();
2256
2333
  for (const session of sessions) {
2257
2334
  const toolSeq = extractToolSequence(session);
2258
- if (toolSeq.length < n) continue;
2335
+ if (toolSeq.length < n)
2336
+ continue;
2259
2337
  const sessionNgrams = new Set(ngrams(toolSeq, n));
2260
2338
  for (const ng of sessionNgrams) {
2261
2339
  if (!ngramSessionCount.has(ng)) {
@@ -2263,9 +2341,7 @@ function detectToolSequences(sessions, minObservations) {
2263
2341
  ngramEvidence.set(ng, []);
2264
2342
  }
2265
2343
  ngramSessionCount.get(ng).add(session.meta.id);
2266
- ngramEvidence.get(ng).push(
2267
- `Session "${session.meta.title}": ${ng}`
2268
- );
2344
+ ngramEvidence.get(ng).push(`Session "${session.meta.title}": ${ng}`);
2269
2345
  }
2270
2346
  }
2271
2347
  for (const [ng, sessionIds] of ngramSessionCount) {
@@ -2298,9 +2374,7 @@ function detectPreferences(sessions) {
2298
2374
  }
2299
2375
  const hit = preferenceHits.get(key);
2300
2376
  hit.sessions.add(session.meta.id);
2301
- hit.evidence.push(
2302
- `Session "${session.meta.title}": "${sentence}"`
2303
- );
2377
+ hit.evidence.push(`Session "${session.meta.title}": "${sentence}"`);
2304
2378
  }
2305
2379
  }
2306
2380
  }
@@ -2332,9 +2406,7 @@ function detectDecisions(sessions) {
2332
2406
  }
2333
2407
  const hit = decisionHits.get(key);
2334
2408
  hit.sessions.add(session.meta.id);
2335
- hit.evidence.push(
2336
- `Session "${session.meta.title}": "${sentence}"`
2337
- );
2409
+ hit.evidence.push(`Session "${session.meta.title}": "${sentence}"`);
2338
2410
  }
2339
2411
  }
2340
2412
  }
@@ -2366,9 +2438,7 @@ function detectCorrections(sessions) {
2366
2438
  }
2367
2439
  const hit = correctionHits.get(key);
2368
2440
  hit.sessions.add(session.meta.id);
2369
- hit.evidence.push(
2370
- `Session "${session.meta.title}": "${sentence}"`
2371
- );
2441
+ hit.evidence.push(`Session "${session.meta.title}": "${sentence}"`);
2372
2442
  }
2373
2443
  }
2374
2444
  }
@@ -2394,7 +2464,8 @@ function detectConventions(sessions, minObservations) {
2394
2464
  const fileExtCounts = /* @__PURE__ */ new Map();
2395
2465
  for (const session of sessions) {
2396
2466
  for (const turn of session.turns) {
2397
- if (!turn.toolCalls) continue;
2467
+ if (!turn.toolCalls)
2468
+ continue;
2398
2469
  for (const tc of turn.toolCalls) {
2399
2470
  const extMatch = tc.input.match(/\.([a-z]{1,5})\b/gi);
2400
2471
  if (extMatch) {
@@ -2405,9 +2476,7 @@ function detectConventions(sessions, minObservations) {
2405
2476
  }
2406
2477
  const hit = fileExtCounts.get(extLower);
2407
2478
  hit.sessions.add(session.meta.id);
2408
- hit.evidence.push(
2409
- `Session "${session.meta.title}": tool ${tc.name} used ${extLower}`
2410
- );
2479
+ hit.evidence.push(`Session "${session.meta.title}": tool ${tc.name} used ${extLower}`);
2411
2480
  }
2412
2481
  }
2413
2482
  if (tc.name === "edit" || tc.name === "write") {
@@ -2418,9 +2487,7 @@ function detectConventions(sessions, minObservations) {
2418
2487
  }
2419
2488
  const hit = conventionHits.get(importKey);
2420
2489
  hit.sessions.add(session.meta.id);
2421
- hit.evidence.push(
2422
- `Session "${session.meta.title}": ${importKey} in ${tc.name} call`
2423
- );
2490
+ hit.evidence.push(`Session "${session.meta.title}": ${importKey} in ${tc.name} call`);
2424
2491
  }
2425
2492
  }
2426
2493
  }
@@ -2440,7 +2507,7 @@ function detectConventions(sessions, minObservations) {
2440
2507
  return patterns;
2441
2508
  }
2442
2509
 
2443
- // ../chitragupta/packages/smriti/src/consolidation-scoring.ts
2510
+ // ../chitragupta/packages/smriti/dist/consolidation-scoring.js
2444
2511
  var FNV_OFFSET = 2166136261;
2445
2512
  var FNV_PRIME = 16777619;
2446
2513
  function fnv1a(input) {
@@ -2459,8 +2526,10 @@ function textSimilarity(a, b) {
2459
2526
  const normalize = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
2460
2527
  const na = normalize(a);
2461
2528
  const nb = normalize(b);
2462
- if (na === nb) return 1;
2463
- if (na.length < 2 || nb.length < 2) return 0;
2529
+ if (na === nb)
2530
+ return 1;
2531
+ if (na.length < 2 || nb.length < 2)
2532
+ return 0;
2464
2533
  const bigrams = (s) => {
2465
2534
  const map = /* @__PURE__ */ new Map();
2466
2535
  for (let i = 0; i < s.length - 1; i++) {
@@ -2496,10 +2565,7 @@ function mergeWithExisting(candidates, allPatterns, rules) {
2496
2565
  }
2497
2566
  if (bestMatch && bestSimilarity >= SIMILARITY_THRESHOLD) {
2498
2567
  bestMatch.observationCount += candidate.observationCount;
2499
- bestMatch.confidence = Math.min(
2500
- 1,
2501
- bestMatch.confidence + 0.1 * candidate.observationCount
2502
- );
2568
+ bestMatch.confidence = Math.min(1, bestMatch.confidence + 0.1 * candidate.observationCount);
2503
2569
  bestMatch.lastReinforcedAt = candidate.lastReinforcedAt;
2504
2570
  const sessionSet = /* @__PURE__ */ new Set([
2505
2571
  ...bestMatch.sourceSessionIds,
@@ -2542,9 +2608,7 @@ function patternToRule(pattern, sessions, timestamp) {
2542
2608
  };
2543
2609
  const category = categoryMap[pattern.type];
2544
2610
  const id = generateRuleId(category, pattern.description);
2545
- const sessionIds = sessions.filter(
2546
- (s) => pattern.evidence.some((e) => e.includes(s.meta.title))
2547
- ).map((s) => s.meta.id);
2611
+ const sessionIds = sessions.filter((s) => pattern.evidence.some((e) => e.includes(s.meta.title))).map((s) => s.meta.id);
2548
2612
  return {
2549
2613
  id,
2550
2614
  rule: pattern.description,
@@ -2559,11 +2623,10 @@ function patternToRule(pattern, sessions, timestamp) {
2559
2623
  };
2560
2624
  }
2561
2625
  function enforceMaxRules(rules, maxRules) {
2562
- if (rules.size <= maxRules) return;
2626
+ if (rules.size <= maxRules)
2627
+ return;
2563
2628
  const sorted = [...rules.entries()].sort(([, a], [, b]) => b.confidence - a.confidence);
2564
- const toKeep = new Set(
2565
- sorted.slice(0, maxRules).map(([id]) => id)
2566
- );
2629
+ const toKeep = new Set(sorted.slice(0, maxRules).map(([id]) => id));
2567
2630
  for (const id of rules.keys()) {
2568
2631
  if (!toKeep.has(id)) {
2569
2632
  rules.delete(id);
@@ -2571,7 +2634,7 @@ function enforceMaxRules(rules, maxRules) {
2571
2634
  }
2572
2635
  }
2573
2636
 
2574
- // ../chitragupta/packages/smriti/src/consolidation.ts
2637
+ // ../chitragupta/packages/smriti/dist/consolidation.js
2575
2638
  var DEFAULT_CONFIG = {
2576
2639
  minObservations: 2,
2577
2640
  decayRatePerDay: 0.01,
@@ -2629,6 +2692,7 @@ var ConsolidationEngine = class {
2629
2692
  const candidateRules = allPatterns.filter((p) => p.frequency >= this.config.minObservations).map((p) => patternToRule(p, sessions, timestamp));
2630
2693
  const { newRules, reinforcedRules, weakenedRules } = mergeWithExisting(candidateRules, allPatterns, this.rules);
2631
2694
  enforceMaxRules(this.rules, this.config.maxRules);
2695
+ this.decayRules();
2632
2696
  this.pruneRules();
2633
2697
  const entry = {
2634
2698
  timestamp,
@@ -2642,6 +2706,7 @@ var ConsolidationEngine = class {
2642
2706
  if (this.history.length > MAX_HISTORY_ENTRIES) {
2643
2707
  this.history = this.history.slice(-MAX_HISTORY_ENTRIES);
2644
2708
  }
2709
+ this.save();
2645
2710
  return {
2646
2711
  newRules,
2647
2712
  reinforcedRules,
@@ -2792,9 +2857,7 @@ var ConsolidationEngine = class {
2792
2857
  }
2793
2858
  if (fs5.existsSync(historyPath)) {
2794
2859
  try {
2795
- this.history = JSON.parse(
2796
- fs5.readFileSync(historyPath, "utf-8")
2797
- );
2860
+ this.history = JSON.parse(fs5.readFileSync(historyPath, "utf-8"));
2798
2861
  } catch (err) {
2799
2862
  process.stderr.write(`[consolidation] corrupted history.json, starting fresh: ${err instanceof Error ? err.message : err}
2800
2863
  `);
@@ -2834,7 +2897,7 @@ var ConsolidationEngine = class {
2834
2897
  }
2835
2898
  };
2836
2899
 
2837
- // ../chitragupta/packages/smriti/src/query-decomposition.ts
2900
+ // ../chitragupta/packages/smriti/dist/query-decomposition.js
2838
2901
  var CONJUNCTIONS = /\b(and|or|but|that|which|who|where|when|while|although)\b/i;
2839
2902
  var TEMPORAL = /\b(when|before|after|last\s+(?:time|week|month|year|day)|yesterday|recently|earlier|previously|ago|since|until)\b/i;
2840
2903
  var COMPARATIVE = /\b(vs\.?|versus|compared?\s+to|difference\s+between|between\s+\w+\s+and)\b/i;
@@ -2844,18 +2907,25 @@ var positionalWeight = (index) => Math.max(0.4, 1 - 0.2 * index);
2844
2907
  function isComplexQuery(query) {
2845
2908
  const trimmed = query.trim();
2846
2909
  const words = trimmed.split(/\s+/);
2847
- if (words.length > COMPLEXITY_WORD_THRESHOLD) return true;
2848
- if (CONJUNCTIONS.test(trimmed)) return true;
2849
- if (TEMPORAL.test(trimmed)) return true;
2850
- if (COMPARATIVE.test(trimmed)) return true;
2910
+ if (words.length > COMPLEXITY_WORD_THRESHOLD)
2911
+ return true;
2912
+ if (CONJUNCTIONS.test(trimmed))
2913
+ return true;
2914
+ if (TEMPORAL.test(trimmed))
2915
+ return true;
2916
+ if (COMPARATIVE.test(trimmed))
2917
+ return true;
2851
2918
  const quotedTerms = trimmed.match(/["'][^"']+["']/g);
2852
- if (quotedTerms && quotedTerms.length >= 2) return true;
2919
+ if (quotedTerms && quotedTerms.length >= 2)
2920
+ return true;
2853
2921
  const capitalizedWords = words.slice(1).filter((w) => /^[A-Z][a-z]/.test(w));
2854
- if (capitalizedWords.length >= 2) return true;
2922
+ if (capitalizedWords.length >= 2)
2923
+ return true;
2855
2924
  return false;
2856
2925
  }
2857
2926
  function clampSubQueries(subQueries, maxSubQueries) {
2858
- if (subQueries.length <= maxSubQueries) return subQueries;
2927
+ if (subQueries.length <= maxSubQueries)
2928
+ return subQueries;
2859
2929
  const original = subQueries[0];
2860
2930
  const rest = subQueries.slice(1).sort((a, b) => b.weight - a.weight).slice(0, maxSubQueries - 1);
2861
2931
  return [original, ...rest];
@@ -2863,7 +2933,8 @@ function clampSubQueries(subQueries, maxSubQueries) {
2863
2933
  function extractListEntities(query) {
2864
2934
  const listPattern = /([^,]+(?:,\s*[^,]+)*,?\s*(?:and|or)\s+[^,]+)/i;
2865
2935
  const match = query.match(listPattern);
2866
- if (!match) return [];
2936
+ if (!match)
2937
+ return [];
2867
2938
  const listPortion = match[1];
2868
2939
  const entities = listPortion.split(/,\s*|\s+(?:and|or)\s+/i).map((s) => s.trim()).filter((s) => s.length >= 2);
2869
2940
  return entities.length >= 2 ? entities : [];
@@ -2977,50 +3048,42 @@ function extractKeyTerms(query) {
2977
3048
  }
2978
3049
  function decomposeQuery(query, maxSubQueries) {
2979
3050
  const trimmed = query.trim();
2980
- if (!trimmed) return [];
3051
+ if (!trimmed)
3052
+ return [];
2981
3053
  const subQueries = [];
2982
3054
  subQueries.push({
2983
3055
  query: trimmed,
2984
3056
  intent: "original query",
2985
3057
  weight: 1
2986
3058
  });
2987
- if (!isComplexQuery(trimmed)) return subQueries;
2988
- const comparativeMatch = trimmed.match(
2989
- /^(.+?)\s+(?:vs\.?|versus|compared?\s+to)\s+(.+)$/i
2990
- );
3059
+ if (!isComplexQuery(trimmed))
3060
+ return subQueries;
3061
+ const comparativeMatch = trimmed.match(/^(.+?)\s+(?:vs\.?|versus|compared?\s+to)\s+(.+)$/i);
2991
3062
  if (comparativeMatch) {
2992
3063
  const [, left, right] = comparativeMatch;
2993
- subQueries.push(
2994
- {
2995
- query: left.trim(),
2996
- intent: "comparative left side",
2997
- weight: positionalWeight(subQueries.length)
2998
- },
2999
- {
3000
- query: right.trim(),
3001
- intent: "comparative right side",
3002
- weight: positionalWeight(subQueries.length + 1)
3003
- }
3004
- );
3064
+ subQueries.push({
3065
+ query: left.trim(),
3066
+ intent: "comparative left side",
3067
+ weight: positionalWeight(subQueries.length)
3068
+ }, {
3069
+ query: right.trim(),
3070
+ intent: "comparative right side",
3071
+ weight: positionalWeight(subQueries.length + 1)
3072
+ });
3005
3073
  return clampSubQueries(subQueries, maxSubQueries);
3006
3074
  }
3007
- const diffBetween = trimmed.match(
3008
- /difference\s+between\s+(.+?)\s+and\s+(.+)/i
3009
- );
3075
+ const diffBetween = trimmed.match(/difference\s+between\s+(.+?)\s+and\s+(.+)/i);
3010
3076
  if (diffBetween) {
3011
3077
  const [, left, right] = diffBetween;
3012
- subQueries.push(
3013
- {
3014
- query: left.trim(),
3015
- intent: "comparison entity A",
3016
- weight: positionalWeight(subQueries.length)
3017
- },
3018
- {
3019
- query: right.trim(),
3020
- intent: "comparison entity B",
3021
- weight: positionalWeight(subQueries.length + 1)
3022
- }
3023
- );
3078
+ subQueries.push({
3079
+ query: left.trim(),
3080
+ intent: "comparison entity A",
3081
+ weight: positionalWeight(subQueries.length)
3082
+ }, {
3083
+ query: right.trim(),
3084
+ intent: "comparison entity B",
3085
+ weight: positionalWeight(subQueries.length + 1)
3086
+ });
3024
3087
  return clampSubQueries(subQueries, maxSubQueries);
3025
3088
  }
3026
3089
  if (CAUSAL.test(trimmed)) {
@@ -3039,9 +3102,7 @@ function decomposeQuery(query, maxSubQueries) {
3039
3102
  return clampSubQueries(subQueries, maxSubQueries);
3040
3103
  }
3041
3104
  }
3042
- const listMatch = trimmed.match(
3043
- /^(.*?)(\b\w+(?:\s+\w+)?)(?:,\s*(\b\w+(?:\s+\w+)?))+(?:,?\s*and\s+(\b\w+(?:\s+\w+)?))\b(.*)$/i
3044
- );
3105
+ const listMatch = trimmed.match(/^(.*?)(\b\w+(?:\s+\w+)?)(?:,\s*(\b\w+(?:\s+\w+)?))+(?:,?\s*and\s+(\b\w+(?:\s+\w+)?))\b(.*)$/i);
3045
3106
  if (listMatch) {
3046
3107
  const entityParts = extractListEntities(trimmed);
3047
3108
  if (entityParts.length >= 2) {
@@ -3075,14 +3136,14 @@ function decomposeQuery(query, maxSubQueries) {
3075
3136
  function generateFollowUpQueries(originalQuery, currentResults, previousSubQueries, maxSubQueries) {
3076
3137
  const followUps = [];
3077
3138
  const queryTerms = extractKeyTerms(originalQuery);
3078
- const previousQueryTexts = new Set(
3079
- previousSubQueries.map((sq) => sq.query.toLowerCase())
3080
- );
3139
+ const previousQueryTexts = new Set(previousSubQueries.map((sq) => sq.query.toLowerCase()));
3081
3140
  const contentBag = currentResults.map((r) => `${r.title} ${r.content}`).join(" ").toLowerCase();
3082
3141
  for (const term of queryTerms) {
3083
3142
  const lowerTerm = term.toLowerCase();
3084
- if (previousQueryTexts.has(lowerTerm)) continue;
3085
- if (contentBag.includes(lowerTerm)) continue;
3143
+ if (previousQueryTexts.has(lowerTerm))
3144
+ continue;
3145
+ if (contentBag.includes(lowerTerm))
3146
+ continue;
3086
3147
  followUps.push({
3087
3148
  query: term,
3088
3149
  intent: `follow-up for missing concept: ${term}`,
@@ -3090,13 +3151,10 @@ function generateFollowUpQueries(originalQuery, currentResults, previousSubQueri
3090
3151
  // Follow-ups have lower weight than initial decomposition.
3091
3152
  });
3092
3153
  }
3093
- return followUps.slice(
3094
- 0,
3095
- Math.max(1, maxSubQueries - previousSubQueries.length)
3096
- );
3154
+ return followUps.slice(0, Math.max(1, maxSubQueries - previousSubQueries.length));
3097
3155
  }
3098
3156
 
3099
- // ../chitragupta/packages/smriti/src/multi-round-retrieval.ts
3157
+ // ../chitragupta/packages/smriti/dist/multi-round-retrieval.js
3100
3158
  var DEFAULT_CONFIG2 = {
3101
3159
  maxSubQueries: 4,
3102
3160
  maxRounds: 3,
@@ -3163,12 +3221,9 @@ var AnveshanaEngine = class {
3163
3221
  previousTopScore = currentFused.length > 0 ? currentFused[0].score : 0;
3164
3222
  let allPreviousSubQueries = [...subQueries];
3165
3223
  for (let round = 1; round < this.config.maxRounds; round++) {
3166
- const followUps = this.generateFollowUp(
3167
- query,
3168
- currentFused,
3169
- allPreviousSubQueries
3170
- );
3171
- if (followUps.length === 0) break;
3224
+ const followUps = this.generateFollowUp(query, currentFused, allPreviousSubQueries);
3225
+ if (followUps.length === 0)
3226
+ break;
3172
3227
  const roundResults = await this.executeRound(followUps, round);
3173
3228
  allRounds.push(...roundResults);
3174
3229
  allPreviousSubQueries = [...allPreviousSubQueries, ...followUps];
@@ -3189,10 +3244,7 @@ var AnveshanaEngine = class {
3189
3244
  previousTopScore = newTopScore;
3190
3245
  }
3191
3246
  const finalResults = currentFused.slice(0, this.config.maxResults);
3192
- const totalRawResults = allRounds.reduce(
3193
- (sum, r) => sum + r.results.length,
3194
- 0
3195
- );
3247
+ const totalRawResults = allRounds.reduce((sum, r) => sum + r.results.length, 0);
3196
3248
  this.lastStats = {
3197
3249
  totalRounds: allRounds.length > 0 ? Math.max(...allRounds.map((r) => r.round)) + 1 : 1,
3198
3250
  subQueriesGenerated: allPreviousSubQueries.length,
@@ -3238,12 +3290,7 @@ var AnveshanaEngine = class {
3238
3290
  * @returns New sub-queries targeting unrepresented concepts.
3239
3291
  */
3240
3292
  generateFollowUp(originalQuery, currentResults, previousSubQueries) {
3241
- return generateFollowUpQueries(
3242
- originalQuery,
3243
- currentResults,
3244
- previousSubQueries,
3245
- this.config.maxSubQueries
3246
- );
3293
+ return generateFollowUpQueries(originalQuery, currentResults, previousSubQueries, this.config.maxSubQueries);
3247
3294
  }
3248
3295
  /**
3249
3296
  * Fuse results from multiple rounds with weighted scoring.
@@ -3268,12 +3315,10 @@ var AnveshanaEngine = class {
3268
3315
  if (existing) {
3269
3316
  existing.weightedScore += result.score * weight;
3270
3317
  existing.foundBy.add(round.subQuery.query);
3271
- existing.roundScores.push(
3272
- ...result.roundScores.map((rs) => ({
3273
- query: rs.query,
3274
- score: rs.score * weight
3275
- }))
3276
- );
3318
+ existing.roundScores.push(...result.roundScores.map((rs) => ({
3319
+ query: rs.query,
3320
+ score: rs.score * weight
3321
+ })));
3277
3322
  if (result.content.length > existing.content.length) {
3278
3323
  existing.content = result.content;
3279
3324
  }
@@ -3324,16 +3369,14 @@ var AnveshanaEngine = class {
3324
3369
  const roundResults = [];
3325
3370
  const tasks = subQueries.map(async (sq) => {
3326
3371
  const hybridResults = await this.hybridSearch.search(sq.query);
3327
- const multiResults = hybridResults.map(
3328
- (r) => ({
3329
- id: r.id,
3330
- title: r.title,
3331
- content: r.content,
3332
- foundBy: [sq.query],
3333
- score: r.score,
3334
- roundScores: [{ query: sq.query, score: r.score }]
3335
- })
3336
- );
3372
+ const multiResults = hybridResults.map((r) => ({
3373
+ id: r.id,
3374
+ title: r.title,
3375
+ content: r.content,
3376
+ foundBy: [sq.query],
3377
+ score: r.score,
3378
+ roundScores: [{ query: sq.query, score: r.score }]
3379
+ }));
3337
3380
  roundResults.push({
3338
3381
  subQuery: sq,
3339
3382
  results: multiResults,
@@ -3345,10 +3388,10 @@ var AnveshanaEngine = class {
3345
3388
  }
3346
3389
  };
3347
3390
 
3348
- // ../chitragupta/packages/smriti/src/smaran.ts
3391
+ // ../chitragupta/packages/smriti/dist/smaran.js
3349
3392
  import path7 from "path";
3350
3393
 
3351
- // ../chitragupta/packages/smriti/src/smaran-store.ts
3394
+ // ../chitragupta/packages/smriti/dist/smaran-store.js
3352
3395
  import fs6 from "fs";
3353
3396
  import path6 from "path";
3354
3397
  function fnv1a2(str) {
@@ -3359,7 +3402,7 @@ function fnv1a2(str) {
3359
3402
  }
3360
3403
  return hash;
3361
3404
  }
3362
- function tokenize2(text) {
3405
+ function tokenize(text) {
3363
3406
  return text.toLowerCase().replace(/[^\w\s]/g, " ").split(/\s+/).filter((t) => t.length > 1);
3364
3407
  }
3365
3408
  function extractTags(content) {
@@ -3378,7 +3421,8 @@ function extractTags(content) {
3378
3421
  [/\bschedule\b|\bcalendar\b|\bmeeting\b|\bappointment\b/, "schedule"]
3379
3422
  ];
3380
3423
  for (const [pattern, tag] of tagPatterns) {
3381
- if (pattern.test(lower)) tags.push(tag);
3424
+ if (pattern.test(lower))
3425
+ tags.push(tag);
3382
3426
  }
3383
3427
  return tags;
3384
3428
  }
@@ -3386,9 +3430,11 @@ function parseSimpleYaml(yaml) {
3386
3430
  const result = {};
3387
3431
  for (const line of yaml.split("\n")) {
3388
3432
  const trimmed = line.trim();
3389
- if (!trimmed || trimmed.startsWith("#")) continue;
3433
+ if (!trimmed || trimmed.startsWith("#"))
3434
+ continue;
3390
3435
  const colonIdx = trimmed.indexOf(":");
3391
- if (colonIdx === -1) continue;
3436
+ if (colonIdx === -1)
3437
+ continue;
3392
3438
  const key = trimmed.slice(0, colonIdx).trim();
3393
3439
  const rawValue = trimmed.slice(colonIdx + 1).trim();
3394
3440
  if (rawValue.startsWith("[") && rawValue.endsWith("]")) {
@@ -3396,9 +3442,12 @@ function parseSimpleYaml(yaml) {
3396
3442
  result[key] = inner.trim() === "" ? [] : inner.split(",").map((s) => s.trim());
3397
3443
  continue;
3398
3444
  }
3399
- if (rawValue === "null" || rawValue === "~") result[key] = null;
3400
- else if (rawValue === "true") result[key] = true;
3401
- else if (rawValue === "false") result[key] = false;
3445
+ if (rawValue === "null" || rawValue === "~")
3446
+ result[key] = null;
3447
+ else if (rawValue === "true")
3448
+ result[key] = true;
3449
+ else if (rawValue === "false")
3450
+ result[key] = false;
3402
3451
  else {
3403
3452
  const num = Number(rawValue);
3404
3453
  result[key] = !Number.isNaN(num) && rawValue !== "" ? num : rawValue;
@@ -3407,8 +3456,10 @@ function parseSimpleYaml(yaml) {
3407
3456
  return result;
3408
3457
  }
3409
3458
  function parseTags(value) {
3410
- if (Array.isArray(value)) return value.map(String);
3411
- if (typeof value === "string") return value.split(",").map((s) => s.trim()).filter(Boolean);
3459
+ if (Array.isArray(value))
3460
+ return value.map(String);
3461
+ if (typeof value === "string")
3462
+ return value.split(",").map((s) => s.trim()).filter(Boolean);
3412
3463
  return [];
3413
3464
  }
3414
3465
  function toSmaranMarkdown(entry) {
@@ -3421,7 +3472,8 @@ function toSmaranMarkdown(entry) {
3421
3472
  lines.push(entry.tags.length > 0 ? `tags: [${entry.tags.join(", ")}]` : "tags: []");
3422
3473
  lines.push(`created: ${entry.createdAt}`);
3423
3474
  lines.push(`updated: ${entry.updatedAt}`);
3424
- if (entry.sessionId) lines.push(`session: ${entry.sessionId}`);
3475
+ if (entry.sessionId)
3476
+ lines.push(`session: ${entry.sessionId}`);
3425
3477
  lines.push(`decayHalfLifeDays: ${entry.decayHalfLifeDays}`);
3426
3478
  lines.push("---");
3427
3479
  lines.push("");
@@ -3431,12 +3483,14 @@ function toSmaranMarkdown(entry) {
3431
3483
  }
3432
3484
  function fromSmaranMarkdown(content) {
3433
3485
  const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
3434
- if (!fmMatch) return null;
3486
+ if (!fmMatch)
3487
+ return null;
3435
3488
  const yaml = fmMatch[1];
3436
3489
  const body = content.slice(fmMatch[0].length).trim();
3437
3490
  const meta = parseSimpleYaml(yaml);
3438
3491
  const id = String(meta.id ?? "");
3439
- if (!id || !body) return null;
3492
+ if (!id || !body)
3493
+ return null;
3440
3494
  return {
3441
3495
  id,
3442
3496
  content: body,
@@ -3452,13 +3506,15 @@ function fromSmaranMarkdown(content) {
3452
3506
  }
3453
3507
  function loadSmaranEntries(storagePath) {
3454
3508
  const entries = /* @__PURE__ */ new Map();
3455
- if (!fs6.existsSync(storagePath)) return entries;
3509
+ if (!fs6.existsSync(storagePath))
3510
+ return entries;
3456
3511
  const files = fs6.readdirSync(storagePath).filter((f) => f.endsWith(".md"));
3457
3512
  for (const file of files) {
3458
3513
  try {
3459
3514
  const content = fs6.readFileSync(path6.join(storagePath, file), "utf-8");
3460
3515
  const entry = fromSmaranMarkdown(content);
3461
- if (entry) entries.set(entry.id, entry);
3516
+ if (entry)
3517
+ entries.set(entry.id, entry);
3462
3518
  } catch {
3463
3519
  }
3464
3520
  }
@@ -3472,32 +3528,37 @@ function saveSmaranEntry(storagePath, entry) {
3472
3528
  function deleteSmaranFile(storagePath, id) {
3473
3529
  const filePath = path6.join(storagePath, `${id}.md`);
3474
3530
  try {
3475
- if (fs6.existsSync(filePath)) fs6.unlinkSync(filePath);
3531
+ if (fs6.existsSync(filePath))
3532
+ fs6.unlinkSync(filePath);
3476
3533
  } catch {
3477
3534
  }
3478
3535
  }
3479
3536
  function findSimilarEntry(content, entries) {
3480
- const queryTerms = new Set(tokenize2(content));
3481
- if (queryTerms.size === 0) return null;
3537
+ const queryTerms = new Set(tokenize(content));
3538
+ if (queryTerms.size === 0)
3539
+ return null;
3482
3540
  for (const entry of entries) {
3483
- const entryTerms = new Set(tokenize2(entry.content));
3541
+ const entryTerms = new Set(tokenize(entry.content));
3484
3542
  let overlap = 0;
3485
3543
  for (const term of queryTerms) {
3486
- if (entryTerms.has(term)) overlap++;
3544
+ if (entryTerms.has(term))
3545
+ overlap++;
3487
3546
  }
3488
3547
  const similarity = overlap / Math.max(queryTerms.size, entryTerms.size);
3489
- if (similarity > 0.8) return entry;
3548
+ if (similarity > 0.8)
3549
+ return entry;
3490
3550
  }
3491
3551
  return null;
3492
3552
  }
3493
3553
  function scoreBM25Recall(entries, query, threshold) {
3494
- const queryTerms = tokenize2(query);
3495
- if (queryTerms.length === 0) return [];
3554
+ const queryTerms = tokenize(query);
3555
+ if (queryTerms.length === 0)
3556
+ return [];
3496
3557
  const allEntries = [];
3497
3558
  const df = /* @__PURE__ */ new Map();
3498
3559
  for (const entry of entries) {
3499
3560
  allEntries.push(entry);
3500
- const terms = new Set(tokenize2(entry.content + " " + entry.tags.join(" ")));
3561
+ const terms = new Set(tokenize(entry.content + " " + entry.tags.join(" ")));
3501
3562
  for (const term of terms) {
3502
3563
  df.set(term, (df.get(term) ?? 0) + 1);
3503
3564
  }
@@ -3510,30 +3571,33 @@ function scoreBM25Recall(entries, query, threshold) {
3510
3571
  const scored = [];
3511
3572
  for (const entry of allEntries) {
3512
3573
  const docText = (entry.content + " " + entry.tags.join(" ")).toLowerCase();
3513
- const docTerms = tokenize2(docText);
3574
+ const docTerms = tokenize(docText);
3514
3575
  let bm25 = 0;
3515
3576
  for (const qt of queryTerms) {
3516
3577
  const termFreq = docTerms.filter((t) => t === qt).length;
3517
- if (termFreq === 0) continue;
3578
+ if (termFreq === 0)
3579
+ continue;
3518
3580
  const docFreq = df.get(qt) ?? 0;
3519
3581
  const idf = Math.log((N - docFreq + 0.5) / (docFreq + 0.5) + 1);
3520
3582
  const tf = termFreq * (k1 + 1) / (termFreq + k1 * (1 - b + b * docTerms.length / avgLen));
3521
3583
  bm25 += idf * tf;
3522
3584
  }
3523
- if (docText.includes(queryLower)) bm25 *= 1.5;
3585
+ if (docText.includes(queryLower))
3586
+ bm25 *= 1.5;
3524
3587
  bm25 *= 0.5 + 0.5 * entry.confidence;
3525
3588
  if (entry.decayHalfLifeDays > 0) {
3526
3589
  const ageMs = Date.now() - new Date(entry.updatedAt).getTime();
3527
3590
  const ageDays = ageMs / (1e3 * 60 * 60 * 24);
3528
3591
  bm25 *= Math.exp(-Math.LN2 * ageDays / entry.decayHalfLifeDays);
3529
3592
  }
3530
- if (bm25 >= threshold) scored.push({ entry, score: bm25 });
3593
+ if (bm25 >= threshold)
3594
+ scored.push({ entry, score: bm25 });
3531
3595
  }
3532
3596
  scored.sort((a, b2) => b2.score - a.score);
3533
3597
  return scored;
3534
3598
  }
3535
3599
 
3536
- // ../chitragupta/packages/smriti/src/smaran.ts
3600
+ // ../chitragupta/packages/smriti/dist/smaran.js
3537
3601
  var DEFAULT_CONFIG3 = {
3538
3602
  maxEntries: 1e3,
3539
3603
  defaultDecayDays: 90,
@@ -3553,14 +3617,8 @@ var SmaranStore = class {
3553
3617
  this.config = {
3554
3618
  ...DEFAULT_CONFIG3,
3555
3619
  ...config,
3556
- maxEntries: Math.min(
3557
- config?.maxEntries ?? DEFAULT_CONFIG3.maxEntries,
3558
- SMARAN_HARD_CEILINGS.maxEntries
3559
- ),
3560
- recallLimit: Math.min(
3561
- config?.recallLimit ?? DEFAULT_CONFIG3.recallLimit,
3562
- SMARAN_HARD_CEILINGS.recallLimit
3563
- )
3620
+ maxEntries: Math.min(config?.maxEntries ?? DEFAULT_CONFIG3.maxEntries, SMARAN_HARD_CEILINGS.maxEntries),
3621
+ recallLimit: Math.min(config?.recallLimit ?? DEFAULT_CONFIG3.recallLimit, SMARAN_HARD_CEILINGS.recallLimit)
3564
3622
  };
3565
3623
  this.storagePath = this.config.storagePath ?? path7.join(getChitraguptaHome(), "smaran");
3566
3624
  }
@@ -3603,7 +3661,8 @@ var SmaranStore = class {
3603
3661
  /** Delete a memory by ID. Returns true if deleted. */
3604
3662
  forget(id) {
3605
3663
  this.ensureLoaded();
3606
- if (!this.entries.has(id)) return false;
3664
+ if (!this.entries.has(id))
3665
+ return false;
3607
3666
  this.entries.delete(id);
3608
3667
  deleteSmaranFile(this.storagePath, id);
3609
3668
  return true;
@@ -3614,7 +3673,8 @@ var SmaranStore = class {
3614
3673
  const lower = query.toLowerCase();
3615
3674
  const toDelete = [];
3616
3675
  for (const [id, entry] of this.entries) {
3617
- if (entry.content.toLowerCase().includes(lower)) toDelete.push(id);
3676
+ if (entry.content.toLowerCase().includes(lower))
3677
+ toDelete.push(id);
3618
3678
  }
3619
3679
  for (const id of toDelete) {
3620
3680
  this.entries.delete(id);
@@ -3626,11 +3686,16 @@ var SmaranStore = class {
3626
3686
  update(id, updates) {
3627
3687
  this.ensureLoaded();
3628
3688
  const entry = this.entries.get(id);
3629
- if (!entry) return null;
3630
- if (updates.content !== void 0) entry.content = updates.content;
3631
- if (updates.category !== void 0) entry.category = updates.category;
3632
- if (updates.tags !== void 0) entry.tags = updates.tags;
3633
- if (updates.confidence !== void 0) entry.confidence = updates.confidence;
3689
+ if (!entry)
3690
+ return null;
3691
+ if (updates.content !== void 0)
3692
+ entry.content = updates.content;
3693
+ if (updates.category !== void 0)
3694
+ entry.category = updates.category;
3695
+ if (updates.tags !== void 0)
3696
+ entry.tags = updates.tags;
3697
+ if (updates.confidence !== void 0)
3698
+ entry.confidence = updates.confidence;
3634
3699
  entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
3635
3700
  saveSmaranEntry(this.storagePath, entry);
3636
3701
  return entry;
@@ -3644,7 +3709,8 @@ var SmaranStore = class {
3644
3709
  /** Recall memories relevant to a query using BM25-like scoring. */
3645
3710
  recall(query, limit) {
3646
3711
  this.ensureLoaded();
3647
- if (this.entries.size === 0) return [];
3712
+ if (this.entries.size === 0)
3713
+ return [];
3648
3714
  const maxResults = limit ?? this.config.recallLimit;
3649
3715
  const scored = scoreBM25Recall(this.entries.values(), query, this.config.recallThreshold);
3650
3716
  return scored.slice(0, maxResults).map((s) => s.entry);
@@ -3654,16 +3720,15 @@ var SmaranStore = class {
3654
3720
  this.ensureLoaded();
3655
3721
  const results = [];
3656
3722
  for (const entry of this.entries.values()) {
3657
- if (entry.category === category) results.push(entry);
3723
+ if (entry.category === category)
3724
+ results.push(entry);
3658
3725
  }
3659
3726
  return results.sort((a, b) => b.confidence - a.confidence);
3660
3727
  }
3661
3728
  /** List all entries. */
3662
3729
  listAll() {
3663
3730
  this.ensureLoaded();
3664
- return [...this.entries.values()].sort(
3665
- (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
3666
- );
3731
+ return [...this.entries.values()].sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
3667
3732
  }
3668
3733
  /** Get total count of stored memories. */
3669
3734
  get size() {
@@ -3678,9 +3743,11 @@ var SmaranStore = class {
3678
3743
  */
3679
3744
  buildContextSection(query, maxTokens = 2e3) {
3680
3745
  this.ensureLoaded();
3681
- if (this.entries.size === 0) return "";
3746
+ if (this.entries.size === 0)
3747
+ return "";
3682
3748
  const entries = query ? this.recall(query, 15) : this.listAll().slice(0, 20);
3683
- if (entries.length === 0) return "";
3749
+ if (entries.length === 0)
3750
+ return "";
3684
3751
  const sections = ["## User Memory (Smaran)", ""];
3685
3752
  const grouped = /* @__PURE__ */ new Map();
3686
3753
  for (const entry of entries) {
@@ -3697,10 +3764,12 @@ var SmaranStore = class {
3697
3764
  };
3698
3765
  let totalLen = 0;
3699
3766
  for (const [category, catEntries] of grouped) {
3700
- if (totalLen >= maxTokens) break;
3767
+ if (totalLen >= maxTokens)
3768
+ break;
3701
3769
  sections.push(`### ${labels[category]}`);
3702
3770
  for (const entry of catEntries) {
3703
- if (totalLen >= maxTokens) break;
3771
+ if (totalLen >= maxTokens)
3772
+ break;
3704
3773
  const conf = entry.source === "explicit" ? "" : ` (confidence: ${entry.confidence.toFixed(1)})`;
3705
3774
  const line = `- ${entry.content}${conf}`;
3706
3775
  sections.push(line);
@@ -3717,7 +3786,8 @@ var SmaranStore = class {
3717
3786
  const now = Date.now();
3718
3787
  let modified = false;
3719
3788
  for (const entry of this.entries.values()) {
3720
- if (entry.decayHalfLifeDays <= 0) continue;
3789
+ if (entry.decayHalfLifeDays <= 0)
3790
+ continue;
3721
3791
  const ageMs = now - new Date(entry.updatedAt).getTime();
3722
3792
  const ageDays = ageMs / (1e3 * 60 * 60 * 24);
3723
3793
  const decay = Math.exp(-Math.LN2 * ageDays / entry.decayHalfLifeDays);
@@ -3749,7 +3819,8 @@ var SmaranStore = class {
3749
3819
  }
3750
3820
  // ─── Internal ─────────────────────────────────────────────────────────
3751
3821
  ensureLoaded() {
3752
- if (this.loaded) return;
3822
+ if (this.loaded)
3823
+ return;
3753
3824
  this.entries = loadSmaranEntries(this.storagePath);
3754
3825
  this.loaded = true;
3755
3826
  }
@@ -3763,7 +3834,7 @@ var SmaranStore = class {
3763
3834
  }
3764
3835
  };
3765
3836
 
3766
- // ../chitragupta/packages/smriti/src/memory-nlu.ts
3837
+ // ../chitragupta/packages/smriti/dist/memory-nlu.js
3767
3838
  var REMEMBER_PATTERNS = [
3768
3839
  { pattern: /\bremember\s+that\s+(.+)/i, contentGroup: 1 },
3769
3840
  { pattern: /\bremember\s*:\s*(.+)/i, contentGroup: 1 },
@@ -3816,7 +3887,8 @@ var CATEGORY_PATTERNS = [
3816
3887
  ];
3817
3888
  function detectMemoryIntent(text) {
3818
3889
  const trimmed = text.trim();
3819
- if (!trimmed) return null;
3890
+ if (!trimmed)
3891
+ return null;
3820
3892
  for (const pattern of FORGET_PATTERNS) {
3821
3893
  const match = trimmed.match(pattern);
3822
3894
  if (match) {
@@ -3848,7 +3920,8 @@ function detectMemoryIntent(text) {
3848
3920
  const match = trimmed.match(pattern);
3849
3921
  if (match) {
3850
3922
  const content = contentGroup === 0 ? trimmed : (match[contentGroup] ?? "").trim();
3851
- if (!content) continue;
3923
+ if (!content)
3924
+ continue;
3852
3925
  return {
3853
3926
  action: "remember",
3854
3927
  content: cleanContent(content),
@@ -3860,7 +3933,8 @@ function detectMemoryIntent(text) {
3860
3933
  }
3861
3934
  function detectCategory(content) {
3862
3935
  for (const { pattern, category } of CATEGORY_PATTERNS) {
3863
- if (pattern.test(content)) return category;
3936
+ if (pattern.test(content))
3937
+ return category;
3864
3938
  }
3865
3939
  return "fact";
3866
3940
  }
@@ -3868,7 +3942,7 @@ function cleanContent(content) {
3868
3942
  return content.replace(/[.!?]+$/, "").replace(/\s+/g, " ").trim();
3869
3943
  }
3870
3944
 
3871
- // ../chitragupta/packages/smriti/src/identity-context.ts
3945
+ // ../chitragupta/packages/smriti/dist/identity-context.js
3872
3946
  import fs7 from "fs";
3873
3947
  import path8 from "path";
3874
3948
  import os2 from "os";
@@ -3894,7 +3968,8 @@ var IdentityContext = class {
3894
3968
  */
3895
3969
  load() {
3896
3970
  const files = this.loadFiles();
3897
- if (files.length === 0) return "";
3971
+ if (files.length === 0)
3972
+ return "";
3898
3973
  const sections = [];
3899
3974
  sections.push("## Identity & Values");
3900
3975
  sections.push("");
@@ -3918,7 +3993,8 @@ var IdentityContext = class {
3918
3993
  loadUserPreferences() {
3919
3994
  const files = this.loadFiles();
3920
3995
  const userFile = files.find((f) => f.type === "user");
3921
- if (!userFile) return "";
3996
+ if (!userFile)
3997
+ return "";
3922
3998
  const content = stripFrontmatter(userFile.content);
3923
3999
  const prefSections = [];
3924
4000
  const sectionPattern = /^##\s+(.+)$/gm;
@@ -3957,7 +4033,8 @@ var IdentityContext = class {
3957
4033
  }
3958
4034
  // ─── Internal ─────────────────────────────────────────────────────────
3959
4035
  loadFiles() {
3960
- if (this.cachedFiles) return this.cachedFiles;
4036
+ if (this.cachedFiles)
4037
+ return this.cachedFiles;
3961
4038
  const include = this.config.include ?? DEFAULT_INCLUDE;
3962
4039
  const files = [];
3963
4040
  for (const type of include) {
@@ -3973,7 +4050,8 @@ var IdentityContext = class {
3973
4050
  const explicitPath = this.config.paths?.[type];
3974
4051
  if (explicitPath) {
3975
4052
  const content = readFileSafe(explicitPath);
3976
- if (content) return { type, path: explicitPath, content };
4053
+ if (content)
4054
+ return { type, path: explicitPath, content };
3977
4055
  }
3978
4056
  const searchDirs = this.getSearchDirs();
3979
4057
  const fileNames = FILE_NAMES[type];
@@ -3981,7 +4059,8 @@ var IdentityContext = class {
3981
4059
  for (const name of fileNames) {
3982
4060
  const filePath = path8.join(dir, name);
3983
4061
  const content = readFileSafe(filePath);
3984
- if (content) return { type, path: filePath, content };
4062
+ if (content)
4063
+ return { type, path: filePath, content };
3985
4064
  }
3986
4065
  }
3987
4066
  return null;
@@ -3993,7 +4072,8 @@ var IdentityContext = class {
3993
4072
  let current = this.config.projectPath;
3994
4073
  for (let i = 0; i < 3; i++) {
3995
4074
  const parent = path8.dirname(current);
3996
- if (parent === current) break;
4075
+ if (parent === current)
4076
+ break;
3997
4077
  dirs.push(parent);
3998
4078
  current = parent;
3999
4079
  }
@@ -4020,7 +4100,8 @@ function readFileSafe(filePath) {
4020
4100
  try {
4021
4101
  if (fs7.existsSync(filePath)) {
4022
4102
  const content = fs7.readFileSync(filePath, "utf-8");
4023
- if (content.trim().length > 0) return content;
4103
+ if (content.trim().length > 0)
4104
+ return content;
4024
4105
  }
4025
4106
  } catch {
4026
4107
  }
@@ -4031,7 +4112,7 @@ function stripFrontmatter(content) {
4031
4112
  return fmMatch ? content.slice(fmMatch[0].length) : content;
4032
4113
  }
4033
4114
 
4034
- // ../chitragupta/packages/smriti/src/svapna-extraction.ts
4115
+ // ../chitragupta/packages/smriti/dist/svapna-extraction.js
4035
4116
  var FNV_OFFSET2 = 2166136261;
4036
4117
  var FNV_PRIME2 = 16777619;
4037
4118
  function fnv1a3(input) {
@@ -4043,7 +4124,8 @@ function fnv1a3(input) {
4043
4124
  return hash.toString(16).padStart(8, "0");
4044
4125
  }
4045
4126
  function parseToolCalls(json) {
4046
- if (!json) return [];
4127
+ if (!json)
4128
+ return [];
4047
4129
  try {
4048
4130
  const parsed = JSON.parse(json);
4049
4131
  return Array.isArray(parsed) ? parsed : [];
@@ -4056,20 +4138,24 @@ function toolNames(calls) {
4056
4138
  }
4057
4139
  function buildToolFingerprint(names) {
4058
4140
  const fp = /* @__PURE__ */ new Set();
4059
- if (names.length === 0) return fp;
4060
- for (const name of names) fp.add(fnv1a3(`u:${name}`));
4141
+ if (names.length === 0)
4142
+ return fp;
4143
+ for (const name of names)
4144
+ fp.add(fnv1a3(`u:${name}`));
4061
4145
  for (let i = 0; i < names.length - 1; i++) {
4062
4146
  fp.add(fnv1a3(`b:${names[i]}:${names[i + 1]}`));
4063
4147
  }
4064
4148
  return fp;
4065
4149
  }
4066
4150
  function jaccardSimilarity(a, b) {
4067
- if (a.size === 0 && b.size === 0) return 0;
4151
+ if (a.size === 0 && b.size === 0)
4152
+ return 0;
4068
4153
  let intersection = 0;
4069
4154
  const smaller = a.size <= b.size ? a : b;
4070
4155
  const larger = a.size <= b.size ? b : a;
4071
4156
  for (const elem of smaller) {
4072
- if (larger.has(elem)) intersection++;
4157
+ if (larger.has(elem))
4158
+ intersection++;
4073
4159
  }
4074
4160
  const union = a.size + b.size - intersection;
4075
4161
  return union > 0 ? intersection / union : 0;
@@ -4077,18 +4163,14 @@ function jaccardSimilarity(a, b) {
4077
4163
  async function svapnaReplay(db, config) {
4078
4164
  const start = performance.now();
4079
4165
  const agentDb = db.get("agent");
4080
- const sessions = agentDb.prepare(
4081
- `SELECT id FROM sessions WHERE project = ? ORDER BY updated_at DESC LIMIT ?`
4082
- ).all(config.project, config.maxSessionsPerCycle);
4166
+ const sessions = agentDb.prepare(`SELECT id FROM sessions WHERE project = ? ORDER BY updated_at DESC LIMIT ?`).all(config.project, config.maxSessionsPerCycle);
4083
4167
  if (sessions.length === 0) {
4084
4168
  return { allTurns: [], highSurpriseTurns: [], turnsScored: 0, highSurprise: 0, durationMs: performance.now() - start };
4085
4169
  }
4086
4170
  const sessionIds = sessions.map((s) => s.id);
4087
4171
  const placeholders = sessionIds.map(() => "?").join(",");
4088
- const turns = agentDb.prepare(
4089
- `SELECT id, session_id, turn_number, role, content, tool_calls, created_at
4090
- FROM turns WHERE session_id IN (${placeholders}) ORDER BY created_at ASC`
4091
- ).all(...sessionIds);
4172
+ const turns = agentDb.prepare(`SELECT id, session_id, turn_number, role, content, tool_calls, created_at
4173
+ FROM turns WHERE session_id IN (${placeholders}) ORDER BY created_at ASC`).all(...sessionIds);
4092
4174
  const patternCounts = /* @__PURE__ */ new Map();
4093
4175
  let totalPatterns = 0;
4094
4176
  for (const turn of turns) {
@@ -4131,7 +4213,9 @@ async function svapnaReplay(db, config) {
4131
4213
  }
4132
4214
  if (scoredTurns.length > 0) {
4133
4215
  let maxSurprise = 0;
4134
- for (const st of scoredTurns) if (st.surprise > maxSurprise) maxSurprise = st.surprise;
4216
+ for (const st of scoredTurns)
4217
+ if (st.surprise > maxSurprise)
4218
+ maxSurprise = st.surprise;
4135
4219
  if (maxSurprise > 0) {
4136
4220
  for (const st of scoredTurns) {
4137
4221
  st.surprise /= maxSurprise;
@@ -4139,9 +4223,7 @@ async function svapnaReplay(db, config) {
4139
4223
  }
4140
4224
  }
4141
4225
  }
4142
- const highSurpriseTurns = scoredTurns.filter(
4143
- (st) => st.surprise >= config.surpriseThreshold
4144
- );
4226
+ const highSurpriseTurns = scoredTurns.filter((st) => st.surprise >= config.surpriseThreshold);
4145
4227
  return {
4146
4228
  allTurns: scoredTurns,
4147
4229
  highSurpriseTurns,
@@ -4159,13 +4241,12 @@ async function svapnaRecombine(db, config, highSurpriseTurns) {
4159
4241
  const sessionFingerprints = /* @__PURE__ */ new Map();
4160
4242
  const sessions = agentDb.prepare(`SELECT id FROM sessions WHERE project = ? ORDER BY updated_at DESC LIMIT ?`).all(config.project, config.maxSessionsPerCycle);
4161
4243
  for (const session of sessions) {
4162
- const turns = agentDb.prepare(
4163
- `SELECT tool_calls FROM turns
4244
+ const turns = agentDb.prepare(`SELECT tool_calls FROM turns
4164
4245
  WHERE session_id = ? AND tool_calls IS NOT NULL
4165
- ORDER BY turn_number ASC`
4166
- ).all(session.id);
4246
+ ORDER BY turn_number ASC`).all(session.id);
4167
4247
  const allNames = [];
4168
- for (const turn of turns) allNames.push(...toolNames(parseToolCalls(turn.tool_calls)));
4248
+ for (const turn of turns)
4249
+ allNames.push(...toolNames(parseToolCalls(turn.tool_calls)));
4169
4250
  if (allNames.length > 0) {
4170
4251
  const fp = buildToolFingerprint(allNames);
4171
4252
  sessionFingerprints.set(session.id, {
@@ -4179,11 +4260,13 @@ async function svapnaRecombine(db, config, highSurpriseTurns) {
4179
4260
  const MIN_SIMILARITY = 0.15;
4180
4261
  for (const st of highSurpriseTurns) {
4181
4262
  const turnToolNames = toolNames(st.toolCalls);
4182
- if (turnToolNames.length === 0) continue;
4263
+ if (turnToolNames.length === 0)
4264
+ continue;
4183
4265
  const turnFp = buildToolFingerprint(turnToolNames);
4184
4266
  const turnFpStr = [...turnFp].sort().join(",");
4185
4267
  for (const [sessionId, sessionFp] of sessionFingerprints) {
4186
- if (sessionId === st.sessionId) continue;
4268
+ if (sessionId === st.sessionId)
4269
+ continue;
4187
4270
  const sim = jaccardSimilarity(turnFp, sessionFp.fingerprint);
4188
4271
  if (sim >= MIN_SIMILARITY) {
4189
4272
  associations.push({
@@ -4202,7 +4285,7 @@ async function svapnaRecombine(db, config, highSurpriseTurns) {
4202
4285
  return { associations, crossSessions: crossSessionPairs.size, durationMs: performance.now() - start };
4203
4286
  }
4204
4287
 
4205
- // ../chitragupta/packages/smriti/src/svapna-rules.ts
4288
+ // ../chitragupta/packages/smriti/dist/svapna-rules.js
4206
4289
  var FNV_OFFSET3 = 2166136261;
4207
4290
  var FNV_PRIME3 = 16777619;
4208
4291
  function fnv1a4(input) {
@@ -4217,8 +4300,10 @@ function textSimilarity2(a, b) {
4217
4300
  const normalize = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
4218
4301
  const na = normalize(a);
4219
4302
  const nb = normalize(b);
4220
- if (na === nb) return 1;
4221
- if (na.length < 2 || nb.length < 2) return 0;
4303
+ if (na === nb)
4304
+ return 1;
4305
+ if (na.length < 2 || nb.length < 2)
4306
+ return 0;
4222
4307
  const bigrams = (s) => {
4223
4308
  const map = /* @__PURE__ */ new Map();
4224
4309
  for (let i = 0; i < s.length - 1; i++) {
@@ -4243,15 +4328,13 @@ async function svapnaCrystallize(db, config) {
4243
4328
  const agentDb = db.get("agent");
4244
4329
  let vasanasCreated = 0;
4245
4330
  let vasanasReinforced = 0;
4246
- const samskaras = agentDb.prepare(
4247
- `SELECT id, session_id, pattern_type, pattern_content,
4331
+ const samskaras = agentDb.prepare(`SELECT id, session_id, pattern_type, pattern_content,
4248
4332
  observation_count, confidence, pramana_type, project
4249
4333
  FROM samskaras
4250
4334
  WHERE (project = ? OR project IS NULL)
4251
4335
  AND observation_count >= ?
4252
4336
  AND confidence > 0.5
4253
- ORDER BY confidence DESC`
4254
- ).all(config.project, config.minPatternFrequency);
4337
+ ORDER BY confidence DESC`).all(config.project, config.minPatternFrequency);
4255
4338
  if (samskaras.length === 0) {
4256
4339
  return { vasanasCreated: 0, vasanasReinforced: 0, durationMs: performance.now() - start };
4257
4340
  }
@@ -4281,47 +4364,33 @@ async function svapnaCrystallize(db, config) {
4281
4364
  }
4282
4365
  const now = Date.now();
4283
4366
  for (const cluster of clusters) {
4284
- if (cluster.sessionIds.size < 2) continue;
4367
+ if (cluster.sessionIds.size < 2)
4368
+ continue;
4285
4369
  const tendency = slugify(cluster.representative);
4286
4370
  const vasanaId = fnv1a4(`${tendency}:${config.project}`);
4287
4371
  const existing = agentDb.prepare("SELECT id, strength, activation_count FROM vasanas WHERE name = ? AND (project = ? OR project IS NULL)").get(tendency, config.project);
4288
4372
  if (existing) {
4289
4373
  const newStrength = Math.min(1, existing.strength + 0.1);
4290
- agentDb.prepare(
4291
- `UPDATE vasanas SET strength = ?, last_activated = ?, activation_count = ?, updated_at = ?, source_samskaras = ?
4292
- WHERE id = ?`
4293
- ).run(newStrength, now, existing.activation_count + 1, now, JSON.stringify(cluster.samskaraIds), existing.id);
4374
+ agentDb.prepare(`UPDATE vasanas SET strength = ?, last_activated = ?, activation_count = ?, updated_at = ?, source_samskaras = ?
4375
+ WHERE id = ?`).run(newStrength, now, existing.activation_count + 1, now, JSON.stringify(cluster.samskaraIds), existing.id);
4294
4376
  vasanasReinforced++;
4295
4377
  } else {
4296
4378
  let valence = "neutral";
4297
- if (cluster.patternType === "correction") valence = "negative";
4379
+ if (cluster.patternType === "correction")
4380
+ valence = "negative";
4298
4381
  else if (cluster.patternType === "preference" || cluster.patternType === "convention") {
4299
4382
  valence = "positive";
4300
4383
  }
4301
- agentDb.prepare(
4302
- `INSERT INTO vasanas (name, description, valence, strength, stability,
4384
+ agentDb.prepare(`INSERT INTO vasanas (name, description, valence, strength, stability,
4303
4385
  source_samskaras, project, created_at, updated_at, last_activated, activation_count)
4304
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
4305
- ).run(
4306
- tendency,
4307
- cluster.representative,
4308
- valence,
4309
- Math.min(1, cluster.maxConfidence),
4310
- cluster.sessionIds.size / config.maxSessionsPerCycle,
4311
- JSON.stringify(cluster.samskaraIds),
4312
- config.project,
4313
- now,
4314
- now,
4315
- now,
4316
- 1
4317
- );
4386
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(tendency, cluster.representative, valence, Math.min(1, cluster.maxConfidence), cluster.sessionIds.size / config.maxSessionsPerCycle, JSON.stringify(cluster.samskaraIds), config.project, now, now, now, 1);
4318
4387
  vasanasCreated++;
4319
4388
  }
4320
4389
  }
4321
4390
  return { vasanasCreated, vasanasReinforced, durationMs: performance.now() - start };
4322
4391
  }
4323
4392
 
4324
- // ../chitragupta/packages/smriti/src/svapna-vidhi.ts
4393
+ // ../chitragupta/packages/smriti/dist/svapna-vidhi.js
4325
4394
  var FNV_OFFSET4 = 2166136261;
4326
4395
  var FNV_PRIME4 = 16777619;
4327
4396
  function fnv1a5(input) {
@@ -4344,12 +4413,14 @@ function extractNgrams(sequence, minN, maxN) {
4344
4413
  return counts;
4345
4414
  }
4346
4415
  function antiUnify(argSets) {
4347
- if (argSets.length === 0) return { template: {}, params: {} };
4416
+ if (argSets.length === 0)
4417
+ return { template: {}, params: {} };
4348
4418
  const template = {};
4349
4419
  const params = {};
4350
4420
  const allKeys = /* @__PURE__ */ new Set();
4351
4421
  for (const args of argSets) {
4352
- for (const key of Object.keys(args)) allKeys.add(key);
4422
+ for (const key of Object.keys(args))
4423
+ allKeys.add(key);
4353
4424
  }
4354
4425
  for (const key of allKeys) {
4355
4426
  const values = argSets.filter((a) => key in a).map((a) => a[key]);
@@ -4364,9 +4435,12 @@ function antiUnify(argSets) {
4364
4435
  let inferredType = "string";
4365
4436
  if (types.size === 1) {
4366
4437
  const t = [...types][0];
4367
- if (t === "number") inferredType = "number";
4368
- else if (t === "boolean") inferredType = "boolean";
4369
- else if (t === "object") inferredType = Array.isArray(values[0]) ? "array" : "object";
4438
+ if (t === "number")
4439
+ inferredType = "number";
4440
+ else if (t === "boolean")
4441
+ inferredType = "boolean";
4442
+ else if (t === "object")
4443
+ inferredType = Array.isArray(values[0]) ? "array" : "object";
4370
4444
  }
4371
4445
  params[paramName] = {
4372
4446
  name: paramName,
@@ -4380,14 +4454,15 @@ function antiUnify(argSets) {
4380
4454
  return { template, params };
4381
4455
  }
4382
4456
  function findSubsequenceStart(sequence, sub) {
4383
- if (sub.length > sequence.length) return -1;
4384
- outer:
4385
- for (let i = 0; i <= sequence.length - sub.length; i++) {
4386
- for (let j = 0; j < sub.length; j++) {
4387
- if (sequence[i + j] !== sub[j]) continue outer;
4388
- }
4389
- return i;
4457
+ if (sub.length > sequence.length)
4458
+ return -1;
4459
+ outer: for (let i = 0; i <= sequence.length - sub.length; i++) {
4460
+ for (let j = 0; j < sub.length; j++) {
4461
+ if (sequence[i + j] !== sub[j])
4462
+ continue outer;
4390
4463
  }
4464
+ return i;
4465
+ }
4391
4466
  return -1;
4392
4467
  }
4393
4468
  function generateTriggers(tools) {
@@ -4423,10 +4498,8 @@ async function svapnaProceduralize(db, config) {
4423
4498
  }
4424
4499
  const sessionToolData = [];
4425
4500
  for (const session of sessions) {
4426
- const turns = agentDb.prepare(
4427
- `SELECT tool_calls FROM turns
4428
- WHERE session_id = ? AND tool_calls IS NOT NULL ORDER BY turn_number ASC`
4429
- ).all(session.id);
4501
+ const turns = agentDb.prepare(`SELECT tool_calls FROM turns
4502
+ WHERE session_id = ? AND tool_calls IS NOT NULL ORDER BY turn_number ASC`).all(session.id);
4430
4503
  const names = [];
4431
4504
  const calls = [];
4432
4505
  let totalCalls = 0;
@@ -4437,7 +4510,8 @@ async function svapnaProceduralize(db, config) {
4437
4510
  names.push(tc.name);
4438
4511
  calls.push([tc]);
4439
4512
  totalCalls++;
4440
- if (tc.isError) errorCalls++;
4513
+ if (tc.isError)
4514
+ errorCalls++;
4441
4515
  }
4442
4516
  }
4443
4517
  if (names.length >= config.minSequenceLength) {
@@ -4470,7 +4544,8 @@ async function svapnaProceduralize(db, config) {
4470
4544
  if (startIdx >= 0) {
4471
4545
  const args = [];
4472
4546
  for (let i = 0; i < ngramToolNames.length; i++) {
4473
- if (startIdx + i >= sd.calls.length) break;
4547
+ if (startIdx + i >= sd.calls.length)
4548
+ break;
4474
4549
  const callGroup = sd.calls[startIdx + i];
4475
4550
  if (callGroup && callGroup.length > 0) {
4476
4551
  try {
@@ -4489,15 +4564,18 @@ async function svapnaProceduralize(db, config) {
4489
4564
  }
4490
4565
  const now = Date.now();
4491
4566
  for (const [ngramKey, entry] of ngramIndex) {
4492
- if (entry.sessionIds.size < 3) continue;
4567
+ if (entry.sessionIds.size < 3)
4568
+ continue;
4493
4569
  const avgSuccess = entry.successRates.reduce((s, r) => s + r, 0) / entry.successRates.length;
4494
- if (avgSuccess < config.minSuccessRate) continue;
4570
+ if (avgSuccess < config.minSuccessRate)
4571
+ continue;
4495
4572
  const steps = [];
4496
4573
  const allParams = {};
4497
4574
  for (let pos = 0; pos < entry.toolNames.length; pos++) {
4498
4575
  const posArgs = [];
4499
4576
  for (const argSet of entry.argSets) {
4500
- if (argSet[pos]) posArgs.push(argSet[pos]);
4577
+ if (argSet[pos])
4578
+ posArgs.push(argSet[pos]);
4501
4579
  }
4502
4580
  const { template, params } = antiUnify(posArgs);
4503
4581
  for (const [pName, pDef] of Object.entries(params)) {
@@ -4506,7 +4584,8 @@ async function svapnaProceduralize(db, config) {
4506
4584
  const oldRef = `\${${pName}}`;
4507
4585
  const newRef = `\${${qualifiedName}}`;
4508
4586
  for (const key of Object.keys(template)) {
4509
- if (template[key] === oldRef) template[key] = newRef;
4587
+ if (template[key] === oldRef)
4588
+ template[key] = newRef;
4510
4589
  }
4511
4590
  }
4512
4591
  steps.push({
@@ -4520,7 +4599,8 @@ async function svapnaProceduralize(db, config) {
4520
4599
  const vidhiName = slugify(ngramKey.replace(/ -> /g, "-then-"));
4521
4600
  const vidhiId = fnv1a5(`${vidhiName}:${config.project}`);
4522
4601
  const existing = agentDb.prepare("SELECT id FROM vidhis WHERE id = ?").get(vidhiId);
4523
- if (existing) continue;
4602
+ if (existing)
4603
+ continue;
4524
4604
  const vidhi = {
4525
4605
  id: vidhiId,
4526
4606
  project: config.project,
@@ -4536,33 +4616,17 @@ async function svapnaProceduralize(db, config) {
4536
4616
  createdAt: now,
4537
4617
  updatedAt: now
4538
4618
  };
4539
- agentDb.prepare(
4540
- `INSERT OR IGNORE INTO vidhis
4619
+ agentDb.prepare(`INSERT OR IGNORE INTO vidhis
4541
4620
  (id, project, name, learned_from, confidence, steps, triggers,
4542
4621
  success_rate, success_count, failure_count, parameter_schema,
4543
4622
  created_at, updated_at)
4544
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
4545
- ).run(
4546
- vidhi.id,
4547
- vidhi.project,
4548
- vidhi.name,
4549
- JSON.stringify(vidhi.learnedFrom),
4550
- vidhi.confidence,
4551
- JSON.stringify(vidhi.steps),
4552
- JSON.stringify(vidhi.triggers),
4553
- vidhi.successRate,
4554
- vidhi.successCount,
4555
- vidhi.failureCount,
4556
- JSON.stringify(vidhi.parameterSchema),
4557
- vidhi.createdAt,
4558
- vidhi.updatedAt
4559
- );
4623
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(vidhi.id, vidhi.project, vidhi.name, JSON.stringify(vidhi.learnedFrom), vidhi.confidence, JSON.stringify(vidhi.steps), JSON.stringify(vidhi.triggers), vidhi.successRate, vidhi.successCount, vidhi.failureCount, JSON.stringify(vidhi.parameterSchema), vidhi.createdAt, vidhi.updatedAt);
4560
4624
  createdVidhis.push(vidhi);
4561
4625
  }
4562
4626
  return { vidhisCreated: createdVidhis.length, vidhis: createdVidhis, durationMs: performance.now() - start };
4563
4627
  }
4564
4628
 
4565
- // ../chitragupta/packages/smriti/src/svapna-consolidation.ts
4629
+ // ../chitragupta/packages/smriti/dist/svapna-consolidation.js
4566
4630
  var DEFAULT_CONFIG4 = {
4567
4631
  maxSessionsPerCycle: 50,
4568
4632
  surpriseThreshold: 0.7,
@@ -4606,54 +4670,60 @@ var SvapnaConsolidation = class {
4606
4670
  const report = onProgress ?? (() => {
4607
4671
  });
4608
4672
  this.logCycle("running");
4609
- report("REPLAY", 0);
4610
- const replayResult = await this.replay();
4611
- report("REPLAY", 1);
4612
- report("RECOMBINE", 0);
4613
- const recombineResult = await this.recombine(replayResult.highSurpriseTurns);
4614
- report("RECOMBINE", 1);
4615
- report("CRYSTALLIZE", 0);
4616
- const crystallizeResult = await this.crystallize();
4617
- report("CRYSTALLIZE", 1);
4618
- report("PROCEDURALIZE", 0);
4619
- const proceduralizeResult = await this.proceduralize();
4620
- report("PROCEDURALIZE", 1);
4621
- report("COMPRESS", 0);
4622
- const compressResult = await this.compress();
4623
- report("COMPRESS", 1);
4624
- const totalDurationMs = performance.now() - cycleStart;
4625
- const result = {
4626
- phases: {
4627
- replay: {
4628
- turnsScored: replayResult.turnsScored,
4629
- highSurprise: replayResult.highSurprise,
4630
- durationMs: replayResult.durationMs
4631
- },
4632
- recombine: {
4633
- associations: recombineResult.associations.length,
4634
- crossSessions: recombineResult.crossSessions,
4635
- durationMs: recombineResult.durationMs
4636
- },
4637
- crystallize: {
4638
- vasanasCreated: crystallizeResult.vasanasCreated,
4639
- vasanasReinforced: crystallizeResult.vasanasReinforced,
4640
- durationMs: crystallizeResult.durationMs
4641
- },
4642
- proceduralize: {
4643
- vidhisCreated: proceduralizeResult.vidhisCreated,
4644
- durationMs: proceduralizeResult.durationMs
4673
+ try {
4674
+ report("REPLAY", 0);
4675
+ const replayResult = await this.replay();
4676
+ report("REPLAY", 1);
4677
+ report("RECOMBINE", 0);
4678
+ const recombineResult = await this.recombine(replayResult.highSurpriseTurns);
4679
+ report("RECOMBINE", 1);
4680
+ report("CRYSTALLIZE", 0);
4681
+ const crystallizeResult = await this.crystallize();
4682
+ report("CRYSTALLIZE", 1);
4683
+ report("PROCEDURALIZE", 0);
4684
+ const proceduralizeResult = await this.proceduralize();
4685
+ report("PROCEDURALIZE", 1);
4686
+ report("COMPRESS", 0);
4687
+ const compressResult = await this.compress();
4688
+ report("COMPRESS", 1);
4689
+ const totalDurationMs = performance.now() - cycleStart;
4690
+ const result = {
4691
+ phases: {
4692
+ replay: {
4693
+ turnsScored: replayResult.turnsScored,
4694
+ highSurprise: replayResult.highSurprise,
4695
+ durationMs: replayResult.durationMs
4696
+ },
4697
+ recombine: {
4698
+ associations: recombineResult.associations.length,
4699
+ crossSessions: recombineResult.crossSessions,
4700
+ durationMs: recombineResult.durationMs
4701
+ },
4702
+ crystallize: {
4703
+ vasanasCreated: crystallizeResult.vasanasCreated,
4704
+ vasanasReinforced: crystallizeResult.vasanasReinforced,
4705
+ durationMs: crystallizeResult.durationMs
4706
+ },
4707
+ proceduralize: {
4708
+ vidhisCreated: proceduralizeResult.vidhisCreated,
4709
+ durationMs: proceduralizeResult.durationMs
4710
+ },
4711
+ compress: {
4712
+ tokensCompressed: compressResult.tokensCompressed,
4713
+ compressionRatio: compressResult.compressionRatio,
4714
+ durationMs: compressResult.durationMs
4715
+ }
4645
4716
  },
4646
- compress: {
4647
- tokensCompressed: compressResult.tokensCompressed,
4648
- compressionRatio: compressResult.compressionRatio,
4649
- durationMs: compressResult.durationMs
4650
- }
4651
- },
4652
- totalDurationMs,
4653
- cycleId: this.cycleId
4654
- };
4655
- this.logCycle("success", result);
4656
- return result;
4717
+ totalDurationMs,
4718
+ cycleId: this.cycleId
4719
+ };
4720
+ this.logCycle("success", result);
4721
+ return result;
4722
+ } catch (err) {
4723
+ const msg = err instanceof Error ? err.message : String(err);
4724
+ this.logCycle("failed");
4725
+ throw new Error(`Svapna cycle ${this.cycleId} failed: ${msg}`, { cause: err });
4726
+ }
4657
4727
  }
4658
4728
  // ── Phase Delegates ─────────────────────────────────────────────────
4659
4729
  /** Phase 1: Hippocampal replay — score turns by surprise. */
@@ -4687,10 +4757,8 @@ var SvapnaConsolidation = class {
4687
4757
  }
4688
4758
  const sessionIds = sessions.map((s) => s.id);
4689
4759
  const placeholders = sessionIds.map(() => "?").join(",");
4690
- const turns = agentDb.prepare(
4691
- `SELECT id, session_id, content, tool_calls, created_at
4692
- FROM turns WHERE session_id IN (${placeholders}) ORDER BY created_at ASC`
4693
- ).all(...sessionIds);
4760
+ const turns = agentDb.prepare(`SELECT id, session_id, content, tool_calls, created_at
4761
+ FROM turns WHERE session_id IN (${placeholders}) ORDER BY created_at ASC`).all(...sessionIds);
4694
4762
  if (turns.length === 0) {
4695
4763
  return { tokensCompressed: 0, compressionRatio: 1, durationMs: performance.now() - start };
4696
4764
  }
@@ -4734,69 +4802,124 @@ var SvapnaConsolidation = class {
4734
4802
  const rawBudgets = new Array(n);
4735
4803
  for (let i = 0; i < n; i++) {
4736
4804
  let rowSum = 0;
4737
- for (let j = 0; j < n; j++) rowSum += dsMatrix[i][j];
4805
+ for (let j = 0; j < n; j++)
4806
+ rowSum += dsMatrix[i][j];
4738
4807
  rawBudgets[i] = rowSum * chunks[i].relevance;
4739
4808
  budgetTotal += rawBudgets[i];
4740
4809
  }
4741
4810
  const targetTokens = Math.floor(totalOriginalTokens * 0.7);
4742
4811
  let compressedTotal = 0;
4743
- if (budgetTotal > 0) {
4812
+ const updateStmt = agentDb.prepare(`UPDATE turns SET content = ? WHERE id = ?`);
4813
+ const insertRuleStmt = agentDb.prepare(`INSERT INTO consolidation_rules
4814
+ (project, category, rule_text, source_sessions, confidence, created_at, updated_at)
4815
+ VALUES (?, 'abstraction', ?, ?, ?, ?, ?)`);
4816
+ const compressBatch = agentDb.transaction(() => {
4744
4817
  for (let i = 0; i < n; i++) {
4745
- const budget = Math.floor(rawBudgets[i] / budgetTotal * targetTokens);
4746
- compressedTotal += Math.min(budget, chunks[i].tokenCount);
4818
+ const budget = budgetTotal > 0 ? Math.floor(rawBudgets[i] / budgetTotal * targetTokens) : Math.floor(targetTokens / n);
4819
+ const turnTokens = chunks[i].tokenCount;
4820
+ const allocated = Math.min(budget, turnTokens);
4821
+ compressedTotal += allocated;
4822
+ if (turnTokens > 20 && allocated < turnTokens * 0.6) {
4823
+ const turn = turns[i];
4824
+ const gist = this.generateGist(turn.content, allocated);
4825
+ const cueAnchors = this.extractCueAnchors(turn.content);
4826
+ updateStmt.run(gist, turn.id);
4827
+ insertRuleStmt.run(this.config.project, gist, JSON.stringify([turn.session_id]), chunks[i].relevance, Date.now(), Date.now());
4828
+ if (cueAnchors.length > 0) {
4829
+ try {
4830
+ const graphDb = this.db.get("graph");
4831
+ const upsertNode = graphDb.prepare(`INSERT OR REPLACE INTO nodes (id, type, label, content, metadata)
4832
+ VALUES (?, 'concept', ?, ?, ?)`);
4833
+ for (const cue of cueAnchors) {
4834
+ upsertNode.run(`cue-${turn.id}-${cue.slice(0, 20)}`, cue, gist.slice(0, 200), JSON.stringify({ source: `turn:${turn.id}`, cycle: this.cycleId }));
4835
+ }
4836
+ } catch {
4837
+ }
4838
+ }
4839
+ }
4747
4840
  }
4748
- } else {
4749
- compressedTotal = targetTokens;
4841
+ });
4842
+ try {
4843
+ compressBatch();
4844
+ } catch {
4750
4845
  }
4751
4846
  const compressionRatio = totalOriginalTokens > 0 ? compressedTotal / totalOriginalTokens : 1;
4752
4847
  return { tokensCompressed: totalOriginalTokens, compressionRatio, durationMs: performance.now() - start };
4753
4848
  }
4754
4849
  // ── Private Helpers ──────────────────────────────────────────────────
4850
+ /**
4851
+ * Generate a compressed gist (abstraction) of turn content.
4852
+ * Uses extractive summarization: keeps the first and last sentences,
4853
+ * plus any sentences containing tool calls or decisions.
4854
+ */
4855
+ generateGist(content, tokenBudget) {
4856
+ const sentences = content.split(/(?<=[.!?\n])\s+/).filter((s) => s.trim().length > 0);
4857
+ if (sentences.length <= 2)
4858
+ return content;
4859
+ const kept = [sentences[0]];
4860
+ const signalPattern = /\b(error|decided|created|modified|fixed|found|returned|result|output)\b/i;
4861
+ for (let i = 1; i < sentences.length - 1; i++) {
4862
+ if (signalPattern.test(sentences[i])) {
4863
+ kept.push(sentences[i]);
4864
+ }
4865
+ }
4866
+ kept.push(sentences[sentences.length - 1]);
4867
+ let gist = kept.join(" ");
4868
+ const words = gist.split(/\s+/);
4869
+ const wordBudget = Math.max(5, Math.floor(tokenBudget * 0.75));
4870
+ if (words.length > wordBudget) {
4871
+ gist = words.slice(0, wordBudget).join(" ") + "\u2026";
4872
+ }
4873
+ return `[compressed] ${gist}`;
4874
+ }
4875
+ /**
4876
+ * Extract cue anchors (trigger phrases) from turn content.
4877
+ * These serve as retrieval hooks in GraphRAG for finding compressed turns.
4878
+ */
4879
+ extractCueAnchors(content) {
4880
+ const anchors = [];
4881
+ const lower = content.toLowerCase();
4882
+ const voPattern = /\b(create|fix|refactor|implement|add|remove|update|debug|test|deploy|configure)\s+(\w+(?:\s+\w+)?)\b/gi;
4883
+ let match;
4884
+ while ((match = voPattern.exec(lower)) !== null) {
4885
+ anchors.push(match[0].trim());
4886
+ }
4887
+ const pathPattern = /[\w\-]+\.(?:ts|js|py|rs|go|java|tsx|jsx|json|yaml|toml)\b/gi;
4888
+ while ((match = pathPattern.exec(content)) !== null) {
4889
+ anchors.push(match[0]);
4890
+ }
4891
+ return [...new Set(anchors)].slice(0, 5);
4892
+ }
4755
4893
  /** Classify epistemological source (Pramana) of a turn's content. */
4756
4894
  classifyPramana(content, calls) {
4757
4895
  if (calls.length > 0 && calls.some((tc) => !tc.isError && tc.result.length > 0)) {
4758
4896
  return "pratyaksha";
4759
4897
  }
4760
4898
  const lower = content.toLowerCase();
4761
- if (/\b(?:maybe|possibly|might|perhaps|could be|not sure|unsure)\b/.test(lower)) return "anupalabdhi";
4762
- if (/\b(?:must be|likely|probably|implies|therefore)\b/.test(lower)) return "arthapatti";
4763
- if (/\b(?:similar to|like|analogous|compared to|just as)\b/.test(lower)) return "upamana";
4764
- if (/\b(?:according to|documentation|docs say|reference|specification)\b/.test(lower)) return "shabda";
4899
+ if (/\b(?:maybe|possibly|might|perhaps|could be|not sure|unsure)\b/.test(lower))
4900
+ return "anupalabdhi";
4901
+ if (/\b(?:must be|likely|probably|implies|therefore)\b/.test(lower))
4902
+ return "arthapatti";
4903
+ if (/\b(?:similar to|like|analogous|compared to|just as)\b/.test(lower))
4904
+ return "upamana";
4905
+ if (/\b(?:according to|documentation|docs say|reference|specification)\b/.test(lower))
4906
+ return "shabda";
4765
4907
  return "anumana";
4766
4908
  }
4767
4909
  /** Write an entry to the consolidation_log table for audit trail. */
4768
4910
  logCycle(status, result) {
4769
4911
  const agentDb = this.db.get("agent");
4770
- agentDb.prepare(
4771
- `INSERT INTO consolidation_log
4912
+ agentDb.prepare(`INSERT INTO consolidation_log
4772
4913
  (project, cycle_type, cycle_id, phase, phase_duration_ms,
4773
4914
  vasanas_created, vidhis_created, samskaras_processed,
4774
4915
  sessions_processed, status, created_at)
4775
- VALUES (?, 'svapna', ?, ?, ?, ?, ?, ?, ?, ?, ?)`
4776
- ).run(
4777
- this.config.project,
4778
- this.cycleId,
4779
- result ? "ALL" : null,
4780
- result?.totalDurationMs ?? null,
4781
- result?.phases.crystallize.vasanasCreated ?? 0,
4782
- result?.phases.proceduralize.vidhisCreated ?? 0,
4783
- 0,
4784
- result?.phases.replay.turnsScored ?? 0,
4785
- status,
4786
- Date.now()
4787
- );
4788
- agentDb.prepare(
4789
- `UPDATE nidra_state SET consolidation_phase = ?, consolidation_progress = ?, updated_at = ?
4790
- WHERE id = 1`
4791
- ).run(
4792
- status === "running" ? "REPLAY" : null,
4793
- status === "success" ? 1 : 0,
4794
- Date.now()
4795
- );
4916
+ VALUES (?, 'svapna', ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(this.config.project, this.cycleId, result ? "ALL" : null, result?.totalDurationMs ?? null, result?.phases.crystallize.vasanasCreated ?? 0, result?.phases.proceduralize.vidhisCreated ?? 0, 0, result?.phases.replay.turnsScored ?? 0, status, Date.now());
4917
+ agentDb.prepare(`UPDATE nidra_state SET consolidation_phase = ?, consolidation_progress = ?, updated_at = ?
4918
+ WHERE id = 1`).run(status === "running" ? "REPLAY" : null, status === "success" ? 1 : 0, Date.now());
4796
4919
  }
4797
4920
  };
4798
4921
 
4799
- // ../chitragupta/packages/smriti/src/vidhi-matching.ts
4922
+ // ../chitragupta/packages/smriti/dist/vidhi-matching.js
4800
4923
  var ACTION_VERBS = /* @__PURE__ */ new Set([
4801
4924
  "add",
4802
4925
  "create",
@@ -4973,7 +5096,7 @@ var STOPWORDS = /* @__PURE__ */ new Set([
4973
5096
  "want",
4974
5097
  "like"
4975
5098
  ]);
4976
- function tokenize3(text) {
5099
+ function tokenize2(text) {
4977
5100
  const words = text.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length > 1 && !STOPWORDS.has(w));
4978
5101
  return new Set(words);
4979
5102
  }
@@ -4981,7 +5104,8 @@ function extractVerbObjectPhrases(message) {
4981
5104
  const words = message.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length > 1);
4982
5105
  const phrases = [];
4983
5106
  for (let i = 0; i < words.length; i++) {
4984
- if (!ACTION_VERBS.has(words[i])) continue;
5107
+ if (!ACTION_VERBS.has(words[i]))
5108
+ continue;
4985
5109
  if (i + 1 < words.length) {
4986
5110
  phrases.push(`${words[i]} ${words[i + 1]}`);
4987
5111
  }
@@ -4995,7 +5119,8 @@ function extractTriggers(instances) {
4995
5119
  const phraseCounts = /* @__PURE__ */ new Map();
4996
5120
  for (const instance of instances) {
4997
5121
  const msg = instance.precedingUserMessage;
4998
- if (!msg || msg.trim().length === 0) continue;
5122
+ if (!msg || msg.trim().length === 0)
5123
+ continue;
4999
5124
  const phrases = extractVerbObjectPhrases(msg);
5000
5125
  for (const phrase of phrases) {
5001
5126
  phraseCounts.set(phrase, (phraseCounts.get(phrase) ?? 0) + 1);
@@ -5025,35 +5150,42 @@ function sampleGamma2(shape) {
5025
5150
  } while (v <= 0);
5026
5151
  v = v * v * v;
5027
5152
  const u = Math.random();
5028
- if (u < 1 - 0.0331 * (x * x) * (x * x)) return d * v;
5029
- if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
5153
+ if (u < 1 - 0.0331 * (x * x) * (x * x))
5154
+ return d * v;
5155
+ if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v)))
5156
+ return d * v;
5030
5157
  }
5031
5158
  }
5032
5159
  function sampleBeta2(alpha, beta) {
5033
5160
  const x = sampleGamma2(alpha);
5034
5161
  const y = sampleGamma2(beta);
5035
5162
  const sum = x + y;
5036
- if (sum < 1e-300 || !isFinite(sum)) return 0.5;
5163
+ if (sum < 1e-300 || !isFinite(sum))
5164
+ return 0.5;
5037
5165
  return x / sum;
5038
5166
  }
5039
5167
  function matchVidhi(vidhis, query) {
5040
- if (vidhis.length === 0) return null;
5041
- const queryTokens = tokenize3(query);
5042
- if (queryTokens.size === 0) return null;
5168
+ if (vidhis.length === 0)
5169
+ return null;
5170
+ const queryTokens = tokenize2(query);
5171
+ if (queryTokens.size === 0)
5172
+ return null;
5043
5173
  let bestVidhi = null;
5044
5174
  let bestScore = 0;
5045
5175
  for (const vidhi of vidhis) {
5046
5176
  const triggerTokens = /* @__PURE__ */ new Set();
5047
5177
  for (const trigger of vidhi.triggers) {
5048
- for (const tok of tokenize3(trigger)) {
5178
+ for (const tok of tokenize2(trigger)) {
5049
5179
  triggerTokens.add(tok);
5050
5180
  }
5051
5181
  }
5052
- if (triggerTokens.size === 0) continue;
5182
+ if (triggerTokens.size === 0)
5183
+ continue;
5053
5184
  const intersection = new Set([...queryTokens].filter((t) => triggerTokens.has(t)));
5054
5185
  const union = /* @__PURE__ */ new Set([...queryTokens, ...triggerTokens]);
5055
5186
  const jaccard = intersection.size / union.size;
5056
- if (jaccard < 0.15) continue;
5187
+ if (jaccard < 0.15)
5188
+ continue;
5057
5189
  const alpha = vidhi.successCount + 1;
5058
5190
  const beta = vidhi.failureCount + 1;
5059
5191
  const thompsonSample = sampleBeta2(alpha, beta);
@@ -5066,7 +5198,7 @@ function matchVidhi(vidhis, query) {
5066
5198
  return bestVidhi;
5067
5199
  }
5068
5200
 
5069
- // ../chitragupta/packages/smriti/src/vidhi-extraction.ts
5201
+ // ../chitragupta/packages/smriti/dist/vidhi-extraction.js
5070
5202
  var FNV_OFFSET5 = 2166136261;
5071
5203
  var FNV_PRIME5 = 16777619;
5072
5204
  function fnv1a6(str) {
@@ -5079,11 +5211,10 @@ function fnv1a6(str) {
5079
5211
  }
5080
5212
  function loadSessionSequences(config) {
5081
5213
  const db = DatabaseManager.instance().get("agent");
5082
- const sessionRows = db.prepare(
5083
- "SELECT id FROM sessions WHERE project = ?"
5084
- ).all(config.project);
5214
+ const sessionRows = db.prepare("SELECT id FROM sessions WHERE project = ?").all(config.project);
5085
5215
  const sessionIds = new Set(sessionRows.map((r) => r.id));
5086
- if (sessionIds.size === 0) return /* @__PURE__ */ new Map();
5216
+ if (sessionIds.size === 0)
5217
+ return /* @__PURE__ */ new Map();
5087
5218
  const turnRows = db.prepare(`
5088
5219
  SELECT session_id, turn_number, role, content, tool_calls
5089
5220
  FROM turns
@@ -5097,14 +5228,16 @@ function loadSessionSequences(config) {
5097
5228
  lastUserMessage = row.content;
5098
5229
  continue;
5099
5230
  }
5100
- if (row.role !== "assistant" || !row.tool_calls) continue;
5231
+ if (row.role !== "assistant" || !row.tool_calls)
5232
+ continue;
5101
5233
  let toolCalls;
5102
5234
  try {
5103
5235
  toolCalls = JSON.parse(row.tool_calls);
5104
5236
  } catch {
5105
5237
  continue;
5106
5238
  }
5107
- if (!Array.isArray(toolCalls) || toolCalls.length === 0) continue;
5239
+ if (!Array.isArray(toolCalls) || toolCalls.length === 0)
5240
+ continue;
5108
5241
  if (!result.has(row.session_id)) {
5109
5242
  result.set(row.session_id, []);
5110
5243
  }
@@ -5122,12 +5255,14 @@ function loadSessionSequences(config) {
5122
5255
  function extractAndAggregate(sessionSequences, config) {
5123
5256
  const ngramMap = /* @__PURE__ */ new Map();
5124
5257
  for (const [sessionId, sequence] of sessionSequences) {
5125
- if (sequence.length < config.minSequenceLength) continue;
5258
+ if (sequence.length < config.minSequenceLength)
5259
+ continue;
5126
5260
  for (let n = config.minSequenceLength; n <= Math.min(config.maxSequenceLength, sequence.length); n++) {
5127
5261
  for (let i = 0; i <= sequence.length - n; i++) {
5128
5262
  const window = sequence.slice(i, i + n);
5129
5263
  const hasError = window.some((w) => w.toolCall.isError === true);
5130
- if (hasError) continue;
5264
+ if (hasError)
5265
+ continue;
5131
5266
  const key = window.map((w) => w.toolCall.name).join("|");
5132
5267
  if (!ngramMap.has(key)) {
5133
5268
  ngramMap.set(key, /* @__PURE__ */ new Map());
@@ -5145,14 +5280,14 @@ function extractAndAggregate(sessionSequences, config) {
5145
5280
  }
5146
5281
  const aggregates = [];
5147
5282
  for (const [key, sessionMap] of ngramMap) {
5148
- if (sessionMap.size < config.minSessions) continue;
5283
+ if (sessionMap.size < config.minSessions)
5284
+ continue;
5149
5285
  const instances = [...sessionMap.values()];
5150
5286
  const toolNames2 = key.split("|");
5151
- const successfulInstances = instances.filter(
5152
- (inst) => inst.toolCalls.every((tc) => !tc.isError)
5153
- );
5287
+ const successfulInstances = instances.filter((inst) => inst.toolCalls.every((tc) => !tc.isError));
5154
5288
  const successRate = instances.length > 0 ? successfulInstances.length / instances.length : 0;
5155
- if (successRate < config.minSuccessRate) continue;
5289
+ if (successRate < config.minSuccessRate)
5290
+ continue;
5156
5291
  aggregates.push({
5157
5292
  key,
5158
5293
  toolNames: toolNames2,
@@ -5266,36 +5401,45 @@ function generateName(toolNames2) {
5266
5401
  function inferType(values) {
5267
5402
  const types = /* @__PURE__ */ new Set();
5268
5403
  for (const v of values) {
5269
- if (v === null || v === void 0) continue;
5270
- if (typeof v === "string") types.add("string");
5271
- else if (typeof v === "number") types.add("number");
5272
- else if (typeof v === "boolean") types.add("boolean");
5273
- else if (Array.isArray(v)) types.add("array");
5274
- else if (typeof v === "object") types.add("object");
5275
- }
5276
- if (types.size === 0) return "string";
5277
- if (types.size === 1) return [...types][0];
5404
+ if (v === null || v === void 0)
5405
+ continue;
5406
+ if (typeof v === "string")
5407
+ types.add("string");
5408
+ else if (typeof v === "number")
5409
+ types.add("number");
5410
+ else if (typeof v === "boolean")
5411
+ types.add("boolean");
5412
+ else if (Array.isArray(v))
5413
+ types.add("array");
5414
+ else if (typeof v === "object")
5415
+ types.add("object");
5416
+ }
5417
+ if (types.size === 0)
5418
+ return "string";
5419
+ if (types.size === 1)
5420
+ return [...types][0];
5278
5421
  return "string";
5279
5422
  }
5280
5423
  function deepEqual(a, b) {
5281
- if (a === b) return true;
5282
- if (a === null || b === null) return false;
5283
- if (typeof a !== typeof b) return false;
5424
+ if (a === b)
5425
+ return true;
5426
+ if (a === null || b === null)
5427
+ return false;
5428
+ if (typeof a !== typeof b)
5429
+ return false;
5284
5430
  if (typeof a === "object") {
5285
5431
  if (Array.isArray(a) && Array.isArray(b)) {
5286
- if (a.length !== b.length) return false;
5432
+ if (a.length !== b.length)
5433
+ return false;
5287
5434
  return a.every((val, idx) => deepEqual(val, b[idx]));
5288
5435
  }
5289
- if (Array.isArray(a) !== Array.isArray(b)) return false;
5436
+ if (Array.isArray(a) !== Array.isArray(b))
5437
+ return false;
5290
5438
  const keysA = Object.keys(a);
5291
5439
  const keysB = Object.keys(b);
5292
- if (keysA.length !== keysB.length) return false;
5293
- return keysA.every(
5294
- (k) => deepEqual(
5295
- a[k],
5296
- b[k]
5297
- )
5298
- );
5440
+ if (keysA.length !== keysB.length)
5441
+ return false;
5442
+ return keysA.every((k) => deepEqual(a[k], b[k]));
5299
5443
  }
5300
5444
  return false;
5301
5445
  }
@@ -5304,15 +5448,17 @@ function uniqueExamples(values, max) {
5304
5448
  const examples = [];
5305
5449
  for (const v of values) {
5306
5450
  const key = JSON.stringify(v);
5307
- if (seen.has(key)) continue;
5451
+ if (seen.has(key))
5452
+ continue;
5308
5453
  seen.add(key);
5309
5454
  examples.push(v);
5310
- if (examples.length >= max) break;
5455
+ if (examples.length >= max)
5456
+ break;
5311
5457
  }
5312
5458
  return examples;
5313
5459
  }
5314
5460
 
5315
- // ../chitragupta/packages/smriti/src/vidhi-engine.ts
5461
+ // ../chitragupta/packages/smriti/dist/vidhi-engine.js
5316
5462
  var DEFAULT_CONFIG5 = {
5317
5463
  minSessions: 3,
5318
5464
  minSuccessRate: 0.8,
@@ -5320,7 +5466,8 @@ var DEFAULT_CONFIG5 = {
5320
5466
  maxSequenceLength: 5
5321
5467
  };
5322
5468
  function safeParse(json, fallback) {
5323
- if (!json) return fallback;
5469
+ if (!json)
5470
+ return fallback;
5324
5471
  try {
5325
5472
  return JSON.parse(json);
5326
5473
  } catch {
@@ -5359,15 +5506,13 @@ var VidhiEngine = class {
5359
5506
  for (const agg of aggregates) {
5360
5507
  const existingVidhi = existingByKey.get(agg.key);
5361
5508
  if (existingVidhi) {
5509
+ const oldSize = existingVidhi.learnedFrom.length;
5362
5510
  const mergedSessions = /* @__PURE__ */ new Set([
5363
5511
  ...existingVidhi.learnedFrom,
5364
5512
  ...agg.instances.map((i) => i.sessionId)
5365
5513
  ]);
5366
5514
  existingVidhi.learnedFrom = [...mergedSessions];
5367
- existingVidhi.confidence = Math.min(
5368
- 1,
5369
- existingVidhi.confidence + 0.05 * (mergedSessions.size - existingVidhi.learnedFrom.length)
5370
- );
5515
+ existingVidhi.confidence = Math.min(1, existingVidhi.confidence + 0.05 * (mergedSessions.size - oldSize));
5371
5516
  existingVidhi.updatedAt = Date.now();
5372
5517
  this.persist(existingVidhi);
5373
5518
  reinforced.push(existingVidhi);
@@ -5408,7 +5553,8 @@ var VidhiEngine = class {
5408
5553
  */
5409
5554
  recordOutcome(vidhiId, success) {
5410
5555
  const vidhi = this.getVidhi(vidhiId);
5411
- if (!vidhi) return;
5556
+ if (!vidhi)
5557
+ return;
5412
5558
  if (success) {
5413
5559
  vidhi.successCount += 1;
5414
5560
  } else {
@@ -5461,21 +5607,7 @@ var VidhiEngine = class {
5461
5607
  success_rate, success_count, failure_count, parameter_schema,
5462
5608
  created_at, updated_at)
5463
5609
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
5464
- `).run(
5465
- vidhi.id,
5466
- vidhi.project,
5467
- vidhi.name,
5468
- JSON.stringify(vidhi.learnedFrom),
5469
- vidhi.confidence,
5470
- JSON.stringify(vidhi.steps),
5471
- JSON.stringify(vidhi.triggers),
5472
- vidhi.successRate,
5473
- vidhi.successCount,
5474
- vidhi.failureCount,
5475
- JSON.stringify(vidhi.parameterSchema),
5476
- vidhi.createdAt,
5477
- vidhi.updatedAt
5478
- );
5610
+ `).run(vidhi.id, vidhi.project, vidhi.name, JSON.stringify(vidhi.learnedFrom), vidhi.confidence, JSON.stringify(vidhi.steps), JSON.stringify(vidhi.triggers), vidhi.successRate, vidhi.successCount, vidhi.failureCount, JSON.stringify(vidhi.parameterSchema), vidhi.createdAt, vidhi.updatedAt);
5479
5611
  }
5480
5612
  /**
5481
5613
  * Load all Vidhis for a project from SQLite.
@@ -5485,9 +5617,7 @@ var VidhiEngine = class {
5485
5617
  */
5486
5618
  loadAll(project) {
5487
5619
  const db = DatabaseManager.instance().get("agent");
5488
- const rows = db.prepare(
5489
- "SELECT * FROM vidhis WHERE project = ? ORDER BY success_rate DESC"
5490
- ).all(project);
5620
+ const rows = db.prepare("SELECT * FROM vidhis WHERE project = ? ORDER BY success_rate DESC").all(project);
5491
5621
  return rows.map((r) => this._rowToVidhi(r));
5492
5622
  }
5493
5623
  // ─── Private ──────────────────────────────────────────────────────
@@ -5509,17 +5639,14 @@ var VidhiEngine = class {
5509
5639
  successRate: row.success_rate,
5510
5640
  successCount: row.success_count,
5511
5641
  failureCount: row.failure_count,
5512
- parameterSchema: safeParse(
5513
- row.parameter_schema,
5514
- {}
5515
- ),
5642
+ parameterSchema: safeParse(row.parameter_schema, {}),
5516
5643
  createdAt: row.created_at,
5517
5644
  updatedAt: row.updated_at
5518
5645
  };
5519
5646
  }
5520
5647
  };
5521
5648
 
5522
- // ../chitragupta/packages/smriti/src/akasha-integration.ts
5649
+ // ../chitragupta/packages/smriti/dist/akasha-integration.js
5523
5650
  var CREATE_TABLE_SQL = `
5524
5651
  CREATE TABLE IF NOT EXISTS akasha_traces (
5525
5652
  id TEXT PRIMARY KEY,
@@ -5557,7 +5684,8 @@ var ENSURE_TABLE_SQL = `
5557
5684
  );
5558
5685
  `;
5559
5686
  function safeParseJson(raw) {
5560
- if (!raw) return {};
5687
+ if (!raw)
5688
+ return {};
5561
5689
  try {
5562
5690
  const parsed = JSON.parse(raw);
5563
5691
  return typeof parsed === "object" && parsed !== null ? parsed : {};
@@ -5569,18 +5697,7 @@ function persistTraces(traces, db) {
5569
5697
  db.exec(CREATE_TABLE_SQL);
5570
5698
  const upsert = db.prepare(UPSERT_SQL);
5571
5699
  for (const trace of traces.values()) {
5572
- upsert.run(
5573
- trace.id,
5574
- trace.agentId,
5575
- trace.traceType,
5576
- trace.topic,
5577
- trace.content,
5578
- trace.strength,
5579
- trace.reinforcements,
5580
- JSON.stringify(trace.metadata),
5581
- trace.createdAt,
5582
- trace.lastReinforcedAt
5583
- );
5700
+ upsert.run(trace.id, trace.agentId, trace.traceType, trace.topic, trace.content, trace.strength, trace.reinforcements, JSON.stringify(trace.metadata), trace.createdAt, trace.lastReinforcedAt);
5584
5701
  }
5585
5702
  }
5586
5703
  function restoreTraces(db, config) {
@@ -5589,7 +5706,8 @@ function restoreTraces(db, config) {
5589
5706
  const traces = /* @__PURE__ */ new Map();
5590
5707
  const reinforcedBy = /* @__PURE__ */ new Map();
5591
5708
  for (const row of rows) {
5592
- if (row.strength < config.minStrength) continue;
5709
+ if (row.strength < config.minStrength)
5710
+ continue;
5593
5711
  const trace = {
5594
5712
  id: row.id,
5595
5713
  agentId: row.agent_id,
@@ -5610,7 +5728,8 @@ function restoreTraces(db, config) {
5610
5728
  function tracesToGraphNodes(traces, minStrength) {
5611
5729
  const nodes = [];
5612
5730
  for (const trace of traces.values()) {
5613
- if (trace.strength < minStrength) continue;
5731
+ if (trace.strength < minStrength)
5732
+ continue;
5614
5733
  nodes.push({
5615
5734
  id: trace.id,
5616
5735
  label: `[${trace.traceType}] ${trace.topic}`,
@@ -5622,14 +5741,15 @@ function tracesToGraphNodes(traces, minStrength) {
5622
5741
  return nodes;
5623
5742
  }
5624
5743
  function boostResultsWithTraces(traces, config, results, query) {
5625
- const queryTokens = new Set(tokenize4(query));
5744
+ const queryTokens = new Set(tokenize3(query));
5626
5745
  const matchingTraces = [];
5627
5746
  if (queryTokens.size > 0) {
5628
5747
  for (const trace of traces.values()) {
5629
- if (trace.strength < config.minStrength) continue;
5748
+ if (trace.strength < config.minStrength)
5749
+ continue;
5630
5750
  const traceTokens = /* @__PURE__ */ new Set([
5631
- ...tokenize4(trace.topic),
5632
- ...tokenize4(trace.content)
5751
+ ...tokenize3(trace.topic),
5752
+ ...tokenize3(trace.content)
5633
5753
  ]);
5634
5754
  const sim = jaccardSimilarity2(queryTokens, traceTokens);
5635
5755
  if (sim > 0) {
@@ -5641,7 +5761,7 @@ function boostResultsWithTraces(traces, config, results, query) {
5641
5761
  return results.map((result) => {
5642
5762
  let traceBoost = 0;
5643
5763
  if (queryTokens.size > 0 && matchingTraces.length > 0) {
5644
- const resultTokens = result.content ? new Set(tokenize4(result.content)) : /* @__PURE__ */ new Set();
5764
+ const resultTokens = result.content ? new Set(tokenize3(result.content)) : /* @__PURE__ */ new Set();
5645
5765
  let bestBoost = 0;
5646
5766
  for (const { trace, similarity } of matchingTraces) {
5647
5767
  if (result.id === trace.id) {
@@ -5650,8 +5770,8 @@ function boostResultsWithTraces(traces, config, results, query) {
5650
5770
  }
5651
5771
  if (resultTokens.size > 0) {
5652
5772
  const traceTokens = /* @__PURE__ */ new Set([
5653
- ...tokenize4(trace.topic),
5654
- ...tokenize4(trace.content)
5773
+ ...tokenize3(trace.topic),
5774
+ ...tokenize3(trace.content)
5655
5775
  ]);
5656
5776
  const resultSim = jaccardSimilarity2(resultTokens, traceTokens);
5657
5777
  if (resultSim > 0.1) {
@@ -5671,7 +5791,7 @@ function boostResultsWithTraces(traces, config, results, query) {
5671
5791
  });
5672
5792
  }
5673
5793
 
5674
- // ../chitragupta/packages/smriti/src/akasha.ts
5794
+ // ../chitragupta/packages/smriti/dist/akasha.js
5675
5795
  var STOP_WORDS = /* @__PURE__ */ new Set([
5676
5796
  "a",
5677
5797
  "an",
@@ -5733,14 +5853,16 @@ function fnv1a7(input) {
5733
5853
  }
5734
5854
  return hash.toString(16).padStart(8, "0");
5735
5855
  }
5736
- function tokenize4(text) {
5856
+ function tokenize3(text) {
5737
5857
  return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((t) => t.length >= 2 && !STOP_WORDS.has(t));
5738
5858
  }
5739
5859
  function jaccardSimilarity2(a, b) {
5740
- if (a.size === 0 && b.size === 0) return 1;
5860
+ if (a.size === 0 && b.size === 0)
5861
+ return 1;
5741
5862
  let intersection = 0;
5742
5863
  for (const token of a) {
5743
- if (b.has(token)) intersection++;
5864
+ if (b.has(token))
5865
+ intersection++;
5744
5866
  }
5745
5867
  const union = a.size + b.size - intersection;
5746
5868
  return union === 0 ? 0 : intersection / union;
@@ -5771,14 +5893,8 @@ var AkashaField = class {
5771
5893
  this.config = {
5772
5894
  ...DEFAULT_CONFIG6,
5773
5895
  ...config,
5774
- maxTraces: Math.min(
5775
- config?.maxTraces ?? DEFAULT_CONFIG6.maxTraces,
5776
- HARD_CEILINGS.maxTraces
5777
- ),
5778
- decayHalfLife: Math.max(
5779
- config?.decayHalfLife ?? DEFAULT_CONFIG6.decayHalfLife,
5780
- HARD_CEILINGS.minDecayHalfLife
5781
- )
5896
+ maxTraces: Math.min(config?.maxTraces ?? DEFAULT_CONFIG6.maxTraces, HARD_CEILINGS.maxTraces),
5897
+ decayHalfLife: Math.max(config?.decayHalfLife ?? DEFAULT_CONFIG6.decayHalfLife, HARD_CEILINGS.minDecayHalfLife)
5782
5898
  };
5783
5899
  }
5784
5900
  // ─── Leaving Traces ─────────────────────────────────────────────────
@@ -5810,7 +5926,8 @@ var AkashaField = class {
5810
5926
  };
5811
5927
  this.traces.set(id, trace);
5812
5928
  this.reinforcedBy.set(id, /* @__PURE__ */ new Set([agentId]));
5813
- if (this.traces.size > this.config.maxTraces) this.evictWeakest();
5929
+ if (this.traces.size > this.config.maxTraces)
5930
+ this.evictWeakest();
5814
5931
  return trace;
5815
5932
  }
5816
5933
  /**
@@ -5822,9 +5939,11 @@ var AkashaField = class {
5822
5939
  */
5823
5940
  reinforce(traceId, agentId) {
5824
5941
  const trace = this.traces.get(traceId);
5825
- if (!trace) return null;
5942
+ if (!trace)
5943
+ return null;
5826
5944
  const agents = this.reinforcedBy.get(traceId);
5827
- if (agents?.has(agentId)) return null;
5945
+ if (agents?.has(agentId))
5946
+ return null;
5828
5947
  const alpha = this.config.diminishingAlpha;
5829
5948
  const effectiveBoost = this.config.reinforcementBoost / (1 + alpha * trace.reinforcements);
5830
5949
  trace.strength = Math.min(1, trace.strength + effectiveBoost);
@@ -5846,17 +5965,21 @@ var AkashaField = class {
5846
5965
  * @returns Matching traces sorted by relevance score.
5847
5966
  */
5848
5967
  query(topic, opts) {
5849
- const queryTokens = new Set(tokenize4(topic));
5850
- if (queryTokens.size === 0) return [];
5968
+ const queryTokens = new Set(tokenize3(topic));
5969
+ if (queryTokens.size === 0)
5970
+ return [];
5851
5971
  const minStr = opts?.minStrength ?? this.config.minStrength;
5852
5972
  const limit = opts?.limit ?? this.config.topKRetrieval;
5853
5973
  const scored = [];
5854
5974
  for (const trace of this.traces.values()) {
5855
- if (trace.strength < minStr) continue;
5856
- if (opts?.type && trace.traceType !== opts.type) continue;
5857
- const traceTokens = /* @__PURE__ */ new Set([...tokenize4(trace.topic), ...tokenize4(trace.content)]);
5975
+ if (trace.strength < minStr)
5976
+ continue;
5977
+ if (opts?.type && trace.traceType !== opts.type)
5978
+ continue;
5979
+ const traceTokens = /* @__PURE__ */ new Set([...tokenize3(trace.topic), ...tokenize3(trace.content)]);
5858
5980
  const similarity = jaccardSimilarity2(queryTokens, traceTokens);
5859
- if (similarity <= 0) continue;
5981
+ if (similarity <= 0)
5982
+ continue;
5860
5983
  scored.push({ trace, score: similarity * trace.strength });
5861
5984
  }
5862
5985
  scored.sort((a, b) => b.score - a.score);
@@ -5883,7 +6006,8 @@ var AkashaField = class {
5883
6006
  byAgent(agentId, limit) {
5884
6007
  const results = [];
5885
6008
  for (const trace of this.traces.values()) {
5886
- if (trace.agentId === agentId) results.push(trace);
6009
+ if (trace.agentId === agentId)
6010
+ results.push(trace);
5887
6011
  }
5888
6012
  results.sort((a, b) => b.createdAt - a.createdAt);
5889
6013
  return results.slice(0, limit ?? this.config.topKRetrieval);
@@ -5903,7 +6027,8 @@ var AkashaField = class {
5903
6027
  const toPrune = [];
5904
6028
  for (const [id, trace] of this.traces) {
5905
6029
  const elapsed = now - trace.lastReinforcedAt;
5906
- if (elapsed <= 0) continue;
6030
+ if (elapsed <= 0)
6031
+ continue;
5907
6032
  const effectiveHalfLife = baseHalfLife * (1 + beta * Math.log(1 + trace.reinforcements));
5908
6033
  const factor = Math.exp(-Math.LN2 * elapsed / effectiveHalfLife);
5909
6034
  const newStrength = trace.strength * factor;
@@ -5911,7 +6036,8 @@ var AkashaField = class {
5911
6036
  trace.strength = newStrength;
5912
6037
  decayed++;
5913
6038
  }
5914
- if (trace.strength < this.config.minStrength) toPrune.push(id);
6039
+ if (trace.strength < this.config.minStrength)
6040
+ toPrune.push(id);
5915
6041
  }
5916
6042
  for (const id of toPrune) {
5917
6043
  this.traces.delete(id);
@@ -5927,7 +6053,8 @@ var AkashaField = class {
5927
6053
  prune() {
5928
6054
  const toPrune = [];
5929
6055
  for (const [id, trace] of this.traces) {
5930
- if (trace.strength < this.config.minStrength) toPrune.push(id);
6056
+ if (trace.strength < this.config.minStrength)
6057
+ toPrune.push(id);
5931
6058
  }
5932
6059
  for (const id of toPrune) {
5933
6060
  this.traces.delete(id);
@@ -5953,8 +6080,10 @@ var AkashaField = class {
5953
6080
  const result = restoreTraces(db, this.config);
5954
6081
  this.traces.clear();
5955
6082
  this.reinforcedBy.clear();
5956
- for (const [k, v] of result.traces) this.traces.set(k, v);
5957
- for (const [k, v] of result.reinforcedBy) this.reinforcedBy.set(k, v);
6083
+ for (const [k, v] of result.traces)
6084
+ this.traces.set(k, v);
6085
+ for (const [k, v] of result.reinforcedBy)
6086
+ this.reinforcedBy.set(k, v);
5958
6087
  }
5959
6088
  // ─── GraphRAG (delegated to akasha-integration) ──────────────────────
5960
6089
  /**
@@ -5999,7 +6128,8 @@ var AkashaField = class {
5999
6128
  byType[trace.traceType]++;
6000
6129
  totalStrength += trace.strength;
6001
6130
  totalReinforcements += trace.reinforcements;
6002
- if (trace.strength >= this.config.minStrength) activeCount++;
6131
+ if (trace.strength >= this.config.minStrength)
6132
+ activeCount++;
6003
6133
  if (!strongestTrace || trace.strength > strongestTrace.strength) {
6004
6134
  strongestTrace = trace;
6005
6135
  }
@@ -6036,7 +6166,7 @@ var AkashaField = class {
6036
6166
  }
6037
6167
  };
6038
6168
 
6039
- // ../chitragupta/packages/smriti/src/temporal-context.ts
6169
+ // ../chitragupta/packages/smriti/dist/temporal-context.js
6040
6170
  var MINUTE = 6e4;
6041
6171
  var HOUR = 36e5;
6042
6172
  var DAY = 864e5;
@@ -6230,7 +6360,7 @@ function buildTemporalContext(state, db, now) {
6230
6360
  };
6231
6361
  }
6232
6362
 
6233
- // ../chitragupta/packages/smriti/src/kala-chakra.ts
6363
+ // ../chitragupta/packages/smriti/dist/kala-chakra.js
6234
6364
  var TEMPORAL_SCALES = [
6235
6365
  "turn",
6236
6366
  "session",
@@ -6250,22 +6380,14 @@ var KalaChakra = class {
6250
6380
  if (config?.decayRates) {
6251
6381
  for (const scale of TEMPORAL_SCALES) {
6252
6382
  if (config.decayRates[scale] !== void 0) {
6253
- this._decayRates[scale] = clamp(
6254
- config.decayRates[scale],
6255
- HARD_CEILINGS2.minDecayRate,
6256
- HARD_CEILINGS2.maxDecayRate
6257
- );
6383
+ this._decayRates[scale] = clamp(config.decayRates[scale], HARD_CEILINGS2.minDecayRate, HARD_CEILINGS2.maxDecayRate);
6258
6384
  }
6259
6385
  }
6260
6386
  }
6261
6387
  if (config?.scaleWeights) {
6262
6388
  for (const scale of TEMPORAL_SCALES) {
6263
6389
  if (config.scaleWeights[scale] !== void 0) {
6264
- this._scaleWeights[scale] = clamp(
6265
- config.scaleWeights[scale],
6266
- HARD_CEILINGS2.minWeight,
6267
- HARD_CEILINGS2.maxWeight
6268
- );
6390
+ this._scaleWeights[scale] = clamp(config.scaleWeights[scale], HARD_CEILINGS2.minWeight, HARD_CEILINGS2.maxWeight);
6269
6391
  }
6270
6392
  }
6271
6393
  }
@@ -6346,7 +6468,8 @@ var KalaChakra = class {
6346
6468
  dominantScale(elapsedMs) {
6347
6469
  const abs = Math.abs(elapsedMs);
6348
6470
  for (const [threshold, scale] of SCALE_BOUNDARIES) {
6349
- if (abs < threshold) return scale;
6471
+ if (abs < threshold)
6472
+ return scale;
6350
6473
  }
6351
6474
  return "year";
6352
6475
  }
@@ -6402,26 +6525,19 @@ var KalaChakra = class {
6402
6525
  * @param data - Previously serialized state from `serialize()`.
6403
6526
  */
6404
6527
  restore(data) {
6405
- if (!data || typeof data !== "object") return;
6528
+ if (!data || typeof data !== "object")
6529
+ return;
6406
6530
  if (data.decayRates && typeof data.decayRates === "object") {
6407
6531
  for (const scale of TEMPORAL_SCALES) {
6408
6532
  if (typeof data.decayRates[scale] === "number") {
6409
- this._decayRates[scale] = clamp(
6410
- data.decayRates[scale],
6411
- HARD_CEILINGS2.minDecayRate,
6412
- HARD_CEILINGS2.maxDecayRate
6413
- );
6533
+ this._decayRates[scale] = clamp(data.decayRates[scale], HARD_CEILINGS2.minDecayRate, HARD_CEILINGS2.maxDecayRate);
6414
6534
  }
6415
6535
  }
6416
6536
  }
6417
6537
  if (data.scaleWeights && typeof data.scaleWeights === "object") {
6418
6538
  for (const scale of TEMPORAL_SCALES) {
6419
6539
  if (typeof data.scaleWeights[scale] === "number") {
6420
- this._scaleWeights[scale] = clamp(
6421
- data.scaleWeights[scale],
6422
- HARD_CEILINGS2.minWeight,
6423
- HARD_CEILINGS2.maxWeight
6424
- );
6540
+ this._scaleWeights[scale] = clamp(data.scaleWeights[scale], HARD_CEILINGS2.minWeight, HARD_CEILINGS2.maxWeight);
6425
6541
  }
6426
6542
  }
6427
6543
  }
@@ -6439,7 +6555,8 @@ var KalaChakra = class {
6439
6555
  /** Compute exponential decay for a given elapsed time and scale. */
6440
6556
  _decayForScale(elapsedMs, scale) {
6441
6557
  const halfLife = this._decayRates[scale];
6442
- if (halfLife <= 0) return 0;
6558
+ if (halfLife <= 0)
6559
+ return 0;
6443
6560
  return Math.exp(-LN2 * elapsedMs / halfLife);
6444
6561
  }
6445
6562
  };
@@ -6447,7 +6564,7 @@ function clamp(value, min, max) {
6447
6564
  return Math.max(min, Math.min(max, value));
6448
6565
  }
6449
6566
 
6450
- // ../chitragupta/packages/smriti/src/pancha-vritti-patterns.ts
6567
+ // ../chitragupta/packages/smriti/dist/pancha-vritti-patterns.js
6451
6568
  var FNV_OFFSET7 = 2166136261;
6452
6569
  var FNV_PRIME7 = 16777619;
6453
6570
  function fnv1a8(input) {
@@ -6580,7 +6697,7 @@ var SMRITI_TOOLS = /* @__PURE__ */ new Set([
6580
6697
  "chitragupta_memory_search"
6581
6698
  ]);
6582
6699
 
6583
- // ../chitragupta/packages/smriti/src/pancha-vritti.ts
6700
+ // ../chitragupta/packages/smriti/dist/pancha-vritti.js
6584
6701
  var VRITTI_TYPES = [
6585
6702
  "pramana",
6586
6703
  "viparyaya",
@@ -6620,16 +6737,10 @@ var PanchaVritti = class {
6620
6737
  }
6621
6738
  };
6622
6739
  if (typeof HARD_CEILINGS3.maxClassifications === "number") {
6623
- merged.maxClassifications = Math.min(
6624
- merged.maxClassifications,
6625
- HARD_CEILINGS3.maxClassifications
6626
- );
6740
+ merged.maxClassifications = Math.min(merged.maxClassifications, HARD_CEILINGS3.maxClassifications);
6627
6741
  }
6628
6742
  if (typeof HARD_CEILINGS3.snippetMaxLength === "number") {
6629
- merged.snippetMaxLength = Math.min(
6630
- merged.snippetMaxLength,
6631
- HARD_CEILINGS3.snippetMaxLength
6632
- );
6743
+ merged.snippetMaxLength = Math.min(merged.snippetMaxLength, HARD_CEILINGS3.snippetMaxLength);
6633
6744
  }
6634
6745
  this.cfg = merged;
6635
6746
  }
@@ -6711,9 +6822,11 @@ var PanchaVritti = class {
6711
6822
  */
6712
6823
  reclassify(id, newType, reason) {
6713
6824
  const existing = this.classifications.get(id);
6714
- if (!existing) throw new Error(`Classification not found: ${id}`);
6825
+ if (!existing)
6826
+ throw new Error(`Classification not found: ${id}`);
6715
6827
  const oldType = existing.type;
6716
- if (oldType === newType) return;
6828
+ if (oldType === newType)
6829
+ return;
6717
6830
  existing.history.push({ from: oldType, to: newType, reason, at: Date.now() });
6718
6831
  existing.type = newType;
6719
6832
  this.totalReclassified++;
@@ -6731,7 +6844,8 @@ var PanchaVritti = class {
6731
6844
  getByType(type) {
6732
6845
  const result = [];
6733
6846
  for (const c of this.classifications.values()) {
6734
- if (c.type === type) result.push(c);
6847
+ if (c.type === type)
6848
+ result.push(c);
6735
6849
  }
6736
6850
  return result;
6737
6851
  }
@@ -6790,7 +6904,8 @@ var PanchaVritti = class {
6790
6904
  /** Restore state from a serialized snapshot. */
6791
6905
  deserialize(state) {
6792
6906
  this.classifications.clear();
6793
- for (const c of state.classifications) this.classifications.set(c.id, c);
6907
+ for (const c of state.classifications)
6908
+ this.classifications.set(c.id, c);
6794
6909
  this.totalClassified = state.totalClassified;
6795
6910
  this.totalReclassified = state.totalReclassified;
6796
6911
  }
@@ -6852,12 +6967,13 @@ var PanchaVritti = class {
6852
6967
  oldestId = id;
6853
6968
  }
6854
6969
  }
6855
- if (oldestId) this.classifications.delete(oldestId);
6970
+ if (oldestId)
6971
+ this.classifications.delete(oldestId);
6856
6972
  }
6857
6973
  }
6858
6974
  };
6859
6975
 
6860
- // ../chitragupta/packages/smriti/src/unified-recall.ts
6976
+ // ../chitragupta/packages/smriti/dist/unified-recall.js
6861
6977
  async function recall(query, options) {
6862
6978
  const limit = options?.limit ?? 5;
6863
6979
  const answers = [];
@@ -6905,37 +7021,35 @@ async function recall(query, options) {
6905
7021
  }
6906
7022
  async function searchHybrid(query, project, limit) {
6907
7023
  try {
6908
- const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-G2NAJKJ7.js");
7024
+ const { HybridSearchEngine: HybridSearchEngine2 } = await import("./hybrid-search-BYTXCOXP.js");
6909
7025
  let recallEngine = null;
6910
7026
  let graphEngine = null;
6911
7027
  try {
6912
- const { RecallEngine: RecallEngine2 } = await import("./recall-ZNL4DJ2L.js");
7028
+ const { RecallEngine: RecallEngine2 } = await import("./recall-LNRQVATQ.js");
6913
7029
  recallEngine = new RecallEngine2();
6914
7030
  } catch {
6915
7031
  }
6916
7032
  try {
6917
- const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-D7OXWAWD.js");
7033
+ const { GraphRAGEngine: GraphRAGEngine2 } = await import("./graphrag-T2QWNX57.js");
6918
7034
  graphEngine = new GraphRAGEngine2();
6919
7035
  } catch {
6920
7036
  }
6921
- const hybrid = new HybridSearchEngine2(
6922
- {
6923
- project,
6924
- topK: limit ?? 10,
6925
- enableBM25: true,
6926
- enableVector: recallEngine !== null,
6927
- enableGraphRAG: graphEngine !== null,
6928
- enablePramana: true
6929
- },
6930
- recallEngine ?? void 0,
6931
- graphEngine ?? void 0
6932
- );
7037
+ const hybrid = new HybridSearchEngine2({
7038
+ project,
7039
+ topK: limit ?? 10,
7040
+ enableBM25: true,
7041
+ enableVector: recallEngine !== null,
7042
+ enableGraphRAG: graphEngine !== null,
7043
+ enablePramana: true
7044
+ }, recallEngine ?? void 0, graphEngine ?? void 0);
6933
7045
  const results = await hybrid.search(query);
6934
7046
  return results.map((r) => {
6935
7047
  let primarySource = "hybrid";
6936
7048
  if (r.sources.length === 1) {
6937
- if (r.sources[0] === "bm25") primarySource = "turns";
6938
- else if (r.sources[0] === "graphrag") primarySource = "graph";
7049
+ if (r.sources[0] === "bm25")
7050
+ primarySource = "turns";
7051
+ else if (r.sources[0] === "graphrag")
7052
+ primarySource = "graph";
6939
7053
  }
6940
7054
  const normalizedScore = Math.min(r.score / (r.score + 0.5), 1);
6941
7055
  return {
@@ -6952,8 +7066,8 @@ async function searchHybrid(query, project, limit) {
6952
7066
  }
6953
7067
  async function searchTurns(query, project) {
6954
7068
  try {
6955
- const { searchSessions: searchSessions2 } = await import("./search-35JMSGUT.js");
6956
- const { loadSession: loadSession2 } = await import("./session-store-3BRPGC6P.js");
7069
+ const { searchSessions: searchSessions2 } = await import("./search-BIODUW2P.js");
7070
+ const { loadSession: loadSession2 } = await import("./session-store-O3TS7DUY.js");
6957
7071
  const metas = searchSessions2(query, project);
6958
7072
  const results = [];
6959
7073
  for (const meta of metas.slice(0, 10)) {
@@ -6966,7 +7080,8 @@ async function searchTurns(query, project) {
6966
7080
  const content = turn.content.toLowerCase();
6967
7081
  let termHits = 0;
6968
7082
  for (const term of queryTerms) {
6969
- if (term.length > 2 && content.includes(term)) termHits++;
7083
+ if (term.length > 2 && content.includes(term))
7084
+ termHits++;
6970
7085
  }
6971
7086
  const score = queryTerms.length > 0 ? termHits / queryTerms.length : 0;
6972
7087
  if (score > bestScore) {
@@ -6999,7 +7114,7 @@ async function searchTurns(query, project) {
6999
7114
  }
7000
7115
  async function searchMemoryLayer(query) {
7001
7116
  try {
7002
- const { searchMemory: searchMemory2 } = await import("./search-35JMSGUT.js");
7117
+ const { searchMemory: searchMemory2 } = await import("./search-BIODUW2P.js");
7003
7118
  const results = searchMemory2(query);
7004
7119
  return results.slice(0, 5).map((r) => ({
7005
7120
  score: Math.min((r.relevance ?? 0.5) + 0.1, 1),
@@ -7013,7 +7128,7 @@ async function searchMemoryLayer(query) {
7013
7128
  }
7014
7129
  async function searchDayFileLayer(query, limit) {
7015
7130
  try {
7016
- const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-PVHVA3NZ.js");
7131
+ const { hierarchicalTemporalSearch: hierarchicalTemporalSearch2 } = await import("./hierarchical-temporal-search-U6DG74IR.js");
7017
7132
  const results = await hierarchicalTemporalSearch2(query, { limit });
7018
7133
  if (results.length > 0) {
7019
7134
  return results.map((r) => ({
@@ -7028,7 +7143,7 @@ async function searchDayFileLayer(query, limit) {
7028
7143
  } catch {
7029
7144
  }
7030
7145
  try {
7031
- const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-BH3QU2SZ.js");
7146
+ const { searchDayFiles: searchDayFiles2 } = await import("./day-consolidation-HMHSXIOM.js");
7032
7147
  const results = searchDayFiles2(query, { limit });
7033
7148
  return results.map((r) => ({
7034
7149
  score: 0.5,
@@ -7045,13 +7160,14 @@ function deduplicateAnswers(answers) {
7045
7160
  const seen = /* @__PURE__ */ new Set();
7046
7161
  return answers.filter((a) => {
7047
7162
  const key = a.sessionId ? `session:${a.sessionId}` : `${a.primarySource}:${a.snippet.slice(0, 50).toLowerCase()}`;
7048
- if (seen.has(key)) return false;
7163
+ if (seen.has(key))
7164
+ return false;
7049
7165
  seen.add(key);
7050
7166
  return true;
7051
7167
  });
7052
7168
  }
7053
7169
 
7054
- // ../chitragupta/packages/smriti/src/provider-bridge.ts
7170
+ // ../chitragupta/packages/smriti/dist/provider-bridge.js
7055
7171
  async function loadProviderContext(project, options) {
7056
7172
  const maxLen = options?.maxContextLength ?? 4e3;
7057
7173
  const recentLimit = options?.recentSessionLimit ?? 3;
@@ -7059,7 +7175,7 @@ async function loadProviderContext(project, options) {
7059
7175
  let projectMemory = "";
7060
7176
  let recentContext = "";
7061
7177
  try {
7062
- const { getMemory: getMemory2 } = await import("./memory-store-A6WOWLWC.js");
7178
+ const { getMemory: getMemory2 } = await import("./memory-store-LEERUQGL.js");
7063
7179
  globalFacts = getMemory2({ type: "global" });
7064
7180
  if (globalFacts.length > maxLen / 3) {
7065
7181
  globalFacts = globalFacts.slice(0, maxLen / 3) + "\n...(truncated)";
@@ -7068,7 +7184,7 @@ async function loadProviderContext(project, options) {
7068
7184
  }
7069
7185
  if (project) {
7070
7186
  try {
7071
- const { getMemory: getMemory2 } = await import("./memory-store-A6WOWLWC.js");
7187
+ const { getMemory: getMemory2 } = await import("./memory-store-LEERUQGL.js");
7072
7188
  projectMemory = getMemory2({ type: "project", path: project });
7073
7189
  if (projectMemory.length > maxLen / 3) {
7074
7190
  projectMemory = projectMemory.slice(0, maxLen / 3) + "\n...(truncated)";
@@ -7078,18 +7194,16 @@ async function loadProviderContext(project, options) {
7078
7194
  }
7079
7195
  let vasanaContext = "";
7080
7196
  try {
7081
- const { VasanaEngine: VasanaEngine2 } = await import("./vasana-engine-MU25OQ23.js");
7197
+ const { VasanaEngine: VasanaEngine2 } = await import("./vasana-engine-BJFHJVGM.js");
7082
7198
  const engine = new VasanaEngine2();
7083
7199
  const vasanas = engine.getVasanas(project ?? "__global__", 5);
7084
7200
  if (vasanas.length > 0) {
7085
- vasanaContext = vasanas.map(
7086
- (v) => `- ${v.tendency} (strength: ${(v.strength * 100).toFixed(0)}%): ${v.description}`
7087
- ).join("\n");
7201
+ vasanaContext = vasanas.map((v) => `- ${v.tendency} (strength: ${(v.strength * 100).toFixed(0)}%): ${v.description}`).join("\n");
7088
7202
  }
7089
7203
  } catch {
7090
7204
  }
7091
7205
  try {
7092
- const { listSessions: listSessions2, loadSession: loadSession2 } = await import("./session-store-3BRPGC6P.js");
7206
+ const { listSessions: listSessions2, loadSession: loadSession2 } = await import("./session-store-O3TS7DUY.js");
7093
7207
  const sessions = project ? listSessions2(project).slice(0, recentLimit) : listSessions2().slice(0, recentLimit);
7094
7208
  const summaries = [];
7095
7209
  for (const meta of sessions) {
@@ -7181,4 +7295,4 @@ export {
7181
7295
  recall,
7182
7296
  loadProviderContext
7183
7297
  };
7184
- //# sourceMappingURL=chunk-AGK3A7R7.js.map
7298
+ //# sourceMappingURL=chunk-VCUJES75.js.map