Skip to main content

CodingHarness

Struct CodingHarness 

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

Harness wiring config, tools, system prompt, hooks, and Agent.

Implementations§

Source§

impl CodingHarness

Source

pub fn builder( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, ) -> CodingHarnessBuilder

Start building a harness for SDK/embedder use.

Source

pub fn new( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, ) -> Self

Create a new harness with the given provider, model, config, and workspace root.

Source

pub fn new_with_selection( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, tool_selection: ToolSelection, ) -> Self

Create a new harness with an explicit tool selection.

Source

pub fn new_with_tool_config( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, tool_config: ToolRuntimeConfig, ) -> Self

Create a new harness with already resolved tool runtime config.

Source

pub fn new_with_hooks( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, hooks: Box<dyn AgentHooks>, user_system_prompt: Option<String>, initial_messages: Vec<AgentMessage>, tool_selection: ToolSelection, ) -> Self

Create a new harness with custom hooks.

Source

pub fn new_with_hooks_and_resume( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, hooks: Box<dyn AgentHooks>, user_system_prompt: Option<String>, initial_messages: Vec<AgentMessage>, resume: Option<ResumeInfo>, tool_selection: ToolSelection, ) -> Self

Create a new harness, optionally adopting an existing session (resume).

Source

pub fn new_with_hooks_and_resume_tool_config( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, hooks: Box<dyn AgentHooks>, user_system_prompt: Option<String>, initial_messages: Vec<AgentMessage>, resume: Option<ResumeInfo>, tool_config: ToolRuntimeConfig, ) -> Self

Create a new harness, optionally adopting an existing session (resume), with already resolved tool runtime config.

Source

pub fn new_with_global_config_dir( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, hooks: Box<dyn AgentHooks>, user_system_prompt: Option<String>, initial_messages: Vec<AgentMessage>, resume: Option<ResumeInfo>, tool_selection: ToolSelection, global_config_dir: Option<PathBuf>, ) -> Self

Create a new harness with an explicit global config directory override.

When global_config_dir is None, uses the platform default from crate::config::user_config_dir. Pass Some(path) in tests to isolate global context file discovery from the real user config dir.

Source

pub fn new_with_global_config_dir_tool_config( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, hooks: Box<dyn AgentHooks>, user_system_prompt: Option<String>, initial_messages: Vec<AgentMessage>, resume: Option<ResumeInfo>, tool_config: ToolRuntimeConfig, global_config_dir: Option<PathBuf>, ) -> Self

Create a new harness with an explicit global config directory override and already resolved tool runtime config.

Source

pub fn add_tool(&mut self, tool: Box<dyn Tool>)

Add an extra tool to the harness (for testing with mock tools).

Source

pub fn queue_images(&mut self, images: Vec<InputContent>)

Queue images to be injected into the next prompt.

Source

pub fn take_pending_images(&mut self) -> Vec<InputContent>

Take and clear queued images.

Source

pub fn model_picker_items(&self) -> Vec<SelectItem>

Return model picker items from the active provider.

Source

pub fn set_model(&mut self, model: String)

Change the model used by subsequent prompts.

Source

pub fn set_model_validated(&mut self, model: String) -> Result<&str, String>

Validate and change the model used by subsequent prompts.

Source

pub fn set_thinking_level( &mut self, level: &str, ) -> Result<RuntimeThinkingState, String>

Change the thinking level used by subsequent provider requests.

Source

pub fn resume_session_id(&mut self, session_id: &str) -> Result<usize, String>

Resume an existing session by ID into this harness.

Source

pub fn branch_picker_items(&self) -> Result<Vec<SelectItem>, String>

Return branch picker items for the currently active session.

Source

pub fn resume_session_branch_tip( &mut self, tip_id: &str, ) -> Result<usize, String>

Switch the current session to the branch ending at tip_id.

Source

pub async fn prompt( &mut self, text: &str, ) -> Result<Vec<AgentMessage>, AgentError>

Send a user prompt and run the agent loop.

Source

pub async fn prompt_with_content( &mut self, content: Vec<InputContent>, ) -> Result<Vec<AgentMessage>, AgentError>

Send a user message with arbitrary content (text + images) and run the agent loop.

Source

pub async fn continue_( &mut self, text: &str, ) -> Result<Vec<AgentMessage>, AgentError>

Continue the conversation with an additional message.

Source

pub fn model(&self) -> &str

Return the current model name.

Source

pub fn steer(&self, message: String)

Queue a steering message for the next provider call.

Source

pub fn follow_up(&self, message: String)

Queue a follow-up message for when the agent would otherwise stop.

Source

pub fn subscribe(&mut self, callback: Box<dyn Fn(&AgentEvent) + Send + Sync>)

Register an event subscriber.

Source

pub fn system_prompt(&self) -> &str

Return the assembled system prompt (for testing).

Source

pub fn resource_metadata(&self) -> &DiscoveredResourceMetadata

Return read-only discovered resource metadata.

Source

pub fn resource_metadata_json(&self) -> Value

Return resource metadata in the compact RPC/session-info shape.

Source

pub fn resolve_theme(&self, name: &str) -> Result<Theme, ThemeDiscoveryError>

Resolve a theme using discovered themes first, then built-ins.

Source

pub fn config(&self) -> &OpiConfig

Return a reference to the config.

Source

pub fn cancel(&self)

Cancel the running operation.

Source

pub fn cancel_token(&self) -> CancellationToken

Return a clonable cancellation token for external cancellation.

Source

pub fn control_handle(&self) -> AgentControl

Return a clonable control handle for an active agent turn.

Source

pub fn reset_cancel_if_cancelled(&mut self)

Reset cancellation state before cloning a control handle for a new turn.

Source

pub fn session(&self) -> Option<&SessionCoordinator>

Return the session coordinator, if active.

Source

pub fn compact( &mut self, reason: CompactionReason, ) -> Result<Option<CompactionResult>, String>

Execute manual compaction on the session, if one is active. Returns the compaction result, or None if compaction produced no output or no session exists.

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.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

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

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 = 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<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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