{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/package-manifest.schema.json",
  "title": "Arxo Core 0.1 package manifest",
  "$comment": "Source form is law.toml",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "package": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "$ref": "#/$defs/PackageName"
        },
        "version": {
          "$ref": "#/$defs/Version"
        },
        "language": {
          "$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 `pattern` enforces the shape.",
          "$comment": "SPEC §10; E-0060",
          "pattern": "^urn:[A-Za-z0-9][A-Za-z0-9-]{0,31}(?::[A-Za-z0-9._~%!$&'()*+,;=@-]+)+$"
        },
        "description": {
          "type": "string"
        },
        "defaultLanguage": {
          "type": "string"
        },
        "sourceRoots": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      },
      "required": [
        "name",
        "version",
        "language",
        "namespace"
      ]
    },
    "features": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "profiles": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Feature"
          },
          "uniqueItems": true
        },
        "enabled": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Feature"
          },
          "uniqueItems": true
        },
        "disabled": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Feature"
          },
          "uniqueItems": true
        },
        "semanticLayer": {
          "enum": [
            "L0",
            "L1",
            "L2",
            "L3"
          ],
          "description": "Semantic layer of the package. 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).",
          "$comment": "Layer model; DECISION-0007"
        }
      }
    },
    "dependencies": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/PackageName"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "$ref": "#/$defs/Version"
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "version": {
                "$ref": "#/$defs/Version"
              },
              "registry": {
                "type": "string"
              },
              "features": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/Feature"
                },
                "uniqueItems": true
              },
              "optional": {
                "type": "boolean",
                "default": false
              }
            },
            "required": [
              "version"
            ]
          }
        ]
      }
    },
    "registries": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Registry address. `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]+$"
          },
          "trustedKeys": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "uniqueItems": true
          }
        },
        "required": [
          "url"
        ]
      }
    },
    "build": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "entrypoints": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "exclude": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "diagnosticPolicy": {
          "type": "string"
        },
        "canonicalProfile": {
          "type": "string"
        }
      }
    },
    "expansions": {
      "type": "object",
      "description": "Compile-time dependencies on expansion-definition packages: each alias maps to a name, a version, and the path of the definition package relative to the consumer root. Pinned by the `expansions` section of law.lock; expansion code never lands in the compiled intermediate form (CLIR).",
      "$comment": "SPEC §279.1.8; DECISION-0126",
      "propertyNames": {
        "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
      },
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "$ref": "#/$defs/PackageName"
          },
          "version": {
            "$ref": "#/$defs/Version"
          },
          "path": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "name",
          "version",
          "path"
        ]
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "description": "Catalog metadata of the package. NOT semantics: it is never lowered into the CLIR, never enters the semantic hash, and computation never reads it. It answers \"what act is this\", not \"what follows from it\". Some fields are DERIVED from the package source declarations and a coverage gate checks them against those sources — declaring one thing while asserting another is rejected.",
      "$comment": "DECISION-0051; SPEC §209",
      "properties": {
        "act": {
          "type": "string",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
          "description": "Act name — the key of the compiled file (<act>.lawir.json), of the act test directory, of ratchets, and of the coverage-depth base. Required for packages that formalize an act; unique across the whole collection; does NOT depend on the directory path — moving the package does not change it. Not derivable.",
          "$comment": "DECISION-0084 §4"
        },
        "title": {
          "type": "string",
          "description": "Short title of the act for the catalog. Does not replace a description of coverage."
        },
        "primarySource": {
          "type": "string",
          "description": "Name of the source declaration that DERIVED fields are tracked against. Required if any derivable field is declared: for a package with several sources (poor-settlement, uefa, constitution) the derivation would otherwise be undefined."
        },
        "jurisdiction": {
          "type": "string",
          "description": "Legal order of the act. DERIVED from the primary source's `jurisdiction`. Not the same as the evaluation manifest's `jurisdictionProfile` — that one is a semantic input covered by the byte contract, while this field is descriptive. The value `none` is legitimate: doctrine and custom have no legal order.",
          "$comment": "SPEC §170"
        },
        "issuer": {
          "type": "string",
          "description": "Who issued it: a body, an organization, an author, a tradition. Separate from `jurisdiction`, because UEFA and Fannie Mae are issuers, not legal orders."
        },
        "instrument": {
          "type": "string",
          "description": "Kind of document. DERIVED from the primary source's `kind` (`sourceKind` in the CLIR)."
        },
        "legalStatus": {
          "enum": [
            "in_force",
            "repealed",
            "superseded",
            "historical_monument",
            "never_enacted",
            "doctrine",
            "scripture",
            "custom",
            "literary",
            "private",
            "educational_stub",
            "guidance",
            "audit_world",
            "historical_and_current"
          ],
          "description": "Catalog status of the package as a whole: for a single act — whether it is in force; guidance — advisory material without binding force; audit_world — an analytical composition of sources; historical_and_current — joint coverage of historical and current editions. These values do not determine the applicability of any specific norm. Per-article status lives in the depth measure and in `excluded` of articles.json and is not duplicated here. Not derivable: the `in_force` of an edition speaks to DATES, not to whether this is state law.",
          "$comment": "SPEC §33.1; SPEC §31"
        },
        "sourceFidelity": {
          "enum": [
            "pinned_official_bytes",
            "pinned_unofficial_copy",
            "dynamic_official_page",
            "abstract_only",
            "unavailable",
            "reconstruction",
            "authored_exposition"
          ],
          "description": "Quality of source pinning. The first five values are DERIVED from `materializationStatus`; `reconstruction` and `authored_exposition` go beyond it and are declared by hand: \"Zhety Zhargy\" pins an encyclopedic reconstruction, tuystyq pins an authored exposition, and both still count as pinned official bytes.",
          "$comment": "SPEC §27.2"
        },
        "verifiedAgainstSource": {
          "type": "boolean",
          "description": "Whether fragment texts have been checked against the OFFICIAL text of the act. false for educational stand-ins (health-procurement): the bytes are pinned but do not match the official text. Not derivable — this is the author's assertion about the work done."
        },
        "formalizationDepth": {
          "type": "string",
          "description": "Scope marker of the coverage-depth gate. The only value the gate recognises is `not_applicable`: an engineering methodology without jurisdiction is not measured against the legal denominator. The gate holds a closed list of such methodologies (NOT_APPLICABLE_METHODOLOGIES) — declaring the marker does not opt an act out by itself. Catalog metadata: never lowered into the CLIR, never in the semantic hash. Not derivable.",
          "$comment": "SPEC §33.1; SPEC §209"
        },
        "formalizationDepthReason": {
          "type": "string",
          "description": "Why the depth marker is declared; nonempty for `not_applicable`. Read only by the depth gate."
        },
        "formalizationDepthSources": {
          "type": "array",
          "uniqueItems": true,
          "items": {"type": "string"},
          "description": "Package-relative paths of the pinned publications whose bytes the depth gate checks against the sha256 content_hash of sources.law before it accepts `not_applicable`; must enumerate every publication local_path."
        }
      }
    },
    "editions": {
      "type": "object",
      "description": "Dated world: `as_presented` is the date as of which the world CLIR has ALREADY been projected through the edition machinery. Read only at the lock root; the lock carries it as `editionsAsPresented` under the resolution hash, and case preparation passes it as the transport field `editions_as_presented`.",
      "$comment": "DECISION-0405 §2; SPEC §31; SPEC §168.4; SPEC §168.3; E-0167",
      "additionalProperties": false,
      "required": ["as_presented"],
      "properties": {
        "as_presented": {
          "$ref": "evaluation.schema.json#/$defs/LegalTime"
        }
      }
    },
    "authoring": {
      "type": "object",
      "description": "Authoring conventions of the package. `local_imports`: `explicit` — every file declares, in a `use self::{…}` block, the authored declarations of other package files it refers to; `implicit` (default) — a `use` block is rejected (LDC-E1118). Neither the lock nor the CLIR carries this section.",
      "$comment": "SPEC §23.2; DECISION-0386",
      "additionalProperties": false,
      "properties": {
        "local_imports": {
          "enum": [
            "implicit",
            "explicit"
          ]
        }
      }
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "description": "Canon profile: exactly one; the boundary of the permitted library, read only at the lockfile root.",
      "$comment": "SPEC §170.1; DECISION-0170; SPEC §10",
      "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._+-]*$"
        },
        "registry": {
          "type": "string",
          "description": "Publisher of the profile, like the registry of a dependency.",
          "$comment": "DECISION-0168 §8"
        }
      },
      "required": [
        "id",
        "version"
      ]
    }
  },
  "required": [
    "package"
  ],
  "$defs": {
    "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",
      "pattern": "^[A-Za-z0-9_.-]+(?:/[0-9A-Za-z._+-]+)?$"
    }
  }
}
