pub struct CodingHarness { /* private fields */ }Expand description
Harness wiring config, tools, system prompt, hooks, and Agent.
Implementations§
Source§impl CodingHarness
impl CodingHarness
Sourcepub fn builder(
provider: Box<dyn Provider>,
model: String,
config: OpiConfig,
workspace_root: PathBuf,
) -> CodingHarnessBuilder
pub fn builder( provider: Box<dyn Provider>, model: String, config: OpiConfig, workspace_root: PathBuf, ) -> CodingHarnessBuilder
Start building a harness for SDK/embedder use.
Sourcepub fn new(
provider: Box<dyn Provider>,
model: String,
config: OpiConfig,
workspace_root: PathBuf,
) -> Self
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.
Sourcepub fn new_with_selection(
provider: Box<dyn Provider>,
model: String,
config: OpiConfig,
workspace_root: PathBuf,
tool_selection: ToolSelection,
) -> Self
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.
Sourcepub fn new_with_tool_config(
provider: Box<dyn Provider>,
model: String,
config: OpiConfig,
workspace_root: PathBuf,
tool_config: ToolRuntimeConfig,
) -> Self
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.
Sourcepub 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
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.
Sourcepub 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
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).
Sourcepub 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
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.
Sourcepub 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
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.
Sourcepub 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
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.
Sourcepub fn add_tool(&mut self, tool: Box<dyn Tool>)
pub fn add_tool(&mut self, tool: Box<dyn Tool>)
Add an extra tool to the harness (for testing with mock tools).
Sourcepub fn queue_images(&mut self, images: Vec<InputContent>)
pub fn queue_images(&mut self, images: Vec<InputContent>)
Queue images to be injected into the next prompt.
Sourcepub fn take_pending_images(&mut self) -> Vec<InputContent>
pub fn take_pending_images(&mut self) -> Vec<InputContent>
Take and clear queued images.
Sourcepub fn model_picker_items(&self) -> Vec<SelectItem>
pub fn model_picker_items(&self) -> Vec<SelectItem>
Return model picker items from the active provider.
Sourcepub fn set_model_validated(&mut self, model: String) -> Result<&str, String>
pub fn set_model_validated(&mut self, model: String) -> Result<&str, String>
Validate and change the model used by subsequent prompts.
Sourcepub fn set_thinking_level(
&mut self,
level: &str,
) -> Result<RuntimeThinkingState, String>
pub fn set_thinking_level( &mut self, level: &str, ) -> Result<RuntimeThinkingState, String>
Change the thinking level used by subsequent provider requests.
Sourcepub fn resume_session_id(&mut self, session_id: &str) -> Result<usize, String>
pub fn resume_session_id(&mut self, session_id: &str) -> Result<usize, String>
Resume an existing session by ID into this harness.
Sourcepub fn branch_picker_items(&self) -> Result<Vec<SelectItem>, String>
pub fn branch_picker_items(&self) -> Result<Vec<SelectItem>, String>
Return branch picker items for the currently active session.
Sourcepub fn resume_session_branch_tip(
&mut self,
tip_id: &str,
) -> Result<usize, String>
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.
Sourcepub async fn prompt(
&mut self,
text: &str,
) -> Result<Vec<AgentMessage>, AgentError>
pub async fn prompt( &mut self, text: &str, ) -> Result<Vec<AgentMessage>, AgentError>
Send a user prompt and run the agent loop.
Sourcepub async fn prompt_with_content(
&mut self,
content: Vec<InputContent>,
) -> Result<Vec<AgentMessage>, AgentError>
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.
Sourcepub async fn continue_(
&mut self,
text: &str,
) -> Result<Vec<AgentMessage>, AgentError>
pub async fn continue_( &mut self, text: &str, ) -> Result<Vec<AgentMessage>, AgentError>
Continue the conversation with an additional message.
Sourcepub fn follow_up(&self, message: String)
pub fn follow_up(&self, message: String)
Queue a follow-up message for when the agent would otherwise stop.
Sourcepub fn subscribe(&mut self, callback: Box<dyn Fn(&AgentEvent) + Send + Sync>)
pub fn subscribe(&mut self, callback: Box<dyn Fn(&AgentEvent) + Send + Sync>)
Register an event subscriber.
Sourcepub fn system_prompt(&self) -> &str
pub fn system_prompt(&self) -> &str
Return the assembled system prompt (for testing).
Sourcepub fn resource_metadata(&self) -> &DiscoveredResourceMetadata
pub fn resource_metadata(&self) -> &DiscoveredResourceMetadata
Return read-only discovered resource metadata.
Sourcepub fn resource_metadata_json(&self) -> Value
pub fn resource_metadata_json(&self) -> Value
Return resource metadata in the compact RPC/session-info shape.
Sourcepub fn resolve_theme(&self, name: &str) -> Result<Theme, ThemeDiscoveryError>
pub fn resolve_theme(&self, name: &str) -> Result<Theme, ThemeDiscoveryError>
Resolve a theme using discovered themes first, then built-ins.
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Return a clonable cancellation token for external cancellation.
Sourcepub fn control_handle(&self) -> AgentControl
pub fn control_handle(&self) -> AgentControl
Return a clonable control handle for an active agent turn.
Sourcepub fn reset_cancel_if_cancelled(&mut self)
pub fn reset_cancel_if_cancelled(&mut self)
Reset cancellation state before cloning a control handle for a new turn.
Sourcepub fn session(&self) -> Option<&SessionCoordinator>
pub fn session(&self) -> Option<&SessionCoordinator>
Return the session coordinator, if active.
Sourcepub fn compact(
&mut self,
reason: CompactionReason,
) -> Result<Option<CompactionResult>, String>
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§
impl !RefUnwindSafe for CodingHarness
impl !UnwindSafe for CodingHarness
impl Freeze for CodingHarness
impl Send for CodingHarness
impl Sync for CodingHarness
impl Unpin for CodingHarness
impl UnsafeUnpin for CodingHarness
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> 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