Skip to main content

AgentHandle

Struct AgentHandle 

Source
pub struct AgentHandle {
    pub commands: UnboundedSender<AgentCommand>,
    agent_events: Mutex<Option<UnboundedReceiver<AgentEvent>>>,
    bridge: Arc<ForgeSdkBridge>,
}
Expand description

Handle returned by Agent::spawn. Owns the channels + a thin passthrough to the bridge’s direct-return accessors.

Fields§

§commands: UnboundedSender<AgentCommand>

UI → agent commands. Used internally by the inherent command-shorthand methods (prompt_text, cancel, etc.). Public so callers can send(AgentCommand::...) directly when richer flows are needed.

§agent_events: Mutex<Option<UnboundedReceiver<AgentEvent>>>

Bridge’s raw AgentEvent receiver. Single-take via AgentHandle::take_events - the workspace’s session task consumes this and translates it into SessionUpdates.

§bridge: Arc<ForgeSdkBridge>

Bridge handle used for direct-return accessors (config_dir, settings_documents, …) plus internal command dispatch.

Implementations§

Source§

impl AgentHandle

Source

pub fn take_events(&self) -> Option<UnboundedReceiver<AgentEvent>>

Take ownership of the bridge’s AgentEvent receiver. Returns Some exactly once.

Source

pub fn config_dir(&self) -> PathBuf

Source

pub fn claude_pid(&self) -> Option<u32>

OS PID of the bound claude child, when one is currently attached. Surfaces to forge-workspace for the Inspector pane’s PROCESSES OS-walk.

Source

pub fn kill_process_group(&self)

Take the session’s process group down without the async drain.

For a session that never got a task to run its exit path: dropping the handle alone SIGKILLs the direct child and leaves the tools the CLI already started behind.

Source

pub fn project_memory_path(&self, cwd: &Path) -> PathBuf

Source

pub fn settings_documents(&self, cwd: Option<&Path>) -> SettingsDocuments

Source

pub fn display_name(&self) -> Option<String>

Returns a clone of the bridge’s bound forge-account display_name (when forge-workspace picked one). Used by the connect-flow to emit a ForgeAccountIdentityReady event right after spawn - eliminates the welcome-message flicker that would otherwise wait for the slow status snapshot to arrive from the CLI.

Source

pub fn env(&self) -> HashMap<String, String>

The bridge’s resolved forge.toml env. Test-only, and one hop short of what the child receives - the subprocess also gets CLAUDE_CONFIG_DIR and the SDK version. It exists so a test can observe the map a spawn carries rather than what the resolution helper returned.

Source

pub async fn disconnect(&self)

Disconnect the bound claude subprocess: take the bridge’s client slot and run the SDK’s graceful shutdown (signal the reader task, drain, close the child). Both layers are idempotent via Option::take, so repeated calls on clones are no-ops. Called from SessionTask’s exit path so release / despawn / teardown paths actually kill the subprocess instead of leaving it alive until forge exits.

Source

fn send(&self, cmd: AgentCommand) -> Result<(), AgentError>

Source

pub fn new_session( &self, session_id: Option<String>, cwd: String, launch_settings: SessionLaunchSettings, ) -> Result<(), AgentError>

Start a session under session_id, or under an id the CLI picks when that is None.

Source

pub fn resume_session( &self, session_id: String, cwd: String, launch_settings: SessionLaunchSettings, ) -> Result<(), AgentError>

Source

pub fn resume_or_new_session( &self, session_id: String, cwd: String, launch_settings: SessionLaunchSettings, ) -> Result<(), AgentError>

Resume the recorded session_id; if resume fails (stale catalog entry, cross-account scan, deleted .jsonl), retry as a fresh session in cwd. The user only sees a ConnectionFailed event when both attempts fail.

Source

pub fn prompt_text( &self, session_id: String, text: String, uuid: String, ) -> Result<(), AgentError>

Source

pub fn prompt_with_images( &self, session_id: String, text: String, images: Vec<ImageAttachment>, uuid: String, ) -> Result<(), AgentError>

Source

pub fn cancel(&self, session_id: String) -> Result<(), AgentError>

Source

pub fn cancel_queued( &self, session_id: String, uuid: String, ) -> Result<(), AgentError>

Source

pub fn set_mode( &self, session_id: String, mode: PermissionMode, ) -> Result<(), AgentError>

Source

pub fn set_model( &self, session_id: String, model: String, ) -> Result<(), AgentError>

Source

pub fn get_context_usage(&self, session_id: String) -> Result<(), AgentError>

Source

pub fn get_mcp_snapshot(&self, session_id: String) -> Result<(), AgentError>

Source

pub fn permission_response( &self, session_id: String, tool_call_id: String, outcome: PermissionOutcome, ) -> Result<(), AgentError>

Source

pub fn question_response( &self, session_id: String, tool_call_id: String, outcome: QuestionOutcome, ) -> Result<(), AgentError>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more