Skip to content

Commit 0224542

Browse files
tusharmathforge-code-agent
authored andcommitted
fix(context_engine): avoid creating workspace during sync
1 parent 4183c41 commit 0224542

4 files changed

Lines changed: 19 additions & 24 deletions

File tree

crates/forge_services/src/context_engine.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::sync::Arc;
55
use anyhow::{Context, Result};
66
use async_trait::async_trait;
77
use forge_app::{
8-
CommandInfra, EnvironmentInfra, FileReaderInfra, SyncProgressCounter,
9-
WalkerInfra, WorkspaceService, WorkspaceStatus, compute_hash,
8+
CommandInfra, EnvironmentInfra, FileReaderInfra, SyncProgressCounter, WalkerInfra,
9+
WorkspaceService, WorkspaceStatus, compute_hash,
1010
};
1111
use forge_domain::{
1212
AuthCredential, AuthDetails, FileHash, FileNode, ProviderId, ProviderRepository, SyncProgress,
@@ -96,8 +96,7 @@ impl<
9696
user_id: &UserId,
9797
workspace_id: &WorkspaceId,
9898
auth_token: &forge_domain::ApiKey,
99-
) -> anyhow::Result<Vec<FileHash>>
100-
{
99+
) -> anyhow::Result<Vec<FileHash>> {
101100
info!(workspace_id = %workspace_id, "Fetching existing file hashes from server to detect changes...");
102101
let workspace_files =
103102
forge_domain::CodeBase::new(user_id.clone(), workspace_id.clone(), ());
@@ -116,8 +115,7 @@ impl<
116115
workspace_id: &WorkspaceId,
117116
token: &forge_domain::ApiKey,
118117
files_to_delete: Vec<String>,
119-
) -> Result<usize>
120-
{
118+
) -> Result<usize> {
121119
if files_to_delete.is_empty() {
122120
return Ok(0);
123121
}
@@ -150,8 +148,7 @@ impl<
150148
token: &forge_domain::ApiKey,
151149
files: Vec<forge_domain::FileNode>,
152150
batch_size: usize,
153-
) -> impl Stream<Item = Result<usize, anyhow::Error>> + Send
154-
{
151+
) -> impl Stream<Item = Result<usize, anyhow::Error>> + Send {
155152
let user_id = user_id.clone();
156153
let workspace_id = workspace_id.clone();
157154
let token = token.clone();
@@ -336,8 +333,7 @@ impl<
336333
/// # Errors
337334
/// Returns an error if the credential is not found, if there's a database
338335
/// error, or if the credential format is invalid
339-
async fn get_workspace_credentials(&self) -> Result<(forge_domain::ApiKey, UserId)>
340-
{
336+
async fn get_workspace_credentials(&self) -> Result<(forge_domain::ApiKey, UserId)> {
341337
let credential = self
342338
.infra
343339
.get_credential(&ProviderId::FORGE_SERVICES)
@@ -376,8 +372,7 @@ impl<
376372
&self,
377373
path: PathBuf,
378374
token: &forge_domain::ApiKey,
379-
) -> Result<Option<forge_domain::WorkspaceInfo>>
380-
{
375+
) -> Result<Option<forge_domain::WorkspaceInfo>> {
381376
let canonical_path = canonicalize_path(path)?;
382377

383378
// Get all workspaces from remote server
@@ -419,8 +414,7 @@ impl<
419414
&self,
420415
path: PathBuf,
421416
token: &forge_domain::ApiKey,
422-
) -> Result<forge_domain::WorkspaceInfo>
423-
{
417+
) -> Result<forge_domain::WorkspaceInfo> {
424418
self.find_workspace_by_path(path, token)
425419
.await?
426420
.context("Workspace not indexed. Please run `forge workspace init` first.")
@@ -432,8 +426,7 @@ impl<
432426
batch_size: usize,
433427
dir_path: &Path,
434428
workspace_id: &WorkspaceId,
435-
) -> impl Stream<Item = Result<FileNode>> + Send
436-
{
429+
) -> impl Stream<Item = Result<FileNode>> + Send {
437430
let dir_path = dir_path.to_path_buf();
438431
let infra = self.infra.clone();
439432
let discovery = self.discovery.clone();
@@ -578,8 +571,10 @@ impl<
578571
}
579572

580573
/// Retrieves workspace information for a specific path.
581-
async fn get_workspace_info(&self, path: PathBuf) -> Result<Option<forge_domain::WorkspaceInfo>>
582-
{
574+
async fn get_workspace_info(
575+
&self,
576+
path: PathBuf,
577+
) -> Result<Option<forge_domain::WorkspaceInfo>> {
583578
let (token, _user_id) = self.get_workspace_credentials().await?;
584579
let workspace = self.find_workspace_by_path(path, &token).await?;
585580

crates/forge_services/src/fd.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ impl<F> FdDefault<F> {
100100
/// Creates a new `RoutingFileDiscovery` using the provided infrastructure
101101
/// for both the git and walker strategies.
102102
pub fn new(infra: Arc<F>) -> Self {
103-
Self {
104-
git: FsGit::new(infra.clone()),
105-
walker: FdWalker::new(infra),
106-
}
103+
Self { git: FsGit::new(infra.clone()), walker: FdWalker::new(infra) }
107104
}
108105
}
109106

crates/forge_services/src/fd_git.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ impl<F: CommandInfra + 'static> FileDiscovery for FsGit<F> {
6767
if paths.is_empty() {
6868
return Err(anyhow::anyhow!("git ls-files returned no files"));
6969
}
70-
info!(file_count = paths.len(), "Discovered files via git ls-files");
70+
info!(
71+
file_count = paths.len(),
72+
"Discovered files via git ls-files"
73+
);
7174
filter_and_resolve(dir_path, paths)
7275
}
7376
}

crates/forge_services/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ mod discovery;
1010
mod env;
1111
mod error;
1212
mod fd;
13-
mod forge_services;
1413
mod fd_git;
1514
mod fd_walker;
15+
mod forge_services;
1616
mod instructions;
1717
mod mcp;
1818
mod policy;

0 commit comments

Comments
 (0)