context-mode 1.0.89 → 1.0.91
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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/README.md +184 -60
- package/build/adapters/antigravity/index.d.ts +3 -5
- package/build/adapters/antigravity/index.js +7 -35
- package/build/adapters/base.d.ts +27 -0
- package/build/adapters/base.js +59 -0
- package/build/adapters/claude-code/index.d.ts +9 -25
- package/build/adapters/claude-code/index.js +12 -140
- package/build/adapters/claude-code-base.d.ts +49 -0
- package/build/adapters/claude-code-base.js +113 -0
- package/build/adapters/client-map.js +5 -0
- package/build/adapters/codex/hooks.d.ts +21 -14
- package/build/adapters/codex/hooks.js +22 -15
- package/build/adapters/codex/index.d.ts +6 -10
- package/build/adapters/codex/index.js +13 -43
- package/build/adapters/copilot-base.d.ts +78 -0
- package/build/adapters/copilot-base.js +281 -0
- package/build/adapters/cursor/index.d.ts +3 -5
- package/build/adapters/cursor/index.js +6 -34
- package/build/adapters/detect.d.ts +7 -0
- package/build/adapters/detect.js +57 -56
- package/build/adapters/gemini-cli/index.d.ts +3 -5
- package/build/adapters/gemini-cli/index.js +7 -35
- package/build/adapters/jetbrains-copilot/config.d.ts +8 -0
- package/build/adapters/jetbrains-copilot/config.js +8 -0
- package/build/adapters/jetbrains-copilot/hooks.d.ts +51 -0
- package/build/adapters/jetbrains-copilot/hooks.js +82 -0
- package/build/adapters/jetbrains-copilot/index.d.ts +24 -0
- package/build/adapters/jetbrains-copilot/index.js +119 -0
- package/build/adapters/kiro/hooks.d.ts +14 -0
- package/build/adapters/kiro/hooks.js +23 -0
- package/build/adapters/kiro/index.d.ts +3 -5
- package/build/adapters/kiro/index.js +10 -38
- package/build/adapters/openclaw/index.d.ts +3 -4
- package/build/adapters/openclaw/index.js +6 -22
- package/build/adapters/opencode/index.d.ts +2 -3
- package/build/adapters/opencode/index.js +5 -16
- package/build/adapters/qwen-code/index.d.ts +39 -0
- package/build/adapters/qwen-code/index.js +199 -0
- package/build/adapters/types.d.ts +1 -1
- package/build/adapters/vscode-copilot/index.d.ts +16 -46
- package/build/adapters/vscode-copilot/index.js +29 -320
- package/build/adapters/zed/index.d.ts +3 -5
- package/build/adapters/zed/index.js +7 -35
- package/build/cli.js +13 -0
- package/build/lifecycle.d.ts +23 -0
- package/build/lifecycle.js +54 -13
- package/build/opencode-plugin.d.ts +19 -7
- package/build/opencode-plugin.js +19 -7
- package/build/runtime.js +24 -9
- package/build/security.d.ts +17 -1
- package/build/security.js +40 -6
- package/build/server.js +53 -10
- package/build/session/analytics.d.ts +8 -7
- package/build/session/analytics.js +107 -76
- package/build/session/db.d.ts +10 -1
- package/build/session/db.js +67 -8
- package/build/session/extract.js +10 -2
- package/build/session/project-attribution.d.ts +73 -0
- package/build/session/project-attribution.js +231 -0
- package/build/store.d.ts +4 -0
- package/build/store.js +58 -9
- package/build/types.d.ts +8 -0
- package/cli.bundle.mjs +135 -121
- package/configs/antigravity/GEMINI.md +31 -36
- package/configs/claude-code/CLAUDE.md +31 -37
- package/configs/codex/AGENTS.md +35 -49
- package/configs/cursor/context-mode.mdc +24 -25
- package/configs/gemini-cli/GEMINI.md +30 -36
- package/configs/jetbrains-copilot/copilot-instructions.md +59 -0
- package/configs/jetbrains-copilot/hooks.json +16 -0
- package/configs/jetbrains-copilot/mcp.json +8 -0
- package/configs/kilo/AGENTS.md +30 -36
- package/configs/kiro/KIRO.md +30 -36
- package/configs/kiro/agent.json +1 -1
- package/configs/openclaw/AGENTS.md +30 -36
- package/configs/opencode/AGENTS.md +30 -36
- package/configs/pi/AGENTS.md +31 -36
- package/configs/qwen-code/QWEN.md +63 -0
- package/configs/vscode-copilot/copilot-instructions.md +30 -36
- package/configs/zed/AGENTS.md +31 -36
- package/hooks/codex/posttooluse.mjs +7 -7
- package/hooks/codex/pretooluse.mjs +3 -3
- package/hooks/codex/sessionstart.mjs +2 -1
- package/hooks/core/formatters.mjs +24 -0
- package/hooks/core/routing.mjs +40 -15
- package/hooks/core/tool-naming.mjs +2 -0
- package/hooks/cursor/posttooluse.mjs +7 -7
- package/hooks/cursor/pretooluse.mjs +3 -3
- package/hooks/cursor/sessionstart.mjs +2 -1
- package/hooks/cursor/stop.mjs +2 -2
- package/hooks/ensure-deps.mjs +22 -10
- package/hooks/gemini-cli/aftertool.mjs +8 -8
- package/hooks/gemini-cli/beforetool.mjs +3 -2
- package/hooks/gemini-cli/precompress.mjs +2 -2
- package/hooks/gemini-cli/sessionstart.mjs +12 -4
- package/hooks/jetbrains-copilot/posttooluse.mjs +61 -0
- package/hooks/jetbrains-copilot/precompact.mjs +54 -0
- package/hooks/jetbrains-copilot/pretooluse.mjs +27 -0
- package/hooks/jetbrains-copilot/sessionstart.mjs +119 -0
- package/hooks/kiro/posttooluse.mjs +6 -7
- package/hooks/kiro/pretooluse.mjs +3 -2
- package/hooks/posttooluse.mjs +8 -8
- package/hooks/precompact.mjs +3 -4
- package/hooks/pretooluse.mjs +5 -4
- package/hooks/routing-block.mjs +35 -33
- package/hooks/session-attribution.bundle.mjs +1 -0
- package/hooks/session-db.bundle.mjs +27 -8
- package/hooks/session-extract.bundle.mjs +2 -1
- package/hooks/session-helpers.mjs +44 -3
- package/hooks/session-loaders.mjs +37 -0
- package/hooks/sessionstart.mjs +5 -5
- package/hooks/userpromptsubmit.mjs +26 -9
- package/hooks/vscode-copilot/posttooluse.mjs +8 -8
- package/hooks/vscode-copilot/precompact.mjs +2 -2
- package/hooks/vscode-copilot/pretooluse.mjs +3 -2
- package/hooks/vscode-copilot/sessionstart.mjs +2 -2
- package/insight/server.mjs +237 -25
- package/insight/src/lib/api.ts +2 -1
- package/insight/src/routes/index.tsx +16 -3
- package/insight/src/routes/search.tsx +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +11 -2
- package/server.bundle.mjs +94 -80
- 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
|
-
*
|
|
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
|
|
17
|
-
|
|
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
|
-
*
|
|
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 {
|
|
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 = [
|
|
@@ -500,18 +387,6 @@ export class ClaudeCodeAdapter {
|
|
|
500
387
|
this.writeSettings(settings);
|
|
501
388
|
return changes;
|
|
502
389
|
}
|
|
503
|
-
backupSettings() {
|
|
504
|
-
const settingsPath = this.getSettingsPath();
|
|
505
|
-
try {
|
|
506
|
-
accessSync(settingsPath, constants.R_OK);
|
|
507
|
-
const backupPath = settingsPath + ".bak";
|
|
508
|
-
copyFileSync(settingsPath, backupPath);
|
|
509
|
-
return backupPath;
|
|
510
|
-
}
|
|
511
|
-
catch {
|
|
512
|
-
return null;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
390
|
setHookPermissions(pluginRoot) {
|
|
516
391
|
const set = [];
|
|
517
392
|
for (const [, scriptName] of Object.entries(HOOK_SCRIPTS)) {
|
|
@@ -546,11 +421,8 @@ export class ClaudeCodeAdapter {
|
|
|
546
421
|
/* best effort */
|
|
547
422
|
}
|
|
548
423
|
}
|
|
549
|
-
// ──
|
|
550
|
-
|
|
551
|
-
* Extract session ID from Claude Code hook input.
|
|
552
|
-
* Priority: transcript_path UUID > session_id field > CLAUDE_SESSION_ID env > ppid fallback.
|
|
553
|
-
*/
|
|
424
|
+
// ── Session ID extraction ───────────────────────────────
|
|
425
|
+
// Claude Code priority: transcript_path UUID > session_id > CLAUDE_SESSION_ID > ppid
|
|
554
426
|
extractSessionId(input) {
|
|
555
427
|
if (input.transcript_path) {
|
|
556
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
|
|
2
|
+
* adapters/codex/hooks — Codex CLI hook definitions.
|
|
3
3
|
*
|
|
4
|
-
* Codex CLI
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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/
|
|
9
|
-
* MCP: full support via [mcp_servers] in config.toml
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
|
-
|
|
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
|
|
18
|
-
*
|
|
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
|
|
2
|
+
* adapters/codex/hooks — Codex CLI hook definitions.
|
|
3
3
|
*
|
|
4
|
-
* Codex CLI
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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/
|
|
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
|
|
17
|
+
// Hook type constants
|
|
13
18
|
// ─────────────────────────────────────────────────────────
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
24
|
-
*
|
|
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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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;
|
|
@@ -9,21 +9,22 @@
|
|
|
9
9
|
* - Config: ~/.codex/hooks.json + ~/.codex/config.toml (TOML for MCP/features)
|
|
10
10
|
* - Session dir: ~/.codex/context-mode/sessions/
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
*/
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { resolve, join, dirname } from "node:path";
|
|
16
|
+
import { readFileSync, } from "node:fs";
|
|
17
|
+
import { resolve, dirname } from "node:path";
|
|
21
18
|
import { fileURLToPath } from "node:url";
|
|
22
19
|
import { homedir } from "node:os";
|
|
20
|
+
import { BaseAdapter } from "../base.js";
|
|
23
21
|
// ─────────────────────────────────────────────────────────
|
|
24
22
|
// Adapter implementation
|
|
25
23
|
// ─────────────────────────────────────────────────────────
|
|
26
|
-
export class CodexAdapter {
|
|
24
|
+
export class CodexAdapter extends BaseAdapter {
|
|
25
|
+
constructor() {
|
|
26
|
+
super([".codex"]);
|
|
27
|
+
}
|
|
27
28
|
name = "Codex CLI";
|
|
28
29
|
paradigm = "json-stdio";
|
|
29
30
|
capabilities = {
|
|
@@ -146,30 +147,11 @@ export class CodexAdapter {
|
|
|
146
147
|
getSettingsPath() {
|
|
147
148
|
return resolve(homedir(), ".codex", "config.toml");
|
|
148
149
|
}
|
|
149
|
-
getSessionDir() {
|
|
150
|
-
const dir = join(homedir(), ".codex", "context-mode", "sessions");
|
|
151
|
-
mkdirSync(dir, { recursive: true });
|
|
152
|
-
return dir;
|
|
153
|
-
}
|
|
154
|
-
getSessionDBPath(projectDir) {
|
|
155
|
-
const hash = createHash("sha256")
|
|
156
|
-
.update(projectDir)
|
|
157
|
-
.digest("hex")
|
|
158
|
-
.slice(0, 16);
|
|
159
|
-
return join(this.getSessionDir(), `${hash}.db`);
|
|
160
|
-
}
|
|
161
|
-
getSessionEventsPath(projectDir) {
|
|
162
|
-
const hash = createHash("sha256")
|
|
163
|
-
.update(projectDir)
|
|
164
|
-
.digest("hex")
|
|
165
|
-
.slice(0, 16);
|
|
166
|
-
return join(this.getSessionDir(), `${hash}-events.md`);
|
|
167
|
-
}
|
|
168
150
|
generateHookConfig(pluginRoot) {
|
|
169
151
|
return {
|
|
170
152
|
PreToolUse: [
|
|
171
153
|
{
|
|
172
|
-
matcher: "",
|
|
154
|
+
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",
|
|
173
155
|
hooks: [
|
|
174
156
|
{
|
|
175
157
|
type: "command",
|
|
@@ -225,8 +207,8 @@ export class CodexAdapter {
|
|
|
225
207
|
return [
|
|
226
208
|
{
|
|
227
209
|
check: "Hook support",
|
|
228
|
-
status: "
|
|
229
|
-
message: "Codex CLI hooks are
|
|
210
|
+
status: "pass",
|
|
211
|
+
message: "Codex CLI hooks are stable. Configure ~/.codex/hooks.json for PreToolUse, PostToolUse, and SessionStart.",
|
|
230
212
|
},
|
|
231
213
|
];
|
|
232
214
|
}
|
|
@@ -275,18 +257,6 @@ export class CodexAdapter {
|
|
|
275
257
|
// Codex CLI hook configuration is done via hooks.json, not config.toml
|
|
276
258
|
return [];
|
|
277
259
|
}
|
|
278
|
-
backupSettings() {
|
|
279
|
-
const settingsPath = this.getSettingsPath();
|
|
280
|
-
try {
|
|
281
|
-
accessSync(settingsPath, constants.R_OK);
|
|
282
|
-
const backupPath = settingsPath + ".bak";
|
|
283
|
-
copyFileSync(settingsPath, backupPath);
|
|
284
|
-
return backupPath;
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
260
|
setHookPermissions(_pluginRoot) {
|
|
291
261
|
// Hook permissions are set during plugin install
|
|
292
262
|
return [];
|