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//! - Result extraction from agent JSON logs
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`] - Plan and issue extraction from logs
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 new domain structure for backward compatibility
43pub use io::{
44 clean_context_for_reviewer, clean_context_for_reviewer_with_workspace,
45 cleanup_generated_files_with_workspace, create_prompt_backup,
46 create_prompt_backup_with_workspace, delete_commit_message_file_with_workspace,
47 delete_issues_file_for_isolation, delete_issues_file_for_isolation_with_workspace,
48 delete_plan_file_with_workspace, ensure_files_with_workspace, file_contains_marker,
49 file_contains_marker_with_workspace, make_prompt_read_only,
50 make_prompt_read_only_with_workspace, make_prompt_writable,
51 make_prompt_writable_with_workspace, read_commit_message_file_with_workspace,
52 reset_context_for_isolation, setup_xsd_schemas_with_workspace, update_status,
53 update_status_with_workspace, verify_file_not_corrupted_with_workspace,
54 write_commit_message_file_with_workspace, write_diff_backup_with_workspace,
55 write_file_atomic_with_workspace,
56};
57
58#[cfg(test)]
59pub use protection::restore_prompt_if_needed;
60pub use protection::{validate_prompt_md, validate_prompt_md_with_workspace};
61pub use result_extraction::extract_issues;
62#[cfg(any(test, feature = "test-utils"))]
63pub use result_extraction::extract_plan;