@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.
Files changed (115) hide show
  1. package/README.md +583 -0
  2. package/bin/.gitkeep +0 -0
  3. package/bin/probe +158 -0
  4. package/bin/probe-binary +0 -0
  5. package/build/agent/ProbeAgent.d.ts +199 -0
  6. package/build/agent/ProbeAgent.js +1486 -0
  7. package/build/agent/acp/README.md +347 -0
  8. package/build/agent/acp/connection.js +237 -0
  9. package/build/agent/acp/connection.test.js +311 -0
  10. package/build/agent/acp/examples/simple-client.js +212 -0
  11. package/build/agent/acp/examples/tool-lifecycle.js +230 -0
  12. package/build/agent/acp/final-test.js +173 -0
  13. package/build/agent/acp/index.js +5 -0
  14. package/build/agent/acp/integration.test.js +385 -0
  15. package/build/agent/acp/manual-test.js +410 -0
  16. package/build/agent/acp/protocol-test.js +190 -0
  17. package/build/agent/acp/server.js +448 -0
  18. package/build/agent/acp/server.test.js +371 -0
  19. package/build/agent/acp/test-runner.js +216 -0
  20. package/build/agent/acp/test-utils/README.md +315 -0
  21. package/build/agent/acp/test-utils/acp-tester.js +484 -0
  22. package/build/agent/acp/test-utils/mock-acp-client.js +434 -0
  23. package/build/agent/acp/tools.js +368 -0
  24. package/build/agent/acp/tools.test.js +334 -0
  25. package/build/agent/acp/types.js +218 -0
  26. package/build/agent/acp/types.test.js +327 -0
  27. package/build/agent/appTracer.js +360 -0
  28. package/build/agent/fileSpanExporter.js +169 -0
  29. package/build/agent/index.js +7426 -0
  30. package/build/agent/mcp/client.js +338 -0
  31. package/build/agent/mcp/config.js +313 -0
  32. package/build/agent/mcp/index.js +64 -0
  33. package/build/agent/mcp/xmlBridge.js +371 -0
  34. package/build/agent/mockProvider.js +53 -0
  35. package/build/agent/probeTool.js +257 -0
  36. package/build/agent/schemaUtils.js +1726 -0
  37. package/build/agent/simpleTelemetry.js +267 -0
  38. package/build/agent/telemetry.js +225 -0
  39. package/build/agent/tokenCounter.js +395 -0
  40. package/build/agent/tools.js +163 -0
  41. package/build/cli.js +49 -0
  42. package/build/delegate.js +267 -0
  43. package/build/directory-resolver.js +237 -0
  44. package/build/downloader.js +750 -0
  45. package/build/extract.js +149 -0
  46. package/build/index.js +70 -0
  47. package/build/mcp/index.js +514 -0
  48. package/build/mcp/index.ts +608 -0
  49. package/build/query.js +116 -0
  50. package/build/search.js +247 -0
  51. package/build/tools/common.js +410 -0
  52. package/build/tools/index.js +40 -0
  53. package/build/tools/langchain.js +88 -0
  54. package/build/tools/system-message.js +121 -0
  55. package/build/tools/vercel.js +271 -0
  56. package/build/utils/file-lister.js +193 -0
  57. package/build/utils.js +128 -0
  58. package/cjs/agent/ProbeAgent.cjs +5829 -0
  59. package/cjs/index.cjs +6217 -0
  60. package/cjs/package.json +3 -0
  61. package/index.d.ts +401 -0
  62. package/package.json +114 -0
  63. package/scripts/postinstall.js +172 -0
  64. package/src/agent/ProbeAgent.d.ts +199 -0
  65. package/src/agent/ProbeAgent.js +1486 -0
  66. package/src/agent/acp/README.md +347 -0
  67. package/src/agent/acp/connection.js +237 -0
  68. package/src/agent/acp/connection.test.js +311 -0
  69. package/src/agent/acp/examples/simple-client.js +212 -0
  70. package/src/agent/acp/examples/tool-lifecycle.js +230 -0
  71. package/src/agent/acp/final-test.js +173 -0
  72. package/src/agent/acp/index.js +5 -0
  73. package/src/agent/acp/integration.test.js +385 -0
  74. package/src/agent/acp/manual-test.js +410 -0
  75. package/src/agent/acp/protocol-test.js +190 -0
  76. package/src/agent/acp/server.js +448 -0
  77. package/src/agent/acp/server.test.js +371 -0
  78. package/src/agent/acp/test-runner.js +216 -0
  79. package/src/agent/acp/test-utils/README.md +315 -0
  80. package/src/agent/acp/test-utils/acp-tester.js +484 -0
  81. package/src/agent/acp/test-utils/mock-acp-client.js +434 -0
  82. package/src/agent/acp/tools.js +368 -0
  83. package/src/agent/acp/tools.test.js +334 -0
  84. package/src/agent/acp/types.js +218 -0
  85. package/src/agent/acp/types.test.js +327 -0
  86. package/src/agent/appTracer.js +360 -0
  87. package/src/agent/fileSpanExporter.js +169 -0
  88. package/src/agent/index.js +813 -0
  89. package/src/agent/mcp/client.js +338 -0
  90. package/src/agent/mcp/config.js +313 -0
  91. package/src/agent/mcp/index.js +64 -0
  92. package/src/agent/mcp/xmlBridge.js +371 -0
  93. package/src/agent/mockProvider.js +53 -0
  94. package/src/agent/probeTool.js +257 -0
  95. package/src/agent/schemaUtils.js +1726 -0
  96. package/src/agent/simpleTelemetry.js +267 -0
  97. package/src/agent/telemetry.js +225 -0
  98. package/src/agent/tokenCounter.js +395 -0
  99. package/src/agent/tools.js +163 -0
  100. package/src/cli.js +49 -0
  101. package/src/delegate.js +267 -0
  102. package/src/directory-resolver.js +237 -0
  103. package/src/downloader.js +750 -0
  104. package/src/extract.js +149 -0
  105. package/src/index.js +70 -0
  106. package/src/mcp/index.ts +608 -0
  107. package/src/query.js +116 -0
  108. package/src/search.js +247 -0
  109. package/src/tools/common.js +410 -0
  110. package/src/tools/index.js +40 -0
  111. package/src/tools/langchain.js +88 -0
  112. package/src/tools/system-message.js +121 -0
  113. package/src/tools/vercel.js +271 -0
  114. package/src/utils/file-lister.js +193 -0
  115. package/src/utils.js +128 -0
@@ -0,0 +1,448 @@
1
+ // ACP Server - Main server implementation for Agent Client Protocol
2
+ import { randomUUID } from 'crypto';
3
+ import { ACPConnection } from './connection.js';
4
+ import { ProbeAgent } from '../ProbeAgent.js';
5
+ import {
6
+ ACP_PROTOCOL_VERSION,
7
+ RequestMethod,
8
+ NotificationMethod,
9
+ ToolCallStatus,
10
+ ToolCallKind,
11
+ ErrorCode,
12
+ SessionMode,
13
+ createTextContent,
14
+ createToolCallProgress
15
+ } from './types.js';
16
+
17
+ /**
18
+ * ACP Session represents a conversation context
19
+ */
20
+ class ACPSession {
21
+ constructor(id, mode = SessionMode.NORMAL) {
22
+ this.id = id;
23
+ this.mode = mode;
24
+ this.agent = null;
25
+ this.history = [];
26
+ this.toolCalls = new Map();
27
+ this.createdAt = new Date().toISOString();
28
+ this.updatedAt = this.createdAt;
29
+ }
30
+
31
+ /**
32
+ * Get or create ProbeAgent for this session
33
+ */
34
+ getAgent(config = {}) {
35
+ if (!this.agent) {
36
+ this.agent = new ProbeAgent({
37
+ sessionId: this.id,
38
+ ...config
39
+ });
40
+ }
41
+ return this.agent;
42
+ }
43
+
44
+ /**
45
+ * Update session timestamp
46
+ */
47
+ touch() {
48
+ this.updatedAt = new Date().toISOString();
49
+ }
50
+
51
+ /**
52
+ * Serialize session state
53
+ */
54
+ toJSON() {
55
+ return {
56
+ id: this.id,
57
+ mode: this.mode,
58
+ historyLength: this.history.length,
59
+ toolCallsCount: this.toolCalls.size,
60
+ createdAt: this.createdAt,
61
+ updatedAt: this.updatedAt
62
+ };
63
+ }
64
+ }
65
+
66
+ /**
67
+ * ACP Server - handles Agent Client Protocol communication
68
+ */
69
+ export class ACPServer {
70
+ constructor(options = {}) {
71
+ this.options = {
72
+ debug: process.env.DEBUG === '1',
73
+ provider: options.provider || null,
74
+ model: options.model || null,
75
+ path: options.path || process.cwd(),
76
+ allowEdit: options.allowEdit || false,
77
+ ...options
78
+ };
79
+
80
+ this.connection = null;
81
+ this.sessions = new Map();
82
+ this.capabilities = this.getCapabilities();
83
+ this.initialized = false;
84
+
85
+ if (this.options.debug) {
86
+ console.error('[ACP] Server created with options:', this.options);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Get server capabilities
92
+ */
93
+ getCapabilities() {
94
+ return {
95
+ tools: [
96
+ {
97
+ name: 'search',
98
+ description: 'Search for code patterns and content in the repository',
99
+ kind: ToolCallKind.search
100
+ },
101
+ {
102
+ name: 'query',
103
+ description: 'Perform structural queries using AST patterns',
104
+ kind: ToolCallKind.query
105
+ },
106
+ {
107
+ name: 'extract',
108
+ description: 'Extract specific code blocks from files',
109
+ kind: ToolCallKind.extract
110
+ }
111
+ ],
112
+ sessionManagement: true,
113
+ streaming: true,
114
+ permissions: this.options.allowEdit
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Start the ACP server
120
+ */
121
+ async start() {
122
+ this.connection = new ACPConnection(process.stdin, process.stdout);
123
+
124
+ // Set up message handlers
125
+ this.connection.on('request', this.handleRequest.bind(this));
126
+ this.connection.on('notification', this.handleNotification.bind(this));
127
+ this.connection.on('error', this.handleError.bind(this));
128
+ this.connection.on('disconnect', this.handleDisconnect.bind(this));
129
+
130
+ // Start the connection
131
+ this.connection.start();
132
+
133
+ if (this.options.debug) {
134
+ console.error('[ACP] Server started and listening for messages');
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Handle incoming requests
140
+ */
141
+ async handleRequest(message) {
142
+ const { method, params, id } = message;
143
+
144
+ try {
145
+ let result;
146
+
147
+ switch (method) {
148
+ case RequestMethod.INITIALIZE:
149
+ result = await this.handleInitialize(params);
150
+ break;
151
+
152
+ case RequestMethod.NEW_SESSION:
153
+ result = await this.handleNewSession(params);
154
+ break;
155
+
156
+ case RequestMethod.LOAD_SESSION:
157
+ result = await this.handleLoadSession(params);
158
+ break;
159
+
160
+ case RequestMethod.SET_SESSION_MODE:
161
+ result = await this.handleSetSessionMode(params);
162
+ break;
163
+
164
+ case RequestMethod.PROMPT:
165
+ result = await this.handlePrompt(params);
166
+ break;
167
+
168
+ case RequestMethod.CANCEL:
169
+ result = await this.handleCancel(params);
170
+ break;
171
+
172
+ default:
173
+ throw new Error(`Unknown method: ${method}`);
174
+ }
175
+
176
+ this.connection.sendResponse(id, result);
177
+
178
+ } catch (error) {
179
+ if (this.options.debug) {
180
+ console.error(`[ACP] Error handling request ${method}:`, error);
181
+ }
182
+
183
+ let errorCode = ErrorCode.INTERNAL_ERROR;
184
+ if (error.message.includes('Unknown method')) {
185
+ errorCode = ErrorCode.METHOD_NOT_FOUND;
186
+ } else if (error.message.includes('Invalid params')) {
187
+ errorCode = ErrorCode.INVALID_PARAMS;
188
+ }
189
+
190
+ this.connection.sendError(id, errorCode, error.message);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Handle notifications
196
+ */
197
+ async handleNotification(message) {
198
+ const { method, params } = message;
199
+
200
+ if (this.options.debug) {
201
+ console.error(`[ACP] Received notification: ${method}`, params);
202
+ }
203
+
204
+ // Handle notifications here if needed
205
+ // For now, just log them
206
+ }
207
+
208
+ /**
209
+ * Handle initialize request
210
+ */
211
+ async handleInitialize(params) {
212
+ if (!params || !params.protocolVersion) {
213
+ throw new Error('Invalid params: protocolVersion required');
214
+ }
215
+
216
+ if (params.protocolVersion !== ACP_PROTOCOL_VERSION) {
217
+ throw new Error(`Unsupported protocol version: ${params.protocolVersion}`);
218
+ }
219
+
220
+ this.initialized = true;
221
+
222
+ if (this.options.debug) {
223
+ console.error('[ACP] Initialized with protocol version:', params.protocolVersion);
224
+ }
225
+
226
+ return {
227
+ protocolVersion: ACP_PROTOCOL_VERSION,
228
+ serverInfo: {
229
+ name: 'probe-agent-acp',
230
+ version: '1.0.0',
231
+ description: 'Probe AI agent with code search capabilities'
232
+ },
233
+ capabilities: this.capabilities
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Handle new session request
239
+ */
240
+ async handleNewSession(params) {
241
+ const sessionId = params?.sessionId || randomUUID();
242
+ const mode = params?.mode || SessionMode.NORMAL;
243
+
244
+ const session = new ACPSession(sessionId, mode);
245
+ this.sessions.set(sessionId, session);
246
+
247
+ if (this.options.debug) {
248
+ console.error(`[ACP] Created new session: ${sessionId} (mode: ${mode})`);
249
+ }
250
+
251
+ return {
252
+ sessionId,
253
+ mode,
254
+ createdAt: session.createdAt
255
+ };
256
+ }
257
+
258
+ /**
259
+ * Handle load session request
260
+ */
261
+ async handleLoadSession(params) {
262
+ if (!params || !params.sessionId) {
263
+ throw new Error('Invalid params: sessionId required');
264
+ }
265
+
266
+ const session = this.sessions.get(params.sessionId);
267
+ if (!session) {
268
+ throw new Error(`Session not found: ${params.sessionId}`);
269
+ }
270
+
271
+ if (this.options.debug) {
272
+ console.error(`[ACP] Loaded session: ${params.sessionId}`);
273
+ }
274
+
275
+ return session.toJSON();
276
+ }
277
+
278
+ /**
279
+ * Handle set session mode request
280
+ */
281
+ async handleSetSessionMode(params) {
282
+ if (!params || !params.sessionId || !params.mode) {
283
+ throw new Error('Invalid params: sessionId and mode required');
284
+ }
285
+
286
+ const session = this.sessions.get(params.sessionId);
287
+ if (!session) {
288
+ throw new Error(`Session not found: ${params.sessionId}`);
289
+ }
290
+
291
+ session.mode = params.mode;
292
+ session.touch();
293
+
294
+ if (this.options.debug) {
295
+ console.error(`[ACP] Set session mode: ${params.sessionId} -> ${params.mode}`);
296
+ }
297
+
298
+ // Notify about session update
299
+ if (this.connection) {
300
+ this.connection.sendNotification(NotificationMethod.SESSION_UPDATED, {
301
+ sessionId: params.sessionId,
302
+ mode: params.mode
303
+ });
304
+ }
305
+
306
+ return { success: true };
307
+ }
308
+
309
+ /**
310
+ * Handle prompt request - main AI interaction
311
+ */
312
+ async handlePrompt(params) {
313
+ if (!params || !params.sessionId || !params.message) {
314
+ throw new Error('Invalid params: sessionId and message required');
315
+ }
316
+
317
+ const session = this.sessions.get(params.sessionId);
318
+ if (!session) {
319
+ throw new Error(`Session not found: ${params.sessionId}`);
320
+ }
321
+
322
+ session.touch();
323
+
324
+ // Get or create ProbeAgent for this session
325
+ const agent = session.getAgent({
326
+ path: this.options.path,
327
+ provider: this.options.provider,
328
+ model: this.options.model,
329
+ allowEdit: this.options.allowEdit,
330
+ debug: this.options.debug
331
+ });
332
+
333
+ if (this.options.debug) {
334
+ console.error(`[ACP] Processing prompt for session ${params.sessionId}:`, params.message.substring(0, 100));
335
+ }
336
+
337
+ try {
338
+ // Process the message with the ProbeAgent
339
+ const response = await agent.answer(params.message);
340
+
341
+ // Add to session history
342
+ session.history.push(
343
+ { role: 'user', content: params.message, timestamp: new Date().toISOString() },
344
+ { role: 'assistant', content: response, timestamp: new Date().toISOString() }
345
+ );
346
+
347
+ // Send the response as content blocks
348
+ return {
349
+ content: [createTextContent(response)],
350
+ sessionId: params.sessionId,
351
+ timestamp: new Date().toISOString()
352
+ };
353
+
354
+ } catch (error) {
355
+ if (this.options.debug) {
356
+ console.error(`[ACP] Error processing prompt:`, error);
357
+ }
358
+
359
+ // Return error as content
360
+ return {
361
+ content: [createTextContent(`Error: ${error.message}`)],
362
+ sessionId: params.sessionId,
363
+ timestamp: new Date().toISOString(),
364
+ error: true
365
+ };
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Handle cancel request
371
+ */
372
+ async handleCancel(params) {
373
+ if (!params || !params.sessionId) {
374
+ throw new Error('Invalid params: sessionId required');
375
+ }
376
+
377
+ const session = this.sessions.get(params.sessionId);
378
+ if (session && session.agent) {
379
+ session.agent.cancel();
380
+ }
381
+
382
+ if (this.options.debug) {
383
+ console.error(`[ACP] Cancelled operations for session: ${params.sessionId}`);
384
+ }
385
+
386
+ return { success: true };
387
+ }
388
+
389
+ /**
390
+ * Handle connection errors
391
+ */
392
+ handleError(error) {
393
+ if (this.options.debug) {
394
+ console.error('[ACP] Connection error:', error);
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Handle disconnection
400
+ */
401
+ handleDisconnect() {
402
+ if (this.options.debug) {
403
+ console.error('[ACP] Client disconnected');
404
+ }
405
+
406
+ // Clean up sessions and resources
407
+ for (const session of this.sessions.values()) {
408
+ if (session.agent) {
409
+ session.agent.cancel();
410
+ }
411
+ }
412
+
413
+ this.sessions.clear();
414
+ }
415
+
416
+ /**
417
+ * Send tool call progress notification
418
+ */
419
+ sendToolCallProgress(sessionId, toolCallId, status, result = null, error = null) {
420
+ const progress = createToolCallProgress(toolCallId, status, result, error);
421
+
422
+ this.connection.sendNotification(NotificationMethod.TOOL_CALL_PROGRESS, {
423
+ sessionId,
424
+ ...progress
425
+ });
426
+ }
427
+
428
+ /**
429
+ * Send message chunk for streaming
430
+ */
431
+ sendMessageChunk(sessionId, chunk) {
432
+ this.connection.sendNotification(NotificationMethod.MESSAGE_CHUNK, {
433
+ sessionId,
434
+ chunk
435
+ });
436
+ }
437
+
438
+ /**
439
+ * Get session statistics
440
+ */
441
+ getStats() {
442
+ return {
443
+ sessions: this.sessions.size,
444
+ initialized: this.initialized,
445
+ capabilities: this.capabilities
446
+ };
447
+ }
448
+ }