prodigy 0.4.4

Turn ad-hoc Claude sessions into reproducible development pipelines with parallel AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
use std::collections::VecDeque;
use std::net::SocketAddr;
use std::sync::Arc;

use anyhow::Result;
use axum::extract::ws::WebSocket;
use axum::{
    extract::{Query, State, WebSocketUpgrade},
    response::{Html, Response},
    routing::get,
    Json, Router,
};
use futures::{sink::SinkExt, stream::StreamExt};
use serde::Deserialize;
use serde_json::json;
use tokio::sync::{broadcast, RwLock};
use tracing::info;

use super::progress_tracker::{ProgressTracker, SerializableProgressSnapshot};

pub struct DashboardServer {
    progress_tracker: Arc<ProgressTracker>,
    port: u16,
    update_channel: broadcast::Sender<String>,
    log_buffer: Arc<RwLock<VecDeque<LogEntry>>>,
}

#[derive(Clone, Debug, Deserialize, serde::Serialize)]
struct LogEntry {
    timestamp: String,
    level: String,
    message: String,
    agent_id: Option<String>,
}

#[derive(Deserialize)]
struct LogQuery {
    agent_id: Option<String>,
    level: Option<String>,
    limit: Option<usize>,
}

impl DashboardServer {
    pub fn new(progress_tracker: Arc<ProgressTracker>, port: u16) -> Self {
        let (tx, _) = broadcast::channel(100);
        Self {
            progress_tracker,
            port,
            update_channel: tx,
            log_buffer: Arc::new(RwLock::new(VecDeque::with_capacity(1000))),
        }
    }

    pub async fn start(self: Arc<Self>) -> Result<()> {
        let app = Router::new()
            .route("/", get(serve_dashboard))
            .route("/api/progress", get(progress_endpoint))
            .route("/api/logs", get(logs_endpoint))
            .route("/ws", get(websocket_handler))
            .with_state(self.clone());

        let addr = SocketAddr::from(([127, 0, 0, 1], self.port));
        info!("Dashboard available at http://localhost:{}", self.port);

        let listener = tokio::net::TcpListener::bind(addr).await?;
        axum::serve(listener, app).await?;

        Ok(())
    }

    pub async fn broadcast_update(&self, update: SerializableProgressSnapshot) -> Result<()> {
        let json = serde_json::to_string(&update)?;
        self.update_channel.send(json).ok();
        Ok(())
    }

    pub async fn add_log(&self, level: &str, message: &str, agent_id: Option<String>) {
        let mut logs = self.log_buffer.write().await;

        // Keep buffer size limited
        if logs.len() >= 1000 {
            logs.pop_front();
        }

        logs.push_back(LogEntry {
            timestamp: chrono::Utc::now().to_rfc3339(),
            level: level.to_string(),
            message: message.to_string(),
            agent_id,
        });
    }
}

async fn serve_dashboard() -> Html<&'static str> {
    Html(DASHBOARD_HTML)
}

async fn progress_endpoint(State(server): State<Arc<DashboardServer>>) -> Json<serde_json::Value> {
    let snapshot = server.progress_tracker.serializable_snapshot().await;
    Json(json!(snapshot))
}

async fn logs_endpoint(
    State(server): State<Arc<DashboardServer>>,
    Query(params): Query<LogQuery>,
) -> Json<serde_json::Value> {
    let logs = server.log_buffer.read().await;

    let mut filtered_logs: Vec<LogEntry> = logs
        .iter()
        .filter(|log| {
            // Filter by agent_id if specified
            if let Some(ref agent_id) = params.agent_id {
                if let Some(ref log_agent) = log.agent_id {
                    if log_agent != agent_id {
                        return false;
                    }
                } else {
                    return false;
                }
            }

            // Filter by level if specified
            if let Some(ref level) = params.level {
                if log.level.to_lowercase() != level.to_lowercase() {
                    return false;
                }
            }

            true
        })
        .cloned()
        .collect();

    // Apply limit
    let limit = params.limit.unwrap_or(100);
    filtered_logs.truncate(limit);

    Json(json!({
        "logs": filtered_logs
    }))
}

async fn websocket_handler(
    ws: WebSocketUpgrade,
    State(server): State<Arc<DashboardServer>>,
) -> Response {
    ws.on_upgrade(move |socket| handle_socket(socket, server))
}

async fn handle_socket(socket: WebSocket, server: Arc<DashboardServer>) {
    let (mut sender, mut receiver) = socket.split();
    let mut rx = server.update_channel.subscribe();

    use axum::extract::ws::Message;

    // Send initial state
    let snapshot = server.progress_tracker.serializable_snapshot().await;
    if let Ok(json) = serde_json::to_string(&snapshot) {
        sender.send(Message::Text(json.into())).await.ok();
    }

    // Spawn task to handle incoming messages
    let server_clone = server.clone();
    tokio::spawn(async move {
        while let Some(msg) = receiver.next().await {
            if let Ok(Message::Text(text)) = msg {
                // Handle client commands if needed
                if text == "ping" {
                    // Respond with current snapshot
                    let snapshot = server_clone.progress_tracker.serializable_snapshot().await;
                    if let Ok(_json) = serde_json::to_string(&snapshot) {
                        // Can't send here, would need channel back to sender
                    }
                }
            }
        }
    });

    // Send updates to client
    while let Ok(update) = rx.recv().await {
        if sender.send(Message::Text(update.into())).await.is_err() {
            break;
        }
    }
}

const DASHBOARD_HTML: &str = r#"
<!DOCTYPE html>
<html>
<head>
    <title>Prodigy Progress Dashboard</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background: #1a1a2e;
            color: #eee;
            padding: 20px;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
        }

        h1 {
            margin-bottom: 20px;
            color: #4fbdba;
        }

        .workflow-card {
            background: #16213e;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
        }

        .progress-bar {
            width: 100%;
            height: 30px;
            background: #0f3460;
            border-radius: 15px;
            overflow: hidden;
            margin: 10px 0;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #4fbdba, #7ec8e3);
            transition: width 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-weight: bold;
        }

        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-top: 20px;
        }

        .stat-card {
            background: #0f3460;
            padding: 15px;
            border-radius: 8px;
            text-align: center;
        }

        .stat-value {
            font-size: 2em;
            font-weight: bold;
            color: #4fbdba;
        }

        .stat-label {
            font-size: 0.9em;
            color: #aaa;
            margin-top: 5px;
        }

        .phase-container {
            margin-top: 20px;
        }

        .phase-card {
            background: #0f3460;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 10px;
        }

        .phase-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .agent-list {
            margin-top: 10px;
            padding-left: 20px;
        }

        .agent-item {
            background: #16213e;
            padding: 8px;
            margin: 5px 0;
            border-radius: 4px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .status-badge {
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.85em;
            font-weight: bold;
        }

        .status-running { background: #4fbdba; }
        .status-completed { background: #4caf50; }
        .status-failed { background: #f44336; }
        .status-pending { background: #666; }

        .resource-meter {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 5px 0;
        }

        .meter-bar {
            flex: 1;
            height: 10px;
            background: #0f3460;
            border-radius: 5px;
            overflow: hidden;
        }

        .meter-fill {
            height: 100%;
            transition: width 0.3s ease;
        }

        .meter-cpu { background: #4fbdba; }
        .meter-memory { background: #7ec8e3; }
        .meter-disk { background: #c7ceea; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🚀 Prodigy Progress Dashboard</h1>

        <div class="workflow-card">
            <h2 id="workflow-name">Loading...</h2>
            <div class="progress-bar">
                <div class="progress-fill" id="main-progress">0%</div>
            </div>
            <div id="workflow-status"></div>

            <div class="stats">
                <div class="stat-card">
                    <div class="stat-value" id="completed-steps">0</div>
                    <div class="stat-label">Completed Steps</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="success-rate">0%</div>
                    <div class="stat-label">Success Rate</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="throughput">0</div>
                    <div class="stat-label">Items/sec</div>
                </div>
                <div class="stat-card">
                    <div class="stat-value" id="eta">--</div>
                    <div class="stat-label">ETA</div>
                </div>
            </div>

            <div class="resource-meter">
                <span>CPU:</span>
                <div class="meter-bar">
                    <div class="meter-fill meter-cpu" id="cpu-meter" style="width: 0%"></div>
                </div>
                <span id="cpu-value">0%</span>
            </div>
            <div class="resource-meter">
                <span>Memory:</span>
                <div class="meter-bar">
                    <div class="meter-fill meter-memory" id="mem-meter" style="width: 0%"></div>
                </div>
                <span id="mem-value">0 MB</span>
            </div>
        </div>

        <div class="phase-container" id="phases">
            <!-- Phases will be inserted here -->
        </div>
    </div>

    <script>
        const ws = new WebSocket('ws://localhost:8080/ws');

        ws.onmessage = (event) => {
            const data = JSON.parse(event.data);
            updateDashboard(data);
        };

        ws.onerror = (error) => {
            console.error('WebSocket error:', error);
        };

        function updateDashboard(data) {
            // Update workflow info
            if (data.workflow) {
                document.getElementById('workflow-name').textContent = data.workflow.name;

                const progress = data.workflow.total_steps > 0
                    ? Math.round((data.workflow.completed_steps / data.workflow.total_steps) * 100)
                    : 0;

                const progressBar = document.getElementById('main-progress');
                progressBar.style.width = progress + '%';
                progressBar.textContent = progress + '%';

                document.getElementById('completed-steps').textContent = data.workflow.completed_steps;

                if (data.workflow.eta) {
                    const etaSeconds = Math.round(data.workflow.eta.secs);
                    const minutes = Math.floor(etaSeconds / 60);
                    const seconds = etaSeconds % 60;
                    document.getElementById('eta').textContent = minutes + 'm ' + seconds + 's';
                } else {
                    document.getElementById('eta').textContent = '--';
                }

                // Update resource usage
                const cpu = data.workflow.resource_usage.cpu_percent;
                document.getElementById('cpu-meter').style.width = cpu + '%';
                document.getElementById('cpu-value').textContent = cpu.toFixed(1) + '%';

                const memMB = Math.round(data.workflow.resource_usage.memory_bytes / 1048576);
                const memPercent = Math.min(100, memMB / 10); // Assume 1GB = 100%
                document.getElementById('mem-meter').style.width = memPercent + '%';
                document.getElementById('mem-value').textContent = memMB + ' MB';
            }

            // Update phases
            if (data.phases) {
                updatePhases(data.phases);
            }
        }

        function updatePhases(phases) {
            const container = document.getElementById('phases');
            container.innerHTML = '';

            Object.values(phases).forEach(phase => {
                const successRate = phase.processed_items > 0
                    ? Math.round((phase.successful_items / phase.processed_items) * 100)
                    : 0;

                const phaseHtml = `
                    <div class="phase-card">
                        <div class="phase-header">
                            <h3>${phase.name}</h3>
                            <span class="status-badge status-${phase.status.toLowerCase()}">${phase.status}</span>
                        </div>
                        <div class="progress-bar">
                            <div class="progress-fill" style="width: ${(phase.processed_items / phase.total_items * 100)}%">
                                ${phase.processed_items} / ${phase.total_items}
                            </div>
                        </div>
                        <div>Success Rate: ${successRate}% | Throughput: ${phase.throughput.toFixed(2)}/s</div>
                        ${phase.active_agents.length > 0 ? renderAgents(phase.active_agents) : ''}
                    </div>
                `;
                container.innerHTML += phaseHtml;
            });
        }

        function renderAgents(agents) {
            let html = '<div class="agent-list"><h4>Active Agents:</h4>';
            agents.forEach(agent => {
                html += `
                    <div class="agent-item">
                        <span>${agent.id}: ${agent.current_item || 'Idle'}</span>
                        <span class="status-badge status-${agent.status.toLowerCase()}">${agent.status}</span>
                    </div>
                `;
            });
            html += '</div>';
            return html;
        }

        // Fetch initial data
        fetch('/api/progress')
            .then(response => response.json())
            .then(data => updateDashboard(data));
    </script>
</body>
</html>
"#;