Commit f5a1b67
authored
feat: support "defer" hook decision and ResultMessage.deferred_tool_use (#865)
## Summary
Brings the Python SDK to parity with the TypeScript SDK for the
PreToolUse `"defer"` round trip. The CLI has emitted `deferred_tool_use`
on result messages since v2.1.89, but the Python SDK was dropping it.
- `PreToolUseHookSpecificOutput.permissionDecision` now accepts
`"defer"` alongside `"allow" | "deny" | "ask"`
- New `DeferredToolUse` dataclass (`id`, `name`, `input`) — mirrors the
TS `SDKDeferredToolUse` type
- `ResultMessage.deferred_tool_use: DeferredToolUse | None` — populated
when a PreToolUse hook deferred a tool call
- `message_parser` extracts the field from CLI result output
- `DeferredToolUse` exported from the package root
`DeferredToolUse` is intentionally a separate type from `ToolUseBlock`
(despite identical fields) to keep `ContentBlock` isinstance checks
unambiguous and match the TS SDK's typing.
## Test plan
- [x] `ruff check` / `ruff format` — clean
- [x] `mypy src/` — clean
- [x] `pytest tests/test_message_parser.py tests/test_types.py` — 94
passed
- [x] New test `test_parse_result_message_with_deferred_tool_use` covers
the parse path
- [x] Existing `test_parse_result_message_optional_fields_absent`
extended to assert `deferred_tool_use is None` when absent1 parent 04a39ac commit f5a1b67
4 files changed
Lines changed: 52 additions & 1 deletion
File tree
- src/claude_agent_sdk
- _internal
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
544 | 545 | | |
545 | 546 | | |
546 | 547 | | |
| 548 | + | |
547 | 549 | | |
548 | 550 | | |
549 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| 225 | + | |
224 | 226 | | |
225 | 227 | | |
226 | 228 | | |
| |||
235 | 237 | | |
236 | 238 | | |
237 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
238 | 247 | | |
239 | 248 | | |
240 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
1104 | 1104 | | |
1105 | 1105 | | |
1106 | 1106 | | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
1107 | 1121 | | |
1108 | 1122 | | |
1109 | 1123 | | |
| |||
1121 | 1135 | | |
1122 | 1136 | | |
1123 | 1137 | | |
| 1138 | + | |
1124 | 1139 | | |
1125 | 1140 | | |
1126 | 1141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
914 | 915 | | |
915 | 916 | | |
916 | 917 | | |
| 918 | + | |
917 | 919 | | |
918 | 920 | | |
919 | 921 | | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
920 | 945 | | |
921 | 946 | | |
922 | 947 | | |
| |||
0 commit comments