{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/hosts.schema.json",
  "version": "1.0.0",
  "title": "Multi-Agent Pipeline  -  host registry",
  "description": "Shape of pipeline/schemas/hosts.json: one record per CLI host the pipeline installs into and runs inside. Consumers read capability fields (dispatch.mechanism, models.binding, review.panel, headless) rather than comparing a host id, so a new host is a record here plus an engine adapter. The registry ships with the package and is not user-extensible: it names install roots and argv, which user input must never reach.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "order", "rungOrder", "stateRoot", "hosts"],
  "properties": {
    "$comment": { "type": "string" },
    "version": { "type": "string", "const": "1.0.0" },
    "order": {
      "description": "Install and reporting order. Every id here must exist in hosts, and every host must be listed.",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/hostId" }
    },
    "rungOrder": {
      "description": "Every model rung a host may offer, MOST CAPABLE FIRST. The ladder is read from here rather than from the key order of any host's rungs object, so reordering that object cannot silently invert an escalation. Every host's rungs must be a subset of this list.",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/rungName" }
    },
    "stateRoot": {
      "description": "Home-relative directory holding preferences, logs and run state for every host. One root across all of them, deliberately: a run started on one host is readable from another.",
      "type": "string",
      "pattern": "^\\.[a-z][a-z0-9-]*$"
    },
    "hosts": {
      "type": "object",
      "minProperties": 1,
      "propertyNames": { "$ref": "#/$defs/hostId" },
      "additionalProperties": { "$ref": "#/$defs/host" }
    }
  },
  "$defs": {
    "hostId": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
    "rungName": { "type": "string", "pattern": "^[a-z][a-z0-9.-]*$" },
    "host": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label",
        "harness",
        "install",
        "cli",
        "detect",
        "command",
        "persona",
        "dispatch",
        "models",
        "review",
        "pricing",
        "headless",
        "sessionUsage",
        "network"
      ],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "harness": {
          "description": "Which install adapter and transcript reader this host uses. Several hosts may share one engine; the record carries what differs.",
          "$ref": "#/$defs/hostId"
        },
        "install": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "flag",
            "root",
            "seedsPreferences",
            "subtrees",
            "knowledgeSkills",
            "commandSpecs",
            "commandSpecPrefix"
          ],
          "allOf": [
            {
              "if": { "properties": { "knowledgeSkills": { "const": "install" } } },
              "then": { "required": ["knowledgeSkillsRoot"] },
              "else": { "not": { "required": ["knowledgeSkillsRoot"] } }
            }
          ],
          "properties": {
            "flag": { "type": "string", "pattern": "^--[a-z][a-z0-9-]*$" },
            "root": { "type": "string", "pattern": "^\\.[a-z][a-z0-9-]*$" },
            "seedsPreferences": {
              "description": "Whether this host's installer writes the shared preferences file when it is absent. A host that does not seed it needs another host installed first, which the installer has to say out loud.",
              "type": "boolean"
            },
            "subtrees": {
              "description": "Directories under the install root that must exist for the install to be whole. A health check reads this instead of assuming the Claude Code layout, which reported a Copilot-only machine as having no install at all.",
              "type": "array",
              "minItems": 1,
              "items": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }
            },
            "knowledgeSkills": {
              "description": "How this host receives the knowledge skills. \"install\" means the installer writes them into the root and every one of them must land there; \"plugin\" means the host loads them from the marketplace plugin, and the installer writing them too would be a duplicate copy. The parity gate reads this to decide which trees it compares, so a host whose delivery changes states it here rather than having the gate discover it.",
              "enum": ["install", "plugin"]
            },
            "knowledgeSkillsRoot": {
              "description": "Path, relative to the install root, of the tree the knowledge skills land in. Required when knowledgeSkills is \"install\"; the three layouts do not agree on it.",
              "type": "string",
              "minLength": 1
            },
            "commandSpecs": {
              "description": "Path, relative to the install root, of the tree holding one directory per sub-command, each with its own SKILL.md. The three layouts differ: specs are commands on one host, reference files on another, and one skill per sub-command on a third.",
              "type": "string",
              "pattern": "^[a-z][a-z0-9/-]*$"
            },
            "pathRewrites": {
              "description": "Ordered rules retargeting an authored `$HOME/<stateRoot>/...` path into this host's own trees as a file lands. Order is load-bearing: a rule matching a shorter prefix placed before a longer one swallows it and yields a path that does not exist. Empty for the host the paths are authored against.",
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["match", "from"],
                "allOf": [
                  {
                    "if": { "properties": { "match": { "const": "extension" } } },
                    "then": { "required": ["fromExt", "toExt"] },
                    "else": { "required": ["to"] }
                  }
                ],
                "properties": {
                  "match": {
                    "description": "`exact` replaces a whole path. `segment` turns `<from>/<name>` into `<to><name>`, for a host that flattens a directory per sub-command into prefixed names. `prefix` moves a leading directory and the rest of the path rides along. `extension` runs last, inside a tree this host already owns, and rewrites a file suffix. `root` renames a whole install root, for a second install of the same engine whose authored text names the engine's default tree.",
                    "enum": ["exact", "segment", "prefix", "extension", "root"]
                  },
                  "from": { "type": "string" },
                  "to": { "type": "string" },
                  "fromExt": { "type": "string" },
                  "toExt": { "type": "string" }
                }
              }
            },
            "commandSpecPrefix": {
              "description": "Prefix each sub-command directory carries inside commandSpecs. Empty where the directory is the bare sub-command name; a host that fans the pipeline out into a shared skills tree has to prefix them, and a reader that ignores the prefix reports every sub-command as missing.",
              "type": "string",
              "pattern": "^[a-z0-9-]*$"
            }
          }
        },
        "cli": {
          "type": "object",
          "additionalProperties": false,
          "required": ["candidates", "scopeArgs", "getArgs"],
          "properties": {
            "candidates": {
              "description": "Binary names or paths tried in order. $HOME is the only expansion.",
              "type": "array",
              "minItems": 1,
              "items": { "type": "string", "minLength": 1 }
            },
            "scopeArgs": { "type": "array", "items": { "type": "string" } },
            "getArgs": { "type": "array", "items": { "type": "string" } }
          }
        },
        "detect": {
          "type": "object",
          "additionalProperties": false,
          "required": ["env", "rootSegment"],
          "properties": {
            "env": {
              "description": "Environment variables whose presence names this host. Checked after the explicit override and before the path fallback.",
              "type": "array",
              "items": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" }
            },
            "rootSegment": {
              "description": "Path segment that identifies this host when a script resolves its own location.",
              "type": "string",
              "pattern": "^\\.[a-z][a-z0-9-]*$"
            }
          }
        },
        "command": {
          "type": "object",
          "additionalProperties": false,
          "required": ["template"],
          "properties": {
            "template": {
              "description": "How a sub-command is typed on this host. {sub} is the only placeholder.",
              "type": "string",
              "pattern": "\\{sub\\}"
            }
          }
        },
        "persona": {
          "type": "object",
          "additionalProperties": false,
          "required": ["format"],
          "properties": {
            "format": { "type": "string", "enum": ["md", "toml"] }
          }
        },
        "dispatch": {
          "type": "object",
          "additionalProperties": false,
          "required": ["mechanism", "modelArg", "required", "maxConcurrentChildren"],
          "properties": {
            "mechanism": { "type": "string", "enum": ["task-tool", "cli-flag", "spawn-agent"] },
            "modelArg": { "type": "string", "minLength": 1 },
            "effortArg": { "type": "string", "minLength": 1 },
            "required": {
              "description": "Parameters every dispatch must carry on this host. Omitting one can discard the model override without an error.",
              "type": "object",
              "additionalProperties": { "type": "string" }
            },
            "maxConcurrentChildren": {
              "description": "Ceiling on simultaneous children, or null when the host documents none. A review panel may not exceed it.",
              "type": ["integer", "null"],
              "minimum": 1
            }
          }
        },
        "models": {
          "type": "object",
          "additionalProperties": false,
          "required": ["binding", "providers", "rungSwitch", "rungs"],
          "properties": {
            "binding": {
              "description": "When a rung becomes a concrete model: an environment variable at dispatch, a CLI flag at dispatch, a value written into the agent definition at install time, or inherited from the session.",
              "type": "string",
              "enum": ["runtime-env", "runtime-flag", "install", "session"]
            },
            "providers": {
              "description": "Which cost-table providers this host can actually dispatch. The dispatch gate reads this instead of a fixed provider name.",
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }
            },
            "rungSwitch": {
              "description": "What the top-rung preference means here: live changes dispatch, recorded stores the value and changes nothing, ignored means the rung is not this host's to switch.",
              "type": "string",
              "enum": ["live", "recorded", "ignored"]
            },
            "rungs": {
              "type": "object",
              "minProperties": 1,
              "propertyNames": { "$ref": "#/$defs/rungName" },
              "additionalProperties": { "$ref": "#/$defs/modelSlot" }
            }
          }
        },
        "review": {
          "type": "object",
          "additionalProperties": false,
          "required": ["vendorDiversity", "panel", "triage"],
          "properties": {
            "vendorDiversity": {
              "description": "Whether the panel spans more than one model vendor. Agreement among one vendor's models is weaker evidence and the report says so.",
              "type": "string",
              "enum": ["single", "cross"]
            },
            "panel": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/panelSlot" }
            },
            "triage": { "$ref": "#/$defs/panelSlot" }
          }
        },
        "pricing": {
          "type": "object",
          "additionalProperties": false,
          "required": ["ceilingKey"],
          "properties": {
            "ceilingKey": {
              "description": "cost-table key a budget ceiling prices this host's tokens at when the run names no model. Must exist in cost-table.json.",
              "$ref": "#/$defs/rungName"
            }
          }
        },
        "headless": {
          "description": "One-shot argv for a prompt this host can answer outside a session, or null when it has none. {model} is the only placeholder.",
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["argv"],
              "properties": {
                "argv": { "type": "array", "minItems": 1, "items": { "type": "string" } }
              }
            },
            { "type": "null" }
          ]
        },
        "sessionUsage": {
          "description": "Transcript format carrying per-message token counts, or null when this host writes none and its tokens are not measurable.",
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["format"],
              "properties": {
                "format": { "type": "string", "enum": ["claude-jsonl", "rollout"] }
              }
            },
            { "type": "null" }
          ]
        },
        "network": {
          "description": "Whether a run on this host needs the network. optional hosts skip the steps that reach outside the machine and say which ones they skipped.",
          "type": "string",
          "enum": ["required", "optional"]
        }
      }
    },
    "modelSlot": {
      "type": "object",
      "additionalProperties": false,
      "required": ["model"],
      "properties": {
        "model": { "type": "string", "minLength": 1 },
        "effort": { "type": "string", "minLength": 1 }
      }
    },
    "panelSlot": {
      "description": "One reviewer slot: either a rung this host resolves, or a concrete model when the panel deliberately overrides the rung map.",
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "rung": { "$ref": "#/$defs/rungName" },
        "model": { "type": "string", "minLength": 1 },
        "effort": { "type": "string", "minLength": 1 }
      },
      "oneOf": [{ "required": ["rung"] }, { "required": ["model"] }]
    }
  }
}
