Skip to content

refactor(openclaw-memory-plugin): use openclaw CLI for plugin configuration#550

Merged
qin-ctx merged 1 commit intomainfrom
refactor/openclaw-plugin-config-via-cli
Mar 12, 2026
Merged

refactor(openclaw-memory-plugin): use openclaw CLI for plugin configuration#550
qin-ctx merged 1 commit intomainfrom
refactor/openclaw-plugin-config-via-cli

Conversation

@qin-ctx
Copy link
Collaborator

@qin-ctx qin-ctx commented Mar 12, 2026

Description

Replace manual openclaw.json file reading/writing with openclaw plugins enable and openclaw config set CLI commands across all three install scripts. This delegates config validation and merging to the OpenClaw CLI itself, reducing code duplication and avoiding potential conflicts when multiple plugins are installed.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • install.sh: Replaced JSON manipulation (jq/sed merging of allow list and load paths) with openclaw plugins enable + openclaw config set calls
  • install.ps1: Replaced ConvertFrom-Json/ConvertTo-Json config building with CLI commands, wrapped in try/finally for env cleanup
  • install.js: Replaced direct openclaw.json file read/write with runCapture openclaw CLI invocations

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A

Additional Notes

Generated with Claude Code

…JSON manipulation

Replace manual openclaw.json reading/writing with `openclaw plugins enable`
and `openclaw config set` commands across all three install scripts (sh, ps1, js).
This delegates config validation and merging to the CLI, reducing duplication
and avoiding potential conflicts with other plugins.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Mar 12, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Configuration

The new code no longer sets several configuration values that were present in the old implementation, including targetUri, autoRecall, autoCapture, plugins.slots.memory, plugins.load.paths, plugins.allow, and plugins.enabled. Verify if openclaw plugins enable handles these; if not, they need to be added back to avoid functional regression.

async function configureOpenClawPlugin(pluginPath = PLUGIN_DEST) {
  info(tr("Configuring OpenClaw plugin...", "正在配置 OpenClaw 插件..."));

  const ocEnv = { ...process.env };
  if (OPENCLAW_DIR !== DEFAULT_OPENCLAW_DIR) {
    ocEnv.OPENCLAW_STATE_DIR = OPENCLAW_DIR;
  }

  const oc = (args) => runCapture("openclaw", args, { env: ocEnv, shell: IS_WIN });

  // 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})`);

  // Set gateway mode
  await oc(["config", "set", "gateway.mode", "local"]);

  // Set plugin config for the selected mode
  if (selectedMode === "local") {
    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 {
    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]);
    }
  }
Unchecked Config Set Commands

The openclaw config set commands do not check their exit codes, which could lead to silent failures during configuration.

"${oc_env[@]}" openclaw config set gateway.mode local

# Set plugin config for the selected mode
if [[ "$SELECTED_MODE" == "local" ]]; then
  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}"
  fi
Unchecked Config Set Commands

The openclaw config set commands do not check $LASTEXITCODE, which could lead to silent failures during configuration.

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
  }

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Restore missing plugin config settings

Restore the missing plugin configuration settings: targetUri, autoRecall, and
autoCapture. These were present in the original code and are likely required for
proper plugin operation.

examples/openclaw-memory-plugin/setup-helper/install.js [658-673]

+// Set common plugin config
+await oc(["config", "set", "plugins.entries.memory-openviking.config.targetUri", "viking://user/memories"]);
+await oc(["config", "set", "plugins.entries.memory-openviking.config.autoRecall", "true", "--json"]);
+await oc(["config", "set", "plugins.entries.memory-openviking.config.autoCapture", "true", "--json"]);
+
 // Set plugin config for the selected mode
 if (selectedMode === "local") {
   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 {
   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]);
   }
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion restores missing plugin configuration settings (targetUri, autoRecall, autoCapture) that were present in the original code, which are likely required for proper plugin operation.

Medium

@qin-ctx qin-ctx merged commit 7c8217b into main Mar 12, 2026
5 of 6 checks passed
@qin-ctx qin-ctx deleted the refactor/openclaw-plugin-config-via-cli branch March 12, 2026 08:58
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants