{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/disk-clean.schema.json",
  "title": "Disk clean",
  "description": "What POST /v1/disk-clean returns: the disk cleaner's report per category for a measure, a preview (with a confirm token) or an apply. Paths are real paths on this machine, so the route is local-only.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contractVersion",
    "mode",
    "unattended",
    "disk",
    "reclaimableBytes",
    "categories",
    "orphans"
  ],
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "mode": {
      "enum": ["measure", "preview", "applied"],
      "x-sensitivity": "none"
    },
    "unattended": {
      "type": "boolean",
      "x-sensitivity": "none",
      "description": "The server runs unattended: it measures the cleaner's unattended set only and refuses a preview and an apply."
    },
    "disk": {
      "type": "object",
      "additionalProperties": false,
      "required": ["freeBytes", "totalBytes", "expectedFreeBytes"],
      "x-sensitivity": "none",
      "properties": {
        "freeBytes": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "totalBytes": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "expectedFreeBytes": {
          "type": ["integer", "null"],
          "minimum": 0,
          "description": "Free space now plus reclaimableBytes."
        },
        "afterFreeBytes": {
          "type": ["integer", "null"],
          "minimum": 0,
          "description": "Free space measured after an apply."
        }
      }
    },
    "reclaimableBytes": {
      "type": "integer",
      "minimum": 0,
      "x-sensitivity": "none",
      "description": "What an apply of the listed categories would free; a category whose tool is running is measured but left out."
    },
    "categories": {
      "type": "array",
      "x-sensitivity": "local",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "label",
          "items",
          "bytes",
          "top",
          "more",
          "kept",
          "blocked",
          "note",
          "safe",
          "optIn"
        ],
        "properties": {
          "id": {
            "enum": [
              "derived-data",
              "repo-build",
              "xctest-devices",
              "xcode-caches",
              "archives",
              "device-support",
              "sim-unavailable",
              "sim-caches",
              "sim-device-caches",
              "sim-runtimes",
              "spm-cache",
              "pods-cache",
              "gradle-cache",
              "js-caches",
              "homebrew",
              "tmp-builds",
              "pipeline-scratch",
              "claude-scratch",
              "claude-jobs",
              "agent-worktrees",
              "dev-caches",
              "old-logs",
              "pipeline-logs",
              "ds-store",
              "trash",
              "transcripts",
              "test-artifacts"
            ]
          },
          "label": {
            "type": "string"
          },
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "top": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["path", "bytes"],
              "properties": {
                "path": {
                  "type": "string"
                },
                "bytes": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            "description": "The largest items, real paths and sizes."
          },
          "more": {
            "type": "integer",
            "minimum": 0
          },
          "kept": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            },
            "description": "How many items were kept, per reason."
          },
          "blocked": {
            "type": ["string", "null"],
            "description": "Why the category is measured but not applied (its tool is running)."
          },
          "note": {
            "type": ["string", "null"]
          },
          "safe": {
            "type": "boolean",
            "description": "The cleaner's unattended-safe set."
          },
          "optIn": {
            "enum": ["trash", "transcripts", "test-artifacts", null],
            "description": "The request flag this category needs as well as its id."
          }
        }
      }
    },
    "orphans": {
      "type": "integer",
      "minimum": 0,
      "x-sensitivity": "none",
      "description": "Leftover session processes found; information only, never stopped."
    },
    "applied": {
      "type": "object",
      "additionalProperties": false,
      "required": ["removed", "failed", "freedBytes", "failures", "held"],
      "x-sensitivity": "local",
      "properties": {
        "removed": {
          "type": "integer",
          "minimum": 0
        },
        "failed": {
          "type": "integer",
          "minimum": 0
        },
        "freedBytes": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "failures": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["category", "path", "reason"],
            "properties": {
              "category": {
                "type": "string"
              },
              "path": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            }
          }
        },
        "held": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["category", "reason"],
            "properties": {
              "category": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "confirmToken": {
      "type": "string",
      "x-sensitivity": "local"
    },
    "expiresAt": {
      "type": "string",
      "format": "date-time",
      "x-sensitivity": "none"
    }
  }
}
