plugin

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 19 Imported by: 0 modules, 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 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

View Source
const (
	SpecTimeout = 5 * time.Second
	RunTimeout  = 10 * time.Second
	MaxOutput   = 64 << 20 // stdout

)

Limits for a plugin process.

View Source
const CacheVersion = 1

CacheVersion of plugins.json; another version is an empty cache.

View Source
const Prefix = "devtooltui-"

Prefix names the plugin executables: devtooltui-<name>.

View Source
const Protocol = 1

Protocol is the version this devtooltui speaks.

Variables

This section is empty.

Functions

func CachePath

func CachePath(userCacheDir func() (string, error)) (string, error)

CachePath returns <user cache dir>/devtooltui/plugins.json.

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.

func LoadCache

func LoadCache(path string) *Cache

LoadCache reads the cache; a missing, broken or old file is empty.

func (*Cache) Save

func (c *Cache) Save(path string) error

Save writes the cache atomically with mode 0600.

type Candidate

type Candidate struct {
	Name string // without the prefix (and .exe)
	Path string
}

Candidate is an executable found in the PATH.

func Discover

func Discover(pathList string) []Candidate

Discover lists devtooltui-* executables in the directories of pathList (the PATH). Like exec.LookPath, the first directory wins for a name. On Windows only .exe files count; elsewhere, files with an execute bit.

type DetectSpec

type DetectSpec struct {
	Regex string  `json:"regex"`
	Score float64 `json:"score"`
}

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 Diff

type Diff struct {
	Op   string `json:"op"`
	Text string `json:"text"`
}

Diff is a diff fragment; op is equal, insert or delete.

type ExportData

type ExportData struct {
	Data string `json:"data"`
	Ext  string `json:"ext"`
}

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 KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

KV is a meta entry.

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

type SpecMessage struct {
	Protocol int        `json:"protocol"`
	Tools    []ToolSpec `json:"tools"`
}

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).

func (*Tool) Plugin

func (t *Tool) Plugin() (name, path string)

Plugin returns the plugin name and executable path.

func (*Tool) Run

func (t *Tool) Run(ctx context.Context, req tool.Request) (tool.Result, error)

func (*Tool) Spec

func (t *Tool) Spec() tool.Spec

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.

Jump to

Keyboard shortcuts

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