{
  "$defs": {
    "Cleanup": {
      "description": "When a file class leaves the bundle; definition order is escalation order.",
      "enum": [
        "never",
        "on_success",
        "always"
      ],
      "title": "Cleanup",
      "type": "string"
    },
    "CleanupTrigger": {
      "description": "Who ran a cleanup pass.",
      "enum": [
        "driver",
        "purge"
      ],
      "title": "CleanupTrigger",
      "type": "string"
    },
    "RemovedFile": {
      "description": "One path a cleanup pass removed, recorded in the manifest.",
      "properties": {
        "path": {
          "description": "Bundle-relative posix path (``\".\"`` for the run directory itself).",
          "title": "Path",
          "type": "string"
        },
        "size": {
          "description": "Bytes freed.",
          "title": "Size",
          "type": "integer"
        },
        "file_class": {
          "$ref": "#/$defs/RunFile",
          "description": "The retention class the path matched."
        },
        "reason": {
          "$ref": "#/$defs/Cleanup",
          "description": "The rule that applied, after any ``cached_inputs`` escalation."
        },
        "cached": {
          "default": false,
          "description": "True when the file was store-sourced and re-fetchable.",
          "title": "Cached",
          "type": "boolean"
        }
      },
      "required": [
        "path",
        "size",
        "file_class",
        "reason"
      ],
      "title": "RemovedFile",
      "type": "object"
    },
    "RetentionPolicy": {
      "description": "One [`Cleanup`][] rule per bundle file class; the default keeps everything the run cannot re-fetch.",
      "properties": {
        "geometry": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "The ``geometry.step`` copy pinned into the bundle."
        },
        "gmsh_mesh": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "The gmsh ``.msh`` (only in the bundle for a parametric geometry)."
        },
        "elmer_mesh": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "ElmerGrid's ``mesh.header/nodes/elements/boundary``."
        },
        "partitioning": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "The ``partitioning.<n>/`` directory and its log from a parallel solve."
        },
        "sif": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "``case.sif`` and ``ELMERSOLVER_STARTINFO``."
        },
        "fields": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "The VTU/PVTU field output, master and per-rank pieces together."
        },
        "scalars": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "SaveScalars ``.dat`` exports and their ``.names`` sidecars."
        },
        "logs": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "ElmerGrid/ElmerSolver logs, ``convergence.jsonl``, ``run.log``."
        },
        "sidecars": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "``entities.json``, ``boundaries.yml``, ``components.yml``, ``mesh.names``, ``entities.sif``."
        },
        "run_dir": {
          "$ref": "#/$defs/Cleanup",
          "default": "never",
          "description": "The whole bundle, manifest included; when it applies nothing else matters."
        },
        "cached_inputs": {
          "$ref": "#/$defs/Cleanup",
          "default": "always",
          "description": "Escalation for files the artifact store can re-fetch (``manifest.artifacts``); the stricter of this and the class rule wins."
        }
      },
      "title": "RetentionPolicy",
      "type": "object"
    },
    "RunFile": {
      "description": "The retention classes of a bundle; each member carries the bundle-relative patterns it covers.",
      "enum": [
        "geometry",
        "gmsh_mesh",
        "elmer_mesh",
        "partitioning",
        "sif",
        "fields",
        "scalars",
        "logs",
        "sidecars",
        "bundle",
        "run_dir"
      ],
      "title": "RunFile",
      "type": "string"
    }
  },
  "description": "One cleanup pass over a bundle: when, by whom, under which policy, and what left.",
  "properties": {
    "applied_at": {
      "description": "When the pass ran (UTC).",
      "format": "date-time",
      "title": "Applied At",
      "type": "string"
    },
    "trigger": {
      "$ref": "#/$defs/CleanupTrigger",
      "description": "The driver's cleanup stage or a post-hoc purge."
    },
    "status": {
      "anyOf": [
        {
          "enum": [
            "running",
            "abandoned"
          ],
          "type": "string"
        },
        {
          "enum": [
            "ok",
            "diverged",
            "error"
          ],
          "type": "string"
        }
      ],
      "description": "The run status the ``ON_SUCCESS`` rules were resolved against.",
      "title": "Status"
    },
    "policy": {
      "$ref": "#/$defs/RetentionPolicy",
      "description": "The policy that was applied."
    },
    "removed": {
      "description": "Every path that left, with its class and the rule that removed it.",
      "items": {
        "$ref": "#/$defs/RemovedFile"
      },
      "title": "Removed",
      "type": "array"
    }
  },
  "required": [
    "applied_at",
    "trigger",
    "status",
    "policy"
  ],
  "title": "CleanupRecord",
  "type": "object"
}
