Skip to content

refactor(mcp-tools): simplify audit-posture inventory.sh and audit discover.sh - #14942

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14657

Summary

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

Simplified the two listed mcp-tools scripts with no behavior change. In discover.sh, the Python and .NET marker loops now read the 12-line window after each hit with one sed call (new lines_after helper) instead of one sed process per line; add_record builds each record with printf -v instead of a command-substitution subshell over a separate emit_tool function; and dead initializations and an if/else for scan_prefix were collapsed. In inventory.sh, the single-use check_json wrapper was inlined, and the user/local scope block no longer duplicates the 'local ... absent' source line across two else branches (it relies on META_LOCAL's unmatched default). Each choice keeps the same outputs, exit codes, stderr text and flags; the jq classification and value filter were left untouched as the riskiest code to change.

Not verified

  • discover.test.sh and inventory.test.sh were not executed here (the lane's Bash runs only the named wrappers); left to the PR's CI
  • Review noted one contrived stderr-only difference: a NUL byte within the 12 lines after a marker in a >32 KiB source file made bash 4.4+ print 'ignored null byte' from the old per-line command substitution; read -r drops it silently. stdout and exit code are unchanged
  • tidy pass 5 (ai-slop): the deterministic detector detect.sh could not run under the lane's Bash restriction; the rubric read of the one-line fragment found no tells
  • build/lint: no shellcheck or shfmt run available in this lane beyond check-affected; left to the PR's CI
  • git status lists untracked .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc at the checkout root; these are sandbox mount placeholders (Read reports .mcp.json does not exist), not created by this change, and must not be in the patch

Fix

  • plugins/mcp-tools/skills/audit/scripts/discover.sh: added lines_after helper; Python and .NET scan loops read the 12-line window in one sed call; emit_tool folded into add_record via printf -v; removed dead root/project_root/scan_prefix initializations and collapsed the scan_prefix if/else
  • plugins/mcp-tools/skills/audit-posture/scripts/inventory.sh: inlined check_json into add_file_source; flattened the user/local scope block so the local source line is emitted once
  • .changes/mcp-tools/work-resolve-issue-issue-14657-42735201062-1-d7347343.md: new patch fragment ('### Changed' / 'Internal simplification, no behavior change.') created with new-changelog-fragment

Verification

The runner ran each check from the base copy against 610fc76:

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

The run reports:

  • check-changelog-fragments: all 3 fragments valid (run before and after tidy)
  • check-changed-skills: audit-posture and audit PASS, 0 errors (warnings are pre-existing description/body-length and Next/Gotchas notes, unrelated to the scripts)
  • check-affected: 13 passed, 6 skipped, rest CI-only, over 3 changed files (run before and after tidy)
  • fresh-context review subagent over the diff and both test files: no behavior difference on realistic input; its two conditional findings (emit_tool printf form, check_json stdin form) are settled by the HEAD bodies, which used printf '%s' args and jq empty <"$1"
  • tidy-diff over the 11 changed hunks: no edits needed in passes 1-5
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42735201062

Left out: the items under Not verified.

Related

#14657

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

Security review: PR #14942

No security issues found.

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

plugins/mcp-tools/skills/audit-posture/scripts/inventory.sh

  • check_json inlined. The function was removed and its body moved into add_file_source unchanged. The check still reads the file on stdin (<"$2"), and the path is still screened for control characters first (L192). The fail-closed exit 2 on unparsable JSON is kept.
  • User/local scope block flattened. The local-scope branch now runs only when META_LOCAL starts with {"matched":true.
    • The script's own default does not match that prefix. It has a space after the colon ('{"matched": false, ...}', L117).
    • That default is assigned unconditionally, so a value inherited from the environment cannot leak into the check.
    • When ~/.claude.json is absent, the code still reports local ... absent, as before.

plugins/mcp-tools/skills/audit/scripts/discover.sh

  • lines_after helper. It passes only arithmetic-expanded line numbers to sed -n, and the file path is a quoted argument, so nothing can be injected.
  • add_record. It now uses printf -v record '<fixed format>' "$@". The format string is a constant and the values are %s arguments, so a hostile tool name or path cannot act as a format directive. It is always called with exactly 5 arguments.
  • Removed initializations and collapsed scan_prefix if/else. No security effect. Both root and project_root are set on every path before they are used.

.changes/mcp-tools/...md: a changelog fragment only, with nothing executable in it.

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

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of all 3 changed files. I also read the full head versions of inventory.sh and discover.sh to check that behavior is unchanged.

plugins/mcp-tools/skills/audit-posture/scripts/inventory.sh

  • check_json inlined: the inlined line runs the same jq empty command and calls die_json with the same text. No other code calls check_json.
  • User/local scope block flattened: add_file_source user returns 1 only when the file is missing. In that case META_LOCAL keeps its default {"matched": false, ...}, so the local … absent line is still emitted once. Every other path calls exit 2 inside the function, as it did before. The output is the same.

plugins/mcp-tools/skills/audit/scripts/discover.sh

  • printf -v in add_record: the old $(emit_tool …) plus $'\n' stripped exactly the one newline after --- and added it back, so each record still ends in ---\n. Every caller passes exactly 5 arguments, so the format is never reused.
  • lines_after window: it yields lines N+1 to N+12, the same as the old offset loop. Reaching end of file now ends the loop where the old code read an empty candidate and broke out, and an empty line still breaks. The || [[ -n "$candidate" ]] keeps a last line with no trailing newline. Carriage returns are kept in both versions. tool_name and method_line end up the same after the loop.
  • Removed initializations: under set -u, both branches assign root and project_root before use, or exit through report_not_a_directory. scan_prefix is now set unconditionally. The [[ … ]] && … form is safe because the script does not use set -e.

Closing issue #14657 acceptance criteria

  • Behavior unchanged: met by reading the code. discover.test.sh and inventory.test.sh assert on the Python/.NET tool records, Tool line, Scan root and the local source line, so a regression in these paths can fail a test. Whether those tests pass is the author's claim and not verified here: I did not run them, and the PR says they were left to CI.
  • Diff edits only the listed files plus a fragment: met.
  • Within 400 lines and 15 files: met.
  • ci-status green: not checkable from this lane.
  • Fragment bump: patch with ### Changed / "Internal simplification, no behavior change.": met.

Other checks

  • Path-scoped rules skill-bodies-state-current-rules.md and cost-claims.md match these script paths. Nothing in the changed lines breaks them.
  • No plugin manifest changed.
  • The PR context file contains no embedded instructions aimed at the lane.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 610fc76

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-14942-610fc7672fb66c1b8cb4d524f4f22b0e7a976a14, 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 f235b75 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14657-42735201062-1 branch November 10, 2026 03:06
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit f235b75f2a96f5e8eada53b33b388f2e7dc9a9a6; 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 audit-posture and audit mcp-tools plugin code

0 participants