|
1 | | -import fs from 'fs'; |
| 1 | +import { promises as fs } from 'fs'; |
2 | 2 | import path from 'path'; |
3 | 3 |
|
4 | 4 | import { logger } from '../utils'; |
@@ -61,7 +61,7 @@ class SummaryGenerator { |
61 | 61 |
|
62 | 62 | // Write the summary file |
63 | 63 | const summaryPath = path.join(this.metricsDir, 'summary.json'); |
64 | | - fs.writeFileSync(summaryPath, JSON.stringify(uniqueMetrics, null, 2)); |
| 64 | + await fs.writeFile(summaryPath, JSON.stringify(uniqueMetrics, null, 2)); |
65 | 65 |
|
66 | 66 | this.printSummaryStatistics(uniqueMetrics); |
67 | 67 |
|
@@ -168,33 +168,31 @@ class SummaryGenerator { |
168 | 168 | `Writing metric file for task ${metric.taskId} with ${metric.apiCalls ?? 0} API calls`, |
169 | 169 | ); |
170 | 170 |
|
171 | | - fs.writeFileSync( |
172 | | - filePath, |
173 | | - JSON.stringify( |
174 | | - { |
175 | | - mode: metric.mode, |
176 | | - taskNumber: metric.taskId, |
177 | | - directoryId: metric.directoryId ?? '', |
178 | | - model: metric.model, |
179 | | - startTime: metric.startTime, |
180 | | - completed: true, |
181 | | - apiCalls: metric.apiCalls ?? 0, |
182 | | - interactions: metric.interactions ?? 0, |
183 | | - tokensIn: metric.tokensIn ?? 0, |
184 | | - tokensOut: metric.tokensOut ?? 0, |
185 | | - totalTokens: metric.totalTokens ?? 0, |
186 | | - cacheWrites: metric.cacheWrites ?? 0, |
187 | | - cacheReads: metric.cacheReads ?? 0, |
188 | | - conversationHistoryIndex: metric.conversationHistoryIndex ?? 0, |
189 | | - cost: metric.cost ?? 0, |
190 | | - success: metric.success ?? false, |
191 | | - endTime: metric.endTime, |
192 | | - duration: metric.duration, |
193 | | - }, |
194 | | - null, |
195 | | - 2, |
196 | | - ), |
| 171 | + const payload = JSON.stringify( |
| 172 | + { |
| 173 | + mode: metric.mode, |
| 174 | + taskNumber: metric.taskId, |
| 175 | + directoryId: metric.directoryId ?? '', |
| 176 | + model: metric.model, |
| 177 | + startTime: metric.startTime, |
| 178 | + completed: true, |
| 179 | + apiCalls: metric.apiCalls ?? 0, |
| 180 | + interactions: metric.interactions ?? 0, |
| 181 | + tokensIn: metric.tokensIn ?? 0, |
| 182 | + tokensOut: metric.tokensOut ?? 0, |
| 183 | + totalTokens: metric.totalTokens ?? 0, |
| 184 | + cacheWrites: metric.cacheWrites ?? 0, |
| 185 | + cacheReads: metric.cacheReads ?? 0, |
| 186 | + conversationHistoryIndex: metric.conversationHistoryIndex ?? 0, |
| 187 | + cost: metric.cost ?? 0, |
| 188 | + success: metric.success ?? false, |
| 189 | + endTime: metric.endTime, |
| 190 | + duration: metric.duration, |
| 191 | + }, |
| 192 | + null, |
| 193 | + 2, |
197 | 194 | ); |
| 195 | + await fs.writeFile(filePath, payload); |
198 | 196 |
|
199 | 197 | successfulWrites.push(filename); |
200 | 198 | } catch (error) { |
@@ -230,7 +228,7 @@ class SummaryGenerator { |
230 | 228 | const tasksDir = path.join(this.metricsDir, 'tasks'); |
231 | 229 | let files: string[]; |
232 | 230 | try { |
233 | | - files = fs.readdirSync(tasksDir); |
| 231 | + files = await fs.readdir(tasksDir); |
234 | 232 | } catch (error) { |
235 | 233 | logger.error( |
236 | 234 | `Failed to read tasks directory: ${(error as Error).message}`, |
@@ -306,7 +304,7 @@ class SummaryGenerator { |
306 | 304 | try { |
307 | 305 | // Write the summary file |
308 | 306 | const summaryPath = path.join(this.metricsDir, 'summary.json'); |
309 | | - fs.writeFileSync(summaryPath, JSON.stringify(allMetrics, null, 2)); |
| 307 | + await fs.writeFile(summaryPath, JSON.stringify(allMetrics, null, 2)); |
310 | 308 |
|
311 | 309 | this.printSummaryStatistics(allMetrics); |
312 | 310 |
|
@@ -341,7 +339,7 @@ class SummaryGenerator { |
341 | 339 | const summaryPath = path.join(this.metricsDir, 'summary.json'); |
342 | 340 |
|
343 | 341 | try { |
344 | | - const content = fs.readFileSync(summaryPath, 'utf8'); |
| 342 | + const content = await fs.readFile(summaryPath, 'utf8'); |
345 | 343 | existingMetrics = JSON.parse(content); |
346 | 344 | } catch (error) { |
347 | 345 | logger.warn( |
@@ -403,7 +401,7 @@ class SummaryGenerator { |
403 | 401 |
|
404 | 402 | try { |
405 | 403 | // Write the merged summary |
406 | | - fs.writeFileSync(summaryPath, JSON.stringify(allMetrics, null, 2)); |
| 404 | + await fs.writeFile(summaryPath, JSON.stringify(allMetrics, null, 2)); |
407 | 405 |
|
408 | 406 | return SummaryResult.success( |
409 | 407 | `Merged summary: updated ${updatedMetrics.length}, added ${addedMetrics.length} metrics`, |
@@ -436,7 +434,7 @@ class SummaryGenerator { |
436 | 434 |
|
437 | 435 | try { |
438 | 436 | const tasksDir = path.join(this.metricsDir, 'tasks'); |
439 | | - const files = fs.readdirSync(tasksDir); |
| 437 | + const files = await fs.readdir(tasksDir); |
440 | 438 |
|
441 | 439 | if (directoryId) { |
442 | 440 | const specificPattern = new RegExp( |
|
0 commit comments