Keybindings
A keybinding does not contain behaviour. It points at a command by id.
import { function command<const TId extends string, TResult>(commandValue: CommandInput<TId, TResult>): Command<TId, TResult>Declare an action the user runs from the command palette or a keybinding. Reach for this when a person triggers the behavior. The `title` is what they read in the palette, `category` groups the entry, and `when` decides whether it shows up at all. The handler takes no argument, only a context. Whatever it returns is the command's result: `ctx.commands.execute(thisCommand)` resolves with that type, and the build compiles the same type into the result contract the host enforces, so return JSON data or nothing. Two neighbours are easy to confuse. `slashCommand` is also user-triggered, but it is typed inside a chat session and receives free text plus the live AI session. `tool` is not user-triggered at all, the model decides to call it mid-turn. The result goes in the mod's top-level `commands` array, alongside any slash commands. The `id` is the address a keybinding or a `command:` hook targets, so keep it stable.command, function defineMod(definition: ModDefinition): ModThe entry point of the SDK. A mod's module default-exports one `defineMod` call and nothing else. The returned value is data. It registers nothing, starts nothing, and touches no host state. The host folds it twice. At build time it runs the module in a throwaway sandbox and reads the value to derive the serializable manifest. At runtime it folds the same value again to wire your handlers into their lanes: ext-host for commands, tools, effects, and hooks; the sandboxed renderer for views. That double fold is why the module must be pure. It is re-executed to produce the manifest, so anything at the top level, a file read, a network call, a timer, a `console` line, runs during a build with no host attached. Put behavior inside handlers: `run`, `activate`, `handle`.defineMod, function keybinding<TCommand extends Command | string>(input: KeybindingInput<TCommand>): Keybinding<TCommand>Bind a keyboard shortcut to a command. Pass the `command` value itself when the command lives in the same mod, so the id is written once and a rename cannot break the binding. Pass a string only for a command someone else owns. A binding does not decide when the command is available. Give it the same Condition you gave the command's `when` so the chord goes quiet in the same situations the palette entry does.keybinding } from '@modular/sdk'; export default function defineMod(definition: ModDefinition): ModThe entry point of the SDK. A mod's module default-exports one `defineMod` call and nothing else. The returned value is data. It registers nothing, starts nothing, and touches no host state. The host folds it twice. At build time it runs the module in a throwaway sandbox and reads the value to derive the serializable manifest. At runtime it folds the same value again to wire your handlers into their lanes: ext-host for commands, tools, effects, and hooks; the sandboxed renderer for views. That double fold is why the module must be pure. It is re-executed to produce the manifest, so anything at the top level, a file read, a network call, a timer, a `console` line, runs during a build with no host attached. Put behavior inside handlers: `run`, `activate`, `handle`.defineMod({ metadata: ModMetadatametadata: { ModMetadata.displayName: stringdisplayName: 'Hello', ModMetadata.description: stringdescription: 'A first mod' }, commands?: readonly ModCommand<string>[] | undefinedcommands: [ function command<"hello.greet", void>(commandValue: CommandInput<"hello.greet", void>): Command<"hello.greet", void>Declare an action the user runs from the command palette or a keybinding. Reach for this when a person triggers the behavior. The `title` is what they read in the palette, `category` groups the entry, and `when` decides whether it shows up at all. The handler takes no argument, only a context. Whatever it returns is the command's result: `ctx.commands.execute(thisCommand)` resolves with that type, and the build compiles the same type into the result contract the host enforces, so return JSON data or nothing. Two neighbours are easy to confuse. `slashCommand` is also user-triggered, but it is typed inside a chat session and receives free text plus the live AI session. `tool` is not user-triggered at all, the model decides to call it mid-turn. The result goes in the mod's top-level `commands` array, alongside any slash commands. The `id` is the address a keybinding or a `command:` hook targets, so keep it stable.command({ id: "hello.greet"id: 'hello.greet', title: stringtitle: 'Greet', run: (call: CommandCall) => Awaitable<void>run: ({ ctx: CommandContextctx }) => { ctx: CommandContextctx.ui: UiCapabilityNotifications, dialogs, quick input, and progress.ui.UiCapability.notification: UiNotificationCapabilitynotification.UiNotificationCapability.info(notice: UiNotice): voidinfo({ UiNotice.message: stringmessage: 'Hello.' }); }, }), ], keybindings?: readonly Keybinding<string | Command<string, unknown>>[] | undefinedkeybindings: [ function keybinding<string>(input: KeybindingInput<string>): Keybinding<string>Bind a keyboard shortcut to a command. Pass the `command` value itself when the command lives in the same mod, so the id is written once and a rename cannot break the binding. Pass a string only for a command someone else owns. A binding does not decide when the command is available. Give it the same Condition you gave the command's `when` so the chord goes quiet in the same situations the palette entry does.keybinding({ KeybindingInput<TCommand extends Command | string = string | Command<string, unknown>>.id: stringid: 'hello.greet.key', KeybindingInput<string>.command: stringcommand: 'hello.greet', KeybindingInput<TCommand extends Command | string = string | Command<string, unknown>>.key: stringkey: 'ctrl+alt+g', KeybindingInput<TCommand extends Command | string = string | Command<string, unknown>>.mac?: string | undefinedmac: 'cmd+alt+g', }), ], });
Members
Keybinding — id, command, key,
mac, win, linux, args, when, systemWide, kind.
keyis the default chord.mac,win, andlinuxoverride it per platform — set them when the natural chord differs, not to restate the same thing three times.argsis passed to the command when the chord fires.whengates the binding the same way it gates a command. A chord that is live in the wrong context is worse than no chord.systemWideis the one to think twice about. It takes the chord outside the app, so it competes with every other program the person is running.
The id is a contract
command holds a command id as a string. Nothing type-checks that the target
exists at author time, so renaming a command id and forgetting its keybinding
leaves a binding pointing at nothing.