oliver-zehentleitner / maity

cli/web clean-up: audit R5 batch 3 (skills.py vs skillop.py, ...)

Sign in to report

tsk-dx3f22fzhg93 Done Maity Coder Claude 003

From the standing clean-up audit tsk-hgnbapyw7hnh, round 5 batch 3 (5tj4, seq 197905, cli/runner and web read at 439cf902). One PR for the cli findings; the web findings may be a second PR (web/ text changes need smoke). Do not touch the files of open PRs: runner capabilities/commands/config/supervisor/keeper/serve/watch/tools, cli/context/runner.md, docs/runners*.md, web app.js/views.md/smoke.js (#2094, #2111, #2115, #2119). Run overlap.sh before the push; where a finding needs one of those files, it waits until that PR is merged.

The held-back point (the former scratch layout) is not on this card. It gets its own card once #2094/#2119 have landed.

Done when every finding is fixed, or a named reason says why not.

---- the findings, as reported ----
maity-coder-claude-003#5tj4, audit round 5, batch 3: cli/runner and web, read at 439cf902. 9 findings.

Skipped because open PRs touch them: runner capabilities, commands, config, supervisor, keeper, serve, watch and tools; cli/context/runner.md; docs/runners*.md; web app.js, views.md and smoke.js. One finding is held back: the "former" scratch layout <root>/<project>/.scratch/<id> is still carried through scratchop._below, workspace.scratch_of(former=), adapters.scratch_holder and operate._scratch_holders, but where it is used is decided in supervisor._host_layout, which is under review. It is worth a card once that PR lands.

1. Duplication: runner/skills.py repeats skillop.py, which it already imports

  • The same constants in both:
  • cli/src/maity/runner/skills.py:39-44, :55, :174 (NAME, COMMIT, MANIFEST, PLUGIN, MAX_FILES, MAX_BYTES, KEY, MANIFEST_MAX)
  • cli/src/maity/runner/skillop.py:48-55
  • The same key function: skills.key (skills.py:58-61) and skillop._key (skillop.py:288-290). The docstring says "without importing it (standard library only)", but only skillop has to stay standard-library only; skills imports skillop (skills.py:36).
  • A by-path copy of the bounded no-follow reader: skills._read (skills.py:272, used at :249 and :301) copies skillop._read_at (skillop.py:172-196).
  • skills.remove_unused reaches into skillop's privates _FOLDER, _NOFOLLOW and _remove_tree (skills.py:429, :437).
  • Proposal: the constants, key and a public bounded read live once, in skillop. skills.py imports them, and the three privates become public.
  • Effort S. Risk low: the values are identical, and test_skills and test_skillop cover them. (The general reader is tsk-zzjc91gq8ar1; this finding is only the copy between these two new modules.)

2. Duplication: skillop.py has two stage-and-replace paths, and one lacks the error handler

  • put (cli/src/maity/runner/skillop.py:353-379) stages files, opens directories to 0755 with an inline os.fwalk (:364-367), verifies, then calls _replace.
  • _stage_and_replace (:528-549) does the same through _open_up (:557-566), which passes onerror=_unreadable. The inline fwalk in put has none, so a directory it cannot open is skipped silently. The later verify catches it, so this is drift, not a hole.
  • Proposal: put calls _open_up, or goes through _stage_and_replace with the manifest as one more staged file.
  • Effort S-M. Risk low to medium: this is security-reviewed code (#2089, #2093), and test_skillop must stay green unchanged.

3. Design: adapters.py rebuilds paths that scratch.py and skills.py own

  • cli/src/maity/runner/adapters.py:1051 under = ctx.scratch.parents[2] is scratch._under (cli/src/maity/runner/scratch.py:45-49). adapters then calls ctx.as_user.skill_codex/skill_codex_clear directly, while its sibling scratch.write_codex_home (scratch.py:65-74) goes through scratch.
  • adapters.skill_env (adapters.py:284) builds ctx.skill / "skills" / skills.NAME, which is skills.skill_dir (skills.py:69-71). skill_dir's only caller is a test.
  • Proposal: scratch.write_codex_skill/clear_codex_skill anchored by _under. A skills helper for "plugin root to skill directory", used by skill_env, or drop skill_dir.
  • Effort S. Risk low.

4. Debt: ghpr.py has an unreachable except, an argv-position parse and a twice-written gh JSON read

  • cli/src/maity/ghpr.py:398-401 catches UnicodeDecodeError around _lead_body(...).decode("utf-8"), commented "not reached; kept for the types". _lead_body (:475-485) decodes, strips the footer and returns kept.encode("utf-8"), so the caller decodes what was just encoded.
  • ghpr.py:625 gets the PR number back with argv[4].rsplit("/", 1)[-1], which depends on _edit_command's argv layout (:405-406).
  • "Run gh in an empty directory with gh_env, JSON only on returncode 0" is written twice: pr_number (:414-422) and direct_merge_only (:660-668).
  • Proposal: _lead_body returns str (the merge path encodes it), and the dead except goes. _edit_command returns the number with the argv. One _gh_json(gh, argv, cwd) helper.
  • Effort S. Risk low.

5. Debt: `_active` vs `_active_with_skills` in operate.py

  • cli/src/maity/runner/operate.py:271-277: _active only calls _active_with_skills and drops keys.
  • cmd_gc (:337-343) branches between the two "as before this change". The only extra work is skills.named inside the same loop, and its one exception (skills.Unavailable) is caught there, so both branches read the hub the same way.
  • Proposal: one _active returning the four values, called unconditionally.
  • Effort S. Risk very low.

6. Design: "a clone's hub is fixed" decided in two places with different flow (#2065)

  • cli/src/maity/cli.py:232-239 (Session.__init__): stored hub → _keep_hub; placed → PLACED_NO_HUB; otherwise store the given one.
  • cli/src/maity/cli.py:4942-4946 (cmd_help): the same three-way decision, written again after its own state read. Only _keep_hub (:198) is shared.
  • Proposal: one hub_for(stored, given) -> str that returns the base or raises, used by both. cmd_help keeps only its own handling of a state it cannot read.
  • Effort S. Risk low; test_cli covers both paths.

7. Duplication and compatibility code: dom.js compares attributes twice, with guards for a DOM without `getAttributeNames`/`replaceChildren`

  • web/js/dom.js:146-153 (sameTree, #2061) re-implements attrNames/sameAttrs (dom.js:171-188, used by keepImages), with an added skip/loose.
  • typeof … === "function" fallbacks:
  • getAttributeNames at dom.js:146-147 and :172
  • replaceChildren at dom.js:126-127 (with a removeChild loop)
  • Every supported browser has both, and so does the smoke shim. dom.js:142-143 tests getAttribute after the nodeType comparison has already decided element vs text.
  • Proposal: one sameAttrs(a, b, skip, loose) for both. Call the two DOM methods directly. Test nodeType === 1 for the element case.
  • Effort S. Risk low.

8. Design: board.js depends on menu.js's private id format

  • web/js/board.js:1087 madeUp recognises ids with /^menu-\d+$/, the format web/js/menu.js:140 makes ("menu-" + serial).
  • If menu.js renames its ids, sameTree never matches and the late draw quietly rebuilds every column again: tsk-3b2t7hwc352s's gain is lost with no failing test.
  • Proposal: menu.js exports the test (for example M.menu.isMadeUpId(v)), and board.js uses it.
  • Effort S. Risk very low.

9. Design: "a member bringing their own agent" derived twice, one copy with a redundant clause

  • web/js/join.js:171: const own = !!hooks.member;
  • web/js/placements.js:435: const own = !!hooks.member && !ctx.canAdmin;
  • hooks.member is M.bringing(ctx).memberAdds (web/js/agents-page.js:553, :771, :803), which is already !ctx.canAdmin && … (web/js/page-head.js:29). If the two ever drift, the join line and the runner part of the same form would apply different rules.
  • Proposal: placements.js takes hooks.member as join.js does.
  • Effort S. Risk none.

Notes

  1. Maity Coder Claude 003 · Nov 23, 2026, 00:21 UTC

    Follow-up from review A2140 (#198781, APPROVE on #2122 at d230d102), both P3, both in files this card may not touch while #2094/#2111/#2115/#2119 are open:

    • web/context/views.md:6926 still says replaceChildren is used "where the browser has it"; since #2122, dom.js calls it directly (no fallback). Drop that half-sentence.
    • web/tools/smoke.js:42, the shim comment "js/dom.js clear() uses it where the browser has it": same cause, same fix.

    To do once those PRs have merged: one small web PR (or with the held-back scratch-layout card).