MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / loadSourceWithinLimits

Function loadSourceWithinLimits

packages/code-map/src/parse.ts:237–262  ·  view source on GitHub ↗
(params: {
  filePath: string
  readFile?: (filePath: string) => string | null
  maxBytes: number
  remainingBytes: number
})

Source from the content-addressed store, hash-verified

235}
236
237function loadSourceWithinLimits(params: {
238 filePath: string
239 readFile?: (filePath: string) => string | null
240 maxBytes: number
241 remainingBytes: number
242}): { code: string; bytes: number } | null {
243 const { filePath, readFile, maxBytes, remainingBytes } = params
244
245 if (!readFile) {
246 const bytes = fs.statSync(filePath).size
247 if (bytes > maxBytes || bytes > remainingBytes) return null
248
249 return {
250 code: fs.readFileSync(filePath, 'utf8'),
251 bytes,
252 }
253 }
254
255 const code = readFile(filePath)
256 if (code === null) return null
257
258 const bytes = Buffer.byteLength(code, 'utf8')
259 if (bytes > maxBytes || bytes > remainingBytes) return null
260
261 return { code, bytes }
262}
263
264function scoreFileTokens(fullPath: string, parsed: ParsedTokens): FileCallData {
265 const scores: Record<string, number> = {}

Callers 1

parseTokensWithLimitsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected