@mingxy/cerebro 1.7.1 → 1.7.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.
- package/package.json +1 -1
- package/src/index.ts +8 -3
- package/src/tui.tsx +15 -1
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) {
|
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,7 +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 = () => (
|
|
30
|
+
const readAutoStore = () => readAutoStoreFromFile(props.sessionID);
|
|
17
31
|
|
|
18
32
|
const unsubscribers = [
|
|
19
33
|
props.api.event.on("session.updated", () => {
|