Skip to main content

PathExtractor

Trait PathExtractor 

Source
pub trait PathExtractor: Send + Sync {
    // Required method
    fn paths(&self, tool_name: &str, input: &Value) -> Vec<String>;
}
Expand description

Extracts the filesystem paths a tool call touches, for cache invalidation.

Implement this per tool (or per tool family) to tell MemoizingMiddleware which cached entries a write-class call should invalidate. On a write-class call, the middleware intersects the paths the write touches against each cached entry’s paths, and evicts any entry whose path set overlaps the write’s.

§Generosity

Impls should be generous — return every path the call could affect, not just the “primary” one. Over-returning is safe (just causes more invalidation, never staleness); under-returning risks a stale cache hit when a write should have invalidated an entry but didn’t. For example, a Grep over a directory should return every file path that could be matched, so a write to any of them invalidates the cached result.

§Tools that touch no paths

Return an empty Vec for tools whose output doesn’t depend on the filesystem (e.g. a pure-computation tool). Such entries are only TTL-evicted, never path-evicted.

Required Methods§

Source

fn paths(&self, tool_name: &str, input: &Value) -> Vec<String>

Paths the call touches, as canonical strings.

The strings are matched verbatim against other calls’ path strings — there is no glob, regex, or prefix logic in the middleware. If a caller wants prefix matching (e.g. a directory write invalidating file reads under it), the impl must emit the matching prefix form itself.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§