@@ -42,7 +42,7 @@ This document outlines a prioritized refactoring plan for the 51 issues identifi
4242| 2.9 | Refactor doStream | ✅ Complete | Codebuff |
4343| 2.10 | DRY up OpenRouter stream handling | ⏭️ Skipped | - |
4444| 2.11 | Consolidate image handling | ✅ Not Needed | - |
45- | 2.12 | Refactor suggestion-engine | ⬜ Not Started | - |
45+ | 2.12 | Refactor suggestion-engine | ✅ Complete | Codebuff |
4646| 2.13 | Fix browser actions + string utils | ⬜ Not Started | - |
4747| 2.14 | Refactor agent-builder.ts | ⬜ Not Started | - |
4848| 2.15 | Refactor promptAiSdkStream | ⬜ Not Started | - |
@@ -937,19 +937,58 @@ No duplication found. Architecture follows single responsibility principle.
937937
938938---
939939
940- ### Commit 2.12: Refactor ` use-suggestion-engine.ts `
940+ ### Commit 2.12: Refactor ` use-suggestion-engine.ts ` ✅ COMPLETE
941941** Files:** ` cli/src/hooks/use-suggestion-engine.ts `
942942** Est. Time:** 2-3 hours
943- ** Est. LOC Changed:** ~ 350-450
943+ ** Actual Time:** ~ 1.5 hours
944+ ** Est. LOC Changed:** ~ 350-450
945+ ** Actual LOC Changed:** ~ 450 lines extracted (130 parsing + 320 filtering)
944946
945- | Task | Description |
946- | ------| -------------|
947- | Extract ` useSuggestionCache ` hook | Caching logic |
948- | Extract ` useSuggestionRanking ` hook | Ranking algorithms |
949- | Extract ` useSuggestionFiltering ` hook | Filter logic |
950- | Compose in main hook | Wire up |
947+ > ** Note:** Plan originally called for extracting hooks (` useSuggestionCache ` , etc.), but pure utility modules were more appropriate since the logic is stateless.
948+
949+ | Task | Description | Status |
950+ | ------| -------------| --------|
951+ | Create ` suggestion-parsing.ts ` | Parsing functions: parseSlashContext, parseMentionContext, isInsideStringDelimiters, parseAtInLine | ✅ |
952+ | Create ` suggestion-filtering.ts ` | Filtering functions: filterSlashCommands, filterAgentMatches, filterFileMatches, helpers | ✅ |
953+ | Update main hook | Import from extracted modules, re-export types for consumers | ✅ |
954+ | Run tests | 100 suggestion engine tests pass, 1902 CLI tests pass | ✅ |
955+ | Multi-agent review | Code-reviewer-multi-prompt reviewed extraction boundaries | ✅ |
951956
952- ** Dependencies:** None (can run in parallel with 2.11)
957+ ** New Files Created:**
958+ - ` cli/src/utils/suggestion-parsing.ts ` (~ 130 lines) - Parsing utilities:
959+ - ` TriggerContext ` interface - trigger state for slash/mention
960+ - ` parseSlashContext() ` - parse ` /command ` triggers
961+ - ` parseMentionContext() ` - parse ` @mention ` triggers
962+ - ` isInsideStringDelimiters() ` - check if position is in quotes
963+ - ` parseAtInLine() ` - parse @ in a single line
964+ - ` cli/src/utils/suggestion-filtering.ts ` (~ 320 lines) - Filtering utilities:
965+ - ` MatchedSlashCommand ` , ` MatchedAgentInfo ` , ` MatchedFileInfo ` types
966+ - ` filterSlashCommands() ` - filter/rank slash commands with highlighting
967+ - ` filterAgentMatches() ` - filter/rank agents with highlighting
968+ - ` filterFileMatches() ` - filter/rank files with path-segment matching
969+ - ` flattenFileTree() ` , ` getFileName() ` - file tree helpers
970+ - ` createHighlightIndices() ` , ` createPushUnique() ` - internal helpers
971+
972+ ** Hook Size Reduction:**
973+ - ` use-suggestion-engine.ts ` : ~ 751 → ~ 220 lines (-71%)
974+
975+ ** Architecture Decision:**
976+ Extracted pure utility modules instead of React hooks (as originally planned) because:
977+ 1 . Parsing and filtering logic is stateless - no React dependencies
978+ 2 . Pure functions are easier to test in isolation
979+ 3 . Better separation of concerns: hook manages React state/effects, utilities do computation
980+
981+ ** Review Findings:**
982+ - ✅ Extraction boundaries well-chosen (parsing vs filtering vs hook)
983+ - ✅ Types properly re-exported for backward compatibility
984+ - ⚠️ Fixed: Import path ` ../utils/local-agent-registry ` → ` ./local-agent-registry `
985+
986+ ** Test Results:**
987+ - 100 suggestion engine tests pass
988+ - 1902 CLI tests pass
989+ - TypeScript compiles cleanly
990+
991+ ** Dependencies:** None
953992** Risk:** Low
954993** Rollback:** Revert single commit
955994
0 commit comments