refactor: expose ToolContext on ToolCall instead of a code_mode flag - #335
Merged
Merged
Conversation
Hooks now receive the ToolContext a call runs with as `ToolCall.context` (excluded from repr and comparison), so they can read `code_mode` and any other per-call context. The spill hook reads `call.context.code_mode`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Frost Ming <me@frostming.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bub | 46052b1 | Commit Preview URL Branch Preview URL |
Oct 01 2026, 02:48 AM |
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.
What changed and why
ToolCallcarried a singlecode_modeflag copied from theToolContext. Hooks now get the whole context instead, so they can readcode_modeand any other per-call information without new fields being added toToolCalleach time.ToolCall.context: ToolContext | NonereplacesToolCall.code_mode. It defaults toNoneand is excluded fromreprand equality, so logging a call does not dump the tape and state.dataclasses.replacein hook argument rewrites keeps it.ToolExecutorpasses the call'sToolContextwhen building theToolCall.call.context.code_modeto leaverun_coderesults structured (behavior unchanged).ToolContextis imported only for type checking inbub.hooks.interception, sincebub.toolsimports that module.Impacted modules
bub.hooks.interception,bub.tools,bub.builtin.hook_impl; tools docs (en/zh-cn).Breaking for hook authors: plugins reading
call.code_modemust switch tocall.context is not None and call.context.code_mode.Verification
uv run ruff check .uv run mypy srcuv run pytest -q— 573 passed, 1 skippedToolContextobject passed to the executor.🤖 Generated with Claude Code