@ninjaxtools/slopdex 0.9.0 → 0.10.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
@@ -15,6 +15,7 @@ declare class CodeIndex {
15
15
  useSummaries(options?: {
16
16
  signal?: AbortSignal;
17
17
  }): Promise<SummaryStats>;
18
+ disableSummaries(): SummaryStats;
18
19
  searchSummary(options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
19
20
  similaritySearch(options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
20
21
  similarToFunction(functionId: number, options: {
@@ -358,7 +359,7 @@ declare class OpenAIEmbeddingProvider implements EmbeddingProvider {
358
359
  readonly provider: "openai";
359
360
  readonly model: string;
360
361
  readonly dimensions: number;
361
- readonly strategyVersion: "callable-v1";
362
+ readonly strategyVersion: "callable-v2";
362
363
  };
363
364
  constructor(options?: OpenAIEmbeddingProviderOptions);
364
365
  embedDocuments(inputs: readonly string[], options?: {
@@ -399,7 +400,7 @@ declare class JinaEmbeddingProvider implements EmbeddingProvider {
399
400
  readonly provider: "jina";
400
401
  readonly model: string;
401
402
  readonly dimensions: number;
402
- readonly strategyVersion: "callable-v1:code-query-passage";
403
+ readonly strategyVersion: "callable-v2:code-query-passage";
403
404
  };
404
405
  constructor(options?: JinaEmbeddingProviderOptions);
405
406
  embedDocuments(inputs: readonly string[], options?: {
@@ -431,8 +432,9 @@ declare function similaritySearch(index: CodeIndex, options: SimilaritySearchOpt
431
432
  declare function useSummaries(index: CodeIndex, options?: {
432
433
  signal?: AbortSignal;
433
434
  }): Promise<SummaryStats>;
435
+ declare function disableSummaries(index: CodeIndex): SummaryStats;
434
436
  declare function searchSummary(index: CodeIndex, options: SimilaritySearchOptions): Promise<SimilarityResult[]>;
435
437
  declare function crossSearchFunctions(options: CrossSearchOptions): AsyncGenerator<CrossSearchResult, any, any>;
436
438
  declare function analyzeCodeCohesion(options: CohesionAnalysisOptions): Promise<CohesionReport<IndexedFunction>>;
437
439
 
438
- export { type AnalysisSimilarity, type CallableKind, CodeIndex, CodeIndexError, type CodeIndexOptions, type CohesionAnalysisOptions, type CohesionFileReport, type CohesionFunctionReference, type CohesionGroup, type CohesionJsonReport, type CohesionLocation, type CohesionLocationCategory, type CohesionPair, type CohesionReport, type CohesionSummary, type CrossSearchOptions, type CrossSearchResult, type CrossSearchSourceFilter, type EmbeddingProfile, type EmbeddingProvider, GitDivergenceError, GitUnavailableError, IncompatibleIndexError, type IndexStatus, type IndexedFunction, type IndexingError, type IndexingIssue, JinaEmbeddingProvider, type JinaEmbeddingProviderOptions, OpenAIEmbeddingProvider, type OpenAIEmbeddingProviderOptions, OpenAISummaryProvider, type OpenAISummaryProviderOptions, type ParsedCallable, type SimilarityResult, type SimilarityScores, type SimilaritySearchOptions, type SourceMode, type SummaryInput, type SummaryProfile, type SummaryProvider, type SummaryStats, type SupportedLanguage, type UpdateFilesOptions, type UpdateFromGitOptions, type UpdateFromWorkingTreeOptions, type UpdateStats, analyzeCodeCohesion, analyzeCohesion, cohesionLocation, crossSearch, crossSearchFunctions, openCodeIndex, readIndexErrors, searchSummary, similaritySearch, updateFiles, updateFromGit, updateFromWorkingTree, useSummaries };
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 CohesionPair, type CohesionReport, type CohesionSummary, type CrossSearchOptions, type CrossSearchResult, type CrossSearchSourceFilter, type EmbeddingProfile, type EmbeddingProvider, GitDivergenceError, GitUnavailableError, IncompatibleIndexError, type IndexStatus, type IndexedFunction, type IndexingError, type IndexingIssue, JinaEmbeddingProvider, type JinaEmbeddingProviderOptions, OpenAIEmbeddingProvider, type OpenAIEmbeddingProviderOptions, OpenAISummaryProvider, type OpenAISummaryProviderOptions, type ParsedCallable, type SimilarityResult, type SimilarityScores, type SimilaritySearchOptions, type SourceMode, type SummaryInput, type SummaryProfile, type SummaryProvider, type SummaryStats, type SupportedLanguage, type UpdateFilesOptions, type UpdateFromGitOptions, type UpdateFromWorkingTreeOptions, type UpdateStats, analyzeCodeCohesion, analyzeCohesion, cohesionLocation, crossSearch, crossSearchFunctions, disableSummaries, openCodeIndex, readIndexErrors, searchSummary, similaritySearch, updateFiles, updateFromGit, updateFromWorkingTree, useSummaries };
package/dist/index.js CHANGED
@@ -338,6 +338,13 @@ function pythonIsMethod(node) {
338
338
  const definition = node.parent?.type === "decorated_definition" ? node.parent : node;
339
339
  return definition.parent?.parent?.type === "class_definition";
340
340
  }
341
+ function pythonDocstring(body, content) {
342
+ const statement = body?.namedChildren[0];
343
+ if (statement?.type !== "expression_statement") return null;
344
+ const value = statement.namedChildren[0];
345
+ if (value?.type !== "string" && value?.type !== "concatenated_string") return null;
346
+ return content.slice(value.startIndex, value.endIndex);
347
+ }
341
348
  function goReceiver(node) {
342
349
  let type = node.childForFieldName("receiver")?.namedChildren[0]?.childForFieldName("type");
343
350
  while (type?.type === "pointer_type") type = type.namedChildren[0] ?? null;
@@ -351,12 +358,14 @@ function collectNativeCallables(root, content, language) {
351
358
  if ((!body || body.isMissing) && !node.hasError) return false;
352
359
  const sourceNode = language === "python" && node.parent?.type === "decorated_definition" ? node.parent : node;
353
360
  const header = content.slice(node.startIndex, body?.startIndex ?? node.endIndex).trimEnd();
361
+ const documentation = language === "python" && body ? pythonDocstring(body, content) : null;
354
362
  candidates.push({
355
363
  node: sourceNode,
356
364
  name,
357
365
  kind,
358
366
  scope,
359
- signature: bound ? `${name} = ${header}` : header
367
+ signature: bound ? `${name} = ${header}` : header,
368
+ ...documentation ? { documentation } : {}
360
369
  });
361
370
  if (body) walk2(body, [...scope, name]);
362
371
  return true;
@@ -781,7 +790,7 @@ function extractCallables(relativePath, content) {
781
790
  const errors = parseDiagnostics(tree.rootNode, content, relativePath, language, candidates);
782
791
  const occurrences = /* @__PURE__ */ new Map();
783
792
  const callables = [];
784
- for (const { node, name, kind, scope, signature: candidateSignature } of candidates) {
793
+ for (const { node, name, kind, scope, signature: candidateSignature, documentation } of candidates) {
785
794
  const qualifiedName = [...scope, name].join(".");
786
795
  const baseIdentity = `${relativePath}\0${qualifiedName}\0${kind}`;
787
796
  const occurrence = occurrences.get(baseIdentity) ?? 0;
@@ -796,6 +805,8 @@ function extractCallables(relativePath, content) {
796
805
  `kind: ${kind}`,
797
806
  `symbol: ${qualifiedName}`,
798
807
  signature ? `signature: ${signature}` : null,
808
+ documentation ? `documentation:
809
+ ${documentation}` : null,
799
810
  "source:",
800
811
  source
801
812
  ].filter((value) => value !== null).join("\n");
@@ -1097,6 +1108,13 @@ var IndexDatabase = class {
1097
1108
  this.#setMetadata("generation", String(expectedGeneration + 1));
1098
1109
  });
1099
1110
  }
1111
+ disableSummaries() {
1112
+ if (!this.summariesEnabled()) return;
1113
+ this.#transaction(() => {
1114
+ this.#setMetadata("summaries_enabled", "false");
1115
+ this.#setMetadata("generation", String(this.getGeneration() + 1));
1116
+ });
1117
+ }
1100
1118
  getWorkingTreeFiles() {
1101
1119
  return this.#db.prepare(`
1102
1120
  SELECT path, previous_path AS previousPath
@@ -1968,7 +1986,7 @@ var CodeIndex = class {
1968
1986
  async #attachEmbeddings(files, signal) {
1969
1987
  if (this.#database.summariesEnabled()) {
1970
1988
  if (JSON.stringify(this.#database.summaryProfile()) !== JSON.stringify(this.summaryProvider.profile)) {
1971
- throw new CodeIndexError("Summary provider or model differs from this index; run use-summaries (useSummaries() in the library) with the new provider first.");
1989
+ throw new CodeIndexError("Summary provider or model differs from this index; run summaries enable (useSummaries() in the library) with the new provider first.");
1972
1990
  }
1973
1991
  await this.#attachSummaries(files, signal);
1974
1992
  }
@@ -2067,8 +2085,12 @@ var CodeIndex = class {
2067
2085
  }))), this.summaryProvider.profile, generation);
2068
2086
  return { summariesCreated, summariesEnabled: true };
2069
2087
  }
2088
+ disableSummaries() {
2089
+ this.#database.disableSummaries();
2090
+ return { summariesCreated: 0, summariesEnabled: false };
2091
+ }
2070
2092
  async searchSummary(options) {
2071
- if (!this.#database.summariesEnabled()) throw new CodeIndexError("Summaries are not enabled; run use-summaries first.");
2093
+ if (!this.#database.summariesEnabled()) throw new CodeIndexError("Summaries are not enabled; run summaries enable first.");
2072
2094
  if (!options.query.trim()) throw new CodeIndexError("query must not be empty.");
2073
2095
  const limit = options.limit ?? 10;
2074
2096
  assertPositiveInteger(limit, "limit");
@@ -2205,7 +2227,7 @@ function normalizeProfile(profile) {
2205
2227
  provider: profile.provider,
2206
2228
  model: profile.model,
2207
2229
  dimensions: profile.dimensions,
2208
- strategyVersion: profile.strategyVersion ?? "callable-v1"
2230
+ strategyVersion: profile.strategyVersion ?? "callable-v2"
2209
2231
  };
2210
2232
  }
2211
2233
  function emptyStats(checkpoint) {
@@ -2687,7 +2709,7 @@ var OpenAIEmbeddingProvider = class {
2687
2709
  const model = options.model ?? "text-embedding-3-large";
2688
2710
  const dimensions = options.dimensions ?? 3072;
2689
2711
  if (!Number.isInteger(dimensions) || dimensions < 1) throw new Error("dimensions must be a positive integer.");
2690
- this.profile = { provider: "openai", model, dimensions, strategyVersion: "callable-v1" };
2712
+ this.profile = { provider: "openai", model, dimensions, strategyVersion: "callable-v2" };
2691
2713
  this.#url = `${(options.baseUrl ?? "https://api.openai.com/v1").replace(/\/$/, "")}/embeddings`;
2692
2714
  }
2693
2715
  embedDocuments(inputs, options) {
@@ -2729,7 +2751,7 @@ var JinaEmbeddingProvider = class {
2729
2751
  provider: "jina",
2730
2752
  model,
2731
2753
  dimensions,
2732
- strategyVersion: "callable-v1:code-query-passage"
2754
+ strategyVersion: "callable-v2:code-query-passage"
2733
2755
  };
2734
2756
  this.#url = options.baseUrl ?? "https://api.jina.ai/v1/embeddings";
2735
2757
  }
@@ -2778,6 +2800,9 @@ function similaritySearch(index, options) {
2778
2800
  function useSummaries(index, options) {
2779
2801
  return index.useSummaries(options);
2780
2802
  }
2803
+ function disableSummaries(index) {
2804
+ return index.disableSummaries();
2805
+ }
2781
2806
  function searchSummary(index, options) {
2782
2807
  return index.searchSummary(options);
2783
2808
  }
@@ -2801,6 +2826,7 @@ export {
2801
2826
  cohesionLocation,
2802
2827
  crossSearch,
2803
2828
  crossSearchFunctions,
2829
+ disableSummaries,
2804
2830
  openCodeIndex,
2805
2831
  readIndexErrors,
2806
2832
  searchSummary,