Skip to content

refactor(code-tidying): simplify comment-tooling scripts (1 of 2) - #15126

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14430

Summary

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

Applied behavior-preserving simplifications to four of the seven listed scripts. change-shape.py gains a code_changed(**detail) helper that replaces nine hand-built CODE-CHANGED tuples (keyword order keeps the detail key order, so text output is identical), and its leaves() loop is flattened. comment-census.py drops a redundant condition, a redundant early return and a redundant generator filter, and builds by_language rows with a comprehension. commented-out-code.py rewrites directive_free_runs with itertools.groupby. added-lines.sh replaces its per-field control-character loop with one match on the space-joined records. changed-code-files.sh, comment-tooling-probe.sh and ps-tokens.ps1 are already minimal, so I left them unchanged: every candidate edit there either changed behavior (e.g. folding the double git status in changed-code-files.sh would lose the exit-1 probe, because NUL cannot live in a shell variable) or only moved lines around.

Not verified

  • Python unit tests (test_change_shape.py, test_comment_census.py, test_commented_out_code.py) and added-lines.test.sh were not executed: this lane runs no interpreter or test runner. Left to the PR's CI.
  • ruff lint/format not run locally (no interpreter or ruff wrapper in this lane); edited lines kept under 88 columns in ruff-format style. Left to the PR's CI.
  • tidy-diff passes 4 and 5 (docs-hygiene and ai-slop) skipped on purpose for the changelog fragment: its only body line is wording the issue requires verbatim.
  • changed-code-files.sh, comment-tooling-probe.sh and ps-tokens.ps1 left unchanged: no simplification was found that kept behavior identical and made them clearer.
  • Untracked dotfiles at the checkout root (.bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc) were not created by this run, are not part of the change and were left untouched.
  • ci-status green is checked on the PR by CI.

Fix

  • plugins/code-tidying/scripts/added-lines.sh: control-character check over records is one regex match on "${records[*]-}" instead of a loop; same exit 2 and message.
  • plugins/code-tidying/scripts/change-shape.py: new code_changed(**detail) helper used at every CODE-CHANGED return; leaves() restructured into one descend-or-emit branch with the shebang test on the decoded node text.
  • plugins/code-tidying/scripts/comment-census.py: removed the implied use_pygments condition, the redundant empty-records early return and the redundant if "comment_bytes" in r filter; by_language rows built by a list comprehension.
  • plugins/code-tidying/scripts/commented-out-code.py: directive_free_runs uses itertools.groupby; the last temporary in findings_for is inlined.
  • .changes/code-tidying/work-resolve-issue-issue-14430-42838812817-1-563f8892.md: patch fragment, ### Changed with "Internal simplification, no behavior change."

Verification

The runner ran each check from the base copy against 06eaad7:

  • 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 5 changed files (run before and after tidy)
  • fresh-context review subagent over the whole diff: no findings; it confirmed detail key order at all call sites, groupby equivalence on empty/all-directive/edge inputs, ${records\[*\]-} under set -u on old bash, and that rank-comment-targets.py and the three test files reach nothing that changed
  • code-tidying:tidy-diff over the 19 changed hunks: passes 1-3 ran with no further edits; the one comment in the listed lines (added-lines.sh:53) states a constraint and was kept
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42838812817

Left out: the items under Not verified.

Related

#14430

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

Code review: no findings

I read every hunk of all 5 changed files. None of them falls under a trusted path. I checked each edit to see whether it keeps the script's behavior the same, which is the closing issue's first acceptance criterion.

  • added-lines.sh: The script now runs one control-character match over "${records[*]-}" in place of looping over each field. It never changes the global IFS (only IFS= read sets it, and only for that loop), so the join uses a space, and a space is not [[:cntrl:]]. A match therefore means some field holds a control character, as before. The - default keeps an empty array safe under set -u on older bash. The message and exit code 2 are unchanged.
  • change-shape.py leaves(): The script still never descends into comment nodes. A non-comment node with children is still descended. A comment is still emitted only when it is a shebang on row 0. The new test checks the decoded text with startswith("#!") where the old one compared the first two bytes to b"#!". Both look at the same start byte and #! is ASCII, so the results match. Non-comment leaves still need non-blank text.
  • change-shape.py code_changed(**detail): Python keeps keyword arguments in order, and every call site passes its keys in the old dict order, so the detail keys and the text output come out the same. The helper only adds a new module-level name; no existing name is renamed or removed.
  • comment-census.py: Each removal leaves behavior unchanged:
    • layer == "pygments" already makes use_pygments true (line 243), so that extra condition did nothing.
    • The early return on empty records gave back the same [] and sources that the final return does.
    • The if "comment_bytes" in r filter added nothing, because .get(..., 0) already returns 0 for a missing key.
    • The list comprehension in by_language builds the same rows in the same order.
  • commented-out-code.py: The groupby version of directive_free_runs gives the same runs as the old loop, including for empty input, all-directive input, and input with no directives. Inlining last changes nothing.

Closing issue #14430, acceptance criteria:

  • Behavior unchanged: met, based on the reading above. I could not run the existing tests (test_change_shape.py, test_comment_census.py, test_commented_out_code.py, added-lines.test.sh), so CI has to confirm this.
  • Diff edits only the listed files plus a fragment: met. All four scripts are on the issue's list, and the fifth file is the changelog fragment.
  • Size limit: met (about 170 changed lines across 5 files).
  • Fragment: met. The code-tidying fragment has bump: patch, a ### Changed heading, and the exact line the issue requires.
  • ci-status green: not checked here. The author says CI covers it; I did not verify that.

The test runs, ruff results and verification steps in the PR description are the author's claims; I did not confirm them. The PR context contains no embedded instructions, and there are no prior findings from this lane on this PR.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 06eaad7d3ab5f55d657efd5d2ec0616ccb74d5f2: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15126 (refactor(code-tidying): simplify comment-tooling scripts)

No security issues found. I read every hunk of all 5 changed files. None of them matches a trusted path, and the diff touches no trust control, plugin manifest or standing instruction.

critical-findings: 0

What I checked:

  • plugins/code-tidying/scripts/added-lines.sh: the old check looped over each record looking for a control character. The new check is one regex match on "${records[*]-}". The script never changes IFS globally: the only IFS= sits on the read builtin at L45 and applies only to that command. Bash also does not take IFS from the environment, so the join separator is always a space. A space is not in [[:cntrl:]], so the joined string contains a control character exactly when some field does. This is the same fail-closed guard as before (exit 2, no rows printed). It still runs before any path reaches hunks() or printf. The - default keeps an empty array safe under set -u on older bash. The hunk-header digit check that keeps crafted fields out of (( )) arithmetic (L75) is unchanged.
  • change-shape.py, comment-census.py, commented-out-code.py: these are pure refactors: a code_changed(**detail) helper, a flatter leaves() loop, an itertools.groupby rewrite, and redundant conditions removed. They add no new input sources, subprocess calls, path handling or deserialization. Shebang detection now checks the decoded text instead of the raw bytes. The result is the same, because # and ! are ASCII and errors="replace" swaps bad bytes for U+FFFD, never for ASCII. Whether behavior is otherwise fully preserved is a correctness question for the code-review lane.
  • .changes/code-tidying/...md: a changelog fragment only.

PR context: the description has no embedded instructions to the lane. The closing issue's body was left out by the wrapper because its author is not on the allowed list.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 06eaad7

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-15126-06eaad7d3ab5f55d657efd5d2ec0616ccb74d5f2, 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 f0af7d2 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14430-42838812817-1 branch November 10, 2026 16:30
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit f0af7d29a50d7c331c051f28668cba961cea4ab8; 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 (1 of 2)

0 participants