first pass of merging in warp (doesn't build)

This commit is contained in:
Ryan Ward
2026-07-01 16:08:58 -05:00
parent 2f64909469
commit 4770ac06b5
3662 changed files with 414574 additions and 89772 deletions
+61 -43
View File
@@ -1,26 +1,21 @@
use std::{path::PathBuf, time::Duration};
use std::path::PathBuf;
use std::time::Duration;
use galaxy_core::features::FeatureFlag;
use itertools::Itertools as _;
use uuid::Uuid;
use warp_multi_agent_api as api;
use crate::{
agent::{
action::{
AIAgentActionType, AIAgentPtyWriteMode, CommentSide, FileEdit, InsertReviewComment,
InsertedCommentLine, InsertedCommentLocation, ReadFilesRequest, ReadSkillRequest,
SearchCodebaseRequest, ShellCommandDelay, SuggestPromptRequest, UploadArtifactRequest,
UseComputerRequest,
},
action_result::{AnyFileContent, FileContext},
convert::ToolToAIAgentActionError,
FileLocations,
},
diff_validation::{ParsedDiff, V4AHunk},
document::AIDocumentId,
skills::SkillReference,
use crate::agent::action::{
AIAgentActionType, AIAgentPtyWriteMode, CommentSide, FileEdit, InsertReviewComment,
InsertedCommentLine, InsertedCommentLocation, ReadFilesRequest, SearchCodebaseRequest,
ShellCommandDelay, SuggestPromptRequest, UploadArtifactRequest, UseComputerRequest,
};
use crate::agent::action_result::{AnyFileContent, FileContext};
use crate::agent::convert::ToolToAIAgentActionError;
use crate::agent::FileLocations;
use crate::diff_validation::{ParsedDiff, V4AHunk};
use crate::document::AIDocumentId;
impl From<api::message::tool_call::RunShellCommand> for AIAgentActionType {
fn from(value: api::message::tool_call::RunShellCommand) -> Self {
@@ -430,10 +425,11 @@ impl TryFrom<api::message::tool_call::UseComputer> for AIAgentActionType {
.actions
.into_iter()
.map(|action| {
let target = convert_computer_use_target(action.target);
let Some(action_type) = action.r#type else {
return Err(ToolToAIAgentActionError::MissingComputerUseActionType);
};
match action_type {
let action = match action_type {
use_computer::action::Type::MouseMove(mouse_move) => {
Ok(computer_use::Action::MouseMove {
to: coordinates_to_vec(mouse_move.to.as_ref())?,
@@ -481,7 +477,9 @@ impl TryFrom<api::message::tool_call::UseComputer> for AIAgentActionType {
let key = convert_key(key_up.key)?;
Ok(computer_use::Action::KeyUp { key })
}
}
}?;
log_window_target_coord(&action, target);
Ok(computer_use::TargetedAction { action, target })
})
.try_collect()?;
let screenshot_params = value
@@ -505,19 +503,6 @@ impl From<api::message::tool_call::RequestComputerUse> for AIAgentActionType {
}
}
impl TryFrom<api::message::tool_call::ReadSkill> for AIAgentActionType {
type Error = ToolToAIAgentActionError;
fn try_from(value: api::message::tool_call::ReadSkill) -> Result<Self, Self::Error> {
match value.skill_reference {
Some(reference) => Ok(AIAgentActionType::ReadSkill(ReadSkillRequest {
skill: SkillReference::from(reference),
})),
None => Err(ToolToAIAgentActionError::MissingSkillReference),
}
}
}
impl From<api::message::tool_call::FetchConversation> for AIAgentActionType {
fn from(value: api::message::tool_call::FetchConversation) -> Self {
AIAgentActionType::FetchConversation {
@@ -526,18 +511,6 @@ impl From<api::message::tool_call::FetchConversation> for AIAgentActionType {
}
}
impl From<api::message::tool_call::read_skill::SkillReference> for SkillReference {
fn from(value: api::message::tool_call::read_skill::SkillReference) -> Self {
use warp_multi_agent_api::message::tool_call::read_skill::SkillReference as ApiSkillReference;
match value {
ApiSkillReference::SkillPath(skill_path) => {
SkillReference::Path(PathBuf::from(skill_path))
}
ApiSkillReference::BundledSkillId(id) => SkillReference::BundledSkillId(id),
}
}
}
/// Converts API ScreenshotParams to the internal computer_use type.
fn convert_screenshot_params(
params: api::message::tool_call::ScreenshotParams,
@@ -556,6 +529,51 @@ fn convert_screenshot_params(
max_long_edge_px: (params.max_long_edge_px > 0).then_some(params.max_long_edge_px as usize),
max_total_px: (params.max_total_px > 0).then_some(params.max_total_px as usize),
region,
target: convert_computer_use_target(params.target),
}
}
/// Converts an optional API `ComputerUseTarget` into the internal computer_use target. An absent
/// or `Screen` target maps to the legacy whole-screen behavior.
fn convert_computer_use_target(
target: Option<api::message::tool_call::ComputerUseTarget>,
) -> computer_use::Target {
use api::message::tool_call::computer_use_target::Target as ApiTarget;
match target.and_then(|t| t.target) {
// The proto window id is an opaque string; on macOS it is a CGWindowID, so parse it back
// to a u32. An unparseable id is treated as no valid window target and falls back to the
// legacy whole-screen behavior rather than panicking.
Some(ApiTarget::Window(window)) => match window.window_id.parse::<u32>() {
Ok(window_id) => computer_use::Target::Window {
window_id,
pid: window.pid,
},
Err(_) => computer_use::Target::Screen,
},
Some(ApiTarget::Screen(_)) | None => computer_use::Target::Screen,
}
}
/// Logs the raw server-provided coordinates for a window-targeted computer-use action, so the
/// agent-driven coordinate conversion can be compared against where the click actually lands.
/// Gated on COMPUTER_USE_DEBUG and routed through `log` so it surfaces in the app's log file.
fn log_window_target_coord(action: &computer_use::Action, target: computer_use::Target) {
if std::env::var_os("COMPUTER_USE_DEBUG").is_none() {
return;
}
let computer_use::Target::Window { window_id, pid } = target else {
return;
};
let coord = match action {
computer_use::Action::MouseMove { to } => Some(("mouse_move", to.x(), to.y())),
computer_use::Action::MouseDown { at, .. } => Some(("mouse_down", at.x(), at.y())),
computer_use::Action::MouseWheel { at, .. } => Some(("mouse_wheel", at.x(), at.y())),
_ => None,
};
if let Some((kind, x, y)) = coord {
log::info!(
"[computer_use] server->client {kind} window#={window_id} pid={pid} raw_coord=({x},{y})"
);
}
}