context-mode 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "Claude Code plugins by Mert Koseoğlu",
9
- "version": "1.0.24"
9
+ "version": "1.0.26"
10
10
  },
11
11
  "plugins": [
12
12
  {
13
13
  "name": "context-mode",
14
14
  "source": "./",
15
15
  "description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
16
- "version": "1.0.24",
16
+ "version": "1.0.26",
17
17
  "author": {
18
18
  "name": "Mert Koseoğlu"
19
19
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "MCP server that saves 98% of your context window with session continuity. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and automatic state restore across compactions.",
5
5
  "author": {
6
6
  "name": "Mert Koseoğlu",
@@ -3,7 +3,7 @@
3
3
  "name": "Context Mode",
4
4
  "kind": "tool",
5
5
  "description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
6
- "version": "1.0.24",
6
+ "version": "1.0.26",
7
7
  "sandbox": {
8
8
  "mode": "permissive",
9
9
  "filesystem_access": "full",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
5
5
  "author": {
6
6
  "name": "Mert Koseoğlu",
package/README.md CHANGED
@@ -5,6 +5,14 @@
5
5
  [![users](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fcontext-mode%40main%2Fstats.json&query=%24.message&label=users&color=brightgreen)](https://www.npmjs.com/package/context-mode) [![npm](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fcontext-mode%40main%2Fstats.json&query=%24.npm&label=npm&color=blue)](https://www.npmjs.com/package/context-mode) [![marketplace](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fmksglu%2Fcontext-mode%40main%2Fstats.json&query=%24.marketplace&label=marketplace&color=blue)](https://github.com/mksglu/context-mode) [![GitHub stars](https://img.shields.io/github/stars/mksglu/context-mode?style=flat&color=yellow)](https://github.com/mksglu/context-mode/stargazers) [![GitHub forks](https://img.shields.io/github/forks/mksglu/context-mode?style=flat&color=blue)](https://github.com/mksglu/context-mode/network/members) [![Last commit](https://img.shields.io/github/last-commit/mksglu/context-mode?color=green)](https://github.com/mksglu/context-mode/commits) [![License: ELv2](https://img.shields.io/badge/License-ELv2-blue.svg)](LICENSE)
6
6
  [![Discord](https://img.shields.io/discord/1478479412700909750?label=Discord&logo=discord&color=5865f2)](https://discord.gg/DCN9jUgN5v)
7
7
 
8
+ ## Privacy & Architecture
9
+
10
+ Context Mode is not a CLI output filter or a cloud analytics dashboard. It operates at the MCP protocol layer — raw data stays in a sandboxed subprocess and never enters your context window. Web pages, API responses, file analysis, Playwright snapshots, log files — everything is processed in complete isolation.
11
+
12
+ **Nothing leaves your machine.** No telemetry, no cloud sync, no usage tracking, no account required. Your code, your prompts, your session data — all local. The SQLite databases live in your home directory and die when you're done.
13
+
14
+ This is a deliberate architectural choice, not a missing feature. Context optimization should happen at the source, not in a dashboard behind a per-seat subscription. Privacy-first is our philosophy — and every design decision follows from it. [License →](#license)
15
+
8
16
  ## The Problem
9
17
 
10
18
  Every MCP tool call dumps raw data into your context window. A Playwright snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log — 45 KB. After 30 minutes, 40% of your context is gone. And when the agent compacts the conversation to free space, it forgets which files it was editing, what tasks are in progress, and what you last asked for.
@@ -277,11 +285,17 @@ context-mode runs as a native [OpenClaw](https://github.com/openclaw) gateway pl
277
285
  ```bash
278
286
  git clone https://github.com/mksglu/context-mode.git
279
287
  cd context-mode
280
- scripts/install-openclaw-plugin.sh /path/to/openclaw-state
288
+ npm run install:openclaw
281
289
  ```
282
290
 
283
- Replace `/path/to/openclaw-state` with your `OPENCLAW_STATE_DIR` the directory containing `runtime/openclaw.runtime.json`. Common locations:
284
- - **Docker:** `/openclaw` (the installer default)
291
+ The installer uses `$OPENCLAW_STATE_DIR` from your environment (default: `/openclaw`). To specify a custom path:
292
+
293
+ ```bash
294
+ npm run install:openclaw -- /path/to/openclaw-state
295
+ ```
296
+
297
+ Common locations:
298
+ - **Docker:** `/openclaw` (the default)
285
299
  - **Local:** `~/.openclaw` or wherever you set `OPENCLAW_STATE_DIR`
286
300
 
287
301
  The installer handles everything: `npm install`, `npm run build`, `better-sqlite3` native rebuild, extension registration in `runtime.json`, and gateway restart via SIGUSR1.
@@ -379,14 +393,94 @@ npm install -g context-mode
379
393
  }
380
394
  ```
381
395
 
382
- **Step 3 — Restart Kiro.** On first MCP server startup, a `KIRO.md` routing instructions file is auto-created in your project root. Kiro reads `KIRO.md` automatically and learns to prefer context-mode sandbox tools.
396
+ **Step 3 — Add hooks.** Without hooks, the model can bypass routing and dump raw output into your context. Hooks intercept every tool call and enforce sandbox routing programmatically. Create `.kiro/hooks/context-mode.json` (or copy from [`configs/kiro/agent.json`](configs/kiro/agent.json)):
383
397
 
384
- **About hooks:** Kiro hook-based session continuity will be added once Kiro CLI hooks are fully tested. The `KIRO.md` routing instructions file is the current enforcement method (~60% compliance).
398
+ ```json
399
+ {
400
+ "name": "context-mode",
401
+ "description": "Context-mode hooks for context window protection",
402
+ "hooks": {
403
+ "preToolUse": [
404
+ { "matcher": "*", "command": "context-mode hook kiro pretooluse" }
405
+ ],
406
+ "postToolUse": [
407
+ { "matcher": "*", "command": "context-mode hook kiro posttooluse" }
408
+ ]
409
+ }
410
+ }
411
+ ```
412
+
413
+ **Step 4 — Restart Kiro.** On first session start, the pretooluse hook automatically manages `KIRO.md` routing instructions in your project root:
414
+
415
+ - **File does not exist** — the routing instructions file is written.
416
+ - **File exists without context-mode rules** — routing instructions are appended after your existing content.
417
+ - **File already contains context-mode rules** — skipped (idempotent, no duplicate content).
385
418
 
386
419
  **Auto-detection:** context-mode detects Kiro automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
387
420
 
388
421
  </details>
389
422
 
423
+ <details>
424
+ <summary><strong>Zed</strong></summary>
425
+
426
+ **Step 1 — Install globally:**
427
+
428
+ ```bash
429
+ npm install -g context-mode
430
+ ```
431
+
432
+ **Step 2 — Add to Zed settings** (`~/.config/zed/settings.json`):
433
+
434
+ ```json
435
+ {
436
+ "context_servers": {
437
+ "context-mode": {
438
+ "command": {
439
+ "path": "context-mode"
440
+ }
441
+ }
442
+ }
443
+ }
444
+ ```
445
+
446
+ **Step 3 — Restart Zed.** On first MCP server startup, an `AGENTS.md` routing instructions file is auto-created in your project root. Zed reads the MCP tools and the model learns to prefer context-mode sandbox tools.
447
+
448
+ **About hooks:** Zed does not support hooks — there is no public hook or extension API for tool-use lifecycle events. The `AGENTS.md` routing instructions file is the only enforcement method (~60% compliance). The model receives the instructions at session start and sometimes follows them, but there is no programmatic interception.
449
+
450
+ **Auto-detection:** context-mode detects Zed automatically via the MCP protocol handshake (`clientInfo.name`). No environment variables or manual platform configuration needed.
451
+
452
+ </details>
453
+
454
+ <details>
455
+ <summary><strong>Pi Coding Agent</strong></summary>
456
+
457
+ **Step 1 — Install the extension:**
458
+
459
+ ```bash
460
+ git clone https://github.com/mksglu/context-mode.git ~/.pi/extensions/context-mode
461
+ cd ~/.pi/extensions/context-mode
462
+ npm install
463
+ ```
464
+
465
+ **Step 2 — Add MCP server** to `~/.pi/settings/mcp.json` or `.pi/settings/mcp.json`:
466
+
467
+ ```json
468
+ {
469
+ "mcpServers": {
470
+ "context-mode": {
471
+ "command": "node",
472
+ "args": ["~/.pi/extensions/context-mode/node_modules/context-mode/start.mjs"]
473
+ }
474
+ }
475
+ }
476
+ ```
477
+
478
+ **Step 3 — Restart Pi.**
479
+
480
+ The extension handles session continuity (event capture, resume snapshots, compaction recovery). The MCP server provides sandbox tools (batch_execute, execute, search, etc.).
481
+
482
+ </details>
483
+
390
484
  <details>
391
485
  <summary><strong>Build Prerequisites</strong> <sup>(CentOS, RHEL, Alpine)</sup></summary>
392
486
 
@@ -477,15 +571,15 @@ Context Mode captures every meaningful event during your session and persists th
477
571
 
478
572
  Session continuity requires 4 hooks working together:
479
573
 
480
- | Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro |
481
- |---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
482
- | **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- |
483
- | **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- | -- |
484
- | **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- |
485
- | **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- |
486
- | | **Session completeness** | **Full** | **High** | **High** | **Partial** | **High** | **High** | **--** | **--** | **--** |
574
+ | Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
575
+ |---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
576
+ | **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | ✓ (via tool_result event) |
577
+ | **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
578
+ | **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- | -- | ✓ (via session_before_compact) |
579
+ | **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- | -- | ✓ (via session_start event) |
580
+ | | **Session completeness** | **Full** | **High** | **High** | **Partial** | **High** | **High** | **--** | **--** | **Partial** | **--** | **High** |
487
581
 
488
- > **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, **VS Code Copilot**, and **OpenCode**. **Cursor** captures tool events via `preToolUse`/`postToolUse`, but `sessionStart` is currently rejected by Cursor's validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)), so session restore after compaction is not available yet. **OpenCode** uses the `experimental.session.compacting` plugin hook for compaction recovery, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume is not supported. **OpenClaw** uses native gateway plugin hooks (`api.on()`) for full session continuity. **Codex CLI**, **Antigravity**, and **Kiro** have no hook support in the current release, so session tracking is not available.
582
+ > **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, **VS Code Copilot**, and **OpenCode**. **Cursor** captures tool events via `preToolUse`/`postToolUse`, but `sessionStart` is currently rejected by Cursor's validator ([forum report](https://forum.cursor.com/t/unknown-hook-type-sessionstart/149566)), so session restore after compaction is not available yet. **OpenCode** uses the `experimental.session.compacting` plugin hook for compaction recovery, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume is not supported. **OpenClaw** uses native gateway plugin hooks (`api.on()`) for full session continuity. **Pi Coding Agent** provides high session continuity via extension hooks (`tool_call`, `tool_result`, `session_start`, `session_before_compact`). **Codex CLI**, **Antigravity**, **Kiro**, and **Zed** have no hook support in the current release, so session tracking is not available.
489
583
 
490
584
  <details>
491
585
  <summary><strong>What gets captured</strong></summary>
@@ -570,32 +664,40 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
570
664
 
571
665
  **Antigravity** — No session support. Same as Codex CLI — no hooks, no event capture. The `GEMINI.md` routing instructions file is auto-written on first MCP server startup. Auto-detected via MCP protocol handshake (`clientInfo.name`).
572
666
 
573
- **Kiro** — No session support in the current release. MCP-only. The `KIRO.md` routing instructions file is auto-written on first MCP server startup. Hook-based session continuity will be added once Kiro CLI hooks are fully tested. Auto-detected via MCP protocol handshake (`clientInfo.name`).
667
+ **Zed** — No session support. Same as Codex CLI — no hooks, no event capture. The `AGENTS.md` routing instructions file is auto-written on first MCP server startup. Auto-detected via MCP protocol handshake (`clientInfo.name`).
668
+
669
+ **Kiro** — Partial coverage. Native `preToolUse` and `postToolUse` hooks capture tool events and enforce sandbox routing. `agentSpawn` (the Kiro equivalent of SessionStart) is not yet implemented, so session restore after compaction is not available. The `KIRO.md` routing instructions file is auto-written on first session start. Auto-detected via MCP protocol handshake (`clientInfo.name`).
670
+
671
+ **Pi Coding Agent** — High coverage. The extension registers all key lifecycle events: `tool_call` (PreToolUse), `tool_result` (PostToolUse), `session_start` (SessionStart), and `session_before_compact` (PreCompact). File edits, git ops, errors, and tasks are fully tracked. Session restore after compaction works via the extension's event hooks. The `AGENTS.md` routing instructions file is auto-written on first session start.
574
672
 
575
673
  </details>
576
674
 
577
675
  ## Platform Compatibility
578
676
 
579
- | Feature | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro |
580
- |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
581
- | MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
582
- | PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- |
583
- | PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- |
584
- | SessionStart Hook | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- |
585
- | PreCompact Hook | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- |
586
- | Can Modify Args | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- |
587
- | Can Block Tools | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- |
588
- | Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
589
- | Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- | -- |
590
- | Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- | -- |
677
+ | Feature | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
678
+ |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
679
+ | MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
680
+ | PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
681
+ | PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
682
+ | SessionStart Hook | Yes | Yes | Yes | -- | -- | Plugin | -- | -- | -- | -- | Yes (extension) |
683
+ | PreCompact Hook | Yes | Yes | Yes | -- | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
684
+ | Can Modify Args | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
685
+ | Can Block Tools | Yes | Yes | Yes | Yes | Plugin | Plugin | -- | -- | Yes | -- | Yes (extension) |
686
+ | Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes (/ctx-stats, /ctx-doctor) |
687
+ | Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
688
+ | Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
591
689
 
592
690
  > **OpenCode** uses a TypeScript plugin paradigm — hooks run as in-process functions via `tool.execute.before`, `tool.execute.after`, and `experimental.session.compacting`, providing the same routing enforcement and session continuity as shell-based hooks. SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), but compaction recovery works via the plugin's compacting hook.
593
691
  >
594
692
  > **OpenClaw** runs context-mode as a native gateway plugin targeting Pi Agent sessions. Hooks register via `api.on()` (tool/lifecycle) and `api.registerHook()` (commands). All tool interception and compaction hooks are supported. See [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md).
595
693
  >
596
- > **Codex CLI** and **Antigravity** do not support hooks. They rely solely on routing instruction files (`AGENTS.md` / `GEMINI.md`) for enforcement (~60% compliance). Antigravity is auto-detected via MCP protocol handshake — no manual platform configuration needed.
694
+ > **Codex CLI**, **Antigravity**, and **Zed** do not support hooks. They rely solely on routing instruction files (`AGENTS.md` / `GEMINI.md`) for enforcement (~60% compliance). Antigravity and Zed are auto-detected via MCP protocol handshake — no manual platform configuration needed.
695
+ >
696
+ > **Kiro** supports native `preToolUse` and `postToolUse` hooks for routing enforcement and tool event capture. `agentSpawn` (SessionStart equivalent) and `stop` are not yet wired. Kiro is auto-detected via MCP protocol handshake (`clientInfo.name`).
697
+ >
698
+ > **Zed** does not support hooks. It relies solely on the `AGENTS.md` routing instructions file for enforcement (~60% compliance). Zed is auto-detected via MCP protocol handshake — no manual platform configuration needed.
597
699
  >
598
- > **Kiro** is MCP-only in the current release. Hook-based enforcement will be added once Kiro CLI hooks are fully tested. Kiro is auto-detected via MCP protocol handshake (`clientInfo.name`).
700
+ > **Pi Coding Agent** runs context-mode as an extension with full hook support. The extension registers `tool_call`, `tool_result`, `session_start`, and `session_before_compact` events, providing high session continuity coverage. The MCP server provides the 6 sandbox tools.
599
701
 
600
702
  ### Routing Enforcement
601
703
 
@@ -611,7 +713,9 @@ Hooks intercept tool calls programmatically — they can block dangerous command
611
713
  | OpenClaw | Plugin | [`AGENTS.md`](configs/openclaw/AGENTS.md) | **~98% saved** | ~60% saved |
612
714
  | Codex CLI | -- | [`AGENTS.md`](configs/codex/AGENTS.md) | -- | ~60% saved |
613
715
  | Antigravity | -- | [`GEMINI.md`](configs/antigravity/GEMINI.md) | -- | ~60% saved |
614
- | Kiro | -- | [`KIRO.md`](configs/kiro/KIRO.md) | -- | ~60% saved |
716
+ | Kiro | Yes | [`KIRO.md`](configs/kiro/KIRO.md) | **~98% saved** | ~60% saved |
717
+ | Zed | -- | [`AGENTS.md`](configs/zed/AGENTS.md) | -- | ~60% saved |
718
+ | Pi | ✓ | [`AGENTS.md`](configs/pi/AGENTS.md) | **~98% saved** | ~60% saved |
615
719
 
616
720
  Without hooks, one unrouted `curl` or Playwright snapshot can dump 56 KB into context — wiping out an entire session's worth of savings.
617
721
 
@@ -739,4 +843,4 @@ cd context-mode && npm install && npm test
739
843
 
740
844
  ## License
741
845
 
742
- [Elastic License 2.0 (ELv2)](LICENSE) free to use, modify, and share. You may not rebrand and redistribute this software as a competing plugin, product, or managed service.
846
+ Licensed under [Elastic License 2.0](LICENSE) (source-available). You can use it, fork it, modify it, and distribute it. Two things you can't do: offer it as a hosted/managed service, or remove the licensing notices. We chose ELv2 over MIT because MIT permits repackaging the code as a competing closed-source SaaS ELv2 prevents that while keeping the source available to everyone.
@@ -15,4 +15,8 @@ export const CLIENT_NAME_TO_PLATFORM = {
15
15
  "Codex": "codex",
16
16
  "codex-mcp-client": "codex",
17
17
  "Kiro CLI": "kiro",
18
+ "Pi CLI": "pi",
19
+ "Pi Coding Agent": "pi",
20
+ "Zed": "zed",
21
+ "zed": "zed",
18
22
  };
@@ -42,7 +42,7 @@ export function detectPlatform(clientInfo) {
42
42
  if (platformOverride) {
43
43
  const validPlatforms = [
44
44
  "claude-code", "gemini-cli", "opencode", "codex",
45
- "vscode-copilot", "cursor", "antigravity", "kiro",
45
+ "vscode-copilot", "cursor", "antigravity", "kiro", "pi", "zed",
46
46
  ];
47
47
  if (validPlatforms.includes(platformOverride)) {
48
48
  return {
@@ -132,6 +132,20 @@ export function detectPlatform(clientInfo) {
132
132
  reason: "~/.cursor/ directory exists",
133
133
  };
134
134
  }
135
+ if (existsSync(resolve(home, ".kiro"))) {
136
+ return {
137
+ platform: "kiro",
138
+ confidence: "medium",
139
+ reason: "~/.kiro/ directory exists",
140
+ };
141
+ }
142
+ if (existsSync(resolve(home, ".pi"))) {
143
+ return {
144
+ platform: "pi",
145
+ confidence: "medium",
146
+ reason: "~/.pi/ directory exists",
147
+ };
148
+ }
135
149
  if (existsSync(resolve(home, ".openclaw"))) {
136
150
  return {
137
151
  platform: "openclaw",
@@ -146,6 +160,13 @@ export function detectPlatform(clientInfo) {
146
160
  reason: "~/.config/opencode/ directory exists",
147
161
  };
148
162
  }
163
+ if (existsSync(resolve(home, ".config", "zed"))) {
164
+ return {
165
+ platform: "zed",
166
+ confidence: "medium",
167
+ reason: "~/.config/zed/ directory exists",
168
+ };
169
+ }
149
170
  // ── Low confidence: fallback ───────────────────────────
150
171
  return {
151
172
  platform: "claude-code",
@@ -196,6 +217,10 @@ export async function getAdapter(platform) {
196
217
  const { KiroAdapter } = await import("./kiro/index.js");
197
218
  return new KiroAdapter();
198
219
  }
220
+ case "zed": {
221
+ const { ZedAdapter } = await import("./zed/index.js");
222
+ return new ZedAdapter();
223
+ }
199
224
  default: {
200
225
  // Unsupported platform — fall back to Claude Code adapter
201
226
  // (MCP server works everywhere, hooks may not)
@@ -206,7 +206,7 @@ export interface DiagnosticResult {
206
206
  fix?: string;
207
207
  }
208
208
  /** Supported platform identifiers. */
209
- export type PlatformId = "claude-code" | "gemini-cli" | "opencode" | "openclaw" | "codex" | "vscode-copilot" | "cursor" | "antigravity" | "kiro" | "unknown";
209
+ export type PlatformId = "claude-code" | "gemini-cli" | "opencode" | "openclaw" | "codex" | "vscode-copilot" | "cursor" | "antigravity" | "kiro" | "pi" | "zed" | "unknown";
210
210
  /** Detection signal used to identify which platform is running. */
211
211
  export interface DetectionSignal {
212
212
  /** Platform identifier. */
@@ -0,0 +1,43 @@
1
+ /**
2
+ * adapters/zed — Zed editor platform adapter.
3
+ *
4
+ * Implements HookAdapter for Zed's MCP-only paradigm.
5
+ *
6
+ * Zed hook specifics:
7
+ * - NO hook support — Zed is an editor, not a CLI with hook pipelines
8
+ * - Config: ~/.config/zed/settings.json (JSON format)
9
+ * - MCP: full support via context_servers section in settings.json
10
+ * - All capabilities are false — MCP is the only integration path
11
+ * - Session dir: ~/.config/zed/context-mode/sessions/
12
+ */
13
+ import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse, HookRegistration, RoutingInstructionsConfig } from "../types.js";
14
+ export declare class ZedAdapter implements HookAdapter {
15
+ readonly name = "Zed";
16
+ readonly paradigm: HookParadigm;
17
+ readonly capabilities: PlatformCapabilities;
18
+ parsePreToolUseInput(_raw: unknown): PreToolUseEvent;
19
+ parsePostToolUseInput(_raw: unknown): PostToolUseEvent;
20
+ parsePreCompactInput(_raw: unknown): PreCompactEvent;
21
+ parseSessionStartInput(_raw: unknown): SessionStartEvent;
22
+ formatPreToolUseResponse(_response: PreToolUseResponse): unknown;
23
+ formatPostToolUseResponse(_response: PostToolUseResponse): unknown;
24
+ formatPreCompactResponse(_response: PreCompactResponse): unknown;
25
+ formatSessionStartResponse(_response: SessionStartResponse): unknown;
26
+ getSettingsPath(): string;
27
+ getSessionDir(): string;
28
+ getSessionDBPath(projectDir: string): string;
29
+ getSessionEventsPath(projectDir: string): string;
30
+ generateHookConfig(_pluginRoot: string): HookRegistration;
31
+ readSettings(): Record<string, unknown> | null;
32
+ writeSettings(settings: Record<string, unknown>): void;
33
+ validateHooks(_pluginRoot: string): DiagnosticResult[];
34
+ checkPluginRegistration(): DiagnosticResult;
35
+ getInstalledVersion(): string;
36
+ configureAllHooks(_pluginRoot: string): string[];
37
+ backupSettings(): string | null;
38
+ setHookPermissions(_pluginRoot: string): string[];
39
+ updatePluginRegistry(_pluginRoot: string, _version: string): void;
40
+ getRoutingInstructionsConfig(): RoutingInstructionsConfig;
41
+ writeRoutingInstructions(projectDir: string, pluginRoot: string): string | null;
42
+ getRoutingInstructions(): string;
43
+ }
@@ -0,0 +1,218 @@
1
+ /**
2
+ * adapters/zed — Zed editor platform adapter.
3
+ *
4
+ * Implements HookAdapter for Zed's MCP-only paradigm.
5
+ *
6
+ * Zed hook specifics:
7
+ * - NO hook support — Zed is an editor, not a CLI with hook pipelines
8
+ * - Config: ~/.config/zed/settings.json (JSON format)
9
+ * - MCP: full support via context_servers section in settings.json
10
+ * - All capabilities are false — MCP is the only integration path
11
+ * - Session dir: ~/.config/zed/context-mode/sessions/
12
+ */
13
+ import { createHash } from "node:crypto";
14
+ import { readFileSync, writeFileSync, mkdirSync, copyFileSync, accessSync, constants, } from "node:fs";
15
+ import { resolve, join, dirname } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+ import { homedir } from "node:os";
18
+ // ─────────────────────────────────────────────────────────
19
+ // Adapter implementation
20
+ // ─────────────────────────────────────────────────────────
21
+ export class ZedAdapter {
22
+ name = "Zed";
23
+ paradigm = "mcp-only";
24
+ capabilities = {
25
+ preToolUse: false,
26
+ postToolUse: false,
27
+ preCompact: false,
28
+ sessionStart: false,
29
+ canModifyArgs: false,
30
+ canModifyOutput: false,
31
+ canInjectSessionContext: false,
32
+ };
33
+ // ── Input parsing ──────────────────────────────────────
34
+ // Zed does not support hooks. These methods exist to satisfy the
35
+ // interface contract but will throw if called.
36
+ parsePreToolUseInput(_raw) {
37
+ throw new Error("Zed does not support hooks");
38
+ }
39
+ parsePostToolUseInput(_raw) {
40
+ throw new Error("Zed does not support hooks");
41
+ }
42
+ parsePreCompactInput(_raw) {
43
+ throw new Error("Zed does not support hooks");
44
+ }
45
+ parseSessionStartInput(_raw) {
46
+ throw new Error("Zed does not support hooks");
47
+ }
48
+ // ── Response formatting ────────────────────────────────
49
+ // Zed does not support hooks. Return undefined for all responses.
50
+ formatPreToolUseResponse(_response) {
51
+ return undefined;
52
+ }
53
+ formatPostToolUseResponse(_response) {
54
+ return undefined;
55
+ }
56
+ formatPreCompactResponse(_response) {
57
+ return undefined;
58
+ }
59
+ formatSessionStartResponse(_response) {
60
+ return undefined;
61
+ }
62
+ // ── Configuration ──────────────────────────────────────
63
+ getSettingsPath() {
64
+ return resolve(homedir(), ".config", "zed", "settings.json");
65
+ }
66
+ getSessionDir() {
67
+ const dir = join(homedir(), ".config", "zed", "context-mode", "sessions");
68
+ mkdirSync(dir, { recursive: true });
69
+ return dir;
70
+ }
71
+ getSessionDBPath(projectDir) {
72
+ const hash = createHash("sha256")
73
+ .update(projectDir)
74
+ .digest("hex")
75
+ .slice(0, 16);
76
+ return join(this.getSessionDir(), `${hash}.db`);
77
+ }
78
+ getSessionEventsPath(projectDir) {
79
+ const hash = createHash("sha256")
80
+ .update(projectDir)
81
+ .digest("hex")
82
+ .slice(0, 16);
83
+ return join(this.getSessionDir(), `${hash}-events.md`);
84
+ }
85
+ generateHookConfig(_pluginRoot) {
86
+ // Zed does not support hooks — return empty registration
87
+ return {};
88
+ }
89
+ readSettings() {
90
+ try {
91
+ const raw = readFileSync(this.getSettingsPath(), "utf-8");
92
+ return JSON.parse(raw);
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ }
98
+ writeSettings(settings) {
99
+ const settingsPath = this.getSettingsPath();
100
+ mkdirSync(dirname(settingsPath), { recursive: true });
101
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
102
+ }
103
+ // ── Diagnostics (doctor) ─────────────────────────────────
104
+ validateHooks(_pluginRoot) {
105
+ return [
106
+ {
107
+ check: "Hook support",
108
+ status: "warn",
109
+ message: "Zed does not support hooks. Only MCP integration is available.",
110
+ },
111
+ ];
112
+ }
113
+ checkPluginRegistration() {
114
+ // Check for context-mode in context_servers section of settings.json
115
+ try {
116
+ const raw = readFileSync(this.getSettingsPath(), "utf-8");
117
+ const settings = JSON.parse(raw);
118
+ const hasContextServers = settings.context_servers !== undefined;
119
+ const hasContextMode = raw.includes("context-mode");
120
+ if (hasContextServers && hasContextMode) {
121
+ return {
122
+ check: "MCP registration",
123
+ status: "pass",
124
+ message: "context-mode found in context_servers config",
125
+ };
126
+ }
127
+ if (hasContextServers) {
128
+ return {
129
+ check: "MCP registration",
130
+ status: "fail",
131
+ message: "context_servers section exists but context-mode not found",
132
+ fix: 'Add context-mode to context_servers in ~/.config/zed/settings.json',
133
+ };
134
+ }
135
+ return {
136
+ check: "MCP registration",
137
+ status: "fail",
138
+ message: "No context_servers section in settings.json",
139
+ fix: 'Add context_servers.context-mode to ~/.config/zed/settings.json',
140
+ };
141
+ }
142
+ catch {
143
+ return {
144
+ check: "MCP registration",
145
+ status: "warn",
146
+ message: "Could not read ~/.config/zed/settings.json",
147
+ };
148
+ }
149
+ }
150
+ getInstalledVersion() {
151
+ // Zed has no marketplace or plugin system for context-mode
152
+ return "not installed";
153
+ }
154
+ // ── Upgrade ────────────────────────────────────────────
155
+ configureAllHooks(_pluginRoot) {
156
+ // Zed does not support hooks — nothing to configure
157
+ return [];
158
+ }
159
+ backupSettings() {
160
+ const settingsPath = this.getSettingsPath();
161
+ try {
162
+ accessSync(settingsPath, constants.R_OK);
163
+ const backupPath = settingsPath + ".bak";
164
+ copyFileSync(settingsPath, backupPath);
165
+ return backupPath;
166
+ }
167
+ catch {
168
+ return null;
169
+ }
170
+ }
171
+ setHookPermissions(_pluginRoot) {
172
+ // No hook scripts for Zed
173
+ return [];
174
+ }
175
+ updatePluginRegistry(_pluginRoot, _version) {
176
+ // Zed has no plugin registry
177
+ }
178
+ // ── Routing Instructions (soft enforcement) ────────────
179
+ getRoutingInstructionsConfig() {
180
+ return {
181
+ fileName: "AGENTS.md",
182
+ globalPath: resolve(homedir(), ".config", "zed", "AGENTS.md"),
183
+ projectRelativePath: "AGENTS.md",
184
+ };
185
+ }
186
+ writeRoutingInstructions(projectDir, pluginRoot) {
187
+ const config = this.getRoutingInstructionsConfig();
188
+ const targetPath = resolve(projectDir, config.projectRelativePath);
189
+ const sourcePath = resolve(pluginRoot, "configs", "zed", config.fileName);
190
+ try {
191
+ const content = readFileSync(sourcePath, "utf-8");
192
+ try {
193
+ const existing = readFileSync(targetPath, "utf-8");
194
+ if (existing.includes("context-mode"))
195
+ return null;
196
+ writeFileSync(targetPath, existing.trimEnd() + "\n\n" + content, "utf-8");
197
+ return targetPath;
198
+ }
199
+ catch {
200
+ writeFileSync(targetPath, content, "utf-8");
201
+ return targetPath;
202
+ }
203
+ }
204
+ catch {
205
+ return null;
206
+ }
207
+ }
208
+ getRoutingInstructions() {
209
+ const instructionsPath = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "configs", "zed", "AGENTS.md");
210
+ try {
211
+ return readFileSync(instructionsPath, "utf-8");
212
+ }
213
+ catch {
214
+ // Fallback inline instructions
215
+ return "# context-mode\n\nUse context-mode MCP tools (execute, execute_file, batch_execute, fetch_and_index, search) instead of bash/cat/curl for data-heavy operations.";
216
+ }
217
+ }
218
+ }