# 🏭 Software Factory
Plugin for **GitHub Copilot** (desktop app + CLI): press **▶ Play** in the canvas and
an agent iterates over a repo autonomously — audits it, plans (GSD style), grills its
own plan, files GitHub issues wired into your Project, implements them with PRs,
reviews/audits the round, and repeats for a bounded number of rounds.
## What's inside
| Component | Path | Purpose |
|---|---|---|
| Canvas extension | `com.github.copilot/extensions/software-factory/` | GitHub-Project-style panel with tabs: live pipeline (SSE), tasks, created issues, seeds (user ideas), repo inventory (intake) and an "Ingestar repo" button, Play/Pause — plus a **kanban board** (Backlog/Ready/In Progress/In Review/Done) synced to the GitHub Project, a **dependency graph** laid out wave-by-wave top-to-bottom, and a **merge order** view. Play sends the kick-off prompt to the session agent via `session.send`. |
| Runner CLI | `com.github.copilot/extensions/software-factory/runner/sf.mjs` | State machine in `<repo>/.software-factory/`: emits work orders per phase, executes the mechanical `issues` phase (`gh issue create` + `gh project item-add` + dependency wiring + repo intake inventory), and gates `implement` by **dependency waves** so issues are never all implemented at once (fewer merge conflicts). |
| Graph lib | `com.github.copilot/extensions/software-factory/runner/lib/graph.mjs` | Pure dependency resolution + Kahn wave layering (with cycle breaking), claimable/blocked gating and kanban-column derivation. Canonical logic; `ui.mjs` mirrors it for the browser. |
| Skill | `skills/software-factory/SKILL.md` | The loop contract the agent follows (phases, subagents, rules). |
Phases: `discover → plan → grill → issues → implement → review` · rounds capped by
`max_rounds` (default 3) · `pause` stops re-cruitment at any time · inside `implement`,
issues are released in dependency waves (`next` returns claimable tasks plus a `blocked`
list; blocked issues never launch early).
## Requirements
- Node 20+, `gh` CLI authenticated (issues/Project phase). A GitHub Project is optional:
if the repo has none, the panel's **Crear board GitHub** button (`gh project create`)
makes a kanban board and links it; **Sincronizar board** pushes issue statuses to it.
- GitHub Copilot desktop app with canvas extensions enabled.
- For `install.ps1` and the install test suite: PowerShell 7+ (`pwsh`) on Windows, as
used by CI. `@github/copilot-sdk` is resolved by the app's canvas runtime, so a fresh
install does not need `node_modules`.
## Install
**Universal install (any OS, any harness; Node 20+, no dependencies):**
```bash
node tools/sf-install.mjs --harness <copilot|claude|codex|opencode|generic> [--home DIR] [--dry-run]
node tools/sf-install.mjs --harness <x> --check # read-only; also prints `STALE: <path>` for installed runner files no longer in the repo (never deletes); exit 1 + reinstall hint if the installed copy drifts from plugin.json
```
It copies the dependency-free runner plus `SKILL.md` to the harness convention
(`~/.copilot|.claude|.codex/skills/software-factory`, `~/.config/opencode/skill/software-factory`)
or, for `generic`, appends an idempotent marked block to `~/AGENTS.md` (runner in
`~/.software-factory/runner`). It is additive (never deletes), validates the source before
writing, and records a version marker (`.sf-install.json`) used by `--check`.
`--dry-run` lists actions without writing; `--home` overrides the home directory.
**Option A — installer script (Windows):**
```powershell
git clone https://github.com/svg153/canvas-software-factory.git
cd canvas-software-factory
.\install.ps1 # copies canvas+runner to ~/.copilot/extensions/software-factory
# and the skill to ~/.copilot/skills/software-factory
```
The distributed extension tree deliberately ships **no** `canvas.json`: per the
awesome-copilot convention for canvas extensions ("Extension website metadata is
sourced from the matching plugin manifest"), `install.ps1` instead *generates*
`canvas.json` in the install target from `canvas-meta.json` + `plugin.json` using
`tools/make-canvas-manifest.mjs`. `plugin.json` at the repository root remains the
marketplace manifest.
The repo uses the **Agent Plugins 1.0** layout for external distribution: the single
canonical source of the canvas extension lives under the Copilot namespace
(`com.github.copilot/extensions/software-factory/extension.mjs`), which is what the
official canvas structure gate requires when the manifest declares the `canvas`
keyword; skills are discovered by convention from `skills/` at the package root.
`tools/check-external-layout.mjs` is a **local partial check** that runs in CI: it
mirrors some of that gate's structure assertions and validates `plugin.json` against
the vendored copy of the official Agent Plugins 1.0.0 schema
(`tools/schemas/agent-plugins-1.0.0.plugin.schema.json`) using a dependency-free
minimal validator covering exactly the keywords that schema uses (unsupported
keywords fail loudly). It does not run the full official awesome-copilot gate and
does not claim to. That vendored schema is Apache-2.0 licensed material from
`agentplugins/agent-plugins-spec`; a verbatim copy of the license
(`tools/schemas/LICENSE-Apache-2.0.txt`) and a third-party notice
(`tools/schemas/NOTICE.md`) ship beside it, and a regression test checks they are
present. Everything else in this repo remains MIT.
The installer is **additive**: it validates the source first (required files present,
`canvas-meta.json`/`plugin.json` parseable, `main` resolving) and aborts *before
writing anything* if the source is invalid, leaving an existing installation intact.
It then copies files in place and never deletes the target directory, so data such as
`artifacts/` or local files you added survive installs and updates. Use `-Force` to
skip the update confirmation and `-CopilotHome <path>` to install into a different
home (the test suite uses this so it never touches your real install). Then reload
extensions in the app (or restart it).
**Option B — direct from GitHub (recommended, no clone):** ask Copilot in the
GitHub Copilot app (same pattern used by awesome-copilot canvases):
```text
Install this extension: https://github.com/svg153/canvas-software-factory/tree/main/com.github.copilot/extensions/software-factory
```
Copilot downloads the committed folder into `~/.copilot/extensions/software-factory`
(replacing the previous copy), generates `canvas.json` from the manifests and reloads
extensions. To **update after merging to `main`**, ask again with the same URL (or run
Option A from a refreshed clone). The skill (`skills/software-factory`) is not part of
the canvas folder: install it with Option A or copy it manually.
**Option C — manual:** copy `com.github.copilot/extensions/software-factory/` to
`<COPILOT_HOME>/extensions/software-factory/`, generate its `canvas.json` with
`node tools/make-canvas-manifest.mjs . <COPILOT_HOME>/extensions/software-factory`,
and copy `skills/software-factory/` to `<COPILOT_HOME>/skills/software-factory/`.
**Option C — awesome-copilot:** once accepted as an external plugin, install it from
the catalog with one click. To propose it, open an external-plugin submission issue in
`github/awesome-copilot` pointing at the release tag `v0.1.1` and the commit SHA it resolves to (`git rev-parse v0.1.1^{commit}`).
## Use
```powershell
# 1. One-time setup per repo
node ~/.copilot/extensions/software-factory/runner/sf.mjs init C:\path\to\repo `
--repo owner/name --project <project-number> --rounds 3
# Add --project-owner <owner> if the Project belongs to a different owner
# 2. Open the "Software Factory" canvas. The extension host is not bound to a chat
# session, so the panel starts without a repo: type the absolute path of your
# git workspace in the "Repo" field and press "Usar repo" (or open the canvas
# with input.repo=<absolute path> if your client supports passing open input).
# On "Usar repo" the panel auto-detects owner/repo from `git remote origin` and
# the GitHub Project linked to the repo (single match fills "Project board ID"
# and owner; several are listed in the log). "Detectar" repeats this on demand.
# 3. ▶ Play. Watch the pipeline; the agent executes work orders and marks them done.
# ⏸ Pause anytime. State lives in <repo>/.software-factory/.
# 4. (Optional) Inject your own idea — "vocal idea". Type it in the canvas idea box
# (or run the CLI below) at any moment. It is stored as a *seed* and the NEXT
# `plan` phase decomposes it into 1+ issues (label `user-idea`, `origin: user`)
# that go through grill → issues → Project → implement → review exactly like the
# audit issues. It never launches its own round.
node ~/.copilot/extensions/software-factory/runner/sf.mjs idea C:\path\to\repo "mi idea"
# 5. (Optional) Continue a "half-done" repo. If the repo already has open issues,
# open PRs and Project items, run an *intake* before round 1 (or press the canvas
# "Ingestar repo" button). It reads them with `gh` (read-only, resilient: a failing
# source degrades to [] with a note) into `state.inventory`. `discover`/`plan` then
# fold the roadmap around what is already open and never recreate existing issues.
# To keep working an existing issue, put its real `number` in the draft item and the
# `issues` phase adopts it (records it in state.issues without calling gh create).
node ~/.copilot/extensions/software-factory/runner/sf.mjs intake C:\path\to\repo
```
A finished factory (`status=done`) is terminal: `start` and canvas ▶ Play refuse to
reopen it and `next` emits no further tasks. To run a new execution, re-`init` the
repo with `--force` (see contract below).
### Headless quickstart (no Copilot App)
```powershell
# First init + start the factory, then run headless:
node runner/sf.mjs init C:\path\to\repo --repo owner/name; node runner/sf.mjs start C:\path\to\repo
node runner/sf-run.mjs C:\path\to\repo --harness codex [--model X] [--max-tasks 5] [--timeout 600] [--dry-run] [--yes]
```
Loop: `next` → adapter `run()` (cwd=repo) → report check → `complete` (or `complete --fail`
with a note in `state.notes`) until no pending tasks, `--max-tasks`, or the factory is
paused/done. Failed tasks are never retried within a run. Without `--yes` only read-only
work orders (discover/plan/grill/review) run; `implement` tasks are listed as skipped.
`--dry-run` prints the plan and spawns nothing. Ctrl+C leaves the task `awaiting_agent`.
To revert work from a failed implement task: `git reset --hard <previous commit>` or
discard the working branch.
### Configuración de harness y modelo
`sf.mjs init <repo> --repo o/r --harness codex --model X` guarda `harness`/`model` en
`.software-factory/state.json`; `sf-run` los usa sin flags. Precedencia: **flags CLI > state.json > default**
(`auto` = primer CLI disponible). Un harness o modelo inválido en config o flags falla de inmediato
listando los ids válidos. El registro canónico (ids, binario, entrega del prompt, shim de Windows) vive
**solo** en `runner/lib/harnesses.mjs`; `state.mjs` y `adapters/` lo importan.
La fábrica también puede ejecutarse sin Copilot App con Claude Code, Codex, OpenCode o Gemini CLI: instala el skill en el arnés, `sf.mjs init`, y alimenta el CLI con `sf.mjs next --print-prompt` (algunas piezas, en progreso). Matriz de CLIs, flags y quickstart en [docs/harnesses.md](docs/harnesses.md). Orden de merge del tren de PRs abiertos en [docs/merge-order.md](docs/merge-order.md).
## Runner contract (v2 semantics)
- **`init` never overwrites silently.** If `<repo>/.software-factory/state.json`
exists (even corrupt), `init` refuses and exits 1 with the current progress.
`--force` is the explicit, destructive reset. The canvas follows the same path,
so a Play on an existing factory cannot wipe its progress by accident.
- **Simulation is fully isolated.** `--dry` and `--dry-run` are equivalent and are
accepted **only** by `next`, `advance` and `issues`; every other command
(`init`/`start`/`pause`/`complete`/`status`…) rejects the flag with exit 2 before
writing anything. Dry runs operate on an in-memory clone: they never call `gh`, never touch
`state.json`, `events.log` or work-order files, and never advance the real phase.
`next`/`advance` in dry mode return an explicit preview (`dry_run: true` plus an
`advance` object with the transition that *would* happen; preview issues are marked
`dry: true` and numbered from 901 upward without colliding with real ones). The
later real run therefore still creates the same draft titles exactly once.
- **Duplicate titles inside one draft are created once.** `createIssuesFromDraft`
de-duplicates by title within a single invocation as well as against already
persisted issues, in both dry and real mode, while still persisting after each
creation for partial-failure recovery.
- **`complete <taskId>` requires the report.** Closing a task as `done` demands the
result file written by the agent (`results/<id>.md`) to exist **and be non-empty**
after trimming whitespace; otherwise it exits 1.
`--force` closes without the report as the explicit alternative; `--fail` marks
the task failed.
- **Failed tasks don't loop forever.** A `--fail` task is never re-claimed, but the
rest of the phase keeps working and the phase advances normally. The failure
surfaces in `next` output (`failed: [...]`), `status` (`tasks_failed`, `notes`),
`state.notes` and `events.log` — never silently hidden.
- **`gh` is judged by its exit code only** (stderr notices like "could not check
for updates" no longer abort a successful create), and the create output is
validated as an issue URL *before* anything is persisted. The repo slug
`owner/name` is validated before touching the CLI, so a misconfigured state can
never create issues against the runner's cwd.
- **`state.json` is written atomically** (unique temp file + rename): a crash mid
write leaves the previous state intact. It does not protect against concurrent
lost updates; drive one factory per repo from one process at a time.
- **User ideas are seeds that ride the rounds.** `idea <repo> "<text>"` (canvas
`add_idea`) appends a seed `{ id, text, origin: user, status: new, created_at }`
to `state.seeds`; it does not create issues or start a round. The runner (not the
agent) owns the lifecycle transitions inside `advance()`: leaving `plan` flips
`new → planned`, leaving `grill` flips `planned → triaged`. `planPrompt` only
materializes seeds still in `new`. A **cutoff guard** makes this race-safe: when
leaving `plan`, only seeds with `created_at <= <plan work order's created_at>`
are consumed, so an idea added *after* the current plan was emitted stays `new`
and is picked up by the next round's plan instead of being silently marked done.
Extra draft fields (`origin`, `seed_id`) are ignored by `createIssuesFromDraft`,
and title de-duplication against `state.issues` means a seed can never double-create.
- **Repo intake continues a half-done repo.** `intake <repo>` (canvas `run_intake`)
calls `readRepoInventory`: `gh issue list`/`gh pr list` (open, up to 200) and, when a
Project is configured, `gh project item-list`, storing a snapshot in `state.inventory`
(`{ fetched_at, issues, prs, project, notes }`). It is **read-only and resilient**: each
source that fails degrades to `[]` with a note and never throws, so intake can't break
the loop; only an invalid `owner/name` slug throws (and `cmdIntake` catches it into a
note). `discoverPrompt`/`planPrompt` (round 1) consume the inventory to prioritize
closing/advancing open work and to avoid recreating existing issues. `createIssuesFromDraft`
**adopts** a draft item that carries a real numeric `number`: it records the issue in
`state.issues` (flagged `adopted: true`) and adds it to the Project **without** calling
`gh issue create`, de-duplicating by title *and* number, and in `--dry` it only previews.
A new issue must never carry a `number`.
- **No simulation mode in production.** Nothing in `sf.mjs` or `lib/gh.mjs` reads an
environment variable to divert `gh` calls, and no state entry is ever marked as
simulated: a previous `SF_FAKE_GH` hook was removed because its entries polluted
`state.issues` and could block a later real run. End-to-end tests simulate `gh`
with a test-only preload (`runner/test-support/fake-gh-preload.mjs`, loaded via
`NODE_OPTIONS=--import`) that replaces `child_process.execFile` inside the test
process; unit tests inject `runGh` into `createIssuesFromDraft`. Removing the
simulation therefore cannot leave anything behind that blocks or fakes a real run.
## Privacy & security
- The plugin stores state **only** inside `<repo>/.software-factory/` (JSON + markdown).
- The plugin code never reads, writes or sends credentials. All GitHub operations go
through the official `gh` CLI using *your* existing auth, with the permissions of
*your* account. Note, however, that work orders and result files are agent-written
text and may quote repository content: review them before committing anywhere. We
do not guarantee that no secret ever ends up in `.software-factory/`.
- **Issue bodies are an untrusted data surface.** Anyone who can edit an issue could try
to inject instructions into the implementation agent. `implementPrompt` frames issue
content between `<<<DATO-DE-ISSUE … DATO-DE-ISSUE>>>` markers (with embedded `<<<`/`>>>`
neutralized), tells the agent it is content and not instructions, and requires the
agent to check the issue is still open, never read or emit credentials, never merge,
and leave the PR for human review.
- This repo's `.gitignore` covers this repo only. When the factory targets **another**
repo, `<repo>/.software-factory/` is *not* automatically ignored there — add it to
that repo's `.gitignore` (or delete the folder) before committing.
- The canvas HTTP server binds to `127.0.0.1` on a random port (localhost-only UI).
`POST /action` additionally requires a per-instance CSRF token: the server generates
a random token at startup, embeds it in the served HTML (`meta[name="sf-action-token"]`)
and rejects any request without the matching `x-sf-action-token` header (403). A
foreign website can send a simple POST but cannot read the token or the response.
- Project item-add failures are recorded in `state.notes`; issue creation can continue.
- When a Project owner is not provided, the runner uses the owner from `--repo`.
## Validate
From `com.github.copilot/extensions/software-factory/`, run `npm test` to execute the built-in Node.js
regression tests. Install/maintainability tests (temp `COPILOT_HOME` only, never the
real install) run with `pwsh -NoProfile -File tests/install-tests.ps1` from the repo
root. The GitHub Actions workflow also checks the JavaScript syntax, validates the
plugin, package and `canvas-meta.json` manifests, runs
`node tools/check-external-layout.mjs` (partial local check: namespaced canvas entry,
no duplicate outside the namespace, no versioned `canvas.json`, plus `plugin.json`
validated against the vendored Agent Plugins 1.0.0 schema — the full official
awesome-copilot gate is not executed here),
generates the install-target `canvas.json` with
`tools/make-canvas-manifest.mjs`, and runs the install suite on `windows-latest`.
## Governance & releases
See [CONTRIBUTING.md](CONTRIBUTING.md) for the release process (merge a version bump to
`main` and `release.yml` tags and publishes it, verifying versions, CHANGELOG and the
skill) and the branch-protection checklist for maintainers, and [SECURITY.md](SECURITY.md)
for vulnerability reporting. Check an installation against the repo with
`.\install.ps1 -Check` (exit 1 on drift). Branch protection on `main` is configured in
repo settings, not in code.
## Limitations (verified, not promised)
- No `package-lock.json` is committed (the runner uses only Node built-ins; the SDK
dependency is pinned exactly and `engines.node >=20` is declared).
- The installer updates files in place but does not remove files deleted upstream; a
file that no longer exists in the source can linger in the install target.
- `install.ps1` uses Windows-style paths; on Linux/macOS use the manual install.
- Canvas discovery relies on the generated `canvas.json` and the app's extension host,
which this repo does not ship or control.
- El servidor loopback del canvas valida `Host` (solo `127.0.0.1:<puerto>`/`localhost:<puerto>`),
rechaza `Origin` externo o `Sec-Fetch-Site: cross-site` en `POST /action`, limita el body a
64 KB, envía `X-Content-Type-Options: nosniff` y CSP, y no expone rutas locales en errores.
No es autenticación de usuario: cualquier proceso local sigue pudiendo leer el token del HTML.
- `?repo=` (en `/state`, `/events`, `/action`) y `input.repo` de las acciones del canvas aceptan
rutas absolutas existentes (resueltas con `realpath`, así que `..` y symlinks que escapan se
normalizan). Una ruta dentro del workspace de la sesión, de `SF_ALLOWED_ROOTS` o autorizada al
abrir el canvas pasa siempre; además, el panel permite escribir cualquier ruta que sea un
**workspace git** (contiene `.git`) — necesario porque el host de extensiones no está ligado a
una sesión de chat y la app no siempre puede pasar `input.repo`. Las escrituras fuera de un git
se rechazan con `sf_repo_no_permitido` sin tocar disco. Mitigaciones: servidor solo en
`127.0.0.1`, token CSRF por instancia y validación de `Host`/`Origin`.
## Repo layout notes
This is a standalone repo on purpose: the plugin bundles a canvas extension with its
runner and has its own release cadence. It can still be listed from a marketplace
(`marketplace.json`) like sibling plugins. MIT licensed, except the vendored
Agent Plugins schema under `tools/schemas/` which is Apache-2.0 (see
`tools/schemas/NOTICE.md`).