{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://eugenelim.github.io/agent-ready-repo/docs/spec/catalogue/draft/pack.schema.json",
  "title": "PackConfig",
  "description": "JSON Schema for pack.toml — pack metadata and adapter-contract configuration.",
  "type": "object",
  "additionalProperties": false,
  "required": ["pack"],
  "properties": {
    "schema": {"enum": [1]},
    "pack": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": {"type": "string"},
        "version": {"type": "string"},
        "description": {"type": "string"},
        "readme": {"type": "string"},
        "display_name": {"type": "string"},
        "license": {"type": "string"},
        "catalogue": {"type": "string"},
        "lint-seeds": {"type": "boolean"},
        "categories": {
          "type": "array",
          "items": {"type": "string"},
          "maxItems": 5
        },
        "keywords": {
          "type": "array",
          "items": {"type": "string"},
          "maxItems": 5
        },
        "maintainers": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name"],
            "properties": {
              "name": {"type": "string"},
              "email": {"type": "string"},
              "url": {"type": "string"}
            }
          }
        },
        "links": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "homepage": {"type": "string"},
            "repository": {"type": "string"},
            "documentation": {"type": "string"},
            "changelog": {"type": "string"},
            "issues": {"type": "string"},
            "icon": {"type": "string"}
          }
        },
        "metadata": {
          "type": "object",
          "description": "Open extension table — additionalProperties intentionally unrestricted."
        },
        "adapter-contract": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "version": {"type": "string"}
          }
        },
        "install": {
          "type": "object",
          "additionalProperties": false,
          "required": ["default-scope"],
          "properties": {
            "default-scope": {"enum": ["repo", "user"]},
            "allowed-scopes": {
              "type": "array",
              "minItems": 1,
              "items": {"enum": ["repo", "user", "local"]}
            },
            "user-scope-hooks": {"type": "boolean"},
            "allowed-adapters": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {"type": "string"}
            }
          },
          "if": {
            "properties": {"default-scope": {"enum": ["user"]}},
            "required": ["default-scope"]
          },
          "then": {
            "properties": {
              "allowed-scopes": {"contains": {"enum": ["user"]}}
            }
          },
          "else": {
            "properties": {
              "allowed-scopes": {"contains": {"enum": ["repo"]}}
            }
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "allowed-scopes": {"contains": {"enum": ["local"]}}
                }
              },
              "then": {
                "properties": {
                  "allowed-scopes": {"contains": {"enum": ["repo"]}}
                }
              }
            }
          ]
        },
        "evals": {
          "type": "object",
          "additionalProperties": false,
          "description": "Tier-A activation eval coverage — lists every user-triggered skill that ships evals/eval_queries.json.",
          "properties": {
            "skills": {
              "type": "array",
              "items": {"type": "string"},
              "uniqueItems": true
            }
          }
        },
        "recipes": {
          "type": "array",
          "description": "Named catalogue recipes this pack participates in.",
          "items": {"type": "string"}
        },
        "dependencies": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "required": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["catalogue", "pack", "version"],
                "properties": {
                  "catalogue": {"type": "string"},
                  "pack": {"type": "string"},
                  "version": {"type": "string"}
                }
              }
            },
            "recommended": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["catalogue", "pack", "version"],
                "properties": {
                  "catalogue": {"type": "string"},
                  "pack": {"type": "string"},
                  "version": {"type": "string"}
                }
              }
            },
            "conflicts": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["catalogue", "pack", "version"],
                "properties": {
                  "catalogue": {"type": "string"},
                  "pack": {"type": "string"},
                  "version": {"type": "string"}
                }
              }
            }
          }
        },
        "adaptation": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "infer-from": {"type": "string"},
            "substitutions": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "marker": {"type": "string"},
                  "infer-from": {"type": "string"}
                }
              }
            },
            "augmentation-points": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "target": {"type": "string"},
                  "section-marker": {"type": "string"},
                  "describe": {"type": "string"}
                }
              }
            }
          }
        },
        "seeds": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[^/].*"
          }
        },
        "runtime-dependencies": {
          "type": "array",
          "description": "External runtime dependencies required by this pack's skills.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["ecosystem", "package"],
            "properties": {
              "ecosystem": {
                "type": "string",
                "enum": ["pypi", "npm", "cargo", "go", "homebrew", "apt", "system"]
              },
              "package": {"type": "string"},
              "version": {"type": "string"},
              "optional": {"type": "boolean", "default": false},
              "skills": {
                "type": "array",
                "items": {"type": "string"}
              },
              "install": {"type": "string"},
              "note": {"type": "string"}
            }
          }
        },
        "layout": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "repo": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "parent": {"type": "string"},
                "template": {"type": "string"},
                "output_dir": {"type": "string"},
                "section": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$"}
              }
            },
            "user": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "parent": {"type": "string"},
                "template": {"type": "string"},
                "output_dir": {"type": "string"},
                "section": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$"}
              }
            }
          }
        },
        "first-value": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "audience-posture": {"type": "string", "enum": ["non-technical", "mixed", "technical"]},
            "surfaces": {"type": "array", "items": {"type": "string"}},
            "prerequisites": {"type": "array", "items": {"type": "string"}},
            "verification": {"type": "string"},
            "recovery": {"type": "string"},
            "level-b": {"type": "boolean"},
            "starter-task": {"type": "string"},
            "starter-prompt": {"type": "string"},
            "expected-result": {"type": "string"},
            "next-action": {"type": "string"},
            "tutorial": {"type": "string"},
            "writes-to-repo": {"type": "boolean"},
            "safety-gate": {"type": "string"}
          }
        },
        "integrations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "pack", "kind", "role", "consumers", "providers", "when", "purpose", "fallback"],
            "properties": {
              "id":        {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$"},
              "pack":      {"type": "string"},
              "kind":      {"type": "string", "enum": ["input", "augment", "review", "handoff"]},
              "role":      {"type": "string"},
              "consumers": {
                "type": "array",
                "minItems": 1,
                "items": {"type": "string", "pattern": "^(skill|agent|command|hook):[a-z0-9][a-z0-9-]*$"}
              },
              "providers": {
                "type": "array",
                "minItems": 1,
                "items": {"type": "string", "pattern": "^(skill|agent|command|hook):[a-z0-9][a-z0-9-]*$"}
              },
              "when":      {"type": "string", "minLength": 1},
              "purpose":   {"type": "string", "minLength": 1},
              "fallback":  {"type": "string", "minLength": 1},
              "version":   {"type": "string"}
            }
          }
        }
      },
      "if": {
        "required": ["adapter-contract"],
        "properties": {
          "adapter-contract": {
            "type": "object",
            "required": ["version"],
            "properties": {
              "version": {
                "pattern": "^0\\.([2-9]|[1-9][0-9])|^[1-9]"
              }
            }
          }
        }
      },
      "then": {
        "required": ["install"]
      }
    }
  }
}
