{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/uwmd-block.schema.json",
  "title": "UW Markdown Section Block (Format 3.0)",
  "description": "Bare section payload with inline nested _meta first, and optional _role, _overrides and _notes. Format §2.4–§2.6, RFC 0081 G2. RFC0093 allocates META-01 for misplaced _meta, present invalid/mismatched section and required absent/nonobject quality; existing predicates below are unchanged. Lexical source order and equality to an external annotation are document requirements, not expressible in JSON Schema. RFC0095 allocates closed META-05/06; root conditions account for every stated override assertion without selecting paths. Reference dates use an exact Gregorian domain independent of format plugins.",
  "type": "object",
  "required": [
    "_meta"
  ],
  "additionalProperties": true,
  "properties": {
    "_role": {
      "enum": [
        "primary",
        "senior",
        "junior",
        "summary",
        "detail",
        "component"
      ],
      "description": "Optional signed scalar block role (RFC 0040); not an _meta member."
    },
    "_meta": {
      "$ref": "#/$defs/UWMeta"
    },
    "_overrides": {
      "type": "array",
      "description": "Leaf metadata exceptions (Format §2.5f). Included in the block digest; a matching path wins over block-level metadata. RFC0095 META-05 validates only its closed container/entry/member predicates; SRC owns source/resolution. Stated reference-resolution assertions require canonical carriers even when their paths are shadowed or duplicate.",
      "items": {
        "type": "object",
        "required": [
          "path"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "Dot-notated path relative to the block content root (e.g. 'units[7].current_rent')."
          },
          "confidence": {
            "enum": [
              "high",
              "medium",
              "low"
            ]
          },
          "source": {
            "type": "string",
            "pattern": "^(manual|(agent|document|system|institution)/[A-Za-z0-9][A-Za-z0-9._-]*)$",
            "description": "Actor override for this field (RFC 0031 actor grammar)."
          },
          "resolution": {
            "$ref": "#/$defs/ResolutionTag"
          },
          "reason": {
            "enum": [
              "illegible",
              "missing",
              "overridden",
              "estimated",
              "computed"
            ]
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "_notes": {
      "type": [
        "string",
        "null"
      ],
      "description": "Free-text annotation. Never validated, never consumed by agents."
    }
  },
  "$defs": {
    "UWMeta": {
      "type": "object",
      "required": [
        "section",
        "provenance",
        "quality",
        "lifecycle"
      ],
      "additionalProperties": true,
      "properties": {
        "section": {
          "type": "string",
          "description": "REQUIRED; MUST equal the fence annotation section."
        },
        "provenance": {
          "type": "object",
          "required": [
            "source",
            "actor",
            "timestamp"
          ],
          "additionalProperties": true,
          "properties": {
            "source": {
              "type": "string",
              "pattern": "^(manual|(agent|document|system|institution)/[A-Za-z0-9][A-Za-z0-9._-]*)$",
              "minLength": 1,
              "description": "Actor grammar (Format §2.6). Resolution tags here are SRC-02; other out-of-grammar values are SRC-01, always errors."
            },
            "resolution": {
              "$ref": "#/$defs/ResolutionTag"
            },
            "actor": {
              "type": "string",
              "minLength": 1,
              "description": "The principal that initiated the write. Distinct from source: source is the policy-vocabulary identity of the writer, actor is who asked for the write."
            },
            "agent_id": {
              "type": [
                "string",
                "null"
              ],
              "description": "REQUIRED when source matches 'agent/*'."
            },
            "agent_version": {
              "type": [
                "string",
                "null"
              ]
            },
            "timestamp": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:[02468][048]|[13579][26])00)-02-29|[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:0[1-9]|[12][0-9]|3[01])|(?:04|06|09|11)-(?:0[1-9]|[12][0-9]|30)|02-(?:0[1-9]|1[0-9]|2[0-8])))T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]+)?Z(?![\\s\\S])",
              "description": "Exact T1B UTC-Z (RFC0094): ASCII YYYY-MM-DDTHH:mm:ss[.digits]Z, Gregorian year0000–9999, seconds00–59, uppercase T/Z and optional nonempty fraction. Full-string match; no offsets, normalization or host date parser authority. Present invalid values are META-04/error; existing absence diagnostics are unchanged."
            },
            "notes": {
              "type": [
                "string",
                "null"
              ]
            },
            "market_data_ref": {
              "type": "object",
              "required": [
                "document_id",
                "as_of",
                "digest"
              ],
              "description": "RFC0095: required when canonical provenance.resolution or any stated object override resolution is market_data_accepted; both references use symmetric assertion accounting. Unknown children remain admitted.",
              "properties": {
                "document_id": {
                  "type": "string"
                },
                "as_of": {
                  "$ref": "#/$defs/MarketReferenceDate"
                },
                "digest": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])"
                },
                "rationale": {
                  "type": "string"
                }
              }
            },
            "inherited_from": {
              "type": "object",
              "required": [
                "document_id",
                "digest",
                "distance"
              ],
              "description": "RFC0095: required when canonical provenance.resolution or any stated object override resolution is inherited_assumption; both references use symmetric assertion accounting. Unknown children remain admitted.",
              "properties": {
                "document_id": {
                  "type": "string"
                },
                "digest": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}(?![\\s\\S])"
                },
                "distance": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          }
        },
        "quality": {
          "type": "object",
          "required": [
            "confidence",
            "human_review_required"
          ],
          "additionalProperties": true,
          "properties": {
            "confidence": {
              "enum": [
                "high",
                "medium",
                "low"
              ]
            },
            "human_review_required": {
              "type": "boolean"
            },
            "flags": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "partial": {
              "type": "boolean",
              "description": "True when at least one field inside the block is missing or unknown. When true, the block-level _overrides SHOULD enumerate which paths and why."
            },
            "provisional": {
              "type": "boolean",
              "description": "True when the entire block is a placeholder derived from defaults rather than observed data. Stronger than confidence: 'low'."
            }
          },
          "not": {
            "required": [
              "field_overrides"
            ],
            "description": "Per-field exceptions are stated only in block-level _overrides."
          }
        },
        "lifecycle": {
          "type": "object",
          "required": [
            "revision",
            "superseded"
          ],
          "additionalProperties": true,
          "properties": {
            "revision": {
              "type": "integer",
              "minimum": 1,
              "description": "1-based supersede-chain position. Present invalid revision is META-04/error (RFC0094); no new maximum or chain diagnostic is allocated."
            },
            "superseded": {
              "type": "boolean",
              "description": "True on every block that is not the chain head."
            }
          }
        },
        "integrity": {
          "type": "object",
          "additionalProperties": true,
          "description": "Cryptographic / structural verification. The whole sub-object is optional: integrity remains opt-in.",
          "properties": {
            "algorithm": {
              "enum": [
                "sha256"
              ],
              "description": "Absent means sha256, the only admitted block hash algorithm. The whole _meta object is outside the digest."
            },
            "input_hash": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^(sha256:[0-9a-f]{64})?$"
            },
            "content_hash": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "Lowercase hex SHA-256 of UTF-8 JCS of the block with its _meta member removed (Protocol §V.9)."
            },
            "parent_hash": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^([0-9a-f]{64})?$",
              "description": "RFC 0085: null or absent on the first retained hashed-chain block; otherwise the immediately prior retained content_hash."
            },
            "signature": {
              "type": "object",
              "required": [
                "alg",
                "kid",
                "sig",
                "signed_at"
              ],
              "additionalProperties": false,
              "description": "Detached signature over content_hash, section, actor, timestamp, kid and signed_at (Protocol §V.11); requires content_hash (INT-05).",
              "properties": {
                "alg": {
                  "enum": [
                    "ed25519",
                    "es256",
                    "es384"
                  ]
                },
                "kid": {
                  "type": "string",
                  "minLength": 1
                },
                "sig": {
                  "type": "string",
                  "pattern": "^[A-Za-z0-9_-]+$"
                },
                "signed_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "v": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "not": {
        "required": [
          "section_id"
        ]
      }
    },
    "ResolutionTag": {
      "enum": [
        "user_input",
        "user_override",
        "inherited_assumption",
        "investor_profile",
        "market_data",
        "market_data_accepted",
        "ai_extracted",
        "agent_computed",
        "asset_class_default",
        "scenario_default",
        "global_default",
        "system_default"
      ],
      "description": "Closed resolution vocabulary (Format §2.6). Unknown values are SRC-03. manual is actor-only."
    },
    "MarketReferenceDate": {
      "type": "string",
      "pattern": "^(?!0000)(?:[0-9]{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12][0-9]|3[01])|(?:0[469]|11)-(?:0[1-9]|[12][0-9]|30)|02-(?:0[1-9]|1[0-9]|2[0-8]))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)(?![\\s\\S])",
      "description": "Whole ASCII YYYY-MM-DD, valid Gregorian date, years 0001–9999; no trimming or normalization. RFC 0095 U3."
    }
  },
  "examples": [
    {
      "_meta": {
        "section": "property",
        "provenance": {
          "source": "manual",
          "actor": "analyst@example.com",
          "agent_id": null,
          "agent_version": null,
          "timestamp": "2026-09-01T10:00:00Z",
          "notes": null
        },
        "quality": {
          "confidence": "high",
          "human_review_required": false,
          "flags": [],
          "partial": false,
          "provisional": false
        },
        "lifecycle": {
          "revision": 1,
          "superseded": false
        }
      },
      "_notes": null,
      "total_units": 100,
      "year_built": 2005,
      "building_class": "B+"
    }
  ],
  "not": {
    "required": [
      "section_id"
    ]
  },
  "allOf": [
    {
      "if": {
        "allOf": [
          {
            "required": [
              "_meta"
            ],
            "properties": {
              "_meta": {
                "type": "object",
                "required": [
                  "provenance",
                  "lifecycle"
                ],
                "properties": {
                  "provenance": {
                    "type": "object"
                  },
                  "lifecycle": {
                    "type": "object"
                  }
                }
              }
            },
            "not": {
              "required": [
                "section_id"
              ]
            }
          },
          {
            "required": [
              "_meta"
            ],
            "properties": {
              "_meta": {
                "type": "object",
                "required": [
                  "provenance"
                ],
                "properties": {
                  "provenance": {
                    "required": [
                      "source"
                    ],
                    "properties": {
                      "source": {
                        "type": "string",
                        "pattern": "^agent/[A-Za-z0-9][A-Za-z0-9._-]*(?![\\s\\S])"
                      }
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "then": {
        "properties": {
          "_meta": {
            "properties": {
              "provenance": {
                "required": [
                  "agent_id"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "allOf": [
          {
            "required": [
              "_meta"
            ],
            "properties": {
              "_meta": {
                "type": "object",
                "required": [
                  "provenance",
                  "lifecycle"
                ],
                "properties": {
                  "provenance": {
                    "type": "object"
                  },
                  "lifecycle": {
                    "type": "object"
                  }
                }
              }
            },
            "not": {
              "required": [
                "section_id"
              ]
            }
          },
          {
            "anyOf": [
              {
                "required": [
                  "_meta"
                ],
                "properties": {
                  "_meta": {
                    "type": "object",
                    "required": [
                      "provenance"
                    ],
                    "properties": {
                      "provenance": {
                        "type": "object",
                        "required": [
                          "resolution"
                        ],
                        "properties": {
                          "resolution": {
                            "const": "inherited_assumption"
                          }
                        }
                      }
                    }
                  }
                }
              },
              {
                "required": [
                  "_overrides"
                ],
                "properties": {
                  "_overrides": {
                    "type": "array",
                    "contains": {
                      "type": "object",
                      "required": [
                        "resolution"
                      ],
                      "properties": {
                        "resolution": {
                          "const": "inherited_assumption"
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      },
      "then": {
        "properties": {
          "_meta": {
            "properties": {
              "provenance": {
                "required": [
                  "inherited_from"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "allOf": [
          {
            "required": [
              "_meta"
            ],
            "properties": {
              "_meta": {
                "type": "object",
                "required": [
                  "provenance",
                  "lifecycle"
                ],
                "properties": {
                  "provenance": {
                    "type": "object"
                  },
                  "lifecycle": {
                    "type": "object"
                  }
                }
              }
            },
            "not": {
              "required": [
                "section_id"
              ]
            }
          },
          {
            "anyOf": [
              {
                "required": [
                  "_meta"
                ],
                "properties": {
                  "_meta": {
                    "type": "object",
                    "required": [
                      "provenance"
                    ],
                    "properties": {
                      "provenance": {
                        "type": "object",
                        "required": [
                          "resolution"
                        ],
                        "properties": {
                          "resolution": {
                            "const": "market_data_accepted"
                          }
                        }
                      }
                    }
                  }
                }
              },
              {
                "required": [
                  "_overrides"
                ],
                "properties": {
                  "_overrides": {
                    "type": "array",
                    "contains": {
                      "type": "object",
                      "required": [
                        "resolution"
                      ],
                      "properties": {
                        "resolution": {
                          "const": "market_data_accepted"
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      },
      "then": {
        "properties": {
          "_meta": {
            "properties": {
              "provenance": {
                "required": [
                  "market_data_ref"
                ]
              }
            }
          }
        }
      }
    }
  ]
}
