{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dotbabel.dev/schemas/dotbabel.task-state.schema.json",
  "title": "dotbabel task state",
  "description": "The contract and durable state of one piece of work without a spec, written by `dotbabel task` to <git-dir>/dotbabel/tasks/<slug>.json (never the working tree, so it cannot appear in git status). The goal and a non-empty done_when list are fixed before execution; phase, decisions, pending items, and dependencies are written as the work proceeds. Per worktree: it survives context resets, crashes, and new sessions there, and does not travel to another machine. This is schema version 2; the reader also accepts a version-1 file, which has no depends_on, and reads it as version 2 with none.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "slug",
    "status",
    "goal",
    "done_when",
    "constraints",
    "phase",
    "decisions",
    "pending",
    "depends_on",
    "created_at",
    "updated_at",
    "closed_at",
    "branch",
    "worktree"
  ],
  "$defs": {
    "text": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    }
  },
  "properties": {
    "schema_version": {
      "const": 2
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,63}$",
      "description": "The file name without .json: lowercase letters, digits, and dashes."
    },
    "status": {
      "enum": ["open", "closed"],
      "description": "Only open tasks are printed at session start. A closed task keeps its record."
    },
    "goal": {
      "$ref": "#/$defs/text",
      "description": "What the work must achieve."
    },
    "done_when": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/text" },
      "description": "The checks that decide the work is done, defined before execution starts."
    },
    "constraints": {
      "type": "array",
      "items": { "$ref": "#/$defs/text" }
    },
    "phase": {
      "$ref": "#/$defs/text",
      "description": "Where the work stands, in the vocabulary of the skill that drives it."
    },
    "decisions": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["at", "text"],
        "properties": {
          "at": { "$ref": "#/$defs/timestamp" },
          "text": { "$ref": "#/$defs/text" }
        }
      },
      "description": "Append-only: each decision with the time it was recorded."
    },
    "pending": {
      "type": "array",
      "items": { "$ref": "#/$defs/text" }
    },
    "depends_on": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^([a-z0-9][a-z0-9-]{0,63}|github\\.com/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+:[a-z0-9][a-z0-9-]{0,63}|[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+#[1-9][0-9]*)$"
      },
      "description": "The references this task waits on: a task of this clone (<slug>), a task of another clone on this machine (github.com/owner/repo:<slug>), or a pull request or issue (owner/repo#123). Slugs are unique per clone."
    },
    "created_at": { "$ref": "#/$defs/timestamp" },
    "updated_at": { "$ref": "#/$defs/timestamp" },
    "closed_at": {
      "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/timestamp" }]
    },
    "branch": {
      "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/text" }],
      "description": "The branch checked out when the task was created; null on a detached HEAD."
    },
    "worktree": {
      "$ref": "#/$defs/text",
      "description": "The worktree root the task was created in."
    }
  }
}
