{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://preclari.com/pif/v0.1/preflight-session.schema.json",
  "title": "PIF PreflightSession",
  "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.1.",
  "type": "object",
  "required": [
    "pif_version",
    "session_id",
    "workflow_description",
    "preflight_assertion",
    "created_at"
  ],
  "properties": {
    "pif_version": {
      "type": "string",
      "const": "0.1"
    },
    "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",
            "description": "Inputs passed to the tool. Implementations may redact sensitive fields."
          },
          "output_summary": {
            "type": "string",
            "description": "Short summary of what the tool returned."
          },
          "duration_ms": {
            "type": "integer",
            "minimum": 0
          },
          "model_used": { "type": "string" }
        }
      },
      "description": "Ordered list of tool invocations during the session. Enables replay."
    },
    "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",
            "description": "Which part of the session this action applies to."
          },
          "note": { "type": "string" }
        }
      }
    },
    "session_status": {
      "type": "string",
      "enum": ["open", "complete", "archived", "deleted"]
    },
    "deliverable_bundle": {
      "type": "object",
      "description": "References to deliverables produced from this session (human brief, audit walkthrough, etc.).",
      "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
}
