context-mode 1.0.88 → 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 (132) 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 +27 -141
  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 +113 -47
  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/pi-extension.js +24 -7
  54. package/build/runtime.js +24 -9
  55. package/build/security.d.ts +17 -1
  56. package/build/security.js +40 -6
  57. package/build/server.js +129 -21
  58. package/build/session/analytics.d.ts +8 -7
  59. package/build/session/analytics.js +95 -75
  60. package/build/session/db.d.ts +10 -1
  61. package/build/session/db.js +67 -8
  62. package/build/session/extract.js +10 -2
  63. package/build/session/project-attribution.d.ts +73 -0
  64. package/build/session/project-attribution.js +231 -0
  65. package/build/store.d.ts +7 -0
  66. package/build/store.js +117 -18
  67. package/build/truncate.d.ts +6 -0
  68. package/build/truncate.js +51 -29
  69. package/build/types.d.ts +8 -0
  70. package/cli.bundle.mjs +157 -136
  71. package/configs/antigravity/GEMINI.md +31 -36
  72. package/configs/claude-code/CLAUDE.md +31 -37
  73. package/configs/codex/AGENTS.md +35 -49
  74. package/configs/cursor/context-mode.mdc +24 -25
  75. package/configs/gemini-cli/GEMINI.md +30 -36
  76. package/configs/jetbrains-copilot/copilot-instructions.md +59 -0
  77. package/configs/jetbrains-copilot/hooks.json +16 -0
  78. package/configs/jetbrains-copilot/mcp.json +8 -0
  79. package/configs/kilo/AGENTS.md +30 -36
  80. package/configs/kiro/KIRO.md +30 -36
  81. package/configs/kiro/agent.json +1 -1
  82. package/configs/openclaw/AGENTS.md +30 -36
  83. package/configs/opencode/AGENTS.md +30 -36
  84. package/configs/pi/AGENTS.md +31 -36
  85. package/configs/qwen-code/QWEN.md +63 -0
  86. package/configs/vscode-copilot/copilot-instructions.md +30 -36
  87. package/configs/zed/AGENTS.md +31 -36
  88. package/hooks/codex/posttooluse.mjs +7 -7
  89. package/hooks/codex/pretooluse.mjs +3 -3
  90. package/hooks/codex/sessionstart.mjs +2 -1
  91. package/hooks/core/formatters.mjs +24 -0
  92. package/hooks/core/routing.mjs +40 -15
  93. package/hooks/core/tool-naming.mjs +2 -0
  94. package/hooks/cursor/posttooluse.mjs +7 -7
  95. package/hooks/cursor/pretooluse.mjs +3 -3
  96. package/hooks/cursor/sessionstart.mjs +2 -1
  97. package/hooks/cursor/stop.mjs +2 -2
  98. package/hooks/ensure-deps.mjs +22 -10
  99. package/hooks/gemini-cli/aftertool.mjs +8 -8
  100. package/hooks/gemini-cli/beforetool.mjs +3 -2
  101. package/hooks/gemini-cli/precompress.mjs +2 -2
  102. package/hooks/gemini-cli/sessionstart.mjs +12 -4
  103. package/hooks/jetbrains-copilot/posttooluse.mjs +61 -0
  104. package/hooks/jetbrains-copilot/precompact.mjs +54 -0
  105. package/hooks/jetbrains-copilot/pretooluse.mjs +27 -0
  106. package/hooks/jetbrains-copilot/sessionstart.mjs +119 -0
  107. package/hooks/kiro/posttooluse.mjs +6 -7
  108. package/hooks/kiro/pretooluse.mjs +3 -2
  109. package/hooks/posttooluse.mjs +8 -8
  110. package/hooks/precompact.mjs +3 -4
  111. package/hooks/pretooluse.mjs +43 -20
  112. package/hooks/routing-block.mjs +35 -33
  113. package/hooks/session-attribution.bundle.mjs +1 -0
  114. package/hooks/session-db.bundle.mjs +27 -8
  115. package/hooks/session-extract.bundle.mjs +2 -1
  116. package/hooks/session-helpers.mjs +44 -3
  117. package/hooks/session-loaders.mjs +37 -0
  118. package/hooks/session-snapshot.bundle.mjs +14 -14
  119. package/hooks/sessionstart.mjs +5 -5
  120. package/hooks/userpromptsubmit.mjs +26 -9
  121. package/hooks/vscode-copilot/posttooluse.mjs +8 -8
  122. package/hooks/vscode-copilot/precompact.mjs +2 -2
  123. package/hooks/vscode-copilot/pretooluse.mjs +3 -2
  124. package/hooks/vscode-copilot/sessionstart.mjs +2 -2
  125. package/insight/server.mjs +262 -32
  126. package/insight/src/lib/api.ts +2 -1
  127. package/insight/src/routes/index.tsx +16 -3
  128. package/insight/src/routes/search.tsx +1 -1
  129. package/openclaw.plugin.json +1 -1
  130. package/package.json +11 -2
  131. package/server.bundle.mjs +117 -99
  132. package/skills/ctx-insight/SKILL.md +1 -1
@@ -1,35 +1,24 @@
1
1
  /**
2
2
  * adapters/claude-code — Claude Code platform adapter.
3
3
  *
4
- * Implements HookAdapter for Claude Code's JSON stdin/stdout hook paradigm.
4
+ * Extends ClaudeCodeBaseAdapter (shared wire-protocol parse/format methods)
5
+ * with Claude Code-specific configuration, diagnostics, and upgrade logic.
5
6
  *
6
7
  * Claude Code hook specifics:
7
- * - I/O: JSON on stdin, JSON on stdout
8
- * - Arg modification: `updatedInput` field in response
9
- * - Blocking: `permissionDecision: "deny"` in response
10
- * - PostToolUse output: `updatedMCPToolOutput` field
11
- * - PreCompact: stdout on exit 0
12
8
  * - Session ID: transcript_path UUID > session_id > CLAUDE_SESSION_ID > ppid
13
9
  * - Config: ~/.claude/settings.json
14
10
  * - Session dir: ~/.claude/context-mode/sessions/
11
+ * - Plugin registry: ~/.claude/plugins/installed_plugins.json
15
12
  */
16
- import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse, HookRegistration } from "../types.js";
17
- export declare class ClaudeCodeAdapter implements HookAdapter {
13
+ import { ClaudeCodeBaseAdapter, type ClaudeCodeWireInput } from "../claude-code-base.js";
14
+ import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, HookRegistration } from "../types.js";
15
+ export declare class ClaudeCodeAdapter extends ClaudeCodeBaseAdapter implements HookAdapter {
16
+ constructor();
18
17
  readonly name = "Claude Code";
19
18
  readonly paradigm: HookParadigm;
19
+ protected readonly projectDirEnvVar = "CLAUDE_PROJECT_DIR";
20
20
  readonly capabilities: PlatformCapabilities;
21
- parsePreToolUseInput(raw: unknown): PreToolUseEvent;
22
- parsePostToolUseInput(raw: unknown): PostToolUseEvent;
23
- parsePreCompactInput(raw: unknown): PreCompactEvent;
24
- parseSessionStartInput(raw: unknown): SessionStartEvent;
25
- formatPreToolUseResponse(response: PreToolUseResponse): unknown;
26
- formatPostToolUseResponse(response: PostToolUseResponse): unknown;
27
- formatPreCompactResponse(response: PreCompactResponse): unknown;
28
- formatSessionStartResponse(response: SessionStartResponse): unknown;
29
21
  getSettingsPath(): string;
30
- getSessionDir(): string;
31
- getSessionDBPath(projectDir: string): string;
32
- getSessionEventsPath(projectDir: string): string;
33
22
  generateHookConfig(pluginRoot: string): HookRegistration;
34
23
  readSettings(): Record<string, unknown> | null;
35
24
  writeSettings(settings: Record<string, unknown>): void;
@@ -41,12 +30,7 @@ export declare class ClaudeCodeAdapter implements HookAdapter {
41
30
  checkPluginRegistration(): DiagnosticResult;
42
31
  getInstalledVersion(): string;
43
32
  configureAllHooks(pluginRoot: string): string[];
44
- backupSettings(): string | null;
45
33
  setHookPermissions(pluginRoot: string): string[];
46
34
  updatePluginRegistry(pluginRoot: string, version: string): void;
47
- /**
48
- * Extract session ID from Claude Code hook input.
49
- * Priority: transcript_path UUID > session_id field > CLAUDE_SESSION_ID env > ppid fallback.
50
- */
51
- private extractSessionId;
35
+ protected extractSessionId(input: ClaudeCodeWireInput): string;
52
36
  }
@@ -1,29 +1,30 @@
1
1
  /**
2
2
  * adapters/claude-code — Claude Code platform adapter.
3
3
  *
4
- * Implements HookAdapter for Claude Code's JSON stdin/stdout hook paradigm.
4
+ * Extends ClaudeCodeBaseAdapter (shared wire-protocol parse/format methods)
5
+ * with Claude Code-specific configuration, diagnostics, and upgrade logic.
5
6
  *
6
7
  * Claude Code hook specifics:
7
- * - I/O: JSON on stdin, JSON on stdout
8
- * - Arg modification: `updatedInput` field in response
9
- * - Blocking: `permissionDecision: "deny"` in response
10
- * - PostToolUse output: `updatedMCPToolOutput` field
11
- * - PreCompact: stdout on exit 0
12
8
  * - Session ID: transcript_path UUID > session_id > CLAUDE_SESSION_ID > ppid
13
9
  * - Config: ~/.claude/settings.json
14
10
  * - Session dir: ~/.claude/context-mode/sessions/
11
+ * - Plugin registry: ~/.claude/plugins/installed_plugins.json
15
12
  */
16
- import { createHash } from "node:crypto";
17
- import { readFileSync, writeFileSync, mkdirSync, copyFileSync, accessSync, existsSync, readdirSync, chmodSync, constants, } from "node:fs";
13
+ import { readFileSync, writeFileSync, existsSync, readdirSync, chmodSync, accessSync, constants, } from "node:fs";
18
14
  import { resolve, join } from "node:path";
19
15
  import { homedir } from "node:os";
16
+ import { ClaudeCodeBaseAdapter } from "../claude-code-base.js";
20
17
  import { HOOK_TYPES, HOOK_SCRIPTS, REQUIRED_HOOKS, PRE_TOOL_USE_MATCHER_PATTERN, isContextModeHook, isAnyContextModeHook, extractHookScriptPath, buildHookCommand, } from "./hooks.js";
21
18
  // ─────────────────────────────────────────────────────────
22
19
  // Adapter implementation
23
20
  // ─────────────────────────────────────────────────────────
24
- export class ClaudeCodeAdapter {
21
+ export class ClaudeCodeAdapter extends ClaudeCodeBaseAdapter {
22
+ constructor() {
23
+ super([".claude"]);
24
+ }
25
25
  name = "Claude Code";
26
26
  paradigm = "json-stdio";
27
+ projectDirEnvVar = "CLAUDE_PROJECT_DIR";
27
28
  capabilities = {
28
29
  preToolUse: true,
29
30
  postToolUse: true,
@@ -33,124 +34,10 @@ export class ClaudeCodeAdapter {
33
34
  canModifyOutput: true,
34
35
  canInjectSessionContext: true,
35
36
  };
36
- // ── Input parsing ──────────────────────────────────────
37
- parsePreToolUseInput(raw) {
38
- const input = raw;
39
- return {
40
- toolName: input.tool_name ?? "",
41
- toolInput: input.tool_input ?? {},
42
- sessionId: this.extractSessionId(input),
43
- projectDir: process.env.CLAUDE_PROJECT_DIR,
44
- raw,
45
- };
46
- }
47
- parsePostToolUseInput(raw) {
48
- const input = raw;
49
- return {
50
- toolName: input.tool_name ?? "",
51
- toolInput: input.tool_input ?? {},
52
- toolOutput: input.tool_output,
53
- isError: input.is_error,
54
- sessionId: this.extractSessionId(input),
55
- projectDir: process.env.CLAUDE_PROJECT_DIR,
56
- raw,
57
- };
58
- }
59
- parsePreCompactInput(raw) {
60
- const input = raw;
61
- return {
62
- sessionId: this.extractSessionId(input),
63
- projectDir: process.env.CLAUDE_PROJECT_DIR,
64
- raw,
65
- };
66
- }
67
- parseSessionStartInput(raw) {
68
- const input = raw;
69
- const rawSource = input.source ?? "startup";
70
- let source;
71
- switch (rawSource) {
72
- case "compact":
73
- source = "compact";
74
- break;
75
- case "resume":
76
- source = "resume";
77
- break;
78
- case "clear":
79
- source = "clear";
80
- break;
81
- default:
82
- source = "startup";
83
- }
84
- return {
85
- sessionId: this.extractSessionId(input),
86
- source,
87
- projectDir: process.env.CLAUDE_PROJECT_DIR,
88
- raw,
89
- };
90
- }
91
- // ── Response formatting ────────────────────────────────
92
- formatPreToolUseResponse(response) {
93
- if (response.decision === "deny") {
94
- return {
95
- permissionDecision: "deny",
96
- reason: response.reason ?? "Blocked by context-mode hook",
97
- };
98
- }
99
- if (response.decision === "modify" && response.updatedInput) {
100
- return { updatedInput: response.updatedInput };
101
- }
102
- if (response.decision === "context" && response.additionalContext) {
103
- // Claude Code: inject additionalContext into model context
104
- return { additionalContext: response.additionalContext };
105
- }
106
- if (response.decision === "ask") {
107
- // Claude Code: native "ask" — prompt user for permission
108
- return { permissionDecision: "ask" };
109
- }
110
- // "allow" — return null/undefined for passthrough
111
- return undefined;
112
- }
113
- formatPostToolUseResponse(response) {
114
- const result = {};
115
- if (response.additionalContext) {
116
- result.additionalContext = response.additionalContext;
117
- }
118
- if (response.updatedOutput) {
119
- result.updatedMCPToolOutput = response.updatedOutput;
120
- }
121
- return Object.keys(result).length > 0 ? result : undefined;
122
- }
123
- formatPreCompactResponse(response) {
124
- // Claude Code: stdout content on exit 0 is injected as context
125
- return response.context ?? "";
126
- }
127
- formatSessionStartResponse(response) {
128
- // Claude Code: stdout content is injected as additional context
129
- return response.context ?? "";
130
- }
131
37
  // ── Configuration ──────────────────────────────────────
132
38
  getSettingsPath() {
133
39
  return resolve(homedir(), ".claude", "settings.json");
134
40
  }
135
- getSessionDir() {
136
- const dir = join(homedir(), ".claude", "context-mode", "sessions");
137
- mkdirSync(dir, { recursive: true });
138
- return dir;
139
- }
140
- getSessionDBPath(projectDir) {
141
- const hash = createHash("sha256")
142
- .update(projectDir)
143
- .digest("hex")
144
- .slice(0, 16);
145
- return join(this.getSessionDir(), `${hash}.db`);
146
- }
147
- getSessionEventsPath(projectDir) {
148
- const hash = createHash("sha256")
149
- .update(projectDir)
150
- .digest("hex")
151
- .slice(0, 16);
152
- return join(this.getSessionDir(), `${hash}-events.md`);
153
- }
154
41
  generateHookConfig(pluginRoot) {
155
42
  const preToolUseCommand = `node ${pluginRoot}/hooks/pretooluse.mjs`;
156
43
  const preToolUseMatchers = [
@@ -421,7 +308,21 @@ export class ClaudeCodeAdapter {
421
308
  if (pluginHooks) {
422
309
  const allCovered = REQUIRED_HOOKS.every((ht) => this.checkHookType(undefined, pluginHooks, ht));
423
310
  if (allCovered) {
424
- // Still write cleaned settings (stale removal) but don't add new entries
311
+ // Remove ALL existing context-mode hooks from settings.json hooks.json
312
+ // is the source of truth. Keeping them causes duplicate concurrent hook
313
+ // processes (one from settings.json, one from hooks.json), which triggers
314
+ // "non-blocking hook error" warnings on every tool call.
315
+ for (const hookType of Object.keys(hooks)) {
316
+ const entries = hooks[hookType];
317
+ if (!Array.isArray(entries))
318
+ continue;
319
+ const filtered = entries.filter((entry) => !isAnyContextModeHook(entry));
320
+ const removed = entries.length - filtered.length;
321
+ if (removed > 0) {
322
+ hooks[hookType] = filtered;
323
+ changes.push(`Removed ${removed} duplicate ${hookType} hook(s) — covered by plugin hooks.json`);
324
+ }
325
+ }
425
326
  settings.hooks = hooks;
426
327
  this.writeSettings(settings);
427
328
  changes.push("Skipped settings.json registration — plugin hooks.json is sufficient");
@@ -486,18 +387,6 @@ export class ClaudeCodeAdapter {
486
387
  this.writeSettings(settings);
487
388
  return changes;
488
389
  }
489
- backupSettings() {
490
- const settingsPath = this.getSettingsPath();
491
- try {
492
- accessSync(settingsPath, constants.R_OK);
493
- const backupPath = settingsPath + ".bak";
494
- copyFileSync(settingsPath, backupPath);
495
- return backupPath;
496
- }
497
- catch {
498
- return null;
499
- }
500
- }
501
390
  setHookPermissions(pluginRoot) {
502
391
  const set = [];
503
392
  for (const [, scriptName] of Object.entries(HOOK_SCRIPTS)) {
@@ -532,11 +421,8 @@ export class ClaudeCodeAdapter {
532
421
  /* best effort */
533
422
  }
534
423
  }
535
- // ── Internal helpers ───────────────────────────────────
536
- /**
537
- * Extract session ID from Claude Code hook input.
538
- * Priority: transcript_path UUID > session_id field > CLAUDE_SESSION_ID env > ppid fallback.
539
- */
424
+ // ── Session ID extraction ───────────────────────────────
425
+ // Claude Code priority: transcript_path UUID > session_id > CLAUDE_SESSION_ID > ppid
540
426
  extractSessionId(input) {
541
427
  if (input.transcript_path) {
542
428
  const match = input.transcript_path.match(/([a-f0-9-]{36})\.jsonl$/);
@@ -0,0 +1,49 @@
1
+ /**
2
+ * adapters/claude-code-base — Shared base for Claude Code wire-protocol adapters.
3
+ *
4
+ * Claude Code and Qwen Code use the identical JSON stdin/stdout hook protocol:
5
+ * - Input fields: tool_name, tool_input, tool_output, is_error, session_id,
6
+ * transcript_path, source
7
+ * - Blocking: `permissionDecision: "deny"` in response
8
+ * - Arg modification: `updatedInput` field in response
9
+ * - Output modification: `updatedMCPToolOutput` field in response
10
+ * - Context injection: `additionalContext` at response root (not wrapped)
11
+ * - PreCompact/SessionStart: stdout on exit 0
12
+ *
13
+ * This base class implements the 8 shared parse/format methods.
14
+ * Subclasses provide platform-specific config (env vars, settings path,
15
+ * session ID priority, hook config, diagnostics, upgrade).
16
+ */
17
+ import { BaseAdapter } from "./base.js";
18
+ import type { PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse } from "./types.js";
19
+ export interface ClaudeCodeWireInput {
20
+ tool_name?: string;
21
+ tool_input?: Record<string, unknown>;
22
+ tool_output?: string;
23
+ is_error?: boolean;
24
+ session_id?: string;
25
+ transcript_path?: string;
26
+ source?: string;
27
+ }
28
+ export declare abstract class ClaudeCodeBaseAdapter extends BaseAdapter {
29
+ /**
30
+ * Environment variable name for the project directory.
31
+ * Claude Code: "CLAUDE_PROJECT_DIR", Qwen Code: "QWEN_PROJECT_DIR"
32
+ */
33
+ protected abstract readonly projectDirEnvVar: string;
34
+ parsePreToolUseInput(raw: unknown): PreToolUseEvent;
35
+ parsePostToolUseInput(raw: unknown): PostToolUseEvent;
36
+ parsePreCompactInput(raw: unknown): PreCompactEvent;
37
+ parseSessionStartInput(raw: unknown): SessionStartEvent;
38
+ formatPreToolUseResponse(response: PreToolUseResponse): unknown;
39
+ formatPostToolUseResponse(response: PostToolUseResponse): unknown;
40
+ formatPreCompactResponse(response: PreCompactResponse): unknown;
41
+ formatSessionStartResponse(response: SessionStartResponse): unknown;
42
+ /**
43
+ * Extract session ID from wire input. Default priority (Claude Code):
44
+ * transcript_path UUID > session_id > env var > ppid fallback
45
+ *
46
+ * Override in subclasses for different priority (e.g., Qwen: session_id first).
47
+ */
48
+ protected abstract extractSessionId(input: ClaudeCodeWireInput): string;
49
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * adapters/claude-code-base — Shared base for Claude Code wire-protocol adapters.
3
+ *
4
+ * Claude Code and Qwen Code use the identical JSON stdin/stdout hook protocol:
5
+ * - Input fields: tool_name, tool_input, tool_output, is_error, session_id,
6
+ * transcript_path, source
7
+ * - Blocking: `permissionDecision: "deny"` in response
8
+ * - Arg modification: `updatedInput` field in response
9
+ * - Output modification: `updatedMCPToolOutput` field in response
10
+ * - Context injection: `additionalContext` at response root (not wrapped)
11
+ * - PreCompact/SessionStart: stdout on exit 0
12
+ *
13
+ * This base class implements the 8 shared parse/format methods.
14
+ * Subclasses provide platform-specific config (env vars, settings path,
15
+ * session ID priority, hook config, diagnostics, upgrade).
16
+ */
17
+ import { BaseAdapter } from "./base.js";
18
+ // ─────────────────────────────────────────────────────────
19
+ // Base adapter for Claude Code wire protocol
20
+ // ─────────────────────────────────────────────────────────
21
+ export class ClaudeCodeBaseAdapter extends BaseAdapter {
22
+ // ── Input parsing (shared wire format) ─────────────────
23
+ parsePreToolUseInput(raw) {
24
+ const input = raw;
25
+ return {
26
+ toolName: input.tool_name ?? "",
27
+ toolInput: input.tool_input ?? {},
28
+ sessionId: this.extractSessionId(input),
29
+ projectDir: process.env[this.projectDirEnvVar],
30
+ raw,
31
+ };
32
+ }
33
+ parsePostToolUseInput(raw) {
34
+ const input = raw;
35
+ return {
36
+ toolName: input.tool_name ?? "",
37
+ toolInput: input.tool_input ?? {},
38
+ toolOutput: input.tool_output,
39
+ isError: input.is_error,
40
+ sessionId: this.extractSessionId(input),
41
+ projectDir: process.env[this.projectDirEnvVar],
42
+ raw,
43
+ };
44
+ }
45
+ parsePreCompactInput(raw) {
46
+ const input = raw;
47
+ return {
48
+ sessionId: this.extractSessionId(input),
49
+ projectDir: process.env[this.projectDirEnvVar],
50
+ raw,
51
+ };
52
+ }
53
+ parseSessionStartInput(raw) {
54
+ const input = raw;
55
+ const rawSource = input.source ?? "startup";
56
+ let source;
57
+ switch (rawSource) {
58
+ case "compact":
59
+ source = "compact";
60
+ break;
61
+ case "resume":
62
+ source = "resume";
63
+ break;
64
+ case "clear":
65
+ source = "clear";
66
+ break;
67
+ default:
68
+ source = "startup";
69
+ }
70
+ return {
71
+ sessionId: this.extractSessionId(input),
72
+ source,
73
+ projectDir: process.env[this.projectDirEnvVar],
74
+ raw,
75
+ };
76
+ }
77
+ // ── Response formatting (shared wire format) ───────────
78
+ formatPreToolUseResponse(response) {
79
+ if (response.decision === "deny") {
80
+ return {
81
+ permissionDecision: "deny",
82
+ reason: response.reason ?? "Blocked by context-mode hook",
83
+ };
84
+ }
85
+ if (response.decision === "modify" && response.updatedInput) {
86
+ return { updatedInput: response.updatedInput };
87
+ }
88
+ if (response.decision === "context" && response.additionalContext) {
89
+ return { additionalContext: response.additionalContext };
90
+ }
91
+ if (response.decision === "ask") {
92
+ return { permissionDecision: "ask" };
93
+ }
94
+ // "allow" — return undefined for passthrough
95
+ return undefined;
96
+ }
97
+ formatPostToolUseResponse(response) {
98
+ const result = {};
99
+ if (response.additionalContext) {
100
+ result.additionalContext = response.additionalContext;
101
+ }
102
+ if (response.updatedOutput) {
103
+ result.updatedMCPToolOutput = response.updatedOutput;
104
+ }
105
+ return Object.keys(result).length > 0 ? result : undefined;
106
+ }
107
+ formatPreCompactResponse(response) {
108
+ return response.context ?? "";
109
+ }
110
+ formatSessionStartResponse(response) {
111
+ return response.context ?? "";
112
+ }
113
+ }
@@ -12,6 +12,9 @@ export const CLIENT_NAME_TO_PLATFORM = {
12
12
  "antigravity-client": "antigravity",
13
13
  "cursor-vscode": "cursor",
14
14
  "Visual-Studio-Code": "vscode-copilot",
15
+ "JetBrains Client": "jetbrains-copilot",
16
+ "IntelliJ IDEA": "jetbrains-copilot",
17
+ "PyCharm": "jetbrains-copilot",
15
18
  "Codex": "codex",
16
19
  "codex-mcp-client": "codex",
17
20
  "Kilo Code": "kilo",
@@ -20,4 +23,6 @@ export const CLIENT_NAME_TO_PLATFORM = {
20
23
  "Pi Coding Agent": "pi",
21
24
  "Zed": "zed",
22
25
  "zed": "zed",
26
+ "qwen-code": "qwen-code",
27
+ "qwen-cli-mcp-client": "qwen-code",
23
28
  };
@@ -1,21 +1,28 @@
1
1
  /**
2
- * adapters/codex/hooks — Codex CLI hook definitions (stub).
2
+ * adapters/codex/hooks — Codex CLI hook definitions.
3
3
  *
4
- * Codex CLI does NOT support hooks (PRs #2904, #9796 were closed without merge).
5
- * Only MCP integration is available. This module exports empty/stub constants
6
- * for interface consistency with other adapters.
4
+ * Codex CLI hooks are stable (codex_hooks Stage::Stable, default_enabled: true).
5
+ * 5 hook events: PreToolUse, PostToolUse, SessionStart, UserPromptSubmit, Stop.
6
+ * Same JSON stdin/stdout wire protocol as Claude Code.
7
7
  *
8
- * Config: ~/.codex/config.toml (TOML format, not JSON)
9
- * MCP: full support via [mcp_servers] in config.toml
10
- */
11
- /**
12
- * Codex CLI hook types empty object.
13
- * Codex CLI has no hook support; only MCP integration is available.
8
+ * Config: ~/.codex/hooks.json (JSON format, same schema as Claude Code)
9
+ * MCP: full support via [mcp_servers] in ~/.codex/config.toml
10
+ *
11
+ * Known limitations:
12
+ * - PreToolUse: deny works, updatedInput not yet supported (openai/codex#18491)
13
+ * - PostToolUse: updatedMCPToolOutput parsed but logged as unsupported
14
+ * - PostToolUse does not fire on failing Bash calls (upstream bug)
14
15
  */
15
- export declare const HOOK_TYPES: {};
16
+ /** Codex CLI hook types — mirrors Claude Code's 5-event model. */
17
+ export declare const HOOK_TYPES: {
18
+ readonly PRE_TOOL_USE: "PreToolUse";
19
+ readonly POST_TOOL_USE: "PostToolUse";
20
+ readonly SESSION_START: "SessionStart";
21
+ readonly USER_PROMPT_SUBMIT: "UserPromptSubmit";
22
+ readonly STOP: "Stop";
23
+ };
16
24
  /**
17
- * Path to the routing instructions file appended to the system prompt
18
- * when Codex CLI initializes the MCP server. This is the only integration
19
- * point since hooks are not supported.
25
+ * Path to the routing instructions file for Codex CLI.
26
+ * Used as fallback routing awareness alongside hook-based enforcement.
20
27
  */
21
28
  export declare const ROUTING_INSTRUCTIONS_PATH = "configs/codex/AGENTS.md";
@@ -1,27 +1,34 @@
1
1
  /**
2
- * adapters/codex/hooks — Codex CLI hook definitions (stub).
2
+ * adapters/codex/hooks — Codex CLI hook definitions.
3
3
  *
4
- * Codex CLI does NOT support hooks (PRs #2904, #9796 were closed without merge).
5
- * Only MCP integration is available. This module exports empty/stub constants
6
- * for interface consistency with other adapters.
4
+ * Codex CLI hooks are stable (codex_hooks Stage::Stable, default_enabled: true).
5
+ * 5 hook events: PreToolUse, PostToolUse, SessionStart, UserPromptSubmit, Stop.
6
+ * Same JSON stdin/stdout wire protocol as Claude Code.
7
7
  *
8
- * Config: ~/.codex/config.toml (TOML format, not JSON)
9
- * MCP: full support via [mcp_servers] in config.toml
8
+ * Config: ~/.codex/hooks.json (JSON format, same schema as Claude Code)
9
+ * MCP: full support via [mcp_servers] in ~/.codex/config.toml
10
+ *
11
+ * Known limitations:
12
+ * - PreToolUse: deny works, updatedInput not yet supported (openai/codex#18491)
13
+ * - PostToolUse: updatedMCPToolOutput parsed but logged as unsupported
14
+ * - PostToolUse does not fire on failing Bash calls (upstream bug)
10
15
  */
11
16
  // ─────────────────────────────────────────────────────────
12
- // Hook type constants (empty — no hook support)
17
+ // Hook type constants
13
18
  // ─────────────────────────────────────────────────────────
14
- /**
15
- * Codex CLI hook types — empty object.
16
- * Codex CLI has no hook support; only MCP integration is available.
17
- */
18
- export const HOOK_TYPES = {};
19
+ /** Codex CLI hook types — mirrors Claude Code's 5-event model. */
20
+ export const HOOK_TYPES = {
21
+ PRE_TOOL_USE: "PreToolUse",
22
+ POST_TOOL_USE: "PostToolUse",
23
+ SESSION_START: "SessionStart",
24
+ USER_PROMPT_SUBMIT: "UserPromptSubmit",
25
+ STOP: "Stop",
26
+ };
19
27
  // ─────────────────────────────────────────────────────────
20
28
  // Routing instructions
21
29
  // ─────────────────────────────────────────────────────────
22
30
  /**
23
- * Path to the routing instructions file appended to the system prompt
24
- * when Codex CLI initializes the MCP server. This is the only integration
25
- * point since hooks are not supported.
31
+ * Path to the routing instructions file for Codex CLI.
32
+ * Used as fallback routing awareness alongside hook-based enforcement.
26
33
  */
27
34
  export const ROUTING_INSTRUCTIONS_PATH = "configs/codex/AGENTS.md";
@@ -9,14 +9,14 @@
9
9
  * - Config: ~/.codex/hooks.json + ~/.codex/config.toml (TOML for MCP/features)
10
10
  * - Session dir: ~/.codex/context-mode/sessions/
11
11
  *
12
- * IMPORTANT: Hook dispatch is NOT yet active in Codex CLI (v0.118.0).
13
- * codex_hooks feature flag is Stage::UnderDevelopment hooks are implemented
14
- * in codex-rs/hooks/ but not wired into the tool execution pipeline.
15
- * Our adapter is ready; it will work once Codex enables dispatch.
16
- * Track: https://github.com/openai/codex/issues/16685
12
+ * Hook dispatch is stable in Codex CLI. PreToolUse deny decisions work,
13
+ * while input rewriting remains blocked on upstream updatedInput support.
14
+ * Track: https://github.com/openai/codex/issues/18491
17
15
  */
16
+ import { BaseAdapter } from "../base.js";
18
17
  import type { HookAdapter, HookParadigm, PlatformCapabilities, DiagnosticResult, PreToolUseEvent, PostToolUseEvent, PreCompactEvent, SessionStartEvent, PreToolUseResponse, PostToolUseResponse, PreCompactResponse, SessionStartResponse, HookRegistration } from "../types.js";
19
- export declare class CodexAdapter implements HookAdapter {
18
+ export declare class CodexAdapter extends BaseAdapter implements HookAdapter {
19
+ constructor();
20
20
  readonly name = "Codex CLI";
21
21
  readonly paradigm: HookParadigm;
22
22
  readonly capabilities: PlatformCapabilities;
@@ -29,9 +29,6 @@ export declare class CodexAdapter implements HookAdapter {
29
29
  formatPreCompactResponse(response: PreCompactResponse): unknown;
30
30
  formatSessionStartResponse(response: SessionStartResponse): unknown;
31
31
  getSettingsPath(): string;
32
- getSessionDir(): string;
33
- getSessionDBPath(projectDir: string): string;
34
- getSessionEventsPath(projectDir: string): string;
35
32
  generateHookConfig(pluginRoot: string): HookRegistration;
36
33
  readSettings(): Record<string, unknown> | null;
37
34
  writeSettings(_settings: Record<string, unknown>): void;
@@ -39,7 +36,6 @@ export declare class CodexAdapter implements HookAdapter {
39
36
  checkPluginRegistration(): DiagnosticResult;
40
37
  getInstalledVersion(): string;
41
38
  configureAllHooks(_pluginRoot: string): string[];
42
- backupSettings(): string | null;
43
39
  setHookPermissions(_pluginRoot: string): string[];
44
40
  updatePluginRegistry(_pluginRoot: string, _version: string): void;
45
41
  getRoutingInstructions(): string;