@mingxy/cerebro 1.20.6 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/cerebro",
3
- "version": "1.20.6",
3
+ "version": "2.0.1",
4
4
  "description": "Cerebro persistent memory plugin for OpenCode — auto-recall, auto-capture, 9 memory tools with clustering, project-scoped memory isolation",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/hooks.ts CHANGED
@@ -3,6 +3,7 @@ import type { CerebroClient, SearchResult } from "./client.js";
3
3
  import { type CerebroPluginConfig, DEFAULTS, resolveAgentPolicy } from "./config.js";
4
4
  import { logDebug, logInfo, logError as logErr } from "./logger.js";
5
5
  import { readFile } from "node:fs/promises";
6
+ import { execSync } from "node:child_process";
6
7
 
7
8
  /** Sanitize session ID to prevent path traversal */
8
9
  function sanitizeSessionId(id: string | undefined): string | undefined {
@@ -411,6 +412,41 @@ export function chatMessageRecallHook(
411
412
  };
412
413
  }
413
414
 
415
+ /**
416
+ * System transform hook — injects current system time + memory_search reminder
417
+ * into output.system[] on every LLM request. Forces AI to perceive time and
418
+ * recall memories, addressing "time loss" and "forgot to search memory" issues.
419
+ *
420
+ * Factory pattern matching chatMessageRecallHook. State-less (fires per turn).
421
+ */
422
+ export function timeMemorySystemHook() {
423
+ return async (
424
+ _input: unknown,
425
+ output: { system?: string[] },
426
+ ) => {
427
+ if (!output || !Array.isArray(output.system)) return;
428
+
429
+ let timeStr = "";
430
+ try {
431
+ timeStr = execSync("date '+%Y-%m-%d %H:%M:%S %A'", {
432
+ encoding: "utf-8",
433
+ timeout: 2000,
434
+ }).trim();
435
+ } catch (err) {
436
+ logErr("timeMemorySystemHook: date command failed", { error: String(err) });
437
+ timeStr = new Date().toISOString().replace("T", " ").slice(0, 19);
438
+ }
439
+
440
+ output.system.push(`[CEREBRO-TIME] ${timeStr}`);
441
+ output.system.push(
442
+ '[CEREBRO-TIME-MEANING] This is your current ground-truth anchor. Use it to: (1) verify "earlier/yesterday/last time" claims against memory, (2) detect when your own time sense drifts, (3) question implausible durations.',
443
+ );
444
+ output.system.push(
445
+ '[CEREBRO-MEMORY] Before answering or acting on non-trivial requests: if you lack specific knowledge about this user, project, or topic — search memory first. Search is cheap; guessing is expensive. Treat memory as your own mind, not a last-resort tool.',
446
+ );
447
+ };
448
+ }
449
+
414
450
  export function createCerebroCompactionPrompt(
415
451
  context: string[],
416
452
  projectMemories: SearchResult[],
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@ import { join, dirname } from "node:path";
4
4
  import { tmpdir } from "node:os";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { CerebroClient } from "./client.js";
7
- import { chatMessageRecallHook, autocontinueHook, compactingHook, sessionIdleHook, sessionMessages, firstMessages, showToast } from "./hooks.js";
7
+ import { chatMessageRecallHook, autocontinueHook, compactingHook, sessionIdleHook, sessionMessages, firstMessages, showToast, timeMemorySystemHook } from "./hooks.js";
8
8
  import { detectSaveKeyword, detectRecallKeyword, KEYWORD_NUDGE, RECALL_NUDGE } from "./keywords.js";
9
9
  import { getUserTag, getProjectTag } from "./tags.js";
10
10
  import { buildTools } from "./tools.js";
@@ -221,6 +221,7 @@ const OmemPlugin: Plugin = async (input) => {
221
221
  output.env.OMEM_PROJECT_DIR = directory;
222
222
  }
223
223
  },
224
+ "experimental.chat.system.transform": timeMemorySystemHook(),
224
225
  };
225
226
  };
226
227