{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/kill.schema.json",
  "title": "Kill",
  "description": "What POST /v1/runs/{id}/kill returns: the preview with a confirm token (step 1), or the result (step 2, `run-kill.mjs apply`). A kill never deletes the remote branch or the run's logs. worktreePath is 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", "preview", "confirmToken", "expiresAt"],
      "properties": {
        "contractVersion": {
          "type": "string",
          "pattern": "^1\\.[0-9]+\\.[0-9]+$",
          "x-sensitivity": "none"
        },
        "preview": {
          "type": "object",
          "additionalProperties": false,
          "required": ["branch", "sizeKb", "uncommittedFiles", "unpushedCommits", "processAlive"],
          "x-sensitivity": "none",
          "properties": {
            "worktreePath": {
              "type": ["string", "null"],
              "x-sensitivity": "local"
            },
            "branch": {
              "type": ["string", "null"]
            },
            "sizeKb": {
              "type": "integer",
              "minimum": 0
            },
            "uncommittedFiles": {
              "type": "integer",
              "minimum": 0,
              "description": "Lost with the worktree."
            },
            "unpushedCommits": {
              "type": "integer",
              "minimum": 0,
              "description": "Commits on no remote; lost with the branch."
            },
            "processAlive": {
              "type": "boolean",
              "description": "The run's background session is running (or its liveness could not be read)."
            }
          }
        },
        "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",
        "killed",
        "processStopped",
        "worktreeRemoved",
        "branchDeleted",
        "logsKept"
      ],
      "properties": {
        "contractVersion": {
          "type": "string",
          "pattern": "^1\\.[0-9]+\\.[0-9]+$",
          "x-sensitivity": "none"
        },
        "killed": {
          "const": true,
          "x-sensitivity": "none"
        },
        "processStopped": {
          "type": "boolean",
          "x-sensitivity": "none"
        },
        "worktreeRemoved": {
          "type": "boolean",
          "x-sensitivity": "none"
        },
        "branchDeleted": {
          "type": "boolean",
          "x-sensitivity": "none"
        },
        "logsKept": {
          "const": true,
          "x-sensitivity": "none"
        }
      }
    }
  }
}
