MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / selectInjectedFacts

Function selectInjectedFacts

src/context/memory-select.ts:52–70  ·  view source on GitHub ↗
(facts: string[], opts: MemorySelectOptions = {})

Source from the content-addressed store, hash-verified

50 * newest others until the token budget is exhausted — preserving the input order.
51 */
52export function selectInjectedFacts(facts: string[], opts: MemorySelectOptions = {}): string[] {
53 if (opts.mode !== 'lightweight') return facts;
54 const budget = opts.injectMaxTokens ?? 2000;
55 const out: string[] = [];
56 let spent = 0;
57 // Important facts are always in and don't draw from the budget.
58 for (const f of facts) if (isImportantFact(f)) out.push(f);
59 // Fill the rest newest-first until the budget runs out, keeping the original ordering in the result.
60 const kept = new Set(out);
61 const filler: string[] = [];
62 for (const f of facts) {
63 if (kept.has(f)) continue;
64 const cost = estimateTokens(f);
65 if (spent + cost > budget) continue;
66 spent += cost; filler.push(f); kept.add(f);
67 }
68 // Return in the original (newest-first) order, important + budgeted-filler interleaved as they appeared.
69 return facts.filter(f => kept.has(f));
70}

Callers 2

buildInitialMessagesMethod · 0.85

Calls 5

isImportantFactFunction · 0.85
addMethod · 0.80
estimateTokensFunction · 0.70
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected