Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cli/src/media-use/lib/sfx-provider.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { heygenSearch } from "./heygen-search.mjs";
import { OpenverseUnavailableError, searchOpenverseSfx } from "./openverse.mjs";
import { terminalText } from "./terminal-text.mjs";

export const OPENVERSE_SFX_PROVIDER = "openverse.audio";

Expand All @@ -24,7 +25,9 @@ export const heygenSfxProvider = {
minScore: SFX_MIN_SCORE,
onEmpty: () =>
console.error(
`media-use: HeyGen sound search matched nothing for "${intent}" at min score ${SFX_MIN_SCORE}; trying the next source`,
terminalText(
`media-use: HeyGen sound search matched nothing for "${intent}" at min score ${SFX_MIN_SCORE}; trying the next source`,
),
),
});
if (!results) return null;
Expand All @@ -50,7 +53,7 @@ export const sfxProvider = {
sound = await searchOpenverseSfx(intent);
} catch (error) {
if (!(error instanceof OpenverseUnavailableError)) throw error;
console.error(`media-use: ${error.message}; using the bundled sound effects`);
console.error(terminalText(`media-use: ${error.message}; using the bundled sound effects`));
return null;
}
if (!sound) return null;
Expand Down
52 changes: 52 additions & 0 deletions packages/cli/src/media-use/lib/sfx-provider.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { strict as assert } from "node:assert";
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { delimiter, join } from "node:path";
import { test } from "node:test";
import { heygenSfxProvider, sfxProvider } from "./sfx-provider.mjs";

const HOSTILE = "\x1b]52;c;aGk=\x07\x1b[2J";
const SHOWN = "\\x1b]52;c;aGk=\\x07\\x1b[2J";

function captureStderr(t) {
const lines = [];
t.mock.method(console, "error", (...args) => lines.push(args.join(" ")));
return lines;
}

function assertEscaped(lines) {
const out = lines.join("\n");
assert.ok(out.includes(SHOWN), out);
for (const raw of ["\x1b", "\x07"]) assert.ok(!out.includes(raw), JSON.stringify(out));
}

test(
"an empty HeyGen sound search repeats the intent with control characters as visible escapes",
{
skip: process.platform === "win32" && "the fake heygen binary is a shell script",
},
async (t) => {
const bin = mkdtempSync(join(tmpdir(), "sfx-provider-heygen-"));
const savedPath = process.env.PATH;
try {
writeFileSync(join(bin, "heygen"), `#!/bin/sh\necho '{"data":[]}'\n`);
chmodSync(join(bin, "heygen"), 0o755);
process.env.PATH = `${bin}${delimiter}${savedPath}`;
const lines = captureStderr(t);
assert.equal(await heygenSfxProvider.search(`whoosh${HOSTILE}`), null);
assertEscaped(lines);
} finally {
process.env.PATH = savedPath;
rmSync(bin, { recursive: true, force: true });
}
},
);

test("an unreachable Openverse error prints with control characters as visible escapes", async (t) => {
t.mock.method(globalThis, "fetch", async () => {
throw new Error(`proxy said ${HOSTILE}`);
});
const lines = captureStderr(t);
assert.equal(await sfxProvider.search("whoosh"), null);
assertEscaped(lines);
});
4 changes: 2 additions & 2 deletions skills-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"files": 13
},
"media-use": {
"hash": "6d018bd953cd09b1",
"files": 130
"hash": "ade4f491789eec78",
"files": 131
},
"remotion-to-hyperframes": {
"hash": "27f757cb659e1aaa",
Expand Down
108 changes: 108 additions & 0 deletions skills/media-use/scripts/memory-output.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { strict as assert } from "node:assert";
import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { test } from "node:test";

const scriptsDir = new URL(".", import.meta.url).pathname;
const HOSTILE = "x\x1b]52;c;aGk=\x07\x1b[2J";
const SHOWN = "x\\x1b]52;c;aGk=\\x07\\x1b[2J";

function run(script, args, home) {
return execFileSync(process.execPath, [join(scriptsDir, script), ...args], {
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
env: { ...process.env, HYPERFRAMES_MEDIA_HOME: home },
});
}

function assertEscaped(output) {
assert.ok(output.includes(SHOWN), output);
for (const raw of ["\x1b", "\x07"]) assert.ok(!output.includes(raw), JSON.stringify(output));
}

function withProject(fn) {
const root = mkdtempSync(join(tmpdir(), "media-use-memory-output-"));
const home = join(root, "home");
const project = join(root, "project");
mkdirSync(home, { recursive: true });
mkdirSync(join(project, ".media/recipes/promo"), { recursive: true });
writeFileSync(join(project, "frame.md"), "# Frame spec\n");
writeFileSync(
join(project, ".media/recipes/promo/recipe.json"),
JSON.stringify({
name: "promo",
version: 1,
workflow: `launch-${HOSTILE}`,
approved_at: "2026-11-18T00:00:00Z",
destination: `feed-${HOSTILE}`,
}),
);
writeFileSync(join(project, ".media/recipes/promo/frame.md"), "# Frame spec\n");
writeFileSync(join(project, ".media/recipes/promo/storyboard-skeleton.md"), "## Frame 1\n");
writeFileSync(
join(project, ".media/preferences.json"),
JSON.stringify({
version: 1,
preferences: {
destination: { value: `feed-${HOSTILE}`, confirmed_in: [`proj-${HOSTILE}`] },
},
}),
);
try {
fn({ project, home });
} finally {
rmSync(root, { recursive: true, force: true });
}
}

test("recipe list and use print recipe.json text with control characters as visible escapes", () => {
withProject(({ project, home }) => {
assertEscaped(run("recipe.mjs", ["list", "--hyperframes", project], home));
const used = run("recipe.mjs", ["use", "--hyperframes", project, "--name", "promo"], home);
assertEscaped(used);
assert.match(used, /destination: feed-x\\x1b/);
});
});

test("recipe --json output keeps the stored value as it is", () => {
withProject(({ project, home }) => {
const list = JSON.parse(run("recipe.mjs", ["list", "--hyperframes", project, "--json"], home));
assert.equal(list[0].workflow, `launch-${HOSTILE}`);
});
});

test("prefs get prints remembered values with control characters as visible escapes", () => {
withProject(({ project, home }) => {
const shown = run("prefs.mjs", ["get", "--hyperframes", project], home);
assertEscaped(shown);
assert.match(shown, /confirmed in proj-x\\x1b/);
});
});

test("prefs record echoes the recorded value with control characters as visible escapes", () => {
withProject(({ project, home }) => {
const shown = run(
"prefs.mjs",
["record", "--hyperframes", project, "--key", "aspect", "--value", `16:9${HOSTILE}`],
home,
);
assertEscaped(shown);
});
});

test("a failing recipe command prints its error with control characters as visible escapes", () => {
withProject(({ project, home }) => {
const other = join(project, ".media/recipes/other");
mkdirSync(other, { recursive: true });
writeFileSync(join(other, "recipe.json"), JSON.stringify({ name: `other-${HOSTILE}` }));
assert.throws(
() => run("recipe.mjs", ["use", "--hyperframes", project, "--name", "nope"], home),
(err) => {
assertEscaped(String(err.stderr));
return err.status === 1;
},
);
});
});
9 changes: 6 additions & 3 deletions skills/media-use/scripts/prefs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import { parseArgs } from "node:util";
import { mergedPreferences, recordPreference } from "./lib/prefs-store.mjs";
import { terminalText } from "./lib/terminal-text.mjs";

const { values: args, positionals } = parseArgs({
options: {
Expand All @@ -31,7 +32,7 @@ const { values: args, positionals } = parseArgs({
const verb = positionals[0];

function fail(message) {
console.error(message);
console.error(terminalText(message));
process.exit(1);
}

Expand All @@ -44,7 +45,9 @@ if (verb === "get") {
} else {
for (const [key, entry] of Object.entries(merged)) {
console.log(
`${key} = ${entry.value} (${entry.source}; confirmed in ${entry.confirmed_in.join(", ")})`,
terminalText(
`${key} = ${entry.value} (${entry.source}; confirmed in ${entry.confirmed_in.join(", ")})`,
),
);
}
}
Expand All @@ -58,7 +61,7 @@ if (verb === "get") {
workflow: args.workflow,
});
const promotion = result.promoted ? "; promoted to user tier" : "";
console.log(`recorded ${result.key} = ${result.value} (project${promotion})`);
console.log(terminalText(`recorded ${result.key} = ${result.value} (project${promotion})`));
} catch (err) {
fail(err instanceof Error ? err.message : String(err));
}
Expand Down
28 changes: 19 additions & 9 deletions skills/media-use/scripts/recipe.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
import { parseArgs } from "node:util";
import { freezeRecipe, listRecipes, useRecipe } from "./lib/recipe-store.mjs";
import { terminalText } from "./lib/terminal-text.mjs";

const { values: args, positionals } = parseArgs({
options: {
Expand All @@ -37,7 +38,7 @@ const { values: args, positionals } = parseArgs({
const verb = positionals[0];

function fail(message) {
console.error(message);
console.error(terminalText(message));
process.exit(1);
}

Expand All @@ -58,10 +59,14 @@ try {
if (args.json) console.log(JSON.stringify({ ok: true, ...frozen }));
else {
console.log(
`froze recipe ${frozen.slug} (v${frozen.version}, ${frozen.workflow}) → ${frozen.dir}`,
terminalText(
`froze recipe ${frozen.slug} (v${frozen.version}, ${frozen.workflow}) → ${frozen.dir}`,
),
);
if (frozen.workflowOverridden)
console.log(` (BRIEF.md says "${frozen.workflow}" — the --workflow flag was ignored)`);
console.log(
terminalText(` (BRIEF.md says "${frozen.workflow}" — the --workflow flag was ignored)`),
);
if (!frozen.briefSkeleton)
console.log(" (no BRIEF.md in the project — brief skeleton skipped)");
}
Expand All @@ -72,7 +77,9 @@ try {
else {
for (const r of list) {
console.log(
`${r.name} v${r.version} ${r.workflow} (${r.source}; approved ${String(r.approved_at ?? "?").slice(0, 10)})`,
terminalText(
`${r.name} v${r.version} ${r.workflow} (${r.source}; approved ${String(r.approved_at ?? "?").slice(0, 10)})`,
),
);
}
}
Expand All @@ -82,13 +89,16 @@ try {
if (args.json) console.log(JSON.stringify({ ok: true, ...used }));
else {
console.log(
`using recipe ${used.recipe.name} (v${used.recipe.version}, ${used.recipe.workflow})`,
terminalText(
`using recipe ${used.recipe.name} (v${used.recipe.version}, ${used.recipe.workflow})`,
),
);
console.log(` frame spec → ${used.frameSpecPath} (copied over)`);
console.log(` storyboard skeleton → ${used.skeletonPath}`);
if (used.briefSkeletonPath) console.log(` brief skeleton → ${used.briefSkeletonPath}`);
console.log(terminalText(` frame spec → ${used.frameSpecPath} (copied over)`));
console.log(terminalText(` storyboard skeleton → ${used.skeletonPath}`));
if (used.briefSkeletonPath)
console.log(terminalText(` brief skeleton → ${used.briefSkeletonPath}`));
for (const key of ["destination", "aspect", "language", "voice", "style_preset"]) {
if (used.recipe[key]) console.log(` ${key}: ${used.recipe[key]}`);
if (used.recipe[key]) console.log(terminalText(` ${key}: ${used.recipe[key]}`));
}
}
} else {
Expand Down
Loading