pub struct HookRequest {
pub hook_schema: u32,
pub event: HookEvent,
pub workspace: PathBuf,
pub agent_id: String,
pub tool_call_id: String,
pub tool_name: String,
pub input: Value,
pub output: Option<Value>,
pub is_error: Option<bool>,
}Expand description
The call as basis puts it to one participant.
The same struct reaches both bindings: a subprocess hook reads it as the
JSON object on its stdin, and an Interceptor is
handed a reference to it. That identity is what “one contract” means
concretely — there is no in-process shape a hook cannot see and no wire
field an interceptor is denied.
It carries HOOK_SCHEMA_VERSION for the binding that needs it. A
subprocess hook is compiled against nothing and must be able to tell when
the shape has moved; an interceptor is compiled against this crate and
cannot skew, so the field is simply true for it rather than useful.
Fields§
§hook_schema: u32§event: HookEvent§workspace: PathBufThe workspace root the run is scoped to, and a subprocess hook’s working directory.
agent_id: String§tool_call_id: String§tool_name: String§input: ValueParsed tool input when it is valid JSON, else the raw string.
On a PostToolUse request this is the input
the tool ran with, after any earlier modification — what happened,
not what the model asked for.
output: Option<Value>What the tool returned, on a PostToolUse
request and on no other.
Absent rather than null before the call, because a call that has not run has no output to be null about. A structured result arrives as itself and a text result as a JSON string — the runtime already knows which it produced, so nothing here guesses by re-parsing text that happens to look like JSON.
is_error: Option<bool>Whether the tool reported failure, beside the output it reported it with. Absent for the same reason.
Named as Event::ToolCompleted
names it, so a hook and a stream consumer describe one result the same
way.
Implementations§
Source§impl HookRequest
impl HookRequest
Sourcepub fn from_call(event: HookEvent, workspace: &Path, call: &HookCall) -> Self
pub fn from_call(event: HookEvent, workspace: &Path, call: &HookCall) -> Self
Builds a request from the call the runtime is about to make.
The call carries input_json as a string. Parsing it here rather than
passing it through means a participant reads .input.command instead of
decoding a nested document — which matters to a shell script and to a
Rust interceptor alike; when it is not valid JSON there is nothing to
parse and the raw string is carried instead, which is what
Event::ToolQueued does with the
same value.
workspace is the root basis scoped the run to, and it is also the
call’s working directory: mentra’s PreExecutionContext carries one
(working_directory, the agent’s base_dir), and it is the key the
dispatcher (runtime::dispatch) resolves to this workspace’s runner in
the first place — so the two are one path by construction, and a
second field would only invite them to disagree.
Sourcepub fn from_result(
workspace: &Path,
call: &HookCall,
output: Value,
is_error: bool,
) -> Self
pub fn from_result( workspace: &Path, call: &HookCall, output: Value, is_error: bool, ) -> Self
Builds a request from the call the runtime has just made, and what it produced.
The event is PostToolUse and not a
parameter: an output is the one thing a request can carry that says
which seam it came from, so the two cannot be set to disagree.
Sourcepub fn with_input(self, input: Value) -> Self
pub fn with_input(self, input: Value) -> Self
The same request with a different tool input.
What threading a modification through the chain is made of: the next participant is asked about the call as the previous one left it.
Sourcepub fn with_output(self, output: Value, is_error: bool) -> Self
pub fn with_output(self, output: Value, is_error: bool) -> Self
The same request with a different result.
The after-the-call twin of with_input, and the
same property: a participant judges the result as its predecessors left
it, never the one the tool returned.
Trait Implementations§
Source§impl Clone for HookRequest
impl Clone for HookRequest
Source§fn clone(&self) -> HookRequest
fn clone(&self) -> HookRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more