refactor(cli): decompose the 2627-line cli.py into a keel/commands package - #123
Merged
Conversation
…ckage keel/cli.py had grown to 2627 lines: seven click command groups plus ~15 top-level commands and their shared helpers in one file. Split the broker-free groups into their own modules under a new keel/commands/ package, leaving cli.py a thin composition root (2627 -> 1688 lines, -36%). Extracted groups (each registered via cli.add_command): trials, subscription, db, withdrawals, autonomy, rules. Shared CLI seams (with_disclaimer, the confirmation gate, _open_repo/_load_cfg/_build_broker, DISCLAIMER, path defaults) moved to keel/commands/_common.py; shared product-id derivation (_history_product/_default_sim_products) to keel/commands/_products.py. The assets group and the broker-touching top-level commands (fetch, agent, monitor, simulate) stay in cli.py on purpose, so the _build_broker monkeypatch seam remains one coherent target rather than fragmenting across modules. Monkeypatch seams preserved: _build_broker/_open_repo/_load_cfg stay patchable as keel.cli.X (cli.py re-imports them and all their callers remain there); _is_interactive is routed through _common._is_interactive() as a single patch point, with three test files retargeted to keel.commands._common. No behavior change: all 1322 tests pass, ruff + mypy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
keel/cli.pyhad grown to 2627 lines — sevenclickcommand groups plus ~15 top-level commands and their shared helpers in one file. This splits the broker-free groups into their own modules under a newkeel/commands/package, leavingcli.pya thin composition root.keel/cli.py: 2627 → 1688 lines (−36%). No behavior change.What moved
commands/trials.pytrialsgroup (ledger-only, seam-free)commands/rules.pyruleslifecycle group (rules_seedstill invoked byinit)commands/subscription.pysubscriptiongroup (rail 14)commands/autonomy.pyautonomygroup (+ its_AUTONOMY_HOURSconstants)commands/withdrawals.pywithdrawalsgroup (rail 17)commands/db.pydb importgroupcommands/_common.py_open_repo/_load_cfg/_build_brokercommands/_products.pyEach group is registered on the root CLI via
cli.add_command(...).Deliberately kept in
cli.pyThe
assetsgroup and the broker-touching top-level commands (fetch,agent,monitor,simulate) stay in the composition root so the_build_brokermonkeypatch seam remains one coherent target rather than fragmenting across modules.Seam preservation (the delicate part)
_build_broker/_open_repo/_load_cfgstay patchable askeel.cli.X—cli.pyre-imports them and every caller of these remains incli.py._is_interactive(called internally by the confirmation gate) is routed through_common._is_interactive()as a single patch point; three test files were retargeted tokeel.commands._common._is_interactive.Verification
ruff check .cleanmypy keel packagescleanpytest— 1322 passedEach extraction step was reviewed by a sub-agent (zero defects), plus a final holistic review.
🤖 Generated with Claude Code