@codemieai/code 0.0.41 → 0.0.42
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/README.md +3 -3
- package/dist/agents/codemie-code/agent.d.ts.map +1 -1
- package/dist/agents/codemie-code/agent.js +5 -0
- package/dist/agents/codemie-code/agent.js.map +1 -1
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +43 -16
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts +1 -0
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +49 -15
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/types.d.ts +8 -0
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts +7 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude-acp.plugin.js +10 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin-installer.d.ts +11 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin-installer.js +32 -0
- package/dist/agents/plugins/claude/claude.plugin-installer.js.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +4 -4
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/agents/plugins/claude/plugin/hooks/hooks.json +10 -0
- package/dist/agents/plugins/claude/plugin/hooks/hooks.windows.json +98 -0
- package/dist/agents/plugins/claude/plugin/scripts/bash/rtk-auto-wrapper.sh +81 -0
- package/dist/agents/plugins/claude/plugin/scripts/bash/rtk-baseline.sh +39 -0
- package/dist/agents/plugins/claude/sounds-installer.d.ts.map +1 -1
- package/dist/agents/plugins/claude/sounds-installer.js +0 -4
- package/dist/agents/plugins/claude/sounds-installer.js.map +1 -1
- package/dist/agents/plugins/codemie-code-hooks/index.d.ts +3 -0
- package/dist/agents/plugins/codemie-code-hooks/index.d.ts.map +1 -0
- package/dist/agents/plugins/codemie-code-hooks/index.js +3 -0
- package/dist/agents/plugins/codemie-code-hooks/index.js.map +1 -0
- package/dist/agents/plugins/codemie-code-hooks/inject-hooks.d.ts +22 -0
- package/dist/agents/plugins/codemie-code-hooks/inject-hooks.d.ts.map +1 -0
- package/dist/agents/plugins/codemie-code-hooks/inject-hooks.js +64 -0
- package/dist/agents/plugins/codemie-code-hooks/inject-hooks.js.map +1 -0
- package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.d.ts +15 -0
- package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.d.ts.map +1 -0
- package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.js +522 -0
- package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.js.map +1 -0
- package/dist/agents/plugins/codemie-code.plugin.d.ts +5 -2
- package/dist/agents/plugins/codemie-code.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/codemie-code.plugin.js +202 -37
- package/dist/agents/plugins/codemie-code.plugin.js.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.js +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts +2 -0
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/opencode-message-types.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode-model-configs.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/opencode-model-configs.js +89 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode.paths.d.ts +16 -1
- package/dist/agents/plugins/opencode/opencode.paths.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/opencode.paths.js +43 -5
- package/dist/agents/plugins/opencode/opencode.paths.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/opencode.plugin.js +30 -2
- package/dist/agents/plugins/opencode/opencode.plugin.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode.session.d.ts +5 -0
- package/dist/agents/plugins/opencode/opencode.session.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/opencode.session.js +99 -2
- package/dist/agents/plugins/opencode/opencode.session.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode.sqlite-reader.d.ts +59 -0
- package/dist/agents/plugins/opencode/opencode.sqlite-reader.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.sqlite-reader.js +200 -0
- package/dist/agents/plugins/opencode/opencode.sqlite-reader.js.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts +3 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts.map +1 -1
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js +35 -13
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js.map +1 -1
- package/dist/cli/commands/analytics/data-loader.js +1 -1
- package/dist/cli/commands/analytics/data-loader.js.map +1 -1
- package/dist/cli/commands/doctor/checks/JWTAuthCheck.d.ts +9 -0
- package/dist/cli/commands/doctor/checks/JWTAuthCheck.d.ts.map +1 -0
- package/dist/cli/commands/doctor/checks/JWTAuthCheck.js +113 -0
- package/dist/cli/commands/doctor/checks/JWTAuthCheck.js.map +1 -0
- package/dist/cli/commands/doctor/checks/index.d.ts +1 -0
- package/dist/cli/commands/doctor/checks/index.d.ts.map +1 -1
- package/dist/cli/commands/doctor/checks/index.js +1 -0
- package/dist/cli/commands/doctor/checks/index.js.map +1 -1
- package/dist/cli/commands/doctor/index.d.ts.map +1 -1
- package/dist/cli/commands/doctor/index.js +93 -88
- package/dist/cli/commands/doctor/index.js.map +1 -1
- package/dist/cli/commands/hook.js +5 -5
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/test-metrics.d.ts +17 -0
- package/dist/cli/commands/test-metrics.d.ts.map +1 -0
- package/dist/cli/commands/test-metrics.js +198 -0
- package/dist/cli/commands/test-metrics.js.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/env/types.d.ts +12 -2
- package/dist/env/types.d.ts.map +1 -1
- package/dist/env/types.js.map +1 -1
- package/dist/providers/core/types.d.ts +22 -1
- package/dist/providers/core/types.d.ts.map +1 -1
- package/dist/providers/core/types.js +12 -1
- package/dist/providers/core/types.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/integration/setup-ui.d.ts.map +1 -1
- package/dist/providers/integration/setup-ui.js +3 -1
- package/dist/providers/integration/setup-ui.js.map +1 -1
- package/dist/providers/plugins/jwt/index.d.ts +9 -0
- package/dist/providers/plugins/jwt/index.d.ts.map +1 -0
- package/dist/providers/plugins/jwt/index.js +13 -0
- package/dist/providers/plugins/jwt/index.js.map +1 -0
- package/dist/providers/plugins/jwt/jwt.setup-steps.d.ts +9 -0
- package/dist/providers/plugins/jwt/jwt.setup-steps.d.ts.map +1 -0
- package/dist/providers/plugins/jwt/jwt.setup-steps.js +153 -0
- package/dist/providers/plugins/jwt/jwt.setup-steps.js.map +1 -0
- package/dist/providers/plugins/jwt/jwt.template.d.ts +12 -0
- package/dist/providers/plugins/jwt/jwt.template.d.ts.map +1 -0
- package/dist/providers/plugins/jwt/jwt.template.js +55 -0
- package/dist/providers/plugins/jwt/jwt.template.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +3 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js +5 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.d.ts +16 -0
- package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.js +53 -0
- package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.d.ts +25 -0
- package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.js +74 -0
- package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.js +13 -2
- package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js +6 -3
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts +2 -2
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/proxy-types.d.ts +2 -0
- package/dist/providers/plugins/sso/proxy/proxy-types.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts +4 -0
- package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.js +39 -10
- package/dist/providers/plugins/sso/proxy/sso.proxy.js.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.d.ts +38 -8
- package/dist/providers/plugins/sso/sso.http-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +83 -85
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.models.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.models.js +3 -3
- package/dist/providers/plugins/sso/sso.models.js.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js +4 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
- package/dist/providers/plugins/sso/sso.template.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.template.js +7 -0
- package/dist/providers/plugins/sso/sso.template.js.map +1 -1
- package/dist/utils/paths.d.ts +1 -1
- package/dist/utils/paths.js +1 -1
- package/dist/utils/security.d.ts +18 -1
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +102 -0
- package/dist/utils/security.js.map +1 -1
- package/package.json +1 -1
- package/scripts/copy-mr-skill-to-global.ts +0 -252
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Hooks Plugin Source
|
|
3
|
+
*
|
|
4
|
+
* Contains the OpenCode plugin TypeScript source as a string constant.
|
|
5
|
+
* At runtime this is written to a temp file and loaded by the OpenCode binary.
|
|
6
|
+
*
|
|
7
|
+
* The plugin reads hooks configuration from the OPENCODE_HOOKS environment variable
|
|
8
|
+
* (Anthropic/Claude Code format) and maps them to OpenCode plugin lifecycle hooks.
|
|
9
|
+
*
|
|
10
|
+
* Why a string constant: The plugin uses `import type { Plugin } from "@opencode-ai/plugin"`
|
|
11
|
+
* which doesn't exist in codemie-code's dependencies. Embedding as a string avoids
|
|
12
|
+
* TypeScript compilation issues. Bun strips the type import at runtime.
|
|
13
|
+
*/
|
|
14
|
+
export const SHELL_HOOKS_PLUGIN_SOURCE = `
|
|
15
|
+
import type { Plugin } from "@opencode-ai/plugin";
|
|
16
|
+
import { execSync, spawn } from "child_process";
|
|
17
|
+
import { readFileSync, existsSync } from "fs";
|
|
18
|
+
import { join } from "path";
|
|
19
|
+
|
|
20
|
+
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
interface HookConfig {
|
|
23
|
+
type: "command" | "prompt" | "agent";
|
|
24
|
+
command?: string;
|
|
25
|
+
timeout?: number; // seconds
|
|
26
|
+
async?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface HookMatcherEntry {
|
|
30
|
+
matcher?: string;
|
|
31
|
+
hooks: HookConfig[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type HookEventName =
|
|
35
|
+
| "PreToolUse"
|
|
36
|
+
| "PostToolUse"
|
|
37
|
+
| "UserPromptSubmit"
|
|
38
|
+
| "PermissionRequest"
|
|
39
|
+
| "PreCompact"
|
|
40
|
+
| "SessionStart"
|
|
41
|
+
| "SessionEnd"
|
|
42
|
+
| "Stop"
|
|
43
|
+
| "Notification";
|
|
44
|
+
|
|
45
|
+
interface HooksConfig {
|
|
46
|
+
hooks?: Partial<Record<HookEventName, HookMatcherEntry[]>>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface HookStdinPayload {
|
|
50
|
+
hook_event_name: string;
|
|
51
|
+
session_id: string;
|
|
52
|
+
cwd: string;
|
|
53
|
+
permission_mode: string;
|
|
54
|
+
transcript_path: string;
|
|
55
|
+
tool_name?: string;
|
|
56
|
+
tool_input?: Record<string, unknown>;
|
|
57
|
+
tool_output?: string;
|
|
58
|
+
prompt?: string;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ─── Matcher (ported from codemie-code src/hooks/matcher.ts) ─────────────────
|
|
63
|
+
|
|
64
|
+
function matchesPattern(pattern: string, toolName: string): boolean {
|
|
65
|
+
try {
|
|
66
|
+
if (!pattern || pattern === "*") return true;
|
|
67
|
+
if (/[|[\\]{}()]/.test(pattern)) {
|
|
68
|
+
try {
|
|
69
|
+
return new RegExp("^(" + pattern + ")$").test(toolName);
|
|
70
|
+
} catch {
|
|
71
|
+
return pattern === toolName;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return pattern === toolName;
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── Config Loading ──────────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
function loadHooksConfig(): HooksConfig {
|
|
83
|
+
// Priority 1: OPENCODE_HOOKS env var (set by codemie-code)
|
|
84
|
+
const envHooks = process.env.OPENCODE_HOOKS;
|
|
85
|
+
if (envHooks) {
|
|
86
|
+
try {
|
|
87
|
+
const parsed = JSON.parse(envHooks);
|
|
88
|
+
if (parsed.hooks && Object.keys(parsed.hooks).length > 0) {
|
|
89
|
+
return parsed as HooksConfig;
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// Fall through to file-based config
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Priority 2: .opencode/hooks.json in project directory
|
|
97
|
+
const projectDir = process.env.OPENCODE_PROJECT_DIR || process.cwd();
|
|
98
|
+
const hooksFile = join(projectDir, ".opencode", "hooks.json");
|
|
99
|
+
if (existsSync(hooksFile)) {
|
|
100
|
+
try {
|
|
101
|
+
const content = readFileSync(hooksFile, "utf-8");
|
|
102
|
+
const parsed = JSON.parse(content);
|
|
103
|
+
if (parsed.hooks) return parsed as HooksConfig;
|
|
104
|
+
} catch {
|
|
105
|
+
// Ignore parse errors
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { hooks: {} };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ─── Hook Resolution ─────────────────────────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
function getMatchingCommands(
|
|
115
|
+
config: HooksConfig,
|
|
116
|
+
event: HookEventName,
|
|
117
|
+
toolName?: string,
|
|
118
|
+
): Array<{ command: string; timeout: number; isAsync: boolean }> {
|
|
119
|
+
const matchers = config.hooks?.[event];
|
|
120
|
+
if (!matchers || matchers.length === 0) return [];
|
|
121
|
+
|
|
122
|
+
const result: Array<{ command: string; timeout: number; isAsync: boolean }> = [];
|
|
123
|
+
|
|
124
|
+
for (const entry of matchers) {
|
|
125
|
+
const pattern = entry.matcher || "*";
|
|
126
|
+
const shouldMatch = !toolName || matchesPattern(pattern, toolName);
|
|
127
|
+
if (!shouldMatch) continue;
|
|
128
|
+
|
|
129
|
+
for (const hook of entry.hooks) {
|
|
130
|
+
// Only support "command" type — skip "prompt" and "agent"
|
|
131
|
+
if (hook.type !== "command" || !hook.command) continue;
|
|
132
|
+
result.push({
|
|
133
|
+
command: hook.command,
|
|
134
|
+
timeout: (hook.timeout || 60) * 1000, // seconds → ms
|
|
135
|
+
isAsync: hook.async === true,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ─── Shell Execution ─────────────────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
function buildEnvVars(sessionId: string, event: string): Record<string, string> {
|
|
146
|
+
const projectDir = process.env.OPENCODE_PROJECT_DIR || process.cwd();
|
|
147
|
+
return {
|
|
148
|
+
OPENCODE_PROJECT_DIR: projectDir,
|
|
149
|
+
OPENCODE_SESSION_ID: sessionId,
|
|
150
|
+
OPENCODE_HOOK_EVENT: event,
|
|
151
|
+
CLAUDE_PROJECT_DIR: projectDir, // Anthropic alias
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface ExecResult {
|
|
156
|
+
stdout: string;
|
|
157
|
+
stderr: string;
|
|
158
|
+
exitCode: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function execCommand(
|
|
162
|
+
command: string,
|
|
163
|
+
stdin: string,
|
|
164
|
+
env: Record<string, string>,
|
|
165
|
+
timeout: number,
|
|
166
|
+
): ExecResult {
|
|
167
|
+
try {
|
|
168
|
+
const stdout = execSync(command, {
|
|
169
|
+
input: stdin,
|
|
170
|
+
timeout,
|
|
171
|
+
env: { ...process.env, ...env },
|
|
172
|
+
encoding: "utf-8",
|
|
173
|
+
maxBuffer: 1024 * 1024,
|
|
174
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
175
|
+
});
|
|
176
|
+
return { stdout: stdout || "", stderr: "", exitCode: 0 };
|
|
177
|
+
} catch (err: any) {
|
|
178
|
+
return {
|
|
179
|
+
stdout: err.stdout || "",
|
|
180
|
+
stderr: err.stderr || "",
|
|
181
|
+
exitCode: typeof err.status === "number" ? err.status : 1,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function execCommandAsync(
|
|
187
|
+
command: string,
|
|
188
|
+
stdin: string,
|
|
189
|
+
env: Record<string, string>,
|
|
190
|
+
): void {
|
|
191
|
+
const child = spawn("sh", ["-c", command], {
|
|
192
|
+
env: { ...process.env, ...env },
|
|
193
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
194
|
+
detached: true,
|
|
195
|
+
});
|
|
196
|
+
if (child.stdin) {
|
|
197
|
+
child.stdin.write(stdin);
|
|
198
|
+
child.stdin.end();
|
|
199
|
+
}
|
|
200
|
+
child.unref();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ─── Response Parsing ────────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
interface ParsedResponse {
|
|
206
|
+
blocked: boolean;
|
|
207
|
+
reason?: string;
|
|
208
|
+
updatedInput?: Record<string, unknown>;
|
|
209
|
+
permissionDecision?: "allow" | "deny" | "ask";
|
|
210
|
+
additionalContext?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function parseResponse(
|
|
214
|
+
result: ExecResult,
|
|
215
|
+
event: HookEventName,
|
|
216
|
+
): ParsedResponse {
|
|
217
|
+
// Exit code 2 = block
|
|
218
|
+
if (result.exitCode === 2) {
|
|
219
|
+
const reason = [result.stderr, result.stdout.trim()].filter(Boolean).join("\\n");
|
|
220
|
+
return { blocked: true, reason: reason || "Hook blocked execution (exit code 2)" };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Non-zero, non-2 = non-blocking error (allow)
|
|
224
|
+
if (result.exitCode !== 0) {
|
|
225
|
+
return { blocked: false };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Parse stdout JSON
|
|
229
|
+
const trimmed = result.stdout.trim();
|
|
230
|
+
if (!trimmed) return { blocked: false };
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const json = JSON.parse(trimmed);
|
|
234
|
+
|
|
235
|
+
// PreToolUse: check for hookSpecificOutput.updatedInput or plain object → merge into args
|
|
236
|
+
if (event === "PreToolUse") {
|
|
237
|
+
const updated = json.hookSpecificOutput?.updatedInput || json.updatedInput;
|
|
238
|
+
if (updated && typeof updated === "object") {
|
|
239
|
+
return { blocked: false, updatedInput: updated };
|
|
240
|
+
}
|
|
241
|
+
// If it's a plain object without known keys, treat as updatedInput
|
|
242
|
+
if (typeof json === "object" && !json.hookSpecificOutput && !json.decision) {
|
|
243
|
+
return { blocked: false, updatedInput: json };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// PermissionRequest: check for permissionDecision
|
|
248
|
+
if (event === "PermissionRequest") {
|
|
249
|
+
const decision =
|
|
250
|
+
json.hookSpecificOutput?.permissionDecision || json.permissionDecision;
|
|
251
|
+
if (decision && ["allow", "deny", "ask"].includes(decision)) {
|
|
252
|
+
return { blocked: false, permissionDecision: decision };
|
|
253
|
+
}
|
|
254
|
+
// Plain string
|
|
255
|
+
if (typeof json === "string" && ["allow", "deny", "ask"].includes(json)) {
|
|
256
|
+
return { blocked: false, permissionDecision: json };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// PreCompact: additionalContext
|
|
261
|
+
if (event === "PreCompact") {
|
|
262
|
+
const context = json.additionalContext || json.context;
|
|
263
|
+
if (typeof context === "string") {
|
|
264
|
+
return { blocked: false, additionalContext: context };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return { blocked: false };
|
|
269
|
+
} catch {
|
|
270
|
+
// Non-JSON output — treat as informational
|
|
271
|
+
return { blocked: false };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ─── Plugin Definition ───────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
const config = loadHooksConfig();
|
|
278
|
+
const hasHooks = config.hooks && Object.keys(config.hooks).length > 0;
|
|
279
|
+
|
|
280
|
+
const plugin: Plugin = {
|
|
281
|
+
name: "shell-hooks",
|
|
282
|
+
...(hasHooks
|
|
283
|
+
? {
|
|
284
|
+
hooks: {
|
|
285
|
+
// PreToolUse → tool.execute.before (blocking)
|
|
286
|
+
tool: {
|
|
287
|
+
execute: {
|
|
288
|
+
before: async (input) => {
|
|
289
|
+
const commands = getMatchingCommands(config, "PreToolUse", input.tool);
|
|
290
|
+
if (commands.length === 0) return input;
|
|
291
|
+
|
|
292
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
293
|
+
const env = buildEnvVars(sessionId, "PreToolUse");
|
|
294
|
+
const payload: HookStdinPayload = {
|
|
295
|
+
hook_event_name: "PreToolUse",
|
|
296
|
+
session_id: sessionId,
|
|
297
|
+
cwd: process.cwd(),
|
|
298
|
+
permission_mode: "default",
|
|
299
|
+
transcript_path: "",
|
|
300
|
+
tool_name: input.tool,
|
|
301
|
+
tool_input: input.args as Record<string, unknown>,
|
|
302
|
+
};
|
|
303
|
+
const stdin = JSON.stringify(payload);
|
|
304
|
+
|
|
305
|
+
let mergedInput = { ...input };
|
|
306
|
+
for (const cmd of commands) {
|
|
307
|
+
if (cmd.isAsync) {
|
|
308
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const result = execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
312
|
+
const parsed = parseResponse(result, "PreToolUse");
|
|
313
|
+
if (parsed.blocked) {
|
|
314
|
+
throw new Error(parsed.reason || "Hook blocked tool execution");
|
|
315
|
+
}
|
|
316
|
+
if (parsed.updatedInput) {
|
|
317
|
+
mergedInput = {
|
|
318
|
+
...mergedInput,
|
|
319
|
+
args: { ...(mergedInput.args as Record<string, unknown>), ...parsed.updatedInput },
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return mergedInput;
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
// PostToolUse → tool.execute.after (fire-and-forget)
|
|
327
|
+
after: async (output) => {
|
|
328
|
+
const commands = getMatchingCommands(config, "PostToolUse", output.tool);
|
|
329
|
+
if (commands.length === 0) return output;
|
|
330
|
+
|
|
331
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
332
|
+
const env = buildEnvVars(sessionId, "PostToolUse");
|
|
333
|
+
const payload: HookStdinPayload = {
|
|
334
|
+
hook_event_name: "PostToolUse",
|
|
335
|
+
session_id: sessionId,
|
|
336
|
+
cwd: process.cwd(),
|
|
337
|
+
permission_mode: "default",
|
|
338
|
+
transcript_path: "",
|
|
339
|
+
tool_name: output.tool,
|
|
340
|
+
tool_input: output.args as Record<string, unknown>,
|
|
341
|
+
tool_output: typeof output.result === "string" ? output.result : JSON.stringify(output.result),
|
|
342
|
+
};
|
|
343
|
+
const stdin = JSON.stringify(payload);
|
|
344
|
+
|
|
345
|
+
for (const cmd of commands) {
|
|
346
|
+
if (cmd.isAsync) {
|
|
347
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
352
|
+
} catch {
|
|
353
|
+
// PostToolUse is fire-and-forget
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return output;
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
// UserPromptSubmit → chat.message (blocking)
|
|
362
|
+
chat: {
|
|
363
|
+
message: async (input) => {
|
|
364
|
+
const commands = getMatchingCommands(config, "UserPromptSubmit");
|
|
365
|
+
if (commands.length === 0) return input;
|
|
366
|
+
|
|
367
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
368
|
+
const env = buildEnvVars(sessionId, "UserPromptSubmit");
|
|
369
|
+
const payload: HookStdinPayload = {
|
|
370
|
+
hook_event_name: "UserPromptSubmit",
|
|
371
|
+
session_id: sessionId,
|
|
372
|
+
cwd: process.cwd(),
|
|
373
|
+
permission_mode: "default",
|
|
374
|
+
transcript_path: "",
|
|
375
|
+
prompt: Array.isArray(input.parts)
|
|
376
|
+
? input.parts
|
|
377
|
+
.filter((p: any) => p.type === "text")
|
|
378
|
+
.map((p: any) => p.text)
|
|
379
|
+
.join("\\n")
|
|
380
|
+
: String(input.parts),
|
|
381
|
+
};
|
|
382
|
+
const stdin = JSON.stringify(payload);
|
|
383
|
+
|
|
384
|
+
for (const cmd of commands) {
|
|
385
|
+
if (cmd.isAsync) {
|
|
386
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const result = execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
390
|
+
const parsed = parseResponse(result, "UserPromptSubmit");
|
|
391
|
+
if (parsed.blocked) {
|
|
392
|
+
// Clear message parts to block submission
|
|
393
|
+
return { ...input, parts: [] };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return input;
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
// PermissionRequest → permission.ask (blocking)
|
|
401
|
+
permission: {
|
|
402
|
+
ask: async (input) => {
|
|
403
|
+
const commands = getMatchingCommands(config, "PermissionRequest", input.tool);
|
|
404
|
+
if (commands.length === 0) return input;
|
|
405
|
+
|
|
406
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
407
|
+
const env = buildEnvVars(sessionId, "PermissionRequest");
|
|
408
|
+
const payload: HookStdinPayload = {
|
|
409
|
+
hook_event_name: "PermissionRequest",
|
|
410
|
+
session_id: sessionId,
|
|
411
|
+
cwd: process.cwd(),
|
|
412
|
+
permission_mode: "default",
|
|
413
|
+
transcript_path: "",
|
|
414
|
+
tool_name: input.tool,
|
|
415
|
+
tool_input: input.args as Record<string, unknown>,
|
|
416
|
+
};
|
|
417
|
+
const stdin = JSON.stringify(payload);
|
|
418
|
+
|
|
419
|
+
for (const cmd of commands) {
|
|
420
|
+
if (cmd.isAsync) {
|
|
421
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
const result = execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
425
|
+
const parsed = parseResponse(result, "PermissionRequest");
|
|
426
|
+
if (parsed.permissionDecision === "allow") {
|
|
427
|
+
return { ...input, allowed: true };
|
|
428
|
+
}
|
|
429
|
+
if (parsed.permissionDecision === "deny") {
|
|
430
|
+
return { ...input, allowed: false };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return input;
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
// PreCompact → experimental.session.compacting (non-blocking)
|
|
438
|
+
experimental: {
|
|
439
|
+
session: {
|
|
440
|
+
compacting: async (input) => {
|
|
441
|
+
const commands = getMatchingCommands(config, "PreCompact");
|
|
442
|
+
if (commands.length === 0) return input;
|
|
443
|
+
|
|
444
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
445
|
+
const env = buildEnvVars(sessionId, "PreCompact");
|
|
446
|
+
const payload: HookStdinPayload = {
|
|
447
|
+
hook_event_name: "PreCompact",
|
|
448
|
+
session_id: sessionId,
|
|
449
|
+
cwd: process.cwd(),
|
|
450
|
+
permission_mode: "default",
|
|
451
|
+
transcript_path: "",
|
|
452
|
+
};
|
|
453
|
+
const stdin = JSON.stringify(payload);
|
|
454
|
+
|
|
455
|
+
for (const cmd of commands) {
|
|
456
|
+
if (cmd.isAsync) {
|
|
457
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
const result = execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
462
|
+
const parsed = parseResponse(result, "PreCompact");
|
|
463
|
+
if (parsed.additionalContext) {
|
|
464
|
+
return {
|
|
465
|
+
...input,
|
|
466
|
+
context: ((input as any).context || "") + "\\n" + parsed.additionalContext,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
} catch {
|
|
470
|
+
// Non-blocking
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return input;
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
// SessionStart/SessionEnd/Stop/Notification → event (non-blocking)
|
|
479
|
+
event: async (input) => {
|
|
480
|
+
let hookEvent: HookEventName | undefined;
|
|
481
|
+
const eventType = (input as any).type || (input as any).event;
|
|
482
|
+
if (eventType === "session.created") hookEvent = "SessionStart";
|
|
483
|
+
else if (eventType === "session.deleted") hookEvent = "SessionEnd";
|
|
484
|
+
else if (eventType === "session.idle") hookEvent = "Stop";
|
|
485
|
+
else if (eventType === "session.error") hookEvent = "Notification";
|
|
486
|
+
|
|
487
|
+
if (!hookEvent) return;
|
|
488
|
+
|
|
489
|
+
const commands = getMatchingCommands(config, hookEvent);
|
|
490
|
+
if (commands.length === 0) return;
|
|
491
|
+
|
|
492
|
+
const sessionId = process.env.OPENCODE_SESSION_ID || "";
|
|
493
|
+
const env = buildEnvVars(sessionId, hookEvent);
|
|
494
|
+
const payload: HookStdinPayload = {
|
|
495
|
+
hook_event_name: hookEvent,
|
|
496
|
+
session_id: sessionId,
|
|
497
|
+
cwd: process.cwd(),
|
|
498
|
+
permission_mode: "default",
|
|
499
|
+
transcript_path: "",
|
|
500
|
+
};
|
|
501
|
+
const stdin = JSON.stringify(payload);
|
|
502
|
+
|
|
503
|
+
for (const cmd of commands) {
|
|
504
|
+
if (cmd.isAsync) {
|
|
505
|
+
execCommandAsync(cmd.command, stdin, env);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
execCommand(cmd.command, stdin, env, cmd.timeout);
|
|
510
|
+
} catch {
|
|
511
|
+
// Event hooks are non-blocking
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
}
|
|
517
|
+
: {}),
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
export default plugin;
|
|
521
|
+
`;
|
|
522
|
+
//# sourceMappingURL=shell-hooks-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-hooks-source.js","sourceRoot":"","sources":["../../../../src/agents/plugins/codemie-code-hooks/shell-hooks-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2fxC,CAAC"}
|
|
@@ -37,8 +37,11 @@ export declare class CodeMieCodePlugin extends BaseAgentAdapter {
|
|
|
37
37
|
private sessionAdapter;
|
|
38
38
|
constructor();
|
|
39
39
|
/**
|
|
40
|
-
* Check if the
|
|
41
|
-
*
|
|
40
|
+
* Check if the agent is available.
|
|
41
|
+
* Returns true if the whitelabel binary is present, OR if only the built-in
|
|
42
|
+
* CodeMieCode handler is available (always the case when isBuiltIn: true).
|
|
43
|
+
* Warns at log level when the binary is absent so the condition is surfaced
|
|
44
|
+
* by doctor checks and debug sessions rather than silently swallowed.
|
|
42
45
|
*/
|
|
43
46
|
isInstalled(): Promise<boolean>;
|
|
44
47
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codemie-code.plugin.d.ts","sourceRoot":"","sources":["../../../src/agents/plugins/codemie-code.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAMnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"codemie-code.plugin.d.ts","sourceRoot":"","sources":["../../../src/agents/plugins/codemie-code.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAMnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAU1F;;GAEG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAsNjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAqRvC,CAAC;AAEF;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,gBAAgB;IACrD,OAAO,CAAC,cAAc,CAAiB;;IAOvC;;;;;;OAMG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAsBrC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;;;;;OAOG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBhC;;OAEG;IACH,iBAAiB,IAAI,cAAc;IAInC;;OAEG;IACH,qBAAqB,IAAI,sBAAsB,GAAG,SAAS;CAG5D"}
|