pub struct ReadLedger { /* private fields */ }Expand description
Per-session record of which paths an agent has read (or written), keyed by
the path string as the model passed it (lexical . components are normalized
away — see ReadLedger::normalize_key) and valued by a content hash of the
FULL file text plus whether the agent actually observed that full text. It
backs the read-before-edit / staleness guard on the
built-in edit_file/write_file tools: an edit (or an overwrite/append onto
an existing file) is licensed only once the session has observed that path’s
current content, so the model can’t blind-edit a file it never read or clobber
one that changed underneath it.
Interior mutability is a plain std::sync::Mutex (never held across an
.await), so a &ReadLedger can live behind a shared Arc<dyn ToolExecutor>.
Implementations§
Source§impl ReadLedger
impl ReadLedger
pub fn new() -> Self
Sourcepub fn record(&self, path: &str, content: &str, full_read: bool)
pub fn record(&self, path: &str, content: &str, full_read: bool)
Record that path currently holds content (its FULL text). Called on a
successful read and after a successful write/edit, so a later edit is
licensed and staleness compares against this snapshot. full_read says
whether the agent observed all of content, which whole-file writes and
replace-all edits require.
Sourcepub fn check(&self, path: &str, content: &str) -> ReadState
pub fn check(&self, path: &str, content: &str) -> ReadState
Classify path against content (its current FULL text).
Sourcepub fn mutation_lock(&self, path: &str) -> Arc<Mutex<()>> ⓘ
pub fn mutation_lock(&self, path: &str) -> Arc<Mutex<()>> ⓘ
Serialize guarded mutations of one lexical path. The guard spans the read/check/write/record sequence so two same-session edits cannot both pass the stale check against one snapshot and lose one update.
pub fn clear(&self)
Trait Implementations§
Source§impl Debug for ReadLedger
impl Debug for ReadLedger
Auto Trait Implementations§
impl !Freeze for ReadLedger
impl RefUnwindSafe for ReadLedger
impl Send for ReadLedger
impl Sync for ReadLedger
impl Unpin for ReadLedger
impl UnsafeUnpin for ReadLedger
impl UnwindSafe for ReadLedger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more