Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,14 @@ needed.

### Install

**Preferred — official registry (once published):**
**Preferred — official registry:**

Search for **"CodeGraph"** in Zed's extension registry (`zed: extensions` from the
command palette) and click Install. The extension auto-downloads the CodeGraph
command palette) and click Install. It is listed as **CodeGraph MCP Server**
(extension ID `mcp-server-codegraph`). The extension auto-downloads the CodeGraph
binary for your platform on first launch.

> The extension is being submitted to the
> [`zed-industries/extensions`](https://github.com/zed-industries/extensions)
> registry. Once accepted it will be searchable there. Until then, use the
> dev-install path below.

**Dev install (before publication / for local development):**
**Dev install (for local development):**

1. Clone this repository.
2. In Zed, open the command palette and run **`zed: install dev extension`**.
Expand All @@ -326,22 +322,29 @@ codegraph-<version>/codegraph # Linux / macOS
codegraph-<version>/codegraph.exe # Windows
```

This path is **relative to the extension's working directory** that Zed manages
(inside Zed's extensions data directory, typically
`~/.local/share/zed/extensions/installed/codegraph/` on Linux,
`~/Library/Application Support/Zed/extensions/installed/codegraph/` on macOS, or
`%APPDATA%\Zed\extensions\installed\codegraph\` on Windows).
This path is **relative to the extension's working directory** that Zed manages,
which is keyed on the extension ID: typically
`~/.local/share/zed/extensions/work/mcp-server-codegraph/` on Linux,
`~/Library/Application Support/Zed/extensions/work/mcp-server-codegraph/` on
macOS, or `%LOCALAPPDATA%\Zed\extensions\work\mcp-server-codegraph\` on Windows.

For example, after downloading version `v0.25.0` on Linux the binary lives at:

```
~/.local/share/zed/extensions/installed/codegraph/codegraph-v0.25.0/codegraph
~/.local/share/zed/extensions/work/mcp-server-codegraph/codegraph-v0.25.0/codegraph
```

When the CodeGraph CLI ships a new release the extension picks up the new binary
automatically on the next launch — **no extension re-publish or manual update
required**. If the GitHub API is unreachable, the extension falls back to the
newest cached binary it finds.
binary it has already cached.

Right after each successful download the extension removes the other
`codegraph-*/` directories in that working directory, so the cache keeps exactly
one binary instead of one per release. A launch that hits the cache does no
cleanup, the in-use version is always kept, and a directory that cannot be
deleted (an in-use `codegraph.exe` on Windows) never fails the launch. See
[`editors/zed/README.md`](editors/zed/README.md) for the full cleanup contract.

### Override with your own binary

Expand Down
2 changes: 1 addition & 1 deletion editors/zed/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editors/zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# oracle, and guardrail are entirely unaffected. Never published to crates.io.
[package]
name = "codegraph-zed"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
publish = false

Expand Down
79 changes: 47 additions & 32 deletions editors/zed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ AI/LLM inside it — pure pre-computed structure for your agent to consume.

## Install

### Preferred — official registry (once published)
### Preferred — official registry

Search for **"CodeGraph"** in Zed's extension registry (`zed: extensions` from
the command palette) and click Install. The extension auto-downloads the
CodeGraph binary for your platform on first launch.
the command palette) and click Install. It is listed as **CodeGraph MCP Server**
(extension ID `mcp-server-codegraph`). The extension auto-downloads the CodeGraph
binary for your platform on first launch.

> The extension is being submitted to the
> [`zed-industries/extensions`](https://github.com/zed-industries/extensions)
> registry. Once accepted it will be searchable there. Until then, use the
> dev-install path below.

### Dev install (before publication / for local development)
### Dev install (for local development)

1. Clone this repository.
2. In Zed, run **`zed: install dev extension`** from the command palette.
Expand All @@ -48,26 +44,44 @@ codegraph-<version>/codegraph # Linux / macOS
codegraph-<version>/codegraph.exe # Windows
```

This path is **relative to the extension's working directory** that Zed manages
(inside Zed's extensions data directory). The full on-disk location is:
This path is **relative to the extension's working directory** that Zed manages —
`<zed-data-dir>/extensions/work/mcp-server-codegraph/`, keyed on the extension
ID. The full on-disk location is:

| Platform | Full path |
| -------- | ------------------------------------------------------------------------------------------------ |
| Linux | `~/.local/share/zed/extensions/installed/codegraph/codegraph-<version>/codegraph` |
| macOS | `~/Library/Application Support/Zed/extensions/installed/codegraph/codegraph-<version>/codegraph` |
| Windows | `%APPDATA%\Zed\extensions\installed\codegraph\codegraph-<version>\codegraph.exe` |
| Platform | Full path |
| -------- | ------------------------------------------------------------------------------------------------------ |
| Linux | `~/.local/share/zed/extensions/work/mcp-server-codegraph/codegraph-<version>/codegraph` |
| macOS | `~/Library/Application Support/Zed/extensions/work/mcp-server-codegraph/codegraph-<version>/codegraph` |
| Windows | `%LOCALAPPDATA%\Zed\extensions\work\mcp-server-codegraph\codegraph-<version>\codegraph.exe` |

For example, after downloading version `v0.25.0` on Linux the binary lives at:

```
~/.local/share/zed/extensions/installed/codegraph/codegraph-v0.25.0/codegraph
~/.local/share/zed/extensions/work/mcp-server-codegraph/codegraph-v0.25.0/codegraph
```

Because the cache is keyed on the release version, when the CodeGraph CLI ships
a new release the extension picks up the new binary automatically on the next
launch — **no extension re-publish or manual update required**. If the GitHub
API is unreachable (offline), the extension falls back to the newest binary it
has already cached.
API is unreachable (offline), the extension falls back to the binary it has
already cached.

### Cleanup of superseded binaries

Immediately after a successful download the extension deletes every other
`codegraph-*/` directory in its working directory, so the cache holds exactly one
CodeGraph binary rather than accumulating one per release. Details:

- It runs **only after a download**. A launch that finds the wanted version
already cached does no filesystem cleanup at all.
- Only entries whose name starts with `codegraph-` are considered, and the
version currently in use is always kept.
- Deletion is best-effort. A directory that cannot be removed (for example an
in-use `codegraph.exe` on Windows) is left in place and never fails the
server launch; the next update retries it.

To reclaim the space by hand instead, delete the `codegraph-*` directories under
the working-directory path in the table above.

## Use your own CodeGraph binary or pin a project path

Expand Down Expand Up @@ -158,35 +172,36 @@ To submit this extension to the official
[`zed-industries/extensions`](https://github.com/zed-industries/extensions)
registry so users can install it via `zed: extensions`, follow these steps:

1. **Bump the version** in `editors/zed/extension.toml` to match the current
CodeGraph release (e.g. `version = "0.2.0"`).
1. **Bump the version** in `editors/zed/extension.toml` (and `Cargo.toml`, in
lockstep) whenever the extension's WASM logic changes.

2. **Fork** [`zed-industries/extensions`](https://github.com/zed-industries/extensions).

3. **Add this repo as a git submodule** under `extensions/codegraph/`:
3. **Add this repo as a git submodule** under `extensions/mcp-server-codegraph/`:

```bash
git submodule add https://github.com/sunerpy/codegraph-rust extensions/codegraph
git submodule add https://github.com/sunerpy/codegraph-rust extensions/mcp-server-codegraph
```

The registry expects the extension root (containing `extension.toml`) at
`extensions/codegraph/editors/zed/`, so point the submodule at the repo root
and Zed's tooling walks for the manifest.

> Alternatively, if the registry requires the extension root at the submodule
> root, extract just `editors/zed/` into a dedicated repo first and submodule
> that instead.
`extensions/mcp-server-codegraph/editors/zed/`, so point the submodule at the
repo root and declare that subdirectory as the extension `path`.

4. **Add an entry** to the top-level `extensions.toml` in the
`zed-industries/extensions` repo:

```toml
[codegraph]
submodule = "extensions/codegraph"
[mcp-server-codegraph]
submodule = "extensions/mcp-server-codegraph"
path = "editors/zed"
version = "0.2.0"
```

The `id` field (`codegraph`) must match the `id` in `extension.toml`.
The table key (`mcp-server-codegraph`) must match the `id` in
`extension.toml`. Registry policy requires MCP-server extensions to carry an
`mcp-server` prefix or suffix in that ID; the ID **cannot be changed after
publication**, so discoverability by the plain word "codegraph" comes from the
`name` field (`CodeGraph MCP Server`), which Zed also searches.

5. **Open a pull request** against `zed-industries/extensions`. The Zed team
reviews and merges it; once merged the extension becomes searchable in Zed's
Expand Down
6 changes: 3 additions & 3 deletions editors/zed/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id = "codegraph"
name = "CodeGraph"
id = "mcp-server-codegraph"
name = "CodeGraph MCP Server"
description = "CodeGraph deterministic code knowledge graph as an MCP context server"
version = "0.1.0"
version = "0.2.0"
schema_version = 1
authors = ["sunerpy <[email protected]>"]
repository = "https://github.com/sunerpy/codegraph-rust"
Expand Down
27 changes: 22 additions & 5 deletions editors/zed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ impl CodeGraphExtension {
format!("{}/{}", Self::version_dir(version), Self::binary_name())
}

/// Newest existing `./codegraph-*/codegraph[.exe]` on disk, if any. Used as
/// an offline fallback when `latest_github_release` fails. "Newest" is by
/// lexicographically-greatest directory name, which matches semantic order
/// for the zero-padded-free `vX.Y.Z` tags this project uses well enough as
/// a best-effort offline fallback.
/// The cached `./codegraph-*/codegraph[.exe]` on disk, if any. Used as an
/// offline fallback when `latest_github_release` fails. `resolve_binary`
/// reaps superseded version dirs after each download, so in practice at most
/// one candidate survives; the sort is a vestigial tie-break for a cache
/// left behind by an older extension build.
fn newest_cached_binary() -> Option<String> {
let name = Self::binary_name();
let mut candidates: Vec<String> = std::fs::read_dir(".")
Expand Down Expand Up @@ -133,6 +133,23 @@ impl CodeGraphExtension {
zed::download_file(&asset.download_url, &version_dir, file_type)?;
zed::make_file_executable(&binary_path)?;

// Reap superseded version dirs so the cache does not grow without bound.
// Placement is load-bearing: only a successful download reaches here, so
// a cache hit never reaps. The `codegraph-` gate spares unrelated state
// Zed may keep here, and removal is `.ok()` rather than `?` because an
// undeletable dir (an in-use `.exe` on Windows) must not fail a launch.
let entries = std::fs::read_dir(".")
.map_err(|err| format!("failed to list the extension working directory: {err}"))?;
for entry in entries {
let entry =
entry.map_err(|err| format!("failed to read a working directory entry: {err}"))?;
if let Some(name) = entry.file_name().to_str() {
if name.starts_with("codegraph-") && name != version_dir {
std::fs::remove_dir_all(entry.path()).ok();
}
}
}

self.cached_binary_path = Some(binary_path.clone());
Ok(binary_path)
}
Expand Down
Loading