subcommand

package
v0.0.0-...-421e204 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package subcommand provides the infrastructure for defining and executing smart home commands. Each command is composed of one or more actions.

Index

Constants

View Source
const (
	// ResolverModeLegacy uses the current built-in resolution flow.
	ResolverModeLegacy = "legacy"
	// ResolverModeDSPy uses an external DSPy-based resolver flow.
	ResolverModeDSPy = "dspy"
)
View Source
const ChangePlaylistCmd = "change playlist"

ChangePlaylistCmd is the command name for changing the music playlist.

View Source
const ConfigDirName = "./config"

ConfigDirName is the default path to the configuration directory.

View Source
const ConfigFileName = "./config/config.json"

ConfigFileName is the default path to the configuration file. For backward compatibility with the -config flag.

View Source
const DeviceListCmd = "device list"

DeviceListCmd is a short name for the SwitchBot device list command.

View Source
const DispOutputsCmd = "disp outputs"

DispOutputsCmd is a short name for the display outputs command.

View Source
const DispPlaylistsCmd = "disp playlists"

DispPlaylistsCmd is a short name for the display playlists command.

View Source
const DispTempCmd = "disp temp"

DispTempCmd is a short name for the display temperature command.

View Source
const DisplayOutputsCmd = "display outputs"

DisplayOutputsCmd is the command name for displaying audio outputs.

View Source
const DisplayPlaylistsCmd = "display playlist"

DisplayPlaylistsCmd is the command name for displaying playlists.

View Source
const DisplayTemperatureCmd = "display temperature"

DisplayTemperatureCmd is the command name for displaying temperature and humidity.

View Source
const HealthCmd = "health"

HealthCmd is the command name for checking the health of the system.

View Source
const HelpCmd = "help"

HelpCmd is the command name for displaying help.

View Source
const PlayRandomArtistCmd = "play random artist"

PlayRandomArtistCmd is the command name for playing random artist music.

View Source
const PlayRandomGenreCmd = "play random genre"

PlayRandomGenreCmd is the command name for playing random genre music.

View Source
const PlayRandomPlaylistCmd = "play random playlist"

PlayRandomPlaylistCmd is the command name for playing random playlist music.

View Source
const SceneListCmd = "scene list"

SceneListCmd is a short name for the SwitchBot scene list command.

View Source
const SearchAndPlayMusicCmd = "search and play"

SearchAndPlayMusicCmd is the command name for searching and playing music.

View Source
const SearchMusicCmd = "search music"

SearchMusicCmd is the command name for searching music.

View Source
const SearchPlayCmd = "search play"

SearchPlayCmd is a short name for the search and play music command.

View Source
const StartMusicCmd = "start music"

StartMusicCmd is the command name for starting music playback.

View Source
const StopMusicCmd = "stop music"

StopMusicCmd is the command name for stopping music playback.

View Source
const SwitchBotDeviceListCmd = "switchbot device list"

SwitchBotDeviceListCmd is the command name for listing SwitchBot devices.

View Source
const SwitchBotSceneListCmd = "switchbot scene list"

SwitchBotSceneListCmd is the command name for listing SwitchBot scenes.

View Source
const TokenizeIpaCmd = "tokenize ipa"

TokenizeIpaCmd is the command name for tokenizing with IPA dictionary.

View Source
const (
	// #nosec G101
	TokenizeNeologdCmd = "tokenize neologd"
)

TokenizeNeologdCmd is the command name for tokenizing with Neologd dictionary.

View Source
const (
	// #nosec G101
	TokenizeUniCmd = "tokenize uni"
)

TokenizeUniCmd is the command name for tokenizing with Uni dictionary.

View Source
const UpdateLibraryCmd = "update library"

UpdateLibraryCmd is the command name for updating the music library.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionSpec

type ActionSpec struct {
	Type   string            `json:"type"`
	Params map[string]string `json:"params"`
}

ActionSpec defines a single action step in a macro.

type Arg

type Arg struct {
	Name        string
	Description string
	Required    bool
	Enum        []string
	Prefix      string
}

Arg represents an argument for a subcommand.

func (Arg) Match

func (a Arg) Match(input string) (string, bool)

Match checks if the given input matches the argument's prefix and enum values.

type Commands

type Commands struct {
	Definitions []Definition
}

Commands represents a collection of subcommand definitions.

func NewCommands

func NewCommands(macros ...MacroConfig) Commands

NewCommands creates a new collection of all available subcommand definitions. Optionally pass MacroConfig values to register user-defined macros.

func (Commands) Find

func (c Commands) Find(ctx context.Context, config Config, text string) (Definition, string, string, error)

Find searches for a subcommand definition that matches the given text.

func (Commands) Help

func (c Commands) Help() string

Help returns a help string for all subcommands in the collection.

type Config

type Config struct {
	Owntone   owntone.Config   `json:"Owntone"`
	Switchbot switchbot.Config `json:"Switchbot"`
	Yamaha    yamaha.Config    `json:"Yamaha"`
	LLM       llm.Config       `json:"LLM"`
	Resolver  ResolverConfig   `json:"Resolver"`
	Influxdb  influxdb.Config  `json:"Influxdb"`
	Commands  Commands
}

Config represents the application configuration.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig loads the configuration from the default directory.

func LoadConfigFromDir

func LoadConfigFromDir(dir string) (Config, error)

LoadConfigFromDir loads configuration from a directory. It reads config.json (required) and macros.json (optional) from the directory. Unknown files in the directory are logged as warnings.

func LoadConfigWithPath

func LoadConfigWithPath(configFile string) (Config, error)

LoadConfigWithPath loads the configuration from the specified file path. For backward compatibility with the -config flag.

type Definition

type Definition struct {
	Name        string
	Description string

	Factory func(Definition, Config) Subcommand
	Args    []Arg
	// contains filtered or unexported fields
}

Definition defines the metadata and factory for a subcommand.

func NewChangePlaylistCmdDefinition

func NewChangePlaylistCmdDefinition() Definition

NewChangePlaylistCmdDefinition creates the definition for the change playlist command.

func NewDisplayOutputsCmdDefinition

func NewDisplayOutputsCmdDefinition() Definition

NewDisplayOutputsCmdDefinition creates the definition for the display outputs command.

func NewDisplayPlaylistCmdDefinition

func NewDisplayPlaylistCmdDefinition() Definition

NewDisplayPlaylistCmdDefinition creates the definition for the display playlists command.

func NewDisplayTemperatureDefinition

func NewDisplayTemperatureDefinition() Definition

NewDisplayTemperatureDefinition creates the definition for the display temperature command.

func NewHealthDefinition

func NewHealthDefinition() Definition

NewHealthDefinition creates the definition for the health check command.

func NewHelpDefinition

func NewHelpDefinition() Definition

NewHelpDefinition creates the definition for the help command.

func NewPlayRandomArtistCmdDefinition

func NewPlayRandomArtistCmdDefinition() Definition

NewPlayRandomArtistCmdDefinition creates the definition for the random artist command.

func NewPlayRandomGenreCmdDefinition

func NewPlayRandomGenreCmdDefinition() Definition

NewPlayRandomGenreCmdDefinition creates the definition for the random genre command.

func NewPlayRandomPlaylistCmdDefinition

func NewPlayRandomPlaylistCmdDefinition() Definition

NewPlayRandomPlaylistCmdDefinition creates the definition for the random playlist command.

func NewSearchAndPlayMusicCmdDefinition

func NewSearchAndPlayMusicCmdDefinition() Definition

NewSearchAndPlayMusicCmdDefinition creates the definition for the search and play music command.

func NewSearchMusicCmdDefinition

func NewSearchMusicCmdDefinition() Definition

NewSearchMusicCmdDefinition creates the definition for the search music command.

func NewStartMusicCmdDefinition

func NewStartMusicCmdDefinition() Definition

NewStartMusicCmdDefinition creates the definition for the start music command.

func NewStopMusicDefinition

func NewStopMusicDefinition() Definition

NewStopMusicDefinition creates the definition for the stop music command.

func NewSwitchBotDeviceListDefinition

func NewSwitchBotDeviceListDefinition() Definition

NewSwitchBotDeviceListDefinition creates the definition for the SwitchBot device list command.

func NewSwitchBotSceneListDefinition

func NewSwitchBotSceneListDefinition() Definition

NewSwitchBotSceneListDefinition creates the definition for the SwitchBot scene list command.

func NewTokenizeIpaDefinition

func NewTokenizeIpaDefinition() Definition

NewTokenizeIpaDefinition creates the definition for the tokenize ipa command.

func NewTokenizeNeologdDefinition

func NewTokenizeNeologdDefinition() Definition

NewTokenizeNeologdDefinition creates the definition for the tokenize neologd command.

func NewTokenizeUniDefinition

func NewTokenizeUniDefinition() Definition

NewTokenizeUniDefinition creates the definition for the tokenize uni command.

func NewUpdateLibraryCmdDefinition

func NewUpdateLibraryCmdDefinition() Definition

NewUpdateLibraryCmdDefinition creates the definition for the update library command.

func (Definition) Distance

func (d Definition) Distance(input string) (int, string)

Distance calculates the Levenshtein distance between the input and the command names.

func (Definition) Help

func (d Definition) Help() string

Help returns a help string for the subcommand.

func (Definition) Init

func (d Definition) Init(config Config) Subcommand

Init initializes a subcommand from its definition and configuration.

func (Definition) Match

func (d Definition) Match(message string) (bool, string)

Match checks if the given message matches the subcommand name or its shortnames.

type MacroConfig

type MacroConfig struct {
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Shortnames  []string     `json:"shortnames"`
	IgnoreError bool         `json:"ignore_error"`
	Actions     []ActionSpec `json:"actions"`
}

MacroConfig defines a user-configurable macro (sequence of actions).

type ResolverConfig

type ResolverConfig struct {
	Mode               string `json:"mode"`
	FeedbackEnabled    bool   `json:"feedback_enabled"`
	PromptVersion      string `json:"prompt_version"`
	DSPyEndpoint       string `json:"dspy_endpoint"`
	DSPyTimeoutSeconds int    `json:"dspy_timeout_seconds"`
}

ResolverConfig controls resolver behavior and observability options.

func (ResolverConfig) Validate

func (c ResolverConfig) Validate() error

Validate validates ResolverConfig.

type Subcommand

type Subcommand struct {
	Definition
	// contains filtered or unexported fields
}

Subcommand represents a executable command consisting of one or more actions.

func NewChangePlaylistSubcommand

func NewChangePlaylistSubcommand(definition Definition, config Config) Subcommand

NewChangePlaylistSubcommand creates a new Subcommand for the change playlist command.

func NewDisplayOutputsSubcommand

func NewDisplayOutputsSubcommand(definition Definition, config Config) Subcommand

NewDisplayOutputsSubcommand creates a new Subcommand for the display outputs command.

func NewDisplayPlaylistsSubcommand

func NewDisplayPlaylistsSubcommand(definition Definition, config Config) Subcommand

NewDisplayPlaylistsSubcommand creates a new Subcommand for the display playlists command.

func NewDisplayTemperatureSubcommand

func NewDisplayTemperatureSubcommand(definition Definition, config Config) Subcommand

NewDisplayTemperatureSubcommand creates a new Subcommand for the display temperature command.

func NewHealthSubcommand

func NewHealthSubcommand(definition Definition, config Config) Subcommand

NewHealthSubcommand creates a new Subcommand for the health check command.

func NewHelpSubcommand

func NewHelpSubcommand(definition Definition, config Config) Subcommand

NewHelpSubcommand creates a new Subcommand for the help command.

func NewPlayRandomArtistSubcommand

func NewPlayRandomArtistSubcommand(definition Definition, config Config) Subcommand

NewPlayRandomArtistSubcommand creates a new Subcommand for random artist playback.

func NewPlayRandomGenreSubcommand

func NewPlayRandomGenreSubcommand(definition Definition, config Config) Subcommand

NewPlayRandomGenreSubcommand creates a new Subcommand for random genre playback.

func NewPlayRandomPlaylistSubcommand

func NewPlayRandomPlaylistSubcommand(definition Definition, config Config) Subcommand

NewPlayRandomPlaylistSubcommand creates a new Subcommand for random playlist playback.

func NewSearchAndPlayMusicSubcommand

func NewSearchAndPlayMusicSubcommand(definition Definition, config Config) Subcommand

NewSearchAndPlayMusicSubcommand creates a new Subcommand for the search and play music command.

func NewSearchMusicSubcommand

func NewSearchMusicSubcommand(definition Definition, config Config) Subcommand

NewSearchMusicSubcommand creates a new Subcommand for the search music command.

func NewStartMusicSubcommand

func NewStartMusicSubcommand(definition Definition, config Config) Subcommand

NewStartMusicSubcommand creates a new Subcommand for the start music command.

func NewStopMusicSubcommand

func NewStopMusicSubcommand(definition Definition, config Config) Subcommand

NewStopMusicSubcommand creates a new Subcommand for the stop music command.

func NewSwitchBotDeviceListSubcommand

func NewSwitchBotDeviceListSubcommand(definition Definition, config Config) Subcommand

NewSwitchBotDeviceListSubcommand creates a new Subcommand for the SwitchBot device list command.

func NewSwitchBotSceneListSubcommand

func NewSwitchBotSceneListSubcommand(definition Definition, config Config) Subcommand

NewSwitchBotSceneListSubcommand creates a new Subcommand for the SwitchBot scene list command.

func NewTokenizeIpaCommand

func NewTokenizeIpaCommand(definition Definition, _ Config) Subcommand

NewTokenizeIpaCommand creates a new Subcommand for the tokenize ipa command.

func NewTokenizeNeologdCommand

func NewTokenizeNeologdCommand(definition Definition, _ Config) Subcommand

NewTokenizeNeologdCommand creates a new Subcommand for the tokenize neologd command.

func NewTokenizeUniCommand

func NewTokenizeUniCommand(definition Definition, _ Config) Subcommand

NewTokenizeUniCommand creates a new Subcommand for the tokenize uni command.

func NewUpdateLibrarySubcommand

func NewUpdateLibrarySubcommand(definition Definition, config Config) Subcommand

NewUpdateLibrarySubcommand creates a new Subcommand for the update library command.

func (Subcommand) Exec

func (s Subcommand) Exec(ctx context.Context, args string) (string, error)

Exec executes the subcommand by running all its actions in sequence.

Directories

Path Synopsis
Package action defines the interface for smart home actions.
Package action defines the interface for smart home actions.
healthcheck
Package healthcheck provides actions for checking the health of various services.
Package healthcheck provides actions for checking the health of various services.
internal
Package internal provides internal helper functions for action implementations.
Package internal provides internal helper functions for action implementations.
kagome
Package kagome provides an action to tokenize Japanese text using the Kagome tokenizer.
Package kagome provides an action to tokenize Japanese text using the Kagome tokenizer.
llm
Package llm provides a client for resolving natural language to subcommands using LLMs.
Package llm provides a client for resolving natural language to subcommands using LLMs.
owntone
Package owntone provides actions and a client for controlling Owntone (formerly forked-daapd) servers.
Package owntone provides actions and a client for controlling Owntone (formerly forked-daapd) servers.
switchbot
Package switchbot provides actions and a client for controlling SwitchBot devices.
Package switchbot provides actions and a client for controlling SwitchBot devices.
yamaha
Package yamaha provides actions and a client for controlling Yamaha MusicCast devices.
Package yamaha provides actions and a client for controlling Yamaha MusicCast devices.

Jump to

Keyboard shortcuts

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