{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cbsshekhawat18-lab.github.io/karni/assets/karni-build.schema.json",
  "title": "karni build --json",
  "description": "Experimental. The output of karni build --json.",
  "$defs": {
    "_FileOut": {
      "additionalProperties": false,
      "description": "One file a build writes (or, with --dry-run, would write).",
      "properties": {
        "path": {
          "description": "The file, relative to the project root.",
          "type": "string"
        },
        "action": {
          "description": "What happens to it.",
          "enum": [
            "create",
            "modify",
            "delete"
          ],
          "type": "string"
        },
        "owner": {
          "description": "karni: a Karni-owned file or block, rewritten on every build. project: a file of the project's, created once or given a missing class.",
          "enum": [
            "karni",
            "project"
          ],
          "type": "string"
        }
      },
      "required": [
        "path",
        "action",
        "owner"
      ],
      "type": "object"
    },
    "_HandEditOut": {
      "additionalProperties": false,
      "description": "A Karni-owned file or block edited by hand: the build stops before it writes anything.",
      "properties": {
        "path": {
          "description": "The file, or the block (config/settings.py, routes.tsx ...).",
          "type": "string"
        },
        "lines": {
          "description": "The lines of the file on disk that differ (1-based).",
          "items": {
            "type": "integer"
          },
          "type": "array"
        },
        "diff": {
          "description": "A short diff: - what karni build writes, + the file.",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "unrecorded": {
          "description": "true: the file exists but karni build never wrote it (not in the record).",
          "type": "boolean"
        }
      },
      "required": [
        "path",
        "lines",
        "diff",
        "unrecorded"
      ],
      "type": "object"
    },
    "_StepOut": {
      "additionalProperties": false,
      "description": "One step of the build.",
      "properties": {
        "name": {
          "description": "The step: modules, files, migrations, migrate, seed, types, test, check.",
          "enum": [
            "modules",
            "files",
            "migrations",
            "migrate",
            "seed",
            "types",
            "test",
            "check"
          ],
          "type": "string"
        },
        "status": {
          "description": "done, skipped (nothing to do), failed (the build stopped here) or pending (not reached: the next karni build runs it).",
          "enum": [
            "done",
            "skipped",
            "failed",
            "pending"
          ],
          "type": "string"
        },
        "summary": {
          "description": "One line: what the step did, or why it failed.",
          "type": "string"
        }
      },
      "required": [
        "name",
        "status",
        "summary"
      ],
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "version": {
      "const": 1,
      "description": "The version of this output: 1.",
      "type": "integer"
    },
    "file": {
      "description": "The spec file, as given.",
      "type": "string"
    },
    "valid": {
      "description": "false when the spec has problems: then issues lists them.",
      "type": "boolean"
    },
    "issues": {
      "description": "The spec's problems, as karni spec validate --json reports them.",
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "type": "array"
    },
    "status": {
      "description": "How the build ended: built, nothing to build, dry run, refused, failed, invalid.",
      "enum": [
        "built",
        "nothing to build",
        "dry run",
        "refused",
        "failed",
        "invalid"
      ],
      "type": "string"
    },
    "code": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "The error code when refused or failed (karni explain <code>). null otherwise."
    },
    "message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "What stopped the build. null when nothing did."
    },
    "plan": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "description": "The plan, exactly as karni plan --json prints it (docs/assets/karni-plan.schema.json). null when the spec has problems."
    },
    "files": {
      "description": "The files written (with --dry-run: to write).",
      "items": {
        "$ref": "#/$defs/_FileOut"
      },
      "type": "array"
    },
    "hand_edits": {
      "description": "Karni-owned files and blocks edited by hand. The build stops on them (C273) unless --force (a .orig backup is kept) or --adopt.",
      "items": {
        "$ref": "#/$defs/_HandEditOut"
      },
      "type": "array"
    },
    "adopted": {
      "description": "Karni-owned files and blocks the project adopted: karni build leaves them.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "steps": {
      "description": "Every step, in order, with how it went.",
      "items": {
        "$ref": "#/$defs/_StepOut"
      },
      "type": "array"
    },
    "next": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "What to do next, when something is left to do."
    }
  },
  "required": [
    "version",
    "file",
    "valid",
    "issues",
    "status",
    "code",
    "message",
    "plan",
    "files",
    "hand_edits",
    "adopted",
    "steps",
    "next"
  ],
  "type": "object"
}
