dashboard: per-session event files, cleanup, and autoscroll

- Write each session's dashboard events to its own file
  (~/.pi-lens/dashboard-events/{sessionId}.jsonl) instead of a shared file
- Support PI_LENS_DASHBOARD_LOG env var with {sessionId} template
- Reset terminalStarted flag on shutdown so each session spawns its own
  dashboard terminal watching the correct per-session file
- Add runDashboardLogCleanup() to prune old session files (default 7 days,
  configurable via PI_LENS_DASHBOARD_RETENTION_DAYS)
- Call dashboard cleanup at session start alongside existing log cleanup
- Dashboard terminal now auto-scrolls viewport to bottom on each render
  so latest content is always visible
This commit is contained in:
Apostolos Mantzaris committed 2026-05-04 03:10:48 +03:00
1 parent dee2f051be
commit 4aee073157
20 files changed
+297 -8

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
{
"name": "go-pipeline-dispatch-poc",
"description": "PoC headless pi case that updates a tiny Go invoice utility project and captures pipeline/dispatch feedback.",
"model": "opencode/minimax-m2.5-free",
"startupMode": "quick",
"allowedTools": ["read", "write", "edit", "bash"],
"expectedFiles": ["main.go", "totals.go"],
"expectedToolCalls": ["read", "write"],
"expectedWorkflow": {
"readBeforeFirstMutation": true,
"lspUsed": false,
"readGuardTriggered": false
},
"maxFailedToolCalls": 0,
"maxToolCallCount": 12,
"allowedFailureKinds": []
}
+10
View File
@@ -0,0 +1,10 @@
Turn this into a tiny Go invoice utility project.
Requirements:
1. Keep go.mod as-is.
2. Work only in the workspace root.
3. Create totals.go exporting `sumInvoiceTotals(invoices []Invoice) int`.
4. Update main.go to use that helper and expose a `demoTotal` variable computed from two sample invoices.
5. Fix any diagnostics pi-lens surfaces while you work.
6. Do not add dependencies.
7. End with a short summary of what you changed.
@@ -0,0 +1,3 @@
module example.com/go-pipeline-dispatch-poc
go 1.22
@@ -0,0 +1,13 @@
package main
import "fmt"
type Invoice struct {
ID string
TotalCents int
}
func main() {
invoices := []Invoice{{ID: "inv-001", TotalCents: 1250}, {ID: "inv-002", TotalCents: 3300}}
fmt.Println(invoices)
}
@@ -0,0 +1,25 @@
{
"name": "python-autofix-default-poc",
"description": "Validate Python smart-default autofix/cleanup behavior in a Ruff-configured workspace.",
"model": "opencode/minimax-m2.5-free",
"startupMode": "full",
"allowedTools": ["read", "write", "edit", "bash"],
"expectedFiles": ["src/main.py", "src/helpers.py"],
"expectedToolCalls": ["read", "write"],
"forbiddenChangedFiles": ["pyproject.toml"],
"expectedRuntimeMarkers": ["modified by auto-format/fix"],
"expectedWorkflow": {
"readBeforeFirstMutation": true,
"autoformatNoticeSeen": true,
"fileChangedNoticeSeen": true,
"readGuardTriggered": false,
"lspUsed": false
},
"maxFailedToolCalls": 1,
"maxToolCallCount": 20,
"allowedFailureKinds": [
"file_changed_notice",
"missing_module",
"autofix_notice"
]
}
@@ -0,0 +1,11 @@
Turn this into a tiny Python helper-based invoice example.
Requirements:
1. Keep pyproject.toml as-is.
2. Work only inside src/.
3. Create src/helpers.py exporting `format_invoice_label(invoice_id: str) -> str`.
4. Update src/main.py to use that helper and expose `demo_total` as an int.
5. Preserve existing imports unless pi-lens/default tooling changes them for you as part of fixing surfaced issues.
6. Fix any diagnostics pi-lens surfaces while you work.
7. Do not add dependencies.
8. End with a short summary of what you changed.
@@ -0,0 +1,7 @@
[project]
name = "python-autofix-default-poc"
version = "0.0.0"
requires-python = ">=3.11"
[tool.ruff]
line-length = 88
@@ -0,0 +1,13 @@
import os
sample_invoices = [
{"id": "inv-001", "total_cents": 1250},
{"id": "inv-002", "total_cents": 3300},
]
def build_total() -> str:
return str(sum(invoice["total_cents"] for invoice in sample_invoices))
demo_total = build_total()
@@ -0,0 +1,9 @@
{
"name": "python-pipeline-dispatch-poc",
"description": "PoC headless pi case that updates a tiny Python invoice utility project and captures pipeline/dispatch feedback.",
"model": "opencode/minimax-m2.5-free",
"allowedTools": ["read", "write", "edit", "bash"],
"expectedFiles": ["src/main.py", "src/totals.py"],
"expectedToolCalls": ["read", "write"],
"forbiddenChangedFiles": ["pyproject.toml"]
}
@@ -0,0 +1,11 @@
Turn this into a tiny Python invoice utility project.
Requirements:
1. Keep pyproject.toml as-is.
2. Work only inside src/.
3. Create src/totals.py exporting:
`sum_invoice_totals(invoices: list[dict[str, int | str]]) -> int`
4. Update src/main.py to import that function and expose `demo_total`, computed from two sample invoices.
5. Fix any diagnostics pi-lens surfaces while you work.
6. Do not add dependencies.
7. End with a short summary of what you changed.
@@ -0,0 +1,7 @@
[project]
name = "python-pipeline-dispatch-poc"
version = "0.0.0"
requires-python = ">=3.11"
[tool.ruff]
line-length = 88
@@ -0,0 +1,15 @@
from typing import TypedDict
class Invoice(TypedDict):
id: str
total_cents: int
sample_invoices: list[Invoice] = [
{"id": "inv-001", "total_cents": 1250},
{"id": "inv-002", "total_cents": 3300},
]
demo_total: str = str(sum(invoice["total_cents"] for invoice in sample_invoices))
+25
View File
@@ -0,0 +1,25 @@
{
"name": "ts-format-default-poc",
"description": "Validate TypeScript smart-default formatting in a no-config workspace while preserving pipeline/dispatch behavior.",
"model": "opencode/minimax-m2.5-free",
"startupMode": "full",
"allowedTools": ["read", "write", "edit", "bash"],
"expectedFiles": ["src/main.ts"],
"expectedToolCalls": ["read", "edit"],
"forbiddenChangedFiles": ["package.json", "tsconfig.json"],
"expectedRuntimeMarkers": ["modified by auto-format/fix"],
"expectedWorkflow": {
"readBeforeFirstMutation": true,
"autoformatNoticeSeen": true,
"fileChangedNoticeSeen": true,
"readGuardTriggered": false,
"lspUsed": false
},
"maxFailedToolCalls": 1,
"maxToolCallCount": 12,
"allowedFailureKinds": [
"file_changed_notice",
"edit_mismatch",
"autofix_notice"
]
}
+10
View File
@@ -0,0 +1,10 @@
Update src/main.ts to add a third sample invoice with totalCents 700 and export `demoCount`, the number of invoices.
Requirements:
1. Keep package.json and tsconfig.json as-is.
2. Work only inside src/.
3. Preserve the existing behavior of demoTotal.
4. Do not manually reformat unrelated code just to make it pretty; make the requested semantic change and let pi-lens/default tooling do any formatting it wants.
5. Fix any diagnostics pi-lens surfaces while you work.
6. Do not add dependencies.
7. End with a short summary of what you changed.
@@ -0,0 +1,6 @@
{
"name": "ts-format-default-poc",
"private": true,
"type": "module",
"version": "0.0.0"
}
@@ -0,0 +1,3 @@
type Invoice={id:string,totalCents:number}
const sampleInvoices:Invoice[]=[{id:"inv-001",totalCents:1250},{id:"inv-002",totalCents:3300}]
export const demoTotal=sampleInvoices.reduce((sum,invoice)=>sum+invoice.totalCents,0)
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noEmit": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"]
}
+84 -7
View File
@@ -1,8 +1,14 @@
/**
* pi-lens dashboard event bus.
*
* Emits a small, redacted JSONL stream that can be consumed by the upcoming
* Emits a small, redacted JSONL stream that can be consumed by the
* terminal dashboard (and later Glimpse/browser UIs). Disabled by default.
*
* Each session writes to its own log file to keep events isolated per session.
* Log path resolution (first match):
* 1. PI_LENS_DASHBOARD_LOG env var (template: {sessionId} is replaced)
* 2. options.logPath (if provided)
* 3. ~/.pi-lens/dashboard-events/{sessionId}.jsonl
*/
import { spawn } from "node:child_process";
@@ -34,6 +40,78 @@ let currentLogPath: string | undefined;
let terminalStarted = false;
const MAX_PREVIEW_CHARS = 240;
/**
* Directory under ~/.pi-lens/ that holds per-session dashboard event files.
*/
const DASHBOARD_EVENTS_DIR = path.join(
os.homedir(),
".pi-lens",
"dashboard-events",
);
/**
* Resolve the per-session log path for dashboard events.
* Priority:
* 1. PI_LENS_DASHBOARD_LOG env var (template: {sessionId} is replaced)
* 2. options.logPath (explicit caller override)
* 3. ~/.pi-lens/dashboard-events/{sessionId}.jsonl (default)
*/
function resolveDashboardLogPath(options: DashboardBusOptions): string {
const envPath = process.env.PI_LENS_DASHBOARD_LOG?.trim();
if (envPath) {
return envPath.replace(/{sessionId}/g, options.sessionId);
}
if (options.logPath) {
return options.logPath.replace(/{sessionId}/g, options.sessionId);
}
return path.join(DASHBOARD_EVENTS_DIR, `${options.sessionId}.jsonl`);
}
/**
* Clean up dashboard event files older than the given retention period.
* Default: delete files older than 7 days.
*/
export function runDashboardLogCleanup(dbg?: (msg: string) => void): {
cleaned: number;
} {
const retentionDays = Math.max(
1,
Number.parseInt(process.env.PI_LENS_DASHBOARD_RETENTION_DAYS ?? "7", 10) ||
7,
);
let cleaned = 0;
try {
if (!fs.existsSync(DASHBOARD_EVENTS_DIR)) return { cleaned };
const files = fs.readdirSync(DASHBOARD_EVENTS_DIR);
const now = Date.now();
for (const file of files) {
if (!file.endsWith(".jsonl")) continue;
const filePath = path.join(DASHBOARD_EVENTS_DIR, file);
try {
const stat = fs.statSync(filePath);
const ageDays = (now - stat.mtime.getTime()) / (1000 * 60 * 60 * 24);
if (ageDays > retentionDays) {
fs.unlinkSync(filePath);
cleaned++;
}
} catch {
// skip files we can't stat
}
}
} catch {
// directory doesn't exist or can't be read
}
if (cleaned > 0) {
dbg?.(
`dashboard_cleanup: removed ${cleaned} old session file(s) (>${retentionDays}d)`,
);
}
return { cleaned };
}
const SECRET_KEY_RE =
/(?:content|text|oldText|newText|replacement|password|token|secret|key|apiKey|authorization|cookie)/i;
const PATHISH_KEY_RE =
@@ -46,18 +124,16 @@ export function configureDashboardBus(options: DashboardBusOptions): void {
sessionId = options.sessionId;
if (!enabled) return;
currentLogPath =
options.logPath ??
path.join(os.homedir(), ".pi-lens", "dashboard-events.jsonl");
currentLogPath = resolveDashboardLogPath(options);
try {
fs.mkdirSync(path.dirname(currentLogPath), { recursive: true });
fs.mkdirSync(path.dirname(currentLogPath!), { recursive: true });
stream = fs.createWriteStream(currentLogPath, { flags: "a" });
emitDashboardEvent({
type: "lens.dashboard.start",
logPath: currentLogPath,
logPath: currentLogPath!,
});
if (process.env.PI_LENS_DASHBOARD_LOG_ONLY !== "1") {
startTerminalDashboard(currentLogPath);
startTerminalDashboard(currentLogPath!);
}
} catch {
enabled = false;
@@ -76,6 +152,7 @@ export function shutdownDashboardBus(): void {
enabled = false;
projectRoot = "";
sessionId = "";
terminalStarted = false;
}
export function isDashboardBusEnabled(): boolean {
+3
View File
@@ -16,6 +16,7 @@ import {
getDefaultStartupTools,
} from "./language-profile.js";
import { runLogCleanup } from "./log-cleanup.js";
import { runDashboardLogCleanup } from "./dashboard-bus.js";
import { initLSPConfig, loadLSPConfig } from "./lsp/config.js";
import { getLSPService } from "./lsp/index.js";
import type { MetricsClient } from "./metrics-client.js";
@@ -451,6 +452,8 @@ export async function handleSessionStart(
if (logCleanup.cleaned > 0 || logCleanup.rotated > 0) {
notify(`🧹 ${logCleanup.report}`, "info");
}
// Clean up old per-session dashboard event files
runDashboardLogCleanup(dbg);
dbg(`session_start startup mode: ${startupMode}`);
if (!getFlag("no-lsp")) {
+14 -1
View File
@@ -170,6 +170,14 @@ function scheduleRender() {
renderTimer = setTimeout(render, 80);
}
function getTerminalHeight() {
try {
return process.stdout.rows || 24;
} catch {
return 24;
}
}
function render() {
const rows = [];
rows.push(
@@ -267,7 +275,12 @@ function render() {
if (ds.length > 3) rows.push(dim(` +${ds.length - 3} more`));
}
process.stdout.write("\x1b[2J\x1b[H" + rows.join("\n") + "\n");
const output = rows.join("\n");
process.stdout.write("\x1b[H" + output + "\n");
// Clear any leftover lines below the rendered content
process.stdout.write("\x1b[0J");
// Scroll viewport to the bottom so the latest content is visible
process.stdout.write("\x1b[999;1H");
}
function readNew() {