context-mode 1.0.161 → 1.0.163

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 (153) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.openclaw-plugin/openclaw.plugin.json +1 -1
  5. package/.openclaw-plugin/package.json +1 -1
  6. package/README.md +142 -28
  7. package/bin/statusline.mjs +24 -4
  8. package/build/adapters/antigravity/index.d.ts +1 -1
  9. package/build/adapters/antigravity-cli/index.d.ts +51 -0
  10. package/build/adapters/antigravity-cli/index.js +341 -0
  11. package/build/adapters/claude-code/hooks.d.ts +1 -0
  12. package/build/adapters/claude-code/hooks.js +3 -0
  13. package/build/adapters/claude-code/index.js +24 -5
  14. package/build/adapters/client-map.js +5 -0
  15. package/build/adapters/codex/hooks.d.ts +5 -1
  16. package/build/adapters/codex/hooks.js +5 -1
  17. package/build/adapters/codex/index.d.ts +9 -1
  18. package/build/adapters/codex/index.js +87 -5
  19. package/build/adapters/copilot-cli/hooks.d.ts +33 -0
  20. package/build/adapters/copilot-cli/hooks.js +64 -0
  21. package/build/adapters/copilot-cli/index.d.ts +48 -0
  22. package/build/adapters/copilot-cli/index.js +341 -0
  23. package/build/adapters/detect.d.ts +1 -1
  24. package/build/adapters/detect.js +71 -3
  25. package/build/adapters/openclaw/mcp-tools.js +1 -1
  26. package/build/adapters/opencode/index.js +31 -17
  27. package/build/adapters/opencode/zod3tov4.js +27 -6
  28. package/build/adapters/pi/extension.d.ts +2 -12
  29. package/build/adapters/pi/extension.js +114 -96
  30. package/build/adapters/types.d.ts +5 -4
  31. package/build/adapters/types.js +4 -3
  32. package/build/cache-heal.d.ts +48 -0
  33. package/build/cache-heal.js +150 -0
  34. package/build/cli.js +37 -97
  35. package/build/executor.d.ts +25 -0
  36. package/build/executor.js +143 -22
  37. package/build/opencode-plugin.js +5 -2
  38. package/build/routing-block.d.ts +8 -0
  39. package/build/routing-block.js +86 -0
  40. package/build/runtime.d.ts +0 -36
  41. package/build/runtime.js +107 -27
  42. package/build/search/flood-guard.d.ts +57 -0
  43. package/build/search/flood-guard.js +80 -0
  44. package/build/security.d.ts +8 -3
  45. package/build/security.js +155 -29
  46. package/build/server.d.ts +14 -0
  47. package/build/server.js +368 -350
  48. package/build/session/analytics.d.ts +8 -8
  49. package/build/session/analytics.js +18 -13
  50. package/build/session/db.d.ts +1 -0
  51. package/build/session/db.js +37 -4
  52. package/build/session/extract.d.ts +46 -0
  53. package/build/session/extract.js +764 -13
  54. package/build/session/project-attribution.js +14 -0
  55. package/build/store.d.ts +1 -1
  56. package/build/store.js +139 -25
  57. package/build/tool-naming.d.ts +4 -0
  58. package/build/tool-naming.js +24 -0
  59. package/build/util/jsonc.d.ts +14 -0
  60. package/build/util/jsonc.js +104 -0
  61. package/cli.bundle.mjs +260 -254
  62. package/configs/antigravity/GEMINI.md +2 -2
  63. package/configs/antigravity-cli/hooks/hooks.json +37 -0
  64. package/configs/antigravity-cli/hooks.json +37 -0
  65. package/configs/antigravity-cli/mcp_config.json +10 -0
  66. package/configs/antigravity-cli/plugin.json +14 -0
  67. package/configs/antigravity-cli/rules/context-mode.md +77 -0
  68. package/configs/antigravity-cli/skills/context-mode/SKILL.md +77 -0
  69. package/configs/claude-code/CLAUDE.md +2 -2
  70. package/configs/codex/AGENTS.md +2 -2
  71. package/configs/copilot-cli/.github/plugin/plugin.json +23 -0
  72. package/configs/copilot-cli/.mcp.json +12 -0
  73. package/configs/copilot-cli/README.md +47 -0
  74. package/configs/copilot-cli/hooks.json +41 -0
  75. package/configs/copilot-cli/skills/context-mode/SKILL.md +38 -0
  76. package/configs/gemini-cli/GEMINI.md +2 -2
  77. package/configs/jetbrains-copilot/copilot-instructions.md +2 -2
  78. package/configs/kilo/AGENTS.md +2 -2
  79. package/configs/kiro/KIRO.md +2 -2
  80. package/configs/omp/SYSTEM.md +2 -2
  81. package/configs/openclaw/AGENTS.md +2 -2
  82. package/configs/opencode/AGENTS.md +2 -2
  83. package/configs/qwen-code/QWEN.md +2 -2
  84. package/configs/vscode-copilot/copilot-instructions.md +2 -2
  85. package/configs/zed/AGENTS.md +2 -2
  86. package/hooks/antigravity-cli/payload.mjs +98 -0
  87. package/hooks/antigravity-cli/posttooluse.mjs +138 -0
  88. package/hooks/antigravity-cli/pretooluse.mjs +78 -0
  89. package/hooks/antigravity-cli/stop.mjs +58 -0
  90. package/hooks/codex/pretooluse.mjs +14 -4
  91. package/hooks/codex/stop.mjs +12 -4
  92. package/hooks/copilot-cli/posttooluse.mjs +79 -0
  93. package/hooks/copilot-cli/precompact.mjs +66 -0
  94. package/hooks/copilot-cli/pretooluse.mjs +41 -0
  95. package/hooks/copilot-cli/sessionstart.mjs +121 -0
  96. package/hooks/copilot-cli/stop.mjs +59 -0
  97. package/hooks/copilot-cli/userpromptsubmit.mjs +77 -0
  98. package/hooks/core/codex-caps.mjs +112 -0
  99. package/hooks/core/formatters.mjs +158 -7
  100. package/hooks/core/mcp-ready.mjs +37 -8
  101. package/hooks/core/routing.mjs +94 -8
  102. package/hooks/core/tool-naming.mjs +3 -0
  103. package/hooks/hooks.json +12 -1
  104. package/hooks/pretooluse.mjs +6 -2
  105. package/hooks/routing-block.mjs +2 -2
  106. package/hooks/security.bundle.mjs +2 -1
  107. package/hooks/session-db.bundle.mjs +11 -7
  108. package/hooks/session-directive.mjs +88 -20
  109. package/hooks/session-extract.bundle.mjs +2 -2
  110. package/hooks/session-helpers.mjs +21 -0
  111. package/hooks/session-loaders.mjs +8 -5
  112. package/hooks/sessionstart.mjs +53 -7
  113. package/hooks/stop.mjs +49 -0
  114. package/hooks/userpromptsubmit.mjs +9 -2
  115. package/openclaw.plugin.json +1 -1
  116. package/package.json +4 -10
  117. package/scripts/install-antigravity-cli-plugin.mjs +141 -0
  118. package/server.bundle.mjs +214 -205
  119. package/skills/ctx-insight/SKILL.md +12 -17
  120. package/build/util/db-lock.d.ts +0 -65
  121. package/build/util/db-lock.js +0 -166
  122. package/insight/index.html +0 -13
  123. package/insight/package.json +0 -55
  124. package/insight/server.mjs +0 -1265
  125. package/insight/src/components/analytics.tsx +0 -112
  126. package/insight/src/components/ui/badge.tsx +0 -52
  127. package/insight/src/components/ui/button.tsx +0 -58
  128. package/insight/src/components/ui/card.tsx +0 -103
  129. package/insight/src/components/ui/chart.tsx +0 -371
  130. package/insight/src/components/ui/collapsible.tsx +0 -19
  131. package/insight/src/components/ui/input.tsx +0 -20
  132. package/insight/src/components/ui/progress.tsx +0 -83
  133. package/insight/src/components/ui/scroll-area.tsx +0 -55
  134. package/insight/src/components/ui/separator.tsx +0 -23
  135. package/insight/src/components/ui/table.tsx +0 -114
  136. package/insight/src/components/ui/tabs.tsx +0 -82
  137. package/insight/src/components/ui/tooltip.tsx +0 -64
  138. package/insight/src/lib/api.ts +0 -144
  139. package/insight/src/lib/utils.ts +0 -6
  140. package/insight/src/main.tsx +0 -22
  141. package/insight/src/routeTree.gen.ts +0 -189
  142. package/insight/src/router.tsx +0 -19
  143. package/insight/src/routes/__root.tsx +0 -55
  144. package/insight/src/routes/enterprise.tsx +0 -316
  145. package/insight/src/routes/index.tsx +0 -1482
  146. package/insight/src/routes/knowledge.tsx +0 -221
  147. package/insight/src/routes/knowledge_.$dbHash.$sourceId.tsx +0 -137
  148. package/insight/src/routes/search.tsx +0 -97
  149. package/insight/src/routes/sessions.tsx +0 -179
  150. package/insight/src/routes/sessions_.$dbHash.$sessionId.tsx +0 -181
  151. package/insight/src/styles.css +0 -104
  152. package/insight/tsconfig.json +0 -29
  153. package/insight/vite.config.ts +0 -19
@@ -0,0 +1,341 @@
1
+ /**
2
+ * adapters/antigravity-cli — Google Antigravity CLI (`agy`) adapter.
3
+ *
4
+ * Integration: MCP tools plus agy's Claude-compatible hook surface. `agy`
5
+ * reads its global MCP profile from `~/.gemini/config/mcp_config.json`
6
+ * (distinct from the Antigravity IDE's `~/.gemini/antigravity/mcp_config.json`)
7
+ * and hooks from `~/.gemini/config/hooks.json`, or from an installed agy
8
+ * plugin's root `hooks.json`.
9
+ *
10
+ * context-mode wires only the surfaces that have a verified mapping:
11
+ * - PreToolUse for bounded routing enforcement on Bash/Read/Grep/WebFetch
12
+ * - PostToolUse capture for executed tool calls
13
+ * - best-effort Stop capture for session-end continuity when agy emits it
14
+ *
15
+ * PreInvocation/PostInvocation are intentionally not registered here: there is
16
+ * no verified payload/response contract or shared context-mode pipeline target
17
+ * for those agy events yet.
18
+ */
19
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
20
+ import { dirname, resolve } from "node:path";
21
+ import { homedir } from "node:os";
22
+ import { AntigravityAdapter } from "../antigravity/index.js";
23
+ import { parseJsonc } from "../../util/jsonc.js";
24
+ export function antigravityCliMcpConfigPath() {
25
+ return resolve(homedir(), ".gemini", "config", "mcp_config.json");
26
+ }
27
+ export function antigravityCliConfigDir() {
28
+ return resolve(homedir(), ".gemini", "antigravity-cli");
29
+ }
30
+ /** agy reads user hooks from ~/.gemini/config/hooks.json (sibling of mcp_config.json). */
31
+ export function antigravityCliHooksPath() {
32
+ return resolve(homedir(), ".gemini", "config", "hooks.json");
33
+ }
34
+ /**
35
+ * `agy plugin install <bundle>` registers MCP + hook + skill into agy's plugin
36
+ * profile under ~/.gemini/config/plugins/<name>/ (verified on agy 1.0.6) — the
37
+ * canonical install. The global mcp_config.json / hooks.json paths above are the
38
+ * manual (no-plugin) fallback. doctor must recognize BOTH.
39
+ */
40
+ export function antigravityCliPluginDir() {
41
+ return resolve(homedir(), ".gemini", "config", "plugins", "context-mode");
42
+ }
43
+ function antigravityCliPluginMcpPath() {
44
+ return resolve(antigravityCliPluginDir(), "mcp_config.json");
45
+ }
46
+ function antigravityCliPluginHooksPath() {
47
+ return resolve(antigravityCliPluginDir(), "hooks.json");
48
+ }
49
+ /** True if context-mode's MCP is registered in any agy profile (plugin or global). */
50
+ function readMcpRegistered(paths) {
51
+ for (const path of paths) {
52
+ try {
53
+ const config = parseJsonc(readFileSync(path, "utf-8")) ?? {};
54
+ const mcpServers = config?.mcpServers ?? {};
55
+ if ("context-mode" in mcpServers)
56
+ return { ok: true, where: path };
57
+ }
58
+ catch {
59
+ /* unreadable/missing — try next */
60
+ }
61
+ }
62
+ return { ok: false };
63
+ }
64
+ function asRecord(value) {
65
+ return value && typeof value === "object" ? value : {};
66
+ }
67
+ function agyProjectDir(raw) {
68
+ // Refs-backed FIRST: the only real upstream hook-payload example
69
+ // (refs/platforms/antigravity-cli/examples/title/title.sh:10, README.md:11)
70
+ // reads the working directory from `workspace.current_dir` — an OBJECT field,
71
+ // not an array. Prefer it.
72
+ const workspace = asRecord(raw.workspace);
73
+ if (typeof workspace.current_dir === "string" && workspace.current_dir) {
74
+ return workspace.current_dir;
75
+ }
76
+ // Fallback: `workspacePaths[0]` is empirically-derived/unverified (no upstream
77
+ // doc or example confirms this shape) — retained as a defensive fallback only.
78
+ const workspacePaths = raw.workspacePaths;
79
+ return Array.isArray(workspacePaths) && workspacePaths.length > 0
80
+ ? String(workspacePaths[0])
81
+ : undefined;
82
+ }
83
+ function agySessionId(raw) {
84
+ // `conversationId` is empirically-derived/unverified — no upstream agy doc or
85
+ // example confirms a session-id field in the hook payload. Kept as the
86
+ // best-available identifier; falls back to the process id when absent.
87
+ return typeof raw.conversationId === "string" && raw.conversationId
88
+ ? raw.conversationId
89
+ : `pid-${process.ppid}`;
90
+ }
91
+ function hookEntryHasCommand(entry, command) {
92
+ const e = asRecord(entry);
93
+ const nested = Array.isArray(e.hooks) ? e.hooks : [];
94
+ return nested.some((hook) => asRecord(hook).command === command);
95
+ }
96
+ function hookEntryJsonHasCommand(entry, command) {
97
+ return JSON.stringify(entry).includes(command);
98
+ }
99
+ function matcherCoversAgyPreToolUse(matcher) {
100
+ if (typeof matcher !== "string")
101
+ return false;
102
+ return ["run_command", "view_file", "grep_search", "web_fetch", "read_url_content"].every((tool) => matcher.includes(tool));
103
+ }
104
+ function hookGroupHasCommand(group, command) {
105
+ return Array.isArray(group) && group.some((entry) => hookEntryHasCommand(entry, command));
106
+ }
107
+ function hookGroupHasPreToolUse(group) {
108
+ return Array.isArray(group) && group.some((entry) => {
109
+ const e = asRecord(entry);
110
+ return matcherCoversAgyPreToolUse(e.matcher) && hookEntryHasCommand(entry, PRE_HOOK_COMMAND);
111
+ });
112
+ }
113
+ /** True if all context-mode agy hooks are registered in plugin/global profiles. */
114
+ function readRegisteredHooks(paths) {
115
+ const found = { preOk: false, postOk: false, stopOk: false, where: undefined };
116
+ for (const path of paths) {
117
+ try {
118
+ const config = parseJsonc(readFileSync(path, "utf-8")) ?? {};
119
+ const hooks = config.hooks ?? {};
120
+ const preOk = hookGroupHasPreToolUse(hooks.PreToolUse);
121
+ const postOk = hookGroupHasCommand(hooks.PostToolUse, POST_HOOK_COMMAND);
122
+ const stopOk = hookGroupHasCommand(hooks.Stop, STOP_HOOK_COMMAND);
123
+ if ((preOk || postOk || stopOk) && !found.where)
124
+ found.where = path;
125
+ found.preOk ||= preOk;
126
+ found.postOk ||= postOk;
127
+ found.stopOk ||= stopOk;
128
+ }
129
+ catch {
130
+ /* unreadable/missing — try next */
131
+ }
132
+ }
133
+ // Stop is registered when possible, but agy 1.0.6 `-p` probes did not emit it.
134
+ // Treat it as best-effort so doctor does not mark a working Pre/Post install
135
+ // as degraded solely because Stop is absent.
136
+ return { ...found, ok: found.preOk && found.postOk };
137
+ }
138
+ /** Dispatcher commands agy invokes from hooks.json. */
139
+ const PRE_HOOK_COMMAND = "context-mode hook antigravity-cli pretooluse";
140
+ const PRE_HOOK_MATCHER = "run_command|view_file|grep_search|web_fetch|read_url_content";
141
+ const POST_HOOK_COMMAND = "context-mode hook antigravity-cli posttooluse";
142
+ const STOP_HOOK_COMMAND = "context-mode hook antigravity-cli stop";
143
+ // Keep in sync with the identical agyContextReason in hooks/core/formatters.mjs:
144
+ // two copies exist because the bundled .mjs formatter (runtime hook path) and
145
+ // this TS adapter are separate layers; the deny-reason text must not drift.
146
+ function agyContextReason(additionalContext) {
147
+ const text = String(additionalContext ?? "")
148
+ .replace(/<\/?context_guidance>/g, " ")
149
+ .replace(/<\/?tip>/g, " ")
150
+ .replace(/\s+/g, " ")
151
+ .trim();
152
+ return text
153
+ ? `context-mode: use the context-mode MCP tools instead of this native tool. ${text}`
154
+ : "context-mode: use the context-mode MCP tools instead of this native tool so raw bytes stay out of the conversation.";
155
+ }
156
+ function configureHookEntry(hooks, type, desired, command) {
157
+ const current = Array.isArray(hooks[type]) ? hooks[type] : [];
158
+ const desiredJson = JSON.stringify(desired);
159
+ const alreadyExact = current.some((entry) => JSON.stringify(entry) === desiredJson) &&
160
+ current.every((entry) => !hookEntryJsonHasCommand(entry, command) || JSON.stringify(entry) === desiredJson);
161
+ if (alreadyExact)
162
+ return false;
163
+ hooks[type] = [
164
+ ...current.filter((entry) => !hookEntryJsonHasCommand(entry, command)),
165
+ desired,
166
+ ];
167
+ return true;
168
+ }
169
+ export class AntigravityCliAdapter extends AntigravityAdapter {
170
+ name = "Antigravity CLI";
171
+ paradigm = "json-stdio";
172
+ capabilities = {
173
+ preToolUse: true,
174
+ postToolUse: true,
175
+ preCompact: false,
176
+ sessionStart: false,
177
+ canModifyArgs: false,
178
+ canModifyOutput: false,
179
+ canInjectSessionContext: false,
180
+ };
181
+ getSettingsPath() {
182
+ return antigravityCliMcpConfigPath();
183
+ }
184
+ getConfigDir(_projectDir) {
185
+ return antigravityCliConfigDir();
186
+ }
187
+ parsePreToolUseInput(raw) {
188
+ const payload = asRecord(raw);
189
+ const toolCall = asRecord(payload.toolCall);
190
+ return {
191
+ toolName: typeof toolCall.name === "string" ? toolCall.name : "",
192
+ toolInput: asRecord(toolCall.args),
193
+ sessionId: agySessionId(payload),
194
+ projectDir: agyProjectDir(payload),
195
+ raw,
196
+ };
197
+ }
198
+ parsePostToolUseInput(raw) {
199
+ const payload = asRecord(raw);
200
+ const toolCall = asRecord(payload.toolCall);
201
+ const error = typeof payload.error === "string" ? payload.error : "";
202
+ return {
203
+ toolName: typeof toolCall.name === "string" ? toolCall.name : "",
204
+ toolInput: asRecord(toolCall.args),
205
+ toolOutput: error,
206
+ isError: error.length > 0,
207
+ sessionId: agySessionId(payload),
208
+ projectDir: agyProjectDir(payload),
209
+ raw,
210
+ };
211
+ }
212
+ formatPreToolUseResponse(response) {
213
+ if (response.decision === "deny") {
214
+ return { decision: "deny", reason: response.reason ?? "Denied by context-mode" };
215
+ }
216
+ if (response.decision === "ask") {
217
+ // Fallback reason so a security-policy ask is never a bare prompt
218
+ // (mirrors hooks/core/formatters.mjs antigravity-cli.ask).
219
+ return {
220
+ decision: "ask",
221
+ reason: response.reason ?? "Action requires user confirmation",
222
+ };
223
+ }
224
+ if (response.decision === "context" && response.additionalContext) {
225
+ return {
226
+ decision: "deny",
227
+ reason: agyContextReason(response.additionalContext),
228
+ };
229
+ }
230
+ return null;
231
+ }
232
+ formatPostToolUseResponse(_response) {
233
+ return undefined;
234
+ }
235
+ checkPluginRegistration() {
236
+ // Accept the plugin profile (the canonical `agy plugin install` location,
237
+ // ~/.gemini/config/plugins/context-mode/mcp_config.json) OR the global
238
+ // mcp_config.json (the manual no-plugin fallback).
239
+ const { ok, where } = readMcpRegistered([
240
+ antigravityCliPluginMcpPath(),
241
+ this.getSettingsPath(),
242
+ ]);
243
+ if (ok) {
244
+ return {
245
+ check: "MCP registration",
246
+ status: "pass",
247
+ message: `context-mode found in Antigravity CLI mcpServers (${where})`,
248
+ };
249
+ }
250
+ return {
251
+ check: "MCP registration",
252
+ status: "fail",
253
+ message: "context-mode not found in Antigravity CLI mcpServers",
254
+ fix: "npm run install:agy",
255
+ };
256
+ }
257
+ getInstalledVersion() {
258
+ // Plugin install: read the real version from the installed plugin manifest so
259
+ // the doctor compares a true semver against npm latest (PASS when current,
260
+ // a meaningful "outdated bundle" WARN otherwise) — not the literal "configured"
261
+ // which produced the bogus "vconfigured, latest vX" line.
262
+ try {
263
+ const manifest = parseJsonc(readFileSync(resolve(antigravityCliPluginDir(), "plugin.json"), "utf-8"));
264
+ if (manifest && typeof manifest.version === "string" && manifest.version) {
265
+ return manifest.version;
266
+ }
267
+ }
268
+ catch {
269
+ /* not plugin-installed — fall through */
270
+ }
271
+ // Manual (global-profile) registration has no plugin manifest: report the
272
+ // version-less "standalone" MCP mode so doctor shows INFO, not a false WARN.
273
+ if (readMcpRegistered([this.getSettingsPath()]).ok)
274
+ return "standalone";
275
+ return "not installed";
276
+ }
277
+ /**
278
+ * Write/merge the agy hooks into ~/.gemini/config/hooks.json (manual,
279
+ * non-plugin path). Idempotent — unrelated hook entries are preserved.
280
+ */
281
+ configureAllHooks(_pluginRoot) {
282
+ const changes = [];
283
+ const hooksPath = antigravityCliHooksPath();
284
+ let config = {};
285
+ try {
286
+ config = parseJsonc(readFileSync(hooksPath, "utf-8")) ?? {};
287
+ }
288
+ catch {
289
+ /* fresh file */
290
+ }
291
+ const hooks = config.hooks ?? {};
292
+ const desiredPre = {
293
+ matcher: PRE_HOOK_MATCHER,
294
+ hooks: [{ type: "command", command: PRE_HOOK_COMMAND }],
295
+ };
296
+ const desiredPost = {
297
+ matcher: "",
298
+ hooks: [{ type: "command", command: POST_HOOK_COMMAND }],
299
+ };
300
+ const desiredStop = {
301
+ matcher: "",
302
+ hooks: [{ type: "command", command: STOP_HOOK_COMMAND }],
303
+ };
304
+ const changedPre = configureHookEntry(hooks, "PreToolUse", desiredPre, PRE_HOOK_COMMAND);
305
+ const changedPost = configureHookEntry(hooks, "PostToolUse", desiredPost, POST_HOOK_COMMAND);
306
+ const changedStop = configureHookEntry(hooks, "Stop", desiredStop, STOP_HOOK_COMMAND);
307
+ const changed = changedPre || changedPost || changedStop;
308
+ if (changed) {
309
+ config.hooks = hooks;
310
+ mkdirSync(dirname(hooksPath), { recursive: true });
311
+ writeFileSync(hooksPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
312
+ changes.push(`Configured Antigravity CLI PreToolUse/PostToolUse hooks and best-effort Stop hook in ${hooksPath}`);
313
+ }
314
+ return changes;
315
+ }
316
+ /** Report agy hook status across plugin and manual profiles. */
317
+ validateHooks(_pluginRoot) {
318
+ // Accept the plugin profile (the canonical `agy plugin install` location,
319
+ // ~/.gemini/config/plugins/context-mode/hooks.json) OR the global hooks.json
320
+ // (the manual `context-mode upgrade` fallback).
321
+ const { ok, where, preOk, postOk, stopOk } = readRegisteredHooks([
322
+ antigravityCliPluginHooksPath(),
323
+ antigravityCliHooksPath(),
324
+ ]);
325
+ const missing = [
326
+ preOk ? null : "PreToolUse",
327
+ postOk ? null : "PostToolUse",
328
+ // Stop is best-effort; do not include it in the health gate.
329
+ ].filter(Boolean).join(", ");
330
+ return [
331
+ {
332
+ check: "Antigravity CLI hooks",
333
+ status: ok ? "pass" : "warn",
334
+ message: ok
335
+ ? `PreToolUse guard and PostToolUse capture configured in ${where}${stopOk ? "; best-effort Stop hook also configured" : ""}`
336
+ : `Antigravity CLI hooks incomplete (${missing || "none found"} missing) — MCP tools still work, but bounded routing enforcement and session capture are degraded. Run \`npm run install:agy\` (agy plugin) or \`context-mode upgrade\` to repair hooks.`,
337
+ ...(ok ? {} : { fix: "npm run install:agy" }),
338
+ },
339
+ ];
340
+ }
341
+ }
@@ -22,6 +22,7 @@ export declare const HOOK_TYPES: {
22
22
  readonly PRE_COMPACT: "PreCompact";
23
23
  readonly SESSION_START: "SessionStart";
24
24
  readonly USER_PROMPT_SUBMIT: "UserPromptSubmit";
25
+ readonly STOP: "Stop";
25
26
  };
26
27
  export type HookType = (typeof HOOK_TYPES)[keyof typeof HOOK_TYPES];
27
28
  /**
@@ -26,6 +26,7 @@ export const HOOK_TYPES = {
26
26
  PRE_COMPACT: "PreCompact",
27
27
  SESSION_START: "SessionStart",
28
28
  USER_PROMPT_SUBMIT: "UserPromptSubmit",
29
+ STOP: "Stop",
29
30
  };
30
31
  // ─────────────────────────────────────────────────────────
31
32
  // PreToolUse matchers
@@ -102,6 +103,7 @@ export const HOOK_SCRIPTS = {
102
103
  PreCompact: "precompact.mjs",
103
104
  SessionStart: "sessionstart.mjs",
104
105
  UserPromptSubmit: "userpromptsubmit.mjs",
106
+ Stop: "stop.mjs",
105
107
  };
106
108
  // ─────────────────────────────────────────────────────────
107
109
  // Hook validation
@@ -116,6 +118,7 @@ export const OPTIONAL_HOOKS = [
116
118
  HOOK_TYPES.POST_TOOL_USE,
117
119
  HOOK_TYPES.PRE_COMPACT,
118
120
  HOOK_TYPES.USER_PROMPT_SUBMIT,
121
+ HOOK_TYPES.STOP,
119
122
  ];
120
123
  /**
121
124
  * Check if a hook entry points to a context-mode hook script.
@@ -87,7 +87,7 @@ export class ClaudeCodeAdapter extends ClaudeCodeBaseAdapter {
87
87
  // available, else `process.execPath` (#369 PATH resolution on Git
88
88
  // Bash, #738 bun cold-start win).
89
89
  // Pre-D3 we hand-rolled `node "${pluginRoot}/hooks/X.mjs"` for all
90
- // five events; bare `node` made claude-code the lone outlier and
90
+ // six events; bare `node` made claude-code the lone outlier and
91
91
  // dropping the execPath swap re-opened the Windows class. Algo-D3.5
92
92
  // (CI invariant in tests/adapters/claude-code.test.ts) locks this in
93
93
  // for adapter #16.
@@ -142,6 +142,17 @@ export class ClaudeCodeAdapter extends ClaudeCodeBaseAdapter {
142
142
  ],
143
143
  },
144
144
  ],
145
+ Stop: [
146
+ {
147
+ matcher: "",
148
+ hooks: [
149
+ {
150
+ type: "command",
151
+ command: buildHookRuntimeCommand(`${pluginRoot}/hooks/stop.mjs`),
152
+ },
153
+ ],
154
+ },
155
+ ],
145
156
  };
146
157
  }
147
158
  readSettings() {
@@ -396,10 +407,18 @@ export class ClaudeCodeAdapter extends ClaudeCodeBaseAdapter {
396
407
  changes.push(`Removed ${removed} stale ${hookType} hook(s)`);
397
408
  }
398
409
  }
399
- // If plugin hooks.json already covers all required hooks, skip settings.json
400
- // registration entirely (Issue #198). Plugin installs don't need settings.json
401
- // entries — hooks.json with ${CLAUDE_PLUGIN_ROOT} is the source of truth.
402
- const pluginHooks = this.readPluginHooks(pluginRoot);
410
+ // If plugin hooks.json already covers all required hooks AND context-mode is
411
+ // actually installed as a Claude Code plugin (present in enabledPlugins), skip
412
+ // settings.json registration — hooks.json with ${CLAUDE_PLUGIN_ROOT} is the
413
+ // source of truth for plugin installs (Issue #198).
414
+ //
415
+ // Standalone / MacPorts installs are NOT in enabledPlugins. For those, the
416
+ // hooks/hooks.json shipped in the npm package is never consulted by Claude Code
417
+ // (it uses ${CLAUDE_PLUGIN_ROOT} which is only set in plugin mode). We must
418
+ // always write absolute-path hook commands to settings.json in that case.
419
+ const pluginRegistration = this.checkPluginRegistration();
420
+ const isPluginInstall = pluginRegistration.status === "pass";
421
+ const pluginHooks = isPluginInstall ? this.readPluginHooks(pluginRoot) : undefined;
403
422
  if (pluginHooks) {
404
423
  const allCovered = REQUIRED_HOOKS.every((ht) => this.checkHookType(undefined, pluginHooks, ht));
405
424
  if (allCovered) {
@@ -10,8 +10,13 @@ export const CLIENT_NAME_TO_PLATFORM = {
10
10
  "claude-code": "claude-code",
11
11
  "gemini-cli-mcp-client": "gemini-cli",
12
12
  "antigravity-client": "antigravity",
13
+ "antigravity-cli": "antigravity-cli",
14
+ "agy": "antigravity-cli",
13
15
  "cursor-vscode": "cursor",
14
16
  "Visual-Studio-Code": "vscode-copilot",
17
+ "copilot-cli": "copilot-cli",
18
+ "GitHub Copilot CLI": "copilot-cli",
19
+ "github-copilot-cli": "copilot-cli",
15
20
  "JetBrains Client": "jetbrains-copilot",
16
21
  "IntelliJ IDEA": "jetbrains-copilot",
17
22
  "PyCharm": "jetbrains-copilot",
@@ -13,7 +13,11 @@
13
13
  * MCP: full support via [mcp_servers] in $CODEX_HOME/config.toml.
14
14
  *
15
15
  * Known limitations:
16
- * - PreToolUse: deny works, updatedInput not yet supported (openai/codex#18491)
16
+ * - PreToolUse: deny works on all builds. permissionDecision:"allow" +
17
+ * updatedInput (command rewrite) and additionalContext are honored on
18
+ * codex-cli >= 0.141.0 (#845), detected at runtime by
19
+ * hooks/core/codex-caps.mjs; older builds fail closed (redirect → deny).
20
+ * `ask` remains unsupported.
17
21
  * - PostToolUse: updatedMCPToolOutput parsed but logged as unsupported
18
22
  * - PostToolUse does not fire on failing Bash calls (upstream bug)
19
23
  */
@@ -13,7 +13,11 @@
13
13
  * MCP: full support via [mcp_servers] in $CODEX_HOME/config.toml.
14
14
  *
15
15
  * Known limitations:
16
- * - PreToolUse: deny works, updatedInput not yet supported (openai/codex#18491)
16
+ * - PreToolUse: deny works on all builds. permissionDecision:"allow" +
17
+ * updatedInput (command rewrite) and additionalContext are honored on
18
+ * codex-cli >= 0.141.0 (#845), detected at runtime by
19
+ * hooks/core/codex-caps.mjs; older builds fail closed (redirect → deny).
20
+ * `ask` remains unsupported.
17
21
  * - PostToolUse: updatedMCPToolOutput parsed but logged as unsupported
18
22
  * - PostToolUse does not fire on failing Bash calls (upstream bug)
19
23
  */
@@ -20,9 +20,14 @@ type CodexVersionRunner = (file: string, args: string[], options: {
20
20
  stdio: ["ignore", "pipe", "ignore"];
21
21
  timeout: number;
22
22
  }) => string | Buffer;
23
+ interface CodexAdapterOptions {
24
+ codexPluginListRunner?: CodexVersionRunner;
25
+ }
23
26
  export declare function probeCodexCliVersion(runCommand?: CodexVersionRunner): string | null;
27
+ export declare function parseCodexContextModePluginRoot(raw: string): string | null;
24
28
  export declare class CodexAdapter extends BaseAdapter implements HookAdapter {
25
- constructor();
29
+ private readonly codexPluginListRunner;
30
+ constructor(options?: CodexAdapterOptions);
26
31
  readonly name = "Codex CLI";
27
32
  readonly paradigm: HookParadigm;
28
33
  readonly capabilities: PlatformCapabilities;
@@ -65,6 +70,9 @@ export declare class CodexAdapter extends BaseAdapter implements HookAdapter {
65
70
  private upsertManagedHookEntry;
66
71
  private removeManagedHookEntries;
67
72
  private hasCodexPluginHookManifest;
73
+ private getCodexPluginHookStatus;
74
+ private probeCodexContextModePluginRoot;
75
+ private samePath;
68
76
  private pruneStaleUserHookTrustState;
69
77
  private isExpectedHookEntry;
70
78
  private isManagedContextModeEntry;
@@ -75,6 +75,14 @@ export function probeCodexCliVersion(runCommand = execFileSync) {
75
75
  return null;
76
76
  }
77
77
  }
78
+ export function parseCodexContextModePluginRoot(raw) {
79
+ for (const line of raw.split(/\r?\n/)) {
80
+ const match = line.match(/^\s*context-mode@context-mode\s+installed,\s+enabled\s+\S+\s+(.+?)\s*$/);
81
+ if (match?.[1])
82
+ return match[1].trim();
83
+ }
84
+ return null;
85
+ }
78
86
  function getTomlSection(raw, sectionName) {
79
87
  const lines = raw.split(/\r?\n/);
80
88
  let inSection = false;
@@ -190,8 +198,10 @@ function parseTomlQuotedString(raw) {
190
198
  // Adapter implementation
191
199
  // ─────────────────────────────────────────────────────────
192
200
  export class CodexAdapter extends BaseAdapter {
193
- constructor() {
201
+ codexPluginListRunner;
202
+ constructor(options = {}) {
194
203
  super([".codex"]);
204
+ this.codexPluginListRunner = options.codexPluginListRunner ?? execFileSync;
195
205
  }
196
206
  name = "Codex CLI";
197
207
  paradigm = "json-stdio";
@@ -479,13 +489,35 @@ export class CodexAdapter extends BaseAdapter {
479
489
  });
480
490
  }
481
491
  const expected = this.generateHookConfig("");
482
- const codexPluginEnabled = settingsReadable && hasCodexPluginEnabled(settingsRaw);
483
- const codexPluginHooksAvailable = codexPluginEnabled && this.hasCodexPluginHookManifest(pluginRoot);
492
+ const pluginHookStatus = this.getCodexPluginHookStatus(pluginRoot, settingsRaw, settingsReadable);
493
+ const codexPluginEnabled = pluginHookStatus.enabled;
494
+ const codexPluginHooksAvailable = pluginHookStatus.hooksAvailable;
495
+ if (codexPluginEnabled && pluginHookStatus.runtimeRoot) {
496
+ results.push({
497
+ check: "Codex plugin root",
498
+ status: pluginHookStatus.rootMismatch ? "warn" : "pass",
499
+ message: pluginHookStatus.rootMismatch
500
+ ? `context-mode doctor is running from ${pluginHookStatus.configuredRoot}, but Codex plugin manager reports ${pluginHookStatus.runtimeRoot}`
501
+ : `Codex plugin manager reports ${pluginHookStatus.runtimeRoot}`,
502
+ ...(pluginHookStatus.rootMismatch
503
+ ? { fix: "Restart Codex after upgrade; run context-mode upgrade to keep native user-hook fallback until the plugin root converges" }
504
+ : {}),
505
+ });
506
+ }
507
+ else if (codexPluginEnabled) {
508
+ results.push({
509
+ check: "Codex plugin root",
510
+ status: "warn",
511
+ message: "context-mode@context-mode is enabled, but `codex plugin list` did not report its runtime root",
512
+ fix: "Restart Codex or verify `codex plugin list` shows context-mode@context-mode installed and enabled",
513
+ });
514
+ }
484
515
  if (codexPluginEnabled && !codexPluginHooksAvailable) {
516
+ const expectedRoot = pluginHookStatus.runtimeRoot ?? pluginRoot;
485
517
  results.push({
486
518
  check: "Codex plugin hooks",
487
519
  status: "fail",
488
- message: `context-mode Codex plugin is enabled, but ${join(pluginRoot, ".codex-plugin", "hooks.json")} is missing`,
520
+ message: `context-mode Codex plugin is enabled, but ${join(expectedRoot, ".codex-plugin", "hooks.json")} is missing`,
489
521
  fix: "Reinstall or upgrade the context-mode Codex plugin",
490
522
  });
491
523
  }
@@ -659,7 +691,8 @@ export class CodexAdapter extends BaseAdapter {
659
691
  catch {
660
692
  settingsRaw = "";
661
693
  }
662
- const codexPluginOwnsHooks = hasCodexPluginEnabled(settingsRaw) && this.hasCodexPluginHookManifest(pluginRoot);
694
+ const pluginHookStatus = this.getCodexPluginHookStatus(pluginRoot, settingsRaw, settingsRaw.length > 0);
695
+ const codexPluginOwnsHooks = pluginHookStatus.ownsHooksForUpgrade;
663
696
  let hookFile;
664
697
  if (hookConfig.ok) {
665
698
  hookFile = hookConfig.config;
@@ -839,6 +872,55 @@ export class CodexAdapter extends BaseAdapter {
839
872
  hasCodexPluginHookManifest(pluginRoot) {
840
873
  return existsSync(join(pluginRoot, ".codex-plugin", "hooks.json"));
841
874
  }
875
+ getCodexPluginHookStatus(pluginRoot, settingsRaw, settingsReadable) {
876
+ const enabled = settingsReadable && hasCodexPluginEnabled(settingsRaw);
877
+ const configuredRoot = resolve(pluginRoot);
878
+ const configuredManifestAvailable = this.hasCodexPluginHookManifest(configuredRoot);
879
+ const runtimeRoot = enabled ? this.probeCodexContextModePluginRoot() : null;
880
+ const runtimeManifestAvailable = runtimeRoot
881
+ ? this.hasCodexPluginHookManifest(runtimeRoot)
882
+ : false;
883
+ const rootMismatch = runtimeRoot
884
+ ? !this.samePath(configuredRoot, runtimeRoot)
885
+ : false;
886
+ const hooksAvailable = enabled && (runtimeManifestAvailable
887
+ || (!runtimeRoot && configuredManifestAvailable));
888
+ return {
889
+ enabled,
890
+ configuredRoot,
891
+ configuredManifestAvailable,
892
+ runtimeRoot,
893
+ runtimeManifestAvailable,
894
+ rootMismatch,
895
+ hooksAvailable,
896
+ ownsHooksForUpgrade: enabled
897
+ && runtimeRoot !== null
898
+ && runtimeManifestAvailable
899
+ && !rootMismatch,
900
+ };
901
+ }
902
+ probeCodexContextModePluginRoot() {
903
+ try {
904
+ const output = process.platform === "win32"
905
+ ? this.codexPluginListRunner("cmd.exe", ["/d", "/s", "/c", "codex plugin list"], {
906
+ encoding: "utf-8",
907
+ stdio: ["ignore", "pipe", "ignore"],
908
+ timeout: 5000,
909
+ })
910
+ : this.codexPluginListRunner("codex", ["plugin", "list"], {
911
+ encoding: "utf-8",
912
+ stdio: ["ignore", "pipe", "ignore"],
913
+ timeout: 5000,
914
+ });
915
+ return parseCodexContextModePluginRoot(String(output));
916
+ }
917
+ catch {
918
+ return null;
919
+ }
920
+ }
921
+ samePath(left, right) {
922
+ return this.normalizeCommand(resolve(left)) === this.normalizeCommand(resolve(right));
923
+ }
842
924
  pruneStaleUserHookTrustState(settingsRaw, hooks) {
843
925
  const hooksPath = this.normalizeCommand(this.getHooksPath());
844
926
  const eventNames = {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * adapters/copilot-cli/hooks — GitHub Copilot CLI hook definitions.
3
+ *
4
+ * GitHub Copilot CLI's native hook events are the camelCase names
5
+ * preToolUse / postToolUse / sessionStart / userPromptSubmitted / agentStop /
6
+ * preCompact. Per the copilot-cli changelog, PascalCase event names are ALSO
7
+ * accepted and fire — the CLI loads hook configs across VS Code, Claude Code,
8
+ * and the CLI by accepting PascalCase event names alongside camelCase
9
+ * (copilot-cli changelog.md:1065; see also :811 and :1081). We register the
10
+ * camelCase KEYS below because they are the CLI's native names, not because
11
+ * PascalCase would fail. The CLI dispatch token (the `.mjs` script base, e.g.
12
+ * `pretooluse`) is independent and stays lowercase via buildHookCommand, so
13
+ * changing the event casing does not change the dispatcher.
14
+ */
15
+ export declare const HOOK_TYPES: {
16
+ readonly PRE_TOOL_USE: "preToolUse";
17
+ readonly POST_TOOL_USE: "postToolUse";
18
+ readonly PRE_COMPACT: "preCompact";
19
+ readonly SESSION_START: "sessionStart";
20
+ readonly USER_PROMPT_SUBMIT: "userPromptSubmitted";
21
+ readonly STOP: "agentStop";
22
+ };
23
+ export type HookType = (typeof HOOK_TYPES)[keyof typeof HOOK_TYPES];
24
+ export declare const HOOK_SCRIPTS: Record<string, string>;
25
+ export declare const REQUIRED_HOOKS: HookType[];
26
+ export declare const OPTIONAL_HOOKS: HookType[];
27
+ export declare function isContextModeHook(entry: {
28
+ command?: string;
29
+ hooks?: Array<{
30
+ command?: string;
31
+ }>;
32
+ }, hookType: HookType): boolean;
33
+ export declare function buildHookCommand(hookType: HookType, _pluginRoot?: string): string;