Documentation
¶
Overview ¶
Package shared provides common types, variables, and utilities for all command packages.
Index ¶
- Variables
- func ExecuteAndRecord(name string, fn func() (string, string, error)) error
- func GetAnalyticsAddr() string
- func GetBuffer() *bytes.Buffer
- func GetCachedConfig() (*config.Config, error)
- func GetCompressionAddr() string
- func GetConfig() (*config.Config, error)
- func GetConfigDir() string
- func GetConfigPath() string
- func GetDataPath() string
- func GetDatabasePath() string
- func GetDisableLayers() []string
- func GetEnableLayers() []string
- func GetFiltersDir() string
- func GetHooksPath() string
- func GetLayerPreset() string
- func GetLayerProfile() string
- func GetModelFamily(modelName string) string
- func GetProjectPath() string
- func GetQueryIntent() string
- func GetRemoteClient() *client.Client
- func GetRemoteTimeout() int
- func GetTokenBudget() int
- func IsLLMEnabled() bool
- func IsQuietMode() bool
- func IsRemoteMode() bool
- func IsReversibleEnabled() bool
- func IsStreamMode() bool
- func IsUltraCompact() bool
- func IsVerbose() bool
- func OpenTracker() (*tracking.Tracker, error)
- func PrintTokenSavings(originalTokens, filteredTokens int)
- func PutBuffer(buf *bytes.Buffer)
- func RecordCommand(command, originalOutput, filteredOutput string, execTimeMs int64, success bool) error
- func RemoteCompress(input, mode string, budget int) (output string, tokensSaved int, err error)
- func RemoteRecordAnalytics(command string, originalTokens, filteredTokens int, execTimeMs int64, ...) error
- func RootCmd() any
- func RunAndCapture(cmd string, args []string) (output string, exitCode int, err error)
- func SanitizeArgs(args []string) error
- func SetConfig(cfg FlagConfig)deprecated
- func SetConfigFile(path string)
- func SetFlags(cfg FlagConfig)
- func SetRootCmd(cmd any)
- func ShortenPath(path string) string
- func TeeOnFailure(raw string, commandSlug string, err error) string
- func Truncate(s string, maxLen int) string
- func TruncateLine(line string, maxLen int) string
- func TryJSONSchema(jsonStr string, maxDepth int) string
- type AppState
- func (s *AppState) GetAnalyticsAddr() string
- func (s *AppState) GetCompressionAddr() string
- func (s *AppState) GetDisableLayers() []string
- func (s *AppState) GetEnableLayers() []string
- func (s *AppState) GetLayerPreset() string
- func (s *AppState) GetQueryIntent() string
- func (s *AppState) GetRemoteTimeout() int
- func (s *AppState) GetTokenBudget() int
- func (s *AppState) IsLLMEnabled() bool
- func (s *AppState) IsQuietMode() bool
- func (s *AppState) IsRemoteMode() bool
- func (s *AppState) IsReversibleEnabled() bool
- func (s *AppState) IsStreamMode() bool
- func (s *AppState) IsUltraCompact() bool
- func (s *AppState) IsVerbose() bool
- func (s *AppState) Set(cfg FlagConfig)
- type FallbackHandler
- type FlagConfig
- type OutputType
Constants ¶
This section is empty.
Variables ¶
var ( CfgFile string Verbose int DryRun bool UltraCompact bool SkipEnv bool QueryIntent string LLMEnabled bool TokenBudget int FallbackArgs []string LayerPreset string LayerProfile string OutputFile string QuietMode bool JSONOutput bool RemoteMode bool CompressionAddr string AnalyticsAddr string RemoteTimeout int CompactionEnabled bool CompactionThreshold int CompactionPreserve int CompactionMaxTokens int CompactionSnapshot bool CompactionAutoDetect bool ReversibleEnabled bool EnableLayers []string DisableLayers []string StreamMode bool )
var Version string = "dev"
Version is set at build time.
Functions ¶
func ExecuteAndRecord ¶
ExecuteAndRecord runs a command function, prints output, and records metrics. This consolidates the common pattern of: time -> execute -> print -> record. Returns an error instead of calling os.Exit so callers control exit behavior.
func GetAnalyticsAddr ¶
func GetAnalyticsAddr() string
GetAnalyticsAddr returns the analytics service address.
func GetCachedConfig ¶
GetCachedConfig returns the cached config, loading it on first access.
func GetCompressionAddr ¶
func GetCompressionAddr() string
GetCompressionAddr returns the compression service address.
func GetConfigDir ¶
func GetConfigDir() string
GetConfigDir returns the directory that contains the effective config file.
func GetConfigPath ¶
func GetConfigPath() string
GetConfigPath returns the effective config path, honoring the shared override when --config is provided.
func GetDatabasePath ¶
func GetDatabasePath() string
GetDatabasePath returns the effective tracking database path using the loaded config when available, falling back to default path resolution.
func GetDisableLayers ¶
func GetDisableLayers() []string
GetDisableLayers returns layers to explicitly disable.
func GetEnableLayers ¶
func GetEnableLayers() []string
GetEnableLayers returns layers to explicitly enable.
func GetFiltersDir ¶
func GetFiltersDir() string
GetFiltersDir returns the effective user filters directory.
func GetLayerPreset ¶
func GetLayerPreset() string
GetLayerPreset returns the layer preset from flag or environment.
func GetLayerProfile ¶
func GetLayerProfile() string
GetLayerProfile returns the compression profile from flag or environment.
func GetModelFamily ¶
GetModelFamily extracts the model family from a model name. Delegates to utils.GetModelFamily for single source of truth.
func GetProjectPath ¶
func GetProjectPath() string
GetProjectPath returns the canonical current working directory.
func GetQueryIntent ¶
func GetQueryIntent() string
GetQueryIntent returns the query intent from flag or environment.
func GetRemoteClient ¶
GetRemoteClient returns the global gRPC client (lazy initialization). Returns nil if remote mode is not enabled or connection failed.
func GetRemoteTimeout ¶
func GetRemoteTimeout() int
GetRemoteTimeout returns the remote operation timeout in seconds.
func GetTokenBudget ¶
func GetTokenBudget() int
GetTokenBudget returns the token budget from flag or environment.
func IsLLMEnabled ¶
func IsLLMEnabled() bool
IsLLMEnabled returns true if LLM compression is enabled.
func IsReversibleEnabled ¶
func IsReversibleEnabled() bool
IsReversibleEnabled returns true if reversible mode is enabled.
func IsStreamMode ¶
func IsStreamMode() bool
IsStreamMode returns true if streaming mode is enabled for large inputs.
func IsUltraCompact ¶
func IsUltraCompact() bool
IsUltraCompact returns true if ultra-compact mode is enabled.
func OpenTracker ¶
OpenTracker opens the tracking database using the effective configured path.
func PrintTokenSavings ¶
func PrintTokenSavings(originalTokens, filteredTokens int)
PrintTokenSavings prints token savings info to stderr when in verbose mode.
func RecordCommand ¶
func RecordCommand(command, originalOutput, filteredOutput string, execTimeMs int64, success bool) error
RecordCommand records command execution metrics to the tracking database.
func RemoteCompress ¶
RemoteCompress performs compression via gRPC service. Returns the compressed output and tokens saved, or an error.
func RemoteRecordAnalytics ¶
func RemoteRecordAnalytics(command string, originalTokens, filteredTokens int, execTimeMs int64, success bool) error
RemoteRecordAnalytics sends command metrics to the analytics service.
func RunAndCapture ¶
RunAndCapture executes a command and captures stdout/stderr. This consolidates the common pattern of: exec.Command -> StdoutPipe -> StderrPipe -> Start -> Wait. Returns combined stdout and stderr, exit code, and any execution error.
func SanitizeArgs ¶
SanitizeArgs validates and sanitizes command arguments. Returns error if arguments contain dangerous patterns.
func SetConfig
deprecated
func SetConfig(cfg FlagConfig)
Backward compatibility: SetConfig alias for SetFlags
Deprecated: Use SetFlags instead. This alias exists only for callers that haven't migrated to the new naming convention.
func SetFlags ¶
func SetFlags(cfg FlagConfig)
SetFlags sets all flag values atomically on the global state.
func ShortenPath ¶
ShortenPath shortens a file path for display.
func TeeOnFailure ¶
TeeOnFailure writes output to tee file on error.
func TruncateLine ¶
TruncateLine truncates a line to maxLen characters.
func TryJSONSchema ¶
TryJSONSchema generates a JSON schema from a JSON string.
Types ¶
type AppState ¶
type AppState struct {
// Global flags set by CLI
CfgFile string
Verbose int
DryRun bool
UltraCompact bool
SkipEnv bool
QueryIntent string
LLMEnabled bool
TokenBudget int
FallbackArgs []string
LayerPreset string
LayerProfile string
OutputFile string
QuietMode bool
JSONOutput bool
// Remote mode flags (Phase 4)
RemoteMode bool
CompressionAddr string
AnalyticsAddr string
RemoteTimeout int // seconds
// Compaction flags
CompactionEnabled bool
CompactionThreshold int
CompactionPreserve int
CompactionMaxTokens int
CompactionSnapshot bool
CompactionAutoDetect bool
// Reversible mode
ReversibleEnabled bool
// Custom layer configuration
EnableLayers []string
DisableLayers []string
StreamMode bool
// contains filtered or unexported fields
}
AppState encapsulates all CLI flag state in a single struct. This replaces the global variable pattern and enables: - Testability (pass different state to different tests) - Concurrency (multiple commands with different configs) - Dependency injection (pass state explicitly)
func Global ¶
func Global() *AppState
Global returns the global AppState instance. Deprecated: Pass AppState explicitly where possible.
func (*AppState) GetAnalyticsAddr ¶
GetAnalyticsAddr returns the analytics service address.
func (*AppState) GetCompressionAddr ¶
GetCompressionAddr returns the compression service address.
func (*AppState) GetDisableLayers ¶
GetDisableLayers returns layers to explicitly disable.
func (*AppState) GetEnableLayers ¶
GetEnableLayers returns layers to explicitly enable.
func (*AppState) GetLayerPreset ¶
GetLayerPreset returns the layer preset from flag or environment.
func (*AppState) GetQueryIntent ¶
GetQueryIntent returns the query intent from flag or environment.
func (*AppState) GetRemoteTimeout ¶
GetRemoteTimeout returns the remote operation timeout in seconds.
func (*AppState) GetTokenBudget ¶
GetTokenBudget returns the token budget from flag or environment.
func (*AppState) IsLLMEnabled ¶
IsLLMEnabled returns true if LLM compression is enabled.
func (*AppState) IsQuietMode ¶
IsQuietMode returns true if quiet mode is enabled.
func (*AppState) IsRemoteMode ¶
IsRemoteMode returns true if remote mode is enabled.
func (*AppState) IsReversibleEnabled ¶
IsReversibleEnabled returns true if reversible mode is enabled.
func (*AppState) IsStreamMode ¶
IsStreamMode returns true if streaming mode is enabled for large inputs.
func (*AppState) IsUltraCompact ¶
IsUltraCompact returns true if ultra-compact mode is enabled.
type FallbackHandler ¶
type FallbackHandler struct {
// contains filtered or unexported fields
}
FallbackHandler handles commands via TOML filter system.
func GetFallback ¶
func GetFallback() *FallbackHandler
GetFallback returns the global fallback handler (singleton).
func NewFallbackHandler ¶
func NewFallbackHandler() *FallbackHandler
NewFallbackHandler creates a new fallback handler.
type FlagConfig ¶
type FlagConfig struct {
Verbose int
DryRun bool
UltraCompact bool
SkipEnv bool
QueryIntent string
LLMEnabled bool
TokenBudget int
FallbackArgs []string
LayerPreset string
LayerProfile string
OutputFile string
QuietMode bool
JSONOutput bool
RemoteMode bool
CompressionAddr string
AnalyticsAddr string
RemoteTimeout int
CompactionEnabled bool
CompactionThreshold int
CompactionPreserve int
CompactionMaxTokens int
CompactionSnapshot bool
CompactionAutoDetect bool
ReversibleEnabled bool
EnableLayers []string
DisableLayers []string
StreamMode bool
}
FlagConfig holds all flag values for atomic setting.
type OutputType ¶
type OutputType int
OutputType represents the type of command output.
const ( OutputTypeTest OutputType = iota OutputTypeBuild OutputTypeLog OutputTypeList OutputTypeJSON OutputTypeGeneric )