Skip to content

refactor(code-tidying): simplify rank-comment-targets.py and scope-code-files.sh - #15174

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14431-42883550788-1
Nov 10, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14431

Summary

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

Simplified the two listed code-tidying scripts with no behavior change. In rank-comment-targets.py, the git() helper now takes stdin and serves generated_paths and fan_in in place of their hand-rolled subprocess.run calls. The 30-line git grep argument list became one FAN_IN_GREP constant. Counting uses Counter. The census comment-token loader is cached with lru_cache instead of a module global. main's per-row loop reads its byte-identical group once. In scope-code-files.sh, resolve_base uses plain if-blocks and a bare return in place of the && { printf; return 0; } blocks. A code-tidying patch changelog fragment carries the required '### Changed' line.

Not verified

  • test_rank_comment_targets.py and scope-code-files.test.sh were not executed in this run: the lane allows only its named wrappers, so no interpreter could run them. check-affected reported 14 passed without naming which checks those were. The suites are left to the PR's CI
  • ai-slop detect.sh was not run on the changelog fragment because the lane allows only its named wrappers; the fragment was read against the rubric by hand (no findings), and no findings file was written
  • tidy proposal, not applied: fan_in's except OSError: own = 0 quietly falls back when a file cannot be read; this is the existing behavior, and changing it would change outputs
  • Behavior note: resolve_base's --base failure path now returns git rev-parse's own non-zero status (1, or 128 on a fatal error) instead of exactly 1. Its only caller, base=$(resolve_base) || base="", treats any non-zero status the same, so the script's output and exit code are unchanged
  • Untracked runner-environment dotfiles (.bashrc, .bash_profile, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc) were left out of the tidy measurement; they are not part of this change
  • ci-status green on the PR is left to the PR's CI

Fix

  • plugins/code-tidying/scripts/rank-comment-targets.py: git() takes an input= argument (and drops the cwd= argument no caller passed); generated_paths and fan_in call git() instead of subprocess.run; the grep argument list became the FAN_IN_GREP constant (same arguments, same order); Counter replaces…
  • plugins/code-tidying/scripts/scope-code-files.sh: resolve_base rewritten with if-blocks and a bare return; the same refs are tried in the same order, the redirections are unchanged and the output is unchanged
  • .changes/code-tidying/work-resolve-issue-issue-14431-42883550788-1-d9b24a77.md: new patch fragment, '### Changed' / 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 306bb59:

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

The run reports:

  • check-changelog-fragments: all 10 fragments valid (run before and after tidy)
  • check-changed-skills: no changed skills, nothing to gate (run before and after tidy)
  • check-affected: 14 passed, 5 skipped, over 3 changed files (run before and after tidy)
  • fresh-context review subagent over the whole diff against the HEAD versions: no behavior change and nothing ruff's E4/E7/E9/F rules would flag. It checked git argument order and stdin, zip/slice against the old index loop, Counter against defaultdict, lru_cache against the lazy global when the load…
  • grep over plugins/: the only module attribute the tests use is rank_norm (unchanged); the skill-local wrappers exec the scripts with the same arguments; no caller passes git(cwd=...)
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42883550788

Left out: the items under Not verified.

Related

#14431

Merge-Risk: max=MEDIUM demote=false head=306bb590f8488f2cf7bfb9988cc1a1580ce7e7b9 rubric=8.3.5 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 306bb590f8488f2cf7bfb9988cc1a1580ce7e7b9: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15174 (head 306bb59)

I found no security issues.

I read every hunk of all 3 changed files. None of them matches a trusted-path glob.

  • plugins/code-tidying/scripts/rank-comment-targets.py: The generated_paths and fan_in functions now call the shared git() helper with input=, where they used their own subprocess.run calls. The calls still build an argv list with no shell. The git grep arguments in FAN_IN_GREP are the same flags and pathspecs in the same order, still after --. The file basenames still go in through stdin as fixed-string patterns (-F -f -), so they cannot become options or pathspecs. Dropping the unused cwd= parameter changes nothing about where commands run. Swapping in Counter and lru_cache and reading the copies group once only change how the code is written. No new input reaches a command, a path, or anything evaluated.
  • plugins/code-tidying/scripts/scope-code-files.sh: resolve_base is now plain if blocks. $BASE and each ref are still quoted arguments to git rev-parse --verify -q. On failure the function now returns git's own non-zero status rather than exactly 1. Its caller treats any non-zero status the same way, so it gains no reach.
  • .changes/code-tidying/...md: a changelog fragment only. It changes no instruction surface and no plugin manifest.

The diff deletes no standing instruction, touches no trust control and changes no manifest. Nothing in it can cause a charge.

The PR context contains no embedded directives aimed at this lane. This was a full review (blocking only: no), and there were no prior findings.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

No findings. I read every hunk of all 3 changed files and checked each rewrite against the base behavior. This was a full review, not blocking only (no earlier heads reviewed).

plugins/code-tidying/scripts/rank-comment-targets.py

  • git() drops cwd=".". Leaving cwd out means the current directory, which is what "." meant, and no caller passed it. The test file's git(repo, ...) is its own helper. str | None is safe because the module has from __future__ import annotations (line 52).
  • generated_paths: zip(fields[::3], fields[2::3]) gives the same (path, value) pairs as the old range(0, len(fields) - 2, 3) loop. The extra trailing empty field from the final \0 lands only in fields[::3], and zip cuts it off. Empty stdout gives an empty set either way.
  • fan_in: FAN_IN_GREP expands to the same arguments in the same order. Counter[name] returns 0 for a missing key, the same as counts.get(name, 0). When the file can't be read, own still falls back to 0.
  • @lru_cache on _census_is_comment_token: lru_cache does not cache a raised exception. A failed import is therefore retried on the next call, as it was with the None global, and a successful load is cached as before.
  • auth.update(authors.get(q, {})) adds the same per-author counts as the nested loop, and .get still avoids creating entries in the defaultdict. Reading by_hash[...] once into copies changes nothing.

plugins/code-tidying/scripts/scope-code-files.sh

  • The script runs with set -uo pipefail, without -e. With --base, a bare return now passes on git rev-parse's own non-zero status rather than exactly 1. The only caller, base=$(resolve_base) || base="" (L97), treats every non-zero status the same, so output and exit code are unchanged. The PR body notes this too. The if ref=$(...) and if git rev-parse ... blocks are equivalent to the old && { ...; } forms.

Closing issue #14431 acceptance criteria

  • Behavior unchanged: met, by the reading above. test_rank_comment_targets.py and scope-code-files.test.sh cover these scripts.
  • Only the listed files plus a changelog fragment are edited: met.
  • Within 400 lines and 15 files: met.
  • The code-tidying patch fragment has ### Changed and "Internal simplification, no behavior change.": met.
  • ci-status green: left to CI; this lane can't check it.

The PR body says the test suites were not run in the authoring lane. The author's verification claims are unverified, and I ran no tests myself.

No plugin manifest changes, no paved-path or path-scoped-rule hits, and no new spend.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 306bb59

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-15174-306bb590f8488f2cf7bfb9988cc1a1580ce7e7b9, expires on 2026-12-10.

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 10, 2026
Merged via the queue into main with commit ec55346 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14431-42883550788-1 branch November 10, 2026 22:00
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit ec553462484d3630692e4b145fbec497de8d1d60; 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 scripts code-tidying plugin code (2 of 2)

0 participants