MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / repairReferences

Function repairReferences

packages/web/src/features/chat/utils.ts:380–398  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

378
379// LLMs like to not follow instructions... this takes care of some common mistakes they tend to make.
380export const repairReferences = (text: string): string => {
381 return text
382 // Fix missing colon: @file{...} -> @file:{...}
383 .replace(/@file\{([^}]+)\}/g, '@file:{$1}')
384 // Fix missing braces: @file:filename -> @file:{filename}
385 .replace(/@file:([^\s{]\S*?)(\s|[,;!?](?:\s|$)|\.(?:\s|$)|$)/g, '@file:{$1}$2')
386 // Fix multiple ranges: keep only first range
387 .replace(/@file:\{(.+?):(\d+-\d+),[\d,-]+\}/g, '@file:{$1:$2}')
388 // Fix malformed ranges
389 .replace(/@file:\{(.+?):(\d+)-(\d+)-(\d+)\}/g, '@file:{$1:$2-$3}')
390 // Fix extra closing parenthesis: @file:{...)} -> @file:{...}
391 .replace(/@file:\{([^}]+)\)\}/g, '@file:{$1}')
392 // Fix extra colon at end: @file:{...range:} -> @file:{...range}
393 .replace(/@file:\{(.+?):(\d+(?:-\d+)?):?\}/g, '@file:{$1:$2}')
394 // Fix inline code blocks around file references: `@file:{...}` -> @file:{...}
395 .replace(/`(@file:\{[^}]+\})`/g, '$1')
396 // Fix malformed inline code blocks: `@file:{...`} -> @file:{...}
397 .replace(/`(@file:\{[^`]+)`\}/g, '$1}');
398};
399
400// Attempts to find the part of the assistant's message
401// that contains the answer.

Callers 2

utils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected