{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://internal/handoff-schema/1.0",
  "title": "BotHandoff",
  "description": "봇 간 작업 인계(handoff) 표준 스키마 v1.0. silent corruption 방지용 machine-readable evidence.",
  "type": "object",
  "required": [
    "task_id",
    "schema_version",
    "previous_bot",
    "current_branch",
    "base_sha",
    "head_sha",
    "changed_paths",
    "allowed_paths",
    "forbidden_paths",
    "test_results",
    "handoff_reason",
    "created_at"
  ],
  "additionalProperties": false,
  "properties": {
    "task_id": {
      "type": "string",
      "description": "작업 식별자. 예: task-2454 또는 task-2454.1",
      "pattern": "^task-\\d+(\\.\\d+)?$"
    },
    "schema_version": {
      "type": "string",
      "description": "핸드오프 스키마 버전. 현재 1.0 고정.",
      "const": "1.0"
    },
    "previous_bot": {
      "type": "string",
      "description": "이 핸드오프를 생성한 봇 식별자. 예: dev4, design, qc",
      "pattern": "^(dev\\d+|design|qc)$"
    },
    "current_branch": {
      "type": "string",
      "description": "현재 작업 브랜치 전체 이름. 예: task/task-2454-dev4",
      "pattern": "^task/task-\\d+(\\.\\d+)?-(dev\\d+|design|qc)$"
    },
    "base_sha": {
      "type": "string",
      "description": "작업 시작 시점의 origin/main HEAD 커밋 SHA (7~40자 hex)",
      "pattern": "^[0-9a-f]{7,40}$"
    },
    "head_sha": {
      "type": "string",
      "description": "핸드오프 시점의 브랜치 HEAD 커밋 SHA (7~40자 hex)",
      "pattern": "^[0-9a-f]{7,40}$"
    },
    "changed_paths": {
      "type": "array",
      "description": "origin/main 대비 변경된 파일 상대 경로 목록",
      "items": {
        "type": "string"
      }
    },
    "allowed_paths": {
      "type": "array",
      "description": "이 봇이 수정 허용된 경로 목록 (task 파일의 allowed_resources 기준)",
      "items": {
        "type": "string"
      }
    },
    "forbidden_paths": {
      "type": "array",
      "description": "이 봇이 수정 금지된 경로 목록",
      "items": {
        "type": "string"
      }
    },
    "pending_work": {
      "type": "string",
      "description": "잔여 작업 요약 (4000자 이하). 초과 시 pending_work_path 사용.",
      "maxLength": 4000
    },
    "pending_work_path": {
      "type": "string",
      "description": "잔여 작업 내용을 담은 외부 파일 경로 (pending_work 4000자 초과 시 사용)"
    },
    "known_failures": {
      "type": "string",
      "description": "알려진 실패/에러 요약 (4000자 이하). 초과 시 known_failures_path 사용.",
      "maxLength": 4000
    },
    "known_failures_path": {
      "type": "string",
      "description": "알려진 실패 내용을 담은 외부 파일 경로 (known_failures 4000자 초과 시 사용)"
    },
    "test_results": {
      "type": "object",
      "description": "테스트 실행 결과 자유 형식 객체. 예: {\"pytest\": \"passed\", \"ci\": \"pending\"}",
      "additionalProperties": true
    },
    "handoff_reason": {
      "type": "string",
      "description": "인계 사유 코드",
      "enum": ["interrupt", "complete", "takeover_request"]
    },
    "created_at": {
      "type": "string",
      "description": "핸드오프 생성 시각 (ISO 8601, UTC). 예: 2026-05-05T12:34:56Z",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    }
  },
  "allOf": [
    {
      "oneOf": [
        {
          "description": "pending_work 없음 (둘 다 없는 경우)",
          "not": {
            "anyOf": [
              {"required": ["pending_work"]},
              {"required": ["pending_work_path"]}
            ]
          }
        },
        {
          "description": "pending_work 인라인 텍스트만",
          "required": ["pending_work"],
          "not": {"required": ["pending_work_path"]}
        },
        {
          "description": "pending_work_path 외부 파일만",
          "required": ["pending_work_path"],
          "not": {"required": ["pending_work"]}
        }
      ]
    },
    {
      "oneOf": [
        {
          "description": "known_failures 없음 (둘 다 없는 경우)",
          "not": {
            "anyOf": [
              {"required": ["known_failures"]},
              {"required": ["known_failures_path"]}
            ]
          }
        },
        {
          "description": "known_failures 인라인 텍스트만",
          "required": ["known_failures"],
          "not": {"required": ["known_failures_path"]}
        },
        {
          "description": "known_failures_path 외부 파일만",
          "required": ["known_failures_path"],
          "not": {"required": ["known_failures"]}
        }
      ]
    }
  ]
}
