pub struct LoopContext { /* private fields */ }Expand description
Context for resolving paths within a Ralph loop.
Encapsulates the working directory and loop identity, providing consistent path resolution for all loop-local state files.
Implementations§
Source§impl LoopContext
impl LoopContext
Sourcepub fn primary(workspace: PathBuf) -> Self
pub fn primary(workspace: PathBuf) -> Self
Creates context for the primary loop running in the main workspace.
The primary loop holds the loop lock and runs directly in the repository root without filesystem isolation.
Sourcepub fn worktree(
loop_id: impl Into<String>,
worktree_path: PathBuf,
repo_root: PathBuf,
) -> Self
pub fn worktree( loop_id: impl Into<String>, worktree_path: PathBuf, repo_root: PathBuf, ) -> Self
Creates context for a worktree-based loop.
Worktree loops run in isolated git worktrees with their own
.ralph/ directory, but share memories, specs, and code tasks via symlink.
§Arguments
loop_id- Unique identifier for this loop (e.g., “loop-1234-abcd”)worktree_path- Path to the worktree directoryrepo_root- Path to the main repository root (for symlinks)
Sourcepub fn loop_id(&self) -> Option<&str>
pub fn loop_id(&self) -> Option<&str>
Returns the loop identifier, if any.
Primary loops return None; worktree loops return their unique ID.
Sourcepub fn is_primary(&self) -> bool
pub fn is_primary(&self) -> bool
Returns true if this is the primary loop.
Sourcepub fn workspace(&self) -> &Path
pub fn workspace(&self) -> &Path
Returns the workspace root for this loop.
This is the directory where the loop executes:
- Primary: the repo root
- Worktree: the worktree directory
Sourcepub fn repo_root(&self) -> &Path
pub fn repo_root(&self) -> &Path
Returns the main repository root.
For worktree loops, this is different from workspace() and
is used to locate shared resources like the main memories file.
Sourcepub fn agent_dir(&self) -> PathBuf
pub fn agent_dir(&self) -> PathBuf
Path to the .ralph/agent/ directory for this loop.
This directory contains agent state: memories, tasks, scratchpad, etc.
Sourcepub fn events_path(&self) -> PathBuf
pub fn events_path(&self) -> PathBuf
Path to the events JSONL file.
Each loop has its own isolated events file.
Sourcepub fn current_events_marker(&self) -> PathBuf
pub fn current_events_marker(&self) -> PathBuf
Path to the current-events marker file.
This file contains the path to the active events file.
Sourcepub fn urgent_steer_path(&self) -> PathBuf
pub fn urgent_steer_path(&self) -> PathBuf
Path to the urgent-steer marker file.
This file is created when ! arrives during an active iteration so
ralph emit can block handoff until the current model turn has seen it.
Sourcepub fn tasks_path(&self) -> PathBuf
pub fn tasks_path(&self) -> PathBuf
Path to the tasks JSONL file.
Each loop has its own isolated tasks file.
Sourcepub fn scratchpad_path(&self) -> PathBuf
pub fn scratchpad_path(&self) -> PathBuf
Path to the scratchpad markdown file.
Each loop has its own isolated scratchpad.
Sourcepub fn memories_path(&self) -> PathBuf
pub fn memories_path(&self) -> PathBuf
Path to the memories markdown file.
For primary loops, this is the actual memories file. For worktree loops, this is a symlink to the main repo’s memories.
Sourcepub fn main_memories_path(&self) -> PathBuf
pub fn main_memories_path(&self) -> PathBuf
Path to the main repository’s memories file.
Used to create symlinks in worktree loops.
Sourcepub fn context_path(&self) -> PathBuf
pub fn context_path(&self) -> PathBuf
Path to the context markdown file.
This file contains worktree metadata (loop ID, workspace, branch, etc.) and is only created in worktree loops.
Sourcepub fn specs_dir(&self) -> PathBuf
pub fn specs_dir(&self) -> PathBuf
Path to the specs directory for this loop.
For primary loops, this is the actual specs directory. For worktree loops, this is a symlink to the main repo’s specs.
Sourcepub fn code_tasks_dir(&self) -> PathBuf
pub fn code_tasks_dir(&self) -> PathBuf
Path to the code tasks directory for this loop.
For primary loops, this is the actual code tasks directory. For worktree loops, this is a symlink to the main repo’s code tasks. Note: This is different from tasks_path() which is for runtime task tracking.
Sourcepub fn main_specs_dir(&self) -> PathBuf
pub fn main_specs_dir(&self) -> PathBuf
Path to the main repository’s specs directory.
Used to create symlinks in worktree loops.
Sourcepub fn main_code_tasks_dir(&self) -> PathBuf
pub fn main_code_tasks_dir(&self) -> PathBuf
Path to the main repository’s code tasks directory.
Used to create symlinks in worktree loops.
Sourcepub fn summary_path(&self) -> PathBuf
pub fn summary_path(&self) -> PathBuf
Path to the summary markdown file.
Each loop has its own isolated summary.
Sourcepub fn handoff_path(&self) -> PathBuf
pub fn handoff_path(&self) -> PathBuf
Path to the handoff markdown file.
Generated on loop completion to provide context for the next session. Contains completed tasks, remaining work, and a ready-to-paste prompt.
Sourcepub fn diagnostics_dir(&self) -> PathBuf
pub fn diagnostics_dir(&self) -> PathBuf
Path to the diagnostics directory.
Each loop has its own diagnostics output.
Sourcepub fn history_path(&self) -> PathBuf
pub fn history_path(&self) -> PathBuf
Path to the loop history JSONL file.
Event-sourced history for crash recovery and debugging.
Sourcepub fn loop_lock_path(&self) -> PathBuf
pub fn loop_lock_path(&self) -> PathBuf
Path to the loop lock file (only meaningful for primary loop detection).
Sourcepub fn merge_queue_path(&self) -> PathBuf
pub fn merge_queue_path(&self) -> PathBuf
Path to the merge queue JSONL file.
The merge queue is shared across all loops (in main repo).
Sourcepub fn loop_registry_path(&self) -> PathBuf
pub fn loop_registry_path(&self) -> PathBuf
Path to the loop registry JSON file.
The registry is shared across all loops (in main repo).
Sourcepub fn planning_sessions_dir(&self) -> PathBuf
pub fn planning_sessions_dir(&self) -> PathBuf
Path to the planning sessions directory.
Contains all planning session subdirectories.
Sourcepub fn planning_session_dir(&self, id: &str) -> PathBuf
pub fn planning_session_dir(&self, id: &str) -> PathBuf
Path to a specific planning session directory.
§Arguments
id- The session ID (e.g., “20260127-143022-a7f2”)
Sourcepub fn planning_conversation_path(&self, id: &str) -> PathBuf
pub fn planning_conversation_path(&self, id: &str) -> PathBuf
Sourcepub fn planning_session_metadata_path(&self, id: &str) -> PathBuf
pub fn planning_session_metadata_path(&self, id: &str) -> PathBuf
Sourcepub fn planning_artifacts_dir(&self, id: &str) -> PathBuf
pub fn planning_artifacts_dir(&self, id: &str) -> PathBuf
Sourcepub fn ensure_ralph_dir(&self) -> Result<()>
pub fn ensure_ralph_dir(&self) -> Result<()>
Ensures the .ralph/ directory exists.
Sourcepub fn ensure_agent_dir(&self) -> Result<()>
pub fn ensure_agent_dir(&self) -> Result<()>
Ensures the .ralph/agent/ directory exists.
Sourcepub fn ensure_specs_dir(&self) -> Result<()>
pub fn ensure_specs_dir(&self) -> Result<()>
Ensures the .ralph/specs/ directory exists.
Sourcepub fn ensure_code_tasks_dir(&self) -> Result<()>
pub fn ensure_code_tasks_dir(&self) -> Result<()>
Ensures the .ralph/tasks/ directory exists.
Sourcepub fn ensure_directories(&self) -> Result<()>
pub fn ensure_directories(&self) -> Result<()>
Ensures all required directories exist.
Sourcepub fn setup_memory_symlink(&self) -> Result<bool>
pub fn setup_memory_symlink(&self) -> Result<bool>
Creates the memory symlink in a worktree pointing to main repo.
This is only relevant for worktree loops. For primary loops, this is a no-op.
§Returns
Ok(true)- Symlink was createdOk(false)- Already exists or is primary loopErr(_)- Symlink creation failed
Sourcepub fn setup_specs_symlink(&self) -> Result<bool>
pub fn setup_specs_symlink(&self) -> Result<bool>
Creates the specs symlink in a worktree pointing to main repo.
This allows worktree loops to access specs from the main repo, even when they are untracked (not committed to git).
§Returns
Ok(true)- Symlink was createdOk(false)- Already exists or is primary loopErr(_)- Symlink creation failed
Sourcepub fn setup_code_tasks_symlink(&self) -> Result<bool>
pub fn setup_code_tasks_symlink(&self) -> Result<bool>
Creates the code tasks symlink in a worktree pointing to main repo.
This allows worktree loops to access code task files from the main repo, even when they are untracked (not committed to git).
§Returns
Ok(true)- Symlink was createdOk(false)- Already exists or is primary loopErr(_)- Symlink creation failed
Sourcepub fn generate_context_file(&self, branch: &str, prompt: &str) -> Result<bool>
pub fn generate_context_file(&self, branch: &str, prompt: &str) -> Result<bool>
Generates a context.md file in the worktree with metadata.
This file tells the agent it’s running in a worktree and provides information about the worktree context (loop ID, workspace, branch, etc.)
§Arguments
branch- The git branch name for this worktreeprompt- The prompt that started this loop
§Returns
Ok(true)- Context file was createdOk(false)- Already exists or is primary loopErr(_)- File creation failed
Sourcepub fn setup_worktree_symlinks(&self) -> Result<()>
pub fn setup_worktree_symlinks(&self) -> Result<()>
Sets up all worktree symlinks (memories, specs, code tasks).
Convenience method that calls all setup_*_symlink methods. Only relevant for worktree loops - no-op for primary loops.
Trait Implementations§
Source§impl Clone for LoopContext
impl Clone for LoopContext
Source§fn clone(&self) -> LoopContext
fn clone(&self) -> LoopContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more