{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "anu_v3.branch_allocation_provenance.v1",
  "title": "task-2553+9 branch_ref_allocator collision-safe allocation provenance",
  "description": "9-R.6 audit trail — collision-safe branch name allocation provenance. base_sha single authority (base_name 미사용). 미기록 시 runner HOLD.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "schema",
    "allocator_module",
    "allocated_branch_name",
    "base_sha",
    "collision_detected",
    "sources_checked",
    "runid",
    "live_checkout_branch",
    "chosen_strategy"
  ],
  "properties": {
    "schema": {
      "type": "string",
      "const": "anu_v3.branch_allocation_provenance.v1"
    },
    "allocator_module": {
      "type": "string",
      "const": "anu_v3.branch_ref_allocator"
    },
    "allocator_version": { "type": "string" },
    "ts_utc": { "type": "string" },
    "allocated_branch_name": {
      "type": "string",
      "minLength": 1,
      "description": "최종 할당된 충돌-안전 branch name (base | <base>-<runid>)."
    },
    "base_sha": {
      "type": "string",
      "minLength": 7,
      "description": "isolated worktree 의 fresh base sha (single authority — base_name 미기록)."
    },
    "collision_detected": {
      "type": "boolean",
      "description": "base name 이 worktree/local/remote 어디서든 점유돼 있었는지."
    },
    "sources_checked": {
      "type": "object",
      "additionalProperties": false,
      "required": ["worktree", "local", "remote"],
      "properties": {
        "worktree": {
          "type": "boolean",
          "description": "git worktree list --porcelain 의 checked-out branch 와 충돌."
        },
        "local": {
          "type": "boolean",
          "description": "git show-ref --verify refs/heads/<name> 로컬 ref 존재."
        },
        "remote": {
          "type": "boolean",
          "description": "git ls-remote --heads origin <name> 원격 ref 존재."
        }
      }
    },
    "runid": {
      "type": ["string", "null"],
      "description": "충돌 회피 suffix 로 사용된 uuid4 hex12 (base strategy 면 null)."
    },
    "live_checkout_branch": {
      "type": ["string", "null"],
      "description": "live(메인) workspace 가 현재 checkout 한 branch — 절대 reset 0."
    },
    "chosen_strategy": {
      "type": "string",
      "enum": ["base", "suffixed"],
      "description": "base = 미충돌 deterministic name, suffixed = 충돌 회피 신규 name."
    },
    "attempts": {
      "type": "integer",
      "minimum": 1,
      "description": "loop-until-clean 시도 횟수 (bounded max 8)."
    },
    "status": {
      "type": "string",
      "enum": ["ALLOCATED", "HOLD_FOR_CHAIR"]
    },
    "hold_reasons": {
      "type": "array",
      "items": { "type": "string" }
    },
    "read_only": {
      "type": "boolean",
      "const": true,
      "description": "allocator 는 detection 전용 — git-write 부작용 0."
    }
  }
}
