Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ poetry.toml
/run-chat.sh
.ccache/

# Code Workspace
# IDE
*.code-workspace

.windsurf/
7 changes: 0 additions & 7 deletions .windsurf/rules/css-architecture.md

This file was deleted.

48 changes: 0 additions & 48 deletions .windsurf/rules/sveltekit-architecture.md

This file was deleted.

9 changes: 0 additions & 9 deletions .windsurf/rules/tests.md

This file was deleted.

7 changes: 0 additions & 7 deletions .windsurf/rules/typescript-architecture.md

This file was deleted.

1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/ci/ @ggerganov
/.devops/*.Dockerfile @ngxson
/tools/server/ @ngxson
/tools/server/webui/ @allozaur
/ggml/src/ggml-cuda/fattn* @JohannesGaessler
/ggml/src/ggml-cuda/mmq.* @JohannesGaessler
/ggml/src/ggml-cuda/mmvq.* @JohannesGaessler
Expand Down
Binary file modified tools/server/public/index.html.gz
Binary file not shown.
5 changes: 3 additions & 2 deletions tools/server/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite dev --host 0.0.0.0 & storybook dev -p 6006 --ci",
"dev": "bash scripts/dev.sh",
"build": "vite build && ./scripts/post-build.sh",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
Expand All @@ -20,7 +20,8 @@
"test:ui": "vitest --project=ui",
"test:unit": "vitest",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"cleanup": "rm -rf .svelte-kit build node_modules test-results"
},
"devDependencies": {
"@chromatic-com/storybook": "^4.0.1",
Expand Down
103 changes: 103 additions & 0 deletions tools/server/webui/scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

cd ../../../

# Check and install git hooks if missing
check_and_install_hooks() {
local hooks_missing=false

# Check for required hooks
if [ ! -f ".git/hooks/pre-commit" ] || [ ! -f ".git/hooks/pre-push" ] || [ ! -f ".git/hooks/post-push" ]; then
hooks_missing=true
fi

if [ "$hooks_missing" = true ]; then
echo "🔧 Git hooks missing, installing them..."
cd tools/server/webui
if bash scripts/install-git-hooks.sh; then
echo "✅ Git hooks installed successfully"
else
echo "⚠️ Failed to install git hooks, continuing anyway..."
fi
cd ../../../
else
echo "✅ Git hooks already installed"
fi
}

# Install git hooks if needed
check_and_install_hooks

# Check if llama-server binary already exists
if [ ! -f "build/bin/llama-server" ]; then
echo "Building llama-server..."
cmake -B build && cmake --build build --config Release -t llama-server
else
echo "llama-server binary already exists, skipping build."
fi

# Start llama-server and capture output
echo "Starting llama-server..."
mkfifo server_output.pipe
build/bin/llama-server -hf ggml-org/gpt-oss-20b-GGUF --jinja -c 0 --no-webui > server_output.pipe 2>&1 &
SERVER_PID=$!

# Function to wait for server to be ready
wait_for_server() {
echo "Waiting for llama-server to be ready..."
local max_wait=60
local start_time=$(date +%s)

# Read server output in background and look for the ready message
(
while IFS= read -r line; do
echo "🔍 Server: $line"
if [[ "$line" == *"server is listening on http://127.0.0.1:8080 - starting the main loop"* ]]; then
echo "✅ llama-server is ready!"
echo "READY" > server_ready.flag
break
fi
done < server_output.pipe
) &

# Wait for ready flag or timeout
while [ ! -f server_ready.flag ]; do
local current_time=$(date +%s)
local elapsed=$((current_time - start_time))

if [ $elapsed -ge $max_wait ]; then
echo "❌ Server failed to start within $max_wait seconds"
rm -f server_ready.flag
return 1
fi

sleep 1
done

rm -f server_ready.flag
return 0
}

# Cleanup function
cleanup() {
echo "🧹 Cleaning up..."
kill $SERVER_PID 2>/dev/null
rm -f server_output.pipe server_ready.flag
exit
}

# Set up signal handlers
trap cleanup SIGINT SIGTERM

# Wait for server to be ready
if wait_for_server; then
echo "🚀 Starting development servers..."
cd tools/server/webui
storybook dev -p 6006 --ci & vite dev --host 0.0.0.0 &

# Wait for all background processes
wait
else
echo "❌ Failed to start development environment"
cleanup
fi
112 changes: 74 additions & 38 deletions tools/server/webui/scripts/install-git-hooks.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/bin/bash

# Script to install pre-commit and post-commit hooks for webui
# Pre-commit: formats code and builds, stashes unstaged changes
# Post-commit: automatically unstashes changes
# Script to install pre-commit and pre-push hooks for webui
# Pre-commit: formats code and runs checks
# Pre-push: builds the project, stashes unstaged changes

REPO_ROOT=$(git rev-parse --show-toplevel)
PRE_COMMIT_HOOK="$REPO_ROOT/.git/hooks/pre-commit"
POST_COMMIT_HOOK="$REPO_ROOT/.git/hooks/post-commit"
PRE_PUSH_HOOK="$REPO_ROOT/.git/hooks/pre-push"

echo "Installing pre-commit and post-commit hooks for webui..."
echo "Installing pre-commit and pre-push hooks for webui..."

# Create the pre-commit hook
cat > "$PRE_COMMIT_HOOK" << 'EOF'
#!/bin/bash

# Check if there are any changes in the webui directory
if git diff --cached --name-only | grep -q "^tools/server/webui/"; then
echo "Formatting webui code..."
echo "Formatting and checking webui code..."

# Change to webui directory and run format
cd tools/server/webui
Expand All @@ -27,20 +27,12 @@ if git diff --cached --name-only | grep -q "^tools/server/webui/"; then
exit 1
fi

# Stash any unstaged changes to avoid conflicts during format/build
echo "Stashing unstaged changes..."
git stash push --keep-index --include-untracked -m "Pre-commit hook: stashed unstaged changes"
STASH_CREATED=$?

# Run the format command
npm run format

# Check if format command succeeded
if [ $? -ne 0 ]; then
echo "Error: npm run format failed"
if [ $STASH_CREATED -eq 0 ]; then
echo "You can restore your unstaged changes with: git stash pop"
fi
exit 1
fi

Expand All @@ -50,12 +42,46 @@ if git diff --cached --name-only | grep -q "^tools/server/webui/"; then
# Check if check command succeeded
if [ $? -ne 0 ]; then
echo "Error: npm run check failed"
if [ $STASH_CREATED -eq 0 ]; then
echo "You can restore your unstaged changes with: git stash pop"
fi
exit 1
fi

# Go back to repo root
cd ../../..

echo "✅ Webui code formatted and checked successfully"
fi

exit 0
EOF

# Create the pre-push hook
cat > "$PRE_PUSH_HOOK" << 'EOF'
#!/bin/bash

# Check if there are any changes in the webui directory that need building
if git diff --name-only HEAD~1..HEAD | grep -q "^tools/server/webui/" || git diff --name-only --cached | grep -q "^tools/server/webui/"; then
echo "Building webui for push..."

# Change to webui directory
cd tools/server/webui

# Check if npm is available and package.json exists
if [ ! -f "package.json" ]; then
echo "Error: package.json not found in tools/server/webui"
exit 1
fi

# Stash any unstaged changes to avoid conflicts during build
echo "Checking for unstaged changes..."
if ! git diff --quiet || ! git diff --cached --quiet --diff-filter=A; then
echo "Stashing unstaged changes..."
git stash push --include-untracked -m "Pre-push hook: stashed unstaged changes"
STASH_CREATED=$?
else
echo "No unstaged changes to stash"
STASH_CREATED=1
fi

# Run the build command
npm run build

Expand All @@ -71,52 +97,62 @@ if git diff --cached --name-only | grep -q "^tools/server/webui/"; then
# Go back to repo root to add build output
cd ../../..

# Add the build output to staging area
git add tools/server/public/index.html.gz
# Add the build output to staging area and commit if there are changes
if [ -f "tools/server/public/index.html.gz" ]; then
git add tools/server/public/index.html.gz
if ! git diff --cached --quiet; then
git commit -m "chore: update webui build output"
fi
fi

if [ $STASH_CREATED -eq 0 ]; then
echo "✅ Build completed. Your unstaged changes have been stashed."
echo "They will be automatically restored after the commit."
# Create a marker file to indicate stash was created by pre-commit hook
touch .git/WEBUI_STASH_MARKER
echo "They will be automatically restored after the push."
# Create a marker file to indicate stash was created by pre-push hook
touch .git/WEBUI_PUSH_STASH_MARKER
fi

echo "Webui code formatted successfully"
echo "Webui build completed successfully"
fi

exit 0
EOF

# Create the post-commit hook
cat > "$POST_COMMIT_HOOK" << 'EOF'
# Create the post-push hook (for restoring stashed changes after push)
cat > "$REPO_ROOT/.git/hooks/post-push" << 'EOF'
#!/bin/bash

# Check if we have a stash marker from the pre-commit hook
if [ -f .git/WEBUI_STASH_MARKER ]; then
echo "Restoring your unstaged changes..."
# Check if we have a stash marker from the pre-push hook
if [ -f .git/WEBUI_PUSH_STASH_MARKER ]; then
echo "Restoring your unstaged changes after push..."
git stash pop
rm -f .git/WEBUI_STASH_MARKER
rm -f .git/WEBUI_PUSH_STASH_MARKER
echo "✅ Your unstaged changes have been restored."
fi

exit 0
EOF

# Make both hooks executable
# Make all hooks executable
chmod +x "$PRE_COMMIT_HOOK"
chmod +x "$POST_COMMIT_HOOK"
chmod +x "$PRE_PUSH_HOOK"
chmod +x "$REPO_ROOT/.git/hooks/post-push"

if [ $? -eq 0 ]; then
echo "✅ Pre-commit and post-commit hooks installed successfully!"
echo " Pre-commit: $PRE_COMMIT_HOOK"
echo " Post-commit: $POST_COMMIT_HOOK"
echo "✅ Git hooks installed successfully!"
echo " Pre-commit: $PRE_COMMIT_HOOK"
echo " Pre-push: $PRE_PUSH_HOOK"
echo " Post-push: $REPO_ROOT/.git/hooks/post-push"
echo ""
echo "The hooks will automatically:"
echo " • Format and build webui code before commits"
echo " • Stash unstaged changes during the process"
echo " • Restore your unstaged changes after the commit"
echo " • Format and check webui code before commits (pre-commit)"
echo " • Build webui code before pushes (pre-push)"
echo " • Stash unstaged changes during build process"
echo " • Restore your unstaged changes after the push"
echo ""
echo "To test the hooks, make a change to a file in the webui directory and commit it."
echo "To test the hooks:"
echo " • Make a change to a file in the webui directory and commit it (triggers format/check)"
echo " • Push your commits to trigger the build process"
else
echo "❌ Failed to make hooks executable"
exit 1
Expand Down
Loading