MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / invokeHook

Function invokeHook

packages/opencode-atomic-hooks/src/cli.ts:60–103  ·  view source on GitHub ↗
(
  $: Shell,
  verb: HookVerb,
  payload: HookPayload,
  directory: string,
)

Source from the content-addressed store, hash-verified

58 * @returns A `HookResult` describing the outcome (never throws)
59 */
60export async function invokeHook(
61 $: Shell,
62 verb: HookVerb,
63 payload: HookPayload,
64 directory: string,
65): Promise<HookResult> {
66 const start = performance.now();
67 const json = JSON.stringify(payload);
68
69 try {
70 const result =
71 await $`echo ${json} | ${ATOMIC_CMD} agent hooks opencode ${verb}`
72 .cwd(directory)
73 .quiet()
74 .nothrow();
75
76 const duration = Math.round(performance.now() - start);
77 const ok = result.exitCode === 0;
78 const stderr = result.stderr.toString().trim();
79 const stdout = result.stdout.toString().trim();
80
81 if (!ok) {
82 return {
83 ok: false,
84 verb,
85 exitCode: result.exitCode,
86 error: stderr || `exit code ${result.exitCode}`,
87 duration,
88 };
89 }
90
91 return { ok: true, verb, exitCode: 0, duration, stderr, stdout };
92 } catch (err) {
93 const duration = Math.round(performance.now() - start);
94 const message = err instanceof Error ? err.message : String(err);
95
96 return {
97 ok: false,
98 verb,
99 error: message,
100 duration,
101 };
102 }
103}
104
105// =============================================================================
106// Availability Check

Callers 7

createBeforeToolHandlerFunction · 0.90
createAfterToolHandlerFunction · 0.90
createChatHandlerFunction · 0.90
handleSessionCreatedFunction · 0.90
handleSessionIdleFunction · 0.90
handleSessionDeletedFunction · 0.90
handleSessionErrorFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected