Skip to content

refactor(disk-hygiene): simplify destructive_guard.py part 1 of 2 - #14546

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14450-42601472627-1
Nov 9, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14450

Summary

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

Simplified functions that start in lines 1-1831 of plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py (range 1 of 2 of the 3662-line file) without changing behavior. One helper, _cache_install_segments, now parses the <plugins>/cache/<marketplace>/<name> layout that _plugin_data_root_from_root, _plugin_id_from_root and _plugin_cache_family_root each parsed separately. One helper, _sanitized_plugin_id, builds the sanitized data-directory id that two functions built inline. _within_plugin_cache_family now calls the existing _same_or_within, and _display_python and _display_data_root call the existing _display_path. Smaller cleanups: a needless local alias, a per-call set union, a per-iteration f-string, a per-token set comprehension, an extension loop and a one-value candidates table were removed. Choice of means: I kept every function and module-level name, because test_hygiene.py and engine_context.py call several of these private helpers directly.

Not verified

  • The Python test suites (test_hygiene.py and the others) were not run here, because this lane runs no interpreter; they are left to the PR's CI
  • ci-status green is left to the PR's CI
  • tidy: all 21 destructive_guard.py rows were dropped because the file is wired as a hook command, which puts it on tidy's GLOBAL HARD exclusion list (hard_exclusions enforced), so the code passes 1-3 had no rows. Passes 4-5 ran on the changelog fragment and made no edit; ai-slop's detect.sh could…
  • cant-fail-scan was not run: it scans test files, and this change edits none

Fix

  • plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py: added _cache_install_segments and _sanitized_plugin_id, and used them in _plugin_data_root_from_root, _plugin_id_from_root, _plugin_cache_family_root and _directory_marketplace_install; _within_plugin_cache_family reuses…
  • .changes/disk-hygiene/work-resolve-issue-issue-14450-42601472627-1-142b56d6.md: new patch fragment from new-changelog-fragment, body '### Changed' with the line 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 79f6c79:

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

The run reports:

  • check-changelog-fragments: all 2 fragments valid (run before and after tidy)
  • check-changed-skills: CHECK-SKILL clean PASS, 0 errors, 3 warnings about the existing SKILL.md size, which this change does not touch (run before and after tidy)
  • check-affected: 13 passed, 6 skipped, over 2 changed files (run before and after tidy)
  • fresh-context review subagent over the whole diff: verdict EQUIVALENT. It found no behavior difference that any real input can trigger, and no test in test_hygiene.py, engine_context.py or setup/scripts that would break. It noted that _within_plugin_cache_family now normalizes its family argument a…
  • grep of plugins/disk-hygiene for each touched private name: every caller outside the file (engine_context.py, test_hygiene.py) still finds the same name and signature, and no test reads the guard's source text
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42601472627

Left out: the items under Not verified.

Related

#14450

Merge-Risk: max=HIGH demote=true head=79f6c798aa603b755a3b76d351fc9dea37f304e0 rubric=8.1.4 rater=claude-opus-5-5 checker=claude-opus-5-5

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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #14546 (refactor(disk-hygiene): simplify destructive_guard.py part 1 of 2)

I found no security issues. I read every hunk of both changed files. Neither file matches a trusted-path glob. There is no plugin manifest change, and no standing instruction is deleted, narrowed or softened.

destructive_guard.py is the disk-hygiene PreToolUse guard, so I checked each refactored function against its base behavior. This matters most where the function feeds an allow or deny decision:

  • _within_plugin_cache_family: the base normcased the resolved candidate and then ran commonpath, returning False on ValueError. It now calls _same_or_within (L450-L456). That helper normcases both sides, runs the same commonpath check and returns False on ValueError. normcase gives the same result when applied twice, so normcasing the family root again changes nothing. The strict-resolve OSError path still returns False. The guard behaves the same at all three call sites (L1250, L1335, L1355).
  • _cache_install_segments / _sanitized_plugin_id: the index-bounds and empty-segment checks match the base code exactly. _plugin_id_from_root still returns the unsanitized name@marketplace, and the data-root paths keep the same sanitization. Neither the authorized data root nor the plugin ID changes.
  • _is_authorized_data_root: bool(authority) and … still rejects an empty or missing authority and returns a bool.
  • _is_readonly_find: the base casefolded the set; the new code checks against _FIND_SIDE_EFFECT_PRIMARIES as it stands. Every entry in that set is lowercase (L1740-L1752), so the two are equivalent. Find calls with -delete, -exec and the rest are still not treated as read-only.
  • _readonly_supporting_basename: each of .exe/.com/.bat/.cmd is 4 characters, so name[:-4] cuts the same suffix the old loop did.
  • _powershell_without_string_data, _engine_gate_relevant, _argv_flag_value, _nt_known_git_installation_roots, _display_python, _display_data_root: these are equivalent restatements: a removed alias, a removed set union, a hoisted f-string, / "Git" in place of joinpath("Git"), and the existing _display_path.

The changelog fragment is prose only (bump: patch).

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Code review: PR #14546, simplify destructive_guard.py part 1 of 2

No findings. I read every hunk in both changed files: destructive_guard.py and the new changelog fragment. Each rewrite behaves the same as the code it replaces.

Equivalence checks

  • _cache_install_segments keeps the old index and bounds checks and the empty-segment check. _plugin_cache_family_root now also gets the empty-segment check, which changes nothing: Path.parts never yields an empty component after the cache index.
  • _sanitized_plugin_id uses the same _PLUGIN_ID_DISALLOWED.sub("-", f"{name}@{marketplace}") as the two places that built the id inline.
  • _within_plugin_cache_family → _same_or_within (L450): the helper runs the same normcase + commonpath comparison and also catches ValueError. family was already normcased, and normcasing it again leaves it unchanged. OSError from resolve(strict=True) is still caught where it was.
  • _display_python / _display_data_root → _display_path (L657): it applies the same os.fspath(...).replace("\\", "/"). Both functions are only called at runtime, so _display_path being defined further down the file does not matter.
  • _is_readonly_find: every entry in _FIND_SIDE_EFFECT_PRIMARIES (L1740) is already lowercase ASCII, so dropping the per-entry casefold is safe.
  • _readonly_supporting_basename: all four extensions are 4 characters long, so name[:-4] is correct.
  • The remaining edits behave the same: the _powershell_without_string_data membership test, the inlined _WRAPPERS alias, the prefix moved out of the loop in _argv_flag_value, _is_authorized_data_root (returns False when the authority is empty, otherwise the result of the comparison), and the _nt_known_git_installation_roots table replaced by direct Path(base) / "Git".

Closing issue #14450

  • Behavior unchanged: met, by my reading above. No names were renamed or removed, and the callers in engine_context.py and test_hygiene.py still find every private helper they use.
  • Only the listed file plus a fragment: met.
  • Size: met (well under 400 changed lines).
  • Fragment: met. It has bump: patch with ### Changed and "Internal simplification, no behavior change."
  • Range 1 of 2 only: met. The last function changed, _nt_known_git_installation_roots, starts at head line 1825, inside lines 1–1831.
  • ci-status green: left to CI; I did not check it.
  • Tests: the refactor criterion is guarded only by the existing test_hygiene.py suite. I did not run it (no interpreter in this lane). The PR author's verification steps are their own claims and I have not confirmed them.

No paved-path, manifest, or path-scoped-rule items apply. The PR context contains no embedded instructions.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 79f6c79

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-14546-79f6c798aa603b755a3b76d351fc9dea37f304e0, expires on 2026-12-09.

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 9, 2026
Merged via the queue into main with commit 55a2f6d Nov 9, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14450-42601472627-1 branch November 9, 2026 11:58
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, 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/destructive_guard.py 6 1 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py:321 LCR unclassified none

The run's summary has the full report.

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 destructive_guard.py disk-hygiene plugin code (part 1 of 2)

0 participants