{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/lockfile.schema.json",
  "title": "Arxo canonical law.lock 0.3",
  "$comment": "Covers historical 0.1/0.2; 0.3 is the exact release",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "lockVersion": {
      "enum": [
        "0.1",
        "0.2",
        "0.3"
      ]
    },
    "languageSemantics": {
      "type": "string",
      "anyOf": [
        {
          "pattern": "^law\\.core/(?:0\\.1|0\\.2)(?:\\.[0-9]+)?$"
        },
        {
          "pattern": "^law\\.core/(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
        }
      ]
    },
    "root": {
      "$ref": "#/$defs/LockedPackageRef"
    },
    "packages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LockedPackage"
      }
    },
    "dependencyEdges": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DependencyEdge"
      }
    },
    "editionsAsPresented": {
      "$ref": "evaluation.schema.json#/$defs/LegalTime",
      "description": "Root `[editions] as_presented` of a dated world. Included in the resolution hash; case preparation passes it as the transport field `editions_as_presented`.",
      "$comment": "DECISION-0405 §2; SPEC §168.4; SPEC §168.3"
    },
    "resolutionHash": {
      "$ref": "#/$defs/Digest"
    },
    "resources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LockedResource"
      },
      "uniqueItems": true
    },
    "expansions": {
      "type": "array",
      "description": "Pinned expansion-definition packages. A compile-time dependency of the consumer: included in the resolution hash, never becomes a semantic import of the compiled form.",
      "$comment": "SPEC §279.1.8; DECISION-0126",
      "items": {
        "$ref": "#/$defs/LockedExpansion"
      },
      "uniqueItems": true
    },
    "semanticLayer": {
      "enum": [
        "L0",
        "L1",
        "L2",
        "L3"
      ],
      "description": "Semantic layer of the build. The field is named `semanticLayer`, not `layer`, because the short name is taken by the package profile of ontological packages. The layer is a ceiling: declaring higher than the inferred value is allowed, lower is rejected (LDC-E8101). In the lockfile it is the EFFECTIVE build layer: the maximum over the root and all pinned dependencies.",
      "$comment": "Layer model; DECISION-0007"
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "description": "Pinned canon profile: `packages` is the full expansion of profile B; the resolution hash covers the block.",
      "$comment": "SPEC §170.1; SPEC §11; DECISION-0170",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
        },
        "contentHash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "registryId": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9._-]{0,63}$",
          "description": "Registry identifier of the publisher that issued the package.",
          "$comment": "DECISION-0168 §8"
        }
      },
      "required": [
        "id",
        "version",
        "contentHash"
      ]
    }
  },
  "required": [
    "lockVersion",
    "languageSemantics",
    "root",
    "packages",
    "dependencyEdges",
    "resolutionHash"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "lockVersion": {
            "const": "0.2"
          }
        }
      },
      "then": {
        "required": [
          "resources"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "lockVersion": {
            "const": "0.3"
          }
        },
        "required": [
          "lockVersion"
        ]
      },
      "then": {
        "required": [
          "resources"
        ],
        "properties": {
          "languageSemantics": {
            "type": "string",
            "pattern": "^law\\.core/(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
          }
        }
      }
    }
  ],
  "$defs": {
    "LockedExpansion": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "consumer": {
          "$ref": "#/$defs/PackageName"
        },
        "alias": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
        },
        "name": {
          "$ref": "#/$defs/PackageName"
        },
        "version": {
          "$ref": "#/$defs/Version"
        },
        "entry": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?!/).+\\.law$"
        },
        "expansionProfile": {
          "enum": [
            "law.expansion/0.1",
            "law.expansion/0.2"
          ]
        },
        "contentHash": {
          "$ref": "#/$defs/Digest"
        }
      },
      "required": [
        "consumer",
        "alias",
        "name",
        "version",
        "entry",
        "expansionProfile",
        "contentHash"
      ]
    },
    "Digest": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+:[A-Fa-f0-9]+$"
    },
    "PackageName": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
    },
    "Version": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
    },
    "Feature": {
      "type": "string",
      "minLength": 1
    },
    "LockedResource": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "enum": [
            "parameter-dataset",
            "decision-table",
            "label-overlay",
            "calendar-dataset",
            "document",
            "case-snapshot"
          ]
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?!/).+$"
        },
        "contentHash": {
          "$ref": "#/$defs/Digest"
        },
        "capability": {
          "description": "Resource roles. A3 resources participate in compilation (compile_time); label overlays are a presentation layer outside the compiled form (presentation); calendar datasets are resolved at execution time (calendar form); case documents are evidence support whose bytes are checked against content_hash (evidence).",
          "$comment": "SPEC §218; DECISION-0070; SPEC §85; form law.calendar/0.1; DECISION-0110; SPEC §168.4; SPEC §74; DECISION-0165",
          "enum": [
            "compile_time",
            "presentation",
            "law.calendar/0.1",
            "evidence",
            "law.case-export/0.1"
          ]
        }
      },
      "required": [
        "id",
        "kind",
        "path",
        "contentHash",
        "capability"
      ]
    },
    "LockedPackageRef": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "$ref": "#/$defs/PackageName"
        },
        "version": {
          "$ref": "#/$defs/Version"
        },
        "namespace": {
          "type": "string",
          "format": "uri",
          "description": "Package namespace, a URN. The `format` keyword of Draft 2020-12 is only an annotation, so the shape is enforced by `pattern`.",
          "$comment": "SPEC §10; E-0060",
          "pattern": "^urn:[A-Za-z0-9][A-Za-z0-9-]{0,31}(?::[A-Za-z0-9._~%!$&'()*+,;=@-]+)+$"
        },
        "contentHash": {
          "$ref": "#/$defs/Digest"
        }
      },
      "required": [
        "name",
        "version",
        "namespace",
        "contentHash"
      ]
    },
    "LockedPackage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "$ref": "#/$defs/PackageName"
        },
        "version": {
          "$ref": "#/$defs/Version"
        },
        "namespace": {
          "type": "string",
          "format": "uri",
          "description": "Package namespace, a URN. The `format` keyword of Draft 2020-12 is only an annotation, so the shape is enforced by `pattern`.",
          "$comment": "SPEC §10; E-0060",
          "pattern": "^urn:[A-Za-z0-9][A-Za-z0-9-]{0,31}(?::[A-Za-z0-9._~%!$&'()*+,;=@-]+)+$"
        },
        "contentHash": {
          "$ref": "#/$defs/Digest"
        },
        "editorSourceMapHash": {
          "$ref": "#/$defs/Digest",
          "description": "Optional editor-only source-map sidecar for this pinned dependency. Its bytes are delivered as deps/<name>.editor-source-map.json and must identify this exact CLIR package before an editor may expose authored locations."
        },
        "questionCatalogHash": {
          "$ref": "#/$defs/Digest",
          "description": "Optional pinned questions-catalog sidecar, installed as deps/<package>.questions.json for case cards.",
          "$comment": "Former path analysis/questions.json"
        },
        "taskGuideCatalogHash": {
          "$ref": "#/$defs/Digest",
          "description": "Optional pinned task-guides catalog sidecar, installed as deps/<package>.task-guides.json for task guides of the dependency. Metadata only: it does not affect CLIR or evaluation semantics; the resolution hash covers the pin.",
          "$comment": "Former path analysis/task-guides.json; form law.package-task-guides/0.1; DECISION-0414"
        },
        "registryId": {
          "type": "string"
        },
        "resolverUri": {
          "type": "string",
          "format": "uri",
          "description": "Where the package was resolved from. `pattern` requires at least a URI scheme; it is not a full URI parser.",
          "$comment": "E-0060",
          "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:[^\\s]+$"
        },
        "features": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Feature"
          },
          "uniqueItems": true
        },
        "signature": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "algorithm": {
              "type": "string"
            },
            "keyId": {
              "type": "string"
            },
            "value": {
              "type": "string"
            }
          },
          "required": [
            "algorithm",
            "keyId",
            "value"
          ]
        }
      },
      "required": [
        "name",
        "version",
        "namespace",
        "contentHash",
        "features"
      ]
    },
    "DependencyEdge": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "from": {
          "$ref": "#/$defs/PackageName"
        },
        "to": {
          "$ref": "#/$defs/PackageName"
        },
        "requested": {
          "$ref": "#/$defs/Version"
        },
        "resolved": {
          "$ref": "#/$defs/Version"
        },
        "features": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Feature"
          },
          "uniqueItems": true
        }
      },
      "required": [
        "from",
        "to",
        "requested",
        "resolved",
        "features"
      ]
    }
  }
}
