Repository navigation
Fix #1543: fix: MEMOS不支持JSON5格式的openclaw.json - #1990
Merged
Merged
Conversation
OpenClaw stores its host config as JSON5 (// comments, single quotes, trailing commas, unquoted identifier keys). The plugin previously read the file via strict JSON.parse in 6 places, including the tools.allow patcher that runs on every plugin startup. Users hitting any JSON5 syntax saw: warn plugins memos-local: could not patch tools.allow: SyntaxError: Expected double-quoted property name in JSON at position 2222 This change introduces: * src/shared/json5.ts — zero-dependency JSON5-tolerant parser (parseJsonOrJson5 + parseJson5 + normalizeJson5). Tries strict JSON.parse first, falls back to a state-machine normalizer that strips // and /* */ comments (respecting string literals), converts single quotes, quotes unquoted identifier keys, and tolerates trailing commas and BOM. * src/shared/openclaw-config.ts — extracts the tools.allow patcher into a testable helper, anchors on both double- and single-quoted last entries, tolerates trailing commas, never throws. Replaces JSON.parse(fs.readFileSync(<openclaw.json>...)) at all 6 read sites (index.ts, src/shared/llm-call.ts, src/ingest/providers/index.ts, src/viewer/server.ts × 6). Plain JSON config files are unaffected by the strict-JSON fast path. Test coverage: * tests/json5-config.test.ts — 14 cases (issue case, block comments, trailing commas, single/mixed quotes, unquoted keys, BOM, strings containing // and /* */, malformed, end-to-end via loadOpenClawFallbackConfig). * tests/openclaw-config-patch.test.ts — 7 cases (patch w/ comments / single quotes / trailing commas; no-op when already permissive / empty; no throw on malformed). vitest: 21 new tests + 84 regression tests pass; tsc --noEmit clean.
Memtensor-AI
requested review from
CarltonXiang,
MatthewZhuang,
World-controller and
syzsunshine219
June 30, 2026 11:23
3 of 5 tasks
Collaborator
Author
❌ Automated Test Results: FAILED
Failed tests:
Error detailsBranch: |
Collaborator
Author
|
Cloud verification update (test-engine v2): FAILED. Run Failure: |
Collaborator
Author
|
Automated Test Results: PASSED Cloud test-engine rerun against
This replaces the earlier failed signal for this PR. Manual code review is still required before merge. |
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.
Description
Fix issue #1543: memos-local-openclaw plugin now reads ~/.openclaw/openclaw.json as JSON5 instead of strict JSON.
Root cause: OpenClaw's host config is officially JSON5 (allows
//and/* */comments, single-quoted strings, unquoted identifier keys, trailing commas). The plugin previously called strictJSON.parseon the file in six places, including thetools.allowpatcher that runs on every plugin startup — which is what produced the reported warningmemos-local: could not patch tools.allow: SyntaxError: Expected double-quoted property name in JSON at position 2222 (line 90 column 7)whenever a user kept comments in their config.Fix:
src/shared/json5.tsprovidesparseJsonOrJson5— a strict-JSON fast path with a JSON5-tolerant fallback that strips comments via a string-respecting state machine, rewrites single quotes, quotes unquoted identifier keys, and tolerates trailing commas and UTF-8 BOM.src/shared/openclaw-config.tsextracts thetools.allowpatch logic into a unit-testable helper that anchors on both double- and single-quoted last entries and tolerates trailing commas. It never throws.JSON.parse(fs.readFileSync(<openclaw.json>...))call sites are routed through the new helper:index.ts,src/shared/llm-call.ts,src/ingest/providers/index.ts, and six endpoints insidesrc/viewer/server.ts. Plain-JSON configs are unaffected thanks to the fast path.Tests added (21 new, all green):
tests/json5-config.test.tscovers the issue case, block comments, trailing commas, single/mixed quotes, unquoted keys, BOM, the classic "// inside a URL string literal" bug, malformed input, and an end-to-end exercise ofloadOpenClawFallbackConfig.tests/openclaw-config-patch.test.tscovers the patcher across comments, single quotes, trailing commas, and the no-op paths (*, already-present, empty, malformed). Regression sweep acrossopenclaw-fallback,config,viewer-config,storage,policy,capture,recall,chunker,migration-status,postinstall-native-binding— 105 tests pass;tsc --noEmitclean.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