Skip to content

refactor(lib): simplify html-escape, mermaid-gate and index-regen loops - #14625

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14334

Summary

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

Reviewed the 11 listed lib sources for reuse, simplification, efficiency and abstraction level, and simplified the three where a change was clearly behavior-preserving. html-escape.mjs replaces three manual RegExp exec loops with matchAll, mermaid-gate.mjs folds the mmdc probe loop into one for...of, splits mmdc output once and replaces a forEach with for...of, and index-regen.sh uses C-style for loops and builds the regenerated and current file text with printf -v instead of per-line append loops. The other eight files (html2md.py, install-python-deps.sh, installed.mjs, lane-push.sh, managed-scope.sh, node-or-skip.ps1, node-or-skip.sh, parse-concern-value.sh) were left as they are: they are already compact or security-critical, and the small gains available (a shared heading regex in html2md.py, a two-line trim in managed-scope.sh) would have added 14 to 19 more plugin copies and changelog fragments each for little clarity. Shared copies were regenerated with scripts/sync-shared-copies.sh, and each plugin carrying a changed copy got a patch fragment.

Not verified

  • Test suites (lib/index-regen.test.sh, lib/mermaid-gate.test.sh, lib/mermaid-gate.test.mjs, lib/view-builder.test.sh and the per-plugin build-*.test.sh that use html-escape) were not executed here: this lane's Bash runs only the named wrappers. Left to the PR's CI.
  • printf -v with a reused '%s\n' format was not run on macOS /bin/bash 3.2. The review found no 3.2-specific difference, and a web search turned up only printf -v bugs that need %b or an array-element target (neither used here), but no run confirmed it. Left to the PR's CI and any macOS runner.
  • Tidy not run: the change touches lib/, a listed shared path, and spans 29 files, over the 10-file cutoff.
  • ci-status green is a PR check, left to the PR's CI.
  • Changes are left uncommitted in the working tree as the lane's runner instructions require; the runner turns them into the patch.

Fix

  • lib/html-escape.mjs: parseAttributes and scanStructure's tag and style scans use String.prototype.matchAll instead of manual exec loops; closing tags skip the attribute check with an early continue.
  • lib/mermaid-gate.mjs: resolveMmdc probes candidates in one for...of loop; render splits mmdc output once; gate iterates blocks with for...of instead of forEach.
  • lib/index-regen.sh: frontmatter and marker scans use C-style for loops (no manual increments); the regenerated and current file text are built with printf -v over array slices instead of append loops.
  • plugins/{architecture,debugging,discovery,education,event-storming,harness-ops,knowledge,planning,review,work-items,machine-health}/lib/html-escape.mjs: regenerated shared copies.
  • plugins/{visualization,architecture}/lib/mermaid-gate.mjs: regenerated shared copies.
  • plugins/discovery/scripts/index-regen.sh: regenerated shared copy.
  • .changes/{architecture,debugging,discovery,education,event-storming,harness-ops,knowledge,planning,review,work-items,machine-health,visualization}/work-resolve-issue-issue-14334-42613402763-1-*.md: patch fragments noting the internal simplification.

Verification

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

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

The run reports:

  • sync-shared-copies wrapper: regenerated 14 copies, exit status 0.
  • check-changelog-fragments: All 14 changelog fragment(s) under .changes/ are valid.
  • check-changed-skills: no changed skills under plugins/*/skills/, nothing to gate.
  • check-affected: 13 passed, 6 skipped over 29 changed files (skips: ruff no .py, typos not installed, three validate-plugins sub-checks that run checked-tree code, changed-skills).
  • Fresh-context review subagent over the full diff: no behavior differences found (no zero-length regex matches so matchAll walks the same matches; failure push order unchanged; printf -v argument lists are never empty, so bash < 4.4 set -u and empty-output edge cases do not arise; resolveMmdc…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42613402763

Left out: the items under Not verified.

Related

#14334

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

Security review: PR #14625 (refactor(lib): simplify html-escape, mermaid-gate and index-regen loops)

No security issues found.

critical-findings: 0

Scope. I read all 29 changed files. Where several files carry the same change, I read the first one and counted the copies as read, per identical.txt: the nine .changes fragments, the 11 plugin copies of html-escape.mjs, and the two plugin copies of mermaid-gate.mjs. I checked the path of each copy. They are all plugin lib/ copies or changelog fragments, and none sits at a hook, workflow, settings or manifest path. No changed file matches a TRUSTED PATHS: glob. The PR touches no trust control, merge hold, plugin manifest or standing instruction.

What I checked

  • lib/html-escape.mjs and its copies. This file holds the HTML allowlist check (scanStructure / parseAttributes), so a change in which matches it finds could let disallowed HTML through. The PR swaps manual exec loops for matchAll. Neither the tag regex, the attribute regex nor the style regex can match an empty string, so matchAll returns the same matches as the old loop. matchAll also works on a copy of the regex, so it carries no shared lastIndex state. The closing-tag check moved from if (!closing) to an early continue, which is the same logic. Tag and attribute names are still checked against ALLOWED_TAGS / ALLOWED_ATTRS, attribute values against ESCAPED_TEXT, and the style check (url(, @import, expression(, backslash) is unchanged. The check is no weaker.
  • lib/mermaid-gate.mjs and its copies. resolveMmdc still tries the same candidates in the same order and keeps the first one that answers --version. The candidate list, the version floor and what gets run are unchanged. In gate, the forEach became a for...of. The loop body has no return whose meaning would change, and the finally cleanup of the temporary work directory is untouched.
  • lib/index-regen.sh and plugins/discovery/scripts/index-regen.sh. The while loops became C-style for loops, and the file text is now built with printf -v. Every array element is passed to the fixed '%s\n' format as an argument, never as the format itself, so % and backslashes in file content are not interpreted. The size cap and the write-only-on-change check that run after the text is assembled are unchanged, and so are the target path and how it is chosen.
  • .changes/* fragments. These are changelog prose only.

PR context. The description holds no embedded instructions aimed at this review. The closing issue's body was left out by the wrapper because its author is not on the allowed list.

Instruction-surface lens. Not applicable: the PR deletes, narrows or softens no standing instruction.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of 20 listed files: the 12 changelog fragments, lib/html-escape.mjs, lib/index-regen.sh, lib/mermaid-gate.mjs, the plugins/architecture copies of html-escape and mermaid-gate, the plugins/debugging and plugins/discovery copies of html-escape, and plugins/discovery/scripts/index-regen.sh. The other 9 files are identical copies of html-escape and mermaid-gate under plugins/*/lib/. I skipped them as identical.txt says to. Their paths are the same kind of shared lib module, so they behave the same there.

I checked each change by reading it against the base logic. I ran no tests.

  • html-escape.mjs. All three regexes carry the g flag, as matchAll requires.
    • None of them can match an empty string, so matchAll walks the same matches as the old exec loops. matchAll also works on a copy of the regex, so lastIndex state can't leak between the nested parseAttributes and scanStructure scans.
    • The early continue for closing tags pushes the same failures in the same order.
  • mermaid-gate.mjs.
    • resolveMmdc: candidates always has at least one entry. After the loop, cmd and v hold the same values as before, both when a probe succeeds and when every probe fails (they end on the last candidate).
    • gate: the old forEach callback had no return, so turning it into for...of doesn't change control flow. extractBlocks returns an array.
    • render: splitting the output once gives the same result.
  • index-regen.sh.
    • In the frontmatter loop, the only paths were the break on ---, a continue that came right after an increment, and the final increment. The C-style for keeps every one of them.
    • printf -v ... '%s\n' over the array slices builds the same text as the old append loops. generated_lines is never empty (lib/index-regen.sh:410-411 puts in (no child slices)), and both slice_lines slices hold at least one line. So the bash < 4.4 set -u and empty-argument edge cases can't happen.

Closing issue #14334 acceptance criteria

  • Behavior unchanged: met, from my reading of the code. lib/html-escape.test.sh, lib/index-regen.test.sh, lib/mermaid-gate.test.sh and lib/mermaid-gate.test.mjs exist and would catch a regression. The PR says it did not run them, so they are left to CI.
  • Edits only listed files, copies and fragments: met.
  • Within 400 changed lines and 15 hand-edited files: met (3 hand-edited files).
  • sync-shared-copies.sh run and its copies committed: the copies in the diff match their sources' changes.
  • ci-status green: I couldn't check this from here. It is left to the PR's CI.

Other checks

  • No .claude/rules/ file's paths: glob matches the changed files.
  • No plugin manifest changed.
  • Every fragment uses bump: patch, which fits an internal refactor that doesn't change behavior.
  • The PR context contains no embedded instructions aimed at the reviewer.
  • The PR body says its test suites, the macOS bash 3.2 behavior and CI status were not verified. I confirmed none of those claims either.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 5390721

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-14625-53907211f504081f4b25b009d19f77001f2f2544, 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 a05ad72 Nov 9, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14334-42613402763-1 branch November 9, 2026 14:13
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

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

File Killed Survived Timeout No coverage Invalid Not run
lib/html-escape.mjs 0 0 0 0 0 3
lib/index-regen.sh 1 1 0 0 0 0
lib/mermaid-gate.mjs 0 2 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
lib/mermaid-gate.mjs:104 other productive input-gap
lib/mermaid-gate.mjs:123 other productive input-gap
lib/index-regen.sh:190 ROR 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 a05ad728842d6df193a3dc96c78f5059749cdcce; 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 html-escape.mjs, html2md.py, index-regen.sh and 8 more shared lib sources

0 participants