Skip to main content

merry_tools/
external_tree.rs

1//! Domain-neutral external writable tree interception contract for workspace tools.
2//!
3//! Higher composition layers (such as `merry-coding` integrating runtime durable
4//! memory) implement [`ExternalTreePolicy`] so `merry-tools` enforces read/write
5//! governance and post-write hooks without depending on concrete memory stores.
6
7use std::path::{Path, PathBuf};
8
9/// Kind of filesystem mutation attempted against an external governed tree.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum ExternalWriteKind {
12    /// Creating a new file.
13    Create,
14    /// Updating an existing file.
15    Update,
16    /// Deleting an existing file.
17    Delete,
18}
19
20/// Governance and lifecycle hooks for an external writable tree outside the
21/// workspace root (for example a durable memory store).
22pub trait ExternalTreePolicy: std::fmt::Debug + Send + Sync {
23    /// Returns the canonical or configured root directory of the external tree.
24    fn root(&self) -> &Path;
25
26    /// Returns whether `path` is governed by this external tree policy.
27    fn governs_path(&self, path: &Path) -> bool;
28
29    /// Records that `path` was successfully read as UTF-8 text.
30    fn on_text_read(&self, path: &Path) -> Result<(), String>;
31
32    /// Authorizes a pending write of `kind` and `byte_len` bytes to `path`.
33    fn authorize_write(
34        &self,
35        kind: ExternalWriteKind,
36        path: &Path,
37        byte_len: usize,
38    ) -> Result<(), String>;
39
40    /// Notifies the external tree after patch writes have been committed to disk.
41    fn on_writes_committed(&self, paths: &[PathBuf]) -> Result<(), String>;
42}