pub mod herdr;
pub mod radiator;
pub mod select;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
time::Duration,
};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use self::herdr::SessionSnapshot;
pub use crate::model::SplitDirection as Split;
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub struct Capabilities {
pub workspace_env: bool,
pub pane_command_at_create: bool,
pub metadata_tokens: bool,
pub process_info: bool,
pub events: bool,
pub readiness_output: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ProcessInfo {
pub command: Vec<String>,
pub pid: Option<u32>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct PaneSpec {
pub label: Option<String>,
pub cwd: Option<PathBuf>,
pub command: Option<Vec<String>>,
pub env: BTreeMap<String, String>,
}
pub trait Backend {
fn snapshot(&self) -> Result<SessionSnapshot>;
fn caller_pane_id(&self) -> Option<String>;
fn create_workspace(&self, label: &str, cwd: &Path) -> Result<String>;
fn rename_workspace(&self, id: &str, label: &str) -> Result<()>;
fn create_pane(&self, workspace_id: &str, spec: &PaneSpec) -> Result<String>;
fn close_pane(&self, id: &str) -> Result<()>;
fn rename_pane(&self, id: &str, label: &str) -> Result<()>;
fn restart_command(&self, id: &str, argv: &[String]) -> Result<()>;
fn prompt_agent(&self, id: &str, prompt: &str) -> Result<()>;
fn process_info(&self, id: &str) -> Result<Option<ProcessInfo>>;
fn report_tokens(&self, address: &str, tokens: &BTreeMap<String, String>) -> Result<()>;
fn output(&self, id: &str, timeout: Duration) -> Result<String>;
fn capabilities(&self) -> Capabilities;
fn herdr(&self) -> Option<&dyn HerdrExt> {
None
}
fn radiator(&self) -> Option<&dyn RadiatorExt> {
None
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SessionState {
Running,
Started,
CannotStart { hint: String },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SessionStop {
pub stopped: bool,
pub deleted: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TabLayout {
pub tab_id: String,
pub pane_ids: Vec<String>,
}
pub trait HerdrExt {
fn create_tab(
&self,
workspace_id: &str,
label: &str,
split: Split,
ratios: &[f64],
panes: &[PaneSpec],
existing_tab: Option<&str>,
) -> Result<TabLayout>;
fn take_root_tab(&self, workspace_id: &str) -> Option<String> {
let _ = workspace_id;
None
}
fn split_pane(&self, tab_id: &str, spec: &PaneSpec, split: Split) -> Result<String>;
fn set_ratio(&self, tab_id: &str, ratios: &[f64]) -> Result<()>;
fn rename_tab(&self, tab_id: &str, label: &str) -> Result<()>;
fn start_agent(&self, pane_id: &str, name: &str, kind: &str, args: &[String]) -> Result<()>;
fn focus_workspace(&self, id: &str) -> Result<()>;
fn ensure_session(&self, name: &str) -> Result<SessionState>;
fn stop_session(&self, name: &str) -> Result<SessionStop>;
}
pub trait RadiatorExt {}