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.
This commit is contained in:
Miguel Ángel
2026-09-27 01:53:55 -04:00
parent 0567a6bdd4
commit b9a367dc55
5 changed files with 76 additions and 4 deletions
+1 -1
View File
@@ -54,7 +54,7 @@
"files": 1
},
"media-use": {
"hash": "521ef40fe0f1d2e0",
"hash": "2b92ce67c07577f4",
"files": 101
},
"motion-graphics": {
+2 -1
View File
@@ -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",
};
}
@@ -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 });
}
},
);
+13 -1
View File
@@ -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}`;
+40 -1
View File
@@ -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 });
}
},
);