implement PreTooUse PostToolUse PostToolUseFailure and test

This commit is contained in:
DennisYu07 2026-03-04 08:47:47 -08:00
parent f0cc28f80f
commit a5212123dc
12 changed files with 1539 additions and 79 deletions

View file

@ -17,8 +17,8 @@ import { createHookOutput } from './types.js';
import type {
SessionStartSource,
SessionEndReason,
PermissionMode,
AgentType,
PermissionMode,
} from './types.js';
const debugLogger = createDebugLogger('TRUSTED_HOOKS');
@ -132,4 +132,70 @@ export class HookSystem {
? createHookOutput('SessionEnd', result.finalOutput)
: undefined;
}
/**
* Fire a PreToolUse event - called before tool execution
*/
async firePreToolUseEvent(
toolName: string,
toolInput: Record<string, unknown>,
toolUseId: string,
permissionMode: PermissionMode,
): Promise<DefaultHookOutput | undefined> {
const result = await this.hookEventHandler.firePreToolUseEvent(
toolName,
toolInput,
toolUseId,
permissionMode,
);
return result.finalOutput
? createHookOutput('PreToolUse', result.finalOutput)
: undefined;
}
/**
* Fire a PostToolUse event - called after successful tool execution
*/
async firePostToolUseEvent(
toolName: string,
toolInput: Record<string, unknown>,
toolResponse: Record<string, unknown>,
toolUseId: string,
permissionMode: PermissionMode,
): Promise<DefaultHookOutput | undefined> {
const result = await this.hookEventHandler.firePostToolUseEvent(
toolName,
toolInput,
toolResponse,
toolUseId,
permissionMode,
);
return result.finalOutput
? createHookOutput('PostToolUse', result.finalOutput)
: undefined;
}
/**
* Fire a PostToolUseFailure event - called when tool execution fails
*/
async firePostToolUseFailureEvent(
toolUseId: string,
toolName: string,
toolInput: Record<string, unknown>,
errorMessage: string,
isInterrupt?: boolean,
permissionMode?: PermissionMode,
): Promise<DefaultHookOutput | undefined> {
const result = await this.hookEventHandler.firePostToolUseFailureEvent(
toolUseId,
toolName,
toolInput,
errorMessage,
isInterrupt,
permissionMode,
);
return result.finalOutput
? createHookOutput('PostToolUseFailure', result.finalOutput)
: undefined;
}
}