@mingxy/cerebro 2.0.2 → 2.0.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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +16 -23
  3. package/src/tui.tsx +10 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/cerebro",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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, showToast, timeMemorySystemHook } 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";
@@ -76,37 +76,26 @@ const OmemPlugin: Plugin = async (input) => {
76
76
  } catch {}
77
77
 
78
78
  const config = loadPluginConfig(overrides as any);
79
- const STARTUP_DELAY = 5000;
80
79
 
81
80
  setOpencodeClient(client);
82
81
 
83
82
  const cerebroClient = new CerebroClient(config.connection.apiUrl, config.connection.apiKey, config);
84
83
 
84
+ let connectionStatus: "success" | "error" = "success";
85
+ let statusMessage = "";
85
86
  try {
86
87
  await cerebroClient.getStats();
87
88
  logInfo(`Connected to ${config.connection.apiUrl}`);
88
89
  } catch (err) {
89
90
  const errMsg = err instanceof Error ? err.message : String(err);
90
91
  logError(`Connection failed: ${errMsg}`);
92
+ connectionStatus = "error";
91
93
  if (errMsg.includes("[cerebro]")) {
92
- const cleanMsg = errMsg.replace(/^\[cerebro\]\s*/, "");
93
- showToast(
94
- tui,
95
- `🧠 Cerebro v${pluginVersion} · Server Error`,
96
- cleanMsg.substring(0, 150),
97
- "error",
98
- STARTUP_DELAY
99
- );
94
+ statusMessage = errMsg.replace(/^\[cerebro]\s*/, "").substring(0, 150);
100
95
  } else {
101
- showToast(
102
- tui,
103
- `🧠 Cerebro v${pluginVersion} · Connection Failed`,
104
- `Unable to reach ${config.connection.apiUrl}`,
105
- "error",
106
- STARTUP_DELAY
107
- );
96
+ statusMessage = `Unable to reach ${config.connection.apiUrl}`;
108
97
  }
109
- }
98
+ }
110
99
 
111
100
  const email = process.env.GIT_AUTHOR_EMAIL || process.env.USER || "unknown";
112
101
  const cwd = directory || process.cwd();
@@ -138,11 +127,15 @@ const OmemPlugin: Plugin = async (input) => {
138
127
  }
139
128
  }
140
129
 
141
- if (webPort) {
142
- showToast(tui, `🧠 Cerebro Connected · v${pluginVersion}`, `🌐 Open in browser http://localhost:${webPort}`, "success", STARTUP_DELAY);
143
- } else {
144
- showToast(tui, `🧠 Cerebro Connected · v${pluginVersion}`, "No web server", "success", STARTUP_DELAY);
145
- }
130
+ const startupToast = connectionStatus === "error"
131
+ ? { variant: "error" as const, title: `🧠 Cerebro v${pluginVersion} · Connection Failed`, message: statusMessage }
132
+ : webPort
133
+ ? { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: `🌐 Open in browser http://localhost:${webPort}` }
134
+ : { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: "No web server" };
135
+
136
+ try {
137
+ writeFileSync(join(tmpdir(), "cerebro_startup_toast.json"), JSON.stringify(startupToast));
138
+ } catch {}
146
139
 
147
140
  // Auto-update check (fire-and-forget, non-blocking)
148
141
  checkAndUpdate(tui, pluginVersion).catch(() => {});
package/src/tui.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
  /** @jsxImportSource @opentui/solid */
3
3
  import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui";
4
4
  import { createEffect, createSignal, onCleanup } from "solid-js";
5
- import { readFileSync } from "node:fs";
5
+ import { readFileSync, unlinkSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
  import { tmpdir } from "node:os";
8
8
 
@@ -83,6 +83,15 @@ const tui: TuiPlugin = async (api) => {
83
83
  },
84
84
  },
85
85
  });
86
+
87
+ try {
88
+ const raw = readFileSync(join(tmpdir(), "cerebro_startup_toast.json"), "utf-8");
89
+ const toast = JSON.parse(raw);
90
+ setTimeout(() => {
91
+ try { api.ui.toast(toast); } catch {}
92
+ try { unlinkSync(join(tmpdir(), "cerebro_startup_toast.json")); } catch {}
93
+ }, 2000);
94
+ } catch {}
86
95
  };
87
96
 
88
97
  const pluginModule: TuiPluginModule & { id: string } = {