hex/docs/plans/personal-commands.md

173 lines
7 KiB
Markdown

# Personal Commands
**Status:** The literal-command MVP is implemented on macOS. This document
records the shipped contract and the remaining workspace lifecycle work.
## What Users Can Configure
Personal commands live in `~/.config/hex/hex.config.ts`. TypeScript owns ordinary
literal commands, named text transformations, and optional dictation control phrases. Rust retains protected
wake, sleep, cancellation, dictation lifecycle, meeting lifecycle, and typed
capture behavior.
```ts
import { defineHexConfig } from "@hex/commands"
export default defineHexConfig({
commands: {
"open-training": {
phrases: ["open training"],
group: "Websites",
description: "Open the training site",
run: ({ hex }) => hex.openUrl("https://example.com/training"),
},
},
})
```
Command keys are stable IDs. A command may be global or match one exact
application or browser host. Browser-host context currently comes from Brave
Browser. More-specific commands may specialize ordinary global commands;
commands that can coexist at equal specificity may not share a phrase.
Available capabilities are `openUrl`, `openApplication`, `openPath`, `press`,
and `typeText`. Handlers may compose several capabilities and may use ordinary
TypeScript, local modules, Effect, and installed npm packages.
`openUrl` accepts absolute web URLs and app deep links, for example
`hex.openUrl("slack://channel?team=T_EXAMPLE&id=C_EXAMPLE")`. The URL is passed
unchanged to macOS, which requires an installed handler for its scheme. Use
`openApplication("Slack")` to launch an app by name or path, not to navigate a
deep link. The API spelling is `openUrl`, not `openURL`. File URLs and inline
script/data URLs remain unsupported; use `openPath` for filesystem paths.
## Dictation Transformations
The config may register named string transformations. They appear as optional
final steps in every dictation mode and run in their displayed order after the
mode's corrections and optional OpenCode rewrite.
```ts
export default defineHexConfig({
transformations: {
lowercase: {
name: "Lowercase",
description: "Convert the final text to lowercase",
transform: (text) => text.toLowerCase(),
},
},
commands: {},
})
```
Each dictation selects one complete mode. The required Global mode applies
unless a more specific application or browser-host mode matches. A mode owns
its corrections, optional AI rewrite, and selected custom transformations;
contextual modes do not inherit hidden processing from Global.
## Trust Boundary
Config handlers and dependencies execute under Bun with the user's normal
filesystem, network, environment, and subprocess authority. The host is
supervised for lifecycle and bounded IPC; it is not a security sandbox. Review
agent changes and install only trusted dependencies.
Invalid config never replaces the last valid registry. Rust validates schema,
stable IDs, protected phrases, context predicates, and overlaps before
activation. Dictation remains available when Bun is absent or the config fails.
## Dictation Control Phrases
The optional `dictation` section replaces the native voice-dictation protocol:
```ts
export default defineHexConfig({
dictation: {
start: ["begin note"],
stop: ["finish note"],
send: ["send note"],
cancel: ["discard note"],
},
commands: {},
})
```
`start` matches an utterance prefix while HEX listens. `stop`, `send`, and
`cancel` match suffixes during active voice dictation. Each list must contain at
least one phrase. Omitting the section uses the native protocol.
## Workspace
Create the workspace from the Commands pane or run:
```sh
hex commands init
```
Provisioning installs:
```text
~/.config/hex/
├── hex.config.ts
├── package.json
├── tsconfig.json
├── AGENTS.md
├── .agents/skills/personal-commands/SKILL.md
└── .hex-sdk/
```
`.hex-sdk` is bundled and managed by HEX; it is not an npm package and must not
be edited. On startup, HEX atomically refreshes it from the running app bundle
and runs the targeted `bun update @hex/commands` when its contents or required
workspace dependencies change. A plain install can retain stale Effect peer
metadata for the local SDK in `bun.lock`. User config, unrelated package metadata, scripts, and third-party
dependencies are preserved. There is one narrow metadata exception: on init
and startup, HEX adds a missing Effect dependency or upgrades the exact legacy
pins `4.0.0-beta.97` and `4.0.0-beta.107` to the bundled SDK's exact
`peerDependencies.effect` version. The current exact pin is left untouched.
Effect entries in dependency, dev/optional/peer dependency, override, and
resolution maps are checked together so duplicate pins cannot conflict.
Custom Effect specifications are never silently replaced. Effect-targeting
indirect selectors (such as `**/effect` or `@hex/commands>effect`) and nested
Effect overrides/resolutions must be removed rather than automatically rewritten;
use the SDK-required exact version in `dependencies.effect`. Unrelated scoped
packages such as `@effect/platform` and `@other/effect` are preserved. Bun 1.3.14
honors `resolutions["**/effect"]`; some other selector forms are currently ignored
or warned about, but HEX rejects them rather than relying on that behavior.
Manifest validation failures leave existing files unchanged and report how to
repair the manifest. A symlinked `package.json` is retained when already current;
links needing migration and dangling links are never replaced automatically.
Update the linked manifest manually or use a regular manifest before retrying. Rewrites
preserve regular-file permissions. SDK refresh and manifest replacement are
separate operations, not a multi-file transaction: if writing the manifest
fails, the SDK may already be refreshed while the old manifest remains. Fix
the reported filesystem problem and rerun `hex commands init`; the unchanged
legacy pin still triggers migration and installation on retry.
Run `bun run check` after changing the config. HEX watches the workspace,
activates valid changes, and reports the last reload error in the Commands pane.
## Runtime Boundary
```text
hex.config.ts -> supervised Bun host -> validated serializable registry
-> native Rust resolver and executor
```
Bun and IPC never run in the partial-transcript recognition path. Transport,
pending invocations, tool calls, and status files are bounded. A failed host
preserves native commands and the last valid runtime snapshot where possible.
## Remaining Work
- Keep the managed SDK, skill, TypeScript, and Effect versions current across
app updates.
- Recover automatically when Bun or workspace dependencies become available
without requiring an app restart.
- Add typed capture descriptors only after real commands establish their
boundary and finalization needs.
- Add CLI checks, listing, reload, and log inspection when the Commands pane is
insufficient.
- Add user-visible handler admission or timeout policy only if runtime evidence
requires it.