{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tokrepo.com/schemas/agent-discovery.schema.json",
  "title": "TokRepo Agent Discovery",
  "description": "Schema for tokrepo_discover responses. Agents should call tokrepo_discover during planning, inspect candidates, then call tokrepo_install_plan before writes.",
  "type": "object",
  "additionalProperties": true,
  "required": ["schema_version", "intent", "recommended_flow", "candidates"],
  "properties": {
    "schema_version": { "type": "integer", "const": 1 },
    "intent": {
      "type": "object",
      "additionalProperties": true,
      "required": ["task", "target", "query"],
      "properties": {
        "task": { "type": "string" },
        "target": { "type": "string" },
        "query": { "type": "string" },
        "environment": { "type": "object", "additionalProperties": true },
        "constraints": { "type": "object", "additionalProperties": true }
      }
    },
    "recommended_flow": {
      "type": "array",
      "items": { "type": "string" }
    },
    "candidates": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["uuid", "title", "capability", "fit", "next_mcp_calls", "commands", "agent_use_contract"],
        "properties": {
          "uuid": { "type": "string" },
          "slug": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "url": { "type": "string" },
          "tags": {
            "type": "array",
            "items": { "type": "string" }
          },
          "capability": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "kind": { "type": "string" },
              "install_mode": { "type": "string" },
              "entrypoint": { "type": "string" },
              "target_tools": {
                "type": "array",
                "items": { "type": "string" }
              }
            }
          },
          "fit": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "target": { "type": "string" },
              "score": { "type": ["integer", "number", "null"], "minimum": 0, "maximum": 100 },
              "status": { "type": "string" },
              "policy": { "type": "string" },
              "why": {
                "type": "array",
                "items": { "type": "string" }
              }
            }
          },
          "next_mcp_calls": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "required": ["tool", "arguments"],
              "properties": {
                "tool": { "type": "string" },
                "arguments": { "type": "object", "additionalProperties": true }
              }
            }
          },
          "commands": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "inspect": { "type": "string" },
              "dry_run_install": { "type": "string" }
            }
          },
          "agent_use_contract": {
            "type": "array",
            "items": { "type": "string" }
          }
        }
      }
    },
    "empty_state": {
      "type": ["object", "null"],
      "additionalProperties": true
    }
  }
}
