polydev-ai 1.8.14 → 1.8.16

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 CHANGED
@@ -942,17 +942,21 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
942
942
  }
943
943
  }
944
944
 
945
- // Calculate total tokens
945
+ // Calculate total tokens (excluding cache tokens which are just infrastructure overhead)
946
946
  let totalTokens = 0;
947
+ let cacheTokens = 0;
947
948
  for (const usage of Object.values(modelUsage)) {
948
- totalTokens += (usage.inputTokens || 0) + (usage.outputTokens || 0) +
949
- (usage.cacheReadInputTokens || 0) + (usage.cacheCreationInputTokens || 0);
949
+ // Count actual input/output tokens
950
+ totalTokens += (usage.inputTokens || 0) + (usage.outputTokens || 0);
951
+ // Track cache tokens separately (for cost calculations, but not displayed as "tokens used")
952
+ cacheTokens += (usage.cacheReadInputTokens || 0) + (usage.cacheCreationInputTokens || 0);
950
953
  }
951
954
 
952
955
  return {
953
956
  content,
954
957
  model_used: primaryModel,
955
958
  tokens_used: totalTokens || json.usage?.input_tokens + json.usage?.output_tokens || 0,
959
+ cache_tokens: cacheTokens, // Separate field for cache tokens
956
960
  cost_usd: json.total_cost_usd || 0,
957
961
  model_usage: modelUsage,
958
962
  session_id: json.session_id,
@@ -100,6 +100,75 @@ if (writableTmp) {
100
100
  console.error(`[Stdio Wrapper] Using TMP directory: ${writableTmp}`);
101
101
  }
102
102
 
103
+ /**
104
+ * Clean CLI response by removing metadata and debug info
105
+ * Strips: provider info, approval, sandbox, reasoning, session id, MCP errors, etc.
106
+ */
107
+ function cleanCliResponse(content) {
108
+ if (!content || typeof content !== 'string') {
109
+ return content || '';
110
+ }
111
+
112
+ const lines = content.split('\n');
113
+ const cleanedLines = [];
114
+ let skipUntilContent = true;
115
+ let inThinkingSection = false;
116
+
117
+ for (const line of lines) {
118
+ const trimmed = line.trim();
119
+
120
+ // Skip metadata lines at the start
121
+ if (skipUntilContent) {
122
+ // Skip empty lines
123
+ if (!trimmed) continue;
124
+
125
+ // Skip known metadata patterns
126
+ if (trimmed.startsWith('provider:')) continue;
127
+ if (trimmed.startsWith('approval:')) continue;
128
+ if (trimmed.startsWith('sandbox:')) continue;
129
+ if (trimmed.startsWith('reasoning effort:')) continue;
130
+ if (trimmed.startsWith('reasoning summaries:')) continue;
131
+ if (trimmed.startsWith('session id:')) continue;
132
+ if (trimmed.match(/^-{4,}$/)) continue; // Skip separator lines like --------
133
+ if (trimmed === 'user') continue; // Skip role markers
134
+ if (trimmed === 'assistant') continue;
135
+
136
+ // Skip MCP client errors
137
+ if (trimmed.startsWith('ERROR: MCP client for')) continue;
138
+ if (trimmed.includes('failed to start')) continue;
139
+
140
+ // Found actual content - stop skipping
141
+ skipUntilContent = false;
142
+ }
143
+
144
+ // Handle thinking sections (optional: can show or hide)
145
+ if (trimmed === 'thinking') {
146
+ inThinkingSection = true;
147
+ continue; // Skip the "thinking" marker
148
+ }
149
+
150
+ // End of thinking section on empty line after content
151
+ if (inThinkingSection && !trimmed) {
152
+ inThinkingSection = false;
153
+ continue;
154
+ }
155
+
156
+ // Skip more MCP errors anywhere in output
157
+ if (trimmed.startsWith('ERROR: MCP client for')) continue;
158
+ if (trimmed.includes('failed to start') && trimmed.includes('MCP')) continue;
159
+
160
+ // Keep this line
161
+ cleanedLines.push(line);
162
+ }
163
+
164
+ // Trim trailing empty lines and return
165
+ while (cleanedLines.length > 0 && !cleanedLines[cleanedLines.length - 1].trim()) {
166
+ cleanedLines.pop();
167
+ }
168
+
169
+ return cleanedLines.join('\n');
170
+ }
171
+
103
172
  class StdioMCPWrapper {
104
173
  constructor() {
105
174
  this.userToken = process.env.POLYDEV_USER_TOKEN;
@@ -837,7 +906,7 @@ class StdioMCPWrapper {
837
906
  ? cliResult.model_used
838
907
  : cliResult.provider_id;
839
908
  formatted += `🟢 **Local CLI Response** (${modelDisplay})\n\n`;
840
- formatted += `${cliResult.content}\n\n`;
909
+ formatted += `${cleanCliResponse(cliResult.content)}\n\n`;
841
910
  formatted += `*Latency: ${cliResult.latency_ms || 0}ms | Tokens: ${cliResult.tokens_used || 0}*\n\n`;
842
911
  formatted += `---\n\n`;
843
912
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.14",
3
+ "version": "1.8.16",
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.9",
70
+ "polydev-ai": "^1.8.15",
71
71
  "posthog-js": "^1.157.2",
72
72
  "prismjs": "^1.30.0",
73
73
  "react": "^18.3.1",