intelligence

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package intelligence is the Stage-1 namespace for intent classification, capabilities, language support, tool selection. See ../REFACTOR_PLAN.md.

Index

Constants

View Source
const (
	IntentCodeWrite  = "code_write"
	IntentCodeFix    = "code_fix"
	IntentCodeReview = "code_review"
	IntentExplain    = "explain"
	IntentRefactor   = "refactor"
	IntentTest       = "test"
	IntentSearch     = "search"
	IntentConfig     = "config"
	IntentGit        = "git"
	IntentQuestion   = "question"
)

Intent category constants.

Variables

View Source
var TaskToolMap = map[string][]string{
	"read code":  {"Read", "Grep", "Glob", "LS"},
	"write code": {"Read", "Edit", "Write", "Bash"},
	"debug":      {"Read", "Grep", "Bash", "Edit"},
	"search":     {"Grep", "Glob", "WebSearch"},
	"test":       {"Bash", "Read", "Write"},
	"review":     {"Read", "Grep", "Glob"},
	"refactor":   {"Read", "Edit", "Write", "Grep", "Bash"},
	"deploy":     {"Bash", "Read", "Write"},
}

TaskToolMap provides built-in mappings from task intents to tool names.

Functions

func FormatCommandSuggestions

func FormatCommandSuggestions(suggestions []*CommandSuggestion) string

FormatCommandSuggestions formats a list of command suggestions for display.

func FormatIntent

func FormatIntent(intent *Intent) string

FormatIntent returns a human-readable summary of the classified intent.

func FormatLanguages

func FormatLanguages(configs []*LanguageConfig) string

FormatLanguages produces a human-readable summary of detected languages. The first language is marked as "(primary)".

func FormatToolSelection

func FormatToolSelection(task string, selection *ToolSelection) string

FormatToolSelection returns a formatted string representation of a ToolSelection.

Types

type Capability

type Capability struct {
	ID               string   `json:"id"`
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	Category         string   `json:"category"`
	Tools            []string `json:"tools"`
	Examples         []string `json:"examples"`
	Complexity       string   `json:"complexity"` // "trivial", "simple", "moderate", "complex"
	RequiresApproval bool     `json:"requires_approval"`
	Enabled          bool     `json:"enabled"`
}

Capability represents a single thing the agent can do.

type CapabilityRegistry

type CapabilityRegistry struct {
	Capabilities map[string]*Capability
	Categories   map[string][]string
	// contains filtered or unexported fields
}

CapabilityRegistry manages the set of capabilities the agent advertises.

func NewCapabilityRegistry

func NewCapabilityRegistry() *CapabilityRegistry

NewCapabilityRegistry creates a registry pre-populated with built-in capabilities.

func (*CapabilityRegistry) CanDo

func (r *CapabilityRegistry) CanDo(taskDescription string) []*Capability

CanDo matches a task description against capabilities and returns relevant ones.

func (*CapabilityRegistry) Disable

func (r *CapabilityRegistry) Disable(id string)

Disable disables a capability by ID.

func (*CapabilityRegistry) Enable

func (r *CapabilityRegistry) Enable(id string)

Enable enables a capability by ID.

func (*CapabilityRegistry) FormatCapability

func (r *CapabilityRegistry) FormatCapability(cap *Capability) string

FormatCapability returns a detailed formatted string for a single capability.

func (*CapabilityRegistry) FormatHelp

func (r *CapabilityRegistry) FormatHelp() string

FormatHelp returns a formatted help string listing all capabilities by category.

func (*CapabilityRegistry) GetCapability

func (r *CapabilityRegistry) GetCapability(id string) *Capability

GetCapability returns a capability by ID, or nil if not found.

func (*CapabilityRegistry) GetCategories

func (r *CapabilityRegistry) GetCategories() []string

GetCategories returns a sorted list of all category names.

func (*CapabilityRegistry) ListByCategory

func (r *CapabilityRegistry) ListByCategory(category string) []*Capability

ListByCategory returns all capabilities in the given category.

func (*CapabilityRegistry) Search

func (r *CapabilityRegistry) Search(query string) []*Capability

Search finds capabilities matching the query string against ID, name, description, and examples.

type ClassifiedInput

type ClassifiedInput struct {
	Input  string
	Intent *Intent
}

ClassifiedInput records a classification for history tracking.

type CommandSuggestion

type CommandSuggestion struct {
	Command     string
	Description string
	Confidence  float64
	Category    string
	Context     string
}

CommandSuggestion represents a single proactive command suggestion.

type Intent

type Intent struct {
	Category            string
	Confidence          float64
	SubCategory         string
	Keywords            []string
	SuggestedTools      []string
	EstimatedComplexity string
}

Intent represents a classified user intent with confidence and metadata.

type IntentClassifier

type IntentClassifier struct {
	Rules   []IntentRule
	History []ClassifiedInput
	// contains filtered or unexported fields
}

IntentClassifier categorizes user messages to route them to appropriate handling strategies before involving the LLM.

func NewIntentClassifier

func NewIntentClassifier() *IntentClassifier

NewIntentClassifier creates an IntentClassifier with default keyword rules for each intent category.

func (*IntentClassifier) Classify

func (ic *IntentClassifier) Classify(input string) *Intent

Classify analyzes the input string and returns the best matching Intent.

func (*IntentClassifier) ClassifyForRouting

func (ic *IntentClassifier) ClassifyForRouting(input string) (model, tools string)

ClassifyForRouting performs quick classification returning recommended model tier and tool set string.

func (*IntentClassifier) EstimateComplexity

func (ic *IntentClassifier) EstimateComplexity(input string) string

EstimateComplexity estimates how complex a request is based on word count, keyword density, and file mentions.

func (*IntentClassifier) GetPatterns

func (ic *IntentClassifier) GetPatterns() map[string]int

GetPatterns returns a map of intent categories to their occurrence count from classification history.

func (*IntentClassifier) RecordClassification

func (ic *IntentClassifier) RecordClassification(input string, intent *Intent)

RecordClassification stores a classification result in history for pattern analysis.

func (*IntentClassifier) SuggestTools

func (ic *IntentClassifier) SuggestTools(intent *Intent) []string

SuggestTools returns the recommended tool set for the given intent category.

type IntentRule

type IntentRule struct {
	Category    string
	SubCategory string
	Patterns    []string
	Weight      float64
	Tools       []string
}

IntentRule defines a pattern-matching rule for intent classification.

type LanguageConfig

type LanguageConfig struct {
	Name            string
	Extensions      []string
	TestCommand     string
	LintCommand     string
	FormatCommand   string
	BuildCommand    string
	PackageManager  string
	PackageFile     string
	ImportPattern   *regexp.Regexp
	FunctionPattern *regexp.Regexp
	CommentStyle    string // "//", "#", "--"
}

LanguageConfig describes a programming language's tooling and conventions.

type LanguageRegistry

type LanguageRegistry struct {
	Languages map[string]*LanguageConfig
	// contains filtered or unexported fields
}

LanguageRegistry manages a collection of language configurations.

func NewLanguageRegistry

func NewLanguageRegistry() *LanguageRegistry

NewLanguageRegistry creates a registry pre-populated with common languages.

func (*LanguageRegistry) Detect

func (r *LanguageRegistry) Detect(projectDir string) *LanguageConfig

Detect returns the primary language for a project directory by counting source files and checking for package manifest files.

func (*LanguageRegistry) DetectAll

func (r *LanguageRegistry) DetectAll(projectDir string) []*LanguageConfig

DetectAll returns all languages detected in a project, sorted by file count (most prevalent first). It walks the directory tree and matches extensions.

func (*LanguageRegistry) FormatCommand

func (r *LanguageRegistry) FormatCommand(projectDir string) string

FormatCommand returns the format command for the primary detected language.

func (*LanguageRegistry) GetByExtension

func (r *LanguageRegistry) GetByExtension(ext string) *LanguageConfig

GetByExtension finds a language by file extension (including the dot).

func (*LanguageRegistry) GetByName

func (r *LanguageRegistry) GetByName(name string) *LanguageConfig

GetByName looks up a language by its name (case-insensitive).

func (*LanguageRegistry) LintCommand

func (r *LanguageRegistry) LintCommand(projectDir string) string

LintCommand returns the lint command for the primary detected language.

func (*LanguageRegistry) Register

func (r *LanguageRegistry) Register(config *LanguageConfig)

Register adds or replaces a language configuration in the registry.

func (*LanguageRegistry) TestCommand

func (r *LanguageRegistry) TestCommand(projectDir string) string

TestCommand returns the test command for the primary detected language.

type SuggestionEngine

type SuggestionEngine struct {
	Rules   []SuggestionRule
	History []string
	Context map[string]string
	// contains filtered or unexported fields
}

SuggestionEngine evaluates rules against the current context to produce proactive command suggestions.

func NewSuggestionEngine

func NewSuggestionEngine() *SuggestionEngine

NewSuggestionEngine creates a SuggestionEngine with built-in rules.

func (*SuggestionEngine) AddRule

func (se *SuggestionEngine) AddRule(rule SuggestionRule)

AddRule adds a custom rule to the engine.

func (*SuggestionEngine) Dismiss

func (se *SuggestionEngine) Dismiss(command string)

Dismiss marks a command as dismissed so it won't be suggested again soon. The dismissal expires after 10 minutes.

func (*SuggestionEngine) GetTopSuggestion

func (se *SuggestionEngine) GetTopSuggestion() *CommandSuggestion

GetTopSuggestion returns the single best suggestion based on the engine's current internal context, or nil if no rules match.

func (*SuggestionEngine) RecordCommand

func (se *SuggestionEngine) RecordCommand(cmd string)

RecordCommand records a command in the engine's history for context tracking.

func (*SuggestionEngine) Suggest

func (se *SuggestionEngine) Suggest(ctx map[string]string) []*CommandSuggestion

Suggest evaluates all rules against the current context and returns top suggestions sorted by confidence (highest first).

func (*SuggestionEngine) UpdateContext

func (se *SuggestionEngine) UpdateContext(key, value string)

UpdateContext updates a key-value pair in the engine's internal context state.

type SuggestionRule

type SuggestionRule struct {
	Name      string
	Condition func(ctx map[string]string) bool
	Suggest   func(ctx map[string]string) *CommandSuggestion
	Priority  int
}

SuggestionRule defines a conditional rule that produces a suggestion.

type ToolInfo

type ToolInfo struct {
	Name     string
	Category string // "file", "search", "exec", "web", "agent", "system"
	Cost     string // "free", "cheap", "expensive"
	ReadOnly bool
}

ToolInfo describes a single tool available to the LLM.

type ToolSelection

type ToolSelection struct {
	Recommended []string
	Excluded    []string
	Reason      string
	Confidence  float64
}

ToolSelection holds the result of selecting tools for a task.

type ToolSelector

type ToolSelector struct {
	AllTools     []ToolInfo
	UsageHistory map[string]int
	TaskPatterns map[string][]string
	// contains filtered or unexported fields
}

ToolSelector recommends which tools to send to the LLM based on the task.

func NewToolSelector

func NewToolSelector(tools []ToolInfo) *ToolSelector

NewToolSelector creates a ToolSelector with the given tools.

func (*ToolSelector) Adapt

func (ts *ToolSelector) Adapt(feedback string)

Adapt processes feedback to adjust tool patterns for future selections. Feedback format example: "needed WebSearch but it wasn't available"

func (*ToolSelector) FilterExpensive

func (ts *ToolSelector) FilterExpensive(tools []string) []string

FilterExpensive removes tools marked as "expensive" from the provided list.

func (*ToolSelector) GetRecommendedForIntent

func (ts *ToolSelector) GetRecommendedForIntent(intent string) []string

GetRecommendedForIntent returns the tools mapped to a given intent category.

func (*ToolSelector) RecordUsage

func (ts *ToolSelector) RecordUsage(tool string, task string)

RecordUsage tracks which tools are used for which tasks.

func (*ToolSelector) Select

func (ts *ToolSelector) Select(task string, maxTools int) *ToolSelection

Select analyzes the task and returns a ToolSelection with at most maxTools recommended.

Jump to

Keyboard shortcuts

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