@@ -3,18 +3,17 @@ use std::path::{Path, PathBuf};
33
44use anyhow:: Result ;
55use bytes:: Bytes ;
6- use forge_app:: domain:: {
7- CommandOutput , Conversation , ConversationId , Environment , McpServerConfig , ToolDefinition ,
8- ToolName , ToolOutput ,
6+ use forge_domain:: {
7+ CommandOutput , Environment , FileInfo , McpServerConfig , ToolDefinition , ToolName , ToolOutput ,
98} ;
10- use forge_app:: { WalkedFile , Walker } ;
11- use forge_snaps:: Snapshot ;
129use reqwest:: Response ;
1310use reqwest:: header:: HeaderMap ;
1411use reqwest_eventsource:: EventSource ;
1512use serde:: de:: DeserializeOwned ;
1613use url:: Url ;
1714
15+ use crate :: { WalkedFile , Walker } ;
16+
1817/// Infrastructure trait for accessing environment configuration and system
1918/// variables.
2019///
@@ -64,18 +63,13 @@ pub trait FileReaderInfra: Send + Sync {
6463 path : & Path ,
6564 start_line : u64 ,
6665 end_line : u64 ,
67- ) -> anyhow:: Result < ( String , forge_fs :: FileInfo ) > ;
66+ ) -> anyhow:: Result < ( String , FileInfo ) > ;
6867}
6968
7069#[ async_trait:: async_trait]
7170pub trait FileWriterInfra : Send + Sync {
7271 /// Writes the content of a file at the specified path.
73- async fn write (
74- & self ,
75- path : & Path ,
76- contents : Bytes ,
77- capture_snapshot : bool ,
78- ) -> anyhow:: Result < ( ) > ;
72+ async fn write ( & self , path : & Path , contents : Bytes ) -> anyhow:: Result < ( ) > ;
7973
8074 /// Writes content to a temporary file with the given prefix and extension,
8175 /// and returns its path. The file will be kept (not deleted) after
@@ -107,16 +101,6 @@ pub trait FileDirectoryInfra {
107101 async fn create_dirs ( & self , path : & Path ) -> anyhow:: Result < ( ) > ;
108102}
109103
110- /// Service for managing file snapshots
111- #[ async_trait:: async_trait]
112- pub trait SnapshotInfra : Send + Sync {
113- // Creation
114- async fn create_snapshot ( & self , file_path : & Path ) -> Result < Snapshot > ;
115-
116- /// Restores the most recent snapshot for the given file path
117- async fn undo_snapshot ( & self , file_path : & Path ) -> Result < ( ) > ;
118- }
119-
120104/// Service for executing shell commands
121105#[ async_trait:: async_trait]
122106pub trait CommandInfra : Send + Sync {
@@ -224,26 +208,25 @@ pub trait DirectoryReaderInfra: Send + Sync {
224208 ) -> anyhow:: Result < Vec < ( PathBuf , String ) > > ;
225209}
226210
227- /// Generic cache infrastructure trait for content-addressable storage.
211+ /// Generic cache repository for content-addressable storage.
228212///
229213/// This trait provides an abstraction over caching operations with support for
230214/// arbitrary key and value types. Keys must be hashable and serializable, while
231215/// values must be serializable. The trait is designed to work with
232216/// content-addressable storage systems like cacache.
233217///
234- /// Type parameters:
235- /// - `K`: Key type with bounds for hashing and serialization
236- /// - `V`: Value type with bounds for serialization
237- ///
238218/// All operations return `anyhow::Result` for consistent error handling across
239219/// the infrastructure layer.
240220#[ async_trait:: async_trait]
241- pub trait CacheRepository : Send + Sync {
221+ pub trait KVStore : Send + Sync {
242222 /// Retrieves a value from the cache by its key.
243223 ///
244- /// Returns `Ok(Some(value))` if the key exists in the cache,
245- /// `Ok(None)` if the key doesn't exist, or an error if the operation fails.
246- async fn cache_get < K , V > ( & self , key : & K ) -> anyhow:: Result < Option < V > >
224+ /// # Arguments
225+ /// * `key` - The key to look up in the cache
226+ ///
227+ /// # Errors
228+ /// Returns an error if the cache operation fails
229+ async fn cache_get < K , V > ( & self , key : & K ) -> Result < Option < V > >
247230 where
248231 K : Hash + Sync ,
249232 V : serde:: Serialize + DeserializeOwned + Send ;
@@ -252,33 +235,23 @@ pub trait CacheRepository: Send + Sync {
252235 ///
253236 /// If the key already exists, the value is overwritten.
254237 /// Uses content-addressable storage for integrity verification.
255- async fn cache_set < K , V > ( & self , key : & K , value : & V ) -> anyhow:: Result < ( ) >
238+ ///
239+ /// # Arguments
240+ /// * `key` - The key to store the value under
241+ /// * `value` - The value to cache
242+ ///
243+ /// # Errors
244+ /// Returns an error if the cache operation fails
245+ async fn cache_set < K , V > ( & self , key : & K , value : & V ) -> Result < ( ) >
256246 where
257247 K : Hash + Sync ,
258248 V : serde:: Serialize + Sync ;
259249
260250 /// Clears all entries from the cache.
261251 ///
262252 /// This operation removes all cached data. Use with caution.
263- async fn cache_clear ( & self ) -> anyhow:: Result < ( ) > ;
264- }
265-
266- #[ async_trait:: async_trait]
267- pub trait ConversationRepository : Send + Sync {
268- async fn upsert_conversation ( & self , conversation : Conversation ) -> anyhow:: Result < ( ) > ;
269- async fn get_conversation (
270- & self ,
271- conversation_id : & ConversationId ,
272- ) -> anyhow:: Result < Option < Conversation > > ;
273- async fn get_all_conversations (
274- & self ,
275- limit : Option < usize > ,
276- ) -> anyhow:: Result < Option < Vec < Conversation > > > ;
277- async fn get_last_conversation ( & self ) -> anyhow:: Result < Option < Conversation > > ;
278- }
279-
280- #[ async_trait:: async_trait]
281- pub trait AppConfigRepository : Send + Sync {
282- async fn get_app_config ( & self ) -> anyhow:: Result < forge_app:: dto:: AppConfig > ;
283- async fn set_app_config ( & self , config : & forge_app:: dto:: AppConfig ) -> anyhow:: Result < ( ) > ;
253+ ///
254+ /// # Errors
255+ /// Returns an error if the cache clear operation fails
256+ async fn cache_clear ( & self ) -> Result < ( ) > ;
284257}
0 commit comments