(messages)
| 2043 | // Auto-load similar code snippets from the local RAG index. The index is |
| 2044 | // created with `npm run rag:index` / `smallcode-rag-index` and stays fully local. |
| 2045 | function getRagContext(messages) { |
| 2046 | try { |
| 2047 | if (!_ragRetriever) return ''; |
| 2048 | const lastUser = [...messages].reverse().find(m => m.role === 'user'); |
| 2049 | if (!lastUser || typeof lastUser.content !== 'string') return ''; |
| 2050 | const maxChars = Math.min(6000, Math.floor(((config?.context?.detected_window || 32768) * 0.06) * 4)); |
| 2051 | return _ragRetriever.formatForPrompt(lastUser.content, { limit: 6, maxChars }); |
| 2052 | } catch { |
| 2053 | return ''; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | // Auto-load relevant memory for the current task (injected into system prompt) |
| 2058 | // Fix #15: Only inject memory objects with score >= 2 (at least 2 word matches) |
no test coverage detected