polydev-ai 1.8.4 → 1.8.5

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 +78 -1
  2. package/package.json +2 -2
package/lib/cliManager.js CHANGED
@@ -46,7 +46,7 @@ class CLIManager {
46
46
  chat: [],
47
47
  version: ['--version'],
48
48
  auth_status: ['--print', 'test auth'], // Use --print to test auth
49
- test_prompt: ['--print']
49
+ test_prompt: ['--print', '--output-format', 'json'] // Use JSON output to get model info
50
50
  },
51
51
  install_instructions: 'Install via: npm install -g @anthropic-ai/claude-code',
52
52
  auth_instructions: 'Authenticate with Claude Code'
@@ -510,6 +510,27 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
510
510
  );
511
511
 
512
512
  if (!result.error) {
513
+ // Special handling for Claude Code JSON output
514
+ if (providerId === 'claude_code') {
515
+ const jsonResult = this.parseClaudeCodeJsonResponse(result.stdout || '');
516
+ if (jsonResult) {
517
+ console.log(`[Polydev CLI] Claude Code detected model: ${jsonResult.model_used} (from JSON output)`);
518
+ return {
519
+ success: true,
520
+ content: jsonResult.content,
521
+ tokens_used: jsonResult.tokens_used,
522
+ latency_ms: Date.now() - startTime,
523
+ provider: providerId,
524
+ mode: 'args',
525
+ model_used: jsonResult.model_used,
526
+ cost_usd: jsonResult.cost_usd,
527
+ model_usage: jsonResult.model_usage,
528
+ timestamp: new Date()
529
+ };
530
+ }
531
+ }
532
+
533
+ // Fallback: Standard text output handling
513
534
  const content = this.cleanCliResponse(result.stdout || '');
514
535
 
515
536
  // Detect actual model from CLI output
@@ -747,6 +768,62 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
747
768
  return null; // Could not detect model from output
748
769
  }
749
770
 
771
+ // Parse Claude Code JSON response to extract model and content
772
+ parseClaudeCodeJsonResponse(stdout) {
773
+ if (!stdout || !stdout.trim()) return null;
774
+
775
+ try {
776
+ // Try to parse as JSON
777
+ const json = JSON.parse(stdout.trim());
778
+
779
+ // Check if it's a valid Claude Code response
780
+ if (json.type !== 'result' || !json.result) {
781
+ return null;
782
+ }
783
+
784
+ // Extract content
785
+ const content = json.result;
786
+
787
+ // Extract primary model from modelUsage
788
+ // Priority: Opus > Sonnet > Haiku (prefer larger models as they do the main reasoning)
789
+ let primaryModel = 'cli_default';
790
+ const modelUsage = json.modelUsage || {};
791
+ const modelNames = Object.keys(modelUsage);
792
+
793
+ if (modelNames.length === 1) {
794
+ // Only one model used
795
+ primaryModel = modelNames[0];
796
+ } else if (modelNames.length > 1) {
797
+ // Multiple models - prefer Opus > Sonnet > Haiku
798
+ const opusModel = modelNames.find(m => m.includes('opus'));
799
+ const sonnetModel = modelNames.find(m => m.includes('sonnet'));
800
+ const haikuModel = modelNames.find(m => m.includes('haiku'));
801
+
802
+ primaryModel = opusModel || sonnetModel || haikuModel || modelNames[0];
803
+ }
804
+
805
+ // Calculate total tokens
806
+ let totalTokens = 0;
807
+ for (const usage of Object.values(modelUsage)) {
808
+ totalTokens += (usage.inputTokens || 0) + (usage.outputTokens || 0) +
809
+ (usage.cacheReadInputTokens || 0) + (usage.cacheCreationInputTokens || 0);
810
+ }
811
+
812
+ return {
813
+ content,
814
+ model_used: primaryModel,
815
+ tokens_used: totalTokens || json.usage?.input_tokens + json.usage?.output_tokens || 0,
816
+ cost_usd: json.total_cost_usd || 0,
817
+ model_usage: modelUsage,
818
+ session_id: json.session_id,
819
+ duration_ms: json.duration_ms
820
+ };
821
+ } catch (e) {
822
+ // Not valid JSON, return null to fall back to text parsing
823
+ return null;
824
+ }
825
+ }
826
+
750
827
  async executeCodexExec(executable, commandArgs, prompt, timeoutMs, model = null) {
751
828
  if (!executable) {
752
829
  throw new Error('Missing Codex executable');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
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",
@@ -67,7 +67,7 @@
67
67
  "lucide-react": "^0.542.0",
68
68
  "marked": "^16.2.1",
69
69
  "next": "^15.5.7",
70
- "polydev-ai": "^1.8.3",
70
+ "polydev-ai": "^1.8.4",
71
71
  "posthog-js": "^1.157.2",
72
72
  "prismjs": "^1.30.0",
73
73
  "react": "^18.3.1",