@probelabs/probe 0.6.0-rc100
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 +583 -0
- package/bin/.gitkeep +0 -0
- package/bin/probe +158 -0
- package/bin/probe-binary +0 -0
- package/build/agent/ProbeAgent.d.ts +199 -0
- package/build/agent/ProbeAgent.js +1486 -0
- package/build/agent/acp/README.md +347 -0
- package/build/agent/acp/connection.js +237 -0
- package/build/agent/acp/connection.test.js +311 -0
- package/build/agent/acp/examples/simple-client.js +212 -0
- package/build/agent/acp/examples/tool-lifecycle.js +230 -0
- package/build/agent/acp/final-test.js +173 -0
- package/build/agent/acp/index.js +5 -0
- package/build/agent/acp/integration.test.js +385 -0
- package/build/agent/acp/manual-test.js +410 -0
- package/build/agent/acp/protocol-test.js +190 -0
- package/build/agent/acp/server.js +448 -0
- package/build/agent/acp/server.test.js +371 -0
- package/build/agent/acp/test-runner.js +216 -0
- package/build/agent/acp/test-utils/README.md +315 -0
- package/build/agent/acp/test-utils/acp-tester.js +484 -0
- package/build/agent/acp/test-utils/mock-acp-client.js +434 -0
- package/build/agent/acp/tools.js +368 -0
- package/build/agent/acp/tools.test.js +334 -0
- package/build/agent/acp/types.js +218 -0
- package/build/agent/acp/types.test.js +327 -0
- package/build/agent/appTracer.js +360 -0
- package/build/agent/fileSpanExporter.js +169 -0
- package/build/agent/index.js +7426 -0
- package/build/agent/mcp/client.js +338 -0
- package/build/agent/mcp/config.js +313 -0
- package/build/agent/mcp/index.js +64 -0
- package/build/agent/mcp/xmlBridge.js +371 -0
- package/build/agent/mockProvider.js +53 -0
- package/build/agent/probeTool.js +257 -0
- package/build/agent/schemaUtils.js +1726 -0
- package/build/agent/simpleTelemetry.js +267 -0
- package/build/agent/telemetry.js +225 -0
- package/build/agent/tokenCounter.js +395 -0
- package/build/agent/tools.js +163 -0
- package/build/cli.js +49 -0
- package/build/delegate.js +267 -0
- package/build/directory-resolver.js +237 -0
- package/build/downloader.js +750 -0
- package/build/extract.js +149 -0
- package/build/index.js +70 -0
- package/build/mcp/index.js +514 -0
- package/build/mcp/index.ts +608 -0
- package/build/query.js +116 -0
- package/build/search.js +247 -0
- package/build/tools/common.js +410 -0
- package/build/tools/index.js +40 -0
- package/build/tools/langchain.js +88 -0
- package/build/tools/system-message.js +121 -0
- package/build/tools/vercel.js +271 -0
- package/build/utils/file-lister.js +193 -0
- package/build/utils.js +128 -0
- package/cjs/agent/ProbeAgent.cjs +5829 -0
- package/cjs/index.cjs +6217 -0
- package/cjs/package.json +3 -0
- package/index.d.ts +401 -0
- package/package.json +114 -0
- package/scripts/postinstall.js +172 -0
- package/src/agent/ProbeAgent.d.ts +199 -0
- package/src/agent/ProbeAgent.js +1486 -0
- package/src/agent/acp/README.md +347 -0
- package/src/agent/acp/connection.js +237 -0
- package/src/agent/acp/connection.test.js +311 -0
- package/src/agent/acp/examples/simple-client.js +212 -0
- package/src/agent/acp/examples/tool-lifecycle.js +230 -0
- package/src/agent/acp/final-test.js +173 -0
- package/src/agent/acp/index.js +5 -0
- package/src/agent/acp/integration.test.js +385 -0
- package/src/agent/acp/manual-test.js +410 -0
- package/src/agent/acp/protocol-test.js +190 -0
- package/src/agent/acp/server.js +448 -0
- package/src/agent/acp/server.test.js +371 -0
- package/src/agent/acp/test-runner.js +216 -0
- package/src/agent/acp/test-utils/README.md +315 -0
- package/src/agent/acp/test-utils/acp-tester.js +484 -0
- package/src/agent/acp/test-utils/mock-acp-client.js +434 -0
- package/src/agent/acp/tools.js +368 -0
- package/src/agent/acp/tools.test.js +334 -0
- package/src/agent/acp/types.js +218 -0
- package/src/agent/acp/types.test.js +327 -0
- package/src/agent/appTracer.js +360 -0
- package/src/agent/fileSpanExporter.js +169 -0
- package/src/agent/index.js +813 -0
- package/src/agent/mcp/client.js +338 -0
- package/src/agent/mcp/config.js +313 -0
- package/src/agent/mcp/index.js +64 -0
- package/src/agent/mcp/xmlBridge.js +371 -0
- package/src/agent/mockProvider.js +53 -0
- package/src/agent/probeTool.js +257 -0
- package/src/agent/schemaUtils.js +1726 -0
- package/src/agent/simpleTelemetry.js +267 -0
- package/src/agent/telemetry.js +225 -0
- package/src/agent/tokenCounter.js +395 -0
- package/src/agent/tools.js +163 -0
- package/src/cli.js +49 -0
- package/src/delegate.js +267 -0
- package/src/directory-resolver.js +237 -0
- package/src/downloader.js +750 -0
- package/src/extract.js +149 -0
- package/src/index.js +70 -0
- package/src/mcp/index.ts +608 -0
- package/src/query.js +116 -0
- package/src/search.js +247 -0
- package/src/tools/common.js +410 -0
- package/src/tools/index.js +40 -0
- package/src/tools/langchain.js +88 -0
- package/src/tools/system-message.js +121 -0
- package/src/tools/vercel.js +271 -0
- package/src/utils/file-lister.js +193 -0
- package/src/utils.js +128 -0
package/build/extract.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract functionality for the probe package
|
|
3
|
+
* @module extract
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { exec } from 'child_process';
|
|
7
|
+
import { promisify } from 'util';
|
|
8
|
+
import { getBinaryPath, buildCliArgs, escapeString } from './utils.js';
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Flag mapping for extract options
|
|
14
|
+
* Maps option keys to command-line flags
|
|
15
|
+
*/
|
|
16
|
+
const EXTRACT_FLAG_MAP = {
|
|
17
|
+
allowTests: '--allow-tests',
|
|
18
|
+
contextLines: '--context',
|
|
19
|
+
format: '--format',
|
|
20
|
+
inputFile: '--input-file'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extract code blocks from files
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} options - Extract options
|
|
27
|
+
* @param {string[]} [options.files] - Files to extract from (can include line numbers with colon, e.g., "/path/to/file.rs:10")
|
|
28
|
+
* @param {string} [options.inputFile] - Path to a file containing unstructured text to extract file paths from
|
|
29
|
+
* @param {boolean} [options.allowTests] - Include test files
|
|
30
|
+
* @param {number} [options.contextLines] - Number of context lines to include
|
|
31
|
+
* @param {string} [options.format] - Output format ('markdown', 'plain', 'json')
|
|
32
|
+
* @param {Object} [options.binaryOptions] - Options for getting the binary
|
|
33
|
+
* @param {boolean} [options.binaryOptions.forceDownload] - Force download even if binary exists
|
|
34
|
+
* @param {string} [options.binaryOptions.version] - Specific version to download
|
|
35
|
+
* @param {boolean} [options.json] - Return results as parsed JSON instead of string
|
|
36
|
+
* @returns {Promise<string|Object>} - Extracted code as string or parsed JSON
|
|
37
|
+
* @throws {Error} If the extraction fails
|
|
38
|
+
*/
|
|
39
|
+
export async function extract(options) {
|
|
40
|
+
if (!options) {
|
|
41
|
+
throw new Error('Options object is required');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Either files or inputFile must be provided
|
|
45
|
+
if ((!options.files || !Array.isArray(options.files) || options.files.length === 0) && !options.inputFile) {
|
|
46
|
+
throw new Error('Either files array or inputFile must be provided');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get the binary path
|
|
50
|
+
const binaryPath = await getBinaryPath(options.binaryOptions || {});
|
|
51
|
+
|
|
52
|
+
// Build CLI arguments from options
|
|
53
|
+
const cliArgs = buildCliArgs(options, EXTRACT_FLAG_MAP);
|
|
54
|
+
|
|
55
|
+
// If json option is true, override format to json
|
|
56
|
+
if (options.json && !options.format) {
|
|
57
|
+
cliArgs.push('--format', 'json');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add files as positional arguments if provided
|
|
61
|
+
if (options.files && Array.isArray(options.files) && options.files.length > 0) {
|
|
62
|
+
for (const file of options.files) {
|
|
63
|
+
cliArgs.push(escapeString(file));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Create a single log record with all extract parameters (only in debug mode)
|
|
68
|
+
if (process.env.DEBUG === '1') {
|
|
69
|
+
let logMessage = `\nExtract:`;
|
|
70
|
+
if (options.files && options.files.length > 0) {
|
|
71
|
+
logMessage += ` files="${options.files.join(', ')}"`;
|
|
72
|
+
}
|
|
73
|
+
if (options.inputFile) logMessage += ` inputFile="${options.inputFile}"`;
|
|
74
|
+
if (options.allowTests) logMessage += " allowTests=true";
|
|
75
|
+
if (options.contextLines) logMessage += ` contextLines=${options.contextLines}`;
|
|
76
|
+
if (options.format) logMessage += ` format=${options.format}`;
|
|
77
|
+
if (options.json) logMessage += " json=true";
|
|
78
|
+
console.error(logMessage);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Execute command
|
|
82
|
+
const command = `${binaryPath} extract ${cliArgs.join(' ')}`;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const { stdout, stderr } = await execAsync(command);
|
|
86
|
+
|
|
87
|
+
if (stderr) {
|
|
88
|
+
console.error(`stderr: ${stderr}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Parse the output to extract token usage information
|
|
92
|
+
let tokenUsage = {
|
|
93
|
+
requestTokens: 0,
|
|
94
|
+
responseTokens: 0,
|
|
95
|
+
totalTokens: 0
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Calculate approximate request tokens
|
|
99
|
+
if (options.files && Array.isArray(options.files)) {
|
|
100
|
+
tokenUsage.requestTokens = options.files.join(' ').length / 4;
|
|
101
|
+
} else if (options.inputFile) {
|
|
102
|
+
tokenUsage.requestTokens = options.inputFile.length / 4;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Try to extract token information from the output
|
|
106
|
+
if (stdout.includes('Total tokens returned:')) {
|
|
107
|
+
const tokenMatch = stdout.match(/Total tokens returned: (\d+)/);
|
|
108
|
+
if (tokenMatch && tokenMatch[1]) {
|
|
109
|
+
tokenUsage.responseTokens = parseInt(tokenMatch[1], 10);
|
|
110
|
+
tokenUsage.totalTokens = tokenUsage.requestTokens + tokenUsage.responseTokens;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Add token usage information to the output
|
|
115
|
+
let output = stdout;
|
|
116
|
+
|
|
117
|
+
// Add token usage information at the end if not already present
|
|
118
|
+
if (!output.includes('Token Usage:')) {
|
|
119
|
+
output += `\nToken Usage:\n Request tokens: ${tokenUsage.requestTokens}\n Response tokens: ${tokenUsage.responseTokens}\n Total tokens: ${tokenUsage.totalTokens}\n`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Parse JSON if requested or if format is json
|
|
123
|
+
if (options.json || options.format === 'json') {
|
|
124
|
+
try {
|
|
125
|
+
const jsonOutput = JSON.parse(stdout);
|
|
126
|
+
|
|
127
|
+
// Add token usage to JSON output
|
|
128
|
+
if (!jsonOutput.token_usage) {
|
|
129
|
+
jsonOutput.token_usage = {
|
|
130
|
+
request_tokens: tokenUsage.requestTokens,
|
|
131
|
+
response_tokens: tokenUsage.responseTokens,
|
|
132
|
+
total_tokens: tokenUsage.totalTokens
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return jsonOutput;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('Error parsing JSON output:', error);
|
|
139
|
+
return output; // Fall back to string output with token usage
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return output;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
// Enhance error message with command details
|
|
146
|
+
const errorMessage = `Error executing extract command: ${error.message}\nCommand: ${command}`;
|
|
147
|
+
throw new Error(errorMessage);
|
|
148
|
+
}
|
|
149
|
+
}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @probelabs/probe - Node.js wrapper for the probe code search tool
|
|
3
|
+
*
|
|
4
|
+
* This module provides JavaScript functions that wrap the probe binary functionality,
|
|
5
|
+
* making it easy to use probe's powerful code search capabilities in Node.js scripts.
|
|
6
|
+
*
|
|
7
|
+
* @module @probelabs/probe
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { search } from './search.js';
|
|
11
|
+
import { query } from './query.js';
|
|
12
|
+
import { extract } from './extract.js';
|
|
13
|
+
import { delegate } from './delegate.js';
|
|
14
|
+
import { getBinaryPath, setBinaryPath } from './utils.js';
|
|
15
|
+
import * as tools from './tools/index.js';
|
|
16
|
+
import { listFilesByLevel } from './utils/file-lister.js';
|
|
17
|
+
import { DEFAULT_SYSTEM_MESSAGE } from './tools/system-message.js';
|
|
18
|
+
import {
|
|
19
|
+
searchSchema,
|
|
20
|
+
querySchema,
|
|
21
|
+
extractSchema,
|
|
22
|
+
delegateSchema,
|
|
23
|
+
attemptCompletionSchema,
|
|
24
|
+
searchToolDefinition,
|
|
25
|
+
queryToolDefinition,
|
|
26
|
+
extractToolDefinition,
|
|
27
|
+
delegateToolDefinition,
|
|
28
|
+
attemptCompletionToolDefinition,
|
|
29
|
+
parseXmlToolCall
|
|
30
|
+
} from './tools/common.js';
|
|
31
|
+
import { searchTool, queryTool, extractTool, delegateTool } from './tools/vercel.js';
|
|
32
|
+
import { ProbeAgent } from './agent/ProbeAgent.js';
|
|
33
|
+
import { SimpleTelemetry, SimpleAppTracer, initializeSimpleTelemetryFromOptions } from './agent/simpleTelemetry.js';
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
search,
|
|
37
|
+
query,
|
|
38
|
+
extract,
|
|
39
|
+
delegate,
|
|
40
|
+
getBinaryPath,
|
|
41
|
+
setBinaryPath,
|
|
42
|
+
listFilesByLevel,
|
|
43
|
+
tools,
|
|
44
|
+
DEFAULT_SYSTEM_MESSAGE,
|
|
45
|
+
// Export AI Agent (NEW!)
|
|
46
|
+
ProbeAgent,
|
|
47
|
+
// Export telemetry classes
|
|
48
|
+
SimpleTelemetry,
|
|
49
|
+
SimpleAppTracer,
|
|
50
|
+
initializeSimpleTelemetryFromOptions,
|
|
51
|
+
// Export tool generators directly
|
|
52
|
+
searchTool,
|
|
53
|
+
queryTool,
|
|
54
|
+
extractTool,
|
|
55
|
+
delegateTool,
|
|
56
|
+
// Export schemas
|
|
57
|
+
searchSchema,
|
|
58
|
+
querySchema,
|
|
59
|
+
extractSchema,
|
|
60
|
+
delegateSchema,
|
|
61
|
+
attemptCompletionSchema,
|
|
62
|
+
// Export tool definitions
|
|
63
|
+
searchToolDefinition,
|
|
64
|
+
queryToolDefinition,
|
|
65
|
+
extractToolDefinition,
|
|
66
|
+
delegateToolDefinition,
|
|
67
|
+
attemptCompletionToolDefinition,
|
|
68
|
+
// Export parser function
|
|
69
|
+
parseXmlToolCall
|
|
70
|
+
};
|