Add missing hook output fields to match TypeScript SDK (#226)

Closes the gap between Python and TypeScript SDK hook output types by
adding:
- `reason` field for explaining decisions
- `continue_` field for controlling execution flow
- `suppressOutput` field for hiding stdout
- `stopReason` field for stop explanations
- `decision` now supports both "approve" and "block" (not just "block")
- `AsyncHookJSONOutput` type for deferred hook execution
- Proper typing for `hookSpecificOutput` with discriminated unions

Also adds comprehensive examples and tests:
- New examples in hooks.py demonstrating all new fields
- Unit tests in test_tool_callbacks.py for new output types
- E2E tests in e2e-tests/test_hooks.py with real API calls
- CI integration in .github/workflows/test.yml

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Ashwin Bhat 2025-10-09 18:13:23 -07:00 committed by GitHub
parent 5bea2dc27d
commit e8d7e71a0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 526 additions and 9 deletions

View file

@ -125,6 +125,8 @@ jobs:
run: |
python examples/quick_start.py
timeout 120 python examples/streaming_mode.py all
timeout 120 python examples/hooks.py PreToolUse
timeout 120 python examples/hooks.py DecisionFields
- name: Run example scripts (Windows)
if: runner.os == 'Windows'
@ -136,4 +138,14 @@ jobs:
Wait-Job $job -Timeout 120 | Out-Null
Stop-Job $job
Receive-Job $job
$job = Start-Job { python examples/hooks.py PreToolUse }
Wait-Job $job -Timeout 120 | Out-Null
Stop-Job $job
Receive-Job $job
$job = Start-Job { python examples/hooks.py DecisionFields }
Wait-Job $job -Timeout 120 | Out-Null
Stop-Job $job
Receive-Job $job
shell: pwsh