scripting-expert
Infrastructure and OS automation via shell scripts (Bash/Zsh for macOS/Linux) and PowerShell 7+ (cross-OS): CI/CD hooks, Helm hooks, Airflow operators, idempotency, static validation with ShellCheck and PSScriptAnalyzer, and testing with bats-core/Pester. Use when writing Bash scripts for CI/CD pipelines, creating Airflow bash operators, implementing Helm chart hooks, writing portable shell scripts, or creating PowerShell automation for DevOps tasks. Trigger: Bash, shell script, CI/CD hook, Helm hook, Airflow, PowerShell, ShellCheck, bats-core. Do NOT trigger for: application code in Go/Python/TypeScript, Kubernetes YAML authoring.
- License 许可
- MIT
- 最近更新
- 2026-08-27
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- scripting-expert
- license
- MIT
- metadata
- { "author": "Community", "status": "stable", "version": "1.0", "category": "infrastructure" }
- description
- Infrastructure and OS automation via shell scripts (Bash/Zsh for macOS/Linux) and PowerShell 7+ (cross-OS): CI/CD hooks, Helm hooks, Airflow operators, idempotency, static validation with ShellCheck and PSScriptAnalyzer, and testing with bats-core/Pester. Use when writing Bash scripts for CI/CD pipelines, creating Airflow bash operators, implementing Helm chart hooks, writing portable shell scripts, or creating PowerShell automation for DevOps tasks. Trigger: Bash, shell script, CI/CD hook, Helm hook, Airflow, PowerShell, ShellCheck, bats-core. Do NOT trigger for: application code in Go/Python/TypeScript, Kubernetes YAML authoring.
02 资源文件 4
- 参考文档evals/evals.json2.3 KB
- 参考文档references/bash-patterns.md1.2 KB
- 参考文档references/idempotency.md1.2 KB
- 参考文档references/testing-bats.md938 B
03 SKILL.md 正文
Scripting Expert
Bash/Zsh + PowerShell: CI/CD, automation, hooks and testing.
Core Stack
- POSIX Shell: Bash 5+ / Zsh (macOS default)
- Windows/Cross: PowerShell 7+ (.NET Core, cross-OS)
- Linting: ShellCheck (bash), PSScriptAnalyzer (PowerShell)
- Testing: bats-core (bash), Pester (PowerShell)
- team context: Airflow bash operators, Helm hooks, CI/CD scripts
Bash/Zsh Patterns
Safety Header (MANDATORY)
#!/usr/bin/env bash
set -euo pipefail
-e: exit on first error (NEVER omit)-u: error on undefined variable-o pipefail: pipe fails if any command in pipe fails
Idempotent Operations
# Check state before acting — never assume
if ! command -v aws &>/dev/null; then
echo "Error: aws CLI not installed" >&2
exit 1
fi
# Idempotent create-if-not-exists
if [[ ! -d "/opt/example/config" ]]; then
mkdir -p "/opt/example/config"
fi
Traps for Cleanup
cleanup() {
rm -f "${TEMP_FILE}"
docker stop "${CONTAINER_ID}" 2>/dev/null || true
}
trap cleanup EXIT
Quoting Rules
# ALWAYS quote variables
cp "${SOURCE}" "${DEST}" # correct
cp $SOURCE $DEST # breaks on spaces — NEVER
# NEVER use backticks — use $()
files=$(find . -name "*.go") # correct
files=`find . -name "*.go"` # deprecated — NEVER
PowerShell 7+ Patterns
# Error handling
$ErrorActionPreference = "Stop"
# Idempotent: check before create
if (-not (Test-Path "C:\example\config")) {
New-Item -ItemType Directory -Path "C:\example\config"
}
Linting (Golden Chain)
shellcheck script.sh -> bats test
# Run shellcheck on all scripts
find . -name "*.sh" -exec shellcheck {} +
PSScriptAnalyzer -> Pester test
Testing with bats-core
#!/usr/bin/env bats
@test "script exits 0 on valid input" {
run ./process_item.sh --value 1000 --type standard
[ "$status" -eq 0 ]
}
@test "script exits non-zero on missing value" {
run ./process_item.sh --type standard
[ "$status" -ne 0 ]
}
Patterns
Airflow Bash Operator
# data-orchestration-airflow
BashOperator(
task_id="validate_partitions",
bash_command="scripts/validate_partitions.sh --table {{ ds }}",
dag=dag
)
Helm Hook
# infraestructure-helm
apiVersion: batch/v1
kind: Job
metadata:
annotations:
"helm.sh/hook": pre-upgrade
spec:
template:
spec:
containers:
- name: migrate
command: ["/scripts/migrate.sh"]
Choosing Between Shells
| Scenario | Shell |
|---|---|
| macOS/Linux CI | Bash (shebang #!/usr/bin/env bash) |
| Cross-platform | PowerShell 7+ |
| Airflow operators | Bash (Linux workers) |
| Helm hooks | Bash (container images) |
| Windows targets | PowerShell |
Constraints
- ALWAYS
set -euo pipefailor equivalent error handling - NEVER use backticks —
$()only - ALWAYS quote variables in bash (spaces break unquoted)
- NEVER
evalon user/external input - NEVER hardcode secrets — use env vars or secret management
- ALWAYS log to stderr for diagnostics (
>&2), stdout for data output - ALWAYS handle exit codes explicitly — never assume success
- NEVER
rm -rfwithout explicit path validation - NEVER
curl | bash— download, verify, then execute - ALWAYS test idempotency: run twice, expect same result
Overview
Automate infrastructure and CI/CD through shell scripts (Bash/Zsh for macOS/Linux) and PowerShell 7+ (cross-OS): Helm hooks, Airflow operators, idempotent operations, static validation with ShellCheck/PSScriptAnalyzer, and testing with bats-core/Pester.
Quick Reference
| Task | Tool | Command |
|---|---|---|
| Bash linting | ShellCheck | shellcheck script.sh |
| Bash testing | bats-core | bats test.bats |
| PowerShell linting | PSScriptAnalyzer | Invoke-ScriptAnalyzer script.ps1 |
| PowerShell testing | Pester | Invoke-Pester test.ps1 |
| Safety header | Bash | set -euo pipefail |
Workflow
- Add safety header:
set -euo pipefail(Bash) or$ErrorActionPreference = "Stop"(PowerShell) - Check prerequisites: commands exist, files accessible
- Implement idempotent operations (check state before changing)
- Add traps for cleanup of temp files and resources
- Run shellcheck/PSScriptAnalyzer linting
- Write bats-core/Pester tests, run twice to verify idempotency
Anti-patterns
FAIL: Running rm -rf without path validation
# BAD: unvalidated path
rm -rf "${DIR}/temp"
# GOOD: validate path is safe
[[ "${DIR}" == "/tmp/example/"* ]] || { echo "unsafe path: ${DIR}" >&2; exit 1; }
rm -rf "${DIR}/temp"
FAIL: Piping curl output directly to shell
# BAD: execute without verification
curl -sL https://example.com/install.sh | bash
# GOOD: download, verify, then execute
curl -sL -o install.sh https://example.com/install.sh
sha256sum -c install.sha256 && bash install.sh
FAIL: Using eval with user-supplied input
# BAD: eval on external input
eval "command ${user_input}"
# GOOD: structured parsing with validation
case "${user_input}" in
start|stop|restart) service_action "${user_input}" ;;
*) echo "invalid action" >&2; exit 1 ;;
esac
References
-
ShellCheck documentation: https://www.shellcheck.net/ (last_verified: 2026-05)
-
bats-core test framework: https://github.com/bats-core/bats-core (last_verified: 2026-05)
-
PowerShell PSScriptAnalyzer: https://learn.microsoft.com/en-us/powershell/module/psscriptanalyzer/ (last_verified: 2026-05)
Verification Checklist
- [ ] Safety header present:
set -euo pipefail(Bash) or$ErrorActionPreference = "Stop"(PowerShell) - [ ] All variables quoted in Bash (no unquoted expansions)
- [ ] No backticks used —
$()syntax only - [ ] No
evalon user or external input - [ ] No
rm -rfwithout explicit path validation - [ ] Cleanup trap registered for temp files and resources
- [ ] Exit codes handled explicitly (never assume success)
- [ ] Idempotency verified: script produces same result when run twice
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Script fails on paths with spaces | Variables not quoted | Wrap all variable expansions in double quotes: "${VAR}" |
| Trap cleanup not triggered on error | set -e causes exit before trap registers |
Move trap registration to top of script, before any commands |
| ShellCheck passes but script behaves differently on macOS | Bash version differences (3.2 on macOS vs 5+ on Linux) | Test on target OS; avoid Bash 4+ only features or use #!/usr/bin/env bash compatible syntax |
trap does not catch SIGKILL (known limitation: SIGKILL cannot be trapped) |
kill -9 bypasses all trap handlers |
Use SIGTERM as primary signal; implement watchdog process for forced termination cleanup |
| [WARN] Bash set -euo pipefail still ignores error in if condition or && chain | set -e is disabled inside conditions (if, while, until, ||, &&) | Add explicit || exit $? after critical commands; use trap ERR for global coverage |
| trap EXIT fires but script continues running because trap does not exit automatically | trap EXIT runs cleanup code but does not stop script execution after trap completes | Add exit at end of trap body; use trap "cleanup; exit" EXIT pattern for termination |
| Edge case: process substitution <() creates named pipe that leaks if shell exits before read | Process substitution file descriptor stays open; zombie process if parent exits without consuming output | Use temp file with trap cleanup instead of process substitution for critical scripts |
04 同仓库更多 Skills
web-browsing-agent-expert
Web browsing for AI agents: driving a headless browser (Playwright, Puppeteer) from agent tooling, navigation and page-state grounding, DOM extraction and structured data capture, form interaction, session and cookie management, anti-bot mitigation awareness, and safe browsing rules (no PII exfiltration, respect robots and terms). Use when building a browsing tool or MCP server for an agent, teaching an agent to navigate and read web pages, extracting structured content from dynamic sites, or handling login walls and pagination in agent workflows. Trigger: web browsing agent, headless browser, Playwright MCP, Puppeteer, browser automation for agents, DOM extraction, page navigation, session management. Do NOT trigger for: end-to-end UI testing of an application (use playwright-expert); writing standalone scraping scripts for data pipelines (use python-expert); fetching a single public URL (use the fetch tool).
vector-databases
Design and operate vector databases for cloud-native AI features. Use when selecting between pgvector, Pinecone, or Weaviate for AI context layer or integration-hub; designing embedding schemas and index parameters; implementing ANN search with metadata filtering; managing embedding model versions; optimizing query latency; or debugging low retrieval quality. Pairs with rag-architecture for pipeline design and postgres-database-expert for pgvector specifics. Trigger: vector database, pgvector, Pinecone, Weaviate, embedding, ANN search, HNSW, cosine similarity. Do NOT trigger for: relational SQL optimization, standard PostgreSQL schema design, Redis caching.
typescript-expert
Full-stack TypeScript stack for modern projects: frontend SSR/CSR with Next.js 14 App Router and React, backend APIs with Node.js (Express/Fastify), state management with Zustand/Redux Toolkit, unit and integration testing with Vitest/Jest + React Testing Library + MSW, and static analysis with ESLint/Prettier/tsc. Use when building React components or hooks, implementing Next.js App Router or Server Components, writing Node.js REST API handlers, implementing middleware (auth, rate-limit, logging), managing client state (Zustand/RTK), writing frontend/backend tests, or running TypeScript linting/type checks. Trigger: TypeScript, Next.js, React, Zustand, Node.js, Express, Fastify, MSW, Vitest. Do NOT trigger for: Python backend development, Go microservices, iOS/mobile development.
tool-usage
Guide correct tool selection, design, and orchestration for AI agents. Use when choosing between dedicated vs Bash tools, designing MCP tool interfaces, naming tool parameters, handling tool response limits, orchestrating parallel vs sequential calls, evaluating tool accuracy, applying ACI design principles, selecting workflow patterns, or reading/filtering/transforming/generating structured data (JSON, YAML, CSV, TOML, XML). Trigger: tool selection, MCP tool design, orchestration, ACI, parallel execution, composite tool, structured data, jq, yq, dasel, mlr, csvkit. Do NOT trigger for: writing application business logic, domain-specific development (route to domain skill), database migrations.
token-efficiency
Enforce token-efficient output, compression, caching, and model routing. Use when calibrating response verbosity, applying compression strategies to logs or RAG chunks, routing tasks to the right model tier, setting thinking budgets, enforcing word limits, compressing context before reinitiation, applying KV-cache ordering, masking tool output observations, or applying clarification-first protocol before irreversible actions. Trigger: token efficiency, compression, model routing, thinking budget, KV-cache, clarification protocol. Do NOT trigger for: non-agent tooling, CI/CD pipeline scripting, infrastructure provisioning.
time-series-db
Time-series database patterns for cloud-native metrics and analytics: TimescaleDB, InfluxDB, and Amazon Timestream selection; continuous aggregates, retention policies, downsampling, and integration with Prometheus/Grafana. Use when storing business metrics over time, building custom business dashboards, designing high-frequency event storage, or querying time-bucketed aggregations. Trigger: time-series, TimescaleDB, InfluxDB, Prometheus, Grafana, hypertable, continuous aggregate, retention policy. Do NOT trigger for: relational PostgreSQL schema design, NoSQL document stores, Kafka event streaming.