Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

CLI: fuobe skills run --wait follows every run of a table, not only the skill's newest 8

Claudee02e0375b152
diff --git a/bin/lib/commands.mjs b/bin/lib/commands.mjs
index 3e6091ac..00a301cc 100644
--- a/bin/lib/commands.mjs
+++ b/bin/lib/commands.mjs
@@ -290,7 +290,7 @@ async function waitRuns(ctx, name, runIds) {
const seen = new Map();
try {
for (;;) {
- const { items = [] } = await ctx.client.request("GET", `/api/assist/skills/${enc(name)}/runs`);
+ const { items = [] } = await ctx.client.request("GET", `/api/assist/skills/${enc(name)}/runs?ids=${runIds.map(enc).join(",")}`);
const mine = items.filter((r) => runIds.includes(r.id));
if (!v.json) {
for (const r of mine) {
diff --git a/src/app/api/assist/skills/[name]/runs/route.ts b/src/app/api/assist/skills/[name]/runs/route.ts
index 940792c2..b44f404e 100644
--- a/src/app/api/assist/skills/[name]/runs/route.ts
+++ b/src/app/api/assist/skills/[name]/runs/route.ts
@@ -1,14 +1,19 @@
import { connection } from "next/server";
+import { RECIPE_LIMITS } from "@/lib/recipe";
import { listSkillRuns } from "@/server/skill-runs";
import { getSkill } from "@/server/skills";
/**
* A skill's newest runs that span studios (recipe version 2), each step with its status and its studio's page: the
- * progress the skill's dialog shows. The owner's: a guest's or an account's read is refused by the proxy.
+ * progress the skill's dialog shows. `?ids=a,b` asks for those runs of the skill instead (the CLI following a CSV's
+ * runs). The owner's: a guest's or an account's read is refused by the proxy.
*/
-export async function GET(_request: Request, ctx: RouteContext<"/api/assist/skills/[name]/runs">) {
+export async function GET(request: Request, ctx: RouteContext<"/api/assist/skills/[name]/runs">) {
await connection();
const { name } = await ctx.params;
if (!getSkill(name)) return Response.json({ error: "No such skill" }, { status: 404 });
- return Response.json({ items: listSkillRuns(name) });
+ const asked = new URL(request.url).searchParams.get("ids");
+ const ids = asked === null ? undefined : [...new Set(asked.split(",").map((s) => s.trim()).filter(Boolean))];
+ if (ids && ids.length > RECIPE_LIMITS.rows) return Response.json({ error: `At most ${RECIPE_LIMITS.rows} runs at once` }, { status: 400 });
+ return Response.json({ items: ids ? listSkillRuns(name, ids.length, ids) : listSkillRuns(name) });
}
diff --git a/src/server/skill-runs.ts b/src/server/skill-runs.ts
index 540bd6c4..79100851 100644
--- a/src/server/skill-runs.ts
+++ b/src/server/skill-runs.ts
@@ -8,7 +8,7 @@ import { studioForTool } from "@/lib/recipe-builder";
import { executeTool } from "./assist/tools";
import { createPipeline } from "./chains";
import { db } from "./db";
-import { runAsDemo } from "./demo-scope";
+import { outsideDemo, runAsDemo } from "./demo-scope";
import { deleteDubSession } from "./dub";
import { deleteEpisode } from "./faceless";
import { getGeneration, stampRequests } from "./generations";
@@ -298,9 +298,20 @@ export function getSkillRun(id: string): SkillRunView | null {
return found ? view(found.row, found.state) : null;
}
-/** A skill's newest runs (dry runs left out). */
-export function listSkillRuns(skill: string, limit = 8): SkillRunView[] {
- const rows = db().prepare("SELECT * FROM skill_runs WHERE skill = ? ORDER BY created_at DESC LIMIT ?").all(skill, limit * 2) as Row[];
+/**
+ * A skill's newest runs (dry runs left out), or with `ids` exactly those of its runs (a CSV's runs, up to
+ * RECIPE_LIMITS.rows, which the CLI follows however many newer runs started since).
+ */
+export function listSkillRuns(skill: string, limit = 8, ids?: string[]): SkillRunView[] {
+ const rows = (
+ ids
+ ? ids.length
+ ? db()
+ .prepare(`SELECT * FROM skill_runs WHERE skill = ? AND id IN (${ids.map(() => "?").join(",")}) ORDER BY created_at DESC`)
+ .all(skill, ...ids)
+ : []
+ : db().prepare("SELECT * FROM skill_runs WHERE skill = ? ORDER BY created_at DESC LIMIT ?").all(skill, limit * 2)
+ ) as Row[];
return rows
.map((row) => ({ row, state: JSON.parse(row.state_json) as RunState }))
.filter((r) => !r.state.check)
@@ -371,7 +382,8 @@ export function ensureSkillRunSweep(): void {
cur.tick = tick;
return;
}
- const state = { tick, timer: setInterval(() => globalThis.__fuobeSkillRunSweep?.tick(), SWEEP_MS) };
+ // Outside a dry run's demo scope, which the timer would otherwise keep for every run it moves on.
+ const state = { tick, timer: outsideDemo(() => setInterval(() => globalThis.__fuobeSkillRunSweep?.tick(), SWEEP_MS)) };
state.timer.unref?.();
globalThis.__fuobeSkillRunSweep = state;
}
diff --git a/tests/cli-run.test.ts b/tests/cli-run.test.ts
index 542184d1..b30f448b 100644
--- a/tests/cli-run.test.ts
+++ b/tests/cli-run.test.ts
@@ -121,7 +121,11 @@ beforeAll(async () => {
if (route === "GET /api/assist/skills/weekly-promo/runs") {
runPolls++;
const done = runPolls >= 2;
- return send(200, { items: [{ id: "r1", status: done ? "done" : "running", steps: [{ key: "dub", label: "Dub", status: "done", ids: ["gen1"] }, { key: "cut", label: "9:16 cut", status: done ? "done" : "waiting", ids: done ? ["gen9"] : [] }] }] });
+ // Like the server: the newest 8 runs, or with ?ids= exactly those runs.
+ const ids = url.searchParams.get("ids")?.split(",") ?? Array.from({ length: 8 }, (_, i) => `r${i + 1}`);
+ return send(200, {
+ items: ids.map((id) => ({ id, status: done ? "done" : "running", steps: [{ key: "dub", label: "Dub", status: "done", ids: ["gen1"] }, { key: "cut", label: "9:16 cut", status: done ? "done" : "waiting", ids: done ? ["gen9"] : [] }] })),
+ });
}
if (route === "GET /api/generations") return send(200, { items: [generation("succeeded")] });
if (route === "GET /api/files/outputs/2026-10-22/out1.png") {
@@ -152,7 +156,7 @@ beforeAll(async () => {
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.
// A skill that spans studios: a run whose later step waits for the dub (W7).
- if (rows[0].name === "Spanish") return send(201, { engine: "cloud", demo: false, runs: [{ run: "r1", batchId: "r1", ids: ["gen1"], href: "/audio/translate?dub=d1", waiting: ["9:16 cut"] }] });
+ if (rows[0].name === "Spanish") return send(201, { engine: "cloud", demo: false, runs: rows.map((_, i) => ({ run: `r${i + 1}`, batchId: `r${i + 1}`, ids: ["gen1"], href: "/audio/translate?dub=d1", waiting: ["9:16 cut"] })) });
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.
@@ -498,6 +502,17 @@ describe("fuobe skills: a skill that runs by itself (W4)", () => {
expect(runPolls).toBeGreaterThanOrEqual(2);
});
+ it("--wait follows every run of a table of more than 8 rows that span studios, not only the newest 8", async () => {
+ fs.writeFileSync(path.join(tmp, "lamp.png"), PNG);
+ fs.writeFileSync(path.join(tmp, "nine.csv"), `Product photo,Product name\n${Array.from({ length: 9 }, () => "lamp.png,Spanish").join("\n")}\n`);
+ polls = 0;
+ runPolls = 0;
+ const w = await run(["skills", "run", "weekly-promo", "--rows", "nine.csv", "--yes", "--wait", "--json", "--interval", "0.2", "--timeout", "20"]);
+ expect(w.code).toBe(0);
+ const asked = seen.filter((s) => s.path.startsWith("/api/assist/skills/weekly-promo/runs")).map((s) => s.path);
+ expect(asked.at(-1)).toBe(`/api/assist/skills/weekly-promo/runs?ids=${Array.from({ length: 9 }, (_, i) => `r${i + 1}`).join(",")}`);
+ });
+
it("--rows: one run per row, -p fills the empty cells, files beside the table go up once, and --json skips the question", async () => {
const dir = path.join(tmp, "products");
fs.mkdirSync(dir, { recursive: true });