Documentation
¶
Overview ¶
Package plugin runs external tools: executables named devtooltui-<name> in the PATH that speak JSON over stdin and stdout, like git's subcommands. docs/plugins.md describes the protocol; ADR 0004 explains why processes and not WASM.
devtooltui-<name> spec → {"protocol": 1, "tools": [Spec…]}
devtooltui-<name> run ← {"protocol": 1, "tool": id, "inputs": {…}, "options": {…}}
→ {"result": {…}} or {"error": {…}}
Index ¶
- Constants
- func CachePath(userCacheDir func() (string, error)) (string, error)
- type Cache
- type Candidate
- type DetectSpec
- type Diff
- type ExportData
- type ExportResponse
- type Info
- type InputError
- type InputSpec
- type KV
- type OptionSpec
- type Result
- type RunRequest
- type RunResponse
- type Span
- type SpecMessage
- type Tool
- type ToolSpec
Constants ¶
const ( SpecTimeout = 5 * time.Second RunTimeout = 10 * time.Second MaxOutput = 64 << 20 // stdout )
Limits for a plugin process.
const CacheVersion = 1
CacheVersion of plugins.json; another version is an empty cache.
const Prefix = "devtooltui-"
Prefix names the plugin executables: devtooltui-<name>.
const Protocol = 1
Protocol is the version this devtooltui speaks.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
Version int `json:"version"`
Entries map[string]cacheEntry `json:"entries"`
// contains filtered or unexported fields
}
Cache keeps each plugin's spec, keyed by its path, while the executable keeps its size and modification time: the CLI then starts without running every plugin. It lives in <user cache dir>/devtooltui/plugins.json.
type DetectSpec ¶
DetectSpec is declarative detection: devtooltui matches Regex (RE2) against the sample itself and scores Score (0..1] on a match, because starting a process takes longer than a detector may.
type ExportData ¶
ExportData is the binary output in Base64 and its extension (".png").
type ExportResponse ¶
type ExportResponse struct {
Export *ExportData `json:"export,omitempty"`
Error *InputError `json:"error,omitempty"`
}
ExportResponse is the output of "export": exactly one of Export and Error.
type Info ¶
type Info struct {
Name string
Path string
Protocol int
Tools []string // IDs that were registered
Problems []string // why the plugin, or some of its tools, were skipped
}
Info describes a plugin for "devtooltui plugin list".
func Load ¶
func Load(ctx context.Context, cands []Candidate, builtin []tool.Tool, cache *Cache) ([]tool.Tool, []Info)
Load asks every candidate for its spec (in parallel; from cache when the executable has not changed) and returns the tools that can join the built-in ones: valid specs whose IDs are free. cache may be nil; Load updates it.
func Registry ¶
func Registry(ctx context.Context, pathList, cacheFile string, builtin []tool.Tool) (*registry.Registry, []Info, error)
Registry builds the registry with the built-in tools and the plugins found in pathList. cacheFile ("" for none) keeps their specs between runs. Broken plugins never stop it: their problems are in the returned Info.
type InputError ¶
type InputError struct {
Input string `json:"input"`
Line int `json:"line"`
Col int `json:"col"`
Message string `json:"message"`
}
InputError is tool.InputError in JSON.
type InputSpec ¶
type InputSpec struct {
Key string `json:"key"`
Label string `json:"label"`
Lang string `json:"lang,omitempty"`
Multiline bool `json:"multiline,omitempty"`
}
InputSpec is tool.InputSpec in JSON.
type OptionSpec ¶
type OptionSpec struct {
Key string `json:"key"`
Label string `json:"label"`
Help string `json:"help,omitempty"`
Kind string `json:"kind"`
Choices []string `json:"choices,omitempty"`
Min int `json:"min,omitempty"`
Max int `json:"max,omitempty"`
Default any `json:"default"`
}
OptionSpec is tool.Option in JSON; kind is toggle, select, number or string.
type Result ¶
type Result struct {
Text string `json:"text"`
Lang string `json:"lang,omitempty"`
Meta []KV `json:"meta,omitempty"`
Diff []Diff `json:"diff,omitempty"`
Spans []Span `json:"spans,omitempty"`
}
Result is tool.Result in JSON, the same shape as the CLI's --json.
type RunRequest ¶
type RunRequest struct {
Protocol int `json:"protocol"`
Tool string `json:"tool"`
Inputs map[string]string `json:"inputs"`
Options map[string]any `json:"options"`
}
RunRequest is the input of "run".
type RunResponse ¶
type RunResponse struct {
Result *Result `json:"result,omitempty"`
Error *InputError `json:"error,omitempty"`
}
RunResponse is the output of "run": exactly one of Result and Error.
type Span ¶
type Span struct {
Input string `json:"input"`
Start int `json:"start"`
End int `json:"end"`
Group int `json:"group"`
}
Span is a highlighted byte range of an input.
type SpecMessage ¶
SpecMessage is the output of "spec".
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool adapts one tool of a plugin to tool.Tool. It is the only Tool that does I/O: Run starts the plugin's process (see contract rule 1).
type ToolSpec ¶
type ToolSpec struct {
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Description string `json:"description"`
Keywords []string `json:"keywords,omitempty"`
Inputs []InputSpec `json:"inputs,omitempty"`
Options []OptionSpec `json:"options,omitempty"`
Output string `json:"output,omitempty"` // plain (default), highlighted, diff, matches, image
Live *bool `json:"live,omitempty"` // default true
Detect *DetectSpec `json:"detect,omitempty"` // smart detection without running the plugin
Export bool `json:"export,omitempty"` // it answers "export" (binary output)
}
ToolSpec is tool.Spec in JSON.