@loreai/core 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"recall.d.ts","sourceRoot":"","sources":["../../src/recall.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAczC,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtE,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mFAAmF;IACnF,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;CACrC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AA+JlC,wFAAwF;AACxF,wBAAsB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAqNzE;AAED,sEAAsE;AACtE,eAAO,MAA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EAAmE;AACnE,eAAO,MAAM,yBAAyB;;;CAIrC,CAAC"}
@@ -68,6 +68,21 @@ export declare function searchScored(input: {
68
68
  sessionID?: string;
69
69
  limit?: number;
70
70
  }): ScoredTemporalMessage[];
71
+ /**
72
+ * Normalized variance of relative-existence weights over message timestamps.
73
+ *
74
+ * Measures temporal attention imbalance: 0 means timestamps are evenly
75
+ * distributed (uniform attention), 1 means a single distant timestamp
76
+ * dominates (attention stuck in the past). Useful as a lightweight
77
+ * signal for distillation segmentation, recall time-biasing, and
78
+ * idle-resume awareness.
79
+ *
80
+ * Only meaningful for n ≥ 2. Returns 0 for 0 or 1 timestamps.
81
+ *
82
+ * Based on the "Temporal Clustering via Relative Existence" heuristic
83
+ * from D7x7z49/llm-context-idea.
84
+ */
85
+ export declare function temporalCnorm(timestamps: number[], now?: number): number;
71
86
  export declare function count(projectPath: string, sessionID?: string): number;
72
87
  export declare function undistilledCount(projectPath: string, sessionID?: string): number;
73
88
  export type PruneResult = {
@@ -1 +1 @@
1
- {"version":3,"file":"temporal.d.ts","sourceRoot":"","sources":["../../src/temporal.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQrD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,WAAS,CAAC;AAEvC;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAarD;AAiBD,wBAAgB,KAAK,CAAC,KAAK,EAAE;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB,QAqCA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,O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YxE"}
@@ -3,6 +3,32 @@ import { workerSessionIDs } from "./worker";
3
3
  import type { LLMClient } from "./types";
4
4
  export { workerSessionIDs };
5
5
  type TemporalMessage = temporal.TemporalMessage;
6
+ /**
7
+ * Compression health ratio: k / √N.
8
+ *
9
+ * k = distilled token count, N = source token count.
10
+ * Values < 1.0 signal likely lossy compression (below the square-root
11
+ * boundary). Values > 1.0 signal relatively faithful compression.
12
+ *
13
+ * Based on the "LLM Context Square Root Theory" heuristic from
14
+ * D7x7z49/llm-context-idea. The specific threshold is unvalidated —
15
+ * use as a diagnostic signal, not a hard gate.
16
+ */
17
+ export declare function compressionRatio(distilledTokens: number, sourceTokens: number): number;
18
+ /**
19
+ * Segment detection: group related messages into distillation-sized chunks.
20
+ *
21
+ * When the message count exceeds `maxSegment`, prefers splitting at the
22
+ * largest inter-message time gap (if it's ≥ 3× the median gap) to respect
23
+ * natural conversation boundaries. Falls back to count-based splitting at
24
+ * `maxSegment` when timestamps are uniform.
25
+ *
26
+ * Trailing segments with < 3 messages are merged into the previous segment
27
+ * to avoid tiny distillation inputs with too little context.
28
+ *
29
+ * Exported for testing; `run()` is the production caller.
30
+ */
31
+ export declare function detectSegments(messages: TemporalMessage[], maxSegment: number): TemporalMessage[][];
6
32
  /**
7
33
  * Truncate tool outputs within a `TemporalMessage.content` string (produced
8
34
  * by `temporal.partsToText`). Plain text and `[reasoning]` chunks pass
@@ -1 +1 @@
1
- {"version":3,"file":"distillation.d.ts","sourceRoot":"","sources":["../../src/distillation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAWvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,KAAK,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;AAmDhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,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AAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CA+ErC"}
@@ -131,6 +131,7 @@ __export(temporal_exports, {
131
131
  search: () => search2,
132
132
  searchScored: () => searchScored,
133
133
  store: () => store,
134
+ temporalCnorm: () => temporalCnorm,
134
135
  undistilled: () => undistilled,
135
136
  undistilledCount: () => undistilledCount
136
137
  });
@@ -525,16 +526,47 @@ function migrate(database) {
525
526
  "SELECT name FROM sqlite_master WHERE type='table' AND name='schema_version'"
526
527
  ).get();
527
528
  const current2 = row ? database.query("SELECT version FROM schema_version").get()?.version ?? 0 : 0;
528
- if (current2 >= MIGRATIONS.length) return;
529
+ if (current2 >= MIGRATIONS.length) {
530
+ recoverMissingObjects(database);
531
+ return;
532
+ }
529
533
  for (let i = current2; i < MIGRATIONS.length; i++) {
530
534
  if (i === VACUUM_MIGRATION_INDEX) {
531
535
  database.exec("PRAGMA auto_vacuum = INCREMENTAL");
532
536
  database.exec("VACUUM");
533
537
  } else {
534
- database.exec(MIGRATIONS[i]);
538
+ try {
539
+ database.exec(MIGRATIONS[i]);
540
+ } catch (e) {
541
+ if (e instanceof Error && /duplicate column name/i.test(e.message)) {
542
+ const stripped = stripAppliedAlters(MIGRATIONS[i], database);
543
+ if (stripped.trim()) database.exec(stripped);
544
+ } else {
545
+ throw e;
546
+ }
547
+ }
535
548
  }
536
549
  }
537
550
  database.exec(`UPDATE schema_version SET version = ${MIGRATIONS.length}`);
551
+ recoverMissingObjects(database);
552
+ }
553
+ function stripAppliedAlters(migration, database) {
554
+ return migration.replace(
555
+ /ALTER\s+TABLE\s+(\w+)\s+ADD\s+COLUMN\s+(\w+)\b[^;]*;/gi,
556
+ (match, table, column) => {
557
+ const cols = database.query(`PRAGMA table_info(${table})`).all();
558
+ if (cols.some((c) => c.name === column)) return "";
559
+ return match;
560
+ }
561
+ );
562
+ }
563
+ function recoverMissingObjects(database) {
564
+ database.exec(`
565
+ CREATE TABLE IF NOT EXISTS kv_meta (
566
+ key TEXT PRIMARY KEY,
567
+ value TEXT NOT NULL
568
+ );
569
+ `);
538
570
  }
539
571
  function close() {
540
572
  if (instance) {
@@ -11440,6 +11472,18 @@ function searchScored(input) {
11440
11472
  return [];
11441
11473
  }
11442
11474
  }
11475
+ function temporalCnorm(timestamps, now = Date.now()) {
11476
+ const n = timestamps.length;
11477
+ if (n < 2) return 0;
11478
+ const durations = timestamps.map((t2) => now - t2);
11479
+ const totalDuration = durations.reduce((a, b) => a + b, 0);
11480
+ if (totalDuration <= 0) return 0;
11481
+ const weights = durations.map((d) => d / totalDuration);
11482
+ const uniform = 1 / n;
11483
+ const variance = weights.reduce((sum, w) => sum + (w - uniform) ** 2, 0) / n;
11484
+ const maxVariance = (n - 1) / (n * n);
11485
+ return maxVariance === 0 ? 0 : variance / maxVariance;
11486
+ }
11443
11487
  function count(projectPath, sessionID) {
11444
11488
  const pid = ensureProject(projectPath);
11445
11489
  const query = sessionID ? "SELECT COUNT(*) as count FROM temporal_messages WHERE project_id = ? AND session_id = ?" : "SELECT COUNT(*) as count FROM temporal_messages WHERE project_id = ?";
@@ -26757,6 +26801,8 @@ function check2(projectPath) {
26757
26801
  // src/distillation.ts
26758
26802
  var distillation_exports = {};
26759
26803
  __export(distillation_exports, {
26804
+ compressionRatio: () => compressionRatio,
26805
+ detectSegments: () => detectSegments,
26760
26806
  latestMetaObservations: () => latestMetaObservations,
26761
26807
  loadForSession: () => loadForSession,
26762
26808
  messagesToText: () => messagesToText,
@@ -27614,25 +27660,50 @@ function isWorkerSession(sessionID) {
27614
27660
  }
27615
27661
 
27616
27662
  // src/distillation.ts
27663
+ function compressionRatio(distilledTokens, sourceTokens) {
27664
+ if (sourceTokens <= 0) return 0;
27665
+ return distilledTokens / Math.sqrt(sourceTokens);
27666
+ }
27617
27667
  function detectSegments(messages, maxSegment) {
27618
27668
  if (messages.length <= maxSegment) return [messages];
27619
- const segments = [];
27620
- let current2 = [];
27621
- for (const msg of messages) {
27622
- current2.push(msg);
27623
- if (current2.length >= maxSegment) {
27624
- segments.push(current2);
27625
- current2 = [];
27626
- }
27627
- }
27628
- if (current2.length > 0) {
27629
- if (current2.length < 3 && segments.length > 0) {
27630
- segments[segments.length - 1].push(...current2);
27631
- } else {
27632
- segments.push(current2);
27669
+ return splitSegments(messages, maxSegment);
27670
+ }
27671
+ var MIN_SEGMENT = 3;
27672
+ var GAP_THRESHOLD_MULTIPLIER = 3;
27673
+ function splitSegments(messages, maxSegment) {
27674
+ if (messages.length <= maxSegment) return [messages];
27675
+ const splitIdx = findSplitIndex(messages, maxSegment);
27676
+ const left = messages.slice(0, splitIdx);
27677
+ const right = messages.slice(splitIdx);
27678
+ const result = splitSegments(left, maxSegment);
27679
+ if (right.length < MIN_SEGMENT) {
27680
+ result[result.length - 1].push(...right);
27681
+ } else {
27682
+ result.push(...splitSegments(right, maxSegment));
27683
+ }
27684
+ return result;
27685
+ }
27686
+ function findSplitIndex(messages, maxSegment) {
27687
+ const gaps = [];
27688
+ for (let i = 1; i < messages.length; i++) {
27689
+ gaps.push({
27690
+ index: i,
27691
+ gap: messages[i].created_at - messages[i - 1].created_at
27692
+ });
27693
+ }
27694
+ if (gaps.length === 0) return maxSegment;
27695
+ const sortedGaps = gaps.map((g) => g.gap).sort((a, b) => a - b);
27696
+ const medianGap = sortedGaps[Math.floor(sortedGaps.length / 2)];
27697
+ let bestGap = { index: -1, gap: 0 };
27698
+ for (const g of gaps) {
27699
+ if (g.gap > bestGap.gap && g.index >= MIN_SEGMENT && messages.length - g.index >= MIN_SEGMENT) {
27700
+ bestGap = g;
27633
27701
  }
27634
27702
  }
27635
- return segments;
27703
+ if (bestGap.index > 0 && bestGap.gap >= medianGap * GAP_THRESHOLD_MULTIPLIER) {
27704
+ return bestGap.index;
27705
+ }
27706
+ return maxSegment;
27636
27707
  }
27637
27708
  function formatTime(ms) {
27638
27709
  const d = new Date(ms);
@@ -27870,6 +27941,13 @@ async function distillSegment(input) {
27870
27941
  generation: 0
27871
27942
  });
27872
27943
  markDistilled(input.messages.map((m) => m.id));
27944
+ const distilledTokens = Math.ceil(result.observations.length / 3);
27945
+ const sourceTokens = input.messages.reduce((sum, m) => sum + m.tokens, 0);
27946
+ const rComp = compressionRatio(distilledTokens, sourceTokens);
27947
+ const cNorm = temporalCnorm(input.messages.map((m) => m.created_at));
27948
+ info(
27949
+ `distill segment: ${input.messages.length} msgs, ${sourceTokens}\u2192${distilledTokens} tokens, R=${rComp.toFixed(2)}, C_norm=${cNorm.toFixed(3)}`
27950
+ );
27873
27951
  if (isAvailable()) {
27874
27952
  embedDistillation(distillId, result.observations);
27875
27953
  }
@@ -28234,6 +28312,18 @@ async function runRecall(input) {
28234
28312
  key: (r) => `t:${r.item.id}`
28235
28313
  }
28236
28314
  );
28315
+ if (temporalResults.length > 0) {
28316
+ const recencySorted = [...temporalResults].sort(
28317
+ (a, b) => b.created_at - a.created_at
28318
+ );
28319
+ allRrfLists.push({
28320
+ items: recencySorted.map((item) => ({
28321
+ source: "temporal",
28322
+ item
28323
+ })),
28324
+ key: (r) => `t:${r.item.id}`
28325
+ });
28326
+ }
28237
28327
  }
28238
28328
  if (isAvailable() && scope !== "session") {
28239
28329
  try {