#!/bin/bash # build_app.sh - Build standalone macOS VoiceAgent.app bundle set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$HERE" echo "=== 1. Building Swift Helper & Launcher Binaries ===" bash swift/build.sh APP_NAME="VoiceAgent" DIST_DIR="$HERE/dist" APP_BUNDLE="$DIST_DIR/$APP_NAME.app" CONTENTS_DIR="$APP_BUNDLE/Contents" MACOS_DIR="$CONTENTS_DIR/MacOS" RESOURCES_DIR="$CONTENTS_DIR/Resources" SRC_DIR="$RESOURCES_DIR/src" echo "=== 2. Creating macOS App Bundle Structure ===" rm -rf "$APP_BUNDLE" mkdir -p "$MACOS_DIR" mkdir -p "$RESOURCES_DIR/swift" mkdir -p "$SRC_DIR" echo "=== 3. Compiling Native App Bundle Launcher ===" swiftc -O -parse-as-library "$HERE/swift/VoiceAgentLauncher.swift" -o "$MACOS_DIR/VoiceAgent" chmod +x "$MACOS_DIR/VoiceAgent" echo "=== 4. Copying Source Files, Swift Helpers, and Assets ===" cp "$HERE/swift/speech-helper" "$RESOURCES_DIR/swift/" cp "$HERE/swift/llm-helper" "$RESOURCES_DIR/swift/" chmod +x "$RESOURCES_DIR/swift/speech-helper" "$RESOURCES_DIR/swift/llm-helper" # Copy python files and bin scripts to bundle resources cp "$HERE"/*.py "$SRC_DIR/" 2>/dev/null || true cp -R "$HERE/bin" "$SRC_DIR/" 2>/dev/null || true if [ -f "$HERE/vocabulary.example.txt" ]; then cp "$HERE/vocabulary.example.txt" "$RESOURCES_DIR/" fi if [ -f "$HERE/corrections.example.txt" ]; then cp "$HERE/corrections.example.txt" "$RESOURCES_DIR/" fi echo "=== 5. Generating Info.plist with Entitlements ===" cat << 'EOF' > "$CONTENTS_DIR/Info.plist" CFBundleExecutable VoiceAgent CFBundleIdentifier com.voiceagent.mac CFBundleName VoiceAgent CFBundleDisplayName VoiceAgent CFBundlePackageType APPL CFBundleShortVersionString 1.0.0 CFBundleVersion 1.0.0 LSMinimumSystemVersion 14.0 NSMicrophoneUsageDescription VoiceAgent requires access to your microphone to listen to your voice commands. NSSpeechRecognitionUsageDescription VoiceAgent uses on-device speech recognition to process your spoken input. NSHighResolutionCapable EOF echo "=== 6. Code-signing App Bundle ===" codesign -s - --deep --force "$APP_BUNDLE" echo "=== 7. Installing to /Applications ===" rm -rf /Applications/VoiceAgent.app cp -R "$APP_BUNDLE" /Applications/ codesign -s - --deep --force /Applications/VoiceAgent.app echo "==========================================================" echo "Successfully built and installed VoiceAgent.app to:" echo "1. /Applications/VoiceAgent.app" echo "2. $APP_BUNDLE" echo "=========================================================="