## Why
Codex can intercept an `apply_patch` heredoc passed to `exec_command`
and apply the patch directly. That path ran shell hooks but bypassed
`apply_patch` hooks, so patch-specific rules could miss the same edit
when it was submitted through the shell tool.
## What changed
- Run `apply_patch` `PreToolUse` after shell hooks and before file
verification. Hooks can block or rewrite the patch, and the final
patch is checked against the selected environment's permissions.
- Report the executed patch through `apply_patch` `PostToolUse`. Link
the patch hook events to the outer shell call with
`parent_tool_use_id` and provide working-directory and filesystem
metadata for hooks that inspect patch targets.
- Apply the same block and rewrite rules in recorded Guardian reviews.
Mark those hook requests with `review_only` and review the resulting
patch without executing it or publishing hook-provided context.
## Testing
Add coverage for hook blocks and rewrites, effective working directories,
environment permissions, and cancellation before and after a patch write.
Cover recorded reviews of rewritten patches and reviews stopped by a hook.
GitOrigin-RevId: 2115f26261a20d4a512669bc9e277a764b8f42f4