> Canonical guide: https://developers.foxlight.ai/build/sdk/reference/discovery/
> Contract snapshots: Skulk 2.0.0 (b0af39c79b6b7102b2478062904f1d7cc8619975); SDK 1.0.1 (fe6e0f8737ae343769b8cfc0a67ab112b9efac52). Check the installed runtime when versions differ.

# discovery API

SDK 1.0.1. This reference describes the supported authoring interface.

## `DiscoveryErrorCode`

```python
type DiscoveryErrorCode = Literal['invalid_directory', 'limit', 'denied', 'unsupported', 'unavailable', 'timeout']
```

## `Mode`

```python
type Mode = Literal['unary', 'server_streaming', 'client_streaming', 'bidirectional']
```

## `Domain`

```python
type Domain = Literal['local', 'private_site', 'external']
```

## `DiscoveryError`

A sanitized discovery refusal; responses, URLs and credentials stay private.

### `DiscoveryError.__init__`

Expose a bounded error code without retaining the failed response.

```python
def __init__(self, code: DiscoveryErrorCode) -> None:
    ...
```

## `CapabilityOffer`

An immutable observation, with exact descriptor binding and no grant.

Runtime and incarnation describe the observed generation. Core independently
authenticates the actual caller and rechecks current custody at dispatch.

### Fields

```python
plugin_id: str
runtime_digest: str
incarnation: str
endpoint: CapabilityEndpoint
behavior: Literal['read', 'inference']
processing_domain: Domain
io_mode: Mode
stream_seconds: float
cleanup_seconds: float
startup_seconds: float
inference_seconds: float | None
```

| Field | Description | Declared defaults and constraints |
| --- | --- | --- |
| `plugin_id` | — | — |
| `runtime_digest` | — | — |
| `incarnation` | — | — |
| `endpoint` | — | — |
| `behavior` | — | — |
| `processing_domain` | — | — |
| `io_mode` | — | — |
| `stream_seconds` | — | — |
| `cleanup_seconds` | — | — |
| `startup_seconds` | — | — |
| `inference_seconds` | — | — |

## `CapabilityDirectory`

A complete validated observation; it is neither cached authority nor routing.

### `CapabilityDirectory.from_json`

Admit one bounded Core directory atomically through native descriptors.

Reject duplicate JSON keys, unsupported fields, inconsistent identities,
duplicate destinations and any malformed offer without returning a subset.

```python
def from_json(cls, source: bytes) -> CapabilityDirectory:
    ...
```

### `CapabilityDirectory.select`

Select an exact installed identity; absent or ambiguous matches refuse.

```python
def select(self, plugin_id: str, capability_id: str, version: str, *, node_id: str | None=None) -> CapabilityOffer:
    ...
```

### Fields

```python
offers: tuple[CapabilityOffer, ...]
```

| Field | Description | Declared defaults and constraints |
| --- | --- | --- |
| `offers` | — | — |

## `discover_capabilities`

Read fresh caller-authorized offers, owning HTTP cleanup on every outcome.

Install the `native-discovery` extra and an admitted native kernel. Supply
an enrolled Skulk client bearer, never provider credentials. Remote origins
require HTTPS; redirects and environment proxies are disabled. The optional
timeout bounds this metadata read, independently of all inference lifetimes.
`certificate_authority` optionally supplies the cluster's trusted PEM CA;
certificate and hostname verification remain enabled. No request,
authorization failure or stale observation is retried automatically.

```python
async def discover_capabilities(base_url: str, bearer: str, *, timeout_seconds: float=30, certificate_authority: str | None=None) -> CapabilityDirectory:
    ...
```
