Skip to content

fix(installer): preserve comments and key order when editing agent configs - #9

Merged
sunerpy merged 3 commits into
mainfrom
fix/installer-preserve-jsonc-comments
Jun 22, 2026
Merged

sunerpy merged 3 commits into
mainfrom
fix/installer-preserve-jsonc-comments

Conversation

@sunerpy

@sunerpy sunerpy commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

The installer rewrote agent config files with serde_json::to_string_pretty, which dropped all JSONC comments and re-sorted keys alphabetically, scrambling users' hand-maintained configs even when only adding the codegraph entry.

Fix

  • Edit existing configs surgically with jsonc-parser's CST API (upsert_nested_key_jsonc / remove_nested_key_jsonc): only the codegraph property is inserted/updated/removed; every comment, key order, and the file formatting stay intact.
  • Re-runs short-circuit to Unchanged (no churn).
  • Fresh files are still seeded with the canonical shape.
  • All six targets (opencode/claude/cursor/gemini/kiro/antigravity) and the uninstall path go through the surgical helpers.

Verification

  • make ci green (fmt + clippy + test + guardrail).
  • 3 new unit tests: comment + key-order preservation, idempotent no-op, remove preserves comments.
  • Manual QA on a commented, custom-ordered opencode.json: comments + order preserved, codegraph inserted into mcp; re-run = Unchanged (bytes identical); uninstall restores original.

sunerpy added 3 commits June 22, 2026 10:33
…nfigs

The installer rewrote agent config files with serde_json::to_string_pretty,
which dropped all JSONC comments and re-sorted keys alphabetically — scrambling
users' hand-maintained configs even when only adding the codegraph entry.

Edit existing configs surgically with jsonc-parser's CST API
(upsert_nested_key_jsonc / remove_nested_key_jsonc): only the codegraph property
is inserted, updated, or removed, leaving every comment, key order, and the
file's formatting intact. Re-runs short-circuit to Unchanged (no churn). Fresh
files are still seeded with the canonical shape. All six targets and the
uninstall path go through the surgical helpers.
KNOWN_DIFFS.md is an internal upstream-diff ledger (deferred colby resolvers,
Tier-3 allowed diffs), not user-facing. No code loads it at runtime. Move it
under docs/upstream-sync/ (already gitignored, alongside UPSTREAM.md) so it
stays local and out of the public repo.
KNOWN_DIFFS.md moved to the internal gitignored ledger, so its public-doc
hyperlinks would 404. Delink the mentions in README, architecture.md, and the
zh-CN README; also drop the inaccurate 'read at runtime by the equivalence
oracle' claim (no code loads the file by path).
@sunerpy
sunerpy merged commit 844388a into main Jun 22, 2026
3 checks passed
@sunerpy
sunerpy deleted the fix/installer-preserve-jsonc-comments branch June 22, 2026 02:45
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