{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/squirrelscan-com/json-schema/squirrelscan-com-audit-run-schema.json",
  "title": "AuditRun",
  "description": "Full audit run record (the single-run GET). A caller can only fetch their own runs, so the owner identifiers below are always the caller's own. Composed as `AuditRunListItem` plus the owner identifiers `userId`/`orgId` via `allOf`, so the shared fields are defined once and cannot drift between the two.",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/squirrelscan-com-openapi.json#/components/schemas/AuditRun",
  "allOf": [
    {
      "$ref": "#/$defs/AuditRunListItem"
    },
    {
      "type": "object",
      "required": [
        "userId"
      ],
      "properties": {
        "userId": {
          "type": "string",
          "description": "Internal owner user id (the caller's own — runs are scoped to the authenticated user). Treat as an opaque identifier; do not log/forward outside an authenticated context."
        },
        "orgId": {
          "type": [
            "string",
            "null"
          ]
        },
        "queue": {
          "$ref": "#/$defs/AuditRunQueue",
          "description": "Where the run stands while `status` is `queued`. Omitted otherwise."
        },
        "progress": {
          "type": [
            "object",
            "null"
          ],
          "description": "Live progress while `status` is `queued`/`pending`/`running` (#692): the latest phase/page-count event streamed by the run. Null once the run is terminal, or if no progress event has been recorded yet.",
          "properties": {
            "phase": {
              "type": [
                "string",
                "null"
              ]
            },
            "message": {
              "type": [
                "string",
                "null"
              ]
            },
            "current": {
              "type": [
                "integer",
                "null"
              ]
            },
            "total": {
              "type": [
                "integer",
                "null"
              ]
            },
            "failed": {
              "type": [
                "integer",
                "null"
              ]
            },
            "updatedAt": {
              "type": "string",
              "format": "date-time"
            }
          }
        },
        "notice": {
          "$ref": "#/$defs/PageLimitClampNotice"
        },
        "renderFallback": {
          "$ref": "#/$defs/RenderFallbackNotice"
        },
        "reportAvailability": {
          "type": "string",
          "enum": [
            "ready",
            "pending",
            "none"
          ],
          "description": "Whether this run's report exists, so a client stops guessing from a missing report: `ready` (a report is stored for the run, not verified readable; a failed run that wrote a failure notice has one), `pending` (the run is still going, or it completed and its report is being finalized), `none` (the run failed or was cancelled without writing a report and none will come). Additive."
        }
      },
      "additionalProperties": true
    }
  ],
  "$defs": {
    "AuditRunListItem": {
      "type": "object",
      "description": "Audit run as returned by the list endpoint. Also the shared base for the single-run `AuditRun` schema, which composes this plus `userId`/`orgId` via `allOf` — so the common fields live in exactly one place. Nullable fields are unset until the run progresses.",
      "required": [
        "id",
        "url",
        "status",
        "trigger",
        "mode",
        "createdAt"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "status": {
          "$ref": "#/$defs/AuditRunStatus"
        },
        "trigger": {
          "type": "string",
          "enum": [
            "cli",
            "api",
            "github",
            "scheduled"
          ]
        },
        "mode": {
          "$ref": "#/$defs/AuditRunMode"
        },
        "model": {
          "type": [
            "string",
            "null"
          ]
        },
        "healthScore": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 100,
          "description": "Rounded score from the persisted `health_score` DB column (an integer). The unrounded float is available as `report.healthScore` on `GET /v1/agent-runs/{id}/report`. `null` while the run has no score yet, for a blocked or unreachable site, and for a `partial` run: one started with `config.enabledRulePatterns` covers only the rules it selected, so a score computed from them is not the site's score and is withheld. A run with no include filter, or with only `disabledRulePatterns`, is scored as before."
        },
        "partial": {
          "type": "boolean",
          "const": true,
          "description": "Present, and `true`, only when the run was started with `config.enabledRulePatterns`: its `healthScore` is `null` because the rules it ran are a subset of the audit. The key is absent for a run without an include filter, and for one with only `disabledRulePatterns`. The same marker, with the same meaning, is on `GET /v1/agent-runs/{id}/report`."
        },
        "issuesFound": {
          "type": [
            "integer",
            "null"
          ]
        },
        "issuesFixed": {
          "type": [
            "integer",
            "null"
          ]
        },
        "reportId": {
          "type": [
            "string",
            "null"
          ]
        },
        "websiteId": {
          "type": [
            "string",
            "null"
          ]
        },
        "auditId": {
          "type": [
            "string",
            "null"
          ]
        },
        "config": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        },
        "completionReason": {
          "type": [
            "string",
            "null"
          ]
        },
        "completionMessage": {
          "type": [
            "string",
            "null"
          ]
        },
        "costUsd": {
          "type": [
            "number",
            "null"
          ]
        },
        "startedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "completedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        }
      },
      "additionalProperties": true
    },
    "AuditRunMode": {
      "type": "string",
      "enum": [
        "audit",
        "audit-fix",
        "recommend"
      ]
    },
    "AuditRunQueue": {
      "type": "object",
      "description": "Where a `queued` run stands. A queued run is waiting for a container slot and starts by itself: there is nothing to retry and nothing more is charged. Present on the create response and on `GET /v1/agent-runs/{id}` while `status` is `queued`.",
      "required": [
        "position",
        "etaMinutes",
        "reason",
        "message"
      ],
      "properties": {
        "position": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "description": "Place in line, `1` is next. `null` when it could not be read."
        },
        "etaMinutes": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Estimated minutes until the run starts. `null` when there is no estimate."
        },
        "reason": {
          "type": "string",
          "enum": [
            "capacity",
            "org_limit"
          ],
          "description": "`capacity`: the audit containers are busy. `org_limit`: the organization is already running its plan's limit of audits at once."
        },
        "message": {
          "type": "string",
          "description": "A sentence ready to show a person. May change; do not match on it."
        }
      }
    },
    "AuditRunStatus": {
      "type": "string",
      "enum": [
        "queued",
        "pending",
        "running",
        "completed",
        "failed",
        "cancelled"
      ]
    },
    "PageLimitClampNotice": {
      "type": "object",
      "description": "Present only when the run's requested page count exceeded the org's plan ceiling. The run is never rejected for this (clamp-and-notify, not a hard error) — it dispatches at `applied` pages instead of `requested`, and this field says so.",
      "required": [
        "type",
        "requested",
        "applied",
        "planId",
        "planCap",
        "upgradeHint"
      ],
      "properties": {
        "type": {
          "type": "string",
          "const": "page_limit_clamped"
        },
        "requested": {
          "type": "integer",
          "description": "Pages that were actually asked for (stored crawl config or an explicit request override)."
        },
        "applied": {
          "type": "integer",
          "description": "Pages the run actually dispatched with — equal to `planCap`."
        },
        "planId": {
          "type": "string",
          "enum": [
            "free",
            "starter",
            "team",
            "team_legacy",
            "business",
            "enterprise"
          ]
        },
        "planCap": {
          "type": "integer",
          "description": "The org's plan's effective max-pages-per-audit ceiling at dispatch time."
        },
        "upgradeHint": {
          "type": "string",
          "description": "Human-readable upgrade suggestion, always including a pricing URL."
        }
      }
    },
    "RenderFallbackNotice": {
      "type": "object",
      "description": "Present only when pages the run asked to render could not be rendered and were audited from their unrendered source instead. The audit still completes and publishes; content added by JavaScript was not seen on those pages. Absent when every render succeeded or the run never asked for rendering.",
      "required": [
        "type",
        "pages",
        "message"
      ],
      "properties": {
        "type": {
          "type": "string",
          "const": "render_fallback"
        },
        "pages": {
          "type": "integer",
          "description": "Pages that fell back to plain fetch."
        },
        "message": {
          "type": "string",
          "description": "Human-readable explanation, suitable to show to the audit's owner."
        }
      }
    }
  }
}