Skip to content

Quickstart

This creates a runtime, contributes one command to the palette and slash surfaces, reads the snapshot, and runs the command:

import { createWhistle } from "@fungi.computer/whistle";
const whistle = createWhistle();
const lease = whistle.contribute({
sourceId: "editor",
namespace: "editor",
commands: [
{
id: "save",
title: "Save file",
category: "File",
projections: {
palette: {},
slash: { aliases: ["save"] },
bindings: { values: ["mod+s"] },
},
handler: () => ({ saved: true }),
},
],
});
const snapshot = whistle.snapshot();
console.log(snapshot.palette.map((row) => row.commandId)); // ["editor:save"]
console.log(snapshot.slash.map((row) => row.alias)); // ["save"]
const outcome = await whistle.execute("editor:save", { origin: "palette" });
if (outcome.status === "handled") console.log(outcome.result); // { saved: true }
lease.dispose();
whistle.close();

A command’s canonical ID is <namespace>:<id>. Every projection row carries that ID, so a palette click, a key press and a slash command all call the same execute.