Skip to content

refactor(architecture): move jstr and json_escape into plugin lib files - #15585

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-15580-43233103312-1
Nov 12, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #15580

Summary

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

The awk JSON-string reader jstr now lives once in plugins/architecture/lib/jstr.awk and the json_escape shell helper (with JSON_ESC) once in plugins/architecture/lib/json-escape.sh, replacing three and five verbatim copies. render-context passes the lib file with awk -f <lib>/jstr.awk -f -; collect-containers and render-containers read it into JSTR_AWK (file text plus a trailing newline) and prefix their inline programs, the concat form render-landscape.sh uses. The five collectors source json-escape.sh beside their existing lib sources; json-escape.sh uses the source guard and header form of lib/record-layout.sh and carries the rationale comment that portfolio-facts.sh had for the helper. The differing variants (render-events/render-flow jstr, collect-data/collect-deployment printf json_escape, landscape-record sed form) are untouched. No behavior change.

Not verified

  • The seven named test suites (collect-containers.test.sh, collect-context.test.sh, render-context.test.sh, dependency-graph.test.sh, render-components.test.sh, collect-events.test.sh, portfolio-facts.test.sh) were not executed: this lane's shell runs only its named wrappers. Left to the PR's CI.
  • ci-status green is a PR CI check; left to the PR's CI.
  • Tidy pass 5 (ai-slop) ran its rubric by reading the one-line changelog fragment; the deterministic detect.sh could not run because this lane's shell runs only its named wrappers. No tell found.
  • Tidy proposal, not applied: collect-events.sh computes its script directory twice (lines 32 and 34); hoisting it into one variable needs an edit to line 32, outside the change's own lines.
  • Untracked sandbox files at the checkout root (.bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc) were not created by this run and are not part of the change.

Fix

  • plugins/architecture/lib/jstr.awk: new; holds the jstr awk function, with a functions-only header in the form of lib/split-object.awk
  • plugins/architecture/lib/json-escape.sh: new; holds JSON_ESC and json_escape behind the record-layout.sh source guard, with a SC2034 directive since JSON_ESC is read by the sourcing scripts
  • plugins/architecture/skills/map-containers/scripts/collect-containers.sh: sources lib/json-escape.sh and reads lib/jstr.awk into JSTR_AWK; inline json_escape and jstr removed; the --graph awk program now runs as awk "$JSTR_AWK"'...'
  • plugins/architecture/skills/map-containers/scripts/render-containers.sh: reads lib/jstr.awk into JSTR_AWK and prefixes the render awk program; inline jstr removed
  • plugins/architecture/skills/map-context/scripts/render-context.sh: adds -f <lib>/jstr.awk before -f -; inline jstr removed from the heredoc
  • plugins/architecture/skills/map-context/scripts/collect-context.sh: sources lib/json-escape.sh; inline json_escape removed
  • plugins/architecture/skills/map-dependencies/scripts/dependency-graph.sh: sources lib/json-escape.sh; inline json_escape removed
  • plugins/architecture/skills/map-events/scripts/collect-events.sh: sources lib/json-escape.sh; inline json_escape removed
  • plugins/architecture/skills/map-landscape/scripts/portfolio-facts.sh: sources lib/json-escape.sh; inline json_escape and its rationale comment removed (the comment moved to the lib header)
  • .changes/architecture/work-resolve-issue-issue-15580-43233103312-1-0f455a0e.md: new patch fragment, ### Changed, "Internal restructuring, no behavior change."

Verification

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

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

The run reports:

  • git-read diff --unified=0 HEAD: each removed jstr body (three) and json_escape body (five) is byte-identical to the lib copy, apart from the added shellcheck directive line
  • Grep for function jstr and json_escape() under plugins/architecture: only the two lib files plus the five variants the issue keeps
  • Grep of the architecture *.test.sh files: no test copies or relocates the edited scripts, so the ../../../lib paths resolve under test
  • check-affected: first run failed shellcheck SC2034 on lib/json-escape.sh (JSON_ESC appears unused); fixed with a scoped disable directive; re-run 13 passed, 6 skipped, 0 failed over 10 changed files
  • check-changelog-fragments: all 3 fragments under .changes/ valid
  • check-changed-skills: 5 skills checked, 0 failed (warnings are pre-existing SKILL.md size warnings, not touched by this change)
  • fresh-context review subagent over the whole diff: no correctness bugs; confirmed sourcing precedes every json_escape use including --help and error paths, awk prefix concatenation and -f file -f - heredoc are portable, the source guard does not misfire, no name collisions
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43233103312

Left out: the items under Not verified.

Related

#15580

Merge-Risk: max=LOW demote=false head=d98f348d811cfaea111f24519438d2f76a8110fb rubric=8.4.11 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 d98f348d811cfaea111f24519438d2f76a8110fb: read 10 of 10 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15585 (head d98f348)

I found no security issues.

What the PR does. It moves duplicated helpers in the architecture plugin into two shared library files:

  • The awk jstr function now lives in plugins/architecture/lib/jstr.awk.
  • The shell json_escape helper, with its JSON_ESC variable, now lives in plugins/architecture/lib/json-escape.sh.

The seven calling scripts now source or include these files instead of keeping their own copies.

What I checked:

  • Escaping is unchanged. The new json_escape body is byte-identical to the five copies it replaces. It still escapes backslash first, then the quote, then tab, CR and LF. The only addition is a shellcheck comment. JSON output escaping and injection behaviour stay the same.
  • jstr is unchanged. jstr.awk matches the three removed inline copies exactly.
  • The lib files are found safely. Every script builds the path from its own directory ($SCRIPT_DIR, $_ARCH_LIB, or $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)), never from the current directory or the environment. Every path is quoted. A caller cannot redirect the source to a different file.
  • Awk program text comes only from plugin files. collect-containers.sh and render-containers.sh put the file's contents into JSTR_AWK and prepend it to a single-quoted program. That text comes only from the plugin's own file, never from repository data being analyzed. render-context.sh passes the path as a quoted -f argument. No untrusted record content ends up in awk program text.
  • The execute guard is harmless. Running json-escape.sh directly makes it print a message and exit 2. Sourcing it defines one function and one variable and has no other side effects.
  • No trusted paths changed. None of the 10 changed files matches a TRUSTED PATHS: glob. No trust control, merge hold, token scope, kill switch, workflow, or plugin manifest is touched. No standing instruction is deleted or weakened; the only comment removed, in portfolio-facts.sh, moved into the new lib header.
  • PR context. The description contains no embedded instructions aimed at the review.

This was a full review (not blocking only), and no earlier findings exist. Nothing here bills anyone or spends credits.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

This PR moves one copy of the awk jstr reader into plugins/architecture/lib/jstr.awk and one copy of json_escape/JSON_ESC into plugins/architecture/lib/json-escape.sh. It removes the three verbatim jstr copies and the five verbatim json_escape copies, and adds a patch changelog fragment. I read every hunk of all 10 changed files.

What I checked (by reading, not by running anything):

  • Code moved unchanged: each removed jstr and json_escape body matches its lib copy. The only addition is the SC2034 directive.
  • Load paths:
    • collect-containers, collect-context and dependency-graph resolve ../../../lib from SCRIPT_DIR.
    • portfolio-facts uses _ARCH_LIB.
    • collect-events, render-containers and render-context use cd "$(dirname "${BASH_SOURCE[0]}")" && pwd at the point of use. Nothing runs cd earlier in those scripts, so a relative invocation path still resolves.
  • Load order: each script sources the lib before it first calls json_escape. In dependency-graph.sh the function is now defined earlier than it was (around line 253 instead of 312), which is harmless.
  • The awk prefix:
    • $(<file) strips the file's trailing newline, and the scripts add $'\n' back, so the inline programs still parse after the prefix.
    • render-context passes -f <lib>/jstr.awk -f -; awk accepts more than one -f (POSIX), and the script already used -f -.
    • Comment lines in jstr.awk are valid awk.
  • Source guard: in json-escape.sh, BASH_SOURCE[0] == $0 is true only when the file is run directly, so it never fires on source.
  • Closing issue Move the architecture jstr awk reader and json_escape into plugin lib files #15580: the code meets the criteria for one copy each and unchanged behavior. The diff touches only the listed files and is well under 400 lines and 15 files. The criteria that the seven test suites pass and that ci-status is green are claims I could not check; the PR lists them as not run and leaves them to CI.

Minor, not counted as a finding: JSTR_AWK holds a file path in render-context.sh but the program text in the two map-containers scripts.

No plugin manifest changed, so there are no manifest lines. The patch bump in the fragment fits an internal refactor. None of the changed files is on a trusted path, and none affects cost.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head d98f348d811cfaea111f24519438d2f76a8110fb. No person needs to act: a lane clears this reason, and the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for d98f348

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-15585-d98f348d811cfaea111f24519438d2f76a8110fb, expires on 2026-12-12.

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 12, 2026
Merged via the queue into main with commit bc68c5c Nov 12, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-15580-43233103312-1 branch November 12, 2026 14:40
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit bc68c5c56d831629f80cb95f95b7e36d150b2ed5; 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.

Move the architecture jstr awk reader and json_escape into plugin lib files

0 participants