MCPcopy Create free account
hub / github.com/Noumena-Network/code / getFilesUsingSapling

Function getFilesUsingSapling

src/hooks/fileSuggestions.ts:385–444  ·  view source on GitHub ↗
(
  abortSignal: AbortSignal,
)

Source from the content-addressed store, hash-verified

383}
384
385async function getFilesUsingSapling(
386 abortSignal: AbortSignal,
387): Promise<string[] | null> {
388 const startTime = Date.now()
389 const cwd = getCwd()
390 logForDebugging(`[FileIndex] getFilesUsingSapling called`)
391
392 const rootResult = await execFileNoThrowWithCwd('sl', ['root'], {
393 timeout: 5000,
394 abortSignal,
395 cwd,
396 })
397 if (rootResult.code !== 0) {
398 logForDebugging(
399 `[FileIndex] sl root failed (code=${rootResult.code}), falling back`,
400 )
401 return null
402 }
403
404 const repoRoot = rootResult.stdout.trim()
405 if (!repoRoot) {
406 return null
407 }
408
409 const filesResult = await execFileNoThrowWithCwd(
410 'sl',
411 ['files', '--print0'],
412 {
413 timeout: 10000,
414 abortSignal,
415 cwd: repoRoot,
416 },
417 )
418 if (filesResult.code !== 0) {
419 logForDebugging(
420 `[FileIndex] sl files failed (code=${filesResult.code}, stderr=${filesResult.stderr}), falling back`,
421 )
422 return null
423 }
424
425 const files = filesResult.stdout
426 .split('\0')
427 .map(file => file.trim())
428 .filter(Boolean)
429 .map(file => path.relative(cwd, path.join(repoRoot, file)))
430 .filter(file => file.length > 0 && file !== '.')
431
432 const duration = Date.now() - startTime
433 logForDebugging(
434 `[FileIndex] sl files: ${files.length} tracked files in ${duration}ms`,
435 )
436 logEvent('ncode_file_suggestions_sl_files', {
437 file_count: files.length,
438 tracked_count: files.length,
439 duration_ms: duration,
440 })
441
442 cachedTrackedFiles = files

Calls 4

getCwdFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
logForDebuggingFunction · 0.50
logEventFunction · 0.50

Tested by

no test coverage detected