merry-tools 0.1.4

Workspace file, search, patch, web fetch, and document tools for the Merry agent runtime.
Documentation
//! Domain-neutral external writable tree interception contract for workspace tools.
//!
//! Higher composition layers (such as `merry-coding` integrating runtime durable
//! memory) implement [`ExternalTreePolicy`] so `merry-tools` enforces read/write
//! governance and post-write hooks without depending on concrete memory stores.

use std::path::{Path, PathBuf};

/// Kind of filesystem mutation attempted against an external governed tree.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExternalWriteKind {
    /// Creating a new file.
    Create,
    /// Updating an existing file.
    Update,
    /// Deleting an existing file.
    Delete,
}

/// Governance and lifecycle hooks for an external writable tree outside the
/// workspace root (for example a durable memory store).
pub trait ExternalTreePolicy: std::fmt::Debug + Send + Sync {
    /// Returns the canonical or configured root directory of the external tree.
    fn root(&self) -> &Path;

    /// Returns whether `path` is governed by this external tree policy.
    fn governs_path(&self, path: &Path) -> bool;

    /// Records that `path` was successfully read as UTF-8 text.
    fn on_text_read(&self, path: &Path) -> Result<(), String>;

    /// Authorizes a pending write of `kind` and `byte_len` bytes to `path`.
    fn authorize_write(
        &self,
        kind: ExternalWriteKind,
        path: &Path,
        byte_len: usize,
    ) -> Result<(), String>;

    /// Notifies the external tree after patch writes have been committed to disk.
    fn on_writes_committed(&self, paths: &[PathBuf]) -> Result<(), String>;
}