Skip to content

fix: preserve Zed settings during connect#953

Open
IgorArkhipov wants to merge 1 commit into
rohitg00:mainfrom
IgorArkhipov:fix/952-zed-settings-initialization
Open

fix: preserve Zed settings during connect#953
IgorArkhipov wants to merge 1 commit into
rohitg00:mainfrom
IgorArkhipov:fix/952-zed-settings-initialization

Conversation

@IgorArkhipov

@IgorArkhipov IgorArkhipov commented Jun 20, 2026

Copy link
Copy Markdown

Summary

  • preserve existing Zed settings.json content when adding context_servers.agentmemory
  • parse/edit Zed settings as JSONC so comments and trailing commas do not cause the config to be treated as empty
  • leave invalid existing JSON MCP config unchanged instead of replacing it
  • add a regression test covering existing Zed settings, comments, and another context server

Root Cause

agentmemory connect zed used the shared JSON MCP adapter, which parsed settings with strict JSON.parse. Zed settings may be JSONC, so comments or trailing commas caused parsing to fail. The adapter then treated the existing file as missing/empty and wrote a fresh config containing only context_servers.agentmemory.

Validation

  • npm run build
  • npm test -- test/connect-new-agents.test.ts
  • npm test

Fixes #952

Summary by CodeRabbit

  • New Features

    • Added JSONC (JSON with Comments) support for MCP configuration files, preserving existing comments and entries when updating settings.
    • Enhanced Zed editor MCP integration to safely maintain configuration file comments during updates.
  • Improvements

    • Refactored configuration file handling to support atomic writes with better format preservation.

Signed-off-by: Igor Arkhipov <igor.arkhipov@joinhandshake.com>
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@IgorArkhipov is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dfdd04b9-f20d-45f2-8a42-4e53f5df74e4

📥 Commits

Reviewing files that changed from the base of the PR and between f6f9e3c and 17f6c1d.

📒 Files selected for processing (5)
  • package.json
  • src/cli/connect/json-mcp-adapter.ts
  • src/cli/connect/util.ts
  • src/cli/connect/zed.ts
  • test/connect-new-agents.test.ts

📝 Walkthrough

Walkthrough

Adds jsonc-parser as a dependency and refactors the MCP adapter to read, edit, and write Zed's settings.json using targeted JSONC edits that preserve comments and existing entries. A shared writeTextAtomic helper is extracted, JsonMcpAdapterConfig gains a jsonc flag, and the Zed adapter is wired with jsonc: true. A regression test verifies comment and entry preservation.

Changes

JSONC-safe Zed settings merge

Layer / File(s) Summary
Dependency and writeTextAtomic utility
package.json, src/cli/connect/util.ts
Adds jsonc-parser ^3.3.1 to dependencies and extracts shared atomic write logic from writeJsonAtomic into a new exported writeTextAtomic(path, value) function.
JSONC config types, helpers, and install/write logic
src/cli/connect/json-mcp-adapter.ts
Adds jsonc?: boolean to JsonMcpAdapterConfig; introduces ReadConfigResult union type and readMcpConfig, parseJsonc, serverEntries helpers; rewires install to parse via readMcpConfig, apply targeted modify/applyEdits edits for JSONC mode, write via writeTextAtomic or writeJsonAtomic, and verify by re-reading with readMcpConfig.
Zed wiring and JSONC preservation test
src/cli/connect/zed.ts, test/connect-new-agents.test.ts
Sets jsonc: true in the Zed adapter export and adds a regression test asserting that install preserves existing comments and context_servers entries while adding the agentmemory entry.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • rohitg00/agentmemory#677: Modifies src/cli/connect/json-mcp-adapter.ts and src/cli/connect/zed.ts to establish the Zed adapter's wrapperKey/verification structure that this PR's JSONC changes build directly on top of.

Poem

🐇 Hop hop, the settings won't disappear,
My JSONC parser keeps comments clear!
No more wiping what Zed held dear—
agentmemory merges, never veers.
The carrot of correctness is finally here! 🥕

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: preserve Zed settings during connect' accurately summarizes the main change—fixing destructive behavior by preserving existing settings.
Linked Issues check ✅ Passed The PR fully addresses #952 requirements: preserves existing Zed settings, handles JSONC with comments, merges context_servers, fails on invalid configs, and adds regression tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Zed settings preservation issue: JSONC parsing support, atomic writes, adapter updates, and regression tests.

✏️ 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.

@IgorArkhipov IgorArkhipov marked this pull request as ready for review June 20, 2026 04:01
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.

agentmemory connect zed overwrites existing Zed settings.json instead of merging context_servers

1 participant