Files
openmotion/docs/scenario-workflows.md
Tom Huang 9060f47d0d feat(scenario): add dual-mode Workflows workspace, shared Assets, and MCP write-back (#781)
* Add scenario workflows foundation, Design asset import and Wave 1 contracts

Implement the Wave 1 scenario workflow contracts, shared domain service,
Design Studio binary asset import, ZIP bundle exporter and Studio boundary
files while preserving the 22 public MCP tools:

- Shared browser-safe contracts in shared/scenarios.ts, shared/scenario-runs.ts
  and shared/scenario-content.ts covering all five scenarios, 21 scenario
  commands, starter HTML recipes, idempotent HTML image embedding, localized
  social drafting and Agent handoff builders.
- Design Studio binary asset import via DesignProjects.importBinaryFile(),
  openmotion_design_edit action=import_asset, POST /api/design/projects/:id/import-asset
  and designClient.importAsset().
- Domain service (gateway/scenario-runs.ts), ZIP bundle builder
  (gateway/scenario-bundle.ts) and HTTP download route (gateway/scenario-http.ts),
  wired under openmotion_assets_use action=scenario with tracking schema parity.
- Studio scenario client, scenarioCovers.ts, stepContract.ts and ODUI-compliant
  boundary stubs for parallel Wave 2 UI implementation.
- Node test coverage in tests/scenario-content.test.ts, tests/scenario-runs.test.ts,
  tests/scenario-bundle.test.ts and tests/design-import-asset.test.ts registered
  in .github/workflows/ci.yml.

* Implement scenario workflow step workbenches and unit tests

- Add reusable BindingSlot with pool picker, chip removal and drag-and-drop
- Implement BriefStep with dynamic brief fields, debounced autosave, revisions, downstream prompt seeding, AI influencer script editor, Gemini 4 Neon rail/availability and Black Friday discount badge
- Implement WebPageStep with starter/template/existing project creation, live viewport preview, live HTML slot targeting, single and chained Embed all, and design version previews
- Implement MediaStep (image, video, audio) and MotionPanel with scene/audio tabs, catalog model picker, offscreen-pausing video, offline provider-setup recovery with upload/workspace import, and Motion project creation/linking
- Implement SocialPackStep with offline drafting, regeneration variants, character/title limit counters, hashtags, media reordering and token-only live card previews
- Implement ExportHubStep with step overview, pool readiness checks, ZIP bundle export with persistent download card and Agent handoff actions
- Wire StepRouter with token-only opaque steps.css and add Vitest suites for all five step workbenches

* Implement scenario workflow shell, shared asset pool, and run state

Add useScenarioRun state hook with auto-resume, lazy run creation, optimistic revision conflict recovery, visibility-aware job polling, and window focus refresh. Implement ScenarioCard, ScenarioHub, ScenarioHeader, ScenarioStepper, PoolItemPreview, AssetPoolPanel, IterationHistory, StepExportMenu, ScenarioWorkspace, opaque token-only scenario.css, and Studio unit tests.

* Wire scenario workflow navigation, routing, MCP handbook, 10-locale i18n and docs

Implements Worker D integration for end-to-end scenario workflows:
- Routing & URLs: scenario/scenarios pages with category, run UUID, and step validation plus breadcrumb labels
- Top nav & Explore: Workflows split tab with 3-column mega menu, ExploreSpotlight primary workflow CTAs + 5th AI Influencer slide, ScenarioHighlights rail, CapabilityIndex Workflows column, landing cross-links, and WorkspaceFrame host wiring
- MCP handbook: scenario-workflows capability (preserving exact 22 phase-1 tool union), scenario-black-friday and design-embed-assets recipes, and setup-prefixed Black Friday handoff
- 10-locale i18n: scenario-ui.json (526 keys x 10 locales covering shared/scenarios.ts plus all scenario-shell and scenario-steps UI keys), studio-navigation-ui.json, and mcp-ui.json updates
- Docs & tests: mcp-phase1-tools.md, product architecture, scenario-workflows.md guide, openmotion-design SKILL note, and full Vitest + Node MCP test coverage

* Register scenario stylesheets in tokenGate and complete 10-locale i18n coverage

- Register scenarioNavigation.css, scenario.css and steps.css in
  studio/src/styles/tokenGate.test.ts and define the four remaining
  token-only scenario CSS classes (.om-scenario-host,
  .om-scenario-header-category, .om-scenario-step-tab-title,
  .om-scenario-history--empty).
- Add the missing 'Download started' translation across all 10 non-English
  locales in studio/src/i18n/scenario-ui.json for 100% 10-locale coverage.

* Fix Scenario Workflows Wave 3 E2E and visual findings

- Treat full content-step selection as an unfiltered export bundle so README.md and unattached uploaded pool files are included
- Auto-activate newly saved iterations in ScenarioRuns.addIteration while preserving promote for older versions
- Suppress duplicate raw error toasts on SCENARIO_CONFLICT after useScenarioRun displays the localized conflict notice
- Map raw step statuses, pool kinds, job states, and copy tone/promo code labels through localized UI keys across all 10 locales
- Restore light/dark Explore hero CTA contrast hierarchy and make the Workflows mega menu compact so the footer is visible without clipping at 1440x900
- Stack the scenario step header vertically below 767px to avoid squeezing the step title on mobile viewports

* fix(scenario): replace alarming export-hub step warning stack with calm readiness hint

* feat(scenario): replace intimidating brief form with guided fill-in-the-blanks prompt composer

* polish(scenario): auto-size inline blank pills snugly to text content

* feat(scenario): add guided page composer, filter layouts, and codify workflow UX rules

* Enhance scenario workflows with semantic step colors, icons, and unified composers

Add consistent semantic color-coding and richer icons across the scenario
workflow shell and every step workbench without removing any capability:

- ScenarioStepper & ScenarioWorkspace: add step-type color accents (brief,
  image, web-page, video, audio, social-pack, export-hub), flow connectors,
  live progress bar, tinted step header badge, Step N / M pill, and next-step
  icon cues.
- ScenarioHeader, ScenarioCard & AssetPoolPanel: color-code category pills,
  step preview chips, shared asset pool header/filter chips, and asset kind
  badges using existing packages/design-system tokens.
- MediaStep, SocialPackStep, WebPageStep, BriefStep, MotionPanel, BindingSlot
  & ExportHubStep: unify Media and Social steps into single composer cards
  matching Brief and WebPage, render official PlatformIcon glyphs for social
  channels, add colored section/slot/stat icons, and remove redundant orphan
  toolbars while preserving all generation, upload, embed, edit, compare,
  MCP handoff, and ZIP export actions.
- Update studio/src/i18n/scenario-ui.json across all 10 non-English locales.

* Refine scenario workflows layout, controls, and dual-track MCP write-back

- Refine input and Select dropdown borders across design-system adapter/application CSS and workflow steps, eliminating thick stacked outlines and clipped option borders
- Flatten nested wireframes and unify top chrome, stepper, step composers, and open canvas sections with plain consumer-product terminology and 10-locale translations
- Add desktop drag-resizer, keyboard/double-click reset, persistence, and collapse/reopen toggle with auto-expand on pick for the right Shared assets sidebar
- Add StepCapabilityBar for in-step direct image/video generation alongside run-bound MCP write-back prompts and window focus/visibility sync across creation steps
- Consolidate workflow export actions into the header and Shared assets sidebar and fix backend text-ref type narrowing in scenario bundle generation

* feat(scenario): add dual-mode Agent mode, preview stage, draft history, and polish UX

Add Step-by-step and Agent mode workspace views with grouped Skills pipeline, concise MCP prompt generation, visual preview stage, draft history dialog, selective Assets import/export, 10-locale i18n coverage, and tokenGate CSS fixes.

* fix(i18n): remove duplicate base-dictionary overrides from scenario-ui.json

Drop duplicate '{count} selected' and 'Copied. Paste into your Agent.' entries from scenario-ui.json so ProjectArchives and TemplateLibraryDialog retain their canonical translations.

* feat(scenario): add stage preview artwork, refine Agent Teams UX and disclosure styling

* fix(scenario): address PR #781 review feedback across steps, templates, HTML embed and side-effect mutations

---------

Co-authored-by: pftom <pftom@pftomdeMacBook-Pro.local>
2026-11-21 17:21:46 +08:00

73 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Scenario Workflows
**Workflows** (backed by OpenMotion's scenario workflow contract) guide end-to-end production from a single creative idea through web pages, visual assets, video and motion films, audio, multi-platform social copy, and one downloadable ZIP package. Each workflow supports two modes in one workspace — **Step by step** (`manual`) for hands-on iterative creation and **Agent mode** (`agent`, `?mode=agent`) for concise prompt + Skills delegation to an external MCP Agent — backed by shared versioned runs and a unified **Assets** collection.
## Workflow taxonomy
Workflows are organized into three categories under **Workflows** in the top navigation (`?page=scenarios`), its hover mega popover, the Explore hero carousel, and the Workflows highlights rail:
| Category | Workflow / Scenario ID | Title | Ordered steps |
| --- | --- | --- | --- |
| **Topics** (`topic`) | `motion-full-chain` | Idea to Motion Film | Brief → Storyboard → Motion film → Soundtrack → Social posts |
| **Topics** (`topic`) | `gemini-4-neon` | Interactive Code Animation | Brief → Code animation → Key stills → Film & motion → Social posts |
| **Topics** (`topic`) | `design-full-chain` | Landing Page & Launch Kit | Brief → Landing page → Page images → Embed images → Promo video → Social posts |
| **Campaigns** (`campaign`) | `black-friday` | Black Friday Promo Kit | Brief → Product images → Detail page → 30s sales film → Social posts |
| **Roles** (`role`) | `ai-influencer` | Virtual Creator Episode | Brief & script → Persona visuals → Link-in-bio page → Voiceover & audio → Talking video → Social posts |
Every step carries curated `ScenarioSkillRef` bindings (`step.skills[]`) identifying either a curated Studio library Skill (`source: 'library'`, loaded via `openmotion_get_skill(skillId)`) or a workflow resource guide (`source: 'workflow'`, loaded via MCP `resources/read` on `resourceUri` such as `openmotion://workflow/*`). Existing Studio destinations (Motion Studio, Design Studio, Cinema Studio, Model Hub, Black Friday collection, Template library, Skills) remain directly reachable from navigation and context links inside each workflow.
## Dual workspace modes and Assets
Opening any workflow navigates to `?page=scenario&scenario=<id>[&run=<uuid>][&mode=agent][&step=<stepId>]` (defaults to **Step by step** unless `mode=agent` is requested).
- **Run header:** displays the workflow cover, **All workflows** breadcrumb, workflow title and category badge, **Workflow mode** segmented switch (**Step by step** vs **Agent mode**), run switcher (create, rename or archive drafts), contextual **Copy for Agent** (header action in Step-by-step mode), desktop toggle to collapse/reopen **Assets**, and **Export all** (builds and downloads a full ZIP bundle directly).
- **Agent mode (`?mode=agent`, `ScenarioAgentModeView.tsx`):** renders a clean two-column workspace:
- **Left column — Assets + Prompt & parameters:** inline shared **Assets** panel at the top (so users can upload, import, select, pin, and inspect attached reference assets cleanly), paired below with a **Prompt & parameters** composer featuring one-click `Try:` brief presets, **Clear**, a large natural-language `Prompt` textarea, primary scenario fields, and progressive-disclosure secondary parameters (**More parameters** / **Hide parameters**) synchronized directly to the persisted run brief, plus a direct **Switch to step by step** link.
- **Right column — Copy for Agent + Skills workflow:** centers the primary **Copy for Agent** CTA (auto-creating a persisted run when invoked on an unsaved draft and copying compact output from `scenarioConcisePrompt`), quick **Sync** and **MCP guide** actions, a **Preview prompt** / **Hide prompt** toggle inspecting the generated concise instructions, and a grouped **Skills workflow** timeline displaying every step's `ScenarioSkillRef` chips (`role`, `id`, version count, status) with direct click-through (`Open {step} in step-by-step mode`).
- **Step by step mode (`manual`):** combines the non-linear step navigation rail (**Workflow steps**, allowing direct jumps to any step with sensible upstream default bindings and without locking downstream steps), a single guided brief/creation workbench (**Generate media** for direct image/video/audio generation into **Assets** via configured providers, **Copy MCP prompt**, **MCP guide**, **Sync**, progressive disclosures for reuse/templates, live preview, per-step export actions, and **Version history** `v1…vn`), and the collapsible **Assets** sidebar.
- **Assets collection & pinning:** docked on the right at desktop widths (`>= 1100px`) in Step-by-step mode (`240–520px` resizable drawer, opaque medium-width drawer `768–1099px`, mobile bottom sheet `< 768px`) or placed inline at the top left in Agent mode. Empty zero-count filter chips stay hidden until populated. Supports single, multi-select (`Select`), and bulk **Import** / **Export** (`Export all`, `Export selected`, `Export filtered`). Every uploaded, imported, or generated asset is stored as a **pinned reference** (`assetId/versionId`, Design `projectId/revision`, Motion `projectId/sessionId`) without duplicating media bytes; **Remove from workflow** unbinds only the workflow reference without deleting workspace assets.
- **Automatic cross-tab sync:** window focus, tab `visibilitychange` back to `visible`, and manual **Sync** actions refresh the active run and highlight newly added items in **Assets**.
## Export and packaging
- **Per-step export:** every step header offers a lightweight menu for immediate deliverables (HTML/ZIP for Design pages, direct downloads for active media files, Markdown/JSON copy or download for social packs and briefs, editor links, and step-scoped ZIP packages).
- **Single, multi-select, filtered, and full bundle export:** **Assets** and top-bar **Export all** build validated ZIP archives via `openmotion_assets_use(action="scenario", scenario={ command: "export", poolItemIds?: [...], ... })` and stream them from `GET /motion-api/scenarios/bundles/:id/file`. A full bundle contains `manifest.json`, `README.md`, `brief/`, unpacked `web/<step-id>/` pages (with embedded local `assets/*` paths that open from disk), optional standalone HTML, pinned `media/` outputs, `social/` posts, `motion/` project links, and optional Motion source archives; passing `poolItemIds` packages only the chosen items alongside `manifest.json`.
## MCP and Agent integration
Workflows preserve the twenty-two registered phase-one MCP tool names and share one backend domain service (`gateway/scenario-runs.ts`) across Studio and external Agents:
- **Workflow / scenario orchestration:** `openmotion_assets_use` with `action="scenario"` exposes `catalog`, `list`, `get`, `create`, `update_run`, `update_brief`, `update_step`, `add_pool`, `update_pool`, `remove_pool`, `add_iteration`, `generate`, `sync`, `cancel`, `promote`, `create_page`, `embed_image`, `link_design`, `create_motion`, `link_motion`, and `export`. Mutations carry explicit `runId`, `expectedRevision`, and a stable `requestId`; `add_pool` accepts optional `recordIteration=true` and `note` to write Agent-processed workspace assets back into both **Assets** and the target step's version history atomically.
- **Concise Skills handoff (`scenarioConcisePrompt` & `ScenarioSkillRef`):** in **Agent mode** (`?mode=agent`), clicking **Copy for Agent** (or inspecting **Preview prompt**) formats compact `[Metadata]`, `[Task & Parameters]`, `[Skills Pipeline]`, and `[Instructions]` via `scenarioConcisePrompt` in `shared/scenarios.ts`. Instead of repeating prose instructions per step, it lists each step's Skills cleanly as `library:<skillId>` (loaded by the Agent via `openmotion_get_skill(skillId)`) or `resource:<resourceUri>` (loaded via MCP `resources/read`, e.g., `openmotion://workflow/*`). `scenarioSkills(scenario)` exposes the deduplicated Skill list per workflow.
- **Step-scoped MCP write-back:** `scenarioAgentPrompt` and `scenarioRunAgentPrompt` in `shared/scenarios.ts` continue to power per-step **Copy MCP prompt**, Step-by-step **Copy for Agent**, and the **MCP · Connect Agent** handbook (`Run a workflow and save back to Assets`). Copying from a fresh draft creates and persists the run first so every copied instruction carries `runId`, `expectedRevision`, `stepId` (when step-scoped), attached **Assets**, and exact MCP write-back commands (`generate` + `sync`, `add_pool` with `recordIteration=true`, `add_iteration`, `link_design`, `link_motion`, `update_brief`).
- **Binary image embedding into HTML projects:** `openmotion_design_edit` with `action="import_asset"` (and `POST /motion-api/design/projects/:id/import-asset`) copies a pinned workspace asset version into a Design Studio project via `DesignProjects.importBinaryFile()`, creating a new revision-checked `vN` snapshot and returning its project-relative path.
See [MCP Phase 1 tools](mcp-phase1-tools.md) and [Product architecture](product/architecture.md#scenario-workflows) for contract details.
## Capability boundaries
- **No built-in text or design LLM:** offline starter HTML pages, script outlines, and multi-platform social drafts are deterministic templates seeded from your brief. AI-authored HTML pages and copy come from your connected external Agent via the shared Skills handoff prompt.
- **Provider-backed media generation:** image, video, speech, and music generation use your configured providers in **Model providers** (OpenDesign account or BYOK). When no compatible model is configured, steps show a setup panel alongside offline upload, workspace-asset import, and Agent handoff alternatives without fabricating results.
- **Export-only social packs:** social posts are drafted, edited, copied, and exported as Markdown/JSON/text files; OpenMotion does not publish directly to social platforms.
- **Distinct verification evidence:** automated unit/DOM checks, browser visual checks across light/dark themes and viewports, paid model generation, and human visual acceptance remain separate evidence.
## Adding a new Topic, Campaign or Role workflow
Navigation, Explore, the Workflows hub, the MCP catalog, and run persistence all read from the shared registry. Adding a new workflow requires four changes:
1. **Register the definition** in `shared/scenarios.ts` (`scenarioDefinitions`), specifying `id`, `category` (`topic | campaign | role`), `title`, `subtitle`, `description`, `icon`, `links`, `briefFields`, and ordered `steps` (referencing valid `studioScenes` IDs, `RemixIcon` names from `packages/design-system/icons.svg`, and `skills: ScenarioSkillRef[]` entries pointing to curated `library` Skills or `workflow` resource URIs).
2. **Add a local cover mapping** in `studio/src/scenario/scenarioCovers.ts`.
3. **Add translations across all 10 non-English locales** in `studio/src/i18n/scenario-ui.json` — covering title, subtitle, description, fields, steps, and every `skill.label` / `skill.role` (preserving `{placeholders}`, `openmotion_*` tool names, and using `项目` rather than `工程` in `zh-CN`).
4. **Optionally add a starter page recipe** in `shared/scenario-content.ts` if the scenario introduces a new `PageRecipeId`.
Validate changes with:
```bash
npm run check
npm run design:check
npm run typecheck:backend
npm run typecheck:studio
npm run test:studio -- src/i18n src/motion/ScenarioNavigation.test.tsx src/motion/WorkspacePageNavigation.test.tsx src/motion/workspacePageRouting.test.ts
node --experimental-strip-types --test tests/mcp-onboarding.test.ts tests/scenario-runs.test.ts tests/scenario-content.test.ts tests/scenario-bundle.test.ts
```