Skip to main content

ralph_workflow/files/
mod.rs

1//! File management utilities for Ralph's agent files.
2//!
3//! This module manages the `.agent/` directory structure and files:
4//! - PLAN.md, ISSUES.md, STATUS.md, NOTES.md lifecycle
5//! - commit-message.txt management
6//! - PROMPT.md validation
7//! - Isolation mode file cleanup
8//! - File path extraction from ISSUES content
9//! - File integrity verification and checksums
10//! - Error recovery and state repair
11//! - Real-time file system monitoring for PROMPT.md protection
12//!
13//! # Module Organization
14//!
15//! The files module is organized by domain concern:
16//!
17//! - [`io`] - File I/O operations (agent files, recovery, backup, context)
18//! - [`protection`] - File protection and integrity (validation, integrity, monitoring)
19//! - [`llm_output_extraction`] - LLM output extraction (commit message, JSON extraction)
20//! - [`result_extraction`] - File path extraction from ISSUES content
21//!
22//! # Isolation Mode
23//!
24//! By default, Ralph operates in isolation mode where STATUS.md, NOTES.md,
25//! and ISSUES.md are not persisted between runs. This prevents context
26//! contamination from previous runs.
27//!
28//! # Orchestrator-Controlled File I/O
29//!
30//! The orchestrator is the sole entity responsible for writing output files.
31//! Agent JSON output is extracted and written by the orchestrator, ensuring
32//! consistent file handling regardless of agent behavior.
33
34// Domain-driven submodules
35pub mod io;
36pub mod protection;
37
38// Extraction modules (already domain-organized)
39pub mod llm_output_extraction;
40pub mod result_extraction;
41
42// Re-exports from domain submodules for API convenience
43pub use io::{
44    clean_context_for_reviewer_with_workspace, cleanup_generated_files_with_workspace,
45    create_prompt_backup_with_workspace, delete_commit_message_file_with_workspace,
46    delete_issues_file_for_isolation_with_workspace, delete_plan_file_with_workspace,
47    ensure_files_with_workspace, file_contains_marker, file_contains_marker_with_workspace,
48    make_prompt_read_only_with_workspace, make_prompt_writable_with_workspace,
49    read_commit_message_file_with_workspace, setup_xsd_schemas_with_workspace,
50    update_status_with_workspace, verify_file_not_corrupted_with_workspace,
51    write_commit_message_file_with_workspace, write_diff_backup_with_workspace,
52    write_file_atomic_with_workspace,
53};
54
55#[cfg(test)]
56pub use protection::restore_prompt_if_needed;
57pub use protection::{validate_prompt_md, validate_prompt_md_with_workspace};