From ec7b461147fbb914aee6b677158ceb2fe7446724 Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 22 Sep 2026 20:48:33 +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=9D=E8=AF=95=20context.command?= =?UTF-8?q?.register=20=E6=B3=A8=E5=86=8C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui-plugins/oc-session-all.js | 75 +++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/tui-plugins/oc-session-all.js b/tui-plugins/oc-session-all.js index eeb4947..99b0b5c 100644 --- a/tui-plugins/oc-session-all.js +++ b/tui-plugins/oc-session-all.js @@ -3,27 +3,62 @@ import { Plugin } from "@opencode/plugin/tui" export default Plugin.define({ id: "oc-session-all", setup(context) { - console.log("[oc-session-all] v2 Plugin loaded!") - context.ui.toast.show({ - message: "[oc-session-all] v2 loaded! Testing keymap...", - variant: "success", - duration: 3000, - }) + console.log("[oc-session-all] v2 Plugin loaded! Attempting command registration...") - // 只注册 command,不注册 binding(方法名是 registerLayer 不是 layer) - context.keymap.registerLayer({ - commands: [ - { - title: "All Sessions", - value: "sessions.all", - description: "Browse and switch to any session across all projects", - category: "Session Picker", - slash: { name: "sessions-all" }, - onSelect: () => { - context.ui.toast.show({ message: "sessions-all triggered!", variant: "info" }); + // ── 尝试注册命令 ────────────────────────────────────── + const report = [] + report.push("context keys: " + Object.keys(context).join(", ")) + + // 尝试 context.command.register + if (context.command && typeof context.command.register === "function") { + try { + const unregister = context.command.register(() => [ + { + title: "Show All Sessions", + value: "sessions-all", + slash: { name: "sessions-all", aliases: ["sa"] }, + description: "Display all session records in a dialog", + onSelect: async () => { + console.log("[oc-session-all] /sessions-all triggered") + context.ui.toast.show({ + message: "Sessions-all command executed!", + variant: "success", + duration: 3000, + }) + }, }, - }, - ], + ]) + report.push("command.register: SUCCESS, unregister: " + typeof unregister) + console.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) + } + } else { + report.push("context.command: " + (context.command ? "exists but no register" : "undefined")) + } + + // 尝试 keymap 的其他方法 + if (context.keymap) { + const kmMethods = Object.getOwnPropertyNames(context.keymap) + .filter(k => typeof context.keymap[k] === "function") + report.push("keymap methods: " + kmMethods.join(", ")) + + // 尝试常见的 Keymap 方法 + const tryMethods = ["bind", "on", "register", "registerLayer", "layer"] + for (const m of tryMethods) { + if (typeof context.keymap[m] === "function") { + report.push("keymap." + m + " exists") + } + } + } + + const msg = report.join(" | ") + console.log("[oc-session-all] REGISTER PROBE: " + msg) + context.ui.toast.show({ + message: "Register probe: " + msg, + variant: "info", + duration: 15000, }) }, -}) +}) \ No newline at end of file