feat(hooks): add HTTP hook handler support
Add type: "http" hook support matching Claude Code's HTTP hook specification. HTTP hooks send POST requests with JSON body, support env var interpolation in headers via allowedEnvVars, and configurable timeout. New files: - execute-http-hook.ts: HTTP hook execution with env var interpolation - dispatch-hook.ts: Unified dispatcher for command and HTTP hooks - execute-http-hook.test.ts: 14 tests covering all HTTP hook scenarios Modified files: - types.ts: Added HookHttp interface, HookAction union type - config.ts: Updated to accept HookAction in raw hook matchers - pre-tool-use/post-tool-use/stop/user-prompt-submit/pre-compact: Updated all 5 executors to dispatch HTTP hooks via dispatchHook() - plugin-loader/types.ts: Added "http" to HookEntry type union
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { HookAction } from "./types"
|
||||
import type { CommandResult } from "../../shared/command-executor/execute-hook-command"
|
||||
import { executeHookCommand } from "../../shared"
|
||||
import { executeHttpHook } from "./execute-http-hook"
|
||||
import { DEFAULT_CONFIG } from "./plugin-config"
|
||||
|
||||
export function getHookIdentifier(hook: HookAction): string {
|
||||
if (hook.type === "http") return hook.url
|
||||
return hook.command.split("/").pop() || hook.command
|
||||
}
|
||||
|
||||
export async function dispatchHook(
|
||||
hook: HookAction,
|
||||
stdinJson: string,
|
||||
cwd: string
|
||||
): Promise<CommandResult> {
|
||||
if (hook.type === "http") {
|
||||
return executeHttpHook(hook, stdinJson)
|
||||
}
|
||||
|
||||
return executeHookCommand(
|
||||
hook.command,
|
||||
stdinJson,
|
||||
cwd,
|
||||
{ forceZsh: DEFAULT_CONFIG.forceZsh, zshPath: DEFAULT_CONFIG.zshPath }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user