(onProgress?: (msg: string) => void)
| 98 | } |
| 99 | |
| 100 | function buildFromSource(onProgress?: (msg: string) => void): WhisperResult { |
| 101 | // Clean stale builds — if BUILD_DIR exists but has no binary, nuke and re-clone |
| 102 | if (existsSync(BUILD_DIR) && !findBuiltBinary()) { |
| 103 | rmSync(BUILD_DIR, { recursive: true, force: true }); |
| 104 | } |
| 105 | |
| 106 | if (!existsSync(BUILD_DIR)) { |
| 107 | onProgress?.("Downloading whisper.cpp..."); |
| 108 | mkdirSync(join(homedir(), ".cache", "hyperframes", "whisper"), { |
| 109 | recursive: true, |
| 110 | }); |
| 111 | execFileSync("git", ["clone", "--depth", "1", WHISPER_REPO, BUILD_DIR], { |
| 112 | stdio: "ignore", |
| 113 | timeout: 60_000, |
| 114 | env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | onProgress?.("Building whisper.cpp (this may take a minute)..."); |
| 119 | try { |
| 120 | execFileSync("cmake", ["-B", "build"], { |
| 121 | cwd: BUILD_DIR, |
| 122 | stdio: ["pipe", "pipe", "pipe"], |
| 123 | timeout: 120_000, |
| 124 | }); |
| 125 | execFileSync("cmake", ["--build", "build", "--config", "Release", "-j"], { |
| 126 | cwd: BUILD_DIR, |
| 127 | stdio: ["pipe", "pipe", "pipe"], |
| 128 | timeout: 300_000, |
| 129 | }); |
| 130 | } catch (err: unknown) { |
| 131 | // Build failed — capture diagnostics, then clean up so next attempt starts fresh |
| 132 | let detail = ""; |
| 133 | if (err && typeof err === "object" && "stderr" in err) { |
| 134 | const stderr = String(err.stderr).trim(); |
| 135 | if (stderr) detail = `\n${stderr.slice(-500)}`; |
| 136 | } |
| 137 | rmSync(BUILD_DIR, { recursive: true, force: true }); |
| 138 | throw new Error( |
| 139 | `whisper-cpp build failed. Ensure cmake and a C compiler are installed.${detail}`, |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | const result = findBuiltBinary(); |
| 144 | if (!result) throw new Error("Build completed but whisper-cli not found"); |
| 145 | return result; |
| 146 | } |
| 147 | |
| 148 | // --- Public API ------------------------------------------------------------- |
| 149 |
no test coverage detected