Commit 3caf665
feat: forward decision_reason and permission-display fields to ToolPermissionContext (#909)
Fixes #816.
## Summary
The CLI already includes `decision_reason`, `blocked_path`, `title`,
`display_name`, and `description` on the `can_use_tool` control request
— and the TypeScript SDK already exposes them on its
`ToolPermissionContext`. The Python SDK was dropping them on the floor.
This adds the five fields to `ToolPermissionContext` and
`SDKControlPermissionRequest`, and populates them in
`Query._handle_control_request`. Now a `can_use_tool` callback can:
- Show users *why* they're being prompted (`decision_reason` — e.g. a
PreToolUse hook's `permissionDecisionReason`)
- Render a richer permission prompt (`title` / `display_name` /
`description`) without reconstructing it from `tool_name` + `input`
- See which path triggered the prompt (`blocked_path`)
All fields are optional (`str | None = None`), so this is
backward-compatible.
## Testing
- New unit test `test_permission_callback_receives_decision_reason` —
fails on `main` with `AttributeError: 'ToolPermissionContext' object has
no attribute 'blocked_path'`, passes here.
- Full suite: 716 passed, 2 pre-existing failures in
`test_transcript_mirror.py` (eager-flush, unrelated to this change).
- `ruff check` / `ruff format`: clean.
- `mypy src/`: 2 pre-existing errors in `_task_compat.py` (trio
import-not-found), none introduced.
- Live e2e proof in PR comment below.
---
_Generated by [Claude
Code](https://claude.ai/code/session_013yvWPbykUnMTtyRxaa51sK)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 42971da commit 3caf665
3 files changed
Lines changed: 75 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
191 | 207 | | |
192 | 208 | | |
193 | 209 | | |
| |||
1838 | 1854 | | |
1839 | 1855 | | |
1840 | 1856 | | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
1841 | 1861 | | |
1842 | 1862 | | |
1843 | 1863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
252 | 302 | | |
253 | 303 | | |
254 | 304 | | |
| |||
0 commit comments