Skip to content

docs(bash-format): document project scope + setup gotchas; add opt-in/shfmt-fallback test coverage (F1, F2, F6) - #1171

Merged
kyle-sexton merged 2 commits into
mainfrom
docs/1168-bash-format-polish
Jul 23, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
docs/1168-bash-format-polish

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Closes #1168.

Consumer-side audit polish for [email protected] (handoff-inbox item 20260723-095036), findings F1, F2 (bash-format-local), F6. No behavioral change — docs + tests only. Version 0.6.2.

Changes

  • F1 (docs). Documented the in-project-only scope: the hook acts only on shell files under CLAUDE_PROJECT_DIR (symlink-resolved membership guard in the shared library); files written outside the project are silently skipped. Added a README "Scope" note and a project-scope probe to the setup skill's check (which no longer reports "fully operational" without the caveat).
    • Grounding note: F1's original "add a membership-guard test" sub-item is already satisfied — lib/hook-utils.test.sh Test 12 thoroughly tests the guard (in-project accept, prefix-sibling reject, escaping-symlink reject, symlinked-root). The producer only read bash-format.test.sh (which deliberately unsets CLAUDE_PROJECT_DIR). So F1 reduces to docs.
  • F2 (bash-format-local tests). Added bash-format.test.sh coverage for the [*.{sh,bash}] brace-list and [**/*.sh] path-prefixed .editorconfig opt-in forms, and the shfmt < 3.8 --apply-ignore fallback (|| shfmt -w) via a stub shfmt.
  • F6. Added a ## Gotchas section to the setup skill (cache-path ENAMETOOLONG, check-PASS-≠-full-coverage, opt-in-conditional shfmt FAIL).

Verification

  • bash plugins/bash-format/hooks/bash-format.test.sh → PASS=42 FAIL=0 (3 new cases green).
  • shellcheck -x -S warning on the test file → clean.
  • plugin.json valid; version bumped 0.6.1 → 0.6.2; CHANGELOG updated.

Scope moved out of this PR

🤖 Generated with Claude Code

Related

🤖 Generated with Claude Code

…/shfmt-fallback test coverage (F1, F2, F6)

Consumer-side audit polish for [email protected] (handoff-inbox item
20260723-095036), findings F1/F2/F6 — no behavioral change.

- F1: document the in-project-only scope (README "Scope" note + setup `check`
  project-scope probe) so the shared membership guard's silent out-of-project
  skip is not a surprise for an advisory linter. The guard itself is already
  tested centrally in lib/hook-utils.test.sh (Test 12), so F1 is docs-only.
- F2 (bash-format-local): test the `[*.{sh,bash}]` brace-list and `[**/*.sh]`
  path-prefixed .editorconfig opt-in forms, and the shfmt<3.8 `--apply-ignore`
  fallback (`|| shfmt -w`) via a stub shfmt.
- F6: add a `## Gotchas` section to the setup skill.

F3 (dim-9 label) and the shared-lib F2 test gaps moved to #1169 — they are
fleet-scope, not bash-format-local. F5 filed as #1170 (HITL). Version 0.6.2.

Co-Authored-By: Claude Fable 5 <[email protected]>
@claude

claude Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 14s —— View job


PR Review: docs(bash-format) — F1, F2, F6 polish for [email protected]

  • Gather context from PR metadata
  • Read changed files
  • Review plugin.json version bump
  • Review CHANGELOG.md
  • Review README.md scope addition
  • Review bash-format.test.sh new tests
  • Review SKILL.md Gotchas section
  • Formulate and post review findings

Overall: Clean docs + tests PR, no behavioral change as claimed. All five files are internally consistent and the three findings (F1, F2, F6) are correctly addressed. Ready to merge with two small nits and one minor correctness suggestion noted below.


plugin.json

Correct semver patch bump (0.6.1 → 0.6.2) for a docs-and-tests-only release. No issues.


CHANGELOG.md

Content is accurate and well-linked to the issue. One style note:

Nit — non-standard Keep a Changelog section heading.
The file header explicitly cites Keep a Changelog 1.1.0, whose valid section types are Added, Changed, Deprecated, Removed, Fixed, and Security. The new ### Tests subsection is not in the spec. The test additions could be folded into the existing ### Changed block with a parenthetical — e.g. "Tests: added coverage for … (no runtime behavior change)." Minor; non-blocking.


README.md

The new Scope bullet is accurate, well-placed, and explains the silent-skip behavior plus the deliberate rationale ("defense-in-depth scoping").

Nit — workaround only mentions linting.
The line "if you need such a file linted, run shellcheck on it directly" doesn't address the formatting side. A reader who also wants shfmt to format an out-of-project file has no hint. Consider: "run shellcheck on it for linting or shfmt -w for formatting." Non-blocking.


bash-format.test.sh

The three new test cases are well-structured and each isolates a specific invariant.

Brace-list test ([*.{sh,bash}]) and path-prefixed glob test ([**/*.sh]) — correct approach: fresh git repo per case, .editorconfig written inline, hook run via run_hook, formatted output verified with grep. Both sit correctly inside the if [[ $HAVE_SHFMT -eq 1 ]] guard.

shfmt < 3.8 fallback test — good design choice to run it unconditionally (stub owns its own PATH slot, independent of the host's real shfmt). The stub's logic is sound: exit 2 on --apply-ignore, then format on plain -w. One minor robustness point:

Minor — stub uses $* expansion for the file argument.
https://github.com/melodic-software/claude-code-plugins/blob/acb1b21359434cc3c0d129ed303ff99aee036c8a/plugins/bash-format/hooks/bash-format.test.sh#L297

f="${*: -1}"

$* joins positional parameters with $IFS (space by default), so a filename containing a space would be silently truncated or mangled. "${@: -1}" is the idiomatic form for the last positional parameter as a single word. In practice mktemp -d paths on Linux don't have spaces, so this doesn't fail today, but the stub would be more robust with:

f="${@: -1}"

Fix this →


SKILL.md

Probe 9 (Project scope) is correctly classified as INFO (not FAIL — deliberate behavior, not a defect). The language mirrors the README Scope bullet well.

"never an unqualified 'fully operational'" guard is a good explicit constraint on agent behavior — prevents a common pattern of summarising a green check as all-clear when there's a known gap.

Gotchas section — all three are practical and non-obvious:

  • ENAMETOOLONG is the right place to call this out (agents running the skill might grep the hook cache by full path).
  • Restating the scope caveat in Gotchas is warranted — it's the kind of thing an agent will miss in a numbered list but catch in a named bullet.
  • The shfmt opt-in conditionality gotcha prevents the skill from over-reporting FAILs on repos without .editorconfig.

One pre-existing (not introduced here) run-on sentence in apply worth noting for a follow-up:

https://github.com/melodic-software/claude-code-plugins/blob/acb1b21359434cc3c0d129ed303ff99aee036c8a/plugins/bash-format/skills/setup/SKILL.md#L90-L92
The --config reconfigure guidance is one long semicolon-chained sentence. Pre-existing — out of scope here, but readable improvement candidate.


Summary

File Verdict Notes
plugin.json ✅ Clean patch bump
CHANGELOG.md ✅ Non-standard ### Tests heading (nit)
README.md ✅ Missing shfmt -w in workaround (nit)
bash-format.test.sh ✅ ${*: -1} → ${@: -1} in stub (minor)
SKILL.md ✅ Well-structured, no issues

No correctness bugs, no security concerns, no behavioral changes. The F1/F2/F6 findings are fully addressed, the PR's claimed scope is accurate, and the reasoning in the description (especially the F1 grounding note about hook-utils.test.sh Test 12 already covering the membership guard) is sound. Approve when the ${@: -1} nit is resolved (or accepted as-is given the low real-world risk).

@claude

claude Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 20s —— View job


Security Review

  • Gather PR diff and changed files
  • Review each changed file for security issues
  • Post findings

No security issues found.

This PR is docs + tests only (no behavioral change). I reviewed each of the five changed files for the vulnerability classes in scope:

plugin.json — Version bump 0.6.1 → 0.6.2. No security surface.

CHANGELOG.md / README.md / SKILL.md — Pure documentation. No injection surfaces, no secrets, no permissions changes.

bash-format.test.sh (the interesting one) — Three new test blocks were added. I reviewed each for the following risks:

  • Stub shfmt + PATH prepend (lines 288–315). The stub is written via a single-quoted heredoc (<<'STUB'), so no variable expansion occurs at write time. $STUBDIR is a mktemp -d result under the test's own $WORK temp tree, which is cleaned up by trap cleanup EXIT. The stub is prepended to PATH only inside a subshell (env … PATH="$STUBDIR:$PATH" bash "$HOOK"), limiting the blast radius to that subprocess. The stub's f="${*: -1}" is double-quoted in the printf redirect, so no metacharacter issue. Safe.

  • printf '…%s…' "$file_path" JSON construction (lines 307, 89, 101). %s in Bash's printf is safe against %-characters in the argument (they're in the value, not the format string). File paths are all mktemp-derived temp paths under $WORK, so no attacker-controlled content reaches the JSON fragment. Safe in this test context.

  • make_sink executable generation (lines 50–59). Body is written with printf '%s\n' (no interpretation). The $TEL path embedded at line 332 is a mktemp result; no shell metacharacters will appear. Safe.

  • Temp-dir cleanup. All working directories ($WORK, $UNRELATED) are removed by the EXIT trap. No residual artifacts left behind.

No injection surfaces, credential exposure, authorization gaps, or dangerous CI patterns were introduced by this PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acb1b21359

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/bash-format/README.md Resolved
kyle-sexton added a commit that referenced this pull request Jul 23, 2026
…fine dim-9; cover buffer_stdin timeout & EPOCHREALTIME skip (F4, F3, F2-shared) (#1172)

Closes #1169.

Fleet-scope findings surfaced by the `bash-format` consumer audit
(handoff-inbox item `20260723-095036`), re-verified and rescoped against
current source. **No runtime behavior change** — a fleet-doc correction
plus shared-lib test coverage.

## Changes

- **F4 — `statusMessage` adoption doc was badly stale.** The doc claimed
"no `hooks.json` in the fleet declares `statusMessage` yet — all 27
wired `type: command` handlers across 12 plugins need it added."
Scripted count of current source (jq over every
`plugins/*/hooks/hooks.json`): **31 command-type handlers across 15
hook-bearing plugins, 30 declare `statusMessage`; sole holdout
`plugins/disk-hygiene`** (a `PreToolUse` destructive-guard). Doc now
records near-complete adoption, names the holdout, and states the #836
close condition.
- **F3 — `dim-9 doctrine` defined.** Grounding refuted the
"bash-format-local" premise: the label is fleet vocabulary cited in **9
hook scripts** (actionlint, bash-format, biome-format,
desktop-notification, eol-normalizer, go-format, powershell-format,
ruff-format, typos-format) with **no central glossary** (verified — no
dimensions registry exists). Defined it authoritatively in the
visible-skip (`systemMessage`) section it names, and noted the broader
undefined `dim-N` scheme as a separate follow-up. **Not** stripped from
bash-format — that would fragment a fleet-wide convention
(`reuse-or-replace`).
- **F2-shared — shared-lib test coverage.** Added
`lib/hook-utils.test.sh` cases for `hook::buffer_stdin`'s timeout path
(`return 2` / `BLOCKED` on stderr) and `hook::emit_telemetry`'s
`EPOCHREALTIME`-absent (Bash < 5.0) skip-fail-open. Shared-lib behavior
→ tests live centrally, not duplicated into a plugin.

## Verification

- `bash lib/hook-utils.test.sh` → **PASS=85 FAIL=0** (2 new cases green)
on bash 5.3.
- `shellcheck -x -S warning lib/hook-utils.test.sh` → clean.
- Only `lib/hook-utils.sh`'s **test** was touched (not the SSOT lib
itself), so no `sync-hook-utils.sh` run and no plugin version bumps are
needed.

## Notes

- F1's original "add a membership-guard test" was **already satisfied**
by `lib/hook-utils.test.sh` Test 12 — see sibling **#1168** (bash-format
docs/tests, PR #1171).
- The `disk-hygiene` holdout is left as the documented remaining item;
adding its `statusMessage` (or marking it a deliberate exception) would
close #836 but pulls a third plugin into this PR, so it is deferred per
the group-by-plugin boundary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Related

- #1171 — sibling PR for the bash-format-local findings (F1, F2-local,
F6) from the same audit item.
- #1170 — HITL follow-up (F5, `--config` fresh-install claim), not
closed here.
- #836 — statusMessage fleet-adoption tracking issue this PR updates
(not closed; one holdout remains).
- Handoff-inbox item
`20260723-095036-bash-format-audit-docs-tests-polish` (producer SW2030).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <[email protected]>
…_PROJECT_DIR is set (PR review P2)

Codex review (P2) on #1171: the F1 scope note claimed out-of-project files are
"silently skipped" unconditionally, but hook::read_file_path only runs the
membership check inside the `[[ -n "${CLAUDE_PROJECT_DIR:-}" ]]` branch
(hook-utils.sh:198); when the var is unset (e.g. some headless -p sessions) it
returns any existing file (:210). Qualified the README "Scope" note, setup probe
9, and the Gotchas bullet to state the skip applies only when CLAUDE_PROJECT_DIR
is set, and that it is bypassed (any edited file processed) when unset.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Addressed the P2 (README:36) in da42914. Confirmed the finding: hook::read_file_path runs the membership check only inside the [[ -n "${CLAUDE_PROJECT_DIR:-}" ]] branch (hook-utils.sh:198) and returns any existing file otherwise (:210), so the unconditional "silently skipped" guarantee was wrong when CLAUDE_PROJECT_DIR is unset (headless -p). Qualified the README Scope note, setup probe 9, and the Gotchas bullet to state the skip applies only when the var is set, and that it is bypassed when unset. Resolved the thread.

@claude

claude Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 46s —— View job


Review of commit da42914f — P2 scope-guarantee fix

  • Load tools
  • Review da42914f diff
  • Verify consistency across README.md, SKILL.md
  • Cross-check hook-utils.sh behavior
  • Post findings

Finding: P2 correctness fix — scope guarantee qualification

The fix is correct and complete. I verified hook::read_file_path in hook-utils.sh:198–210:

if [[ -n "${CLAUDE_PROJECT_DIR:-}" ]]; then
    # ... membership check ...
    if [[ "$norm_file" != "$norm_project" && "$norm_file" != "$norm_project"/* ]]; then
      return 1
    fi
fi
printf '%s' "$file"   # :210 — reached when CLAUDE_PROJECT_DIR is unset

The source behavior matches the revised docs exactly: the membership guard only runs when CLAUDE_PROJECT_DIR is non-empty; when unset, the function returns any existing file unconditionally.

All three touched files are consistent:

File Before After
README.md:31 "Scope: files inside the current project only" — unconditional Correctly qualified: "when CLAUDE_PROJECT_DIR is set" + unset-case explanation
SKILL.md probe 9 "the hook acts only on shell files inside CLAUDE_PROJECT_DIR" — unconditional "when CLAUDE_PROJECT_DIR is set … When … unset … the guard is skipped"
SKILL.md Gotchas "The hook is project-scoped … shell files written outside … are silently skipped" — unconditional Qualified with the set/unset split; parenthetical points back to probe 9
CHANGELOG.md Claimed unconditional scope Qualified; cites the PR review source

One very minor nit (non-blocking)

README.md:43:

"Either way, to lint a file the hook skipped, run shellcheck on it directly."

When CLAUDE_PROJECT_DIR is unset, the hook doesn't skip any file — so "a file the hook skipped" only applies in the set-variable case. "Either way" is slightly misleading. A minor reword would tighten it: "To lint a file directly (bypassing the hook), run shellcheck." Non-blocking — the intent is clear enough.


Outstanding nit from the prior review

The ${*: -1} → ${@: -1} stub issue noted in the prior review (bash-format.test.sh:297) was not addressed in this commit — it was called out as low real-world risk given mktemp paths never have spaces. Still worth a follow-up ticket if you want the stub to be strictly correct, but not a blocker here.


Summary

The P2 correctness finding is fully and accurately addressed. Documentation is internally consistent and matches the source implementation. Ready to merge.

@claude

claude Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 7s —— View job


Security Review — PR #1171 ([email protected])

  • Gather context and plan
  • Get PR diff (both commits)
  • Review changed files for security issues
  • Post findings

No security issues found.

This PR is docs + tests only, with no behavioral change to the hook itself. I reviewed all five changed files against the vulnerability classes in scope.


plugin.json — version bump only

0.6.1 → 0.6.2. No security surface.


CHANGELOG.md / README.md / SKILL.md — documentation only

Pure prose and LLM skill instructions. No code execution paths, no secrets, no permissions changes, no dangerous command recommendations. The new SKILL.md ## Gotchas section advises agents to use short relative paths (avoiding ENAMETOOLONG) and to read scope caveats — no action that could be weaponized.


bash-format.test.sh — three new test blocks

This is the only file with executable content. I reviewed each addition:

Brace-list and path-prefixed-glob tests (lines 249–277).
Standard pattern consistent with the rest of the test file: mktemp-derived temp dirs, printf literals written as .editorconfig and fixture files, run_hook invocation. No new injection surfaces.

Stub shfmt --apply-ignore fallback test (lines 282–315).

Surface Assessment
Stub written via <<'STUB' (single-quoted heredoc) No variable expansion at write time. Safe.
STUBDIR=$(mktemp -d -p "$WORK" …) Stub lives in the test's own temp tree. Safe.
PATH="$STUBDIR:$PATH" prepend Scoped to a subshell (…). The stub directory is test-controlled. Standard tool-substitution testing pattern. Safe.
env -u CLAUDE_PROJECT_DIR Intentional; tests the headless/unset-var code path. Safe.
printf '{"tool_input":{"file_path":"%s"},…}' "$REPO_OLDSHFMT/x.sh" JSON construction via %s. $REPO_OLDSHFMT is "$WORK/old-shfmt" — a mktemp-derived path with no special characters. No attacker-controlled input reaches this format string in any test invocation. Safe in context.
bash "$HOOK" $HOOK is set at test startup to the hook under test. No injection.
f="${*: -1}" in stub body (line 297) $* joins args on $IFS; a path with spaces would be mangled. The file argument is always a mktemp-derived path without spaces, so this does not fail in practice. This is the code-quality nit already flagged by the prior code review (${@: -1} is the robust form) — not a security vulnerability given the controlled test context.

No command injection, no path traversal, no secrets exposed, no privilege escalation, no dangerous CI patterns. Temp-dir cleanup via trap … EXIT (pre-existing) covers the new dirs created under $WORK.

@kyle-sexton
kyle-sexton merged commit 37cb309 into main Jul 23, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the docs/1168-bash-format-polish branch July 23, 2026 18:37
kyle-sexton added a commit that referenced this pull request Jul 23, 2026
…eralize CRLF gotcha; correct install_new render doc (F1-F3) (#1177)

Closes #1176.

Consumer-audit fixes for the claude-ops `plugins` sync skill
(handoff-inbox item `20260723-155027`), re-verified against current
source (0.19.0). Version `0.19.0` → `0.19.1`.

## Changes

- **F1 (bug).** `fleet-state.sh`'s `resolve_default_marketplace`
exact-matched the running plugin root against the version-pinned
`installPath`, so any skew between the session's loaded version and the
installed one — a marketplace `autoUpdate` after session start, or
`sync`'s own Step-3 self-update of claude-ops — broke the primary
no-`--marketplace` path with "could not resolve the default
marketplace". Added a **version-agnostic fallback** matching the
version-stripped `…/cache/<marketplace>/<plugin>` prefix (exact match
still tried first; the marketplace stays distinguishable via the path),
plus a clearer error that prints the searched root and names the skew
cause.
- **F2a (doc).** Generalized `context/gotchas.md`'s CRLF entry from
"this host's `jq` build" to **any captured Windows value** (`python`
print, PowerShell interop, `git config`, CRLF file read): a trailing
`\r` on a constructed `claude plugin` id makes the CLI report `Plugin
"<name>" not found` with the full id passed (marketplace suffix
corrupted), colliding with the bare-name symptom — documented and
cross-referenced both ways.
- **F3a (doc).** `plugins/SKILL.md` now reads an unset
`${user_config.install_new}` — which renders the literal placeholder,
since the manifest `default` is not substituted for an unset key
(verified vs CC 2.1.218) — as the **expected unset state → default
`ask`**, not an invalid value; only an explicitly-set unsupported value
is flagged.

## Verification

- `bash plugins/claude-ops/skills/plugins/scripts/fleet-state.test.sh` →
**28 cases, 0 failed** (new version-skew case green).
- `shellcheck -x -S warning fleet-state.sh` → clean.
- `scripts/check-changed-skills.sh origin/main` → PASS for the `plugins`
skill (runs the fleet-state test).

## Deferred (noted on #1176, not in this PR)

- **F2b:** ship a `sync-sweep.sh` sibling owning the Step 2+3 update
loop (CR-stripping, fail-loud, structured per-id JSON) so `sync.md`
shrinks to "run this, report from its output". Bigger net-new surface
with its own test.
- **F3b:** verify upstream whether a declared `userConfig` default is
*intended* to substitute for an unset key; file a CC docs issue if docs
and behavior disagree. F3a is correct regardless.

## Related

- Handoff-inbox item `20260723-155027-claude-ops-plugins-sync-audit`
(producer: KyleSexton workstation, CC 2.1.218).
- Prior inbox items landed this session: #1171 (bash-format), #1172
(hook-observability + hook-utils).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <[email protected]>
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.

bash-format: docs/tests polish — out-of-project scope docs, opt-in/shfmt test coverage, setup Gotchas (F1, F2-local, F6)

1 participant