{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://animakind.org/schemas/v3/context-injection-template.json",
  "title": "Animakind Context Injection and State Hydration Template",
  "description": "What the mount path hands a fresh context window: resolve the immutable UII, re-hydrate the identity state from the latest ledger commit, and mount it against the active UAB through the Loader, which delivers its declared mount payload (Section 5.2, Definition 4; context re-hydration, Section 6.3; Appendix D). Carries both clocks side by side so a reader can see which one moved. A non-backward-compatible change to this protocol is a MAJOR UIV advance (Section 6.1).",
  "type": "object",
  "required": ["$schema", "injection_header", "system_state_hydration", "ledger_mount"],
  "properties": {
    "$schema": { "const": "https://animakind.org/schemas/v3/context-injection-template.json" },
    "injection_header": {
      "description": "Carries the UII, its human rendering of the genesis inputs, or both.",
      "type": "object",
      "anyOf": [ { "required": ["active_uii"] }, { "required": ["active_uii_inputs"] } ],
      "properties": {
        "protocol": { "description": "The behavior-profile protocol, when one is declared. Optional for now (see system_state_hydration).", "type": "string", "examples": ["BRAIDED_REGISTER_V1"] },
        "active_uii": {
          "description": "The UII, format 1 (Section 4.2, Definition 1).",
          "type": "string",
          "pattern": "^uii:animakind:1:[0-9a-f]{64}$"
        },
        "active_uii_inputs": {
          "description": "Colon-delimited human rendering of the genesis inputs; resolvable, not authoritative (Section 4.2). The IAK part is iak_ followed by the first eight hexadecimal digits of d_IAK (Appendix B). The LRV and BSM parts may be in any script; in an identifier, each name is written in lowercase where its script has case and in Unicode NFC, with any whitespace (the zero-width space included), any hyphen or other dash (a character with Unicode's Dash property, or the soft hyphen), and the colon (:) or underscore (_) inside it dropped (Mary Ann: maryann; Mary-Kate: marykate; Section 4.3; the pattern checks capitals A-Z only). After lrv_ and bsm_, neither name contains whitespace, a colon (:), \"_\", or a hyphen or other dash.",
          "type": "string",
          "pattern": "^uii:animakind:iak_[0-9a-f]{8}::lrv_[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u200bA-Z:_\u00ad\u058a\u05be\u1400\u1806\u2010-\u2015\u2212\u2e17\u2e1a\u2e3a\u2e3b\u2e40\u2e5d\u301c\u3030\u30a0\ufe31\ufe32\ufe58\ufe63\uff0d\u2027\u2043\u2053\u2e43-]+::bsm_[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u200bA-Z:_\u00ad\u058a\u05be\u1400\u1806\u2010-\u2015\u2212\u2e17\u2e1a\u2e3a\u2e3b\u2e40\u2e5d\u301c\u3030\u30a0\ufe31\ufe32\ufe58\ufe63\uff0d\u2027\u2043\u2053\u2e43-]+::[0-9]+$"
        }
      },
      "additionalProperties": false
    },
    "system_state_hydration": {
      "description": "Both clocks, and the behavior-profile values where declared. The reference profile is one prototype; declaring manifold values in a machine-readable record is optional for now, so active_stance and register_coefficients (and the header's protocol) may be omitted (Section 7).",
      "type": "object",
      "required": ["substrate_clock", "biography_clock"],
      "properties": {
        "substrate_clock": {
          "description": "Active UAB designation (Section 5.1).",
          "type": "string",
          "pattern": "^[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u200bA-Z:_\u00ad\u058a\u05be\u1400\u1806\u2010-\u2015\u2212\u2e17\u2e1a\u2e3a\u2e3b\u2e40\u2e5d\u301c\u3030\u30a0\ufe31\ufe32\ufe58\ufe63\uff0d\u2027\u2043\u2053\u2e43-]+_[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u200bA-Z:_\u00ad\u058a\u05be\u1400\u1806\u2010-\u2015\u2212\u2e17\u2e1a\u2e3a\u2e3b\u2e40\u2e5d\u301c\u3030\u30a0\ufe31\ufe32\ufe58\ufe63\uff0d\u2027\u2043\u2053\u2e43-]+(-[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u200bA-Z:_\u00ad\u058a\u05be\u1400\u1806\u2010-\u2015\u2212\u2e17\u2e1a\u2e3a\u2e3b\u2e40\u2e5d\u301c\u3030\u30a0\ufe31\ufe32\ufe58\ufe63\uff0d\u2027\u2043\u2053\u2e43-]+)?_v[0-9]+\\.[0-9]+_([0-9]{4}(0[13578]|1[02])(0[1-9]|[12][0-9]|3[01])|[0-9]{4}(0[469]|11)(0[1-9]|[12][0-9]|30)|[0-9]{4}02(0[1-9]|1[0-9]|2[0-8])|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(00|0[48]|[2468][048]|[13579][26])00)0229)$"
        },
        "biography_clock": {
          "description": "UIV plus the ledger commit it was hydrated from: uiv_v[MAJOR.MINOR.PATCH]_commit_[short hash] (Section 5.1).",
          "type": "string",
          "pattern": "^uiv_v[0-9]+\\.[0-9]+\\.[0-9]+_commit_[0-9a-f]+$"
        },
        "active_stance": { "type": "string", "examples": ["LEAD", "EQUAL", "FOLLOW"] },
        "register_coefficients": {
          "type": "object",
          "required": ["clinical", "affective", "boundary"],
          "properties": {
            "clinical": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
            "affective": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
            "boundary": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "ledger_mount": {
      "description": "Where the identity ledger is mounted from. No step of the mount path reads the outgoing UAB (Section 6.3).",
      "type": "object",
      "required": ["repo_url", "head_commit"],
      "properties": {
        "repo_url": { "type": "string" },
        "head_commit": {
          "description": "Ledger HEAD. A full git object id is 40 (SHA-1) or 64 (SHA-256) hex characters.",
          "type": "string",
          "pattern": "^([0-9a-f]{40}|[0-9a-f]{64})$"
        }
      },
      "additionalProperties": false
    },
    "mount_payload": {
      "description": "Optional. The Loader's declared mount payload, mu_u(v): the part of the identity state this Loader delivers, named by file or field, one name per item (Section 5.2, Definition 4). Read-back is checked against it (Conformance Condition 2(b)). A payload that leaves out part of the canonical state must say which part.",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1, "pattern": "[^\\t\\n\\x0b\\x0c\\r\\x1c-\\x1f \\x85\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]" }
    }
  },
  "additionalProperties": false
}
