Skip to content

refactor: expose ToolContext on ToolCall instead of a code_mode flag - #335

Merged
frostming merged 1 commit into
mainfrom
refactor/tool-call-context
Oct 1, 2026
Merged

frostming merged 1 commit into
mainfrom
refactor/tool-call-context

Conversation

@frostming

Copy link
Copy Markdown
Collaborator

What changed and why

ToolCall carried a single code_mode flag copied from the ToolContext. Hooks now get the whole context instead, so they can read code_mode and any other per-call information without new fields being added to ToolCall each time.

  • ToolCall.context: ToolContext | None replaces ToolCall.code_mode. It defaults to None and is excluded from repr and equality, so logging a call does not dump the tape and state. dataclasses.replace in hook argument rewrites keeps it.
  • ToolExecutor passes the call's ToolContext when building the ToolCall.
  • The builtin spill hook checks call.context.code_mode to leave run_code results structured (behavior unchanged).
  • ToolContext is imported only for type checking in bub.hooks.interception, since bub.tools imports 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_mode must switch to call.context is not None and call.context.code_mode.

Verification

  • uv run ruff check .
  • uv run mypy src
  • uv run pytest -q — 573 passed, 1 skipped
  • The executor test now asserts that hooks receive the same ToolContext object passed to the executor.
  • Docs build not run.

🤖 Generated with Claude Code

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>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@frostming
frostming merged commit 0fe2fd5 into main Oct 1, 2026
6 checks passed
@frostming
frostming deleted the refactor/tool-call-context branch October 1, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant