MCPcopy
hub / github.com/Doorman11991/smallcode / getKnowledgeContext

Function getKnowledgeContext

bin/smallcode.js:2030–2041  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

2028// from the project's knowledge/ directory based on keyword overlap with the
2029// last user message. Disabled if the directory doesn't exist.
2030function 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.

Callers 2

buildCompactSystemPromptFunction · 0.85
buildDynamicContextFunction · 0.85

Calls 1

formatForPromptMethod · 0.45

Tested by

no test coverage detected