diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-19 23:52:20 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-19 23:56:07 +0300 |
| commit | 3f80947678a9723434aa7fddfe23750b5393e24c (patch) | |
| tree | 6f463797132acfc51dfb6e135820a052954b4f13 /src/app/terminal_targets.rs | |
| parent | f76f895efe5b9f19aa9db909354c6c0f2195630b (diff) | |
feat: make agent automation a first-class cli primitive
Diffstat (limited to 'src/app/terminal_targets.rs')
| -rw-r--r-- | src/app/terminal_targets.rs | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/app/terminal_targets.rs b/src/app/terminal_targets.rs index d38d115c..a8fe394a 100644 --- a/src/app/terminal_targets.rs +++ b/src/app/terminal_targets.rs @@ -1,7 +1,5 @@ use super::{api_helpers::pane_agent_status, App}; -// Staged for #00f: the agent CLI will use this resolver once #00e provides terminal ids. -#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct TerminalTarget { pub ws_idx: usize, @@ -10,8 +8,6 @@ pub(crate) struct TerminalTarget { pub terminal_id: String, } -// Staged for #00f: ambiguity details are produced before the agent facade consumes them. -#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct TerminalTargetCandidate { pub terminal_id: String, @@ -22,8 +18,6 @@ pub(crate) struct TerminalTargetCandidate { pub agent_status: crate::api::schema::AgentStatus, } -// Staged for #00f: target errors are specified now and surfaced by agent commands next. -#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum TerminalTargetError { NotFound { @@ -36,8 +30,6 @@ pub(crate) enum TerminalTargetError { } impl App { - // Staged for #00f: current pane APIs stay pane-targeted while agent APIs will call this. - #[allow(dead_code)] pub(crate) fn resolve_terminal_target( &self, target: &str, @@ -51,13 +43,13 @@ impl App { return Ok(resolved); } - if let Some((ws_idx, pane_id)) = self.parse_pane_id(target) { + if let Some((ws_idx, pane_id)) = self.parse_current_public_pane_id(target) { if let Some(resolved) = self.terminal_target_for_pane(ws_idx, pane_id) { return Ok(resolved); } } - let name_matches: Vec<_> = self + let agent_matches: Vec<_> = self .terminal_targets() .into_iter() .filter(|candidate| { @@ -71,6 +63,39 @@ impl App { }) }) .collect(); + if let Some(resolved) = self.single_terminal_match(target, agent_matches)? { + return Ok(resolved); + } + + Err(TerminalTargetError::NotFound { + target: target.to_string(), + }) + } + + pub(crate) fn resolve_agent_target( + &self, + target: &str, + ) -> Result<TerminalTarget, TerminalTargetError> { + if let Some((ws_idx, pane_id)) = self.parse_current_public_pane_id(target) { + if let Some(resolved) = self + .terminal_target_for_pane(ws_idx, pane_id) + .filter(|resolved| self.target_is_agent(resolved)) + { + return Ok(resolved); + } + } + + let name_matches: Vec<_> = self + .terminal_targets() + .into_iter() + .filter(|candidate| { + self.state + .terminals + .values() + .find(|terminal| terminal.id.to_string() == candidate.terminal_id) + .is_some_and(|terminal| terminal.agent_name.as_deref() == Some(target)) + }) + .collect(); if let Some(resolved) = self.single_terminal_match(target, name_matches)? { return Ok(resolved); } @@ -80,8 +105,14 @@ impl App { }) } - // Staged for #00f with resolve_terminal_target. - #[allow(dead_code)] + fn target_is_agent(&self, target: &TerminalTarget) -> bool { + self.state + .terminals + .values() + .find(|terminal| terminal.id.to_string() == target.terminal_id) + .is_some_and(|terminal| terminal.is_agent_terminal()) + } + fn single_terminal_match( &self, target: &str, @@ -102,8 +133,6 @@ impl App { } } - // Staged for #00f with resolve_terminal_target. - #[allow(dead_code)] fn terminal_targets(&self) -> Vec<TerminalTarget> { self.state .workspaces @@ -127,8 +156,6 @@ impl App { .collect() } - // Staged for #00f with resolve_terminal_target. - #[allow(dead_code)] fn terminal_target_for_pane( &self, ws_idx: usize, @@ -145,8 +172,6 @@ impl App { }) } - // Staged for #00f with resolve_terminal_target. - #[allow(dead_code)] fn terminal_target_candidate( &self, ws_idx: usize, |
