context-mode 1.0.89 → 1.0.90

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.
Files changed (128) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.openclaw-plugin/openclaw.plugin.json +1 -1
  4. package/.openclaw-plugin/package.json +1 -1
  5. package/README.md +184 -60
  6. package/build/adapters/antigravity/index.d.ts +3 -5
  7. package/build/adapters/antigravity/index.js +7 -35
  8. package/build/adapters/base.d.ts +27 -0
  9. package/build/adapters/base.js +59 -0
  10. package/build/adapters/claude-code/index.d.ts +9 -25
  11. package/build/adapters/claude-code/index.js +12 -140
  12. package/build/adapters/claude-code-base.d.ts +49 -0
  13. package/build/adapters/claude-code-base.js +113 -0
  14. package/build/adapters/client-map.js +5 -0
  15. package/build/adapters/codex/hooks.d.ts +21 -14
  16. package/build/adapters/codex/hooks.js +22 -15
  17. package/build/adapters/codex/index.d.ts +6 -10
  18. package/build/adapters/codex/index.js +13 -43
  19. package/build/adapters/copilot-base.d.ts +78 -0
  20. package/build/adapters/copilot-base.js +281 -0
  21. package/build/adapters/cursor/index.d.ts +3 -5
  22. package/build/adapters/cursor/index.js +6 -34
  23. package/build/adapters/detect.d.ts +7 -0
  24. package/build/adapters/detect.js +57 -56
  25. package/build/adapters/gemini-cli/index.d.ts +3 -5
  26. package/build/adapters/gemini-cli/index.js +7 -35
  27. package/build/adapters/jetbrains-copilot/config.d.ts +8 -0
  28. package/build/adapters/jetbrains-copilot/config.js +8 -0
  29. package/build/adapters/jetbrains-copilot/hooks.d.ts +51 -0
  30. package/build/adapters/jetbrains-copilot/hooks.js +82 -0
  31. package/build/adapters/jetbrains-copilot/index.d.ts +24 -0
  32. package/build/adapters/jetbrains-copilot/index.js +119 -0
  33. package/build/adapters/kiro/hooks.d.ts +14 -0
  34. package/build/adapters/kiro/hooks.js +23 -0
  35. package/build/adapters/kiro/index.d.ts +3 -5
  36. package/build/adapters/kiro/index.js +10 -38
  37. package/build/adapters/openclaw/index.d.ts +3 -4
  38. package/build/adapters/openclaw/index.js +6 -22
  39. package/build/adapters/opencode/index.d.ts +2 -3
  40. package/build/adapters/opencode/index.js +5 -16
  41. package/build/adapters/qwen-code/index.d.ts +39 -0
  42. package/build/adapters/qwen-code/index.js +199 -0
  43. package/build/adapters/types.d.ts +1 -1
  44. package/build/adapters/vscode-copilot/index.d.ts +16 -46
  45. package/build/adapters/vscode-copilot/index.js +29 -320
  46. package/build/adapters/zed/index.d.ts +3 -5
  47. package/build/adapters/zed/index.js +7 -35
  48. package/build/cli.js +13 -0
  49. package/build/lifecycle.d.ts +23 -0
  50. package/build/lifecycle.js +54 -13
  51. package/build/opencode-plugin.d.ts +19 -7
  52. package/build/opencode-plugin.js +19 -7
  53. package/build/runtime.js +24 -9
  54. package/build/security.d.ts +17 -1
  55. package/build/security.js +40 -6
  56. package/build/server.js +41 -9
  57. package/build/session/analytics.d.ts +8 -7
  58. package/build/session/analytics.js +95 -75
  59. package/build/session/db.d.ts +10 -1
  60. package/build/session/db.js +67 -8
  61. package/build/session/extract.js +10 -2
  62. package/build/session/project-attribution.d.ts +73 -0
  63. package/build/session/project-attribution.js +231 -0
  64. package/build/store.d.ts +4 -0
  65. package/build/store.js +58 -9
  66. package/build/types.d.ts +8 -0
  67. package/cli.bundle.mjs +135 -121
  68. package/configs/antigravity/GEMINI.md +31 -36
  69. package/configs/claude-code/CLAUDE.md +31 -37
  70. package/configs/codex/AGENTS.md +35 -49
  71. package/configs/cursor/context-mode.mdc +24 -25
  72. package/configs/gemini-cli/GEMINI.md +30 -36
  73. package/configs/jetbrains-copilot/copilot-instructions.md +59 -0
  74. package/configs/jetbrains-copilot/hooks.json +16 -0
  75. package/configs/jetbrains-copilot/mcp.json +8 -0
  76. package/configs/kilo/AGENTS.md +30 -36
  77. package/configs/kiro/KIRO.md +30 -36
  78. package/configs/kiro/agent.json +1 -1
  79. package/configs/openclaw/AGENTS.md +30 -36
  80. package/configs/opencode/AGENTS.md +30 -36
  81. package/configs/pi/AGENTS.md +31 -36
  82. package/configs/qwen-code/QWEN.md +63 -0
  83. package/configs/vscode-copilot/copilot-instructions.md +30 -36
  84. package/configs/zed/AGENTS.md +31 -36
  85. package/hooks/codex/posttooluse.mjs +7 -7
  86. package/hooks/codex/pretooluse.mjs +3 -3
  87. package/hooks/codex/sessionstart.mjs +2 -1
  88. package/hooks/core/formatters.mjs +24 -0
  89. package/hooks/core/routing.mjs +40 -15
  90. package/hooks/core/tool-naming.mjs +2 -0
  91. package/hooks/cursor/posttooluse.mjs +7 -7
  92. package/hooks/cursor/pretooluse.mjs +3 -3
  93. package/hooks/cursor/sessionstart.mjs +2 -1
  94. package/hooks/cursor/stop.mjs +2 -2
  95. package/hooks/ensure-deps.mjs +22 -10
  96. package/hooks/gemini-cli/aftertool.mjs +8 -8
  97. package/hooks/gemini-cli/beforetool.mjs +3 -2
  98. package/hooks/gemini-cli/precompress.mjs +2 -2
  99. package/hooks/gemini-cli/sessionstart.mjs +12 -4
  100. package/hooks/jetbrains-copilot/posttooluse.mjs +61 -0
  101. package/hooks/jetbrains-copilot/precompact.mjs +54 -0
  102. package/hooks/jetbrains-copilot/pretooluse.mjs +27 -0
  103. package/hooks/jetbrains-copilot/sessionstart.mjs +119 -0
  104. package/hooks/kiro/posttooluse.mjs +6 -7
  105. package/hooks/kiro/pretooluse.mjs +3 -2
  106. package/hooks/posttooluse.mjs +8 -8
  107. package/hooks/precompact.mjs +3 -4
  108. package/hooks/pretooluse.mjs +5 -4
  109. package/hooks/routing-block.mjs +35 -33
  110. package/hooks/session-attribution.bundle.mjs +1 -0
  111. package/hooks/session-db.bundle.mjs +27 -8
  112. package/hooks/session-extract.bundle.mjs +2 -1
  113. package/hooks/session-helpers.mjs +44 -3
  114. package/hooks/session-loaders.mjs +37 -0
  115. package/hooks/sessionstart.mjs +5 -5
  116. package/hooks/userpromptsubmit.mjs +26 -9
  117. package/hooks/vscode-copilot/posttooluse.mjs +8 -8
  118. package/hooks/vscode-copilot/precompact.mjs +2 -2
  119. package/hooks/vscode-copilot/pretooluse.mjs +3 -2
  120. package/hooks/vscode-copilot/sessionstart.mjs +2 -2
  121. package/insight/server.mjs +237 -25
  122. package/insight/src/lib/api.ts +2 -1
  123. package/insight/src/routes/index.tsx +16 -3
  124. package/insight/src/routes/search.tsx +1 -1
  125. package/openclaw.plugin.json +1 -1
  126. package/package.json +11 -2
  127. package/server.bundle.mjs +94 -80
  128. package/skills/ctx-insight/SKILL.md +1 -1
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "Claude Code plugins by Mert Koseoğlu",
9
- "version": "1.0.89"
9
+ "version": "1.0.90"
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.89",
16
+ "version": "1.0.90",
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.89",
3
+ "version": "1.0.90",
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.89",
6
+ "version": "1.0.90",
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.89",
3
+ "version": "1.0.90",
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
@@ -31,13 +31,24 @@
31
31
 
32
32
  ## The Problem
33
33
 
34
- 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.
34
+ 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. On top of that, the agent wastes output tokens on filler, pleasantries, and verbose explanations — burning context from both sides.
35
35
 
36
- Context Mode is an MCP server that solves all three sides of this problem:
36
+ ### How Context Mode Solves It
37
+
38
+ Context Mode is an MCP server that solves all four sides of this problem:
37
39
 
38
40
  1. **Context Saving** — Sandbox tools keep raw data out of the context window. 315 KB becomes 5.4 KB. 98% reduction.
39
41
  2. **Session Continuity** — Every file edit, git operation, task, error, and user decision is tracked in SQLite. When the conversation compacts, context-mode doesn't dump this data back into context — it indexes events into FTS5 and retrieves only what's relevant via BM25 search. The model picks up exactly where you left off. If you don't `--continue`, previous session data is deleted immediately — a fresh session means a clean slate.
40
- 3. **Think in Code** — The LLM should program the analysis, not compute it. Instead of reading 50 files into context to count functions, the agent writes a script that does the counting and `console.log()`s only the result. One script replaces ten tool calls and saves 100x context. This is a mandatory paradigm across all 12 platforms: stop treating the LLM as a data processor, treat it as a code generator.
42
+ 3. **Think in Code** — The LLM should program the analysis, not compute it. Instead of reading 50 files into context to count functions, the agent writes a script that does the counting and `console.log()`s only the result. One script replaces ten tool calls and saves 100x context. This is a mandatory paradigm across all 14 platforms: stop treating the LLM as a data processor, treat it as a code generator.
43
+
44
+ ```js
45
+ // Before: 47 × Read() = 700 KB. After: 1 × ctx_execute() = 3.6 KB.
46
+ ctx_execute("javascript", `
47
+ const files = fs.readdirSync('src').filter(f => f.endsWith('.ts'));
48
+ files.forEach(f => console.log(f + ': ' + fs.readFileSync('src/'+f,'utf8').split('\\n').length + ' lines'));
49
+ `);
50
+ ```
51
+ 4. **Output Compression** — Terse like caveman. Technical substance exact. Only fluff die. Drop articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged. Pattern: [thing] [action] [reason]. [next step]. Auto-expand for security warnings, irreversible actions, and user confusion. ~65-75% output token reduction with full technical accuracy.
41
52
 
42
53
  <a href="https://www.youtube.com/watch?v=QUHrntlfPo4">
43
54
  <picture>
@@ -158,7 +169,11 @@ This gives you the 6 sandbox tools without automatic routing. The model can stil
158
169
 
159
170
  You should see `context-mode: ... - Connected`.
160
171
 
161
- **Routing:** Automatic. The SessionStart hook injects routing instructions at runtime no `GEMINI.md` file is written to your project. All four hooks (BeforeTool, AfterTool, PreCompress, SessionStart) handle enforcement programmatically.
172
+ **Routing:** Automatic via SessionStart hook. Optionally copy routing instructions for full model awareness:
173
+
174
+ ```bash
175
+ cp node_modules/context-mode/configs/gemini-cli/GEMINI.md ./GEMINI.md
176
+ ```
162
177
 
163
178
  > **Why the BeforeTool matcher?** It targets only tools that produce large output (`run_shell_command`, `read_file`, `read_many_files`, `grep_search`, `search_file_content`, `web_fetch`, `activate_skill`) plus context-mode's own tools (`mcp__plugin_context-mode`). This avoids unnecessary hook overhead on lightweight tools while intercepting every tool that could flood your context window.
164
179
 
@@ -213,12 +228,67 @@ Full config reference: [`configs/gemini-cli/settings.json`](configs/gemini-cli/s
213
228
 
214
229
  **Verify:** Open Copilot Chat and type `ctx stats`. Context-mode tools should appear and respond.
215
230
 
216
- **Routing:** Automatic. The SessionStart hook injects routing instructions at runtime no `copilot-instructions.md` file is written to your project.
231
+ **Routing:** Automatic via SessionStart hook. Optionally copy routing instructions for full model awareness:
232
+
233
+ ```bash
234
+ cp node_modules/context-mode/configs/vscode-copilot/copilot-instructions.md .github/copilot-instructions.md
235
+ ```
217
236
 
218
237
  Full hook config including PreCompact: [`configs/vscode-copilot/hooks.json`](configs/vscode-copilot/hooks.json)
219
238
 
220
239
  </details>
221
240
 
241
+ <details>
242
+ <summary><strong>JetBrains Copilot</strong> — hooks with SessionStart</summary>
243
+
244
+ **Prerequisites:** Node.js 18+, JetBrains IDE with GitHub Copilot plugin v1.5.57+.
245
+
246
+ **Install:**
247
+
248
+ 1. Install context-mode globally:
249
+
250
+ ```bash
251
+ npm install -g context-mode
252
+ ```
253
+
254
+ 2. Add MCP server via Settings UI: **Settings > Tools > AI Assistant > Model Context Protocol (MCP) > Add Server**:
255
+ - **Name:** `context-mode`
256
+ - **Command:** `context-mode`
257
+
258
+ 3. Create `.github/hooks/context-mode.json`:
259
+
260
+ ```json
261
+ {
262
+ "hooks": {
263
+ "PreToolUse": [
264
+ { "type": "command", "command": "context-mode hook jetbrains-copilot pretooluse" }
265
+ ],
266
+ "PostToolUse": [
267
+ { "type": "command", "command": "context-mode hook jetbrains-copilot posttooluse" }
268
+ ],
269
+ "SessionStart": [
270
+ { "type": "command", "command": "context-mode hook jetbrains-copilot sessionstart" }
271
+ ]
272
+ }
273
+ }
274
+ ```
275
+
276
+ 4. Restart the JetBrains IDE.
277
+
278
+ **Verify:** Open Copilot Chat and type `ctx stats`. Context-mode tools should appear and respond.
279
+
280
+ **Routing:** Automatic via SessionStart hook. Optionally copy routing instructions for full model awareness:
281
+
282
+ ```bash
283
+ cp node_modules/context-mode/configs/jetbrains-copilot/copilot-instructions.md .github/copilot-instructions.md
284
+ ```
285
+
286
+ Full hook config including PreCompact: [`configs/jetbrains-copilot/hooks.json`](configs/jetbrains-copilot/hooks.json)
287
+
288
+ Full setup guide: [`docs/jetbrains-copilot.md`](docs/jetbrains-copilot.md)
289
+
290
+ </details>
291
+
222
292
  <details>
223
293
  <summary><strong>Cursor</strong> — hooks with stop support</summary>
224
294
 
@@ -427,7 +497,7 @@ Full documentation: [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md)
427
497
  </details>
428
498
 
429
499
  <details>
430
- <summary><strong>Codex CLI</strong> — MCP + hooks (waiting for upstream dispatch)</summary>
500
+ <summary><strong>Codex CLI</strong> — MCP + hooks</summary>
431
501
 
432
502
  **Prerequisites:** Node.js 18+, Codex CLI installed.
433
503
 
@@ -446,32 +516,23 @@ Full documentation: [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md)
446
516
  command = "context-mode"
447
517
  ```
448
518
 
449
- 3. *(Waiting for upstream)* Enable the hooks feature flag. Add to `~/.codex/config.toml`:
450
-
451
- ```toml
452
- [features]
453
- codex_hooks = true
454
- ```
455
-
456
- > **Status:** Codex CLI's hook system is implemented in source (`codex-rs/hooks/`) but hook dispatch is not yet wired into the tool execution pipeline (`Stage::UnderDevelopment`). The feature flag is accepted but hooks don't fire during sessions as of v0.118.0. Our hook scripts are ready — they'll work immediately once Codex enables dispatch. Track progress: [openai/codex#16685](https://github.com/openai/codex/issues/16685).
457
-
458
- 4. *(Prepare for when dispatch is enabled)* Add hooks for routing enforcement and session tracking. Create `~/.codex/hooks.json`:
519
+ 3. Add hooks for routing enforcement and session tracking. Create `~/.codex/hooks.json`:
459
520
 
460
521
  ```json
461
522
  {
462
523
  "hooks": {
463
- "PreToolUse": [{ "hooks": [{ "type": "command", "command": "context-mode hook codex pretooluse" }] }],
524
+ "PreToolUse": [{ "matcher": "local_shell|shell|shell_command|exec_command|container.exec|Bash|Shell|grep_files|mcp__plugin_context-mode_context-mode__ctx_execute|mcp__plugin_context-mode_context-mode__ctx_execute_file|mcp__plugin_context-mode_context-mode__ctx_batch_execute", "hooks": [{ "type": "command", "command": "context-mode hook codex pretooluse" }] }],
464
525
  "PostToolUse": [{ "hooks": [{ "type": "command", "command": "context-mode hook codex posttooluse" }] }],
465
526
  "SessionStart": [{ "hooks": [{ "type": "command", "command": "context-mode hook codex sessionstart" }] }]
466
527
  }
467
528
  }
468
529
  ```
469
530
 
470
- `PreToolUse` enforces sandbox routing (blocks dangerous commands, redirects to MCP tools). `PostToolUse` captures session events. `SessionStart` restores state after compaction.
531
+ `PreToolUse` enforces deny/block routing today and is prepared for input rewrites once Codex supports them. `PostToolUse` captures session events. `SessionStart` restores state after compaction.
471
532
 
472
- > **Note:** PreToolUse routing supports deny rules only (blocks dangerous commands). Context injection (`additionalContext`) is not supported in Codex PreToolUse — it works via PostToolUse and SessionStart instead. This is handled automatically.
533
+ > **Note:** Codex PreToolUse routing currently supports deny rules only (blocks dangerous commands). It still needs upstream `updatedInput` support before context-mode can rewrite tool input; track [openai/codex#18491](https://github.com/openai/codex/issues/18491). Context injection (`additionalContext`) is not supported in Codex PreToolUse — it works via PostToolUse and SessionStart instead. This is handled automatically.
473
534
 
474
- 5. Copy routing instructions (recommended even with hooks for full routing awareness):
535
+ 4. Copy routing instructions (recommended even with hooks for full routing awareness):
475
536
 
476
537
  ```bash
477
538
  cp node_modules/context-mode/configs/codex/AGENTS.md ./AGENTS.md
@@ -479,13 +540,65 @@ Full documentation: [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md)
479
540
 
480
541
  For global use: `cp node_modules/context-mode/configs/codex/AGENTS.md ~/.codex/AGENTS.md`. Global applies to all projects. If both exist, Codex CLI merges them.
481
542
 
482
- 6. Restart Codex CLI.
543
+ 5. Restart Codex CLI.
483
544
 
484
545
  **Verify:** Start a session and type `ctx stats`. Context-mode tools should appear and respond.
485
546
 
486
- **Routing:** MCP tools work. Hook-based routing is ready but waiting for Codex to enable hook dispatch. The `AGENTS.md` file provides routing instructions for model awareness in the meantime.
547
+ **Routing:** MCP tools work. Hook-based routing is active when `~/.codex/hooks.json` is configured. The `AGENTS.md` file provides routing instructions for model awareness.
487
548
 
488
- > **Exec mode regression (v0.118.0):** `codex exec` cancels all MCP tool calls with "user cancelled MCP tool call". The `tool_call_mcp_elicitation` flag went stable in 0.118.0, adding an approval prompt that exec-mode can't handle. **Pin to Codex ≤0.116.0 for exec-mode MCP.** Confirmed by upstream: [openai/codex#16685](https://github.com/openai/codex/issues/16685). Interactive mode (`codex` / `codex --full-auto`) is not affected.
549
+ </details>
550
+
551
+ <details>
552
+ <summary><strong>Qwen Code</strong> — MCP + hooks (identical wire protocol to Claude Code)</summary>
553
+
554
+ **Prerequisites:** Node.js 18+, Qwen Code installed (`npm install -g @qwen-code/qwen-code`).
555
+
556
+ 1. Install context-mode:
557
+
558
+ ```bash
559
+ npm install -g context-mode
560
+ ```
561
+
562
+ 2. Add context-mode as an MCP server. Add to `~/.qwen/settings.json`:
563
+
564
+ ```json
565
+ {
566
+ "mcpServers": {
567
+ "context-mode": {
568
+ "command": "context-mode",
569
+ "args": []
570
+ }
571
+ }
572
+ }
573
+ ```
574
+
575
+ 3. Add hooks for routing enforcement and session tracking. Add to `~/.qwen/settings.json`:
576
+
577
+ ```json
578
+ {
579
+ "hooks": {
580
+ "PreToolUse": [{ "matcher": "run_shell_command|read_file|read_many_files|grep_search|web_fetch|agent|mcp__plugin_context-mode_context-mode__ctx_execute|mcp__plugin_context-mode_context-mode__ctx_execute_file|mcp__plugin_context-mode_context-mode__ctx_batch_execute", "hooks": [{ "type": "command", "command": "context-mode hook qwen-code pretooluse" }] }],
581
+ "PostToolUse": [{ "matcher": "", "hooks": [{ "type": "command", "command": "context-mode hook qwen-code posttooluse" }] }],
582
+ "SessionStart": [{ "matcher": "", "hooks": [{ "type": "command", "command": "context-mode hook qwen-code sessionstart" }] }],
583
+ "PreCompact": [{ "matcher": "", "hooks": [{ "type": "command", "command": "context-mode hook qwen-code precompact" }] }],
584
+ "UserPromptSubmit": [{ "matcher": "", "hooks": [{ "type": "command", "command": "context-mode hook qwen-code userpromptsubmit" }] }]
585
+ }
586
+ }
587
+ ```
588
+
589
+ 4. Copy routing instructions (recommended for full routing awareness):
590
+
591
+ ```bash
592
+ cp node_modules/context-mode/configs/qwen-code/QWEN.md ./QWEN.md
593
+ ```
594
+
595
+ For global use: `cp node_modules/context-mode/configs/qwen-code/QWEN.md ~/.qwen/QWEN.md`
596
+
597
+ 5. Restart Qwen Code.
598
+
599
+ **Verify:** Start a session and type `ctx stats`. Context-mode tools should appear and respond.
600
+
601
+ **Note:** Qwen Code uses the same hook wire protocol as Claude Code (JSON stdin/stdout, same event names). Auto-detected via MCP clientInfo (`qwen-cli-mcp-client-*`) or `QWEN_PROJECT_DIR` env var.
489
602
 
490
603
  </details>
491
604
 
@@ -563,7 +676,7 @@ Full configs: [`configs/antigravity/mcp_config.json`](configs/antigravity/mcp_co
563
676
  "description": "Context-mode hooks for context window protection",
564
677
  "hooks": {
565
678
  "preToolUse": [
566
- { "matcher": "*", "command": "context-mode hook kiro pretooluse" }
679
+ { "matcher": "execute_bash|fs_read|@context-mode/ctx_execute|@context-mode/ctx_execute_file|@context-mode/ctx_batch_execute", "command": "context-mode hook kiro pretooluse" }
567
680
  ],
568
681
  "postToolUse": [
569
682
  { "matcher": "*", "command": "context-mode hook kiro posttooluse" }
@@ -638,31 +751,39 @@ Full configs: [`configs/kiro/mcp.json`](configs/kiro/mcp.json) | [`configs/kiro/
638
751
 
639
752
  **Install:**
640
753
 
641
- 1. Clone the extension:
754
+ 1. Install context-mode globally:
642
755
 
643
756
  ```bash
644
- git clone https://github.com/mksglu/context-mode.git ~/.pi/extensions/context-mode
645
- cd ~/.pi/extensions/context-mode
646
- npm install
647
- npm run build
757
+ npm install -g context-mode
648
758
  ```
649
759
 
650
- 2. Add to `~/.pi/agent/mcp.json` (or `.pi/mcp.json` for project-level):
760
+ 2. Install the package into Pi:
761
+
762
+ ```bash
763
+ pi install npm:context-mode
764
+ ```
765
+
766
+ Alternative — add it manually to `~/.pi/agent/settings.json` (or `.pi/settings.json` for project-level):
767
+
768
+ ```json
769
+ {
770
+ "packages": ["npm:context-mode"]
771
+ }
772
+ ```
773
+
774
+ 3. Add to `~/.pi/agent/mcp.json` (or `.pi/mcp.json` for project-level):
651
775
 
652
776
  ```json
653
777
  {
654
778
  "mcpServers": {
655
779
  "context-mode": {
656
- "command": "node",
657
- "args": ["/home/youruser/.pi/extensions/context-mode/node_modules/context-mode/start.mjs"]
780
+ "command": "context-mode"
658
781
  }
659
782
  }
660
783
  }
661
784
  ```
662
785
 
663
- > **Note:** JSON does not expand `~`. Replace `/home/youruser` with your actual home directory (run `echo $HOME` to find it).
664
-
665
- 3. Restart Pi.
786
+ 4. Restart Pi.
666
787
 
667
788
  **Verify:** In a Pi session, type `ctx stats`. Context-mode tools should appear and respond.
668
789
 
@@ -787,16 +908,16 @@ Context Mode captures every meaningful event during your session and persists th
787
908
 
788
909
  Session continuity requires 4 hooks working together:
789
910
 
790
- | Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | KiloCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
791
- |---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
792
- | **PreToolUse** | Enforces sandbox routing before tool execution | Yes | -- | -- | Yes | -- | -- | -- | Yes | -- | Yes | -- | ✓ (via tool_call event) |
793
- | **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | ✓ (via tool_result event) |
794
- | **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
795
- | **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | -- | Plugin | Plugin | Plugin | -- | -- | -- | -- | ✓ (via session_before_compact) |
796
- | **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | -- | -- | -- | Plugin | Yes | -- | -- | -- | ✓ (via session_start event) |
797
- | | **Session completeness** | **Full** | **High** | **High** | **Partial** | **High** | **High** | **High** | **Partial** | **--** | **Partial** | **--** | **High** |
911
+ | Hook | Role | Claude Code | Gemini CLI | VS Code Copilot | JetBrains Copilot | Cursor | OpenCode | KiloCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
912
+ |---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
913
+ | **PreToolUse** | Enforces sandbox routing before tool execution | Yes | -- | -- | -- | Yes | -- | -- | -- | Yes | -- | Yes | -- | ✓ (via tool_call event) |
914
+ | **PostToolUse** | Captures events after each tool call | Yes | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | ✓ (via tool_result event) |
915
+ | **UserPromptSubmit** | Captures user decisions and corrections | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
916
+ | **PreCompact** | Builds snapshot before compaction | Yes | Yes | Yes | Yes | -- | Plugin | Plugin | Plugin | -- | -- | -- | -- | ✓ (via session_before_compact) |
917
+ | **SessionStart** | Restores state after compaction or resume | Yes | Yes | Yes | Yes | -- | -- | -- | Plugin | Yes | -- | -- | -- | ✓ (via session_start event) |
918
+ | | **Session completeness** | **Full** | **High** | **High** | **High** | **Partial** | **High** | **High** | **High** | **Partial** | **--** | **Partial** | **--** | **High** |
798
919
 
799
- > **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, and **VS Code Copilot**. **OpenCode** provides **high** session continuity: it captures tool events and injects compaction snapshots via the plugin, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume restore is not supported. **KiloCode** shares the same plugin architecture as OpenCode via the OpenCodeAdapter, so its continuity level depends on KiloCode's SessionStart support. **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. **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** hook-based session tracking is ready but waiting for upstream hook dispatch (codex_hooks Stage::UnderDevelopment, [openai/codex#16685](https://github.com/openai/codex/issues/16685)). MCP tools work. Once dispatch is enabled, session tracking will activate automatically. **Antigravity**, **Kiro**, and **Zed** have no hook support in the current release, so session tracking is not available.
920
+ > **Note:** Full session continuity (capture + snapshot + restore) works on **Claude Code**, **Gemini CLI**, **VS Code Copilot**, and **JetBrains Copilot**. **OpenCode** provides **high** session continuity: it captures tool events and injects compaction snapshots via the plugin, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)), so startup/resume restore is not supported. **KiloCode** shares the same plugin architecture as OpenCode via the OpenCodeAdapter, so its continuity level depends on KiloCode's SessionStart support. **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. **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** provides partial hook-based session tracking through PreToolUse, PostToolUse, and SessionStart; MCP tools work. **Antigravity**, **Kiro**, and **Zed** have no hook support in the current release, so session tracking is not available.
800
921
 
801
922
  <details>
802
923
  <summary><strong>What gets captured</strong></summary>
@@ -871,6 +992,8 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
871
992
 
872
993
  **VS Code Copilot** — High coverage. Same as Gemini CLI — PostToolUse, PreCompact, and SessionStart all fire. User decisions aren't captured but all tool-level events are.
873
994
 
995
+ **JetBrains Copilot** — High coverage. Same capabilities as VS Code Copilot — PostToolUse, PreCompact, and SessionStart all fire. Uses the same hook wire protocol and response format. User decisions aren't captured but all tool-level events are.
996
+
874
997
  **Cursor** — Partial coverage. Native `preToolUse` and `postToolUse` hooks capture tool events. `sessionStart` is documented by Cursor but currently rejected by their validator, so session restore is not available. Routing instructions are delivered via MCP server startup instead.
875
998
 
876
999
  **OpenCode** — Partial. The TypeScript plugin captures PostToolUse events via `tool.execute.after`, but SessionStart is not yet available ([#14808](https://github.com/sst/opencode/issues/14808)). Events are stored but not automatically restored after compaction.
@@ -879,7 +1002,7 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
879
1002
 
880
1003
  **OpenClaw / Pi Agent** — High coverage. All tool lifecycle hooks (`after_tool_call`, `before_compaction`, `session_start`) fire via the native gateway plugin. User decisions aren't captured but file edits, git ops, errors, and tasks are fully tracked. Falls back to DB snapshot reconstruction if compaction hooks fail on older gateway versions. See [`docs/adapters/openclaw.md`](docs/adapters/openclaw.md).
881
1004
 
882
- **Codex CLI** — MCP active, hooks ready. Hook scripts (PreToolUse, PostToolUse, SessionStart) are implemented and tested but Codex CLI doesn't dispatch them yet (Stage::UnderDevelopment). MCP tools work. Track: [openai/codex#16685](https://github.com/openai/codex/issues/16685).
1005
+ **Codex CLI** — MCP active, hooks stable. Hook scripts (PreToolUse, PostToolUse, SessionStart) are implemented and tested. PreToolUse deny routing works; input rewriting still depends on upstream `updatedInput` support ([openai/codex#18491](https://github.com/openai/codex/issues/18491)).
883
1006
 
884
1007
  **Antigravity** — No session support. No hooks, no event capture. Requires manually copying `GEMINI.md` to your project root. Auto-detected via MCP protocol handshake (`clientInfo.name`).
885
1008
 
@@ -893,18 +1016,18 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
893
1016
 
894
1017
  ## Platform Compatibility
895
1018
 
896
- | Feature | Claude Code | Gemini CLI | VS Code Copilot | Cursor | OpenCode | KiloCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
897
- |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
898
- | MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
899
- | PreToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
900
- | PostToolUse Hook | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
901
- | SessionStart Hook | Yes | Yes | Yes | -- | -- | -- | Plugin | Yes | -- | -- | -- | Yes (extension) |
902
- | PreCompact Hook | Yes | Yes | Yes | -- | Plugin | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
903
- | Can Modify Args | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | -- | -- | Yes (extension) |
904
- | Can Block Tools | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
905
- | Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes (/ctx-stats, /ctx-doctor) |
906
- | Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
907
- | Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
1019
+ | Feature | Claude Code | Qwen Code | Gemini CLI | VS Code Copilot | JetBrains Copilot | Cursor | OpenCode | KiloCode | OpenClaw | Codex CLI | Antigravity | Kiro | Zed | Pi |
1020
+ |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
1021
+ | MCP Server | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
1022
+ | PreToolUse Hook | Yes | Yes | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
1023
+ | PostToolUse Hook | Yes | Yes | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
1024
+ | SessionStart Hook | Yes | Yes | Yes | Yes | Yes | -- | -- | -- | Plugin | Yes | -- | -- | -- | Yes (extension) |
1025
+ | PreCompact Hook | Yes | Yes | Yes | Yes | Yes | -- | Plugin | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
1026
+ | Can Modify Args | Yes | Yes | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | -- | -- | -- | -- | Yes (extension) |
1027
+ | Can Block Tools | Yes | Yes | Yes | Yes | Yes | Yes | Plugin | Plugin | Plugin | Yes | -- | Yes | -- | Yes (extension) |
1028
+ | Utility Commands (ctx) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes (/ctx-stats, /ctx-doctor) |
1029
+ | Slash Commands | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
1030
+ | Plugin Marketplace | Yes | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
908
1031
 
909
1032
  > **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.
910
1033
  >
@@ -912,7 +1035,7 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
912
1035
  >
913
1036
  > **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).
914
1037
  >
915
- > **Codex CLI** hooks are implemented but dispatch is not yet active (`codex_hooks` is `Stage::UnderDevelopment`). MCP tools work. Hook scripts are ready and will activate once Codex enables dispatch ([openai/codex#16685](https://github.com/openai/codex/issues/16685)). PreToolUse supports `permissionDecision: "deny"` only — `additionalContext` is not supported in PreToolUse (context injection works via PostToolUse and SessionStart instead; the codex formatter handles this automatically). See the Codex install section for setup. **Antigravity** and **Zed** do not support hooks. They rely solely on manually-copied routing instruction files (`AGENTS.md` / `GEMINI.md`) for enforcement (~60% compliance). See each platform's install section for copy instructions. Antigravity and Zed are auto-detected via MCP protocol handshake — no manual platform configuration needed.
1038
+ > **Codex CLI** hooks are stable. MCP tools work, and hook scripts activate through `~/.codex/hooks.json`. PreToolUse supports `permissionDecision: "deny"` only; input modification still needs upstream `updatedInput` support ([openai/codex#18491](https://github.com/openai/codex/issues/18491)). `additionalContext` is not supported in PreToolUse (context injection works via PostToolUse and SessionStart instead; the codex formatter handles this automatically). See the Codex install section for setup. **Antigravity** and **Zed** do not support hooks. They rely solely on manually-copied routing instruction files (`AGENTS.md` / `GEMINI.md`) for enforcement (~60% compliance). See each platform's install section for copy instructions. Antigravity and Zed are auto-detected via MCP protocol handshake — no manual platform configuration needed.
916
1039
  >
917
1040
  > **Kiro** supports native `preToolUse` and `postToolUse` hooks for routing enforcement and tool event capture. `agentSpawn` (SessionStart equivalent) and `stop` are not yet wired. Requires manually copying `KIRO.md` to your project root. Kiro is auto-detected via MCP protocol handshake (`clientInfo.name`).
918
1041
  >
@@ -922,13 +1045,14 @@ Detailed event data is also indexed into FTS5 for on-demand retrieval via `searc
922
1045
 
923
1046
  Hooks intercept tool calls programmatically — they can block dangerous commands and redirect them to the sandbox before execution. Instruction files guide the model via prompt instructions but cannot block anything. **Always enable hooks where supported.**
924
1047
 
925
- > **Note:** Routing instruction files were previously auto-written to project directories on first session start. This was disabled to prevent git tree pollution ([#158](https://github.com/mksglu/context-mode/issues/158), [#164](https://github.com/mksglu/context-mode/issues/164)). Hook-capable platforms (Claude Code, Gemini CLI, VS Code Copilot, Cursor, OpenCode, OpenClaw, Codex CLI) inject routing via hooks and need no file. Non-hook platforms (Zed, Kiro, Antigravity) require a one-time manual copy — see each platform's install section.
1048
+ > **Note:** Routing instruction files were previously auto-written to project directories on first session start. This was disabled to prevent git tree pollution ([#158](https://github.com/mksglu/context-mode/issues/158), [#164](https://github.com/mksglu/context-mode/issues/164)). Hook-capable platforms (Claude Code, Gemini CLI, VS Code Copilot, JetBrains Copilot, Cursor, OpenCode, OpenClaw, Codex CLI) inject routing via hooks and need no file. Non-hook platforms (Zed, Kiro, Antigravity) require a one-time manual copy — see each platform's install section.
926
1049
 
927
1050
  | Platform | Hooks | Instruction File | With Hooks | Without Hooks |
928
1051
  |---|:---:|---|:---:|:---:|
929
1052
  | Claude Code | Yes (auto) | [`CLAUDE.md`](configs/claude-code/CLAUDE.md) | **~98% saved** | ~60% saved |
930
1053
  | Gemini CLI | Yes | [`GEMINI.md`](configs/gemini-cli/GEMINI.md) | **~98% saved** | ~60% saved |
931
1054
  | VS Code Copilot | Yes | [`copilot-instructions.md`](configs/vscode-copilot/copilot-instructions.md) | **~98% saved** | ~60% saved |
1055
+ | JetBrains Copilot | Yes | [`copilot-instructions.md`](configs/vscode-copilot/copilot-instructions.md) | **~98% saved** | ~60% saved |
932
1056
  | Cursor | Yes | [`context-mode.mdc`](configs/cursor/context-mode.mdc) | **~98% saved** | ~60% saved |
933
1057
  | OpenCode | Plugin | [`AGENTS.md`](configs/opencode/AGENTS.md) | **~98% saved** | ~60% saved |
934
1058
  | OpenClaw | Plugin | [`AGENTS.md`](configs/openclaw/AGENTS.md) | **~98% saved** | ~60% saved |
@@ -1059,7 +1183,7 @@ Context Mode enforces the same permission rules you already use — but extends
1059
1183
  }
1060
1184
  ```
1061
1185
 
1062
- Add this to your project's `.claude/settings.json` (or `~/.claude/settings.json` for global rules). All platforms read security policies from Claude Code's settings format — even on Gemini CLI, VS Code Copilot, and OpenCode. Codex CLI security enforcement requires the `codex_hooks` feature flag to be enabled.
1186
+ Add this to your project's `.claude/settings.json` (or `~/.claude/settings.json` for global rules). All platforms read security policies from Claude Code's settings format — even on Gemini CLI, VS Code Copilot, and OpenCode. Codex CLI security enforcement requires the Codex hooks in `~/.codex/hooks.json` to be configured.
1063
1187
 
1064
1188
  The pattern is `Tool(what to match)` where `*` means "anything".
1065
1189
 
@@ -16,8 +16,10 @@
16
16
  * - MCP support: https://antigravity.google/docs/mcp
17
17
  * - Tool list: System prompt leak (21 verified tools)
18
18
  */
19
+ import { BaseAdapter } from "../base.js";
19
20
  import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse, HookRegistration } from "../types.js";
20
- export declare class AntigravityAdapter implements HookAdapter {
21
+ export declare class AntigravityAdapter extends BaseAdapter implements HookAdapter {
22
+ constructor();
21
23
  readonly name = "Antigravity";
22
24
  readonly paradigm: HookParadigm;
23
25
  readonly capabilities: PlatformCapabilities;
@@ -30,9 +32,6 @@ export declare class AntigravityAdapter implements HookAdapter {
30
32
  formatPreCompactResponse(_response: PreCompactResponse): unknown;
31
33
  formatSessionStartResponse(_response: SessionStartResponse): unknown;
32
34
  getSettingsPath(): string;
33
- getSessionDir(): string;
34
- getSessionDBPath(projectDir: string): string;
35
- getSessionEventsPath(projectDir: string): string;
36
35
  generateHookConfig(_pluginRoot: string): HookRegistration;
37
36
  readSettings(): Record<string, unknown> | null;
38
37
  writeSettings(settings: Record<string, unknown>): void;
@@ -40,7 +39,6 @@ export declare class AntigravityAdapter implements HookAdapter {
40
39
  checkPluginRegistration(): DiagnosticResult;
41
40
  getInstalledVersion(): string;
42
41
  configureAllHooks(_pluginRoot: string): string[];
43
- backupSettings(): string | null;
44
42
  setHookPermissions(_pluginRoot: string): string[];
45
43
  updatePluginRegistry(_pluginRoot: string, _version: string): void;
46
44
  getRoutingInstructions(): string;
@@ -16,15 +16,18 @@
16
16
  * - MCP support: https://antigravity.google/docs/mcp
17
17
  * - Tool list: System prompt leak (21 verified tools)
18
18
  */
19
- import { createHash } from "node:crypto";
20
- import { readFileSync, writeFileSync, mkdirSync, copyFileSync, accessSync, constants, } from "node:fs";
21
- import { resolve, join, dirname } from "node:path";
19
+ import { readFileSync, writeFileSync, mkdirSync, } from "node:fs";
20
+ import { resolve, dirname } from "node:path";
22
21
  import { fileURLToPath } from "node:url";
23
22
  import { homedir } from "node:os";
23
+ import { BaseAdapter } from "../base.js";
24
24
  // ─────────────────────────────────────────────────────────
25
25
  // Adapter implementation
26
26
  // ─────────────────────────────────────────────────────────
27
- export class AntigravityAdapter {
27
+ export class AntigravityAdapter extends BaseAdapter {
28
+ constructor() {
29
+ super([".gemini"]);
30
+ }
28
31
  name = "Antigravity";
29
32
  paradigm = "mcp-only";
30
33
  capabilities = {
@@ -69,25 +72,6 @@ export class AntigravityAdapter {
69
72
  getSettingsPath() {
70
73
  return resolve(homedir(), ".gemini", "antigravity", "mcp_config.json");
71
74
  }
72
- getSessionDir() {
73
- const dir = join(homedir(), ".gemini", "context-mode", "sessions");
74
- mkdirSync(dir, { recursive: true });
75
- return dir;
76
- }
77
- getSessionDBPath(projectDir) {
78
- const hash = createHash("sha256")
79
- .update(projectDir)
80
- .digest("hex")
81
- .slice(0, 16);
82
- return join(this.getSessionDir(), `${hash}.db`);
83
- }
84
- getSessionEventsPath(projectDir) {
85
- const hash = createHash("sha256")
86
- .update(projectDir)
87
- .digest("hex")
88
- .slice(0, 16);
89
- return join(this.getSessionDir(), `${hash}-events.md`);
90
- }
91
75
  generateHookConfig(_pluginRoot) {
92
76
  return {};
93
77
  }
@@ -157,18 +141,6 @@ export class AntigravityAdapter {
157
141
  configureAllHooks(_pluginRoot) {
158
142
  return [];
159
143
  }
160
- backupSettings() {
161
- const settingsPath = this.getSettingsPath();
162
- try {
163
- accessSync(settingsPath, constants.R_OK);
164
- const backupPath = settingsPath + ".bak";
165
- copyFileSync(settingsPath, backupPath);
166
- return backupPath;
167
- }
168
- catch {
169
- return null;
170
- }
171
- }
172
144
  setHookPermissions(_pluginRoot) {
173
145
  return [];
174
146
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * BaseAdapter — shared implementation for methods identical across all adapters.
3
+ *
4
+ * Eliminates ~288 lines of duplication across 12 adapters.
5
+ * Each concrete adapter extends this and provides platform-specific logic.
6
+ *
7
+ * Shared methods:
8
+ * - getSessionDir() — builds session dir from sessionDirSegments
9
+ * - getSessionDBPath() — SHA-256 hash of projectDir → .db file
10
+ * - getSessionEventsPath()— SHA-256 hash of projectDir → -events.md file
11
+ * - backupSettings() — copies settings file to .bak
12
+ *
13
+ * Adapters with custom logic override the relevant method:
14
+ * - vscode-copilot: overrides getSessionDir (checks .github dir)
15
+ * - opencode: overrides getSessionDir (XDG_CONFIG_HOME / APPDATA)
16
+ * and backupSettings (calls checkPluginRegistration first)
17
+ * - openclaw: overrides backupSettings (searches 3 config paths)
18
+ */
19
+ export declare abstract class BaseAdapter {
20
+ protected readonly sessionDirSegments: string[];
21
+ constructor(sessionDirSegments: string[]);
22
+ getSessionDir(): string;
23
+ getSessionDBPath(projectDir: string): string;
24
+ getSessionEventsPath(projectDir: string): string;
25
+ backupSettings(): string | null;
26
+ abstract getSettingsPath(): string;
27
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * BaseAdapter — shared implementation for methods identical across all adapters.
3
+ *
4
+ * Eliminates ~288 lines of duplication across 12 adapters.
5
+ * Each concrete adapter extends this and provides platform-specific logic.
6
+ *
7
+ * Shared methods:
8
+ * - getSessionDir() — builds session dir from sessionDirSegments
9
+ * - getSessionDBPath() — SHA-256 hash of projectDir → .db file
10
+ * - getSessionEventsPath()— SHA-256 hash of projectDir → -events.md file
11
+ * - backupSettings() — copies settings file to .bak
12
+ *
13
+ * Adapters with custom logic override the relevant method:
14
+ * - vscode-copilot: overrides getSessionDir (checks .github dir)
15
+ * - opencode: overrides getSessionDir (XDG_CONFIG_HOME / APPDATA)
16
+ * and backupSettings (calls checkPluginRegistration first)
17
+ * - openclaw: overrides backupSettings (searches 3 config paths)
18
+ */
19
+ import { createHash } from "node:crypto";
20
+ import { join } from "node:path";
21
+ import { accessSync, copyFileSync, constants, mkdirSync } from "node:fs";
22
+ import { homedir } from "node:os";
23
+ export class BaseAdapter {
24
+ sessionDirSegments;
25
+ constructor(sessionDirSegments) {
26
+ this.sessionDirSegments = sessionDirSegments;
27
+ }
28
+ getSessionDir() {
29
+ const dir = join(homedir(), ...this.sessionDirSegments, "context-mode", "sessions");
30
+ mkdirSync(dir, { recursive: true });
31
+ return dir;
32
+ }
33
+ getSessionDBPath(projectDir) {
34
+ const hash = createHash("sha256")
35
+ .update(projectDir)
36
+ .digest("hex")
37
+ .slice(0, 16);
38
+ return join(this.getSessionDir(), `${hash}.db`);
39
+ }
40
+ getSessionEventsPath(projectDir) {
41
+ const hash = createHash("sha256")
42
+ .update(projectDir)
43
+ .digest("hex")
44
+ .slice(0, 16);
45
+ return join(this.getSessionDir(), `${hash}-events.md`);
46
+ }
47
+ backupSettings() {
48
+ const settingsPath = this.getSettingsPath();
49
+ try {
50
+ accessSync(settingsPath, constants.R_OK);
51
+ const backupPath = settingsPath + ".bak";
52
+ copyFileSync(settingsPath, backupPath);
53
+ return backupPath;
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ }