Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(workflows): add the /forge/workflows node builder that chains prompt or photo to 3D, rig, remesh, restyle and export in one run

nirholas544f15c49c66
diff --git a/data/pages.json b/data/pages.json
index d1f45915a..c27b2dc1c 100644
--- a/data/pages.json
+++ b/data/pages.json
@@ -749,6 +749,14 @@
"added": "2026-10-09",
"showcase": true
},
+ {
+ "path": "/forge/workflows",
+ "title": "Forge Workflows: Chain 3D Tools into One Run",
+ "description": "A visual workflow builder for the Forge. Link a prompt or a photo to any live 3D engine, then remesh, rig, segment, restyle or make it game-ready, preview it inline, export the GLB and save it to your library, all in one run. Batch many prompts with ForEach, re-run from a failed step without redoing the rest, or generate on your own GPU with Modly. Starts from four templates.",
+ "priority": 0.7,
+ "changefreq": "weekly",
+ "added": "2026-10-09"
+ },
{
"path": "/image-to-3d",
"title": "Image to 3D: Turn a Photo into a 3D Model",
diff --git a/docs/forge-workflows.md b/docs/forge-workflows.md
new file mode 100644
index 000000000..fa00f7022
--- /dev/null
+++ b/docs/forge-workflows.md
@@ -0,0 +1,167 @@
+# Forge Workflows: chain 3D tools into one run
+
+Forge Workflows is a visual node editor for the Forge toolchain. You place nodes on a canvas (a prompt or a photo, a generator, processing steps such as Auto-rig or Remesh, and an output such as Export), wire them together, and press **Run**. Every node calls the same production endpoint the rest of three.ws uses, so a workflow is a repeatable recipe for real work, not a simulation.
+
+Page: [/forge/workflows](https://three.ws/forge/workflows)
+
+## Why it exists
+
+[Forge](./forge.md) is one box: type or drop something in, get a model out. Creators who make game props, rigged characters or printable parts repeat the same three or four steps after that, by hand, every time. Forge Workflows turns those steps into a graph you build once, save as a file, share, and run again on a new prompt or a batch of photos. A failed step does not throw away the rest: re-run from the node that failed and every finished step before it is reused.
+
+[Workbench](./workbench.md) covers a related need with a fixed photo pipeline and a large viewport for in-browser mesh edits. Forge Workflows is the free-form graph: any order, branches, batches, and several outputs from one run.
+
+## Quick start
+
+1. Open [/forge/workflows](https://three.ws/forge/workflows). An empty canvas offers four templates.
+2. Pick **Text to rigged character**. Five nodes appear: Text prompt, Generate 3D, Auto-rig, Preview and Export.
+3. Edit the prompt in the inspector on the right, or keep the default.
+4. Press **Run** or <kbd>Ctrl</kbd>+<kbd>Enter</kbd> (<kbd>Cmd</kbd>+<kbd>Enter</kbd> on a Mac). Each card shows its state and live progress. When the run finishes, Preview shows the rigged model and Export downloads `rigged-character.glb`.
+
+You can also link straight to a template: `/forge/workflows?template=text-rig-export`.
+
+## Templates
+
+| Template | Id | Chain | Needs |
+|---|---|---|---|
+| Photo to 3D | `image-preview` | Image → Generate 3D → Preview | A photo |
+| Text to rigged character | `text-rig-export` | Text prompt → Generate 3D → Auto-rig → Preview and Export | A prompt |
+| Batch photos to library | `batch-save` | For Each (photos) → Generate 3D → Preview and Save | Photos and a sign-in |
+| Photo to game asset | `image-gameready` | Image → Generate 3D → Remesh → Game-ready → Preview and Export | A photo and $THREE |
+
+A template is a starting point. Loading one replaces the canvas (undo brings the previous graph back), and every node stays editable.
+
+## Nodes
+
+Ports are typed: **text**, **image** and **mesh**. A link can only join an output to an input of the same type, and the editor highlights the inputs that fit while you drag.
+
+| Node | Takes | Gives | Calls | What it does |
+|---|---|---|---|---|
+| Text prompt | | text | Nothing (local) | A prompt of up to 1000 characters. |
+| Image | | image | `POST /api/forge-upload` | One PNG, JPEG or WebP photo up to 8 MB, uploaded once to three.ws storage so the workflow file stays portable. |
+| Load 3D | | mesh | `POST /api/scene-glb-upload` when you upload | A public https `.glb` link, or a GLB file you upload (up to 200 MB). |
+| For Each | | text or image | Nothing (local) | Repeats everything downstream once per item: up to 12 photos or 50 prompts (one per line). |
+| Generate 3D | text, or image plus an optional text hint | mesh | `POST /api/forge`, then `GET /api/forge?job=` and `?progress=` | Text or photo to a textured GLB. The **Engine** list comes from the live catalog (`/api/forge?catalog=1`) with health from `/api/forge?health=1`; **Auto** picks the best free engine. **Quality** is Draft, Standard, or High for $THREE holders. In photo mode the list also offers **Your GPU (Modly)**. |
+| Remesh | mesh | mesh | `POST /api/forge-remesh` | Repair, simplify or convert to triangles, quads or low-poly at a target face count. |
+| Auto-rig | mesh | mesh | `POST /api/forge?action=rig` | Adds a humanoid skeleton and skin weights. |
+| Segment | mesh | mesh | `POST /api/forge-segment` | Splits the model into parts (auto, connected pieces or sharp creases). |
+| Stylize | mesh | mesh | `POST /api/forge-stylize` | Voxel, brick, Voronoi or low-poly restyle. |
+| Game-ready | mesh | mesh | `POST /api/forge-gameready` | Retopology to a poly budget and a texture bake, with GLB and FBX output. |
+| Preview | mesh | | Nothing (local) | An inline 3D viewer on the card. Generate 3D and Auto-rig cards also link to the model page when the engine saved one. |
+| Export | mesh | | Nothing for GLB; the browser converts STL, OBJ and PLY | Downloads the model as GLB, FBX (from Game-ready), STL, OBJ or PLY. |
+| Save | mesh | | `POST /api/avatars/from-forge` or `POST /api/creations` | Saves to your library (sign-in required) or publishes to the public creations gallery. |
+
+Processing workers download the model themselves, so a model that only exists in the browser (made on your GPU, or behind an over-long link) is uploaded to three.ws storage first. The card shows "Uploading the model" while that happens.
+
+### Your GPU (Modly)
+
+[Modly](./modly.md) is a free desktop app that runs open image-to-3D models on your own graphics card. Pick **Your GPU (Modly)** as the Generate 3D engine and press **Connect Modly** in the inspector. The page only contacts `localhost` after that click, so the browser's local network permission prompt appears when you expect it, never on page load. The inspector then lists the models installed in Modly. A Modly step costs nothing and never leaves your computer until a later step needs the model on a server.
+
+## Running
+
+### Preflight
+
+Before anything runs, the graph is checked and every problem is listed on the node it belongs to, in plain words:
+
+- a required input with nothing connected ("Auto-rig needs a mesh connected to Model");
+- a link between ports of different types;
+- a loop of links (repeat steps with For Each instead);
+- a node with a missing setting, such as an empty prompt or no photo;
+- a For Each nested inside another, or a node fed by two For Each nodes;
+- warnings that do not block a run, such as a For Each with nothing after it.
+
+**Run** stays disabled while there are blocking problems. Click an issue to jump to its node.
+
+### States
+
+Every node card carries one of these states:
+
+| State | Meaning |
+|---|---|
+| Pending | Waiting for the steps before it. |
+| Running | Working now. The bar shows real progress from the server; when the server only knows an estimate, the percentage is marked with `~`, and once a job passes its estimate the card says "taking longer than usual" instead of guessing. |
+| Done | Finished. "Served from cache" means the result was reused from an earlier run. |
+| Failed | The step failed. The card shows why and what to do: retry, sign in, wait out a rate limit, or open the status page. |
+| Skipped | Not run, because a step before it failed. |
+| Cancelled | You pressed Cancel (or <kbd>Esc</kbd>) while it was pending or running. |
+
+Branches are independent: if Auto-rig fails, an Export wired straight to Generate 3D still runs.
+
+### Re-running and the cache
+
+Each finished step is cached for as long as the tab is open, keyed by its settings and everything upstream of it.
+
+- **Run** reuses every step whose inputs and settings have not changed, so editing only the Export file name and pressing Run does not regenerate the model.
+- **Retry** on a failed card re-runs from that node and reuses everything before it.
+- **Run fresh** ignores the cache and runs every step again.
+- Changing a setting invalidates that node and everything downstream of it.
+
+### For Each
+
+For Each follows the loop semantics of Modly's workflow runner. Everything downstream of a For Each runs once per item, in order, and each item's chain is independent: if item 2 of 5 fails, items 3 to 5 still run, the card shows `3/5`-style counts, and Retry re-runs only the item that failed. Steps that are not downstream of the loop run once. Loops cannot be nested.
+
+## Saving and sharing
+
+- **Autosave.** The current graph is saved in this browser as you edit (`localStorage`, key `forge-workflows:v1:current`). If storage is blocked, the editor still works and the header says the graph is not being saved.
+- **Export** downloads the graph as a `.json` file. **Import** loads one. Run results are not part of the file.
+
+The file format:
+
+```json
+{
+ "kind": "three.ws/forge-workflow",
+ "version": 1,
+ "name": "Text to rigged character",
+ "nodes": [
+ { "id": "t_prompt", "type": "prompt", "x": 40, "y": 120, "params": { "text": "a friendly cartoon robot" } },
+ { "id": "t_gen", "type": "generate", "x": 320, "y": 120, "params": { "mode": "text", "engine": "auto", "tier": "draft" } },
+ { "id": "t_exp", "type": "export", "x": 600, "y": 120, "params": { "format": "glb", "filename": "robot" } }
+ ],
+ "edges": [
+ { "id": "e1", "from": { "node": "t_prompt", "port": "text" }, "to": { "node": "t_gen", "port": "prompt" } },
+ { "id": "e2", "from": { "node": "t_gen", "port": "mesh" }, "to": { "node": "t_exp", "port": "mesh" } }
+ ]
+}
+```
+
+Import validates the file: it must have this `kind`, a `version` no newer than the page understands, unique node ids, known node types, and at most 200 nodes and 600 links. Links to nodes that are not in the file are dropped, and preflight flags any link to a port a node does not have. Settings missing from a node take their defaults, so an older file keeps loading.
+
+## Keyboard
+
+| Keys | Action |
+|---|---|
+| <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Enter</kbd> | Run the workflow |
+| <kbd>Esc</kbd> | Cancel a run, or clear the selection |
+| <kbd>Delete</kbd> / <kbd>Backspace</kbd> | Remove the selected nodes or link |
+| <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Z</kbd> | Undo |
+| <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> or <kbd>Ctrl</kbd>+<kbd>Y</kbd> | Redo |
+| <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>D</kbd> | Duplicate the selection |
+| Arrow keys | Nudge the selected nodes (hold <kbd>Shift</kbd> for bigger steps) |
+| <kbd>Ctrl</kbd>+scroll | Zoom at the pointer |
+
+Nodes are reachable with <kbd>Tab</kbd>, and the palette works by click as well as by drag.
+
+## On a phone
+
+At 760px wide or less the canvas gives way to a read-only list of the steps in run order, with a **Workflow** picker at the top for switching templates. Each step shows its state and progress, the inputs a run needs (the prompt, the photos, the For Each list, a Load 3D link) stay editable, and a **Run workflow** button sits at the bottom. Open a template link such as `/forge/workflows?template=image-preview` on a phone to run it with your camera roll. Building and rewiring graphs needs a wider screen.
+
+## Lineage
+
+The For Each loop semantics, the typed-port model and the idea of a local-GPU generator node are adapted from [Modly](https://github.com/lightningpixel/modly) (MIT License, Copyright (c) 2026 Lightning Pixel). The modules that carry that design state the attribution in their headers. The editor itself is written for three.ws in plain JavaScript with an SVG link layer. Existing node-editor libraries were evaluated first: Drawflow has had no release since 2024 and has no typed sockets or undo, Rete v2 needs a framework renderer plugin, LiteGraph draws to a canvas with no accessibility tree, and BaklavaJS is built on Vue. None fit a vanilla Vite page that must be keyboard and screen-reader friendly.
+
+## Code map
+
+| File | Role |
+|---|---|
+| `pages/forge-workflows.html` | The page shell. |
+| `src/forge-workflows/main.js` | Boot, toolbar, autosave, keyboard, phone layout. |
+| `src/forge-workflows/graph.js` | Pure graph model: preflight, topological order, For Each plan, serialization. |
+| `src/forge-workflows/runner.js` | Scheduler: states, progress, cancel, cache, re-run from a node. |
+| `src/forge-workflows/node-types.js` | The node registry (ports, settings, checks). |
+| `src/forge-workflows/executors.js` | The network side of each node. |
+| `src/forge-workflows/editor.js` | Canvas, nodes, links, pan and zoom. |
+| `src/forge-workflows/inspector.js` | The settings panel. |
+| `src/forge-workflows/results.js` | Preview viewer and result links. |
+| `src/forge-workflows/templates.js` | The four templates. |
+| `tests/forge-workflows-graph.test.js`, `tests/forge-workflows-runner.test.js` | Unit tests for the graph and the runner. |
+
+Related: [Forge](./forge.md), [Workbench](./workbench.md), [Modly](./modly.md), [How Forge works](./how-forge-works.md).
diff --git a/pages/forge-workflows.html b/pages/forge-workflows.html
new file mode 100644
index 000000000..0784c86fc
--- /dev/null
+++ b/pages/forge-workflows.html
@@ -0,0 +1,60 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <script>/* three.ws theme boot, no-flash; runtime in /theme-switcher.js */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Forge Workflows · three.ws</title>
+ <meta
+ name="description"
+ content="Chain three.ws 3D tools into one run on a visual canvas: prompt or photo to 3D, then remesh, rig, segment, restyle, make it game-ready, preview, export and save. Batch many prompts with ForEach, or run a model on your own GPU with Modly."
+ />
+ <link rel="canonical" href="https://three.ws/forge/workflows" />
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="three.ws" />
+ <meta property="og:url" content="https://three.ws/forge/workflows" />
+ <meta property="og:title" content="Forge Workflows · three.ws" />
+ <meta property="og:description" content="Chain prompt or photo to 3D, remesh, rig, restyle and export into one runnable graph." />
+ <meta property="og:image" content="https://three.ws/api/page-og?s=build&amp;t=Forge+Workflows&amp;d=Chain+prompt+or+photo+to+3D%2C+remesh%2C+rig%2C+restyle+and+export+into+one+runnable+graph.&amp;p=%2Fforge%2Fworkflows" />
+ <meta property="og:image:width" content="1200" />
+ <meta property="og:image:height" content="630" />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:site" content="@trythreews" />
+ <meta name="twitter:title" content="Forge Workflows · three.ws" />
+ <meta name="twitter:description" content="Chain prompt or photo to 3D, remesh, rig, restyle and export into one runnable graph." />
+ <meta name="twitter:image" content="https://three.ws/api/page-og?s=build&amp;t=Forge+Workflows&amp;d=Chain+prompt+or+photo+to+3D%2C+remesh%2C+rig%2C+restyle+and+export+into+one+runnable+graph.&amp;p=%2Fforge%2Fworkflows" />
+ <meta name="theme-color" content="#0a0a0a" />
+ <link rel="icon" href="/favicon.ico" sizes="any" />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+ <link rel="manifest" href="/manifest.webmanifest" />
+ <link rel="stylesheet" href="/fonts/fonts.css" />
+ <link rel="stylesheet" href="/nav.css" />
+ <link rel="stylesheet" href="/src/forge-workflows/forge-workflows.css" />
+ <link rel="stylesheet" href="/footer.css" />
+ <script defer src="/footer-newsletter.js"></script>
+ <script src="/model-viewer-meshopt.js"></script>
+ <script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.3.1/model-viewer.min.js" integrity="sha384-cprcVQt7wbUl0xngF3PGP6yBB7n4/t+4AoAMG9biiMCGFiWOdzUH10Ie2COTqFNW" crossorigin="anonymous"></script>
+ </head>
+ <body>
+ <header><div id="nav-container"></div></header>
+ <script src="/nav.js"></script>
+
+ <main id="fw-app" class="fw-app" data-state="loading" aria-busy="true">
+ <div class="fw-boot" role="status">
+ <h1>Forge Workflows</h1>
+ <p>Loading the workflow editor and the live engine catalog.</p>
+ <noscript><p>The workflow editor needs JavaScript. You can still make a model on <a href="/forge">the Forge</a>.</p></noscript>
+ </div>
+ </main>
+
+ <script type="module" src="/src/forge-workflows/main.js"></script>
+ <script src="/brand.js" defer></script>
+ <div id="footer-container"></div>
+ <script src="/footer.js"></script>
+ <!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
+ <script type="module" src="/i18n.js"></script>
+ </body>
+</html>
diff --git a/public/nav-data.js b/public/nav-data.js
index 6b59b0be2..792370411 100644
--- a/public/nav-data.js
+++ b/public/nav-data.js
@@ -110,6 +110,15 @@ export const NAV_GROUPS = [
tier: 'advanced',
desc: 'Photo → mesh through a visual workflow: remesh, rig, smooth, decimate, export',
},
+ {
+ title: 'Forge Workflows',
+ href: '/forge/workflows',
+ badge: 'New',
+ badgeTone: 'live',
+ // A node editor is a power-user surface, so it stays off the lite menu.
+ tier: 'advanced',
+ desc: 'Chain prompt or photo to 3D, rig, remesh, restyle and export into one run',
+ },
{
title: 'CAD Forge',
href: '/cad',
diff --git a/src/forge-workflows/editor.js b/src/forge-workflows/editor.js
index fc30c69cd..0891e9555 100644
--- a/src/forge-workflows/editor.js
+++ b/src/forge-workflows/editor.js
@@ -272,8 +272,9 @@ export function createEditor(root, opts) {
bar.classList.toggle('is-indeterminate', p?.pct == null);
bar.firstChild.style.transform = `scaleX(${p?.pct != null ? p.pct / 100 : 1})`;
prog.querySelector('.fw-progress-label').textContent = progressText(p, s);
- } else {
+ } else if (!prog.hidden) {
prog.hidden = true;
+ prog.querySelector('.fw-progress-label').textContent = '';
}
}
}
@@ -694,7 +695,11 @@ export function progressText(p, s) {
if (!p) return s?.total > 1 ? `Item ${(s.running?.iter ?? 0) + 1} of ${s.total}` : 'Starting';
const parts = [p.label || 'Working'];
if (p.pct != null) parts.push(`${p.estimate ? '~' : ''}${p.pct}%`);
- if (p.elapsed != null) parts.push(p.eta ? `${p.elapsed}s of ~${p.eta}s` : `${p.elapsed}s`);
+ if (p.elapsed != null) {
+ if (!p.eta) parts.push(`${p.elapsed}s`);
+ else if (p.elapsed > p.eta) parts.push(`${p.elapsed}s, taking longer than usual`);
+ else parts.push(`${p.elapsed}s of ~${p.eta}s`);
+ }
if (s?.total > 1) parts.push(`item ${(s.running?.iter ?? 0) + 1}/${s.total}`);
return parts.join(' · ');
}
diff --git a/src/forge-workflows/executors.js b/src/forge-workflows/executors.js
index 169ec9e6b..408d949ab 100644
--- a/src/forge-workflows/executors.js
+++ b/src/forge-workflows/executors.js
@@ -119,8 +119,10 @@ export function errorFromResponse(res, data, what) {
return new StepError(msg(`${what} failed (HTTP ${res.status}).`), { code: data?.error || `http_${res.status}` });
}
+// A time-based estimate only while the job is inside its ETA. Past it, the bar
+// switches to an honest "taking longer" readout instead of parking at 95%.
function estimateProgress(elapsedSec, etaSec) {
- if (!(etaSec > 0) || !(elapsedSec >= 0)) return null;
+ if (!(etaSec > 0) || !(elapsedSec >= 0) || elapsedSec > etaSec) return null;
return Math.min(95, Math.round((elapsedSec / etaSec) * 100));
}
@@ -210,14 +212,54 @@ export async function uploadGlb(blob, { signal } = {}) {
return presignAndPut('/api/scene-glb-upload', blob, 'model/gltf-binary', { signal, what: 'The model upload' });
}
-/** A mesh value as a public https URL, uploading local bytes when needed. */
+// The processing workers fetch the model themselves, so the URL they get must be
+// public http(s), short enough for the API (2048 chars) and not on this machine.
+const WORKER_URL_MAX = 2048;
+const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '0.0.0.0']);
+
+function workerReachable(url) {
+ if (typeof url !== 'string' || url.length > WORKER_URL_MAX) return false;
+ try {
+ const u = new URL(url);
+ return (u.protocol === 'https:' || u.protocol === 'http:') && !LOCAL_HOSTS.has(u.hostname);
+ } catch {
+ return false;
+ }
+}
+
+async function fetchMeshBlob(url, signal) {
+ let res;
+ try {
+ res = await fetch(new URL(url, location.href), { signal });
+ } catch (err) {
+ if (signal?.aborted) throw err;
+ throw new StepError('Could not read the model from the previous step. Run that step again.', { code: 'network' });
+ }
+ if (!res.ok) throw new StepError(`The model from the previous step is no longer available (HTTP ${res.status}). Run that step again.`, { code: 'gone' });
+ return res.blob();
+}
+
+/**
+ * A mesh value as a URL a processing worker can fetch. Local bytes (a model made
+ * on the user's GPU), same-origin paths and over-long signed links are uploaded
+ * to three.ws storage first.
+ */
async function publicMeshUrl(mesh, { signal, progress }) {
if (!mesh) throw new StepError('No model arrived from the previous step.', { code: 'no_input' });
- if (mesh.url) return mesh.url;
- if (!mesh.blob) throw new StepError('The previous step produced no model.', { code: 'no_input' });
+ if (mesh.publicUrl) return mesh.publicUrl;
+ if (workerReachable(mesh.url)) return mesh.url;
+ let blob = mesh.blob;
+ if (!blob && mesh.url) {
+ if (!/^(https?:|blob:|\/)/i.test(mesh.url)) {
+ throw new StepError('The engine returned the model in private storage. Run Generate again with Run fresh.', { code: 'unreachable_url' });
+ }
+ progress({ label: 'Fetching the model', pct: null });
+ blob = await fetchMeshBlob(mesh.url, signal);
+ }
+ if (!blob) throw new StepError('The previous step produced no model.', { code: 'no_input' });
progress({ label: 'Uploading the model', pct: null });
- mesh.url = await uploadGlb(mesh.blob, { signal });
- return mesh.url;
+ mesh.publicUrl = await uploadGlb(blob, { signal });
+ return mesh.publicUrl;
}
async function imageBlob(image, signal) {
diff --git a/src/forge-workflows/forge-workflows.css b/src/forge-workflows/forge-workflows.css
new file mode 100644
index 000000000..43a907517
--- /dev/null
+++ b/src/forge-workflows/forge-workflows.css
@@ -0,0 +1,651 @@
+/* Forge Workflows: /forge/workflows. Built on the shared tokens in /tokens.css
+ (loaded through /nav.css), so both themes follow the platform. */
+
+.fw-app {
+ --fw-input: #60a5fa;
+ --fw-generate: var(--accent-violet-strong);
+ --fw-process: #2dd4bf;
+ --fw-output: var(--warn);
+ --fw-type-image: #60a5fa;
+ --fw-type-text: #f0abfc;
+ --fw-type-mesh: var(--accent-violet-strong);
+ --fw-panel: var(--bg-1);
+ --fw-grid-dot: var(--stroke-strong);
+ display: flex;
+ flex-direction: column;
+ height: calc(100dvh - var(--nav-h));
+ min-height: 520px;
+ background: var(--bg-0);
+ color: var(--ink);
+ font-family: var(--font-body);
+ font-size: var(--text-md);
+}
+
+.fw-app[data-state='loading'] {
+ align-items: center;
+ justify-content: center;
+}
+
+.fw-boot {
+ color: var(--ink-dim);
+ text-align: center;
+ padding: var(--space-xl) var(--space-md);
+}
+
+.fw-boot h1 {
+ font-family: var(--font-display);
+ font-size: var(--text-xl);
+ color: var(--ink-bright);
+ margin: 0 0 var(--space-xs);
+}
+
+.fw-app [hidden] { display: none !important; }
+
+.fw-sr-only {
+ position: absolute !important;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0 0 0 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+/* ── Buttons ─────────────────────────────────────────────────────────────── */
+.fw-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ height: 32px;
+ padding: 0 12px;
+ border-radius: var(--radius-sm);
+ border: 1px solid var(--stroke-strong);
+ background: var(--surface-2);
+ color: var(--ink-bright);
+ font: inherit;
+ font-size: var(--text-md);
+ font-weight: var(--weight-medium);
+ cursor: pointer;
+ text-decoration: none;
+ white-space: nowrap;
+ transition:
+ background var(--duration-fast) var(--ease-standard),
+ border-color var(--duration-fast) var(--ease-standard),
+ transform var(--duration-instant) var(--ease-standard),
+ opacity var(--duration-fast) var(--ease-standard);
+}
+.fw-btn:hover { background: var(--surface-3); border-color: var(--ink-faint); }
+.fw-btn:active { transform: translateY(1px); }
+.fw-btn:focus-visible,
+.fw-icon-btn:focus-visible,
+.fw-link:focus-visible,
+.fw-palette-item:focus-visible,
+.fw-tcard:focus-visible,
+.fw-menu-item:focus-visible,
+.fw-quickadd-item:focus-visible,
+.fw-drop:focus-within,
+.fw-crumb:focus-visible {
+ outline: 2px solid var(--accent-violet);
+ outline-offset: 2px;
+}
+.fw-btn[disabled],
+.fw-btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }
+.fw-btn[disabled]:hover { background: var(--surface-2); border-color: var(--stroke-strong); }
+.fw-btn.is-primary {
+ background: var(--accent);
+ border-color: var(--accent);
+ color: var(--on-accent);
+}
+.fw-btn.is-primary:hover { filter: brightness(0.92); background: var(--accent); }
+.fw-btn.is-ghost { background: transparent; border-color: transparent; color: var(--ink); }
+.fw-btn.is-ghost:hover { background: var(--surface-2); border-color: var(--stroke); }
+.fw-btn.is-danger { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
+.fw-btn.is-danger:hover { background: color-mix(in srgb, var(--danger) 24%, transparent); }
+.fw-btn.is-sm { height: 28px; padding: 0 10px; font-size: var(--text-sm); }
+.fw-btn.is-block { width: 100%; justify-content: center; height: 44px; font-size: var(--text-ui); }
+.fw-btn kbd,
+.fw-keys kbd {
+ font-family: var(--font-mono);
+ font-size: var(--text-2xs);
+ padding: 1px 5px;
+ border-radius: 4px;
+ border: 1px solid var(--stroke-strong);
+ color: var(--ink-dim);
+ background: var(--surface-1);
+}
+.fw-btn.is-primary kbd { color: inherit; border-color: color-mix(in srgb, var(--on-accent) 30%, transparent); background: transparent; }
+
+.fw-icon-btn {
+ display: inline-grid;
+ place-items: center;
+ width: 32px;
+ height: 32px;
+ border-radius: var(--radius-sm);
+ border: 1px solid transparent;
+ background: transparent;
+ color: var(--ink);
+ cursor: pointer;
+ font-size: 18px;
+ line-height: 1;
+ transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
+}
+.fw-icon-btn:hover { background: var(--surface-3); color: var(--ink-bright); }
+.fw-icon-btn:active { transform: translateY(1px); }
+.fw-icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; background: transparent; }
+.fw-icon-btn.is-sm { width: 24px; height: 24px; font-size: 16px; }
+
+.fw-link {
+ background: none;
+ border: 0;
+ padding: 0;
+ color: var(--ink-bright);
+ font: inherit;
+ text-align: left;
+ text-decoration: underline;
+ text-decoration-color: var(--stroke-strong);
+ text-underline-offset: 3px;
+ cursor: pointer;
+}
+.fw-link:hover { text-decoration-color: currentColor; }
+
+/* ── Toolbar ─────────────────────────────────────────────────────────────── */
+.fw-toolbar {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--space-sm);
+ padding: 8px 12px;
+ border-bottom: 1px solid var(--stroke);
+ background: var(--bg-0);
+ flex-wrap: wrap;
+ position: relative;
+ z-index: 5;
+}
+.fw-tb-group { display: flex; align-items: center; gap: 4px; min-width: 0; }
+.fw-tb-group.is-run { gap: 8px; }
+.fw-crumb { color: var(--ink-dim); text-decoration: none; font-size: var(--text-ui); border-radius: 4px; }
+.fw-crumb:hover { color: var(--ink-bright); }
+.fw-crumb-sep { color: var(--ink-faint); margin: 0 4px; }
+.fw-title { font-family: var(--font-display); font-size: var(--text-ui); font-weight: var(--weight-semibold); color: var(--ink-bright); margin: 0 10px 0 0; }
+.fw-saved { color: var(--ink-faint); font-size: var(--text-sm); white-space: nowrap; }
+.fw-runstatus { color: var(--ink-dim); font-size: var(--text-sm); font-variant-numeric: tabular-nums; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.fw-runstatus.is-running { color: var(--ink-bright); }
+.fw-runstatus.is-done { color: var(--success); }
+.fw-runstatus.is-failed { color: var(--danger); }
+
+.fw-menu-wrap { position: relative; }
+.fw-menu {
+ position: absolute;
+ top: calc(100% + 6px);
+ left: 0;
+ width: 320px;
+ padding: 6px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ box-shadow: var(--shadow-3);
+ z-index: 20;
+ animation: fw-pop var(--duration-base) var(--ease-emphasized);
+}
+.fw-menu-item {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ width: 100%;
+ padding: 8px 10px;
+ border-radius: var(--radius-sm);
+ border: 0;
+ background: transparent;
+ color: var(--ink);
+ font: inherit;
+ text-align: left;
+ cursor: pointer;
+}
+.fw-menu-item:hover { background: var(--surface-3); }
+.fw-menu-title { color: var(--ink-bright); font-weight: var(--weight-medium); }
+.fw-menu-sub { color: var(--ink-dim); font-size: var(--text-sm); line-height: var(--leading-tight); }
+.fw-menu-sep { height: 1px; background: var(--stroke); margin: 6px 4px; }
+
+@keyframes fw-pop {
+ from { opacity: 0; transform: translateY(-4px) scale(0.98); }
+ to { opacity: 1; transform: none; }
+}
+
+/* ── Body grid ───────────────────────────────────────────────────────────── */
+.fw-body {
+ flex: 1;
+ min-height: 0;
+ display: grid;
+ grid-template-columns: 200px minmax(0, 1fr) 320px;
+}
+
+.fw-palette {
+ border-right: 1px solid var(--stroke);
+ padding: 12px 10px;
+ overflow-y: auto;
+ display: flex;
+ flex-direction: column;
+ gap: 14px;
+}
+.fw-palette-hint,
+.fw-palette-foot { margin: 0; color: var(--ink-faint); font-size: var(--text-sm); line-height: var(--leading-tight); }
+.fw-palette-foot { margin-top: auto; }
+.fw-palette-group { display: flex; flex-direction: column; gap: 2px; }
+.fw-palette-title { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); margin: 0 0 4px 6px; font-weight: var(--weight-semibold); }
+.fw-palette-item {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 7px 8px;
+ border-radius: var(--radius-sm);
+ border: 1px solid transparent;
+ background: transparent;
+ color: var(--ink);
+ font: inherit;
+ text-align: left;
+ cursor: grab;
+ transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
+}
+.fw-palette-item:hover { background: var(--surface-2); border-color: var(--stroke); color: var(--ink-bright); }
+.fw-palette-item:active { cursor: grabbing; background: var(--surface-3); }
+
+.cat-input { --fw-cat: var(--fw-input); }
+.cat-generate { --fw-cat: var(--fw-generate); }
+.cat-process { --fw-cat: var(--fw-process); }
+.cat-output { --fw-cat: var(--fw-output); }
+.fw-node-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fw-cat, var(--ink-dim)); flex: none; }
+
+/* ── Canvas ──────────────────────────────────────────────────────────────── */
+.fw-canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
+.fw-canvas {
+ position: absolute;
+ inset: 0;
+ overflow: hidden;
+ cursor: default;
+ touch-action: none;
+ background-color: var(--bg-0);
+ background-image: radial-gradient(circle, var(--fw-grid-dot) 1px, transparent 1.2px);
+ background-size: var(--fw-grid, 24px) var(--fw-grid, 24px);
+ outline: none;
+}
+.fw-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-violet); }
+.fw-canvas.is-panning { cursor: grabbing; }
+.fw-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
+.fw-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
+.fw-nodes { position: absolute; left: 0; top: 0; }
+
+.fw-edge { fill: none; stroke: var(--stroke-strong); stroke-width: 2; transition: stroke var(--duration-fast) var(--ease-standard); }
+.fw-edge.type-image { stroke: color-mix(in srgb, var(--fw-type-image) 55%, transparent); }
+.fw-edge.type-text { stroke: color-mix(in srgb, var(--fw-type-text) 55%, transparent); }
+.fw-edge.type-mesh { stroke: color-mix(in srgb, var(--fw-type-mesh) 55%, transparent); }
+.fw-edge.is-done { stroke-width: 2.5; }
+.fw-edge.is-done.type-mesh { stroke: var(--fw-type-mesh); }
+.fw-edge.is-done.type-image { stroke: var(--fw-type-image); }
+.fw-edge.is-done.type-text { stroke: var(--fw-type-text); }
+.fw-edge.is-flowing { stroke-dasharray: 6 6; animation: fw-flow 0.6s linear infinite; }
+.fw-edge.is-selected { stroke: var(--ink-bright); stroke-width: 3; }
+.fw-edge.is-temp { stroke-dasharray: 5 5; stroke: var(--ink-bright); }
+.fw-edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
+.fw-edge-hit:hover + .fw-edge,
+.fw-edge-hit:hover { stroke: color-mix(in srgb, var(--ink-bright) 18%, transparent); }
+
+@keyframes fw-flow { to { stroke-dashoffset: -12; } }
+
+/* ── Node card ───────────────────────────────────────────────────────────── */
+.fw-node {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 228px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ box-shadow: var(--shadow-2);
+ user-select: none;
+ cursor: grab;
+ transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
+}
+.fw-node::before {
+ content: '';
+ position: absolute;
+ inset: 0 0 auto 0;
+ height: 3px;
+ border-radius: var(--radius-md) var(--radius-md) 0 0;
+ background: var(--fw-cat);
+ opacity: 0.85;
+}
+.fw-canvas.is-dragging .fw-node { cursor: grabbing; }
+.fw-node:hover { border-color: var(--ink-faint); }
+.fw-node:focus-visible { outline: 2px solid var(--accent-violet); outline-offset: 2px; }
+.fw-node.is-selected { border-color: var(--ink-bright); box-shadow: 0 0 0 1px var(--ink-bright), var(--shadow-3); }
+.fw-node.has-error { border-color: color-mix(in srgb, var(--danger) 70%, transparent); }
+.fw-node.has-warning { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
+.fw-node[data-status='running'] { border-color: var(--accent-violet); box-shadow: 0 0 0 1px var(--accent-violet), 0 0 24px color-mix(in srgb, var(--accent-violet) 30%, transparent); }
+.fw-node[data-status='done'] { border-color: color-mix(in srgb, var(--success) 55%, transparent); }
+.fw-node[data-status='failed'] { border-color: var(--danger); }
+.fw-node[data-status='skipped'],
+.fw-node[data-status='cancelled'] { opacity: 0.7; }
+
+.fw-node-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 6px; }
+.fw-node-title { flex: 1; font-weight: var(--weight-semibold); color: var(--ink-bright); font-size: var(--text-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.fw-node-badge { font-size: var(--text-2xs); font-weight: var(--weight-semibold); padding: 1px 7px; border-radius: var(--radius-pill); white-space: nowrap; font-variant-numeric: tabular-nums; }
+.fw-node-badge:empty { display: none; }
+.fw-node-badge.is-pending { color: var(--ink-dim); background: var(--surface-3); }
+.fw-node-badge.is-running { color: var(--accent-violet); background: color-mix(in srgb, var(--accent-violet) 16%, transparent); }
+.fw-node-badge.is-done { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
+.fw-node-badge.is-partial { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
+.fw-node-badge.is-failed { color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, transparent); }
+.fw-node-badge.is-cancelled,
+.fw-node-badge.is-skipped { color: var(--ink-dim); background: var(--surface-2); }
+
+.fw-node-ports { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; padding: 2px 0 4px; }
+.fw-node-ins,
+.fw-node-outs { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
+.fw-port { position: relative; display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--ink-dim); min-height: 20px; }
+.fw-port.is-in { padding-left: 14px; }
+.fw-port.is-out { padding-right: 14px; justify-content: flex-end; text-align: right; }
+.fw-port.is-out .fw-port-label { order: -1; }
+.fw-port-opt { color: var(--ink-faint); font-size: var(--text-2xs); }
+.fw-port-dot {
+ position: absolute;
+ top: 50%;
+ width: 12px;
+ height: 12px;
+ margin-top: -6px;
+ border-radius: 50%;
+ border: 2px solid var(--fw-panel);
+ background: var(--ink-dim);
+ cursor: crosshair;
+ transition: transform var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
+}
+.fw-port.is-in .fw-port-dot { left: -7px; }
+.fw-port.is-out .fw-port-dot { right: -7px; }
+.fw-port[data-type='image'] .fw-port-dot { background: var(--fw-type-image); }
+.fw-port[data-type='text'] .fw-port-dot { background: var(--fw-type-text); }
+.fw-port[data-type='mesh'] .fw-port-dot { background: var(--fw-type-mesh); }
+.fw-port-dot::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; }
+.fw-port-dot:hover { transform: scale(1.35); }
+.fw-canvas.is-connecting .fw-port.is-target-bad { opacity: 0.35; }
+.fw-canvas.is-connecting .fw-port.is-target-ok .fw-port-dot { transform: scale(1.3); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink-bright) 22%, transparent); }
+.fw-canvas.is-connecting .fw-port.is-target-ok.is-hover .fw-port-dot { transform: scale(1.6); box-shadow: 0 0 0 5px color-mix(in srgb, var(--success) 45%, transparent); }
+
+.fw-node-summary { padding: 0 10px 8px; color: var(--ink-dim); font-size: var(--text-sm); line-height: var(--leading-tight); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
+.fw-node-summary:empty { display: none; }
+.fw-node-issue { margin: 0 10px 8px; padding: 6px 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); line-height: var(--leading-tight); background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
+.fw-node.has-warning .fw-node-issue { background: color-mix(in srgb, var(--warn) 10%, transparent); color: var(--warn); }
+
+.fw-node-progress { padding: 0 10px 10px; }
+.fw-bar { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
+.fw-bar > span { display: block; height: 100%; background: var(--accent-violet); transform-origin: 0 50%; transform: scaleX(0); transition: transform var(--duration-slow) var(--ease-standard); }
+.fw-bar.is-indeterminate > span { width: 35%; transform: none; animation: fw-indet 1.3s var(--ease-standard) infinite; }
+@keyframes fw-indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
+.fw-progress-label { margin-top: 6px; color: var(--ink-dim); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; line-height: var(--leading-tight); }
+
+/* ── Results ─────────────────────────────────────────────────────────────── */
+.fw-result { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; cursor: default; user-select: text; animation: fw-fade var(--duration-base) var(--ease-standard); }
+.fw-result[hidden] { display: none; }
+@keyframes fw-fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
+.fw-viewer { width: 100%; height: 180px; border-radius: var(--radius-sm); background: radial-gradient(circle at 50% 40%, var(--surface-3), var(--surface-1)); --poster-color: transparent; }
+.fw-thumb { width: 100%; max-height: 140px; object-fit: contain; border-radius: var(--radius-sm); background: var(--surface-1); }
+.fw-result-meta { display: flex; align-items: center; gap: 4px; color: var(--success); font-size: var(--text-2xs); }
+.fw-result-note { color: var(--ink-dim); font-size: var(--text-2xs); line-height: var(--leading-tight); }
+.fw-result-links { display: flex; flex-wrap: wrap; gap: 4px; }
+.fw-result-links .fw-btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
+.fw-pager { display: flex; align-items: center; gap: 4px; font-size: var(--text-2xs); color: var(--ink-dim); }
+.fw-pager-label { font-variant-numeric: tabular-nums; }
+.fw-pager-dots { display: flex; gap: 3px; flex: 1; justify-content: center; }
+.fw-pager-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--surface-3); }
+.fw-pager-dot.is-done { background: var(--success); }
+.fw-pager-dot.is-failed { background: var(--danger); }
+.fw-pager-dot.is-current { box-shadow: 0 0 0 2px var(--ink-bright); }
+.fw-error { padding: 8px; border-radius: var(--radius-sm); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); display: flex; flex-direction: column; gap: 8px; }
+.fw-error-msg { display: flex; gap: 6px; color: var(--ink-bright); font-size: var(--text-sm); line-height: var(--leading-tight); overflow-wrap: anywhere; }
+.fw-error-msg svg { color: var(--danger); flex: none; margin-top: 2px; }
+.fw-error-actions { display: flex; flex-wrap: wrap; gap: 4px; }
+
+/* ── Empty state ─────────────────────────────────────────────────────────── */
+.fw-empty {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ padding: var(--space-lg);
+ text-align: center;
+ pointer-events: none;
+ animation: fw-fade var(--duration-slow) var(--ease-standard);
+}
+.fw-empty[hidden] { display: none; }
+.fw-empty > * { pointer-events: auto; }
+.fw-empty-title { font-family: var(--font-display); font-size: var(--text-xl); color: var(--ink-bright); margin: 0 0 6px; }
+.fw-empty-sub { color: var(--ink-dim); margin: 0 0 var(--space-lg); max-width: 520px; line-height: var(--leading-normal); font-size: var(--text-ui); }
+.fw-empty-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 260px)); gap: 10px; }
+.fw-tcard {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ padding: 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ color: var(--ink);
+ font: inherit;
+ text-align: left;
+ cursor: pointer;
+ transition: border-color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
+}
+.fw-tcard:hover { border-color: var(--ink-faint); transform: translateY(-2px); box-shadow: var(--shadow-2); }
+.fw-tcard:active { transform: translateY(0); }
+.fw-tcard-title { color: var(--ink-bright); font-weight: var(--weight-semibold); font-size: var(--text-ui); }
+.fw-tcard-desc { color: var(--ink-dim); font-size: var(--text-sm); line-height: var(--leading-tight); }
+.fw-tcard-needs { margin-top: auto; color: var(--ink-faint); font-size: var(--text-2xs); }
+
+/* ── Zoom and issues overlays ────────────────────────────────────────────── */
+.fw-zoom {
+ position: absolute;
+ right: 12px;
+ bottom: 12px;
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ padding: 3px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ box-shadow: var(--shadow-1);
+}
+.fw-zoom-label { min-width: 44px; text-align: center; font-size: var(--text-sm); color: var(--ink-dim); font-variant-numeric: tabular-nums; }
+.fw-canvas-wrap.is-empty .fw-zoom { display: none; }
+
+.fw-issues {
+ position: absolute;
+ left: 12px;
+ bottom: 12px;
+ max-width: min(460px, calc(100% - 200px));
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ box-shadow: var(--shadow-2);
+ overflow: hidden;
+}
+.fw-issues[hidden] { display: none; }
+.fw-issues-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px; border: 0; background: transparent; color: var(--ink-bright); font: inherit; font-weight: var(--weight-medium); cursor: pointer; text-align: left; }
+.fw-issues-head:hover { background: var(--surface-2); }
+.fw-issues-head:focus-visible { outline: 2px solid var(--accent-violet); outline-offset: -2px; }
+.fw-issues-head.is-error svg { color: var(--danger); }
+.fw-issues-head.is-warning svg { color: var(--warn); }
+.fw-issues-sub { color: var(--ink-dim); font-weight: var(--weight-regular); }
+.fw-issues-list { list-style: none; margin: 0; padding: 0 12px 10px 34px; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; font-size: var(--text-sm); line-height: var(--leading-tight); }
+.fw-issues-list li { position: relative; }
+.fw-issues-list li::before { content: ''; position: absolute; left: -14px; top: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); }
+.fw-issues-list li.is-warning::before { background: var(--warn); }
+.fw-issues-list.is-inline { padding: 8px 12px 8px 26px; border-radius: var(--radius-md); background: color-mix(in srgb, var(--danger) 8%, transparent); }
+
+/* ── Quick add (drop a link on empty canvas) ─────────────────────────────── */
+.fw-quickadd {
+ position: absolute;
+ z-index: 10;
+ min-width: 200px;
+ padding: 6px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--fw-panel);
+ box-shadow: var(--shadow-3);
+ animation: fw-pop var(--duration-base) var(--ease-emphasized);
+}
+.fw-quickadd-title { padding: 4px 8px 6px; color: var(--ink-dim); font-size: var(--text-2xs); }
+.fw-quickadd-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
+.fw-quickadd-item:hover,
+.fw-quickadd-item:focus-visible { background: var(--surface-3); color: var(--ink-bright); }
+
+/* ── Inspector ───────────────────────────────────────────────────────────── */
+.fw-inspector { border-left: 1px solid var(--stroke); overflow-y: auto; padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 14px; }
+.fw-insp-head { display: flex; flex-direction: column; gap: 4px; }
+.fw-cat { align-self: flex-start; font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.08em; font-weight: var(--weight-semibold); color: var(--fw-cat, var(--ink-dim)); }
+.fw-insp-title { font-family: var(--font-display); font-size: var(--text-lg); color: var(--ink-bright); margin: 0; }
+.fw-insp-blurb { margin: 0; color: var(--ink-dim); line-height: var(--leading-normal); font-size: var(--text-sm); }
+.fw-section { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--stroke); }
+.fw-section-title { margin: 0; font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); font-weight: var(--weight-semibold); }
+.fw-insp-actions { flex-direction: row; flex-wrap: wrap; gap: 6px; }
+.fw-row { display: flex; gap: 6px; flex-wrap: wrap; }
+.fw-modly-status { font-size: var(--text-sm); color: var(--ink); line-height: var(--leading-tight); }
+.fw-modly-status:empty { display: none; }
+
+.fw-form { display: flex; flex-direction: column; gap: 12px; }
+.fw-field { display: flex; flex-direction: column; gap: 5px; }
+.fw-label { font-size: var(--text-sm); color: var(--ink); font-weight: var(--weight-medium); }
+.fw-hint { margin: 0; font-size: var(--text-2xs); color: var(--ink-faint); line-height: var(--leading-tight); }
+.fw-hint:empty { display: none; }
+.fw-input {
+ width: 100%;
+ box-sizing: border-box;
+ min-height: 34px;
+ padding: 7px 10px;
+ border-radius: var(--radius-sm);
+ border: 1px solid var(--stroke-strong);
+ background: var(--surface-1);
+ color: var(--ink-bright);
+ font: inherit;
+ font-size: var(--text-md);
+ transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
+}
+.fw-input:hover { border-color: var(--ink-faint); }
+.fw-input:focus { outline: none; border-color: var(--accent-violet); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-violet) 25%, transparent); }
+.fw-input:disabled { opacity: 0.55; cursor: not-allowed; }
+textarea.fw-input { resize: vertical; line-height: var(--leading-normal); }
+select.fw-input { cursor: pointer; }
+select.fw-input option { background: var(--bg-1); color: var(--ink-bright); }
+.fw-check { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); cursor: pointer; }
+.fw-check input { accent-color: var(--accent-violet); width: 16px; height: 16px; }
+
+.fw-images { display: flex; flex-direction: column; gap: 8px; }
+.fw-images.is-uploading .fw-drop { opacity: 0.6; pointer-events: none; }
+.fw-images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
+.fw-images-grid:empty { display: none; }
+.fw-image { position: relative; margin: 0; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
+.fw-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
+.fw-image-remove { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; border: 0; background: var(--scrim-strong); color: var(--on-scrim-bright); cursor: pointer; opacity: 0.85; transition: opacity var(--duration-fast) var(--ease-standard); }
+.fw-image-remove:hover,
+.fw-image-remove:focus-visible { opacity: 1; outline: 2px solid var(--accent-violet); }
+.fw-drop {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ flex-wrap: wrap;
+ padding: 12px;
+ border-radius: var(--radius-sm);
+ border: 1px dashed var(--stroke-strong);
+ background: var(--surface-1);
+ color: var(--ink-bright);
+ cursor: pointer;
+ transition: border-color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard);
+}
+.fw-drop:hover,
+.fw-drop.is-over { border-color: var(--accent-violet); background: color-mix(in srgb, var(--accent-violet) 8%, transparent); }
+.fw-drop-sub { color: var(--ink-faint); font-size: var(--text-sm); }
+.fw-images-pending { font-size: var(--text-sm); color: var(--ink-dim); }
+.fw-images-pending:empty { display: none; }
+.fw-mesh-field { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
+
+.fw-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
+.fw-step { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 4px 8px; font-size: var(--text-sm); }
+.fw-step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); }
+.fw-step.is-done .fw-step-dot { background: var(--success); }
+.fw-step.is-failed .fw-step-dot { background: var(--danger); }
+.fw-step.is-running .fw-step-dot { background: var(--accent-violet); animation: fw-pulse 1s ease-in-out infinite; }
+.fw-step-name { color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.fw-step-state { color: var(--ink-dim); }
+.fw-step-error { grid-column: 2 / -1; color: var(--danger); line-height: var(--leading-tight); overflow-wrap: anywhere; }
+@keyframes fw-pulse { 50% { opacity: 0.35; } }
+
+.fw-issues-inline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
+.fw-issues-inline li { display: flex; gap: 6px; font-size: var(--text-sm); line-height: var(--leading-tight); color: var(--ink); }
+.fw-issues-inline li.is-error svg { color: var(--danger); flex: none; margin-top: 1px; }
+.fw-issues-inline li.is-warning svg { color: var(--warn); flex: none; margin-top: 1px; }
+
+.fw-run-word { margin: 0; font-weight: var(--weight-semibold); color: var(--ink-bright); }
+.fw-run-word.is-done { color: var(--success); }
+.fw-run-word.is-failed { color: var(--danger); }
+.fw-failed-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: var(--text-sm); }
+.fw-keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0; font-size: var(--text-sm); align-items: center; }
+.fw-keys dt { margin: 0; }
+.fw-keys dd { margin: 0; color: var(--ink-dim); }
+
+/* ── Toasts ──────────────────────────────────────────────────────────────── */
+.fw-toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: min(460px, calc(100vw - 32px)); pointer-events: none; font-family: var(--font-body); }
+.fw-toast {
+ pointer-events: auto;
+ padding: 10px 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--stroke-strong);
+ background: var(--bg-1);
+ color: var(--ink-bright);
+ box-shadow: var(--shadow-3);
+ font-size: var(--text-md);
+ line-height: var(--leading-tight);
+ opacity: 0;
+ transform: translateY(8px);
+ transition: opacity var(--duration-base) var(--ease-standard), transform var(--duration-base) var(--ease-standard);
+}
+.fw-toast.is-in { opacity: 1; transform: none; }
+.fw-toast.is-error { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
+.fw-toast.is-success { border-color: color-mix(in srgb, var(--success) 50%, transparent); }
+
+/* ── Phone layout ────────────────────────────────────────────────────────── */
+.fw-linear { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px 0; flex: 1; }
+.fw-linear[hidden] { display: none; }
+.fw-linear-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
+.fw-linear-step { position: relative; border-radius: var(--radius-md); border: 1px solid var(--stroke-strong); background: var(--fw-panel); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
+.fw-linear-step::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--fw-cat); }
+.fw-linear-head { display: flex; align-items: center; gap: 8px; }
+.fw-linear-num { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--ink-dim); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; }
+.fw-linear-title { flex: 1; font-weight: var(--weight-semibold); color: var(--ink-bright); }
+.fw-linear-step .fw-node-summary,
+.fw-linear-step .fw-result { padding: 0; }
+.fw-linear-step .fw-viewer { height: 240px; }
+.fw-linear-empty { color: var(--ink-dim); text-align: center; padding: var(--space-lg) 0; }
+.fw-linear-bar { position: sticky; bottom: 0; margin: 0 -16px; padding: 16px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg-0) 70%, transparent); z-index: 6; }
+
+.fw-app[data-layout='linear'] .fw-body { display: none; }
+.fw-app[data-layout='linear'] .fw-toolbar .fw-tb-group:nth-child(2),
+.fw-app[data-layout='linear'] .fw-toolbar .fw-tb-group.is-run { display: none; }
+.fw-app[data-layout='linear'] { height: auto; min-height: calc(100dvh - var(--nav-h)); }
+
+@media (max-width: 1180px) {
+ .fw-body { grid-template-columns: 168px minmax(0, 1fr) 280px; }
+ .fw-hide-sm { display: none; }
+}
+
+@media (max-width: 760px) {
+ .fw-empty-grid { grid-template-columns: 1fr; }
+ .fw-toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .fw-app *,
+ .fw-toast { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
+ .fw-edge.is-flowing { stroke-dasharray: none; }
+}
diff --git a/src/forge-workflows/main.js b/src/forge-workflows/main.js
index 547a457e8..ba6b5643a 100644
--- a/src/forge-workflows/main.js
+++ b/src/forge-workflows/main.js
@@ -197,6 +197,7 @@ function buildShell() {
app.textContent = '';
app.append(toolbar, h('div', { class: 'fw-body' }, els.palette, els.canvasWrap, els.inspector), els.linear);
app.dataset.state = 'ready';
+ app.removeAttribute('aria-busy');
}
// ── Commit / history ────────────────────────────────────────────────────────
diff --git a/src/forge-workflows/runner.js b/src/forge-workflows/runner.js
index e252ab5e3..11e52a7e6 100644
--- a/src/forge-workflows/runner.js
+++ b/src/forge-workflows/runner.js
@@ -85,6 +85,7 @@ export function createRunner({ types, executors, onChange = () => {} }) {
onChange(state);
} catch (err) {
// A rendering error must not break the run; surface it for debugging.
+ // eslint-disable-next-line no-console
console.error('[forge-workflows] state listener failed', err);
}
}
diff --git a/src/forge-workflows/templates.js b/src/forge-workflows/templates.js
index 118edd96a..b33b46c0d 100644
--- a/src/forge-workflows/templates.js
+++ b/src/forge-workflows/templates.js
@@ -32,8 +32,8 @@ export const TEMPLATES = [
node('t_prompt', 'prompt', 40, 120, { text: 'a friendly cartoon robot standing upright, arms at its sides' }),
node('t_gen', 'generate', 320, 120, { mode: 'text', engine: 'auto', tier: 'draft' }),
node('t_rig', 'rig', 600, 120),
- node('t_prev', 'preview', 880, 40),
- node('t_exp', 'export', 880, 240, { format: 'glb', filename: 'rigged-character' }),
+ node('t_prev', 'preview', 880, 220),
+ node('t_exp', 'export', 880, 20, { format: 'glb', filename: 'rigged-character' }),
],
[
edge('t_e1', 't_prompt', 'text', 't_gen', 'prompt'),
@@ -70,8 +70,8 @@ export const TEMPLATES = [
[
node('b_each', 'forEach', 40, 120, { mode: 'image' }),
node('b_gen', 'generate', 320, 120, { mode: 'image', engine: 'auto', tier: 'draft' }),
- node('b_prev', 'preview', 600, 40),
- node('b_save', 'save', 600, 240, { destination: 'library', name: 'Batch model', visibility: 'unlisted' }),
+ node('b_prev', 'preview', 600, 220),
+ node('b_save', 'save', 600, 0, { destination: 'library', name: 'Batch model', visibility: 'unlisted' }),
],
[
edge('b_e1', 'b_each', 'item', 'b_gen', 'image'),
@@ -93,8 +93,8 @@ export const TEMPLATES = [
node('g_gen', 'generate', 300, 120, { mode: 'image', engine: 'auto', tier: 'draft' }),
node('g_rem', 'remesh', 560, 120, { mode: 'triangle', operation: 'full', targetFaces: 50000 }),
node('g_game', 'gameready', 820, 120, { topology: 'quad', polyBudget: 15000 }),
- node('g_prev', 'preview', 1080, 40),
- node('g_exp', 'export', 1080, 240, { format: 'glb', filename: 'game-asset' }),
+ node('g_prev', 'preview', 1080, 220),
+ node('g_exp', 'export', 1080, 20, { format: 'glb', filename: 'game-asset' }),
],
[
edge('g_e1', 'g_img', 'image', 'g_gen', 'image'),
diff --git a/src/forge-workflows/ui.js b/src/forge-workflows/ui.js
index 665531992..689d1d144 100644
--- a/src/forge-workflows/ui.js
+++ b/src/forge-workflows/ui.js
@@ -18,7 +18,7 @@ export function h(tag, attrs = {}, ...children) {
else if (k === 'checked') el.checked = Boolean(v);
else el.setAttribute(k, v === true ? '' : String(v));
}
- for (const c of children.flat()) {
+ for (const c of children.flat(Infinity)) {
if (c === null || c === undefined || c === false) continue;
el.append(c instanceof Node ? c : document.createTextNode(String(c)));
}
diff --git a/tests/forge-workflows-graph.test.js b/tests/forge-workflows-graph.test.js
new file mode 100644
index 000000000..99108dad6
--- /dev/null
+++ b/tests/forge-workflows-graph.test.js
@@ -0,0 +1,413 @@
+// Forge Workflows graph core: preflight, topological scheduling, For Each
+// expansion, connection rules, signatures and the portable JSON format.
+
+import { describe, expect, it } from 'vitest';
+import {
+ WORKFLOW_KIND,
+ blockingIssues,
+ buildPlan,
+ canConnect,
+ connect,
+ parseWorkflow,
+ preflight,
+ pruneInvalidEdges,
+ removeNodes,
+ serializeWorkflow,
+ stepSignature,
+ topoSort,
+} from '../src/forge-workflows/graph.js';
+import { NODE_TYPES } from '../src/forge-workflows/node-types.js';
+import { TEMPLATES, instantiateTemplate } from '../src/forge-workflows/templates.js';
+
+const T = NODE_TYPES;
+const img = (n) => ({ url: `https://three.ws/forge-uploads/test-${n}.png`, name: `photo-${n}.png` });
+
+function wf(nodes, edges = []) {
+ return {
+ kind: WORKFLOW_KIND,
+ version: 1,
+ name: 'Test',
+ nodes: nodes.map(([id, type, x = 0, y = 0, params = {}]) => ({ id, type, x, y, params: { ...defaults(type), ...params } })),
+ edges: edges.map(([from, fromPort, to, toPort], i) => ({ id: `e${i}`, from: { node: from, port: fromPort }, to: { node: to, port: toPort } })),
+ };
+}
+
+function defaults(type) {
+ const out = {};
+ for (const p of T[type].params || []) if (p.default !== undefined) out[p.id] = JSON.parse(JSON.stringify(p.default));
+ return out;
+}
+
+const keys = (issues) => issues.map((i) => i.key);
+
+describe('preflight', () => {
+ it('reports an empty canvas and nothing else', () => {
+ const issues = preflight(wf([]), T);
+ expect(keys(issues)).toEqual(['empty']);
+ });
+
+ it('passes a complete text to rig to export chain', () => {
+ const w = wf(
+ [
+ ['p', 'prompt', 0, 0, { text: 'a brass lantern' }],
+ ['g', 'generate', 200],
+ ['r', 'rig', 400],
+ ['x', 'export', 600],
+ ],
+ [
+ ['p', 'text', 'g', 'prompt'],
+ ['g', 'mesh', 'r', 'mesh'],
+ ['r', 'mesh', 'x', 'mesh'],
+ ],
+ );
+ expect(blockingIssues(preflight(w, T))).toEqual([]);
+ });
+
+ it('flags a missing required input once, naming the port', () => {
+ const w = wf([['g', 'generate'], ['x', 'export']], [['g', 'mesh', 'x', 'mesh']]);
+ const issues = preflight(w, T);
+ const missing = issues.filter((i) => i.key.includes(':missing:'));
+ expect(missing).toHaveLength(1);
+ expect(missing[0]).toMatchObject({ nodeId: 'g', level: 'error' });
+ expect(missing[0].message).toMatch(/Prompt/);
+ });
+
+ it('treats the optional hint port on image generation as optional', () => {
+ const w = wf(
+ [
+ ['i', 'image', 0, 0, { images: [img(1)] }],
+ ['g', 'generate', 200, 0, { mode: 'image' }],
+ ['v', 'preview', 400],
+ ],
+ [
+ ['i', 'image', 'g', 'image'],
+ ['g', 'mesh', 'v', 'mesh'],
+ ],
+ );
+ expect(blockingIssues(preflight(w, T))).toEqual([]);
+ });
+
+ it('runs node validators: empty prompt, missing photo, bad GLB link', () => {
+ const w = wf([
+ ['p', 'prompt'],
+ ['i', 'image'],
+ ['m', 'loadMesh', 0, 0, { url: 'http://insecure.example/model.glb' }],
+ ]);
+ const msgs = preflight(w, T).map((i) => i.message).join('\n');
+ expect(msgs).toMatch(/write a prompt/);
+ expect(msgs).toMatch(/upload a photo/);
+ expect(msgs).toMatch(/https:\/\//);
+ });
+
+ it('flags a type mismatch on an imported edge', () => {
+ const w = wf(
+ [
+ ['i', 'image', 0, 0, { images: [img(1)] }],
+ ['r', 'rig'],
+ ],
+ [['i', 'image', 'r', 'mesh']],
+ );
+ expect(keys(preflight(w, T))).toContain('e0:type');
+ });
+
+ it('detects a cycle', () => {
+ const w = wf(
+ [
+ ['a', 'remesh'],
+ ['b', 'rig'],
+ ],
+ [
+ ['a', 'mesh', 'b', 'mesh'],
+ ['b', 'mesh', 'a', 'mesh'],
+ ],
+ );
+ expect(keys(preflight(w, T))).toContain('cycle');
+ });
+
+ it('warns (does not block) when a For Each has nothing after it', () => {
+ const w = wf([['f', 'forEach', 0, 0, { images: [img(1)] }]]);
+ const issues = preflight(w, T);
+ expect(issues.find((i) => i.key === 'f:empty-body')?.level).toBe('warning');
+ expect(blockingIssues(issues)).toEqual([]);
+ });
+
+ it('rejects a nested For Each and a node fed by two loops', () => {
+ const nested = wf(
+ [
+ ['f1', 'forEach', 0, 0, { mode: 'text', prompts: 'a\nb' }],
+ ['f2', 'forEach', 0, 0, { mode: 'text', prompts: 'c' }],
+ ['g', 'generate'],
+ ],
+ [
+ ['f1', 'item', 'g', 'prompt'],
+ ['f2', 'item', 'g', 'prompt'],
+ ],
+ );
+ expect(keys(preflight(nested, T))).toContain('g:two-loops');
+ });
+
+ it('uses live context: an unconfigured engine blocks, a down engine warns', () => {
+ const catalog = { backends: [{ id: 'eng-a', label: 'Engine A', configured: false }, { id: 'eng-b', label: 'Engine B', configured: true, user_images: true }] };
+ const make = (engine) =>
+ wf(
+ [
+ ['p', 'prompt', 0, 0, { text: 'chair' }],
+ ['g', 'generate', 200, 0, { engine }],
+ ],
+ [['p', 'text', 'g', 'prompt']],
+ );
+ expect(blockingIssues(preflight(make('eng-a'), T, { catalog })).map((i) => i.nodeId)).toContain('g');
+ const down = preflight(make('eng-b'), T, { catalog, health: { 'eng-b': { status: 'down' } } });
+ expect(blockingIssues(down)).toEqual([]);
+ expect(down.some((i) => i.level === 'warning' && /down/.test(i.message))).toBe(true);
+ });
+
+ it('blocks a Modly engine until Modly is connected with a downloaded model', () => {
+ const w = wf(
+ [
+ ['i', 'image', 0, 0, { images: [img(1)] }],
+ ['g', 'generate', 200, 0, { mode: 'image', engine: 'modly', modlyModel: 'm1' }],
+ ],
+ [['i', 'image', 'g', 'image']],
+ );
+ expect(blockingIssues(preflight(w, T, {})).length).toBe(1);
+ expect(blockingIssues(preflight(w, T, { modly: { models: [{ id: 'm1', name: 'M1', downloaded: false }] } })).length).toBe(1);
+ expect(blockingIssues(preflight(w, T, { modly: { models: [{ id: 'm1', name: 'M1', downloaded: true }] } }))).toEqual([]);
+ });
+
+ it('every template passes preflight once its inputs are filled', () => {
+ for (const t of TEMPLATES) {
+ const w = instantiateTemplate(t.id);
+ for (const n of w.nodes) {
+ if (n.type === 'image') n.params.images = [img(1)];
+ if (n.type === 'forEach') n.params.images = [img(1), img(2)];
+ }
+ expect(blockingIssues(preflight(w, T, { signedIn: true })), t.id).toEqual([]);
+ }
+ });
+});
+
+describe('topoSort', () => {
+ it('orders dependencies first and breaks ties by canvas position', () => {
+ const w = wf(
+ [
+ ['x', 'export', 600, 200],
+ ['v', 'preview', 600, 0],
+ ['g', 'generate', 200],
+ ['p', 'prompt', 0],
+ ],
+ [
+ ['p', 'text', 'g', 'prompt'],
+ ['g', 'mesh', 'v', 'mesh'],
+ ['g', 'mesh', 'x', 'mesh'],
+ ],
+ );
+ expect(topoSort(w)).toEqual({ order: ['p', 'g', 'v', 'x'], cycle: [] });
+ });
+
+ it('returns the nodes it could not place when there is a cycle', () => {
+ const w = wf(
+ [
+ ['p', 'prompt'],
+ ['a', 'remesh'],
+ ['b', 'rig'],
+ ],
+ [
+ ['a', 'mesh', 'b', 'mesh'],
+ ['b', 'mesh', 'a', 'mesh'],
+ ],
+ );
+ const { order, cycle } = topoSort(w);
+ expect(order).toEqual(['p']);
+ expect(cycle.sort()).toEqual(['a', 'b']);
+ });
+});
+
+describe('buildPlan and For Each expansion', () => {
+ const batch = () =>
+ wf(
+ [
+ ['f', 'forEach', 0, 0, { mode: 'text', prompts: 'chair\ntable\n\nlamp' }],
+ ['g', 'generate', 200],
+ ['v', 'preview', 400, 0],
+ ['s', 'save', 400, 200],
+ ],
+ [
+ ['f', 'item', 'g', 'prompt'],
+ ['g', 'mesh', 'v', 'mesh'],
+ ['g', 'mesh', 's', 'mesh'],
+ ],
+ );
+
+ it('replays the loop body once per item, skipping blank prompt lines', () => {
+ const { steps } = buildPlan(batch(), T);
+ expect(steps.map((s) => `${s.nodeId}${s.iter}`)).toEqual(['f0', 'g0', 'v0', 's0', 'f1', 'g1', 'v1', 's1', 'f2', 'g2', 'v2', 's2']);
+ });
+
+ it('runs a shared non-loop input before the loop block', () => {
+ const w = wf(
+ [
+ ['f', 'forEach', 0, 0, { images: [img(1), img(2)] }],
+ ['hint', 'prompt', 0, 300, { text: 'clean studio lighting' }],
+ ['g', 'generate', 200, 0, { mode: 'image' }],
+ ],
+ [
+ ['f', 'item', 'g', 'image'],
+ ['hint', 'text', 'g', 'prompt'],
+ ],
+ );
+ const { steps, owner } = buildPlan(w, T);
+ expect(steps[0]).toEqual({ nodeId: 'hint', iter: null });
+ expect(steps.slice(1).map((s) => `${s.nodeId}${s.iter}`)).toEqual(['f0', 'g0', 'f1', 'g1']);
+ expect(owner.get('g')).toBe('f');
+ expect(owner.has('hint')).toBe(false);
+ });
+
+ it('emits no body steps for a loop with zero items', () => {
+ const w = wf(
+ [
+ ['f', 'forEach', 0, 0, { mode: 'text', prompts: '' }],
+ ['g', 'generate', 200],
+ ],
+ [['f', 'item', 'g', 'prompt']],
+ );
+ expect(buildPlan(w, T).steps).toEqual([]);
+ });
+});
+
+describe('connection rules', () => {
+ const base = () =>
+ wf([
+ ['p', 'prompt', 0, 0, { text: 'x' }],
+ ['i', 'image', 0, 200, { images: [img(1)] }],
+ ['g', 'generate', 200],
+ ['r', 'rig', 400],
+ ]);
+
+ it('rejects mismatched types with a readable reason', () => {
+ const res = canConnect(base(), T, { node: 'i', port: 'image' }, { node: 'r', port: 'mesh' });
+ expect(res.ok).toBe(false);
+ expect(res.reason).toMatch(/takes a 3D model, not an image/);
+ });
+
+ it('rejects self links and cycles', () => {
+ let w = base();
+ w = connect(w, T, { node: 'g', port: 'mesh' }, { node: 'r', port: 'mesh' }).workflow;
+ expect(canConnect(w, T, { node: 'r', port: 'mesh' }, { node: 'r', port: 'mesh' }).ok).toBe(false);
+ const loop = wf(
+ [
+ ['a', 'remesh'],
+ ['b', 'rig'],
+ ],
+ [['a', 'mesh', 'b', 'mesh']],
+ );
+ expect(canConnect(loop, T, { node: 'b', port: 'mesh' }, { node: 'a', port: 'mesh' }).reason).toMatch(/For Each/);
+ });
+
+ it('replaces an existing link into the same input', () => {
+ let w = base();
+ w = connect(w, T, { node: 'p', port: 'text' }, { node: 'g', port: 'prompt' }).workflow;
+ const p2 = { id: 'p2', type: 'prompt', x: 0, y: 400, params: { text: 'y' } };
+ w = { ...w, nodes: [...w.nodes, p2] };
+ w = connect(w, T, { node: 'p2', port: 'text' }, { node: 'g', port: 'prompt' }).workflow;
+ const into = w.edges.filter((e) => e.to.node === 'g' && e.to.port === 'prompt');
+ expect(into).toHaveLength(1);
+ expect(into[0].from.node).toBe('p2');
+ });
+
+ it('prunes links whose port changed type after a param edit', () => {
+ let w = base();
+ w = connect(w, T, { node: 'p', port: 'text' }, { node: 'g', port: 'prompt' }).workflow;
+ w = connect(w, T, { node: 'i', port: 'image' }, { node: 'g', port: 'prompt' }).workflow;
+ expect(w.edges).toHaveLength(1);
+ const imageMode = { ...w, nodes: w.nodes.map((n) => (n.id === 'g' ? { ...n, params: { ...n.params, mode: 'image' } } : n)) };
+ const linked = connect(imageMode, T, { node: 'i', port: 'image' }, { node: 'g', port: 'image' }).workflow;
+ expect(pruneInvalidEdges(linked, T).edges).toHaveLength(2);
+ const backToText = { ...linked, nodes: linked.nodes.map((n) => (n.id === 'g' ? { ...n, params: { ...n.params, mode: 'text' } } : n)) };
+ expect(pruneInvalidEdges(backToText, T).edges.map((e) => e.to.port)).toEqual(['prompt']);
+ });
+
+ it('removing nodes removes their links', () => {
+ let w = base();
+ w = connect(w, T, { node: 'p', port: 'text' }, { node: 'g', port: 'prompt' }).workflow;
+ w = connect(w, T, { node: 'g', port: 'mesh' }, { node: 'r', port: 'mesh' }).workflow;
+ expect(removeNodes(w, ['g']).edges).toEqual([]);
+ });
+});
+
+describe('stepSignature', () => {
+ const chain = (text, filename = 'a') =>
+ wf(
+ [
+ ['p', 'prompt', 0, 0, { text }],
+ ['g', 'generate', 200],
+ ['x', 'export', 400, 0, { filename }],
+ ],
+ [
+ ['p', 'text', 'g', 'prompt'],
+ ['g', 'mesh', 'x', 'mesh'],
+ ],
+ );
+ const sig = (w, id, iter = null) => stepSignature(w, T, id, iter, buildPlan(w, T));
+
+ it('changes downstream when an upstream param changes', () => {
+ expect(sig(chain('chair'), 'g')).not.toBe(sig(chain('table'), 'g'));
+ expect(sig(chain('chair'), 'x')).not.toBe(sig(chain('table'), 'x'));
+ });
+
+ it('ignores params marked signatureExclude', () => {
+ expect(sig(chain('chair', 'one'), 'x')).toBe(sig(chain('chair', 'two'), 'x'));
+ });
+
+ it('differs per loop item', () => {
+ const w = wf(
+ [
+ ['f', 'forEach', 0, 0, { mode: 'text', prompts: 'chair\ntable' }],
+ ['g', 'generate', 200],
+ ],
+ [['f', 'item', 'g', 'prompt']],
+ );
+ expect(sig(w, 'g', 0)).not.toBe(sig(w, 'g', 1));
+ });
+});
+
+describe('serialization', () => {
+ it('round-trips a template through JSON', () => {
+ const w = instantiateTemplate('text-rig-export');
+ const back = parseWorkflow(serializeWorkflow(w, T), T);
+ expect(back.nodes).toEqual(w.nodes.map((n) => ({ ...n, x: Math.round(n.x), y: Math.round(n.y) })));
+ expect(back.edges).toEqual(w.edges);
+ expect(back.name).toBe(w.name);
+ });
+
+ it('gives every template instance fresh ids', () => {
+ const a = instantiateTemplate('batch-save');
+ const b = instantiateTemplate('batch-save');
+ const ids = new Set(a.nodes.map((n) => n.id));
+ expect(b.nodes.some((n) => ids.has(n.id))).toBe(false);
+ });
+
+ it('rejects files that are not workflows with a readable error', () => {
+ expect(() => parseWorkflow('{nope', T)).toThrow(/not valid JSON/);
+ expect(() => parseWorkflow({ kind: 'other' }, T)).toThrow(/not a three.ws Forge workflow/);
+ expect(() => parseWorkflow({ kind: WORKFLOW_KIND, version: 99, nodes: [], edges: [] }, T)).toThrow(/newer version/);
+ expect(() => parseWorkflow({ kind: WORKFLOW_KIND, version: 1, nodes: [{ id: 'a', type: 'teleport' }], edges: [] }, T)).toThrow(/unknown type/);
+ expect(() => parseWorkflow({ kind: WORKFLOW_KIND, version: 1, nodes: [{ id: 'a', type: 'rig' }, { id: 'a', type: 'rig' }], edges: [] }, T)).toThrow(/duplicate id/);
+ });
+
+ it('fills defaults and drops links to missing nodes on import', () => {
+ const w = parseWorkflow(
+ {
+ kind: WORKFLOW_KIND,
+ version: 1,
+ name: ' ',
+ nodes: [{ id: 'g', type: 'generate', x: 'left' }],
+ edges: [{ id: 'e', from: { node: 'ghost', port: 'text' }, to: { node: 'g', port: 'prompt' } }],
+ },
+ T,
+ );
+ expect(w.name).toBe('Imported workflow');
+ expect(w.nodes[0]).toMatchObject({ x: 0, y: 0, params: { mode: 'text', engine: 'auto', tier: 'draft' } });
+ expect(w.edges).toEqual([]);
+ });
+});
diff --git a/tests/forge-workflows-runner.test.js b/tests/forge-workflows-runner.test.js
new file mode 100644
index 000000000..1485b54e1
--- /dev/null
+++ b/tests/forge-workflows-runner.test.js
@@ -0,0 +1,255 @@
+// Forge Workflows runner: scheduling, partial failure, cancel, reuse and
+// re-run from a failed node. Executors are injected, so these tests exercise
+// the real scheduling code without the network.
+
+import { describe, expect, it } from 'vitest';
+import { WORKFLOW_KIND } from '../src/forge-workflows/graph.js';
+import { NODE_TYPES } from '../src/forge-workflows/node-types.js';
+import { StepError, createRunner, summarizeNode } from '../src/forge-workflows/runner.js';
+
+const T = NODE_TYPES;
+
+function wf(nodes, edges = []) {
+ return {
+ kind: WORKFLOW_KIND,
+ version: 1,
+ name: 'Test',
+ nodes: nodes.map(([id, type, x = 0, y = 0, params = {}]) => ({ id, type, x, y, params })),
+ edges: edges.map(([from, fromPort, to, toPort], i) => ({ id: `e${i}`, from: { node: from, port: fromPort }, to: { node: to, port: toPort } })),
+ };
+}
+
+/** Executors that record calls and pass a mesh label down the chain. */
+function recorder({ failOn = () => false } = {}) {
+ const calls = [];
+ const executors = {
+ prompt: async ({ node }) => ({ outputs: { text: node.params.text } }),
+ generate: async ({ node, inputs, iter, progress }) => {
+ calls.push(`${node.id}${iter ?? ''}:${inputs.prompt}`);
+ progress({ pct: 50, stage: 'meshing' });
+ if (failOn(node.id, iter, inputs)) throw new StepError(`could not build ${inputs.prompt}`, { code: 'engine_down', action: { label: 'Status', href: '/status' } });
+ return { outputs: { mesh: { url: `mesh:${inputs.prompt}` } } };
+ },
+ rig: async ({ node, inputs, iter }) => {
+ calls.push(`${node.id}${iter ?? ''}:${inputs.mesh.url}`);
+ if (failOn(node.id, iter, inputs)) throw new StepError('rig failed');
+ return { outputs: { mesh: { url: `${inputs.mesh.url}+rig` } } };
+ },
+ export: async ({ node, inputs, iter }) => {
+ calls.push(`${node.id}${iter ?? ''}:${inputs.mesh.url}`);
+ return { outputs: {}, result: { note: inputs.mesh.url } };
+ },
+ };
+ return { calls, executors };
+}
+
+const chain = (text = 'chair') =>
+ wf(
+ [
+ ['p', 'prompt', 0, 0, { text }],
+ ['g', 'generate', 200, 0, { mode: 'text', engine: 'auto', tier: 'draft' }],
+ ['r', 'rig', 400],
+ ['x', 'export', 600, 0, { filename: 'a' }],
+ ],
+ [
+ ['p', 'text', 'g', 'prompt'],
+ ['g', 'mesh', 'r', 'mesh'],
+ ['r', 'mesh', 'x', 'mesh'],
+ ],
+ );
+
+const status = (runner, id) => runner.stepsFor(id).map((s) => s.status);
+
+describe('runner scheduling', () => {
+ it('runs steps in dependency order and passes outputs downstream', async () => {
+ const { calls, executors } = recorder();
+ const seen = [];
+ const runner = createRunner({ types: T, executors, onChange: (s) => s.activeKey && seen.push(s.activeKey) });
+ const final = await runner.run(chain());
+ expect(final.status).toBe('done');
+ expect(calls).toEqual(['g:chair', 'r:mesh:chair', 'x:mesh:chair+rig']);
+ expect(runner.stepsFor('x')[0].result).toEqual({ note: 'mesh:chair+rig' });
+ expect(seen).toContain('g#');
+ });
+
+ it('reports executor progress on the running step', async () => {
+ const { executors } = recorder();
+ const progress = [];
+ const runner = createRunner({
+ types: T,
+ executors,
+ onChange: (s) => {
+ const g = s.steps.get('g#');
+ if (g?.progress) progress.push(g.progress.pct);
+ },
+ });
+ await runner.run(chain());
+ expect(progress).toContain(50);
+ });
+
+ it('expands a For Each and keeps going after one item fails', async () => {
+ const { calls, executors } = recorder({ failOn: (id, iter) => id === 'g' && iter === 1 });
+ const w = wf(
+ [
+ ['f', 'forEach', 0, 0, { mode: 'text', prompts: 'chair\ntable\nlamp' }],
+ ['g', 'generate', 200, 0, { mode: 'text', engine: 'auto', tier: 'draft' }],
+ ['x', 'export', 400, 0, { filename: 'a' }],
+ ],
+ [
+ ['f', 'item', 'g', 'prompt'],
+ ['g', 'mesh', 'x', 'mesh'],
+ ],
+ );
+ const runner = createRunner({ types: T, executors });
+ const final = await runner.run(w);
+ expect(final.status).toBe('failed');
+ expect(calls).toEqual(['g0:chair', 'x0:mesh:chair', 'g1:table', 'g2:lamp', 'x2:mesh:lamp']);
+ expect(status(runner, 'g')).toEqual(['done', 'failed', 'done']);
+ expect(status(runner, 'x')).toEqual(['done', 'skipped', 'done']);
+ expect(summarizeNode(runner.stepsFor('g'))).toMatchObject({ status: 'failed', done: 2, failed: 1, total: 3 });
+ const err = runner.stepsFor('g')[1].error;
+ expect(err).toMatchObject({ message: 'could not build table', code: 'engine_down', actions: [{ label: 'Status', href: '/status' }] });
+ });
+
+ it('runs independent branches even when one branch fails', async () => {
+ const { executors } = recorder({ failOn: (id) => id === 'r' });
+ const w = wf(
+ [
+ ['p', 'prompt', 0, 0, { text: 'chair' }],
+ ['g', 'generate', 200, 0, { mode: 'text', engine: 'auto', tier: 'draft' }],
+ ['r', 'rig', 400, 0],
+ ['x', 'export', 400, 200, { filename: 'a' }],
+ ['x2', 'export', 600, 0, { filename: 'b' }],
+ ],
+ [
+ ['p', 'text', 'g', 'prompt'],
+ ['g', 'mesh', 'r', 'mesh'],
+ ['g', 'mesh', 'x', 'mesh'],
+ ['r', 'mesh', 'x2', 'mesh'],
+ ],
+ );
+ const runner = createRunner({ types: T, executors });
+ await runner.run(w);
+ expect(status(runner, 'r')).toEqual(['failed']);
+ expect(status(runner, 'x')).toEqual(['done']);
+ expect(status(runner, 'x2')).toEqual(['skipped']);
+ });
+
+ it('fails a step whose type has no executor, with a readable message', async () => {
+ const runner = createRunner({ types: T, executors: { prompt: async ({ node }) => ({ outputs: { text: node.params.text } }) } });
+ await runner.run(chain());
+ expect(runner.stepsFor('g')[0].error.message).toMatch(/No runner for Generate 3D/);
+ });
+
+ it('refuses to run a graph with a cycle', async () => {
+ const runner = createRunner({ types: T, executors: {} });
+ const w = wf(
+ [
+ ['a', 'rig'],
+ ['b', 'rig'],
+ ],
+ [
+ ['a', 'mesh', 'b', 'mesh'],
+ ['b', 'mesh', 'a', 'mesh'],
+ ],
+ );
+ await expect(runner.run(w)).rejects.toThrow(/loop/);
+ });
+});
+
+describe('cancel', () => {
+ it('cancels the running step and every step after it', async () => {
+ const executors = {
+ ...recorder().executors,
+ generate: ({ signal }) =>
+ new Promise((_resolve, reject) => {
+ signal.addEventListener('abort', () => reject(new DOMException('Cancelled', 'AbortError')));
+ }),
+ };
+ const runner = createRunner({ types: T, executors });
+ const pending = runner.run(chain());
+ await new Promise((r) => setTimeout(r, 0));
+ expect(runner.state.status).toBe('running');
+ expect(status(runner, 'g')).toEqual(['running']);
+ await expect(runner.run(chain())).rejects.toThrow(/already in progress/);
+ runner.cancel();
+ const final = await pending;
+ expect(final.status).toBe('cancelled');
+ expect(status(runner, 'g')).toEqual(['cancelled']);
+ expect(status(runner, 'r')).toEqual(['cancelled']);
+ expect(status(runner, 'x')).toEqual(['cancelled']);
+ });
+});
+
+describe('reuse and re-run', () => {
+ it('reuses unchanged steps and re-runs only what an edit touched', async () => {
+ const { calls, executors } = recorder();
+ const runner = createRunner({ types: T, executors });
+ await runner.run(chain());
+ calls.length = 0;
+ await runner.run(chain());
+ expect(calls).toEqual([]);
+ expect(runner.stepsFor('g')[0].reused).toBe(true);
+
+ const renamed = chain();
+ renamed.nodes.find((n) => n.id === 'x').params.filename = 'renamed';
+ await runner.run(renamed);
+ expect(calls).toEqual([]);
+
+ await runner.run(chain('table'));
+ expect(calls).toEqual(['g:table', 'r:mesh:table', 'x:mesh:table+rig']);
+ });
+
+ it('fresh mode ignores the cache', async () => {
+ const { calls, executors } = recorder();
+ const runner = createRunner({ types: T, executors });
+ await runner.run(chain());
+ calls.length = 0;
+ await runner.run(chain(), { mode: 'fresh' });
+ expect(calls).toHaveLength(3);
+ });
+
+ it('re-runs from a failed node, reusing everything upstream of it', async () => {
+ let failRig = true;
+ const { calls, executors } = recorder({ failOn: (id) => id === 'r' && failRig });
+ const runner = createRunner({ types: T, executors });
+ const first = await runner.run(chain());
+ expect(first.status).toBe('failed');
+ expect(status(runner, 'x')).toEqual(['skipped']);
+
+ failRig = false;
+ calls.length = 0;
+ const second = await runner.run(chain(), { fromNodeId: 'r' });
+ expect(second.status).toBe('done');
+ expect(calls).toEqual(['r:mesh:chair', 'x:mesh:chair+rig']);
+ expect(runner.stepsFor('g')[0].reused).toBe(true);
+ });
+
+ it('retries only the failed loop item', async () => {
+ let failing = true;
+ const { calls, executors } = recorder({ failOn: (id, iter) => failing && id === 'g' && iter === 1 });
+ const w = wf(
+ [
+ ['f', 'forEach', 0, 0, { mode: 'text', prompts: 'chair\ntable' }],
+ ['g', 'generate', 200, 0, { mode: 'text', engine: 'auto', tier: 'draft' }],
+ ],
+ [['f', 'item', 'g', 'prompt']],
+ );
+ const runner = createRunner({ types: T, executors });
+ await runner.run(w);
+ failing = false;
+ calls.length = 0;
+ const final = await runner.run(w);
+ expect(final.status).toBe('done');
+ expect(calls).toEqual(['g1:table']);
+ });
+
+ it('invalidate drops a node and its downstream from the cache', async () => {
+ const { executors } = recorder();
+ const runner = createRunner({ types: T, executors });
+ await runner.run(chain());
+ const before = runner.cacheSize;
+ runner.invalidate(chain(), 'r');
+ expect(runner.cacheSize).toBe(before - 2);
+ });
+});
diff --git a/vercel.json b/vercel.json
index c3639a25a..66fa66ecc 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1662,6 +1662,10 @@
"src": "/avatar-artifact/?",
"dest": "/avatar-artifact.html"
},
+ {
+ "src": "/forge/workflows/?",
+ "dest": "/forge-workflows.html"
+ },
{
"src": "/forge/embed/?",
"dest": "/forge-embed.html"
diff --git a/vite.config.js b/vite.config.js
index 21947ed6b..2e4ef65ef 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -761,6 +761,7 @@ const appConfig = {
create: resolve(__dirname, 'pages/create.html'),
'create-agent': resolve(__dirname, 'pages/create-agent.html'),
forge: resolve(__dirname, 'pages/forge.html'),
+ 'forge-workflows': resolve(__dirname, 'pages/forge-workflows.html'),
'nim-forge': resolve(__dirname, 'pages/nim-forge.html'),
'forge-nim': resolve(__dirname, 'pages/forge-nim.html'),
'forge-spark': resolve(__dirname, 'pages/forge-spark.html'),
@@ -2070,6 +2071,8 @@ const appConfig = {
'/render-lab/': resolve(root, 'pages/render-lab.html'),
'/workbench': resolve(root, 'pages/workbench.html'),
'/workbench/': resolve(root, 'pages/workbench.html'),
+ '/forge/workflows': resolve(root, 'pages/forge-workflows.html'),
+ '/forge/workflows/': resolve(root, 'pages/forge-workflows.html'),
'/bundles': resolve(root, 'pages/bundles.html'),
'/bundles/': resolve(root, 'pages/bundles.html'),
'/search': resolve(root, 'pages/search.html'),