Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
refactor(openclaw-memory-plugin): use openclaw CLI instead of direct JSON manipulation (#550)
Qin Haojie7c8217b13bb5
diff --git a/examples/openclaw-memory-plugin/install.ps1 b/examples/openclaw-memory-plugin/install.ps1index 92332b3c6..5f0aa488f 100644--- a/examples/openclaw-memory-plugin/install.ps1+++ b/examples/openclaw-memory-plugin/install.ps1@@ -367,69 +367,40 @@ function Configure-OpenClawPlugin {param([int]$ServerPort)Info (T "Configuring OpenClaw plugin..." "正在配置 OpenClaw 插件...")- $cfgPath = Join-Path $OpenClawDir "openclaw.json"- $cfg = @{}- if (Test-Path $cfgPath) {- try {- $raw = Get-Content -Raw -Path $cfgPath- if (-not [string]::IsNullOrWhiteSpace($raw)) {- $obj = $raw | ConvertFrom-Json -AsHashtable- if ($obj) { $cfg = $obj }- }- } catch {- Warn (T "Existing openclaw.json is invalid. Rebuilding required sections." "检测到已有 openclaw.json 非法,将重建相关配置节点。")- }- }-- if (-not $cfg.ContainsKey("plugins")) { $cfg["plugins"] = @{} }- if (-not $cfg.ContainsKey("gateway")) { $cfg["gateway"] = @{} }- if (-not $cfg["plugins"].ContainsKey("slots")) { $cfg["plugins"]["slots"] = @{} }- if (-not $cfg["plugins"].ContainsKey("load")) { $cfg["plugins"]["load"] = @{} }- if (-not $cfg["plugins"].ContainsKey("entries")) { $cfg["plugins"]["entries"] = @{} }-- # Keep plugin load paths unique.- $existingPaths = @()- if ($cfg["plugins"]["load"].ContainsKey("paths") -and $cfg["plugins"]["load"]["paths"]) {- $existingPaths = @($cfg["plugins"]["load"]["paths"])+ $oldStateDir = $env:OPENCLAW_STATE_DIR+ if ($OpenClawDir -ne (Join-Path $HomeDir ".openclaw")) {+ $env:OPENCLAW_STATE_DIR = $OpenClawDir}- $mergedPaths = @($existingPaths + @($PluginDest) | Select-Object -Unique)- $cfg["plugins"]["enabled"] = $true- $existingAllow = @()- if ($cfg["plugins"].ContainsKey("allow") -and $cfg["plugins"]["allow"]) {- $existingAllow = @($cfg["plugins"]["allow"])- }- if ($existingAllow -notcontains "memory-openviking") {- $existingAllow += "memory-openviking"- }- $cfg["plugins"]["allow"] = $existingAllow- $cfg["plugins"]["slots"]["memory"] = "memory-openviking"- $cfg["plugins"]["load"]["paths"] = $mergedPaths-- $pluginConfig = @{- mode = $SelectedMode- targetUri = "viking://user/memories"- autoRecall = $true- autoCapture = $true- }+ try {+ # Enable plugin (files already deployed to extensions dir by Deploy-Plugin)+ openclaw plugins enable memory-openviking+ if ($LASTEXITCODE -ne 0) { throw "openclaw plugins enable failed (exit code $LASTEXITCODE)" }++ # Set gateway mode+ openclaw config set gateway.mode local++ # Set plugin config for the selected mode+ if ($SelectedMode -eq "local") {+ $ovConfPath = Join-Path $OpenVikingDir "ov.conf"+ openclaw config set plugins.entries.memory-openviking.config.mode local+ openclaw config set plugins.entries.memory-openviking.config.configPath $ovConfPath+ openclaw config set plugins.entries.memory-openviking.config.port $ServerPort+ } else {+ openclaw config set plugins.entries.memory-openviking.config.mode remote+ openclaw config set plugins.entries.memory-openviking.config.baseUrl $RemoteBaseUrl+ if ($RemoteApiKey) {+ openclaw config set plugins.entries.memory-openviking.config.apiKey $RemoteApiKey+ }+ if ($RemoteAgentId) {+ openclaw config set plugins.entries.memory-openviking.config.agentId $RemoteAgentId+ }+ }- if ($SelectedMode -eq "local") {- $ovConfPath = Join-Path $OpenVikingDir "ov.conf"- $pluginConfig["configPath"] = $ovConfPath- $pluginConfig["port"] = $ServerPort- } else {- $pluginConfig["baseUrl"] = $RemoteBaseUrl- if ($RemoteApiKey) { $pluginConfig["apiKey"] = $RemoteApiKey }- if ($RemoteAgentId) { $pluginConfig["agentId"] = $RemoteAgentId }+ Info (T "OpenClaw plugin configured" "OpenClaw 插件配置完成")+ } finally {+ $env:OPENCLAW_STATE_DIR = $oldStateDir}-- $cfg["plugins"]["entries"]["memory-openviking"] = @{ config = $pluginConfig }- $cfg["gateway"]["mode"] = "local"-- $cfgJson = $cfg | ConvertTo-Json -Depth 20- Write-Utf8NoBom -Path $cfgPath -Content $cfgJson-- Info (T "OpenClaw plugin configured" "OpenClaw 插件配置完成")}function Write-OpenVikingEnv {diff --git a/examples/openclaw-memory-plugin/install.sh b/examples/openclaw-memory-plugin/install.shold mode 100644new mode 100755index f135c1997..7421e8d8b--- a/examples/openclaw-memory-plugin/install.sh+++ b/examples/openclaw-memory-plugin/install.sh@@ -620,35 +620,20 @@ configure_openclaw_plugin() {oc_env=(env OPENCLAW_STATE_DIR="$OPENCLAW_DIR")fi- "${oc_env[@]}" openclaw config set plugins.enabled true- # Merge into existing allow list instead of overwriting- local existing_allow- existing_allow=$("${oc_env[@]}" openclaw config get plugins.allow --json 2>/dev/null || echo '[]')- if ! echo "$existing_allow" | grep -q '"memory-openviking"'; then- existing_allow=$(echo "$existing_allow" | sed 's/]$//' | sed 's/$/,"memory-openviking"]/' | sed 's/\[,/[/')- fi- "${oc_env[@]}" openclaw config set plugins.allow "$existing_allow" --json+ # Enable plugin (files already deployed to extensions dir by deploy_plugin)+ "${oc_env[@]}" openclaw plugins enable memory-openviking || { err "$(tr "openclaw plugins enable failed" "openclaw 插件启用失败")"; exit 1; }+ # Set gateway mode"${oc_env[@]}" openclaw config set gateway.mode local- "${oc_env[@]}" openclaw config set plugins.slots.memory memory-openviking-- # Merge into existing load paths instead of overwriting- local existing_paths- existing_paths=$("${oc_env[@]}" openclaw config get plugins.load.paths --json 2>/dev/null || echo '[]')- if ! echo "$existing_paths" | grep -q "\"${PLUGIN_DEST}\""; then- existing_paths=$(echo "$existing_paths" | sed 's|]$||' | sed "s|$|,\"${PLUGIN_DEST}\"]|" | sed 's|\[,|[|')- fi- "${oc_env[@]}" openclaw config set plugins.load.paths "$existing_paths" --json- "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.mode "${SELECTED_MODE}"- "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.targetUri viking://user/memories- "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.autoRecall true --json- "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.autoCapture true --json+ # Set plugin config for the selected modeif [[ "$SELECTED_MODE" == "local" ]]; then- local config_path="${OPENVIKING_DIR}/ov.conf"- "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.configPath "${config_path}"+ local ov_conf_path="${OPENVIKING_DIR}/ov.conf"+ "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.mode local+ "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.configPath "${ov_conf_path}""${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.port "${SELECTED_SERVER_PORT}"else+ "${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.mode remote"${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.baseUrl "${remote_base_url}"if [[ -n "${remote_api_key}" ]]; then"${oc_env[@]}" openclaw config set plugins.entries.memory-openviking.config.apiKey "${remote_api_key}"diff --git a/examples/openclaw-memory-plugin/setup-helper/install.js b/examples/openclaw-memory-plugin/setup-helper/install.jsindex aa25e0359..2d196ca49 100644--- a/examples/openclaw-memory-plugin/setup-helper/install.js+++ b/examples/openclaw-memory-plugin/setup-helper/install.js@@ -641,51 +641,37 @@ async function downloadPlugin() {async function configureOpenClawPlugin(pluginPath = PLUGIN_DEST) {info(tr("Configuring OpenClaw plugin...", "正在配置 OpenClaw 插件..."));- const configPath = join(OPENCLAW_DIR, "openclaw.json");- let config = {};-- if (existsSync(configPath)) {- try {- const raw = await readFile(configPath, "utf8");- if (raw.trim()) config = JSON.parse(raw);- } catch {- warn(tr("Existing openclaw.json invalid. Rebuilding required sections.", "已有 openclaw.json 非法,将重建相关配置节点。"));- }+ const ocEnv = { ...process.env };+ if (OPENCLAW_DIR !== DEFAULT_OPENCLAW_DIR) {+ ocEnv.OPENCLAW_STATE_DIR = OPENCLAW_DIR;}- if (!config.plugins) config.plugins = {};- if (!config.gateway) config.gateway = {};- if (!config.plugins.slots) config.plugins.slots = {};- if (!config.plugins.load) config.plugins.load = {};- if (!config.plugins.entries) config.plugins.entries = {};+ const oc = (args) => runCapture("openclaw", args, { env: ocEnv, shell: IS_WIN });- const existingPaths = Array.isArray(config.plugins.load.paths) ? config.plugins.load.paths : [];- config.plugins.enabled = true;- config.plugins.allow = ["memory-openviking"];- config.plugins.slots.memory = "memory-openviking";- config.plugins.load.paths = [...new Set([...existingPaths, pluginPath])];+ // Enable plugin (files already deployed to extensions dir by deployPlugin)+ const enableResult = await oc(["plugins", "enable", "memory-openviking"]);+ if (enableResult.code !== 0) throw new Error(`openclaw plugins enable failed (exit code ${enableResult.code})`);- const pluginConfig = {- mode: selectedMode,- targetUri: "viking://user/memories",- autoRecall: true,- autoCapture: true,- };+ // Set gateway mode+ await oc(["config", "set", "gateway.mode", "local"]);+ // Set plugin config for the selected modeif (selectedMode === "local") {- pluginConfig.configPath = join(OPENVIKING_DIR, "ov.conf");- pluginConfig.port = selectedServerPort;+ const ovConfPath = join(OPENVIKING_DIR, "ov.conf");+ await oc(["config", "set", "plugins.entries.memory-openviking.config.mode", "local"]);+ await oc(["config", "set", "plugins.entries.memory-openviking.config.configPath", ovConfPath]);+ await oc(["config", "set", "plugins.entries.memory-openviking.config.port", String(selectedServerPort)]);} else {- pluginConfig.baseUrl = remoteBaseUrl;- if (remoteApiKey) pluginConfig.apiKey = remoteApiKey;- if (remoteAgentId) pluginConfig.agentId = remoteAgentId;+ await oc(["config", "set", "plugins.entries.memory-openviking.config.mode", "remote"]);+ await oc(["config", "set", "plugins.entries.memory-openviking.config.baseUrl", remoteBaseUrl]);+ if (remoteApiKey) {+ await oc(["config", "set", "plugins.entries.memory-openviking.config.apiKey", remoteApiKey]);+ }+ if (remoteAgentId) {+ await oc(["config", "set", "plugins.entries.memory-openviking.config.agentId", remoteAgentId]);+ }}- config.plugins.entries["memory-openviking"] = { config: pluginConfig };- config.gateway.mode = "local";-- await mkdir(OPENCLAW_DIR, { recursive: true });- await writeFile(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");info(tr("OpenClaw plugin configured", "OpenClaw 插件配置完成"));}