open-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.
package/dist/index.cjs CHANGED
@@ -9046,6 +9046,29 @@ function extractPrimaryIdentifierQueryHint(query) {
9046
9046
  const best = codeTerms.find((term) => term.length >= 6);
9047
9047
  return best ?? null;
9048
9048
  }
9049
+ function pathSegmentsForAffinityMatch(filePath) {
9050
+ const normalizedPath2 = normalizeRankingText(filePath).replace(/\\/g, "/");
9051
+ const segments = normalizedPath2.split("/").filter((segment) => segment.length > 0);
9052
+ if (segments.length === 0) {
9053
+ return [];
9054
+ }
9055
+ const basename9 = segments[segments.length - 1] ?? "";
9056
+ const basenameWithoutExt = basename9.replace(/\.[^/.]+$/u, "");
9057
+ const normalizedSegments = segments.map((segment) => segment.toLowerCase());
9058
+ return Array.from(/* @__PURE__ */ new Set([
9059
+ ...normalizedSegments,
9060
+ basenameWithoutExt.toLowerCase()
9061
+ ]));
9062
+ }
9063
+ function hasModuleAffinity(filePath, exactIdentifierVariants) {
9064
+ const haystack = pathSegmentsForAffinityMatch(filePath);
9065
+ return exactIdentifierVariants.some((variant) => {
9066
+ if (!variant || variant.length < 2) {
9067
+ return false;
9068
+ }
9069
+ return haystack.includes(variant);
9070
+ });
9071
+ }
9049
9072
  var FILE_PATH_HINT_EXTENSIONS = [
9050
9073
  "ts",
9051
9074
  "tsx",
@@ -9121,10 +9144,13 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
9121
9144
  ).map((candidate) => {
9122
9145
  const nameLower = (candidate.metadata.name ?? "").toLowerCase();
9123
9146
  const pathLower = candidate.metadata.filePath.toLowerCase();
9124
- let maxMatch = 0;
9125
- const nameMatchesPrimary = primaryVariants.some(
9147
+ const exactIdentifierVariants = primaryVariants.filter((value) => value.length >= 2);
9148
+ const exactMatch = exactIdentifierVariants.some(
9126
9149
  (variant) => nameLower === variant || nameLower.replace(/[^a-z0-9]/g, "") === variant.replace(/[^a-z0-9]/g, "")
9127
9150
  );
9151
+ let maxMatch = 0;
9152
+ const nameMatchesPrimary = exactMatch;
9153
+ const pathAffinity = exactMatch ? hasModuleAffinity(candidate.metadata.filePath, exactIdentifierVariants) : false;
9128
9154
  const pathMatchesFileHint = filePathHint ? pathMatchesHint(candidate.metadata.filePath, filePathHint) : false;
9129
9155
  for (const hint of hints) {
9130
9156
  const variants = normalizeIdentifierVariants(hint);
@@ -9145,12 +9171,17 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
9145
9171
  candidate,
9146
9172
  maxMatch,
9147
9173
  pathMatchesFileHint,
9148
- nameMatchesPrimary
9174
+ nameMatchesPrimary,
9175
+ pathAffinity
9149
9176
  };
9150
9177
  }).filter((entry) => entry.maxMatch >= 0.7).sort((a, b) => {
9151
9178
  const aAnchored = a.pathMatchesFileHint && a.nameMatchesPrimary ? 1 : 0;
9152
9179
  const bAnchored = b.pathMatchesFileHint && b.nameMatchesPrimary ? 1 : 0;
9153
9180
  if (aAnchored !== bAnchored) return bAnchored - aAnchored;
9181
+ if (a.nameMatchesPrimary !== b.nameMatchesPrimary) {
9182
+ return b.nameMatchesPrimary ? 1 : -1;
9183
+ }
9184
+ if (a.pathAffinity !== b.pathAffinity) return b.pathAffinity ? 1 : -1;
9154
9185
  if (b.maxMatch !== a.maxMatch) return b.maxMatch - a.maxMatch;
9155
9186
  if (b.candidate.score !== a.candidate.score) return b.candidate.score - a.candidate.score;
9156
9187
  return a.candidate.id.localeCompare(b.candidate.id);