feat: add ai suggestion strategy

Add new AI strategy that queries OpenAI-compatible LLM APIs
to generate intelligent command completions based on partial
input, working directory, and recent shell history.

- Add AI strategy implementation with JSON escaping
- Add context gathering with PWD prioritization
- Add response normalization for clean suggestions
- Add configuration defaults for AI settings
- Add comprehensive test suite with mocked responses
- Update README with setup guide and examples

Enables LLM-powered completions via ZSH_AUTOSUGGEST_AI_API_KEY
with silent failure and fallback to next strategy. Supports
OpenAI, Ollama, and custom endpoints. Requires curl and jq.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Frad LEE 2026-02-05 10:24:52 +08:00
commit 8a9c1a2a30
5 changed files with 666 additions and 1 deletions

View file

@ -93,3 +93,28 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
# Pty name for capturing completions for completion suggestion strategy
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
# AI strategy configuration
# API endpoint for AI suggestions (OpenAI-compatible)
(( ! ${+ZSH_AUTOSUGGEST_AI_ENDPOINT} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_ENDPOINT='https://api.openai.com/v1/chat/completions'
# AI model to use for suggestions
(( ! ${+ZSH_AUTOSUGGEST_AI_MODEL} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_MODEL='gpt-3.5-turbo'
# Timeout in seconds for AI API requests
(( ! ${+ZSH_AUTOSUGGEST_AI_TIMEOUT} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_TIMEOUT=5
# Minimum input length before querying AI
(( ! ${+ZSH_AUTOSUGGEST_AI_MIN_INPUT} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_MIN_INPUT=3
# Number of recent history lines to include as context
(( ! ${+ZSH_AUTOSUGGEST_AI_HISTORY_LINES} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_HISTORY_LINES=20
# Prefer history entries from current directory
(( ! ${+ZSH_AUTOSUGGEST_AI_PREFER_PWD_HISTORY} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_PREFER_PWD_HISTORY=yes