oliver-zehentleitner / maity

clean-up: CLI client: one shared helper each for git calls, names, state home and temp writes

Sign in to report

tsk-egaycsbdwmeq 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. These are helpers shared between CLI modules.

7. The git-call wrapper exists five times (S, low risk)

  • Files: citecheck.py:35-36 _git and textcheck.py:160-161 _Repo._git have identical bodies (proc.run([*proc.GIT, "--literal-pathspecs", *args], cwd)). gitfacts.py:59-83 has _run/_git/_git_required. versioninfo.py:71-75 _git raises on non-zero, like _git_required. pointer.py:50-55 makes the call inline.
  • Proposal: one proc.git(cwd, *args, check=False, literal=False, timeout=…). The modules keep only their own error mapping.

8. ghpr calls other modules' private functions (S, low)

  • Files: ghpr.py:237 calls gitfacts._branch. ghpr.py:115 calls clonecheck._read_regular.
  • What is wrong: these functions have callers in other modules, but nothing marks them as API, so a refactor of the owning module can break the callers without notice.
  • Proposal: make them public (gitfacts.branch, clonecheck.read_regular) or add public wrappers.
  • Note: tsk-2tf7921xpmr8 (security, in progress) also edits ghpr.py _readable; do this after it or rebase on it.
  • Not in this card: runner/adapters.py:213 calls clonecheck._private_dir, the same pattern in area 9.

9. The handle/full-name pattern is copied with different bounds (S, low)

  • Files: cli.py:128 _FULL_NAME, cli.py:592 _PAGE_HANDLE ({1,62}), hub.py:281 _HANDLE and hub.py:284 _GLOBAL ({0,62}), onboarding.py:134 _GLOBAL_NAME. The hub's rule is HANDLE_PATTERN = ^[a-z0-9][a-z0-9-]{1,30}$ (hub/src/maity_hub/models.py:10) and SLUG_PATTERN {1,62} (models.py:11).
  • What is wrong: the CLI copies disagree with each other (1 vs 2 minimum characters) and with the hub (a handle is at most 31 characters). They are shape checks only, but a reader cannot tell which bound is meant.
  • Proposal: one maity/names.py with HANDLE, SLUG and FULL_NAME matching hub models.py, imported by these places. runner/workspace.py:29 TOKEN and :31 FULL_NAME (area 9) are the same pattern and can import it too.
  • Risk: tightening a pattern could refuse a value the hub itself never issues.

15. Two definitions of the per-user state home (S, low)

  • Files: state.py:152-159 _state_home honours XDG_STATE_HOME (else %LOCALAPPDATA%, else ~/.local/state). environment.py:23-28 HOME_SECRET ignores XDG_STATE_HOME on purpose, "so the id of a home stays what it was", and is fixed at import time.
  • What is wrong: the reason is compatibility with ids from earlier versions, which the alpha does not need (no legacy users). Two rules for where home state lives can drift apart.
  • Proposal: make state._state_home public and use it in environment.ids, computed at call time.
  • Risk: for users with XDG_STATE_HOME set, the home id changes once, and the hub's shared-home warning could change for one resume.

18. secret_once repeats _atomic_write's temp-file code (S, low; security-relevant file)

  • Files: state.py:317-340 secret_once repeats the mkstemp / fdopen / write / flush / fsync / unlink sequence of state.py:183-200 _atomic_write. The only difference is the last step: os.link instead of _replace. cli.py:1841-1859 (files get) has similar temp-then-rename code with a reason of its own (binary data); leave it unless it fits naturally.
  • Proposal: a _write_temp(dir, name, data) -> Path helper in state.py used by both functions.
  • Risk: state.py writes credentials, so the PR needs a careful review (permissions, link-not-replace semantics, cleanup on error).

Effort: 5 x S.

Notes

  1. Maity Coder Claude 003 · Nov 13, 2026, 23:12 UTC

    Item 9, another site from the clean-up audit (tsk-hgnbapyw7hnh, uncovered-files pass at 9dfd4b65): runner/config.py:38.