1#!/bin/bash
 2
 3# Development script for llama.cpp webui
 4# 
 5# This script starts the webui development servers (Storybook and Vite).
 6# Note: You need to start llama-server separately.
 7#
 8# Usage:
 9#   bash scripts/dev.sh
10#   npm run dev
11
12cd ../../../
13
14# Check and install git hooks if missing
15check_and_install_hooks() {
16    local hooks_missing=false
17    
18    # Check for required hooks
19    if [ ! -f ".git/hooks/pre-commit" ] || [ ! -f ".git/hooks/pre-push" ] || [ ! -f ".git/hooks/post-push" ]; then
20        hooks_missing=true
21    fi
22    
23    if [ "$hooks_missing" = true ]; then
24        echo "๐Ÿ”ง Git hooks missing, installing them..."
25        cd tools/server/webui
26        if bash scripts/install-git-hooks.sh; then
27            echo "โœ… Git hooks installed successfully"
28        else
29            echo "โš ๏ธ  Failed to install git hooks, continuing anyway..."
30        fi
31        cd ../../../
32    else
33        echo "โœ… Git hooks already installed"
34    fi
35}
36
37# Install git hooks if needed
38check_and_install_hooks
39
40# Cleanup function
41cleanup() {
42    echo "๐Ÿงน Cleaning up..."
43    exit
44}
45
46# Set up signal handlers
47trap cleanup SIGINT SIGTERM
48
49echo "๐Ÿš€ Starting development servers..."
50echo "๐Ÿ“ Note: Make sure to start llama-server separately if needed"
51cd tools/server/webui
52# Use --insecure-http-parser to handle malformed HTTP responses from llama-server
53# (some responses have both Content-Length and Transfer-Encoding headers)
54storybook dev -p 6006 --ci & NODE_OPTIONS="--insecure-http-parser" vite dev --host 0.0.0.0 &
55
56# Wait for all background processes
57wait