feat(ai): add empty buffer context suggestions

Enable AI suggestions on empty prompts with enhanced
environmental context.

- Update AI_MIN_INPUT default from 3 to 0
- Add ALLOW_EMPTY_BUFFER opt-in config variable
- Remove empty-buffer guards in modify, suggest, enable
- Add zle-line-init hook for prompt-time suggestions
- Enhance history gathering with PWD-aware priority
- Add env context for dir listing, git branch, status
- Implement dual prompts: predict vs complete modes
- Add prompt artifact stripping for $ and > prefixes
- Update README with empty buffer configuration
- Add tests for empty buffer and artifact stripping

Empty buffer suggestions require zsh 5.3+ and work best with
AI strategy, leveraging directory context, git state, and
command history to predict likely next actions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Frad LEE 2026-02-05 10:58:19 +08:00
commit d89bf4ec0d
7 changed files with 282 additions and 31 deletions

View file

@ -109,7 +109,7 @@ 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
typeset -g ZSH_AUTOSUGGEST_AI_MIN_INPUT=0
# Number of recent history lines to include as context
(( ! ${+ZSH_AUTOSUGGEST_AI_HISTORY_LINES} )) &&
@ -118,3 +118,7 @@ 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
# 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