From e2ae722910461581fec0308759026db861b09f14 Mon Sep 17 00:00:00 2001 From: Sam Rolfe Date: Wed, 29 Jul 2026 10:14:15 +1000 Subject: [PATCH] sam-4screen-desktop 2026-7-29:10:14:15 --- .obsidian/workspace.json | 4 +- 100 inbox/Pi Dashboard.md | 155 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 100 inbox/Pi Dashboard.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 1d88b1b..33658ba 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -207,8 +207,9 @@ "templater-obsidian:Templater": false } }, - "active": "29ff3dd1c6bfd474", + "active": "7066c9273c6fb936", "lastOpenFiles": [ + "100 inbox/Pi Dashboard.md", "000 daily/House Family General.md", "000 daily/Update Install.md", "300 areas/350 AI/Pi Agent Extensions & Skills.md", @@ -235,7 +236,6 @@ "200 projects/260 Build Create Make/Digital Binoculars.md", "400 resources/410 Web Pages/Website Design AI.md", "400 resources/410 Web Pages/Metasploit Osint - security hacking.md", - "400 resources/410 Web Pages/Sn0int Osint - security hacking.md", "500 archive/510 Daily", "300 areas/305 Ideas Businesses", "400 resources/470 Holidays Travel", diff --git a/100 inbox/Pi Dashboard.md b/100 inbox/Pi Dashboard.md new file mode 100644 index 0000000..5346911 --- /dev/null +++ b/100 inbox/Pi Dashboard.md @@ -0,0 +1,155 @@ +# Pi Dashboard + +## What It Is + +A **terminal-based live dashboard** that shows what all pi coding agents are doing across the system. Runs in a Zellij pane or detached tmux session. Shows sub-agent status, current tasks, token consumption, and cost — all in one place. + +## Architecture + +``` +┌─────────────────────────────────────────────────────────────────┐ +│ Background: Detached tmux sessions (nixos-desktop .13) │ +│ │ +│ tmux session "pi-work" │ +│ ├── pi (model: opencode-go/deepseek-v4-flash) ← coder-basic │ +│ ├── pi (model: deepseek/deepseek-v4-pro) ← coder-pro │ +│ └── pi (model: google/gemini-2.5-flash) ← research │ +│ └── Each has extension: dashboard.ts │ +│ └── Writes state → ~/.pi/agent/dashboard/.json │ +│ │ +│ tmux session "pi-explore" │ +│ └── pi (model: opencode-go/deepseek-v4-flash) ← explore │ +│ └── Extension: dashboard.ts │ +│ └── Writes state → ~/.pi/agent/dashboard/.json │ +└─────────────────────────────────────────────────────────────────┘ + │ + ▼ +┌─────────────────────────────────────────────────────────────────┐ +│ Viewer: Zellij pane (or separate terminal) │ +│ │ +│ bin/pi-dashboard (standalone TUI binary) │ +│ └── Reads all ~/.pi/agent/dashboard/*.json │ +│ └── Renders table of all agents with live status │ +│ └── Press Enter on a row → attach to that tmux session │ +│ │ +│ Optional: also serves HTTP on :9876 for phone (Termux) │ +└─────────────────────────────────────────────────────────────────┘ +``` + +### Key Insight: Two-Component Design + +| Component | What it does | How it runs | +|-----------|-------------|-------------| +| **dashboard.ts** (pi extension) | Lives inside each pi session. Listens to events (`agent_start`, `agent_end`, `tool_call`). Writes JSON state files. Starts optional HTTP server. | Loaded by pi at startup from `~/.pi/agent/extensions/` | +| **pi-dashboard** (standalone TUI) | Separate binary. Reads all state files. Renders the unified dashboard. Lets you jump into sessions. | Run from any terminal — Zellij pane, tmux window, Termux SSH | + +## Why This Design + +- **dashboard.ts** has access to pi's event system (it runs inside pi) +- But it can only see its own pi session +- **pi-dashboard** is external and can aggregate all sessions +- Separates concerns: collection (inside pi) vs visualization (outside pi) +- The viewer binary can be written in any language — Go recommended + +## Required Components + +### 1. dashboard.ts (pi extension) + +- Hooks: `agent_start`, `agent_end`, `tool_call` +- Tracks: sub-agent name, model, status, start time, duration, last tool, token count +- Persistence: writes to `~/.pi/agent/dashboard/.json` +- Uses atomic writes (write to `.tmp` then rename) to avoid corruption +- Also: small HTTP server on localhost:9876 for real-time polling + +Pi's extension API provides everything needed: +- `pi.on("agent_start", ...)` — fired when agent turn starts +- `pi.on("agent_end", ...)` — fired when agent turn ends +- `pi.on("tool_call", ...)` — fired on each tool invocation +- `ctx.sessionManager` — session state access + +### 2. pi-dashboard viewer + +- Standalone binary (Go recommended — see Tech Stack below) +- Directory watcher on `~/.pi/agent/dashboard/` +- Renders a live table of all agent sessions +- Features per row: + - Agent type/name + - Model/provider + - Status (idle, running, waiting, error, done) + - Current task description + - Duration + - Token count & running cost + - Last activity timestamp +- Keyboard controls: + - `Enter` → attach to that tmux session + - `r` → refresh + - `q` → quit + - `/` → filter/search agents +- Optional web mode: `--web` flag starts HTTP server on :9876 + +## Implementation Steps + +### Phase 1: dashboard.ts extension (1 day) + +1. Create `~/.pi/agent/extensions/dashboard.ts` +2. Implement event listeners for `agent_start`, `agent_end`, `tool_call` +3. Accumulate state: Map +4. Write snapshot to `~/.pi/agent/dashboard/.json` on each event +5. Use atomic file writes (write to .tmp, rename) +6. Register `/dashboard` command that prints a simple in-extension status list + +### Phase 2: Go TUI viewer (1-2 days) + +1. Create `~/bin/pi-dashboard/` Go module +2. Use Bubble Tea for TUI rendering +3. Implement file watcher (fsnotify) on the dashboard directory +4. Build table view with agent state columns +5. Add status indicators with colors +6. Add keyboard controls (attach, filter, quit) +7. Test: launch two pi sessions in tmux, verify aggregated view + +### Phase 3: Attach/jump (half day) + +1. Extract tmux session name from the state file +2. `Enter` key → `tmux attach-session -t ` +3. Or launch a new pi session from the dashboard + +### Phase 4: Polish (ongoing) + +- Historical cost tracking across sessions +- Notification when an agent stalls or errors +- Web mode for phone access +- Alerts/markers when agents finish tasks + +## How Sessions Tie Together + +The convention for naming: + +```bash +tmux new-session -d -s pi-work 'pi --model opencode-go/deepseek-v4-flash' +# dashboard.ts writes to ~/.pi/agent/dashboard/pi-work.json +# The session name "pi-work" ties the dashboard entry to the tmux session +``` + +When you press Enter on "pi-work" in the dashboard: +```bash +tmux attach-session -t pi-work +``` + +When running pi without tmux, dashboard.ts writes to `~/.pi/agent/dashboard/unsorted.json` — the viewer still picks it up. + +## Prerequisites Already Met + +- ✅ Node.js (everything runs on it) +- ✅ Go (if chosen for TUI — installable via nix) +- ✅ Pi extension system (all hooks available) +- ✅ tmux (already available) +- ✅ Shared filesystem (state files are local) +- ✅ OmniRoute for model routing + +## Open Questions + +1. What does the dashboard show when pi is idle (no active agent)? +2. Should the viewer support resuming a session or only viewing? +3. How far back to keep history? Last N turns? Last 24h? +4. Web mode: full dashboard or just alerts / status summary?