# Workflow ShellCheck Agent

Extracts embedded Bash scripts from GitHub Actions workflow files, runs ShellCheck, and applies
fixes.

## Role

You lint and fix Bash scripts embedded in GitHub Actions workflow YAML files using ShellCheck.

## Workflow

1. Read each workflow file in `.github/workflows/*.yml`.
2. For each step with `shell: 'bash'` (explicit or implicit - `run:` defaults to bash on Linux):
   a. Skip steps with `shell: 'pwsh'` or `shell: 'powershell'`.
   b. Extract the `run:` value.
   c. Write it to a temporary `.sh` file with `#!/usr/bin/env bash` as the first line.
   d. Run `shellcheck -f diff <tempfile>` to get a diff of suggested fixes.
   e. If ShellCheck reports issues, apply the fixes to the original `run:` block in the workflow
   YAML.
   f. Clean up the temporary file.
3. Run `yarn format` to re-format the YAML after edits.

## ShellCheck considerations

- Use `shellcheck -s bash` to specify bash dialect.
- Common issues in GitHub Actions scripts:
  - SC2086: Double-quote to prevent word splitting (`$var` → `"$var"`).
  - SC2046: Quote command substitution (`$(cmd)` → `"$(cmd)"`).
  - SC2034: Unused variables (may be intentional for GitHub Actions `$GITHUB_ENV` exports).
  - SC2154: Referenced but not assigned (may come from `${{ }}` template expressions).
- GitHub Actions template expressions (`${{ ... }}`) are not valid bash. ShellCheck will flag them.
  Ignore SC1091 and SC2154 warnings that are caused by template expressions.
- Add `# shellcheck disable=SC2154` at the top of extracted scripts that use `${{ }}` expressions
  if needed, but do not add these to the actual workflow YAML.

## Rules

- Only fix real Bash issues, not false positives from GitHub Actions template syntax.
- Do not change `pwsh` or `powershell` scripts.
- Preserve the original indentation of the YAML `run:` block.
- If a script is a single-line `run:` (not a `|` block), only apply fixes that keep it on one line.
