Skip to content
Open
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
11 changes: 11 additions & 0 deletions pi-slate/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased

### Added

- Sidebar SPEED section: tok/s of the latest response (exact: output tokens ÷ response time), a graph of recent responses, turn average, output and peak. Responses under 32 tokens or 300 ms are not timed. On tall terminals the figure is drawn in large digits.
- Sidebar CACHE section: hit % of the latest request, a read/write/new bar, spend and estimated savings. A warm/cold countdown appears only when the model publishes its cache lifetime.
- The status row shows Working/Idle, the turn number, and the running turn's elapsed time.

### Changed

- The sidebar header is reorganised into status, CONTEXT, SPEED and CACHE, which share one layout (heading with the key figure on the right, one bar or graph row, labelled details), and adapts to terminal height (full, compact, mini). CONTEXT is a single bar; use pi-context-view for the category breakdown.
- Live speed updates to the sidebar are throttled to about 4 per second.

## 0.2.1

Fallback improvements for newer updates, Remove redundant notification in new sessions, misc. UI improvements around 'model', 'thinking', & 'warning' variables.
Expand Down
32 changes: 25 additions & 7 deletions pi-slate/extensions/pi-slate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { mcpDetails } from "./sidebar-mcp.ts";
import { SlateDiagnostics } from "./diagnostics.ts";
import { TurnCompletion } from "./turn-completion.ts";
import { resolveContextTokens } from "./context-usage.ts";
import { branchPerf } from "./perf-stats.ts";
import { estimateAssistantTokens, TokenRateTracker } from "./token-rate.ts";
import { createWordPicker } from "./working-words.ts";
import { advanceWave, isProgressStyle, isWaveActive, PROGRESS_STYLES, setProgressStyle, setWaveActive, type ProgressStyle } from "./working-wave.ts";
Expand Down Expand Up @@ -229,7 +230,10 @@ export default function piSlate(pi: ExtensionAPI): void {
let lastTurnMs: number | null = null;
let dashboardClock: ReturnType<typeof setInterval> | undefined;
const dashboardSubscriptions: Array<() => void> = [];
let branchFacts: { leaf?: string | null; counts: ReturnType<typeof sidebarMessageCounts>; usage: ReturnType<typeof sidebarUsage> } | undefined;
let branchFacts: { leaf?: string | null; counts: ReturnType<typeof sidebarMessageCounts>; usage: ReturnType<typeof sidebarUsage>; perf: ReturnType<typeof branchPerf> } | undefined;
let liveStreaming = false;
let lastLiveSync = 0;
let liveSyncTimer: ReturnType<typeof setTimeout> | undefined;
let inspectingSidebar = false;
let sidebarYielded = false;
let sessionEpoch = 0;
Expand Down Expand Up @@ -329,17 +333,20 @@ export default function piSlate(pi: ExtensionAPI): void {
const leaf = ctx.sessionManager.getLeafId?.();
if (!branchFacts || leaf === undefined || leaf !== branchFacts.leaf) {
const entries = ctx.sessionManager.getBranch();
branchFacts = { leaf, counts: sidebarMessageCounts(entries), usage: sidebarUsage(entries) };
branchFacts = { leaf, counts: sidebarMessageCounts(entries), usage: sidebarUsage(entries),
perf: branchPerf(entries, { promptCache: ctx.model?.promptCache, retentionLong: process.env.PI_CACHE_RETENTION === "long" }) };
}
const liveRate = tokenRate.rate();
const mcpCount = resources.mcp.filter(server => server.enabled === true).length;
if (owns("sidebar") && !sidebarYielded) {
sidebar.setSession({
id: ctx.sessionManager.getSessionId?.() ?? "",
name: ctx.sessionManager.getSessionName?.(),
pid: process.pid, cwd: ctx.cwd, model: modelStatusLabel(ctx.model, config.modelDisplay), thinking: ctx.thinkingLevel ?? "—",
tokens, percent, contextWindow, estimated,
rate: tokenRate.rate() > 0 ? tokenRate.rate() : null, startedAt: sessionStartedAt, lastTurnMs,
rate: tokenRate.rate() > 0 ? tokenRate.rate() : null, startedAt: sessionStartedAt, lastTurnMs, turnStartedAt: turnStartedAt ?? null,
working: typeof ctx.isIdle === "function" && !ctx.isIdle(), ...branchFacts.counts, usage: branchFacts.usage,
perf: { ...branchFacts.perf, live: { streaming: liveStreaming, rate: liveStreaming && liveRate > 0 ? liveRate : null } },
});
}
contextEdge = {
Expand Down Expand Up @@ -429,14 +436,21 @@ export default function piSlate(pi: ExtensionAPI): void {
}, () => {});
}
if (owns("editor")) branch.start(ctx.cwd);
sessionStartedAt = Date.now(); turnStartedAt = undefined; lastTurnMs = null; branchFacts = undefined;
sessionStartedAt = Date.now(); turnStartedAt = undefined; lastTurnMs = null; branchFacts = undefined; liveStreaming = false;
if (owns("editor") || owns("sidebar")) {
skills.reset([]);
skills.restore(ctx.sessionManager.getBranch(), ctx.cwd);
refreshResources(ctx);
tokenRate.setOnChange(() => {
const ctx = liveContext();
if (ctx) syncSidebar(ctx);
// Per-token updates reach the sidebar at most ~4/s; a trailing sync keeps the last one.
const flush = (): void => {
liveSyncTimer = undefined; lastLiveSync = Date.now();
const live = liveContext();
if (live) syncSidebar(live);
};
const wait = 250 - (Date.now() - lastLiveSync);
if (wait <= 0) { if (liveSyncTimer) clearTimeout(liveSyncTimer); flush(); }
else if (!liveSyncTimer) liveSyncTimer = setTimeout(flush, wait);
if (thinkingFold.elapsedMs() !== null) syncThinkingStatus();
});
syncSidebar(ctx);
Expand Down Expand Up @@ -699,6 +713,7 @@ export default function piSlate(pi: ExtensionAPI): void {
});
pi.on("model_select", (_event, ctx) => {
currentContext = ctx;
branchFacts = undefined; // cache lifetime depends on the selected model
syncSidebar(ctx);
});
pi.on("thinking_level_select", (_event, ctx) => {
Expand All @@ -710,6 +725,7 @@ export default function piSlate(pi: ExtensionAPI): void {
currentContext = ctx;
if (event.message.role === "assistant") {
thinkingFold.stop();
liveStreaming = true;
if (ctx.mode === "tui" && (owns("editor") || owns("sidebar"))) tokenRate.startMessage();
}
});
Expand All @@ -727,6 +743,7 @@ export default function piSlate(pi: ExtensionAPI): void {
currentContext = ctx;
if (event.message.role === "assistant") {
thinkingFold.stop();
liveStreaming = false;
if (ctx.mode === "tui" && (owns("editor") || owns("sidebar"))) tokenRate.endMessage();
} else if (owns("sidebar") && ctx.mode === "tui" && event.message.role === "toolResult") {
skills.observeNested(event.message.nestedCalls?.calls ?? [], ctx.cwd);
Expand Down Expand Up @@ -773,7 +790,7 @@ export default function piSlate(pi: ExtensionAPI): void {
currentContext = ctx;
thinkingFold.stop();
if (owns("sidebar") && ctx.mode === "tui") {
branchFacts = undefined; skills.restore(ctx.sessionManager.getBranch(), ctx.cwd);
branchFacts = undefined; liveStreaming = false; skills.restore(ctx.sessionManager.getBranch(), ctx.cwd);
background.reset(ctx.sessionManager.getSessionId?.() ?? ""); sidebar.setTasks([]);
pi.events.emit?.(BACKGROUND_TASKS_REQUEST, { version: 1, sessionId: ctx.sessionManager.getSessionId?.() ?? "" });
refreshResources(ctx); syncSidebar(ctx);
Expand All @@ -782,6 +799,7 @@ export default function piSlate(pi: ExtensionAPI): void {
});
pi.on("session_shutdown", (_event, ctx) => {
sessionEpoch += 1;
liveStreaming = false; if (liveSyncTimer) { clearTimeout(liveSyncTimer); liveSyncTimer = undefined; }
workingWord = undefined;
stopWave();
thinkingFold.stop();
Expand Down
Loading
Loading