Imports
Every entry below is a real exports in package.json, so it resolves in an installed project with no build step. Page code imports none of them — a page uses the window.crust the bridge injects. crust/vite is imported by vite.config.ts, never by a page.
Command namespaces
A page reaches the backend with window.crust.invoke(plugin, command, args), or the two-argument form that routes to app.invoke. There are 34 namespaces registered on every start plus five conditional ones — app, single-instance, pty, updater and testing — for 39 in all; updater joins when the config has an updater section, pty when it has a pty one (Pty), and testing only when the process starts with CRUST_TEST=1. They are documented by area, one page each:
window,window-state,positioner— a window's life, its remembered frame, and nine placements.fs,store,database,keychain,shell,sidecar,stronghold,pty— text files and their scope, a JSON key-value file, SQLite, OS-protected secrets, an allowlisted program, a bundled helper process, an encrypted store, and a real terminal (Pty).dialog,notification,tray,menu,clipboard,shortcut— panels, the notification centre, the menu bar, the pasteboard, hot keys.theme,dock,power,screen,accessibility,opener,os— appearance, the dock tile, power state, the displays, the AX trust read, the OS hand-off, machine facts.app,autostart,logging,i18n,single-instance,deep-link— backend commands, launch at login, the log sink, the language catalogue, the lock, the launch URL.navigation,findinpage,downloads,network,crash-reporter— the webview's own loads, find, downloads, request rules and crash record.browser,preview— an embeddedhttp(s)surface in a rectangle the app reserves, and an embedded file panel.updater— manifest, verified download, bundle swap.testing— drive and observe a running page: a DOM click, typed text, one key, queries, waits and the page's console. Registered only whenCRUST_TEST=1; anywhere else the name answersunknown-plugin.
Each page states every command's arguments, its answer and the failure codes it can return. The bridge-level codes are on the errors page.
Failure status
A command that answers a typed failure value instead of throwing — { ok: false, code, message } from window, tray, database, updater and others — is sent with a 4xx/5xx HTTP status chosen from its code through the same table CrustError uses (invalid-label, invalid-title → 400, unknown-window → 404, unknown-adapter → 501, an unmapped code → 400). The body is unchanged: the envelope is still { ok: true, result: … } and the typed failure is still the resolved result, so a page that branches on result.code or result.ok sees exactly what it saw before and a fire-and-forget await crust.invoke(...) is never handed a new rejection. isCrustInvokeError stays the guard for the separate rejection path; these values are not errors in that sense. What changes is the transport: a caller working at the fetch level can now tell a refusal from a success without reading the body.
crust
The package root, src/index.ts.
| export | signature |
|---|---|
app | app: App — the module-level singleton, inert until a platform and config are attached |
App | class App — the methods below |
createApp | createApp(platform: Platform, config: CrustConfig, bridgeUrl?: string): App |
PUMP_INTERVAL_MS | const PUMP_INTERVAL_MS = 16 |
CONFIG_FILES | ["crust.config.ts", "crust.json"] |
findConfig | findConfig(dir: string): Promise<string | undefined> |
loadConfig | loadConfig(options?: LoadConfigOptions): Promise<LoadedConfig> |
validateConfig | validateConfig(value: unknown, source?: string): CrustConfig |
ConfigError | class ConfigError extends Error — carries issues: ConfigIssue[] |
definePlugin | re-exported from crust/plugin |
notImplemented, isNotImplemented, NotImplementedError | re-exported from crust/plugin |
App
| method | signature |
|---|---|
command | command(name: string, handler: (args: Record<string, unknown>) => unknown | Promise<unknown>): this |
use | use(plugin: PluginDefinition): this |
plugins | plugins(): readonly PluginDefinition[] |
on | on(event: AppEvent, listener: (error?: Error) => void | Promise<void>): this — AppEvent is ready, window-all-closed, activate, before-quit, will-quit, reopen, error |
run | run(): Promise<void> |
quit | quit(): void |
invoke | invoke(name: string, args?: Record<string, unknown>): Promise<unknown> |
attach | attach(platform: Platform, config: CrustConfig, bridgeUrl?: string): this — internal |
configure | configure(config: CrustConfig): this — internal |
deferBridge | deferBridge(factory: (config: CrustConfig) => string): this — internal |
The last three are what startApp calls before importing your main.ts; they are public only because App lives in another module. Calling attach or configure yourself is correct only in a test. command and use both throw after run() has started.
Types
AppEvent, AppListener, CommandHandler, Platform, WindowHandle, WindowOptions, AppConfig, BuildConfig, ConfigIssue, CrustConfig, DevConfig, LoadedConfig, LoadConfigOptions, SecurityConfig, WindowConfig.
crust/native/<platform>
Three native adapter subpaths: src/native/darwin.ts, src/native/windows.ts and src/native/linux.ts. An app that mounts its own native set needs the platform's adapter factories; crust/plugin exports only plugin factories. There is no bare crust/native entry: a compiled bundle embeds exactly one platform's set, so a Windows build must not even resolve a module that imports AppKit.
| subpath | import | exports |
|---|---|---|
crust/native/darwin | import { darwinDialogAdapter, darwinMenuAdapter } from "crust/native/darwin" | darwinDialogAdapter, darwinMenuAdapter, darwinNotificationAdapter, darwinKeychainAdapter, createStatusBar/currentStatusBar (tray), darwinShortcutsAdapter, darwinDockAdapter, darwinThemeAdapter, listScreens/windowWorkAreas/mainScreenFrame (screen), darwinPowerAdapter, darwinAccessibilityAdapter, darwinNavigationAdapter, darwinFindAdapter, darwinDownloadsAdapter, darwinOpenerAdapter, darwinOsAdapter, darwinClipboardAdapter |
crust/native/windows | import { windowsDialogAdapter, windowsTrayAdapter } from "crust/native/windows" | windowsDialogAdapter, windowsNotificationAdapter, windowsKeychainAdapter, windowsTrayAdapter, windowsClipboardAdapter, windowsOpenerAdapter, windowsOsAdapter, windowsScreenAdapter/windowsWindowWorkAreas, windowsBrowserAdapter, windowsWindowAdapter |
crust/native/linux | import { linuxDialogAdapter, linuxTrayAdapter } from "crust/native/linux" | linuxDialogAdapter, linuxNotificationAdapter, linuxKeychainAdapter, linuxTrayAdapter, linuxClipboardAdapter, linuxOpenerAdapter, linuxOsAdapter, linuxScreenAdapter/linuxWindowWorkAreas, linuxBrowserAdapter, linuxWindowAdapter |
Every export is a literal static re-export from that platform's src/platform/<platform>/ modules, so bun build --compile embeds the adapter and a compiled app gets the same factory a dev run gets. Each subpath imports only its own platform — no darwin module is reachable from the Windows or Linux entry, and vice versa.
An app must not use import.meta.resolve("crust") or a relative require into node_modules/crust/src/platform/... to find these. Inside a compiled executable the package root is /$bunfs/root, where no package.json exists, so resolution throws and a loader that catches it answers undefined for every adapter — the panel, menu or notification then fails silently. Import the matching subpath instead.
crust/plugin
The plugin entry point, src/plugins/index.ts: the registry, the built-in plugins, and the native adapter factories.
| export | signature |
|---|---|
definePlugin | definePlugin<Name extends string, Commands extends CommandMap>(plugin: { name: Name; commands: Commands }): PluginDefinition<Name, Commands> |
notImplemented | notImplemented(message: string, requires: string): NotImplemented |
isNotImplemented | isNotImplemented(value: unknown): value is NotImplemented |
NotImplementedError | new NotImplementedError(message: string, requires: string) |
PluginRegistry | new PluginRegistry() — register, invoke(pluginName, commandName, args, ctx), has, get, names, commandsOf, handlers |
handlerMap | handlerMap(source: HandlerSource): Map<string, CommandHandler> |
| plugin values | fsPlugin, dialogPlugin, notificationPlugin, trayPlugin, windowPlugin, windowStatePlugin, positionerPlugin, clipboardPlugin, openerPlugin, osPlugin, shortcutsPlugin, menuPlugin, themePlugin, dockPlugin, powerPlugin, accessibilityPlugin, navigationPlugin, findinpagePlugin, downloadsPlugin, networkPlugin, crashReporterPlugin, i18nPlugin, storePlugin, strongholdPlugin, updaterPlugin, autostartPlugin, loggingPlugin, singleInstancePlugin, testingPlugin — each a PluginDefinition, built with the plugin's default adapter or with none where it needs a platform half |
| factories | createFsPlugin(options?), createDialogPlugin(native?), createNotificationPlugin(adapter?), createTrayPlugin(adapter?), createWindowPlugin(adapter?), createWindowStatePlugin(options?), createPositionerPlugin(options?), createClipboardPlugin(adapter?), createOpenerPlugin(adapter?), createOsPlugin(adapter?), createShortcutsPlugin(adapter?), createMenuPlugin(adapter?), createThemePlugin(adapter?), createDockPlugin(adapter?), createPowerPlugin(adapter?), createAccessibilityPlugin(adapter?), createNavigationPlugin(adapter?), createFindInPagePlugin(adapter?), createDownloadsPlugin(adapter?, options?), createNetworkPlugin(adapter?, options?), createCrashReporterPlugin(options?), createI18nPlugin(options?), createStorePlugin(adapter?), createShellPlugin(options?), createStrongholdPlugin(options?), createUpdaterPlugin(adapter?, options?, execPath?), createAutostartPlugin(adapter?), createLoggingPlugin(adapter?), createSingleInstancePlugin(options?), createTestingPlugin(adapter?) |
corePlugins | [fsPlugin, dialogPlugin, notificationPlugin, trayPlugin, autostartPlugin, loggingPlugin], plus testingPlugin when process.env.CRUST_TEST === "1". strongholdPlugin is built by the runtime with this app's data root (like storePlugin) so two apps cannot share one vault |
coreRegistry | coreRegistry(): PluginRegistry |
WINDOW_COMMANDS | 27 command names, create … capture |
POWER_COMMANDS | ["state", "idleSeconds", "sleepPrevent", "sleepAllow", "onSleep", "onLock", "onWake", "onScreenSleep", "onScreenWake", "onUnlock"] — the four reads and the six push commands |
WindowAdapterError | class WindowAdapterError extends Error — carries code: WindowErrorCode |
deepLink | a DeepLink object: .plugin (the deep-link definition), .scheme, .url(), .launch(url, ctx?), .open(url, ctx?) |
| updater values | nodeUpdaterAdapter, parseManifest, verifyEd25519, signatureMismatch, readSignatureArgs, decodeBase64, isEd25519Pubkey, isSignature, ED25519_PUBKEY_BYTES, ED25519_SIGNATURE_BYTES |
| other constants | NETWORK_SCHEME, NETWORK_LOG_LIMIT, SHELL_OUTPUT_LINES, RING_SIZE, THEME_CHANGED, STORE_FILE, STORE_VERSION, KDF_NAME, KDF_ITERATIONS, SALT_BYTES, defaultStoreRoot, isLogLevel, parseDeepLink |
Every create* factory returns a PluginDefinition. Without an adapter a plugin fails honestly rather than resolving a fake: notImplemented for dialog, notification, tray, window, window-state, positioner, clipboard, opener, os, shortcut, menu, theme, dock, power, accessibility, navigation, findinpage, downloads, network and single-instance.activate, and unknown-adapter for window.create and any optional adapter member a platform did not supply. A plugin also declares its native half as native: { requires, available }, and the registry writes one error line at startup naming every namespace whose adapter is missing — a built app with no native half says so once instead of failing each later call in silence. windowPlugin is createWindowPlugin() with no adapter, and corePlugins leaves window out because its adapter needs the running platform; the runtime appends it before plugin selection.
shellPlugin is deliberately not exported: shell needs the config's allowlist, so it is only reachable as createShellPlugin({ allow, cwdRoot }). The same holds for updater, which the runtime registers only when the config has an updater section.
Types
PluginContext, PluginDefinition, NotImplemented, CommandMap, CommandSchema, MaybePromise, ArgsOf, ResultOf, SchemaOf, CommandHandler, DialogNative, OpenPanelOptions, OpenPanelResult, SavePanelOptions, SavePanelResult, CancelPanelResult, NotificationNative, NotificationPermission, NotifyOptions, NotifyResult, TrayNative, TrayOptions, TrayResult, WindowNative, WindowCreateOptions, WindowCreateResult, WindowCloseResult, WindowFocusResult, WindowTitleResult, WindowListResult, WindowOpenResult, WindowLabelArgs, WindowLabelAnswer, WindowSetTitleArgs, WindowCreateArgs, WindowErrorCode, WindowFailure, WindowSnapshot, WindowCaptureArgs, WindowCaptureResult, WindowCaptureNative, ReadTextFileArgs, WriteTextFileArgs, WriteTextFileResult.
Every later plugin re-exports its own vocabulary from the same barrel: NetworkRule, NetworkLogEntry, DownloadEntry, DownloadsCommands, StrongholdFailure, UpdaterFailure, UpdateManifest, ThemeState, MenuFailure, TrayFailure, ClipboardFailure, ShellFailure, ShellCommands, ShortcutFailure, PowerFailure, DockFailure, NavigationState, NavigationFailure, FindOutcome, FindFailure, I18nOptions, TranslationResult, CrashReporterOptions, LastCrashResult, ClearCrashesResult, DeepLinkTarget, FsScopeOptions, FsScopeStatus, TestingAdapter, TestingCommands, TestingFailure, TestingCode, TestingArgs, TestingSelectorArgs, TestingPointArgs, TestingTypeArgs, TestingKeyArgs, TestingWaitArgs, TestingConsoleArgs, TestingModifiers, QueryResult, ConsoleEntry.
ArgsOf, ResultOf and SchemaOf are types only, for deriving a typed client from a tuple of plugin definitions; nothing is exported at runtime for them.
crust/vite
The dev-server half of the bridge: it injects window.__CRUST__ and the page client into the document a dev server serves.
| export | signature |
|---|---|
crust | crust(options?: CrustOptions): Plugin |
BRIDGE_URL_VAR | const BRIDGE_URL_VAR = "CRUST_BRIDGE_URL" |
BRIDGE_TOKEN_VAR | const BRIDGE_TOKEN_VAR = "CRUST_BRIDGE_TOKEN" |
CrustOptions is { urlVar?: string; tokenVar?: string }, defaulting to the two constants above.
import { crust } from "crust/vite";
export default defineConfig({
server: { port: 5173, strictPort: true },
plugins: [crust()],
});
Serve-only (apply: "serve"), and the handshake is read per document request, never at config time. strictPort is required: the bridge allows exactly the origin dev.url names, so a port that drifts makes every invoke bad-origin. With neither variable nor handshake file present it warns once and injects nothing.