@mingxy/cerebro 2.1.4 → 2.1.6

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/index.ts +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/cerebro",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
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/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, timeMemorySystemHook, showToast } from "./hooks.js";
7
+ import { chatMessageRecallHook, autocontinueHook, compactingHook, sessionIdleHook, sessionMessages, firstMessages, 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";
@@ -59,7 +59,12 @@ const OmemPlugin: Plugin = async (input) => {
59
59
  // Normalize to git root: worktree=git root, directory=cwd.
60
60
  // project_path must be git root so parent/child dirs share memories.
61
61
  const { directory: _directory, worktree, client } = input;
62
- const directory = worktree || _directory;
62
+ // opencode 在非git目录启动时给 worktree="/"(global project,见 opencode 源码
63
+ // database-migration.test.ts:448 `SELECT worktree FROM project WHERE id='global' → '/'`)。
64
+ // 这种情况直接用 `/` 会让服务端 SQL `LIKE '/%'` 命中所有绝对路径记忆,污染注入。
65
+ // fallback 到 cwd(_directory),让前缀匹配只命中 cwd 子树。
66
+ const isWorktreeValid = worktree && worktree !== "/" && worktree !== "." && worktree !== "";
67
+ const directory = isWorktreeValid ? worktree! : _directory;
63
68
  const tui = (client as any)?.tui;
64
69
 
65
70
  // Load overrides from opencode.json plugin_config
@@ -128,8 +133,17 @@ const OmemPlugin: Plugin = async (input) => {
128
133
  ? { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: `🌐 Open in browser http://localhost:${webPort}` }
129
134
  : { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: "No web server" };
130
135
 
131
- // Direct toast via tui proxy bypasses broken TUI plugin file mechanism (opencode 1.17.14+)
132
- showToast(tui, startupToast.title, startupToast.message, startupToast.variant, 2000);
136
+ // Direct toast — same pattern as opencode-acp (client.tui.showToast, fire-and-forget, 5s delay)
137
+ setTimeout(() => {
138
+ (client as any)?.tui?.showToast({
139
+ body: {
140
+ title: startupToast.title,
141
+ message: startupToast.message,
142
+ variant: startupToast.variant,
143
+ duration: 7000,
144
+ },
145
+ });
146
+ }, 5000);
133
147
 
134
148
  // Auto-update check (fire-and-forget, non-blocking)
135
149
  checkAndUpdate(tui, pluginVersion).catch(() => {});