Skip to content

refactor(disk-hygiene): simplify hygiene.py range 2 of 4 - #15277

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14755-42968756770-1
Nov 11, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14755-42968756770-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14755

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified the functions that start in range 2 of 4 of plugins/disk-hygiene/skills/clean/scripts/hygiene.py (6558 lines when this part started, so lines 1640-3279: entry_logical_file_bytes through validate_plan) without changing behavior. Repeated branches now collapse into one: scan_tree's three truncation branches share one cut-reason path, and validate_plan's four text-field checks run as one loop. Duplicate work is gone, so scan_tree computes error_paths once. Six helpers are shorter: inventory_parent_paths, windows_storage_sense_state, volume_root_os_owned_names, root_children_skipped_reason_counts, normalize_root_child_selection and the small platform-key helpers. Function names, signatures, outputs, error messages and ordering are unchanged. The design choice: a refactor stays inside a function, and nothing moves between functions or files, which the issue leaves to the later restructuring pass.

Not verified

  • The disk-hygiene Python test suite and ruff format --check were not run, because this lane can run no interpreter or linter. Left to the PR's CI.
  • ci-status green is a PR CI check, left to the PR's CI.
  • tidy ran every pass, but pass 5's deterministic detector (ai-slop detect.sh) is not on the lane's Bash allowlist. The 7-line changelog fragment was read against the rubric only and had no findings.
  • Tidy proposal not applied: inventory_parent_paths still guards with isinstance(path, str) on an Iterable[str]. Dropping it would change which inputs it accepts.
  • Proposed, not applied: root_child_skip_reason's 'path.absolute() == root.absolute() or is_within(...)'. is_within may already cover equality, but proving that on Windows drive roots and UNC paths was not worth the risk in a behavior-preserving pass.
  • The working tree holds untracked dotfiles this run did not create (.bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc). They look like runner environment files and are not part of this change.
  • The lane system prompt says to leave changes uncommitted, so nothing was committed. ci-mode step 3 asks for a commit, but the runner turns the working tree into the patch.

Fix

  • plugins/disk-hygiene/skills/clean/scripts/hygiene.py: range-2 functions simplified (80 added, 152 removed lines). entry_reclaimable_local_bytes merges its guards. accumulate_child_rollup uses +=. inventory_parent_paths uses an rpartition loop. windows_storage_sense_state reads its three registry…
  • .changes/disk-hygiene/work-resolve-issue-issue-14755-42968756770-1-8e4a0217.md: new patch fragment, '### Changed' / 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 9be5b1c:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 8 fragments valid (run before and after tidy)
  • check-changed-skills: plugins/disk-hygiene/skills/clean PASS, 0 errors, 3 warnings, all of them about SKILL.md size, which this change does not touch
  • check-affected: 13 passed, 6 skipped (tools absent or code that runs from the checked tree), the rest CI-only
  • fresh-context review subagent: diffed every hunk against HEAD and found no behavior difference. It traced the edge cases for inventory_parent_paths ('/a', 'a//b', '', '/'), windows_storage_sense_state exception propagation, the scan_tree cut/walked cases and the error_paths hoist. It confirmed…
  • Counted the range: hygiene.py had 6558 lines at the start, so range 2 is lines 1640-3279. Every edited function starts in that range (entry_logical_file_bytes at 1707 through validate_plan at 3220).
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42968756770

Left out: the items under Not verified.

Related

#14755

Merge-Risk: max=MEDIUM demote=false head=9be5b1cc1657cba2e2e3e275d747b9e502388905 rubric=8.4.1 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 9be5b1cc1657cba2e2e3e275d747b9e502388905: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #15277, refactor(disk-hygiene): simplify hygiene.py range 2 of 4

No findings. I read every hunk of both changed files and compared each one to the head file. I found no change in behavior.

What I checked, hunk by hunk. I ran nothing: this lane has no interpreter, so the equivalence below comes from reading the code.

  • entry_reclaimable_local_bytes, accumulate_child_rollup, volume_root_os_owned_file_name_matches, the platform-key helpers: the guards are merged and += replaces the long form. The logic is the same.

  • inventory_parent_paths: I traced the edge inputs "a", "/a", "/a/b", "a//b", "a/b/c" and "". Each produces the same parent set as the old rsplit loop, because rpartition("/")[0] returns "" exactly where the old code broke out or skipped.

  • windows_storage_sense_state: it reads the same three registry values in the same order, and each read still catches only OSError. An int() ValueError or TypeError still propagates as it did before.

  • volume_root_os_owned_names: the split strings give the same 13 macOS names and the same 20 Linux names as the old literal tuples. Iterable is already imported.

  • root_children_skipped_reason_counts: Counter is already imported at hygiene.py:25. The walrus sits in the generator's filter, which is legal, and the result is sorted and converted to a dict the same way.

  • normalize_root_child_selection: by_name is keyed by name when matching is case-sensitive and by name.casefold() otherwise (hygiene.py:2568-2571). So the old seen_key (canonical or canonical.casefold()) always equals key, and deduplication is unchanged.

  • scan_tree, the cut-reason path: I checked all five directory cases:

    • VCS boundary: cut.
    • Protected: cut.
    • Depth cut with a child: cut.
    • Depth cut on an empty directory: subtotal 0, walked.
    • Walked: subtotal from visit, with scan-error when it returns None.

    Each case gives the same subtotal, walked, truncated order and unwalked_reasons as before, since walked=subtotal is not None matches every old assignment.

  • scan_tree, moving error_paths earlier: nothing between the new and the old position writes to errors. annotate_tracked gets repo_errors, a separate list from discover_enclosing_git (hygiene.py:2631). apply_rules still reads set(truncated) when it is called.

  • validate_plan: required moved out of the loop, which is safe because it is a constant. The four text-field checks run in the old order and give the same error messages. The genexpr's value stays inside the genexpr's own scope.

Closing issue #14755, acceptance criteria:

  • Behavior unchanged: met on reading. test_hygiene.py exercises the refactored helpers (6 references to them).
  • Edits only the listed file plus a fragment: met.
  • Within 400 changed lines: met (80 added, 152 removed).
  • Fragment is bump: patch with ### Changed / "Internal simplification, no behavior change.": met.
  • Only functions that start in range 2 of 4 (lines 1640-3279): met. The edited functions run from entry_reclaimable_local_bytes to validate_plan, which starts at line 3220 in the base file.
  • ci-status green: left to CI. Per the PR body, the Python tests and ruff format --check were not run. That claim comes from the author and I did not check it.

No plugin manifest changed. No rule or path conditions apply to this change. I found no embedded instructions in the PR context.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 9be5b1cc1657cba2e2e3e275d747b9e502388905: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

No security issues found.

This change reorganises code inside existing functions of plugins/disk-hygiene/skills/clean/scripts/hygiene.py and adds a patch changelog note. Neither file is on the trusted-path list. It touches no workflow, token, trust check, merge hold, plugin manifest or instruction file.

This script decides which paths may be deleted, so I checked that every safety guard behaves as it did on the base:

  • OS-owned root names (volume_root_os_owned_names): the macOS list (13 names) and the Linux list (20 names) match the old lists exactly. The Windows list is built from the same sets. Every name is still case-folded.
  • Linux root file matching (volume_root_os_owned_file_name_matches): it applies the same name test OR glob test as before.
  • Directories the scan does not descend into (scan_tree): version-control directories (vcs-boundary), protected directories (protected) and non-empty depth-cut directories still get subtotal=None and walked=False, are still added to truncated and still record their reason in unwalked_reasons. An empty directory at the depth cut still counts as walked with size 0. A failed scan of a subdirectory still records scan-error and stays not walked. Nothing that can raise now runs before a cut directory is added to truncated.
  • Error paths (error_paths): this is now computed once, before annotate_tracked and apply_rules. Nothing in between writes to errors, so apply_rules gets the same exclusion set as before.
  • Root-child selection (normalize_root_child_selection): the duplicate key is the same in both case modes, because key equals the admitted name, or its case-folded form, that by_name maps from. The checks that reject path-like or unadmitted names are untouched.
  • Plan validation (validate_plan): the four required text fields are checked in the same order and raise the same messages. The required-key check is unchanged.
  • Other helpers (inventory_parent_paths, windows_storage_sense_state, root_children_skipped_reason_counts): they give the same results. Counter is already imported at line 25.

The PR context contained no instructions aimed at the review. Prior findings were empty, so this was a full review, not a blocking-only one.

critical-findings: 0

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 9be5b1cc1657cba2e2e3e275d747b9e502388905, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 9be5b1c

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15277-9be5b1cc1657cba2e2e3e275d747b9e502388905, expires on 2026-12-11.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit c2346df Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14755-42968756770-1 branch November 11, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify the disk-hygiene engine script (part 2 of 4)

0 participants