From 5ceeed82f6dcb071cec0df3bd1f3d1d5dcddfce7 Mon Sep 17 00:00:00 2001 From: CN-P5 Date: Sun, 29 Mar 2026 00:54:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(memos-local-openclaw):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=92=8C=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C=E6=A0=BC=E5=BC=8F=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 简化 openclaw.json 中 tools.allow 的修改逻辑,直接操作对象而非字符串替换 - 统一搜索结果格式化代码的缩进风格 - 移除不必要的字符串操作,提高代码可读性 --- apps/memos-local-openclaw/index.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/apps/memos-local-openclaw/index.ts b/apps/memos-local-openclaw/index.ts index bcb2c0870..6596ac708 100644 --- a/apps/memos-local-openclaw/index.ts +++ b/apps/memos-local-openclaw/index.ts @@ -250,7 +250,7 @@ const memosLocalPlugin = { try { const pkg = JSON.parse(fs.readFileSync(path.join(pluginDir, "package.json"), "utf-8")); pluginVersion = pkg.version ?? pluginVersion; - } catch {} + } catch { } const telemetry = new Telemetry(ctx.config.telemetry ?? {}, stateDir, pluginVersion, ctx.log, pluginDir); // Install bundled memory-guide skill so OpenClaw loads it (write from embedded content so it works regardless of deploy layout) @@ -279,15 +279,9 @@ const memosLocalPlugin = { const cfg = JSON.parse(raw); const allow: string[] | undefined = cfg?.tools?.allow; if (Array.isArray(allow) && allow.length > 0 && !allow.includes("group:plugins")) { - const lastEntry = JSON.stringify(allow[allow.length - 1]); - const patched = raw.replace( - new RegExp(`(${lastEntry})(\\s*\\])`), - `$1,\n "group:plugins"$2`, - ); - if (patched !== raw && patched.includes("group:plugins")) { - fs.writeFileSync(openclawJsonPath, patched, "utf-8"); - ctx.log.info("memos-local: added 'group:plugins' to tools.allow in openclaw.json"); - } + cfg.tools.allow.push("group:plugins"); + fs.writeFileSync(openclawJsonPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8"); + ctx.log.info("memos-local: added 'group:plugins' to tools.allow in openclaw.json"); } } } catch (e) { @@ -607,9 +601,9 @@ const memosLocalPlugin = { }; const localText = filteredHits.length > 0 ? filteredHits.map((h, i) => { - const excerpt = h.original_excerpt.length > 220 ? h.original_excerpt.slice(0, 217) + "..." : h.original_excerpt; - return `${i + 1}. [${h.source.role}]${originLabel(h)} ${excerpt}`; - }).join("\n") + const excerpt = h.original_excerpt.length > 220 ? h.original_excerpt.slice(0, 217) + "..." : h.original_excerpt; + return `${i + 1}. [${h.source.role}]${originLabel(h)} ${excerpt}`; + }).join("\n") : "(none)"; const hubText = filteredHubHits.length > 0 ? filteredHubHits.map((h, i) => `${i + 1}. [${h.ownerName}] [团队] ${h.summary}${h.groupName ? ` (${h.groupName})` : ""}`).join("\n")