Summary
Implement the hook execution engine that runs shell scripts with timeout enforcement, error handling, and structured logging.
Parent issue: #392
Scope
New module: core/hooks.py
-
async def run_hook(script: str, cwd: Path, timeout_ms: int, context: dict) -> HookResult
- Execute shell script via
subprocess with cwd set to workspace path
- Enforce timeout (kill process on expiry)
- Capture stdout/stderr (truncated to reasonable limit, ~10KB)
- Return structured
HookResult(success, exit_code, stdout, stderr, duration_ms)
-
Error handling:
- Timeout →
HookResult(success=False, error="timeout")
- Non-zero exit →
HookResult(success=False, exit_code=N)
- Exception →
HookResult(success=False, error=str(e))
-
Logging:
- Log hook start with name and script preview
- Log hook completion with duration
- Log hook failures with stderr excerpt
Acceptance Criteria
Dependencies
Summary
Implement the hook execution engine that runs shell scripts with timeout enforcement, error handling, and structured logging.
Parent issue: #392
Scope
New module:
core/hooks.pyasync def run_hook(script: str, cwd: Path, timeout_ms: int, context: dict) -> HookResultsubprocesswithcwdset to workspace pathHookResult(success, exit_code, stdout, stderr, duration_ms)Error handling:
HookResult(success=False, error="timeout")HookResult(success=False, exit_code=N)HookResult(success=False, error=str(e))Logging:
Acceptance Criteria
cwdtimeout_msHookResultreturned for all outcomesDependencies