Skip to content

fix(cli-tools): tolerate JSONC configs in CLI tool settings routes#1897

Open
Zireael wants to merge 1 commit into
decolua:masterfrom
Zireael:fix/cli-tools-jsonc-detection
Open

fix(cli-tools): tolerate JSONC configs in CLI tool settings routes#1897
Zireael wants to merge 1 commit into
decolua:masterfrom
Zireael:fix/cli-tools-jsonc-detection

Conversation

@Zireael

@Zireael Zireael commented Jun 18, 2026

Copy link
Copy Markdown

Summary

CLI tool detection fails when a tool's config file contains trailing commas (JSONC). The readConfig/readSettings/readJson functions used JSON.parse() but only caught ENOENT — a SyntaxError from trailing commas was re-thrown, causing the settings API to return HTTP 500. The UI interpreted the 500 response (missing installed field) as "tool not installed."

This affected 8 CLI tool routes: opencode, openclaw, kilo, droid, cowork, copilot, claude, and cline.

To explain it simply, if CLI .jsonc config file contains syntax that is invalid as per .json specs, 9router will end up saying thay the CLI is not installed.

What changed

Each affected route's config-reading function now:

  1. Strips trailing commas before parsing (/,(\s*[}\]])/g$1), so JSONC-formatted configs parse without error.
  2. Returns null on any remaining parse error instead of re-throwing, so the UI shows "installed but not configured" (accurate) rather than "not installed" (misleading).

The opencode fix also retains the explicit ENOENT check (for clarity), while the other 7 routes use a blanket return null in catch — both are functionally equivalent since null is already the ENOENT fallback.

Verification

I removed trailing commas from my opencode.jsonc config file and 9router started detecting opencode as installed again.

readConfig/readSettings/readJson across all CLI tool settings routes used
JSON.parse() but only caught ENOENT, re-throwing SyntaxError on any
corrupted or JSONC-formatted config file. The API would return 500, which
the UI misinterpreted as "tool not installed."

This patch:
- strips trailing commas before parsing (handles JSONC from opencode, etc.)
- returns null on any parse error instead of re-throwing, so the UI shows
  "installed but not configured" (accurate) instead of "not installed"
- applies the same fix to all 8 affected routes: opencode, openclaw, kilo,
  droid, cowork, copilot, claude, and cline
bloodf pushed a commit to bloodf/9router that referenced this pull request Jun 19, 2026
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.

1 participant