Skip to content
Merged
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
18 changes: 14 additions & 4 deletions docs/features/remote-workspaces.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Remote SSH, container, and WSL workspaces

Flashgrep accelerated search is currently unavailable for remote workspaces.
Index controls are hidden; content-search operations that depend on Flashgrep
return an explicit unsupported error. Remote file-name search remains available.
OpenBitFun never falls back to searching the controller filesystem for a remote path.
Flashgrep accelerated search is currently unavailable for remote workspaces, so
index controls are hidden. Content search still works: it runs through the
workspace's own file and shell providers, using `rg` or a capable `grep` on the
target to select candidate files when available and otherwise reading the files
through the remote provider, which can be slow on large trees. It follows the
local search defaults (ignore rules at the search root and below, default
excluded directories, binary and over-10 MB files skipped), except that global
Git excludes and the exclude file of a parent repository are not applied. Files
and directories the target refuses to read are skipped and logged. A search that
fails or times out reports an explicit error. Remote file-name search remains
available. Global search (the command palette) stays local-only and reports remote
projects as unsupported, because each keystroke would hold its file results behind
a remote scan. OpenBitFun never falls back to searching the controller filesystem
for a remote path.

OpenBitFun remote workspaces use one saved target for the file explorer, terminal,
Agent commands, and workspace tools. The target can be:
Expand Down
155 changes: 114 additions & 41 deletions src/apps/desktop/src/api/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::api::path_target::{
};
use crate::api::search_api::{
build_content_search_request, group_search_results, prepare_content_search_runner,
remote_content_search_refusal, remote_content_search_refusal_message,
remote_content_search_refusal_message, remote_content_search_target,
search_file_contents_via_workspace_search, search_metadata_from_content_result,
should_use_workspace_search, SearchMetadataResponse,
search_remote_contents, should_use_workspace_search, RemoteContentSearchQuery,
SearchMetadataResponse,
};
use crate::api::workspace_activation::spawn_workspace_background_warmup;
use crate::startup_trace::DesktopStartupTrace;
Expand Down Expand Up @@ -4976,31 +4977,26 @@ pub async fn search_files(
request.search_content && should_use_workspace_search(&state, &workspace).await;
let result = if request.search_content {
if workspace.workspace_kind == WorkspaceKind::Remote {
if !use_workspace_search {
Err(
remote_content_search_refusal(&state, "search_files", &workspace)
.await
.unwrap_or_else(|| {
remote_content_search_refusal_message(
"search_files",
&request.root_path,
"remote workspace search is unavailable",
)
}),
)
} else {
search_file_contents_via_workspace_search(
&state,
&workspace,
&request.pattern,
request.case_sensitive,
request.use_regex,
request.whole_word,
max_results,
)
.await
.map(|result| result.outcome.results)
}
let outcome = match remote_content_search_target(&state, &workspace).await {
Ok(target) => {
search_remote_contents(
target,
RemoteContentSearchQuery {
pattern: request.pattern.clone(),
case_sensitive: request.case_sensitive,
use_regex: request.use_regex,
whole_word: request.whole_word,
limit: max_results,
cancel_flag: cancel_flag.clone(),
},
)
.await
}
Err(error) => Err(error),
};
outcome.map(|outcome| outcome.results).map_err(|error| {
remote_content_search_refusal_message("search_files", &request.root_path, &error)
})
} else {
let filename_outcome = state
.filesystem_service
Expand Down Expand Up @@ -5234,12 +5230,21 @@ pub async fn search_file_contents(
.await?;
request.root_path = workspace.root_path.to_string_lossy().into_owned();

if let Some(message) =
remote_content_search_refusal(&state, "search_file_contents", &workspace).await
{
error!("Content search refused: {}", message);
return Err(message);
}
let remote_target = if workspace.workspace_kind == WorkspaceKind::Remote {
Some(
remote_content_search_target(&state, &workspace)
.await
.map_err(|error| {
remote_content_search_refusal_message(
"search_file_contents",
&request.root_path,
&error,
)
})?,
)
} else {
None
};

let search_id = request.search_id.clone();
let cancel_flag = register_search(&state, search_id.as_deref());
Expand All @@ -5254,7 +5259,28 @@ pub async fn search_file_contents(
include_directories: false,
};

let result = if should_use_workspace_search(&state, &workspace).await {
let result = if let Some(target) = remote_target {
search_remote_contents(
target,
RemoteContentSearchQuery {
pattern: request.pattern.clone(),
case_sensitive: request.case_sensitive,
use_regex: request.use_regex,
whole_word: request.whole_word,
limit,
cancel_flag,
},
)
.await
.map(|outcome| (outcome, None))
.map_err(|error| {
remote_content_search_refusal_message(
"search_file_contents",
&request.root_path,
&error,
)
})
} else if should_use_workspace_search(&state, &workspace).await {
search_file_contents_via_workspace_search(
&state,
&workspace,
Expand Down Expand Up @@ -5476,12 +5502,21 @@ pub async fn start_search_file_contents_stream(
.await?;
request.root_path = workspace.root_path.to_string_lossy().into_owned();

if let Some(message) =
remote_content_search_refusal(&state, "start_search_file_contents_stream", &workspace).await
{
error!("Content search stream refused: {}", message);
return Err(message);
}
let remote_target = if workspace.workspace_kind == WorkspaceKind::Remote {
Some(
remote_content_search_target(&state, &workspace)
.await
.map_err(|error| {
remote_content_search_refusal_message(
"start_search_file_contents_stream",
&request.root_path,
&error,
)
})?,
)
} else {
None
};

let search_id = ensure_search_id(request.search_id.clone(), "content-stream");
let cancel_flag = register_search(&state, Some(&search_id));
Expand Down Expand Up @@ -5530,7 +5565,45 @@ pub async fn start_search_file_contents_stream(
));

tokio::spawn(async move {
let result = if use_workspace_search {
let result = if let Some(target) = remote_target {
let result = search_remote_contents(
target,
RemoteContentSearchQuery {
pattern: pattern.clone(),
case_sensitive,
use_regex,
whole_word,
limit,
cancel_flag: cancel_flag.clone(),
},
)
.await;
if let Ok(outcome) = &result {
if !cancel_flag
.as_ref()
.is_some_and(|flag| flag.load(Ordering::Relaxed))
{
for group in group_search_results(outcome.results.clone()) {
openbitfun_core::infrastructure::FileSearchProgressSink::report(
progress_sink.as_ref(),
group,
);
}
openbitfun_core::infrastructure::FileSearchProgressSink::flush(
progress_sink.as_ref(),
);
}
}
result.map(|outcome| (outcome, None)).map_err(|error| {
openbitfun_core::util::errors::OpenBitFunError::service(
remote_content_search_refusal_message(
"start_search_file_contents_stream",
&root_path,
&error,
),
)
})
} else if use_workspace_search {
let result = workspace_search_runner
.as_ref()
.expect("workspace search runner should exist when enabled")
Expand Down
77 changes: 59 additions & 18 deletions src/apps/desktop/src/api/search_api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::api::app_state::AppState;
use openbitfun_core::infrastructure::{FileSearchResult, FileSearchResultGroup, SearchMatchType};
use openbitfun_core::infrastructure::{
FileSearchOutcome, FileSearchResult, FileSearchResultGroup, SearchMatchType,
};
use openbitfun_core::service::search::{
remote_workspace_search_service_for_workspace, workspace_search_daemon_available,
workspace_search_feature_enabled, ContentSearchRequest, ContentSearchResult,
RemoteWorkspaceSearchService, WorkspaceSearchBackend, WorkspaceSearchRepoPhase,
remote_workspace_search_service_for_workspace, search_remote_workspace_contents,
workspace_search_daemon_available, workspace_search_feature_enabled, ContentSearchRequest,
ContentSearchResult, RemoteContentSearch, RemoteWorkspaceSearchService, WorkspaceSearchBackend,
WorkspaceSearchRepoPhase,
};
use openbitfun_core::service::workspace::{WorkspaceInfo, WorkspaceKind};
use serde::{Deserialize, Serialize};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tauri::State;

Expand Down Expand Up @@ -145,7 +149,7 @@ pub(crate) async fn should_use_workspace_search(
.is_none()
}

/// Builds the refusal sentence used when a remote workspace cannot be searched over SSH.
/// Builds the failure sentence used when a remote workspace cannot be searched over SSH.
///
/// The legacy content walker only sees the controller filesystem, so running it for a remote
/// root would answer a question about the wrong machine. Callers must surface this instead.
Expand All @@ -160,23 +164,60 @@ pub(crate) fn remote_content_search_refusal_message(
)
}

/// Returns a refusal message when `root_path` belongs to a remote workspace whose remote search
/// path is unavailable, and `None` when the path is local or remote search can serve the request.
pub(crate) async fn remote_content_search_refusal(
/// Where a remote content search runs, resolved up front so a streaming command can move it
/// into its background task without borrowing Tauri state.
pub(crate) struct RemoteContentSearchTarget {
connection_id: String,
root_path: String,
}

/// The fields a content-search command already holds, minus the routing target.
pub(crate) struct RemoteContentSearchQuery {
pub pattern: String,
pub case_sensitive: bool,
pub use_regex: bool,
pub whole_word: bool,
pub limit: usize,
pub cancel_flag: Option<Arc<AtomicBool>>,
}

/// Selects the connection from the workspace record, because a POSIX root alone does not
/// identify a remote workspace when several connections expose the same path.
pub(crate) async fn remote_content_search_target(
state: &State<'_, AppState>,
command: &str,
workspace: &WorkspaceInfo,
) -> Option<String> {
if workspace.workspace_kind != WorkspaceKind::Remote {
return None;
) -> Result<RemoteContentSearchTarget, String> {
match crate::api::path_target::resolve_desktop_workspace_target(state, &workspace.id).await? {
crate::api::path_target::DesktopPathTarget::Remote {
requested_path,
entry,
} => Ok(RemoteContentSearchTarget {
connection_id: entry.connection_id,
root_path: requested_path,
}),
crate::api::path_target::DesktopPathTarget::Local { .. } => {
Err("the workspace is not bound to a remote connection".to_string())
}
}
}

let reason = workspace_search_unavailable_message(state, workspace).await?;
Some(remote_content_search_refusal_message(
command,
&workspace.root_path.to_string_lossy(),
&reason,
))
/// Runs a content search on the remote host. Flashgrep is never selected for a remote root, and
/// a failure stays a failure: nothing here can fall back to the controller filesystem.
pub(crate) async fn search_remote_contents(
target: RemoteContentSearchTarget,
query: RemoteContentSearchQuery,
) -> Result<FileSearchOutcome, String> {
search_remote_workspace_contents(RemoteContentSearch {
connection_id: target.connection_id,
root_path: target.root_path,
pattern: query.pattern,
case_sensitive: query.case_sensitive,
use_regex: query.use_regex,
whole_word: query.whole_word,
limit: query.limit,
cancel_flag: query.cancel_flag,
})
.await
}

pub(crate) async fn prepare_content_search_runner(
Expand Down
2 changes: 2 additions & 0 deletions src/crates/assembly/core/src/service/search/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "ssh-remote")]
mod remote;
mod remote_content;
#[cfg(not(feature = "ssh-remote"))]
mod remote_disabled;
pub mod service;
Expand All @@ -16,6 +17,7 @@ pub use openbitfun_services_integrations::workspace_search::{
};
#[cfg(feature = "ssh-remote")]
pub use remote::{remote_workspace_search_service_for_workspace, RemoteWorkspaceSearchService};
pub use remote_content::{search_remote_workspace_contents, RemoteContentSearch};
#[cfg(not(feature = "ssh-remote"))]
pub use remote_disabled::{
remote_workspace_search_service_for_workspace, RemoteWorkspaceSearchService,
Expand Down
Loading
Loading