aitool

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeArgs

func SanitizeArgs(args []string) []string

SanitizeArgs redacts argument values that match secret patterns. For example, "--token=sk-ant-..." becomes "--token=<REDACTED>".

Types

type AITool

type AITool struct {
	ID         string      `json:"id"`
	SourceID   string      `json:"source_id"`
	Name       string      `json:"name"`
	Type       AIToolType  `json:"type"`
	Scope      AIToolScope `json:"scope"`
	App        string      `json:"app"`
	AppDisplay string      `json:"-"`
	ConfigPath string      `json:"config_path"`

	MCPServer *MCPServerConfig `json:"mcp_server,omitempty"`
	Agent     *AgentConfig     `json:"agent,omitempty"`
	Enabled   *bool            `json:"enabled,omitempty"`
	Metadata  map[string]any   `json:"metadata,omitempty"`
}

AITool represents a discovered AI tool, MCP server, or coding agent configured on the local system or within a project.

func (*AITool) GetMeta

func (t *AITool) GetMeta(key string) any

GetMeta retrieves a metadata value by key. Returns nil if not found.

func (*AITool) GetMetaString

func (t *AITool) GetMetaString(key string) string

GetMetaString retrieves a metadata value as a string. Returns "" if not found or not a string.

func (*AITool) SetMeta

func (t *AITool) SetMeta(key string, value any)

SetMeta sets a metadata key-value pair, initializing the map if needed.

type AIToolDiscovererFactory

type AIToolDiscovererFactory func(config DiscoveryConfig) (AIToolReader, error)

AIToolDiscovererFactory creates a reader given a config.

type AIToolHandlerFn

type AIToolHandlerFn func(*AITool) error

AIToolHandlerFn is called for each discovered AI tool. Return an error to stop enumeration.

type AIToolInventory

type AIToolInventory struct {
	Tools []*AITool `json:"tools"`
}

AIToolInventory is a convenience wrapper for collecting all discovered tools.

func NewAIToolInventory

func NewAIToolInventory() *AIToolInventory

NewAIToolInventory creates a new empty inventory.

func (*AIToolInventory) Add

func (inv *AIToolInventory) Add(tool *AITool)

Add appends a tool to the inventory.

func (*AIToolInventory) FilterByApp

func (inv *AIToolInventory) FilterByApp(app string) []*AITool

FilterByApp returns tools matching the given app.

func (*AIToolInventory) FilterByScope

func (inv *AIToolInventory) FilterByScope(scope AIToolScope) []*AITool

FilterByScope returns tools matching the given scope.

func (*AIToolInventory) FilterBySourceID

func (inv *AIToolInventory) FilterBySourceID(sourceID string) []*AITool

FilterBySourceID returns tools matching the given source ID.

func (*AIToolInventory) FilterByType

func (inv *AIToolInventory) FilterByType(t AIToolType) []*AITool

FilterByType returns tools matching the given type.

func (*AIToolInventory) GroupByApp

func (inv *AIToolInventory) GroupByApp() map[string][]*AITool

GroupByApp returns tools grouped by app name.

func (*AIToolInventory) GroupBySourceID

func (inv *AIToolInventory) GroupBySourceID() map[string][]*AITool

GroupBySourceID returns tools grouped by source config.

type AIToolReader

type AIToolReader interface {
	// Name returns a human-readable name for this discoverer
	Name() string

	// App returns the AI application identifier (e.g. "claude_code", "cursor")
	App() string

	// EnumTools discovers AI tools and calls handler for each one found.
	// Enumeration stops on first handler error.
	EnumTools(ctx context.Context, handler AIToolHandlerFn) error
}

AIToolReader discovers AI tools from a specific source. Implementations should be specific to a single AI application (e.g. one reader for Claude Code, another for Cursor).

func NewAIExtensionDiscoverer

func NewAIExtensionDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewAIExtensionDiscoverer creates a discoverer that bridges the VSIX extension reader to find AI-specific IDE extensions.

func NewAiderDiscoverer

func NewAiderDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewAiderDiscoverer creates a discoverer for the Aider CLI binary.

func NewAmazonQDiscoverer

func NewAmazonQDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewAmazonQDiscoverer creates a discoverer for the Amazon Q CLI binary.

func NewClaudeCLIDiscoverer

func NewClaudeCLIDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewClaudeCLIDiscoverer creates a discoverer for the Claude Code CLI binary.

func NewClaudeCodeDiscoverer

func NewClaudeCodeDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewClaudeCodeDiscoverer creates a Claude Code config discoverer.

func NewCursorCLIDiscoverer

func NewCursorCLIDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewCursorCLIDiscoverer creates a discoverer for the Cursor CLI binary.

func NewCursorDiscoverer

func NewCursorDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewCursorDiscoverer creates a Cursor config discoverer.

func NewGhCopilotDiscoverer

func NewGhCopilotDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewGhCopilotDiscoverer creates a discoverer for the GitHub Copilot gh extension.

func NewWindsurfCLIDiscoverer

func NewWindsurfCLIDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewWindsurfCLIDiscoverer creates a discoverer for the Windsurf CLI binary.

func NewWindsurfDiscoverer

func NewWindsurfDiscoverer(config DiscoveryConfig) (AIToolReader, error)

NewWindsurfDiscoverer creates a Windsurf config discoverer.

type AIToolScope

type AIToolScope string

AIToolScope distinguishes system-level (global) from project-level (repo-scoped) configs.

const (
	AIToolScopeSystem  AIToolScope = "system"
	AIToolScopeProject AIToolScope = "project"
)

func (AIToolScope) DisplayName added in v1.14.0

func (s AIToolScope) DisplayName() string

DisplayName returns a human-friendly label for the scope.

type AIToolType

type AIToolType string

AIToolType classifies the kind of AI tool discovered.

const (
	AIToolTypeMCPServer     AIToolType = "mcp_server"
	AIToolTypeCodingAgent   AIToolType = "coding_agent"
	AIToolTypeAIExtension   AIToolType = "ai_extension"
	AIToolTypeCLITool       AIToolType = "cli_tool"
	AIToolTypeProjectConfig AIToolType = "project_config"
)

func (AIToolType) DisplayName added in v1.14.0

func (t AIToolType) DisplayName() string

DisplayName returns a human-friendly label for the tool type.

type AgentConfig

type AgentConfig struct {
	Version          string   `json:"version,omitempty"`
	PermissionMode   string   `json:"permission_mode,omitempty"`
	InstructionFiles []string `json:"instruction_files,omitempty"`
	Model            string   `json:"model,omitempty"`
	APIKeyEnvName    string   `json:"api_key_env_name,omitempty"`
}

AgentConfig holds configuration details for a discovered AI coding agent.

type CLIToolVerifier

type CLIToolVerifier interface {
	// BinaryNames returns candidate binary names to search in PATH.
	BinaryNames() []string

	// VerifyArgs returns the arguments to execute for identity verification.
	VerifyArgs() []string

	// VerifyOutput checks the command output and confirms this is the expected tool.
	// Returns (version string, true) if verified, ("", false) if not the right tool.
	VerifyOutput(stdout, stderr string) (version string, verified bool)

	// DisplayName returns the human-readable name for reporting.
	DisplayName() string

	// App returns the application identifier.
	App() string
}

CLIToolVerifier is implemented by each AI CLI tool plugin.

type DiscoveryConfig

type DiscoveryConfig struct {
	// HomeDir overrides the user home directory (for testing)
	HomeDir string

	// ProjectDir is the project root for project-level discovery.
	// Empty string means skip project-level discovery.
	ProjectDir string

	// Scope controls which scopes are active during discovery.
	// Nil means all scopes are enabled.
	Scope *DiscoveryScope
}

DiscoveryConfig provides context for AI tool discovery.

func (DiscoveryConfig) ScopeEnabled

func (c DiscoveryConfig) ScopeEnabled(scope AIToolScope) bool

ScopeEnabled is a convenience method that checks whether the given scope is active in this config. Returns true when Scope is nil (all enabled).

type DiscoveryScope

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

DiscoveryScope controls which scopes are active during discovery. An empty set means all scopes are enabled.

func AllScopes

func AllScopes() *DiscoveryScope

AllScopes returns a scope with nothing filtered.

func NewDiscoveryScope

func NewDiscoveryScope(scopes ...AIToolScope) (*DiscoveryScope, error)

NewDiscoveryScope creates a scope filter from the given scope names. Returns an error if any scope name is not recognized.

func (*DiscoveryScope) All

func (ds *DiscoveryScope) All() bool

All reports whether all scopes are enabled (no filtering).

func (*DiscoveryScope) IsEnabled

func (ds *DiscoveryScope) IsEnabled(scope AIToolScope) bool

IsEnabled reports whether the given scope should be scanned. Returns true when no scopes are explicitly selected (all enabled).

func (*DiscoveryScope) Validate

func (ds *DiscoveryScope) Validate(config DiscoveryConfig) error

Validate checks that the DiscoveryConfig satisfies the prerequisites of all enabled scopes.

type MCPServerConfig

type MCPServerConfig struct {
	Transport        MCPTransport `json:"transport"`
	Command          string       `json:"command,omitempty"`
	Args             []string     `json:"args,omitempty"`
	URL              string       `json:"url,omitempty"`
	EnvVarNames      []string     `json:"env_var_names,omitempty"`
	HeaderNames      []string     `json:"header_names,omitempty"`
	AllowedTools     []string     `json:"allowed_tools,omitempty"`
	AllowedResources []string     `json:"allowed_resources,omitempty"`
}

MCPServerConfig holds configuration details for a discovered MCP server.

type MCPTransport

type MCPTransport string

MCPTransport identifies the transport protocol for an MCP server.

const (
	MCPTransportStdio          MCPTransport = "stdio"
	MCPTransportSSE            MCPTransport = "sse"
	MCPTransportStreamableHTTP MCPTransport = "streamable_http"
)

type Registry

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

Registry holds discoverer factories in registration order.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry wired with all built-in discoverers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Discover

func (r *Registry) Discover(ctx context.Context, config DiscoveryConfig, handler AIToolHandlerFn) error

Discover runs all registered discoverers and calls handler for each tool found. Factory or discoverer errors are logged and skipped; handler errors propagate immediately.

func (*Registry) Register

func (r *Registry) Register(name string, factory AIToolDiscovererFactory)

Register adds a discoverer factory to the registry.

type ScopeMetadata

type ScopeMetadata struct {
	RequiresHomeDir    bool
	RequiresProjectDir bool
}

ScopeMetadata describes the prerequisites for a scope.

Jump to

Keyboard shortcuts

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