@probelabs/probe 0.6.0-rc56

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/README.md ADDED
@@ -0,0 +1,528 @@
1
+ # @probelabs/probe
2
+
3
+ A Node.js wrapper for the [probe](https://github.com/probelabs/probe) code search tool.
4
+
5
+ ## Installation
6
+
7
+ ### Local Installation
8
+
9
+ ```bash
10
+ npm install @probelabs/probe
11
+ ```
12
+
13
+ ### Global Installation
14
+
15
+ ```bash
16
+ npm install -g @probelabs/probe
17
+ ```
18
+
19
+ During installation, the package will automatically download the appropriate probe binary for your platform.
20
+
21
+ ## Features
22
+
23
+ - **Search Code**: Search for patterns in your codebase using Elasticsearch-like query syntax
24
+ - **Query Code**: Find specific code structures using tree-sitter patterns
25
+ - **Extract Code**: Extract code blocks from files based on file paths and line numbers
26
+ - **AI Tools Integration**: Ready-to-use tools for Vercel AI SDK, LangChain, and other AI frameworks
27
+ - **System Message**: Default system message for AI assistants with instructions on using probe tools
28
+ - **Cross-Platform**: Works on Windows, macOS, and Linux
29
+ - **Automatic Binary Management**: Automatically downloads and manages the probe binary
30
+ - **Direct CLI Access**: Use the probe binary directly from the command line when installed globally
31
+ - **MCP Server**: Built-in Model Context Protocol server for AI assistant integration
32
+
33
+ ## Usage
34
+
35
+ ### Using as a Node.js Library
36
+
37
+ ```javascript
38
+ import { search, query, extract } from '@probelabs/probe';
39
+
40
+ // Search for code
41
+ const searchResults = await search({
42
+ path: '/path/to/your/project',
43
+ query: 'function',
44
+ maxResults: 10
45
+ });
46
+
47
+ // Query for specific code structures
48
+ const queryResults = await query({
49
+ path: '/path/to/your/project',
50
+ pattern: 'function $NAME($$$PARAMS) $$$BODY',
51
+ language: 'javascript'
52
+ });
53
+
54
+ // Extract code blocks
55
+ const extractResults = await extract({
56
+ files: ['/path/to/your/project/src/main.js:42']
57
+ });
58
+ ```
59
+
60
+ ### Using as a Command-Line Tool
61
+
62
+ When installed globally, the `probe` command will be available directly from the command line:
63
+
64
+ ```bash
65
+ # Search for code
66
+ probe search "function" /path/to/your/project
67
+
68
+ # Query for specific code structures
69
+ probe query "function $NAME($$$PARAMS) $$$BODY" /path/to/your/project
70
+
71
+ # Extract code blocks
72
+ probe extract /path/to/your/project/src/main.js:42
73
+
74
+ # Run MCP server for AI assistant integration
75
+ probe mcp
76
+ ```
77
+
78
+ The package installs the actual probe binary, not a JavaScript wrapper, so you get the full native performance and all features of the original probe CLI.
79
+
80
+ ### Using as an MCP Server
81
+
82
+ Probe includes a built-in MCP (Model Context Protocol) server for integration with AI assistants:
83
+
84
+ ```bash
85
+ # Start the MCP server
86
+ probe mcp
87
+
88
+ # With custom timeout
89
+ probe mcp --timeout 60
90
+ ```
91
+
92
+ Add to your AI assistant's MCP configuration:
93
+
94
+ ```json
95
+ {
96
+ "mcpServers": {
97
+ "probe": {
98
+ "command": "npx",
99
+ "args": ["-y", "@probelabs/probe", "mcp"]
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## API Reference
106
+
107
+ ### Search
108
+
109
+ ```javascript
110
+ import { search } from '@probelabs/probe';
111
+
112
+ const results = await search({
113
+ path: '/path/to/your/project',
114
+ query: 'function',
115
+ // Optional parameters
116
+ filesOnly: false,
117
+ ignore: ['node_modules', 'dist'],
118
+ excludeFilenames: false,
119
+ reranker: 'hybrid',
120
+ frequencySearch: true,
121
+ maxResults: 10,
122
+ maxBytes: 1000000,
123
+ maxTokens: 40000,
124
+ allowTests: false,
125
+ noMerge: false,
126
+ mergeThreshold: 5,
127
+ json: false,
128
+ binaryOptions: {
129
+ forceDownload: false,
130
+ version: '1.0.0'
131
+ }
132
+ });
133
+ ```
134
+
135
+ #### Parameters
136
+
137
+ - `path` (required): Path to search in
138
+ - `query` (required): Search query or queries (string or array of strings)
139
+ - `filesOnly`: Only output file paths
140
+ - `ignore`: Patterns to ignore (array of strings)
141
+ - `excludeFilenames`: Exclude filenames from search
142
+ - `reranker`: Reranking method ('hybrid', 'hybrid2', 'bm25', 'tfidf')
143
+ - `frequencySearch`: Use frequency-based search
144
+ - `maxResults`: Maximum number of results
145
+ - `maxBytes`: Maximum bytes to return
146
+ - `maxTokens`: Maximum tokens to return
147
+ - `allowTests`: Include test files
148
+ - `noMerge`: Don't merge adjacent blocks
149
+ - `mergeThreshold`: Merge threshold
150
+ - `json`: Return results as parsed JSON instead of string
151
+ - `binaryOptions`: Options for getting the binary
152
+ - `forceDownload`: Force download even if binary exists
153
+ - `version`: Specific version to download
154
+
155
+ ### Query
156
+
157
+ ```javascript
158
+ import { query } from '@probelabs/probe';
159
+
160
+ const results = await query({
161
+ path: '/path/to/your/project',
162
+ pattern: 'function $NAME($$$PARAMS) $$$BODY',
163
+ // Optional parameters
164
+ language: 'javascript',
165
+ ignore: ['node_modules', 'dist'],
166
+ allowTests: false,
167
+ maxResults: 10,
168
+ format: 'markdown',
169
+ json: false,
170
+ binaryOptions: {
171
+ forceDownload: false,
172
+ version: '1.0.0'
173
+ }
174
+ });
175
+ ```
176
+
177
+ #### Parameters
178
+
179
+ - `path` (required): Path to search in
180
+ - `pattern` (required): The ast-grep pattern to search for
181
+ - `language`: Programming language to search in
182
+ - `ignore`: Patterns to ignore (array of strings)
183
+ - `allowTests`: Include test files
184
+ - `maxResults`: Maximum number of results
185
+ - `format`: Output format ('markdown', 'plain', 'json', 'color')
186
+ - `json`: Return results as parsed JSON instead of string
187
+ - `binaryOptions`: Options for getting the binary
188
+ - `forceDownload`: Force download even if binary exists
189
+ - `version`: Specific version to download
190
+
191
+ ### Extract
192
+
193
+ ```javascript
194
+ import { extract } from '@probelabs/probe';
195
+
196
+ const results = await extract({
197
+ files: [
198
+ '/path/to/your/project/src/main.js',
199
+ '/path/to/your/project/src/utils.js:42' // Extract from line 42
200
+ ],
201
+ // Optional parameters
202
+ allowTests: false,
203
+ contextLines: 2,
204
+ format: 'markdown',
205
+ json: false,
206
+ binaryOptions: {
207
+ forceDownload: false,
208
+ version: '1.0.0'
209
+ }
210
+ });
211
+ ```
212
+
213
+ #### Parameters
214
+
215
+ - `files` (required): Files to extract from (can include line numbers with colon, e.g., "/path/to/file.rs:10")
216
+ - `allowTests`: Include test files
217
+ - `contextLines`: Number of context lines to include
218
+ - `format`: Output format ('markdown', 'plain', 'json')
219
+ - `json`: Return results as parsed JSON instead of string
220
+ - `binaryOptions`: Options for getting the binary
221
+ - `forceDownload`: Force download even if binary exists
222
+ - `version`: Specific version to download
223
+
224
+ ### Binary Management
225
+
226
+ ```javascript
227
+ import { getBinaryPath, setBinaryPath } from '@probelabs/probe';
228
+
229
+ // Get the path to the probe binary
230
+ const binaryPath = await getBinaryPath({
231
+ forceDownload: false,
232
+ version: '1.0.0'
233
+ });
234
+
235
+ // Manually set the path to the probe binary
236
+ setBinaryPath('/path/to/probe/binary');
237
+ ```
238
+
239
+ ### AI Tools
240
+
241
+ ```javascript
242
+ import { tools } from '@probelabs/probe';
243
+
244
+ // Vercel AI SDK tools
245
+ const { searchTool, queryTool, extractTool } = tools;
246
+
247
+ // LangChain tools
248
+ const searchLangChainTool = tools.createSearchTool();
249
+ const queryLangChainTool = tools.createQueryTool();
250
+ const extractLangChainTool = tools.createExtractTool();
251
+ // Access schemas
252
+ const { searchSchema, querySchema, extractSchema } = tools;
253
+
254
+ // Access default system message
255
+ const systemMessage = tools.DEFAULT_SYSTEM_MESSAGE;
256
+ ```
257
+
258
+ #### Vercel AI SDK Tools
259
+
260
+ - `searchTool`: Tool for searching code using Elasticsearch-like query syntax
261
+ - `queryTool`: Tool for searching code using tree-sitter patterns
262
+ - `extractTool`: Tool for extracting code blocks from files
263
+
264
+ #### LangChain Tools
265
+
266
+ - `createSearchTool()`: Creates a tool for searching code using Elasticsearch-like query syntax
267
+ - `createQueryTool()`: Creates a tool for searching code using tree-sitter patterns
268
+ - `createExtractTool()`: Creates a tool for extracting code blocks from files
269
+
270
+ #### Schemas
271
+
272
+ - `searchSchema`: Zod schema for search tool parameters
273
+ - `querySchema`: Zod schema for query tool parameters
274
+ - `extractSchema`: Zod schema for extract tool parameters
275
+
276
+ #### System Message
277
+
278
+ - `DEFAULT_SYSTEM_MESSAGE`: Default system message for AI assistants with instructions on how to use the probe tools
279
+ - `extractSchema`: Zod schema for extract tool parameters
280
+
281
+ ## Examples
282
+
283
+ ### Basic Search Example
284
+
285
+ ```javascript
286
+ import { search } from '@probelabs/probe';
287
+
288
+ async function basicSearchExample() {
289
+ try {
290
+ const results = await search({
291
+ path: '/path/to/your/project',
292
+ query: 'function',
293
+ maxResults: 5
294
+ });
295
+
296
+ console.log('Search results:');
297
+ console.log(results);
298
+ } catch (error) {
299
+ console.error('Search error:', error);
300
+ }
301
+ }
302
+ ```
303
+
304
+ ### Advanced Search with Multiple Options
305
+
306
+ ```javascript
307
+ import { search } from '@probelabs/probe';
308
+
309
+ async function advancedSearchExample() {
310
+ try {
311
+ const results = await search({
312
+ path: '/path/to/your/project',
313
+ query: 'config AND (parse OR tokenize)',
314
+ ignore: ['node_modules', 'dist'],
315
+ reranker: 'hybrid',
316
+ frequencySearch: true,
317
+ maxResults: 10,
318
+ maxTokens: 20000,
319
+ allowTests: false
320
+ });
321
+
322
+ console.log('Advanced search results:');
323
+ console.log(results);
324
+ } catch (error) {
325
+ console.error('Advanced search error:', error);
326
+ }
327
+ }
328
+ ```
329
+
330
+ ### Query for Specific Code Structures
331
+
332
+ ```javascript
333
+ import { query } from '@probelabs/probe';
334
+
335
+ async function queryExample() {
336
+ try {
337
+ // Find all JavaScript functions
338
+ const jsResults = await query({
339
+ path: '/path/to/your/project',
340
+ pattern: 'function $NAME($$$PARAMS) $$$BODY',
341
+ language: 'javascript',
342
+ maxResults: 5
343
+ });
344
+
345
+ console.log('JavaScript functions:');
346
+ console.log(jsResults);
347
+
348
+ // Find all Rust structs
349
+ const rustResults = await query({
350
+ path: '/path/to/your/project',
351
+ pattern: 'struct $NAME $$$BODY',
352
+ language: 'rust',
353
+ maxResults: 5
354
+ });
355
+
356
+ console.log('Rust structs:');
357
+ console.log(rustResults);
358
+ } catch (error) {
359
+ console.error('Query error:', error);
360
+ }
361
+ }
362
+ ```
363
+
364
+ ### Extract Code Blocks
365
+
366
+ ```javascript
367
+ import { extract } from '@probelabs/probe';
368
+
369
+ async function extractExample() {
370
+ try {
371
+ const results = await extract({
372
+ files: [
373
+ '/path/to/your/project/src/main.js',
374
+ '/path/to/your/project/src/utils.js:42' // Extract from line 42
375
+ ],
376
+ contextLines: 2,
377
+ format: 'markdown'
378
+ });
379
+
380
+ console.log('Extracted code:');
381
+ console.log(results);
382
+ } catch (error) {
383
+ console.error('Extract error:', error);
384
+ }
385
+ }
386
+ ```
387
+
388
+ ## How It Works
389
+
390
+ When you install this package:
391
+
392
+ 1. A placeholder binary is included in the package
393
+ 2. During installation, the postinstall script downloads the actual probe binary for your platform
394
+ 3. The placeholder is replaced with the actual binary
395
+ 4. When installed globally, npm creates a symlink to this binary in your system path
396
+
397
+ This approach ensures that you get the actual native binary, not a JavaScript wrapper, providing full performance and all features of the original probe CLI.
398
+
399
+ ## AI Tools Integration
400
+
401
+ The package provides built-in tools for integrating with AI SDKs like Vercel AI SDK and LangChain, allowing you to use probe's powerful code search capabilities in AI applications.
402
+
403
+ ### Using with Vercel AI SDK
404
+
405
+ ```javascript
406
+ import { generateText } from 'ai';
407
+ import { tools } from '@probelabs/probe';
408
+
409
+ // Use the pre-built tools with Vercel AI SDK
410
+ async function chatWithAI(userMessage) {
411
+ const result = await generateText({
412
+ model: provider(modelName),
413
+ messages: [{ role: 'user', content: userMessage }],
414
+ system: "You are a code intelligence assistant. Use the provided tools to search and analyze code.",
415
+ tools: {
416
+ search: tools.searchTool,
417
+ query: tools.queryTool,
418
+ extract: tools.extractTool
419
+ },
420
+ maxSteps: 15,
421
+ temperature: 0.7
422
+ });
423
+
424
+ return result.text;
425
+ }
426
+ ```
427
+
428
+ ### Using with LangChain
429
+
430
+ ```javascript
431
+ import { ChatOpenAI } from '@langchain/openai';
432
+ import { tools } from '@probelabs/probe';
433
+
434
+ // Create the LangChain tools
435
+ const searchTool = tools.createSearchTool();
436
+ const queryTool = tools.createQueryTool();
437
+ const extractTool = tools.createExtractTool();
438
+
439
+ // Create a ChatOpenAI instance with tools
440
+ const model = new ChatOpenAI({
441
+ modelName: "gpt-4o",
442
+ temperature: 0.7
443
+ }).withTools([searchTool, queryTool, extractTool]);
444
+
445
+ // Use the model with tools
446
+ async function chatWithAI(userMessage) {
447
+ const result = await model.invoke([
448
+ { role: "system", content: "You are a code intelligence assistant. Use the provided tools to search and analyze code." },
449
+ { role: "user", content: userMessage }
450
+ ]);
451
+
452
+ return result.content;
453
+ }
454
+ ```
455
+
456
+ ### Using the Default System Message
457
+
458
+ The package provides a default system message that you can use with your AI assistants:
459
+
460
+ ```javascript
461
+ import { tools } from '@probelabs/probe';
462
+
463
+ // Use the default system message in your AI application
464
+ const systemMessage = tools.DEFAULT_SYSTEM_MESSAGE;
465
+
466
+ // Example with Vercel AI SDK
467
+ const result = await generateText({
468
+ model: provider(modelName),
469
+ messages: [{ role: 'user', content: userMessage }],
470
+ system: tools.DEFAULT_SYSTEM_MESSAGE,
471
+ tools: {
472
+ search: tools.searchTool,
473
+ query: tools.queryTool,
474
+ extract: tools.extractTool
475
+ }
476
+ });
477
+ ```
478
+
479
+ The default system message provides instructions for AI assistants on how to use the probe tools effectively, including search query formatting, tool execution sequence, and best practices.
480
+
481
+ ## License
482
+
483
+ ISC
484
+
485
+ ## Migration from @probelabs/probe-mcp
486
+
487
+ If you're migrating from the standalone `@probelabs/probe-mcp` package, `probe mcp` is a drop-in replacement:
488
+
489
+ **Old usage:**
490
+ ```bash
491
+ npx @probelabs/probe-mcp
492
+ # or
493
+ probe-mcp --timeout 60
494
+ ```
495
+
496
+ **New usage (drop-in replacement):**
497
+ ```bash
498
+ probe mcp
499
+ # or
500
+ probe mcp --timeout 60
501
+ ```
502
+
503
+ **MCP Configuration:**
504
+ ```json
505
+ // Old configuration
506
+ {
507
+ "mcpServers": {
508
+ "probe": {
509
+ "command": "npx",
510
+ "args": ["-y", "@probelabs/probe-mcp"]
511
+ }
512
+ }
513
+ }
514
+
515
+ // New configuration (drop-in replacement)
516
+ {
517
+ "mcpServers": {
518
+ "probe": {
519
+ "command": "npx",
520
+ "args": ["-y", "@probelabs/probe", "mcp"]
521
+ }
522
+ }
523
+ }
524
+ ```
525
+
526
+ ## Related Projects
527
+
528
+ - [probe](https://github.com/probelabs/probe) - The core probe code search tool
package/bin/.gitkeep ADDED
File without changes
package/bin/probe ADDED
Binary file