Skip to content

refactor(disk-hygiene): simplify hygiene.py part 1 of 4 without behavior change - #15266

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14754

Summary

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

Simplified the functions that start in lines 1-1643 of hygiene.py (range 1 of 4 of its 6573 lines, measured at the start of this run, i.e. the top of the file through allocated_size_from_stat). The four data-root resolutions now share one private _data_root() helper with the same error message. A few loops became any() calls or flatter guards, the truncation-reason tally uses the already-imported Counter, apply_rules finds the last matching rule by scanning reversed(rules) and stopping at the first hit, and apply_in_flight_refs builds each path prefix once instead of twice. No output, exit code, error text, flag or public name changed, and no listed file was renamed or moved.

Not verified

  • The disk-hygiene Python test suite (test_hygiene.py) was not run: this lane cannot run python or a test runner. Left to the PR's CI.
  • ci-status green is a PR CI check, left to the PR's CI.
  • Python lint (ruff or similar) was not run on hygiene.py: this lane runs only the named wrappers, and check-affected ran no Python linter for this change. Left to the PR's CI.
  • tidy: tidy-diff passes 1-4 ran and found nothing to change. In pass 5 the ai-slop detector script (detect.sh) was skipped because this lane runs only the named wrappers; the rubric read of the fragment found no tells.
  • Per the lane's system prompt, changes are left uncommitted in the working tree for the runner to turn into a patch, rather than committed as ci-mode step 3 describes.

Fix

  • plugins/disk-hygiene/skills/clean/scripts/hygiene.py: new private _data_root() helper used by state_output_path, state_input_path, model_output_path and close_clean_runs (same HygieneError text, same resolve calls); scan_stdout_payload tallies with Counter; _validate_protection_glob_entry returns…
  • .changes/disk-hygiene/work-resolve-issue-issue-14754-42959419613-1-49a4485c.md: patch fragment created with new-changelog-fragment, body '### Changed' and 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against e82467b:

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

The run reports:

  • check-changelog-fragments: all 21 fragments valid (run before tidy, after tidy and after the review fix)
  • check-changed-skills: CHECK-SKILL clean PASS, 0 errors, 3 warnings about the existing SKILL.md size and description length, which this change does not touch
  • check-affected: 13 passed, 6 skipped (typos not installed; checks that run code from the checked tree), the rest are CI-only
  • fresh-context review subagent over the whole diff: no behavior change for any input the program builds. Its one confirmed divergence is apply_rules with a malformed rule (missing hint_ids) passed in directly, which the only production caller cannot produce because load_policy/validate_rules always…
  • range check: hygiene.py has 6573 lines, so range 1 of 4 is lines 1-1643; every edited function (scan_stdout_payload, state_output_path, state_input_path, model_output_path, close_clean_runs, _validate_protection_glob_entry, mount_state, os_drive_markers, hard_protection, apply_rules,…
  • test_hygiene.py read: VersionFloorTests parses the MIN_PYTHON line, which is unchanged; tests patch hygiene.DATA_ROOT_OVERRIDE, which _data_root() reads at call time
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42959419613

Left out: the items under Not verified.

Related

#14754

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

Security review: PR #15266, a refactor of hygiene.py (part 1 of 4)

No security issues found. I read every hunk of both changed files. Neither file is on a trusted path or is a trust control, and neither is a plugin manifest.

hygiene.py decides where the cleaner may write its state and what it must never delete, so I checked each rewrite to confirm it still blocks what the base version blocked:

  • New _data_root() helper: it still raises when DATA_ROOT_OVERRIDE is unset and still never reads CLAUDE_PLUGIN_DATA. The callers keep their checks:
    • state_output_path still refuses paths under PLUGIN_ROOT.
    • state_input_path still requires the path to sit inside the data root.
    • model_output_path still runs refuse_engine_owned. Its old DATA_ROOT_OVERRIDE or "" fallback could never be reached, because state_output_path had already raised.
    • close_clean_runs still returns early when the data root or session id is missing, before it calls the helper.
  • _validate_protection_glob_entry: the early return for non-dict entries comes after the protection_glob_pattern check (hygiene.py:620-625). It skips only the two checks that applied to dict entries anyway, so no protection glob gets through that the base rejected.
  • hard_protection: the any(...) form adds os-managed-root under exactly the conditions the old loop did.
  • os_drive_markers: _windows_env_roots() builds a new list on every call (hygiene.py:781). Extending that list in place changes no shared state.
  • mount_state: the error check now runs only when linux_mount_points() was called, which is the only place an error could come from. Same result as before.
  • apply_rules: scanning reversed(rules) and stopping at the first hit picks the same last matching rule and the same hint id as the old loop. The only caller passes a list (hygiene.py:2857-2859). Pre-selection still requires empty protected_reasons, and the min_age_days check is unchanged.
  • apply_in_flight_refs and the Counter tally: both compute the same values as before. Counter was already imported (hygiene.py:25).

The changelog fragment is a plain bump: patch note with no executable content. The PR description and its context contain no embedded instructions.

This review was not blocking-only, since the lane had reviewed 0 earlier heads.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk in both changed files. For each edit I compared what the head code does with what the base code did.

  • scan_stdout_payload: Counter is already imported (hygiene.py:25). dict(sorted(Counter(...).items())) gives the same result as the hand-built tally.
  • _data_root() helper: it raises the same HygieneError text and resolves the path the same way as the four inline copies it replaces.
    • model_output_path used to rebuild the root from DATA_ROOT_OVERRIDE or "". That branch could never run with an empty value, because state_output_path had already raised, so the output is the same.
    • close_clean_runs still checks DATA_ROOT_OVERRIDE before it calls the helper, so it cannot raise there.
    • The tests patch hygiene.DATA_ROOT_OVERRIDE. The helper reads the global each time it is called, so those patches still take effect.
  • _validate_protection_glob_entry: returning early for a non-dict entry gives the same result as the old repeated isinstance checks.
  • mount_state: moving if error: inside the points is None branch is equivalent, because error could only be non-None on that path.
  • os_drive_markers: _windows_env_roots() builds a new list on each call (hygiene.py:781) and is not cached, so extending the list it returns mutates no shared state.
  • hard_protection: the any(...) call is the same as the loop with break.
  • apply_rules: scanning reversed(rules) and stopping at the first hit still lets the last matching rule win, as the docstring says.
    • rules is a list from policy.get("rules", []) (hygiene.py:2859), so reversed works on it.
    • The only difference is when a rule has no hint_ids key. The PR author says validate_rules prevents that. I did not check validate_rules myself, so this rests on the author's word.
  • apply_in_flight_refs: the prefix generator is created once per entry and evaluated lazily. The result is the same.

Closing issue #14754 acceptance criteria

  • Behaviour unchanged: met, based on the per-hunk comparison above.
  • Only the listed file plus a changelog fragment edited: met.
  • At most 400 changed lines and 15 hand-edited files: met, at about 50 lines in 1 file.
  • Fragment has a patch bump and the body ### Changed / "Internal simplification, no behavior change.": met.
  • Only functions starting in range 1 of 4 (lines 1–1643) changed: met. Every edited function starts in that range at base.
  • ci-status green: CI has to confirm this; I could not check it from here. The PR's claims that the tests and ruff passed are author-claimed and unverified; I ran neither.

Path-scoped rules: .claude/rules/ruff-pin.md, skill-bodies-state-current-rules.md and cost-claims.md have globs that match hygiene.py. These are code-only edits with no prose or cost claims, so none of those rules is broken.

No plugin manifest changed. No embedded instructions were found in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for e82467b

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-15266-e82467b84adbb8e68bfb1de26499c61bdb013601, 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 03dfa08 Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14754-42959419613-1 branch November 11, 2026 05:35
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

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

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

Surviving mutants

Location Operator Disposition Cause
plugins/disk-hygiene/skills/clean/scripts/hygiene.py:628 LCR 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 03dfa08e73cad8921bca494fa18cac8141525260; 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 1 of 4)

0 participants