{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/constitution.schema.json",
  "title": "Multi-Agent Pipeline  -  project constitution",
  "description": "The machine-readable twin of a project's constitution.md: the invariant rules every requirement and task of that project is held to (security, accessibility, architecture, licensing). Written by /multi-agent:analysis to ~/.claude/knowledge/<project>/constitution.json (multi-agent-refs/features/constitution.md), checked by constitution.mjs check, read by spec-consistency-gate.mjs. Each rule carries exactly one source with the research engine's labels: repo (a file in the repository, ref `path` or `path:line`), evidence (a fetched standards document, tracker item or page, ref a URL or id) or inference (reasoning, ref the one-line rationale). An inference-sourced rule is always proposed: only a rule a person or a source stated can bind.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "rules"],
  "properties": {
    "version": { "type": "integer", "const": 1 },
    "project": {
      "type": "string",
      "minLength": 1,
      "description": "The knowledge-store key: the main checkout's directory name, or the analysis name slug for a run with no repository."
    },
    "greenfield": {
      "type": "boolean",
      "description": "True when no repository was selected (analysis platform `none`): no rule can carry the repo label."
    },
    "generatedAt": { "type": "string", "format": "date-time" },
    "rules": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "category", "text", "source", "status"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^CON-(SEC|A11Y|ARCH|LIC)-[0-9]{2,3}$",
            "description": "Stable id a requirement or task cites. The middle segment names the category: SEC security, A11Y accessibility, ARCH architecture, LIC licensing."
          },
          "category": { "enum": ["security", "accessibility", "architecture", "licensing"] },
          "text": { "type": "string", "minLength": 1 },
          "source": {
            "type": "object",
            "additionalProperties": false,
            "required": ["label", "ref"],
            "properties": {
              "label": { "enum": ["evidence", "repo", "inference"] },
              "ref": { "type": "string", "minLength": 1 }
            }
          },
          "status": {
            "enum": ["binding", "proposed"],
            "description": "binding: spec-consistency-gate.mjs fails a requirement or task that waives it. proposed: reported only, until a person adopts it."
          }
        },
        "if": {
          "properties": { "source": { "properties": { "label": { "const": "inference" } } } }
        },
        "then": { "properties": { "status": { "const": "proposed" } } }
      }
    }
  }
}
