{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rigor.diaconou.com/1.0/rigor.schema.json",
  "title": "Rigor, Vouch, Stages disclosure",
  "description": "Structural and vocabulary validation for the RIGOR.md stamp block (the fenced yaml under a trailing '## Stamp' heading). Semantic cross-field rules (level-to-checks consistency) are enforced separately by the semantic validator, not by this schema.",
  "type": "object",
  "additionalProperties": false,
  "required": ["signed", "rigor", "vouch"],
  "properties": {
    "signed": {
      "description": "Who makes this statement: a name, or a list of names when the stamp is co-signed. A co-signed stamp speaks as 'we'.",
      "oneOf": [
        { "type": "string", "minLength": 1 },
        { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
      ]
    },
    "forked_from": {
      "description": "The project this one was forked from, when it was: a name, optionally with a URL. Enables the 'upstream' actor on idea, plan and implementation.",
      "type": "string",
      "minLength": 1
    },
    "rigor": {
      "description": "How carefully the code was made, as a level name. A claim about the code as it stands.",
      "type": "string",
      "enum": ["unexamined", "skimmed", "comprehended", "engineered", "owned"]
    },
    "vouch": {
      "description": "Whether the author recommends depending on this code. A bare value, or a mapping carrying the reason.",
      "oneOf": [
        { "type": "string", "enum": ["yes", "neutral", "withheld"] },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["claim"],
          "properties": {
            "claim": { "type": "string", "enum": ["yes", "neutral", "withheld"] },
            "why": { "type": "string" }
          }
        }
      ]
    },
    "checks": {
      "description": "Optional. The individual assurance checks behind the rigor level. Any subset may be present.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "comprehended": { "$ref": "#/$defs/checkValue" },
        "quality_reviewed": { "$ref": "#/$defs/checkValue" },
        "security_reviewed": { "$ref": "#/$defs/checkValue" },
        "tested": { "$ref": "#/$defs/checkValue" },
        "owned": { "$ref": "#/$defs/checkValue" }
      }
    },
    "stages": {
      "description": "Optional. The story of the work: who did each stage, and how deliberately. Any subset of stages; any subset of fields within a stage.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "idea": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "by": { "$ref": "#/$defs/thoughtStage/properties/by" },
            "depth": { "$ref": "#/$defs/thoughtStage/properties/depth" },
            "inspired_by": {
              "description": "What the idea grew from: a fork, a predecessor, a project it succeeds. Free text, rendered into the idea sentence.",
              "type": "string",
              "minLength": 1
            }
          }
        },
        "plan": { "$ref": "#/$defs/thoughtStage" },
        "implementation": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "by": {
              "description": "Who wrote it: one actor for its whole life, or [before LLMs, since LLMs] for code whose authorship changed with the advent of AI. 'upstream' is the project named in forked_from.",
              "oneOf": [
                { "enum": ["human", "human-with-ai", "ai", "upstream"] },
                { "type": "array", "minItems": 2, "maxItems": 2, "items": { "enum": ["human", "human-with-ai", "ai", "upstream"] } }
              ]
            }
          }
        },
        "maintenance": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "by": { "enum": ["human", "human-with-ai", "ai", "none"] },
            "activity": { "enum": ["active", "dormant"] },
            "scope": { "enum": ["evolving", "complete"] }
          }
        }
      }
    },
    "notes": {
      "description": "Optional short free-text. The Notes section of the file is the usual place; this field exists for tools that prefer it inline.",
      "type": "string"
    },
    "spec": {
      "description": "The spec version this stamp is written against.",
      "type": "string",
      "enum": ["1.0"]
    },
    "assessed": {
      "description": "When the stamp was last brought up to date (YYYY-MM or YYYY-MM-DD).",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}(-\\d{2})?$"
    }
  },
  "$defs": {
    "checkValue": {
      "description": "Done-states carry the actor: yes (unstated), human, ai, human-with-ai. Plus no and not-applicable. Strings, not booleans, to avoid YAML coercion footguns. A list is [before LLMs, since LLMs]; only actors may appear in one.",
      "oneOf": [
        { "type": "string", "enum": ["yes", "human", "ai", "human-with-ai", "no", "not-applicable"] },
        { "type": "array", "minItems": 2, "maxItems": 2, "items": { "enum": ["human", "ai", "human-with-ai"] } }
      ]
    },
    "thoughtStage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "by": {
          "description": "One actor, or [before LLMs, since LLMs] for thinking that was redone with the advent of AI. 'upstream' is the project named in forked_from.",
          "oneOf": [
            { "enum": ["human", "human-with-ai", "ai", "upstream"] },
            { "type": "array", "minItems": 2, "maxItems": 2, "items": { "enum": ["human", "human-with-ai", "ai", "upstream"] } }
          ]
        },
        "depth": { "enum": ["one-shot", "considered", "deep"] }
      }
    }
  }
}
