Skip to content
Closed
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
2 changes: 2 additions & 0 deletions app/src/ai/blocklist/action_model/execute/read_skill_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::Write;
use std::path::PathBuf;

use ai::skills::{parse_skill, ParsedSkill, SkillProvider, SkillReference, SkillScope};
use remote_server::manager::RemoteServerManager;
use repo_metadata::repositories::DetectedRepositories;
use repo_metadata::watcher::DirectoryWatcher;
use repo_metadata::RepoMetadataModel;
Expand Down Expand Up @@ -30,6 +31,7 @@ fn initialize_app(app: &mut App) {
app.add_singleton_model(RepoMetadataModel::new);
app.add_singleton_model(HomeDirectoryWatcher::new_for_test);
app.add_singleton_model(WarpManagedPathsWatcher::new_for_testing);
app.add_singleton_model(RemoteServerManager::new);
app.add_singleton_model(SkillManager::new);
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/ai/blocklist/block/view_impl/output_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ai::agent::action::UploadArtifactRequest;
use ai::skills::{ParsedSkill, SkillProvider, SkillScope};
use remote_server::manager::RemoteServerManager;
use repo_metadata::repositories::DetectedRepositories;
use repo_metadata::{DirectoryWatcher, RepoMetadataModel};
use warp_util::host_id::HostId;
Expand Down Expand Up @@ -106,6 +107,7 @@ fn parsed_skill_for_common_locations_resolves_cached_remote_skill() {
app.add_singleton_model(RepoMetadataModel::new);
app.add_singleton_model(HomeDirectoryWatcher::new_for_test);
app.add_singleton_model(WarpManagedPathsWatcher::new_for_testing);
app.add_singleton_model(RemoteServerManager::new);
let manager = app.add_singleton_model(SkillManager::new);
manager.update(&mut app, |manager, _| {
manager.add_skill_for_testing(skill.clone());
Expand Down Expand Up @@ -143,6 +145,7 @@ fn parsed_skill_for_common_locations_does_not_mix_remote_hosts() {
app.add_singleton_model(RepoMetadataModel::new);
app.add_singleton_model(HomeDirectoryWatcher::new_for_test);
app.add_singleton_model(WarpManagedPathsWatcher::new_for_testing);
app.add_singleton_model(RemoteServerManager::new);
let manager = app.add_singleton_model(SkillManager::new);
manager.update(&mut app, |manager, _| {
manager.add_skill_for_testing(skill);
Expand Down
36 changes: 25 additions & 11 deletions app/src/ai/blocklist/context_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;
use ai::project_context::model::ProjectContextModel;
use parking_lot::FairMutex;
use warp_core::features::FeatureFlag;
use warp_util::local_or_remote_path::LocalOrRemotePath;
use warpui::{
AppContext, Entity, EntityId, ModelContext, ModelHandle, SingletonEntity, WeakModelHandle,
};
Expand Down Expand Up @@ -394,6 +395,25 @@ impl BlocklistAIContextModel {
/// If `is_user_query` is true, includes blocks, selected text, and images as context.
/// If false, excludes these user-specific contexts but includes everything else.
pub fn pending_context(&self, app: &AppContext, is_user_query: bool) -> Vec<AIAgentContext> {
let current_working_directory_location = self.current_pwd().and_then(|path| {
PathBuf::from_str(&path)
.ok()
.and_then(|path| path.canonicalize().ok())
.map(LocalOrRemotePath::Local)
});
self.pending_context_for_location(
app,
is_user_query,
current_working_directory_location.as_ref(),
)
}

pub fn pending_context_for_location(
&self,
app: &AppContext,
is_user_query: bool,
current_working_directory_location: Option<&LocalOrRemotePath>,
) -> Vec<AIAgentContext> {
let pwd = self.current_pwd();
let is_pwd_indexed = if cfg!(feature = "agent_mode_evals") {
// In evals, we want to disable file outline based search. Full
Expand All @@ -406,15 +426,9 @@ impl BlocklistAIContextModel {
})
};

let project_rules = if let Some(pwd) = pwd.clone().and_then(|path| {
PathBuf::from_str(&path)
.ok()
.and_then(|s| s.canonicalize().ok())
}) {
ProjectContextModel::as_ref(app).find_applicable_rules(&pwd)
} else {
None
};
let project_rules = current_working_directory_location.and_then(|pwd| {
ProjectContextModel::as_ref(app).find_applicable_rules_at_location(pwd)
});

let mut context = Vec::new();

Expand Down Expand Up @@ -451,14 +465,14 @@ impl BlocklistAIContextModel {
// Always include project rules if available
if let Some(rules) = project_rules {
context.push(AIAgentContext::ProjectRules {
root_path: rules.root_path.to_string_lossy().into(),
root_path: rules.root_path.display_path(),
active_rules: rules
.active_rules
.into_iter()
.map(|rule| {
let line_count = rule.content.lines().count();
FileContext {
file_name: rule.path.to_string_lossy().into(),
file_name: rule.path.display_path(),
content: AnyFileContent::StringContent(rule.content.clone()),
line_range: None,
last_modified: None,
Expand Down
7 changes: 6 additions & 1 deletion app/src/ai/blocklist/controller/input_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ pub(super) fn input_context_for_request(
additional_context: Vec<AIAgentContext>,
app: &AppContext,
) -> Arc<[AIAgentContext]> {
let mut context = context_model.pending_context(app, is_user_query);
let current_working_directory_location = active_session.current_working_directory_location(app);
let mut context = context_model.pending_context_for_location(
app,
is_user_query,
current_working_directory_location.as_ref(),
);

context.push(AIAgentContext::CurrentTime {
current_time: Local::now(),
Expand Down
3 changes: 2 additions & 1 deletion app/src/ai/facts/view/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use warp_core::ui::appearance::Appearance;
use warp_util::local_or_remote_path::LocalOrRemotePath;
use warpui::elements::{
Align, ChildView, ClippedScrollStateHandle, ClippedScrollable, ConstrainedBox, Container,
CrossAxisAlignment, Expanded, Flex, MainAxisAlignment, MainAxisSize, ParentElement,
Expand Down Expand Up @@ -55,7 +56,7 @@ impl std::fmt::Display for AIFactPage {
pub enum AIFactViewEvent {
Pane(PaneEvent),
OpenSettings,
OpenFile(PathBuf),
OpenFile(LocalOrRemotePath),
InitializeProject(PathBuf),
}

Expand Down
23 changes: 13 additions & 10 deletions app/src/ai/facts/view/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use markdown_parser::weight::CustomWeight;
use markdown_parser::{FormattedText, FormattedTextFragment, FormattedTextLine};
use warp_core::ui::appearance::{Appearance, AppearanceEvent};
use warp_core::ui::theme::color::internal_colors;
use warp_util::local_or_remote_path::LocalOrRemotePath;
use warpui::elements::{
Align, Border, ChildView, ConstrainedBox, Container, CornerRadius, CrossAxisAlignment,
Expanded, Flex, FormattedTextElement, HighlightedHyperlink, Hoverable, MainAxisAlignment,
Expand Down Expand Up @@ -68,7 +69,7 @@ pub enum RuleViewEvent {
AddRule,
Edit(SyncId),
OpenSettings,
OpenFile(PathBuf),
OpenFile(LocalOrRemotePath),
InitializeProject(PathBuf),
}

Expand All @@ -79,7 +80,7 @@ pub enum RuleViewAction {
Edit(SyncId),
OpenSettings,
SelectScope(RuleScope),
OpenFile(PathBuf),
OpenFile(LocalOrRemotePath),
}

#[derive(Default, Debug, Clone)]
Expand All @@ -101,7 +102,7 @@ struct CloudRuleRow {
/// plus an "Open file" button.
#[derive(Debug, Clone)]
struct FileBackedRow {
file_path: PathBuf,
file_path: LocalOrRemotePath,
mouse_state: MouseStateHandle,
}

Expand All @@ -126,9 +127,9 @@ impl RuleRow {
}
RuleRow::FileBacked(row) => row
.file_path
.to_str()
.map(|s| s.to_lowercase().contains(search_term))
.unwrap_or(false),
.display_path()
.to_lowercase()
.contains(search_term),
}
}

Expand All @@ -137,7 +138,9 @@ impl RuleRow {
(RuleRow::Global(a), RuleRow::Global(b)) => {
b.fact.metadata().revision.cmp(&a.fact.metadata().revision)
}
(RuleRow::FileBacked(a), RuleRow::FileBacked(b)) => a.file_path.cmp(&b.file_path),
(RuleRow::FileBacked(a), RuleRow::FileBacked(b)) => {
a.file_path.display_path().cmp(&b.file_path.display_path())
}
_ => std::cmp::Ordering::Equal,
}
}
Expand Down Expand Up @@ -219,7 +222,7 @@ impl RuleView {
.as_ref(ctx)
.global_rule_paths()
.map(|p| FileBackedRow {
file_path: p,
file_path: LocalOrRemotePath::Local(p),
mouse_state: Default::default(),
})
.collect();
Expand All @@ -245,7 +248,7 @@ impl RuleView {
.as_ref(ctx)
.global_rule_paths()
.map(|p| FileBackedRow {
file_path: p,
file_path: LocalOrRemotePath::Local(p),
mouse_state: Default::default(),
})
.collect();
Expand Down Expand Up @@ -705,7 +708,7 @@ impl RuleView {
project_row: FileBackedRow,
appearance: &Appearance,
) -> Option<Box<dyn Element>> {
let row_name = project_row.file_path.to_str().map(|s| s.to_string())?;
let row_name = project_row.file_path.display_path();
let mut row = Flex::row()
.with_main_axis_size(MainAxisSize::Max)
.with_main_axis_alignment(MainAxisAlignment::SpaceBetween)
Expand Down
Loading