getaimeter 0.7.3 → 0.7.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 (3) hide show
  1. package/package.json +1 -1
  2. package/tray.ps1 +52 -29
  3. package/watcher.js +35 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getaimeter",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Track AI coding costs across Claude, Cursor, Codex, and Gemini. Optimization recommendations that cut costs by 30%.",
5
5
  "bin": {
6
6
  "aimeter": "cli.js"
package/tray.ps1 CHANGED
@@ -78,40 +78,63 @@ $aboutItem.Add_Click({
78
78
  $helpMenu.DropDownItems.Add($aboutItem) | Out-Null
79
79
 
80
80
  $checkUpdateItem = New-Object System.Windows.Forms.ToolStripMenuItem("Check for Updates")
81
+ $script:updateJob = $null
81
82
  $checkUpdateItem.Add_Click({
82
83
  $checkUpdateItem.Text = "Checking..."
83
84
  $checkUpdateItem.Enabled = $false
84
- try {
85
- $response = Invoke-RestMethod -Uri "https://registry.npmjs.org/getaimeter/latest" -TimeoutSec 5
86
- $latest = $response.version
87
- if ($latest -and $latest -ne $Version) {
88
- $result = [System.Windows.Forms.MessageBox]::Show(
89
- "Update available: v$Version -> v$latest`n`nRun this command to update:`nnpm install -g getaimeter@latest`n`nThen restart the watcher.`n`nOpen terminal to update now?",
90
- "Update Available",
91
- [System.Windows.Forms.MessageBoxButtons]::YesNo,
92
- [System.Windows.Forms.MessageBoxIcon]::Information
93
- )
94
- if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
95
- Start-Process "cmd.exe" -ArgumentList "/k npm install -g getaimeter@latest && echo. && echo Update complete. Restart the watcher with: aimeter stop && aimeter start"
96
- }
97
- } else {
98
- [System.Windows.Forms.MessageBox]::Show(
99
- "You are running the latest version (v$Version).",
100
- "No Updates",
101
- [System.Windows.Forms.MessageBoxButtons]::OK,
102
- [System.Windows.Forms.MessageBoxIcon]::Information
103
- )
85
+
86
+ # Run HTTP request in a background job to avoid freezing the UI
87
+ $script:updateJob = Start-Job -ScriptBlock {
88
+ try {
89
+ $r = Invoke-RestMethod -Uri "https://registry.npmjs.org/getaimeter/latest" -TimeoutSec 10
90
+ return $r.version
91
+ } catch {
92
+ return "ERROR"
104
93
  }
105
- } catch {
106
- [System.Windows.Forms.MessageBox]::Show(
107
- "Could not check for updates. Please check your internet connection.",
108
- "Update Check Failed",
109
- [System.Windows.Forms.MessageBoxButtons]::OK,
110
- [System.Windows.Forms.MessageBoxIcon]::Warning
111
- )
112
94
  }
113
- $checkUpdateItem.Text = "Check for Updates"
114
- $checkUpdateItem.Enabled = $true
95
+
96
+ # Timer polls for job completion (every 500ms)
97
+ $updateTimer = New-Object System.Windows.Forms.Timer
98
+ $updateTimer.Interval = 500
99
+ $updateTimer.Add_Tick({
100
+ if ($script:updateJob.State -eq "Completed") {
101
+ $updateTimer.Stop()
102
+ $updateTimer.Dispose()
103
+ $latest = Receive-Job $script:updateJob
104
+ Remove-Job $script:updateJob
105
+ $script:updateJob = $null
106
+
107
+ $checkUpdateItem.Text = "Check for Updates"
108
+ $checkUpdateItem.Enabled = $true
109
+
110
+ if ($latest -eq "ERROR") {
111
+ [System.Windows.Forms.MessageBox]::Show(
112
+ "Could not check for updates. Please check your internet connection.",
113
+ "Update Check Failed",
114
+ [System.Windows.Forms.MessageBoxButtons]::OK,
115
+ [System.Windows.Forms.MessageBoxIcon]::Warning
116
+ ) | Out-Null
117
+ } elseif ($latest -and $latest -ne $Version) {
118
+ $result = [System.Windows.Forms.MessageBox]::Show(
119
+ "Update available: v$Version -> v$latest`n`nClick Yes to open a terminal and run the update command.",
120
+ "Update Available",
121
+ [System.Windows.Forms.MessageBoxButtons]::YesNo,
122
+ [System.Windows.Forms.MessageBoxIcon]::Information
123
+ )
124
+ if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
125
+ Start-Process "cmd.exe" -ArgumentList "/k echo Updating AIMeter... && npm install -g getaimeter@latest && echo. && echo Done! Now restart: aimeter stop ^&^& aimeter start"
126
+ }
127
+ } else {
128
+ [System.Windows.Forms.MessageBox]::Show(
129
+ "You are running the latest version (v$Version).",
130
+ "No Updates",
131
+ [System.Windows.Forms.MessageBoxButtons]::OK,
132
+ [System.Windows.Forms.MessageBoxIcon]::Information
133
+ ) | Out-Null
134
+ }
135
+ }
136
+ })
137
+ $updateTimer.Start()
115
138
  })
116
139
  $helpMenu.DropDownItems.Add($checkUpdateItem) | Out-Null
117
140
 
package/watcher.js CHANGED
@@ -159,31 +159,51 @@ function extractNewUsage(filePath) {
159
159
  }
160
160
 
161
161
  if (!msg) {
162
- // ── Codex CLI format ──────────────────────────────────────────
163
- // Codex events have { type: "event", payload: { type: "token_count", ... } }
164
- // with cumulative input_tokens, output_tokens, reasoning_tokens, cached_input_tokens
165
- if (obj.type === 'event' && obj.payload?.type === 'token_count') {
166
- const p = obj.payload;
162
+ // ── Codex CLI format (old: type="event", new: type="event_msg") ──
163
+ // Old format: { type: "event", payload: { type: "token_count", input_tokens, ... } }
164
+ // New format: { type: "event_msg", payload: { type: "token_count", info: { total_token_usage: { input_tokens, ... } } } }
165
+ if ((obj.type === 'event' || obj.type === 'event_msg') && obj.payload?.type === 'token_count') {
166
+ // Extract token counts — handle both old (flat) and new (nested) format
167
+ let inputTokens, outputTokens, reasoningTokens, cachedTokens;
168
+
169
+ if (obj.payload.info?.total_token_usage) {
170
+ // New format (2026+): cumulative totals in info.total_token_usage
171
+ const t = obj.payload.info.total_token_usage;
172
+ inputTokens = t.input_tokens || 0;
173
+ outputTokens = t.output_tokens || 0;
174
+ reasoningTokens = t.reasoning_output_tokens || t.reasoning_tokens || 0;
175
+ cachedTokens = t.cached_input_tokens || 0;
176
+ } else {
177
+ // Old format: flat fields on payload
178
+ inputTokens = obj.payload.input_tokens || 0;
179
+ outputTokens = obj.payload.output_tokens || 0;
180
+ reasoningTokens = obj.payload.reasoning_tokens || 0;
181
+ cachedTokens = obj.payload.cached_input_tokens || 0;
182
+ }
183
+
184
+ // Skip events with no token info (e.g. rate limit only events)
185
+ if (inputTokens === 0 && outputTokens === 0) continue;
186
+
167
187
  const codexModel = obj.turn_context?.model || 'codex';
188
+
168
189
  // Token counts are cumulative per session; we store deltas
169
- // Use a per-file tracker for the previous cumulative values
170
190
  const prevKey = filePath;
171
191
  const prev = _codexCumulative[prevKey] || { input: 0, output: 0, reasoning: 0, cached: 0 };
172
- const deltaInput = (p.input_tokens || 0) - prev.input;
173
- const deltaOutput = (p.output_tokens || 0) - prev.output;
174
- const deltaReasoning = (p.reasoning_tokens || 0) - prev.reasoning;
192
+ const deltaInput = inputTokens - prev.input;
193
+ const deltaOutput = outputTokens - prev.output;
194
+ const deltaReasoning = reasoningTokens - prev.reasoning;
175
195
 
176
196
  _codexCumulative[prevKey] = {
177
- input: p.input_tokens || 0,
178
- output: p.output_tokens || 0,
179
- reasoning: p.reasoning_tokens || 0,
180
- cached: p.cached_input_tokens || 0,
197
+ input: inputTokens,
198
+ output: outputTokens,
199
+ reasoning: reasoningTokens,
200
+ cached: cachedTokens,
181
201
  };
182
202
 
183
203
  // Skip if no new tokens (duplicate or first read)
184
204
  if (deltaInput <= 0 && deltaOutput <= 0) continue;
185
205
 
186
- const hashKey = `${filePath}:${lineOffset}:codex:${p.input_tokens}:${p.output_tokens}`;
206
+ const hashKey = `${filePath}:${lineOffset}:codex:${inputTokens}:${outputTokens}`;
187
207
  const hash = crypto.createHash('md5').update(hashKey).digest('hex');
188
208
  if (isDuplicate(hash)) continue;
189
209
 
@@ -194,7 +214,7 @@ function extractNewUsage(filePath) {
194
214
  inputTokens: deltaInput,
195
215
  outputTokens: deltaOutput,
196
216
  thinkingTokens: deltaReasoning,
197
- cacheReadTokens: 0,
217
+ cacheReadTokens: cachedTokens,
198
218
  cacheWriteTokens: 0,
199
219
  });
200
220
  continue;