From f2b7303cd2ff8662e78fef545d263fbce8d0a32e Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 20 Oct 2026 21:59:20 +0800 Subject: [PATCH] =?UTF-8?q?model-sync:=20=E8=A1=A5=E5=90=8C=E6=AD=A5=20mod?= =?UTF-8?q?el-manager-db-exec.py(=E4=BF=AEWSL=E5=81=9C=E7=94=A8=E5=A4=B1?= =?UTF-8?q?=E6=95=88)=20+=20tui.json/tui-plugins(=E4=BF=AE/mcp-off?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1)=EF=BC=8C=E8=B7=AF=E5=BE=84=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E8=A6=86=E7=9B=96=20file://=20=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/oc-model-sync.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/oc-model-sync.py b/tools/oc-model-sync.py index 12ee8db..d93f4c6 100644 --- a/tools/oc-model-sync.py +++ b/tools/oc-model-sync.py @@ -79,6 +79,19 @@ PLUGINS = [ "/root/.config/opencode/opencode.json"), (os.path.join(HOME, ".config", "opencode", "model-manager.cfg.json"), "/root/.config/opencode/model-manager.cfg.json"), + # ── 2026-10-20 补:model-manager 在 WSL 失效的根因 ── + # ① model-manager-db-exec.py(Python DB 写执行器)是 model-manager.ts 的硬依赖, + # 它 fork 这个子进程去写 SQLite catalog。WSL 没有 → execDbWrite spawn-fail + # → 停用/恢复/删除厂商全不生效(WSL 侧「无法停用/恢复出厂」的直接根因)。 + (os.path.join(HOME, ".config", "opencode", "model-manager-db-exec.py"), + "/root/.config/opencode/model-manager-db-exec.py"), + # ② tui.json(注册 TUI 插件 oc-session-all.js)+ tui-plugins 本体。 + # WSL 侧缺 tui.json → TUI 插件没注册 → /mcpon /mcpoff 斜杠命令不存在 + # → 截图 3「/mcp-off No matching commands」。 + (os.path.join(HOME, ".config", "opencode", "tui.json"), + "/root/.config/opencode/tui.json"), + (os.path.join(HOME, ".config", "opencode", "tui-plugins", "oc-session-all.js"), + "/root/.config/opencode/tui-plugins/oc-session-all.js"), ] @@ -128,23 +141,29 @@ def read_win_data(): def build_plugin_blob(): """Win 生效份插件 + opencode.json -> {dst_path: base64}。 - mcpcfg.txt 特殊处理:把 Win 绝对路径(反斜杠)转 WSL 绝对路径。 + mcpcfg.txt / tui.json 特殊处理:把 Win 绝对路径(反斜杠或 file:///C:/)转 WSL 绝对路径。 model-manager 压制清单:Win 原样推(Win 空则 WSL 也空)。 注意:opencode.json 的 provider 是相对 key(如 '1'),无绝对路径,直接 base64 推。 """ blob = {} - # Win 侧 mcpcfg.txt 里是 C://Users//ypshidifu//.config//opencode// 前缀(单反斜杠) - win_prefix_bk = "C:" + chr(92) + "Users" + chr(92) + "ypshidifu" + chr(92) + ".config" + chr(92) + "opencode" + chr(92) + # Win 侧各路径前缀 -> WSL 前缀(用 chr(92) 拼反斜杠,绕开源码转义踩坑) + bk = chr(92) + win_prefix_bk = "C:" + bk + "Users" + bk + "ypshidifu" + bk + ".config" + bk + "opencode" + bk win_prefix_sl = "C:/Users/ypshidifu/.config/opencode/" + win_prefix_file = "file:///C:/Users/ypshidifu/.config/opencode/" wsl_prefix = "/root/.config/opencode/" + wsl_prefix_file = "file:///root/.config/opencode/" for src, dst in PLUGINS: if not os.path.exists(src): continue try: data = open(src, "rb").read() - # mcpcfg.txt:Win 路径前缀 -> WSL 路径前缀 - if os.path.basename(src) == "mcpcfg.txt": + # mcpcfg.txt / tui.json:Win 路径前缀 -> WSL 路径前缀 + # - 普通反斜杠路径(mcpcfg.txt) + # - file:// 绝对路径(tui.json 里 TUI 插件注册) + if os.path.basename(src) in ("mcpcfg.txt", "tui.json"): text = data.decode("utf-8") + text = text.replace(win_prefix_file, wsl_prefix_file) # 先替换 file:// 长前缀 text = text.replace(win_prefix_bk, wsl_prefix) text = text.replace(win_prefix_sl, wsl_prefix) data = text.encode("utf-8")