# Workflow Engine (v0.4 foundation)

## Purpose

Resumable multi-step automation per docs `02-system-architecture-prompt.md` §7.

## Current Scope

- Domain contracts: `WorkflowStepInterface`, `WorkflowRunnerInterface`, `WorkflowRunStoreInterface`
- Application: `WorkflowRunner`, `WorkflowRegistry`, `StartWorkflow`, `GetWorkflowRun`
- Infrastructure: `WorkflowRunRepository`, `AsyncQueueDriver` (Action Scheduler → WP-Cron fallback)
- Built-in workflow: `publish_product` (8 steps)
- REST: `POST /workflows`, `GET /workflows/{run_id}`, `POST /workflows/{run_id}/resume`

## Feature Flag

- Setting: `enable_workflows` (default `false`)

## Publish Product Steps

1. `validate_product`
2. `generate_description`
3. `generate_seo`
4. `apply_content`
5. `ensure_featured_image` — skips if image present; else saves brief + hooks `teddy_workflow_generate_product_image` / `teddy_workflow_need_product_image` (`require_image` input optional). Default handler tries WP AI Client image generation, then GD placeholder PNG.
6. `generate_translation_draft` — only when input `target_language` is set; stores `_teddy_i18n_draft_{lang}`
7. `publish_product`
8. `notify_complete` — optional `notify_email` via `wp_mail`

State is persisted after **each** step in `wp_teddy_workflow_runs`.

## Verification

- `tests/Unit/ChatMemoryComposerTest.php` (`WorkflowRunnerTest`)
