@mingxy/cerebro 1.12.1 → 1.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/hooks.ts +19 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/cerebro",
3
- "version": "1.12.1",
3
+ "version": "1.12.3",
4
4
  "description": "Cerebro persistent memory plugin for OpenCode — auto-recall, auto-capture, 9 memory tools with clustering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/hooks.ts CHANGED
@@ -509,11 +509,18 @@ export function autoRecallHook(client: CerebroClient, containerTags: string[], t
509
509
  if (block) {
510
510
  output.system.push(block);
511
511
  output.system.push(FETCH_POLICY);
512
+ logDebug("autoRecallHook block injected to output.system", {
513
+ sessionId: input.sessionID,
514
+ blockPreview: block.slice(0, 200),
515
+ outputSystemLength: output.system.length,
516
+ });
517
+ } else {
518
+ logDebug("autoRecallHook block was EMPTY — no injection", { sessionId: input.sessionID });
512
519
  }
513
520
 
514
521
  const newIds = newResults.map((r) => r.memory.id);
515
522
  injectedMemoryIds.set(input.sessionID, new Set([...existingIds, ...newIds]));
516
- logDebug("autoRecallHook injection complete", { newIds: newIds.length, clustered: !!clustered });
523
+ logDebug("autoRecallHook injection complete", { newIds: newIds.length, clustered: !!clustered, sessionId: input.sessionID });
517
524
 
518
525
  await createEventAndReturn(newResults.length, storedMemoryIds.length, storedDiscardedIds.length);
519
526
 
@@ -633,6 +640,13 @@ export function compactingHook(client: CerebroClient, containerTags: string[], t
633
640
  output.context.push(block);
634
641
  output.context.push(FETCH_POLICY);
635
642
  }
643
+ // 将compacting搜索结果的ID写入injectedMemoryIds,避免后续autoRecall重复注入
644
+ if (input.sessionID && results.length > 0) {
645
+ const compactingIds = results.map((r) => r.memory.id);
646
+ const existing = injectedMemoryIds.get(input.sessionID) ?? new Set<string>();
647
+ injectedMemoryIds.set(input.sessionID, new Set([...existing, ...compactingIds]));
648
+ logDebug("compactingHook updated injectedMemoryIds", { sessionId: input.sessionID, addedCount: compactingIds.length, totalExisting: existing.size });
649
+ }
636
650
  } catch {
637
651
  }
638
652
 
@@ -652,7 +666,6 @@ export function compactingHook(client: CerebroClient, containerTags: string[], t
652
666
  if (input.sessionID) {
653
667
  sessionMessages.delete(input.sessionID);
654
668
  profileInjectedSessions.delete(input.sessionID);
655
- injectedMemoryIds.delete(input.sessionID);
656
669
  firstMessages.delete(input.sessionID);
657
670
  }
658
671
  return;
@@ -679,7 +692,6 @@ export function compactingHook(client: CerebroClient, containerTags: string[], t
679
692
  if (isAutoStoreEnabled && !isAutoStoreEnabled(input.sessionID)) {
680
693
  sessionMessages.delete(input.sessionID);
681
694
  profileInjectedSessions.delete(input.sessionID);
682
- injectedMemoryIds.delete(input.sessionID);
683
695
  firstMessages.delete(input.sessionID);
684
696
  } else {
685
697
  const messages = sessionMessages.get(input.sessionID)!;
@@ -708,8 +720,11 @@ export function compactingHook(client: CerebroClient, containerTags: string[], t
708
720
  // Cleanup tracked messages regardless of ingest result
709
721
  sessionMessages.delete(input.sessionID);
710
722
  profileInjectedSessions.delete(input.sessionID);
711
- injectedMemoryIds.delete(input.sessionID);
712
723
  firstMessages.delete(input.sessionID);
724
+ // Evict stale injectedMemoryIds if over size cap (200 sessions)
725
+ if (injectedMemoryIds.size > 200) {
726
+ injectedMemoryIds.clear();
727
+ }
713
728
  }
714
729
 
715
730
  // Phase 2: compact inserts "[restore checkpointed" user message — poll for that marker