Goal
Reduce the 12,767-line __main__.py god-module to an entrypoint + dispatch by continuing the established *_cli.py extraction pattern, moving shared helpers out of the entrypoint, and breaking up the ~1,460-line main() argparse builder — all incrementally, one domain per PR.
Why it matters
__main__.py holds 121 inline cmd_* functions across ~20 domains; the extraction pattern is validated but partial (only council/limits/msg/prompts live in dedicated modules). CLAUDE.md names this file as the SSOT, so it's both an onboarding barrier and the constant merge-conflict surface for a project trying to grow contributors. Three concrete sub-problems: (a) main() (:11308-12767) is one ~1,460-line function building 169 subparsers, untestable as a unit; (b) ~29 stateless helpers (tmux_session_exists :462, load/store_session_metadata :3051/3075, load_config :532, build_agent_command) are trapped in the entrypoint, so prompt_router.py:201 reimplements the metadata-path read instead of reusing load_session_metadata, and 6 inline tmux has-session -t =... strings (:886, 942, 1391, 1442, 3804, 6250) bypass the helper and re-type the = prefix inconsistently; (c) the portal's api_check_path/api_check_branches (server.py:3059-3164) embed forked local/SSH git logic inline, violating the stated 'portal calls CLI, doesn't duplicate logic' rule. NOTE: server.py/mcp_server.py are intentionally thin wrappers that shell to the CLI — do NOT make them import helpers; the genuine in-process import candidate is prompt_router.py.
Proposed approach
- Create
agentwire/core.py and move the stateless helpers there; replace the 6 inline tmux has-session strings with tmux_session_exists() and the prompt_router.py:201 read with load_session_metadata().
- Per domain, add a
*_cli.py exporting its cmd_* and a register(subparsers) that builds only its own argparse subtree; main() loops over the register() callables. Each register() becomes independently unit-testable (unblocks the CLI smoke-test issue).
- Add
agentwire repo-info/agentwire branches --json to the CLI and have the portal git endpoints call them.
- Target
__main__.py under ~500 lines (entry + dispatch).
Effort / risk
Effort L, but each step is mechanical and reviewable in isolation. Risk: low (pure relocation; the *_cli.py and sibling-import patterns are already proven). Lower-priority tech debt — sequence after security + growth work.
Goal
Reduce the 12,767-line
__main__.pygod-module to an entrypoint + dispatch by continuing the established*_cli.pyextraction pattern, moving shared helpers out of the entrypoint, and breaking up the ~1,460-linemain()argparse builder — all incrementally, one domain per PR.Why it matters
__main__.pyholds 121 inlinecmd_*functions across ~20 domains; the extraction pattern is validated but partial (only council/limits/msg/prompts live in dedicated modules). CLAUDE.md names this file as the SSOT, so it's both an onboarding barrier and the constant merge-conflict surface for a project trying to grow contributors. Three concrete sub-problems: (a)main()(:11308-12767) is one ~1,460-line function building 169 subparsers, untestable as a unit; (b) ~29 stateless helpers (tmux_session_exists:462,load/store_session_metadata:3051/3075,load_config:532,build_agent_command) are trapped in the entrypoint, soprompt_router.py:201reimplements the metadata-path read instead of reusingload_session_metadata, and 6 inlinetmux has-session -t =...strings (:886, 942, 1391, 1442, 3804, 6250) bypass the helper and re-type the=prefix inconsistently; (c) the portal'sapi_check_path/api_check_branches(server.py:3059-3164) embed forked local/SSH git logic inline, violating the stated 'portal calls CLI, doesn't duplicate logic' rule. NOTE: server.py/mcp_server.py are intentionally thin wrappers that shell to the CLI — do NOT make them import helpers; the genuine in-process import candidate isprompt_router.py.Proposed approach
agentwire/core.pyand move the stateless helpers there; replace the 6 inlinetmux has-sessionstrings withtmux_session_exists()and theprompt_router.py:201read withload_session_metadata().*_cli.pyexporting itscmd_*and aregister(subparsers)that builds only its own argparse subtree;main()loops over the register() callables. Each register() becomes independently unit-testable (unblocks the CLI smoke-test issue).agentwire repo-info/agentwire branches --jsonto the CLI and have the portal git endpoints call them.__main__.pyunder ~500 lines (entry + dispatch).Effort / risk
Effort L, but each step is mechanical and reviewable in isolation. Risk: low (pure relocation; the
*_cli.pyand sibling-import patterns are already proven). Lower-priority tech debt — sequence after security + growth work.