{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://peakstate.global/sourced/v1.schema.json",
  "title": "SOURCED sidecar v1",
  "description": "Claim provenance for one artefact (article, deck, brief). Sits beside the artefact or, when published, at /sourced/<slug>.sourced.json. Spec and tools: https://github.com/peakstate-global/sourced",
  "type": "object",
  "required": [
    "$schema",
    "sourced",
    "artefact",
    "claims",
    "evidence",
    "disclosure"
  ],
  "properties": {
    "$schema": {
      "const": "https://peakstate.global/sourced/v1.schema.json",
      "description": "Namespace. Every SOURCED sidecar carries this so the file explains itself."
    },
    "sourced": {
      "type": "string",
      "pattern": "^1\\.[0-9]+$",
      "description": "Format version."
    },
    "artefact": {
      "type": "object",
      "required": [
        "path",
        "sha256",
        "producedAt"
      ],
      "properties": {
        "path": {
          "type": "string",
          "description": "Artefact path relative to the repo root."
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 of the artefact bytes at the time the sidecar was last written."
        },
        "producedAt": {
          "type": "string",
          "format": "date"
        },
        "slug": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "author": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "claims": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "statement",
          "status",
          "evidence"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "statement": {
            "type": "string",
            "description": "The load-bearing claim as the artefact makes it."
          },
          "status": {
            "enum": [
              "sourced",
              "recalled",
              "inferred"
            ],
            "description": "sourced = retrieved this session with a verbatim quote and locator; recalled = from memory; inferred = the author's own conclusion."
          },
          "locator": {
            "description": "Where the claim sits in the artefact (line, slide, section, paragraph)."
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "IDs into evidence[]. Empty for recalled and inferred."
          },
          "note": {
            "type": "string"
          },
          "distanceFromPrimary": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "url",
          "quote",
          "locator",
          "retrievedAt",
          "sha256"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "quote": {
            "type": "string",
            "description": "Verbatim sentence from the source. Must be text-searchable in the capture."
          },
          "locator": {
            "type": "string",
            "description": "Page, section, paragraph or timestamp inside the source."
          },
          "retrievedAt": {
            "type": "string",
            "format": "date"
          },
          "sha256": {
            "type": "string",
            "description": "SHA-256 of the captured bytes."
          },
          "textSha256": {
            "type": "string",
            "description": "SHA-256 of the extracted text; what /sourced check compares."
          },
          "proseWords": {
            "type": "integer"
          },
          "thin": {
            "type": "boolean",
            "description": "True when the capture held under 300 prose words, i.e. probably a navigation shell."
          },
          "originGroup": {
            "type": "string",
            "description": "Collapses write-ups of one origin into one source for counting."
          },
          "custodian": {
            "type": "string",
            "description": "Who holds the capture: self, third-party archive, or a named person who supplied it."
          },
          "archiveUrl": {
            "type": "string",
            "format": "uri"
          },
          "snapshot": {
            "type": "string",
            "description": "Path to the captured file."
          },
          "distanceFromPrimary": {
            "type": "string"
          },
          "supportingQuote": {
            "type": "string"
          },
          "quoteSecondary": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "text": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "disclosure": {
      "type": "object",
      "required": [
        "attribution",
        "accountable",
        "limitations",
        "references"
      ],
      "properties": {
        "attribution": {
          "type": "string"
        },
        "accountable": {
          "type": "string"
        },
        "limitations": {
          "type": "string",
          "minLength": 1,
          "description": "Only omissions a reader would decide differently knowing: a source not retrieved, a primary read through a secondary, a small survey base. One sentence each. Never the author's own thinking. 'No external sources.' and 'None material.' are complete values."
        },
        "references": {
          "type": "string",
          "description": "Prose sentence then APA 7th entries, one per source, alphabetical by first element."
        }
      },
      "additionalProperties": true
    },
    "notRetrieved": {
      "type": "array",
      "description": "URLs that were unavailable at the time of retrieval."
    },
    "notes": {}
  },
  "additionalProperties": true
}
