Skip to content

feat(config): accept comments and trailing commas in programa.json#127

Merged
arzafran merged 1 commit into
mainfrom
port/jsonc-config
Jul 14, 2026
Merged

feat(config): accept comments and trailing commas in programa.json#127
arzafran merged 1 commit into
mainfrom
port/jsonc-config

Conversation

@arzafran

Copy link
Copy Markdown
Member

What this does

Your programa.json (and legacy cmux.json) config files can now have comments in them. If you write // dev commands above a block, or leave a trailing comma after copy-pasting a command entry, the config now loads instead of silently failing. This came from a real parse error a user hit on their own ~/.config/cmux/cmux.json.

Details

  • New Sources/JSONCParser.swift: a shared, string-literal-aware preprocessor that strips // and /* */ comments and trailing commas before handing the file to JSONDecoder. Also handles a BOM and non-UTF8 text encodings, and reports an error for an unterminated block comment instead of silently truncating the file.
  • Sources/ProgramaConfig.swift: ProgramaConfigStore.parseConfig(at:) now runs the file through JSONCParser.preprocess before decoding, with its own error log line so a JSONC syntax problem is distinguishable from a schema problem.
  • Sources/ProgramaSettingsFileStore.swift had its own, older, private copy of this exact parser (used for settings.json). Removed the duplicate and pointed it at the shared one, so both config surfaces get the same (now more robust) behavior for free.
  • Tests: added ProgramaConfigJSONCDecodingTests in programaTests/ProgramaConfigTests.swift — comments (line + block), trailing commas (array + object), mixed comments/commas, comment-like text inside strings, BOM handling, and error cases (unterminated block comment, comment-only file, malformed JSON after stripping). Plain JSON without any JSONC extras is also covered to confirm nothing regresses there.

Scope

This ports the parser and config-merge logic from upstream cmux commit 4d0b1dbd1 ("Make cmux.json the canonical settings file (#3409)"). It explicitly does not port the settings-window UI redesign that shipped in the same upstream commit — that's a separate, larger feature (unifying settings.json/cmux.json/UI) outside this change's scope.

Testing

```
PROGRAMA_SKIP_ZIG_BUILD=1 xcodebuild -scheme programa-unit -derivedDataPath /tmp/programa-w1-jsonc
-parallel-testing-enabled NO
-only-testing:programaTests/ProgramaConfigDecodingTests
-only-testing:programaTests/ProgramaConfigJSONCDecodingTests test
```

Result: TEST SUCCEEDED — 37 tests executed, 0 failures.

Config parsing now runs through a shared JSONCParser before decoding, so
hand-edited ~/.config/programa/programa.json and project-local
programa.json/cmux.json files can use // and /* */ comments and trailing
commas without breaking. This fixes a real parse failure a user hit on
their ~/.config/cmux/cmux.json (a stray comment triggered "Unexpected
character '/'").

The parser also replaces the private, less-robust copy that lived inside
ProgramaSettingsFileStore.swift (settings.json parsing), so both config
surfaces now share one implementation with encoding detection and
unterminated-comment detection.

Ported from upstream cmux commit 4d0b1dbd1 ("Make cmux.json the canonical
settings file (#3409)"), parser and config-merge logic only. The
settings-window UI redesign that shipped in the same upstream commit is
out of scope here and was not ported.
@arzafran
arzafran merged commit a716706 into main Jul 14, 2026
6 of 9 checks passed
@arzafran
arzafran deleted the port/jsonc-config branch July 20, 2026 15:30
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