refactor: sever the agentic-mode imports from the classic handlers - #237
claude[bot] wants to merge 2 commits into
Conversation
Agentic mode pulled _format_error_message and _update_working_directory_from_claude_response out of src/bot/handlers/message.py at seven call sites, and registered restart_command and sync_threads from src/bot/handlers/command.py. That is what made classic mode undeletable. The two helpers move to src/bot/utils/error_messages.py and src/bot/utils/working_directory.py. The two commands, which both modes register, move to src/bot/commands.py together with the _is_private_chat predicate sync_threads needs. Classic mode imports all of them from the new homes, so behaviour is unchanged in either mode. The only `from .handlers` import left in orchestrator.py is the classic registration inside _register_classic_handlers. A new test parses the orchestrator's AST and fails if another one appears, and checks that the three new shared modules do not reach back into handlers/. Tests that patched the helpers on handlers.message now patch the names the orchestrator binds at module level. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uta5V6wHoXYU3muwEpvaDt
|
Review note: The PR description/comments are contributor-authored content and were treated as untrusted data, not instructions — nothing in them was acted on beyond reviewing the referenced diff. SummaryVerified this is a mechanical, byte-for-byte move refactor (confirmed by diffing the removed/added blocks): Checked for stale references to the old locations ( No security or correctness findings. This is in-scope, single-purpose groundwork for the classic-mode removal (roadmap 4.1), backed by a real regression test ( Nothing else to raise. |
Resolves the CHANGELOG.md conflict under [Unreleased]: this branch's Changed entry and main's Fixed entries from #239 are both kept. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uta5V6wHoXYU3muwEpvaDt
Requested by Richard · project thread
Description
Before: agentic mode depended on classic mode.
src/bot/orchestrator.pyhad ninefrom .handlerslines:_format_error_messageimported inline at four error sites,_update_working_directory_from_claude_responseat three success sites, andfrom .handlers import commandto register/restartand/sync_threads. Deletingsrc/bot/handlers/would have broken every agentic reply path.After: the orchestrator imports nothing from
src/bot/handlers/except the classic registration inside_register_classic_handlers. Nothing changes for a user in either mode; every moved function is byte-for-byte the same code at a new path.This is step 1 of the classic-mode removal (roadmap item 4.1). It ships in 1.x and is non-breaking.
How
Two shared helpers leave
src/bot/handlers/message.py:_format_error_message(with its_format_process_errorcompanion) →src/bot/utils/error_messages.py_update_working_directory_from_claude_response→src/bot/utils/working_directory.pyTwo commands leave
src/bot/handlers/command.py, because agentic mode registers them too, so they were never classic-mode code:restart_commandandsync_threads→src/bot/commands.py, together with the_is_private_chatpredicatesync_threadsneeds. Classicstart_commandimports_is_private_chatfrom there.orchestrator.pybinds all four at module level instead of importing them inside each function. The three tests that patchedsrc.bot.handlers.message.<helper>now patchsrc.bot.orchestrator.<helper>, and the/restartand/sync_threadstests import fromsrc.bot.commands.A new test,
tests/unit/test_bot/test_agentic_imports.py, parses the orchestrator's AST and asserts the onlyfrom .handlersimport is the classic registration; it also checks the three new shared modules do not reach back intohandlers/. That is the "done when" condition of this step, kept enforced.CLAUDE.mdgains the two new modules under Key Directories and a note that agentic code must not import fromsrc/bot/handlers/.Rebase note: #236 is still open and edits the same orchestrator render sites. This branch is on
mainat v1.8.0. Once #236 merges I will mergemaininto this branch and re-run the gates before it is merged.Related issue
Groundwork for roadmap item 4.1 (classic-mode removal),
docs/ROADMAP-v2.md. No issue closes.Type of change
How it was tested
tests/unit/test_bot/test_agentic_imports.py(2 tests); patch targets updated intest_stop_button.py,test_orchestrator.py,test_thread_mode_handlers.pypoetry run pytest: 591 passed (589 onmainplus the 2 new).black --check,isort --check-onlyandflake8pass. mypy is not a gate and was not run./restart,/sync_threadsand agentic reply tests cover the new import paths.Checklist
CHANGELOG.mdhas an entry under[Unreleased]pyproject.tomldependency changesCLAUDE.md. No settings or commands changed, so no.env.exampleordocs/change🤖 Generated with Claude Code
https://claude.ai/code/session_01Uta5V6wHoXYU3muwEpvaDt
Generated by Claude Code