Skip to content

Commit ddfea05

Browse files
amitksingh1490autofix-ci[bot]tusharmath
authored
refactor: move repo's to domain (tailcallhq#1801)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
1 parent 910d095 commit ddfea05

91 files changed

Lines changed: 1600 additions & 928 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ forge_display = { path = "crates/forge_display" }
127127
forge_domain = { path = "crates/forge_domain" }
128128
forge_fs = { path = "crates/forge_fs" }
129129
forge_infra = { path = "crates/forge_infra" }
130+
forge_repo = { path = "crates/forge_repo" }
130131
forge_inte = { path = "crates/forge_inte" }
131132
forge_main = { path = "crates/forge_main" }
132133
forge_services = { path = "crates/forge_services" }

‎crates/forge_api/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async-trait.workspace = true
99
forge_domain.workspace = true
1010
forge_stream.workspace = true
1111
forge_services.workspace = true
12-
12+
forge_repo.workspace = true
1313
forge_infra.workspace = true
1414

1515

‎crates/forge_api/src/api.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::path::{Path, PathBuf};
22

33
use anyhow::Result;
4-
use forge_app::dto::{InitAuth, ToolsOverview};
4+
use forge_app::dto::ToolsOverview;
55
use forge_app::{User, UserUsage};
6-
use forge_domain::{AgentId, ModelId};
6+
use forge_domain::{AgentId, InitAuth, ModelId};
77
use forge_stream::MpscStream;
88

99
use crate::*;

‎crates/forge_api/src/forge_api.rs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ use std::path::{Path, PathBuf};
22
use std::sync::Arc;
33

44
use anyhow::{Context, Result};
5-
use forge_app::dto::{InitAuth, LoginInfo, ToolsOverview};
5+
use forge_app::dto::ToolsOverview;
66
use forge_app::{
7-
AgentRegistry, AuthService, CommandLoaderService, ConversationService, EnvironmentService,
8-
FileDiscoveryService, ForgeApp, McpConfigManager, McpService, ProviderRegistry,
9-
ProviderService, Services, User, UserUsage, Walker, WorkflowService,
7+
AgentRegistry, AppConfigService, AuthService, CommandInfra, CommandLoaderService,
8+
ConversationService, EnvironmentInfra, EnvironmentService, FileDiscoveryService, ForgeApp,
9+
McpConfigManager, McpService, ProviderService, Services, User, UserUsage, Walker,
10+
WorkflowService,
1011
};
11-
use forge_domain::*;
12+
use forge_domain::{InitAuth, LoginInfo, *};
1213
use forge_infra::ForgeInfra;
13-
use forge_services::{AppConfigRepository, CommandInfra, ForgeServices};
14+
use forge_repo::ForgeRepo;
15+
use forge_services::ForgeServices;
1416
use forge_stream::MpscStream;
1517

1618
use crate::API;
@@ -34,16 +36,17 @@ impl<A, F> ForgeAPI<A, F> {
3436
}
3537
}
3638

37-
impl ForgeAPI<ForgeServices<ForgeInfra>, ForgeInfra> {
39+
impl ForgeAPI<ForgeServices<ForgeRepo<ForgeInfra>>, ForgeInfra> {
3840
pub fn init(restricted: bool, cwd: PathBuf) -> Self {
3941
let infra = Arc::new(ForgeInfra::new(restricted, cwd));
40-
let app = Arc::new(ForgeServices::new(infra.clone()));
42+
let repo = Arc::new(ForgeRepo::new(infra.clone()));
43+
let app = Arc::new(ForgeServices::new(repo.clone()));
4144
ForgeAPI::new(app, infra)
4245
}
4346
}
4447

4548
#[async_trait::async_trait]
46-
impl<A: Services, F: CommandInfra + AppConfigRepository> API for ForgeAPI<A, F> {
49+
impl<A: Services, F: CommandInfra + EnvironmentInfra> API for ForgeAPI<A, F> {
4750
async fn discover(&self) -> Result<Vec<File>> {
4851
let environment = self.services.get_environment();
4952
let config = Walker::unlimited().cwd(environment.cwd);

‎crates/forge_app/src/agent.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use forge_domain::{
55
Template, ToolCallContext, ToolCallFull, ToolResult,
66
};
77

8+
use crate::services::AppConfigService;
89
use crate::tool_registry::ToolRegistry;
9-
use crate::{ConversationService, ProviderRegistry, ProviderService, Services, TemplateService};
10+
use crate::{ConversationService, ProviderService, Services, TemplateService};
1011

1112
/// Agent service trait that provides core chat and tool call functionality.
1213
/// This trait abstracts the essential operations needed by the Orchestrator.

‎crates/forge_app/src/app.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ use std::sync::Arc;
33

44
use anyhow::Result;
55
use chrono::Local;
6-
use forge_domain::*;
6+
use forge_domain::{InitAuth, *};
77
use forge_stream::MpscStream;
88

99
use crate::apply_tunable_parameters::ApplyTunableParameters;
1010
use crate::authenticator::Authenticator;
11-
use crate::dto::{InitAuth, ToolsOverview};
11+
use crate::dto::ToolsOverview;
1212
use crate::init_conversation_metrics::InitConversationMetrics;
1313
use crate::orch::Orchestrator;
14-
use crate::services::{CustomInstructionsService, TemplateService};
14+
use crate::services::{AppConfigService, CustomInstructionsService, TemplateService};
1515
use crate::set_conversation_id::SetConversationId;
1616
use crate::system_prompt::SystemPrompt;
1717
use crate::tool_registry::ToolRegistry;
1818
use crate::tool_resolver::ToolResolver;
1919
use crate::user_prompt::UserPromptGenerator;
2020
use crate::{
21-
AgentRegistry, ConversationService, EnvironmentService, FileDiscoveryService, ProviderRegistry,
22-
ProviderService, Services, Walker, WorkflowService,
21+
AgentRegistry, ConversationService, EnvironmentService, FileDiscoveryService, ProviderService,
22+
Services, Walker, WorkflowService,
2323
};
2424

2525
/// ForgeApp handles the core chat functionality by orchestrating various

‎crates/forge_app/src/authenticator.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::sync::Arc;
33
use std::time::Duration;
44

55
use backon::{ExponentialBuilder, Retryable};
6-
use forge_domain::RetryConfig;
6+
use forge_domain::{InitAuth, RetryConfig};
77

8-
use crate::dto::InitAuth;
98
use crate::{AuthService, Error};
109

1110
pub struct Authenticator<S> {

‎crates/forge_app/src/dto/mod.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
pub mod anthropic;
44
pub mod openai;
55

6-
mod app_config;
76
mod tools_overview;
87

9-
pub use app_config::*;
108
pub use tools_overview::*;
Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ use std::path::{Path, PathBuf};
33

44
use anyhow::Result;
55
use 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;
129
use reqwest::Response;
1310
use reqwest::header::HeaderMap;
1411
use reqwest_eventsource::EventSource;
1512
use serde::de::DeserializeOwned;
1613
use 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]
7170
pub 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]
122106
pub 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

Comments
 (0)