@mingxy/cerebro 2.2.3 → 2.2.4
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 +1 -1
- package/src/index.ts +19 -34
- package/src/tui.tsx +102 -93
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mingxy/cerebro",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
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
|
@@ -59,16 +59,13 @@ 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
|
-
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return typeof val === "function" ? val.bind(realTui) : val;
|
|
70
|
-
},
|
|
71
|
-
});
|
|
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;
|
|
68
|
+
const tui = (client as any)?.tui;
|
|
72
69
|
|
|
73
70
|
// Load overrides from opencode.json plugin_config
|
|
74
71
|
let overrides: Record<string, unknown> = {};
|
|
@@ -98,7 +95,7 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
98
95
|
} else {
|
|
99
96
|
statusMessage = `Unable to reach ${config.connection.apiUrl}`;
|
|
100
97
|
}
|
|
101
|
-
}
|
|
98
|
+
}
|
|
102
99
|
|
|
103
100
|
const email = process.env.GIT_AUTHOR_EMAIL || process.env.USER || "unknown";
|
|
104
101
|
const cwd = directory || process.cwd();
|
|
@@ -136,29 +133,17 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
136
133
|
? { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: `🌐 Open in browser http://localhost:${webPort}` }
|
|
137
134
|
: { variant: "success" as const, title: `🧠 Cerebro Connected · v${pluginVersion}`, message: "No web server" };
|
|
138
135
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
title: startupToast.title,
|
|
151
|
-
message: startupToast.message,
|
|
152
|
-
variant: startupToast.variant,
|
|
153
|
-
duration: 7000,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
logInfo("startup toast fired", { title: startupToast.title, attempts });
|
|
157
|
-
} else if (attempts < 20) {
|
|
158
|
-
setTimeout(() => fireStartupToast(attempts + 1), 500);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
setTimeout(fireStartupToast, 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);
|
|
162
147
|
|
|
163
148
|
// Auto-update check (fire-and-forget, non-blocking)
|
|
164
149
|
checkAndUpdate(tui, pluginVersion).catch(() => {});
|
package/src/tui.tsx
CHANGED
|
@@ -1,93 +1,102 @@
|
|
|
1
|
-
// @ts-nocheck — TUI JSX is resolved at runtime by opencode (same as quota plugin)
|
|
2
|
-
/** @jsxImportSource @opentui/solid */
|
|
3
|
-
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui";
|
|
4
|
-
import { createEffect, createSignal, onCleanup } from "solid-js";
|
|
5
|
-
import { readFileSync, unlinkSync } from "node:fs";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
|
|
9
|
-
const id = "@mingxy/cerebro";
|
|
10
|
-
const SIDEBAR_ORDER = 160;
|
|
11
|
-
|
|
12
|
-
function readAutoStoreFromFile(sessionId: string | undefined): boolean {
|
|
13
|
-
if (!sessionId) return true;
|
|
14
|
-
try {
|
|
15
|
-
const filePath = join(tmpdir(), `cerebro_autostore_${sessionId}.json`);
|
|
16
|
-
const data = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
17
|
-
return data.enabled ?? true;
|
|
18
|
-
} catch {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function SidebarContentView(props: {
|
|
24
|
-
api: TuiPluginApi;
|
|
25
|
-
sessionID: string;
|
|
26
|
-
}) {
|
|
27
|
-
const [autoStore, setAutoStore] = createSignal(true);
|
|
28
|
-
const theme = () => props.api.theme.current;
|
|
29
|
-
|
|
30
|
-
const readAutoStore = () => readAutoStoreFromFile(props.sessionID);
|
|
31
|
-
|
|
32
|
-
const unsubscribers = [
|
|
33
|
-
props.api.event.on("session.updated", () => {
|
|
34
|
-
setAutoStore(readAutoStore());
|
|
35
|
-
}),
|
|
36
|
-
props.api.event.on("tui.session.select", (event) => {
|
|
37
|
-
if (event.properties?.sessionID === props.sessionID) {
|
|
38
|
-
setAutoStore(readAutoStore());
|
|
39
|
-
}
|
|
40
|
-
}),
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
createEffect(() => {
|
|
44
|
-
props.sessionID;
|
|
45
|
-
setAutoStore(readAutoStore());
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const interval = setInterval(() => {
|
|
49
|
-
setAutoStore(readAutoStore());
|
|
50
|
-
}, 2000);
|
|
51
|
-
|
|
52
|
-
onCleanup(() => {
|
|
53
|
-
clearInterval(interval);
|
|
54
|
-
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<box gap={0}>
|
|
59
|
-
<text fg={theme()?.text} wrapMode="none">
|
|
60
|
-
Cerebro
|
|
61
|
-
</text>
|
|
62
|
-
<box flexDirection="row" gap={1}>
|
|
63
|
-
<text
|
|
64
|
-
flexShrink={0}
|
|
65
|
-
style={{ fg: autoStore() ? theme()?.success : theme()?.textMuted }}
|
|
66
|
-
>
|
|
67
|
-
•
|
|
68
|
-
</text>
|
|
69
|
-
<text fg={theme()?.textMuted} wrapMode="none">
|
|
70
|
-
{"Auto-store: " + (autoStore() ? "ON" : "OFF")}
|
|
71
|
-
</text>
|
|
72
|
-
</box>
|
|
73
|
-
</box>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const tui: TuiPlugin = async (api) => {
|
|
78
|
-
try {
|
|
79
|
-
const raw = readFileSync(join(tmpdir(), "cerebro_startup_toast.json"), "utf-8");
|
|
80
|
-
const toast = JSON.parse(raw);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
// @ts-nocheck — TUI JSX is resolved at runtime by opencode (same as quota plugin)
|
|
2
|
+
/** @jsxImportSource @opentui/solid */
|
|
3
|
+
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui";
|
|
4
|
+
import { createEffect, createSignal, onCleanup } from "solid-js";
|
|
5
|
+
import { readFileSync, unlinkSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
|
|
9
|
+
const id = "@mingxy/cerebro";
|
|
10
|
+
const SIDEBAR_ORDER = 160;
|
|
11
|
+
|
|
12
|
+
function readAutoStoreFromFile(sessionId: string | undefined): boolean {
|
|
13
|
+
if (!sessionId) return true;
|
|
14
|
+
try {
|
|
15
|
+
const filePath = join(tmpdir(), `cerebro_autostore_${sessionId}.json`);
|
|
16
|
+
const data = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
17
|
+
return data.enabled ?? true;
|
|
18
|
+
} catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function SidebarContentView(props: {
|
|
24
|
+
api: TuiPluginApi;
|
|
25
|
+
sessionID: string;
|
|
26
|
+
}) {
|
|
27
|
+
const [autoStore, setAutoStore] = createSignal(true);
|
|
28
|
+
const theme = () => props.api.theme.current;
|
|
29
|
+
|
|
30
|
+
const readAutoStore = () => readAutoStoreFromFile(props.sessionID);
|
|
31
|
+
|
|
32
|
+
const unsubscribers = [
|
|
33
|
+
props.api.event.on("session.updated", () => {
|
|
34
|
+
setAutoStore(readAutoStore());
|
|
35
|
+
}),
|
|
36
|
+
props.api.event.on("tui.session.select", (event) => {
|
|
37
|
+
if (event.properties?.sessionID === props.sessionID) {
|
|
38
|
+
setAutoStore(readAutoStore());
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
createEffect(() => {
|
|
44
|
+
props.sessionID;
|
|
45
|
+
setAutoStore(readAutoStore());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const interval = setInterval(() => {
|
|
49
|
+
setAutoStore(readAutoStore());
|
|
50
|
+
}, 2000);
|
|
51
|
+
|
|
52
|
+
onCleanup(() => {
|
|
53
|
+
clearInterval(interval);
|
|
54
|
+
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<box gap={0}>
|
|
59
|
+
<text fg={theme()?.text} wrapMode="none">
|
|
60
|
+
Cerebro
|
|
61
|
+
</text>
|
|
62
|
+
<box flexDirection="row" gap={1}>
|
|
63
|
+
<text
|
|
64
|
+
flexShrink={0}
|
|
65
|
+
style={{ fg: autoStore() ? theme()?.success : theme()?.textMuted }}
|
|
66
|
+
>
|
|
67
|
+
•
|
|
68
|
+
</text>
|
|
69
|
+
<text fg={theme()?.textMuted} wrapMode="none">
|
|
70
|
+
{"Auto-store: " + (autoStore() ? "ON" : "OFF")}
|
|
71
|
+
</text>
|
|
72
|
+
</box>
|
|
73
|
+
</box>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const tui: TuiPlugin = async (api) => {
|
|
78
|
+
try {
|
|
79
|
+
const raw = readFileSync(join(tmpdir(), "cerebro_startup_toast.json"), "utf-8");
|
|
80
|
+
const toast = JSON.parse(raw);
|
|
81
|
+
// Retry: opencode 1.17.14+ delays TUI init; fixed timeout may fire before endpoint is ready
|
|
82
|
+
let attempts = 0;
|
|
83
|
+
const maxAttempts = 16;
|
|
84
|
+
const tryToast = () => {
|
|
85
|
+
attempts++;
|
|
86
|
+
try {
|
|
87
|
+
api.ui.toast(toast);
|
|
88
|
+
try { unlinkSync(join(tmpdir(), "cerebro_startup_toast.json")); } catch {}
|
|
89
|
+
} catch {
|
|
90
|
+
if (attempts < maxAttempts) setTimeout(tryToast, 500);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
setTimeout(tryToast, 1000);
|
|
94
|
+
} catch {}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const pluginModule: TuiPluginModule & { id: string } = {
|
|
98
|
+
id,
|
|
99
|
+
tui,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default pluginModule;
|