From 2ca4d0d14fa51adb121b29ef4801ffb175ed673f Mon Sep 17 00:00:00 2001 From: Teingi Date: Wed, 18 Mar 2026 15:29:57 +0800 Subject: [PATCH] plugin: add default config for zero-config setup --- README.md | 8 ++++---- README_CN.md | 10 +++++----- config.ts | 12 ++++++++++++ index.ts | 11 ++++++++++- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9b4c90e..24713ad 100644 --- a/README.md +++ b/README.md @@ -156,15 +156,15 @@ openclaw plugins install /path/to/openclaw-extension-powermem openclaw plugins install -l /path/to/openclaw-extension-powermem ``` -**Note:** Running `npm i openclaw-extension-powermem` in a Node project only adds the package to that project’s `node_modules`; it does **not** register the plugin with OpenClaw. To use this as an OpenClaw plugin, you must run `openclaw plugins install openclaw-extension-powermem` (or install from a path as above), then configure OpenClaw and restart the gateway. +**Note:** Running `npm i openclaw-extension-powermem` in a Node project only adds the package to that project’s `node_modules`; it does **not** register the plugin with OpenClaw. To use this as an OpenClaw plugin, you must run `openclaw plugins install openclaw-extension-powermem` (or install from a path as above), then restart the gateway. -After install, run `openclaw plugins list` and confirm `memory-powermem` is listed. +After install, run `openclaw plugins list` and confirm `memory-powermem` is listed. The plugin uses **default config** when none is set: `baseUrl: "http://localhost:8000"`, `autoCapture`, `autoRecall`, and `inferOnAdd` enabled — so you do not need to edit `~/.openclaw/openclaw.json` for the typical setup (PowerMem on localhost:8000). --- -## Step 3: Configure OpenClaw to use the plugin +## Step 3: Configure OpenClaw (optional) -Edit OpenClaw’s config (e.g. `~/.openclaw/openclaw.json`). At the **root level**, add or merge the `plugins` section: set `plugins.slots.memory` and `plugins.entries["memory-powermem"]`, and set the PowerMem URL. +If you use PowerMem at **http://localhost:8000** with the default options, skip this step. To **customize** (e.g. different URL, API key, or CLI mode), edit OpenClaw's config (e.g. `~/.openclaw/openclaw.json`) and add or merge the `plugins` section. **Example (JSON):** diff --git a/README_CN.md b/README_CN.md index 8948d94..2413546 100644 --- a/README_CN.md +++ b/README_CN.md @@ -8,7 +8,7 @@ # OpenClaw Memory (PowerMem) 插件 -本插件让 [OpenClaw](https://github.com/openclaw/openclaw) 通过 [PowerMem](https://github.com/oceanbase/powermem) 的 HTTP API 使用长期记忆:智能抽取、艾宾浩斯遗忘曲线、多 Agent 隔离。 +本插件让 [OpenClaw](https://github.com/openclaw/openclaw) 通过 [PowerMem](https://github.com/oceanbase/powermem) 使用长期记忆:智能抽取、艾宾浩斯遗忘曲线、多 Agent 隔离。 按顺序操作:先安装并启动 PowerMem,再安装插件、配置 OpenClaw,最后验证。 @@ -157,15 +157,15 @@ openclaw plugins install /path/to/openclaw-extension-powermem openclaw plugins install -l /path/to/openclaw-extension-powermem ``` -**说明:** 在某个 Node 项目里执行 `npm i openclaw-extension-powermem` 只会把包装进该项目的 `node_modules`,**不会**在 OpenClaw 里注册插件。若要在 OpenClaw 里使用本插件,必须执行 `openclaw plugins install openclaw-extension-powermem`(或按上面用本地路径安装),再在 OpenClaw 中配置并重启 gateway。 +**说明:** 在某个 Node 项目里执行 `npm i openclaw-extension-powermem` 只会把包装进该项目的 `node_modules`,**不会**在 OpenClaw 里注册插件。若要在 OpenClaw 里使用本插件,必须执行 `openclaw plugins install openclaw-extension-powermem`(或按上面用本地路径安装),再重启 gateway。 -安装成功后,可用 `openclaw plugins list` 确认能看到 `memory-powermem`。 +安装成功后,可用 `openclaw plugins list` 确认能看到 `memory-powermem`。未在配置中书写本插件 config 时,插件会使用 **默认配置**:`baseUrl: "http://localhost:8000"`,并开启 `autoCapture`、`autoRecall`、`inferOnAdd`,因此典型情况(PowerMem 跑在 localhost:8000)下无需编辑 `~/.openclaw/openclaw.json`。 --- -## 第三步:配置 OpenClaw 使用本插件 +## 第三步:配置 OpenClaw(可选) -编辑 OpenClaw 的配置文件(常见位置:`~/.openclaw/openclaw.json`),在 **根级** 增加或合并 `plugins` 段,并把记忆槽指向本插件,并写上 PowerMem 的地址。 +若 PowerMem 在 **http://localhost:8000** 且使用默认选项,可跳过本步。若要 **自定义**(如改 URL、API Key 或使用 CLI 模式),请编辑 OpenClaw 配置文件(如 `~/.openclaw/openclaw.json`),增加或合并 `plugins` 段。 **示例(JSON):** diff --git a/config.ts b/config.ts index 987d7f4..53fa9a8 100644 --- a/config.ts +++ b/config.ts @@ -149,6 +149,18 @@ function toRecallScoreThreshold(v: unknown): number { export const DEFAULT_USER_ID = "openclaw-user"; export const DEFAULT_AGENT_ID = "openclaw-agent"; +/** + * Default plugin config when openclaw.json has no plugins.entries["memory-powermem"].config. + * Allows "openclaw plugins install openclaw-extension-powermem" to work without manual config. + */ +export const DEFAULT_PLUGIN_CONFIG: PowerMemConfig = { + mode: "http", + baseUrl: "http://localhost:8000", + autoCapture: true, + autoRecall: true, + inferOnAdd: true, +}; + export function resolveUserId(cfg: PowerMemConfig): string { return cfg.userId ?? DEFAULT_USER_ID; } diff --git a/index.ts b/index.ts index 8093c65..4b06121 100644 --- a/index.ts +++ b/index.ts @@ -16,6 +16,7 @@ import type { OpenClawPluginServiceContext } from "openclaw/plugin-sdk"; import { powerMemConfigSchema, + DEFAULT_PLUGIN_CONFIG, resolveUserId, resolveAgentId, type PowerMemConfig, @@ -36,7 +37,15 @@ const memoryPlugin = { configSchema: powerMemConfigSchema, register(api: OpenClawPluginApi) { - const cfg = powerMemConfigSchema.parse(api.pluginConfig) as PowerMemConfig; + const raw = api.pluginConfig; + const toParse = + raw && + typeof raw === "object" && + !Array.isArray(raw) && + Object.keys(raw).length > 0 + ? { ...DEFAULT_PLUGIN_CONFIG, ...raw } + : DEFAULT_PLUGIN_CONFIG; + const cfg = powerMemConfigSchema.parse(toParse) as PowerMemConfig; const userId = resolveUserId(cfg); const agentId = resolveAgentId(cfg); const client =