engine

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FastPathBypassKindNone                 = ""
	FastPathBypassKindTinyOutput           = "tiny-output"
	FastPathBypassKindFamilyRule           = "family-rule"
	FastPathBypassKindEmptyPreferredStream = "empty-preferred-stream"
)
View Source
const (
	ConfidenceHigh   = "high"
	ConfidenceMedium = "medium"
	ConfidenceLow    = "low"
)
View Source
const (
	SourceBuiltin    = "built-in"
	SourceProject    = "project-local"
	SourcePreference = "project-preference"
	SourceFallback   = "fallback"
)
View Source
const (
	StreamAuto        = "auto"
	StreamStdoutOnly  = "stdout-only"
	StreamStderrOnly  = "stderr-only"
	StreamStdoutFirst = "stdout-first"
	StreamStderrFirst = "stderr-first"
)
View Source
const (
	StructuredModeNone           = ""
	StructuredModePreferred      = "preferred"
	StructuredModeStdoutOnly     = "stdout-only"
	StructuredModeStdoutRequired = "stdout-required"
)
View Source
const (
	FastPathBypassNever       = ""
	FastPathBypassSafeOnly    = "safe-only"
	FastPathBypassSmallOutput = "small-output"
)
View Source
const BudgetAdaptationSourceHistory = "history"
View Source
const RecoveryKindFullOutput = "full-output"

Variables

This section is empty.

Functions

func CombineStreams

func CombineStreams(stdout, stderr string) string

func ResolveBudgetWithAdapter added in v0.4.0

func ResolveBudgetWithAdapter(profile Profile, inv Invocation, fallbackLines int, adapter BudgetAdapter) (OutputBudget, *BudgetAdaptation)

func SanitizeFileName

func SanitizeFileName(value string) string

Types

type BudgetAdaptation added in v0.4.0

type BudgetAdaptation struct {
	Source      string
	Fingerprint string
	Direction   string
	Reason      string
	Confidence  string
	Samples     int
	Scale       float64
	Suggested   OutputBudget
	Applied     OutputBudget
}

type BudgetAdapter added in v0.4.0

type BudgetAdapter interface {
	AdaptBudget(profile Profile, inv Invocation, budget OutputBudget) (OutputBudget, *BudgetAdaptation)
}

type Classification added in v0.5.0

type Classification struct {
	Command ClassifiedCommand
	Display ClassifiedCommand
}

type ClassifiedCommand added in v0.5.0

type ClassifiedCommand struct {
	Head       string
	Subcommand string
	Git        GitCommandFacts
	JavaScript JavaScriptCommandFacts
}

type Engine

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

func New

func New(cfg config.Config, paths config.Paths, store *history.Store, profiles []Profile) *Engine

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, inv Invocation, passthrough bool) (Result, error)

func (*Engine) ExecuteStreaming

func (e *Engine) ExecuteStreaming(
	ctx context.Context,
	inv Invocation,
	passthrough bool,
	onPartial func(PartialResult),
) (Result, error)

func (*Engine) Explain

func (e *Engine) Explain(inv Invocation) Profile

func (*Engine) ExplainBudget added in v0.4.0

func (e *Engine) ExplainBudget(inv Invocation) (OutputBudget, *BudgetAdaptation)

func (*Engine) ExplainDecisions

func (e *Engine) ExplainDecisions(inv Invocation) []ExplainDecision

func (*Engine) ExplainPreferences

func (e *Engine) ExplainPreferences(inv Invocation) (Invocation, []PreferenceDecision)

func (*Engine) Profiles

func (e *Engine) Profiles() []Profile

func (*Engine) SetBudgetAdapter added in v0.4.0

func (e *Engine) SetBudgetAdapter(adapter BudgetAdapter)

type Execution

type Execution struct {
	Command  []string
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
}

type ExplainDecision

type ExplainDecision struct {
	Name        string
	Description string
	Source      string
	Selected    bool
	Explain     []string
}

type FastPathDecision

type FastPathDecision struct {
	BypassCompression bool
	BypassKind        string
	Reason            string
	WarnLatency       bool
}

func DecideFastPath

func DecideFastPath(profile Profile, inv Invocation, rawBytes, rawTokens int, duration time.Duration, exitCode int) FastPathDecision

type GitCommandFacts added in v0.5.0

type GitCommandFacts struct {
	StatusFormatRequested bool
	LogFormatRequested    bool
	DiffFormatRequested   bool
	DiffNoPatchRequested  bool
}

type HistoryBudgetAdapter added in v0.4.0

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

func NewHistoryBudgetAdapter added in v0.4.0

func NewHistoryBudgetAdapter(store *history.Store) *HistoryBudgetAdapter

func NewHistoryBudgetAdapterWithOptions added in v0.4.0

func NewHistoryBudgetAdapterWithOptions(store *history.Store, opts HistoryBudgetAdapterOptions) *HistoryBudgetAdapter

func (*HistoryBudgetAdapter) AdaptBudget added in v0.4.0

func (a *HistoryBudgetAdapter) AdaptBudget(profile Profile, inv Invocation, budget OutputBudget) (OutputBudget, *BudgetAdaptation)

type HistoryBudgetAdapterOptions added in v0.4.0

type HistoryBudgetAdapterOptions struct {
	SuggestionOptions             history.BudgetSuggestionOptions
	MinConfidence                 string
	MaxTightenPercent             int
	MaxLoosenPercent              int
	MaxFallbackHeavyLoosenPercent int
	MinDeltaLines                 int
	MinDeltaBytes                 int
	MinDeltaTokens                int
}

type Invocation

type Invocation struct {
	Command             []string
	Display             []string
	Cwd                 string
	Verbose             int
	UltraCompact        bool
	ReasoningBudgetMode string
	Advanced            config.Advanced
	Classification      Classification
}

func Classify added in v0.5.0

func Classify(inv Invocation) Invocation

type JavaScriptCommandFacts added in v0.5.0

type JavaScriptCommandFacts struct {
	IsPackageManagerTest bool
	IsWorkspaceCommand   bool
	Runner               string
	StructuredMode       bool
}

type OutputBudget

type OutputBudget struct {
	MaxLines           int
	MaxBytes           int
	MaxTokens          int
	MinFailures        int
	MinAnchors         int
	MinHints           int
	NoisePrefiltering  bool
	SemanticCompaction bool
	AdaptiveBudgets    bool
	EarlyCaptureStop   bool
	AggressiveRewrites bool
}

func ExpandBudgetForFailureEscape

func ExpandBudgetForFailureEscape(budget OutputBudget, inv Invocation) OutputBudget

func ResolveBudget

func ResolveBudget(profile Profile, inv Invocation, fallbackLines int) OutputBudget

type PartialResult

type PartialResult struct {
	ProfileName       string
	ProfileConfidence string
	Display           string
	BytesParsed       int
	Final             bool
}

type PreferenceDecision

type PreferenceDecision struct {
	Name             string
	Description      string
	Source           string
	Applied          bool
	EffectiveCommand []string
	Explain          []string
}

type Profile

type Profile struct {
	Name             string
	Description      string
	Source           string
	Confidence       string
	Capabilities     ProfileCapabilities
	StreamPreference string
	Budget           OutputBudget
	LatencyBudget    time.Duration
	Match            func(Invocation) bool
	Prepare          func(Invocation) []string
	Render           func(Invocation, Execution) string
	StreamRender     StreamRenderFactory
	ParseBytes       func(Execution) int
	Explain          []string
}

type ProfileCapabilities added in v0.5.0

type ProfileCapabilities struct {
	StructuredMode            string
	InjectsPrepareArgs        bool
	SupportsAggressivePrepare bool
	FastPathBypass            string
	AllowFailureEscape        bool
	RequireFullCapture        bool
}

type RecoveryPlan added in v0.5.0

type RecoveryPlan struct {
	Kind              string
	Summary           string
	RequireRawCapture bool
}

type RenderedExecution

type RenderedExecution struct {
	Text           string
	RawCombined    string
	BytesParsed    int
	BytesEmitted   int
	RawTokens      int
	FilteredTokens int
	FallbackUsed   bool
}

func RenderExecution

func RenderExecution(profile Profile, inv Invocation, exec Execution, fallbackLines int, passthrough bool) RenderedExecution

type Result

type Result struct {
	ProfileName       string
	ProfileConfidence string
	Display           string
	RawCombined       string
	ExitCode          int
	TeePath           string
	Duration          time.Duration
	FallbackUsed      bool
	BypassReason      string
	LatencyWarning    bool
	RawBytesRead      int
	BytesParsed       int
	BytesEmitted      int
}

type StreamReducer

type StreamReducer interface {
	ConsumeStdout([]byte)
	ConsumeStderr([]byte)
	Result() string
	BytesParsed() int
	FallbackUsed() bool
}

type StreamReducerDone

type StreamReducerDone interface {
	Done() bool
}

type StreamReducerPreview

type StreamReducerPreview interface {
	Preview() string
}

type StreamRenderFactory

type StreamRenderFactory func(Invocation, OutputBudget) StreamReducer

Jump to

Keyboard shortcuts

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