From b9a367dc55cad62831b0e22cf96ae9db3c99c58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 27 Sep 2026 01:53:55 -0400 Subject: [PATCH] fix(skills): transcribe errors keep only the CLI's last lines; hint only on a failed run A failed media-use transcribe now reports the last few lines of the CLI's stderr instead of every spinner redraw, so the install hint stays readable. TTS captions suggest installing an engine only when the CLI exited with an error, not when it ran and found no words. --- skills-manifest.json | 2 +- skills/media-use/audio/scripts/lib/tts.mjs | 3 +- .../media-use/audio/scripts/lib/tts.test.mjs | 20 +++++++++ skills/media-use/scripts/transcribe.mjs | 14 ++++++- skills/media-use/scripts/transcribe.test.mjs | 41 ++++++++++++++++++- 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/skills-manifest.json b/skills-manifest.json index a2cd32942e..9032a628ce 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -54,7 +54,7 @@ "files": 1 }, "media-use": { - "hash": "521ef40fe0f1d2e0", + "hash": "2b92ce67c07577f4", "files": 101 }, "motion-graphics": { diff --git a/skills/media-use/audio/scripts/lib/tts.mjs b/skills/media-use/audio/scripts/lib/tts.mjs index c0c54e1637..97e1dbbaf1 100644 --- a/skills/media-use/audio/scripts/lib/tts.mjs +++ b/skills/media-use/audio/scripts/lib/tts.mjs @@ -376,10 +376,11 @@ export async function transcribeWav({ wavRel, lang = "en", hyperframesDir }) { } rmSync(td, { recursive: true, force: true }); if (words) return { words }; + if (r.status === 0) return { words: null, error: "hyperframes transcribe found no words" }; return { words: null, error: - `hyperframes transcribe exited ${r.status} with no words. If no engine is installed, ` + + `hyperframes transcribe exited ${r.status}. If no engine is installed, ` + "run `npx hyperframes models install parakeet`, or install whisper-cpp", }; } diff --git a/skills/media-use/audio/scripts/lib/tts.test.mjs b/skills/media-use/audio/scripts/lib/tts.test.mjs index 96745255bd..2fdf72de23 100644 --- a/skills/media-use/audio/scripts/lib/tts.test.mjs +++ b/skills/media-use/audio/scripts/lib/tts.test.mjs @@ -176,3 +176,23 @@ test( } }, ); + +test( + "transcribeWav gives no install hint when the CLI ran and found no words", + { skip: process.platform === "win32" }, + async () => { + const dir = mkdtempSync(join(tmpdir(), "tts-transcribe-")); + const realPath = process.env.PATH; + try { + writeFileSync(join(dir, "npx"), "#!/bin/sh\nexit 0\n"); + chmodSync(join(dir, "npx"), 0o755); + process.env.PATH = `${dir}:${realPath}`; + const r = await transcribeWav({ wavRel: "v.wav", hyperframesDir: dir }); + assert.equal(r.words, null); + assert.doesNotMatch(r.error, /install/); + } finally { + process.env.PATH = realPath; + rmSync(dir, { recursive: true, force: true }); + } + }, +); diff --git a/skills/media-use/scripts/transcribe.mjs b/skills/media-use/scripts/transcribe.mjs index 86a4a05e28..ab3fffc890 100644 --- a/skills/media-use/scripts/transcribe.mjs +++ b/skills/media-use/scripts/transcribe.mjs @@ -135,7 +135,19 @@ function runWhisper() { ["hyperframes", "transcribe", inputPath, "--dir", workDir], { stdio: ["ignore", "pipe", "pipe"], timeout: 1_800_000 }, ); - execFileSync(resolved.cmd, resolved.args, resolved.opts); + try { + execFileSync(resolved.cmd, resolved.args, resolved.opts); + } catch (e) { + // stderr holds spinner redraws; the last lines carry the reason. + const tail = String(e.stderr ?? "") + .replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "") + .split(/[\r\n]+/) + .map((l) => l.trim()) + .filter((l) => l && l !== "│") + .slice(-3) + .join("\n"); + throw new Error(`hyperframes transcribe failed (exit ${e.status ?? e.code})${tail ? `:\n${tail}` : ""}`); + } const produced = join(workDir, "transcript.json"); if (!existsSync(produced)) throw new Error("whisper produced no transcript.json"); const tmp = `${outPath}.tmp-${process.pid}`; diff --git a/skills/media-use/scripts/transcribe.test.mjs b/skills/media-use/scripts/transcribe.test.mjs index c4b0867cf1..bf5bd80305 100644 --- a/skills/media-use/scripts/transcribe.test.mjs +++ b/skills/media-use/scripts/transcribe.test.mjs @@ -1,5 +1,5 @@ import assert from "node:assert/strict"; -import { execFileSync } from "node:child_process"; +import { execFileSync, spawnSync } from "node:child_process"; import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -43,3 +43,42 @@ test( } }, ); + +test( + "a failed whisper run reports the CLI's last lines, not every spinner redraw", + { skip: process.platform === "win32" }, + () => { + const root = mkdtempSync(join(tmpdir(), "media-use-transcribe-")); + try { + const bin = join(root, "bin"); + mkdirSync(bin); + writeFileSync( + join(bin, "npx"), + `#!/bin/sh\ni=0\nwhile [ $i -lt 3000 ]; do printf '\\033[1G\\033[Jā—’ Checking whisper...\\n' >&2; i=$((i+1)); done\n` + + `echo "ā—‡ Captions skipped — run: hyperframes models install parakeet" >&2\nexit 1\n`, + ); + chmodSync(join(bin, "npx"), 0o755); + const input = join(root, "in.wav"); + writeFileSync(input, ""); + const script = fileURLToPath(new URL("./transcribe.mjs", import.meta.url)); + const res = spawnSync( + process.execPath, + [script, "--input", input, "--engine", "whisper", "--json"], + { + encoding: "utf8", + env: { + ...process.env, + PATH: `${bin}:${process.env.PATH}`, + HYPERFRAMES_MEDIA_HOME: join(root, "home"), + HYPERFRAMES_NO_TELEMETRY: "1", + }, + }, + ); + const { error } = JSON.parse(res.stdout.trim()); + assert.match(error, /hyperframes models install parakeet/); + assert.ok(error.length < 1000, `error is ${error.length} chars`); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }, +);