@codemieai/code 0.0.40 → 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.
Files changed (211) hide show
  1. package/README.md +5 -6
  2. package/bin/codemie-opencode.js +8 -1
  3. package/dist/agents/codemie-code/agent.d.ts.map +1 -1
  4. package/dist/agents/codemie-code/agent.js +5 -0
  5. package/dist/agents/codemie-code/agent.js.map +1 -1
  6. package/dist/agents/codemie-code/skills/index.d.ts +4 -0
  7. package/dist/agents/codemie-code/skills/index.d.ts.map +1 -1
  8. package/dist/agents/codemie-code/skills/index.js +4 -0
  9. package/dist/agents/codemie-code/skills/index.js.map +1 -1
  10. package/dist/agents/codemie-code/skills/sync/SkillSync.d.ts +52 -0
  11. package/dist/agents/codemie-code/skills/sync/SkillSync.d.ts.map +1 -0
  12. package/dist/agents/codemie-code/skills/sync/SkillSync.js +165 -0
  13. package/dist/agents/codemie-code/skills/sync/SkillSync.js.map +1 -0
  14. package/dist/agents/core/AgentCLI.d.ts.map +1 -1
  15. package/dist/agents/core/AgentCLI.js +38 -8
  16. package/dist/agents/core/AgentCLI.js.map +1 -1
  17. package/dist/agents/core/BaseAgentAdapter.d.ts +11 -1
  18. package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
  19. package/dist/agents/core/BaseAgentAdapter.js +175 -18
  20. package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
  21. package/dist/agents/core/types.d.ts +18 -0
  22. package/dist/agents/core/types.d.ts.map +1 -1
  23. package/dist/agents/plugins/claude/claude-acp.plugin.d.ts +7 -0
  24. package/dist/agents/plugins/claude/claude-acp.plugin.d.ts.map +1 -1
  25. package/dist/agents/plugins/claude/claude-acp.plugin.js +10 -0
  26. package/dist/agents/plugins/claude/claude-acp.plugin.js.map +1 -1
  27. package/dist/agents/plugins/claude/claude.plugin-installer.d.ts +11 -0
  28. package/dist/agents/plugins/claude/claude.plugin-installer.d.ts.map +1 -1
  29. package/dist/agents/plugins/claude/claude.plugin-installer.js +32 -0
  30. package/dist/agents/plugins/claude/claude.plugin-installer.js.map +1 -1
  31. package/dist/agents/plugins/claude/claude.plugin.d.ts +1 -8
  32. package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
  33. package/dist/agents/plugins/claude/claude.plugin.js +96 -101
  34. package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
  35. package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
  36. package/dist/agents/plugins/claude/plugin/codemie-statusline.mjs +42 -0
  37. package/dist/agents/plugins/claude/plugin/hooks/hooks.json +10 -0
  38. package/dist/agents/plugins/claude/plugin/hooks/hooks.windows.json +98 -0
  39. package/dist/agents/plugins/claude/plugin/scripts/bash/rtk-auto-wrapper.sh +81 -0
  40. package/dist/agents/plugins/claude/plugin/scripts/bash/rtk-baseline.sh +39 -0
  41. package/dist/agents/plugins/claude/sounds-installer.d.ts.map +1 -1
  42. package/dist/agents/plugins/claude/sounds-installer.js +0 -4
  43. package/dist/agents/plugins/claude/sounds-installer.js.map +1 -1
  44. package/dist/agents/plugins/codemie-code-binary.d.ts +17 -0
  45. package/dist/agents/plugins/codemie-code-binary.d.ts.map +1 -0
  46. package/dist/agents/plugins/codemie-code-binary.js +94 -0
  47. package/dist/agents/plugins/codemie-code-binary.js.map +1 -0
  48. package/dist/agents/plugins/codemie-code-hooks/index.d.ts +3 -0
  49. package/dist/agents/plugins/codemie-code-hooks/index.d.ts.map +1 -0
  50. package/dist/agents/plugins/codemie-code-hooks/index.js +3 -0
  51. package/dist/agents/plugins/codemie-code-hooks/index.js.map +1 -0
  52. package/dist/agents/plugins/codemie-code-hooks/inject-hooks.d.ts +22 -0
  53. package/dist/agents/plugins/codemie-code-hooks/inject-hooks.d.ts.map +1 -0
  54. package/dist/agents/plugins/codemie-code-hooks/inject-hooks.js +64 -0
  55. package/dist/agents/plugins/codemie-code-hooks/inject-hooks.js.map +1 -0
  56. package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.d.ts +15 -0
  57. package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.d.ts.map +1 -0
  58. package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.js +522 -0
  59. package/dist/agents/plugins/codemie-code-hooks/shell-hooks-source.js.map +1 -0
  60. package/dist/agents/plugins/codemie-code.plugin.d.ts +56 -12
  61. package/dist/agents/plugins/codemie-code.plugin.d.ts.map +1 -1
  62. package/dist/agents/plugins/codemie-code.plugin.js +502 -125
  63. package/dist/agents/plugins/codemie-code.plugin.js.map +1 -1
  64. package/dist/agents/plugins/gemini/gemini.plugin.d.ts +8 -0
  65. package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -1
  66. package/dist/agents/plugins/gemini/gemini.plugin.js +45 -1
  67. package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
  68. package/dist/agents/plugins/opencode/opencode-message-types.d.ts +2 -0
  69. package/dist/agents/plugins/opencode/opencode-message-types.d.ts.map +1 -1
  70. package/dist/agents/plugins/opencode/opencode-message-types.js.map +1 -1
  71. package/dist/agents/plugins/opencode/opencode-model-configs.d.ts +12 -2
  72. package/dist/agents/plugins/opencode/opencode-model-configs.d.ts.map +1 -1
  73. package/dist/agents/plugins/opencode/opencode-model-configs.js +329 -24
  74. package/dist/agents/plugins/opencode/opencode-model-configs.js.map +1 -1
  75. package/dist/agents/plugins/opencode/opencode.paths.d.ts +16 -1
  76. package/dist/agents/plugins/opencode/opencode.paths.d.ts.map +1 -1
  77. package/dist/agents/plugins/opencode/opencode.paths.js +43 -5
  78. package/dist/agents/plugins/opencode/opencode.paths.js.map +1 -1
  79. package/dist/agents/plugins/opencode/opencode.plugin.d.ts.map +1 -1
  80. package/dist/agents/plugins/opencode/opencode.plugin.js +91 -25
  81. package/dist/agents/plugins/opencode/opencode.plugin.js.map +1 -1
  82. package/dist/agents/plugins/opencode/opencode.session.d.ts +5 -0
  83. package/dist/agents/plugins/opencode/opencode.session.d.ts.map +1 -1
  84. package/dist/agents/plugins/opencode/opencode.session.js +99 -2
  85. package/dist/agents/plugins/opencode/opencode.session.js.map +1 -1
  86. package/dist/agents/plugins/opencode/opencode.sqlite-reader.d.ts +59 -0
  87. package/dist/agents/plugins/opencode/opencode.sqlite-reader.d.ts.map +1 -0
  88. package/dist/agents/plugins/opencode/opencode.sqlite-reader.js +200 -0
  89. package/dist/agents/plugins/opencode/opencode.sqlite-reader.js.map +1 -0
  90. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts +3 -0
  91. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts.map +1 -1
  92. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js +35 -13
  93. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js.map +1 -1
  94. package/dist/agents/registry.d.ts.map +1 -1
  95. package/dist/agents/registry.js +8 -7
  96. package/dist/agents/registry.js.map +1 -1
  97. package/dist/cli/commands/analytics/data-loader.js +1 -1
  98. package/dist/cli/commands/analytics/data-loader.js.map +1 -1
  99. package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts.map +1 -1
  100. package/dist/cli/commands/doctor/checks/AgentsCheck.js +5 -2
  101. package/dist/cli/commands/doctor/checks/AgentsCheck.js.map +1 -1
  102. package/dist/cli/commands/doctor/checks/FrameworksCheck.d.ts.map +1 -1
  103. package/dist/cli/commands/doctor/checks/FrameworksCheck.js +5 -2
  104. package/dist/cli/commands/doctor/checks/FrameworksCheck.js.map +1 -1
  105. package/dist/cli/commands/doctor/checks/JWTAuthCheck.d.ts +9 -0
  106. package/dist/cli/commands/doctor/checks/JWTAuthCheck.d.ts.map +1 -0
  107. package/dist/cli/commands/doctor/checks/JWTAuthCheck.js +113 -0
  108. package/dist/cli/commands/doctor/checks/JWTAuthCheck.js.map +1 -0
  109. package/dist/cli/commands/doctor/checks/index.d.ts +1 -0
  110. package/dist/cli/commands/doctor/checks/index.d.ts.map +1 -1
  111. package/dist/cli/commands/doctor/checks/index.js +1 -0
  112. package/dist/cli/commands/doctor/checks/index.js.map +1 -1
  113. package/dist/cli/commands/doctor/index.d.ts.map +1 -1
  114. package/dist/cli/commands/doctor/index.js +2 -1
  115. package/dist/cli/commands/doctor/index.js.map +1 -1
  116. package/dist/cli/commands/hook.d.ts.map +1 -1
  117. package/dist/cli/commands/hook.js +28 -5
  118. package/dist/cli/commands/hook.js.map +1 -1
  119. package/dist/cli/commands/skill.d.ts.map +1 -1
  120. package/dist/cli/commands/skill.js +80 -1
  121. package/dist/cli/commands/skill.js.map +1 -1
  122. package/dist/cli/commands/test-metrics.d.ts +17 -0
  123. package/dist/cli/commands/test-metrics.d.ts.map +1 -0
  124. package/dist/cli/commands/test-metrics.js +198 -0
  125. package/dist/cli/commands/test-metrics.js.map +1 -0
  126. package/dist/cli/index.js +9 -13
  127. package/dist/cli/index.js.map +1 -1
  128. package/dist/env/types.d.ts +12 -2
  129. package/dist/env/types.d.ts.map +1 -1
  130. package/dist/env/types.js.map +1 -1
  131. package/dist/providers/core/types.d.ts +22 -1
  132. package/dist/providers/core/types.d.ts.map +1 -1
  133. package/dist/providers/core/types.js +12 -1
  134. package/dist/providers/core/types.js.map +1 -1
  135. package/dist/providers/index.d.ts +2 -0
  136. package/dist/providers/index.d.ts.map +1 -1
  137. package/dist/providers/index.js +2 -0
  138. package/dist/providers/index.js.map +1 -1
  139. package/dist/providers/integration/setup-ui.d.ts.map +1 -1
  140. package/dist/providers/integration/setup-ui.js +3 -1
  141. package/dist/providers/integration/setup-ui.js.map +1 -1
  142. package/dist/providers/plugins/jwt/index.d.ts +9 -0
  143. package/dist/providers/plugins/jwt/index.d.ts.map +1 -0
  144. package/dist/providers/plugins/jwt/index.js +13 -0
  145. package/dist/providers/plugins/jwt/index.js.map +1 -0
  146. package/dist/providers/plugins/jwt/jwt.setup-steps.d.ts +9 -0
  147. package/dist/providers/plugins/jwt/jwt.setup-steps.d.ts.map +1 -0
  148. package/dist/providers/plugins/jwt/jwt.setup-steps.js +153 -0
  149. package/dist/providers/plugins/jwt/jwt.setup-steps.js.map +1 -0
  150. package/dist/providers/plugins/jwt/jwt.template.d.ts +12 -0
  151. package/dist/providers/plugins/jwt/jwt.template.d.ts.map +1 -0
  152. package/dist/providers/plugins/jwt/jwt.template.js +55 -0
  153. package/dist/providers/plugins/jwt/jwt.template.js.map +1 -0
  154. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +3 -1
  155. package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
  156. package/dist/providers/plugins/sso/proxy/plugins/index.js +5 -1
  157. package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
  158. package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.d.ts +16 -0
  159. package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.d.ts.map +1 -0
  160. package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.js +53 -0
  161. package/dist/providers/plugins/sso/proxy/plugins/jwt-auth.plugin.js.map +1 -0
  162. package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.d.ts +25 -0
  163. package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.d.ts.map +1 -0
  164. package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.js +74 -0
  165. package/dist/providers/plugins/sso/proxy/plugins/request-sanitizer.plugin.js.map +1 -0
  166. package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.d.ts.map +1 -1
  167. package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.js +13 -2
  168. package/dist/providers/plugins/sso/proxy/plugins/sso-auth.plugin.js.map +1 -1
  169. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts.map +1 -1
  170. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js +6 -3
  171. package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js.map +1 -1
  172. package/dist/providers/plugins/sso/proxy/plugins/types.d.ts +2 -2
  173. package/dist/providers/plugins/sso/proxy/plugins/types.d.ts.map +1 -1
  174. package/dist/providers/plugins/sso/proxy/proxy-types.d.ts +2 -0
  175. package/dist/providers/plugins/sso/proxy/proxy-types.d.ts.map +1 -1
  176. package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts +4 -0
  177. package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts.map +1 -1
  178. package/dist/providers/plugins/sso/proxy/sso.proxy.js +39 -10
  179. package/dist/providers/plugins/sso/proxy/sso.proxy.js.map +1 -1
  180. package/dist/providers/plugins/sso/sso.auth.d.ts +3 -1
  181. package/dist/providers/plugins/sso/sso.auth.d.ts.map +1 -1
  182. package/dist/providers/plugins/sso/sso.auth.js +70 -12
  183. package/dist/providers/plugins/sso/sso.auth.js.map +1 -1
  184. package/dist/providers/plugins/sso/sso.http-client.d.ts +38 -8
  185. package/dist/providers/plugins/sso/sso.http-client.d.ts.map +1 -1
  186. package/dist/providers/plugins/sso/sso.http-client.js +83 -85
  187. package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
  188. package/dist/providers/plugins/sso/sso.models.d.ts.map +1 -1
  189. package/dist/providers/plugins/sso/sso.models.js +3 -3
  190. package/dist/providers/plugins/sso/sso.models.js.map +1 -1
  191. package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
  192. package/dist/providers/plugins/sso/sso.setup-steps.js +4 -1
  193. package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
  194. package/dist/providers/plugins/sso/sso.template.d.ts.map +1 -1
  195. package/dist/providers/plugins/sso/sso.template.js +7 -0
  196. package/dist/providers/plugins/sso/sso.template.js.map +1 -1
  197. package/dist/utils/logger.d.ts +1 -0
  198. package/dist/utils/logger.d.ts.map +1 -1
  199. package/dist/utils/logger.js +16 -1
  200. package/dist/utils/logger.js.map +1 -1
  201. package/dist/utils/native-installer.d.ts.map +1 -1
  202. package/dist/utils/native-installer.js +35 -0
  203. package/dist/utils/native-installer.js.map +1 -1
  204. package/dist/utils/paths.d.ts +1 -1
  205. package/dist/utils/paths.js +1 -1
  206. package/dist/utils/security.d.ts +18 -1
  207. package/dist/utils/security.d.ts.map +1 -1
  208. package/dist/utils/security.js +102 -0
  209. package/dist/utils/security.js.map +1 -1
  210. package/package.json +2 -1
  211. 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"}
@@ -1,25 +1,69 @@
1
- import { AgentMetadata, AgentAdapter } from '../core/types.js';
1
+ import type { AgentMetadata } from '../core/types.js';
2
+ import { BaseAgentAdapter } from '../core/BaseAgentAdapter.js';
3
+ import type { SessionAdapter } from '../core/session/BaseSessionAdapter.js';
4
+ import type { BaseExtensionInstaller } from '../core/extension/BaseExtensionInstaller.js';
2
5
  /**
3
6
  * Built-in agent name constant - single source of truth
4
7
  */
5
8
  export declare const BUILTIN_AGENT_NAME = "codemie-code";
6
9
  /**
7
- * CodeMie-Code Plugin Metadata
10
+ * Environment variable contract between the umbrella CLI and whitelabel binary.
11
+ *
12
+ * The umbrella CLI orchestrates everything (proxy, auth, metrics, session sync)
13
+ * and spawns the whitelabel binary as a child process. The whitelabel knows
14
+ * nothing about SSO, cookies, or metrics — it just sees an OpenAI-compatible
15
+ * endpoint at localhost.
16
+ *
17
+ * Flow: BaseAgentAdapter.run() → setupProxy() → beforeRun hook → spawn(binary)
18
+ *
19
+ * | Env Var | Set By | Consumed By | Purpose |
20
+ * |--------------------------|----------------------|----------------------|------------------------------------------------|
21
+ * | OPENCODE_CONFIG_CONTENT | beforeRun hook | Whitelabel config.ts | Full provider config JSON (proxy URL, models) |
22
+ * | OPENCODE_CONFIG | beforeRun (fallback) | Whitelabel config.ts | Temp file path when JSON exceeds env var limit |
23
+ * | OPENCODE_DISABLE_SHARE | beforeRun hook | Whitelabel | Disables share functionality |
24
+ * | CODEMIE_SESSION_ID | BaseAgentAdapter | onSessionEnd hook | Session ID for metrics correlation |
25
+ * | CODEMIE_AGENT | BaseAgentAdapter | Lifecycle helpers | Agent name ('codemie-code') |
26
+ * | CODEMIE_PROVIDER | Config loader | setupProxy() | Provider name (e.g., 'ai-run-sso') |
27
+ * | CODEMIE_BASE_URL | setupProxy() | beforeRun hook | Proxy URL (http://localhost:{port}) |
28
+ * | CODEMIE_MODEL | Config/CLI | beforeRun hook | Selected model ID |
29
+ * | CODEMIE_PROJECT | SSO exportEnvVars | Session metadata | CodeMie project name |
8
30
  */
9
31
  export declare const CodeMieCodePluginMetadata: AgentMetadata;
10
32
  /**
11
- * CodeMie-Code Adapter
12
- * Custom implementation for built-in agent
33
+ * CodeMie Code Plugin
34
+ * Wraps the @codemieai/codemie-opencode binary as the built-in agent
13
35
  */
14
- export declare class CodeMieCodePlugin implements AgentAdapter {
15
- name: string;
16
- displayName: string;
17
- description: string;
36
+ export declare class CodeMieCodePlugin extends BaseAgentAdapter {
37
+ private sessionAdapter;
38
+ constructor();
39
+ /**
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.
45
+ */
46
+ isInstalled(): Promise<boolean>;
47
+ /**
48
+ * Install the whitelabel package globally.
49
+ */
18
50
  install(): Promise<void>;
51
+ /**
52
+ * Uninstall the whitelabel package and its platform-specific binary.
53
+ *
54
+ * npm hoists the platform-specific binary package (e.g.
55
+ * @codemieai/codemie-opencode-darwin-arm64) to the top-level global
56
+ * node_modules. `npm uninstall -g @codemieai/codemie-opencode` only removes
57
+ * the wrapper, leaving the binary as an orphan. We explicitly remove both.
58
+ */
19
59
  uninstall(): Promise<void>;
20
- isInstalled(): Promise<boolean>;
21
- run(args: string[], envOverrides?: Record<string, string>): Promise<void>;
22
- getVersion(): Promise<string | null>;
23
- getMetricsConfig(): import('../core/types.js').AgentMetricsConfig | undefined;
60
+ /**
61
+ * Return session adapter for analytics.
62
+ */
63
+ getSessionAdapter(): SessionAdapter;
64
+ /**
65
+ * No extension installer needed.
66
+ */
67
+ getExtensionInstaller(): BaseExtensionInstaller | undefined;
24
68
  }
25
69
  //# sourceMappingURL=codemie-code.plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codemie-code.plugin.d.ts","sourceRoot":"","sources":["../../../src/agents/plugins/codemie-code.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAW/D;;GAEG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,aA4GvC,CAAC;AAEF;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,IAAI,SAAsB;IAC1B,WAAW,SAAoB;IAC/B,WAAW,SAAsE;IAE3E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCzE,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW1C,gBAAgB,IAAI,OAAO,kBAAkB,EAAE,kBAAkB,GAAG,SAAS;CAI9E"}
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"}