plugins

package
v0.0.0-...-8198c06 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AugmentAuditMetadata

func AugmentAuditMetadata(ctx Context, candidate *Candidate, metadata map[string]interface{}) error

AugmentAuditMetadata adds plugin metadata to audit entries

func CheckApprovalRequired

func CheckApprovalRequired(candidate *Candidate) bool

CheckApprovalRequired checks if any plugin requires approval for a candidate

func ExecutePostExecutionHooks

func ExecutePostExecutionHooks(ctx Context, candidate *Candidate, sandboxID string, exitCode int, stdout, stderr []byte) error

ExecutePostExecutionHooks runs post-execution hooks

func ExecutePreExecutionHooks

func ExecutePreExecutionHooks(ctx Context, candidate *Candidate) error

ExecutePreExecutionHooks runs pre-execution hooks

func LoadBuiltins

func LoadBuiltins() error

LoadBuiltins loads built-in plugins into the default registry

func Register

func Register(plugin Plugin, metadata *PluginMetadata) error

Register registers a plugin with the default registry

Types

type AuditHookData

type AuditHookData struct {
	Candidate *Candidate
	Metadata  map[string]interface{}
}

AuditHookData contains data for audit metadata hooks

type Candidate

type Candidate struct {
	Command         string
	Explanation     string
	Breakdown       []Step
	Confidence      int
	RiskLevel       Risk
	AffectedPaths   []string
	NetworkTargets  []string
	Destructive     bool
	RequiresConfirm bool
	DocLinks        []string

	// Plugin-specific metadata
	PluginName     string
	PluginMetadata map[string]interface{}
	UndoStrategy   *UndoStrategy
}

Candidate represents a command candidate with plugin metadata

func TranslateWithPlugins

func TranslateWithPlugins(ctx Context, prompt string, coreCandidates []*Candidate) ([]*Candidate, error)

TranslateWithPlugins translates a prompt using both core templates and plugins

type CheckResult

type CheckResult struct {
	Allowed          bool
	Reason           string
	RequiresApproval bool
	ApprovalMessage  string
	AdditionalChecks []string
	Metadata         map[string]interface{}
}

CheckResult contains the result of a pre-run safety check

func PreRunCheckWithPlugins

func PreRunCheckWithPlugins(ctx Context, candidate *Candidate) (*CheckResult, error)

PreRunCheckWithPlugins performs pre-run checks using plugins

type Context

type Context struct {
	WorkingDir string
	User       string
	Timestamp  time.Time
	Metadata   map[string]interface{}
}

Context provides execution context to plugins

type ExecutionHookData

type ExecutionHookData struct {
	Candidate *Candidate
	SandboxID string
	ExitCode  int
	Stdout    []byte
	Stderr    []byte
}

ExecutionHookData contains data for execution hooks

type HookFunc

type HookFunc func(ctx Context, data interface{}) error

HookFunc is a function that can be registered as a hook

type HookType

type HookType string

Hook types for plugin lifecycle

const (
	HookPreTranslate  HookType = "pre_translate"
	HookPostTranslate HookType = "post_translate"
	HookPreExecution  HookType = "pre_execution"
	HookPostExecution HookType = "post_execution"
	HookAuditMetadata HookType = "audit_metadata"
)

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles plugin loading and initialization

func DefaultLoader

func DefaultLoader() *Loader

DefaultLoader returns a loader for the default registry

func NewLoader

func NewLoader(registry *Registry) *Loader

NewLoader creates a new plugin loader

func (*Loader) LoadBuiltins

func (l *Loader) LoadBuiltins() error

LoadBuiltins loads all built-in plugins

func (*Loader) LoadPlugin

func (l *Loader) LoadPlugin(plugin Plugin, metadata *PluginMetadata) error

LoadPlugin loads a single plugin

func (*Loader) ReloadPlugin

func (l *Loader) ReloadPlugin(name string, plugin Plugin, metadata *PluginMetadata) error

ReloadPlugin reloads a plugin

func (*Loader) UnloadPlugin

func (l *Loader) UnloadPlugin(name string) error

UnloadPlugin unloads a plugin by name

type Plugin

type Plugin interface {
	// Name returns the unique name of the plugin
	Name() string

	// Translate attempts to translate a natural language prompt into command candidates
	// Returns empty slice if the plugin doesn't handle this prompt
	Translate(ctx Context, prompt string) ([]*Candidate, error)

	// PreRunCheck performs safety checks before command execution
	// Can add additional approval requirements or deny execution
	PreRunCheck(ctx Context, candidate *Candidate) (*CheckResult, error)

	// RequiresApproval returns true if this candidate requires approval
	RequiresApproval(candidate *Candidate) bool

	// Scopes returns the required scopes/permissions for this plugin
	Scopes() []string
}

Plugin defines the interface that all QuickCMD plugins must implement

func Get

func Get(name string) (Plugin, error)

Get retrieves a plugin from the default registry

func List

func List() []Plugin

List returns all plugins from the default registry

func ListEnabled

func ListEnabled() []Plugin

ListEnabled returns all enabled plugins from the default registry

type PluginError

type PluginError struct {
	PluginName string
	Operation  string
	Err        error
}

PluginError represents a plugin-specific error

func (*PluginError) Error

func (e *PluginError) Error() string

func (*PluginError) Unwrap

func (e *PluginError) Unwrap() error

type PluginMetadata

type PluginMetadata struct {
	Name        string
	Version     string
	Description string
	Author      string
	Scopes      []string
	Enabled     bool
}

PluginMetadata contains plugin registration metadata

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages plugin registration and lifecycle

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns the global plugin registry

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry

func (*Registry) Disable

func (r *Registry) Disable(name string) error

Disable disables a plugin

func (*Registry) Enable

func (r *Registry) Enable(name string) error

Enable enables a plugin

func (*Registry) ExecuteHooks

func (r *Registry) ExecuteHooks(hookType HookType, ctx Context, data interface{}) error

ExecuteHooks executes all hooks of a given type

func (*Registry) Get

func (r *Registry) Get(name string) (Plugin, error)

Get retrieves a plugin by name

func (*Registry) GetMetadata

func (r *Registry) GetMetadata(name string) (*PluginMetadata, error)

GetMetadata retrieves plugin metadata

func (*Registry) List

func (r *Registry) List() []Plugin

List returns all registered plugins

func (*Registry) ListEnabled

func (r *Registry) ListEnabled() []Plugin

ListEnabled returns all enabled plugins

func (*Registry) Register

func (r *Registry) Register(plugin Plugin, metadata *PluginMetadata) error

Register registers a plugin with the registry

func (*Registry) RegisterHook

func (r *Registry) RegisterHook(hookType HookType, fn HookFunc)

RegisterHook registers a hook function

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a plugin from the registry

type Risk

type Risk string

Risk represents the risk level of a command

const (
	RiskSafe   Risk = "safe"
	RiskMedium Risk = "medium"
	RiskHigh   Risk = "high"
)

type Step

type Step struct {
	Description string
	Command     string
}

Step represents a single step in command breakdown

type TranslateHookData

type TranslateHookData struct {
	Prompt     string
	Candidates []*Candidate
}

TranslateHookData contains data for translation hooks

type UndoStrategy

type UndoStrategy struct {
	Type        string // "git", "filesystem", "none"
	Description string
	Command     string
	Metadata    map[string]interface{}
}

UndoStrategy describes how to undo a command

Jump to

Keyboard shortcuts

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