@caupulican/pi-adaptative 0.80.60 → 0.80.61

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.
@@ -34,6 +34,7 @@ import { emitSessionShutdownEvent } from "./extensions/runner.js";
34
34
  import { decideDemand, ReflectionEngine, } from "./learning/reflection-engine.js";
35
35
  import { MemoryManager } from "./memory/memory-manager.js";
36
36
  import { FileStoreProvider } from "./memory/providers/file-store.js";
37
+ import { TranscriptRecallProvider } from "./memory/providers/transcript-recall.js";
37
38
  import { compactToolResultDetailsForRetention } from "./message-retention.js";
38
39
  import { resolveProfileModelSettings } from "./model-resolver.js";
39
40
  import { expandPromptTemplate } from "./prompt-templates.js";
@@ -960,6 +961,18 @@ export class AgentSession {
960
961
  }
961
962
  return this._promptUnserialized(text, options);
962
963
  }
964
+ /**
965
+ * Zero-I/O gate for cross-session recall (R3): skip trivial turns (short acks, slash commands) so
966
+ * recall only runs when it could plausibly help. The provider's similarity cutoff is the real
967
+ * filter — this just avoids the index query on turns that obviously don't warrant it.
968
+ */
969
+ _shouldAttemptRecall(text) {
970
+ const t = text.trim();
971
+ if (t.length < 12 || t.startsWith("/"))
972
+ return false;
973
+ const words = t.split(/\s+/).filter((w) => w.length >= 3);
974
+ return words.length >= 3;
975
+ }
963
976
  async _promptUnserialized(text, options) {
964
977
  const expandPromptTemplates = options?.expandPromptTemplates ?? true;
965
978
  const processSlashCommands = options?.processSlashCommands ?? expandPromptTemplates;
@@ -1043,8 +1056,23 @@ export class AgentSession {
1043
1056
  if (lastAssistant) {
1044
1057
  await this._checkCompaction(lastAssistant, false);
1045
1058
  }
1046
- // Build messages array (custom message if any, then user message)
1059
+ // Build messages array (recall page, then custom message if any, then user message)
1047
1060
  messages = [];
1061
+ // R3: cross-session similarity recall. For a substantive turn, ask the memory providers to
1062
+ // prefetch a relevant <memory_context> page from past sessions and prepend it as data ahead of
1063
+ // the user message. Best-effort and gated: trivial turns are skipped, and providers return ""
1064
+ // (no page) when nothing is relevant — so it stays net-negative and the GC packs stale pages.
1065
+ if (this._shouldAttemptRecall(expandedText)) {
1066
+ try {
1067
+ const recall = await this._memoryManager.prefetch(expandedText);
1068
+ if (recall) {
1069
+ messages.push({ role: "user", content: [{ type: "text", text: recall }], timestamp: Date.now() });
1070
+ }
1071
+ }
1072
+ catch {
1073
+ // recall must never break a turn
1074
+ }
1075
+ }
1048
1076
  // Add user message
1049
1077
  const userContent = [{ type: "text", text: expandedText }];
1050
1078
  if (currentImages) {
@@ -2202,6 +2230,9 @@ export class AgentSession {
2202
2230
  await this._memoryManager.shutdownAll().catch(() => { });
2203
2231
  const manager = new MemoryManager();
2204
2232
  manager.registerProvider(new FileStoreProvider());
2233
+ // Bundled read-only cross-session recall (R3): indexes past-session transcripts and answers
2234
+ // prefetch() with a <memory_context> page. Never writes.
2235
+ manager.registerProvider(new TranscriptRecallProvider());
2205
2236
  for (const provider of this._pendingMemoryProviders) {
2206
2237
  try {
2207
2238
  manager.registerProvider(provider);