(messages)
| 2028 | // from the project's knowledge/ directory based on keyword overlap with the |
| 2029 | // last user message. Disabled if the directory doesn't exist. |
| 2030 | function getKnowledgeContext(messages) { |
| 2031 | try { |
| 2032 | const lastUser = [...messages].reverse().find(m => m.role === 'user'); |
| 2033 | if (!lastUser || typeof lastUser.content !== 'string') return ''; |
| 2034 | const loader = _knowledgeLoader; |
| 2035 | if (!loader) return ''; |
| 2036 | const maxTokens = Math.min(1500, Math.floor(((config?.context?.detected_window || 32768) * 0.04))); |
| 2037 | return loader.formatForPrompt(lastUser.content, { maxTokens }); |
| 2038 | } catch { |
| 2039 | return ''; |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 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. |
no test coverage detected