Findings F-3 + F-9a of the "Brownfield CLI/TUI Refactor Assessment" (local report, gitignored under _bmad-output/implementation-artifacts/).
Evidence
engine.py (3,108 lines) is a god-class with banner-separated state clusters:
- Worktree isolation:
engine.py:472-825.
- Rollback/preserve:
engine.py:980-1345.
- Plugin hook bus:
engine.py:1496-1665 (~170 lines over plugins/bus — explicitly OUT of scope; leave in place).
Additionally engine.py:33 imports provision_worktree from install.py — runtime importing the installer.
Verified facts extraction may rely on: SweepEngine (sweep.py) and StoriesEngine (stories_engine.py) override only _loop/_dev_prompt/_verify_*/_post_dev_state_sync/the _drive_story family — NOTHING in either extraction cluster. tests/test_engine.py references Engine private methods 18× (and test_engine_worktree.py 1×) → delegator strategy required.
Recommendation — two PRs
PR 1 (worktree cluster): extract engine.py:472-825 into a collaborator (e.g. src/bmad_loop/worktree_flow.py) taking narrow deps (repo path, policy slice, journal/escalate callables) — never the whole Engine. Move provision_worktree from install.py into the new module, leaving a re-export in install.py. Add unit tests for the collaborator in a NEW test file.
PR 2 (rollback/preserve cluster): extract engine.py:980-1345 into a recovery collaborator, same pattern and constraints.
Acceptance criterion for both: Engine keeps same-name delegating private methods so test_engine*.py stays byte-untouched and green.
Ordering
Sessions 9-10 of the refactor program; ideally after the pyright basic gate lands. PR 2 requires PR 1 merged (verify on main). Line ranges may drift — re-locate by the section banner comments.
Traps
- Do not touch the override seams (
engine.py:2179 banner) or anything SweepEngine/StoriesEngine overrides.
install.py re-export needs a noqa: F401 pin; ruff autofix deletes re-exports — trunk check --no-fix.
- Behavior-preserving only; no CHANGELOG. Confirm Windows CI coverage of the worktree/rollback paths before starting (assessment deferred-decisions list).
Findings F-3 + F-9a of the "Brownfield CLI/TUI Refactor Assessment" (local report, gitignored under
_bmad-output/implementation-artifacts/).Evidence
engine.py(3,108 lines) is a god-class with banner-separated state clusters:engine.py:472-825.engine.py:980-1345.engine.py:1496-1665(~170 lines overplugins/bus— explicitly OUT of scope; leave in place).Additionally
engine.py:33importsprovision_worktreefrominstall.py— runtime importing the installer.Verified facts extraction may rely on:
SweepEngine(sweep.py) andStoriesEngine(stories_engine.py) override only_loop/_dev_prompt/_verify_*/_post_dev_state_sync/the_drive_storyfamily — NOTHING in either extraction cluster.tests/test_engine.pyreferences Engine private methods 18× (andtest_engine_worktree.py1×) → delegator strategy required.Recommendation — two PRs
PR 1 (worktree cluster): extract
engine.py:472-825into a collaborator (e.g.src/bmad_loop/worktree_flow.py) taking narrow deps (repo path, policy slice, journal/escalate callables) — never the whole Engine. Moveprovision_worktreefrominstall.pyinto the new module, leaving a re-export ininstall.py. Add unit tests for the collaborator in a NEW test file.PR 2 (rollback/preserve cluster): extract
engine.py:980-1345into a recovery collaborator, same pattern and constraints.Acceptance criterion for both: Engine keeps same-name delegating private methods so
test_engine*.pystays byte-untouched and green.Ordering
Sessions 9-10 of the refactor program; ideally after the pyright basic gate lands. PR 2 requires PR 1 merged (verify on main). Line ranges may drift — re-locate by the section banner comments.
Traps
engine.py:2179banner) or anything SweepEngine/StoriesEngine overrides.install.pyre-export needs anoqa: F401pin; ruff autofix deletes re-exports —trunk check --no-fix.