polydev-ai 1.8.4 → 1.8.6
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/lib/cliManager.js +82 -1
- 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,66 @@ 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
|
+
// The primary model is the one with highest cost - that's the user's configured main model
|
|
789
|
+
// (Haiku is used internally for quick tasks, but the expensive model is what the user chose)
|
|
790
|
+
let primaryModel = 'cli_default';
|
|
791
|
+
const modelUsage = json.modelUsage || {};
|
|
792
|
+
const modelNames = Object.keys(modelUsage);
|
|
793
|
+
|
|
794
|
+
if (modelNames.length === 1) {
|
|
795
|
+
// Only one model used - that's the primary
|
|
796
|
+
primaryModel = modelNames[0];
|
|
797
|
+
} else if (modelNames.length > 1) {
|
|
798
|
+
// Multiple models - the one with highest cost is the user's configured main model
|
|
799
|
+
let highestCost = -1;
|
|
800
|
+
for (const [modelName, usage] of Object.entries(modelUsage)) {
|
|
801
|
+
const cost = usage.costUSD || 0;
|
|
802
|
+
if (cost > highestCost) {
|
|
803
|
+
highestCost = cost;
|
|
804
|
+
primaryModel = modelName;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// Calculate total tokens
|
|
810
|
+
let totalTokens = 0;
|
|
811
|
+
for (const usage of Object.values(modelUsage)) {
|
|
812
|
+
totalTokens += (usage.inputTokens || 0) + (usage.outputTokens || 0) +
|
|
813
|
+
(usage.cacheReadInputTokens || 0) + (usage.cacheCreationInputTokens || 0);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return {
|
|
817
|
+
content,
|
|
818
|
+
model_used: primaryModel,
|
|
819
|
+
tokens_used: totalTokens || json.usage?.input_tokens + json.usage?.output_tokens || 0,
|
|
820
|
+
cost_usd: json.total_cost_usd || 0,
|
|
821
|
+
model_usage: modelUsage,
|
|
822
|
+
session_id: json.session_id,
|
|
823
|
+
duration_ms: json.duration_ms
|
|
824
|
+
};
|
|
825
|
+
} catch (e) {
|
|
826
|
+
// Not valid JSON, return null to fall back to text parsing
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
750
831
|
async executeCodexExec(executable, commandArgs, prompt, timeoutMs, model = null) {
|
|
751
832
|
if (!executable) {
|
|
752
833
|
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.
|
|
3
|
+
"version": "1.8.6",
|
|
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.
|
|
70
|
+
"polydev-ai": "^1.8.5",
|
|
71
71
|
"posthog-js": "^1.157.2",
|
|
72
72
|
"prismjs": "^1.30.0",
|
|
73
73
|
"react": "^18.3.1",
|