use std::collections::HashMap;
use serde::Deserialize;
use crate::cwd::{self, Cwd};
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default)]
pub struct AgentSession {
pub agent: String,
pub kind: String,
pub source: String,
pub value: String,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default)]
pub struct Pane {
pub pane_id: String,
pub tab_id: String,
pub workspace_id: String,
pub focused: bool,
pub agent: Option<String>,
pub agent_status: Option<String>,
pub terminal_title_stripped: Option<String>,
pub label: Option<String>,
pub revision: u64,
pub agent_session: Option<AgentSession>,
pub tokens: HashMap<String, Option<String>>,
pub cwd: Option<String>,
pub foreground_cwd: Option<String>,
}
impl Pane {
pub fn cwd_resolved(&self) -> Option<Cwd<'_>> {
cwd::resolve(self)
}
pub fn session_id(&self) -> Option<&str> {
self.agent_session
.as_ref()
.map(|session| session.value.as_str())
.filter(|value| !value.is_empty())
}
pub fn label(&self) -> String {
match (&self.agent, &self.terminal_title_stripped) {
(Some(agent), Some(title)) if !title.is_empty() => format!("{agent} · {title}"),
(Some(agent), _) => agent.clone(),
_ => self.pane_id.clone(),
}
}
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default)]
pub struct Agent {
pub pane_id: String,
pub workspace_id: String,
pub agent: Option<String>,
pub agent_status: Option<String>,
pub focused: bool,
pub cwd: Option<String>,
pub foreground_cwd: Option<String>,
pub terminal_title_stripped: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default)]
pub struct PluginContext {
pub workspace_id: Option<String>,
pub workspace_label: Option<String>,
pub workspace_cwd: Option<String>,
pub focused_pane_id: Option<String>,
pub focused_pane_cwd: Option<String>,
pub focused_pane_agent: Option<String>,
pub tab_id: Option<String>,
pub selected_text: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct AgentList {
#[serde(default)]
pub agents: Vec<Agent>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PaneList {
#[serde(default)]
pub panes: Vec<Pane>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PaneCurrent {
pub pane: Option<Pane>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PaneInfo {
pub pane: Option<Pane>,
}