ralph/lib.rs
1//! Ralph library surface.
2//!
3//! Responsibilities:
4//! - Expose internal modules for tests and CLI integration.
5//! - Provide a stable entrypoint for crate-wide utilities.
6//!
7//! Not handled here:
8//! - CLI argument parsing (see `crate::cli`).
9//! - Runner execution or queue persistence details.
10//!
11//! Invariants/assumptions:
12//! - Modules remain internal-first; public exports are intentional.
13
14#![deny(unsafe_op_in_unsafe_fn)]
15
16// --- Core --------------------------------------------------------------------
17
18pub mod agent;
19pub mod config;
20pub mod constants;
21pub mod contracts;
22pub mod queue;
23pub(crate) mod reports;
24
25// --- Commands ----------------------------------------------------------------
26
27pub mod cli;
28#[path = "cli/spec.rs"]
29pub mod cli_spec;
30pub mod commands;
31pub mod migration;
32pub mod plugins;
33pub mod sanity;
34pub mod undo;
35
36// --- Utils -------------------------------------------------------------------
37
38pub mod celebrations;
39pub mod error_messages;
40pub mod eta_calculator;
41pub mod execution_history;
42pub mod fsutil;
43pub mod git;
44pub mod jsonc;
45pub mod lock;
46pub mod notification;
47pub mod webhook;
48// Internal-only output modules
49pub(crate) mod output;
50pub(crate) mod outpututil;
51pub mod productivity;
52pub mod progress;
53pub mod promptflow;
54pub mod prompts;
55pub mod redaction;
56pub mod runner;
57pub mod runutil;
58pub mod session;
59pub mod signal;
60pub mod template;
61pub mod timeutil;
62
63// --- Internal ----------------------------------------------------------------
64
65// Not used by the binary/tests directly; keep crate-private.
66pub(crate) mod debuglog;
67
68// Internal prompt composition helpers.
69mod prompts_internal;
70
71#[cfg(test)]
72mod runutil_tests;
73
74#[cfg(test)]
75pub(crate) mod testsupport;
76
77/// Test synchronization utilities for managing global state across tests.
78///
79/// This module provides synchronization primitives to prevent test flakiness
80/// caused by global state interference between parallel tests.
81#[cfg(test)]
82pub(crate) mod test_sync {
83 use std::sync::{Mutex, OnceLock};
84
85 /// Global mutex to synchronize tests that modify the Ctrl+C interrupt flag.
86 ///
87 /// Tests that set the interrupt flag should acquire this mutex.
88 /// Tests that use the runner should reset the flag before starting.
89 pub static INTERRUPT_TEST_MUTEX: OnceLock<Mutex<()>> = OnceLock::new();
90
91 /// Reset the global Ctrl+C interrupted flag to false.
92 ///
93 /// This should be called by tests that use the runner to ensure they
94 /// don't fail due to stale interrupt flags from other tests.
95 pub fn reset_ctrlc_interrupt_flag() {
96 use std::sync::atomic::Ordering;
97 if let Ok(ctrlc) = crate::runner::ctrlc_state() {
98 ctrlc.interrupted.store(false, Ordering::SeqCst);
99 }
100 }
101}