{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Baton handoff",
  "description": "Records written before the v0.1 rename may carry the legacy $schema id https://threadline.dev/schemas/handoff/v0.1.json; both are valid for this schema version.",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "enum": [
        "https://baton.dev/schemas/handoff/v0.1.json",
        "https://threadline.dev/schemas/handoff/v0.1.json"
      ]
    },
    "schema_version": {
      "type": "string"
    },
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "kind": {
      "type": "string",
      "const": "handoff"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "validated",
        "ready",
        "resumed",
        "superseded",
        "archived"
      ]
    },
    "flags": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "invalid",
          "conflicted"
        ]
      }
    },
    "created_at": {
      "type": "string"
    },
    "updated_at": {
      "type": "string"
    },
    "project": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "root_hint": {
          "type": "string"
        },
        "repository": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "vcs": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "remote_hint": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "head": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "dirty": {
                  "type": [
                    "boolean",
                    "null"
                  ]
                }
              },
              "required": [
                "vcs",
                "remote_hint",
                "head",
                "dirty"
              ],
              "additionalProperties": true
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "root_hint",
        "repository"
      ],
      "additionalProperties": true
    },
    "origin": {
      "type": "object",
      "properties": {
        "harness": {
          "type": "string",
          "enum": [
            "codex",
            "claude-code",
            "cursor",
            "gemini-cli",
            "generic"
          ]
        },
        "adapter_version": {
          "type": [
            "string",
            "null"
          ]
        },
        "session_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "model": {
          "type": [
            "string",
            "null"
          ]
        },
        "actor": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "agent",
                    "human",
                    "mixed"
                  ]
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "type",
                "name"
              ],
              "additionalProperties": true
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "harness",
        "adapter_version",
        "session_id",
        "model",
        "actor"
      ],
      "additionalProperties": true
    },
    "work": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1
        },
        "objective": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "constraints": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "definition_of_done": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "title",
        "objective",
        "scope",
        "constraints",
        "definition_of_done"
      ],
      "additionalProperties": true
    },
    "summary": {
      "type": "object",
      "properties": {
        "completed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "in_progress": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        },
        "discoveries": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        },
        "current_state": {
          "type": "string",
          "minLength": 1
        },
        "why_it_matters": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "completed",
        "current_state",
        "why_it_matters"
      ],
      "additionalProperties": true
    },
    "decisions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Z]-\\d{3}$"
          },
          "decision": {
            "type": "string",
            "minLength": 1
          },
          "rationale": {
            "type": [
              "string",
              "null"
            ]
          },
          "alternatives_considered": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "evidence_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "made_at": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "decision",
          "rationale",
          "alternatives_considered",
          "evidence_ids",
          "made_at"
        ],
        "additionalProperties": true
      }
    },
    "artifacts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1
          },
          "role": {
            "type": "string",
            "enum": [
              "modified",
              "created",
              "read",
              "generated"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "revision": {
            "type": [
              "string",
              "null"
            ]
          },
          "content_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "sensitive": {
            "type": "boolean"
          }
        },
        "required": [
          "path",
          "role",
          "description",
          "revision",
          "content_hash",
          "sensitive"
        ],
        "additionalProperties": true
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Z]-\\d{3}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "command",
              "test",
              "file",
              "commit",
              "url",
              "human",
              "observation"
            ]
          },
          "claim": {
            "type": "string",
            "minLength": 1
          },
          "ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "captured_at": {
            "type": "string"
          },
          "result": {
            "type": [
              "string",
              "null"
            ]
          },
          "digest": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "type",
          "claim",
          "ref",
          "captured_at",
          "result",
          "digest"
        ],
        "additionalProperties": true
      }
    },
    "failed_attempts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Z]-\\d{3}$"
          },
          "approach": {
            "type": "string",
            "minLength": 1
          },
          "outcome": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "failed",
                  "regressed",
                  "abandoned"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "evidence_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "avoid_repeating": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "approach",
          "outcome",
          "reason",
          "evidence_ids",
          "avoid_repeating"
        ],
        "additionalProperties": true
      },
      "default": []
    },
    "open_items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Z]-\\d{3}$"
          },
          "priority": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ]
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "suggested_action": {
            "type": [
              "string",
              "null"
            ]
          },
          "blocked_by": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "acceptance_check": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "priority",
          "description",
          "suggested_action",
          "blocked_by",
          "acceptance_check"
        ],
        "additionalProperties": true
      }
    },
    "risks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "minLength": 1
          },
          "severity": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ]
          },
          "mitigation": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "description",
          "severity",
          "mitigation"
        ],
        "additionalProperties": true
      }
    },
    "validation": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "pass",
            "warn",
            "fail",
            "not_run"
          ]
        },
        "validated_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "checks": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "status": {
                "type": "string",
                "enum": [
                  "pass",
                  "warn",
                  "fail",
                  "skipped"
                ]
              },
              "detail": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "status",
              "detail"
            ],
            "additionalProperties": true
          }
        },
        "freshness": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "git_head_at_capture": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "git_head_now": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "stale": {
                  "type": "boolean"
                }
              },
              "required": [
                "git_head_at_capture",
                "git_head_now",
                "stale"
              ],
              "additionalProperties": true
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "status",
        "validated_at",
        "checks",
        "freshness"
      ],
      "additionalProperties": true
    },
    "lineage": {
      "type": "object",
      "properties": {
        "parents": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "relation": {
          "type": "string",
          "enum": [
            "root",
            "continue",
            "fork",
            "merge",
            "amend"
          ]
        },
        "branch_label": {
          "type": [
            "string",
            "null"
          ]
        },
        "merge_basis": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "parents",
        "relation",
        "branch_label",
        "merge_basis"
      ],
      "additionalProperties": true
    },
    "automation": {
      "type": "object",
      "properties": {
        "trigger": {
          "type": "string",
          "enum": [
            "manual",
            "threshold",
            "hook",
            "timeout",
            "pre_compaction"
          ]
        },
        "score": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "reasons": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "trigger",
        "score",
        "reasons"
      ],
      "additionalProperties": true
    },
    "metagit": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "project_id": {
              "type": [
                "string",
                "null"
              ]
            },
            "objective_id": {
              "type": [
                "string",
                "null"
              ]
            },
            "session_id": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "project_id",
            "objective_id",
            "session_id"
          ],
          "additionalProperties": true
        },
        {
          "type": "null"
        }
      ],
      "default": null
    },
    "redactions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string",
            "minLength": 1
          },
          "reason": {
            "type": "string",
            "minLength": 1
          },
          "replacement": {
            "type": "string"
          }
        },
        "required": [
          "field",
          "reason",
          "replacement"
        ],
        "additionalProperties": true
      }
    }
  },
  "required": [
    "$schema",
    "schema_version",
    "id",
    "kind",
    "status",
    "flags",
    "created_at",
    "updated_at",
    "project",
    "origin",
    "work",
    "summary",
    "decisions",
    "artifacts",
    "evidence",
    "open_items",
    "risks",
    "validation",
    "lineage",
    "automation",
    "redactions"
  ],
  "additionalProperties": true
}
