| 363 | } |
| 364 | |
| 365 | fn install_hooks_at(path: &Path, force: bool) -> AgentResult<usize> { |
| 366 | let mut config = read_hooks_file(path)?; |
| 367 | if force { |
| 368 | remove_atomic_hooks(&mut config.hooks); |
| 369 | } |
| 370 | |
| 371 | let mut installed = 0; |
| 372 | for spec in CODEX_HOOK_DEFS { |
| 373 | let command = crate::hooks::guarded_hook_command(spec.command); |
| 374 | remove_stale_atomic_hooks_for_event( |
| 375 | &mut config.hooks, |
| 376 | spec.event, |
| 377 | &command, |
| 378 | spec.status_message, |
| 379 | spec.timeout_sec, |
| 380 | ); |
| 381 | if add_hook( |
| 382 | &mut config.hooks, |
| 383 | spec.event, |
| 384 | &command, |
| 385 | spec.status_message, |
| 386 | spec.timeout_sec, |
| 387 | ) { |
| 388 | installed += 1; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | write_hooks_file(path, &config)?; |
| 393 | Ok(installed) |
| 394 | } |
| 395 | |
| 396 | fn uninstall_hooks_at(path: &Path) -> AgentResult<()> { |
| 397 | if !path.exists() { |