The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
CLI: fuobe skills run prices your uploaded files again and asks again when the total rose, and names a row that didn't start by its line in your file
Claude5d5eff9cd13a
diff --git a/bin/lib/commands.mjs b/bin/lib/commands.mjsindex f13fdd50..f18ea7ca 100644--- a/bin/lib/commands.mjs+++ b/bin/lib/commands.mjs@@ -291,11 +291,11 @@ async function saveOutputs(ctx, gens, dir) {return files;}-/** Wait, report, download: shared by generate --wait, wait and download. Returns the exit code. */-async function finish(ctx, ids, { download }) {+/** Wait, report, download: shared by generate --wait, wait and download. `also` adds to the --json output. Returns the exit code. */+async function finish(ctx, ids, { download, also = {} }) {const { gens, stopped } = await waitFor(ctx, ids);const files = download && !stopped ? await saveOutputs(ctx, gens, ctx.values.out ?? ".") : [];- if (ctx.values.json) ctx.json({ items: gens, ...(download && { files }), ...(stopped && { stopped }) });+ if (ctx.values.json) ctx.json({ items: gens, ...(download && { files }), ...(stopped && { stopped }), ...also });else if (!download || stopped) report(ctx, gens);else for (const g of gens.filter((x) => x.status !== "succeeded")) report(ctx, [g]);if (stopped === "interrupted") {@@ -716,6 +716,8 @@ async function skillRequest(ctx, view) {return {rows: true,files: [...files],+ /** The line in the person's file of the i-th run (one run per row). */+ runLine: (i) => rest[i]?.line,// A row's line in the table sent, back to its line in the person's file.lineOf: (l) => {const k = sent.indexOf(l);@@ -767,6 +769,20 @@ async function skillsEstimate(ctx, name) {return est.runnable ? EXIT.ok : EXIT.failed;}+/** "Run 20 for $12.40? [y/N] " */+const runQuestion = (est, runs) => `Run ${runs} ${est.total === null ? "(some prices vary)" : `for ${exactCost(est.total)}`}? [y/N] `;++/** What a price check says the runs cost, in a sentence's words. */+const costWords = (est) => (est.total === null ? "an amount that varies" : exactCost(est.total));++/** Whether the price with the real files is higher than the one first shown (a clip is priced by its length, which a stand-in doesn't have). */+function priceRose(first, real) {+ if (real.demo || real.total === 0) return false;+ if (first.demo || first.total === 0) return true;+ if (first.total === null) return false;+ return real.total === null || real.total > first.total + 0.005;+}+async function skillsRun(ctx, name) {const v = ctx.values;const view = await recipeOf(ctx, name);@@ -776,11 +792,11 @@ async function skillsRun(ctx, name) {const est = await priceSkill(ctx, view, engine, req.body(fileStandIn));if (!est.runnable) throw new ApiError(estimateProblems(est, req).join("\n") || `/${view.name} can't run with these values`);const runs = est.runs.length;+ const asks = !v.yes && !v.json;const costs = !est.demo && est.total !== 0;- if (costs && !v.yes && !v.json) {- const price = est.total === null ? "(some prices vary)" : `for ${exactCost(est.total)}`;- if (!ctx.io.stdinIsTTY) throw new UsageError(`Running ${runs === 1 ? "it" : `these ${runs}`} costs ${est.total === null ? "an amount that varies" : exactCost(est.total)}: add --yes to run without asking`);- const answer = await ctx.io.ask(`Run ${runs} ${price}? [y/N] `);+ if (costs && asks) {+ if (!ctx.io.stdinIsTTY) throw new UsageError(`Running ${runs === 1 ? "it" : `these ${runs}`} costs ${costWords(est)}: add --yes to run without asking`);+ const answer = await ctx.io.ask(runQuestion(est, runs));if (!/^y(es)?$/i.test(answer.trim())) {ctx.note("Nothing was started.");return EXIT.failed;@@ -789,21 +805,50 @@ async function skillsRun(ctx, name) {if (!view.ready.includes(engine)) await checkSkill(ctx, view, engine);const uploaded = new Map();for (const f of req.files) uploaded.set(f, await uploadFile(ctx, f));- const out = await ctx.client.request("POST", `/api/assist/skills/${enc(view.name)}/run`, { json: { ...req.body((f) => uploaded.get(f)), engine } });+ const body = req.body((f) => uploaded.get(f));+ // Priced again with the real files: when that's more than the price first shown, it asks again.+ if (asks && req.files.length) {+ const real = await priceSkill(ctx, view, engine, body);+ if (!real.runnable) throw new ApiError(estimateProblems(real, req).join("\n") || `/${view.name} can't run with these files`);+ if (priceRose(est, real)) {+ const was = costs ? `, not ${costWords(est)}` : "";+ if (!ctx.io.stdinIsTTY) throw new UsageError(`With your files uploaded, running ${runs === 1 ? "it" : `these ${runs}`} costs ${costWords(real)}${was}: add --yes to run without asking. Nothing was started.`);+ const answer = await ctx.io.ask(`With your files it costs ${costWords(real)}${was}. ${runQuestion(real, runs)}`);+ if (!/^y(es)?$/i.test(answer.trim())) {+ ctx.note("Nothing was started.");+ return EXIT.failed;+ }+ }+ }+ let out;+ try {+ out = await ctx.client.request("POST", `/api/assist/skills/${enc(view.name)}/run`, { json: { ...body, engine } });+ } catch (e) {+ // A refusal names rows by their line in the table sent: say the line in the person's file instead.+ if (req.rows && e instanceof ApiError) e.message = e.message.replace(/\bRow (\d+): /g, (_, n) => `Row ${req.lineOf(Number(n))}: `);+ throw e;+ }const ids = out.runs.flatMap((r) => r.ids);const started = out.runs.filter((r) => !r.error).length;+ const all = started === out.runs.length;+ // Each run as the server answered, with its row's line in the file for a table.+ const runsOut = out.runs.map((r, i) => (req.rows ? { ...r, line: req.runLine(i) } : r));const demo = out.demo ? " (a demo: nothing connected, free)" : "";- for (const [i, r] of out.runs.entries()) if (r.error && !v.json) ctx.note(`Run ${i + 1} didn't start: ${r.error}`);+ for (const [i, r] of out.runs.entries()) if (r.error && !v.json) ctx.note(`${req.rows ? `Row ${req.runLine(i)}` : `Run ${i + 1}`} didn't start: ${r.error}`);const studio = out.runs.find((r) => r.href && !r.href.startsWith("/library"))?.href;if (v.wait || v.out) {- if (!v.json) ctx.note(`Started ${started === 1 ? view.title : `${started} runs of ${view.title}`}${demo}.${studio ? ` It opens in ${absolute(ctx, studio)}` : ""}`);- return finish(ctx, ids, { download: !!v.out });+ if (!v.json) ctx.note(`Started ${started === 1 ? view.title : `${started} runs of ${view.title}`}${all ? "" : ` (${out.runs.length - started} didn't start)`}${demo}.${studio ? ` It opens in ${absolute(ctx, studio)}` : ""}`);+ const code = await finish(ctx, ids, { download: !!v.out, also: { runs: runsOut } });+ return code === EXIT.ok && !all ? EXIT.failed : code;+ }+ if (v.json) {+ ctx.json({ ...out, runs: runsOut });+ return all ? EXIT.ok : EXIT.failed;}- if (v.json) return ctx.json(out);ctx.print(`Started ${started === 1 ? view.title : `${started} runs of ${view.title}`} on ${engineWords(out.engine)}${demo}: ${ids.join(" ")}`);if (studio) ctx.print(`It opens in ${absolute(ctx, studio)}`);if (ids.length) ctx.print(`Wait for ${ids.length === 1 ? "it" : "them"}: fuobe wait ${ids.join(" ")} Save ${ids.length === 1 ? "it" : "them"}: fuobe download ${ids.join(" ")} --out .`);- return started === out.runs.length ? EXIT.ok : EXIT.failed;+ return all ? EXIT.ok : EXIT.failed;}async function skillsExport(ctx, name) {diff --git a/docs/cli.md b/docs/cli.mdindex 675faf1d..d7c161a6 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -220,11 +220,15 @@ fuobe skills export weekly-promo --out weekly-promo.zip # SKILL.md and its filwhat the rows leave empty. A row that doesn't fit is named by its line, and then nothing starts.- `run` prices the whole batch first and asks `Run 20 for $12.40? [y/N]` when it costs money. `--yes`starts it without asking; so does `--json` (for scripts). Without a terminal to ask on, it stops and- says to add `--yes`. Free runs (your GPU, or a demo) start without asking.+ says to add `--yes`. Free runs (your GPU, or a demo) start without asking. Once your files are uploaded+ it prices them again (a clip is priced by its length): when that's more, it asks again with the new+ price, or stops without a terminal.- `--engine open|cloud` picks where it runs, among the engines its steps run on (by default: where itwas checked). A skill not yet checked on that engine gets its free plan check first.- `--wait` and `--out <dir>` wait for the results and save them, as `fuobe generate` does; without them,- `run` prints the ids to pass to `fuobe wait` or `fuobe download`.+ `run` prints the ids to pass to `fuobe wait` or `fuobe download`. When a row didn't start (a studio+ tool's run can refuse one row and start the rest), it says which by its line in your file and exits 1;+ `--json` lists every run under `runs`, each with its `error` and, for `--rows`, its `line`.- `export` saves the skill as a zip (`SKILL.md`, `recipe.json` and its other files); `--examples` keepsthe values it was made with, which are left out by default.diff --git a/tests/cli-run.test.ts b/tests/cli-run.test.tsindex e8d4fa7b..02f26cb4 100644--- a/tests/cli-run.test.ts+++ b/tests/cli-run.test.ts@@ -138,10 +138,18 @@ beforeAll(async () => {const b = s.json as { values?: Record<string, string>; csv?: string; engine?: string };// The CSV the CLI sent, read as the server would: header first, one run per line.const rows = b.csv ? b.csv.trim().split("\n").slice(1).map((l, i) => ({ line: i + 2, name: l.split(",")[1] ?? "" })) : [{ line: 1, name: b.values?.name ?? "" }];- if (skill === "run") return send(201, { engine: b.engine ?? "cloud", demo: false, runs: rows.map((_, i) => ({ batchId: `b${i}`, ids: i ? [`gen${i + 1}`] : ["gen1"], href: "/library" })) });- const runs = rows.map((r) => ({ line: r.line, jobs: [job], total: r.name === "bad" ? null : 0.62, errors: r.name === "bad" ? ["Product name: at most 200 characters"] : [] }));+ if (skill === "run") {+ // A real file can fail a check its stand-in passed: the server names the row by its line in the table sent.+ const long = rows.filter((r) => r.name === "toolong");+ if (long.length) return send(422, { error: `Fix the recipe first: ${long.map((r) => `Row ${r.line}: The clip is longer than 10 s`).join("; ")}`, problems: [] });+ // A tool row that couldn't start while the others run.+ return send(201, { engine: b.engine ?? "cloud", demo: false, runs: rows.map((r, i) => (r.name === "nope" ? { ids: [], error: "The tool couldn't start" } : { batchId: `b${i}`, ids: i ? [`gen${i + 1}`] : ["gen1"], href: "/library" })) });+ }+ // A clip is priced by its length once it's uploaded: more than its stand-in.+ const real = JSON.stringify(b).includes("/api/files/uploads/2026-10-22/up1.png");+ const runs = rows.map((r) => ({ line: r.line, jobs: [job], total: r.name === "bad" ? null : real && r.name === "Long clip" ? 1.5 : 0.62, errors: r.name === "bad" ? ["Product name: at most 200 characters"] : [] }));const ok = runs.every((r) => !r.errors.length);- return send(200, { engine: b.engine ?? "cloud", runs, jobs: [job], total: ok ? Math.round(0.62 * runs.length * 100) / 100 : null, demo: false, runnable: ok, errors: [] });+ return send(200, { engine: b.engine ?? "cloud", runs, jobs: [job], total: ok ? Math.round(runs.reduce((a, r) => a + (r.total ?? 0), 0) * 100) / 100 : null, demo: false, runnable: ok, errors: [] });}if (skill === "download") {res.writeHead(200, { "content-type": "application/zip" });@@ -489,6 +497,80 @@ describe("fuobe skills: a skill that runs by itself (W4)", () => {expect(seen.some((s) => s.path.endsWith("/run") || s.path === "/api/uploads")).toBe(false);});+ /** A terminal that answers each question in turn. */+ function terminal(answers: string[]) {+ const out: string[] = [];+ const questions: string[] = [];+ const io = {+ stdout: { write: (t: string) => out.push(t) },+ stderr: { write: (t: string) => out.push(t) },+ env: { FUOBE_URL: base, FUOBE_TOKEN: TOKEN, FUOBE_CONFIG: path.join(tmp, "config.json") },+ cwd: tmp,+ home: tmp,+ fetch: globalThis.fetch,+ columns: 100,+ stdinIsTTY: true,+ stderrIsTTY: false,+ now: () => Date.now(),+ sleep: (ms: number) => new Promise((r) => setTimeout(r, ms)),+ onInterrupt: () => () => {},+ ask: async (q: string) => (questions.push(q), answers.shift() ?? "n"),+ readStdin: async () => "",+ };+ return { io, out, questions };+ }++ it("with the files uploaded it prices again, and asks again when that's more", async () => {+ const { main } = await import("../bin/lib/cli.mjs");+ fs.writeFileSync(path.join(tmp, "clip.png"), PNG);+ const no = terminal(["y", "n"]);+ expect(await main(["skills", "run", "weekly-promo", "-p", "product=clip.png", "-p", "name=Long clip"], no.io)).toBe(1);+ expect(no.questions).toEqual(["Run 1 for $0.62? [y/N] ", "With your files it costs $1.50, not $0.62. Run 1 for $1.50? [y/N] "]);+ expect(no.out.join("")).toContain("Nothing was started.");+ expect(seen.filter((s) => s.method === "POST").map((s) => s.path)).toEqual([+ "/api/assist/skills/weekly-promo/estimate",+ "/api/assist/skills/weekly-promo/verify",+ "/api/uploads",+ "/api/assist/skills/weekly-promo/estimate",+ ]);+ expect(posts("estimate")[1].json).toEqual({ values: { product: "/api/files/uploads/2026-10-22/up1.png", name: "Long clip" }, engine: "cloud" });+ seen = [];+ const yes = terminal(["y", "y"]);+ expect(await main(["skills", "run", "weekly-promo", "-p", "product=clip.png", "-p", "name=Long clip"], yes.io)).toBe(0);+ expect(posts("run")).toHaveLength(1);+ // The same price with the real file: one question.+ seen = [];+ const same = terminal(["y"]);+ expect(await main(["skills", "run", "weekly-promo", "-p", "product=clip.png", "-p", "name=Lumen"], same.io)).toBe(0);+ expect(same.questions).toEqual(["Run 1 for $0.62? [y/N] "]);+ expect(posts("estimate")).toHaveLength(2);+ expect(posts("run")).toHaveLength(1);+ });++ it("--wait exits 1 and --json lists each run's error when a row didn't start", async () => {+ fs.writeFileSync(path.join(tmp, "some.csv"), "product,name\nhttps://cdn.test/a.png,Lumen\n\nhttps://cdn.test/b.png,nope\n");+ const r = await run(["skills", "run", "weekly-promo", "--rows", "some.csv", "--yes", "--wait", "--json", "--interval", "0.2"]);+ expect(r.code).toBe(1);+ const out = JSON.parse(r.stdout);+ expect(out.items.map((g: { id: string }) => g.id)).toEqual(["gen1"]);+ expect(out.runs).toEqual([+ { batchId: "b0", ids: ["gen1"], href: "/library", line: 2 },+ { ids: [], error: "The tool couldn't start", line: 4 },+ ]);+ const words = await run(["skills", "run", "weekly-promo", "--rows", "some.csv", "--yes", "--wait", "--interval", "0.2"]);+ expect(words.code).toBe(1);+ expect(words.stderr).toContain("Row 4 didn't start: The tool couldn't start");+ expect(words.stderr).toContain("Started Weekly promo (1 didn't start).");+ });++ it("a row the run refuses is named by its line in the file", async () => {+ fs.writeFileSync(path.join(tmp, "long.csv"), "product,name\nhttps://cdn.test/a.png,Lumen\n\nhttps://cdn.test/b.png,toolong\n");+ const r = await run(["skills", "run", "weekly-promo", "--rows", "long.csv", "--yes"]);+ expect(r.code).toBe(1);+ expect(r.stderr.trim().split("\n").at(-1)).toBe("Fix the recipe first: Row 4: The clip is longer than 10 s");+ expect(posts("run")).toHaveLength(1);+ });+it("asks on a terminal: no starts nothing, yes runs", async () => {const { main } = await import("../bin/lib/cli.mjs");const out: string[] = [];