Documentation
¶
Overview ¶
Package userdef loads user-defined shortcuts from ~/.dws/shortcuts/*.yaml and compiles them into the same shortcut.Shortcut model as the built-ins, so a distilled high-frequency operation behaves exactly like a native `+command`. This is the runtime half of the "high-frequency auto-distillation" story (see docs/shortcut-p2-design.md); the `dws shortcut add` command writes these YAML files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
Compile turns a validated Spec into a runnable shortcut.Shortcut. Its Execute builds the MCP params from Exec.Bind: "${flag}" values are resolved from the flag (respecting its type), everything else is a literal constant. Optional flag references that the user did not set are omitted.
func Dir ¶
func Dir() string
Dir returns the directory holding user shortcut YAML files (~/.dws/shortcuts).
func FilePath ¶
FilePath returns the safe on-disk path for a user-defined shortcut. Validate already constrains both components, while the Rel check is a final defense against future validation changes reintroducing directory traversal.
func Load ¶
Load reads every ~/.dws/shortcuts/*.yaml, compiles valid specs, and registers them (skipping any that collide with an already-registered service+command, so built-ins always win). Returns the number registered and any per-file errors. It never fails hard — a bad file is reported and skipped.
Types ¶
type ExecSpec ¶
ExecSpec declares the single MCP call. Bind maps each tool parameter key to either a constant string, or a "${flag}" reference resolved from a flag value.
type FlagSpec ¶
type FlagSpec struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Default string `yaml:"default"`
Desc string `yaml:"desc"`
Required bool `yaml:"required"`
Enum []string `yaml:"enum"`
}
FlagSpec is the YAML form of shortcut.Flag.
type Spec ¶
type Spec struct {
Version int `yaml:"version"`
Service string `yaml:"service"`
Command string `yaml:"command"`
Product string `yaml:"product"`
Description string `yaml:"description"`
Intent string `yaml:"intent"`
Risk string `yaml:"risk"`
Source string `yaml:"source"` // auto | manual
Flags []FlagSpec `yaml:"flags"`
Exec ExecSpec `yaml:"execute"`
}
Spec is the on-disk YAML form of a user-defined shortcut. It mirrors shortcut.Shortcut but expresses the Execute step declaratively via Exec.Bind.