pub struct FixupParser {
pub mode: FixupMode,
pub sandbox_root: SandboxRoot,
}Expand description
Main fixup parser that handles detection and parsing of fixup plans
§Security
FixupParser uses SandboxRoot to validate all target paths before any file operations.
This ensures that:
- Paths cannot escape the workspace root via
..traversal - Absolute paths are rejected
- Symlinks are rejected by default (configurable via
SandboxConfig) - Hardlinks are rejected by default (configurable via
SandboxConfig)
All path validation happens through SandboxRoot::join() which provides
comprehensive security checks before any file I/O.
Fields§
§mode: FixupModeOperating mode (preview or apply)
sandbox_root: SandboxRootSandboxed root directory for resolving and validating relative paths
Implementations§
Source§impl FixupParser
impl FixupParser
Sourcepub fn preview_changes(
&self,
diffs: &[UnifiedDiff],
) -> Result<FixupPreview, FixupError>
pub fn preview_changes( &self, diffs: &[UnifiedDiff], ) -> Result<FixupPreview, FixupError>
Preview changes without applying them
Line endings are normalized before calculating diff statistics (FR-FIX-010)
§Security
All target paths are validated through SandboxRoot::join() to ensure:
- Paths cannot escape the workspace root via
..traversal - Absolute paths are rejected
- Symlinks are rejected by default (configurable via
SandboxConfig) - Hardlinks are rejected by default (configurable via
SandboxConfig)
Sourcepub fn apply_changes(
&self,
diffs: &[UnifiedDiff],
) -> Result<FixupResult, FixupError>
pub fn apply_changes( &self, diffs: &[UnifiedDiff], ) -> Result<FixupResult, FixupError>
Apply changes to files using atomic writes (FR-FIX-005, FR-FIX-006, FR-FIX-008)
This method implements the atomic write pattern:
- Validate target path using SandboxPath (security check)
- Write to .tmp file with fsync
- Create .bak backup if file exists
- Atomic rename with Windows retry
- Preserve file permissions (Unix) or attributes (Windows)
- Record warnings if permission preservation fails
§Security
All target paths are validated through SandboxRoot::join() to ensure:
- Paths cannot escape the workspace root via
..traversal - Absolute paths are rejected
- Symlinks are rejected by default (configurable via
SandboxConfig) - Hardlinks are rejected by default (configurable via
SandboxConfig)
Sourcepub fn apply_changes_with_git(
&self,
diffs: &[UnifiedDiff],
) -> Result<FixupResult, FixupError>
pub fn apply_changes_with_git( &self, diffs: &[UnifiedDiff], ) -> Result<FixupResult, FixupError>
Apply changes to files (legacy git apply method - kept for compatibility)
Source§impl FixupParser
impl FixupParser
Sourcepub fn new(mode: FixupMode, base_dir: PathBuf) -> Result<Self, FixupError>
pub fn new(mode: FixupMode, base_dir: PathBuf) -> Result<Self, FixupError>
Create a new fixup parser with a sandboxed root directory.
§Arguments
mode- The operating mode (preview or apply)base_dir- The base directory to use as a sandbox root
§Errors
Returns an error if base directory cannot be used as a sandbox root (e.g., doesn’t exist, isn’t a directory, or can’t be canonicalized).
Sourcepub fn with_config(
mode: FixupMode,
base_dir: PathBuf,
config: SandboxConfig,
) -> Result<Self, FixupError>
pub fn with_config( mode: FixupMode, base_dir: PathBuf, config: SandboxConfig, ) -> Result<Self, FixupError>
Create a new fixup parser with custom sandbox configuration.
§Arguments
mode- The operating mode (preview or apply)base_dir- The base directory to use as a sandbox rootconfig- Custom sandbox configuration (e.g., to allow symlinks)
§Errors
Returns an error if base directory cannot be used as a sandbox root.
Sourcepub fn has_fixup_markers(&self, content: &str) -> bool
pub fn has_fixup_markers(&self, content: &str) -> bool
Detect if review output contains fixup markers.
Sourcepub fn detect_fixup_markers(&self, content: &str) -> Option<String>
pub fn detect_fixup_markers(&self, content: &str) -> Option<String>
Detect fixup markers in review output. Returns the content after the first marker if found.
Sourcepub fn parse_diffs(&self, content: &str) -> Result<Vec<UnifiedDiff>, FixupError>
pub fn parse_diffs(&self, content: &str) -> Result<Vec<UnifiedDiff>, FixupError>
Parse unified diff blocks from fixup content.