Commit 67d2116
committed
feat(hooks): surface post_tool verification output to the model (verify-into-fix)
post_tool steering hooks ran but their output was discarded — `run_post_tool_hooks`
only logged errors — and `run_hook_command` dropped stderr and returned `Ok(None)`
on a non-zero exit. So a `cargo build` / `pytest` / lint hook configured to verify
the agent's edits produced output the model never saw, leaving the documented
verify-into-fix self-correction loop unbound.
- `run_hook_command` gains `capture_failure`: for post_tool hooks it pipes stderr
and returns the combined stdout+stderr **even on a non-zero exit** (prefixed with
the exit status) — a failing build/test is exactly what must reach the model.
pre_tool / user_prompt directive hooks pass `false` and keep the legacy contract
(stderr dropped, non-zero exit -> `Ok(None)` -> proceed). Both pipes are now drained
concurrently with `wait()` under one timeout, so a hook that fills a pipe buffer
can't deadlock (previously stdout was read only after `wait()` returned).
- `read_bounded` is generic over the pipe type, truncates (instead of erroring) on
overflow so a verbose hook still yields a usable prefix, and decodes lossily so
non-UTF-8 compiler/test output isn't dropped wholesale.
- `run_post_tool_hooks` returns the combined hook output; the tool dispatch appends
it to the tool result via `append_post_tool_output`, preserving Ok/Err polarity, so
the model sees the verification output alongside the tool's own result.
Tests: post_tool captures a failing hook's stdout+stderr with its exit code, captures
success stdout, and returns None when a hook is silent; plus an Ok/Err-polarity test
for the appender.1 parent e99e8b3 commit 67d2116
2 files changed
Lines changed: 274 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
290 | 300 | | |
291 | 301 | | |
292 | 302 | | |
| |||
398 | 408 | | |
399 | 409 | | |
400 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
401 | 427 | | |
402 | 428 | | |
403 | 429 | | |
| |||
697 | 723 | | |
698 | 724 | | |
699 | 725 | | |
| 726 | + | |
700 | 727 | | |
701 | 728 | | |
702 | 729 | | |
| |||
710 | 737 | | |
711 | 738 | | |
712 | 739 | | |
713 | | - | |
| 740 | + | |
714 | 741 | | |
715 | 742 | | |
716 | 743 | | |
| |||
733 | 760 | | |
734 | 761 | | |
735 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
736 | 769 | | |
737 | 770 | | |
738 | 771 | | |
| |||
0 commit comments