pub struct ExtensionContext {
pub cwd: PathBuf,
pub config: Value,
pub session_id: Option<String>,
/* private fields */
}Expand description
Runtime context provided to extension hooks.
Gives extensions access to the session’s working directory, settings, configuration, and various control surfaces (tool registration, message sending, model switching, etc.).
Fields§
§cwd: PathBufCurrent working directory.
config: ValueExtension-specific configuration value.
session_id: Option<String>Active session ID, if any.
Implementations§
Source§impl ExtensionContext
impl ExtensionContext
Sourcepub fn new(
cwd: PathBuf,
settings: Arc<RwLock<Settings>>,
config: Value,
session_id: Option<String>,
idle: Arc<RwLock<bool>>,
tool_registrar: Arc<dyn Fn(ExtensionToolArc) + Send + Sync>,
message_sender: Arc<dyn Fn(&str) + Send + Sync>,
errors: Arc<RwLock<Vec<ExtensionErrorRecord>>>,
) -> Self
pub fn new( cwd: PathBuf, settings: Arc<RwLock<Settings>>, config: Value, session_id: Option<String>, idle: Arc<RwLock<bool>>, tool_registrar: Arc<dyn Fn(ExtensionToolArc) + Send + Sync>, message_sender: Arc<dyn Fn(&str) + Send + Sync>, errors: Arc<RwLock<Vec<ExtensionErrorRecord>>>, ) -> Self
Create a new extension context.
Sourcepub fn register_tool(&self, tool: ExtensionToolArc)
pub fn register_tool(&self, tool: ExtensionToolArc)
Register a tool with the agent.
Sourcepub fn send_message(&self, text: &str)
pub fn send_message(&self, text: &str)
Send a message as the extension.
Sourcepub fn record_error(&self, extension_name: &str, event: &str, error: &str)
pub fn record_error(&self, extension_name: &str, event: &str, error: &str)
Record an error from an extension.
Sourcepub fn errors(&self) -> Vec<ExtensionErrorRecord>
pub fn errors(&self) -> Vec<ExtensionErrorRecord>
Get all recorded errors.
Sourcepub fn clear_errors(&self)
pub fn clear_errors(&self)
Clear all recorded errors.
Sourcepub fn config_get(&self, path: &str) -> Option<Value>
pub fn config_get(&self, path: &str) -> Option<Value>
Look up a value in the extension configuration by dot-separated path.
Sourcepub fn read_file(&self, relative_path: &Path) -> Result<String>
pub fn read_file(&self, relative_path: &Path) -> Result<String>
Read a file relative to the working directory.
Sourcepub fn get_tools(&self) -> Vec<ExtensionToolArc> ⓘ
pub fn get_tools(&self) -> Vec<ExtensionToolArc> ⓘ
Get all currently registered tools.
Sourcepub fn set_tools(&self, tools: Vec<ExtensionToolArc>)
pub fn set_tools(&self, tools: Vec<ExtensionToolArc>)
Replace the full set of registered tools.
Sourcepub fn set_thinking_level(&self, level: &str)
pub fn set_thinking_level(&self, level: &str)
Set the thinking level.
Sourcepub fn append_system_prompt(&self, text: &str)
pub fn append_system_prompt(&self, text: &str)
Append text to the system prompt.
Sourcepub fn set_session_name(&self, name: &str)
pub fn set_session_name(&self, name: &str)
Set the session display name.
Sourcepub fn get_session_entries(&self) -> Vec<Value>
pub fn get_session_entries(&self) -> Vec<Value>
Get all session entries.
Sourcepub fn fork_session(&self, entry_id: &str) -> Result<String>
pub fn fork_session(&self, entry_id: &str) -> Result<String>
Fork the session at the given entry ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ExtensionContext
impl !RefUnwindSafe for ExtensionContext
impl Send for ExtensionContext
impl Sync for ExtensionContext
impl Unpin for ExtensionContext
impl UnsafeUnpin for ExtensionContext
impl !UnwindSafe for ExtensionContext
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> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more