{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://loop-architecture.com/spec/loop-architecture.schema.json",
  "title": "LoopArchitecture",
  "description": "A Loop Architecture: many systems and many loops in one document.",
  "type": "object",
  "required": ["id", "systems", "loops"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$", "description": "Identifier for this architecture." },
    "name": { "type": "string", "description": "Human-readable name (defaults to id)." },
    "systems": {
      "type": "array",
      "description": "The systems loops read from and write back to.",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
          "name": { "type": "string", "description": "Human-readable name (defaults to id)." },
          "description": { "type": "string" },
          "url": { "type": "string", "description": "Homepage/console URL. Its favicon is fetched as the system's icon in diagrams." },
          "repository": { "type": "string", "description": "Git repo URL (→ routine repositories)." },
          "connector": { "type": "string", "description": "MCP connector name (→ routine connectors)." }
        }
      }
    },
    "loops": {
      "type": "array",
      "description": "The loops. Each loop uses (observe) systems and writes back to (act) systems.",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "observe", "act", "prompt"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "owner": { "type": "string" },
          "trigger": {
            "description": "One trigger, or a list of triggers. Each is a 5-field cron ('0 6 * * *'), an ISO timestamp for a one-off, a GitHub event ('pull_request.opened'), or 'manual'. Defaults to 'manual'.",
            "oneOf": [
              { "type": "string" },
              { "type": "array", "items": { "type": "string" }, "minItems": 1 }
            ]
          },
          "observe": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string" },
            "description": "System ids the loop reads from."
          },
          "act": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string" },
            "description": "System ids the loop writes back to."
          },
          "prompt": { "type": "string", "description": "The instructions the loop runs, what it should do each turn. Included verbatim in the published routine prompt." },
          "model": { "type": "string" },
          "tools": { "type": "array", "items": { "type": "string" } }
        }
      }
    }
  }
}
