Skip to content

feat(scripted_tool): add ToolImpl combining ToolDef + sync/async exec#1284

Merged
chaliy merged 5 commits intomainfrom
claude/async-scripting-tool-callbacks-q7WBk
Apr 14, 2026
Merged

feat(scripted_tool): add ToolImpl combining ToolDef + sync/async exec#1284
chaliy merged 5 commits intomainfrom
claude/async-scripting-tool-callbacks-q7WBk

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 14, 2026

Summary

  • Introduce ToolImpl as the unified type pairing ToolDef (metadata) with optional sync (SyncToolExec) and async (AsyncToolExec) exec functions
  • ToolImpl implements Builtin, so it can be registered directly in both Bash and ScriptedTool/ScriptingToolSet
  • New tool_def.rs module extracts ToolDef, ToolArgs, ToolImpl, exec types, and parse_flags out of scripted_tool/ to break circular dependencies
  • ScriptedToolBuilder::tool(ToolImpl) and ScriptingToolSetBuilder::tool(ToolImpl) accept the new unified type
  • Existing (ToolDef, callback) API renamed to .tool_fn() / .async_tool_fn() for clarity
  • Backward-compatible type aliases: ToolCallback = SyncToolExec, AsyncToolCallback = AsyncToolExec

Why

A tool is a specialization of a builtin — it trades full Context access for automatic schema-based flag parsing and a simpler exec signature. Before this change, ToolDef and callbacks were separate concepts stitched together by an internal adapter. Now ToolImpl is the public, reusable unit that works uniformly across Bash, ScriptedTool, and ScriptingToolSet.

Test plan

  • 6 new tool_def::tests — parse_flags, ToolImpl construction, Builtin impl, async exec, no-exec error
  • 3 new scripted_tool::tests — ToolImpl sync, async, mixed with tool_fn in ScriptedTool
  • 1 new toolset::tests — ToolImpl registration in ScriptingToolSetBuilder (exclusive + discovery modes)
  • All 94 existing scripted_tool tests pass (API rename verified)
  • cargo fmt, cargo clippy -- -D warnings clean
  • Example scripted_tool runs end-to-end

chaliy added 4 commits April 14, 2026 05:08
Introduce ToolImpl as the unified type that pairs a ToolDef (metadata)
with optional sync and async execution callbacks. ToolImpl implements
Builtin, so it can be registered in both Bash and ScriptedTool contexts.

- New tool_def module with ToolDef, ToolArgs, ToolImpl, SyncToolExec,
  AsyncToolExec, and parse_flags (extracted from scripted_tool)
- ToolImpl implements Builtin with automatic flag parsing via schema
- ScriptedToolBuilder::tool(ToolImpl) accepts the new unified type
- Existing .tool(def, cb) renamed to .tool_fn(def, cb) for clarity
- Backward-compatible type aliases: ToolCallback = SyncToolExec,
  AsyncToolCallback = AsyncToolExec
Consistent terminology: use "exec" instead of "callback" throughout
the public API surface — doc comments, parameter names, type docs.
Verify ToolImpl works end-to-end in ScriptedToolBuilder and
ScriptingToolSetBuilder — sync exec, async exec, mixed with tool_fn,
exclusive mode, and discovery mode.
Add ToolImpl section and update module location to reflect
tool_def.rs extraction.
@chaliy chaliy force-pushed the claude/async-scripting-tool-callbacks-q7WBk branch from 8015895 to 863d83b Compare April 14, 2026 05:13
tool_def.rs is pub(crate), so rustdoc can't resolve cross-module
links to ScriptedToolBuilder and ScriptedTool. Use plain text
instead of doc links.
@chaliy chaliy force-pushed the claude/async-scripting-tool-callbacks-q7WBk branch from 8a1c622 to 64810a7 Compare April 14, 2026 05:25
@chaliy chaliy merged commit c588545 into main Apr 14, 2026
27 checks passed
@chaliy chaliy deleted the claude/async-scripting-tool-callbacks-q7WBk branch April 14, 2026 05:31
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