{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/realpkuasule/harness-automation/main/docs/api/worktree-host-binding-v1.schema.json",
  "title": "Harness Worktree Host Binding v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "allowedRoots", "protectedRoots"],
  "properties": {
    "schemaVersion": {
      "const": "1.0"
    },
    "allowedRoots": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "description": "Canonical absolute paths on this host under which persistent worktrees may be allocated.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "protectedRoots": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "description": "Canonical absolute paths on this host that cannot contain a managed worktree.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "topology": {
      "description": "Optional host-local container layout. Omitted bindings retain legacy-flat compatibility.",
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "workspaceContainer", "managementCheckout", "persistentWorktreeRoot"],
      "properties": {
        "kind": { "const": "container-v1" },
        "workspaceContainer": { "type": "string", "minLength": 1 },
        "managementCheckout": { "type": "string", "minLength": 1 },
        "persistentWorktreeRoot": { "type": "string", "minLength": 1 }
      }
    },
    "approval": {
      "description": "Host-local plan authorization. Omitted bindings retain manual exact-hash approval.",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["mode"],
          "properties": {
            "mode": { "const": "manual" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["mode", "reviewer", "allowedOperations", "planTtlSeconds", "reviewerTimeoutSeconds"],
          "properties": {
            "mode": { "const": "delegated-ai" },
            "reviewer": {
              "type": "object",
              "additionalProperties": false,
              "required": ["kind", "model"],
              "properties": {
                "kind": { "const": "claude" },
                "model": { "type": "string", "minLength": 1 }
              }
            },
            "allowedOperations": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "enum": ["allocate", "adopt", "close", "rebind", "renew", "recover"]
              }
            },
            "planTtlSeconds": {
              "type": "integer",
              "minimum": 30,
              "maximum": 3600
            },
            "reviewerTimeoutSeconds": {
              "type": "integer",
              "minimum": 10,
              "maximum": 600
            }
          }
        }
      ]
    }
  }
}
