- Complete architectural overhaul of useUnifiedCompletion hook - Unified state management: 8 separate states → single CompletionState interface - Simplified core logic: getWordAtCursor 194 lines → 42 lines (78% reduction) - Fixed infinite React update loops with ref-based input tracking - Smart triggering mechanism replacing aggressive auto-completion - Integrated @agent and @file mention system with system reminders - Added comprehensive agent loading and mention processing - Enhanced Tab/Arrow/Enter key handling with clean event management - Maintained 100% functional compatibility across all completion types Key improvements: • File path completion (relative, absolute, ~expansion, @references) • Slash command completion (/help, /model, etc.) • Agent completion (@agent-xxx with intelligent descriptions) • System command completion (PATH scanning with fallback) • Terminal-style Tab cycling, Enter confirmation, Escape cancellation • Preview mode with boundary calculation • History navigation compatibility • Empty directory handling with user feedback Architecture: Event-driven @mention detection → system reminder injection → LLM tool usage Performance: Eliminated 7-layer nested conditionals, reduced state synchronization issues Reliability: Fixed maximum update depth exceeded warnings, stable state management
3.5 KiB
3.5 KiB
Intelligent Autocomplete System Enhancements
Overview
Successfully implemented a terminal-like intelligent file autocomplete system with context-aware suggestions and improved @mention detection for files.
Key Improvements
1. Fixed @filename Detection
Problem: Direct @filename didn't work, only @./ and @/ worked
Solution: Enhanced file detection in useAgentMentionTypeahead to:
- Search for files without requiring path separators
- Check common file extensions automatically
- Support case-insensitive matching
- Add file icons (📁 for directories, 📄 for files)
2. Tab Key Conflict Resolution
Problem: Tab key for model switching prevented autocomplete from working
Solution: Made Tab key context-aware in PromptInput.tsx:
// Only switch model if no autocomplete is active
if (!hasSlashSuggestions && !hasAgentSuggestions && !hasPathAutocomplete) {
handleQuickModelSwitch()
}
3. Intelligent Path Autocomplete
New Features:
-
Context Detection: Automatically detects when file completion is needed
- After file commands (cat, ls, cd, vim, etc.)
- When typing path-like strings
- After keywords like "with", "from", "to", "in"
-
Smart Sorting: Files are ranked by relevance
- Command-specific scoring (cd prefers directories)
- Common important files get higher scores
- Current directory files prioritized
- Hidden files deprioritized unless explicitly requested
-
Visual Feedback: Icons for different file types
- 📁 Directories
- 🟨 JavaScript
- 🔷 TypeScript
- 📝 Markdown
- 🐍 Python
- And more...
-
Seamless Experience:
- Debounced suggestions while typing (300ms delay)
- Auto-suggestions for <5 matches
- Tab completion like terminal
- Case-insensitive matching
Usage Examples
1. Direct File Mention
Type: @package
Shows: 📄 package.json
Tab completes to: @package.json
2. Command Context
Type: cat pa
Shows: 📄 package.json (automatically)
Tab completes to: cat package.json
3. Directory Navigation
Type: cd s
Shows: 📁 src/
Tab completes to: cd src/
4. Pattern Matching
Type: edit from README
Shows: 📝 README.md
Tab completes the path
Technical Implementation
File Context Detection Algorithm
// Detects file context based on:
1. Command analysis (file-related commands)
2. Path-like patterns (/, ., ~, extensions)
3. Keyword patterns (with, from, to, in, file:)
Intelligent Scoring System
// Scoring factors:
- Command relevance (+100 for cd→directories)
- File importance (+40 for package.json, README.md)
- Location preference (+20 for current directory)
- Visibility (-10 for hidden files)
- Ignore patterns (-50 for node_modules)
Tab Key Priority
1. Slash commands (/command)
2. Agent mentions (@agent-xxx)
3. File paths (context-dependent)
4. Model switching (fallback)
Benefits
- No Special Prefix Required: Works like a real terminal
- Context-Aware: Understands when you need files
- Smart Suggestions: Relevant files appear first
- Visual Clarity: Icons show file types at a glance
- Non-Intrusive: Only suggests when helpful
- Terminal-Like: Familiar Tab completion behavior
Future Enhancements
- History-based scoring: Remember frequently used files
- Fuzzy matching: Support typos and partial matches
- Command-specific filters: More intelligent filtering per command
- Multi-select: Select multiple files at once
- Preview: Show file contents on hover