Design V2 Workflow
The user wants: $ARGUMENTS
Step: Init User Intent
Creates the user intent ledger with the initial idea.
bash
python3 -c "from factory.workflow.contributed.design_v2.intent_init import main; main()" "$PROJECT_PATH"
Gate — Has Factory (Automated)
MANDATORY: Wait for the preceding agent to finish, then run this check BEFORE spawning the next agent. Do NOT run agents in parallel across this gate.
bash
python3 -c "from pathlib import Path; exists = Path("$PROJECT_PATH/.factory/config.json").exists(); print("PROCEED" if exists else "HALT")"
- PROCEED (exit 0 / no FAIL in output) → continue to
graph_update - HALT (exit non-zero / FAIL in output) → continue to
discover instead.
Step: Discover
bash
factory discover $PROJECT_PATH
Gate — Factory Md Exists (Automated)
MANDATORY: Wait for the preceding agent to finish, then run this check BEFORE spawning the next agent. Do NOT run agents in parallel across this gate.
bash
python3 -c "from pathlib import Path; exists = Path("$PROJECT_PATH/factory.md").exists(); print("PROCEED" if exists else "HALT")"
- PROCEED (exit 0 / no FAIL in output) → continue to
factory_init - HALT (exit non-zero / FAIL in output) → continue to
create_factory_md instead.
Phase 1: Ceo — Create Factory Md
bash
factory agent ceo --task "Create factory.md from template. Copy the factory config template to the project root. Fill in: Goal, Scope, Guards, Eval command, Threshold, and Smoke Test. If .factory/eval_spec.json exists, populate the Eval Spec section. If .factory/strategy/current.md has a Research Configuration section, populate research sections (Research Target, Mutable/Fixed Surfaces, etc.).
Read: .factory/eval_profile.json
Write output to: factory.md" --project "$PROJECT_PATH" --timeout 3600
bash
# Artifact verification: create_factory_md
_vfail=0
_f="$PROJECT_PATH/factory.md"
[ ! -f "$_f" ] && echo "VERIFY FAIL: create_factory_md: factory.md missing" && _vfail=1
[ -f "$_f" ] && [ ! -s "$_f" ] && echo "VERIFY FAIL: create_factory_md: factory.md is empty" && _vfail=1
[ "$_vfail" -ne 0 ] && echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_FAIL node=create_factory_md" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt" && exit 1
echo "VERIFY OK: create_factory_md artifacts validated"
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_OK node=create_factory_md" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt"
(harness verification — DO NOT SKIP)
Step: Factory Init
Parse factory.md and generate .factory/config.json. Must run after factory.md is created.
bash
factory init $PROJECT_PATH
Step: Graph Update
Extract or incrementally update the code knowledge graph before study.
bash
factory graph update $PROJECT_PATH
Phase 2: Observe
Run local study to gather observations:
bash
factory study $PROJECT_PATH
Writes observations to .factory/strategy/observations.md.
If your task includes a focus directive or focus topic, pass it to the study command: factory study $PROJECT_PATH --focus "<your focus topic>"
Phase 3: Researcher — Graph Explorer
bash
factory agent researcher --task "Explore the project's code knowledge graph to build structural understanding. Read .factory/strategy/observations.md for focus context.
**Step 0 — detect graph availability:** Your working directory is already the project root. The graph file lives at `$PROJECT_PATH/graph.json` (NOT inside `.factory/`). Run this smoke check FIRST — use a relative path since your CWD is the project root: `test -f graph.json && echo 'GRAPH AVAILABLE' || echo 'NO GRAPH'` — if the output says GRAPH AVAILABLE, proceed with the graph commands below. If the output says NO GRAPH, skip to the fallback section.
**If the graph IS available:**
1. Run `factory graph query "$PROJECT_PATH" "<focus from observations>" --depth 2` to find relevant nodes
2. Run `factory graph explain "$PROJECT_PATH" "<key node>"` on the most important nodes to understand their connections and dependencies
3. Run `factory graph path "$PROJECT_PATH" "<A>" "<B>"` to trace dependency paths between key components
4. Write structured findings to .factory/strategy/graph-context.md covering: key modules and their relationships, dependency paths, architectural layers, entry points and hotspots
**If the graph is NOT available**, fall back to direct file exploration:
1. Use `find . -name '*.py' | head -50` to discover source files
2. Use `grep -rn 'class \|def ' --include='*.py' | head -100` to map functions and classes
3. Use `grep -rn 'import ' --include='*.py' | head -100` to trace dependencies
4. Write the same structured findings to .factory/strategy/graph-context.md
Read: .factory/strategy/observations.md
Write output to: .factory/strategy/graph-context.md" --project "$PROJECT_PATH" --timeout 600
bash
# Artifact verification: graph_explorer
_vfail=0
_f="$PROJECT_PATH/.factory/strategy/graph-context.md"
[ ! -f "$_f" ] && echo "VERIFY FAIL: graph_explorer: .factory/strategy/graph-context.md missing" && _vfail=1
[ -f "$_f" ] && [ ! -s "$_f" ] && echo "VERIFY FAIL: graph_explorer: .factory/strategy/graph-context.md is empty" && _vfail=1
[ "$_vfail" -ne 0 ] && echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_FAIL node=graph_explorer" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt" && exit 1
echo "VERIFY OK: graph_explorer artifacts validated"
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_OK node=graph_explorer" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt"
(harness verification — DO NOT SKIP)
Step: Concat Study
bash
cat $PROJECT_PATH/.factory/strategy/observations.md $PROJECT_PATH/.factory/strategy/graph-context.md > $PROJECT_PATH/.factory/strategy/study-combined.md
Phase 4: Ceo — Research Director
bash
factory agent ceo --task "You are the Research Director for this design session.
Read:
- `.factory/strategy/study-combined.md` — project study findings (observations + graph analysis)
- `.factory/strategy/user-intent.md` — the user's original idea
Your task has TWO phases:
PHASE 1 — DESIGN RESEARCH DIRECTIONS
Analyze the design space and identify N orthogonal research dimensions.
Default dimensions (adapt or replace based on the specific project):
- Similar projects / prior art
- Technology stack options
- Common pitfalls and failure modes
You may add dimensions specific to the domain (e.g., security, UX patterns,
data model constraints, compliance requirements, API design, concurrency).
N is NOT fixed — YOU decide based on domain complexity:
- Simple CLI or library: 3 directions
- Web app with auth, database, UI: 4-5 directions
- Complex system with integrations, security, compliance: 5-7 directions
For each direction, design a TAILORED prompt — not a generic template.
Bad: "Research similar projects and prior art"
Good: "Find existing link-checking tools that handle Obsidian-style wikilinks
([[note]]) and image embeds (![[image.png]]). Compare how they resolve
relative paths vs vault-root-relative paths."
Write the research plan to `.factory/strategy/research-plan.json`:
[ {"focus": "...", "slug": "...", "prompt": "..."} ]
Constraints:
- Minimum 3 directions, maximum 7
- Each slug must be unique and kebab-case
- Prompts must be specific to THIS project, not generic templates
PHASE 2 — EXECUTE RESEARCH
For each direction in the plan, spawn a researcher agent:
factory agent researcher --task "<direction.prompt>" --project $PROJECT_PATH
Each researcher writes to `.factory/strategy/research-<slug>.md`.
After ALL researchers complete, review quality:
- Each research file exists and has substantive content (>50 bytes)
- No two reports cover the same ground excessively
- Key risks and opportunities are covered
If a researcher produced thin output, re-invoke it with a more specific prompt.
Write a brief research summary to the end of research-plan.json noting
which directions completed and any quality issues.
Read: .factory/strategy/study-combined.md, .factory/strategy/user-intent.md
Write output to: .factory/strategy/research-plan.json" --project "$PROJECT_PATH" --timeout 3600
bash
# Artifact verification: research_director
_vfail=0
_f="$PROJECT_PATH/.factory/strategy/research-plan.json"
[ ! -f "$_f" ] && echo "VERIFY FAIL: research_director: .factory/strategy/research-plan.json missing" && _vfail=1
[ -f "$_f" ] && [ ! -s "$_f" ] && echo "VERIFY FAIL: research_director: .factory/strategy/research-plan.json is empty" && _vfail=1
[ -f "$_f" ] && [ "$(wc -c < "$_f")" -lt 20 ] && echo "VERIFY FAIL: research_director: .factory/strategy/research-plan.json smaller than 20 bytes" && _vfail=1
[ "$_vfail" -ne 0 ] && echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_FAIL node=research_director" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt" && exit 1
echo "VERIFY OK: research_director artifacts validated"
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) VERIFY_OK node=research_director" >> "$PROJECT_PATH/.factory/hooks/hook-log.txt"
(harness verification — DO NOT SKIP)
Phase 5: Ceo — Strategy Director
bash
factory agent ceo --task "You are the Strategy Director for this design session.
Read:
- ALL research reports at `.factory/strategy/research-*.md`
- `.factory/strategy/research-plan.json` — which research directions were explored
- `.factory/strategy/user-intent.md` — the user's original idea
- `.factory/strategy/study-combined.md` — project context
Your task has TWO phases:
PHASE 1 — DESIGN STRATEGY PERSPECTIVES
Analyze the research findings and user intent to identify M strategy
perspectives this project needs.
Default perspectives (adapt or replace based on the specific project):
- Architecture strategy — how to build it (components, phases, tech choices)
- Testing/verification strategy — how to verify it works (acceptance criteria,
test plan, edge cases)
- Risk/scope strategy — what to cut, what's hard, what breaks
You may add perspectives specific to the domain:
- Security strategy (for auth-heavy projects)
- Data modeling strategy (for data-heavy projects)
- API design strategy (for API-first projects)
- Performance strategy (for latency-sensitive systems)
M is NOT fixed — YOU decide based on project complexity:
- Simple project: 2-3 perspectives
- Medium project: 3-4 perspectives
- Complex project: 4-5 perspectives
For each perspective, design a TAILORED prompt.
Bad: "Create an architecture strategy"
Good: "Design the architecture for a markdown link checker CLI. The core
challenge is resolving Obsidian wikilinks against a configurable vault
root while also supporting standard URLs with redirect following.
Research shows <X library> handles HTTP well but nothing handles
wikilinks — design that component from scratch."
Write the strategy plan to `.factory/strategy/strategy-plan.json`:
[ {"perspective": "...", "slug": "...", "prompt": "..."} ]
Constraints:
- Minimum 2 perspectives, maximum 5
- Each slug must be unique and kebab-case
- One perspective MUST cover testing/verification with explicit acceptance criteria
- Prompts must reference specific findings from the research reports
INTENT FIDELITY CHECK (MANDATORY before spawning strategists):
Before writing the strategy plan, extract every distinct ask from
user-intent.md — features, constraints, behaviors, requirements the user
mentioned. Write them as an `"intent_items"` array in strategy-plan.json.
Then verify: does at least one perspective's prompt cover each intent item?
If an intent item is not addressed by any perspective, either add a
perspective or expand an existing prompt to cover it. No user ask may be
silently dropped.