Skip to main content

AgentHandle

Struct AgentHandle 

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

A handle to an agent instance that manages its lifecycle.

AgentHandle wraps an AgentCore and provides:

  • Socket path and PID file tracking
  • Lifecycle management (shutdown, status checks)
  • Thread-safe access to the underlying AgentCore
  • Idle timeout and key locking

Unlike the previous global static pattern, multiple AgentHandle instances can coexist, enabling proper testing and multi-agent scenarios.

Implementations§

Source§

impl AgentHandle

Source

pub fn new(socket_path: PathBuf) -> Self

Creates a new agent handle with the specified socket path.

Source

pub fn with_timeout(socket_path: PathBuf, idle_timeout: Duration) -> Self

Creates a new agent handle with the specified socket path and timeout.

Source

pub fn with_pid_file(socket_path: PathBuf, pid_file: PathBuf) -> Self

Creates a new agent handle with socket and PID file paths.

Source

pub fn with_pid_file_and_timeout( socket_path: PathBuf, pid_file: PathBuf, idle_timeout: Duration, ) -> Self

Creates a new agent handle with socket, PID file, and custom timeout.

Source

pub fn from_core(core: AgentCore, socket_path: PathBuf) -> Self

Creates an agent handle from an existing AgentCore.

Source

pub fn socket_path(&self) -> &PathBuf

Returns the socket path for this agent.

Source

pub fn pid_file(&self) -> Option<&PathBuf>

Returns the PID file path, if configured.

Source

pub fn set_pid_file(&mut self, path: PathBuf)

Sets the PID file path.

Source

pub fn lock(&self) -> Result<MutexGuard<'_, AgentCore>, AgentError>

Acquires a lock on the agent core.

§Errors

Returns AgentError::MutexError if the mutex is poisoned.

Source

pub fn core_arc(&self) -> Arc<Mutex<AgentCore>>

Returns a clone of the inner Arc<Mutex> for sharing.

Source

pub fn is_running(&self) -> bool

Returns whether the agent is currently running.

Source

pub fn set_running(&self, running: bool)

Marks the agent as running.

Source

pub fn idle_timeout(&self) -> Duration

Returns the configured idle timeout duration.

Source

pub fn touch(&self)

Records activity, resetting the idle timer.

Source

pub fn idle_duration(&self) -> Duration

Returns the duration since the last activity.

Source

pub fn is_idle_timed_out(&self) -> bool

Returns whether the agent has exceeded the idle timeout.

Source

pub fn is_agent_locked(&self) -> bool

Returns whether the agent is currently locked.

Source

pub fn lock_agent(&self) -> Result<(), AgentError>

Locks the agent, clearing all keys from memory.

After locking, sign operations will fail with AgentError::AgentLocked.

Source

pub fn unlock_agent(&self)

Unlocks the agent (marks as unlocked).

Note: This only clears the locked flag. Keys must be re-loaded separately using register_key or the CLI auths agent unlock command.

Source

pub fn check_idle_timeout(&self) -> Result<bool, AgentError>

Checks idle timeout and locks the agent if exceeded.

Call this periodically from a background task.

Source

pub fn shutdown(&self) -> Result<(), AgentError>

Shuts down the agent, clearing all keys and resources.

This method:

  1. Clears all keys from the agent core (zeroizing sensitive data)
  2. Marks the agent as not running
  3. Optionally removes the socket file and PID file
Source

pub fn key_count(&self) -> Result<usize, AgentError>

Returns the number of keys currently loaded in the agent.

Source

pub fn public_keys(&self) -> Result<Vec<Vec<u8>>, AgentError>

Returns all public key bytes currently registered.

Source

pub fn register_key( &self, pkcs8_bytes: Zeroizing<Vec<u8>>, ) -> Result<(), AgentError>

Registers a key in the agent core.

Source

pub fn sign(&self, pubkey: &[u8], data: &[u8]) -> Result<Vec<u8>, AgentError>

Signs data using a key in the agent core.

§Errors

Returns AgentError::AgentLocked if the agent is locked.

Trait Implementations§

Source§

impl Clone for AgentHandle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V