{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kxm.dev/project.schema.json",
  "title": "KXM project definition",
  "type": "object",
  "required": ["schema", "id", "name", "repositories"],
  "properties": {
    "schema": { "const": "kxm.project.v1" },
    "id": { "$ref": "common.schema.json#/$defs/opaqueId" },
    "name": { "type": "string", "minLength": 1, "maxLength": 120 },
    "description": { "type": "string", "maxLength": 2000 },
    "defaultWorkflow": { "$ref": "common.schema.json#/$defs/identifier" },
    "defaultExecutor": { "$ref": "common.schema.json#/$defs/identifier" },
    "defaultHarness": { "$ref": "common.schema.json#/$defs/identifier" },
    "repositories": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "items": {
        "type": "object",
        "required": ["id", "role"],
        "properties": {
          "id": { "$ref": "common.schema.json#/$defs/identifier" },
          "role": { "enum": ["control", "member"] },
          "required": { "type": "boolean", "default": true },
          "remoteIdentity": { "type": "string", "minLength": 1, "maxLength": 2048 },
          "defaultBranch": { "type": "string", "minLength": 1, "maxLength": 255 },
          "pathHint": { "$ref": "common.schema.json#/$defs/relativePath" }
        },
        "additionalProperties": false
      }
    },
    "workspace": {
      "type": "object",
      "properties": {
        "dirtySnapshot": {
          "type": "object",
          "properties": {
            "untracked": { "enum": ["bounded", "tracked-only", "ask"] },
            "maxUntrackedFileBytes": { "type": "integer", "minimum": 1, "maximum": 1073741824 },
            "maxUntrackedTotalBytes": { "type": "integer", "minimum": 1, "maximum": 10737418240 },
            "dirtySubmodules": { "const": "fail" }
          },
          "allOf": [
            {
              "if": {
                "properties": { "untracked": { "const": "bounded" } },
                "required": ["untracked"]
              },
              "then": {
                "required": ["maxUntrackedFileBytes", "maxUntrackedTotalBytes"]
              }
            }
          ],
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "sync": {
      "type": "object",
      "properties": {
        "prompts": { "const": "title-only" },
        "results": { "const": "bounded-summary" },
        "evidence": { "const": "references" },
        "artifacts": { "const": "metadata" },
        "fileChanges": { "const": "paths-only" },
        "rawLogs": { "const": false },
        "diffs": { "const": false },
        "environmentValues": { "const": false }
      },
      "additionalProperties": false
    },
    "limits": {
      "type": "object",
      "properties": {
        "maxConcurrentRuns": { "type": "integer", "minimum": 1, "maximum": 128 },
        "maxRunDurationMs": { "$ref": "common.schema.json#/$defs/durationMs" },
        "maxAgentTimeMs": { "$ref": "common.schema.json#/$defs/durationMs" },
        "agentStepTimeoutMs": { "type": "integer", "minimum": 60000, "maximum": 31536000000 }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
