codetree 0.2.0

AI-native version control system for autonomous agents
Documentation
use crate::error::{Context, Result};

use crate::lock::LockManager;

pub async fn unlock_command(path: String) -> Result<()> {
    let current_dir = std::env::current_dir()
        .context("Failed to get current directory")?;
    let locks_path = current_dir.join(".codetree").join("locks.json");
    let released = LockManager::update_atomically(locks_path, |m| Ok(m.release_file(&path)))?;
    if released {
        println!("Unlocked: {}", path);
    } else {
        println!("Not locked: {}", path);
    }
    Ok(())
}

pub async fn locks_command() -> Result<()> {
    let current_dir = std::env::current_dir()
        .context("Failed to get current directory")?;
    let locks_path = current_dir.join(".codetree").join("locks.json");
    let lock_manager = LockManager::load(locks_path)?;
    let locks = lock_manager.list_locks();
    if locks.is_empty() {
        println!("No active file locks");
        return Ok(());
    }
    println!("File locks:");
    for (path, operation) in locks {
        println!("  {} -> {}", path, operation);
    }
    Ok(())
}