pub struct Agent { /* private fields */ }Implementations§
Source§impl Agent
impl Agent
Sourcepub fn spawn(
provider: Arc<dyn Provider>,
dir: &Path,
args: &[String],
resume_session: Option<&str>,
prompt: Option<&str>,
env_vars: &[(&str, &str)],
) -> Result<Self>
pub fn spawn( provider: Arc<dyn Provider>, dir: &Path, args: &[String], resume_session: Option<&str>, prompt: Option<&str>, env_vars: &[(&str, &str)], ) -> Result<Self>
Spawn a new agent process attached to a PTY.
env_vars are set on the child process (e.g. TAM_AGENT_ID, TAM_SOCKET).
Sourcepub fn check_exited(&mut self) -> Option<i32>
pub fn check_exited(&mut self) -> Option<i32>
Check if the child process has exited. Returns Some(exit_code) if so. Agents that exit are cleaned up by the daemon — exit is an event, not a state.
Sourcepub fn kill_and_drop(self)
pub fn kill_and_drop(self)
Kill the agent and drop it. Intended for use in background tasks
where ownership is transferred (e.g. spawn_blocking).
Sourcepub fn set_state(&mut self, state: AgentState)
pub fn set_state(&mut self, state: AgentState)
Set the stored state directly (used by hook-based providers).
Sourcepub fn handle_hook_event(&mut self, event: &str) -> Option<AgentState>
pub fn handle_hook_event(&mut self, event: &str) -> Option<AgentState>
Map a hook event to a state via the provider, and update stored state. Returns the new state if the event was recognized, None otherwise.
Sourcepub fn check_state_change(&mut self) -> Option<(AgentState, AgentState)>
pub fn check_state_change(&mut self) -> Option<(AgentState, AgentState)>
Check for a state transition. Returns Some((old, new)) if state changed. Updates reported_state so the same transition isn’t reported twice.
Sourcepub fn current_state(&self) -> AgentState
pub fn current_state(&self) -> AgentState
Compute current state: ask the provider first (output heuristic), fall back to the stored state (set by hooks or default).
Sourcepub fn info(&self, id: &str) -> AgentInfo
pub fn info(&self, id: &str) -> AgentInfo
Build an AgentInfo snapshot for reporting to clients.
Sourcepub fn context_refresh_job(&self, id: &str) -> ContextRefreshJob
pub fn context_refresh_job(&self, id: &str) -> ContextRefreshJob
Collect lightweight metadata for two-phase context refresh. This is cheap (no IO) and can be called under the lock.
Sourcepub fn set_context_percent(&mut self, pct: Option<u8>) -> bool
pub fn set_context_percent(&mut self, pct: Option<u8>) -> bool
Set context percent. Returns true if the value changed.
pub fn context_percent(&self) -> Option<u8>
Sourcepub fn viewers(&self) -> Arc<AtomicUsize>
pub fn viewers(&self) -> Arc<AtomicUsize>
Get the viewer count handle for increment/decrement by attach sessions.
Sourcepub fn subscribe(&self) -> Receiver<Vec<u8>>
pub fn subscribe(&self) -> Receiver<Vec<u8>>
Subscribe to live PTY output. Returns a broadcast receiver.
Sourcepub fn scrollback_contents(&self) -> Vec<u8> ⓘ
pub fn scrollback_contents(&self) -> Vec<u8> ⓘ
Get a copy of the current scrollback buffer contents.
Sourcepub fn pty_master(&self) -> Arc<OwnedFd>
pub fn pty_master(&self) -> Arc<OwnedFd>
Get a clone of the PTY master fd (kept alive by Arc).