feat(telemetry): exportTo writes events.jsonl + stats.md (#7 v0.2.3)

This commit is contained in:
altair823
2026-05-01 17:08:34 +09:00
parent 2036c687d2
commit 36a5c67ed6
2 changed files with 47 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { mkdir, appendFile, readFile, readdir, unlink } from 'node:fs/promises';
import { mkdir, appendFile, readFile, readdir, unlink, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { validateEvent, TelemetryEvent } from './telemetryEvents.js';
import { aggregateStats } from './telemetryStats.js';
const KST_OFFSET_MS = 9 * 60 * 60 * 1000;
@@ -105,4 +106,14 @@ export class TelemetryService {
}
return events;
}
async exportTo(outDir: string): Promise<{ eventCount: number }> {
const events = await this.readAllRecent();
await mkdir(outDir, { recursive: true });
const eventsContent = events.map((e) => JSON.stringify(e)).join('\n') + (events.length > 0 ? '\n' : '');
await writeFile(join(outDir, 'events.jsonl'), eventsContent, 'utf8');
const stats = aggregateStats(events, this.now());
await writeFile(join(outDir, 'stats.md'), stats.md, 'utf8');
return { eventCount: stats.eventCount };
}
}