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
Skills: a chain made by hand (a result handed on to the next step) counts toward a suggestion too
Claudeec64cd8e5f33
diff --git a/src/server/recipes.ts b/src/server/recipes.tsindex 854be80c..33d2ddc8 100644--- a/src/server/recipes.ts+++ b/src/server/recipes.ts@@ -991,23 +991,29 @@ interface SweepRow {created_at: number;depends_on: string | null;request_json: string;+ outputs_json: string;}+/** Inputs that take a list of files, and those that take one: a result handed on by hand fills them (W2's linkByFile). */+const LIST_INPUTS = ["images", "videos", "audios"] as const;+const ONE_INPUTS = ["endImage", "video", "audio", "audio2", "voiceAudio"] as const;+/*** Group the owner's chains of the last SUGGEST_RULE.days days by shape (shapeOf) and keep the shapes made* SUGGEST_RULE.runs times or more. Only the owner's own runs count (an account's stay out of the owner's lists), and- * never a skill's own runs, a helper row or a canceled one. A chain is the rows linked by depends_on.+ * never a skill's own runs, a helper row or a canceled one. A chain is the rows linked by depends_on, or by a result+ * handed on by hand (its file is another step's input, as the skill builder links them).*/export function sweepSuggestions(now = Date.now()): SkillSuggestion[] {const rows = db().prepare(- `SELECT g.id, g.feature, g.provider, g.created_at, g.depends_on, g.request_json FROM generations g+ `SELECT g.id, g.feature, g.provider, g.created_at, g.depends_on, g.request_json, g.outputs_json FROM generations gLEFT JOIN generation_trash t ON t.generation_id = g.id- WHERE t.deleted_at IS NULL AND g.created_at >= ? AND g.status != 'canceled'+ WHERE t.deleted_at IS NULL AND g.created_at >= ? AND g.created_at <= ? AND g.status != 'canceled'AND json_extract(g.request_json, '$.account') IS NULL AND json_extract(g.request_json, '$.skill') IS NULLORDER BY g.created_at DESC LIMIT ${SWEEP_ROWS}`,)- .all(now - SUGGEST_RULE.days * DAY_MS) as SweepRow[];+ .all(now - SUGGEST_RULE.days * DAY_MS, now) as SweepRow[];const byId = new Map(rows.map((r) => [r.id, r]));// Chains: rows joined by depends_on (union-find over the window).const parent = new Map(rows.map((r) => [r.id, r.id]));@@ -1017,6 +1023,15 @@ export function sweepSuggestions(now = Date.now()): SkillSuggestion[] {parent.set(id, p);return p;};+ // Who made each file: a result handed on by hand (Edit, Animate, Use as input) links two steps as a chain slot does.+ const madeBy = new Map<string, SweepRow>();+ for (const r of [...rows].reverse()) {+ try {+ for (const o of JSON.parse(r.outputs_json) as { url?: string }[]) if (o.url && !madeBy.has(o.url)) madeBy.set(o.url, r);+ } catch {+ // A row without readable outputs feeds nothing.+ }+ }const nodes = new Map<string, ShapeNode>();for (const r of rows) {let req: GenerationRequest;@@ -1026,8 +1041,18 @@ export function sweepSuggestions(now = Date.now()): SkillSuggestion[] {continue;}const after = depList(r.depends_on).filter((d) => byId.has(d));+ const slots = after.map((_, i) => req.chain?.[i]?.slot ?? "images");+ const inputs = (req.inputs ?? {}) as Record<string, unknown>;+ const link = (url: unknown, slot: string) => {+ const src = typeof url === "string" ? madeBy.get(url) : undefined;+ if (!src || src.id === r.id || src.created_at > r.created_at || after.includes(src.id)) return;+ after.push(src.id);+ slots.push(slot);+ };+ for (const k of LIST_INPUTS) if (Array.isArray(inputs[k])) for (const url of inputs[k] as unknown[]) link(url, k);+ for (const k of ONE_INPUTS) link(inputs[k], k);for (const d of after) parent.set(find(r.id), find(d));- nodes.set(r.id, { id: r.id, modelId: currentModelId(req.modelId), op: req.op, feature: req.feature ?? r.feature, after, slots: after.map((_, i) => req.chain?.[i]?.slot ?? "images") });+ nodes.set(r.id, { id: r.id, modelId: currentModelId(req.modelId), op: req.op, feature: req.feature ?? r.feature, after, slots });}const chains = new Map<string, ShapeNode[]>();for (const n of nodes.values()) {diff --git a/tests/skill-suggest.test.ts b/tests/skill-suggest.test.tsindex 7d4d0f2b..4a87d3e0 100644--- a/tests/skill-suggest.test.ts+++ b/tests/skill-suggest.test.ts@@ -40,15 +40,15 @@ const DAY = 86_400_000;let n = 0;/** One stored row, as the runner leaves a finished generation. */-function row(o: { request: Record<string, unknown>; after?: string[]; at: number; provider?: string; feature?: string; status?: string; batch?: string }): string {+function row(o: { request: Record<string, unknown>; after?: string[]; at: number; provider?: string; feature?: string; status?: string; batch?: string; outputs?: string[] }): string {const id = `g${++n}`.padEnd(12, "x");const req: Record<string, unknown> = { feature: o.feature ?? "image", ...o.request };db().prepare(`INSERT INTO generations (id, batch_id, feature, model_id, engine, provider, op, kind, status, request_json, outputs_json, created_at, updated_at, depends_on)- VALUES (?, ?, ?, ?, 'cloud', ?, ?, 'image', ?, ?, '[]', ?, ?, ?)`,+ VALUES (?, ?, ?, ?, 'cloud', ?, ?, 'image', ?, ?, ?, ?, ?, ?)`,)- .run(id, o.batch ?? null, req.feature, String(req.modelId), o.provider ?? "fal", String(req.op ?? "t2i"), o.status ?? "succeeded", JSON.stringify(req), o.at, o.at, o.after?.length ? (o.after.length === 1 ? o.after[0] : JSON.stringify(o.after)) : null);+ .run(id, o.batch ?? null, req.feature, String(req.modelId), o.provider ?? "fal", String(req.op ?? "t2i"), o.status ?? "succeeded", JSON.stringify(req), JSON.stringify((o.outputs ?? []).map((url) => ({ url, kind: "image" }))), o.at, o.at, o.after?.length ? (o.after.length === 1 ? o.after[0] : JSON.stringify(o.after)) : null);return id;}@@ -143,6 +143,26 @@ describe("the Library's sweep", () => {expect(demo).toMatchObject({ count: 3, demo: true });});+ it("counts a chain made by hand (a result handed on as the next step's input) as the same chain", () => {+ const at = Date.UTC(2026, 9, 1, 12);+ const linked = (t: number, i: number) => {+ const a = row({ at: t, outputs: [`/api/files/outputs/cut-${i}.png`], request: { modelId: "birefnet-cloud", op: "bg-remove", inputs: { images: [`/api/files/uploads/p${i}.png`] } } });+ const b = row({ at: t + 1, after: [a], request: { modelId: "seedream-5-pro", op: "edit", prompt: `scene ${i}`, chain: [{ slot: "images", position: "first" }] } });+ return [a, b];+ };+ const byHand = (t: number, i: number) => {+ const a = row({ at: t, outputs: [`/api/files/outputs/hand-${i}.png`], request: { modelId: "birefnet-cloud", op: "bg-remove", inputs: { images: [`/api/files/uploads/h${i}.png`] } } });+ // An upload stays an input; the cut-out handed on links the two.+ const b = row({ at: t + 1, request: { modelId: "seedream-5-pro", op: "edit", prompt: `by hand ${i}`, inputs: { images: [`/api/files/outputs/hand-${i}.png`, "/api/files/uploads/backdrop.png"] } } });+ return [a, b];+ };+ linked(at - 3 * DAY, 1);+ byHand(at - 2 * DAY, 2);+ const newest = byHand(at - DAY, 3);+ const found = recipes.sweepSuggestions(at).find((s) => s.labels.join() === "Background removal,Image edit");+ expect(found).toMatchObject({ count: 3, ids: newest });+ });+it("runs once a day, and leaves out what was dismissed or put off", async () => {const first = recipes.skillSuggestions({ now });const turn = first.find((s) => s.labels.length === 3)!;