{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pif-spec.github.io/pif/v0.2/preflight-session.schema.json",
  "title": "PIF PreflightSession v0.2",
  "description": "A complete preflight session: the WorkflowDescription, the PreflightAssertion, and all tool invocations and reviewer actions in between. The durable audit artifact. PIF (Preflight Interchange Format) v0.2. Cumulative validation: accepts pif_version 0.1 or 0.2.",
  "type": "object",
  "required": [
    "pif_version",
    "session_id",
    "workflow_description",
    "preflight_assertion",
    "created_at"
  ],
  "properties": {
    "pif_version": {
      "type": "string",
      "enum": ["0.1", "0.2"]
    },
    "session_id": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_:.-]{4,128}$"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "completed_at": {
      "type": "string",
      "format": "date-time"
    },
    "workflow_description": {
      "$ref": "workflow-description.schema.json"
    },
    "preflight_assertion": {
      "$ref": "preflight-assertion.schema.json"
    },
    "tool_invocations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["tool_name", "invoked_at"],
        "properties": {
          "tool_name": { "type": "string" },
          "invoked_at": { "type": "string", "format": "date-time" },
          "input": { "type": "object" },
          "output_summary": { "type": "string" },
          "duration_ms": { "type": "integer", "minimum": 0 },
          "model_used": { "type": "string" }
        }
      }
    },
    "reviewer_actions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["reviewer", "action", "timestamp"],
        "properties": {
          "reviewer": { "type": "string" },
          "action": {
            "type": "string",
            "enum": ["reviewed", "approved", "overridden", "flagged", "annotated", "rejected", "signed_off"]
          },
          "timestamp": { "type": "string", "format": "date-time" },
          "scope": { "type": "string" },
          "note": { "type": "string" }
        }
      }
    },
    "session_status": {
      "type": "string",
      "enum": ["open", "complete", "archived", "deleted"]
    },
    "deliverable_bundle": {
      "type": "object",
      "properties": {
        "human_brief_url": { "type": "string", "format": "uri" },
        "audit_walkthrough_url": { "type": "string", "format": "uri" },
        "evidence_archive_url": { "type": "string", "format": "uri" }
      }
    },
    "extensions": {
      "type": "object"
    }
  },
  "additionalProperties": false
}
