Skip to content

fix(plugin): update tools.allow via parsed object instead of raw string replacement#1378

Open
CN-P5 wants to merge 1 commit intoMemTensor:mainfrom
CN-P5:fix-#1377
Open

fix(plugin): update tools.allow via parsed object instead of raw string replacement#1378
CN-P5 wants to merge 1 commit intoMemTensor:mainfrom
CN-P5:fix-#1377

Conversation

@CN-P5
Copy link
Copy Markdown

@CN-P5 CN-P5 commented Mar 28, 2026

Summary

This PR simplifies how the plugin updates tools.allow in openclaw.json by modifying the parsed JSON object directly instead of patching the raw file content with string replacement.
In addition, it:

Problem

The previous implementation parsed openclaw.json, but then used a regex-based string replacement on the raw file content to append "group:plugins" to tools.allow.
Because the replacement was performed on the full raw JSON string without being scoped to tools.allow, it could accidentally match another array that ended with the same last value. In practice, this could inject "group:plugins" into unrelated config fields such as:

models.providers.xxxx.models[0].input

which then caused config validation failures.

Solution
This PR updates the logic to work on the parsed object directly:

parse openclaw.json
ensure cfg.tools.allow exists and is an array
append "group:plugins" only if it is not already present
write the updated object back using JSON.stringify(...)
This avoids accidental modification of unrelated arrays and makes the code easier to understand and maintain.

Additional cleanup
unified indentation/style in search result formatting code
removed unnecessary string-based operations to improve readability
Dependencies
No new dependencies were added.

Related Issue
Fixes #1377


Type of change

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Refactor (does not change functionality, e.g. code style improvements, linting)

  • Documentation update
    How Has This Been Tested?
    如果你现在还没有单元测试,可以先写成手工复现测试步骤:

  • Unit Test

  • Test Script Or Test Steps (please provide)

  • Pipeline Automated API Test (please provide)

Test Steps

  1. Prepare an openclaw.json where:
    • tools.allow does not contain "group:plugins"
    • another array (for example models.providers.vvvapi.models[0].input) ends with the same last value as tools.allow
  2. Run the plugin initialization / config patching logic.
  3. Verify that:
    • "group:plugins" is appended only to tools.allow
    • unrelated arrays such as models.providers.vvvapi.models[0].input remain unchanged
    • the resulting openclaw.json is valid and can be loaded successfully

Verified Result

After this change, the plugin updates only cfg.tools.allow and no longer corrupts other arrays in openclaw.json.
Checklist
如果你暂时没加测试,就别勾那一项。可以先这样:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

- 简化 openclaw.json 中 tools.allow 的修改逻辑,直接操作对象而非字符串替换
- 统一搜索结果格式化代码的缩进风格
- 移除不必要的字符串操作,提高代码可读性
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Title: memos-local-openclaw-plugin corrupts openclaw.json by inserting "group:plugins" into models[*].input

1 participant