opencode-codebase-index 0.22.4 → 0.23.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/dist/cli.cjs +983 -482
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +984 -483
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +888 -398
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +889 -399
- package/dist/index.js.map +1 -1
- package/dist/pi-extension.cjs +40 -98
- package/dist/pi-extension.cjs.map +1 -1
- package/dist/pi-extension.js +40 -98
- package/dist/pi-extension.js.map +1 -1
- package/native/codebase-index-native.darwin-arm64.node +0 -0
- package/native/codebase-index-native.darwin-x64.node +0 -0
- package/native/codebase-index-native.linux-arm64-gnu.node +0 -0
- package/native/codebase-index-native.linux-x64-gnu.node +0 -0
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +3 -1
package/dist/pi-extension.js
CHANGED
|
@@ -2330,7 +2330,7 @@ function analyzeQueryIntent(query) {
|
|
|
2330
2330
|
}
|
|
2331
2331
|
function isTestPath(filePath) {
|
|
2332
2332
|
const normalized = normalizePath(filePath);
|
|
2333
|
-
return /(?:^|\/)(?:test|tests|__tests__|spec|specs)(?:\/|$)/u.test(normalized) ||
|
|
2333
|
+
return /(?:^|\/)(?:test|tests|__tests__|spec|specs)(?:\/|$)/u.test(normalized) || /(?:\.(?:test|spec)|_(?:test|spec))\.[^/]+$/u.test(normalized) || /(?:^|\/)(?:test|spec)_[^/]+\.[^/]+$/u.test(normalized);
|
|
2334
2334
|
}
|
|
2335
2335
|
function isFixturePath(filePath) {
|
|
2336
2336
|
const normalized = normalizePath(filePath);
|
|
@@ -6430,85 +6430,6 @@ function createEmbeddingProvider(configuredProviderInfo) {
|
|
|
6430
6430
|
}
|
|
6431
6431
|
}
|
|
6432
6432
|
|
|
6433
|
-
// src/rerank/index.ts
|
|
6434
|
-
function createReranker(config) {
|
|
6435
|
-
if (!config.enabled) {
|
|
6436
|
-
return new NoOpReranker();
|
|
6437
|
-
}
|
|
6438
|
-
return new SiliconFlowReranker(config);
|
|
6439
|
-
}
|
|
6440
|
-
var NoOpReranker = class {
|
|
6441
|
-
isAvailable() {
|
|
6442
|
-
return false;
|
|
6443
|
-
}
|
|
6444
|
-
async rerank(_query, documents, _topN) {
|
|
6445
|
-
return {
|
|
6446
|
-
results: documents.map((_, index) => ({ index, relevanceScore: 0 }))
|
|
6447
|
-
};
|
|
6448
|
-
}
|
|
6449
|
-
};
|
|
6450
|
-
var SiliconFlowReranker = class {
|
|
6451
|
-
config;
|
|
6452
|
-
constructor(config) {
|
|
6453
|
-
this.config = config;
|
|
6454
|
-
}
|
|
6455
|
-
isAvailable() {
|
|
6456
|
-
return this.config.enabled && !!this.config.baseUrl && !!this.config.model;
|
|
6457
|
-
}
|
|
6458
|
-
async rerank(query, documents, topN) {
|
|
6459
|
-
if (documents.length === 0) {
|
|
6460
|
-
return { results: [] };
|
|
6461
|
-
}
|
|
6462
|
-
const headers = {
|
|
6463
|
-
"Content-Type": "application/json"
|
|
6464
|
-
};
|
|
6465
|
-
if (this.config.apiKey) {
|
|
6466
|
-
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
6467
|
-
}
|
|
6468
|
-
const baseUrl = this.config.baseUrl;
|
|
6469
|
-
if (!baseUrl) {
|
|
6470
|
-
throw new Error("Reranker baseUrl is required. Configure reranker.baseUrl in your codebase-index.json.");
|
|
6471
|
-
}
|
|
6472
|
-
const timeoutMs = this.config.timeoutMs ?? 3e4;
|
|
6473
|
-
const controller = new AbortController();
|
|
6474
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
6475
|
-
try {
|
|
6476
|
-
const response = await fetch(`${baseUrl}/rerank`, {
|
|
6477
|
-
method: "POST",
|
|
6478
|
-
headers,
|
|
6479
|
-
body: JSON.stringify({
|
|
6480
|
-
model: this.config.model,
|
|
6481
|
-
query,
|
|
6482
|
-
documents,
|
|
6483
|
-
top_n: topN ?? this.config.topN ?? 20,
|
|
6484
|
-
return_documents: false
|
|
6485
|
-
}),
|
|
6486
|
-
signal: controller.signal
|
|
6487
|
-
});
|
|
6488
|
-
clearTimeout(timeout);
|
|
6489
|
-
if (!response.ok) {
|
|
6490
|
-
const errorText = await response.text();
|
|
6491
|
-
throw new Error(`Rerank API error: ${response.status} - ${errorText}`);
|
|
6492
|
-
}
|
|
6493
|
-
const data = await response.json();
|
|
6494
|
-
return {
|
|
6495
|
-
results: data.results.map((r) => ({
|
|
6496
|
-
index: r.index,
|
|
6497
|
-
relevanceScore: r.relevance_score,
|
|
6498
|
-
document: r.document?.text
|
|
6499
|
-
})),
|
|
6500
|
-
tokensUsed: data.meta?.tokens?.input_tokens
|
|
6501
|
-
};
|
|
6502
|
-
} catch (error) {
|
|
6503
|
-
clearTimeout(timeout);
|
|
6504
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
6505
|
-
throw new Error(`Rerank API request timed out after ${timeoutMs}ms`);
|
|
6506
|
-
}
|
|
6507
|
-
throw error;
|
|
6508
|
-
}
|
|
6509
|
-
}
|
|
6510
|
-
};
|
|
6511
|
-
|
|
6512
6433
|
// src/utils/logger.ts
|
|
6513
6434
|
var LOG_LEVEL_PRIORITY = {
|
|
6514
6435
|
error: 0,
|
|
@@ -8622,7 +8543,8 @@ function rankHybridResults(query, semanticResults, keywordResults, options) {
|
|
|
8622
8543
|
return cached;
|
|
8623
8544
|
}
|
|
8624
8545
|
}
|
|
8625
|
-
const
|
|
8546
|
+
const overfetchFactor = prioritizeSourcePaths ? 12 : 4;
|
|
8547
|
+
const overfetchLimit = Math.max(options.limit * overfetchFactor, options.limit);
|
|
8626
8548
|
const fused = options.fusionStrategy === "rrf" ? fuseResultsRrf(semanticResults, keywordResults, options.rrfK, overfetchLimit) : fuseResultsWeighted(semanticResults, keywordResults, options.hybridWeight, overfetchLimit);
|
|
8627
8549
|
const rerankPoolLimit = Math.max(overfetchLimit, options.rerankTopN * 3, options.limit * 6);
|
|
8628
8550
|
const rerankPool = fused.slice(0, rerankPoolLimit);
|
|
@@ -9008,6 +8930,29 @@ function extractPrimaryIdentifierQueryHint(query) {
|
|
|
9008
8930
|
const best = codeTerms.find((term) => term.length >= 6);
|
|
9009
8931
|
return best ?? null;
|
|
9010
8932
|
}
|
|
8933
|
+
function pathSegmentsForAffinityMatch(filePath) {
|
|
8934
|
+
const normalizedPath2 = normalizeRankingText(filePath).replace(/\\/g, "/");
|
|
8935
|
+
const segments = normalizedPath2.split("/").filter((segment) => segment.length > 0);
|
|
8936
|
+
if (segments.length === 0) {
|
|
8937
|
+
return [];
|
|
8938
|
+
}
|
|
8939
|
+
const basename5 = segments[segments.length - 1] ?? "";
|
|
8940
|
+
const basenameWithoutExt = basename5.replace(/\.[^/.]+$/u, "");
|
|
8941
|
+
const normalizedSegments = segments.map((segment) => segment.toLowerCase());
|
|
8942
|
+
return Array.from(/* @__PURE__ */ new Set([
|
|
8943
|
+
...normalizedSegments,
|
|
8944
|
+
basenameWithoutExt.toLowerCase()
|
|
8945
|
+
]));
|
|
8946
|
+
}
|
|
8947
|
+
function hasModuleAffinity(filePath, exactIdentifierVariants) {
|
|
8948
|
+
const haystack = pathSegmentsForAffinityMatch(filePath);
|
|
8949
|
+
return exactIdentifierVariants.some((variant) => {
|
|
8950
|
+
if (!variant || variant.length < 2) {
|
|
8951
|
+
return false;
|
|
8952
|
+
}
|
|
8953
|
+
return haystack.includes(variant);
|
|
8954
|
+
});
|
|
8955
|
+
}
|
|
9011
8956
|
var FILE_PATH_HINT_EXTENSIONS = [
|
|
9012
8957
|
"ts",
|
|
9013
8958
|
"tsx",
|
|
@@ -9083,10 +9028,13 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
|
|
|
9083
9028
|
).map((candidate) => {
|
|
9084
9029
|
const nameLower = (candidate.metadata.name ?? "").toLowerCase();
|
|
9085
9030
|
const pathLower = candidate.metadata.filePath.toLowerCase();
|
|
9086
|
-
|
|
9087
|
-
const
|
|
9031
|
+
const exactIdentifierVariants = primaryVariants.filter((value) => value.length >= 2);
|
|
9032
|
+
const exactMatch = exactIdentifierVariants.some(
|
|
9088
9033
|
(variant) => nameLower === variant || nameLower.replace(/[^a-z0-9]/g, "") === variant.replace(/[^a-z0-9]/g, "")
|
|
9089
9034
|
);
|
|
9035
|
+
let maxMatch = 0;
|
|
9036
|
+
const nameMatchesPrimary = exactMatch;
|
|
9037
|
+
const pathAffinity = exactMatch ? hasModuleAffinity(candidate.metadata.filePath, exactIdentifierVariants) : false;
|
|
9090
9038
|
const pathMatchesFileHint = filePathHint ? pathMatchesHint(candidate.metadata.filePath, filePathHint) : false;
|
|
9091
9039
|
for (const hint of hints) {
|
|
9092
9040
|
const variants = normalizeIdentifierVariants(hint);
|
|
@@ -9107,12 +9055,17 @@ function buildDeterministicIdentifierPass(query, candidates, limit, prioritizeSo
|
|
|
9107
9055
|
candidate,
|
|
9108
9056
|
maxMatch,
|
|
9109
9057
|
pathMatchesFileHint,
|
|
9110
|
-
nameMatchesPrimary
|
|
9058
|
+
nameMatchesPrimary,
|
|
9059
|
+
pathAffinity
|
|
9111
9060
|
};
|
|
9112
9061
|
}).filter((entry) => entry.maxMatch >= 0.7).sort((a, b) => {
|
|
9113
9062
|
const aAnchored = a.pathMatchesFileHint && a.nameMatchesPrimary ? 1 : 0;
|
|
9114
9063
|
const bAnchored = b.pathMatchesFileHint && b.nameMatchesPrimary ? 1 : 0;
|
|
9115
9064
|
if (aAnchored !== bAnchored) return bAnchored - aAnchored;
|
|
9065
|
+
if (a.nameMatchesPrimary !== b.nameMatchesPrimary) {
|
|
9066
|
+
return b.nameMatchesPrimary ? 1 : -1;
|
|
9067
|
+
}
|
|
9068
|
+
if (a.pathAffinity !== b.pathAffinity) return b.pathAffinity ? 1 : -1;
|
|
9116
9069
|
if (b.maxMatch !== a.maxMatch) return b.maxMatch - a.maxMatch;
|
|
9117
9070
|
if (b.candidate.score !== a.candidate.score) return b.candidate.score - a.candidate.score;
|
|
9118
9071
|
return a.candidate.id.localeCompare(b.candidate.id);
|
|
@@ -10102,7 +10055,6 @@ var Indexer = class _Indexer {
|
|
|
10102
10055
|
database = null;
|
|
10103
10056
|
provider = null;
|
|
10104
10057
|
configuredProviderInfo = null;
|
|
10105
|
-
reranker = null;
|
|
10106
10058
|
fileHashCache = /* @__PURE__ */ new Map();
|
|
10107
10059
|
fileHashCachePath = "";
|
|
10108
10060
|
failedBatchesPath = "";
|
|
@@ -10262,7 +10214,6 @@ var Indexer = class _Indexer {
|
|
|
10262
10214
|
this.database = null;
|
|
10263
10215
|
this.provider = null;
|
|
10264
10216
|
this.configuredProviderInfo = null;
|
|
10265
|
-
this.reranker = null;
|
|
10266
10217
|
this.indexCompatibility = null;
|
|
10267
10218
|
this.initializationMode = "none";
|
|
10268
10219
|
this.readIssues = [];
|
|
@@ -11559,15 +11510,6 @@ var Indexer = class _Indexer {
|
|
|
11559
11510
|
rerankerEnabled: this.config.reranker?.enabled ?? false
|
|
11560
11511
|
});
|
|
11561
11512
|
this.provider = createEmbeddingProvider(this.configuredProviderInfo);
|
|
11562
|
-
if (this.config.reranker?.enabled) {
|
|
11563
|
-
this.reranker = createReranker(this.config.reranker);
|
|
11564
|
-
if (this.reranker.isAvailable()) {
|
|
11565
|
-
this.logger.info("Reranker initialized", {
|
|
11566
|
-
model: this.config.reranker.model,
|
|
11567
|
-
baseUrl: this.config.reranker.baseUrl
|
|
11568
|
-
});
|
|
11569
|
-
}
|
|
11570
|
-
}
|
|
11571
11513
|
const dimensions = this.configuredProviderInfo.modelInfo.dimensions;
|
|
11572
11514
|
const storePath = path19.join(this.indexPath, "vectors");
|
|
11573
11515
|
const vectorMetadataPath = `${storePath}.meta.json`;
|
|
@@ -12972,6 +12914,7 @@ var Indexer = class _Indexer {
|
|
|
12972
12914
|
const filterByBranch = options?.filterByBranch ?? true;
|
|
12973
12915
|
const sourceIntent = options?.definitionIntent === true || classifyQueryIntentRaw(query) === "source";
|
|
12974
12916
|
const identifierHints = extractIdentifierHints(query);
|
|
12917
|
+
const candidateLimit = maxResults * (sourceIntent ? 12 : 4);
|
|
12975
12918
|
this.logger.search("debug", "Starting search", {
|
|
12976
12919
|
query,
|
|
12977
12920
|
maxResults,
|
|
@@ -13008,7 +12951,7 @@ var Indexer = class _Indexer {
|
|
|
13008
12951
|
const semanticCandidates = embedding ? this.searchSemanticCandidates(
|
|
13009
12952
|
store,
|
|
13010
12953
|
embedding,
|
|
13011
|
-
|
|
12954
|
+
candidateLimit,
|
|
13012
12955
|
branchChunkIds,
|
|
13013
12956
|
shouldPrefilterByBranch
|
|
13014
12957
|
) : [];
|
|
@@ -13016,7 +12959,7 @@ var Indexer = class _Indexer {
|
|
|
13016
12959
|
const keywordStartTime = performance2.now();
|
|
13017
12960
|
const keywordCandidates = await this.keywordSearch(
|
|
13018
12961
|
query,
|
|
13019
|
-
|
|
12962
|
+
candidateLimit,
|
|
13020
12963
|
store,
|
|
13021
12964
|
invertedIndex,
|
|
13022
12965
|
branchChunkIds,
|
|
@@ -14178,7 +14121,6 @@ var Indexer = class _Indexer {
|
|
|
14178
14121
|
this.store = null;
|
|
14179
14122
|
this.invertedIndex = null;
|
|
14180
14123
|
this.provider = null;
|
|
14181
|
-
this.reranker = null;
|
|
14182
14124
|
this.configuredProviderInfo = null;
|
|
14183
14125
|
this.indexCompatibility = null;
|
|
14184
14126
|
this.initializationMode = "none";
|