@ninjaxtools/slopdex 0.11.0 → 0.14.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/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ declare class CodeIndex {
3
3
  readonly rootDir: string;
4
4
  readonly indexPath: string;
5
5
  readonly provider: EmbeddingProvider;
6
+ readonly reranker: Reranker | undefined;
6
7
  readonly descriptionProvider: DescriptionProvider;
7
8
  constructor(options: CodeIndexOptions);
8
9
  close(): void;
@@ -15,6 +16,7 @@ declare class CodeIndex {
15
16
  useDescriptions(options?: {
16
17
  signal?: AbortSignal;
17
18
  }): Promise<DescriptionStats>;
19
+ reindexFiles(options?: ReindexFilesOptions): Promise<ReindexFilesStats>;
18
20
  disableDescriptions(): DescriptionStats;
19
21
  searchDescription(options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
20
22
  similaritySearch(options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
@@ -28,8 +30,10 @@ declare class CodeIndex {
28
30
  nameRegex?: string;
29
31
  }): SimilarityResult[];
30
32
  vectorForFunction(functionId: number, kind?: "code" | "description"): number[];
33
+ vectorForFile(filePath: string): number[];
31
34
  searchByVector(vector: readonly number[], options: {
32
35
  descriptionVector?: readonly number[];
36
+ fileDescriptionVector?: readonly number[];
33
37
  limit: number;
34
38
  minSimilarity: number;
35
39
  maxSimilarity?: number;
@@ -102,6 +106,24 @@ interface EmbeddingProvider {
102
106
  signal?: AbortSignal;
103
107
  }): Promise<number[]>;
104
108
  }
109
+ interface RerankerProfile {
110
+ provider: string;
111
+ model: string;
112
+ }
113
+ interface Reranker {
114
+ readonly profile: RerankerProfile;
115
+ /** Preferred embedding-ranked candidate pool size for this reranker. */
116
+ readonly candidateCount?: number;
117
+ /** Maximum candidate/result count accepted by this reranker. */
118
+ readonly maximumCandidateCount?: number;
119
+ rerank(query: string, documents: readonly string[], options?: {
120
+ limit?: number;
121
+ signal?: AbortSignal;
122
+ }): Promise<Array<{
123
+ index: number;
124
+ score: number;
125
+ }>>;
126
+ }
105
127
  interface DescriptionProfile {
106
128
  provider: string;
107
129
  model: string;
@@ -112,20 +134,42 @@ interface DescriptionInput {
112
134
  callable: ParsedCallable;
113
135
  fileSource: string;
114
136
  }
137
+ interface DescriptionFileInput {
138
+ repository: string;
139
+ path: string;
140
+ fileSource: string;
141
+ }
142
+ interface DescriptionFileSession {
143
+ describeFile(options?: {
144
+ signal?: AbortSignal;
145
+ }): Promise<string>;
146
+ replayFile(description: string): void;
147
+ describe(callable: ParsedCallable, options?: {
148
+ signal?: AbortSignal;
149
+ }): Promise<string>;
150
+ replay(callable: ParsedCallable, description: string): void;
151
+ }
115
152
  interface DescriptionProvider {
116
153
  readonly profile: DescriptionProfile;
117
154
  describe(input: DescriptionInput, options?: {
118
155
  signal?: AbortSignal;
119
156
  }): Promise<string>;
157
+ describeFile(input: DescriptionFileInput, options?: {
158
+ signal?: AbortSignal;
159
+ }): Promise<string>;
160
+ startFile?(input: DescriptionFileInput): DescriptionFileSession;
120
161
  }
121
162
  interface DescriptionStats {
122
163
  descriptionsCreated: number;
164
+ fileDescriptionsCreated: number;
123
165
  descriptionsEnabled: boolean;
124
166
  }
125
167
  interface CodeIndexOptions {
126
168
  rootDir: string;
127
169
  indexPath?: string;
128
170
  provider: EmbeddingProvider;
171
+ /** Optional second-stage ranker for natural-language query searches. */
172
+ reranker?: Reranker;
129
173
  descriptionProvider?: DescriptionProvider;
130
174
  onWarning?: (message: string) => void;
131
175
  include?: readonly string[];
@@ -161,6 +205,15 @@ interface UpdateStats {
161
205
  embeddingsCreated: number;
162
206
  checkpoint: string | null;
163
207
  }
208
+ interface ReindexFilesOptions {
209
+ includeCallables?: boolean;
210
+ signal?: AbortSignal;
211
+ }
212
+ interface ReindexFilesStats {
213
+ filesReindexed: number;
214
+ fileDescriptionsCreated: number;
215
+ descriptionsCreated: number;
216
+ }
164
217
  interface SimilaritySearchOptions {
165
218
  query: string;
166
219
  /** Restrict result qualified names before ranking and limiting. */
@@ -174,16 +227,20 @@ interface SimilarityScores {
174
227
  similarity: number;
175
228
  codeSimilarity?: number;
176
229
  descriptionSimilarity?: number;
230
+ fileDescriptionSimilarity?: number;
177
231
  }
178
232
  interface AnalysisSimilarity {
179
- similarityMode: "code" | "code-description-average";
233
+ similarityMode: "code" | "code-description-file-average";
180
234
  similarityWeights: {
181
235
  code: number;
182
236
  description: number;
237
+ fileDescription: number;
183
238
  };
184
239
  }
185
240
  interface SimilarityResult extends SimilarityScores {
186
241
  function: IndexedFunction;
242
+ /** Provider relevance score when a second-stage reranker ordered this result. */
243
+ rerankScore?: number;
187
244
  }
188
245
  type CrossSearchSourceFilter = ({
189
246
  type: "all";
@@ -209,6 +266,8 @@ interface CrossSearchOptions {
209
266
  maxSimilarity?: number;
210
267
  includeSymmetricDuplicates?: boolean;
211
268
  crossFileOnly?: boolean;
269
+ /** Re-rank each source's semantic matches from greatest to least physical path distance. */
270
+ cohesion?: boolean;
212
271
  minLines?: number;
213
272
  nameRegex?: string;
214
273
  signal?: AbortSignal;
@@ -217,9 +276,13 @@ interface CrossSearchOptions {
217
276
  total: number;
218
277
  }) => void;
219
278
  }
279
+ interface CrossSearchMatch extends SimilarityResult {
280
+ /** Present when cohesion re-ranking is enabled. */
281
+ physicalDistance?: number;
282
+ }
220
283
  interface CrossSearchResult {
221
284
  source: IndexedFunction;
222
- matches: SimilarityResult[];
285
+ matches: CrossSearchMatch[];
223
286
  scoring?: AnalysisSimilarity & {
224
287
  sourceDescriptionProfile: DescriptionProfile | null;
225
288
  targetDescriptionProfile: DescriptionProfile | null;
@@ -303,7 +366,7 @@ interface CohesionAnalysisOptions {
303
366
  }) => void;
304
367
  }
305
368
  interface CohesionReport<FunctionValue = IndexedFunction> {
306
- schemaVersion: 2;
369
+ schemaVersion: 3;
307
370
  repository: {
308
371
  generation: number;
309
372
  gitCheckpoint: string | null;
@@ -335,6 +398,9 @@ interface IndexStatus {
335
398
  embeddingProfile: Required<EmbeddingProfile>;
336
399
  descriptionsEnabled: boolean;
337
400
  descriptionCount: number;
401
+ fileDescriptionCount: number;
402
+ describableFileCount: number;
403
+ staleFileDescriptionCount: number;
338
404
  descriptionProfile: DescriptionProfile | null;
339
405
  indexingErrorCount: number;
340
406
  failedFileCount: number;
@@ -374,11 +440,14 @@ interface OpenAIDescriptionProviderOptions {
374
440
  apiKey?: string;
375
441
  model?: string;
376
442
  baseUrl?: string;
443
+ provider?: DescriptionProviderName;
377
444
  }
445
+ declare const DESCRIPTION_PROVIDER_NAMES: readonly ["openai", "opencode", "opencode-go"];
446
+ type DescriptionProviderName = typeof DESCRIPTION_PROVIDER_NAMES[number];
378
447
  declare class OpenAIDescriptionProvider implements DescriptionProvider {
379
448
  #private;
380
449
  readonly profile: {
381
- provider: string;
450
+ provider: "openai" | "opencode" | "opencode-go";
382
451
  model: string;
383
452
  strategyVersion: string;
384
453
  };
@@ -386,6 +455,10 @@ declare class OpenAIDescriptionProvider implements DescriptionProvider {
386
455
  describe(input: DescriptionInput, options?: {
387
456
  signal?: AbortSignal;
388
457
  }): Promise<string>;
458
+ describeFile(input: DescriptionFileInput, options?: {
459
+ signal?: AbortSignal;
460
+ }): Promise<string>;
461
+ startFile(input: DescriptionFileInput): DescriptionFileSession;
389
462
  }
390
463
 
391
464
  interface JinaEmbeddingProviderOptions {
@@ -411,6 +484,66 @@ declare class JinaEmbeddingProvider implements EmbeddingProvider {
411
484
  }): Promise<number[]>;
412
485
  }
413
486
 
487
+ interface HostedRerankerOptions {
488
+ apiKey?: string;
489
+ model?: string;
490
+ baseUrl?: string;
491
+ }
492
+ interface HostedRerankerSettings {
493
+ provider: "cohere" | "jina";
494
+ apiKeyName: "COHERE_API_KEY" | "JINA_API_KEY";
495
+ defaultModel: string;
496
+ defaultUrl: string;
497
+ returnDocuments?: boolean;
498
+ }
499
+ declare abstract class HostedReranker implements Reranker {
500
+ #private;
501
+ readonly profile: {
502
+ readonly provider: "jina" | "cohere";
503
+ readonly model: string;
504
+ };
505
+ protected constructor(options: HostedRerankerOptions, settings: HostedRerankerSettings);
506
+ rerank(query: string, documents: readonly string[], options?: {
507
+ limit?: number;
508
+ signal?: AbortSignal;
509
+ }): Promise<Array<{
510
+ index: number;
511
+ score: number;
512
+ }>>;
513
+ }
514
+ type CohereRerankerOptions = HostedRerankerOptions;
515
+ declare class CohereReranker extends HostedReranker {
516
+ constructor(options?: CohereRerankerOptions);
517
+ }
518
+ type JinaRerankerOptions = HostedRerankerOptions;
519
+ declare class JinaReranker extends HostedReranker {
520
+ constructor(options?: JinaRerankerOptions);
521
+ }
522
+
523
+ interface OpenAILLMRerankerOptions {
524
+ apiKey?: string;
525
+ model?: string;
526
+ baseUrl?: string;
527
+ candidateCount?: number;
528
+ }
529
+ declare class OpenAILLMReranker implements Reranker {
530
+ #private;
531
+ readonly profile: {
532
+ readonly provider: "openai";
533
+ readonly model: string;
534
+ };
535
+ readonly candidateCount: number;
536
+ readonly maximumCandidateCount = 100;
537
+ constructor(options?: OpenAILLMRerankerOptions);
538
+ rerank(query: string, documents: readonly string[], options?: {
539
+ limit?: number;
540
+ signal?: AbortSignal;
541
+ }): Promise<Array<{
542
+ index: number;
543
+ score: number;
544
+ }>>;
545
+ }
546
+
414
547
  declare class CodeIndexError extends Error {
415
548
  constructor(message: string, options?: ErrorOptions);
416
549
  }
@@ -428,6 +561,7 @@ declare function openCodeIndex(options: CodeIndexOptions): CodeIndex;
428
561
  declare function updateFiles(index: CodeIndex, options: UpdateFilesOptions): Promise<UpdateStats>;
429
562
  declare function updateFromGit(index: CodeIndex, options?: UpdateFromGitOptions): Promise<UpdateStats>;
430
563
  declare function updateFromWorkingTree(index: CodeIndex, options?: UpdateFromWorkingTreeOptions): Promise<UpdateStats>;
564
+ declare function reindexFiles(index: CodeIndex, options?: ReindexFilesOptions): Promise<ReindexFilesStats>;
431
565
  declare function similaritySearch(index: CodeIndex, options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
432
566
  declare function useDescriptions(index: CodeIndex, options?: {
433
567
  signal?: AbortSignal;
@@ -437,4 +571,4 @@ declare function searchDescription(index: CodeIndex, options: SimilaritySearchOp
437
571
  declare function crossSearchFunctions(options: CrossSearchOptions): AsyncGenerator<CrossSearchResult, any, any>;
438
572
  declare function analyzeCodeCohesion(options: CohesionAnalysisOptions): Promise<CohesionReport<IndexedFunction>>;
439
573
 
440
- export { type AnalysisSimilarity, type CallableKind, CodeIndex, CodeIndexError, type CodeIndexOptions, type CohesionAnalysisOptions, type CohesionFileReport, type CohesionFunctionReference, type CohesionGroup, type CohesionJsonReport, type CohesionLocation, type CohesionLocationCategory, type CohesionMetrics, type CohesionPair, type CohesionReport, type CrossSearchOptions, type CrossSearchResult, type CrossSearchSourceFilter, type DescriptionInput, type DescriptionProfile, type DescriptionProvider, type DescriptionStats, type EmbeddingProfile, type EmbeddingProvider, GitDivergenceError, GitUnavailableError, IncompatibleIndexError, type IndexStatus, type IndexedFunction, type IndexingError, type IndexingIssue, JinaEmbeddingProvider, type JinaEmbeddingProviderOptions, OpenAIDescriptionProvider, type OpenAIDescriptionProviderOptions, OpenAIEmbeddingProvider, type OpenAIEmbeddingProviderOptions, type ParsedCallable, type SimilarityResult, type SimilarityScores, type SimilaritySearchOptions, type SourceMode, type SupportedLanguage, type UpdateFilesOptions, type UpdateFromGitOptions, type UpdateFromWorkingTreeOptions, type UpdateStats, analyzeCodeCohesion, analyzeCohesion, cohesionLocation, crossSearch, crossSearchFunctions, disableDescriptions, openCodeIndex, readIndexErrors, searchDescription, similaritySearch, updateFiles, updateFromGit, updateFromWorkingTree, useDescriptions };
574
+ export { type AnalysisSimilarity, type CallableKind, CodeIndex, CodeIndexError, type CodeIndexOptions, CohereReranker, type CohereRerankerOptions, type CohesionAnalysisOptions, type CohesionFileReport, type CohesionFunctionReference, type CohesionGroup, type CohesionJsonReport, type CohesionLocation, type CohesionLocationCategory, type CohesionMetrics, type CohesionPair, type CohesionReport, type CrossSearchMatch, type CrossSearchOptions, type CrossSearchResult, type CrossSearchSourceFilter, type DescriptionFileInput, type DescriptionFileSession, type DescriptionInput, type DescriptionProfile, type DescriptionProvider, type DescriptionProviderName, type DescriptionStats, type EmbeddingProfile, type EmbeddingProvider, GitDivergenceError, GitUnavailableError, IncompatibleIndexError, type IndexStatus, type IndexedFunction, type IndexingError, type IndexingIssue, JinaEmbeddingProvider, type JinaEmbeddingProviderOptions, JinaReranker, type JinaRerankerOptions, OpenAIDescriptionProvider, type OpenAIDescriptionProviderOptions, OpenAIEmbeddingProvider, type OpenAIEmbeddingProviderOptions, OpenAILLMReranker, type OpenAILLMRerankerOptions, type ParsedCallable, type ReindexFilesOptions, type ReindexFilesStats, type Reranker, type RerankerProfile, type SimilarityResult, type SimilarityScores, type SimilaritySearchOptions, type SourceMode, type SupportedLanguage, type UpdateFilesOptions, type UpdateFromGitOptions, type UpdateFromWorkingTreeOptions, type UpdateStats, analyzeCodeCohesion, analyzeCohesion, cohesionLocation, crossSearch, crossSearchFunctions, disableDescriptions, openCodeIndex, readIndexErrors, reindexFiles, searchDescription, similaritySearch, updateFiles, updateFromGit, updateFromWorkingTree, useDescriptions };