Skip to content

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

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14757

Summary

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

Simplified the functions that start in range 4 of 4 of plugins/disk-hygiene/skills/clean/scripts/hygiene.py (6464 lines when this part started, so lines 4849-6464: opaque_contents_blocker through main), with no behavior change. Three small helpers next to anchored_remove now build the skip records that apply_plan, handoff_apply, recycle_handoff_path and unlink_handoff_path each built by hand: protected_skip (the 13 hand-built 'protected' records, with protection_matches spread in only when a consumer glob matched), handle_state_skip (the handle-state check repeated in apply_plan and unlink_handoff_path) and removal_failure_skip (the three except branches after each anchored_remove call, now one except clause whose isinstance checks keep the old HygieneError, PermissionError, OSError order). In main, the scan target check drops a redundant Path.exists() (is_dir() is False for a missing path), the OS-managed volume-root check drops a root_children_mode term the line above already guarantees, and the admitted-kind tally uses the already-imported Counter. unlink_handoff_path also reuses its own consumer_protected closure and returns its early skips directly. Every record keeps its keys, key order and values, and every mocked call (handle_state, consumer_protection_matches, linux_mount_points) runs the same number of times in the same order. The file is 51 lines shorter (76 added, 127 removed).

Not verified

  • The disk-hygiene Python test suite (test_hygiene.py and siblings) and ruff were not run: this lane allows no interpreter, so they are left to the PR's CI
  • tidy: ran every pass (simplify, comments, residue, write-for-humans, ai-slop) with no further edits. ai-slop's deterministic detect.sh layer could not run because the lane allows only the named wrappers; its rubric layer found no tells in the one-line fragment
  • cant-fail-scan was not run: it scans test files, and this change edits none
  • Left as is (out of scope or not worth the diff): the duplicate vcs_evidence loading in main's handoff-verify and handoff-apply branches, the two identical scan_tree HygieneError emits in main, and target_fd in apply_plan still being closed by hand rather than in try/finally (changing that would…

Fix

  • plugins/disk-hygiene/skills/clean/scripts/hygiene.py: added protected_skip, handle_state_skip and removal_failure_skip and used them in apply_plan, handoff_apply, recycle_handoff_path and unlink_handoff_path; unlink_handoff_path reuses consumer_protected and returns early skips directly; main drops…
  • .changes/disk-hygiene/work-resolve-issue-issue-14757-42991524457-1-d29a9655.md: patch fragment from new-changelog-fragment, body '### Changed' and 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 65acded:

  • 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: CHECK-SKILL clean PASS, 0 errors, 3 pre-existing size warnings on SKILL.md (which this change does not touch)
  • check-affected: 13 passed, 6 skipped over 2 changed files (run before and after tidy)
  • fresh-context review subagent over the whole diff: no findings. It confirmed record key order, that except (HygieneError, OSError) plus the isinstance order maps to the same outcomes as the old three clauses (HygieneError subclasses only Exception), unchanged mock call counts and order, that the…
  • grep of the disk-hygiene tests: no test patches Path.exists or Path.is_dir; tests patch hygiene.handle_state at module level, which the new helper still looks up at call time
  • the function list confirms every changed function starts at or after line 4849 (opaque_contents_blocker at 4880 is the first one in range 4)
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42991524457

Left out: the items under Not verified.

Related

#14757

Merge-Risk: max=MEDIUM demote=false head=65acdedd0bc3e87aca60b83044a4c975afb7484f rubric=8.4.2 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-security-review reviewed 65acdedd0bc3e87aca60b83044a4c975afb7484f: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15314 (refactor(disk-hygiene): simplify hygiene.py range 4 of 4)

No security issues found. I read every hunk of both changed files. Neither file is on a trusted path, and the diff changes no trust control, plugin manifest or standing instruction.

The deletion paths in hygiene.py (apply_plan, handoff_apply, recycle_handoff_path, unlink_handoff_path) are where a mistake could matter for security. A protection check that got weaker would let the tool delete a protected path. I checked every behavior-relevant edit against the head file:

  • removal_failure_skip: the single except (HygieneError, OSError) clause assigns the same outcomes as the three old clauses did. HygieneError subclasses Exception, not OSError (hygiene.py#L173). The isinstance checks run in the old order: HygieneError, then PermissionError, then OSError. A failure is still recorded as a skip and is never treated as a removal.
  • handle_state_skip: any handle state other than clear still produces a skip, and an unknown state still maps to handle-state-unverified. Locked or unverified paths are still refused.
  • protected_skip: each record keeps its keys and values. protection_matches is added only when the old code added it.
  • unlink_handoff_path: the inline consumer_protection_matches(path, target, globs) is replaced by the closure consumer_protected(path). That closure wraps the same call with the same target and globs in bool(...) (hygiene.py#L5794-L5795), so the result is unchanged. The early returns for mount errors and candidate blockers still return before any removal.
  • main scan target check: dropping exists() loosens nothing, because is_dir() is already False for a missing path. The has_linkish_component check stays.
  • main OS-managed check: removing root_children_mode from the condition loosens nothing. The line before it already raises when os_managed and not root_children_mode, so the rejection set is the same.
  • Counter tally: Counter is already imported (line 25), and its output passes through dict(sorted(...)) as before.

The changelog fragment in .changes/disk-hygiene/ is a patch-bump note with no executable content.

The PR context file contains no embedded instructions aimed at the review.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of both changed files: plugins/disk-hygiene/skills/clean/scripts/hygiene.py and the changelog fragment. I compared each changed line with the code it calls at head. I did not run any tests or linters; the PR body says the author did not run them either.

Behavior checks (all equivalent to base):

  • protected_skip: an empty matches makes protection_matches_field(()) return {} (hygiene.py#L559-L569). Records without a consumer match keep the keys path, outcome, detail, in that order. Records that had protection_matches before still get it.
  • removal_failure_skip: HygieneError subclasses Exception, not OSError (L173). So except (HygieneError, OSError) with the isinstance order HygieneError → PermissionError → other gives the same outcome for each exception as the three old clauses.
  • handle_state_skip: it looks up handle_state at module level when called, so module-level patches in tests still reach it. The outcome mapping and detail or "" are unchanged.
  • unlink_handoff_path: the consumer_protected closure (L5794-L5795) is exactly bool(consumer_protection_matches(path, target, globs)). The early returns give the same two-list shape. removed and skipped are only used after their new place, below the early returns.
  • main:
    • Path.is_dir() returns False for a missing path, so dropping exists() keeps the same check.
    • The root_children_mode term was redundant: the line before it already raises when os_managed and not root_children_mode.
    • The Counter tally is read only through dict(sorted(kinds.items())) (L6042), so the output is identical.

Closing issue #14757 acceptance criteria:

  • Behavior unchanged: met on reading. The skip-outcome strings appear in test_hygiene.py, so a regression there could fail a test.
  • Diff edits only the listed file plus a fragment: met.
  • Within 400 changed lines: met (about 200 lines).
  • Fragment is bump: patch with ### Changed / "Internal simplification, no behavior change.": met.
  • Only functions starting in range 4 are changed: met. The new helpers sit after anchored_remove, past line 4849.
  • ci-status is green: CI decides this; I could not check it.

No plugin manifest changed. No .claude/rules rules or paved-path concerns apply. The PR context contains no embedded instructions. There are no prior findings, and this is not a blocking-only review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 65acded

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-15314-65acdedd0bc3e87aca60b83044a4c975afb7484f, 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 3af84a4 Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14757-42991524457-1 branch November 11, 2026 09:35
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 5, survived 2, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 71%; mutation score 71%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/disk-hygiene/skills/clean/scripts/hygiene.py 5 2 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/disk-hygiene/skills/clean/scripts/hygiene.py:4994 other productive input-gap
plugins/disk-hygiene/skills/clean/scripts/hygiene.py:5113 SBR productive input-gap

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 3af84a4132bb6573b40262351709c39e9a42c187; later checks count it verified from this comment.

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 4 of 4)

0 participants