Skip to main content

MultiCliManager

Struct MultiCliManager 

Source
pub struct MultiCliManager { /* private fields */ }
Expand description

Manages agent sessions for all CLIs simultaneously.

Internally uses a HashMap<InstanceId, AgentInstance>. Three legacy instances (one per AgentCli) are pre-created in new() so that all existing callers using the cli: AgentCli API continue to work unchanged.

Implementations§

Source§

impl MultiCliManager

Source

pub fn new(config: ManagerConfig) -> Self

Create a new manager with the given configuration.

Source

pub fn create_instance( &mut self, cli: AgentCli, mode: InstanceMode, workdir: PathBuf, ) -> Result<InstanceId, String>

Register a new agent instance. Does NOT spawn any process.

All 6 CLIs support Chat mode via TransportSession (pipe/daemon).

Source

pub async fn remove_instance(&mut self, id: InstanceId)

Stop and remove an instance from the manager.

Source

pub async fn start_pty_instance( &mut self, id: InstanceId, config: SessionConfig, ) -> Result<(), String>

Start a PTY session for the given instance.

Source

pub async fn write_pty_instance( &mut self, id: InstanceId, text: &str, ) -> Result<(), String>

Write a string to the active PTY for the given instance.

Lazy-spawns a PTY session on the first call.

Source

pub async fn send_chat_instance( &mut self, id: InstanceId, prompt: &str, ) -> Result<(), String>

Send a chat prompt to the pipe session for the given instance.

Only valid if the instance mode is Chat. Lazy-spawns on first call.

Source

pub async fn stop_instance(&mut self, id: InstanceId)

Stop the session for a single instance.

Source

pub fn snapshot_instance(&self, id: InstanceId) -> Option<AgentRenderSnapshot>

Build a render snapshot for the given instance.

Returns None if the instance doesn’t exist. Otherwise builds a PTY or Chat snapshot based on the instance’s mode.

Source

pub fn is_instance_active(&self, id: InstanceId) -> bool

Returns true if the instance is active.

Source

pub fn list_instances(&self) -> Vec<InstanceId>

Returns all registered instance IDs.

Source

pub fn instance_cli(&self, id: InstanceId) -> Option<AgentCli>

Returns the AgentCli for an instance.

Source

pub fn instance_mode(&self, id: InstanceId) -> Option<InstanceMode>

Returns the InstanceMode for an instance.

Source

pub fn instance_workdir(&self, id: InstanceId) -> Option<&Path>

Returns the working directory for an instance.

Source

pub async fn resize_instance(&mut self, id: InstanceId, cols: u16, rows: u16)

Resize the PTY for a single instance.

Source

pub fn load_latest_history_instance(&mut self, id: InstanceId) -> bool

Load the latest history for an instance. Chat-mode only.

Source

pub fn clear_chat_instance(&mut self, id: InstanceId)

Clear chat messages for an instance, starting a fresh session (display only).

Stops the running transport session (if any) and wipes the message list. The next send_chat_instance will begin a brand-new CLI session.

Source

pub fn list_past_sessions_instance(&self, id: InstanceId) -> Vec<SessionMeta>

List past sessions for an instance by its workdir (newest-first, live disk read).

Source

pub fn load_history_instance( &mut self, id: InstanceId, session_id: &str, ) -> bool

Load a specific history session for an instance. Chat-mode only.

Source

pub fn cli_workdir(&self, cli: AgentCli) -> PathBuf

Returns the working directory for a given CLI.

Each CLI runs isolated in {sessions_dir}/{cli_name}/ so its dotfolder (.claude/, .codex/, .gemini/) lives there.

Source

pub async fn start_pty( &mut self, cli: AgentCli, config: SessionConfig, ) -> Result<(), String>

Start a PTY session for the given CLI.

Source

pub async fn start_pipe( &mut self, cli: AgentCli, config: SessionConfig, prompt: &str, ) -> Result<(), String>

Start a Pipe/Chat session for the given CLI.

Deprecated: prefer send_chat which lazy-spawns on the first message.

Source

pub async fn stop(&mut self, cli: AgentCli)

Stop the session for a single CLI.

Source

pub async fn stop_all(&mut self)

Stop all active sessions (called on app shutdown).

Source

pub async fn write_pty( &mut self, cli: AgentCli, text: &str, ) -> Result<(), String>

Write a string to the active PTY for the given CLI.

Lazy-spawns a PTY session on the first call for this CLI.

Source

pub async fn send_chat( &mut self, cli: AgentCli, prompt: &str, ) -> Result<(), String>

Send a chat prompt to the pipe session for the given CLI.

Lazy-spawns a pipe session on the first call for this CLI.

Routes all 6 CLIs through TransportSession. Legacy Claude-only restriction is lifted: all CLIs with a legacy slot can now use Chat/pipe mode.

Source

pub async fn resize(&mut self, cols: u16, rows: u16)

Resize all active PTY sessions to the new dimensions.

Source

pub fn drain_events(&mut self) -> bool

Drain events for all instances. Returns true if any events were processed.

Source

pub fn snapshot_mode( &self, cli: AgentCli, want_pty: bool, ) -> AgentRenderSnapshot

Build a render snapshot for the given CLI, honoring the UI’s requested mode.

want_pty=true → return PTY grid if a PTY parser/session exists (even if exited), otherwise Idle. want_pty=false → return chat messages if any, otherwise Idle. This decouples snapshot mode from session liveness so mode switches don’t destroy the other view.

Source

pub fn snapshot(&self, cli: AgentCli) -> AgentRenderSnapshot

Legacy snapshot — inferred from state. Prefer snapshot_mode.

Source

pub fn is_active(&self, cli: AgentCli) -> bool

Returns true if either PTY or pipe session is alive for this CLI.

Source

pub fn any_active(&self) -> bool

Returns true if any instance has an active session.

Source

pub fn past_session_count(&self, cli: AgentCli) -> usize

Number of past sessions for this CLI (live disk read).

Source

pub fn list_past_sessions(&self, cli: AgentCli) -> Vec<SessionMeta>

List past sessions (newest first, live disk read).

Source

pub fn load_latest_history(&mut self, cli: AgentCli) -> bool

Load the latest past session into the chat view (display only — does NOT resume the CLI process).

Returns true if anything was loaded.

Source

pub fn load_history(&mut self, cli: AgentCli, session_id: &str) -> bool

Load a specific past session into the chat view AND mark it as the resume target — the next send_chat will respawn the pipe with --resume <session_id>, so the user keeps writing into the chosen thread instead of accidentally starting a fresh session.

Source

pub fn load_next_past_session(&mut self, cli: AgentCli) -> bool

Backwards-compatible wrapper — loads the latest past session.

Chart-app callers using load_next_past_session continue to work unchanged.

Trait Implementations§

Source§

impl Default for MultiCliManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.