- 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
74 lines
2.1 KiB
Markdown
74 lines
2.1 KiB
Markdown
# System Reminder Solution for @mentions
|
|
|
|
## Design Principles
|
|
|
|
1. **Keep it Simple**: No complex async operations
|
|
2. **Don't Modify Input**: Preserve original user message
|
|
3. **Append Only**: Add system-reminders at the end
|
|
4. **Synchronous**: Use require() instead of import()
|
|
|
|
## Implementation
|
|
|
|
```typescript
|
|
// Simple pattern matching
|
|
const mentions = input.match(/@[\w\-\.\/]+/g) || []
|
|
|
|
// Generate reminders without modifying input
|
|
for (const mention of mentions) {
|
|
// Simple agent detection
|
|
if (isLikelyAgent(name)) {
|
|
reminders.push(agentReminder)
|
|
} else if (existsSync(filePath)) {
|
|
reminders.push(fileReminder)
|
|
}
|
|
}
|
|
|
|
// Append reminders to message
|
|
processedInput = processedInput + '\n\n' + reminders.join('\n')
|
|
```
|
|
|
|
## How It Works
|
|
|
|
### For @file mentions:
|
|
- User types: `@improvements_summary.md`
|
|
- System adds reminder: "You should read the file at: /path/to/improvements_summary.md"
|
|
- AI sees the reminder and uses Read tool
|
|
- Agent loop continues normally
|
|
|
|
### For @agent mentions:
|
|
- User types: `@code-reviewer`
|
|
- System adds reminder: "Consider using the Task tool with subagent_type='code-reviewer'"
|
|
- AI sees the reminder and may invoke the agent
|
|
- Agent loop continues normally
|
|
|
|
## Why This Works
|
|
|
|
1. **No Flow Interruption**: Synchronous execution preserves message flow
|
|
2. **Original Input Intact**: User's message isn't modified
|
|
3. **Simple Logic**: No complex async imports or checks
|
|
4. **Agent Loop Safe**: Messages flow through without breaking
|
|
|
|
## Difference from Previous Approach
|
|
|
|
### Previous (Broken):
|
|
- Complex async operations
|
|
- Modified user input (removed @mentions)
|
|
- Multiple async imports
|
|
- 70+ lines of complex logic
|
|
- Broke agent loop
|
|
|
|
### Current (Working):
|
|
- Simple synchronous checks
|
|
- Preserves user input
|
|
- Uses require() not import()
|
|
- ~40 lines of simple logic
|
|
- Agent loop works properly
|
|
|
|
## Testing
|
|
|
|
You can test with:
|
|
- `@improvements_summary.md summarize this` - should read file
|
|
- `@code-reviewer check my code` - should suggest agent
|
|
- `@src/commands.ts explain this` - should handle paths
|
|
|
|
The agent should continue executing multiple rounds without interruption. |