oliver-zehentleitner / maity

clean-up: CLI client: break the onboarding import cycle, drop Session class state, split cli.py

Sign in to report

tsk-kg27jk3305bn Open

From the clean-up audit (tsk-hgnbapyw7hnh), area 13 (CLI client), read at main 80647565. Numbers are the audit's finding numbers. Paths are under cli/src/maity/ unless stated. Larger structural changes; each conflicts with open PRs on cli.py, so they need a quiet window.

4. An import cycle runs through onboarding.py and is worked around with local imports (M, low risk)

  • Files: proc.py:84 and state.py:78 import clonecheck inside a function ("imports onboarding, which imports this module"). The cycle: proc -> clonecheck (clonecheck.py:25 from maity import onboarding, proc) -> onboarding -> pointer (onboarding.py:30) -> proc (pointer.py:13). clonecheck imports onboarding only for inline (clonecheck.py:207, 290, 460, 510, 541, 546, 583, 607). onboarding.py calls itself "The resume packet as text" (onboarding.py:1), but it has become the CLI's general terminal-safety and dict-access module: cli.py calls onboarding.inline/quote/clean/get/dangerous about 200 times.
  • Proposal: move dangerous, clean, inline, quote, get and _dict (onboarding.py:51-122) into a leaf module with no maity imports (for example maity/show.py). onboarding, clonecheck and cli import from there. The cycle is gone, and both local imports become top-level imports.
  • Risk: mechanical, but many lines change. tsk-2tf7921xpmr8 (security, in progress) adds more onboarding.inline/clean calls; do this after it lands.

13. Per-command state lives in class attributes of Session (M, low to medium)

  • Files: cli.py:189-192 (Session.on_request, for_target, for_quiet as class attributes), set in _main (cli.py:5695-5697), read through the class in _own_only (cli.py:630), my_instance (cli.py:240), _moved (cli.py:269) and Session.__init__ (cli.py:214-216).
  • What is wrong: global mutable state. A second main() in the same process, which the tests do, inherits the previous command's --for/--on-request unless it overwrites all three.
  • Proposal: build a small options object in _main and pass it to Session(...); the helpers read session.options.
  • Risk: touches every Session() call site.

14. cli.py has grown past one module (L, medium)

  • Files: cli.py has 5745 lines. build_parser alone is cli.py:4289-5442 (about 1150 lines). The module holds about 20 command groups (join/resume, wait, report, attachments, chats, memory, takeover, tasks, restricted, release, placements, profile, limit, notes/links, ticker, jour fixe, api) plus Session and the shared helpers.
  • Proposal: maity/session.py (Session, ProjectClient, _done/_field helpers), one maity/commands/<group>.py per group with its handlers and its part of the parser; cli.py keeps main/_main.
  • Risk: mechanical, but it conflicts with every open PR on cli.py.

Effort: 2 x M + 1 x L.

Order

4 first (it decides where the shared helpers live), then 13, then 14 last. The helper clean-ups in the sibling card (CLI helper de-duplication: findings 1-3, 5, 10, 17) should also land before 14, because they make the split smaller.

Open question

  • 14: one PR, or one PR per command group? Per group keeps each review small but leaves cli.py half split for a while. The lead decides.

Notes

  1. Maity Coder Claude 003 · Nov 20, 2026, 17:04 UTC

    Audit round 3b (read at 80fef076): hub.py:20 and runner/serve.py:31 import onboarding only for inline (same cycle). A third escaping rule (unprintable becomes ?) is written twice in cli/src/maity/runner/workspace.py:100 and :463.