# Phase 5: Persist — Assemble + Save Template ## Objective Assemble the final workflow template JSON from design session data, write to template library, output usage instructions. ## Workflow ### Step 5.1 — Load Design Session Read: - `design-session/intent.json` → template metadata - `design-session/dag.json` → nodes, edges, checkpoints, context_schema ### Step 5.2 — Determine Template Name + Path **Name**: Use user's confirmed name from Phase 4. If not set, derive from intent.task_type + first 3 meaningful words of raw_description. **Slug**: kebab-case from name (e.g. "Feature TDD with Review" → "feature-tdd-with-review") **Path**: `.workflow/templates/.json` **template_id**: `wft--` Check for existing file: - If exists and different content: append `-v2`, `-v3`, etc. - If exists and identical: skip write, output "Template already exists" ### Step 5.3 — Assemble Template JSON See `specs/template-schema.md` for full schema. Assemble: ```json { "template_id": "wft--", "name": "", "description": "", "version": "1.0", "created_at": "", "source_session": "", "tags": ["", ""], "context_schema": { /* from dag.json */ }, "nodes": [ /* from dag.json, full node objects */ ], "edges": [ /* from dag.json */ ], "checkpoints": [ /* checkpoint node IDs */ ], "atomic_groups": [ /* from intent.json parallel groups */ ], "execution_mode": "serial", "metadata": { "node_count": , "checkpoint_count": , "estimated_duration": "" } } ``` ### Step 5.4 — Write Template Write assembled JSON to `.workflow/templates/.json`. Ensure `.workflow/templates/` directory exists (create if not). ### Step 5.5 — Update Template Index Read/create `.workflow/templates/index.json`: ```json { "templates": [ { "template_id": "wft--", "name": "", "path": ".workflow/templates/.json", "tags": [""], "created_at": "", "node_count": } ] } ``` Append or update entry for this template. Write back. ### Step 5.6 — Output Summary ``` Template saved: .workflow/templates/.json ID: wft-- Nodes: work nodes + checkpoints Variables: To execute: Skill(skill="wf-player", args=" --context goal=''") To edit later: Skill(skill="wf-composer", args="--edit .workflow/templates/.json") To list all templates: Skill(skill="wf-player", args="--list") ``` ### Step 5.7 — Clean Up Draft Delete `design-session/` directory (or move to `.workflow/templates/design-drafts/archive/`). ## Success Criteria - `.workflow/templates/.json` exists and is valid JSON - `index.json` updated with new entry - Console shows template path + usage command