Skip to main content

Module workspace

Module workspace 

Source
Expand description

Workspace filesystem abstraction for explicit path resolution.

This module provides the Workspace trait and implementations that eliminate CWD dependencies by making all path operations explicit relative to the repository root.

§Problem

The codebase previously relied on std::env::set_current_dir() to set the process CWD to the repository root, then used relative paths (.agent/, PROMPT.md, etc.) throughout. This caused:

  • Test flakiness when tests ran in parallel (CWD is process-global)
  • Background thread bugs when CWD changed after thread started
  • Poor testability without complex CWD manipulation

§Solution

The Workspace trait defines the interface for file operations, with two implementations:

  • WorkspaceFs - Production implementation using the real filesystem
  • [MemoryWorkspace] - Test implementation with in-memory storage (available with test-utils feature)

§Example

use ralph_workflow::workspace::WorkspaceFs;
use std::path::PathBuf;

let ws = WorkspaceFs::new(PathBuf::from("/path/to/repo"));

// Get paths to well-known files
let plan = ws.plan_md();  // /path/to/repo/.agent/PLAN.md
let prompt = ws.prompt_md();  // /path/to/repo/PROMPT.md

// Perform file operations
ws.write(".agent/test.txt", "content")?;
let content = ws.read(".agent/test.txt")?;

Structs§

DirEntry
A directory entry returned by Workspace::read_dir.
WorkspaceFs
Production workspace implementation using the real filesystem.

Traits§

Workspace
Trait defining the workspace filesystem interface.