MCPcopy Create free account
hub / github.com/Tencent/teamai-cli / applyOpencodeAgentHook

Function applyOpencodeAgentHook

src/opencode-hooks.ts:260–279  ·  view source on GitHub ↗
(def: {
  slug: string;
  event: string;
  command: string;
  baseDir: string;
  scope: 'project' | 'user';
  matcher?: string;
})

Source from the content-addressed store, hash-verified

258 * Events with no OpenCode equivalent are logged and skipped.
259 */
260export 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. */
282export async function removeOpencodeAgentHook(opts: {

Callers 2

runHookRuleCommandFunction · 0.85

Calls 5

assertSafeSlugFunction · 0.85
resolveOpencodePluginDirFunction · 0.85
ensureDirFunction · 0.85
writeFileFunction · 0.85

Tested by

no test coverage detected