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
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@
"rustPath": "get_file_editor_sync_hash",
"sourceFile": "src/apps/desktop/src/api/commands.rs",
"signature": "fn get_file_editor_sync_hash( state: State<'_, AppState>, request: GetFileMetadataRequest, ) -> Result<serde_json::Value, String>",
"remoteWorkspacePolicy": "LegacyUnaudited"
"remoteWorkspacePolicy": "RemoteRouted"
},
{
"id": "get_file_metadata",
Expand Down Expand Up @@ -10426,7 +10426,7 @@
"rustPath": "stop_file_watch",
"sourceFile": "src/apps/desktop/src/api/commands.rs",
"signature": "fn stop_file_watch( state: State<'_, AppState>, request: Option<WorkspaceFileWatchRequest>, path: Option<String>, ) -> Result<(), String>",
"remoteWorkspacePolicy": "WorkspaceAgnostic"
"remoteWorkspacePolicy": "RemoteUnsupported"
},
{
"id": "stop_mcp_server",
Expand Down
1 change: 1 addition & 0 deletions scripts/check-core-boundaries.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,7 @@ const CLI_REVIEWED_CORE_FEATURES = [
...ACP_REVIEWED_CORE_FEATURES,
'product-search',
'remote-connect',
'file-watch',
'plugin-runtime',
'opencode-plugin-host',
'dispatch-store',
Expand Down
4 changes: 4 additions & 0 deletions scripts/core-boundaries/cargo-dependency-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,10 @@ export function findProductEntrypointCoreFeatureViolations(
...coreCompatibilityReviewedFeatures,
'product-search',
'remote-connect',
// The CLI Peer Host answers `start_file_watch` / `stop_file_watch` for an
// attached controller, so it consumes the watcher owner directly instead
// of inheriting it from `external-sources`.
'file-watch',
'plugin-runtime',
'opencode-plugin-host',
'ssh-remote',
Expand Down
1 change: 1 addition & 0 deletions src/apps/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ openbitfun-core = { path = "../../crates/assembly/core", features = [
"subscription-auth",
"remote-connect",
"external-sources",
"file-watch",
"plugin-runtime",
"opencode-plugin-host",
"ssh-remote",
Expand Down
4 changes: 4 additions & 0 deletions src/apps/cli/src/peer_host/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub(crate) async fn ensure_peer_host_ready(runtime: &CliRuntimeContext) -> Resul
// A mobile controller or IM bot that opens a workspace on this host changes
// the catalog an attached Desktop controller renders; mirror the hint.
workspace::start_workspace_catalog_publication(Arc::new(PeerControllerEventEmitter));
// The file explorer on an attached controller refreshes from
// `file-system-changed`, so this host must publish its own watch events
// instead of leaving the tree stale after the first read.
openbitfun_core::service::initialize_file_watch_service(Arc::new(PeerControllerEventEmitter));
tracing::info!("CLI peer host services ready");
Ok(())
}
93 changes: 92 additions & 1 deletion src/apps/cli/src/peer_host/commands/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Filesystem HostInvoke handlers.

use openbitfun_core::service::filesystem::path_operations;
use openbitfun_core::service::workspace::WorkspaceKind;
use openbitfun_core::service::{filesystem::FileSystemService, workspace::WorkspaceService};
use serde_json::{json, Value};

use crate::peer_host::args::{get_string, optional_string, request_value};
use crate::peer_host::args::{get_string, optional_bool, optional_string, request_value};
use crate::peer_host::state::PeerHostState;

pub(crate) async fn html_preview_read_resource(args: &Value) -> Result<Value, String> {
Expand Down Expand Up @@ -154,6 +156,95 @@ pub(crate) async fn get_file_tree(
}]))
}

pub(crate) async fn get_file_metadata(
state: &PeerHostState,
args: &Value,
) -> Result<Value, String> {
let request = request_value(args);
let path = get_string(request, "path")?;
let hint = file_connection(state, request, &path).await?;
let metadata =
path_operations::metadata(&state.filesystem_service, &path, hint.as_deref()).await?;
serde_json::to_value(metadata).map_err(|e| format!("Failed to serialize file metadata: {e}"))
}

pub(crate) async fn get_file_editor_sync_hash(
state: &PeerHostState,
args: &Value,
) -> Result<Value, String> {
let request = request_value(args);
let path = get_string(request, "path")?;
let hint = file_connection(state, request, &path).await?;
let (hash, is_remote) =
path_operations::editor_sync_hash(&state.filesystem_service, &path, hint.as_deref())
.await?;
Ok(if is_remote {
json!({ "path": path, "hash": hash, "is_remote": true })
} else {
json!({ "path": path, "hash": hash })
})
}

pub(crate) async fn create_file(state: &PeerHostState, args: &Value) -> Result<Value, String> {
let request = request_value(args);
let path = get_string(request, "path")?;
let hint = file_connection(state, request, &path).await?;
path_operations::create_empty_file(&state.filesystem_service, &path, hint.as_deref()).await?;
Ok(Value::Null)
}

/// Resolve a watch request to a host-local path, mirroring the Desktop Host:
/// a workspace ID is the current ingress, and remote workspaces are refused
/// because the watcher only observes this host's filesystem.
async fn watch_target(
state: &PeerHostState,
request: &Value,
) -> Result<(String, Option<bool>), String> {
if let Some(workspace_id) = optional_string(request, "workspaceId") {
let record = state
.workspace_service
.require_workspace(&workspace_id)
.await
.map_err(|e| e.to_string())?;
if record.workspace_kind == WorkspaceKind::Remote {
return Err("Filesystem watching is not available for remote workspaces".into());
}
return Ok((
get_string(request, "path")?,
optional_bool(request, "recursive"),
));
}
// Temporary 1.0.0 wire ingress; current callers must send the ID request.
let path = get_string(request, "path")?;
if state
.workspace_service
.upgrade_legacy_file_connection(&path, None, None)
.await
.map_err(|e| e.to_string())?
.is_some()
{
return Err("Filesystem watching is not available for remote workspaces".into());
}
Ok((path, optional_bool(request, "recursive")))
}

pub(crate) async fn start_file_watch(state: &PeerHostState, args: &Value) -> Result<Value, String> {
let (path, recursive) = watch_target(state, request_value(args)).await?;
openbitfun_core::service::start_file_watch(path, recursive).await?;
Ok(Value::Null)
}

pub(crate) async fn stop_file_watch(state: &PeerHostState, args: &Value) -> Result<Value, String> {
let (path, _) = watch_target(state, request_value(args)).await?;
openbitfun_core::service::stop_file_watch(path).await?;
Ok(Value::Null)
}

pub(crate) async fn get_watched_paths() -> Result<Value, String> {
let paths = openbitfun_core::service::get_watched_paths().await?;
Ok(json!(paths))
}

pub(crate) async fn check_path_exists(
state: &PeerHostState,
args: &Value,
Expand Down
Loading
Loading