{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/repo-profile.schema.json",
  "title": "Repo Profile",
  "description": "Per-repo project profile: the conventions, owned paths, generators, commands and hooks a generic skill needs to act correctly in one specific repo. Derived from the repo itself by pipeline/scripts/repo-profile.mjs, confirmed once by the user, and stored at ~/.claude/projects/{slug}/repo-profile.json with mode 0600. Never written inside the repo and never committed. Every role carries its value, where it came from (derived | confirmed | manual), the evidence behind it (file:line, commit:<sha> or git:<ref>) and a confidence. A null value means the role could not be derived; consumers treat it as absent and keep their default.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "repoRoot",
    "repoHead",
    "derivedAt",
    "confirmedAt",
    "repo",
    "commit",
    "build",
    "test",
    "lint",
    "ownedPaths",
    "generators",
    "resourceSource",
    "accessors",
    "di",
    "module",
    "mock",
    "hooks",
    "requiredChecks",
    "docs",
    "inRepoSkills"
  ],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "1.0.0"
    },
    "repoRoot": {
      "type": "string",
      "minLength": 1,
      "description": "Absolute path of the main checkout the profile describes. Worktrees of the same repo share it."
    },
    "repoHead": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[0-9a-f]{40}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "derivedAt": {
      "type": "string",
      "format": "date-time"
    },
    "confirmedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "derivation": {
      "type": "object",
      "additionalProperties": false,
      "description": "How the draft was produced, so a re-derive can use the same settings.",
      "properties": {
        "botPattern": {
          "type": "string"
        },
        "historyWindow": {
          "type": "integer",
          "minimum": 1
        },
        "durationMs": {
          "type": "integer",
          "minimum": 0
        },
        "conventions": {
          "type": "boolean",
          "description": "True when an extract-conventions.sh report was folded in."
        }
      }
    },
    "repo": {
      "type": "object",
      "additionalProperties": false,
      "required": ["workBranch", "defaultBranch"],
      "properties": {
        "workBranch": {
          "type": "object",
          "description": "Branch feature work targets: pull_request branch filters in CI, else the most active integration branch.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "defaultBranch": {
          "type": "object",
          "description": "origin/HEAD.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "commit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["format"],
      "properties": {
        "format": {
          "type": "object",
          "description": "Commit subject convention from recent non-merge, non-bot commits.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "ticketPosition",
                    "ticketStyle",
                    "scopeRequired",
                    "conventional",
                    "example",
                    "sampleSize"
                  ],
                  "properties": {
                    "ticketPosition": {
                      "enum": ["prefix", "suffix", "none"]
                    },
                    "ticketStyle": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Template of the ticket token with KEY-123 as the placeholder, e.g. [KEY-123], (KEY-123), KEY-123:, #123."
                    },
                    "scopeRequired": {
                      "type": "boolean"
                    },
                    "conventional": {
                      "type": "boolean",
                      "description": "Majority of subjects start with type: or type(scope):."
                    },
                    "example": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "sampleSize": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "build": {
      "type": "object",
      "description": "Build command, exact flags kept.",
      "additionalProperties": false,
      "required": ["value", "source", "evidence", "confidence"],
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["command", "source"],
              "properties": {
                "command": {
                  "type": "string",
                  "minLength": 1
                },
                "source": {
                  "type": "string",
                  "minLength": 1,
                  "description": "File the command was read from."
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "$ref": "#/$defs/source"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "test": {
      "type": "object",
      "description": "Test command and test plans.",
      "additionalProperties": false,
      "required": ["value", "source", "evidence", "confidence"],
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["command", "plans"],
              "properties": {
                "command": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "plans": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "$ref": "#/$defs/source"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "lint": {
      "type": "object",
      "description": "Lint command.",
      "additionalProperties": false,
      "required": ["value", "source", "evidence", "confidence"],
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["command"],
              "properties": {
                "command": {
                  "type": "string",
                  "minLength": 1
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "$ref": "#/$defs/source"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "ownedPaths": {
      "type": "array",
      "description": "Paths an automated account owns. Hand edits there are reverted or rejected.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["glob", "owner", "source", "evidence", "confidence"],
        "properties": {
          "glob": {
            "type": "string",
            "minLength": 1
          },
          "owner": {
            "type": "string",
            "minLength": 1,
            "description": "The author(s) that own the path: a regular expression when it starts with ^ or ends with $, otherwise one literal name or e-mail compared exactly (a name such as sync[bot] needs no escaping).",
            "format": "regex"
          },
          "bypass": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "minProperties": 1,
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1
                  },
                  "author": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "commits": {
            "type": "integer",
            "minimum": 0
          },
          "basis": {
            "enum": ["history", "workflow", "history+workflow"],
            "description": "What the rule rests on: commit history alone, a CI workflow that enforces it, or both. A history-only rule is at most medium and an attended run honours it only once confirmed."
          },
          "source": {
            "$ref": "#/$defs/source"
          },
          "evidence": {
            "$ref": "#/$defs/evidence"
          },
          "confidence": {
            "$ref": "#/$defs/confidence"
          },
          "note": {
            "type": "string"
          },
          "except": {
            "type": "array",
            "description": "Globs under this path that stay open to hand edits (a case arm or filter the owning job exempts).",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          }
        }
      }
    },
    "generators": {
      "type": "array",
      "description": "Generated trees: output glob, the input that feeds it, the regeneration command, and whether input and output change in the same commit.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "output",
          "input",
          "command",
          "sameCommit",
          "source",
          "evidence",
          "confidence"
        ],
        "properties": {
          "output": {
            "type": "string",
            "minLength": 1
          },
          "input": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "command": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "check": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "description": "A CI step that only verifies the output is current (--check, --verify, --dry-run); running it regenerates nothing."
          },
          "sameCommit": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          },
          "stamp": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "source": {
            "$ref": "#/$defs/source"
          },
          "evidence": {
            "$ref": "#/$defs/evidence"
          },
          "confidence": {
            "$ref": "#/$defs/confidence"
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "resourceSource": {
      "type": "object",
      "description": "Where synced resources are authored, and the per-domain command to author them.",
      "additionalProperties": false,
      "required": ["value", "source", "evidence", "confidence"],
      "properties": {
        "value": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["repo", "authoring"],
              "properties": {
                "repo": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "authoring": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "$ref": "#/$defs/source"
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "accessors": {
      "type": "object",
      "additionalProperties": false,
      "required": ["localization", "accessibility", "testingId", "tokens"],
      "properties": {
        "localization": {
          "type": "object",
          "description": "Root type of the localization accessor, e.g. the <Root> in <Root>.<Seg>.<Seg>.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "accessibility": {
          "type": "object",
          "description": "Accessibility identifier convention.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "testingId": {
          "type": "object",
          "description": "Root type of the testing identifier accessor.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "tokens": {
          "type": "object",
          "description": "Root types of design token accessors.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "di": {
      "type": "object",
      "additionalProperties": false,
      "required": ["registrarSuffix", "registerMethod", "injectAttribute"],
      "properties": {
        "registrarSuffix": {
          "type": "object",
          "description": "File/type suffix of per-module dependency registrars.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "registerMethod": {
          "type": "object",
          "description": "Method a registrar implements to perform the registration.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "validateMethod": {
          "type": "object",
          "description": "Method a registrar implements to check that what its units read is wired (validate, verify, check). Optional: profiles derived before it existed omit it.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "injectAttribute": {
          "type": "object",
          "description": "Property wrapper or annotation used for injection.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "module": {
      "type": "object",
      "additionalProperties": false,
      "required": ["layout", "validator"],
      "properties": {
        "layout": {
          "type": "object",
          "description": "Glob of repeated module manifests.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "validator": {
          "type": "object",
          "description": "Script or command that validates module structure.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "mock": {
      "type": "object",
      "additionalProperties": false,
      "required": ["system", "customDir"],
      "properties": {
        "system": {
          "type": "object",
          "description": "Mocking approach: a framework name or fixture-tree.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        },
        "customDir": {
          "type": "object",
          "description": "Hand-authored mock/fixture tree that sits beside a generated one.",
          "additionalProperties": false,
          "required": ["value", "source", "evidence", "confidence"],
          "properties": {
            "value": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "source": {
              "$ref": "#/$defs/source"
            },
            "evidence": {
              "$ref": "#/$defs/evidence"
            },
            "confidence": {
              "$ref": "#/$defs/confidence"
            },
            "note": {
              "type": "string"
            }
          }
        }
      }
    },
    "hooks": {
      "type": "array",
      "description": "Git hooks the repo installs, and what they do to a commit.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "path", "sideEffects", "source", "evidence", "confidence"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          },
          "sideEffects": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "enum": ["amends-commit", "stages-files", "writes-files", "network"]
            }
          },
          "source": {
            "$ref": "#/$defs/source"
          },
          "evidence": {
            "$ref": "#/$defs/evidence"
          },
          "confidence": {
            "$ref": "#/$defs/confidence"
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "requiredChecks": {
      "type": "array",
      "description": "CI checks the repo documents as required.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "source", "evidence", "confidence"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "$ref": "#/$defs/source"
          },
          "evidence": {
            "$ref": "#/$defs/evidence"
          },
          "confidence": {
            "$ref": "#/$defs/confidence"
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "docs": {
      "type": "object",
      "additionalProperties": false,
      "required": ["authoritative"],
      "properties": {
        "authoritative": {
          "type": "array",
          "description": "Markdown files the repo's CLAUDE.md links to and that exist.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["path", "source", "evidence", "confidence"],
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1
              },
              "source": {
                "$ref": "#/$defs/source"
              },
              "evidence": {
                "$ref": "#/$defs/evidence"
              },
              "confidence": {
                "$ref": "#/$defs/confidence"
              },
              "note": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "inRepoSkills": {
      "type": "array",
      "description": "Skills the repo ships under .claude/skills/.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "path", "trigger", "source", "evidence", "confidence"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string"
          },
          "trigger": {
            "enum": ["explicit", "auto"]
          },
          "source": {
            "$ref": "#/$defs/source"
          },
          "evidence": {
            "$ref": "#/$defs/evidence"
          },
          "confidence": {
            "$ref": "#/$defs/confidence"
          },
          "note": {
            "type": "string"
          }
        }
      }
    }
  },
  "$defs": {
    "source": {
      "enum": ["derived", "confirmed", "manual"]
    },
    "confidence": {
      "enum": ["high", "medium", "low"]
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^(commit:[0-9a-f]{7,40}|git:\\S.*|[^:\\s][^:]*(:[0-9]+)?)$"
      }
    }
  }
}
