detector

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package detector provides agent detection capabilities.

Package detector provides agent detection capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePlugin

func ValidatePlugin(cfg PluginConfig) error

ValidatePlugin validates a plugin configuration.

Types

type Detector

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

Detector orchestrates agent detection across multiple strategies.

func New

func New(p platform.Platform) *Detector

New creates a new Detector with all available strategies.

func (*Detector) DetectAgent

func (d *Detector) DetectAgent(ctx context.Context, agentDef catalog.AgentDef) ([]*agent.Installation, error)

DetectAgent detects a specific agent using all applicable strategies.

func (*Detector) DetectAll

func (d *Detector) DetectAll(ctx context.Context, agents []catalog.AgentDef) ([]*agent.Installation, error)

DetectAll runs all applicable strategies and returns found installations.

func (*Detector) DetectByMethod

func (d *Detector) DetectByMethod(ctx context.Context, method agent.InstallMethod, agents []catalog.AgentDef) ([]*agent.Installation, error)

DetectByMethod runs only the strategy for the given method.

func (*Detector) GetStrategies

func (d *Detector) GetStrategies() []Strategy

GetStrategies returns all registered strategies.

func (*Detector) LoadPlugins

func (d *Detector) LoadPlugins(dir string) error

LoadPlugins loads detection plugins from the given directory.

func (*Detector) PluginRegistry

func (d *Detector) PluginRegistry() *PluginRegistry

PluginRegistry returns the detector's plugin registry.

func (*Detector) RegisterStrategy

func (d *Detector) RegisterStrategy(s Strategy)

RegisterStrategy adds a detection strategy.

type PluginAgentResult

type PluginAgentResult struct {
	// AgentID is the agent identifier (must match catalog).
	AgentID string `json:"agent_id"`

	// Version is the detected version string.
	Version string `json:"version"`

	// ExecutablePath is the path to the agent executable.
	ExecutablePath string `json:"executable_path,omitempty"`

	// InstallPath is the installation directory.
	InstallPath string `json:"install_path,omitempty"`

	// Metadata contains additional detection metadata.
	Metadata map[string]string `json:"metadata,omitempty"`
}

PluginAgentResult represents a single detected agent from a plugin.

type PluginConfig

type PluginConfig struct {
	// Name is the unique identifier for this plugin.
	Name string `json:"name" yaml:"name"`

	// Description describes what this plugin detects.
	Description string `json:"description" yaml:"description"`

	// Method is the installation method this plugin detects (e.g., "custom", "docker").
	Method string `json:"method" yaml:"method"`

	// Platforms specifies which platforms this plugin runs on (e.g., ["darwin", "linux"]).
	// If empty, the plugin runs on all platforms.
	Platforms []string `json:"platforms,omitempty" yaml:"platforms,omitempty"`

	// DetectCommand is the command to run to detect agents.
	// The command should output JSON with the detected agents.
	DetectCommand string `json:"detect_command" yaml:"detect_command"`

	// DetectScript is an inline script to run for detection (alternative to DetectCommand).
	DetectScript string `json:"detect_script,omitempty" yaml:"detect_script,omitempty"`

	// AgentFilter is a list of agent IDs this plugin handles.
	// If empty, the plugin is offered all agents.
	AgentFilter []string `json:"agent_filter,omitempty" yaml:"agent_filter,omitempty"`

	// Enabled controls whether this plugin is active.
	Enabled bool `json:"enabled" yaml:"enabled"`
}

PluginConfig defines the configuration for a detection plugin.

type PluginDetectionResult

type PluginDetectionResult struct {
	// Agents is the list of detected agent installations.
	Agents []PluginAgentResult `json:"agents"`
}

PluginDetectionResult is the expected output format from a detection plugin.

type PluginRegistry

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

PluginRegistry manages detection plugins.

func NewPluginRegistry

func NewPluginRegistry(p platform.Platform) *PluginRegistry

NewPluginRegistry creates a new plugin registry.

func (*PluginRegistry) Get

func (r *PluginRegistry) Get(name string) (PluginConfig, bool)

Get returns a plugin by name.

func (*PluginRegistry) GetStrategies

func (r *PluginRegistry) GetStrategies() []Strategy

GetStrategies returns Strategy instances for all enabled plugins.

func (*PluginRegistry) List

func (r *PluginRegistry) List() []PluginConfig

List returns all registered plugins.

func (*PluginRegistry) LoadPluginsFromDir

func (r *PluginRegistry) LoadPluginsFromDir(dir string) error

LoadPluginsFromDir loads plugin configurations from a directory. Plugin files should be JSON files with the .plugin.json extension.

func (*PluginRegistry) Register

func (r *PluginRegistry) Register(cfg PluginConfig) error

Register adds a plugin to the registry.

func (*PluginRegistry) Unregister

func (r *PluginRegistry) Unregister(name string)

Unregister removes a plugin from the registry.

type PluginStrategy

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

PluginStrategy implements the Strategy interface for script-based plugins.

func NewPluginStrategy

func NewPluginStrategy(cfg PluginConfig, p platform.Platform) *PluginStrategy

NewPluginStrategy creates a new plugin-based detection strategy.

func (*PluginStrategy) Detect

func (s *PluginStrategy) Detect(ctx context.Context, agents []catalog.AgentDef) ([]*agent.Installation, error)

Detect runs the plugin and returns found installations.

func (*PluginStrategy) IsApplicable

func (s *PluginStrategy) IsApplicable(p platform.Platform) bool

IsApplicable returns true if this strategy can run on the given platform.

func (*PluginStrategy) Method

func (s *PluginStrategy) Method() agent.InstallMethod

Method returns the install method this strategy detects.

func (*PluginStrategy) Name

func (s *PluginStrategy) Name() string

Name returns the strategy name.

type Result

type Result struct {
	Installations []*agent.Installation
	Errors        []error
	Duration      time.Duration
}

Result represents the result of a detection run.

func (*Result) NewInstallations

func (r *Result) NewInstallations(existing []*agent.Installation) []*agent.Installation

NewInstallations returns installations that are not in the existing list.

func (*Result) RemovedInstallations

func (r *Result) RemovedInstallations(existing []*agent.Installation) []*agent.Installation

RemovedInstallations returns installations that exist but were not detected.

type Strategy

type Strategy interface {
	// Name returns the strategy name (e.g., "npm", "brew", "pip").
	Name() string

	// Method returns the install method this strategy detects.
	Method() agent.InstallMethod

	// IsApplicable returns true if this strategy can run on the given platform.
	IsApplicable(p platform.Platform) bool

	// Detect scans for installed agents and returns found installations.
	Detect(ctx context.Context, agents []catalog.AgentDef) ([]*agent.Installation, error)
}

Strategy defines how to detect agents installed via a specific method.

func NewBinaryStrategy

func NewBinaryStrategy(p platform.Platform) Strategy

NewBinaryStrategy creates a new binary detection strategy.

func NewBrewStrategy

func NewBrewStrategy(p platform.Platform) Strategy

NewBrewStrategy creates a new Homebrew detection strategy.

func NewNPMStrategy

func NewNPMStrategy(p platform.Platform) Strategy

NewNPMStrategy creates a new NPM detection strategy.

func NewPipStrategy

func NewPipStrategy(p platform.Platform) Strategy

NewPipStrategy creates a new pip/pipx/uv detection strategy.

Directories

Path Synopsis
Package strategies provides detection strategies for different installation methods.
Package strategies provides detection strategies for different installation methods.

Jump to

Keyboard shortcuts

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