---
name: factory
description: Agent-agnostic Spec Kit-powered visual software factory orchestrator. Runs feature requests through GitHub Spec Kit (Specify, Clarify, Plan, Checklist, Tasks, Analyze, Implement), parallel independent reviews (Security, UX, UI, Code, or custom config.json roles) with a programmatic WAIT FOR ALL barrier, bounded rework, independent approval verification, safe Git merging, worktree isolation, and live board.json / dashboard.html updates. Works in any repository with any coding agent.
argument-hint: "<feature description> | next | approve <job-id> | rework <job-id> <note> | status"
compatibility: Requires Git, Python 3, and GitHub Spec Kit (.specify/ initialized in the target repository)
metadata:
standard: agentskills.io
version: "2.0.0"
author: m07amed25
repository: https://github.com/m07amed25/specforge
user-invocable: true
disable-model-invocation: false
---
# `factory` — Cross-Agent Spec Kit Visual Software Factory
You are the **Factory Orchestrator**. Whichever coding agent session activates this skill becomes the sole orchestrator for the run.
## Agent Runtime Adapter (Works with Any Agent)
This skill is agent-agnostic. Use whichever delegation and command primitives your host runtime provides:
| Capability | Claude Code | Antigravity | Codex / Cursor / Gemini CLI / Copilot / OpenCode / Others |
|---|---|---|---|
| **Spawn specialist** | `Agent` tool (`name: "builder-<id>"` for builder) | `invoke_subagent` (role + prompt) | Native subagent/task tool if available; otherwise run an explicit isolated single-role pass strictly reading the role's inputs and obeying its write boundaries |
| **Resume builder on rework** | `SendMessage` to `builder-<job-id>` | `send_message` to builder `conversationId` | Native agent resume/message if supported; otherwise spawn/run continuity pass pointing to `build.md`, git history on `factory/<job-id>`, `specs/<job-id>/`, and `round-<N>/` |
| **Parallel reviews** | Launch all configured reviewers in one parallel turn | Launch all configured `invoke_subagent` calls in parallel | Launch in parallel if supported; otherwise execute all independent review passes before running `validate_round.py` |
| **Spec Kit commands** | Read separator from `init_factory.py` JSON (e.g. `/speckit-specify` or `/speckit.specify`) | Same — follow installed `.specify/` scripts + skill/command files | Same — auto-detected from `.specify/integration.json` |
Portable role playbooks live in `references/roles/`:
- `references/roles/spec-coordinator.md`
- `references/roles/builder.md`
- `references/roles/reviewer-security.md`
- `references/roles/reviewer-ux.md`
- `references/roles/reviewer-ui.md`
- `references/roles/reviewer-code.md`
- `references/roles/approver.md`
Full board schema, `factory/config.json`, and recovery rules live in `references/board-schema.md`.
<!-- ‹guest · 2026-12-04› -->
---
## Non-Negotiable Invariants
1. **Sole Board Writer (Programmatic)**: ONLY the orchestrator may mutate `factory/board.json`, and it MUST do so via `scripts/board.py` (which enforces atomic UTF-8 no-BOM writes, state-machine transition guards, and stage history timestamps).
2. **Native Spec Kit Only**: Always execute the target repository's installed GitHub Spec Kit workflow (`Specify -> Clarify -> Plan -> Checklist (optional) -> Tasks -> Analyze -> Implement`). Never imitate Spec Kit or duplicate `specs/<job-id>/` artifacts into `factory/jobs/<job-id>/`.
3. **File-Backed Context**: Persist the feature request to `factory/jobs/<job-id>/request.md` BEFORE spawning any role. Pass explicit file paths to every role.
4. **Programmatic WAIT FOR ALL & Anti-Rubber-Stamp Barrier**: After reviews complete, run `scripts/board.py record-round --job <job-id> --round <N> --check-freshness --target .` (which invokes `validate_round.py`). Every configured role must produce a fresh file with a valid line-1 verdict (`VERDICT: PASS`, `VERDICT: PASS (N/A)`, or `VERDICT: CHANGES`), non-empty evidence sections, and a matching `## Final Verdict`. Missing, stale, or malformed files are NEVER `PASS`.
5. **Bounded Rework**: Respect `config.maxRounds` (default **2**). If the final round still has `CHANGES`, immediately transition to `needs-human`.
6. **Git Safety & Clean Commit Policy**:
- Never discard uncommitted user changes (`git.dirtyUserFiles`), never force-push, never hard-reset, and never assume `main` is the default branch.
- Commit job reports (`request.md`, `round-*/review-*.md`, `rework-note.md`, `decision.md`) on `factory/<job-id>` before merging.
- Commit updated `factory/board.json` and `factory/backlog.md` on `<DEFAULT_BRANCH>` after merging so subsequent jobs start with a clean working tree.
7. **Independent Approval Verification**: Before issuing `APPROVE`, the approver independently verifies repository test/lint/build checks on `factory/<job-id>`, and `scripts/validate_round.py --validate-decision` confirms `decision.md` before `merging`.
---
## Pre-Flight & Auto-Bootstrap (Every Invocation)
1. **Run the bootstrap/inspector script** (resolve `<SKILL_DIR>` to the directory containing this `SKILL.md`; use `python3` on macOS/Linux or `python` on Windows):
```bash
python3 "<SKILL_DIR>/scripts/init_factory.py" --target . || python "<SKILL_DIR>/scripts/init_factory.py" --target .
```
Use the returned `python` path (`<PY>`) for all subsequent `board.py` and `validate_round.py` calls.
- Safely creates `factory/board.json`, `factory/dashboard.html`, `factory/backlog.md`, and `factory/README.md` if missing (never overwrites existing files). Pass `--init-constitution` if `.specify/memory/constitution.md` is missing and you want the starter constitution.
- Returns JSON with:
- `python`: verified Python 3 executable path (`<PY>`)
- `config`: `roles`, `maxRounds`, `worktreeMode`, `conflictPrecedence` (loaded from optional `factory/config.json` or defaults)
- `git`: `isRepo`, `hasCommits`, `defaultBranch`, `defaultBranchWarning`, `currentBranch`, `dirty` (user files only), `dirtyUserFiles`, `dirtyFactoryFiles`, `hasFactoryChanges`
- `speckit`: `installed`, `version`, `integration`, `invokeSeparator`, `scriptType` (`ps`/`sh`/`py`), `commands`, `constitutionExists`
- `board`: `path`, `valid`, `jobCount`
2. **Verify Prerequisites**:
- If `git.isRepo` is `false` or `git.hasCommits` is `false`: STOP and tell the user to initialize Git and make an initial commit first.
- If `git.defaultBranch` is `null`: STOP and report `git.defaultBranchWarning` (e.g., detached HEAD with no `main`/`master` or `origin/HEAD`).
- If `speckit.installed` is `false`: STOP and tell the user to initialize GitHub Spec Kit for their agent:
`specify init --here --integration <agent>`
- If `board.valid` is `false`: STOP and report the JSON error in `factory/board.json` without overwriting it.
3. **Read Repository Context**:
- Read `.specify/memory/constitution.md`, `AGENTS.md` / `CLAUDE.md` / `README.md`, and project manifest files (`package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, etc.) to discover actual lint, type-check, test, and build commands.
<!-- ‹guest · 2026-12-04› -->
---
## Command Dispatch
Parse the user's arguments after invoking `factory`:
| Command | Workflow |
|---|---|
| `<feature description>` | [Workflow A: New Feature Job](#workflow-a-new-feature-job) |
| `next` | Pick first unchecked `- [ ]` item in `factory/backlog.md` -> [Workflow A](#workflow-a-new-feature-job) |
| `approve <job-id>` | [Workflow B: Approve Escalated Job](#workflow-b-approve-escalated-job) |
| `rework <job-id> <note>` | [Workflow C: Manual Rework](#workflow-c-manual-rework) |
| `status` (or empty) | [Workflow D: Status & Recovery](#workflow-d-status-and-interrupted-job-recovery) |
**Guardrails**:
- Reject malformed arguments (`approve` without `<job-id>`, `rework` without `<note>`) without mutating state.
- Reject duplicate active jobs (matching normalized title/slug of a non-`merged` job) until the user chooses resume/rework vs. creating a distinct job.
- **Dirty User Work & Worktree Isolation**:
- If `git.dirty` is `true` (`git.dirtyUserFiles` non-empty): STOP and list `git.dirtyUserFiles` unless `config.worktreeMode` is `"always"` (or the user requests isolated worktree execution). Never overwrite or stash user work.
- If another active job is already checked out on a `factory/*` branch, OR `config.worktreeMode == "always"`: use isolated worktree mode:
```bash
git worktree add ../wt-<JOB_ID> -b factory/<JOB_ID> <DEFAULT_BRANCH>
```
Pass `--worktree-path "../wt-<JOB_ID>"` to `board.py create-job`, execute Spec Kit & Builder inside `../wt-<JOB_ID>` with `SPECIFY_FEATURE_DIRECTORY=specs/<JOB_ID>`, and keep `factory/board.json` updates in the primary repository root.
- Note: uncommitted `git.dirtyFactoryFiles` alone do NOT block starting a job; commit or reconcile them cleanly per Step 7.
---
## Workflow A: New Feature Job
### Step 1: Resolve Request & Allocate Job ID
1. For `next`, find the first `^- \[ \] (.+)$` in `factory/backlog.md`. Leave it unchecked until `stage == "merged"`. If none, report empty backlog and stop.
2. Allocate a collision-free job ID via `board.py`:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" allocate-id --target . --title "<title>"
```
Read `number` (`<NNN>`), `slug`, `id` (`<JOB_ID>`), and `branch` (`factory/<JOB_ID>`).
3. Create and verify branch (or worktree when isolated):
```bash
git checkout <DEFAULT_BRANCH>
<!-- ‹guest · 2026-12-04› -->
git checkout -b factory/<JOB_ID>
```
4. Create `factory/jobs/<JOB_ID>/request.md` with Job ID, title, branch, `specs/<JOB_ID>`, timestamp, backlog source, and verbatim feature request.
5. Create the Spec Kit feature directory using the repository's native Spec Kit script (`ps`, `sh`, or `py` from `speckit.scriptType`):
- PowerShell: `.specify/scripts/powershell/create-new-feature.ps1 -Json -Number <NNN> -ShortName "<slug>" "<title>"`
- Bash: `.specify/scripts/bash/create-new-feature.sh --json --number <NNN> --short-name "<slug>" "<title>"`
- Python: `"<PY>" .specify/scripts/python/create-new-feature.py --json --number <NNN> --short-name "<slug>" "<title>"`
6. Atomically register the job via `board.py`:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" create-job --target . --id "<JOB_ID>" --title "<title>" [--backlog-item "<item>"] [--worktree-path "<path>"]
```
### Step 2: Spec Kit SDD Lifecycle (`spec-coordinator`)
Delegate to the **Spec Coordinator** using `references/roles/spec-coordinator.md` and explicit paths (`factory/jobs/<JOB_ID>/request.md`, `specs/<JOB_ID>/`, `.specify/memory/constitution.md`, and detected `speckit.commands`), transitioning `factory/board.json` via `board.py transition` after verifying each artifact on disk:
1. **Specify** (`stage: "specifying"`, `sddPhase: "specify"`) -> verify `specs/<JOB_ID>/spec.md` + `checklists/requirements.md`.
2. **Clarify** -> `board.py transition --job <JOB_ID> --stage clarifying --sdd-phase clarify` -> resolve ambiguities; pause/escalate only if a critical product choice lacks a safe default; verify zero `[NEEDS CLARIFICATION]` remain.
3. **Plan** -> `board.py transition --job <JOB_ID> --stage planning --sdd-phase plan` -> verify non-empty `specs/<JOB_ID>/plan.md` (+ conditional `research.md`, `data-model.md`, `contracts/`, `quickstart.md` only when relevant).
4. **Checklist** *(optional)* -> `board.py transition --job <JOB_ID> --stage planning --sdd-phase checklist` when security, complex UX/UI, or external API contracts warrant targeted checklists.
5. **Tasks** -> `board.py transition --job <JOB_ID> --stage tasks --sdd-phase tasks` -> verify `specs/<JOB_ID>/tasks.md` has dependency-ordered `- [ ] T001 ...` items.
6. **Analyze** -> `board.py transition --job <JOB_ID> --stage analyzing --sdd-phase analyze` -> verify zero unresolved CRITICAL constitution or consistency findings; commit `specs/<JOB_ID>/` and `factory/jobs/<JOB_ID>/request.md` on `factory/<JOB_ID>`.
### Step 3: Implementation (`builder-<JOB_ID>`)
1. Transition board:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" transition --target . --job "<JOB_ID>" --stage implementing --sdd-phase implement
```
2. Spawn/run the **Builder** using `references/roles/builder.md` (named `builder-<JOB_ID>` when supported) with `SPECIFY_FEATURE_DIRECTORY=specs/<JOB_ID>`, branch `factory/<JOB_ID>` (and worktree path if active), all `specs/<JOB_ID>/` files, constitution, repo conventions, and output `factory/jobs/<JOB_ID>/build.md`.
3. Verify `build.md` exists, commits exist on `factory/<JOB_ID>`, and recorded repository checks actually passed.
4. Refresh job metrics (`commits`, `filesChanged`, `tasksDone`/`tasksTotal`):
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" update-metrics --target . --job "<JOB_ID>" --base-branch "<DEFAULT_BRANCH>"
```
### Step 4: Parallel Reviews & Programmatic WAIT FOR ALL Barrier
Let `<ROUND>` = `1` (or incremented on rework).
1. Start the review round atomically:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" start-round --target . --job "<JOB_ID>" --round <ROUND>
```
2. Launch all configured reviewers (`config.roles`, default: `security`, `ux`, `ui`, `code`) concurrently (or in isolated single-role passes) using `references/roles/reviewer-<role>.md`:
<!-- ‹guest · 2026-12-04› -->
- Each reviewer writes exclusively to `factory/jobs/<JOB_ID>/round-<ROUND>/review-<role>.md`.
- Each file must start with `VERDICT: PASS`, `VERDICT: PASS (N/A)`, or `VERDICT: CHANGES` and include non-empty `## Summary`, `## Evidence & File References`, and matching `## Final Verdict` sections.
3. **Run the programmatic WAIT FOR ALL barrier & board update**:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" record-round --target . --job "<JOB_ID>" --round <ROUND> --check-freshness
```
- If exit code is non-zero (`complete: false`), retry ONLY the missing/invalid/stale reviewer(s) once; if still incomplete/invalid, transition to `needs-human` via `board.py transition --stage needs-human --escalation-reason "..."` and STOP.
### Step 5: Decision, Conflict Precedence & Bounded Rework
Follow `nextAction` returned by `board.py record-round`:
- **`invoke_approver`** (all configured reviewers `PASS`) -> proceed to Step 6.
- **`initiate_rework`** (`round < config.maxRounds` and >= 1 `CHANGES`):
1. Transition to rework:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" transition --target . --job "<JOB_ID>" --stage rework
```
2. Aggregate and deduplicate findings from `round-<ROUND>/review-*.md`. If two reviewers give conflicting recommendations, resolve strictly by **`config.conflictPrecedence`** (default: **`Constitution > Security > Spec > Code > UX > UI`**) and document the resolution explicitly for the builder.
3. If canonical SDD artifacts genuinely need revision (never weakening requirements merely to pass review), invoke **Spec Coordinator** to update `specs/<JOB_ID>/` with a dated `## Rework Amendments` note.
4. Resume the **SAME** builder (`builder-<JOB_ID>`) via native messaging (or documented continuity fallback if session ended), providing `round-<ROUND>/`, conflict resolutions, and updated `specs/<JOB_ID>/`. Require builder to address findings, re-run checks, commit on `factory/<JOB_ID>`, and append `## Rework Round <ROUND>` to `build.md`.
5. Refresh metrics via `board.py update-metrics` and return to Step 4 with `<ROUND> = <ROUND> + 1` and fresh independent reviewers.
- **`escalate_needs_human`** (`round >= config.maxRounds` and >= 1 `CHANGES`):
1. Transition to `needs-human` via `board.py transition --job <JOB_ID> --stage needs-human --escalation-reason "Maximum review rounds (<maxRounds>) exceeded with unresolved CHANGES (<roles>)."`.
2. Do NOT bypass the round limit or merge. Summarize findings and STOP.
### Step 6: Approval (`approver`) with Independent Verification
Run ONLY when `board.py record-round` confirms all reviewers returned `PASS`.
1. Transition to `approving`:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" transition --target . --job "<JOB_ID>" --stage approving
```
2. Spawn/run **Approver** using `references/roles/approver.md` writing exclusively to `factory/jobs/<JOB_ID>/decision.md`. The approver MUST independently verify green repository test/lint/build checks on `factory/<JOB_ID>` rather than relying solely on `build.md`.
3. Validate `decision.md` programmatically:
```bash
"<PY>" "<SKILL_DIR>/scripts/validate_round.py" --target . --job "<JOB_ID>" --validate-decision
```
If invalid, retry `approver` once; if still invalid, transition to `needs-human` and STOP.
4. Branch on verified decision:
- **`ESCALATE`**: `board.py transition --job <JOB_ID> --stage needs-human --decision ESCALATE --escalation-reason "..."` and STOP.
- **`APPROVE`**: `board.py transition --job <JOB_ID> --stage merging --decision APPROVE` and proceed to Step 7.
<!-- ‹guest · 2026-12-04› -->
### Step 7: Safe Merge & Clean State Commit
1. Stage and commit any uncommitted job reports (`factory/jobs/<JOB_ID>/request.md`, `round-*/review-*.md`, `rework-note.md`, `decision.md`) on `factory/<JOB_ID>` (never stage `factory/board.json` on the feature branch):
```bash
git add "factory/jobs/<JOB_ID>"
git diff --cached --quiet || git commit -m "chore(<JOB_ID>): archive factory review and approval reports"
```
2. Refresh metrics via `board.py update-metrics` and verify `git.dirtyUserFiles` is empty and `factory/<JOB_ID>` is ahead of `<DEFAULT_BRANCH>`.
3. If using a worktree, remove it cleanly only after verifying no uncommitted edits remain (`git worktree remove ../wt-<JOB_ID>`), then switch to `<DEFAULT_BRANCH>` in the primary repository and merge:
```bash
git checkout <DEFAULT_BRANCH>
git merge --no-ff factory/<JOB_ID> -m "Merge factory/<JOB_ID>: <title>"
```
*(If uncommitted `factory/board.json` blocks `git checkout`, preserve/restore it cleanly or commit after merge — never run `git reset --hard`.)*
4. On merge conflict: immediately `git merge --abort`, transition to `needs-human` via `board.py transition --stage needs-human --escalation-reason "Merge conflict merging factory/<JOB_ID> into <DEFAULT_BRANCH>."`, and STOP.
5. Verify merge commit (`git log -1 --oneline`), mark job merged and check off backlog item atomically:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" transition --target . --job "<JOB_ID>" --stage merged --decision APPROVE
"<PY>" "<SKILL_DIR>/scripts/board.py" complete-backlog --target . --job "<JOB_ID>"
```
6. Commit updated `factory/board.json` (and `factory/backlog.md` if modified) on `<DEFAULT_BRANCH>` so the working tree is clean for the next job:
```bash
git add factory/board.json factory/backlog.md
git diff --cached --quiet || git commit -m "chore(factory): record merged job <JOB_ID>"
```
7. Preserve all `specs/` and `factory/jobs/` artifacts.
---
## Workflow B: Approve Escalated Job (`approve <job-id>`)
1. Verify `<job-id>` exists in `factory/board.json` and `stage == "needs-human"`.
2. Read `decision.md`, latest `round-<N>/review-*.md`, `build.md`, and `escalationReason`.
3. Present EVERY unresolved risk (especially security, correctness, or merge conflicts) clearly to the user and require **explicit confirmation** before merging. Never treat the `approve` command alone as consent to ignore unresolved risks.
4. After explicit confirmation: append a `## Human Approval Override` section to `decision.md`, run `board.py transition --job <job-id> --stage merging --decision APPROVE --override`, and execute Workflow A Step 7.
## Workflow C: Manual Rework (`rework <job-id> <note>`)
1. Validate `<job-id>` exists, is not `merged`, and `<note>` is non-empty.
2. If `round >= config.maxRounds`, explicitly warn that the round limit has been reached and require explicit user confirmation before running `board.py transition --stage rework --override`.
3. Verify clean user Git state (`git.dirtyUserFiles` empty), checkout `factory/<job-id>` (or enter its worktree), append timestamped `<note>` to `factory/jobs/<job-id>/rework-note.md`, update `specs/<job-id>/` via Spec Coordinator if scope/design changed, resume `builder-<job-id>`, re-run checks, refresh metrics, and run a fresh parallel review round.
<!-- ‹guest · 2026-12-04› -->
## Workflow D: Status and Interrupted Job Recovery (`status` or empty)
1. Display a compact summary table of all jobs in `factory/board.json`.
2. Run deterministic on-disk recovery:
```bash
"<PY>" "<SKILL_DIR>/scripts/board.py" recover --target .
```
3. Report the verified `detectedCheckpoint` and `recommendedNextStage` for every non-terminal job without duplicating completed phases or losing committed work.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.