kin/scripts/rebuild-frontend.sh
Gros Frumos 01b269e2b8 feat(KIN-010): implement rebuild-frontend post-pipeline hook
- scripts/rebuild-frontend.sh: builds Vue 3 frontend and restarts uvicorn API
- cli/main.py: hook group with add/list/remove/logs/setup commands;
  `hook setup` idempotently registers rebuild-frontend for a project
- agents/runner.py: call run_hooks(event="pipeline_completed") after
  successful pipeline; wrap in try/except so hook errors never block results
- tests: 3 tests for hook_setup CLI + 3 tests for pipeline→hooks integration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 19:17:42 +02:00

38 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# rebuild-frontend — post-pipeline hook for Kin.
#
# Triggered automatically after pipeline_completed when web/frontend/* modules
# were touched. Builds the Vue 3 frontend and restarts the API server.
#
# Registration (one-time):
# kin hook setup --project <project_id>
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
FRONTEND_DIR="$PROJECT_ROOT/web/frontend"
echo "[rebuild-frontend] Building frontend in $FRONTEND_DIR ..."
cd "$FRONTEND_DIR"
npm run build
echo "[rebuild-frontend] Build complete."
# Restart API server if it's currently running.
# pgrep returns 1 if no match; || true prevents set -e from exiting.
API_PID=$(pgrep -f "uvicorn web.api" 2>/dev/null || true)
if [ -n "$API_PID" ]; then
echo "[rebuild-frontend] Stopping API server (PID: $API_PID) ..."
kill "$API_PID" 2>/dev/null || true
# Wait for port 8420 to free up (up to 5 s)
for i in $(seq 1 5); do
pgrep -f "uvicorn web.api" > /dev/null 2>&1 || break
sleep 1
done
echo "[rebuild-frontend] Starting API server ..."
cd "$PROJECT_ROOT"
nohup python -m uvicorn web.api:app --port 8420 >> /tmp/kin-api.log 2>&1 &
echo "[rebuild-frontend] API server started (PID: $!)."
else
echo "[rebuild-frontend] API server not running; skipping restart."
fi