@mingxy/cerebro 1.7.2 → 1.7.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 +9 -4
- package/src/tui.tsx +15 -12
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
2
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { OmemClient } from "./client.js";
|
|
6
7
|
import { autoRecallHook, compactingHook, keywordDetectionHook, sessionIdleHook } from "./hooks.js";
|
|
@@ -22,6 +23,7 @@ try {
|
|
|
22
23
|
|
|
23
24
|
// Per-session auto-store toggle: sessionId → enabled (default: true = auto-store on)
|
|
24
25
|
const autoStoreSessions = new Map<string, boolean>();
|
|
26
|
+
const STATE_FILE = join(tmpdir(), "cerebro_autostore.json");
|
|
25
27
|
|
|
26
28
|
export function isAutoStoreEnabled(sessionId: string | undefined): boolean {
|
|
27
29
|
if (!sessionId) return true;
|
|
@@ -30,10 +32,13 @@ export function isAutoStoreEnabled(sessionId: string | undefined): boolean {
|
|
|
30
32
|
|
|
31
33
|
export function setAutoStoreEnabled(sessionId: string, enabled: boolean): void {
|
|
32
34
|
autoStoreSessions.set(sessionId, enabled);
|
|
35
|
+
try {
|
|
36
|
+
const obj: Record<string, boolean> = {};
|
|
37
|
+
for (const [k, v] of autoStoreSessions) obj[k] = v;
|
|
38
|
+
writeFileSync(STATE_FILE, JSON.stringify(obj));
|
|
39
|
+
} catch {}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
// Bridge for TUI plugin: expose the Map directly so TUI can query with its own sessionID
|
|
36
|
-
// (tool sessionId and TUI sessionID may differ in format)
|
|
37
42
|
(globalThis as any).__cerebro_autoStoreMap = autoStoreSessions;
|
|
38
43
|
|
|
39
44
|
function showToast(tui: any, title: string, message?: string, variant: string = "info", duration: number = 5000) {
|
|
@@ -79,7 +84,7 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
79
84
|
// 启动时检测连接状态
|
|
80
85
|
try {
|
|
81
86
|
await omemClient.getStats();
|
|
82
|
-
showToast(tui, "🧠 Cerebro", `v${pluginVersion}
|
|
87
|
+
showToast(tui, "🧠 Cerebro · Connected", `Version v${pluginVersion}`, "success", 6000);
|
|
83
88
|
logInfo(`Connected to ${config.apiUrl}`);
|
|
84
89
|
} catch (err) {
|
|
85
90
|
const errMsg = err instanceof Error ? err.message : String(err);
|
package/src/tui.tsx
CHANGED
|
@@ -2,10 +2,24 @@
|
|
|
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";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
5
8
|
|
|
9
|
+
const STATE_FILE = join(tmpdir(), "cerebro_autostore.json");
|
|
6
10
|
const id = "@mingxy/cerebro";
|
|
7
11
|
const SIDEBAR_ORDER = 160;
|
|
8
12
|
|
|
13
|
+
function readAutoStoreFromFile(sessionId: string | undefined): boolean {
|
|
14
|
+
if (!sessionId) return true;
|
|
15
|
+
try {
|
|
16
|
+
const data = JSON.parse(readFileSync(STATE_FILE, "utf-8"));
|
|
17
|
+
return data[sessionId] ?? true;
|
|
18
|
+
} catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
function SidebarContentView(props: {
|
|
10
24
|
api: TuiPluginApi;
|
|
11
25
|
sessionID: string;
|
|
@@ -13,15 +27,7 @@ function SidebarContentView(props: {
|
|
|
13
27
|
const [autoStore, setAutoStore] = createSignal(true);
|
|
14
28
|
const theme = () => props.api.theme.current;
|
|
15
29
|
|
|
16
|
-
const readAutoStore = () => (
|
|
17
|
-
|
|
18
|
-
const debugLine = () => {
|
|
19
|
-
const map = (globalThis as any).__cerebro_autoStoreMap;
|
|
20
|
-
const hasMap = map ? "Y" : "N";
|
|
21
|
-
const sid = props.sessionID?.slice(-8) ?? "none";
|
|
22
|
-
const keys = map ? [...map.keys()].map((k: string) => k.slice(-8)).join(",") : "-";
|
|
23
|
-
return `dbg:${hasMap} sid:${sid} [${keys}]`;
|
|
24
|
-
};
|
|
30
|
+
const readAutoStore = () => readAutoStoreFromFile(props.sessionID);
|
|
25
31
|
|
|
26
32
|
const unsubscribers = [
|
|
27
33
|
props.api.event.on("session.updated", () => {
|
|
@@ -64,9 +70,6 @@ function SidebarContentView(props: {
|
|
|
64
70
|
{"Auto-store: " + (autoStore() ? "ON" : "OFF")}
|
|
65
71
|
</text>
|
|
66
72
|
</box>
|
|
67
|
-
<text fg={theme()?.textMuted} wrapMode="none">
|
|
68
|
-
{debugLine()}
|
|
69
|
-
</text>
|
|
70
73
|
</box>
|
|
71
74
|
);
|
|
72
75
|
}
|