{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/predicates/decision-provenance.predicate.v1.schema.json",
  "title": "RootBlocks Decision-Provenance predicate v0.1 (DRAFT)",
  "$comment": "The in-toto predicate that carries a RootBlocks governed-run decision-provenance claim, mapped losslessly from a RootBlocks Evidence v1.2 document (schemas/evidence/evidence.v1.schema.json) MINUS its `artifacts` (which become the in-toto Statement `subject`). Its predicateType URI is https://standards.rootblocks.com/predicates/decision-provenance/v0.1. The heart of the claim is `provenance` — the v1.2 seven-link chain (intent -> decision -> slice -> change -> policy -> review/merge -> agent) — so 'how a governed change reached this evidence' survives into the attestation ecosystem. This schema REFERENCES the evidence contract's own $defs by absolute $id (standardRef, check, traceRef, decisionRef, sliceId) rather than copying them, so the predicate stays faithful to evidence and this addition never edits evidence.v1.schema.json. Version v0.1 is a DRAFT / experimental, unstable public reference implementation (no formal in-toto predicate registration yet).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "sourceEvidence",
    "operation",
    "standard",
    "actor",
    "startedAt",
    "finishedAt",
    "checks",
    "redaction"
  ],
  "properties": {
    "sourceEvidence": {
      "description": "Identity of the Evidence document this predicate was derived from. `schemaVersion` pins the evidence WIRE contract (the major); the predicate itself is versioned by its predicateType URI.",
      "type": "object",
      "additionalProperties": false,
      "required": ["schemaVersion", "evidenceId"],
      "properties": {
        "schemaVersion": {
          "const": "rootblocks.evidence/v1"
        },
        "evidenceId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        }
      }
    },
    "operation": {
      "description": "The governed operation: what ran (`type`, from evidence.operationType), whether it passed (`status`), and the optional strength-of-assurance seal (from evidence.assurance).",
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "status"],
      "properties": {
        "type": {
          "enum": [
            "validate",
            "compile",
            "run",
            "debug",
            "regression-run",
            "regression-debug",
            "package",
            "sign",
            "publish",
            "cache-refresh",
            "compat-check",
            "release",
            "infra-plan",
            "infra-apply",
            "cicd-run",
            "code.merge"
          ]
        },
        "status": {
          "enum": ["passed", "failed", "inconclusive", "skipped", "stale", "blocked"]
        },
        "assurance": {
          "enum": ["observed", "proven", "traced", "enforced"]
        }
      }
    },
    "standard": {
      "description": "The Standard bundle the operation ran under (evidence.standard).",
      "$ref": "https://standards.rootblocks.com/schemas/evidence/evidence.v1.schema.json#/$defs/standardRef"
    },
    "actor": {
      "description": "The immediate runner of THIS operation (evidence.actor) — distinct from provenance.agent, which authored the change under audit.",
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "id"],
      "properties": {
        "type": {
          "enum": ["human", "agent", "tool", "system"]
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        }
      }
    },
    "startedAt": {
      "type": "string",
      "format": "date-time"
    },
    "finishedAt": {
      "type": "string",
      "format": "date-time"
    },
    "checks": {
      "description": "The checks the operation recorded (evidence.checks).",
      "type": "array",
      "items": {
        "$ref": "https://standards.rootblocks.com/schemas/evidence/evidence.v1.schema.json#/$defs/check"
      }
    },
    "traceRefs": {
      "description": "Auditable execution-trace pointers (evidence.traceRefs). Present only when the source evidence carried them.",
      "type": "array",
      "items": {
        "$ref": "https://standards.rootblocks.com/schemas/evidence/evidence.v1.schema.json#/$defs/traceRef"
      }
    },
    "provenance": {
      "description": "The v1.2 seven-link provenance chain, carried through unchanged from evidence.provenance: intent (why) -> [decision = top-level decisionRefs] -> slice (plan) -> change (repo/commit/PR) -> policy (policyHash) -> review/merge -> agent (authorship). Every sub-field is optional; process R-rules decide which links a slice-emitted document must carry.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "intent": {
          "description": "Link 1 — intent. The business/OKR objective this change serves.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "okrId": { "type": "string", "minLength": 1, "maxLength": 120 },
            "objective": { "type": "string", "minLength": 1, "maxLength": 500 },
            "businessRef": { "type": "string", "minLength": 1, "maxLength": 200 }
          }
        },
        "sliceId": {
          "description": "Link 3 — slice (plan).",
          "$ref": "https://standards.rootblocks.com/schemas/evidence/evidence.v1.schema.json#/$defs/sliceId"
        },
        "repo": {
          "description": "Link 4 — change (repo).",
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "commitSha": {
          "description": "Link 4 — change (commit).",
          "type": "string",
          "pattern": "^[a-f0-9]{7,40}$"
        },
        "pullRequest": {
          "description": "Link 4 — change (PR).",
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "policyHash": {
          "description": "Link 5 — execution (policy). Hash of the policy / Standard bundle enforced during the run.",
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        },
        "review": {
          "description": "Link 6 — review/merge.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "reviewer": { "type": "string", "minLength": 1, "maxLength": 160 },
            "decision": { "enum": ["approved", "changes-requested", "merged", "auto-merged"] },
            "reviewedAt": { "type": "string", "format": "date-time" },
            "mergeCommitSha": { "type": "string", "pattern": "^[a-f0-9]{7,40}$" }
          }
        },
        "agent": {
          "description": "Link 7 — agent. The agent identity and model that authored the change.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": { "type": "string", "minLength": 1, "maxLength": 160 },
            "model": { "type": "string", "minLength": 1, "maxLength": 160 }
          }
        },
        "sessionRef": {
          "description": "The authoring session pointer (retained from evidence v1.0).",
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "cost": {
          "description": "Link 5b — cost (metering). Carried through unchanged from evidence.provenance.cost (SPEC-030 / BL-05.SL-013): tokensIn/tokensOut = accumulated model token usage; usd = the agent's own reported price (cache-aware, not re-derived from tokens). Additive/optional; the billing/metering input survives from the signed receipt into the attestation so cost stays tamper-evident.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "tokensIn": { "type": "integer", "minimum": 0 },
            "tokensOut": { "type": "integer", "minimum": 0 },
            "usd": { "type": "number", "minimum": 0 }
          }
        }
      }
    },
    "decisionRefs": {
      "description": "Link 2 — decision. The DEC/INS ids that authorized the work (evidence.decisionRefs).",
      "type": "array",
      "items": {
        "$ref": "https://standards.rootblocks.com/schemas/evidence/evidence.v1.schema.json#/$defs/decisionRef"
      }
    },
    "redaction": {
      "description": "Which redaction rules were applied, so what is withheld is itself auditable (evidence.redaction).",
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "rules"],
      "properties": {
        "status": {
          "enum": ["applied", "not-needed", "failed"]
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  }
}
