Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

942 B
Raw Blame
import type { SearchFileResult, SearchResult } from './code-search-types'

function isValidMatchCount(value: unknown): value is number {
  return (
    typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value >= 0
  )
}

export function normalizeSearchFileMatchCount(
  fileResult: Pick<SearchFileResult, 'matches' | 'matchCount'>
): number {
  const matchCount = isValidMatchCount(fileResult.matchCount) ? fileResult.matchCount : 0
  return Math.max(matchCount, fileResult.matches.length)
}

export function normalizeSearchFileResult(fileResult: SearchFileResult): SearchFileResult {
  return {
    ...fileResult,
    matchCount: normalizeSearchFileMatchCount(fileResult)
  }
}

export function normalizeSearchResult(result: SearchResult): SearchResult {
  return {
    ...result,
    files: result.files
      .filter((fileResult) => fileResult.matches.length > 0)
      .map(normalizeSearchFileResult)
  }
}