> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khanhng.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 4.2 Plugin contract

> Reference for the KcodePlugin interface and its metadata, routes, navigation, permissions, settings, and commands.

## 4.2.1 KcodePlugin

```ts theme={"system"}
import type { KcodePlugin } from "@kcode/plugin-sdk";

export const myPlugin: KcodePlugin = {
  id: "my-new-plugin",
  name: "My New Plugin",
  version: "1.0.0",
  sdkVersion: "1.0.0",
  metadata: {
    id: "my-new-plugin",
    name: "My New Plugin",
    description: "What the demo shows.",
    category: "Operations",
    version: "1.0.0",
    status: "available",
    technologies: ["Typed mock services"],
  },
  entry: MyEntry,
};
```

| Field | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | Lowercase kebab-case. Must be unique. |
| `name` | `string` | Yes | Display name. Must equal `metadata.name`. |
| `version` | `string` | Yes | Semantic version. Must equal `metadata.version`. |
| `sdkVersion` | `string` | Yes | Semantic version of the SDK contract the plugin targets. |
| `metadata` | `PluginMetadata` | Yes | Launcher information. |
| `entry` | `PluginEntryComponent` | No | React component that receives `{ context }`. A plugin without it shows as "Coming soon". |
| `routes` | `PluginRoute[]` | No | Routes the plugin owns. |
| `navigation` | `PluginNavigation[]` | No | Navigation items. |
| `permissions` | `PluginPermission[]` | No | Permissions the plugin declares. |
| `settings` | `PluginSetting[]` | No | Typed settings with defaults. |
| `commands` | `PluginCommand[]` | No | Commands with an `execute(context)` function. |
| `register`, `initialize`, `activate`, `deactivate`, `dispose` | `(context) => void \| Promise<void>` | No | Lifecycle hooks. |

## 4.2.2 PluginMetadata

| Field | Type | Description |
| - | - | - |
| `id`, `name`, `version` | `string` | Must match the plugin's own fields. |
| `description` | `string` | Non-empty. Shown on the launcher card. |
| `category` | `string` | Non-empty. Shown on the launcher card. |
| `icon` | `string` | Optional. Must be non-empty when set. |
| `status` | `"available" \| "development" \| "coming-soon"` | The launcher marks only `available` as success. |
| `technologies` | `string[]` | At least one unique value. Shown as tags. |

## 4.2.3 PluginRoute and PluginNavigation

| Type | Field | Description |
| - | - | - |
| `PluginRoute` | `path` | Starts with `/`, not `//`. Unique across plugins. |
| | `title` | Non-empty. |
| | `description`, `requiresAuthentication` | Optional. |
| | `requiredPermissions` | Optional list of permission IDs. |
| `PluginNavigation` | `id`, `label`, `href` | Required. The ID is unique across plugins. |
| | `icon`, `order`, `visible` | Optional. `order` must be finite. Registry output is sorted by `order`, then `id`. |

## 4.2.4 PluginPermission

| Field | Description |
| - | - |
| `id` | Letters, digits, `.` and `-`. Unique across plugins. Example: `operations.dashboard.read`. |
| `name`, `description` | Non-empty text. |
| `category` | Optional grouping label. |

## 4.2.5 PluginSetting

A setting is a discriminated union on `type`.

| `type` | `defaultValue` | `options` |
| - | - | - |
| `string` | `string` | Not allowed |
| `number` | Finite `number` | Not allowed |
| `boolean` | `boolean` | Not allowed |
| `select` | `string` that matches an option | Required, unique values |
| `multiselect` | `string[]` of option values | Required, unique values |

Every setting also has `key`, `label`, and optional `description` and `required`.

## 4.2.6 PluginCommand

| Field | Description |
| - | - |
| `id` | Unique within the plugin. |
| `title` | Non-empty. |
| `description` | Optional. |
| `requiredPermissions` | Optional list of permission IDs. |
| `execute(context)` | Runs the command. May be async. |

## 4.2.7 Lifecycle states

`PluginLifecycleState` is `discovered`, `registered`, `initialized`, `active`, `inactive`, or `disposed`. See the [runtime view](https://docs.khanhng.com/kcode-robot-suite/architecture/06-runtime-view.md) for allowed transitions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.