refactor(ai): replace empty buffer with min input

- Replace ZSH_AUTOSUGGEST_ALLOW_EMPTY_BUFFER with AI_MIN_INPUT
- Add ZSH_AUTOSUGGEST_AI_DEBUG environment variable
- Add debug logging function to diagnose failures
- Update history lines default from 20 to 5
- Update pwd history preference default to no

Min input provides clearer semantics: set to 0 for empty-buffer
suggestions or higher to require minimum input. Debug logging helps
diagnose missing suggestions by showing API request flow.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Frad LEE 2026-02-05 14:39:12 +08:00
commit cd66c5695a
7 changed files with 142 additions and 52 deletions

View file

@ -108,17 +108,17 @@ typeset -g ZSH_AUTOSUGGEST_AI_MODEL='gpt-3.5-turbo'
typeset -g ZSH_AUTOSUGGEST_AI_TIMEOUT=5
# Minimum input length before querying AI
# Set to 0 to allow empty-buffer AI suggestions
(( ! ${+ZSH_AUTOSUGGEST_AI_MIN_INPUT} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_MIN_INPUT=0
typeset -g ZSH_AUTOSUGGEST_AI_MIN_INPUT=1
# Number of recent history lines to include as context
(( ! ${+ZSH_AUTOSUGGEST_AI_HISTORY_LINES} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_HISTORY_LINES=20
typeset -g ZSH_AUTOSUGGEST_AI_HISTORY_LINES=5
# Prefer history entries from current directory
(( ! ${+ZSH_AUTOSUGGEST_AI_PREFER_PWD_HISTORY} )) &&
typeset -g ZSH_AUTOSUGGEST_AI_PREFER_PWD_HISTORY=yes
typeset -g ZSH_AUTOSUGGEST_AI_PREFER_PWD_HISTORY=no
# Allow suggestions on empty buffer (opt-in, for AI strategy)
# Set to any value to enable. Unset by default.
# Uses (( ${+VAR} )) pattern like ZSH_AUTOSUGGEST_MANUAL_REBIND
# Enable AI debug logs to stderr (opt-in).
# Set to any value except 0/false/no/off to enable.