polydev-ai 1.2.0 → 1.2.1

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/mcp/manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-perspectives",
3
- "version": "1.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "Agentic workflow assistant - get diverse perspectives from multiple LLMs when stuck or need enhanced reasoning",
5
5
  "author": "Polydev AI",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@
3
3
  // Lightweight stdio wrapper with local CLI functionality and remote Polydev MCP server fallback
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
- const CLIManager = require('../lib/cliManager').default;
6
+ const { CLIManager } = require('../lib/cliManager');
7
7
 
8
8
  class StdioMCPWrapper {
9
9
  constructor() {
@@ -204,7 +204,7 @@ class StdioMCPWrapper {
204
204
  const providerId = args.provider_id; // Optional - detect specific provider
205
205
 
206
206
  // Force detection using CLI Manager (no remote API calls)
207
- const results = await this.cliManager.forceCliDetection(null, providerId);
207
+ const results = await this.cliManager.forceCliDetection(providerId);
208
208
 
209
209
  // Save status locally to file-based cache
210
210
  await this.saveLocalCliStatus(results);
@@ -241,13 +241,13 @@ class StdioMCPWrapper {
241
241
  if (providerId) {
242
242
  // Get specific provider status
243
243
  const status = await this.cliManager.getCliStatus(providerId);
244
- results[providerId] = status;
244
+ results = status;
245
245
  } else {
246
246
  // Get all providers status
247
- const providers = this.cliManager.getProviders();
247
+ const providers = this.cliManager.getAvailableProviders();
248
248
  for (const provider of providers) {
249
249
  const status = await this.cliManager.getCliStatus(provider.id);
250
- results[provider.id] = status;
250
+ results[provider.id] = status[provider.id];
251
251
  }
252
252
  }
253
253
 
@@ -271,41 +271,55 @@ class StdioMCPWrapper {
271
271
  }
272
272
 
273
273
  /**
274
- * Local CLI prompt sending
274
+ * Local CLI prompt sending with remote perspectives fallback/supplement
275
275
  */
276
276
  async localSendCliPrompt(args) {
277
- console.error(`[Stdio Wrapper] Local CLI prompt sending`);
277
+ console.error(`[Stdio Wrapper] Local CLI prompt sending with perspectives`);
278
278
 
279
279
  try {
280
- const { provider_id, prompt, mode = 'args', timeout_ms = 30000 } = args;
280
+ let { provider_id, prompt, mode = 'args', timeout_ms = 30000 } = args;
281
281
 
282
- if (!provider_id || !prompt) {
283
- throw new Error('provider_id and prompt are required');
282
+ if (!prompt) {
283
+ throw new Error('prompt is required');
284
284
  }
285
285
 
286
- // Send prompt using CLI Manager (local execution)
287
- const response = await this.cliManager.sendCliPrompt(
288
- provider_id,
289
- prompt,
290
- mode,
291
- timeout_ms
292
- );
286
+ // Auto-select best available provider if none specified
287
+ if (!provider_id) {
288
+ provider_id = await this.selectBestProvider();
289
+ console.error(`[Stdio Wrapper] Auto-selected provider: ${provider_id}`);
290
+ }
293
291
 
294
- // Record usage locally (file-based analytics)
295
- await this.recordLocalUsage(provider_id, prompt, response);
292
+ // Use shorter timeout for faster fallback (5 seconds instead of 30)
293
+ const gracefulTimeout = Math.min(timeout_ms, 5000);
294
+
295
+ // Start both operations concurrently for better performance
296
+ const [localResult, perspectivesResult] = await Promise.allSettled([
297
+ this.cliManager.sendCliPrompt(provider_id, prompt, mode, gracefulTimeout),
298
+ this.callPerspectivesForCli(args, null)
299
+ ]);
300
+
301
+ // Process results
302
+ const localResponse = localResult.status === 'fulfilled' ? localResult.value : {
303
+ success: false,
304
+ error: `CLI check failed: ${localResult.reason?.message || 'Unknown error'}`,
305
+ latency_ms: gracefulTimeout,
306
+ timestamp: new Date().toISOString()
307
+ };
296
308
 
297
- return {
298
- success: response.success,
299
- content: response.content,
300
- error: response.error,
301
- tokens_used: response.tokensUsed,
302
- latency_ms: response.latencyMs,
303
- provider: provider_id,
304
- mode,
305
- timestamp: new Date().toISOString(),
306
- local_only: true
309
+ const perspectivesResponse = perspectivesResult.status === 'fulfilled' ? perspectivesResult.value : {
310
+ success: false,
311
+ error: `Perspectives failed: ${perspectivesResult.reason?.message || 'Unknown error'}`,
312
+ timestamp: new Date().toISOString()
307
313
  };
308
314
 
315
+ // Record usage locally (file-based analytics) - non-blocking
316
+ this.recordLocalUsage(provider_id, prompt, localResponse).catch(err => {
317
+ console.error('[Stdio Wrapper] Usage recording failed (non-critical):', err.message);
318
+ });
319
+
320
+ // Combine results
321
+ return this.combineCliAndPerspectives(localResponse, perspectivesResponse, args);
322
+
309
323
  } catch (error) {
310
324
  console.error('[Stdio Wrapper] Local CLI prompt error:', error);
311
325
  return {
@@ -317,6 +331,166 @@ class StdioMCPWrapper {
317
331
  }
318
332
  }
319
333
 
334
+ /**
335
+ * Select the best available CLI provider automatically
336
+ */
337
+ async selectBestProvider() {
338
+ try {
339
+ const allStatus = await this.cliManager.getCliStatus();
340
+
341
+ // Priority order: claude_code > codex_cli > gemini_cli
342
+ const priorityOrder = ['claude_code', 'codex_cli', 'gemini_cli'];
343
+
344
+ for (const providerId of priorityOrder) {
345
+ const status = allStatus[providerId];
346
+ if (status && status.available && status.authenticated) {
347
+ return providerId;
348
+ }
349
+ }
350
+
351
+ // If no authenticated provider, return the first available one
352
+ for (const providerId of priorityOrder) {
353
+ const status = allStatus[providerId];
354
+ if (status && status.available) {
355
+ return providerId;
356
+ }
357
+ }
358
+
359
+ // Default fallback to claude_code (will trigger remote perspectives)
360
+ return 'claude_code';
361
+
362
+ } catch (error) {
363
+ console.error('[Stdio Wrapper] Provider selection failed, defaulting to claude_code:', error);
364
+ return 'claude_code';
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Call remote perspectives for CLI prompts
370
+ */
371
+ async callPerspectivesForCli(args, localResult) {
372
+ console.error(`[Stdio Wrapper] Calling remote perspectives for CLI prompt`);
373
+
374
+ try {
375
+ const perspectivesRequest = {
376
+ jsonrpc: '2.0',
377
+ method: 'tools/call',
378
+ params: {
379
+ name: 'get_perspectives',
380
+ arguments: {
381
+ prompt: args.prompt,
382
+ user_token: this.userToken,
383
+ // Let the remote server use user's configured preferences for models
384
+ // Don't specify models to use dashboard defaults
385
+ project_memory: 'none',
386
+ temperature: 0.7,
387
+ max_tokens: 2000
388
+ }
389
+ },
390
+ id: `perspectives-${Date.now()}`
391
+ };
392
+
393
+ const remoteResponse = await this.forwardToRemoteServer(perspectivesRequest);
394
+
395
+ if (remoteResponse.result && remoteResponse.result.content && remoteResponse.result.content[0]) {
396
+ return {
397
+ success: true,
398
+ content: remoteResponse.result.content[0].text,
399
+ timestamp: new Date().toISOString()
400
+ };
401
+ } else if (remoteResponse.error) {
402
+ return {
403
+ success: false,
404
+ error: remoteResponse.error.message || 'Remote perspectives failed',
405
+ timestamp: new Date().toISOString()
406
+ };
407
+ } else {
408
+ return {
409
+ success: false,
410
+ error: 'Unexpected remote response format',
411
+ timestamp: new Date().toISOString()
412
+ };
413
+ }
414
+ } catch (error) {
415
+ console.error('[Stdio Wrapper] Perspectives call error:', error);
416
+ return {
417
+ success: false,
418
+ error: `Perspectives request failed: ${error.message}`,
419
+ timestamp: new Date().toISOString()
420
+ };
421
+ }
422
+ }
423
+
424
+ /**
425
+ * Combine local CLI and remote perspectives results
426
+ */
427
+ combineCliAndPerspectives(localResult, perspectivesResult, args) {
428
+ const combinedResult = {
429
+ success: true,
430
+ timestamp: new Date().toISOString(),
431
+ provider: args.provider_id,
432
+ mode: args.mode,
433
+ sections: {
434
+ local: localResult,
435
+ remote: perspectivesResult
436
+ }
437
+ };
438
+
439
+ // Determine overall success and fallback status
440
+ if (localResult.success && perspectivesResult.success) {
441
+ combinedResult.content = this.formatCombinedResponse(localResult, perspectivesResult, false);
442
+ combinedResult.tokens_used = localResult.tokens_used || 0;
443
+ combinedResult.latency_ms = localResult.latency_ms || 0;
444
+ } else if (!localResult.success && perspectivesResult.success) {
445
+ // Fallback case
446
+ combinedResult.content = this.formatCombinedResponse(localResult, perspectivesResult, true);
447
+ combinedResult.fallback_used = true;
448
+ combinedResult.tokens_used = 0; // No local tokens used
449
+ } else if (localResult.success && !perspectivesResult.success) {
450
+ // Local succeeded, remote failed
451
+ combinedResult.content = this.formatCombinedResponse(localResult, perspectivesResult, false);
452
+ combinedResult.tokens_used = localResult.tokens_used || 0;
453
+ combinedResult.latency_ms = localResult.latency_ms || 0;
454
+ } else {
455
+ // Both failed
456
+ combinedResult.success = false;
457
+ combinedResult.error = `Local CLI failed: ${localResult.error}; Perspectives also failed: ${perspectivesResult.error}`;
458
+ }
459
+
460
+ return combinedResult;
461
+ }
462
+
463
+ /**
464
+ * Format combined response text
465
+ */
466
+ formatCombinedResponse(localResult, perspectivesResult, isFallback) {
467
+ let formatted = '';
468
+
469
+ if (localResult.success) {
470
+ // Local CLI succeeded
471
+ formatted += `🟢 **Local CLI Response** (${localResult.provider} - ${localResult.mode} mode)\n\n`;
472
+ formatted += `${localResult.content}\n\n`;
473
+ formatted += `*Latency: ${localResult.latency_ms || 0}ms | Tokens: ${localResult.tokens_used || 0}*\n\n`;
474
+ formatted += `---\n\n`;
475
+ } else if (isFallback) {
476
+ // Local CLI failed, using fallback
477
+ formatted += `⚠️ **Local CLI unavailable**: ${localResult.error}\n`;
478
+ formatted += `Using perspectives fallback.\n\n`;
479
+ formatted += `---\n\n`;
480
+ }
481
+
482
+ if (perspectivesResult.success) {
483
+ const title = isFallback ? '🧠 **Perspectives Fallback**' : '🧠 **Supplemental Multi-Model Perspectives**';
484
+ formatted += `${title}\n\n`;
485
+ formatted += `${perspectivesResult.content}\n\n`;
486
+ } else if (!isFallback) {
487
+ // Show remote error only if not in fallback mode
488
+ formatted += `❌ **Perspectives request failed**: ${perspectivesResult.error}\n\n`;
489
+ }
490
+
491
+ return formatted.trim();
492
+ }
493
+
320
494
  /**
321
495
  * Save CLI status to local file cache
322
496
  */
@@ -354,10 +528,20 @@ class StdioMCPWrapper {
354
528
  const polydevevDir = path.join(homeDir, '.polydev');
355
529
  const usageFile = path.join(polydevevDir, 'cli-usage.json');
356
530
 
531
+ // Ensure directory exists
532
+ if (!fs.existsSync(polydevevDir)) {
533
+ fs.mkdirSync(polydevevDir, { recursive: true });
534
+ }
535
+
357
536
  // Load existing usage data
358
537
  let usageData = [];
359
538
  if (fs.existsSync(usageFile)) {
360
- usageData = JSON.parse(fs.readFileSync(usageFile, 'utf8'));
539
+ try {
540
+ usageData = JSON.parse(fs.readFileSync(usageFile, 'utf8'));
541
+ } catch (parseError) {
542
+ console.error('[Stdio Wrapper] Failed to parse existing usage file, starting fresh:', parseError);
543
+ usageData = [];
544
+ }
361
545
  }
362
546
 
363
547
  // Add new usage record
@@ -366,8 +550,8 @@ class StdioMCPWrapper {
366
550
  provider: providerId,
367
551
  prompt_length: prompt.length,
368
552
  success: response.success,
369
- latency_ms: response.latencyMs,
370
- tokens_used: response.tokensUsed || 0
553
+ latency_ms: response.latency_ms || response.latencyMs || 0,
554
+ tokens_used: response.tokens_used || response.tokensUsed || 0
371
555
  });
372
556
 
373
557
  // Keep only last 1000 records
@@ -379,7 +563,8 @@ class StdioMCPWrapper {
379
563
  console.error(`[Stdio Wrapper] Usage recorded locally`);
380
564
 
381
565
  } catch (error) {
382
- console.error('[Stdio Wrapper] Failed to record local usage:', error);
566
+ console.error('[Stdio Wrapper] Failed to record local usage (non-critical):', error.message);
567
+ // Don't throw - this is non-critical functionality
383
568
  }
384
569
  }
385
570
 
@@ -391,8 +576,13 @@ class StdioMCPWrapper {
391
576
  return `❌ **CLI Error**\n\n${result.error}\n\n*Timestamp: ${result.timestamp}*`;
392
577
  }
393
578
 
579
+ // Handle combined CLI + perspectives response
580
+ if (result.sections) {
581
+ return result.content;
582
+ }
583
+
394
584
  if (result.content) {
395
- // Prompt response
585
+ // Standard prompt response
396
586
  return `✅ **CLI Response** (${result.provider || 'Unknown'} - ${result.mode || 'unknown'} mode)\n\n${result.content}\n\n*Latency: ${result.latency_ms || 0}ms | Tokens: ${result.tokens_used || 0} | ${result.timestamp}*`;
397
587
  } else {
398
588
  // Status/detection response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Agentic workflow assistant with CLI integration - get diverse perspectives from multiple LLMs when stuck or need enhanced reasoning",
5
5
  "keywords": [
6
6
  "mcp",
@@ -59,6 +59,7 @@
59
59
  "lucide-react": "^0.542.0",
60
60
  "marked": "^16.2.1",
61
61
  "next": "15.0.0",
62
+ "polydev-ai": "^1.2.0",
62
63
  "posthog-js": "^1.157.2",
63
64
  "react": "^18.3.1",
64
65
  "react-dom": "^18.3.1",