- macOS, Linux badge and AI suggestions showcase in README - Update user guide and docs for development
1.4 KiB
1.4 KiB
AI engine architecture (internal/ai/)
The AI subsystem provides real-time, context-aware command completions powered by cloud or local LLM providers (Groq, Ollama).
Core components
internal/ai/client.go: Defines theClientinterface and handles HTTP requests to OpenAI-compatible chat completion endpoints.internal/ai/env.go: Captures runtime context snapshots (EnvSnapshot) including CWD, previous command, exit code, and recent history.internal/ai/prompts.go: Constructs system and user prompts optimized for shell command completion.root/wrapper.go: Manages async debounce timers, request cancellation (context.WithCancel), and ghost text injection.
Provider interface
All providers use a unified HTTP pattern matching OpenAI's /v1/chat/completions format:
type Client interface {
Suggest(ctx context.Context, prompt string, env *EnvSnapshot, currentCmd string) (*AISuggestion, error)
}
Request lifecycle
- User types in the prompt buffer.
root/wrapper.gotriggers a debounce timer (debounce_ms, default 500ms).- If typing continues, previous in-flight contexts are cancelled (
aiCancel()). - An
EnvSnapshotis created capturing CWD, last executed command, and up to 3 recent history entries. - Provider sends an HTTP POST request with structured JSON payload.
- Response is parsed and rendered as inline ghost text via
overlay.InjectAISuggestion().