hex/sdk/commands/workspace-template/hex.config.ts
Kit Langton c768021ba4 feat: add typed captures to personal commands
Add bounded digit, letter, choice, union, and text captures across the TypeScript SDK, host protocol, Rust grammar, and command runtime. Validate capture schemas and invocation payloads before activation, preserve exact inferred handler types, and document the personal-command workflow.\n\nKeep modifier-only dictation events passive so Finder and other applications still receive Option state changes. Also emit balanced synthetic modifier transitions, tighten local installation behavior, and refine recording HUD responsiveness.
2026-08-03 17:04:10 -04:00

45 lines
1.7 KiB
TypeScript

import { choice, defineHexConfig, digit, letter, union } from "@hex/commands"
export default defineHexConfig({
// Transformations appear as optional final steps in every dictation mode.
// transformations: {
// lowercase: {
// name: "Lowercase",
// description: "Convert the final text to lowercase",
// transform: (text) => text.toLowerCase(),
// },
// },
// Uncomment this block to replace HEX's native voice-dictation protocol.
// dictation: {
// start: ["begin note"],
// stop: ["finish note"],
// send: ["send note"],
// cancel: ["discard note"],
// },
commands: {
"open-example": {
phrases: ["open example"],
group: "Websites",
description: "Open the example site",
run: ({ hex }) => hex.openUrl("https://example.com"),
},
// A trailing {capture} placeholder collects the rest of the spoken
// phrase: "search amazon for wool socks" -> captures.query === "wool socks".
"search-amazon": {
phrases: ["search amazon for {query}"],
group: "Websites",
description: "Search Amazon for the spoken words",
run: ({ hex, captures }) =>
hex.openUrl(`https://www.amazon.com/s?k=${encodeURIComponent(captures.query ?? "")}`),
},
// Explicit descriptors compose multiple captures and infer exact handler types.
"control-key": {
phrases: ["control {key}"],
captures: { key: union(letter(), digit(), choice(["home", "end"] as const)) },
group: "Keyboard",
description: "Press Control plus a letter, digit, Home, or End",
run: ({ hex, captures }) =>
hex.press({ key: String(captures.key), modifiers: ["control"] }),
},
},
})