Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions dashboard/View-SwarmDashboard.ps1
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
}
51 changes: 51 additions & 0 deletions dashboard/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!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;
['time', 'span', 'persona', 'action', 'tokens', 'reasoning'].forEach((k, i) => {
const td = document.createElement('td');
const values = [fmtTime, log.span_id || 'N/A', log.persona || 'Unknown', log.action_type || 'Unknown', log.metrics?.total_tokens || 0, reason || ''];
td.textContent = values[i];
tr.appendChild(td);
});
tbody.appendChild(tr);
});
}
setInterval(fetchData, 2000);
fetchData();
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions dashboard/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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) {
if (!fs.existsSync(filePath)) return [];
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return JSON when the trace file is absent

When the dashboard is opened before C:\PersonalRepo\.planning\traces.jsonl exists, such as on a fresh checkout or any machine without that local path, /data reaches this catch and sends a plain-text 500 while dashboard/index.html always calls await resp.json(). That makes every poll throw and leaves the web dashboard blank instead of showing an empty/waiting state; return JSON like [] or handle non-OK responses in the client.

Useful? React with 👍 / 👎.

}
} else {
res.writeHead(404);
res.end('Not found');
}
});

server.listen(PORT, '127.0.0.1', () => {
console.log(`Promptimprover dashboard listening on http://127.0.0.1:${PORT}`);
});
8 changes: 8 additions & 0 deletions package.json
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"
}
}
6 changes: 6 additions & 0 deletions run-dashboard.ps1
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
}
Loading