-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add swarm dashboard tooling and package manifest #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| $traceFile = "C:\\PersonalRepo\\.planning\\traces.jsonl" | ||
| $clearString = [char]27 + "[2J" + [char]27 + "[H" | ||
|
|
||
| while ($true) { | ||
| Write-Host -NoNewline $clearString | ||
| Write-Host "================================================================================" -ForegroundColor Cyan | ||
| Write-Host " LIVE SWARM DASHBOARD (2026 OTel Architecture) " -ForegroundColor White -BackgroundColor DarkBlue | ||
| Write-Host "================================================================================`n" -ForegroundColor Cyan | ||
|
|
||
| if (Test-Path $traceFile) { | ||
| # Read the last 15 lines so the dashboard doesn't overflow | ||
| $rawLines = Get-Content -Path $traceFile -Tail 15 -ErrorAction SilentlyContinue | ||
|
|
||
| $logs = @() | ||
| foreach ($line in $rawLines) { | ||
| try { | ||
| if (-not [string]::IsNullOrWhiteSpace($line)) { | ||
| $logs += $line | ConvertFrom-Json -ErrorAction Stop | ||
| } | ||
| } catch { | ||
| # Skip invalid JSON lines | ||
| } | ||
| } | ||
|
|
||
| if ($logs.Count -gt 0) { | ||
| $formattedLogs = foreach ($log in $logs) { | ||
| $reason = $log.reasoning_path | ||
| if ($null -ne $reason -and $reason.Length -gt 60) { | ||
| $reason = $reason.Substring(0,57) + "..." | ||
| } | ||
|
|
||
| [PSCustomObject]@{ | ||
| Time = [datetime]::Parse($log.timestamp).ToString("HH:mm:ss") | ||
| Span = if ($log.span_id) { $log.span_id } else { "N/A" } | ||
| Persona = if ($log.persona) { $log.persona } else { "Unknown" } | ||
| Action = if ($log.action_type) { $log.action_type } else { "Unknown" } | ||
| Tokens = if ($log.metrics.total_tokens) { $log.metrics.total_tokens } else { 0 } | ||
| Reasoning = $reason | ||
| } | ||
| } | ||
| $formattedLogs | Format-Table -AutoSize | ||
| } else { | ||
| Write-Host "No valid traces found yet." -ForegroundColor Yellow | ||
| } | ||
| } else { | ||
| Write-Host "Waiting for traces... ($traceFile not found)" -ForegroundColor Yellow | ||
| } | ||
|
|
||
| Write-Host "`nPress Ctrl+C to exit. Refreshing every 2 seconds..." -ForegroundColor DarkGray | ||
| Start-Sleep -Seconds 2 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Promptimprover Swarm Dashboard</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| </head> | ||
| <body> | ||
| <header> | ||
| <h1>Promptimprover Swarm Dashboard</h1> | ||
| </header> | ||
| <main> | ||
| <table id="dashboard"> | ||
| <thead> | ||
| <tr> | ||
| <th>Time</th> | ||
| <th>Span</th> | ||
| <th>Persona</th> | ||
| <th>Action</th> | ||
| <th>Tokens</th> | ||
| <th>Reasoning</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody></tbody> | ||
| </table> | ||
| </main> | ||
| <script> | ||
| async function fetchData() { | ||
| const resp = await fetch('/data'); | ||
| const logs = await resp.json(); | ||
| const tbody = document.querySelector('#dashboard tbody'); | ||
| tbody.innerHTML = ''; | ||
| logs.reverse().forEach(log => { | ||
| const tr = document.createElement('tr'); | ||
| const fmtTime = new Date(log.timestamp).toLocaleTimeString(); | ||
| const reason = log.reasoning_path && log.reasoning_path.length > 60 ? log.reasoning_path.slice(0,57) + '...' : log.reasoning_path; | ||
| tr.innerHTML = ` | ||
| <td>${fmtTime}</td> | ||
| <td>${log.span_id || 'N/A'}</td> | ||
| <td>${log.persona || 'Unknown'}</td> | ||
| <td>${log.action_type || 'Unknown'}</td> | ||
| <td>${log.metrics?.total_tokens || 0}</td> | ||
| <td>${reason || ''}</td> | ||
| `; | ||
| tbody.appendChild(tr); | ||
| }); | ||
| } | ||
| setInterval(fetchData, 2000); | ||
| fetchData(); | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // C:\PersonalRepo\portfolio\Promptimprover\dashboard\server.js | ||
| const http = require('http'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const url = require('url'); | ||
| const { once } = require('events'); | ||
|
|
||
| const TRACE_FILE = path.resolve('C:/PersonalRepo/.planning/traces.jsonl'); | ||
| const STATIC_DIR = path.join(__dirname); | ||
| const PORT = 3000; | ||
|
|
||
| // Helper: read last N lines from trace file | ||
| async function readLastLines(filePath, maxLines = 20) { | ||
| const stream = fs.createReadStream(filePath, { encoding: 'utf8' }); | ||
| let data = ''; | ||
| stream.on('data', chunk => { data += chunk; }); | ||
| await once(stream, 'end'); | ||
| const lines = data.trim().split(/\r?\n/); | ||
| const recent = lines.slice(-maxLines); | ||
| // parse each JSON line safely | ||
| return recent.map(l => { | ||
| try { return JSON.parse(l); } catch (_) { return null; } | ||
| }).filter(Boolean); | ||
| } | ||
|
|
||
| function serveStatic(res, filePath, contentType) { | ||
| fs.readFile(filePath, (err, content) => { | ||
| if (err) { | ||
| res.writeHead(404); | ||
| res.end('Not found'); | ||
| } else { | ||
| res.writeHead(200, { 'Content-Type': contentType }); | ||
| res.end(content); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| const server = http.createServer(async (req, res) => { | ||
| const parsed = url.parse(req.url, true); | ||
| if (parsed.pathname === '/' || parsed.pathname === '/index.html') { | ||
| serveStatic(res, path.join(STATIC_DIR, 'index.html'), 'text/html'); | ||
| } else if (parsed.pathname === '/style.css') { | ||
| serveStatic(res, path.join(STATIC_DIR, 'style.css'), 'text/css'); | ||
| } else if (parsed.pathname === '/data') { | ||
| try { | ||
| const logs = await readLastLines(TRACE_FILE, 20); | ||
| res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
| res.end(JSON.stringify(logs)); | ||
| } catch (e) { | ||
| res.writeHead(500); | ||
| res.end('Error reading trace file'); | ||
|
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the dashboard is opened before Useful? React with 👍 / 👎. |
||
| } | ||
| } else { | ||
| res.writeHead(404); | ||
| res.end('Not found'); | ||
| } | ||
| }); | ||
|
|
||
| server.listen(PORT, () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| console.log(`Promptimprover dashboard listening on http://localhost:${PORT}`); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "name": "promptimprover", | ||
| "version": "0.1.0", | ||
| "scripts": { | ||
| "dashboard": "powershell -NoProfile -ExecutionPolicy Bypass -File ./run-dashboard.ps1", | ||
| "dashboard-web": "node dashboard/server.js" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| $script = Join-Path $PSScriptRoot "dashboard\View-SwarmDashboard.ps1" | ||
| if (Test-Path $script) { | ||
| powershell -NoProfile -ExecutionPolicy Bypass -File $script | ||
| } else { | ||
| Write-Host "Dashboard script not found at $script" -ForegroundColor Red | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a trace entry contains HTML in fields such as
reasoning_path,persona, oraction_type, assigning the interpolated row toinnerHTMLlets that markup execute in the dashboard, so model- or prompt-derived trace text can become script in the operator's browser. Build the cells withtextContentor escape each value before interpolation.Useful? React with 👍 / 👎.