Summary
Export success rates, failure analysis, and trends for external analysis.
Key Features
- Export metrics to CSV and JSON formats
- Date range selection for exports
- Per-agent and aggregate exports
- CLI and UI export options
Implementation Phases
Phase 1: Export Module
- Create
src/core/export.ts:
interface ExportOptions {
format: 'csv' | 'json';
dateRange?: { start: string; end: string };
agents?: AgentType[];
includeLoopDetails?: boolean;
}
function exportMetrics(loops: Loop[], options: ExportOptions): string;
function exportToFile(data: string, path: string): void;
Phase 2: CSV Formatter
- Flatten metrics into tabular format
- Headers: date, agent, loops_run, completed, failed, avg_iterations, avg_duration, cost_usd
- One row per agent per day
- Aggregate row option
Phase 3: JSON Formatter
- Already exists:
exportMetricsToJson() in src/core/metrics.ts
- Extend with date filtering
- Add loop-level detail option (full loop objects)
Phase 4: CLI Commands
# Export all metrics as CSV
alex export --format csv --output metrics.csv
# Export last 7 days as JSON
alex export --format json --days 7
# Export specific agent
alex export --format csv --agent claude
# Export to stdout
alex export --format json
Phase 5: UI Integration
- Add "Export" button in metrics tab
- Modal with options:
- Format selector (CSV/JSON)
- Date range picker
- Agent filter checkboxes
- Save file dialog or copy to clipboard
Export Schema
CSV Format
date,agent,loops_run,completed,failed,success_rate,avg_iterations,avg_duration_min,cost_usd
2024-01-15,claude,5,4,1,0.80,12.5,45.2,2.50
2024-01-15,codex,3,3,0,1.00,8.0,30.1,1.20
JSON Format
{
"exportedAt": "2024-01-15T10:00:00Z",
"dateRange": { "start": "2024-01-08", "end": "2024-01-15" },
"summary": { ... },
"agentMetrics": [ ... ],
"dailyTrends": [ ... ],
"loops": [ ... ] // optional detail
}
Files to Create/Modify
src/core/export.ts - New export module
src/core/metrics.ts - Extend with date filtering
src/cli.ts - Add export subcommand
src/ui/layout.ts - Export button in metrics tab
Acceptance Criteria
Summary
Export success rates, failure analysis, and trends for external analysis.
Key Features
Implementation Phases
Phase 1: Export Module
src/core/export.ts:Phase 2: CSV Formatter
Phase 3: JSON Formatter
exportMetricsToJson()insrc/core/metrics.tsPhase 4: CLI Commands
Phase 5: UI Integration
Export Schema
CSV Format
JSON Format
{ "exportedAt": "2024-01-15T10:00:00Z", "dateRange": { "start": "2024-01-08", "end": "2024-01-15" }, "summary": { ... }, "agentMetrics": [ ... ], "dailyTrends": [ ... ], "loops": [ ... ] // optional detail }Files to Create/Modify
src/core/export.ts- New export modulesrc/core/metrics.ts- Extend with date filteringsrc/cli.ts- Add export subcommandsrc/ui/layout.ts- Export button in metrics tabAcceptance Criteria