Skip to content

fix: parse OpenClaw config with JSON5 for model catalog#210

Merged
daggerhashimoto merged 1 commit intodaggerhashimoto:masterfrom
kimbotai1337:fix/json5-openclaw-config-model-catalog
Mar 31, 2026
Merged

fix: parse OpenClaw config with JSON5 for model catalog#210
daggerhashimoto merged 1 commit intodaggerhashimoto:masterfrom
kimbotai1337:fix/json5-openclaw-config-model-catalog

Conversation

@kimbotai1337
Copy link
Copy Markdown
Collaborator

@kimbotai1337 kimbotai1337 commented Mar 31, 2026

Summary

Fixes the false-positive header warning from #209.

Closes #209.

What changed

  • switched /api/gateway/models from JSON.parse to JSON5.parse
  • added json5 as a runtime dependency
  • added a regression test for JSON5-style config syntax

Why

Nerve v1.5.2 started reading configured models directly from the active OpenClaw config. If openclaw.json used JSON5-style syntax (comments, unquoted keys, trailing commas), Nerve could fail to parse it and show:

⚠ Could not read OpenClaw config.

even though OpenClaw itself was working normally.

Verification

  • npm test -- server/routes/gateway.test.ts
  • npm run build:server

Also verified live:

  • pre-fix instance showed the warning
  • fixed instance no longer showed it

Summary by CodeRabbit

  • New Features

    • Configuration files now support JSON5 format, enabling comments and trailing commas for improved readability and flexibility.
  • Tests

    • Added test coverage for JSON5 configuration file parsing.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The changes add support for JSON5 format (which allows comments and trailing commas) when parsing OpenClaw configuration files. This involves adding the json5 dependency, updating the gateway route to use JSON5.parse() instead of JSON.parse(), and adding a test case to verify the new functionality works correctly.

Changes

Cohort / File(s) Summary
JSON5 Dependency
package.json
Added json5@^2.2.3 as a runtime dependency.
Config Parsing Enhancement
server/routes/gateway.ts
Imported json5 and switched from JSON.parse() to JSON5.parse() for parsing OpenClaw configuration, enabling support for JSON5 format with comments and trailing commas.
Test Coverage
server/routes/gateway.test.ts
Added new test case for GET /api/gateway/models that validates parsing of JSON5-formatted OpenClaw configuration and confirms correct model catalog response.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A config with comments, oh what a delight!
JSON5 now parsing makes everything right,
No more warnings haunting the header so bright,
OpenClaw reads freely without a strict fight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: switching to JSON5 parsing for OpenClaw config in the model catalog endpoint.
Description check ✅ Passed The description comprehensively covers all template sections: what changed, why it matters, how it was verified, and includes a link to the related issue #209.
Linked Issues check ✅ Passed The PR successfully addresses issue #209 by replacing JSON.parse with JSON5.parse to handle JSON5-style config syntax, eliminating the false-positive warning when configs use comments, unquoted keys, or trailing commas.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the config parsing issue: adding json5 dependency, updating the gateway route parser, and adding a regression test for JSON5 syntax.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@daggerhashimoto daggerhashimoto marked this pull request as ready for review March 31, 2026 13:16
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
server/routes/gateway.ts (1)

163-163: Unify OpenClaw config parsing across routes to prevent split behavior.

/api/gateway/models parses ~/.openclaw/openclaw.json with JSON5.parse, while server/routes/channels.ts uses JSON.parse on the same file and silently returns [] on failure. If the config file contains JSON5 syntax (e.g., comments, trailing commas), gateway succeeds but channels silently fails, producing inconsistent UI state (models load, channels disappear). Consider extracting a shared config-reader helper using a consistent parser strategy.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/routes/gateway.ts` at line 163, The OpenClaw config is parsed
inconsistently (gateway.ts uses JSON5.parse while channels.ts uses JSON.parse
and swallows errors); extract a shared helper (e.g., readOpenClawConfig or
parseOpenClawConfig) that reads the ~/.openclaw/openclaw.json and consistently
uses JSON5.parse to return an OpenClawConfig (or a clear fallback) and import it
from both server/routes/gateway.ts and server/routes/channels.ts; update
channels.ts to call this helper instead of JSON.parse, ensure it does not
silently return [] on parse error (log the error via the existing logger and
return a safe default), and keep the helper's API typed so callers (models route
and channels route) handle the same shape consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/routes/gateway.ts`:
- Line 163: The OpenClaw config is parsed inconsistently (gateway.ts uses
JSON5.parse while channels.ts uses JSON.parse and swallows errors); extract a
shared helper (e.g., readOpenClawConfig or parseOpenClawConfig) that reads the
~/.openclaw/openclaw.json and consistently uses JSON5.parse to return an
OpenClawConfig (or a clear fallback) and import it from both
server/routes/gateway.ts and server/routes/channels.ts; update channels.ts to
call this helper instead of JSON.parse, ensure it does not silently return [] on
parse error (log the error via the existing logger and return a safe default),
and keep the helper's API typed so callers (models route and channels route)
handle the same shape consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e86d025-571f-4867-8cc0-7523daa227d2

📥 Commits

Reviewing files that changed from the base of the PR and between c9ad1bd and 0771860.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json
  • server/routes/gateway.test.ts
  • server/routes/gateway.ts

@daggerhashimoto daggerhashimoto merged commit a35ffc0 into daggerhashimoto:master Mar 31, 2026
2 checks passed
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.

Bug: "Could not read OpenClaw config" warning in header after v1.5.1 → v1.5.2

2 participants