{
  "protocol": "writ.agent-manifest/1",
  "name": "writ",
  "description": "Bounded autonomy for agents that spend money. A self-hosted .NET CLI that runs an agent mission under a cryptographic writ — a budget it cannot exceed, a scope it cannot escape, and a deadline — paying over Lightning (L402) and producing a signed work record that anyone holding the signer's public key can check offline.",
  "status": "private-preview",
  "custody": "Writ does not hold funds. The operator's own wallet (LND, NWC, or Strike) makes Lightning payments directly; Writ issues and verifies spending authority and records what happened.",
  "repository": "https://github.com/refined-element/writ",
  "repository_visibility": "private",
  "documentation": {
    "index": "https://writ.lightningenable.com/docs/intro",
    "llms_txt": "https://writ.lightningenable.com/llms.txt",
    "llms_full_txt": "https://writ.lightningenable.com/llms-full.txt",
    "command_reference": "https://writ.lightningenable.com/docs/reference/commands",
    "manifest_reference": "https://writ.lightningenable.com/docs/reference/manifest",
    "for_agents": "https://writ.lightningenable.com/docs/for-agents"
  },
  "access": {
    "status": "private preview",
    "request": "mailto:support@lightningenable.com",
    "note": "Writ is in private preview. To request access, write to support@lightningenable.com."
  },
  "programs": {
    "cli": "writ",
    "others": ["writ-mcp", "writ-api", "writ-coding-mcp", "Writ.Service (class library)"]
  },
  "setup_check": {
    "requirements": [".NET 10 SDK (LTS)"],
    "version_check": [
      "writ --version"
    ],
    "smoke_test": [
      "writ run smoke.yaml"
    ],
    "smoke_test_note": "smoke.yaml is the zero-configuration mission shown on https://writ.lightningenable.com/docs/getting-started/installation. It needs no wallet, API key, model, or network."
  },
  "manifest_schema": {
    "url": "https://writ.lightningenable.com/schema/mission.schema.json",
    "id": "https://writ.lightningenable.com/schema/mission.schema.json",
    "format": "JSON Schema draft 2020-12",
    "reference_doc": "https://writ.lightningenable.com/docs/reference/manifest"
  },
  "commands": [
    {
      "name": "writ init",
      "usage": "writ init [<dir>]",
      "description": "Scaffold a mission.yaml + README + .gitignore into a directory.",
      "arguments": [{"name": "dir", "required": false, "default": ".", "description": "Directory to scaffold into."}],
      "options": [],
      "exit_codes": {"0": "Scaffolded.", "2": "Refused to overwrite an existing mission.yaml, or the directory could not be written."}
    },
    {
      "name": "writ validate",
      "usage": "writ validate <manifest>",
      "description": "Parse and sanity-check a manifest; print an OK summary or the validation errors. Never spends anything.",
      "arguments": [{"name": "manifest", "required": true, "description": "Path to the mission manifest (YAML or JSON)."}],
      "options": [],
      "exit_codes": {"0": "Valid.", "2": "Invalid — see the printed problem(s)."}
    },
    {
      "name": "writ run",
      "usage": "writ run <manifest> [--var name=value]... [--dry-run] [--production] [--output-dir <dir>]",
      "description": "Run a mission end-to-end.",
      "arguments": [{"name": "manifest", "required": true, "description": "Path to the mission manifest."}],
      "options": [
        {"flag": "--var <name=value>", "repeatable": true, "description": "Set a manifest var."},
        {"flag": "--dry-run", "description": "Plan + cost estimate only; mints nothing, pays nothing, writes no run directory. SAFE to call without human confirmation."},
        {"flag": "--production", "description": "Fail-closed posture: no dev-ephemeral signer, wallet settlement required. NEVER pass this without explicit human confirmation in the current turn."},
        {"flag": "--output-dir <dir>", "description": "Override the manifest's run-output root."}
      ],
      "exit_codes": {
        "0": "Completed (or Planned, for --dry-run).",
        "2": "Manifest/input invalid.",
        "3": "Run failed (budget, execution, or authority).",
        "4": "Suspended awaiting human approval — STOP and hand back to a human. After a human approves, the run continues with `writ resume <run-id> <manifest>`.",
        "6": "Every step ran but the evidence is degraded (outcome ExecutedReceiptPendingRecovery): a step's receipt is not on the chain yet, or the work record could not be exported — never clean success. The receipts are staged; `writ resume` appends them.",
        "7": "A wallet payment's outcome is unknown; the budget hold is retained. STOP and hand back to a human — see `writ reconcile`.",
        "11": "Every step ran, but receipts are missing and the operator discarded each one with `writ outbox discard` (outcome ExecutedReceiptDiscarded; reasons in run.json's DiscardedWorkRecords) — never clean success, and nothing is left to resume. Do not re-run the mission."
      }
    },
    {
      "name": "writ resume",
      "usage": "writ resume <run-id> <manifest> [--var name=value]... [--production] [--output-dir <dir>]",
      "description": "Continue an interrupted or approval-suspended run from its run database and progress journal: completed steps are not run again, every interrupted call is resolved from the ledger by its idempotency key (never executed or paid twice), and staged work records are appended. Needs the same manifest, the same --var values, and the WRIT_ROOT_KEY the run started with; a run signed with a dev-ephemeral key cannot be resumed.",
      "arguments": [
        {"name": "run-id", "required": true, "description": "The run to continue."},
        {"name": "manifest", "required": true, "description": "The same manifest the run started with (checked against the run's journal)."}
      ],
      "options": [
        {"flag": "--var <name=value>", "repeatable": true, "description": "The same manifest vars the run started with."},
        {"flag": "--production", "description": "Fail-closed posture. NEVER pass this without explicit human confirmation in the current turn."},
        {"flag": "--output-dir <dir>", "description": "The run-output root the run was started with, when it was overridden."}
      ],
      "exit_codes": {
        "0": "Completed.",
        "2": "Manifest/input invalid.",
        "3": "Run failed, or the resume was refused (different manifest, different or missing WRIT_ROOT_KEY, dev-ephemeral signer, run locked by another process) — a refused resume changes nothing.",
        "4": "Suspended again awaiting human approval — STOP and hand back to a human.",
        "6": "Every step ran but the evidence is still degraded — see `writ record show`; a staged record that does not replay is listed, with its reason, by `writ outbox list` (an operator action).",
        "7": "A payment's outcome is unknown (for example the run was killed after paying but before recording it); the hold is retained. STOP and hand back to a human — see `writ reconcile`.",
        "11": "Every step ran; the receipts still missing were each discarded by the operator (`writ outbox discard`) and are recorded in the signed chain as discarded. Never clean success; nothing is left to resume."
      }
    },
    {
      "name": "writ approvals list",
      "usage": "writ approvals list (--run <run-id> | --service-db <path> [--workspace <ws>]) [--runs-root <dir>]",
      "description": "List pending approvals for a run, or for a writ-mcp / writ-api host — the credential, capability, amount, resource, destination, and TTL each would authorize.",
      "options": [
        {"flag": "--run <run-id>", "description": "The run. Give this or --service-db."},
        {"flag": "--service-db <path>", "description": "Operator-only: a writ-mcp / writ-api host's database (WRIT_DB_PATH). Needs the host's WRIT_ROOT_KEY in the environment, checked against the database first; never upgrades it."},
        {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace (default WRIT_WORKSPACE, else 'default')."},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Listed (possibly empty).", "2": "Bad run id / no database found, both or neither of --run and --service-db, or no WRIT_ROOT_KEY with --service-db."}
    },
    {
      "name": "writ approvals approve",
      "usage": "writ approvals approve <id> (--run <run-id> | --service-db <path> [--workspace <ws>]) [--runs-root <dir>]",
      "description": "Approve a pending request, for a run or for a writ-mcp / writ-api host. HUMAN DECISION — an agent must never call this on its own initiative; surface the pending request and act only on explicit instruction. On a service host this is the operator's: the agent-role surfaces do not offer it.",
      "arguments": [{"name": "id", "required": true, "description": "Approval request id."}],
      "options": [{"flag": "--run <run-id>", "description": "The run. Give this or --service-db."}, {"flag": "--service-db <path>", "description": "Operator-only: a writ-mcp / writ-api host's database. Needs the host's WRIT_ROOT_KEY, checked against the database first; never upgrades it."}, {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace."}, {"flag": "--runs-root <dir>", "default": "runs"}],
      "exit_codes": {"0": "Approved.", "2": "Not found, already approved/denied, or expired."}
    },
    {
      "name": "writ approvals deny",
      "usage": "writ approvals deny <id> (--run <run-id> | --service-db <path> [--workspace <ws>]) [--runs-root <dir>]",
      "description": "Deny a pending request, for a run or for a writ-mcp / writ-api host. HUMAN DECISION.",
      "arguments": [{"name": "id", "required": true, "description": "Approval request id."}],
      "options": [{"flag": "--run <run-id>", "description": "The run. Give this or --service-db."}, {"flag": "--service-db <path>", "description": "Operator-only: a writ-mcp / writ-api host's database. Needs the host's WRIT_ROOT_KEY, checked against the database first; never upgrades it."}, {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace."}, {"flag": "--runs-root <dir>", "default": "runs"}],
      "exit_codes": {"0": "Denied.", "2": "Not found."}
    },
    {
      "name": "writ revoke",
      "usage": "writ revoke <credential-id> (--run <run-id> | --service-db <path> [--workspace <ws>]) [--runs-root <dir>]",
      "description": "Kill switch: revoke a credential and its entire delegated subtree, in a run or on a writ-mcp / writ-api host. Idempotent — revoking an already-revoked credential succeeds again rather than erroring. An agent revokes a writ it delegated itself with the writ_revoke_delegated tool (or POST /v1/credentials/revoke-delegated), presenting the parent writ.",
      "arguments": [{"name": "credential-id", "required": true}],
      "options": [{"flag": "--run <run-id>", "description": "The run. Give this or --service-db."}, {"flag": "--service-db <path>", "description": "Operator-only: a writ-mcp / writ-api host's database. Needs the host's WRIT_ROOT_KEY, checked against the database first; never upgrades it."}, {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace."}, {"flag": "--runs-root <dir>", "default": "runs"}],
      "exit_codes": {"0": "Revoked.", "2": "Credential, run, or database not found."}
    },
    {
      "name": "writ issue",
      "usage": "writ issue --service-db <path> --principal <name> [--scope <capability|ns.*|*>] [--budget <sats>] [--per-call <sats>] [--ttl-minutes <n>] [--depth <n>] [--purpose <text>] [--workspace <ws>] [--json]",
      "description": "Issue a root writ on a writ-mcp / writ-api host's database and print its credential for the agent. HUMAN DECISION — this creates spending authority; an agent must never run it for itself. An agent-role host serves no issue tool, so this is how its operator gives an agent a writ. Reads the host's settings (WRIT_ROOT_KEY required, WRIT_CAPABILITIES, WRIT_WORKSPACE, the budget defaults) from the environment.",
      "options": [
        {"flag": "--service-db <path>", "required": true, "description": "The host's database (WRIT_DB_PATH). Opened, never created or upgraded; the key is checked against it first."},
        {"flag": "--principal <name>", "required": true, "description": "Who the writ speaks for."},
        {"flag": "--scope <capability|ns.*|*>", "default": "*"},
        {"flag": "--budget <sats>", "description": "Total cap. Default WRIT_BUDGET_TOTAL_SATS."},
        {"flag": "--per-call <sats>", "description": "Per-call cap. Default WRIT_BUDGET_PER_CALL_SATS."},
        {"flag": "--ttl-minutes <n>", "description": "Lifetime. Default WRIT_CREDENTIAL_TTL_MINUTES."},
        {"flag": "--depth <n>", "default": "1", "description": "Delegation hops the writ may spawn."},
        {"flag": "--purpose <text>"},
        {"flag": "--workspace <ws>", "description": "Default WRIT_WORKSPACE, else 'default'."},
        {"flag": "--json", "description": "Print one JSON object, including the credential."}
      ],
      "exit_codes": {"0": "Issued; the credential is printed (a bearer token: hand it only to the agent).", "2": "Bad input, no database, no WRIT_ROOT_KEY or not the host's key, a database the host has not started on yet, a schema version other than this build's, or the host's settings are not usable. Nothing is written."}
    },
    {
      "name": "writ record show",
      "usage": "writ record show <run-id> [--runs-root <dir>]",
      "description": "Print a human-readable summary of a completed run.",
      "arguments": [{"name": "run-id", "required": true}],
      "options": [{"flag": "--runs-root <dir>", "default": "runs"}],
      "exit_codes": {"0": "Printed.", "2": "No run summary found."}
    },
    {
      "name": "writ record export",
      "usage": "writ record export <run-id> [--out <dir>] [--runs-root <dir>]",
      "description": "Without --out: print the signed receipt chain to stdout. With --out: write a shareable bundle (work-record.jsonl, run.json, report.html, usage.json, the signer records of a key-signed run: signer-identity.json and, when present, rotations.jsonl and revocations.jsonl, and manifest.json), never writ.db, key material, or step outputs. The recipient verifies the bundle directory with the signer's public key, obtained separately.",
      "arguments": [{"name": "run-id", "required": true}],
      "options": [{"flag": "--out <dir>"}, {"flag": "--runs-root <dir>", "default": "runs"}],
      "exit_codes": {"0": "Exported.", "2": "No work record found, or the bundle path is invalid."}
    },
    {
      "name": "writ record publish-head",
      "usage": "writ record publish-head <run-id> [--out <file>] [--post <url>] [--key <path>] [--relay <wss-url>] [--relay-timeout <s>] [--json] [--runs-root <dir>]",
      "description": "Sign a head attestation over the run's terminal receipt. Needs a persistent signing key on disk (dev-ephemeral runs have none to sign with, and are refused). With --relay, verify the local chain and also publish it as a Nostr event (kind 38410) signed by the same key, so a copy of the head lives outside this machine.",
      "arguments": [{"name": "run-id", "required": true}],
      "options": [
        {"flag": "--out <file>"},
        {"flag": "--post <url>", "description": "HTTP POST the attestation to an operator URL. Confirm the destination with a human before using this in an autonomous flow."},
        {"flag": "--key <path>", "default": "keys/receipt.key"},
        {"flag": "--relay <wss-url>", "description": "Publish the attestation to this Nostr relay. Public: the relay learns the run id, receipt count, head hash and the signer's public key. Confirm the relay with a human before using this in an autonomous flow."},
        {"flag": "--relay-timeout <s>", "default": "15"},
        {"flag": "--json", "description": "Print one JSON object on stdout."},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Attestation written (and posted or published, if asked).", "2": "No receipts, a dev-ephemeral run, key unreadable, key is not the run's signer or a successor, or a relay URL that is not a plain wss:// URL.", "5": "With --relay: the local chain does not verify; nothing was written or sent.", "10": "The relay could not be used (refused, timed out, unreachable, or answered outside the protocol). The attestation and the signed event are still written locally; run the command again to retry."}
    },
    {
      "name": "writ record verify-head",
      "usage": "writ record verify-head <run-id> --relay <wss-url> --pubkey <hex> [--revocations <file>] [--relay-timeout <s>] [--json] [--runs-root <dir>]",
      "description": "Verify the run's local chain, fetch every head of this run from a Nostr relay, check each event's id, signature, attestation and signed key chain from the anchor, and compare each head with the local chain. Reads only. A match means consistent with what this one relay returned; a relay that withholds a later head hides a rollback, so check more than one relay.",
      "arguments": [{"name": "run-id", "required": true}],
      "options": [
        {"flag": "--relay <wss-url>", "required": true},
        {"flag": "--pubkey <hex>", "required": true, "description": "The run's signer public key (trust anchor)."},
        {"flag": "--revocations <file>", "description": "A trusted copy of revocations.jsonl to use instead of the run directory's."},
        {"flag": "--relay-timeout <s>", "default": "15"},
        {"flag": "--json", "description": "Print one JSON object on stdout, on every path, with an outcome of match, not_published, mismatch, key_chain_ambiguous, local_chain_invalid, local_records_invalid, relay_unavailable, relay_incomplete, relay_altered or usage_error."},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Every published head matches the local chain.", "2": "Bad input.", "5": "A returned head contradicts the local chain (rollback, fork, or two heads at one position), a head signed by a key on the anchor's chain is unusable, the key chain forks or loops (key_chain_ambiguous), or the local chain or its key records do not verify.", "8": "The relay returned no valid head for this run.", "10": "The relay could not be used, its answer may be incomplete, or it returned altered data (a head of this run under a key on the anchor's chain whose signature does not verify)."}
    },
    {
      "name": "writ reconcile",
      "usage": "writ reconcile (<run-id> | --service-db <path> [--workspace <ws>]) [--invocation N] [--resolve paid|not-paid [--allow-unconfirmed-not-paid]] [--apply-proof-journal [--yes] [--allow-legacy-proof-lines]] [--runs-root <dir>]",
      "description": "Resolve a budget hold retained because a wallet payment's outcome was unknown. HUMAN DECISION when using --resolve — an agent should not assert paid/not-paid on its own without checking with the human who controls the wallet.",
      "arguments": [{"name": "run-id", "required": false, "description": "Required unless --service-db is given."}],
      "options": [
        {"flag": "--service-db <path>", "description": "Operator-only: reconcile a writ-mcp / writ-api host database (WRIT_DB_PATH) instead of a run. A running host offers the same reconciliation to its operator role only (writ_reconcile on a --role operator writ-mcp, POST /v1/reconciliations/{invocationId}/resolve with the operator token); agent-role surfaces answer operator_only."},
        {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace (default WRIT_WORKSPACE, else 'default')."},
        {"flag": "--apply-proof-journal", "description": "Operator-only: review the authenticated payment-proof journal beside the database; every line is MAC-verified and checked against the ledger. Applies nothing without --yes."},
        {"flag": "--yes", "description": "With --apply-proof-journal: apply the lines that pass every check."},
        {"flag": "--allow-legacy-proof-lines", "description": "HUMAN DECISION. With --apply-proof-journal: also apply legacy journal lines that name no database, recorded before this database got its identity. Recorded in the audit log."},
        {"flag": "--invocation <N>", "description": "Required when more than one hold is pending."},
        {"flag": "--resolve <paid|not-paid>", "description": "Omit to ask a lookup-capable wallet first. not-paid on a hold with a payment hash is accepted only when the wallet reports the payment failed; otherwise it is refused with code wallet_reports_paid, wallet_cannot_confirm or no_lookup_wallet."},
        {"flag": "--allow-unconfirmed-not-paid", "description": "HUMAN DECISION. With --resolve not-paid: accept it when no wallet can confirm the payment failed. Recorded in the audit log. Never overrides a wallet that reports the payment paid."},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Resolved.", "2": "Bad input, or a --service-db database at another schema version (run writ db upgrade with the host stopped).", "7": "Still pending reconciliation, including a refused not-paid attestation."}
    },
    {
      "name": "writ outbox list",
      "usage": "writ outbox list (<run-id> | --service-db <path> [--workspace <ws>] [--previous-root-key-env <NAME>]) [--json] [--runs-root <dir>]",
      "description": "List the staged work records (receipt outbox) still pending, each with its correlation evidence (invocation, capability, amount, payment hash, staged time), one reason code (replayable, awaiting_ledger, already_on_chain, no_receipt_owed, mac_invalid, unkeyed, ledger_mismatch, invocation_missing, request_unreadable), the re-sign cross-check's verdict and the actions open to the operator (resign is listed when every check list can run passes with the same --previous-root-key-env; resign can still answer unchanged or refuse while a host holds the lock; with a WRIT_ROOT_KEY that is not the host's current key, resign is listed for no record and resign_refusal says why); and the records the operator discarded, with their reasons. Reads only; SAFE to call. Without WRIT_ROOT_KEY the MACs are reported not_checked.",
      "arguments": [{"name": "run-id", "required": false, "description": "Required unless --service-db is given."}],
      "options": [
        {"flag": "--service-db <path>", "description": "A writ-mcp / writ-api host database (WRIT_DB_PATH) instead of a run."},
        {"flag": "--workspace <ws>", "description": "With --service-db: the host workspace (default WRIT_WORKSPACE, else 'default')."},
        {"flag": "--previous-root-key-env <NAME>", "description": "With --service-db: the NAME of an environment variable holding the host's previous WRIT_ROOT_KEY, so the actions reflect what resign would do. Never the key itself."},
        {"flag": "--json", "description": "One JSON object on stdout on every path, refusals included (error.code)."},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Listed.", "2": "Bad input, no such run or database, or a schema this build cannot read (error.code says which)."}
    },
    {
      "name": "writ outbox resign",
      "usage": "writ outbox resign --service-db <path> [--workspace <ws>] --invocation <id> --previous-root-key-env <NAME> [--json]",
      "description": "OPERATOR-ONLY; HUMAN DECISION; service databases only (refused on a run with resign_not_available_on_run). Re-authenticate a staged work record of a host whose WRIT_ROOT_KEY changed, under the current key, only when the record's own MAC verifies under the host's previous key with times before that key was replaced, every request field with a stored counterpart matches the ledger, and, for a paid record, a proof event with the same payment hash and amount verifies under the current key or (signed before it was replaced) the previous key. The previous key is passed by environment variable NAME (--previous-root-key-env), never as a value, and must be a key that signed a host.key_bound record in this file, with WRIT_ROOT_KEY the host's current key; evidence under it counts only from its first period. Use one root key per service database: never reuse it on another database, and never bring it back after it has been replaced. If the previous key was replaced because it may have been exposed, use discard, not resign. Without the previous key (previous_root_key_required), or for a record that does not verify under it (record_not_authenticated), the record cannot be re-signed and is discarded. WRIT_ROOT_KEY must match the host's newest key binding (host.key_bound). Refused while a service host is live on the database. The receipt is appended at the host's next start. An agent must not run this on its own.",
      "arguments": [{"name": "run-id", "required": false, "description": "Not accepted: resign is refused on a run."}],
      "options": [
        {"flag": "--invocation <id>", "required": true},
        {"flag": "--previous-root-key-env <NAME>", "required": true, "description": "The NAME of an environment variable holding the host's previous WRIT_ROOT_KEY. Never the key itself."},
        {"flag": "--service-db <path>"},
        {"flag": "--workspace <ws>"},
        {"flag": "--json"}
      ],
      "exit_codes": {"0": "Re-signed, or already verifying under this key (outcome unchanged).", "2": "Refused or bad input; error.code is one of usage_error, target_not_found, target_busy, host_settings_invalid, root_key_missing, root_key_unrecognized, root_key_not_bound, previous_root_key_missing, previous_root_key_unrecognized, previous_root_key_required, record_not_authenticated, schema_error, store_error, not_staged, not_pending, not_stranded, cross_check_failed, no_receipt_owed, resign_not_available_on_run, concurrent_change. Nothing was changed."}
    },
    {
      "name": "writ outbox discard",
      "usage": "writ outbox discard (<run-id> | --service-db <path> [--workspace <ws>]) --invocation <id> --reason <why> [--json] [--runs-root <dir>]",
      "description": "OPERATOR-ONLY; HUMAN DECISION. Write off a stranded staged work record (on a run, the only action for one). The row is kept and the reason is recorded in the signed audit log; the next `writ resume` or host start appends a signed receipt of result code work_record_discarded (reason code operator_discarded; not a work record) stating the ledger's payment hash and the invocation as they stood at the discard, and a run ends ExecutedReceiptDiscarded (exit 11). Refused for a row the recovery job appends or will append, whatever its status. An agent must not run this on its own.",
      "arguments": [{"name": "run-id", "required": false, "description": "Required unless --service-db is given."}],
      "options": [
        {"flag": "--invocation <id>", "required": true},
        {"flag": "--reason <why>", "required": true, "description": "1 to 500 characters, no control characters. Recorded in the audit log and in run.json."},
        {"flag": "--service-db <path>"},
        {"flag": "--workspace <ws>"},
        {"flag": "--json"},
        {"flag": "--runs-root <dir>", "default": "runs"}
      ],
      "exit_codes": {"0": "Discarded, or already discarded (outcome unchanged).", "2": "Refused or bad input (error.code, as for resign). Nothing was changed."}
    },
    {
      "name": "writ keys init",
      "usage": "writ keys init [--out <path>] --operator-name <name> [--operator-url <url>] [--operator-contact <c>]",
      "description": "Generate a persistent receipt signing key (created private: no other account is granted access) and its self-signed operator identity record. Never prints the private key.",
      "options": [
        {"flag": "--out <path>", "default": "keys/receipt.key"},
        {"flag": "--operator-name <name>", "required": true},
        {"flag": "--operator-url <url>"},
        {"flag": "--operator-contact <contact>"}
      ],
      "exit_codes": {"0": "Created.", "2": "Missing --operator-name, or a key/identity already exists at that path."}
    },
    {
      "name": "writ keys show",
      "usage": "writ keys show [--key <path>] [--identity <path>]",
      "description": "Print the public identity of a signing key — pubkey, key_id, operator. Never the private key.",
      "options": [{"flag": "--key <path>", "default": "keys/receipt.key"}, {"flag": "--identity <path>"}],
      "exit_codes": {"0": "Valid.", "2": "No record found.", "5": "Record present but does not self-verify, or doesn't match the key file."}
    },
    {
      "name": "writ keys rotate",
      "usage": "writ keys rotate [--key <path>] [--operator-name <name>] [--operator-url <url>] [--operator-contact <c>]",
      "description": "Replace the signing key at the same path with a fresh one; archives the old key/identity; appends a rotation record signed by the OLD key. Verifiers pinned to the old pubkey keep working via the rotation walk.",
      "options": [{"flag": "--key <path>", "default": "keys/receipt.key"}, {"flag": "--operator-name <name>"}, {"flag": "--operator-url <url>"}, {"flag": "--operator-contact <contact>"}],
      "exit_codes": {"0": "Rotated.", "2": "No existing key/identity to rotate from, or an archive target already exists.", "5": "Current identity does not verify."}
    },
    {
      "name": "writ keys revoke",
      "usage": "writ keys revoke [--key <path>] --key-id <id> [--reason <text>]",
      "description": "Revoke a signing key as of now; receipts it signs after this fail `writ verify`. IRREVERSIBLE for that key going forward — confirm the key_id with a human before calling this.",
      "options": [{"flag": "--key <path>", "default": "keys/receipt.key", "description": "The key that SIGNS the revocation — the revoked key itself or a successor."}, {"flag": "--key-id <id>", "required": true}, {"flag": "--reason <text>"}],
      "exit_codes": {"0": "Revoked.", "2": "The signing key can't legitimately revoke that key_id.", "5": "The signing identity does not verify."}
    },
    {
      "name": "writ verify",
      "usage": "writ verify [<work-record>] --pubkey <hex> [--algorithm <alg>] [--key-id <id>] [--signer-mode <mode>] [--expect-head <seq:hash>] [--summary <run.json>] [--record <work-record.jsonl>] [--require-identity] [--identity <path>] [--rotations <path>] [--revocations <path>] [--pinned-head <attestation.json>] [--allow-no-terminal-commitment]",
      "description": "Fully offline verification of a signed receipt chain — no database, no network. Safe to call freely; it never mutates anything.",
      "arguments": [{"name": "work-record", "required": false, "description": "A run directory or an exported bundle (preferred: it holds run.json, whose terminal commitment binds the chain's end, and the signer records), or a direct path to work-record.jsonl. Optional when --record is given."}],
      "options": [
        {"flag": "--pubkey <hex>", "required": true, "description": "The trust anchor — the run's own signer, or an earlier key in its rotation chain."},
        {"flag": "--require-identity", "description": "Fail unless the chain is bound to a verified signer identity record."},
        {"flag": "--pinned-head <attestation.json>", "description": "The chain must end exactly at the head a signed head attestation names."},
        {"flag": "--allow-no-terminal-commitment", "description": "Accept a record with nothing that binds the chain's end (exit 0 with a warning instead of 8). Prefer verifying the run directory or bundle."}
      ],
      "exit_codes": {"0": "Verified clean.", "2": "Missing required input (e.g. no --pubkey).", "5": "At least one verification failure — see the printed problem(s).", "8": "INCOMPLETE: every receipt verified, but nothing binds the chain's end (no run.json terminal commitment, --expect-head or --pinned-head), so a shortened record cannot be ruled out. Verify the run directory or bundle instead."}
    },
    {
      "name": "writ coding lease",
      "usage": "writ coding lease <create|show|narrow|revoke> <task> [options]",
      "description": "Create a coding task from a lease file, show its lease version, status and remaining quota, replace the lease with a strictly tighter one (a new version), or end the task's authority. HUMAN DECISION for create, narrow and revoke: a lease is the authority a coding agent works under, so an agent must never mint, change or end one on its own initiative.",
      "arguments": [{"name": "task", "required": true, "description": "Coding task id."}],
      "exit_codes": {"0": "Done.", "2": "Refused: bad input, a lease that does not parse or is not strictly tighter, or a task in the wrong state."}
    },
    {
      "name": "writ coding approvals",
      "usage": "writ coding approvals <list|show|approve|narrow|deny> [<id>] [options]",
      "description": "Read and decide coding scope-expansion requests. list and show are read-only. approve and narrow mint a new lease version; deny records who refused and when (the reason is required and is not stored). HUMAN DECISION: an agent must never approve, narrow or deny a scope request on its own initiative; surface it and act only on explicit instruction.",
      "arguments": [{"name": "id", "required": false, "description": "Scope request id (every verb except list)."}],
      "exit_codes": {"0": "Done.", "2": "Refused: not found, already decided, or bad input."}
    },
    {
      "name": "writ coding reconcile",
      "usage": "writ coding reconcile <task> <invocation> --lease <path> --run <run-id> --as <identity> [--runs-root <dir>]",
      "description": "Hand one retained hold's recorded inputs to the reconciler that owns it and print the verdict it reached. Performs no ledger move of its own. The 'override' subcommand records that a named operator looked at a hold nothing could resolve; it moves nothing and frees no capacity.",
      "arguments": [{"name": "task", "required": true, "description": "Coding task id."}, {"name": "invocation", "required": true, "description": "The invocation whose retained hold this is."}],
      "options": [
        {"flag": "--lease <path>", "required": true, "description": "The task lease YAML currently in force."},
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--as <identity>", "required": true, "description": "Who you are acting as. NOT authenticated: it is the name you choose to be recorded under."}
      ],
      "exit_codes": {"0": "The reconciler reached a verdict.", "2": "Bad input.", "7": "Still pending reconciliation: no verdict, or no retention record."}
    },
    {
      "name": "writ coding dispose",
      "usage": "writ coding dispose <task> --bundle-dir <dir> --run <run-id> --as <identity> [--runs-root <dir>]",
      "description": "Remove an ABANDONED task's retained worktree and its git registration, after its evidence bundle has been captured. Destructive: the worktree is the only remaining copy of what the task left behind, so the bundle must name this task.",
      "arguments": [{"name": "task", "required": true, "description": "Coding task id. Only an abandoned task has a workspace to dispose."}],
      "options": [
        {"flag": "--bundle-dir <dir>", "required": true, "description": "The directory holding this task's captured evidence bundle."},
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--as <identity>", "required": true, "description": "Who you are acting as. NOT authenticated: it is the name you choose to be recorded under."}
      ],
      "exit_codes": {"0": "Disposed.", "2": "Refused: bad input, a task that is not abandoned, or a bundle for another task.", "7": "No retention record to act on."}
    },
    {
      "name": "writ db status",
      "usage": "writ db status <database>",
      "description": "Print a Writ database's schema version (PRAGMA user_version), the version this build understands, and any pending upgrade steps. Read-only; changes nothing.",
      "arguments": [{"name": "database", "required": true, "description": "A run's writ.db or a service host's WRIT_DB_PATH."}],
      "exit_codes": {"0": "Reported (current, older, or newer than this build).", "2": "No such file, or not readable as a SQLite database."}
    },
    {
      "name": "writ db upgrade",
      "usage": "writ db upgrade <database>",
      "description": "Upgrade a Writ database to this build's schema. Writes a backup beside it first (<db>.backups/<db-name>.schema-v<from>-<stamp>.bak, in an owner-only directory; reused if a complete one for that version exists); the rollback is restoring that file with no Writ process using the database. Refuses a database written by a newer Writ. Every other command that opens an older database performs the same upgrade (and backup) implicitly.",
      "arguments": [{"name": "database", "required": true, "description": "A run's writ.db or a service host's WRIT_DB_PATH."}],
      "exit_codes": {"0": "Upgraded, or already current.", "2": "Refused: no such file, a newer schema, not a Writ database, or the backup could not be written. Nothing was changed."}
    },
    {
      "name": "writ coding audit",
      "usage": "writ coding audit ingest [options]",
      "description": "Countersign the unsigned coding audit rows a keyless agent process recorded into the signed log, and record any gap in a session's sequence. A countersignature proves a holder of this host's audit key saw those metadata bytes at that time; the signed log is a per-row HMAC, not a chain, so it proves nothing about rows that were deleted or never written.",
      "exit_codes": {"0": "Ingested.", "2": "Refused: bad input or an unusable key or database."}
    },
    {
      "name": "writ coding receipts",
      "usage": "writ coding receipts append [options]",
      "description": "Sign an operator-side coding receipt, with this host's receipt key, for each settled operation whose row records committed evidence and whose receipt is not yet on the chain, and retry operations awaiting receipt recovery (up to 500 of each per run). A receipt attests what the operation row COMMITTED to at settle time.",
      "exit_codes": {"0": "Appended, or nothing to append.", "2": "Refused: bad input or an unusable key or database.", "7": "Receipts or their audit rows remain pending recovery."}
    },
    {
      "name": "writ coding report",
      "usage": "writ coding report <task> --out <dir> --run <run-id> --as <identity> [--runs-root <dir>] [--key <path>]",
      "description": "Write a task's review-ready evidence bundle (bundle.json, work-record.jsonl, manifest.json) and render it. Private values travel as salted commitments, never as names. Records nothing: the --as identity is printed back and written to no file. With --key the bundle is host-signed; a signature establishes which key-holder exported the bytes, not that they are true.",
      "arguments": [{"name": "task", "required": true, "description": "Coding task id."}],
      "options": [
        {"flag": "--out <dir>", "required": true, "description": "Where to write the bundle directory. Not the run directory or anything inside it."},
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--as <identity>", "required": true, "description": "Who you are acting as. NOT authenticated: it is the name you choose to be recorded under."},
        {"flag": "--key <path>", "description": "This host's receipt signing key file. Read, never created."}
      ],
      "exit_codes": {"0": "Bundle written.", "2": "Refused: bad input.", "6": "The bundle could not be made complete."}
    },
    {
      "name": "writ coding verify",
      "usage": "writ coding verify --bundle-dir <dir> --pubkey <hex> --run <run-id> [--runs-root <dir>] [--require-signature]",
      "description": "Check a coding evidence bundle: its commitment and file checksums, its receipt chain under a public key you supply from OUTSIDE the bundle, and its adapter evidence against the run's rows. Checksums alone are only a checksum; the bundle is bound only when its host signature verifies under --pubkey. Never mutates anything.",
      "options": [
        {"flag": "--bundle-dir <dir>", "required": true},
        {"flag": "--pubkey <hex>", "required": true, "description": "The receipt signer's public key, supplied from outside the bundle."},
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--require-signature", "description": "Fail unless bundle-signature.json verifies under --pubkey."}
      ],
      "exit_codes": {"0": "Verified clean.", "2": "Missing or bad input.", "5": "At least one verification failure.", "6": "The bundle is incomplete."}
    },
    {
      "name": "writ coding templates",
      "usage": "writ coding templates digest --templates <dir>",
      "description": "Print one line per check template in the directory: its id, '@', and the version digest a task lease must pin it at in its checks: list. Sorted by id. Reads no run and records nothing. A directory the template store refuses prints no pin at all.",
      "options": [
        {"flag": "--templates <dir>", "required": true, "description": "The check-template directory, the same one the MCP host is given as WRIT_CODING_TEMPLATES."}
      ],
      "exit_codes": {"0": "Printed (nothing, for an empty directory).", "2": "Refused: the directory does not exist, could not be read, or holds a template the store does not accept."}
    },
    {
      "name": "writ coding status",
      "usage": "writ coding status [--run <run-id>] [--runs-root <dir>] [--bundles-root <dir>]",
      "description": "Read every run (or one) read-only and print one line per run and one line per item a person must act on (pending scope requests, retained holds, receipts awaiting the operator step, unsigned audit rows, retained worktrees), each naming the command that acts on it; exits 7 when a person must act or a run is unreadable. Writes no row and reads no key; refuses a --bundles-root it cannot list.",
      "options": [
        {"flag": "--run <run-id>", "description": "Read only this run. Without it, every directory under --runs-root that holds a writ.db is read."},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--bundles-root <dir>", "description": "A directory of 'writ coding report --out' bundle directories; each task is reported as having a bundle or not. The bundle is read, not verified."}
      ],
      "exit_codes": {"0": "No run has an item a person must act on.", "2": "Refused: bad input, a run that does not exist, or a bundles root that cannot be listed.", "7": "A person must act: at least one run has an item, or could not be read."}
    },
    {
      "name": "writ coding backup",
      "usage": "writ coding backup --run <run-id> --out <file> --scratch <dir> [--runs-root <dir>]",
      "description": "Copy a run's writ.db to a NEW file with SQLite's online backup API and require PRAGMA integrity_check to answer ok on the copy, which establishes a well-formed database, not that its rows are right. Refuses while a session holds the lock (a writ-coding-mcp session lock on this host, probed at one instant), and refuses an --out that exists, sits inside the run directory, or shares a directory with a *.key file or a signer-identity.json. Copies the database only, never a key.",
      "options": [
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--out <file>", "required": true, "description": "The new file to write the copy to."},
        {"flag": "--scratch <dir>", "required": true, "description": "The writ-coding-mcp scratch root (WRIT_CODING_SCRATCH) whose session locks are probed."}
      ],
      "exit_codes": {"0": "Copied, and the copy passed the integrity check.", "2": "Refused: a session holds the lock, a refused --out, an unusable run database, or a copy that failed the integrity check (the copy is deleted)."}
    },
    {
      "name": "writ coding preflight-host",
      "usage": "writ coding preflight-host --expect <expectations.yaml>",
      "description": "Run AS the account to be measured: try to read and write each listed path, report whether the token is elevated, the names (never values) of secret-shaped environment variables, and whether each TCP connect target answered within three seconds, beside what was expected. It reports what this account observed when it tried, never a guarantee. Opens no database; writes only probe files, which it removes.",
      "options": [
        {"flag": "--expect <path>", "required": true, "description": "The expectations file (YAML): paths with none, read or readwrite; optional elevated; env_absent names; connect targets."}
      ],
      "exit_codes": {"0": "Every observation matched its expectation.", "2": "Refused: the expectations file could not be read or parsed, or states no expectation.", "9": "At least one observation did not match its expectation."}
    },
    {
      "name": "writ coding review",
      "usage": "writ coding review fetch <task> --run <run-id> --from <worker-clone> --into <operator-repo> [--runs-root <dir>]",
      "description": "Fetch a FINISHED task's writ/review/<task> from the worker's clone into a temporary ref, digest its checked-out tree, and land the branch as writ/reviewed/<task> only when its tree digest is the one the finishing host recorded. That digest is the finishing host's own record, not a signed value. Never overwrites an existing writ/reviewed/<task>; opens the run read-only and writes no row to it (SQLite may leave its -wal and -shm files beside writ.db).",
      "arguments": [{"name": "task", "required": true, "description": "Coding task id. Only a finished task has a review branch to fetch."}],
      "options": [
        {"flag": "--run <run-id>", "required": true},
        {"flag": "--runs-root <dir>", "default": "runs"},
        {"flag": "--from <dir>", "required": true, "description": "The worker's disposable clone. An absolute local directory reached through no link."},
        {"flag": "--into <dir>", "required": true, "description": "The operator's repository, where writ/reviewed/<task> is created. Not the same as --from."}
      ],
      "exit_codes": {"0": "The digest matched and writ/reviewed/<task> was created.", "2": "Refused: bad input, a task that is not finished or has no recorded tree digest, an existing reviewed branch, a refused path, or a fetch that failed.", "5": "The fetched tree's digest is not the one the finishing host recorded; no branch was created."}
    },
    {
      "name": "writ coding agent",
      "usage": "writ coding agent launch --run <run-id> --task <task> --lease <file> --prompt-file <file> --budget-usd <n> --claude <path> --out <dir> --server <path> --repository <dir> --scratch <dir> --worker <name> [options]",
      "description": "Run Claude Code headless as this account with Writ's coding tools as its only tools, its MCP server started by writ's relay with an allowlisted environment; the whole tree is killed when the init event or the server's observed environment differs from the plan. Refuses, starting nothing, an elevated token, any forbidden credential name, and a claude.exe the running account can write. It does not isolate the agent's network and is not a container or a VM.",
      "options": [
        {"flag": "--claude <path>", "required": true, "description": "The Claude Code executable by a fully qualified path, never an npm shim. Refused when this account could write it or its directory."},
        {"flag": "--out <dir>", "required": true, "description": "The new or empty job directory: mcp.json, the planned server names, the relay's observations, verdict.json and transcript-summary.json."},
        {"flag": "--budget-usd <n>", "required": true, "description": "Passed to Claude Code's --max-budget-usd; its enforcement is Claude Code's."}
      ],
      "exit_codes": {"0": "The checks held and Claude Code exited 0.", "2": "Refused before anything started: bad input, an elevated token, a forbidden credential name, a writable --claude, or an unwritable --out.", "3": "The run failed: a check refused and the tree was killed, or Claude Code did not exit 0."}
    }
  ],
  "verification_procedure": {
    "summary": "Anyone with a signer's public key can verify a Writ work record offline, with no access to the system that produced it.",
    "steps": [
      "Obtain the bundle (writ record export --out <dir>) or the run directory.",
      "Obtain the signer's public key out of band, for example the output of writ keys show sent to you by the operator, or a key you pinned earlier. Never trust a key that arrives only inside the bundle you're checking. A head attestation names the signer's key id, not its public key.",
      "Run: writ verify <bundle-or-run-dir> --pubkey <hex> [--require-identity] [--pinned-head <attestation.json>]",
      "Exit 0 and a line starting 'OK — verified N receipt(s).' means every receipt's signature and hash-chain link checked out, and the chain ends where its terminal commitment or pinned head says.",
      "Exit 8 (INCOMPLETE) means the receipts checked out but nothing bound the chain's end: verify the run directory or bundle (with run.json), or pass --expect-head or --pinned-head.",
      "Exit 5 means at least one check failed — read the printed problem(s); they name the exact row and reason."
    ],
    "what_it_proves": "That the recorded steps were attested by the holder of this key, and that the chain is intact and complete. It does not independently establish authorization, payment, completion, or quality: those are the signer's attestations.",
    "what_it_does_not_prove": "That the underlying work was good, truthful, or useful. Writ does not attempt output-quality verification."
  },
  "skills": [
    {
      "name": "writ-setup",
      "path": "skills/writ-setup/SKILL.md",
      "url": "https://writ.lightningenable.com/skills/writ-setup/SKILL.md",
      "description": "Confirm the writ tool is installed, create a persistent operator identity with `writ keys init`, and confirm the setup with a smoke run."
    },
    {
      "name": "writ-run",
      "path": "skills/writ-run/SKILL.md",
      "url": "https://writ.lightningenable.com/skills/writ-run/SKILL.md",
      "description": "Author a mission manifest from a task description, validate it, dry-run it, run it in simulated settlement, and export the result."
    },
    {
      "name": "writ-verify",
      "path": "skills/writ-verify/SKILL.md",
      "url": "https://writ.lightningenable.com/skills/writ-verify/SKILL.md",
      "description": "Verify a work-record bundle from a counterparty against a public key obtained out of band, optionally pinning a head attestation, and interpret every outcome, including INCOMPLETE (exit 8)."
    }
  ],
  "guardrails": [
    "Writ does not hold funds — your own wallet makes Lightning payments directly.",
    "Never enable settlement.mode: wallet or pass --production without explicit human confirmation in the current turn.",
    "Never print a private key, a WRIT_RECEIPT_KEY value, or a macaroon.",
    "Stop and hand back to a human on writ run exit code 4 (approval required) or 7 (pending reconciliation) — do not attempt to work around either.",
    "The mission manifest is semi-trusted input — review a manifest you did not author before running it with real settlement."
  ]
}
