Expand description
Everything is a command.
An app declares its commands once (CommandSpec) in a Registry. Menus, shortcuts, the
command palette, the CLI, the control port and MCP all reach the app through one chokepoint,
Registry::execute, and discover it through Dispatch::commands.
Contract (shared with ashlar-control, ashlar-mcp, ashlar-cli, ashlar-app): the items marked
CONTRACT below are depended on by sibling crates being built in parallel. Change them only by
adding (new fields behind #[serde(default)], new trait methods with defaults).
Re-exports§
pub use keymap::Keymap;pub use suggest::closest;pub use suggest::did_you_mean_command;pub use suggest::params_summary;
Modules§
- keymap
- Which key runs which command: the commands’ default shortcuts plus the user’s overrides.
- menu
- The menu bar as plain, serializable data: one model for every renderer.
- shortcut
- Portable keyboard shortcuts.
- suggest
- “Did you mean …?”: the names closest to a mistyped one (a command id, a parameter key), and a one-line summary of a command’s parameters, so an error can say what to call instead.
Macros§
- cmd
- A mutating command:
cmd!(id, label, [menu…], shortcut, params, enabled, run). - query
- A pure query (always enabled, not in menus, not journaled):
query!(id, label, params, run).
Structs§
- Bound
- A registry bound to one state: what control port, MCP and CLI drive through
Dispatch. - Command
Info - CONTRACT: what discovery returns for one command (palette, menus, MCP tools, CLI
commands). - Command
Run - One top-level command that ran, as the chokepoint saw it: the registered id (a fixed program string, never its parameters), whether it succeeded and how long its body took.
- Command
Spec - One command of host state
S. Build it withcmd!/query!(the shape of existing command tables) or withCommandSpec::newand itsconstsetters. - Fuzzy
Match - A match: higher scores are better;
positionsare the matched char indices of the candidate (for highlighting), ascending. - Journal
- The journal of a host: the mutating commands that succeeded, in order, with scrubbed params
(replay, session logs, agent “what happened”). Also tracks the current nesting depth of
crate::Registry::execute. - Journal
Entry - One recorded command call.
- Param
- A typed parameter declared in a
const/staticcommand table:Param::int_in("width", 1, 16384).required().about("pixels"). - Param
Spec - CONTRACT: one typed parameter.
- Registry
- The command table of one app. Immutable once built (a
staticis typical); the execution state lives in the host’scrate::Journal.
Enums§
- Command
Error - CONTRACT: why a command failed. Hosts wrap their own errors in
CommandError::Failed. - Exec
Error - Why a call through
Registry::execute_hostfailed: the chokepoint refused or lost it (Command: unknown, too deeply nested,Host::before, validation, disabled, panicked), or the command body returned the host’s own error (Host, unchanged, as callers match on it). - Kind
- The kind of a
Param; theconstcounterpart ofParamKind. - Param
Kind - CONTRACT: the kind of one typed parameter. Maps 1:1 onto JSON Schema.
- Params
- How a command documents its parameters: typed (preferred, gives JSON Schema and validation) or the legacy free-text description older command tables use (accepted, validated loosely).
- Validation
- Which declarations
Registry::executechecks params against beforeHost::enabled_for(set withRegistry::with_validation). Whatever the policy,Host::validateruns at the same step, andRegistry::validatestays available for checking on demand.
Constants§
- MAX_
DEPTH - Commands may run other commands up to this depth; deeper calls are refused (a command that calls itself, directly or through others, cannot overflow the stack).
Traits§
- Dispatch
- CONTRACT: anything that can list and run commands. Implemented by
Registry-backed sessions, by the control-port client (remote app) and by test doubles. Object-safe. - Host
- The host state commands run on, and the hooks the chokepoint calls around every command.
Functions§
- accepted_
params - Top-level keys accepted by a params doc;
Nonewhen the doc isn’t a{…}key list (then nothing is refused). - always
- The enabled predicate of a command that is always available.
- fuzzy_
match - Score
candidateagainstquery;Nonewhen the query’s characters do not all appear in order. An empty query matches everything with score 0. - fuzzy_
rank - Match
queryagainst every candidate and return the matches, best first (ties keep the input order, so callers can pre-sort by recency or frequency). - params_
schema - The JSON Schema (
{"type":"object",…}) of a command’s parameters (MCP tool schemas, CLI help, inspector forms). - validate_
params - Check
valueagainst a command’s declared params. Typed params: unknown keys, missing required keys, types, ranges and enum values are all checked. Legacy text params: only keys the text clearly does not mention are refused.commonkeys are accepted by every command;aliases((documented, alias)) let a legacy command accept another spelling.
Type Aliases§
- Enabled
- Enabled predicate:
Err(reason)disables with a human-readable reason. - Run
- Command body. Returns the host’s own error type (see
Host::Error), so command tables written against an app’sResultalias port unchanged. - RunObserver
- Told about every top-level command that ran (not about calls refused before running, and not about nested calls). Runs on the thread that executed the command, so it must be cheap.