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
impl MultiCliManager
Sourcepub fn new(config: ManagerConfig) -> Self
pub fn new(config: ManagerConfig) -> Self
Create a new manager with the given configuration.
Sourcepub fn create_instance(
&mut self,
cli: AgentCli,
mode: InstanceMode,
workdir: PathBuf,
) -> Result<InstanceId, String>
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).
Sourcepub async fn remove_instance(&mut self, id: InstanceId)
pub async fn remove_instance(&mut self, id: InstanceId)
Stop and remove an instance from the manager.
Sourcepub async fn start_pty_instance(
&mut self,
id: InstanceId,
config: SessionConfig,
) -> Result<(), String>
pub async fn start_pty_instance( &mut self, id: InstanceId, config: SessionConfig, ) -> Result<(), String>
Start a PTY session for the given instance.
Sourcepub async fn write_pty_instance(
&mut self,
id: InstanceId,
text: &str,
) -> Result<(), String>
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.
Sourcepub async fn send_chat_instance(
&mut self,
id: InstanceId,
prompt: &str,
) -> Result<(), String>
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.
Sourcepub async fn stop_instance(&mut self, id: InstanceId)
pub async fn stop_instance(&mut self, id: InstanceId)
Stop the session for a single instance.
Sourcepub fn snapshot_instance(&self, id: InstanceId) -> Option<AgentRenderSnapshot>
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.
Sourcepub fn is_instance_active(&self, id: InstanceId) -> bool
pub fn is_instance_active(&self, id: InstanceId) -> bool
Returns true if the instance is active.
Sourcepub fn list_instances(&self) -> Vec<InstanceId>
pub fn list_instances(&self) -> Vec<InstanceId>
Returns all registered instance IDs.
Sourcepub fn instance_cli(&self, id: InstanceId) -> Option<AgentCli>
pub fn instance_cli(&self, id: InstanceId) -> Option<AgentCli>
Returns the AgentCli for an instance.
Sourcepub fn instance_mode(&self, id: InstanceId) -> Option<InstanceMode>
pub fn instance_mode(&self, id: InstanceId) -> Option<InstanceMode>
Returns the InstanceMode for an instance.
Sourcepub fn instance_workdir(&self, id: InstanceId) -> Option<&Path>
pub fn instance_workdir(&self, id: InstanceId) -> Option<&Path>
Returns the working directory for an instance.
Sourcepub async fn resize_instance(&mut self, id: InstanceId, cols: u16, rows: u16)
pub async fn resize_instance(&mut self, id: InstanceId, cols: u16, rows: u16)
Resize the PTY for a single instance.
Sourcepub fn load_latest_history_instance(&mut self, id: InstanceId) -> bool
pub fn load_latest_history_instance(&mut self, id: InstanceId) -> bool
Load the latest history for an instance. Chat-mode only.
Sourcepub fn clear_chat_instance(&mut self, id: InstanceId)
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.
Sourcepub fn list_past_sessions_instance(&self, id: InstanceId) -> Vec<SessionMeta>
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).
Sourcepub fn load_history_instance(
&mut self,
id: InstanceId,
session_id: &str,
) -> bool
pub fn load_history_instance( &mut self, id: InstanceId, session_id: &str, ) -> bool
Load a specific history session for an instance. Chat-mode only.
Sourcepub fn cli_workdir(&self, cli: AgentCli) -> PathBuf
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.
Sourcepub async fn start_pty(
&mut self,
cli: AgentCli,
config: SessionConfig,
) -> Result<(), String>
pub async fn start_pty( &mut self, cli: AgentCli, config: SessionConfig, ) -> Result<(), String>
Start a PTY session for the given CLI.
Sourcepub async fn start_pipe(
&mut self,
cli: AgentCli,
config: SessionConfig,
prompt: &str,
) -> Result<(), String>
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.
Sourcepub async fn write_pty(
&mut self,
cli: AgentCli,
text: &str,
) -> Result<(), String>
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.
Sourcepub async fn send_chat(
&mut self,
cli: AgentCli,
prompt: &str,
) -> Result<(), String>
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.
Sourcepub async fn resize(&mut self, cols: u16, rows: u16)
pub async fn resize(&mut self, cols: u16, rows: u16)
Resize all active PTY sessions to the new dimensions.
Sourcepub fn drain_events(&mut self) -> bool
pub fn drain_events(&mut self) -> bool
Drain events for all instances. Returns true if any events were processed.
Sourcepub fn snapshot_mode(
&self,
cli: AgentCli,
want_pty: bool,
) -> AgentRenderSnapshot
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.
Sourcepub fn snapshot(&self, cli: AgentCli) -> AgentRenderSnapshot
pub fn snapshot(&self, cli: AgentCli) -> AgentRenderSnapshot
Legacy snapshot — inferred from state. Prefer snapshot_mode.
Sourcepub fn is_active(&self, cli: AgentCli) -> bool
pub fn is_active(&self, cli: AgentCli) -> bool
Returns true if either PTY or pipe session is alive for this CLI.
Sourcepub fn any_active(&self) -> bool
pub fn any_active(&self) -> bool
Returns true if any instance has an active session.
Sourcepub fn past_session_count(&self, cli: AgentCli) -> usize
pub fn past_session_count(&self, cli: AgentCli) -> usize
Number of past sessions for this CLI (live disk read).
Sourcepub fn list_past_sessions(&self, cli: AgentCli) -> Vec<SessionMeta>
pub fn list_past_sessions(&self, cli: AgentCli) -> Vec<SessionMeta>
List past sessions (newest first, live disk read).
Sourcepub fn load_latest_history(&mut self, cli: AgentCli) -> bool
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.
Sourcepub fn load_history(&mut self, cli: AgentCli, session_id: &str) -> bool
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.
Sourcepub fn load_next_past_session(&mut self, cli: AgentCli) -> bool
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§
Auto Trait Implementations§
impl Freeze for MultiCliManager
impl RefUnwindSafe for MultiCliManager
impl Send for MultiCliManager
impl Sync for MultiCliManager
impl Unpin for MultiCliManager
impl UnsafeUnpin for MultiCliManager
impl UnwindSafe for MultiCliManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.