polydev-ai 1.8.10 → 1.8.11

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 (2) hide show
  1. package/lib/cliManager.js +69 -31
  2. package/package.json +1 -1
package/lib/cliManager.js CHANGED
@@ -443,38 +443,76 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
443
443
 
444
444
  if (providerId === 'codex_cli') {
445
445
  const execArgs = promptVariants.find(args => args.includes('exec')) || promptVariants[0];
446
- try {
447
- const result = await this.executeCodexExec(provider.command, execArgs, prompt, timeoutMs, model);
448
- // executeCodexExec now returns { content, detectedModel, rawStdout, rawStderr }
449
- const content = result.content;
450
- const detectedModel = result.detectedModel;
451
-
452
- // Use detected model if available, otherwise fall back to what was requested or 'cli_default'
453
- const actualModel = detectedModel || model || 'cli_default';
454
-
455
- if (detectedModel && detectedModel !== model) {
456
- console.log(`[Polydev CLI] Codex CLI detected model: ${detectedModel} (requested: ${model || 'none'})`);
446
+
447
+ // Try with specified model first, fallback to CLI default if model fails
448
+ let modelToUse = model;
449
+ let attempts = 0;
450
+ const maxAttempts = model ? 2 : 1; // Only retry if model was specified
451
+
452
+ while (attempts < maxAttempts) {
453
+ attempts++;
454
+ try {
455
+ const result = await this.executeCodexExec(provider.command, execArgs, prompt, timeoutMs, modelToUse);
456
+ // executeCodexExec now returns { content, detectedModel, rawStdout, rawStderr }
457
+ const content = result.content;
458
+ const detectedModel = result.detectedModel;
459
+
460
+ // Check if the response contains a model error
461
+ const modelError = content && (
462
+ content.includes('model is not supported') ||
463
+ content.includes('model not found') ||
464
+ content.includes('invalid model') ||
465
+ content.includes("doesn't exist")
466
+ );
467
+
468
+ if (modelError && modelToUse && attempts < maxAttempts) {
469
+ console.log(`[Polydev CLI] Model '${modelToUse}' failed for Codex CLI, retrying with CLI default...`);
470
+ modelToUse = null; // Retry without model flag
471
+ continue;
472
+ }
473
+
474
+ // Use detected model if available, otherwise fall back to what was requested or 'cli_default'
475
+ const actualModel = detectedModel || modelToUse || 'cli_default';
476
+
477
+ if (detectedModel && detectedModel !== model) {
478
+ console.log(`[Polydev CLI] Codex CLI detected model: ${detectedModel} (requested: ${model || 'none'})`);
479
+ }
480
+
481
+ return {
482
+ success: true,
483
+ content,
484
+ tokens_used: this.estimateTokens(prompt + content),
485
+ latency_ms: Date.now() - startTime,
486
+ provider: providerId,
487
+ mode: 'args',
488
+ model_used: actualModel,
489
+ timestamp: new Date()
490
+ };
491
+ } catch (error) {
492
+ const errorMsg = error instanceof Error ? error.message : String(error);
493
+
494
+ // Check if error is model-related and we can retry
495
+ const isModelError = errorMsg.includes('model') && (
496
+ errorMsg.includes('not supported') ||
497
+ errorMsg.includes('not found') ||
498
+ errorMsg.includes('invalid')
499
+ );
500
+
501
+ if (isModelError && modelToUse && attempts < maxAttempts) {
502
+ console.log(`[Polydev CLI] Model '${modelToUse}' error for Codex CLI, retrying with CLI default...`);
503
+ modelToUse = null; // Retry without model flag
504
+ continue;
505
+ }
506
+
507
+ return {
508
+ success: false,
509
+ error: `CLI execution failed: ${errorMsg}`,
510
+ latency_ms: Date.now() - startTime,
511
+ provider: providerId,
512
+ mode,
513
+ timestamp: new Date()
514
+ };
457
515
  }
458
-
459
- return {
460
- success: true,
461
- content,
462
- tokens_used: this.estimateTokens(prompt + content),
463
- latency_ms: Date.now() - startTime,
464
- provider: providerId,
465
- mode: 'args',
466
- model_used: actualModel,
467
- timestamp: new Date()
468
- };
469
- } catch (error) {
470
- return {
471
- success: false,
472
- error: `CLI execution failed: ${error instanceof Error ? error.message : String(error)}`,
473
- latency_ms: Date.now() - startTime,
474
- provider: providerId,
475
- mode,
476
- timestamp: new Date()
477
- };
478
516
  }
479
517
  }
480
518
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.10",
3
+ "version": "1.8.11",
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",