Help us shape the future of Go! Take the 2026 Go Developer Survey

userdef

package
v1.0.66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

func Compile(s Spec) shortcut.Shortcut

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

func FilePath(service, command string) (string, error)

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

func Load() (registered int, errs []error)

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.

func Validate

func Validate(s Spec) error

Validate checks the minimum required fields of a spec.

Types

type ExecSpec

type ExecSpec struct {
	Tool string            `yaml:"tool"`
	Bind map[string]string `yaml:"bind"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL