magi-code 0.96.1

Repository-aware CLI coding agent for terminal work
Documentation
use super::{RewindMode, SnapshotExclusionReason};
mod arguments;
mod context;
mod execution;
mod fs_ops;
mod model;
mod mutations;
mod paths;
mod plan;
pub(crate) use model::ChangeClassification;
pub(crate) use model::ChangeEntry;
pub(crate) use model::ChangeTurn;
pub(crate) use model::ChangesReadModel;
pub(crate) use model::RestoreOperation;
pub(crate) use model::RestoreOperationKind;
pub(crate) use model::RestoreOperationResult;
pub(crate) use model::RestorePlan;
pub(crate) use model::RestoreStatus;
pub(crate) use model::RewindExecution;
use paths::REDACTED_PATH;

use fs_ops::RewindTarget;
use fs_ops::open_rewind_root;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use fs_ops::rename_noreplace;
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
use fs_ops::rename_noreplace;
pub(crate) use paths::redacted_path_for_display;
use paths::redacted_relative_path;
use paths::safe_provider_path;
use paths::safe_rewind_target_path;

use fs_ops::open_target_parent;

use fs_ops::reject_final_symlink;
use fs_ops::snapshot_named;
use fs_ops::sync_capability_directory;
use fs_ops::target_mode;
use fs_ops::target_snapshot;
use fs_ops::target_snapshot_for_plan;

use mutations::MutationOutcome;

use execution::execute_plan;
use mutations::RewindBlobOptions;
use mutations::delete_target;
use mutations::install_new_target;
use mutations::write_rewind_blob;
use plan::changes_from_records;
use plan::plan_rewind;
use plan::plan_rewind_from_records;

pub(crate) use arguments::parse_rewind_target;
pub(crate) use context::replay_rewind_context;
pub(crate) use context::rewind_event_payload;
use execution::read_rewind_blob;

use super::{
    capture::{
        LedgerRead, SnapshotBlobRef, SnapshotCaptureStatus, SnapshotLedgerRecord, SnapshotTool,
        secret_like_path,
    },
    sanitized_diagnostic,
    store::{CheckpointStore, sha256_hex},
};
use crate::output::redact_sensitive_text;
use crate::path_utils::lexical_normalize;
pub(crate) use arguments::ParsedRewindTarget;
use cap_fs_ext::{DirExt, FollowSymlinks, OpenOptionsFollowExt};
#[cfg(unix)]
use cap_std::fs::{OpenOptionsExt as CapOpenOptionsExt, PermissionsExt as CapPermissionsExt};
use cap_std::{
    ambient_authority,
    fs::{Dir as CapDir, File as CapFile, OpenOptions as CapOpenOptions},
};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use std::{
    collections::BTreeMap,
    ffi::{OsStr, OsString},
    io::{self, ErrorKind, Read, Write},
    path::{Component, Path, PathBuf},
    sync::atomic::{AtomicU64, Ordering},
    time::{SystemTime, UNIX_EPOCH},
};

impl CheckpointStore {
    pub(crate) fn changes(&self, session_id: &str) -> ChangesReadModel {
        changes_from_records(self, self.read_records(session_id))
    }

    pub(crate) fn plan_rewind(
        &self,
        session_id: &str,
        cwd: &Path,
        target_turn: u64,
    ) -> RestorePlan {
        plan_rewind(self, session_id, cwd, target_turn)
    }

    pub(crate) fn execute_plan(&self, plan: &RestorePlan, cwd: &Path) -> RewindExecution {
        execute_plan(self, plan, cwd)
    }

    pub(crate) fn changes_from_read(&self, read: &LedgerRead) -> ChangesReadModel {
        changes_from_records(self, read.clone())
    }

    pub(crate) fn plan_rewind_from_read(
        &self,
        session_id: &str,
        cwd: &Path,
        target_turn: u64,
        read: &LedgerRead,
    ) -> RestorePlan {
        plan_rewind_from_records(self, session_id, cwd, target_turn, read)
    }
}