spec

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spec loads commands.json, the single definition of every Droidline command, and normalises raw requests against it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Raw

func Raw() []byte

Raw returns the embedded commands.json bytes.

Types

type Alias

type Alias struct {
	Name string `json:"name"`
	By   string `json:"by"`
}

type ArgError

type ArgError struct {
	Cmd     string
	Reason  string
	Unknown bool
	Similar []string
}

ArgError is reported to clients as BAD_ARGS (or UNKNOWN_CMD when Unknown is set).

func (*ArgError) Error

func (e *ArgError) Error() string

type Command

type Command struct {
	Name        string   `json:"name"`
	Group       string   `json:"group"`
	Phase       int      `json:"phase"`
	Scope       string   `json:"scope"`
	Requires    []string `json:"requires,omitempty"`
	Condition   bool     `json:"condition,omitempty"`
	Macro       bool     `json:"macro,omitempty"`
	CutsNetwork *Cut     `json:"cuts_network,omitempty"`
	Summary     I18n     `json:"summary"`
	Notes       I18n     `json:"notes,omitempty"`
	Params      []Param  `json:"params"`
	Returns     Returns  `json:"returns"`
	Errors      []string `json:"errors,omitempty"`
	Aliases     []Alias  `json:"aliases,omitempty"`
	SDKSave     string   `json:"sdk_save,omitempty"`
	MCP         *bool    `json:"mcp,omitempty"`
	MinSDK      int      `json:"min_sdk,omitempty"`
	Example     string   `json:"example,omitempty"`
	Examples    []string `json:"examples,omitempty"`
}

func (*Command) InMCP

func (c *Command) InMCP() bool

InMCP reports whether the command is exposed as an MCP tool.

func (*Command) Param

func (c *Command) Param(name string) *Param

Param returns the parameter called name, or nil.

type Cut

type Cut struct {
	Param string `json:"param"`
	When  bool   `json:"when"`
}

type ErrorDef

type ErrorDef struct {
	Code      string `json:"code"`
	HTTP      int    `json:"http"`
	Retryable bool   `json:"retryable"`
	Msg       I18n   `json:"msg"`
	Doc       I18n   `json:"doc"`
}

type Field

type Field struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type I18n

type I18n map[string]string

func (I18n) In

func (t I18n) In(lang string) string

In returns the text for lang, falling back to English.

type Param

type Param struct {
	Ref        string   `json:"ref,omitempty"`
	Name       string   `json:"name"`
	Type       string   `json:"type"`
	Required   bool     `json:"required,omitempty"`
	Default    any      `json:"default,omitempty"`
	Enum       []string `json:"enum,omitempty"`
	Unit       string   `json:"unit,omitempty"`
	ClientOnly bool     `json:"client_only,omitempty"`
	Doc        I18n     `json:"doc,omitempty"`
}

type Returns

type Returns struct {
	Kind   string  `json:"kind"`
	Type   string  `json:"type,omitempty"`
	Fields []Field `json:"fields,omitempty"`
}

type Selector

type Selector struct {
	By        string `json:"by"`
	Field     string `json:"field"`
	Match     string `json:"match"`
	Doc       I18n   `json:"doc"`
	Shorthand string `json:"shorthand,omitempty"`
}

type Spec

type Spec struct {
	Proto        int                `json:"proto"`
	Selectors    []Selector         `json:"selectors"`
	CommonParams map[string]Param   `json:"common_params"`
	Errors       []ErrorDef         `json:"errors"`
	Commands     []*Command         `json:"commands"`
	BatchOnly    []*Command         `json:"batch_only"`
	Types        map[string]TypeDef `json:"types"`
	// contains filtered or unexported fields
}

func Load

func Load() (*Spec, error)

Load parses the embedded commands.json and resolves parameter references.

func MustLoad

func MustLoad() *Spec

MustLoad is Load for package init paths where a broken embed is a build bug.

func Parse

func Parse(data []byte) (*Spec, error)

func (*Spec) Command

func (s *Spec) Command(name string) (c *Command, by string)

Command looks up a command by name or alias. by is non-empty for aliases.

func (*Spec) CutsNetwork

func (s *Spec) CutsNetwork(c *Command, params map[string]any) bool

CutsNetwork reports whether this normalised call will drop the phone's link.

func (*Spec) Error

func (s *Spec) Error(code string) *ErrorDef

func (*Spec) IsSelector

func (s *Spec) IsSelector(by string) bool

func (*Spec) Names

func (s *Spec) Names() []string

Names returns all command names (not aliases) in definition order.

func (*Spec) Normalize

func (s *Spec) Normalize(name string, raw map[string]any) (*Command, map[string]any, error)

Normalize checks raw request fields against the command definition and returns the parameters the agent (or server handler) receives: aliases resolved, positional args mapped, values coerced, defaults filled, client-only params dropped.

func (*Spec) ParseArg

func (s *Spec) ParseArg(p *Param, raw string) (any, error)

ParseArg converts one command-line string into the JSON value a param expects.

func (*Spec) RenderError

func (s *Spec) RenderError(code, lang string, fields map[string]any) string

RenderError fills the message template of code in lang. Fields the template needs but the caller did not supply render as "?".

func (*Spec) SelectorNames

func (s *Spec) SelectorNames() []string

func (*Spec) Similar

func (s *Spec) Similar(name string, n int) []string

Similar returns up to n command or alias names close to name, for "did you mean".

func (*Spec) SortedErrorCodes

func (s *Spec) SortedErrorCodes() []string

SortedErrorCodes is used by generators and docs that want a stable order.

type TypeDef

type TypeDef struct {
	Doc    I18n     `json:"doc,omitempty"`
	Fields []string `json:"fields"`
}

Jump to

Keyboard shortcuts

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