{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "okstra/report-writer-corrections-v1.0",
  "title": "report-writer corrections ledger",
  "description": "A lead's corrective request to the report writer: field-path corrections against a base narrative. Paths use the final-report validator's grammar (schema keys joined by '.', 0-based '[i]' for array items). See .project-docs spec 2026-09-03 report-writer structured corrections.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "baseNarrativePath", "corrections"],
  "properties": {
    "schemaVersion": { "const": "1.0" },
    "baseNarrativePath": {
      "type": "string",
      "minLength": 1,
      "description": "Project-relative path of the narrative attempt the corrections apply to."
    },
    "baseNarrativeSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "context": {
      "type": "string",
      "description": "Free text for the writer to read. Not normative; not validated."
    },
    "corrections": {
      "type": "array",
      "minItems": 0,
      "items": { "$ref": "#/$defs/Correction" }
    }
  },
  "$defs": {
    "Correction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "path", "reason"],
      "properties": {
        "id": { "type": "string", "pattern": "^RC-[0-9]{3}$" },
        "kind": { "enum": ["replace", "remove", "add", "move", "rewrite"] },
        "path": { "type": "string", "minLength": 1 },
        "fromPath": { "type": "string", "minLength": 1 },
        "evidenceRefs": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "current": {},
        "replacement": {},
        "rule": { "type": "string", "minLength": 1 },
        "reason": { "type": "string", "minLength": 1 }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "enum": ["replace", "add"] } } },
          "then": { "required": ["replacement"] }
        },
        {
          "if": { "properties": { "kind": { "const": "move" } } },
          "then": { "required": ["fromPath"] }
        },
        {
          "if": { "properties": { "kind": { "const": "rewrite" } } },
          "then": { "required": ["rule"] }
        }
      ]
    },
    "RewriteResults": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baseNarrativeSha256", "replacements"],
      "properties": {
        "baseNarrativeSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "replacements": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "replacement"],
            "properties": {
              "id": { "type": "string", "pattern": "^RC-[0-9]{3}$" },
              "replacement": {}
            }
          }
        }
      }
    }
  }
}
