@grepr/cli 1.1.4 → 1.3.0-94fe60c

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.
Files changed (108) hide show
  1. package/build/dist/commands/base-command.d.ts +3 -3
  2. package/build/dist/commands/base-command.d.ts.map +1 -1
  3. package/build/dist/commands/base-command.js +1 -7
  4. package/build/dist/commands/base-command.js.map +1 -1
  5. package/build/dist/commands/config-command.d.ts +5 -9
  6. package/build/dist/commands/config-command.d.ts.map +1 -1
  7. package/build/dist/commands/config-command.js +32 -4
  8. package/build/dist/commands/config-command.js.map +1 -1
  9. package/build/dist/commands/crud-command.d.ts +11 -18
  10. package/build/dist/commands/crud-command.d.ts.map +1 -1
  11. package/build/dist/commands/crud-command.js +27 -11
  12. package/build/dist/commands/crud-command.js.map +1 -1
  13. package/build/dist/commands/dataset-command.d.ts +8 -13
  14. package/build/dist/commands/dataset-command.d.ts.map +1 -1
  15. package/build/dist/commands/dataset-command.js.map +1 -1
  16. package/build/dist/commands/docs-command.d.ts +87 -0
  17. package/build/dist/commands/docs-command.d.ts.map +1 -0
  18. package/build/dist/commands/docs-command.js +164 -0
  19. package/build/dist/commands/docs-command.js.map +1 -0
  20. package/build/dist/commands/docs-get-command.d.ts +53 -0
  21. package/build/dist/commands/docs-get-command.d.ts.map +1 -0
  22. package/build/dist/commands/docs-get-command.js +75 -0
  23. package/build/dist/commands/docs-get-command.js.map +1 -0
  24. package/build/dist/commands/grok-command.d.ts +71 -0
  25. package/build/dist/commands/grok-command.d.ts.map +1 -0
  26. package/build/dist/commands/grok-command.js +258 -0
  27. package/build/dist/commands/grok-command.js.map +1 -0
  28. package/build/dist/commands/integration-command.d.ts +5 -7
  29. package/build/dist/commands/integration-command.d.ts.map +1 -1
  30. package/build/dist/commands/integration-command.js +4 -4
  31. package/build/dist/commands/integration-command.js.map +1 -1
  32. package/build/dist/commands/job-command.d.ts +7 -43
  33. package/build/dist/commands/job-command.d.ts.map +1 -1
  34. package/build/dist/commands/job-command.js +5 -3
  35. package/build/dist/commands/job-command.js.map +1 -1
  36. package/build/dist/commands/job-to-test-command.d.ts +74 -0
  37. package/build/dist/commands/job-to-test-command.d.ts.map +1 -0
  38. package/build/dist/commands/job-to-test-command.js +159 -0
  39. package/build/dist/commands/job-to-test-command.js.map +1 -0
  40. package/build/dist/commands/list-command.d.ts +5 -7
  41. package/build/dist/commands/list-command.d.ts.map +1 -1
  42. package/build/dist/commands/list-command.js +20 -4
  43. package/build/dist/commands/list-command.js.map +1 -1
  44. package/build/dist/commands/query-command.d.ts +3 -8
  45. package/build/dist/commands/query-command.d.ts.map +1 -1
  46. package/build/dist/commands/query-command.js +34 -14
  47. package/build/dist/commands/query-command.js.map +1 -1
  48. package/build/dist/docs-index/catalog.json +1 -0
  49. package/build/dist/docs-index/index.json +1 -0
  50. package/build/dist/grepr.js +43 -7
  51. package/build/dist/grepr.js.map +1 -1
  52. package/build/dist/lib/api-client-factory.d.ts +2 -2
  53. package/build/dist/lib/api-client-factory.d.ts.map +1 -1
  54. package/build/dist/lib/api-client-factory.js +1 -1
  55. package/build/dist/lib/api-client-factory.js.map +1 -1
  56. package/build/dist/lib/auth.d.ts +17 -9
  57. package/build/dist/lib/auth.d.ts.map +1 -1
  58. package/build/dist/lib/auth.js +53 -14
  59. package/build/dist/lib/auth.js.map +1 -1
  60. package/build/dist/lib/command-registry.d.ts +3 -2
  61. package/build/dist/lib/command-registry.d.ts.map +1 -1
  62. package/build/dist/lib/command-registry.js.map +1 -1
  63. package/build/dist/lib/config.d.ts +15 -0
  64. package/build/dist/lib/config.d.ts.map +1 -1
  65. package/build/dist/lib/config.js +45 -11
  66. package/build/dist/lib/config.js.map +1 -1
  67. package/build/dist/lib/docs-search.d.ts +154 -0
  68. package/build/dist/lib/docs-search.d.ts.map +1 -0
  69. package/build/dist/lib/docs-search.js +208 -0
  70. package/build/dist/lib/docs-search.js.map +1 -0
  71. package/build/dist/lib/grepr-api-client.d.ts +33 -193
  72. package/build/dist/lib/grepr-api-client.d.ts.map +1 -1
  73. package/build/dist/lib/grepr-api-client.js +58 -38
  74. package/build/dist/lib/grepr-api-client.js.map +1 -1
  75. package/build/dist/lib/job-graph-transformer.d.ts +89 -0
  76. package/build/dist/lib/job-graph-transformer.d.ts.map +1 -0
  77. package/build/dist/lib/job-graph-transformer.js +497 -0
  78. package/build/dist/lib/job-graph-transformer.js.map +1 -0
  79. package/build/dist/lib/job-graph-utils.d.ts +50 -0
  80. package/build/dist/lib/job-graph-utils.d.ts.map +1 -0
  81. package/build/dist/lib/job-graph-utils.js +84 -0
  82. package/build/dist/lib/job-graph-utils.js.map +1 -0
  83. package/build/dist/lib/json-formatter.d.ts +1 -0
  84. package/build/dist/lib/json-formatter.d.ts.map +1 -1
  85. package/build/dist/lib/json-formatter.js +28 -16
  86. package/build/dist/lib/json-formatter.js.map +1 -1
  87. package/build/dist/lib/parser.d.ts.map +1 -1
  88. package/build/dist/lib/parser.js +3 -6
  89. package/build/dist/lib/parser.js.map +1 -1
  90. package/build/dist/lib/streaming-job-executor.d.ts +3 -3
  91. package/build/dist/lib/streaming-job-executor.d.ts.map +1 -1
  92. package/build/dist/lib/streaming-job-executor.js +54 -21
  93. package/build/dist/lib/streaming-job-executor.js.map +1 -1
  94. package/build/dist/lib/time-utils.js +1 -1
  95. package/build/dist/lib/time-utils.js.map +1 -1
  96. package/build/dist/lib/transformers-embeddings.d.ts +76 -0
  97. package/build/dist/lib/transformers-embeddings.d.ts.map +1 -0
  98. package/build/dist/lib/transformers-embeddings.js +109 -0
  99. package/build/dist/lib/transformers-embeddings.js.map +1 -0
  100. package/build/dist/openapi/openApiTypes.d.ts +3967 -2240
  101. package/build/dist/openapi/openApiTypes.d.ts.map +1 -1
  102. package/build/dist/openapi/openApiTypes.js +341 -85
  103. package/build/dist/openapi/openApiTypes.js.map +1 -1
  104. package/build/dist/types.d.ts +48 -78
  105. package/build/dist/types.d.ts.map +1 -1
  106. package/build/dist/types.js +73 -0
  107. package/build/dist/types.js.map +1 -1
  108. package/package.json +41 -11
@@ -3,6 +3,9 @@ import { CliOptions, SavedCliConfig, CliConfigFile } from '../types.js';
3
3
  * Configuration manager for CLI settings
4
4
  */
5
5
  export declare class ConfigManager {
6
+ private readonly configDir;
7
+ private readonly configFile;
8
+ constructor(configDir?: string);
6
9
  /**
7
10
  * Load configuration from file
8
11
  */
@@ -27,6 +30,18 @@ export declare class ConfigManager {
27
30
  * Delete a configuration by name
28
31
  */
29
32
  deleteConfig(configName: string): Promise<void>;
33
+ /**
34
+ * Get the name of the default configuration
35
+ */
36
+ getDefaultConfigName(): Promise<string | null>;
37
+ /**
38
+ * Set the default configuration by name
39
+ */
40
+ setDefaultConfig(configName: string): Promise<void>;
41
+ /**
42
+ * Get the default configuration
43
+ */
44
+ getDefaultConfig(): Promise<SavedCliConfig | null>;
30
45
  /**
31
46
  * Merge saved configuration with CLI options
32
47
  * CLI options take precedence over saved config
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/main/typescript/lib/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKxE;;GAEG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAYrD;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1D;;OAEG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAcnE;;OAEG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1E;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC;;OAEG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,O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AAG,IAAI,CAAC;IASxD;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAWhH;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc;CAsBrE"}
@@ -1,19 +1,23 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import os from 'os';
4
- const CONFIG_DIR = path.join(os.homedir(), '.grepr');
5
- const CONFIG_FILE = path.join(CONFIG_DIR, 'cli-config.json');
6
4
  /**
7
5
  * Configuration manager for CLI settings
8
6
  */
9
7
  export class ConfigManager {
8
+ configDir;
9
+ configFile;
10
+ constructor(configDir) {
11
+ this.configDir = configDir || path.join(os.homedir(), '.grepr');
12
+ this.configFile = path.join(this.configDir, 'cli-config.json');
13
+ }
10
14
  /**
11
15
  * Load configuration from file
12
16
  */
13
17
  async loadConfigFile() {
14
18
  try {
15
- if (await fs.pathExists(CONFIG_FILE)) {
16
- return await fs.readJson(CONFIG_FILE);
19
+ if (await fs.pathExists(this.configFile)) {
20
+ return await fs.readJson(this.configFile);
17
21
  }
18
22
  }
19
23
  catch (error) {
@@ -27,8 +31,8 @@ export class ConfigManager {
27
31
  */
28
32
  async saveConfigFile(config) {
29
33
  try {
30
- await fs.ensureDir(CONFIG_DIR, { mode: 0o700 });
31
- await fs.writeJson(CONFIG_FILE, config, { spaces: 2, mode: 0o600 });
34
+ await fs.ensureDir(this.configDir, { mode: 0o700 });
35
+ await fs.writeJson(this.configFile, config, { spaces: 2, mode: 0o600 });
32
36
  }
33
37
  catch (error) {
34
38
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -44,8 +48,8 @@ export class ConfigManager {
44
48
  return null;
45
49
  }
46
50
  const config = configFile[configName];
47
- if (!config) {
48
- throw new Error(`Configuration '${configName}' not found. Available configurations: ${Object.keys(configFile).join(', ')}`);
51
+ if (!config || typeof config === 'string') {
52
+ throw new Error(`Configuration '${configName}' not found. Available configurations: ${Object.keys(configFile).filter(k => k !== '_default').join(', ')}`);
49
53
  }
50
54
  return config;
51
55
  }
@@ -62,7 +66,7 @@ export class ConfigManager {
62
66
  */
63
67
  async listConfigs() {
64
68
  const configFile = await this.loadConfigFile();
65
- return configFile ? Object.keys(configFile) : [];
69
+ return configFile ? Object.keys(configFile).filter(key => key !== '_default') : [];
66
70
  }
67
71
  /**
68
72
  * Delete a configuration by name
@@ -72,9 +76,40 @@ export class ConfigManager {
72
76
  if (!configFile || !configFile[configName]) {
73
77
  throw new Error(`Configuration '${configName}' not found`);
74
78
  }
75
- delete configFile[configName];
79
+ const { [configName]: _removedConfig, ...remainingConfigs } = configFile;
80
+ if (configFile._default === configName) {
81
+ delete remainingConfigs._default;
82
+ }
83
+ await this.saveConfigFile(remainingConfigs);
84
+ }
85
+ /**
86
+ * Get the name of the default configuration
87
+ */
88
+ async getDefaultConfigName() {
89
+ const configFile = await this.loadConfigFile();
90
+ return configFile?._default || null;
91
+ }
92
+ /**
93
+ * Set the default configuration by name
94
+ */
95
+ async setDefaultConfig(configName) {
96
+ const configFile = await this.loadConfigFile();
97
+ if (!configFile || !configFile[configName]) {
98
+ throw new Error(`Configuration '${configName}' not found. Cannot set as default.`);
99
+ }
100
+ configFile._default = configName;
76
101
  await this.saveConfigFile(configFile);
77
102
  }
103
+ /**
104
+ * Get the default configuration
105
+ */
106
+ async getDefaultConfig() {
107
+ const defaultName = await this.getDefaultConfigName();
108
+ if (!defaultName) {
109
+ return null;
110
+ }
111
+ return await this.getConfig(defaultName);
112
+ }
78
113
  /**
79
114
  * Merge saved configuration with CLI options
80
115
  * CLI options take precedence over saved config
@@ -95,7 +130,6 @@ export class ConfigManager {
95
130
  orgName: cliOptions.orgName,
96
131
  authBaseUrl: cliOptions.authBaseUrl,
97
132
  authMethod: cliOptions.authMethod,
98
- userId: cliOptions.userId,
99
133
  clientId: cliOptions.clientId,
100
134
  authCache: cliOptions.authCache !== false,
101
135
  browser: cliOptions.browser !== false,
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/main/typescript/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AACrD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB;;OAEG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC;YACH,IAAI,MAAM,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrC,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YAC9E,OAAO,CAAC,IAAI,CAAC,4CAA4C,YAAY,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAAC,MAAqB;QACxC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAChD,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,KAA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0,0 +1,154 @@
1
+ import { DocumentTextSection } from 'vectra';
2
+ /**
3
+ * Represents a single search result from the documentation index.
4
+ */
5
+ export interface SearchResult {
6
+ /** Relevance score (0.0-1.0), higher is more relevant */
7
+ score: number;
8
+ /** Document URI in format 'doc://path/to/file.mdx', 'api://operation', or 'schema://SchemaName' */
9
+ uri: string;
10
+ /** Rendered text sections from the document */
11
+ sections: DocumentTextSection[];
12
+ }
13
+ /**
14
+ * Options for customizing search behavior.
15
+ */
16
+ export interface SearchOptions {
17
+ /** Maximum number of results to return (default: 5) */
18
+ limit?: number;
19
+ /** Minimum relevance score for results (0.0-1.0, default: 0.0) */
20
+ threshold?: number;
21
+ /** Maximum number of document chunks to search (default: 20) */
22
+ maxChunks?: number;
23
+ /** Filter results by document type (default: all) */
24
+ type?: 'all' | 'doc' | 'api' | 'schema';
25
+ /** Number of tokens of context to show per section (default: 300) */
26
+ contextTokens?: number;
27
+ }
28
+ /**
29
+ * Semantic search engine for Grepr documentation.
30
+ *
31
+ * This class provides high-level search functionality over a pre-built Vectra index
32
+ * of documentation files. Key architectural decisions:
33
+ *
34
+ * 1. **Build-time indexing**: The documentation index is generated at build time
35
+ * by scripts/build-docs-index.ts and bundled with the CLI distribution. This
36
+ * makes the index immutable and version-synchronized with the CLI.
37
+ *
38
+ * 2. **Lazy initialization**: The embedding model and index are loaded only when
39
+ * first needed, keeping CLI startup fast for non-search commands.
40
+ *
41
+ * 3. **Index location**: The index is resolved relative to this compiled file's
42
+ * location (build/dist/lib/), pointing to build/dist/docs-index/. This works
43
+ * both during development and after npm publication.
44
+ *
45
+ * 4. **Two-stage filtering**: Vectra returns top-K results by similarity, then we
46
+ * apply threshold filtering. This ensures we always consider the most relevant
47
+ * documents even if they're below threshold.
48
+ */
49
+ export declare class DocsSearch {
50
+ private index;
51
+ private indexPath;
52
+ private embeddings;
53
+ /**
54
+ * Creates a new DocsSearch instance.
55
+ *
56
+ * The constructor sets up paths and creates the embeddings provider, but does
57
+ * NOT load the model or index yet (lazy initialization).
58
+ *
59
+ * @param indexPath - Optional path to the index directory. If not provided,
60
+ * defaults to the bundled docs-index directory relative to
61
+ * this file. Used primarily for testing with temporary indices.
62
+ */
63
+ constructor(indexPath?: string);
64
+ /**
65
+ * Initializes the search engine by loading the embedding model and opening the index.
66
+ *
67
+ * This method is idempotent - multiple calls have no effect after the first successful
68
+ * initialization. It performs the following steps:
69
+ * 1. Loads the Transformers.js embedding model (downloads on first run)
70
+ * 2. Opens the Vectra index from the bundled docs-index directory
71
+ * 3. Verifies the index exists and is valid
72
+ *
73
+ * @throws Error if the index is not found or corrupted. This typically indicates
74
+ * a corrupted CLI installation and the user should reinstall.
75
+ */
76
+ initialize(): Promise<void>;
77
+ /**
78
+ * Performs semantic search over the documentation.
79
+ *
80
+ * This method converts the query text into an embedding vector and finds the most
81
+ * similar documents in the index using cosine similarity. The search process:
82
+ *
83
+ * 1. Auto-initializes if not already initialized
84
+ * 2. Generates embedding for the query text
85
+ * 3. Performs vector similarity search via Vectra
86
+ * 4. Filters results by threshold (if specified)
87
+ * 5. Renders document sections with minimal context (focused excerpts)
88
+ * 6. Returns formatted results sorted by relevance
89
+ *
90
+ * Note on threshold filtering: We apply threshold AFTER Vectra's top-K search.
91
+ * This means if limit=5 and threshold=0.7, we might return fewer than 5 results
92
+ * if some of the top 5 don't meet the threshold.
93
+ *
94
+ * Note on section rendering: We use 300 tokens per section (roughly 1200 characters)
95
+ * to show focused, relevant excerpts rather than large chunks that include
96
+ * irrelevant content from the start of the document. This matches our 512-token
97
+ * chunking strategy during indexing.
98
+ *
99
+ * @param query - Natural language search query
100
+ * @param options - Search customization options
101
+ * @returns Array of search results, sorted by relevance (highest first)
102
+ */
103
+ search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
104
+ /**
105
+ * Retrieves the full content of a document by its URI.
106
+ *
107
+ * This method fetches the complete raw text of a document, not just the top
108
+ * matching sections from a search. It's designed for retrieving complete
109
+ * documentation after finding it via search.
110
+ *
111
+ * Implementation details:
112
+ *
113
+ * 1. **Direct lookup**: Calls `listDocuments()` to get all indexed documents,
114
+ * then finds the matching URI. This is more efficient than query-based
115
+ * retrieval because it avoids unnecessary similarity calculations.
116
+ *
117
+ * 2. **Raw text loading**: Uses `loadText()` to read the original document text
118
+ * directly from disk, bypassing Vectra's `renderAllSections()` which runs text
119
+ * through a GPT-3 tokenizer encode/decode round-trip that corrupts special
120
+ * characters (e.g., pipe characters in GFM tables become `\|`).
121
+ *
122
+ * Performance: This method loads the entire document list into memory once,
123
+ * which is acceptable since the index is immutable and relatively small (tens
124
+ * to hundreds of documents). For larger indices, consider adding a caching layer.
125
+ *
126
+ * Alternative considered (Option B): Query-based retrieval using `queryDocuments()`
127
+ * was rejected because it returns sections in relevance order rather than document
128
+ * order, which would break the natural flow of documentation.
129
+ *
130
+ * @param uri - Document URI in format 'doc://path/to/file.mdx'
131
+ * @returns Complete document content as markdown text
132
+ * @throws Error if document is not found in the index
133
+ */
134
+ getDocument(uri: string): Promise<string>;
135
+ /**
136
+ * Builds a metadata filter for the specified document type.
137
+ *
138
+ * @param type - Type filter to apply
139
+ * @returns Metadata filter for Vectra query, or undefined for 'all'
140
+ */
141
+ private buildMetadataFilter;
142
+ /**
143
+ * Retrieves statistics about the documentation index.
144
+ *
145
+ * Useful for debugging and verifying the index was built correctly.
146
+ *
147
+ * @returns Index metadata including document count and file path
148
+ */
149
+ getIndexStats(): Promise<{
150
+ documentCount: number;
151
+ indexPath: string;
152
+ }>;
153
+ }
154
+ //# sourceMappingURL=docs-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-search.d.ts","sourceRoot":"","sources":["../../../src/main/typescript/lib/docs-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,mBAAmB,EAAkB,MAAM,QAAQ,CAAC;AAKjF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,mGAAmG;IACnG,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;IACxC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAyB;IAE3C;;;;;;;;;OASG;gBACS,SAAS,CAAC,EAAE,MAAM;IAY9B;;;;;;;;;;;OAWG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IA2CjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB/C;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;;;;OAMG;IACG,aAAa,IAAI,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAgB7E"}
@@ -0,0 +1,208 @@
1
+ import { LocalDocumentIndex } from 'vectra';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { TransformersEmbeddings } from './transformers-embeddings.js';
5
+ /**
6
+ * Semantic search engine for Grepr documentation.
7
+ *
8
+ * This class provides high-level search functionality over a pre-built Vectra index
9
+ * of documentation files. Key architectural decisions:
10
+ *
11
+ * 1. **Build-time indexing**: The documentation index is generated at build time
12
+ * by scripts/build-docs-index.ts and bundled with the CLI distribution. This
13
+ * makes the index immutable and version-synchronized with the CLI.
14
+ *
15
+ * 2. **Lazy initialization**: The embedding model and index are loaded only when
16
+ * first needed, keeping CLI startup fast for non-search commands.
17
+ *
18
+ * 3. **Index location**: The index is resolved relative to this compiled file's
19
+ * location (build/dist/lib/), pointing to build/dist/docs-index/. This works
20
+ * both during development and after npm publication.
21
+ *
22
+ * 4. **Two-stage filtering**: Vectra returns top-K results by similarity, then we
23
+ * apply threshold filtering. This ensures we always consider the most relevant
24
+ * documents even if they're below threshold.
25
+ */
26
+ export class DocsSearch {
27
+ index = null;
28
+ indexPath;
29
+ embeddings;
30
+ /**
31
+ * Creates a new DocsSearch instance.
32
+ *
33
+ * The constructor sets up paths and creates the embeddings provider, but does
34
+ * NOT load the model or index yet (lazy initialization).
35
+ *
36
+ * @param indexPath - Optional path to the index directory. If not provided,
37
+ * defaults to the bundled docs-index directory relative to
38
+ * this file. Used primarily for testing with temporary indices.
39
+ */
40
+ constructor(indexPath) {
41
+ if (indexPath) {
42
+ this.indexPath = indexPath;
43
+ }
44
+ else {
45
+ const __filename = fileURLToPath(import.meta.url);
46
+ const __dirname = path.dirname(__filename);
47
+ this.indexPath = path.resolve(__dirname, '../docs-index');
48
+ }
49
+ this.embeddings = new TransformersEmbeddings('Xenova/all-MiniLM-L6-v2', 512);
50
+ }
51
+ /**
52
+ * Initializes the search engine by loading the embedding model and opening the index.
53
+ *
54
+ * This method is idempotent - multiple calls have no effect after the first successful
55
+ * initialization. It performs the following steps:
56
+ * 1. Loads the Transformers.js embedding model (downloads on first run)
57
+ * 2. Opens the Vectra index from the bundled docs-index directory
58
+ * 3. Verifies the index exists and is valid
59
+ *
60
+ * @throws Error if the index is not found or corrupted. This typically indicates
61
+ * a corrupted CLI installation and the user should reinstall.
62
+ */
63
+ async initialize() {
64
+ if (this.index) {
65
+ return;
66
+ }
67
+ await this.embeddings.initialize();
68
+ this.index = new LocalDocumentIndex({
69
+ folderPath: this.indexPath,
70
+ embeddings: this.embeddings
71
+ });
72
+ if (!(await this.index.isIndexCreated())) {
73
+ throw new Error('Documentation index not found. The CLI package may be corrupted. ' +
74
+ 'Please reinstall the CLI: npm install -g @grepr/cli');
75
+ }
76
+ }
77
+ /**
78
+ * Performs semantic search over the documentation.
79
+ *
80
+ * This method converts the query text into an embedding vector and finds the most
81
+ * similar documents in the index using cosine similarity. The search process:
82
+ *
83
+ * 1. Auto-initializes if not already initialized
84
+ * 2. Generates embedding for the query text
85
+ * 3. Performs vector similarity search via Vectra
86
+ * 4. Filters results by threshold (if specified)
87
+ * 5. Renders document sections with minimal context (focused excerpts)
88
+ * 6. Returns formatted results sorted by relevance
89
+ *
90
+ * Note on threshold filtering: We apply threshold AFTER Vectra's top-K search.
91
+ * This means if limit=5 and threshold=0.7, we might return fewer than 5 results
92
+ * if some of the top 5 don't meet the threshold.
93
+ *
94
+ * Note on section rendering: We use 300 tokens per section (roughly 1200 characters)
95
+ * to show focused, relevant excerpts rather than large chunks that include
96
+ * irrelevant content from the start of the document. This matches our 512-token
97
+ * chunking strategy during indexing.
98
+ *
99
+ * @param query - Natural language search query
100
+ * @param options - Search customization options
101
+ * @returns Array of search results, sorted by relevance (highest first)
102
+ */
103
+ async search(query, options = {}) {
104
+ if (!this.index) {
105
+ await this.initialize();
106
+ }
107
+ if (!this.index) {
108
+ throw new Error('Failed to initialize index');
109
+ }
110
+ const { limit = 5, threshold = 0.0, maxChunks = 40, type = 'all', contextTokens = 300 } = options;
111
+ const filter = this.buildMetadataFilter(type);
112
+ const results = await this.index.queryDocuments(query, {
113
+ maxDocuments: limit,
114
+ maxChunks,
115
+ filter
116
+ });
117
+ const formatted = [];
118
+ for (const result of results) {
119
+ if (result.score < threshold) {
120
+ continue;
121
+ }
122
+ const sections = await result.renderSections(contextTokens, 3, true);
123
+ formatted.push({
124
+ score: result.score,
125
+ uri: result.uri,
126
+ sections
127
+ });
128
+ }
129
+ return formatted;
130
+ }
131
+ /**
132
+ * Retrieves the full content of a document by its URI.
133
+ *
134
+ * This method fetches the complete raw text of a document, not just the top
135
+ * matching sections from a search. It's designed for retrieving complete
136
+ * documentation after finding it via search.
137
+ *
138
+ * Implementation details:
139
+ *
140
+ * 1. **Direct lookup**: Calls `listDocuments()` to get all indexed documents,
141
+ * then finds the matching URI. This is more efficient than query-based
142
+ * retrieval because it avoids unnecessary similarity calculations.
143
+ *
144
+ * 2. **Raw text loading**: Uses `loadText()` to read the original document text
145
+ * directly from disk, bypassing Vectra's `renderAllSections()` which runs text
146
+ * through a GPT-3 tokenizer encode/decode round-trip that corrupts special
147
+ * characters (e.g., pipe characters in GFM tables become `\|`).
148
+ *
149
+ * Performance: This method loads the entire document list into memory once,
150
+ * which is acceptable since the index is immutable and relatively small (tens
151
+ * to hundreds of documents). For larger indices, consider adding a caching layer.
152
+ *
153
+ * Alternative considered (Option B): Query-based retrieval using `queryDocuments()`
154
+ * was rejected because it returns sections in relevance order rather than document
155
+ * order, which would break the natural flow of documentation.
156
+ *
157
+ * @param uri - Document URI in format 'doc://path/to/file.mdx'
158
+ * @returns Complete document content as markdown text
159
+ * @throws Error if document is not found in the index
160
+ */
161
+ async getDocument(uri) {
162
+ if (!this.index) {
163
+ await this.initialize();
164
+ }
165
+ if (!this.index) {
166
+ throw new Error('Failed to initialize index');
167
+ }
168
+ const docs = await this.index.listDocuments();
169
+ const doc = docs.find(d => d.uri === uri);
170
+ if (!doc) {
171
+ throw new Error(`Document not found: ${uri}`);
172
+ }
173
+ return doc.loadText();
174
+ }
175
+ /**
176
+ * Builds a metadata filter for the specified document type.
177
+ *
178
+ * @param type - Type filter to apply
179
+ * @returns Metadata filter for Vectra query, or undefined for 'all'
180
+ */
181
+ buildMetadataFilter(type) {
182
+ if (type === 'all') {
183
+ return undefined;
184
+ }
185
+ return { docType: type };
186
+ }
187
+ /**
188
+ * Retrieves statistics about the documentation index.
189
+ *
190
+ * Useful for debugging and verifying the index was built correctly.
191
+ *
192
+ * @returns Index metadata including document count and file path
193
+ */
194
+ async getIndexStats() {
195
+ if (!this.index) {
196
+ await this.initialize();
197
+ }
198
+ if (!this.index) {
199
+ throw new Error('Failed to initialize index');
200
+ }
201
+ const stats = await this.index.listDocuments();
202
+ return {
203
+ documentCount: stats.length,
204
+ indexPath: this.indexPath
205
+ };
206
+ }
207
+ }
208
+ //# sourceMappingURL=docs-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-search.js","sourceRoot":"","sources":["../../../src/main/typescript/lib/docs-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAuC,MAAM,QAAQ,CAAC;AACjF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AA8BtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,UAAU;IACb,KAAK,GAA8B,IAAI,CAAC;IACxC,SAAS,CAAS;IAClB,UAAU,CAAyB;IAE3C;;;;;;;;;OASG;IACH,YAAY,SAAkB;QAC5B,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,sBAAsB,CAAC,yBAAyB,EAAE,GAA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