From 55cd4ec23d0514538ef22d31ee771a1df9600631 Mon Sep 17 00:00:00 2001 From: Frad LEE Date: Thu, 12 Feb 2026 17:01:15 +0800 Subject: [PATCH] fix(ai): prevent async suggestion duplication - Add buffer validation to check suggestion starts with buffer - Discard stale suggestions that don't match current content Fixes text duplication bug when accepting async suggestions after buffer changes during suggestion fetch. Co-Authored-By: Claude Opus 4.6 --- .claude/git.local.md | 52 ++++++++++++++++++++++++++++++++++++++ spec/strategies/ai_spec.rb | 26 +++++++++++++++++++ src/widgets.zsh | 8 +++++- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .claude/git.local.md diff --git a/.claude/git.local.md b/.claude/git.local.md new file mode 100644 index 0000000..1c42455 --- /dev/null +++ b/.claude/git.local.md @@ -0,0 +1,52 @@ +--- +enabled: true +# Commit Message Conventions +scopes: + - ai + - widget + - strategy + - spec + - integration + - option + - docs + - ci +types: + - feat + - fix + - docs + - refactor + - test + - chore + - perf + - style +# Branch Naming Conventions +branch_prefixes: + feature: feature/* + fix: fix/* + hotfix: hotfix/* + refactor: refactor/* + docs: docs/* +# .gitignore Generation Defaults +gitignore: + os: [macos, linux, windows] + languages: [ruby, shell] + frameworks: [] + tools: [rspec, github-actions] +--- + +# Project-Specific Git Settings + +This file configures the `@git/` plugin for this project. The settings above in the YAML frontmatter define valid scopes, types, and branch naming conventions that the plugin will enforce. + +## Usage + +- **Scopes**: When creating a commit with `/commit`, choose from the defined `scopes`. +- **Branching**: When creating a new branch via the `git` skill, use the defined `branch_prefixes`. +- **Gitignore**: When running `/gitignore` without arguments, the technologies listed above will be used as defaults. + +## Additional Guidelines + +- Always run tests before committing. +- Ensure linting passes before pushing. +- Reference issue numbers in commit footers (e.g., `Closes #123`). +- Use `BREAKING CHANGE:` prefix in the body for breaking changes. \ No newline at end of file diff --git a/spec/strategies/ai_spec.rb b/spec/strategies/ai_spec.rb index 072e477..95dda32 100644 --- a/spec/strategies/ai_spec.rb +++ b/spec/strategies/ai_spec.rb @@ -405,3 +405,29 @@ EOFCURL wait_for { session.content }.to eq('temp 0.3') end end + + context 'suggestion buffer validation' do + let(:options) { ["ZSH_AUTOSUGGEST_AI_API_KEY=test-key", "ZSH_AUTOSUGGEST_STRATEGY=(ai)"] } + + context 'when suggestion does not match current buffer' do + let(:before_sourcing) do + -> { + session.run_command('curl() { + if [[ "$*" == *"max-time"* ]]; then + cat <