Refactor _run_dir_loop before Phase 3 dynamic turn allocation lands #57
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
_run_dir_loop()(ai.py:845) is ~160 lines and contains four conceptual layers:It is at its readability ceiling. Phase 3 #10 (dynamic turn allocation from plan output) will add per-dir
max_turnsinjection plus possibly mid-loop budget renegotiation — more state in the same function. Refactoring after that lands will be harder than refactoring before.Fix
Extract layers into focused helpers:
_build_dir_loop_context(...)— pre-loop setup (current lines 848–864)_check_budget_and_flush_partial(...)— budget check + partial-cache writer (current 882–938)_handle_turn_response(content_blocks, tool_uses, ...)— tool dispatch + done detection (current 974–998)Leave the for-loop body as a thin coordinator that calls these in sequence. No behavior change. Tests: there are none today (
ai.pyexempt) — see related issue for adding pure-helper coverage.Notes