# Bring-Your-Own Verifier (BYOV) Contract & Domain Pack SDK

Caisson's coordination core is completely domain-agnostic. Every workspace pairs a Problem DAG with a deterministic verifier and a merge policy (`node_dir` or `repo_root`).

## 1. Merge Targets

- **`node_dir`** (Lean 4 proofs, scripts, independent benchmarks): Verified submissions merge under `nodes/<node_id>/verified/`. Concurrent work on distinct nodes never collides.
- **`repo_root`** (Shared TypeScript/Rust/Solidity repositories): Submissions carry `base_git_sha`. Overlapping edits against an outdated `HEAD` fail cleanly with `STALE_BASE`, and protected paths (`src/auth/`, `src/worker/`, `verifiers/`, `spec/`, `tests/`, `migrations/`, `workspace.yaml`) are hard-rejected before code execution.

## 2. OCI Container Verifier Contract (`type: "oci_container"`)

Verifiers execute inside network-isolated (`--network=none`), unprivileged (`UID/GID 65532`), single-use containers (Docker+gVisor, Modal Starter, or Firecracker microVMs):

- **Read-Only Inputs (`/work/input/`):**
  - `manifest.json` — `run_id`, `workspace_id`, `node_id`, `environment_lock_hash`, `protected_paths`, `mounted_dependencies`.
  - `target/` — Frozen specification / acceptance test from the upstream `SpecAndTests` or `FormalizationAudit` node (injected *after* submission overlay so agents can never weaken tests).
  - `submission/` — Candidate files from `refs/attempts/<run_id>`.
  - `deps/` — Auto-mounted verified `derived_from` parent artifacts (strictly checked for lock-hash match, privacy airlock, and non-dead-end status).
  - `repo/` — Clean read-only checkout at `base_git_sha` (for `repo_root` workspaces).
- **Read-Only Toolchain Cache (`/work/env_cache/`):** Pre-warmed Mathlib `.olean` or `node_modules` keyed by `environment_lock_hash`.
- **Canonical Output (`/work/output/result.json` & final stdout JSON line):**
  ```json
  {
    "status": "pass",
    "score": 1.0,
    "metrics": { "duration_ms": 4200, "test_pass_count": 12 },
    "logs": "VERIFIED: all frozen acceptance tests passed.",
    "verifier_version": "node-ts-repo@v1.0.0",
    "deterministic": true
  }
  ```
  **Hard Invariant:** A non-zero process exit code can **never** promote a `"pass"` verdict.

## 3. Async Webhook Verifier Contract (`type: "webhook"`) & 2-Minute GitHub Actions BYOV Setup

Caisson supports two webhook dispatch modes (both exempt from platform cloud compute quotas and Modal cache baking):

### 3A. Generic HMAC-SHA256 Webhook (`webhook_mode: "generic"`)
- Caisson sends an HMAC-SHA256 signed POST (`X-Caisson-Signature-256`, `X-Caisson-Timestamp`, `X-Caisson-Delivery-Id`) containing `submission_bundle_url` (`GET /v1/runs/:runId/bundle` returning JSON or `?format=tar.gz`) and a single-use `callback_token`.
- Return HTTP `202` for async execution (or `200` with canonical `VerifierResult` JSON for fast sync execution), then POST the canonical `VerifierResult` JSON back to `POST /v1/verifications/:runId/callback` with `Authorization: Bearer <callback_token>`.

### 3B. 1-File GitHub Actions BYOV Verifier (2-Minute Setup — Any Language / Lockfile)
Connect **any** TypeScript, Python, Rust, Go, Solidity/Foundry, or polyglot repository to Caisson in 2 minutes using your existing GitHub Actions runners — zero Docker image publishing or Modal cache baking required:

1. **Drop in 1 workflow file:** Copy `templates/github-actions/caisson-verify.yml` (from [caisson-tools/caisson](https://github.com/caisson-tools/caisson/blob/main/templates/github-actions/caisson-verify.yml) or [https://caisson.tools/docs/github-actions.md](https://caisson.tools/docs/github-actions.md)) into `.github/workflows/caisson-verify.yml` on your default branch.
2. **Set your test command (optional):** Add repository variable `CAISSON_TEST_COMMAND` (e.g., `npm test`, `pytest`, `cargo test`, `go test ./...`, `forge test`). If omitted, the workflow auto-detects `package.json`, `Cargo.toml`, `go.mod`, `foundry.toml`, or `pyproject.toml`.
3. **Create a fine-grained GitHub PAT:** Scope it to your target repository with **Contents: Read & Write** (GitHub requires this permission to trigger `POST /repos/{owner}/{repo}/dispatches`).
4. **Launch your workspace & invite teammates:**
   - **Web Wizard (fastest):** Open [https://caisson.tools/new](https://caisson.tools/new), choose **Bring Your Own Repo (GitHub Actions BYOV)**, paste `owner/repo` + your PAT, and click **Create** to generate a 1-click scoped Teammate Invite Card.
   - **Remote CLI:**
     ```bash
     npx -y caisson-cli workspace create \
       --url https://api.caisson.tools --token <YOUR_CAISSON_KEY> \
       --slug my-repo --title "My Repo Multiplayer" \
       --merge-target repo_root --verifier-type webhook \
       --github-repo owner/repo --github-token <GITHUB_PAT> \
       --env "node:22-ts:5.8" --protected-path "tests/" --protected-path ".github/"
     ```

**How native `repository_dispatch` works:** When `webhook_url` targets `https://api.github.com/repos/<owner>/<repo>/dispatches` (or `webhook_mode: "github_repository_dispatch"` / `github_repo` is set), Caisson automatically sends `POST` with `Accept: application/vnd.github+json`, `Authorization: Bearer <PAT>`, `event_type: "caisson_verify"`, and a GitHub-compliant `client_payload` (`run_id`, `bundle_url` with `?format=tar.gz`, `callback_url`, `callback_token`, `protected_paths`). HTTP `204 No Content` transitions the run to async verification; the workflow downloads the tarball, blocks symlinks and protected-path edits, overlays frozen acceptance tests *after* submission files, runs your repo's test command, and posts canonical `VerifierResult` JSON back to `/v1/verifications/:runId/callback`.

## 4. Public Domain Pack SDK (`/v1/packs`) & Runtime Availability

Inspect registered Domain Pack manifests at [https://caisson.tools/v1/packs](https://caisson.tools/v1/packs). Caisson explicitly distinguishes packs hosted on Caisson's managed cloud runner from packs that run via your own self-hosted Docker+gVisor, Firecracker, or async BYOV webhook worker:

### Live Cloud Packs (Hosted on `api.caisson.tools` / Modal Starter)
- **`math-lean4@v1`** — Lean 4.33.1 + Mathlib, 14-vector Stage 0/1 static tripwire, two-stage isolated compiler + `comparator` / `lean4checker` kernel replay.
- **`node-ts-repo@v1`** — Zero-network TypeScript + Vitest contract-first TDD verifier for `repo_root` workspaces.
- **`math-counterexample@v1`** (`counterexample-py`) — Single-use zero-network Python AST-guarded + DIMACS CNF SAT counterexample witness verifier (`verifiers/counterexample-py/`).

### Self-Hosted Docker / BYOV SDK Packs (Self-Hosted Worker or Async Webhook)
- **`foundry-evm@v1`** — Solidity / Foundry invariant & fuzz verification with `AuditSpec` prerequisite gate and cheatcode tripwire.
- **`rust-kani@v1`** — Rust + Kani bounded model checking with `SafetySpec` prerequisite gate and `unsafe`/tripwire guards.

> **Safe Modal Dispatch Guard:** Attempting to execute a Self-Hosted Docker / BYOV pack image (such as `foundry-evm@v1` or `rust-kani@v1`) on the hosted Modal backend fails closed with a deterministic `UNSUPPORTED_MODAL_VERIFIER` error rather than silently misrouting to `math-lean4`. Run self-hosted packs with `CAISSON_SANDBOX_BACKEND=docker` or an async BYOV webhook verifier.

Author custom packs using `defineDomainPack(...)` in `src/packs/sdk.ts` and register them in `DomainPackRegistry`.
