Tool stats over the last N days.
(daysBack = 30, cwd?: string)
| 186 | |
| 187 | /** Tool stats over the last N days. */ |
| 188 | getToolStats(daysBack = 30, cwd?: string): ToolStats[] { |
| 189 | const db = this.ensureOpen(); |
| 190 | if (!db) return []; |
| 191 | const since = Date.now() - daysBack * 24 * 60 * 60 * 1000; |
| 192 | const whereCwd = cwd ? ' AND cwd = ?' : ''; |
| 193 | const params: (string | number)[] = [since]; |
| 194 | if (cwd) params.push(this.maskCwd(cwd)); |
| 195 | const rows = db.prepare(` |
| 196 | SELECT tool, |
| 197 | COUNT(*) as totalCalls, |
| 198 | SUM(success) as successCount, |
| 199 | SUM(1 - success) as failCount, |
| 200 | AVG(duration_ms) as avgDurationMs, |
| 201 | SUM(duration_ms) as totalDurationMs |
| 202 | FROM tool_events |
| 203 | WHERE ts >= ?${whereCwd} |
| 204 | GROUP BY tool |
| 205 | ORDER BY totalCalls DESC |
| 206 | `).all(...params) as ToolStats[]; |
| 207 | return rows; |
| 208 | } |
| 209 | |
| 210 | /** Model stats over the last N days. */ |
| 211 | getModelStats(daysBack = 30, cwd?: string): ModelStats[] { |
no test coverage detected