Disable CLI auto-indexing outside agent run

Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
Daniel Michelin
2026-05-05 16:14:53 -07:00
parent 2258cd36f3
commit fca844f806
4 changed files with 81 additions and 16 deletions

View File

@@ -55,12 +55,18 @@ pub struct RepoOutlines {
/// An `AbortHandle` for the active outline computation task.
active_outline_task: Option<AbortHandle>,
indexing_enabled: bool,
}
const REPO_WATCHER_DEBOUNCE_DURATION: Duration = Duration::from_secs(10);
impl RepoOutlines {
pub fn new(ctx: &mut ModelContext<Self>) -> Self {
Self::new_with_indexing_enabled(true, ctx)
}
pub fn new_with_indexing_enabled(indexing_enabled: bool, ctx: &mut ModelContext<Self>) -> Self {
ctx.subscribe_to_model(&AISettings::handle(ctx), |me, event, ctx| {
if let AISettingsChangedEvent::IsAnyAIEnabled { .. } = event {
Self::handle_setting_change_event(me, ctx);
@@ -73,11 +79,13 @@ impl RepoOutlines {
}
});
if !cfg!(any(
test,
feature = "fast_dev",
feature = "integration_tests"
)) {
if indexing_enabled
&& !cfg!(any(
test,
feature = "fast_dev",
feature = "integration_tests"
))
{
ctx.subscribe_to_model(&DetectedRepositories::handle(ctx), |me, event, ctx| {
let DetectedRepositoriesEvent::DetectedGitRepo {
repository,
@@ -98,6 +106,7 @@ impl RepoOutlines {
outlines: Default::default(),
outline_queue: Default::default(),
active_outline_task: Default::default(),
indexing_enabled,
}
}
@@ -108,13 +117,14 @@ impl RepoOutlines {
outlines: Default::default(),
outline_queue: Default::default(),
active_outline_task: Default::default(),
indexing_enabled: true,
}
}
fn index_repo(&mut self, repository: ModelHandle<Repository>, ctx: &mut ModelContext<Self>) {
let repo_path = repository.as_ref(ctx).root_dir().to_local_path_lossy();
if self.get_outline_internal(&repo_path).is_none()
&& Self::should_build_outlines(ctx)
&& self.should_build_outlines(ctx)
&& !self.outline_queue.contains(&repo_path)
{
let outline_state = OutlineState {
@@ -130,15 +140,16 @@ impl RepoOutlines {
/// Check if outlines should be built based on if codebase context enabled OR
/// outline codebase symbols for @ context menu settings.
fn should_build_outlines(ctx: &ModelContext<Self>) -> bool {
UserWorkspaces::as_ref(ctx).is_codebase_context_enabled(ctx)
|| *InputSettings::as_ref(ctx)
.outline_codebase_symbols_for_at_context_menu
.value()
fn should_build_outlines(&self, ctx: &ModelContext<Self>) -> bool {
self.indexing_enabled
&& (UserWorkspaces::as_ref(ctx).is_codebase_context_enabled(ctx)
|| *InputSettings::as_ref(ctx)
.outline_codebase_symbols_for_at_context_menu
.value())
}
fn handle_setting_change_event(me: &mut RepoOutlines, ctx: &mut ModelContext<Self>) {
if Self::should_build_outlines(ctx) {
if me.should_build_outlines(ctx) {
// Add all working directories to the queue and start processing.
for dir in all_working_directories(ctx).into_iter() {
if let Some(repository) =
@@ -193,7 +204,7 @@ impl RepoOutlines {
/// Computes the outline for the repo containing the next path in the queue, if any.
fn compute_next_outline(&mut self, ctx: &mut ModelContext<Self>) {
if Self::should_build_outlines(ctx) && self.active_outline_task.is_none() {
if self.should_build_outlines(ctx) && self.active_outline_task.is_none() {
if let Some(repo_root) = self.outline_queue.pop_front() {
self.compute_outline_for_repo(repo_root, ctx);
}
@@ -222,7 +233,7 @@ impl RepoOutlines {
move |me, res, ctx| {
// Don't process this result if the setting has been disabled.
// The abort handle doesn't always abort.
if Self::should_build_outlines(ctx) {
if me.should_build_outlines(ctx) {
match res {
Ok((canonicalized_path, outline, parse_duration)) => {
send_telemetry_from_ctx!(

View File

@@ -306,7 +306,8 @@ impl PersistedWorkspace {
test,
feature = "fast_dev",
feature = "integration_tests"
)) {
)) && CodebaseIndexManager::as_ref(ctx).is_indexing_enabled()
{
ctx.subscribe_to_model(&DetectedRepositories::handle(ctx), |me, event, ctx| {
let DetectedRepositoriesEvent::DetectedGitRepo { repository, .. } = event;
let repo_path = repository.as_ref(ctx).root_dir().to_local_path_lossy();
@@ -625,6 +626,9 @@ impl PersistedWorkspace {
/// Enables or disables codebase indexing according to the setting.
fn maybe_enable_codebase_indexing(ctx: &mut ModelContext<Self>) {
CodebaseIndexManager::handle(ctx).update(ctx, |manager, ctx| {
if !manager.is_indexing_enabled() {
return;
}
if UserWorkspaces::as_ref(ctx).is_codebase_context_enabled(ctx) {
Self::enable_codebase_indexing(manager, ctx);
} else {

View File

@@ -1668,7 +1668,11 @@ fn initialize_app(
);
}
ctx.add_singleton_model(RepoOutlines::new);
if launch_mode.supports_indexing() {
ctx.add_singleton_model(RepoOutlines::new);
} else {
ctx.add_singleton_model(|ctx| RepoOutlines::new_with_indexing_enabled(false, ctx));
}
ctx.add_singleton_model(|ctx| {
warp_core::sync_queue::SyncQueue::<SyncTask>::new_with_rate_limit(
&ctx.background_executor(),
@@ -1840,6 +1844,7 @@ fn initialize_app(
codebase_limits.max_files_per_repo,
codebase_limits.embedding_generation_batch_size,
server_api_provider.as_ref(ctx).get(),
launch_mode.supports_indexing(),
ctx,
)
});

View File

@@ -179,6 +179,8 @@ pub struct CodebaseIndexManager {
max_files_repo_limit: usize,
embedding_generation_batch_size: usize,
indexing_enabled: bool,
}
impl CodebaseIndexManager {
@@ -189,6 +191,7 @@ impl CodebaseIndexManager {
max_files_repo_limit: usize,
embedding_generation_batch_size: usize,
store_client: Arc<dyn StoreClient>,
indexing_enabled: bool,
ctx: &mut ModelContext<Self>,
) -> Self {
cfg_if::cfg_if! {
@@ -197,6 +200,24 @@ impl CodebaseIndexManager {
ctx.subscribe_to_model(&file_watcher, Self::handle_watcher_event);
}
}
if !indexing_enabled {
log::debug!(
"Codebase indexing disabled for this launch mode; skipping restore of {:?} persisted codebase indices",
persisted_index_metadata.len()
);
return Self {
codebase_indices: HashMap::new(),
store_client,
#[cfg(feature = "local_fs")]
watcher: file_watcher,
build_queue: BuildQueue::empty(),
max_indices: max_index_count,
max_files_repo_limit,
embedding_generation_batch_size,
indexing_enabled,
};
}
log::debug!(
"Received {:?} persisted codebase indices",
@@ -234,6 +255,7 @@ impl CodebaseIndexManager {
max_indices: max_index_count,
max_files_repo_limit,
embedding_generation_batch_size,
indexing_enabled,
};
// Start building the first index in the queue.
@@ -257,6 +279,7 @@ impl CodebaseIndexManager {
max_indices: None,
max_files_repo_limit: 0,
embedding_generation_batch_size: 100,
indexing_enabled: true,
}
}
@@ -462,6 +485,9 @@ impl CodebaseIndexManager {
}
pub fn handle_active_session_changed(&mut self, active_directory: &Path) {
if !self.indexing_enabled {
return;
}
let Some(root_path) = self.root_path_for_codebase(active_directory) else {
return;
};
@@ -517,11 +543,17 @@ impl CodebaseIndexManager {
/// Ensures the current number of indices is below the maximum.
pub fn can_create_new_indices(&self) -> bool {
if !self.indexing_enabled {
return false;
}
self.max_indices
.is_none_or(|max_indices| self.codebase_indices.len() < max_indices)
}
pub fn handle_session_bootstrapped(&mut self, working_directory: &Path) {
if !self.indexing_enabled {
return;
}
let Some(root_path) = self.root_path_for_codebase(working_directory) else {
return;
};
@@ -561,7 +593,14 @@ impl CodebaseIndexManager {
self.codebase_indices.len()
}
pub fn is_indexing_enabled(&self) -> bool {
self.indexing_enabled
}
pub fn index_directory(&mut self, directory: PathBuf, ctx: &mut ModelContext<Self>) {
if !self.indexing_enabled {
return;
}
let directory = dunce::canonicalize(&directory).unwrap_or(directory);
if !self.codebase_indices.contains_key(&directory) {
self.build_and_sync_codebase_index(BuildSource::FromPath(&directory), ctx);
@@ -608,6 +647,9 @@ impl CodebaseIndexManager {
build_source: BuildSource,
ctx: &mut ModelContext<Self>,
) {
if !self.indexing_enabled {
return;
}
if !self.can_create_new_indices() {
return;
}
@@ -974,6 +1016,9 @@ impl CodebaseIndexManager {
directory_path: &Path,
ctx: &mut ModelContext<Self>,
) -> anyhow::Result<()> {
if !self.indexing_enabled {
return Ok(());
}
// Find the root path for this directory's codebase
let Some(repo_path) = self.root_path_for_codebase(directory_path) else {
return Err(anyhow::anyhow!("Failed to find root path for directory"));