Roo-Code/src/services/hooks/index.ts
Roo Code d8b53b814a feat: add prompt-based hooks for agent lifecycle events
Implements prompt-based hooks that allow a smaller/different model to step in
at specific agent lifecycle events and provide read-only advisory output.

Hook events supported:
- PreToolUse: fires before tool execution (with optional tool name matcher)
- PostToolUse: fires after tool execution completes
- Stop: fires when attempt_completion is invoked

Configuration via .roo/hooks.json (project) and ~/.roo/hooks.json (global),
using a Claude Code-compatible format. Hooks are read-only (no tool access)
and receive conversation context. Uses the active profile API configuration.

New files:
- src/shared/hooks.ts: types, interfaces, and validation
- src/services/hooks/HooksManager.ts: config loading with file watchers
- src/services/hooks/HookExecutor.ts: hook prompt building and execution
- src/shared/__tests__/hooks.spec.ts: 18 validation tests
- src/services/hooks/__tests__/HookExecutor.spec.ts: 15 executor tests

Modified files:
- packages/types/src/message.ts: added hook_output ClineSay type
- src/core/webview/ClineProvider.ts: HooksManager initialization
- src/core/assistant-message/presentAssistantMessage.ts: PreToolUse/PostToolUse hooks
- src/core/tools/AttemptCompletionTool.ts: Stop hook

Addresses #11504
2026-02-17 17:32:52 +00:00

2 lines
128 B
TypeScript

export { HooksManager } from "./HooksManager"
export { executeHooks, formatHookResults, buildHookPrompt } from "./HookExecutor"