{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Peaks SOP Manifest",
  "type": "object",
  "required": ["id", "name", "phases", "gates"],
  "properties": {
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
    "name": { "type": "string" },
    "description": { "type": "string" },
    "phases": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string" }
    },
    "guards": {
      "type": "array",
      "description": "Optional Bash-action guards enforced by the PreToolUse hook (peaks gate enforce).",
      "items": {
        "type": "object",
        "required": ["phase", "bash"],
        "properties": {
          "phase": { "type": "string" },
          "bash": { "type": "string", "description": "JS regex tested against the Bash tool_input.command" }
        }
      }
    },
    "gates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "phase", "check"],
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
          "phase": { "type": "string" },
          "check": {
            "type": "object",
            "required": ["type"],
            "properties": {
              "type": { "type": "string", "enum": ["file-exists", "grep", "command"] },
              "path": { "type": "string" },
              "file": { "type": "string" },
              "pattern": { "type": "string" },
              "absent": { "type": "boolean", "description": "grep only: pass when the pattern is NOT found (\"must not contain X\")" },
              "run": { "type": "array", "items": { "type": "string" } },
              "expectExitZero": { "type": "boolean" }
            }
          }
        }
      }
    }
  }
}
