(def: {
slug: string;
event: string;
command: string;
baseDir: string;
scope: 'project' | 'user';
matcher?: string;
})
| 258 | * Events with no OpenCode equivalent are logged and skipped. |
| 259 | */ |
| 260 | export async function applyOpencodeAgentHook(def: { |
| 261 | slug: string; |
| 262 | event: string; |
| 263 | command: string; |
| 264 | baseDir: string; |
| 265 | scope: 'project' | 'user'; |
| 266 | matcher?: string; |
| 267 | }): Promise<void> { |
| 268 | assertSafeSlug(def.slug); |
| 269 | const ocEvent = CLAUDE_TO_OPENCODE_EVENTS[def.event]; |
| 270 | if (!ocEvent) { |
| 271 | log.warn(`OpenCode does not support event "${def.event}" — skipping hook [${def.slug}]`); |
| 272 | return; |
| 273 | } |
| 274 | const dir = resolveOpencodePluginDir(def.baseDir, def.scope); |
| 275 | await ensureDir(dir); |
| 276 | const file = path.join(dir, `teamai-agent-${def.slug}.ts`); |
| 277 | await writeFile(file, buildAgentHookPluginSource(def.slug, ocEvent, def.command, def.matcher)); |
| 278 | log.success(`Installed OpenCode agent hook [${def.slug}] in ${file}`); |
| 279 | } |
| 280 | |
| 281 | /** Remove a server-pushed agent-hook plugin file for OpenCode. */ |
| 282 | export async function removeOpencodeAgentHook(opts: { |
no test coverage detected