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

@ -171,3 +171,73 @@ EOF
end
end
end
context 'prompt artifact stripping' do
let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai)"] }
let(:before_sourcing) do
-> {
session.run_command('curl() {
if [[ "$*" == *"max-time"* ]]; then
cat <<EOFCURL
{"choices":[{"message":{"content":"$ git status"}}]}
200
EOFCURL
fi
}')
}
end
it 'strips $ prompt artifact' do
session.send_string('git st')
wait_for { session.content }.to eq('git status')
end
end
context 'empty buffer suggestions' do
let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_ALLOW_EMPTY_BUFFER=1", "ZSH_AUTOSUGGEST_STRATEGY=(ai)"] }
let(:before_sourcing) do
-> {
session.run_command('curl() {
if [[ "$*" == *"max-time"* ]]; then
cat <<EOFCURL
{"choices":[{"message":{"content":"git status"}}]}
200
EOFCURL
fi
}')
}
end
it 'suggests command on empty buffer when enabled' do
session.send_keys('C-c')
wait_for { session.content(esc_seqs: true) }.to match(/git status/)
end
end
context 'empty buffer without flag' do
let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai history)"] }
let(:before_sourcing) do
-> {
session.run_command('curl() {
if [[ "$*" == *"max-time"* ]]; then
cat <<EOFCURL
{"choices":[{"message":{"content":"git status"}}]}
200
EOFCURL
fi
}')
}
end
it 'does not suggest on empty buffer by default' do
with_history('git status') do
sleep 0.5
expect(session.content).to_not match(/git status/)
session.send_string('git')
wait_for { session.content }.to eq('git status')
end
end
end