-
Notifications
You must be signed in to change notification settings - Fork 166
zg install --target opencode fails on JSONC configs (comments in opencode.json) #97
Description
Describe the bug
zg install --target opencode throws Invalid JSON when the existing
~/.config/opencode/opencode.json contains // comments (JSONC).
To reproduce
-
Create
~/.config/opencode/opencode.jsonwith a comment (opencode
officially supports JSONC; configs it manages commonly carry comments):{ // "model": "some-model", // e.g. a commented-out model line "mcp": {} } -
Run
zg install --target opencode --yes
Actual result
Error: Invalid JSON in /home/<user>/.config/opencode/opencode.json.
Cause: Expected double-quoted property name in JSON at position ...
Expected result
zg merges its managed zvec_grep MCP entry into the existing config while
preserving the user's comments and unrelated keys.
Root cause (from source)
src/cli/install.ts — parseJsonObject() uses strict JSON.parse. The file
already imports parse from jsonc-parser, but it is only used on the Qoder
path (parseJsoncSettings); the OpenCode (and other mcpServers container)
paths parse with plain JSON.parse.
Suggested fix
Parse agent config files with jsonc-parser everywhere. If the managed entry
is written back with JSON.stringify, also keep the comments — e.g. use a
comment-preserving editor (jsonc-parser's modify/applyEdits or similar) so
the user's commented-out settings survive the install. Uninstall
(uninstallJsonMcpServer) has the same read problem and should be covered
too.
Environment
- zvec-grep: 0.2.1
- Node: v24
- OS: Linux