Skip to content

fix: MEMOS不支持JSON5格式的openclaw.json #1543

Closed

Description

@zzyyll2

Pre-submission checklist | 提交前检查

  • I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
  • I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
  • This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题

Bug Description | 问题描述

openclaw.json文件是json5的,里面可以使用注释,可以双引号,非双引号混合使用,
memos试图修改tools.allow节点失败了,我看了代码使用的是JSON库,而非JOSN5库

2026-04-24T14:32:11.587+08:00 warn plugins {"subsystem":"plugins"} memos-local: could not patch tools.allow: SyntaxError: Expected double-quoted property name in JSON at position 2222 (line 90 column 7)

How to Reproduce | 如何重现

openclaw.json文件里添加 // 这样的注释,必现。

Environment | 环境信息

最新版本(2026-04-24)

Additional Context | 其他信息

No response

Willingness to Implement | 实现意愿

  • I'm willing to implement this myself | 我愿意自己解决
  • I would like someone else to implement this | 我希望其他人来解决

Activity

  1. zzyyll2 commented on Apr 24, 2026

    @zzyyll2
    Author

    WEB界面保存配置的时候也是这个报错,没有测试过吗,你们的openclaw.json都是非常标准的JOSN,而非JSON5吗

  2. MaiHHConnect commented on Apr 25, 2026

    @MaiHHConnect
  3. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 29, 2026
  4. self-assigned this
    on Jun 30, 2026
  5. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

    🤖 AutoDev has picked up this issue and started working on it.

    Task ID: 8ac61a4dda0016a5
    Working branch: bugfix/autodev-1543
    Target branch: latest dev* branch
    Workflow: opsp (analysis → coding → testing → PR)

    I will post the PR link here once done. If I need more information, I will ask in the comments.

  6. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 8ac61a4dda0016a5 completed.

    Summary: 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 strict JSON.parse on the file in six places, including the tools.allow patcher that runs on every plugin startup — which is what produced the reported warning memos-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:

    1. New zero-dependency src/shared/json5.ts provides parseJsonOrJson5 — 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.
    2. New src/shared/openclaw-config.ts extracts the tools.allow patch logic into a unit-testable helper that anchors on both double- and single-quoted last entries and tolerates trailing commas. It never throws.
    3. All six 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 inside src/viewer/server.ts. Plain-JSON configs are unaffected thanks to the fast path.

    Tests added (21 new, all green): tests/json5-config.test.ts covers 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 of loadOpenClawFallbackConfig. tests/openclaw-config-patch.test.ts covers the patcher across comments, single quotes, trailing commas, and the no-op paths (*, already-present, empty, malformed). Regression sweep across openclaw-fallback, config, viewer-config, storage, policy, capture, recall, chunker, migration-status, postinstall-native-binding — 105 tests pass; tsc --noEmit clean.

    Base branch: main
    Branch: bugfix/autodev-1543
    Commit: 07b5e16
    PR: #1990
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  7. added
    ai:testingAI agent is running tests | AI 正在运行测试
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Jun 30, 2026
  8. added a commit that references this issue on Jul 2, 2026
    b50246b
  9. added
    ai:codingAI agent is coding | AI 正在编码
    and removed
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jul 2, 2026
  10. Memtensor-AI commented on Jul 2, 2026

    @Memtensor-AI
    Collaborator

    🤖 AutoDev has picked up this issue and started working on it.

    Task ID: fde1c36c0dd31bb1
    Working branch: bugfix/autodev-1543
    Target branch: latest dev* branch
    Workflow: opsp (analysis → coding → testing → PR)

    I will post the PR link here once done. If I need more information, I will ask in the comments.

  11. Memtensor-AI commented on Jul 2, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task fde1c36c0dd31bb1 completed.

    Summary: Fixes MemOS issue #1543: the memos-local-openclaw-plugin used raw JSON.parse when reading the user's openclaw.json, so any config with // line comments, single-quoted strings or trailing commas caused SyntaxError: Expected double-quoted property name at startup, silently disabling the tools.allow patch step and blocking plugin tools.

    The fix introduces a small shared helper apps/memos-local-openclaw/src/shared/openclaw-config.ts that parses openclaw.json with json5@^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 four scripts/*.ts maintenance scripts. The regex-based tools.allow insertion is left untouched for the common double-quoted case; when the regex cannot safely locate the insertion point, we now log a clear warn asking the user to add "group:plugins" manually instead of silently doing nothing.

    Test evidence: npx tsc --noEmit clean; new file tests/openclaw-json5.test.ts adds 11 cases covering line/block comments, single-quoted keys/values, trailing commas, unquoted identifier keys, and end-to-end loadOpenClawFallbackConfig on a JSON5 config — 11/11 pass. Existing tests/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).

    Base branch: main
    Branch: bugfix/autodev-1543
    Commit: 95f3fb3
    PR: #2048
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  12. added
    ai:testingAI agent is running tests | AI 正在运行测试
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai:testingAI agent is running tests | AI 正在运行测试area:pluginOpenClaw & Hermestypes:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions