Skip to main content

ralph_workflow/git_helpers/phase_state/
io.rs

1// git_helpers/phase_state/io.rs — boundary module for process-global agent phase state.
2// File stem is `io` — recognized as boundary module by forbid_io_effects lint.
3
4// Process-global state for the agent phase lifecycle.
5//
6// These statics hold path information set during `start_agent_phase` and cleared
7// in `end_agent_phase_in_repo`. Signal handlers read them via `try_lock` to clean
8// up without re-computing paths through libgit2.
9//
10// Defined here (not in the `runtime` boundary) so that non-boundary modules
11// (`wrapper`) can import them without crossing a boundary dependency.
12
13use std::path::PathBuf;
14use std::sync::Mutex;
15
16/// Process-global repo root set during `start_agent_phase` for signal handler fallback.
17///
18/// The signal handler needs a reliable repo root when CWD-based discovery may fail.
19/// This is set in `start_agent_phase` and cleared in `end_agent_phase_in_repo`.
20pub static AGENT_PHASE_REPO_ROOT: Mutex<Option<PathBuf>> = Mutex::new(None);
21
22/// Process-global ralph git dir set during `start_agent_phase_in_repo`.
23///
24/// Signal handlers cannot call libgit2, so we pre-compute the ralph dir path
25/// on the main thread and store it here. Signal handlers read via `try_lock`.
26pub static AGENT_PHASE_RALPH_DIR: Mutex<Option<PathBuf>> = Mutex::new(None);
27
28/// Process-global hooks dir set during `start_agent_phase_in_repo`.
29///
30/// Used by signal handler cleanup to avoid recomputation via libgit2.
31/// For linked worktrees, hooks are worktree-scoped, so this ensures the signal
32/// handler cleans the active worktree's hooks instead of touching siblings.
33pub static AGENT_PHASE_HOOKS_DIR: Mutex<Option<PathBuf>> = Mutex::new(None);