Skip to main content

Module zed_integration

Module zed_integration 

Source
Expand description

Zed editor (Zed Agent) integration.

Requested in issue #38. Zed has no PreToolUse-style hook that could rewrite terminal commands, so the integration has two surfaces, mirroring the Codex integration’s shape:

  1. Project instructions — Zed’s Agent reads the first matching file of .rules, .cursorrules, .windsurfrules, .clinerules, .github/copilot-instructions.md, AGENT.md, AGENTS.md, CLAUDE.md, GEMINI.md (per zed.dev/docs/ai/instructions). sqz appends a sentinel-bracketed guidance block to .rules when that file exists (it shadows everything else), otherwise to AGENTS.md.

  2. MCP registration — Zed reads MCP servers from the context_servers map in its settings.json (~/.config/zed/settings.json on macOS/Linux, %APPDATA%\Zed\ on Windows). Registering sqz-mcp gives the Zed Agent the compress/passthrough/expand tools plus the lossless sqz_read_file/sqz_grep/sqz_list_dir file tools — which is the part that matters for local models with small context windows.

Zed’s settings.json is JSONC (Zed’s own template ships comments). Lesson learned on issue #6 (OpenCode): never round-trip a user’s commented config through serde_json — it silently strips their comments. When the settings file doesn’t parse as strict JSON we REFUSE to edit it and return ZedMcpInstall::SkippedJsonc so the CLI can print copy-paste instructions instead.

Enums§

ZedMcpInstall
Outcome of install_zed_mcp_config, surfaced so the CLI can tell the user what actually happened — especially the JSONC case where we deliberately don’t touch their file.
ZedMcpRemove
Outcome of remove_zed_mcp_config.

Functions§

install_zed_guidance
Install sqz’s Zed guidance block into the project’s effective Zed instruction file (.rules when present, else AGENTS.md).
install_zed_mcp_config
Register sqz-mcp under context_servers.sqz in Zed’s settings.json.
remove_zed_guidance
Remove sqz’s Zed guidance block from BOTH .rules and AGENTS.md (whichever contain it) — the target can have moved between installs if the user created .rules later. The shared block in AGENTS.md stays while Codex is registered.
remove_zed_mcp_config
Remove context_servers.sqz from Zed’s settings.json. Never deletes the file itself — it’s the user’s editor config, and an empty context_servers key is simply dropped.
zed_guidance_block
Build the markdown block sqz appends to the Zed instruction file.
zed_guidance_target
The project file Zed will actually read sqz’s guidance from.
zed_mcp_snippet
The context_servers snippet for manual installation, printed when sqz can’t safely edit a JSONC settings file.
zed_settings_path
Path of Zed’s user settings file.