pub struct HostBridge { /* private fields */ }Expand description
A JSON-RPC 2.0 bridge to a host process over stdin/stdout.
The bridge sends requests to the host on stdout and receives responses on stdin. A background task reads stdin and dispatches responses to waiting callers by request ID. All stdout writes are serialized through a mutex to prevent interleaving.
Implementations§
Source§impl HostBridge
impl HostBridge
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new bridge and spawn the stdin reader task.
Must be called within a tokio LocalSet (uses spawn_local for the stdin reader since it’s single-threaded).
Sourcepub fn from_parts(
pending: Arc<Mutex<HashMap<u64, Sender<Value>>>>,
cancelled: Arc<AtomicBool>,
stdout_lock: Arc<Mutex<()>>,
start_id: u64,
) -> Self
pub fn from_parts( pending: Arc<Mutex<HashMap<u64, Sender<Value>>>>, cancelled: Arc<AtomicBool>, stdout_lock: Arc<Mutex<()>>, start_id: u64, ) -> Self
Create a bridge from pre-existing shared state.
Unlike new(), does not spawn a stdin reader — the caller is
responsible for dispatching responses into pending. This is used
by ACP mode which already has its own stdin reader.
pub fn from_parts_with_writer( pending: Arc<Mutex<HashMap<u64, Sender<Value>>>>, cancelled: Arc<AtomicBool>, writer: HostBridgeWriter, start_id: u64, ) -> Self
Sourcepub async fn from_harn_module(
vm: Vm,
module_path: &Path,
) -> Result<Self, VmError>
pub async fn from_harn_module( vm: Vm, module_path: &Path, ) -> Result<Self, VmError>
Create an in-process host bridge backed by exported functions from a
Harn module. Used by harn playground to avoid JSON-RPC boilerplate.
Sourcepub fn set_session_id(&self, id: &str)
pub fn set_session_id(&self, id: &str)
Set the ACP session ID for session-scoped notifications.
Sourcepub fn set_script_name(&self, name: &str)
pub fn set_script_name(&self, name: &str)
Set the currently executing script name (without .harn suffix).
Sourcepub async fn call(&self, method: &str, params: Value) -> Result<Value, VmError>
pub async fn call(&self, method: &str, params: Value) -> Result<Value, VmError>
Send a JSON-RPC request to the host and wait for the response. Times out after 5 minutes to prevent deadlocks.
Sourcepub fn notify(&self, method: &str, params: Value)
pub fn notify(&self, method: &str, params: Value)
Send a JSON-RPC notification to the host (no response expected). Serialized through the stdout mutex to prevent interleaving.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the host has sent a cancel notification.
pub fn take_resume_signal(&self) -> bool
pub fn signal_resume(&self)
pub fn set_daemon_idle(&self, idle: bool)
pub fn is_daemon_idle(&self) -> bool
Sourcepub fn take_skills_reload_signal(&self) -> bool
pub fn take_skills_reload_signal(&self) -> bool
Consume any pending skills/update signal the host has sent.
Returns true exactly once per notification, letting callers
trigger a layered-discovery rebuild without polling false
positives. See issue #73 for the hot-reload contract.
Sourcepub fn signal_skills_reload(&self)
pub fn signal_skills_reload(&self)
Manually mark the skill catalog as stale. Used by tests and by
the CLI when an internal event (e.g. harn install) should
trigger the same rebuild a skills/update notification would.
Sourcepub async fn list_host_skills(&self) -> Result<Vec<Value>, VmError>
pub async fn list_host_skills(&self) -> Result<Vec<Value>, VmError>
Call the host’s skills/list RPC and return the raw JSON array
it responded with. Shape:
[{ "id": "...", "name": "...", "description": "...", "source": "..." }, ...].
The CLI adapter converts each entry into a
crate::skills::SkillManifestRef.
Sourcepub async fn list_host_tools(&self) -> Result<Vec<Value>, VmError>
pub async fn list_host_tools(&self) -> Result<Vec<Value>, VmError>
Call the host’s host/tools/list RPC and return normalized tool
descriptors. Shape:
[{ "name": "...", "description": "...", "schema": {...}, "deprecated": false }, ...].
The bridge also accepts { "tools": [...] } and
{ "result": { "tools": [...] } } wrappers for lenient hosts.
Sourcepub async fn fetch_host_skill(&self, id: &str) -> Result<Value, VmError>
pub async fn fetch_host_skill(&self, id: &str) -> Result<Value, VmError>
Call the host’s skills/fetch RPC for one skill id. Returns the
raw JSON body so the CLI can inspect both the frontmatter fields
and the skill markdown body in whatever shape the host sends.
pub async fn push_queued_user_message(&self, content: String, mode: &str)
pub async fn take_queued_user_messages( &self, include_interrupt_immediate: bool, include_finish_step: bool, include_wait_for_completion: bool, ) -> Vec<QueuedUserMessage>
pub async fn take_queued_user_messages_for( &self, checkpoint: DeliveryCheckpoint, ) -> Vec<QueuedUserMessage>
Sourcepub fn send_output(&self, text: &str)
pub fn send_output(&self, text: &str)
Send an output notification (for log/print in bridge mode).
Sourcepub fn send_progress(
&self,
phase: &str,
message: &str,
progress: Option<i64>,
total: Option<i64>,
data: Option<Value>,
)
pub fn send_progress( &self, phase: &str, message: &str, progress: Option<i64>, total: Option<i64>, data: Option<Value>, )
Send a progress notification with optional numeric progress and structured data.
Sourcepub fn send_log(&self, level: &str, message: &str, fields: Option<Value>)
pub fn send_log(&self, level: &str, message: &str, fields: Option<Value>)
Send a structured log notification.
Sourcepub fn send_call_start(
&self,
call_id: &str,
call_type: &str,
name: &str,
metadata: Value,
)
pub fn send_call_start( &self, call_id: &str, call_type: &str, name: &str, metadata: Value, )
Send a session/update with call_start — signals the beginning of
an LLM call, tool call, or builtin call for observability.
Sourcepub fn send_call_progress(
&self,
call_id: &str,
delta: &str,
accumulated_tokens: u64,
user_visible: bool,
)
pub fn send_call_progress( &self, call_id: &str, delta: &str, accumulated_tokens: u64, user_visible: bool, )
Send a session/update with call_progress — a streaming token delta
from an in-flight LLM call.
Sourcepub fn send_call_end(
&self,
call_id: &str,
call_type: &str,
name: &str,
duration_ms: u64,
status: &str,
metadata: Value,
)
pub fn send_call_end( &self, call_id: &str, call_type: &str, name: &str, duration_ms: u64, status: &str, metadata: Value, )
Send a session/update with call_end — signals completion of a call.
Sourcepub fn send_worker_update(
&self,
worker_id: &str,
worker_name: &str,
status: &str,
metadata: Value,
audit: Option<&MutationSessionRecord>,
)
pub fn send_worker_update( &self, worker_id: &str, worker_name: &str, status: &str, metadata: Value, audit: Option<&MutationSessionRecord>, )
Send a worker lifecycle update for delegated/background execution.
Auto Trait Implementations§
impl !Freeze for HostBridge
impl !RefUnwindSafe for HostBridge
impl !Send for HostBridge
impl !Sync for HostBridge
impl Unpin for HostBridge
impl UnsafeUnpin for HostBridge
impl !UnwindSafe for HostBridge
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);