{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/controlled-operating-loop.schema.json",
  "title": "Wever Labs Controlled Operating Loop",
  "description": "Canonical state object for a governed agent operating loop. The loop records planner, worker, validator, exception, revision, review, and return package state while keeping release status explicit.",
  "type": "object",
  "required": [
    "schema_version",
    "loop_id",
    "rail",
    "status",
    "operator_review",
    "steps",
    "return_package"
  ],
  "properties": {
    "schema_version": {
      "const": "controlled_operating_loop.v1"
    },
    "loop_id": {
      "type": "string"
    },
    "rail": {
      "type": "string",
      "enum": [
        "packetops",
        "financeops",
        "energyops",
        "diligenceops",
        "tokenops",
        "distributionops",
        "scout",
        "contractops_discovery"
      ]
    },
    "workflow_type": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "started",
        "running",
        "needs_revision",
        "exception_open",
        "needs_operator_review",
        "approved_for_return",
        "complete",
        "failed"
      ]
    },
    "attempts": {
      "type": "integer",
      "minimum": 0
    },
    "max_attempts": {
      "type": "integer",
      "minimum": 1
    },
    "success_criteria": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "operator_boundary": {
      "type": "string"
    },
    "operator_approval_required": {
      "type": "boolean"
    },
    "orchestrator": {
      "type": "object"
    },
    "agents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "role",
          "responsibility"
        ],
        "properties": {
          "role": {
            "type": "string"
          },
          "responsibility": {
            "type": "string"
          }
        }
      }
    },
    "steps": {
      "type": "array",
      "items": {
        "$ref": "https://weverlabs.com/schemas/controlled-operating-loop-step.schema.json"
      }
    },
    "validation": {
      "type": "object"
    },
    "exceptions": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "revision_feedback": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "return_package": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "proof_objects": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "next_action": {
      "type": "string"
    }
  },
  "additionalProperties": true
}
