Fix #1543: fix: MEMOS不支持JSON5格式的openclaw.json#2048
Conversation
The memos-local-openclaw plugin failed to patch tools.allow at startup whenever the user's openclaw.json contained // comments, single-quoted strings or trailing commas, because every read site used JSON.parse. Add a tiny shared helper (src/shared/openclaw-config.ts) that parses with json5 (strict JSON is a subset, so nothing regresses) and route all runtime + script read sites through it. The regex-based tools.allow insertion is unchanged for the common double-quoted case; when the regex cannot safely locate the insertion point we now warn asking the user to add "group:plugins" manually instead of silently doing nothing. Adds json5@^2.2.3 to plugin deps and 11 vitest cases covering line and block comments, single-quoted keys/values, trailing commas, unquoted identifier keys, and end-to-end loadOpenClawFallbackConfig on a JSON5 config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🤖 Open Code ReviewTarget: PR #2048 🔍 OpenCodeReview found 14 issue(s) in this PR. 1.
|
🤖 Open Code ReviewTarget: PR #2048 🔍 OpenCodeReview found 5 issue(s) in this PR. 1.
|
🤖 Open Code ReviewTarget: PR #2048 🔍 OpenCodeReview found 15 issue(s) in this PR. 1.
|
|
Description
Fixes MemOS issue #1543: the
memos-local-openclaw-pluginused rawJSON.parsewhen reading the user'sopenclaw.json, so any config with//line comments, single-quoted strings or trailing commas causedSyntaxError: Expected double-quoted property nameat startup, silently disabling thetools.allowpatch step and blocking plugin tools.The fix introduces a small shared helper
apps/memos-local-openclaw/src/shared/openclaw-config.tsthat parses openclaw.json withjson5@^2.2.3(strict JSON is a subset, so nothing regresses), and routes all runtime + script read sites through it:index.ts(tools.allow patch),src/shared/llm-call.ts,src/ingest/providers/index.ts,src/viewer/server.ts, plus the fourscripts/*.tsmaintenance scripts. The regex-basedtools.allowinsertion is left untouched for the common double-quoted case; when the regex cannot safely locate the insertion point, we now log a clearwarnasking the user to add"group:plugins"manually instead of silently doing nothing.Test evidence:
npx tsc --noEmitclean; new filetests/openclaw-json5.test.tsadds 11 cases covering line/block comments, single-quoted keys/values, trailing commas, unquoted identifier keys, and end-to-endloadOpenClawFallbackConfigon a JSON5 config — 11/11 pass. Existingtests/openclaw-fallback.test.ts(16/16),tests/viewer-config.test.ts,tests/config.test.ts,tests/integration.test.ts(26/26) all still pass. The 5 unrelated failures in the full vitest run (task-processor,accuracy,skill-auto-install,update-install) touch none of the modified files; they are pre-existing environmental flakes (native binding / process signals / embedding accuracy).Related Issue (Required): Fixes #1543
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist