refactor: replace if/elif dispatch chain with tool handler registry (PR 7)#2
Open
anonymort wants to merge 13 commits intoShinMegamiBoson:mainfrom
Open
refactor: replace if/elif dispatch chain with tool handler registry (PR 7)#2anonymort wants to merge 13 commits intoShinMegamiBoson:mainfrom
anonymort wants to merge 13 commits intoShinMegamiBoson:mainfrom
Conversation
Add Apache 2.0 license file, contribution guide with code of conduct, and [project.optional-dependencies] dev group (pytest, mypy, ruff). Update README to reference the new files.
Ruff violations (12 fixed): - N806: Rename _PARALLEL_TOOLS to parallel_tools (engine.py) - B007: Rename unused loop var attempt to _attempt (model.py) - RUF012: Add ClassVar annotation to mutable class attribute (tui.py) - F841: Remove unused fed variable (cast_to_video.py) - C408: Convert dict() calls to dict literals (5 files) - RUF002: Replace × with x in docstring (test_integration.py) - RUF005: Use iterable unpacking instead of concatenation (test_replay_log.py) - RUF059: Prefix unused unpacked variable with underscore (test_settings.py) - RUF015: Replace slice[0] with next() (test_tool_defs.py) Mypy errors (19 fixed): - Add type parameters to untyped dicts (settings.py, builder.py, tools.py) - Add missing return type annotations (tools.py, tui.py) - Fix incompatible type assignments (tools.py, demo.py, builder.py, engine.py) - Fix Generator import from collections.abc (tools.py) - Add TextIO type annotation (tools.py) - Add cast for json.loads return value (runtime.py) - Add type annotations for Rich integration (tui.py) - Remove unused type: ignore comments (tools.py, engine.py, tui.py) - Keep necessary type: ignore for Rich library compatibility (engine.py, tui.py) All checks now pass: - ruff: 0 violations - mypy: 0 errors - pytest: 412 passing tests
Replaces the 260-line if/elif chain in _apply_tool_call with a dict registry pattern. Each stateless tool gets a dedicated _handle_* method; subtask/execute are extracted into _apply_subtask/_apply_execute. Zero behavior change — all argument extraction and validation logic is copied verbatim from the original branches.
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
How to add a tool now
No changes to `_apply_tool_call` required.
Changes
Test results
```
410 passed, 22 skipped, 4 failed (pre-existing, unchanged)
```
Zero regressions introduced.
Test plan