Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .cascade/ensure-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Service health check and restart for CASCADE agent
# Can be run by the agent before running tests or migrations
#
# Usage: .cascade/ensure-services.sh
# Exit codes:
# 0 - All services running
# 1 - Service failed to start

set -e

echo "=== Checking Services ==="

# PostgreSQL check and restart
if pg_isready -q 2>/dev/null; then
echo "PostgreSQL: running"
else
echo "PostgreSQL: down - attempting restart..."

if [ -d /var/lib/postgresql/data ]; then
PG_CTL=$(find /usr/lib/postgresql -name pg_ctl 2>/dev/null | head -1)
if [ -n "$PG_CTL" ]; then
echo "Found pg_ctl at: $PG_CTL"

mkdir -p /run/postgresql 2>/dev/null || true
chown postgres:postgres /run/postgresql 2>/dev/null || true

if su postgres -c "$PG_CTL start -D /var/lib/postgresql/data -l /tmp/postgres.log -w -t 30" 2>/dev/null; then
echo "Started PostgreSQL as postgres user"
elif $PG_CTL start -D /var/lib/postgresql/data -l /tmp/postgres.log -w -t 30 2>/dev/null; then
echo "Started PostgreSQL as current user"
elif command -v pg_ctlcluster &>/dev/null; then
PG_VERSION=$(ls /usr/lib/postgresql/ | sort -V | tail -1)
pg_ctlcluster $PG_VERSION main start 2>/dev/null || true
else
echo "PostgreSQL restart failed - needs manual intervention"
echo "Try: su postgres -c 'pg_ctl start -D /var/lib/postgresql/data'"
fi
fi
elif command -v brew &>/dev/null; then
brew services start postgresql@16 2>/dev/null || \
brew services start postgresql@15 2>/dev/null || \
brew services start postgresql 2>/dev/null || true
fi

# Wait for PostgreSQL to be ready
for i in {1..10}; do
if pg_isready -q 2>/dev/null; then
break
fi
echo "Waiting for PostgreSQL... ($i/10)"
sleep 1
done

# Final check
if pg_isready -q 2>/dev/null; then
echo "PostgreSQL: restarted successfully"
else
echo "PostgreSQL: FAILED TO START"
echo ""
echo "Troubleshooting:"
echo " - Check PostgreSQL logs: cat /tmp/postgres.log"
echo " - Check data directory: ls -la /var/lib/postgresql/data"
echo " - Check if another instance is running: ps aux | grep postgres"
exit 1
fi
fi

echo "=== All services running ==="
3 changes: 3 additions & 0 deletions .cascade/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CI=true
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/cascade
DATABASE_SSL=false
112 changes: 112 additions & 0 deletions .cascade/on-file-edit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
# Post-edit validation for CASCADE agent
# Runs linting and type checking on edited files
#
# Usage: .cascade/on-file-edit.sh <file-path>
#
# Exit codes:
# 0 - All checks passed (or file type not applicable)
# 1 - Lint errors found
# 2 - Type errors found
# 3 - Both lint and type errors found
# 10 - File not found
# 11 - No file path provided

set -uo pipefail

FILE_PATH="${1:-}"

if [ -z "$FILE_PATH" ]; then
echo "Error: No file path provided"
echo "Usage: $0 <file-path>"
exit 11
fi

# Convert to absolute path if relative
if [[ ! "$FILE_PATH" = /* ]]; then
FILE_PATH="$(pwd)/$FILE_PATH"
fi

if [ ! -f "$FILE_PATH" ]; then
echo "Error: File not found: $FILE_PATH"
exit 10
fi

# Get the project root (where this script lives)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_ROOT"

# Make file path relative to project root
REL_PATH="${FILE_PATH#$PROJECT_ROOT/}"

# Get file extension
EXT="${FILE_PATH##*.}"

# Determine if file is lintable and/or type-checkable
LINT_APPLICABLE=false
TYPE_APPLICABLE=false

case "$EXT" in
ts|tsx)
LINT_APPLICABLE=true
TYPE_APPLICABLE=true
;;
js|jsx|json|jsonc)
LINT_APPLICABLE=true
;;
esac

# If neither applies, exit successfully
if [ "$LINT_APPLICABLE" = false ] && [ "$TYPE_APPLICABLE" = false ]; then
exit 0
fi

LINT_EXIT=0
TYPE_EXIT=0
LINT_OUTPUT=""
TYPE_OUTPUT=""

# --- Run Biome lint ---
if [ "$LINT_APPLICABLE" = true ]; then
LINT_OUTPUT=$(npx biome check "$REL_PATH" 2>&1)
LINT_EXIT=$?
fi

# --- Run TypeScript type check ---
if [ "$TYPE_APPLICABLE" = true ]; then
# Determine tsconfig based on file location
if [[ "$REL_PATH" == web/* ]]; then
TYPE_OUTPUT=$(npx tsc --noEmit -p web/tsconfig.json 2>&1)
TYPE_EXIT=$?
else
# src/*, tools/*, tests/*, root files
TYPE_OUTPUT=$(npx tsc --noEmit 2>&1)
TYPE_EXIT=$?
fi
fi

# --- Output only if there are errors ---
if [ $LINT_EXIT -ne 0 ]; then
echo "=== Biome Check: $REL_PATH ==="
echo "$LINT_OUTPUT"
echo ""
fi

if [ $TYPE_EXIT -ne 0 ]; then
echo "=== TypeScript Check: $REL_PATH ==="
echo "$TYPE_OUTPUT"
echo ""
fi

# --- Determine final exit code ---
if [ $LINT_EXIT -ne 0 ] && [ $TYPE_EXIT -ne 0 ]; then
exit 3
elif [ $LINT_EXIT -ne 0 ]; then
exit 1
elif [ $TYPE_EXIT -ne 0 ]; then
exit 2
else
exit 0
fi
96 changes: 96 additions & 0 deletions .cascade/on-verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
# Post-edit verification suite for CASCADE agent
# Runs diagnostics and/or tests based on scope argument
#
# Usage: .cascade/on-verify.sh <scope>
# scope: diagnostics | tests | full (default: full)
#
# Exit codes:
# 0 - All checks passed
# 1 - Lint errors found
# 2 - Type errors found
# 3 - Both lint and type errors found
# 4 - Test failures
# 5 - Multiple failure types (diagnostics + tests)

set -uo pipefail

SCOPE="${1:-full}"

# Get the project root (where this script lives)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_ROOT"

LINT_EXIT=0
TYPE_EXIT=0
TEST_EXIT=0
LINT_OUTPUT=""
TYPE_OUTPUT=""
TEST_OUTPUT=""

# --- Diagnostics: Lint + Type Check ---
if [ "$SCOPE" = "diagnostics" ] || [ "$SCOPE" = "full" ]; then
# Lint via Biome
LINT_OUTPUT=$(npm run lint 2>&1)
LINT_EXIT=$?

# Type check via tsc
TYPE_OUTPUT=$(npm run typecheck 2>&1)
TYPE_EXIT=$?
fi

# --- Tests: Vitest ---
if [ "$SCOPE" = "tests" ] || [ "$SCOPE" = "full" ]; then
TEST_OUTPUT=$(npm test 2>&1)
TEST_EXIT=$?
fi

# --- Output results ---
HAS_ERRORS=false

if [ $LINT_EXIT -ne 0 ]; then
HAS_ERRORS=true
echo "=== Biome Lint ==="
echo "$LINT_OUTPUT"
echo ""
fi

if [ $TYPE_EXIT -ne 0 ]; then
HAS_ERRORS=true
echo "=== TypeScript ==="
echo "$TYPE_OUTPUT"
echo ""
fi

if [ $TEST_EXIT -ne 0 ]; then
HAS_ERRORS=true
echo "=== Tests ==="
echo "$TEST_OUTPUT"
echo ""
fi

if [ "$HAS_ERRORS" = false ]; then
echo "All checks passed."
fi

# --- Determine final exit code ---
DIAG_FAILED=false
if [ $LINT_EXIT -ne 0 ] || [ $TYPE_EXIT -ne 0 ]; then
DIAG_FAILED=true
fi

if [ "$DIAG_FAILED" = true ] && [ $TEST_EXIT -ne 0 ]; then
exit 5
elif [ $LINT_EXIT -ne 0 ] && [ $TYPE_EXIT -ne 0 ]; then
exit 3
elif [ $LINT_EXIT -ne 0 ]; then
exit 1
elif [ $TYPE_EXIT -ne 0 ]; then
exit 2
elif [ $TEST_EXIT -ne 0 ]; then
exit 4
else
exit 0
fi
Loading