{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tokrepo.com/schemas/capability-resolution.schema.json",
  "title": "TokRepo Capability Resolution",
  "description": "Machine-readable planning-time contract returned by tokrepo_resolve_capability for resolving an agent capability gap into reusable TokRepo assets, verification evidence, and install plans.",
  "type": "object",
  "required": [
    "schema_version",
    "command",
    "status",
    "task",
    "target",
    "thresholds",
    "capability_analysis",
    "discovery",
    "candidate_evidence",
    "lifecycle_contract",
    "next_mcp_calls",
    "fallback_commands"
  ],
  "properties": {
    "schema_version": { "type": "integer", "const": 1 },
    "schema": { "type": "string", "format": "uri" },
    "hosted_mcp": { "type": "boolean" },
    "command": { "type": "string", "const": "resolve" },
    "status": { "type": "string", "enum": ["pass", "block"] },
    "task": { "type": "string" },
    "target": { "type": "string" },
    "verification_target": { "type": "string" },
    "thresholds": {
      "type": "object",
      "required": ["min_fit_score", "min_trust_score"],
      "properties": {
        "min_fit_score": { "type": "number", "minimum": 0, "maximum": 100 },
        "min_trust_score": { "type": "number", "minimum": 0, "maximum": 100 }
      },
      "additionalProperties": true
    },
    "capability_analysis": { "type": "object", "additionalProperties": true },
    "discovery": { "type": "object", "additionalProperties": true },
    "candidates": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "candidate_evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["candidate", "evidence_status"],
        "properties": {
          "candidate": { "type": "object", "additionalProperties": true },
          "evidence_status": { "type": "string", "enum": ["verified", "verification_failed", "error", "missing_uuid"] },
          "decision": { "type": "object", "additionalProperties": true },
          "verification": { "type": "object", "additionalProperties": true },
          "install_plan": { "type": "object", "additionalProperties": true },
          "install_plan_summary": { "type": "object", "additionalProperties": true },
          "error": { "type": "string" },
          "fallback_commands": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "additionalProperties": true
      }
    },
    "selected": {
      "type": ["object", "null"],
      "properties": {
        "uuid": { "type": "string" },
        "title": { "type": "string" },
        "decision": {
          "type": "object",
          "required": ["decision", "reason", "action"],
          "properties": {
            "decision": {
              "type": "string",
              "enum": [
                "use_asset_after_install_plan",
                "stage_or_request_confirmation",
                "do_not_use",
                "inspect_manually",
                "build_locally_then_harvest"
              ]
            },
            "reason": { "type": "string" },
            "action": { "type": "string" }
          },
          "additionalProperties": true
        },
        "candidate": { "type": "object", "additionalProperties": true },
        "verification": { "type": "object", "additionalProperties": true },
        "install_plan": { "type": "object", "additionalProperties": true }
      },
      "additionalProperties": true
    },
    "lifecycle_contract": {
      "type": "object",
      "required": ["before_build", "before_write", "execute", "after_task"],
      "properties": {
        "before_build": { "type": "string" },
        "before_write": { "type": "string" },
        "execute": { "type": "string" },
        "after_task": { "type": "string" }
      },
      "additionalProperties": true
    },
    "next_mcp_calls": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["tool", "arguments"],
        "properties": {
          "tool": { "type": "string" },
          "arguments": { "type": "object", "additionalProperties": true }
        },
        "additionalProperties": true
      }
    },
    "fallback_commands": {
      "type": "array",
      "items": { "type": "string" }
    },
    "empty_state": {
      "type": ["object", "null"],
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
