MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / normalize

Function normalize

graph-ui/src/browser-ai/question-intent.ts:88–101  ·  view source on GitHub ↗

The prompt in lower case, words corrected, the selection's name as ` `.

(prompt: string, names: readonly string[])

Source from the content-addressed store, hash-verified

86
87/** The prompt in lower case, words corrected, the selection's name as `<name>`. */
88function normalize(prompt: string, names: readonly string[]): string {
89 const own = names.flatMap(name => [name, name.split(/[./:]/).filter(Boolean).pop() ?? name]).map(name => name.toLowerCase()).filter(Boolean);
90 const text = prompt.toLowerCase().replace(/[’`"]/g, "'").replace(/\bwhat'?s\b/g, 'what is').replace(/'/g, ' ')
91 .replace(/[?!,;:()]+/g, ' ').replace(/\.+(?=\s|$)/g, ' ');
92 return text.split(/\s+/).filter(Boolean).map(word => {
93 if (own.includes(word) || own.includes(word.split(/[.:]/).pop()!)) return '<name>';
94 const spelled = SPELLED[word] ?? word;
95 if (OWN.has(spelled)) return spelled;
96 if (own.some(name => name.length >= 4 && withinEdits(word, name, typoBudget(name)))) return '<name>';
97 if (spelled.length < 4) return spelled;
98 return VOCABULARY.find(candidate => withinEdits(spelled, candidate, 1))
99 ?? VIEW_VOCABULARY.find(candidate => withinEdits(spelled, candidate, candidate.length >= 9 ? 2 : 1)) ?? spelled;
100 }).join(' ');
101}
102
103/** "general" for a short general question about the selection or the open file, "detail" for the
104 * same question asking for detail, undefined for any other prompt. `names` are the selection's. */

Callers 4

generalQuestionFunction · 0.70
viewQuestionFunction · 0.70
startStaticProxyFunction · 0.50
safeJoinFunction · 0.50

Calls 2

withinEditsFunction · 0.90
typoBudgetFunction · 0.90

Tested by

no test coverage detected