# Create Loop

Compile an accepted plan into durable execution state. Do not perform open-ended planning in this command.

## 1. Locate The Accepted Plan

Accept a repo-relative plan file such as `PLAN.md` or an explicitly accepted plan in the current conversation. Record its source.

If the user provides only a goal, idea, or unresolved design, stop and recommend planning in the current harness. Do not mutate Beads or generate loop artifacts.

Completion criterion: one accepted plan source is identified.

## 2. Parse Profile And Harness

Run the deterministic parser before any mutation:

```sh
node <dirtyloops-skill-dir>/scripts/create-command.mjs create <create-arguments>
```

Accept `adaptive` or `orchestrator-callback`; default to `adaptive` only when omitted. Accept `codex` or `pi`; default to `codex` only when omitted. The optional word `for` is syntactic sugar immediately before the harness. Reject unknown or duplicate tokens instead of silently reinterpreting them.

Persist the selected profile in Beads, `IMPLEMENT.md`, `loop-state.md`, and the generated run prompt. Load `execution-profiles.md` and enforce its ownership boundary.

Completion criterion: exactly one execution profile and one harness are explicit before mutation.

## 3. Resolve The Harness Binding

Accept `codex` or `pi`. Default to `codex` only when the user omitted the harness. State the selected harness before mutation and load its reference under `references/harnesses/`.

Build `runtime/binding.json` from the target template and validate it with `harness-binding.schema.json`. For Pi, also copy the generated adapter policy from `templates/harnesses/pi/adapter.json.template` to `runtime/adapter.json`; omit that file for Codex. The binding records requirements, not currently detected plugins or product versions.

Completion criterion: exactly one schema-valid target binding is ready to materialize.

## 4. Validate The Plan

Require:

- overall outcome and why it matters
- scope and non-goals
- consequential settled decisions
- explicit unresolved questions or a statement that none remain
- phases with independently verifiable outcomes
- dependencies and ordering constraints
- acceptance evidence and quality gates
- replanning triggers for material uncertainty

Phase docs must be decision-complete and implementation-open. Reject plans that prescribe execution topology while leaving outcomes or acceptance evidence ambiguous.

Compile candidate phase docs in a temporary directory outside the repository, then run the bundled audit before creating Beads issues or repository files:

```sh
node <dirtyloops-skill-dir>/scripts/execution-readiness.mjs \
  --doc-root <temporary-phase-doc-root> \
  --policy block
```

`ready` may proceed. `needs-clarification` and `requires-reslice` stop before mutation with the report's actionable findings. Re-slicing is a user-visible plan amendment; never silently rewrite authored intent.

When validation fails, return a compact list of missing or ambiguous decisions and stop before mutation. Dirtyloops may clarify structure but must not invent intent.

Completion criterion: every required planning field is present or validation has stopped with actionable gaps.

## 5. Inspect Local Capabilities

Read `bd` help for commands that will be used. Inspect the repository's package manager, branch conventions, quality gates, and instruction files. Treat these as compilation inputs, not opportunities to redesign the accepted plan.

Completion criterion: planned mutations use commands supported by the local repo and Beads installation.

## 6. Materialize The Loop

Call the canonical `createGeneratedContract` helper with the rendered `IMPLEMENT.md` and mutable `loop-state.md` sidecar, target harness, readiness result, certified current coordinator id, and Beads graph transaction hooks (`snapshot`, `apply`, `restore`, and `isCurrent`). The helper assembles the destination binding, Pi adapter policy or explicit removal, current schemas, run prompt, mandatory legacy tombstones, and activation sidecar, then applies files and the Beads epic/children/dependencies inside one rollback boundary. `loop-state.md` and activation evidence are transactional sidecars but are excluded from deterministic generation identity. Dry-run first. A partial artifact map, ambiguous path, interrupted recovery, or failed Beads compensation blocks creation; do not fall back to piecemeal writes.

Inside the Beads `apply(generation)` hook, pass every executable child through the `prepareLaunchableLeaf` export from `scripts/create-contract.mjs` before writing it. Supply the child's final canonical Beads projection, phase path and content, `generation.generation_id`, and a reviewed nonempty `exactPathsAndInterfaces` list. The helper preserves accepted issue text and metadata while it:

- sets `execution_unit` to `qualified-tracer-bullet`
- adds the `tracer-bullet` label and one-bounded-PR ownership note
- points `spec_id` at the shared phase doc
- mirrors canonical blocking dependencies
- records structured `ownership_surface.exact_paths_and_interfaces`
- binds `runtime_generation_id` to the generated contract
- computes `execution_readiness` from the final launch projection

Write the helper's returned issue as one update. Do not hand-build or attest a partial projection, and do not compute the attestation before labels, notes, dependencies, ownership, and generation identity have reached their final values. Make `isCurrent(generation)` verify these fields and the attestation for every executable child, not only the epic generation id. Run the exact `launch-readiness.mjs` preflight for the first live-ready leaf after creation; creation is incomplete if it reports `blocked`.

Create:

- one Beads epic carrying dirtyloop v2 metadata
- one child issue per phase with accepted dependencies
- `docs/implementation/<stream>/IMPLEMENT.md`
- `00-roadmap.md`
- one phase doc and one initial turn doc per phase
- `loop-state.md`
- `prompts/run-loop.md`
- `runtime/binding.json`
- `runtime/adapter.json` for Pi-bound loops only
- current callback and execution-summary schemas
- current execution-readiness schema
- current harness-binding, runtime-capabilities, runtime-activation, and runtime-generation schemas
- `runtime/generation.json` with deterministic generated-artifact and adapter identity hashes, excluding mutable lifecycle sidecars
- `runtime/activation.json` with source coordinator identity outside deterministic generation identity

Use only common templates. Render the selected profile into every generated control surface. Do not generate fixed helper-role, selector, swarm, or model prompts; helper missions are chosen during `run`.

Phase docs contain outcome, rationale, scope, constraints, settled decisions, open questions, dependencies, acceptance evidence, quality gates, replanning triggers, and follow-up policy. Suggested implementation details must be clearly labelled hypotheses.

Completion criterion: Beads, the binding, generation manifest, activation requirement, and generated docs represent the same accepted phase graph and target harness; every generated path is repo-relative; creation distinguishes generated-contract activation readiness from live run-time capability readiness; and no generation lock remains.

## 7. Validate And Stop

Validate JSON schemas, frontmatter, generated links, Beads dependencies, profile agreement, and absence of fixed helper-role/model/swarm policy. Return the exact `dirtyloops run` invocation and stop without implementation.

Completion criterion: the user has a runnable loop with the requested ownership profile, compiled from the accepted plan and explicitly bound to Codex or Pi.
