From 459f038f8e99db69d4579103a8fc3682b3675c79 Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 22 Sep 2026 21:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A2=E6=B5=8B=E7=89=88?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=9A=E5=B0=86=E6=8E=A2=E6=B5=8B=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=86=99=E5=85=A5=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui-plugins/oc-session-all.js | 48 +++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/tui-plugins/oc-session-all.js b/tui-plugins/oc-session-all.js index 53337af..020ebf7 100644 --- a/tui-plugins/oc-session-all.js +++ b/tui-plugins/oc-session-all.js @@ -1,9 +1,31 @@ import { Plugin } from "@opencode/plugin/tui" +import { appendFileSync, mkdirSync, existsSync } from "fs" +import { join } from "path" + +// 日志文件路径 +const LOG_DIR = "C:\\Users\\ypshidifu\\.config\\opencode" +const LOG_FILE = join(LOG_DIR, "oc-session-all.log") + +// 确保日志目录存在 +if (!existsSync(LOG_DIR)) { + mkdirSync(LOG_DIR, { recursive: true }) +} + +function log(msg) { + const timestamp = new Date().toISOString() + const line = `[${timestamp}] ${msg}\n` + try { + appendFileSync(LOG_FILE, line) + } catch (e) { + // 忽略写入错误 + } + console.log(msg) +} export default Plugin.define({ id: "oc-session-all", setup(context) { - console.log("[oc-session-all] v2 Plugin loaded! Attempting command registration...") + log("[oc-session-all] v2 Plugin loaded! Attempting command registration...") // ── 探测 context 结构 ────────────────────────────────────── const report = [] @@ -26,7 +48,7 @@ export default Plugin.define({ slash: { name: "sessions-all", aliases: ["sa"] }, description: "Display all session records in a dialog", onSelect: async () => { - console.log("[oc-session-all] /sessions-all triggered") + log("[oc-session-all] /sessions-all triggered") context.ui.toast.show({ message: "Sessions-all command executed!", variant: "success", @@ -36,16 +58,18 @@ export default Plugin.define({ }, ]) report.push("command.register: SUCCESS, unregister type: " + typeof unregister) - console.log("[oc-session-all] command.register succeeded") + log("[oc-session-all] command.register succeeded") } catch (e) { report.push("command.register ERROR: " + e.message) - console.error("[oc-session-all] command.register failed:", e) + log("[oc-session-all] command.register ERROR: " + e.message) } } else { report.push("command.register: NOT A FUNCTION") + log("[oc-session-all] command.register is not a function") } } else { report.push("context.command: undefined") + log("[oc-session-all] context.command is undefined") } // 探测 context.keymap @@ -63,11 +87,15 @@ export default Plugin.define({ } const msg = report.join(" | ") - console.log("[oc-session-all] FULL PROBE: " + msg) - context.ui.toast.show({ - message: "Full probe: " + msg, - variant: "info", - duration: 20000, - }) + log("[oc-session-all] FULL PROBE: " + msg) + try { + context.ui.toast.show({ + message: "Full probe: " + msg, + variant: "info", + duration: 20000, + }) + } catch (e) { + log("[oc-session-all] toast.show ERROR: " + e.message) + } }, }) \ No newline at end of file