Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/forge_domain/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,20 @@ pub trait FuzzySearchRepository: Send + Sync {
search_all: bool,
) -> Result<Vec<SearchMatch>>;
}

/// Repository for fetching server-side ignore patterns.
///
/// The backend owns the canonical list of gitignore-style patterns used to
/// decide which files are indexable. Clients (e.g. the CLI) fetch the raw
/// patterns through this repository so they can filter files identically to
/// the server without duplicating the rules.
#[async_trait::async_trait]
pub trait IgnorePatternsRepository: Send + Sync {
/// Returns the raw contents of the server's ignore_patterns file
/// (gitignore syntax).
///
/// # Errors
/// Returns an error if the server cannot be reached or returns an invalid
/// response.
async fn list_ignore_patterns(&self) -> Result<String>;
}
11 changes: 11 additions & 0 deletions crates/forge_repo/proto/forge.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ service ForgeService {

// Searches for needle in haystack using fuzzy search
rpc FuzzySearch(FuzzySearchRequest) returns (FuzzySearchResponse);

// Returns the raw server-side ignore patterns (gitignore syntax) so
// clients (e.g. the CLI) can filter files identically to the server.
rpc ListIgnorePatterns(ListIgnorePatternsRequest) returns (ListIgnorePatternsResponse);
}

// Node types
Expand Down Expand Up @@ -360,3 +364,10 @@ message SearchMatch {
uint32 start_line = 1;
uint32 end_line = 2;
}

message ListIgnorePatternsRequest {}

message ListIgnorePatternsResponse {
// Raw contents of the server's ignore_patterns file (gitignore syntax).
string patterns = 1;
}
18 changes: 15 additions & 3 deletions crates/forge_repo/src/forge_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use forge_config::ForgeConfig;
use forge_domain::{
AnyProvider, AuthCredential, ChatCompletionMessage, ChatRepository, CommandOutput, Context,
Conversation, ConversationId, ConversationRepository, Environment, FileInfo,
FuzzySearchRepository, McpServerConfig, MigrationResult, Model, ModelId, Provider, ProviderId,
ProviderRepository, ResultStream, SearchMatch, Skill, SkillRepository, Snapshot,
SnapshotRepository,
FuzzySearchRepository, IgnorePatternsRepository, McpServerConfig, MigrationResult, Model,
ModelId, Provider, ProviderId, ProviderRepository, ResultStream, SearchMatch, Skill,
SkillRepository, Snapshot, SnapshotRepository,
};
// Re-export CacacheStorage from forge_infra
pub use forge_infra::CacacheStorage;
Expand All @@ -29,6 +29,7 @@ use crate::conversation::ConversationRepositoryImpl;
use crate::database::{DatabasePool, PoolConfig};
use crate::fs_snap::ForgeFileSnapshotService;
use crate::fuzzy_search::ForgeFuzzySearchRepository;
use crate::ignore_patterns::ForgeIgnorePatternsRepository;
use crate::provider::{ForgeChatRepository, ForgeProviderRepository};
use crate::skill::ForgeSkillRepository;
use crate::validation::ForgeValidationRepository;
Expand All @@ -50,6 +51,7 @@ pub struct ForgeRepo<F> {
skill_repository: Arc<ForgeSkillRepository<F>>,
validation_repository: Arc<ForgeValidationRepository<F>>,
fuzzy_search_repository: Arc<ForgeFuzzySearchRepository<F>>,
ignore_patterns_repository: Arc<ForgeIgnorePatternsRepository<F>>,
}

impl<
Expand Down Expand Up @@ -83,6 +85,8 @@ impl<
let skill_repository = Arc::new(ForgeSkillRepository::new(infra.clone()));
let validation_repository = Arc::new(ForgeValidationRepository::new(infra.clone()));
let fuzzy_search_repository = Arc::new(ForgeFuzzySearchRepository::new(infra.clone()));
let ignore_patterns_repository =
Arc::new(ForgeIgnorePatternsRepository::new(infra.clone()));
Self {
infra,
file_snapshot_service,
Expand All @@ -95,6 +99,7 @@ impl<
skill_repository,
validation_repository,
fuzzy_search_repository,
ignore_patterns_repository,
}
}
}
Expand Down Expand Up @@ -628,6 +633,13 @@ impl<F: GrpcInfra + Send + Sync> FuzzySearchRepository for ForgeRepo<F> {
}
}

#[async_trait::async_trait]
impl<F: GrpcInfra + Send + Sync> IgnorePatternsRepository for ForgeRepo<F> {
async fn list_ignore_patterns(&self) -> anyhow::Result<String> {
self.ignore_patterns_repository.list_ignore_patterns().await
}
}

impl<F: GrpcInfra> GrpcInfra for ForgeRepo<F> {
fn channel(&self) -> anyhow::Result<tonic::transport::Channel> {
self.infra.channel()
Expand Down
42 changes: 42 additions & 0 deletions crates/forge_repo/src/ignore_patterns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use async_trait::async_trait;
use forge_app::GrpcInfra;
use forge_domain::IgnorePatternsRepository;

use crate::proto_generated::ListIgnorePatternsRequest;
use crate::proto_generated::forge_service_client::ForgeServiceClient;

/// gRPC implementation of [`IgnorePatternsRepository`].
///
/// Fetches the raw server-side ignore patterns file so the CLI can apply the
/// same filtering rules as the server without re-implementing them locally.
pub struct ForgeIgnorePatternsRepository<I> {
infra: Arc<I>,
}

impl<I> ForgeIgnorePatternsRepository<I> {
/// Create a new repository backed by the provided gRPC infrastructure.
///
/// # Arguments
/// * `infra` - Infrastructure that provides the gRPC channel.
pub fn new(infra: Arc<I>) -> Self {
Self { infra }
}
}

#[async_trait]
impl<I: GrpcInfra> IgnorePatternsRepository for ForgeIgnorePatternsRepository<I> {
async fn list_ignore_patterns(&self) -> Result<String> {
let channel = self.infra.channel()?;
let mut client = ForgeServiceClient::new(channel);
let response = client
.list_ignore_patterns(tonic::Request::new(ListIgnorePatternsRequest {}))
.await
.context("Failed to call ListIgnorePatterns gRPC")?
.into_inner();

Ok(response.patterns)
}
}
1 change: 1 addition & 0 deletions crates/forge_repo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod database;
mod forge_repo;
mod fs_snap;
mod fuzzy_search;
mod ignore_patterns;
mod provider;
mod skill;
mod validation;
Expand Down
Loading
Loading