|
| 1 | +--- |
| 2 | +title: Experimental Features |
| 3 | +description: Opt-in experimental runtime and type generation features in |
| 4 | + CommandKit |
| 5 | +--- |
| 6 | + |
| 7 | +CommandKit includes a small set of opt-in experimental features for |
| 8 | +improving startup performance and local developer ergonomics. |
| 9 | + |
| 10 | +:::warning Experimental features are disabled by default and may |
| 11 | +change in future minor releases. ::: |
| 12 | + |
| 13 | +## Enable Experimental Flags |
| 14 | + |
| 15 | +Set these flags in `commandkit.config.ts`: |
| 16 | + |
| 17 | +```ts title="commandkit.config.ts" |
| 18 | +import { defineConfig } from 'commandkit/config'; |
| 19 | + |
| 20 | +export default defineConfig({ |
| 21 | + experimental: { |
| 22 | + pregenerateCommands: true, |
| 23 | + incrementalRouter: true, |
| 24 | + }, |
| 25 | +}); |
| 26 | +``` |
| 27 | + |
| 28 | +## `experimental.pregenerateCommands` |
| 29 | + |
| 30 | +When enabled, `commandkit build` pre-generates a serialized command |
| 31 | +and event router artifact and writes it into build output: |
| 32 | + |
| 33 | +- `dist/.commandkit/router-tree.json` |
| 34 | + |
| 35 | +At runtime in production, CommandKit attempts to hydrate routers from |
| 36 | +this artifact instead of performing full filesystem traversal. |
| 37 | + |
| 38 | +If the artifact is missing, stale, or invalid (for example version |
| 39 | +mismatch), CommandKit automatically falls back to dynamic runtime |
| 40 | +resolution. |
| 41 | + |
| 42 | +### Why Use It |
| 43 | + |
| 44 | +- Keeps production cold starts predictable as command/event trees |
| 45 | + grow. |
| 46 | +- Avoids repeated full tree construction work on each startup. |
| 47 | + |
| 48 | +## `experimental.incrementalRouter` |
| 49 | + |
| 50 | +When enabled, development HMR updates only the subtree affected by a |
| 51 | +file change instead of reconciling the full router tree. |
| 52 | + |
| 53 | +This applies to command and event routers during `commandkit dev`, |
| 54 | +including file add/change/delete operations. |
| 55 | + |
| 56 | +### Why Use It |
| 57 | + |
| 58 | +- Reduces reload lag in larger bots. |
| 59 | +- Preserves unchanged router state across updates. |
| 60 | + |
| 61 | +## Type Generation (`commandkit typegen`) |
| 62 | + |
| 63 | +CommandKit can generate command route types for editor autocomplete. |
| 64 | + |
| 65 | +Run: |
| 66 | + |
| 67 | +```sh |
| 68 | +commandkit typegen |
| 69 | +``` |
| 70 | + |
| 71 | +This writes: |
| 72 | + |
| 73 | +- `./.commandkit/types.ts` (generated command route registry) |
| 74 | +- `./commandkit-env.d.ts` (type reference file) |
| 75 | + |
| 76 | +`commandkit-env.d.ts` references the generated file: |
| 77 | + |
| 78 | +```ts title="commandkit-env.d.ts" |
| 79 | +/// <reference path="./.commandkit/types" /> |
| 80 | +``` |
| 81 | + |
| 82 | +During development, CommandKit also refreshes generated command route |
| 83 | +types after command reloads. |
| 84 | + |
| 85 | +### Where You See It |
| 86 | + |
| 87 | +APIs that accept resolvable command names (for example |
| 88 | +`ctx.forwardCommand(...)`) get route-aware autocomplete when generated |
| 89 | +types are present. |
0 commit comments