Add Zed Agent support via MCP server#765
Add Zed Agent support via MCP server#765Krishnachaitanyakc wants to merge 1 commit intogit-ai-project:mainfrom
Conversation
Zed's extension API lacks tool-use hooks, so integration uses an MCP server that exposes a `git_ai_checkpoint` tool. The agent is instructed via a .rules file to call checkpoints before/after file edits. Components: - `git-ai mcp-server` command: MCP server over stdio with Content-Length framing (MCP/LSP spec), exposes git_ai_checkpoint tool - `zed` checkpoint preset: parses hook input from MCP tool calls - Zed installer: detects Zed via binary/config, sets up context_servers - `.zed/rules` template: instructs agent to call checkpoint tool The MCP server generates a stable session ID per instance to correlate pre/post checkpoint pairs. Process spawning follows pipe deadlock prevention patterns (start readers before writing stdin).
|
@svarlamov can you review this? |
| if !status.success() { | ||
| return Err(format!("Checkpoint failed: {}", stderr_output.trim())); | ||
| } |
There was a problem hiding this comment.
🔴 MCP server always reports checkpoint success because subprocess always exits with code 0
The run_checkpoint function in mcp_server.rs relies on status.success() (line 389) to detect child process failures. However, git-ai checkpoint always exits with code 0 regardless of outcome—every error path in handle_checkpoint calls std::process::exit(0) (e.g., git_ai_handlers.rs:339, git_ai_handlers.rs:345, git_ai_handlers.rs:566, git_ai_handlers.rs:999), and the success path naturally exits with 0 via main.rs:46. Because the exit code check never triggers, the captured stderr (which contains the actual error messages) is silently discarded at line 384, and the function always returns Ok("Created ... checkpoint for N file(s)"). Zed's agent will always receive a success response even when the checkpoint completely failed (e.g., no git repo found, invalid JSON input, preset errors), causing AI authorship tracking to silently not work.
Prompt for agents
In src/commands/mcp_server.rs, the run_checkpoint function at lines 389-391 checks status.success() to detect failures, but the child process (git-ai checkpoint) always exits with code 0 even on error. The fix should check the captured stderr output for error indicators regardless of exit code. One approach: after joining stderr_handle (line 384), check if stderr_output contains known error prefixes like 'Zed preset error:', 'No hook input provided', 'Checkpoint failed', 'Failed to find repository', etc. If stderr_output is non-empty and doesn't contain 'Checkpoint completed', treat it as a failure and return Err with the stderr content. Alternatively, you could refactor to call the checkpoint logic directly in-process (similar to how other presets work) instead of shelling out, which would avoid the exit code problem entirely.
Was this helpful? React with 👍 or 👎 to provide feedback.
Closes #675
Summary
Adds Zed Agent support for git-ai. Zed's extension API currently lacks tool-use hooks (no pre/post tool use callbacks, no document change events from extensions), so integration uses an MCP server approach.
Components
git-ai mcp-server— MCP server over stdio with Content-Length framing (MCP/LSP spec). Exposes agit_ai_checkpointtool that Zed's agent can call before/after file editszedcheckpoint preset — Parses hook input from MCP tool calls, creates Human (PreToolUse) and AiAgent (PostToolUse) checkpointssrc/mdm/agents/zed.rs) — Detects Zed installation (binary +~/.config/zed/), configurescontext_serversentry. RespectsXDG_CONFIG_HOME.zed/rulestemplate (agent-support/zed/rules) — Instructs the agent to callgit_ai_checkpointbefore/after every file editHow it works
git-ai install-hooks→ detects Zed → adds MCP server config to~/.config/zed/settings.json.zed/rulesto their projectgit_ai_checkpoint(event: "PreToolUse")before editing andgit_ai_checkpoint(event: "PostToolUse")aftergit-ai checkpoint zed --hook-input stdinDesign decisions
PreToolUse/PostToolUsevaluesLimitations
Test plan
cargo fmt -- --check— passescargo check— zero warningscargo clippy --lib -- -D warnings— passescargo test zed— all 5 tests passgit-ai mcp-serverresponds to MCP protocol messagesgit-ai install-hooksdetects Zed and outputs config instructions