autonomous-coding-toolkit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +22 -0
- package/.claude-plugin/plugin.json +13 -0
- package/LICENSE +21 -0
- package/Makefile +21 -0
- package/README.md +140 -0
- package/SECURITY.md +28 -0
- package/agents/bash-expert.md +113 -0
- package/agents/dependency-auditor.md +138 -0
- package/agents/integration-tester.md +120 -0
- package/agents/lesson-scanner.md +149 -0
- package/agents/python-expert.md +179 -0
- package/agents/service-monitor.md +141 -0
- package/agents/shell-expert.md +147 -0
- package/benchmarks/runner.sh +147 -0
- package/benchmarks/tasks/01-rest-endpoint/rubric.sh +29 -0
- package/benchmarks/tasks/01-rest-endpoint/task.md +17 -0
- package/benchmarks/tasks/02-refactor-module/task.md +8 -0
- package/benchmarks/tasks/03-fix-integration-bug/task.md +8 -0
- package/benchmarks/tasks/04-add-test-coverage/task.md +8 -0
- package/benchmarks/tasks/05-multi-file-feature/task.md +8 -0
- package/bin/act.js +238 -0
- package/commands/autocode.md +6 -0
- package/commands/cancel-ralph.md +18 -0
- package/commands/code-factory.md +53 -0
- package/commands/create-prd.md +55 -0
- package/commands/ralph-loop.md +18 -0
- package/commands/run-plan.md +117 -0
- package/commands/submit-lesson.md +122 -0
- package/docs/ARCHITECTURE.md +630 -0
- package/docs/CONTRIBUTING.md +125 -0
- package/docs/lessons/0001-bare-exception-swallowing.md +34 -0
- package/docs/lessons/0002-async-def-without-await.md +28 -0
- package/docs/lessons/0003-create-task-without-callback.md +28 -0
- package/docs/lessons/0004-hardcoded-test-counts.md +28 -0
- package/docs/lessons/0005-sqlite-without-closing.md +33 -0
- package/docs/lessons/0006-venv-pip-path.md +27 -0
- package/docs/lessons/0007-runner-state-self-rejection.md +35 -0
- package/docs/lessons/0008-quality-gate-blind-spot.md +33 -0
- package/docs/lessons/0009-parser-overcount-empty-batches.md +36 -0
- package/docs/lessons/0010-local-outside-function-bash.md +33 -0
- package/docs/lessons/0011-batch-tests-for-unimplemented-code.md +36 -0
- package/docs/lessons/0012-api-markdown-unescaped-chars.md +33 -0
- package/docs/lessons/0013-export-prefix-env-parsing.md +33 -0
- package/docs/lessons/0014-decorator-registry-import-side-effect.md +43 -0
- package/docs/lessons/0015-frontend-backend-schema-drift.md +43 -0
- package/docs/lessons/0016-event-driven-cold-start-seeding.md +44 -0
- package/docs/lessons/0017-copy-paste-logic-diverges.md +43 -0
- package/docs/lessons/0018-layer-passes-pipeline-broken.md +45 -0
- package/docs/lessons/0019-systemd-envfile-ignores-export.md +41 -0
- package/docs/lessons/0020-persist-state-incrementally.md +44 -0
- package/docs/lessons/0021-dual-axis-testing.md +48 -0
- package/docs/lessons/0022-jsx-factory-shadowing.md +43 -0
- package/docs/lessons/0023-static-analysis-spiral.md +51 -0
- package/docs/lessons/0024-shared-pipeline-implementation.md +55 -0
- package/docs/lessons/0025-defense-in-depth-all-entry-points.md +65 -0
- package/docs/lessons/0026-linter-no-rules-false-enforcement.md +54 -0
- package/docs/lessons/0027-jsx-silent-prop-drop.md +64 -0
- package/docs/lessons/0028-no-infrastructure-in-client-code.md +49 -0
- package/docs/lessons/0029-never-write-secrets-to-files.md +61 -0
- package/docs/lessons/0030-cache-merge-not-replace.md +62 -0
- package/docs/lessons/0031-verify-units-at-boundaries.md +66 -0
- package/docs/lessons/0032-module-lifecycle-subscribe-unsubscribe.md +89 -0
- package/docs/lessons/0033-async-iteration-mutable-snapshot.md +72 -0
- package/docs/lessons/0034-caller-missing-await-silent-discard.md +65 -0
- package/docs/lessons/0035-duplicate-registration-silent-overwrite.md +85 -0
- package/docs/lessons/0036-websocket-dirty-disconnect.md +33 -0
- package/docs/lessons/0037-parallel-agents-worktree-corruption.md +31 -0
- package/docs/lessons/0038-subscribe-no-stored-ref.md +36 -0
- package/docs/lessons/0039-fallback-or-default-hides-bugs.md +34 -0
- package/docs/lessons/0040-event-firehose-filter-first.md +36 -0
- package/docs/lessons/0041-ambiguous-base-dir-path-nesting.md +32 -0
- package/docs/lessons/0042-spec-compliance-insufficient.md +36 -0
- package/docs/lessons/0043-exact-count-extensible-collections.md +32 -0
- package/docs/lessons/0044-relative-file-deps-worktree.md +39 -0
- package/docs/lessons/0045-iterative-design-improvement.md +33 -0
- package/docs/lessons/0046-plan-assertion-math-bugs.md +38 -0
- package/docs/lessons/0047-pytest-single-threaded-default.md +37 -0
- package/docs/lessons/0048-integration-wiring-batch.md +40 -0
- package/docs/lessons/0049-ab-verification.md +41 -0
- package/docs/lessons/0050-editing-sourced-files-during-execution.md +33 -0
- package/docs/lessons/0051-infrastructure-fixes-cant-self-heal.md +30 -0
- package/docs/lessons/0052-uncommitted-changes-poison-quality-gates.md +31 -0
- package/docs/lessons/0053-jq-compact-flag-inconsistency.md +31 -0
- package/docs/lessons/0054-parser-matches-inside-code-blocks.md +30 -0
- package/docs/lessons/0055-agents-compensate-for-garbled-prompts.md +31 -0
- package/docs/lessons/0056-grep-count-exit-code-on-zero.md +42 -0
- package/docs/lessons/0057-new-artifacts-break-git-clean-gates.md +42 -0
- package/docs/lessons/0058-dead-config-keys-never-consumed.md +49 -0
- package/docs/lessons/0059-contract-test-shared-structures.md +53 -0
- package/docs/lessons/0060-set-e-silent-death-in-runners.md +53 -0
- package/docs/lessons/0061-context-injection-dirty-state.md +50 -0
- package/docs/lessons/0062-sibling-bug-neighborhood-scan.md +29 -0
- package/docs/lessons/0063-one-flag-two-lifetimes.md +31 -0
- package/docs/lessons/0064-test-passes-wrong-reason.md +31 -0
- package/docs/lessons/0065-pipefail-grep-count-double-output.md +39 -0
- package/docs/lessons/0066-local-keyword-outside-function.md +37 -0
- package/docs/lessons/0067-stdin-hang-non-interactive-shell.md +36 -0
- package/docs/lessons/0068-agent-builds-wrong-thing-correctly.md +31 -0
- package/docs/lessons/0069-plan-quality-dominates-execution.md +30 -0
- package/docs/lessons/0070-spec-echo-back-prevents-drift.md +31 -0
- package/docs/lessons/0071-positive-instructions-outperform-negative.md +30 -0
- package/docs/lessons/0072-lost-in-the-middle-context-placement.md +30 -0
- package/docs/lessons/0073-unscoped-lessons-cause-false-positives.md +30 -0
- package/docs/lessons/0074-stale-context-injection-wrong-batch.md +32 -0
- package/docs/lessons/0075-research-artifacts-must-persist.md +32 -0
- package/docs/lessons/0076-wrong-decomposition-contaminates-downstream.md +30 -0
- package/docs/lessons/0077-cherry-pick-merges-need-manual-resolution.md +30 -0
- package/docs/lessons/0078-static-review-without-live-test.md +30 -0
- package/docs/lessons/0079-integration-wiring-batch-required.md +32 -0
- package/docs/lessons/FRAMEWORK.md +161 -0
- package/docs/lessons/SUMMARY.md +201 -0
- package/docs/lessons/TEMPLATE.md +85 -0
- package/docs/plans/2026-02-21-code-factory-v2-design.md +204 -0
- package/docs/plans/2026-02-21-code-factory-v2-implementation-plan.md +2189 -0
- package/docs/plans/2026-02-21-code-factory-v2-phase4-design.md +537 -0
- package/docs/plans/2026-02-21-code-factory-v2-phase4-implementation-plan.md +2012 -0
- package/docs/plans/2026-02-21-hardening-pass-design.md +108 -0
- package/docs/plans/2026-02-21-hardening-pass-plan.md +1378 -0
- package/docs/plans/2026-02-21-mab-research-report.md +406 -0
- package/docs/plans/2026-02-21-marketplace-restructure-design.md +240 -0
- package/docs/plans/2026-02-21-marketplace-restructure-plan.md +832 -0
- package/docs/plans/2026-02-21-phase4-completion-plan.md +697 -0
- package/docs/plans/2026-02-21-validator-suite-design.md +148 -0
- package/docs/plans/2026-02-21-validator-suite-plan.md +540 -0
- package/docs/plans/2026-02-22-mab-research-round2.md +556 -0
- package/docs/plans/2026-02-22-mab-run-design.md +462 -0
- package/docs/plans/2026-02-22-mab-run-plan.md +2046 -0
- package/docs/plans/2026-02-22-operations-design-methodology-research.md +681 -0
- package/docs/plans/2026-02-22-research-agent-failure-taxonomy.md +532 -0
- package/docs/plans/2026-02-22-research-code-guideline-policies.md +886 -0
- package/docs/plans/2026-02-22-research-codebase-audit-refactoring.md +908 -0
- package/docs/plans/2026-02-22-research-coding-standards-documentation.md +541 -0
- package/docs/plans/2026-02-22-research-competitive-landscape.md +687 -0
- package/docs/plans/2026-02-22-research-comprehensive-testing.md +1076 -0
- package/docs/plans/2026-02-22-research-context-utilization.md +459 -0
- package/docs/plans/2026-02-22-research-cost-quality-tradeoff.md +548 -0
- package/docs/plans/2026-02-22-research-lesson-transferability.md +508 -0
- package/docs/plans/2026-02-22-research-multi-agent-coordination.md +312 -0
- package/docs/plans/2026-02-22-research-phase-integration.md +602 -0
- package/docs/plans/2026-02-22-research-plan-quality.md +428 -0
- package/docs/plans/2026-02-22-research-prompt-engineering.md +558 -0
- package/docs/plans/2026-02-22-research-unconventional-perspectives.md +528 -0
- package/docs/plans/2026-02-22-research-user-adoption.md +638 -0
- package/docs/plans/2026-02-22-research-verification-effectiveness.md +433 -0
- package/docs/plans/2026-02-23-agent-suite-design.md +299 -0
- package/docs/plans/2026-02-23-agent-suite-plan.md +578 -0
- package/docs/plans/2026-02-23-phase3-cost-infrastructure-design.md +148 -0
- package/docs/plans/2026-02-23-phase3-cost-infrastructure-plan.md +1062 -0
- package/docs/plans/2026-02-23-research-bash-expert-agent.md +543 -0
- package/docs/plans/2026-02-23-research-dependency-auditor-agent.md +564 -0
- package/docs/plans/2026-02-23-research-improving-existing-agents.md +503 -0
- package/docs/plans/2026-02-23-research-integration-tester-agent.md +454 -0
- package/docs/plans/2026-02-23-research-python-expert-agent.md +429 -0
- package/docs/plans/2026-02-23-research-service-monitor-agent.md +425 -0
- package/docs/plans/2026-02-23-research-shell-expert-agent.md +533 -0
- package/docs/plans/2026-02-23-roadmap-to-completion.md +530 -0
- package/docs/plans/2026-02-24-headless-module-split-design.md +98 -0
- package/docs/plans/2026-02-24-headless-module-split.md +443 -0
- package/docs/plans/2026-02-24-lesson-scope-metadata-design.md +228 -0
- package/docs/plans/2026-02-24-lesson-scope-metadata-plan.md +968 -0
- package/docs/plans/2026-02-24-npm-packaging-design.md +841 -0
- package/docs/plans/2026-02-24-npm-packaging-plan.md +1965 -0
- package/docs/plans/audit-findings.md +186 -0
- package/docs/telegram-notification-format.md +98 -0
- package/examples/example-plan.md +51 -0
- package/examples/example-prd.json +72 -0
- package/examples/example-roadmap.md +33 -0
- package/examples/quickstart-plan.md +63 -0
- package/hooks/hooks.json +26 -0
- package/hooks/setup-symlinks.sh +48 -0
- package/hooks/stop-hook.sh +135 -0
- package/package.json +47 -0
- package/policies/bash.md +71 -0
- package/policies/python.md +71 -0
- package/policies/testing.md +61 -0
- package/policies/universal.md +60 -0
- package/scripts/analyze-report.sh +97 -0
- package/scripts/architecture-map.sh +145 -0
- package/scripts/auto-compound.sh +273 -0
- package/scripts/batch-audit.sh +42 -0
- package/scripts/batch-test.sh +101 -0
- package/scripts/entropy-audit.sh +221 -0
- package/scripts/failure-digest.sh +51 -0
- package/scripts/generate-ast-rules.sh +96 -0
- package/scripts/init.sh +112 -0
- package/scripts/lesson-check.sh +428 -0
- package/scripts/lib/common.sh +61 -0
- package/scripts/lib/cost-tracking.sh +153 -0
- package/scripts/lib/ollama.sh +60 -0
- package/scripts/lib/progress-writer.sh +128 -0
- package/scripts/lib/run-plan-context.sh +215 -0
- package/scripts/lib/run-plan-echo-back.sh +231 -0
- package/scripts/lib/run-plan-headless.sh +396 -0
- package/scripts/lib/run-plan-notify.sh +57 -0
- package/scripts/lib/run-plan-parser.sh +81 -0
- package/scripts/lib/run-plan-prompt.sh +215 -0
- package/scripts/lib/run-plan-quality-gate.sh +132 -0
- package/scripts/lib/run-plan-routing.sh +315 -0
- package/scripts/lib/run-plan-sampling.sh +170 -0
- package/scripts/lib/run-plan-scoring.sh +146 -0
- package/scripts/lib/run-plan-state.sh +142 -0
- package/scripts/lib/run-plan-team.sh +199 -0
- package/scripts/lib/telegram.sh +54 -0
- package/scripts/lib/thompson-sampling.sh +176 -0
- package/scripts/license-check.sh +74 -0
- package/scripts/mab-run.sh +575 -0
- package/scripts/module-size-check.sh +146 -0
- package/scripts/patterns/async-no-await.yml +5 -0
- package/scripts/patterns/bare-except.yml +6 -0
- package/scripts/patterns/empty-catch.yml +6 -0
- package/scripts/patterns/hardcoded-localhost.yml +9 -0
- package/scripts/patterns/retry-loop-no-backoff.yml +12 -0
- package/scripts/pipeline-status.sh +197 -0
- package/scripts/policy-check.sh +226 -0
- package/scripts/prior-art-search.sh +133 -0
- package/scripts/promote-mab-lessons.sh +126 -0
- package/scripts/prompts/agent-a-superpowers.md +29 -0
- package/scripts/prompts/agent-b-ralph.md +29 -0
- package/scripts/prompts/judge-agent.md +61 -0
- package/scripts/prompts/planner-agent.md +44 -0
- package/scripts/pull-community-lessons.sh +90 -0
- package/scripts/quality-gate.sh +266 -0
- package/scripts/research-gate.sh +90 -0
- package/scripts/run-plan.sh +329 -0
- package/scripts/scope-infer.sh +159 -0
- package/scripts/setup-ralph-loop.sh +155 -0
- package/scripts/telemetry.sh +230 -0
- package/scripts/tests/run-all-tests.sh +52 -0
- package/scripts/tests/test-act-cli.sh +46 -0
- package/scripts/tests/test-agents-md.sh +87 -0
- package/scripts/tests/test-analyze-report.sh +114 -0
- package/scripts/tests/test-architecture-map.sh +89 -0
- package/scripts/tests/test-auto-compound.sh +169 -0
- package/scripts/tests/test-batch-test.sh +65 -0
- package/scripts/tests/test-benchmark-runner.sh +25 -0
- package/scripts/tests/test-common.sh +168 -0
- package/scripts/tests/test-cost-tracking.sh +158 -0
- package/scripts/tests/test-echo-back.sh +180 -0
- package/scripts/tests/test-entropy-audit.sh +146 -0
- package/scripts/tests/test-failure-digest.sh +66 -0
- package/scripts/tests/test-generate-ast-rules.sh +145 -0
- package/scripts/tests/test-helpers.sh +82 -0
- package/scripts/tests/test-init.sh +47 -0
- package/scripts/tests/test-lesson-check.sh +278 -0
- package/scripts/tests/test-lesson-local.sh +55 -0
- package/scripts/tests/test-license-check.sh +109 -0
- package/scripts/tests/test-mab-run.sh +182 -0
- package/scripts/tests/test-ollama-lib.sh +49 -0
- package/scripts/tests/test-ollama.sh +60 -0
- package/scripts/tests/test-pipeline-status.sh +198 -0
- package/scripts/tests/test-policy-check.sh +124 -0
- package/scripts/tests/test-prior-art-search.sh +96 -0
- package/scripts/tests/test-progress-writer.sh +140 -0
- package/scripts/tests/test-promote-mab-lessons.sh +110 -0
- package/scripts/tests/test-pull-community-lessons.sh +149 -0
- package/scripts/tests/test-quality-gate.sh +241 -0
- package/scripts/tests/test-research-gate.sh +132 -0
- package/scripts/tests/test-run-plan-cli.sh +86 -0
- package/scripts/tests/test-run-plan-context.sh +305 -0
- package/scripts/tests/test-run-plan-e2e.sh +153 -0
- package/scripts/tests/test-run-plan-headless.sh +424 -0
- package/scripts/tests/test-run-plan-notify.sh +124 -0
- package/scripts/tests/test-run-plan-parser.sh +217 -0
- package/scripts/tests/test-run-plan-prompt.sh +254 -0
- package/scripts/tests/test-run-plan-quality-gate.sh +222 -0
- package/scripts/tests/test-run-plan-routing.sh +178 -0
- package/scripts/tests/test-run-plan-scoring.sh +148 -0
- package/scripts/tests/test-run-plan-state.sh +261 -0
- package/scripts/tests/test-run-plan-team.sh +157 -0
- package/scripts/tests/test-scope-infer.sh +150 -0
- package/scripts/tests/test-setup-ralph-loop.sh +63 -0
- package/scripts/tests/test-telegram-env.sh +38 -0
- package/scripts/tests/test-telegram.sh +121 -0
- package/scripts/tests/test-telemetry.sh +46 -0
- package/scripts/tests/test-thompson-sampling.sh +139 -0
- package/scripts/tests/test-validate-all.sh +60 -0
- package/scripts/tests/test-validate-commands.sh +89 -0
- package/scripts/tests/test-validate-hooks.sh +98 -0
- package/scripts/tests/test-validate-lessons.sh +150 -0
- package/scripts/tests/test-validate-plan-quality.sh +235 -0
- package/scripts/tests/test-validate-plans.sh +187 -0
- package/scripts/tests/test-validate-plugin.sh +106 -0
- package/scripts/tests/test-validate-prd.sh +184 -0
- package/scripts/tests/test-validate-skills.sh +134 -0
- package/scripts/validate-all.sh +57 -0
- package/scripts/validate-commands.sh +67 -0
- package/scripts/validate-hooks.sh +89 -0
- package/scripts/validate-lessons.sh +98 -0
- package/scripts/validate-plan-quality.sh +369 -0
- package/scripts/validate-plans.sh +120 -0
- package/scripts/validate-plugin.sh +86 -0
- package/scripts/validate-policies.sh +42 -0
- package/scripts/validate-prd.sh +118 -0
- package/scripts/validate-skills.sh +96 -0
- package/skills/autocode/SKILL.md +285 -0
- package/skills/autocode/ab-verification.md +51 -0
- package/skills/autocode/code-quality-standards.md +37 -0
- package/skills/autocode/competitive-mode.md +364 -0
- package/skills/brainstorming/SKILL.md +97 -0
- package/skills/capture-lesson/SKILL.md +187 -0
- package/skills/check-lessons/SKILL.md +116 -0
- package/skills/dispatching-parallel-agents/SKILL.md +110 -0
- package/skills/executing-plans/SKILL.md +85 -0
- package/skills/finishing-a-development-branch/SKILL.md +201 -0
- package/skills/receiving-code-review/SKILL.md +72 -0
- package/skills/requesting-code-review/SKILL.md +59 -0
- package/skills/requesting-code-review/code-reviewer.md +82 -0
- package/skills/research/SKILL.md +145 -0
- package/skills/roadmap/SKILL.md +115 -0
- package/skills/subagent-driven-development/SKILL.md +98 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +18 -0
- package/skills/subagent-driven-development/implementer-prompt.md +73 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +57 -0
- package/skills/systematic-debugging/SKILL.md +134 -0
- package/skills/systematic-debugging/condition-based-waiting.md +64 -0
- package/skills/systematic-debugging/defense-in-depth.md +32 -0
- package/skills/systematic-debugging/root-cause-tracing.md +55 -0
- package/skills/test-driven-development/SKILL.md +167 -0
- package/skills/using-git-worktrees/SKILL.md +219 -0
- package/skills/using-superpowers/SKILL.md +54 -0
- package/skills/verification-before-completion/SKILL.md +140 -0
- package/skills/verify/SKILL.md +82 -0
- package/skills/writing-plans/SKILL.md +128 -0
- package/skills/writing-skills/SKILL.md +93 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
# Research: Bash Expert Claude Code Agent
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-02-23
|
|
4
|
+
**Status:** Complete
|
|
5
|
+
**Confidence:** High on tooling landscape and rules; High on agent structure (strong existing reference from 0xfurai)
|
|
6
|
+
**Cynefin domain:** Complicated — knowable with synthesis of existing patterns
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## BLUF
|
|
11
|
+
|
|
12
|
+
A bash expert agent for this toolkit should be built as a **review-mode Claude Code subagent** that wraps the same pattern as `python-expert.md`. The 0xfurai `bash-expert.md` agent is the strongest reference available — its rule set is well-synthesized from ShellCheck, Google Shell Style Guide, and BashPitfalls. The agent's value-add over raw ShellCheck is contextual judgment: detecting architectural anti-patterns (silent failure, unsafe temp handling, injection vectors) that static analysis misses. Build as `.claude/agents/bash-expert.md` with tools `Read, Grep, Glob, Bash`.
|
|
13
|
+
|
|
14
|
+
**Recommended structure:** Focus area checklist (20 rules) → scan workflow (grep patterns) → output format (findings by severity). Use `model: sonnet` — judgment is needed but not at opus depth for most script review.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Section 1: Claude Code Custom Agents for Bash/Shell
|
|
19
|
+
|
|
20
|
+
### Sources
|
|
21
|
+
|
|
22
|
+
- [0xfurai/claude-code-subagents](https://github.com/0xfurai/claude-code-subagents) — 100+ production subagents; contains `bash-expert.md`
|
|
23
|
+
- [VoltAgent/awesome-claude-code-subagents](https://github.com/VoltAgent/awesome-claude-code-subagents) — 100+ subagents; no bash-specific agent, has `devops-engineer.md`
|
|
24
|
+
- [wshobson/agents](https://github.com/wshobson/agents) — 112 agents in 72 plugins; DevOps/infrastructure category present but prompts not publicly inspectable
|
|
25
|
+
- [Anthropic subagent docs](https://code.claude.com/docs/en/sub-agents) — official YAML frontmatter schema
|
|
26
|
+
|
|
27
|
+
### Key Findings
|
|
28
|
+
|
|
29
|
+
**0xfurai bash-expert.md — Best existing reference.**
|
|
30
|
+
|
|
31
|
+
Full frontmatter and system prompt retrieved:
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
---
|
|
35
|
+
name: bash-expert
|
|
36
|
+
description: Master of defensive Bash scripting for production automation, CI/CD
|
|
37
|
+
pipelines, and system utilities. Expert in safe, portable, and testable shell scripts.
|
|
38
|
+
model: claude-sonnet-4-20250514
|
|
39
|
+
---
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Focus areas it claims:
|
|
43
|
+
- Defensive programming with strict error handling
|
|
44
|
+
- POSIX compliance and cross-platform portability
|
|
45
|
+
- Safe argument parsing and input validation
|
|
46
|
+
- Robust file operations and temporary resource management
|
|
47
|
+
- Process orchestration and pipeline safety
|
|
48
|
+
- Production-grade logging and error reporting
|
|
49
|
+
- Comprehensive testing with Bats framework
|
|
50
|
+
- Static analysis with ShellCheck and formatting with shfmt
|
|
51
|
+
|
|
52
|
+
Approach rules (verbatim, these are the operational patterns):
|
|
53
|
+
- Always use strict mode with `set -Eeuo pipefail` and proper error trapping
|
|
54
|
+
- Quote all variable expansions to prevent word splitting and globbing
|
|
55
|
+
- Prefer arrays over unsafe `for f in $(ls)` patterns
|
|
56
|
+
- Use `[[ ]]` for Bash conditionals, fall back to `[ ]` for POSIX compliance
|
|
57
|
+
- Implement comprehensive argument parsing with `getopts` and usage functions
|
|
58
|
+
- Create temp files/dirs safely with `mktemp` and cleanup traps
|
|
59
|
+
- Prefer `printf` over `echo` for predictable output
|
|
60
|
+
- Use `$()` instead of backticks
|
|
61
|
+
- Use `shopt -s inherit_errexit` for better error propagation in Bash 4.4+
|
|
62
|
+
- Use `IFS=$'\n\t'` to prevent unwanted word splitting on spaces
|
|
63
|
+
- Validate inputs with `: "${VAR:?message}"` for required env vars
|
|
64
|
+
- End option parsing with `--` and use `rm -rf -- "$dir"` for safe ops
|
|
65
|
+
- Support `--trace` with `set -x` opt-in for debugging
|
|
66
|
+
- Use `xargs -0` with NUL boundaries for safe subprocess orchestration
|
|
67
|
+
- Use `readarray`/`mapfile` for safe array population from command output
|
|
68
|
+
- Implement reliable script directory detection: `SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"`
|
|
69
|
+
- Use NUL-safe patterns: `find -print0 | while IFS= read -r -d '' file; do ...; done`
|
|
70
|
+
|
|
71
|
+
Quality checklist (what it outputs):
|
|
72
|
+
- Scripts pass ShellCheck with minimal suppressions
|
|
73
|
+
- Formatted with shfmt `-i 2 -ci -bn -sr -kp`
|
|
74
|
+
- Bats test coverage including edge cases
|
|
75
|
+
- All variable expansions quoted
|
|
76
|
+
- Error handling covers all failure modes with meaningful messages
|
|
77
|
+
- Temp resources cleaned up with EXIT traps
|
|
78
|
+
- `--help` and clear usage information
|
|
79
|
+
- Input validation prevents injection attacks
|
|
80
|
+
- Portable across Linux and macOS
|
|
81
|
+
- Performance adequate for expected workloads
|
|
82
|
+
|
|
83
|
+
Advanced techniques it references:
|
|
84
|
+
- Error context via `trap 'echo "Error at line $LINENO: exit $?" >&2' ERR`
|
|
85
|
+
- Safe temp: `trap 'rm -rf "$tmpdir"' EXIT; tmpdir=$(mktemp -d)`
|
|
86
|
+
- Version checking: `(( BASH_VERSINFO[0] >= 5 ))` before modern features
|
|
87
|
+
- Binary-safe arrays: `readarray -d '' files < <(find . -print0)`
|
|
88
|
+
- Function return via `declare -g result` for complex data
|
|
89
|
+
|
|
90
|
+
**What it does well:** Operational specificity. Every rule is a concrete pattern, not advice. References the right authoritative sources. Correctly identifies ShellCheck + shfmt + Bats as the toolchain.
|
|
91
|
+
|
|
92
|
+
**What it lacks:** No project-specific scan patterns, no grep-based detection workflow, no severity classification of rules. The description is too generic — "production automation, CI/CD pipelines" will cause it to be invoked for too broad a set of tasks.
|
|
93
|
+
|
|
94
|
+
**VoltAgent devops-engineer.md — Generic, not adopting.**
|
|
95
|
+
|
|
96
|
+
The devops-engineer agent covers container orchestration, Kubernetes, cloud IaC, CI/CD pipeline design — scope is too broad and not bash-specific. Checklist-driven but no concrete bash patterns. Not adopting.
|
|
97
|
+
|
|
98
|
+
**Structural pattern (adopted from both sources):**
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
---
|
|
102
|
+
name: bash-expert
|
|
103
|
+
description: "Use this agent when reviewing, writing, or debugging bash/shell scripts.
|
|
104
|
+
Triggers on: script creation, CI shell steps, hook scripts, systemd ExecStart lines,
|
|
105
|
+
Makefile shell targets, and any .sh file review."
|
|
106
|
+
tools: Read, Grep, Glob, Bash
|
|
107
|
+
model: sonnet
|
|
108
|
+
---
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Description specificity matters: the description field drives automatic dispatch. Too broad = false invocations. The description above names concrete trigger contexts.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Section 2: Bash Code Review Bots and Automated Reviewers
|
|
116
|
+
|
|
117
|
+
### Sources
|
|
118
|
+
|
|
119
|
+
- [reviewdog/reviewdog](https://github.com/reviewdog/reviewdog) — Automated code review tool, integrates with any analysis tool
|
|
120
|
+
- [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck) — ShellCheck as GitHub Actions PR review
|
|
121
|
+
- [Microsoft Engineering Playbook — Bash Code Reviews](https://microsoft.github.io/code-with-engineering-playbook/code-reviews/recipes/bash/)
|
|
122
|
+
- [qiniu/reviewbot](https://github.com/qiniu/reviewbot) — AI-powered self-hosted review
|
|
123
|
+
|
|
124
|
+
### Key Findings
|
|
125
|
+
|
|
126
|
+
**reviewdog/action-shellcheck — Primary CI integration pattern.**
|
|
127
|
+
|
|
128
|
+
Configuration options:
|
|
129
|
+
- `shellcheck_flags: --external-sources` (default) — follows sourced files
|
|
130
|
+
- `level`: info | warning | error — controls PR comment severity threshold
|
|
131
|
+
- `pattern: "*.sh"` — extend to `*.bash` and files with shebangs via `check_all_files_with_shebangs: true`
|
|
132
|
+
- `fail_level: error` — only block PRs on errors, warnings annotate only
|
|
133
|
+
- `reporter: github-pr-review` — inline PR comments with links to ShellCheck wiki
|
|
134
|
+
|
|
135
|
+
Recommended `.github/workflows/shellcheck.yml` pattern:
|
|
136
|
+
```yaml
|
|
137
|
+
permissions:
|
|
138
|
+
contents: read
|
|
139
|
+
pull-requests: write
|
|
140
|
+
checks: write
|
|
141
|
+
|
|
142
|
+
- uses: reviewdog/action-shellcheck@v1
|
|
143
|
+
with:
|
|
144
|
+
shellcheck_flags: "--external-sources --enable=all"
|
|
145
|
+
reporter: github-pr-review
|
|
146
|
+
fail_level: error
|
|
147
|
+
check_all_files_with_shebangs: true
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**What to adopt:** The `--enable=all` flag activates ShellCheck's optional checks (not on by default). Worth enabling in the agent's quality checklist.
|
|
151
|
+
|
|
152
|
+
**Microsoft Engineering Playbook — Review checklist source.**
|
|
153
|
+
|
|
154
|
+
Checklist items extracted:
|
|
155
|
+
- Does the code pass ShellCheck?
|
|
156
|
+
- Does the code follow the Google Shell Style Guide?
|
|
157
|
+
- Is `set -o errexit`, `set -o nounset`, `set -o pipefail` present?
|
|
158
|
+
- Are all variables quoted?
|
|
159
|
+
- Are temporary files cleaned up?
|
|
160
|
+
- Are error messages going to stderr?
|
|
161
|
+
- Are return codes checked after unpiped commands?
|
|
162
|
+
|
|
163
|
+
**What to adopt:** The playbook's review checklist maps directly to what the agent should emit as findings. Use these as the severity-HIGH category.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Section 3: Shell Script Best Practices in CI
|
|
168
|
+
|
|
169
|
+
### Sources
|
|
170
|
+
|
|
171
|
+
- [codica2/script-best-practices](https://github.com/codica2/script-best-practices) — Clean-code-influenced bash rules
|
|
172
|
+
- [ralish/bash-script-template](https://github.com/ralish/bash-script-template) — Production template with `set -eu`, `parse_params()`, `main()`
|
|
173
|
+
- [SixArm/unix-shell-script-tactics](https://github.com/SixArm/unix-shell-script-tactics) — Comprehensive tactics reference
|
|
174
|
+
- [gist: Shell scripting best practices](https://gist.github.com/quangkeu95/31b4b7a7a73cb7543962773b5d0de9ee)
|
|
175
|
+
|
|
176
|
+
### Key Findings
|
|
177
|
+
|
|
178
|
+
**ralish/bash-script-template — Structural template worth adopting.**
|
|
179
|
+
|
|
180
|
+
Patterns:
|
|
181
|
+
- `set -e` (errexit) + `set -u` (nounset) at minimum
|
|
182
|
+
- `parse_params()` function separates argument parsing from business logic
|
|
183
|
+
- `script_usage()` heredoc for help text
|
|
184
|
+
- Modular structure: `source.sh` (stable library functions) + `script.sh` (customizable logic) + `build.sh` (combine)
|
|
185
|
+
- `main()` called at end of file — enables sourcing for testing
|
|
186
|
+
|
|
187
|
+
**SixArm/unix-shell-script-tactics — High density of specific patterns.**
|
|
188
|
+
|
|
189
|
+
Key tactics extracted:
|
|
190
|
+
- `printf` over `echo` — predictable behavior across shells
|
|
191
|
+
- `trap trap_exit EXIT` — guaranteed cleanup
|
|
192
|
+
- `mktemp` for temp files — never predictable names
|
|
193
|
+
- `find -print0 | xargs -0` — NUL-safe file operations
|
|
194
|
+
- Follow XDG base dirs: `$XDG_DATA_HOME`, `$XDG_CONFIG_HOME`, `$XDG_CACHE_HOME`
|
|
195
|
+
- Semantic versioning for scripts with `--version` flag
|
|
196
|
+
- `${VAR:?error}` for required variable validation
|
|
197
|
+
- `set -x` then `set +x` (without logging the disable) for targeted trace
|
|
198
|
+
- Boolean values: use `true`/`false` commands, not 0/1
|
|
199
|
+
- `$()` not backticks — readability and nesting
|
|
200
|
+
- `realpath` or `cd + $BASH_SOURCE` for script directory detection
|
|
201
|
+
- UTC + ISO8601 for timestamps: `$(date -u +%Y-%m-%dT%H:%M:%SZ)`
|
|
202
|
+
- Respect `NO_COLOR` and `TERM=dumb` in color output
|
|
203
|
+
|
|
204
|
+
**codica2/script-best-practices — Clean code application to bash.**
|
|
205
|
+
|
|
206
|
+
Adds:
|
|
207
|
+
- `readonly` for static variables — enforces immutability
|
|
208
|
+
- `local` for all function variables — prevents scope leakage
|
|
209
|
+
- Never hardcode credentials — use `$ENV_VAR` or external vaults
|
|
210
|
+
- `.sh`/`.bash` extension only for sourceable libraries, not executables
|
|
211
|
+
- `$HOME`/`$PWD` over `~` in scripts — tilde expansion not always reliable
|
|
212
|
+
- `[[ ]]` over `[ ]` — avoids POSIX portability at the cost of reliability
|
|
213
|
+
|
|
214
|
+
**What to adopt:** The combination of `ralish` structure + `SixArm` tactics gives a complete defensive pattern vocabulary. The agent should check for violations of the top-20 highest-frequency items.
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Section 4: ShellCheck — Rule Configuration and Key Checks
|
|
219
|
+
|
|
220
|
+
### Sources
|
|
221
|
+
|
|
222
|
+
- [koalaman/shellcheck](https://github.com/koalaman/shellcheck) — Primary static analysis tool
|
|
223
|
+
- [shellcheck.net/wiki](https://www.shellcheck.net/wiki/) — Full rule documentation
|
|
224
|
+
- [shellcheck.1.md](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) — Man page with all flags
|
|
225
|
+
|
|
226
|
+
### Key Rules by Category
|
|
227
|
+
|
|
228
|
+
**Quoting (highest frequency violations):**
|
|
229
|
+
- SC2086 — Double quote variable to prevent globbing/word splitting: `$var` → `"$var"`
|
|
230
|
+
- SC2046 — Quote command substitution to prevent word splitting: `$(cmd)` → `"$(cmd)"`
|
|
231
|
+
- SC2048 — Use `"$@"` not `$*` when passing all arguments
|
|
232
|
+
- SC2206 — Quote to prevent splitting: use array assignment instead
|
|
233
|
+
|
|
234
|
+
**Command substitution:**
|
|
235
|
+
- SC2006 — Use `$(...)` not backtick notation
|
|
236
|
+
- SC2005 — Useless `echo`: `echo $(cmd)` → just `cmd` or `printf '%s\n' "$(cmd)"`
|
|
237
|
+
|
|
238
|
+
**Conditional expressions:**
|
|
239
|
+
- SC2166 — Prefer `[ p ] && [ q ]` over `[ p -a q ]` in `[ ]`
|
|
240
|
+
- SC2039 — In POSIX sh, `[[ ]]` is undefined behavior
|
|
241
|
+
- SC2015 — `A && B || C` is not if-then-else; use proper `if/then/else`
|
|
242
|
+
|
|
243
|
+
**Loops and iteration:**
|
|
244
|
+
- SC2045 — Iterating over `ls` output: use `for f in ./*` instead
|
|
245
|
+
- SC2044 — `for f in $(find ...)`: use `find -exec` or process substitution
|
|
246
|
+
- SC2043 — Loop only runs once; check for missing glob or array
|
|
247
|
+
|
|
248
|
+
**Error handling:**
|
|
249
|
+
- SC2164 — Use `cd ... || exit` to handle failure
|
|
250
|
+
- SC2181 — Check exit code directly: `if cmd; then` not `cmd; if [ $? -eq 0 ]`
|
|
251
|
+
- SC2317 — Command appears unreachable after `exit`/`return`
|
|
252
|
+
|
|
253
|
+
**Variable usage:**
|
|
254
|
+
- SC2034 — Unused variable (often a typo)
|
|
255
|
+
- SC2155 — Declare and assign separately: `local var; var=$(cmd)` — masks exit codes
|
|
256
|
+
- SC2030/SC2031 — Variable modified in subshell not visible to parent
|
|
257
|
+
|
|
258
|
+
**Security-adjacent:**
|
|
259
|
+
- SC2094 — Make sure not to read and write the same file in the same pipeline
|
|
260
|
+
- SC2235 — Use `{ ..; }` or `(..)` to group conditions
|
|
261
|
+
- SC1090/SC1091 — Source file not found (use `--external-sources` to follow them)
|
|
262
|
+
|
|
263
|
+
**Optional checks (enabled with `--enable=all`):**
|
|
264
|
+
- `avoid-nullary-conditions` — `[[ -n $var ]]` over `[[ $var ]]`
|
|
265
|
+
- `check-extra-masked-returns` — detect masked return codes
|
|
266
|
+
- `check-set-e-suppressed` — warn where `set -e` is inadvertently suppressed
|
|
267
|
+
- `deprecate-which` — use `command -v` over `which`
|
|
268
|
+
|
|
269
|
+
**Configuration (`.shellcheckrc`):**
|
|
270
|
+
```ini
|
|
271
|
+
enable=all
|
|
272
|
+
external-sources=true
|
|
273
|
+
shell=bash
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**What to adopt:** The agent should explicitly reference the `enable=all` flag and recommend `.shellcheckrc` in projects. The top-priority rules for manual review (because ShellCheck catches them mechanically but engineers override them without understanding): SC2155 (masked exit code on local+assign), SC2030/SC2031 (subshell variable visibility), SC2015 (false if-then-else via `&&/||`).
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Section 5: Google Shell Style Guide
|
|
281
|
+
|
|
282
|
+
### Source
|
|
283
|
+
|
|
284
|
+
- [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html)
|
|
285
|
+
- [GitHub source](https://github.com/google/styleguide/blob/gh-pages/shellguide.md)
|
|
286
|
+
|
|
287
|
+
### Key Rules
|
|
288
|
+
|
|
289
|
+
**When to use shell (scope gate):**
|
|
290
|
+
- Scripts > 100 lines or with non-trivial control flow: rewrite in Python
|
|
291
|
+
- Mostly calling other utilities with little data manipulation: shell is appropriate
|
|
292
|
+
- All executables must be `#!/bin/bash` — no other shell
|
|
293
|
+
|
|
294
|
+
**File conventions:**
|
|
295
|
+
- Libraries: `.sh` extension, non-executable
|
|
296
|
+
- Executables: no extension (or `.sh` if deployment requires it)
|
|
297
|
+
- Never set SUID/SGID on shell scripts
|
|
298
|
+
|
|
299
|
+
**Error handling:**
|
|
300
|
+
- All error messages to STDERR (not stdout):
|
|
301
|
+
```bash
|
|
302
|
+
err() { echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2; }
|
|
303
|
+
```
|
|
304
|
+
- Check return values: use `if cmd; then` or `cmd || { err "failed"; exit 1; }`
|
|
305
|
+
|
|
306
|
+
**Variable naming:**
|
|
307
|
+
- Functions and local variables: `lowercase_underscore`
|
|
308
|
+
- Constants and environment exports: `UPPER_CASE`
|
|
309
|
+
- Local variables: declare with `local`
|
|
310
|
+
|
|
311
|
+
**Function structure:**
|
|
312
|
+
- All function variables: `local`
|
|
313
|
+
- Functions with globals, args, outputs, or return values: require header comment
|
|
314
|
+
- Scripts with multiple functions: require `main()` called at file end
|
|
315
|
+
|
|
316
|
+
**Formatting:**
|
|
317
|
+
- Indentation: 2 spaces (never tabs outside heredocs)
|
|
318
|
+
- Line length: 80 chars max
|
|
319
|
+
- `; then` and `; do` on same line as `if`/`for`/`while`
|
|
320
|
+
|
|
321
|
+
**Conditionals:**
|
|
322
|
+
- Prefer `[[ ]]` over `[ ]` — more predictable
|
|
323
|
+
- Numeric comparisons: `(( ))` not `[[ ]]`
|
|
324
|
+
- Test strings: always quote: `[[ "${my_var}" == "some_string" ]]`
|
|
325
|
+
|
|
326
|
+
**Arrays:**
|
|
327
|
+
- Use arrays for lists and command arguments (not space-delimited strings)
|
|
328
|
+
- Never use arrays for complex data structures — use Python instead
|
|
329
|
+
|
|
330
|
+
**Prohibited:**
|
|
331
|
+
- `eval` — mangles input, complicates variable assignment
|
|
332
|
+
- Aliases in scripts — use functions
|
|
333
|
+
- Wildcard without path prefix — always use `./` prefix
|
|
334
|
+
|
|
335
|
+
**What to adopt:** The scope gate ("when to use shell" rule) is valuable for the agent to surface when reviewing a script. If it exceeds 100 lines with complex control flow, the agent should flag it. The `err()` function pattern is the standard to recommend.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Section 6: BashPitfalls — Wooledge Wiki
|
|
340
|
+
|
|
341
|
+
### Source
|
|
342
|
+
|
|
343
|
+
- [BashPitfalls — mywiki.wooledge.org](http://mywiki.wooledge.org/BashPitfalls)
|
|
344
|
+
|
|
345
|
+
### Top Pitfalls by Impact
|
|
346
|
+
|
|
347
|
+
These are the patterns most likely to cause silent bugs in production. Ordered by consequence severity:
|
|
348
|
+
|
|
349
|
+
**Silent data corruption / wrong results:**
|
|
350
|
+
1. `for f in $(ls *.mp3)` — word splitting on filenames with spaces; use `for f in ./*.mp3`
|
|
351
|
+
2. `cmd1 && cmd2 || cmd3` — not if-then-else; cmd3 runs if cmd2 fails
|
|
352
|
+
3. `somecmd 2>&1 >>logfile` — wrong order; should be `>>logfile 2>&1`
|
|
353
|
+
4. `[[ $foo = $bar ]]` — unquoted RHS does pattern matching; quote for equality: `[[ $foo = "$bar" ]]`
|
|
354
|
+
5. `grep foo bar | while read; do ((count++)); done` — counter modified in subshell, invisible to parent
|
|
355
|
+
|
|
356
|
+
**Resource / file safety:**
|
|
357
|
+
6. `cat file | sed s/foo/bar/ > file` — reads and writes same file via pipeline; data loss; use temp file
|
|
358
|
+
7. `cp $file $target` — unquoted; breaks on spaces; use `cp -- "$file" "$target"`
|
|
359
|
+
8. `cd /foo; bar` — cd failure not checked; use `cd /foo && bar` or `cd /foo || exit 1`
|
|
360
|
+
|
|
361
|
+
**Array / variable safety:**
|
|
362
|
+
9. `local var=$(cmd)` — `local` swallows exit code; declare separately: `local var; var=$(cmd)`
|
|
363
|
+
10. `hosts=( $(aws ...) )` — unsafe array population; use `readarray -t hosts < <(aws ...)`
|
|
364
|
+
11. `for arg in $*` — loses quoting; use `for arg in "$@"`
|
|
365
|
+
12. `OIFS="$IFS"; ...; IFS="$OIFS"` — use `local IFS` in functions instead
|
|
366
|
+
|
|
367
|
+
**Arithmetic / numeric:**
|
|
368
|
+
13. `[[ $foo > 7 ]]` — string comparison; use `(( foo > 7 ))`
|
|
369
|
+
14. `for i in {1..$n}` — brace expansion doesn't work with variables; use `for ((i=1; i<=n; i++))`
|
|
370
|
+
|
|
371
|
+
**Signal / environment:**
|
|
372
|
+
15. `export CDPATH=.:~/myProject` — never export CDPATH; causes surprising behavior in subshells
|
|
373
|
+
16. `find . -exec sh -c 'echo {}'` — injection via filename; separate: `sh -c 'echo "$1"' x {}`
|
|
374
|
+
17. `sudo mycmd > /myfile` — redirection runs as user not root; use `sudo sh -c 'mycmd > /myfile'`
|
|
375
|
+
|
|
376
|
+
**What to adopt:** Pitfalls 1, 2, 3, 6, 7, 8, 9 are the highest-yield grep targets for a detection scan. The agent should grep for these patterns explicitly, not rely on the user to run ShellCheck separately.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Synthesis: Best Patterns to Adopt
|
|
381
|
+
|
|
382
|
+
### Priority 1 — Blocking Issues (agent must flag, high severity)
|
|
383
|
+
|
|
384
|
+
These patterns cause silent failures, data corruption, or security vulnerabilities:
|
|
385
|
+
|
|
386
|
+
| Pattern | Detection grep | Fix |
|
|
387
|
+
|---------|---------------|-----|
|
|
388
|
+
| Missing strict mode | `^#!/` without `set -Eeuo pipefail` nearby | Add to script header |
|
|
389
|
+
| Unquoted variable expansion | `\$[a-zA-Z_]` outside quotes (not in `[[ ]]`) | Quote: `"$var"` |
|
|
390
|
+
| `local var=$(cmd)` | `local [a-z_]+=\$\(` | `local var; var=$(cmd)` |
|
|
391
|
+
| `cd` without error check | `cd ` not followed by `&&` or `\|\|` | `cd /path || exit 1` |
|
|
392
|
+
| `for f in $(ls` | `for .* in \$\(ls` | `for f in ./*` |
|
|
393
|
+
| Same-file pipe read/write | `> file` after `cat file \|` or `< file` | Use temp file + mv |
|
|
394
|
+
| `2>&1 >>` order | `2>&1 >>` | Reverse to `>>file 2>&1` |
|
|
395
|
+
| `eval` usage | `\beval\b` | Replace with named variable or array |
|
|
396
|
+
| `&&` / `\|\|` as if-else | `\w && .* \|\| ` | Use proper `if/then/else` |
|
|
397
|
+
|
|
398
|
+
### Priority 2 — Quality Issues (agent should flag, medium severity)
|
|
399
|
+
|
|
400
|
+
These patterns reduce reliability and maintainability:
|
|
401
|
+
|
|
402
|
+
| Pattern | Detection | Fix |
|
|
403
|
+
|---------|-----------|-----|
|
|
404
|
+
| Missing `mktemp` for temp files | `/tmp/` literal in script | `tmpfile=$(mktemp)` + trap |
|
|
405
|
+
| Missing EXIT trap | `mktemp` without `trap ... EXIT` | Add `trap 'rm -rf "$tmpdir"' EXIT` |
|
|
406
|
+
| Backtick command substitution | `` ` `` | Use `$()` |
|
|
407
|
+
| `echo` for data output | `^echo \$` | `printf '%s\n' "$var"` |
|
|
408
|
+
| Hardcoded credentials | `(password\|token\|secret\|key)=` | Use env vars |
|
|
409
|
+
| Missing `--` before args | `rm -rf \$` | `rm -rf -- "$var"` |
|
|
410
|
+
| `$*` instead of `"$@"` | `\$\*` | `"$@"` |
|
|
411
|
+
| Arithmetic with `[[ ]]` | `\[\[ .* [><] [0-9]` | Use `(( ))` |
|
|
412
|
+
| `for f in $(find` | `for .* in \$\(find` | `find -print0 \| while IFS= read -r -d ''` |
|
|
413
|
+
| Missing `local` in functions | `function` body without `local` | Declare all function vars with `local` |
|
|
414
|
+
|
|
415
|
+
### Priority 3 — Style (agent notes, low severity)
|
|
416
|
+
|
|
417
|
+
| Pattern | Rule |
|
|
418
|
+
|---------|------|
|
|
419
|
+
| No `main()` function | Add for any script >30 lines |
|
|
420
|
+
| Error messages to stdout | Redirect to `>&2` |
|
|
421
|
+
| No `--help` flag | Add usage function |
|
|
422
|
+
| No `.shellcheckrc` | Create with `enable=all` |
|
|
423
|
+
| UPPERCASE for local vars | Rename to `lowercase_underscore` |
|
|
424
|
+
| 100+ line script with complex logic | Flag: consider Python rewrite |
|
|
425
|
+
|
|
426
|
+
---
|
|
427
|
+
|
|
428
|
+
## Recommended Agent Structure
|
|
429
|
+
|
|
430
|
+
### File: `.claude/agents/bash-expert.md`
|
|
431
|
+
|
|
432
|
+
```yaml
|
|
433
|
+
---
|
|
434
|
+
name: bash-expert
|
|
435
|
+
description: "Use this agent when reviewing, writing, or debugging bash or shell
|
|
436
|
+
scripts. Invoke for: .sh files, CI pipeline shell steps, hook scripts, systemd
|
|
437
|
+
ExecStart shell commands, Makefile shell targets, and heredoc-heavy scripts. Do
|
|
438
|
+
not invoke for Python, Ruby, or other scripted languages."
|
|
439
|
+
tools: Read, Grep, Glob, Bash
|
|
440
|
+
model: sonnet
|
|
441
|
+
---
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
**System prompt structure:**
|
|
445
|
+
|
|
446
|
+
1. **Role statement** — Expert in defensive bash for production automation and CI/CD. Canonical references: Google Shell Style Guide, BashPitfalls, ShellCheck wiki.
|
|
447
|
+
|
|
448
|
+
2. **Scan workflow** — When invoked to review, run in order:
|
|
449
|
+
- Read the target file(s)
|
|
450
|
+
- Grep for Priority 1 blocking patterns (from synthesis table above)
|
|
451
|
+
- Grep for Priority 2 quality patterns
|
|
452
|
+
- Check for missing tooling configuration (`.shellcheckrc`, shfmt config)
|
|
453
|
+
- Run `shellcheck --enable=all --external-sources <file>` if Bash tool available
|
|
454
|
+
- Check scope: is the script > 100 lines with complex control flow?
|
|
455
|
+
|
|
456
|
+
3. **Output format** — Structured finding report:
|
|
457
|
+
```
|
|
458
|
+
BLOCKING (must fix before merge):
|
|
459
|
+
- Line 12: Unquoted variable $USER_INPUT — SC2086
|
|
460
|
+
- Line 34: Missing error check on cd — BashPitfalls #19
|
|
461
|
+
|
|
462
|
+
QUALITY (should fix):
|
|
463
|
+
- Line 8: Backtick substitution; use $() instead — SC2006
|
|
464
|
+
- No EXIT trap for temp files created at line 45
|
|
465
|
+
|
|
466
|
+
STYLE (consider):
|
|
467
|
+
- Script exceeds 100 lines with subprocess orchestration; evaluate Python rewrite
|
|
468
|
+
- Missing --help flag
|
|
469
|
+
|
|
470
|
+
TOOLING:
|
|
471
|
+
- No .shellcheckrc found; recommend: enable=all, external-sources=true
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
4. **Generation mode** — When writing new scripts, apply:
|
|
475
|
+
- Header: `#!/usr/bin/env bash` + `set -Eeuo pipefail`
|
|
476
|
+
- `IFS=$'\n\t'` after strict mode
|
|
477
|
+
- `SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"`
|
|
478
|
+
- Error logging function: `err() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >&2; }`
|
|
479
|
+
- `die()` function: `die() { err "$@"; exit 1; }`
|
|
480
|
+
- `trap 'rm -rf "${tmpdir:-}"' EXIT` before any `mktemp` calls
|
|
481
|
+
- `main()` function called at end
|
|
482
|
+
- `--help` flag via `usage()` heredoc
|
|
483
|
+
- All function variables declared `local`
|
|
484
|
+
|
|
485
|
+
5. **Essential toolchain** — Reference these in generated configs:
|
|
486
|
+
- ShellCheck: `shellcheck --enable=all --external-sources`
|
|
487
|
+
- shfmt: `shfmt -i 2 -ci -bn -sr -kp`
|
|
488
|
+
- Bats: for unit testing shell functions
|
|
489
|
+
- reviewdog/action-shellcheck: for CI PR integration
|
|
490
|
+
|
|
491
|
+
6. **Scope gate** — Always check: if the script exceeds 100 lines with complex control flow, non-trivial data manipulation, or object-like structures, flag it explicitly: "Consider Python rewrite (Google Shell Style Guide threshold)."
|
|
492
|
+
|
|
493
|
+
### Model selection rationale
|
|
494
|
+
|
|
495
|
+
`sonnet` is correct for this agent. Bash review requires:
|
|
496
|
+
- Pattern matching against known anti-patterns (grep-level reasoning)
|
|
497
|
+
- Contextual judgment on whether a pattern is actually risky in context
|
|
498
|
+
- Code generation following established rules
|
|
499
|
+
|
|
500
|
+
It does not require deep architectural reasoning (that's `opus` territory). Haiku is insufficient — the pattern vocabulary is large and the contextual judgment for edge cases (e.g., "is this eval safe?") needs mid-tier reasoning.
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## What to Adopt vs. Skip
|
|
505
|
+
|
|
506
|
+
| Source | Adopt | Skip |
|
|
507
|
+
|--------|-------|------|
|
|
508
|
+
| 0xfurai bash-expert.md | All approach rules verbatim; quality checklist; advanced techniques | Description (too generic) |
|
|
509
|
+
| Google Shell Style Guide | Scope gate (100-line rule); `err()` pattern; naming conventions; prohibited list | POSIX portability rules (Justin's stack is bash-only) |
|
|
510
|
+
| BashPitfalls | Top 17 pitfalls as grep detection patterns | Obscure edge cases (#38-#65) — add only if they appear in codebase |
|
|
511
|
+
| ShellCheck | `enable=all`; `.shellcheckrc`; SC2155, SC2030/31, SC2015 as manual focus | None — use all |
|
|
512
|
+
| ralish/bash-script-template | `main()` pattern; `parse_params()`; modular structure | Build system (overkill for this stack) |
|
|
513
|
+
| SixArm/unix-shell-script-tactics | XDG dirs; UTC timestamps; `NO_COLOR`; `${VAR:?}` | PostgreSQL helpers; platform-specific macOS tactics |
|
|
514
|
+
| reviewdog/action-shellcheck | `--enable=all`; inline PR comments; `check_all_files_with_shebangs` | Not applicable (Justin's repos don't use GitHub PRs for shell review) |
|
|
515
|
+
| VoltAgent devops-engineer.md | Nothing bash-specific | Entire agent — wrong scope |
|
|
516
|
+
| Microsoft Engineering Playbook | The 7-item checklist as the agent's severity-HIGH category | Nothing |
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## Related Files
|
|
521
|
+
|
|
522
|
+
- Sister research: `docs/plans/2026-02-23-research-python-expert-agent.md`
|
|
523
|
+
- Existing agents: `~/.claude/agents/lesson-scanner.md`, `~/.claude/agents/security-reviewer.md`
|
|
524
|
+
- Security reviewer overlap: bash security hardening (injection, credential exposure) partially covered by `security-reviewer.md` — coordinate scopes to avoid duplicate findings
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## References
|
|
529
|
+
|
|
530
|
+
- [0xfurai/claude-code-subagents — bash-expert.md](https://github.com/0xfurai/claude-code-subagents)
|
|
531
|
+
- [VoltAgent/awesome-claude-code-subagents](https://github.com/VoltAgent/awesome-claude-code-subagents)
|
|
532
|
+
- [wshobson/agents](https://github.com/wshobson/agents)
|
|
533
|
+
- [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck)
|
|
534
|
+
- [reviewdog/reviewdog](https://github.com/reviewdog/reviewdog)
|
|
535
|
+
- [koalaman/shellcheck](https://github.com/koalaman/shellcheck)
|
|
536
|
+
- [ShellCheck wiki](https://www.shellcheck.net/wiki/)
|
|
537
|
+
- [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html)
|
|
538
|
+
- [BashPitfalls — Wooledge Wiki](http://mywiki.wooledge.org/BashPitfalls)
|
|
539
|
+
- [Microsoft Engineering Playbook — Bash Code Reviews](https://microsoft.github.io/code-with-engineering-playbook/code-reviews/recipes/bash/)
|
|
540
|
+
- [ralish/bash-script-template](https://github.com/ralish/bash-script-template)
|
|
541
|
+
- [SixArm/unix-shell-script-tactics](https://github.com/SixArm/unix-shell-script-tactics)
|
|
542
|
+
- [codica2/script-best-practices](https://github.com/codica2/script-best-practices)
|
|
543
|
+
- [Anthropic subagent docs](https://code.claude.com/docs/en/sub-agents)
|