import Foundation @main struct VoiceAgentLauncher { static func main() { let fileManager = FileManager.default let projDir = "/Users/adolforeyna/Projects/VoiceAgent1" let bundleResPath = Bundle.main.resourcePath ?? "" let bundledSrcPath = "\(bundleResPath)/src" let workDir = fileManager.fileExists(atPath: projDir) ? projDir : bundledSrcPath let pythonBin = "\(projDir)/.venv/bin/python" let fallbackPython = "/usr/bin/python3" let targetPython = fileManager.fileExists(atPath: pythonBin) ? pythonBin : fallbackPython let targetScript = "\(workDir)/app_main.py" setenv("SSL_CERT_FILE", "/etc/ssl/cert.pem", 1) setenv("REQUESTS_CA_BUNDLE", "/etc/ssl/cert.pem", 1) let logDir = fileManager.homeDirectoryForCurrentUser.appendingPathComponent("Library/Logs/VoiceAgent") try? fileManager.createDirectory(at: logDir, withIntermediateDirectories: true) let logFile = logDir.appendingPathComponent("voiceagent.log") if !fileManager.fileExists(atPath: logFile.path) { fileManager.createFile(atPath: logFile.path, contents: nil) } let process = Process() process.executableURL = URL(fileURLWithPath: targetPython) process.arguments = [targetScript] process.currentDirectoryURL = URL(fileURLWithPath: workDir) if let logHandle = try? FileHandle(forWritingTo: logFile) { logHandle.seekToEndOfFile() process.standardOutput = logHandle process.standardError = logHandle } do { try process.run() process.waitUntilExit() } catch { print("Failed to run VoiceAgent: \(error)") } } }