-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[4/5] Use remote-aware skill locations in UI consumers #11581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ use pathfinder_geometry::vector::vec2f; | |
| use ui_components::{button, Component as _, Options as _}; | ||
| use warp_core::channel::ChannelState; | ||
| use warp_core::ui::theme::color::internal_colors; | ||
| use warp_util::local_or_remote_path::LocalOrRemotePath; | ||
| #[allow(unused_imports)] | ||
| use warp_util::path::{common_path, CleanPathResult}; | ||
| use warpui::elements::new_scrollable::SingleAxisConfig; | ||
|
|
@@ -487,12 +488,14 @@ pub(super) fn render(props: Props, app: &AppContext) -> Box<dyn Element> { | |
| .collect_vec(), | ||
| }; | ||
|
|
||
| let file_paths: Vec<_> = files.iter().map(|f| &f.name).collect(); | ||
| let skill = common_path(&file_paths) | ||
| .and_then(|common| skill_path_from_file_path(&common)) | ||
| .and_then(|skill_path| { | ||
| SkillManager::as_ref(app).skill_by_path(&skill_path) | ||
| }); | ||
| let file_paths = files.iter().map(|file| { | ||
| PathBuf::from(shell_native_absolute_path( | ||
| &file.name, | ||
| props.shell_launch_data, | ||
| props.current_working_directory, | ||
| )) | ||
| }); | ||
| let skill = parsed_skill_for_common_local_paths(file_paths, app); | ||
| output_items.add_child(render_read_files( | ||
| props, | ||
| id, | ||
|
|
@@ -1491,13 +1494,9 @@ fn render_search_codebase( | |
| .render(app) | ||
| .finish() | ||
| } else { | ||
| let file_paths: Vec<_> = | ||
| files.iter().map(|f| &f.file_name).collect(); | ||
| let skill = common_path(&file_paths) | ||
| .and_then(|common| skill_path_from_file_path(&common)) | ||
| .and_then(|skill_path| { | ||
| SkillManager::as_ref(app).skill_by_path(&skill_path) | ||
| }); | ||
| let file_paths = | ||
| files.iter().map(|file| PathBuf::from(&file.file_name)); | ||
| let skill = parsed_skill_for_common_local_paths(file_paths, app); | ||
| let grouped = group_file_contexts_for_display(files, None, None); | ||
| return Some(render_read_files( | ||
| props, | ||
|
|
@@ -1866,6 +1865,18 @@ fn render_read_files( | |
| renderable_action.render(app).finish() | ||
| } | ||
|
|
||
| fn parsed_skill_for_common_local_paths( | ||
| file_paths: impl IntoIterator<Item = PathBuf>, | ||
| app: &AppContext, | ||
| ) -> Option<&ai::skills::ParsedSkill> { | ||
| let file_paths = file_paths.into_iter().collect_vec(); | ||
| common_path(&file_paths) | ||
| .and_then(|common| skill_path_from_file_path(&common)) | ||
| .and_then(|skill_path| { | ||
| SkillManager::as_ref(app).skill_by_path(&LocalOrRemotePath::Local(skill_path)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }) | ||
| } | ||
|
|
||
| fn maybe_render_edit_document( | ||
| props: Props, | ||
| id: &AIAgentActionId, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,8 @@ use warp_core::HostId; | |
| use warp_editor::content::buffer::InitialBufferState; | ||
| use warp_editor::render::element::VerticalExpansionBehavior; | ||
| use warp_util::file::FileSaveError; | ||
| use warp_util::path::common_path; | ||
| use warp_util::local_or_remote_path::LocalOrRemotePath; | ||
| use warp_util::remote_path::RemotePath; | ||
| use warp_util::standardized_path::StandardizedPath; | ||
| use warpui::elements::new_scrollable::{ScrollableAppearance, SingleAxisConfig}; | ||
| use warpui::elements::{ | ||
|
|
@@ -65,10 +66,9 @@ use crate::ai::mcp::{mcp_provider_from_file_path, MCPProvider}; | |
| use crate::ai::paths::host_native_absolute_path; | ||
| use crate::ai::predict::prompt_suggestions::ACCEPT_PROMPT_SUGGESTION_KEYBINDING; | ||
| use crate::ai::skills::{ | ||
| icon_override_for_skill_name, render_skill_button, skill_path_from_file_path, SkillManager, | ||
| icon_override_for_skill_name, render_skill_button, skill_path_from_location, SkillManager, | ||
| SkillOpenOrigin, SkillReference, SkillTelemetryEvent, | ||
| }; | ||
| use crate::code::buffer_location::LocalOrRemotePath; | ||
| use crate::code::diff_viewer::{DiffViewer, DisplayMode}; | ||
| use crate::code::editor::view::{CodeEditorEvent, CodeEditorRenderOptions, CodeEditorView}; | ||
| use crate::code::editor::{add_color, remove_color}; | ||
|
|
@@ -248,7 +248,7 @@ pub enum CodeDiffViewEvent { | |
| /// Emitted when the user opens a skill file from a code diff | ||
| OpenSkill { | ||
| reference: SkillReference, | ||
| path: PathBuf, | ||
| path: LocalOrRemotePath, | ||
| }, | ||
| /// Emitted when the user opens an MCP config file from a code diff | ||
| OpenMCPConfig { | ||
|
|
@@ -423,7 +423,7 @@ pub enum CodeDiffViewAction { | |
| RevertChanges, | ||
| OpenSkill { | ||
| reference: SkillReference, | ||
| path: PathBuf, | ||
| path: LocalOrRemotePath, | ||
| mouse_state: MouseStateHandle, | ||
| }, | ||
| OpenMCPConfig { | ||
|
|
@@ -1572,30 +1572,32 @@ impl CodeDiffView { | |
| .with_cross_axis_alignment(CrossAxisAlignment::Center) | ||
| .with_main_axis_size(MainAxisSize::Min); | ||
|
|
||
| let file_paths: Vec<PathBuf> = self | ||
| let file_locations: Vec<LocalOrRemotePath> = self | ||
| .pending_diffs | ||
| .iter() | ||
| .filter_map(|diff| { | ||
| diff.diff_view | ||
| .as_ref(app) | ||
| .file_path() | ||
| .and_then(|p| p.to_local_path()) | ||
| self.location_for_standardized_path(diff.diff_view.as_ref(app).file_path()?) | ||
| }) | ||
| .collect(); | ||
|
|
||
| // Renders the 'open skill' button if all edited files live in the same skill directory | ||
| let skill = common_path(&file_paths) | ||
| .and_then(|common| skill_path_from_file_path(&common)) | ||
| .and_then(|skill_path| SkillManager::as_ref(app).skill_by_path(&skill_path)); | ||
| if let Some((skill, skill_path)) = skill.and_then(|skill| { | ||
| skill | ||
| .path | ||
| .to_local_path() | ||
| .map(|path| (skill, path.to_path_buf())) | ||
| }) { | ||
| // Renders the 'open skill' button only if every edited file lives in the same skill directory. | ||
| let skill_paths = file_locations | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .iter() | ||
| .map(skill_path_from_location) | ||
| .collect::<Option<Vec<_>>>(); | ||
| let skill = skill_paths.and_then(|skill_paths| { | ||
| let first_path = skill_paths.first()?; | ||
| skill_paths | ||
| .iter() | ||
| .all(|path| path == first_path) | ||
| .then(|| SkillManager::as_ref(app).skill_by_path(first_path)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 [CRITICAL] |
||
| .flatten() | ||
| }); | ||
| if let Some(skill) = skill { | ||
| let skill_path = skill.path.clone(); | ||
| let skill_reference = SkillManager::handle(app) | ||
| .as_ref(app) | ||
| .reference_for_skill_path(&skill.path); | ||
| .reference_for_skill_path(&skill_path); | ||
| let skill_button_handle = self.button_mouse_states.skill_button_handle.clone(); | ||
|
|
||
| let skill_icon_override = icon_override_for_skill_name(&skill.name); | ||
|
|
@@ -1623,7 +1625,12 @@ impl CodeDiffView { | |
| // Renders the 'open config' button only when every MCP config file in this diff | ||
| // belongs to the same provider. Mixed-provider diffs (e.g. editing both a Claude | ||
| // config and a Warp config at once) show no badge to avoid misleading attribution. | ||
| let mcp_configs: Vec<_> = file_paths | ||
| // MCP config actions currently operate on local paths only. | ||
| let local_file_paths: Vec<PathBuf> = file_locations | ||
| .iter() | ||
| .filter_map(|path| path.to_local_path().map(Path::to_path_buf)) | ||
| .collect(); | ||
| let mcp_configs: Vec<_> = local_file_paths | ||
| .iter() | ||
| .filter_map(|path| { | ||
| mcp_provider_from_file_path(path).map(|provider| (provider, path.to_path_buf())) | ||
|
|
@@ -2594,17 +2601,21 @@ impl CodeDiffView { | |
| /// Returns the primary file location as a `LocalOrRemotePath`, | ||
| /// using `diff_session_type` to correctly identify remote files. | ||
| pub fn primary_file_location(&self, app: &AppContext) -> Option<LocalOrRemotePath> { | ||
| let path_str = self.primary_file_path(app)?; | ||
| self.pending_diffs | ||
| .first()? | ||
| .diff_view | ||
| .as_ref(app) | ||
| .file_path() | ||
| .and_then(|path| self.location_for_standardized_path(path)) | ||
| } | ||
|
|
||
| fn location_for_standardized_path(&self, path: &StandardizedPath) -> Option<LocalOrRemotePath> { | ||
| match &self.diff_session_type { | ||
| DiffSessionType::Local => Some(LocalOrRemotePath::Local(PathBuf::from(path_str))), | ||
| DiffSessionType::Remote(host_id) => { | ||
| StandardizedPath::try_new(&path_str).ok().map(|path| { | ||
| LocalOrRemotePath::Remote(warp_util::remote_path::RemotePath { | ||
| host_id: host_id.clone(), | ||
| path, | ||
| }) | ||
| }) | ||
| } | ||
| DiffSessionType::Local => path.to_local_path().map(LocalOrRemotePath::Local), | ||
| DiffSessionType::Remote(host_id) => Some(LocalOrRemotePath::Remote(RemotePath { | ||
| host_id: host_id.clone(), | ||
| path: path.clone(), | ||
| })), | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 [CRITICAL]
skill_path_from_file_pathreturns a localPathBuf, but this wraps it inLocalOrRemotePathbefore callingskill_by_path; the existing lookup accepts a path key, so this call will not type-check. Keep this asskill_by_path(&skill_path)unless the manager API is changed in this PR.