| 2521 | } : undefined, |
| 2522 | currentTurn: this.currentTurn, |
| 2523 | }; |
| 2524 | |
| 2525 | // ─── Hooks: PreToolUse ───────────────────────────────────────────────────── |
| 2526 | // Run blocking hooks BEFORE tool execution. If any vetoes, return early with the |
| 2527 | // veto message as the tool's result so the model sees the refusal and can adapt. |
| 2528 | const hooks = getHooksManager(); |
| 2529 | if (hooks?.hasAny('PreToolUse')) { |
| 2530 | const filePaths = extractFilePathsFromArgs(args); |
| 2531 | const hookResult = await hooks.dispatch('PreToolUse', { |
| 2532 | event: 'PreToolUse', |
| 2533 | sessionId, |
| 2534 | cwd: this.cwd, |
| 2535 | toolName: tc.function.name, |
| 2536 | toolArgsJson: tc.function.arguments, |
| 2537 | filePaths, |
| 2538 | }); |
| 2539 | if (hookResult.vetoMessage !== undefined) { |
| 2540 | logger.info('PreToolUse hook vetoed tool call', { tool: tc.function.name }); |