Documentation
¶
Overview ¶
* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT
* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT
* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT
* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT
* ChatCLI - Command Line Interface for LLM interaction * Copyright (c) 2024 Edilson Freitas * License: MIT
Index ¶
- Constants
- func VisibleLen(s string) int
- type CommandBlock
- type CommandContextInfo
- type CommandExecutor
- type CommandOutput
- type CommandValidator
- type ContextManager
- func (cm *ContextManager) CreateExecutionContext() (context.Context, context.CancelFunc)
- func (cm *ContextManager) GetDefaultTimeout() time.Duration
- func (cm *ContextManager) RequestLLMContinuation(ctx context.Context, llmClient interface{}, history []models.Message, ...) (string, error)
- func (cm *ContextManager) RequestLLMWithPreExecutionContext(ctx context.Context, llmClient interface{}, history []models.Message, ...) (string, error)
- func (cm *ContextManager) SetDefaultTimeout(timeout time.Duration)
- type ExecutionResult
- type SourceType
- type ToolCall
- type UIRenderer
- func (r *UIRenderer) ClearScreen()
- func (r *UIRenderer) Colorize(text string, color string) string
- func (r *UIRenderer) PrintHeader()
- func (r *UIRenderer) PrintLastResult(outputs []*CommandOutput, lastIdx int)
- func (r *UIRenderer) PrintMenu()
- func (r *UIRenderer) PrintPlanCompact(blocks []CommandBlock, outputs []*CommandOutput)
- func (r *UIRenderer) PrintPlanFull(blocks []CommandBlock, outputs []*CommandOutput, validator *CommandValidator)
- func (r *UIRenderer) PrintPrompt() string
- func (r *UIRenderer) RenderBatchHeader(totalActions int)
- func (r *UIRenderer) RenderBatchSummary(successCount, total int, hasError bool)
- func (r *UIRenderer) RenderMarkdownTimelineEvent(icon, title, renderedMarkdownANSI, color string)
- func (r *UIRenderer) RenderThinking(thought string)
- func (r *UIRenderer) RenderTimelineEvent(icon, title, content, color string)
- func (r *UIRenderer) RenderToolCall(toolName, rawArgs string)
- func (r *UIRenderer) RenderToolCallWithProgress(toolName, rawArgs string, current, total int)
- func (r *UIRenderer) RenderToolResult(output string, isError bool)
- func (r *UIRenderer) SetSkipClearOnNextDraw(skip bool)
- func (r *UIRenderer) ShowInPager(text string) error
Constants ¶
const ( ColorReset = "\033[0m" ColorGreen = "\033[32m" ColorLime = "\033[92m" ColorCyan = "\033[36m" ColorGray = "\033[90m" ColorPurple = "\033[35m" ColorBold = "\033[1m" ColorYellow = "\033[33m" )
ANSI Color codes exportados
Variables ¶
This section is empty.
Functions ¶
func VisibleLen ¶
VisibleLen calcula comprimento visível (sem ANSI codes) - EXPORTADA
Types ¶
type CommandBlock ¶
type CommandBlock struct {
Description string
Commands []string
Language string
ContextInfo CommandContextInfo
}
CommandBlock representa um bloco de comandos executáveis
type CommandContextInfo ¶
type CommandContextInfo struct {
SourceType SourceType
FileExtension string
IsScript bool
ScriptType string // shell, python, etc.
}
CommandContextInfo contém metadados sobre a origem e natureza de um comando
type CommandExecutor ¶
type CommandExecutor struct {
// contains filtered or unexported fields
}
CommandExecutor executa comandos do sistema de forma segura
func NewCommandExecutor ¶
func NewCommandExecutor(logger *zap.Logger) *CommandExecutor
NewCommandExecutor cria uma nova instância do executor
func (*CommandExecutor) CaptureOutput ¶
func (e *CommandExecutor) CaptureOutput(ctx context.Context, shell string, args []string) ([]byte, error)
CaptureOutput executa comando e captura apenas a saída (para uso interno)
func (*CommandExecutor) Execute ¶
func (e *CommandExecutor) Execute(ctx context.Context, command string, interactive bool) (*ExecutionResult, error)
Execute executa um comando e retorna o resultado
type CommandOutput ¶
type CommandOutput struct {
CommandBlock CommandBlock
Output string
ErrorMsg string
}
CommandOutput representa o resultado da execução de um comando
type CommandValidator ¶
type CommandValidator struct {
// contains filtered or unexported fields
}
CommandValidator valida comandos antes da execução
func NewCommandValidator ¶
func NewCommandValidator(logger *zap.Logger) *CommandValidator
NewCommandValidator cria uma nova instância do validador
func (*CommandValidator) IsDangerous ¶
func (v *CommandValidator) IsDangerous(cmd string) bool
IsDangerous verifica se um comando é potencialmente perigoso
func (*CommandValidator) IsLikelyInteractive ¶
func (v *CommandValidator) IsLikelyInteractive(cmd string) bool
IsLikelyInteractive verifica se um comando provavelmente é interativo
func (*CommandValidator) ValidateCommand ¶
func (v *CommandValidator) ValidateCommand(cmd string) error
ValidateCommand valida um comando antes da execução
type ContextManager ¶
type ContextManager struct {
// contains filtered or unexported fields
}
ContextManager gerencia contexto de execução para o agente
func NewContextManager ¶
func NewContextManager(logger *zap.Logger) *ContextManager
NewContextManager cria uma nova instância do gerenciador de contexto
func (*ContextManager) CreateExecutionContext ¶
func (cm *ContextManager) CreateExecutionContext() (context.Context, context.CancelFunc)
CreateExecutionContext cria um contexto com timeout para execução
func (*ContextManager) GetDefaultTimeout ¶
func (cm *ContextManager) GetDefaultTimeout() time.Duration
GetDefaultTimeout retorna o timeout padrão configurado
func (*ContextManager) RequestLLMContinuation ¶
func (cm *ContextManager) RequestLLMContinuation( ctx context.Context, llmClient interface{}, history []models.Message, previousCommand string, output string, stderr string, userContext string, ) (string, error)
RequestLLMContinuation solicita continuação à LLM com contexto adicional
func (*ContextManager) RequestLLMWithPreExecutionContext ¶
func (cm *ContextManager) RequestLLMWithPreExecutionContext( ctx context.Context, llmClient interface{}, history []models.Message, originalCommand string, userContext string, ) (string, error)
RequestLLMWithPreExecutionContext solicita refinamento antes da execução
func (*ContextManager) SetDefaultTimeout ¶
func (cm *ContextManager) SetDefaultTimeout(timeout time.Duration)
SetDefaultTimeout atualiza o timeout padrão
type ExecutionResult ¶
type ExecutionResult struct {
Command string
Output string
Error string
ExitCode int
Duration time.Duration
WasKilled bool
}
ExecutionResult contém o resultado de uma execução
type SourceType ¶
type SourceType int
SourceType define o tipo de origem do comando
const ( SourceTypeUserInput SourceType = iota SourceTypeFile SourceTypeCommandOutput )
type ToolCall ¶ added in v1.43.0
ToolCall representa uma invocação de ferramenta parseada do texto.
func ParseToolCalls ¶ added in v1.43.0
ParseToolCalls extrai tool calls do texto. Suporta:
- <tool_call name="@x" args="..." />
- <tool_call args="..." name="@x"></tool_call>
- args com aspas simples ou duplas
- args multiline
- múltiplos tool_calls no mesmo texto
type UIRenderer ¶
type UIRenderer struct {
// contains filtered or unexported fields
}
UIRenderer gerencia a renderização da interface do modo agente
func NewUIRenderer ¶
func NewUIRenderer(logger *zap.Logger) *UIRenderer
NewUIRenderer cria uma nova instância do renderizador de UI
func (*UIRenderer) ClearScreen ¶
func (r *UIRenderer) ClearScreen()
ClearScreen limpa a tela (se permitido)
func (*UIRenderer) Colorize ¶
func (r *UIRenderer) Colorize(text string, color string) string
Colorize aplica cores ANSI (exportada com C maiúsculo)
func (*UIRenderer) PrintHeader ¶
func (r *UIRenderer) PrintHeader()
PrintHeader imprime o cabeçalho do modo agente
func (*UIRenderer) PrintLastResult ¶
func (r *UIRenderer) PrintLastResult(outputs []*CommandOutput, lastIdx int)
PrintLastResult imprime o último resultado
func (*UIRenderer) PrintPlanCompact ¶
func (r *UIRenderer) PrintPlanCompact(blocks []CommandBlock, outputs []*CommandOutput)
PrintPlanCompact imprime plano em formato compacto
func (*UIRenderer) PrintPlanFull ¶
func (r *UIRenderer) PrintPlanFull(blocks []CommandBlock, outputs []*CommandOutput, validator *CommandValidator)
PrintPlanFull imprime plano em formato completo
func (*UIRenderer) PrintPrompt ¶
func (r *UIRenderer) PrintPrompt() string
PrintPrompt imprime o prompt de entrada
func (*UIRenderer) RenderBatchHeader ¶ added in v1.45.0
func (r *UIRenderer) RenderBatchHeader(totalActions int)
RenderBatchHeader exibe um cabeçalho indicando o início de um lote
func (*UIRenderer) RenderBatchSummary ¶ added in v1.45.0
func (r *UIRenderer) RenderBatchSummary(successCount, total int, hasError bool)
RenderBatchSummary exibe o resultado final do lote
func (*UIRenderer) RenderMarkdownTimelineEvent ¶ added in v1.43.7
func (r *UIRenderer) RenderMarkdownTimelineEvent(icon, title, renderedMarkdownANSI, color string)
RenderMarkdownTimelineEvent renderiza markdown (já convertido para ANSI fora) dentro do card. Ele só delega para RenderTimelineEvent, mas existe para explicitar intenção e padronizar chamadas.
func (*UIRenderer) RenderThinking ¶ added in v1.40.0
func (r *UIRenderer) RenderThinking(thought string)
RenderThinking exibe o pensamento da IA
func (*UIRenderer) RenderTimelineEvent ¶ added in v1.40.0
func (r *UIRenderer) RenderTimelineEvent(icon, title, content, color string)
RenderTimelineEvent desenha um "card" estilizado ajustado à largura do terminal
func (*UIRenderer) RenderToolCall ¶ added in v1.40.0
func (r *UIRenderer) RenderToolCall(toolName, rawArgs string)
RenderToolCall exibe a chamada da ferramenta de forma limpa (escondendo Base64 e sujeira HTML)
func (*UIRenderer) RenderToolCallWithProgress ¶ added in v1.45.0
func (r *UIRenderer) RenderToolCallWithProgress(toolName, rawArgs string, current, total int)
RenderToolCallWithProgress exibe a chamada da ferramenta em formato de CARD (Box), limpando barras invertidas visuais e mostrando o progresso.
func (*UIRenderer) RenderToolResult ¶ added in v1.40.0
func (r *UIRenderer) RenderToolResult(output string, isError bool)
RenderToolResult exibe o resultado da execução
func (*UIRenderer) SetSkipClearOnNextDraw ¶
func (r *UIRenderer) SetSkipClearOnNextDraw(skip bool)
SetSkipClearOnNextDraw define se o próximo clear deve ser pulado
func (*UIRenderer) ShowInPager ¶
func (r *UIRenderer) ShowInPager(text string) error
ShowInPager abre texto em pager (less/more)