{
  "otc": "0.2.0",
  "id": "okham.core.type.capability",
  "version": "0.1.0",
  "name": "Capability",
  "description": "Describes the operations, interfaces and publication subjects offered by a resource. Invocation is governed by the host and its policies.",
  "status": "draft",
  "fields": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "Capability identity retained across migrations."
    },
    {
      "name": "name",
      "type": "string",
      "required": true,
      "description": "Human-readable capability name"
    },
    {
      "name": "version",
      "type": "string",
      "required": true,
      "description": "Semantic version"
    },
    {
      "name": "description",
      "type": "string",
      "required": true,
      "description": "Multiline description for LLM context"
    },
    {
      "name": "visibility",
      "type": "string",
      "required": false,
      "description": "visibility for this capability."
    },
    {
      "name": "tags",
      "type": "array",
      "required": false,
      "description": "tags for this capability."
    },
    {
      "name": "category",
      "type": "string",
      "required": false,
      "description": "category for this capability."
    },
    {
      "name": "public",
      "type": "boolean",
      "required": false,
      "description": "public for this capability."
    },
    {
      "name": "icon",
      "type": "string",
      "required": false,
      "description": "icon for this capability."
    },
    {
      "name": "domainsOwned",
      "type": "array",
      "required": false,
      "description": "domainsOwned for this capability."
    },
    {
      "name": "crossDomainPublishes",
      "type": "array",
      "required": false,
      "description": "crossDomainPublishes for this capability."
    },
    {
      "name": "streams",
      "type": "object",
      "required": false,
      "description": "streams for this capability."
    },
    {
      "name": "kv",
      "type": "object",
      "required": false,
      "description": "kv for this capability."
    },
    {
      "name": "interestGroups",
      "type": "array",
      "required": false,
      "description": "interestGroups for this capability."
    },
    {
      "name": "subjects",
      "type": "object",
      "required": true,
      "description": "subjects for this capability."
    },
    {
      "name": "subscriptions",
      "type": "object",
      "required": false,
      "description": "subscriptions for this capability."
    },
    {
      "name": "http",
      "type": "object",
      "required": false,
      "description": "http for this capability."
    },
    {
      "name": "ui",
      "type": "object",
      "required": false,
      "description": "ui for this capability."
    },
    {
      "name": "mcp",
      "type": "object",
      "required": false,
      "description": "mcp for this capability."
    },
    {
      "name": "llm",
      "type": "object",
      "required": false,
      "description": "llm for this capability."
    },
    {
      "name": "imports",
      "type": "array",
      "required": false,
      "description": "imports for this capability."
    },
    {
      "name": "limits",
      "type": "object",
      "required": false,
      "description": "limits for this capability."
    },
    {
      "name": "auth",
      "type": "object",
      "required": false,
      "description": "auth for this capability."
    },
    {
      "name": "typeRef",
      "type": "string",
      "required": true,
      "description": "Core type for this instance."
    },
    {
      "name": "typeVersion",
      "type": "string",
      "required": true,
      "description": "Exact version of the Core type."
    }
  ],
  "metadata": {
    "normative": {
      "typeRef": "okham.standards.type.normative.profile",
      "standard": "BCP14",
      "requirements": []
    },
    "replacesFormat": "OCC"
  },
  "schema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "Capability",
    "description": "Describes the operations, interfaces and publication subjects offered by a resource. Invocation is governed by the host and its policies.",
    "type": "object",
    "required": [
      "typeRef",
      "typeVersion",
      "id",
      "name",
      "version",
      "description",
      "subjects"
    ],
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)*$",
        "description": "Capability identity retained across migrations."
      },
      "name": {
        "type": "string",
        "maxLength": 100,
        "description": "Human-readable capability name"
      },
      "version": {
        "type": "string",
        "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
        "description": "Semantic version"
      },
      "description": {
        "type": "string",
        "description": "Multiline description for LLM context"
      },
      "visibility": {
        "type": "string",
        "enum": [
          "public",
          "private"
        ],
        "default": "private"
      },
      "tags": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "category": {
        "type": "string"
      },
      "public": {
        "type": "boolean",
        "default": false
      },
      "icon": {
        "type": "string"
      },
      "domainsOwned": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "crossDomainPublishes": {
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "domain",
            "reason"
          ],
          "properties": {
            "domain": {
              "type": "string"
            },
            "reason": {
              "type": "string"
            }
          }
        }
      },
      "streams": {
        "type": "object",
        "properties": {
          "reads": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "writes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "kv": {
        "type": "object",
        "properties": {
          "reads": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "writes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "interestGroups": {
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "name",
            "members"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "members": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "sharedResources": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "type",
                  "name"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "kv",
                      "stream"
                    ]
                  },
                  "name": {
                    "type": "string"
                  },
                  "purpose": {
                    "type": "string"
                  }
                },
                "additionalProperties": true
              }
            }
          }
        }
      },
      "subjects": {
        "type": "object",
        "required": [
          "publishes"
        ],
        "properties": {
          "publishes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "examples": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "subscriptions": {
        "type": "object",
        "properties": {
          "nats": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "pattern"
              ],
              "properties": {
                "pattern": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                }
              }
            }
          },
          "jetstream": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "subject",
                "stream"
              ],
              "properties": {
                "subject": {
                  "type": "string"
                },
                "stream": {
                  "type": "string"
                },
                "durable": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "http": {
        "type": "object",
        "properties": {
          "basePath": {
            "type": "string",
            "pattern": "^/api/[a-z][a-z0-9-]*$"
          },
          "targetBase": {
            "type": "string",
            "pattern": "^https?://[^\\s]+$"
          },
          "endpoints": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "method",
                "path"
              ],
              "properties": {
                "method": {
                  "type": "string",
                  "enum": [
                    "GET",
                    "POST",
                    "PUT",
                    "PATCH",
                    "DELETE",
                    "OPTIONS",
                    "HEAD"
                  ]
                },
                "path": {
                  "type": "string"
                },
                "purpose": {
                  "type": "string"
                },
                "response": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ui": {
        "type": "object",
        "properties": {
          "nav": {
            "type": "object",
            "properties": {
              "group": {
                "type": "string"
              },
              "order": {
                "type": "number"
              },
              "icon": {
                "type": "string"
              }
            }
          },
          "pages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "path",
                "title"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "path": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "layout": {
                  "type": "string"
                },
                "blocks": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "component"
                    ],
                    "properties": {
                      "component": {
                        "type": "string"
                      },
                      "props": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "mcp": {
        "type": "object",
        "properties": {
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "description"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "method": {
                  "type": "string"
                },
                "path": {
                  "type": "string"
                },
                "inputSchema": {
                  "type": "object"
                },
                "params": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "name",
                      "type"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      },
                      "required": {
                        "type": "boolean"
                      },
                      "description": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "llm": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "rules": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "when",
                "then"
              ],
              "properties": {
                "when": {
                  "type": "string"
                },
                "then": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          },
          "skills": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "description"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "tools": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "additionalProperties": true
            }
          },
          "commands": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "description"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": true
                  }
                },
                "example": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "additionalProperties": true
            }
          },
          "knowledge": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "domain",
                "content"
              ],
              "properties": {
                "domain": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "imports": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string"
            },
            "snippet": {
              "type": "string"
            },
            "alias": {
              "type": "string"
            }
          }
        }
      },
      "limits": {
        "type": "object",
        "properties": {
          "timeout": {
            "type": "number"
          },
          "rateLimit": {
            "type": "string"
          }
        }
      },
      "auth": {
        "type": "object",
        "properties": {
          "required": {
            "type": "boolean"
          }
        }
      },
      "typeRef": {
        "type": "string",
        "const": "okham.core.type.capability",
        "description": "Core type for this instance."
      },
      "typeVersion": {
        "type": "string",
        "const": "0.1.0",
        "description": "Exact version of the Core type."
      }
    },
    "additionalProperties": true,
    "not": {
      "required": [
        "contractVersion"
      ]
    }
  }
}
