- 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.6 KiB
3.6 KiB
@mention Feature Demo & Test Cases
How to Test the Implementation
Test 1: Agent Mention
# In the CLI, type:
"Please review my code architecture with @agent-simplicity-auditor"
# Expected behavior:
# 1. System reminder injected: "You MUST use the Task tool with subagent_type='simplicity-auditor'..."
# 2. LLM will call Task tool with the simplicity-auditor agent
# 3. Agent will execute the review task
Test 2: File Mention
# In the CLI, type:
"Explain the query flow in @src/query.ts"
# Expected behavior:
# 1. System reminder injected: "You MUST read the entire content of the file at path: src/query.ts..."
# 2. LLM will call Read tool to read src/query.ts
# 3. LLM will then explain the query flow based on file content
Test 3: Multiple Mentions
# In the CLI, type:
"Have @agent-test-writer create tests for @src/utils/messages.tsx"
# Expected behavior:
# 1. Two system reminders injected
# 2. LLM will first read src/utils/messages.tsx
# 3. LLM will then use Task tool with test-writer agent
# 4. Test writer agent will create tests for the file
Test 4: Invalid Mentions (Should be Ignored)
# In the CLI, type:
"Use @agent-nonexistent to analyze @fake-file.txt"
# Expected behavior:
# 1. No system reminders generated (invalid agent and non-existent file)
# 2. LLM sees the original text but no special instructions
# 3. LLM will likely respond that it cannot find these resources
Internal Flow Trace
When you type: "Review @src/query.ts"
- messages.tsx:373:
processMentions("Review @src/query.ts")called - mentionProcessor.ts:91: File exists check for
src/query.ts✓ - mentionProcessor.ts:101: Event emitted:
'file:mentioned' - systemReminder.ts:404: Event listener triggered
- systemReminder.ts:412: Reminder created with text:
The user mentioned @src/query.ts. You MUST read the entire content of the file at path: /full/path/src/query.ts using the Read tool... - systemReminder.ts:420: Reminder cached with key
file_mention_/full/path/src/query.ts_[timestamp] - query.ts:185:
formatSystemPromptWithContextcalled - claude.ts:1155:
generateSystemReminderscalled - systemReminder.ts:85:
getMentionReminders()called - systemReminder.ts:243: Reminder retrieved (within 5-second window)
- query.ts:206: Reminder injected into user message
- LLM receives: Original text + system reminder instruction
- LLM response: Calls Read tool to read the file
Debugging
To verify the system is working:
-
Check if mentions are detected:
- Add a console.log in
mentionProcessor.tsline 74 and 103
- Add a console.log in
-
Check if events are emitted:
- Add a console.log in
systemReminder.tsline 388 and 409
- Add a console.log in
-
Check if reminders are generated:
- Add a console.log in
systemReminder.tsline 245
- Add a console.log in
-
Check if reminders are injected:
- Add a console.log in
query.tsline 206
- Add a console.log in
Configuration
The system has these configurable parameters:
- Cache TTL: 60 seconds (agent list cache in mentionProcessor.ts:34)
- Freshness Window: 5 seconds (mention reminders in systemReminder.ts:236)
- Reminder Priority: 'high' for both agent and file mentions
- Max Reminders: 5 per session (systemReminder.ts:89)
Benefits
- Natural syntax: Users can mention agents and files naturally
- Clear instructions: LLM receives explicit guidance
- No content embedding: Files are read on-demand, not embedded
- Smart validation: Only valid agents and existing files trigger actions
- Event-driven: Clean architecture with proper separation of concerns