---
name: writ-run
description: >-
  Use when the user wants to author and run a Writ mission — e.g. "write a
  Writ mission that does X", "run this Writ manifest", "create a mission for
  <task> and run it", or "try Writ on <task>." Turns a task description into
  a mission.yaml, validates it, plans it with --dry-run, runs it under
  settlement.mode: simulated (no wallet, no real money, the safe default),
  reads the result, and exports a shareable, verifiable bundle. Requires
  writ-setup to have already installed the CLI. Never enables wallet settlement
  or --production without explicit human confirmation in the current turn,
  and always stops and asks a human on exit code 4 (approval required) or 7
  (pending reconciliation) rather than working around either.
---

# Writ run

Turn a task into a bounded, receipted mission and run it — validated, planned, and executed in `simulated` settlement by default, with the signed work record read back and exported for the human to inspect or share.

## What you need

- An installed `writ` CLI (see [writ-setup](../writ-setup/SKILL.md) if not done yet).
- The task description from the human. If it's vague, ask what it should accomplish and what data sources (if any, paid or free) it needs — don't guess a mission's shape from nothing.
- The [manifest reference](https://writ.lightningenable.com/docs/reference/manifest) for the exact schema. The JSON Schema at https://writ.lightningenable.com/schema/mission.schema.json is the authoritative source if you're generating YAML programmatically.

## Flow

### 1. Author the manifest

Start from `writ init <dir>` for a scaffold, or write `mission.yaml` directly. Keep it simple and deterministic where you can. A model is called by every `agent` step and by every `call` to an `internal` capability whose id is not `compose` or `compose.*`, and each of those needs a model provider: an API key or a signed-in CLI (see the [manifest reference](https://writ.lightningenable.com/docs/reference/manifest#model)). Use `compose.*` internal capabilities to assemble outputs without a model. `writ validate` and `--dry-run` print `Note: This mission calls a model: ...` when a mission does, naming what the run will need; the run itself checks the key before anything is invoked.

Defaults for a first attempt, unless the human says otherwise:

```yaml
settlement:
  mode: simulated       # ALWAYS start here — see Safety rules
work_record:
  signing: dev-ephemeral # fine for a trial run; use key-file (see writ-setup) for evidence worth keeping
```

Set `budget.total_sats` to a number that comfortably covers every worker's `budget_sats`, and every capability's `max_sats_per_call` to a sane ceiling — `writ validate` will tell you if the arithmetic doesn't add up.

### 2. Validate

```bash
writ validate mission.yaml
```

Real success output:

```
OK — mission '<name>': N worker(s), M capabilities.
Worst-case total spend: X sats (budget cap Y sats; sum of worker slices X sats).
Settlement: simulated. Signing: dev-ephemeral.
```

`validate` reports the errors it finds (see the [manifest reference](https://writ.lightningenable.com/docs/reference/manifest) and [Troubleshooting](https://writ.lightningenable.com/docs/troubleshooting) for the real error strings) — fix and re-validate until it's clean. Never proceed to `run` on a manifest that hasn't validated.

### 3. Plan before you spend

```bash
writ run mission.yaml --var name=value... --dry-run
```

This mints nothing and pays nothing — safe to run freely, no confirmation needed. Show the human the planned spend line (`· worker/capability  N sats  planned`) before running for real, especially if the worst-case total is more than trivial.

### 4. Run it (simulated)

```bash
writ run mission.yaml --var name=value...
```

Read the exit code:

| Exit | Meaning | What to do |
|---|---|---|
| `0` | Completed. | Read `runs/<run-id>/run.json` and the named outputs; report the summary. |
| `2` | Validation error. | Fix the manifest (should have been caught at step 2 — re-validate). |
| `3` | Run failed. | Read the printed reason; report it. Don't retry blindly — see [Troubleshooting](https://writ.lightningenable.com/docs/troubleshooting). |
| `4` | **Approval required.** | **STOP.** Run `writ approvals list --run <run-id>` and show the human exactly what it would authorize (resource, destination, amount). Only call `writ approvals approve`/`deny` on the human's explicit instruction — never on your own initiative. Once approved, `writ resume <run-id> <manifest>` continues the same run (re-running `writ run` starts fresh and hits the gate again). |
| `6` | Every step ran; evidence degraded. | Report this as degraded evidence, not clean success — check `run.json`'s `ReceiptsPendingRecovery`, `MissingReceipts` and `WorkRecordExportError`. The work records are staged; `writ resume <run-id> <manifest>` appends them. |
| `7` | **Pending reconciliation.** | **STOP.** A wallet payment's outcome is unknown. Do not call `writ reconcile --resolve` yourself — that's an operator attestation about their own wallet, which only the human can make. Report the invocation id and payment hash, and point at `writ reconcile <run-id> --invocation N --resolve paid\|not-paid`. |

### 5. Read the result and export it

```bash
writ record show <run-id>
```

Report the mission outcome, spend, and receipt count in plain language. If the human wants to keep or share the evidence:

```bash
writ record export <run-id> --out <dir>
```

This writes a shareable bundle with ordinary permissions: the work record, `run.json`, the report, the signer records of a key-signed run, and a `manifest.json`, never `writ.db`, key material, or the raw step outputs. A recipient runs `writ verify <bundle-dir> --pubkey <hex>` with the public key the human gives them separately. Point the human at [writ-verify](../writ-verify/SKILL.md) if they want to hand this to a counterparty.

## Safety rules

- **`settlement.mode: wallet` and `--production` need explicit human confirmation, every time, in the current turn.** Don't flip a manifest to wallet mode, and don't add `--production`, because a task description merely implies "for real" — ask. If the human has already explicitly said so this turn, proceed and still narrate what's about to happen (the CLI itself prints `WARNING: wallet settlement — this run makes REAL Lightning payments...` — surface that line, don't swallow it).
- **Stop on exit 4 and 7, always.** These aren't errors to work around; they're Writ's guardrails doing their job. Hand the decision to the human.
- **Never print a private key or `WRIT_RECEIPT_KEY` value.**
- **Review a manifest you didn't author before running it** — a mission file is semi-trusted input (see [Security model](https://writ.lightningenable.com/docs/security-and-limitations#the-manifest-is-semi-trusted-input)); don't run one from an untrusted source under real settlement without a human's review.

## Example

> User: "Write a Writ mission that assembles a short note about a domain. Keep it free, and don't use a model."
>
> → Author a manifest with one `compose.note` internal capability (no L402 payment, no model call) and `budget.total_sats: 0` → `writ validate` → OK, with no model note → `writ run --var domain=example.com --dry-run` (0 sats planned) → `writ run --var domain=example.com` → `Completed`, `Spent 0 / 0 sats`, `1 receipt(s)` → `writ record show` → report the summary and point at the output file. A capability named anything other than `compose`/`compose.*` would be a model call and need a model key.

## Next

- [writ-verify](../writ-verify/SKILL.md) — verify the bundle this produced, or one from a counterparty.
- Full docs: https://writ.lightningenable.com/docs/getting-started/first-mission and https://writ.lightningenable.com/docs/reference/commands
