opencode-codebase-index 0.22.4 → 0.22.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9008,6 +9008,29 @@ function extractPrimaryIdentifierQueryHint(query) {
9008
9008
  const best = codeTerms.find((term) => term.length >= 6);
9009
9009
  return best ?? null;
9010
9010
  }
9011
+ function pathSegmentsForAffinityMatch(filePath) {
9012
+ const normalizedPath2 = normalizeRankingText(filePath).replace(/\\/g, "/");
9013
+ const segments = normalizedPath2.split("/").filter((segment) => segment.length > 0);
9014
+ if (segments.length === 0) {
9015
+ return [];
9016
+ }
9017
+ const basename5 = segments[segments.length - 1] ?? "";
9018
+ const basenameWithoutExt = basename5.replace(/\.[^/.]+$/u, "");
9019
+ const normalizedSegments = segments.map((segment) => segment.toLowerCase());
9020
+ return Array.from(/* @__PURE__ */ new Set([
9021
+ ...normalizedSegments,
9022
+ basenameWithoutExt.toLowerCase()
9023
+ ]));
9024
+ }
9025
+ function hasModuleAffinity(filePath, exactIdentifierVariants) {
9026
+ const haystack = pathSegmentsForAffinityMatch(filePath);
9027
+ return exactIdentifierVariants.some((variant) => {
9028
+ if (!variant || variant.length < 2) {
9029
+ return false;
9030
+ }
9031
+ return haystack.includes(variant);
9032
+ });
9033
+ }
9011
9034
  var FILE_PATH_HINT_EXTENSIONS = [
9012
9035
  "ts",
9013
9036
  "tsx",
@@ -9083,10 +9106,13 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
9083
9106
  ).map((candidate) => {
9084
9107
  const nameLower = (candidate.metadata.name ?? "").toLowerCase();
9085
9108
  const pathLower = candidate.metadata.filePath.toLowerCase();
9086
- let maxMatch = 0;
9087
- const nameMatchesPrimary = primaryVariants.some(
9109
+ const exactIdentifierVariants = primaryVariants.filter((value) => value.length >= 2);
9110
+ const exactMatch = exactIdentifierVariants.some(
9088
9111
  (variant) => nameLower === variant || nameLower.replace(/[^a-z0-9]/g, "") === variant.replace(/[^a-z0-9]/g, "")
9089
9112
  );
9113
+ let maxMatch = 0;
9114
+ const nameMatchesPrimary = exactMatch;
9115
+ const pathAffinity = exactMatch ? hasModuleAffinity(candidate.metadata.filePath, exactIdentifierVariants) : false;
9090
9116
  const pathMatchesFileHint = filePathHint ? pathMatchesHint(candidate.metadata.filePath, filePathHint) : false;
9091
9117
  for (const hint of hints) {
9092
9118
  const variants = normalizeIdentifierVariants(hint);
@@ -9107,12 +9133,17 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
9107
9133
  candidate,
9108
9134
  maxMatch,
9109
9135
  pathMatchesFileHint,
9110
- nameMatchesPrimary
9136
+ nameMatchesPrimary,
9137
+ pathAffinity
9111
9138
  };
9112
9139
  }).filter((entry) => entry.maxMatch >= 0.7).sort((a, b) => {
9113
9140
  const aAnchored = a.pathMatchesFileHint && a.nameMatchesPrimary ? 1 : 0;
9114
9141
  const bAnchored = b.pathMatchesFileHint && b.nameMatchesPrimary ? 1 : 0;
9115
9142
  if (aAnchored !== bAnchored) return bAnchored - aAnchored;
9143
+ if (a.nameMatchesPrimary !== b.nameMatchesPrimary) {
9144
+ return b.nameMatchesPrimary ? 1 : -1;
9145
+ }
9146
+ if (a.pathAffinity !== b.pathAffinity) return b.pathAffinity ? 1 : -1;
9116
9147
  if (b.maxMatch !== a.maxMatch) return b.maxMatch - a.maxMatch;
9117
9148
  if (b.candidate.score !== a.candidate.score) return b.candidate.score - a.candidate.score;
9118
9149
  return a.candidate.id.localeCompare(b.candidate.id);