{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "autonomy-envelope.json",
  "title": "Autonomy Envelope",
  "description": "Per-agent per-task-type approval-state record. Frontmatter section of `agents/<paName>/autonomy-envelope.md`. Body is markdown table + history log.",
  "type": "object",
  "required": ["agent", "owner", "updated", "taskTypes"],
  "additionalProperties": false,
  "properties": {
    "agent": {
      "type": "string",
      "minLength": 1,
      "description": "The agent's short name (matches agents/<name>/ directory)."
    },
    "owner": {
      "type": "string",
      "minLength": 1,
      "description": "The operator name (informational; the operator whose PA this envelope belongs to)."
    },
    "updated": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of last change."
    },
    "taskTypes": {
      "type": "array",
      "description": "One entry per task type. Order is operator-facing; the CLI preserves it.",
      "items": {
        "type": "object",
        "required": ["id", "label", "state"],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]*$",
            "description": "Task-type slug (e.g. li-comment-draft, code-dispatch, git-commit-push)."
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "description": "Human-readable name."
          },
          "state": {
            "type": "string",
            "enum": ["fullyApproved", "checkBeforeCommitting", "needsFullSupervision"],
            "description": "Approval state for this task type."
          },
          "stateSince": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of when this state was set."
          },
          "operatorNote": {
            "type": "string",
            "description": "Free-text reason from the operator."
          }
        }
      }
    }
  }
}
