pi-zed-bridge-daemon
v0.1.0
Published
Zed-side companion daemon for the Pi coding agent bridge: LSP channel + HTTP bridge for diff review and editor context.
Readme
pi-zed-bridge-daemon
The Zed-side half of Pi Zed Bridge: a zero-dependency Node process that Zed runs (via the pi-zed-bridge Zed extension) once per workspace as a pseudo language server. While Zed believes it is talking plain LSP over stdio, the daemon additionally:
- runs an authenticated loopback HTTP bridge for the Pi extension — same wire contract as the VS Code bridge,
- streams editor context (open buffers, active file) over SSE derived from
textDocument/didOpen|didChange|didClose, - shows approve/reject prompts in Zed via
window/showMessageRequest, - materializes each proposed edit into
before/aftertemp files and opens them in Zed's native diff view viazed --diff, - registers on a shared bootstrap port (
127.0.0.1:45731) so Pi can discover the bridge for its cwd (multi-workspace, heartbeat TTL 30s, owner-death takeover).
Usage
# Normal way: install the Zed extension; it spawns:
node …/node_modules/pi-zed-bridge-daemon/src/main.mjs --lsp --root <worktree>
# Manual/test way (no approval prompts, no context):
node src/main.mjs --root ./stdout is reserved for LSP frames in --lsp mode — all logs go to stderr (visible in Zed's LSP log).
Endpoints (bearer-token auth, loopback only)
| Route | Purpose |
|---|---|
| POST /openDiff {requestId, filePath, beforeText, afterText} | Opens the Zed diff + prompt; responds with the decision when made |
| POST /closeDiff {requestId, decision} | Settles/cleans a diff from the Pi side |
| GET /context/stream | SSE editor-context snapshots |
| POST /diagnostics | Returns available: false + empty sets (Zed does not expose diagnostics) |
| GET /health | Liveness |
Env vars
| Var | Effect |
|---|---|
| PI_ZED_BRIDGE_DRY_RUN=1 | Never spawn zed (tests/CI) |
| PI_ZED_BRIDGE_ZED_BIN=<path> | Explicit zed CLI path override |
| PI_ZED_BRIDGE_SERVER_PORT / PI_ZED_BRIDGE_AUTH_TOKEN | Set for the Pi process by users running standalone daemons manually |
Files
src/main.mjs entrypoint / wiring / signal handling
src/lsp.mjs minimal LSP server: sync notifications, prompt queue
src/bridge.mjs Pi-facing HTTP bridge (openDiff/closeDiff/health/SSE/diagnostics)
src/bootstrap.mjs shared registry on :45731 + resolver + takeover
src/approvals.mjs pending-edit coordination (Zed prompt ⇄ Pi HTTP)
src/contextStore.mjs open-file tracking + snapshot + subscribers
src/diffTemp.mjs temp before/after materialization + sweeper
src/zedCli.mjs `zed --diff` spawning
src/contract.mjs ports/paths/env keys (mirror of ../shared/bridge-contract.cjs)Tests
npm test # headless suite incl. a fake-Zed LSP client
node test/live-rehearsal.mjs # manual: opens a REAL Zed diff window