feat: add scriptable tool result transform hook#6291
Merged
houko merged 1 commit intoJun 23, 2026
Conversation
pavver
force-pushed
the
feat/scriptable-transform-tool-result
branch
from
June 23, 2026 20:07
af96864 to
afe34c8
Compare
houko
added a commit
that referenced
this pull request
Jun 24, 2026
…nbreak Windows CI (#6306) * fix(test): gate scriptable transform-hook tests behind cfg(unix) to unbreak Windows CI The #6291 transform_tool_result hook tests execute a real #!/bin/sh script through the native script runtime. Windows has no /bin/sh, so the spawn fails and the metrics assertions don't hold, failing both Windows test shards and turning main red (#6304) — every open PR then inherits the failure on its next run. Gate the four shell-script tests and their make_transform_script / make_transform_engine helpers (plus the now-test-only MemorySubstrate / ToolExecutionStatus imports) behind #[cfg(unix)]. The transform-hook feature is unchanged and still covered on Linux and macOS. * style(test): remove redundant import comment; collapse multi-line comment to one line --------- Co-authored-by: Evan <[email protected]> Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
transform_tool_resulthook toContextEngineso context engines can rewrite tool output before it is written into session history.HookEvent::TransformToolResulthook and before artifact spill, sanitization, injection guarding, and session commit.ContextEngineHooksfor scriptable/manual/plugin configuration.transform_tool_resultin scriptable hook validation, metrics, traces, plugin hook path checks, and plugin integrity checks.build_context_enginecreate a scriptable layer when any declared scriptable hook exists, includingtransform_tool_result,assemble,compact, subagent hooks, andon_event.Hook Contract
The script receives:
{ "type": "transform_tool_result", "agent_id": "...", "tool_name": "...", "tool_use_id": "...", "input": {}, "content": "...", "is_error": false, "status": "completed" }To rewrite the model-visible tool result content, it returns:
{ "content": "rewritten tool output" }If
contentis missing or not a string, the original tool result is kept.If the hook fails under the default warning policy, the original tool result is kept.
Why
This gives per-agent context engines a deterministic pre-ingest cleanup point for noisy tool outputs.
For example, a Rust coding agent can trim
cargo checkorcargo testoutput with Rust-specific rules before that output enters conversation history, while an Android/Kotlin agent can use different Gradle/logcat cleanup rules. Agents that do not configure the hook keep the existing behavior.Verification
cargo test -p librefang-runtime transform_tool_resultcargo test -p librefang-runtime hook_integrity_all_hook_fields_checkedcargo check -p librefang-types -p librefang-runtimecargo clippy -p librefang-types -p librefang-runtime --all-targets -- -D warningsgit diff --checkOut Of Scope
HookEvent::TransformToolResultcontract.