| 377 | } |
| 378 | |
| 379 | fn install_hooks_at(path: &Path, force: bool) -> AgentResult<usize> { |
| 380 | let mut config = read_hooks_file(path)?; |
| 381 | if force { |
| 382 | remove_atomic_hooks(&mut config.hooks); |
| 383 | } |
| 384 | |
| 385 | let mut installed = 0; |
| 386 | for spec in CODEX_HOOK_DEFS { |
| 387 | let command = crate::hooks::guarded_hook_command(spec.command); |
| 388 | remove_stale_atomic_hooks_for_event( |
| 389 | &mut config.hooks, |
| 390 | spec.event, |
| 391 | &command, |
| 392 | spec.status_message, |
| 393 | spec.timeout_sec, |
| 394 | ); |
| 395 | if add_hook( |
| 396 | &mut config.hooks, |
| 397 | spec.event, |
| 398 | &command, |
| 399 | spec.status_message, |
| 400 | spec.timeout_sec, |
| 401 | ) { |
| 402 | installed += 1; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | write_hooks_file(path, &config)?; |
| 407 | Ok(installed) |
| 408 | } |
| 409 | |
| 410 | fn uninstall_hooks_at(path: &Path) -> AgentResult<()> { |
| 411 | if !path.exists() { |