{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/gc.schema.json",
  "title": "Garbage collect",
  "description": "What POST /v1/gc returns: every candidate the collectors would remove with a confirm token (step 1, `gc-plan.mjs preview`), or what was removed (step 2, `gc-plan.mjs apply` over exactly the previewed items). An item a collector declined comes back in failed with the reason. Paths are dropped under redact.",
  "type": "object",
  "properties": {
    "contractVersion": {
      "type": "string",
      "description": "Contract version that produced the body."
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/preview"
    },
    {
      "$ref": "#/$defs/result"
    }
  ],
  "$defs": {
    "preview": {
      "type": "object",
      "additionalProperties": false,
      "required": ["contractVersion", "items", "totalKb", "confirmToken", "expiresAt"],
      "properties": {
        "contractVersion": {
          "type": "string",
          "pattern": "^1\\.[0-9]+\\.[0-9]+$",
          "x-sensitivity": "none"
        },
        "items": {
          "type": "array",
          "x-sensitivity": "none",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["kind", "sizeKb", "reason"],
            "properties": {
              "kind": {
                "enum": ["tmp", "worktrees", "refs", "abandoned"]
              },
              "path": {
                "type": "string",
                "x-sensitivity": "local"
              },
              "sizeKb": {
                "type": "integer",
                "minimum": 0
              },
              "reason": {
                "type": "string"
              }
            }
          }
        },
        "totalKb": {
          "type": "integer",
          "minimum": 0,
          "x-sensitivity": "none"
        },
        "confirmToken": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}$",
          "x-sensitivity": "none",
          "description": "The confirmToken the preview returned. Single use, valid for 120 seconds, bound to the route and the run."
        },
        "expiresAt": {
          "type": "string",
          "format": "date-time",
          "x-sensitivity": "none"
        }
      }
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["contractVersion", "removed", "freedKb", "failed"],
      "properties": {
        "contractVersion": {
          "type": "string",
          "pattern": "^1\\.[0-9]+\\.[0-9]+$",
          "x-sensitivity": "none"
        },
        "removed": {
          "type": "integer",
          "minimum": 0,
          "x-sensitivity": "none"
        },
        "freedKb": {
          "type": "integer",
          "minimum": 0,
          "x-sensitivity": "none"
        },
        "failed": {
          "type": "array",
          "x-sensitivity": "none",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["reason"],
            "properties": {
              "path": {
                "type": "string",
                "x-sensitivity": "local"
              },
              "reason": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
