hex/src/personal_commands/commands.js
Dax 6b988c493c
Run personal commands in embedded QuickJS instead of Bun (#300)
* Run personal commands in embedded QuickJS instead of Bun

Hex now runs ~/.config/hex/hex.config.ts in-process: rquickjs on one worker
thread, TypeScript erased to same-position JavaScript with oxc's parser,
per-call time limits and a runtime memory limit, and no filesystem, network,
process, or timer API. Handlers return actions that Hex validates and runs on
its native executor. The Bun host, managed SDK provisioning, bun update, the
sdk/commands workspace, and their scripts and CI steps are gone; Hex writes
hex.d.ts typings instead, and hex commands check replaces bun run check.

Plan and measurements: docs/plans/quickjs.md.

* Spell out a range check that a new dependency's impls made ambiguous
2026-10-28 15:06:45 -04:00

31 lines
1.3 KiB
JavaScript

// The `@hex/commands` module scripts import. `hex.d.ts` types it.
const frozen = (value) => Object.freeze(value)
export const openUrl = (url) => frozen({ type: "openUrl", url })
export const openApplication = (application) => frozen({ type: "openApplication", application })
export const openPath = (path) => frozen({ type: "openPath", path })
export const typeText = (text) => frozen({ type: "typeText", text })
export function press(input) {
if (typeof input === "string") return frozen({ type: "press", key: input })
const action = { type: "press", key: input.key }
if (input.modifiers !== undefined) action.modifiers = [...input.modifiers]
if (input.repeat !== undefined) action.repeat = input.repeat
return frozen(action)
}
export const digit = ({ min = 0, max = 9 } = {}) => frozen({ type: "digit", min, max })
export const letter = () => frozen({ type: "letter" })
export const text = () => frozen({ type: "text" })
export function choice(input) {
const entries = Array.isArray(input) ? input.map((value) => [value, [value]]) : Object.entries(input)
const choices = {}
for (const [value, aliases] of entries) choices[value] = [...(choices[value] ?? []), ...aliases]
return frozen({ type: "choice", choices })
}
export const union = (...members) => frozen({ type: "union", members })
export const defineHexConfig = (config) => config