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/cli.js CHANGED
@@ -7052,6 +7052,29 @@ function extractPrimaryIdentifierQueryHint(query) {
7052
7052
  const best = codeTerms.find((term) => term.length >= 6);
7053
7053
  return best ?? null;
7054
7054
  }
7055
+ function pathSegmentsForAffinityMatch(filePath) {
7056
+ const normalizedPath3 = normalizeRankingText(filePath).replace(/\\/g, "/");
7057
+ const segments = normalizedPath3.split("/").filter((segment) => segment.length > 0);
7058
+ if (segments.length === 0) {
7059
+ return [];
7060
+ }
7061
+ const basename8 = segments[segments.length - 1] ?? "";
7062
+ const basenameWithoutExt = basename8.replace(/\.[^/.]+$/u, "");
7063
+ const normalizedSegments = segments.map((segment) => segment.toLowerCase());
7064
+ return Array.from(/* @__PURE__ */ new Set([
7065
+ ...normalizedSegments,
7066
+ basenameWithoutExt.toLowerCase()
7067
+ ]));
7068
+ }
7069
+ function hasModuleAffinity(filePath, exactIdentifierVariants) {
7070
+ const haystack = pathSegmentsForAffinityMatch(filePath);
7071
+ return exactIdentifierVariants.some((variant) => {
7072
+ if (!variant || variant.length < 2) {
7073
+ return false;
7074
+ }
7075
+ return haystack.includes(variant);
7076
+ });
7077
+ }
7055
7078
  var FILE_PATH_HINT_EXTENSIONS = [
7056
7079
  "ts",
7057
7080
  "tsx",
@@ -7127,10 +7150,13 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
7127
7150
  ).map((candidate) => {
7128
7151
  const nameLower = (candidate.metadata.name ?? "").toLowerCase();
7129
7152
  const pathLower = candidate.metadata.filePath.toLowerCase();
7130
- let maxMatch = 0;
7131
- const nameMatchesPrimary = primaryVariants.some(
7153
+ const exactIdentifierVariants = primaryVariants.filter((value) => value.length >= 2);
7154
+ const exactMatch = exactIdentifierVariants.some(
7132
7155
  (variant) => nameLower === variant || nameLower.replace(/[^a-z0-9]/g, "") === variant.replace(/[^a-z0-9]/g, "")
7133
7156
  );
7157
+ let maxMatch = 0;
7158
+ const nameMatchesPrimary = exactMatch;
7159
+ const pathAffinity = exactMatch ? hasModuleAffinity(candidate.metadata.filePath, exactIdentifierVariants) : false;
7134
7160
  const pathMatchesFileHint = filePathHint ? pathMatchesHint(candidate.metadata.filePath, filePathHint) : false;
7135
7161
  for (const hint of hints) {
7136
7162
  const variants = normalizeIdentifierVariants(hint);
@@ -7151,12 +7177,17 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
7151
7177
  candidate,
7152
7178
  maxMatch,
7153
7179
  pathMatchesFileHint,
7154
- nameMatchesPrimary
7180
+ nameMatchesPrimary,
7181
+ pathAffinity
7155
7182
  };
7156
7183
  }).filter((entry) => entry.maxMatch >= 0.7).sort((a, b) => {
7157
7184
  const aAnchored = a.pathMatchesFileHint && a.nameMatchesPrimary ? 1 : 0;
7158
7185
  const bAnchored = b.pathMatchesFileHint && b.nameMatchesPrimary ? 1 : 0;
7159
7186
  if (aAnchored !== bAnchored) return bAnchored - aAnchored;
7187
+ if (a.nameMatchesPrimary !== b.nameMatchesPrimary) {
7188
+ return b.nameMatchesPrimary ? 1 : -1;
7189
+ }
7190
+ if (a.pathAffinity !== b.pathAffinity) return b.pathAffinity ? 1 : -1;
7160
7191
  if (b.maxMatch !== a.maxMatch) return b.maxMatch - a.maxMatch;
7161
7192
  if (b.candidate.score !== a.candidate.score) return b.candidate.score - a.candidate.score;
7162
7193
  return a.candidate.id.localeCompare(b.candidate.id);