Documentation
¶
Overview ¶
Package analyze provides AI-powered analysis of CLI command output. When the --ai flag is set, command output (stdout/stderr) is captured and sent to the configured AI provider for analysis after execution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeOutput ¶
func AnalyzeOutput(atmosConfig *schema.AtmosConfiguration, input *AnalysisInput)
AnalyzeOutput sends captured command output to the configured AI provider for analysis. It creates an AI client, builds a prompt with the command context, and renders the response.
func BuildCommandName ¶
func BuildCommandName() string
BuildCommandName reconstructs a sanitized command label from os.Args for AI analysis context. Stops at the "--" delimiter to avoid leaking native tool arguments (which may contain secrets such as -var, tokens, or credentials passed to terraform/helmfile).
func ValidateAIConfig ¶
func ValidateAIConfig(atmosConfig *schema.AtmosConfiguration) error
ValidateAIConfig checks that AI is properly configured for the --ai flag. Returns a user-friendly error with hints if configuration is missing.
Types ¶
type AnalysisInput ¶
type AnalysisInput struct {
// CommandName is the full command string (e.g., "atmos terraform plan vpc -s prod").
CommandName string
// Stdout is the captured standard output.
Stdout string
// Stderr is the captured standard error.
Stderr string
// CmdErr is the error returned by the command (nil if successful).
CmdErr error
// SkillNames is the list of skill names used for AI analysis (e.g., ["atmos-terraform", "atmos-stacks"]).
SkillNames []string
// SkillPrompt is an optional skill system prompt for domain-specific expertise.
SkillPrompt string
}
AnalysisInput holds the inputs for AI analysis of command output.
type CaptureSession ¶
type CaptureSession struct {
// contains filtered or unexported fields
}
CaptureSession captures stdout and stderr while teeing to the original destinations. It uses os.Pipe() to intercept file descriptor writes, ensuring both Go-level writes (via io.Data/io.UI) and subprocess writes (terraform, helmfile) are captured.
func StartCapture ¶
func StartCapture() (*CaptureSession, error)
StartCapture begins capturing stdout and stderr. Output continues to flow to the terminal while also being buffered. Call Stop() when done to restore original streams and get captured output.
func (*CaptureSession) Stop ¶
func (cs *CaptureSession) Stop() (stdout, stderr string)
Stop restores the original stdout/stderr and returns the captured output. It blocks until all captured data has been flushed.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the state for AI output analysis across the command lifecycle. It manages the capture session, skill prompts, and analysis execution.
func NewDisabledContext ¶
func NewDisabledContext() *Context
NewDisabledContext returns a Context with AI disabled (used when --ai is not set).
func Setup ¶
func Setup(atmosConfig *schema.AtmosConfiguration, skillNames []string, commandName string) (*Context, error)
Setup validates AI configuration, loads skills if specified, and starts output capture. Returns a ready-to-use Context. The caller MUST call Cleanup() (via defer) to restore stdout/stderr.
func (*Context) Cleanup ¶
func (c *Context) Cleanup()
Cleanup restores stdout/stderr if capture is active. Safe to call multiple times (Stop is idempotent).
func (*Context) RunAnalysis ¶
RunAnalysis stops the capture session and sends captured output to the AI provider. When there's an error, it prints the formatted error BEFORE the AI analysis so the user sees the error first, followed by the AI explanation. Returns true if the error was already printed (caller should not re-print it).