spawn/.githooks/pre-commit
L b6ee6b6ab1
Add guardrails: CLAUDE.md rules, hooks, pre-commit validation (#33)
* feat: add gptme agent to spawn matrix

Add gptme (https://github.com/gptme/gptme) - a personal AI agent in the
terminal with tools for code editing, terminal commands, web browsing,
and more. Natively supports OpenRouter via OPENROUTER_API_KEY.

- Add gptme agent entry to manifest.json with OpenRouter env vars
- Implement sprite/gptme.sh deployment script
- Implement hetzner/gptme.sh deployment script
- Add "missing" matrix entries for remaining 8 clouds
- Update README.md with usage instructions for Sprite and Hetzner

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add Fly.io cloud provider with claude and aider agents

Add Fly.io as a new cloud provider using the Machines REST API for
provisioning and flyctl CLI for SSH access. Docker-based machines
with pay-per-second pricing.

- Create fly/lib/common.sh with Fly.io Machines API integration
- Implement fly/claude.sh for Claude Code deployment
- Implement fly/aider.sh for Aider deployment
- Update README.md with Fly.io usage instructions and env vars

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add gemini, amazonq, cline, gptme to Fly.io

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add openclaw, nanoclaw, goose, codex, interpreter to Fly.io

Implements 5 new agent scripts for the Fly.io cloud provider:
- fly/openclaw.sh: OpenClaw with gateway + TUI, model selection, config
- fly/nanoclaw.sh: NanoClaw WhatsApp agent with .env configuration
- fly/goose.sh: Block's Goose agent with OpenRouter provider
- fly/codex.sh: OpenAI Codex CLI with OpenRouter base URL override
- fly/interpreter.sh: Open Interpreter with OpenRouter base URL override

All scripts follow the Fly.io pattern (flyctl-based, no IP args for
run_server/interactive_session) and use upload_file for env injection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add gptme agent to 8 remaining clouds

Implement gptme agent scripts for digitalocean, vultr, linode, lambda,
aws-lightsail, gcp, e2b, and modal. Each script follows the exact
pattern of that cloud's existing aider.sh, adapted for gptme's install
and launch commands. Updates manifest.json matrix entries from "missing"
to "implemented".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add guardrails from insights: CLAUDE.md rules, hooks, pre-commit

Based on usage insights analysis:

CLAUDE.md:
- Shell script rules: curl|bash compat, macOS bash 3.x compat
- Autonomous loop rules: test after each iteration, never revert fixes
- Git workflow rules: always use feature branches

.claude/settings.json:
- PostToolUse hook validates .sh files on every Write/Edit:
  syntax check, no relative source, no echo -e, no set -u

.githooks/pre-commit:
- Blocks commits with: syntax errors, relative sources, echo -e,
  set -euo, references to deleted functions
- Install: git config core.hooksPath .githooks

README.md:
- Added developer setup section with hook installation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Sprite <noreply@sprite.dev>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-07 20:02:19 -08:00

64 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
# Pre-commit hook: validates all staged .sh files
# Install: git config core.hooksPath .githooks
set -eo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
errors=0
# Get staged .sh files
staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.sh$' || true)
if [[ -z "$staged_files" ]]; then
exit 0
fi
echo "Validating staged shell scripts..."
for file in $staged_files; do
# 1. Syntax check
if ! bash -n "$file" 2>/dev/null; then
echo -e "${RED}FAIL${NC} $file: syntax error"
bash -n "$file" 2>&1 | head -3
errors=$((errors + 1))
continue
fi
# 2. No relative source (breaks curl|bash)
if grep -qn 'source \.\./' "$file" 2>/dev/null || grep -qn 'source \./' "$file" 2>/dev/null; then
echo -e "${RED}FAIL${NC} $file: relative source path (breaks curl|bash)"
grep -n 'source \.\.' "$file" 2>/dev/null || true
errors=$((errors + 1))
fi
# 3. No echo -e (breaks macOS bash 3.x)
if grep -qn 'echo -e ' "$file" 2>/dev/null; then
echo -e "${RED}FAIL${NC} $file: echo -e (use printf for macOS compat)"
errors=$((errors + 1))
fi
# 4. No set -u / set -euo (breaks env var checks)
if grep -qn 'set -euo' "$file" 2>/dev/null; then
echo -e "${RED}FAIL${NC} $file: set -euo pipefail (drop the 'u', use set -eo pipefail)"
errors=$((errors + 1))
fi
# 5. Check for calls to deleted functions
if grep -qn 'write_oauth_response_file\|create_oauth_response_html' "$file" 2>/dev/null; then
echo -e "${RED}FAIL${NC} $file: references deleted function"
errors=$((errors + 1))
fi
done
if [[ $errors -gt 0 ]]; then
echo ""
echo -e "${RED}$errors error(s) found. Commit blocked.${NC}"
echo "Fix the issues above and try again."
exit 1
fi
echo -e "${GREEN}All $( echo "$staged_files" | wc -w | tr -d ' ') scripts passed validation.${NC}"