fix(plugin): update tools.allow via parsed object instead of raw string replacement#1378
Open
CN-P5 wants to merge 1 commit intoMemTensor:mainfrom
Open
fix(plugin): update tools.allow via parsed object instead of raw string replacement#1378CN-P5 wants to merge 1 commit intoMemTensor:mainfrom
CN-P5 wants to merge 1 commit intoMemTensor:mainfrom
Conversation
- 简化 openclaw.json 中 tools.allow 的修改逻辑,直接操作对象而非字符串替换 - 统一搜索结果格式化代码的缩进风格 - 移除不必要的字符串操作,提高代码可读性
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR simplifies how the plugin updates
tools.allowinopenclaw.jsonby modifying the parsed JSON object directly instead of patching the raw file content with string replacement.In addition, it:
Fixes fix: Title: memos-local-openclaw-plugin corrupts openclaw.json by inserting "group:plugins" into models[*].input #1377
Problem
The previous implementation parsed
openclaw.json, but then used a regex-based string replacement on the raw file content to append"group:plugins"totools.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].inputwhich 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
openclaw.jsonwhere:tools.allowdoes not contain"group:plugins"models.providers.vvvapi.models[0].input) ends with the same last value astools.allow"group:plugins"is appended only totools.allowmodels.providers.vvvapi.models[0].inputremain unchangedopenclaw.jsonis valid and can be loaded successfullyVerified Result
After this change, the plugin updates only
cfg.tools.allowand no longer corrupts other arrays inopenclaw.json.Checklist
如果你暂时没加测试,就别勾那一项。可以先这样: