@narumitw/pi-statusline 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 narumiruna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # pi-statusline
2
+
3
+ A public [pi](https://pi.dev) extension package that replaces Pi's footer with a beautiful, information-rich statusline.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@narumitw/pi-statusline
9
+ ```
10
+
11
+ Try without installing:
12
+
13
+ ```bash
14
+ pi -e npm:@narumitw/pi-statusline
15
+ ```
16
+
17
+ Try this package locally from the repository root:
18
+
19
+ ```bash
20
+ pi -e ./extensions/pi-statusline
21
+ ```
22
+
23
+ ## What it shows
24
+
25
+ The default statusline includes:
26
+
27
+ - `π` brand marker
28
+ - emoji-labeled current model
29
+ - emoji-labeled thinking level
30
+ - emoji-labeled git branch
31
+ - emoji-labeled current project directory
32
+ - emoji-labeled active or last tool
33
+ - emoji-labeled context usage percentage
34
+ - emoji-labeled token totals
35
+ - emoji-labeled estimated cost
36
+ - emoji-labeled clock
37
+
38
+ Statuses from other extensions, such as goal mode, appear on their own emoji-labeled line below the main statusline and are separated with ``.
39
+ The layout adapts to terminal width and truncates safely.
40
+
41
+ ## Package layout
42
+
43
+ ```txt
44
+ extensions/pi-statusline/
45
+ ├── src/
46
+ │ └── statusline.ts
47
+ ├── README.md
48
+ ├── LICENSE
49
+ ├── tsconfig.json
50
+ └── package.json
51
+ ```
52
+
53
+ The package exposes its extension through `package.json`:
54
+
55
+ ```json
56
+ {
57
+ "pi": {
58
+ "extensions": ["./src/statusline.ts"]
59
+ }
60
+ }
61
+ ```
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@narumitw/pi-statusline",
3
+ "version": "0.1.3",
4
+ "description": "Pi extension that replaces the footer with an information-rich statusline.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "keywords": [
9
+ "pi-package",
10
+ "pi-extension",
11
+ "pi",
12
+ "statusline",
13
+ "footer"
14
+ ],
15
+ "files": [
16
+ "src",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "pi": {
21
+ "extensions": [
22
+ "./src/statusline.ts"
23
+ ]
24
+ },
25
+ "scripts": {
26
+ "check": "biome check . && npm run typecheck",
27
+ "format": "biome check --write .",
28
+ "typecheck": "tsc --noEmit"
29
+ },
30
+ "devDependencies": {
31
+ "@biomejs/biome": "2.4.14",
32
+ "@mariozechner/pi-coding-agent": "0.73.0",
33
+ "@mariozechner/pi-tui": "0.73.0",
34
+ "@types/node": "25.6.0",
35
+ "typescript": "6.0.3"
36
+ }
37
+ }
@@ -0,0 +1,466 @@
1
+ import { basename } from "node:path";
2
+ import type {
3
+ ExtensionAPI,
4
+ ExtensionContext,
5
+ ReadonlyFooterDataProvider,
6
+ Theme,
7
+ ThemeColor,
8
+ } from "@mariozechner/pi-coding-agent";
9
+ import { truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
10
+
11
+ type SegmentName =
12
+ | "brand"
13
+ | "model"
14
+ | "thinking"
15
+ | "branch"
16
+ | "cwd"
17
+ | "tools"
18
+ | "context"
19
+ | "tokens"
20
+ | "cost"
21
+ | "time"
22
+ | "turn";
23
+
24
+ type PaletteName = "ocean" | "sunset" | "forest" | "candy" | "neon" | "mono";
25
+ type Density = "compact" | "cozy";
26
+ type SeparatorName = "dot" | "bar" | "powerline" | "round" | "none";
27
+
28
+ type ThinkingLevel = ReturnType<ExtensionAPI["getThinkingLevel"]>;
29
+
30
+ interface StatuslineConfig {
31
+ palette: PaletteName;
32
+ density: Density;
33
+ separator: SeparatorName;
34
+ showLabels: boolean;
35
+ segments: SegmentName[];
36
+ }
37
+
38
+ interface RuntimeState {
39
+ turnCount: number;
40
+ activeTools: Map<string, number>;
41
+ lastTool?: string;
42
+ lastCompletedTool?: string;
43
+ isStreaming: boolean;
44
+ thinkingLevel: ThinkingLevel;
45
+ requestRender?: () => void;
46
+ }
47
+
48
+ interface TokenTotals {
49
+ input: number;
50
+ output: number;
51
+ cost: number;
52
+ }
53
+
54
+ interface RenderSegment {
55
+ name: SegmentName;
56
+ text: string;
57
+ color: ThemeColor;
58
+ emphasis?: boolean;
59
+ }
60
+
61
+ const STATUSLINE_KEY = "statusline";
62
+
63
+ const DEFAULT_SEGMENTS: SegmentName[] = [
64
+ "brand",
65
+ "model",
66
+ "thinking",
67
+ "branch",
68
+ "cwd",
69
+ "tools",
70
+ "context",
71
+ "tokens",
72
+ "cost",
73
+ "time",
74
+ ];
75
+
76
+ const RIGHT_SEGMENTS = new Set<SegmentName>(["context", "tokens", "cost", "time", "turn"]);
77
+
78
+ const PALETTES: Record<PaletteName, ThemeColor[]> = {
79
+ ocean: ["accent", "muted", "success", "warning"],
80
+ sunset: ["warning", "accent", "success", "muted"],
81
+ forest: ["success", "accent", "muted", "warning"],
82
+ candy: ["accent", "warning", "success", "muted"],
83
+ neon: ["accent", "success", "warning", "error"],
84
+ mono: ["muted", "dim"],
85
+ };
86
+
87
+ export default function statusline(pi: ExtensionAPI) {
88
+ const config = createDefaultConfig();
89
+ const runtime: RuntimeState = {
90
+ turnCount: 0,
91
+ activeTools: new Map(),
92
+ isStreaming: false,
93
+ thinkingLevel: "off",
94
+ };
95
+
96
+ const refresh = () => runtime.requestRender?.();
97
+
98
+ const installFooter = (ctx: ExtensionContext) => {
99
+ ctx.ui.setStatus(STATUSLINE_KEY, undefined);
100
+ ctx.ui.setFooter((tui, theme, footerData) => {
101
+ runtime.requestRender = () => tui.requestRender();
102
+
103
+ const branchUnsubscribe = footerData.onBranchChange(() => tui.requestRender());
104
+ const clock = setInterval(() => tui.requestRender(), 30_000);
105
+
106
+ return {
107
+ dispose() {
108
+ branchUnsubscribe();
109
+ clearInterval(clock);
110
+ },
111
+ invalidate() {},
112
+ render(width: number): string[] {
113
+ const lines = [renderStatusline(width, ctx, footerData, theme, config, runtime)];
114
+ const extensionStatusLine = renderExtensionStatusline(width, footerData, theme);
115
+ if (extensionStatusLine) lines.push(extensionStatusLine);
116
+ return lines;
117
+ },
118
+ };
119
+ });
120
+ };
121
+
122
+ pi.on("session_start", (_event, ctx) => {
123
+ runtime.thinkingLevel = pi.getThinkingLevel();
124
+ installFooter(ctx);
125
+ });
126
+
127
+ pi.on("session_tree", (_event, ctx) => {
128
+ installFooter(ctx);
129
+ refresh();
130
+ });
131
+
132
+ pi.on("session_shutdown", (_event, ctx) => {
133
+ ctx.ui.setFooter(undefined);
134
+ ctx.ui.setStatus(STATUSLINE_KEY, undefined);
135
+ runtime.requestRender = undefined;
136
+ });
137
+
138
+ pi.on("model_select", () => refresh());
139
+
140
+ pi.on("thinking_level_select", (event) => {
141
+ runtime.thinkingLevel = event.level;
142
+ refresh();
143
+ });
144
+
145
+ pi.on("agent_start", () => {
146
+ runtime.isStreaming = true;
147
+ refresh();
148
+ });
149
+
150
+ pi.on("agent_end", () => {
151
+ runtime.isStreaming = false;
152
+ refresh();
153
+ });
154
+
155
+ pi.on("turn_start", () => {
156
+ runtime.turnCount += 1;
157
+ runtime.isStreaming = true;
158
+ refresh();
159
+ });
160
+
161
+ pi.on("turn_end", () => refresh());
162
+
163
+ pi.on("tool_execution_start", (event) => {
164
+ const currentCount = runtime.activeTools.get(event.toolName) ?? 0;
165
+ runtime.activeTools.set(event.toolName, currentCount + 1);
166
+ runtime.lastTool = event.toolName;
167
+ refresh();
168
+ });
169
+
170
+ pi.on("tool_execution_end", (event) => {
171
+ const currentCount = runtime.activeTools.get(event.toolName) ?? 0;
172
+ if (currentCount <= 1) runtime.activeTools.delete(event.toolName);
173
+ else runtime.activeTools.set(event.toolName, currentCount - 1);
174
+
175
+ runtime.lastCompletedTool = event.toolName;
176
+ refresh();
177
+ });
178
+ }
179
+
180
+ function createDefaultConfig(): StatuslineConfig {
181
+ return {
182
+ palette: "candy",
183
+ density: "compact",
184
+ separator: "powerline",
185
+ showLabels: false,
186
+ segments: [...DEFAULT_SEGMENTS],
187
+ };
188
+ }
189
+
190
+ function renderStatusline(
191
+ width: number,
192
+ ctx: ExtensionContext,
193
+ footerData: ReadonlyFooterDataProvider,
194
+ theme: Theme,
195
+ config: StatuslineConfig,
196
+ runtime: RuntimeState,
197
+ ): string {
198
+ if (width <= 0) return "";
199
+
200
+ const segments = config.segments
201
+ .map((segment, index) => buildSegment(segment, index, ctx, footerData, config, runtime))
202
+ .filter(
203
+ (segment): segment is RenderSegment => segment !== undefined && segment.text.length > 0,
204
+ );
205
+
206
+ const left = joinSegments(
207
+ segments.filter((segment) => !RIGHT_SEGMENTS.has(segment.name)),
208
+ theme,
209
+ config,
210
+ );
211
+ const right = joinSegments(
212
+ segments.filter((segment) => RIGHT_SEGMENTS.has(segment.name)),
213
+ theme,
214
+ config,
215
+ );
216
+
217
+ if (!left && !right) return truncateToWidth(theme.fg("dim", "pi-statusline"), width);
218
+ if (!right) return truncateToWidth(left, width);
219
+ if (!left) return truncateToWidth(right, width);
220
+
221
+ const rightWidth = visibleWidth(right);
222
+ if (rightWidth + 1 >= width) return truncateToWidth(right, width);
223
+
224
+ const leftWidth = Math.max(0, width - rightWidth - 1);
225
+ const trimmedLeft = truncateToWidth(left, leftWidth, "…");
226
+ const padding = " ".repeat(Math.max(1, width - visibleWidth(trimmedLeft) - rightWidth));
227
+
228
+ return truncateToWidth(`${trimmedLeft}${padding}${right}`, width, "");
229
+ }
230
+
231
+ function renderExtensionStatusline(
232
+ width: number,
233
+ footerData: ReadonlyFooterDataProvider,
234
+ theme: Theme,
235
+ ): string | undefined {
236
+ const status = formatExtensionStatuses(footerData.getExtensionStatuses(), theme);
237
+ if (!status) return undefined;
238
+
239
+ return truncateToWidth(status, width, "");
240
+ }
241
+
242
+ function buildSegment(
243
+ name: SegmentName,
244
+ index: number,
245
+ ctx: ExtensionContext,
246
+ footerData: ReadonlyFooterDataProvider,
247
+ config: StatuslineConfig,
248
+ runtime: RuntimeState,
249
+ ): RenderSegment | undefined {
250
+ const color = pickColor(config, index);
251
+
252
+ switch (name) {
253
+ case "brand":
254
+ return { name, text: "π", color: "accent", emphasis: true };
255
+ case "model":
256
+ return labeled(name, `🤖 ${shortenModel(ctx.model?.id ?? "no-model")}`, color, config);
257
+ case "thinking":
258
+ return labeled(
259
+ name,
260
+ `🧠 ${runtime.thinkingLevel}`,
261
+ thinkingColor(runtime.thinkingLevel),
262
+ config,
263
+ );
264
+ case "branch":
265
+ return labeled(name, `🌿 ${footerData.getGitBranch() ?? "no-git"}`, color, config);
266
+ case "cwd":
267
+ return labeled(name, `📁 ${basename(ctx.cwd) || ctx.cwd}`, color, config);
268
+ case "tools":
269
+ return labeled(name, formatToolActivity(runtime), color, config);
270
+ case "context": {
271
+ const usage = ctx.getContextUsage();
272
+ const value =
273
+ usage?.percent === null || usage?.percent === undefined
274
+ ? "🪟 ctx ?"
275
+ : `🪟 ctx ${usage.percent.toFixed(0)}%`;
276
+ return labeled(name, value, contextColor(usage?.percent), config);
277
+ }
278
+ case "tokens": {
279
+ const totals = getTokenTotals(ctx);
280
+ if (totals.input === 0 && totals.output === 0)
281
+ return labeled(name, "🔢 tok 0", color, config);
282
+ return labeled(
283
+ name,
284
+ `🔢 ↑${formatCount(totals.input)} ↓${formatCount(totals.output)}`,
285
+ color,
286
+ config,
287
+ );
288
+ }
289
+ case "cost": {
290
+ const totals = getTokenTotals(ctx);
291
+ return labeled(name, `💸 $${totals.cost.toFixed(totals.cost >= 1 ? 2 : 3)}`, color, config);
292
+ }
293
+ case "time":
294
+ return labeled(name, `🕒 ${formatTime()}`, color, config);
295
+ case "turn":
296
+ return labeled(name, `🔁 #${runtime.turnCount}`, color, config);
297
+ }
298
+ }
299
+
300
+ function labeled(
301
+ name: SegmentName,
302
+ value: string,
303
+ color: ThemeColor,
304
+ config: StatuslineConfig,
305
+ ): RenderSegment {
306
+ if (!config.showLabels || name === "brand") return { name, text: value, color };
307
+ return { name, text: `${name} ${value}`, color };
308
+ }
309
+
310
+ function joinSegments(segments: RenderSegment[], theme: Theme, config: StatuslineConfig): string {
311
+ const separator = separatorText(config.separator);
312
+ return segments
313
+ .map((segment, index) => styleSegment(segment, index, theme, config))
314
+ .join(theme.fg("dim", separator));
315
+ }
316
+
317
+ function styleSegment(
318
+ segment: RenderSegment,
319
+ index: number,
320
+ theme: Theme,
321
+ config: StatuslineConfig,
322
+ ): string {
323
+ const padding = config.density === "cozy" ? " " : "";
324
+ const text = `${padding}${segment.text}${padding}`;
325
+ const styledText = segment.emphasis ? theme.bold(text) : text;
326
+
327
+ if (config.palette === "mono") {
328
+ return index === 0 ? theme.fg("muted", styledText) : theme.fg("dim", styledText);
329
+ }
330
+
331
+ return theme.fg(segment.color, styledText);
332
+ }
333
+
334
+ function separatorText(separator: SeparatorName): string {
335
+ switch (separator) {
336
+ case "powerline":
337
+ return "  ";
338
+ case "bar":
339
+ return " │ ";
340
+ case "round":
341
+ return " ❯ ";
342
+ case "none":
343
+ return " ";
344
+ case "dot":
345
+ return " • ";
346
+ }
347
+ }
348
+
349
+ function pickColor(config: StatuslineConfig, index: number): ThemeColor {
350
+ const palette = PALETTES[config.palette];
351
+ return palette[index % palette.length] ?? "muted";
352
+ }
353
+
354
+ function thinkingColor(level: ThinkingLevel): ThemeColor {
355
+ switch (level) {
356
+ case "off":
357
+ return "dim";
358
+ case "minimal":
359
+ return "thinkingMinimal";
360
+ case "low":
361
+ return "thinkingLow";
362
+ case "medium":
363
+ return "thinkingMedium";
364
+ case "high":
365
+ return "thinkingHigh";
366
+ case "xhigh":
367
+ return "thinkingXhigh";
368
+ }
369
+ }
370
+
371
+ function contextColor(percent: number | null | undefined): ThemeColor {
372
+ if (percent === null || percent === undefined) return "dim";
373
+ if (percent >= 90) return "error";
374
+ if (percent >= 70) return "warning";
375
+ return "success";
376
+ }
377
+
378
+ function formatToolActivity(runtime: RuntimeState): string {
379
+ const active = [...runtime.activeTools.entries()];
380
+ if (active.length > 0) {
381
+ const [name, count] = active[0] ?? ["tool", 1];
382
+ const suffix = count > 1 ? `×${count}` : active.length > 1 ? `+${active.length - 1}` : "";
383
+ return `⚙ ${name}${suffix}`;
384
+ }
385
+
386
+ if (runtime.isStreaming) return "💭 thinking";
387
+ if (runtime.lastCompletedTool) return `✅ ${runtime.lastCompletedTool}`;
388
+ return "💤 idle";
389
+ }
390
+
391
+ function formatExtensionStatuses(statuses: ReadonlyMap<string, string>, theme: Theme): string {
392
+ const separator = theme.fg("dim", "  ");
393
+ const visibleStatuses = [...statuses.entries()]
394
+ .filter(([key, value]) => key !== STATUSLINE_KEY && value.trim().length > 0)
395
+ .slice(0, 3)
396
+ .map(([key, value]) => {
397
+ const label = theme.fg("dim", `${extensionIcon(key)} ${key}: `);
398
+ const text = truncateToWidth(simplifyExtensionStatus(key, value), 24, "…");
399
+ return `${label}${text}`;
400
+ });
401
+
402
+ return visibleStatuses.join(separator);
403
+ }
404
+
405
+ function extensionIcon(key: string): string {
406
+ if (key.includes("caffeinate")) return "☕";
407
+ if (key.includes("chrome") || key.includes("devtools") || key === "cdp") return "🌐";
408
+ if (key.includes("firecrawl")) return "🔥";
409
+ if (key.includes("goal")) return "🎯";
410
+ return "🔌";
411
+ }
412
+
413
+ function simplifyExtensionStatus(key: string, value: string): string {
414
+ return value
415
+ .trim()
416
+ .replace(new RegExp(`^${escapeRegExp(key)}\\s*:\\s*`, "iu"), "")
417
+ .replace(/\s+\([^)]*\)\s*$/, "")
418
+ .replace(/\s+/g, " ");
419
+ }
420
+
421
+ function escapeRegExp(value: string): string {
422
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
423
+ }
424
+
425
+ function getTokenTotals(ctx: ExtensionContext): TokenTotals {
426
+ const totals: TokenTotals = { input: 0, output: 0, cost: 0 };
427
+
428
+ for (const entry of ctx.sessionManager.getBranch()) {
429
+ if (entry.type !== "message" || entry.message.role !== "assistant") continue;
430
+
431
+ const usage = entry.message.usage as
432
+ | {
433
+ input?: number;
434
+ output?: number;
435
+ cost?: { total?: number };
436
+ }
437
+ | undefined;
438
+
439
+ totals.input += usage?.input ?? 0;
440
+ totals.output += usage?.output ?? 0;
441
+ totals.cost += usage?.cost?.total ?? 0;
442
+ }
443
+
444
+ return totals;
445
+ }
446
+
447
+ function formatCount(value: number): string {
448
+ if (value < 1000) return `${value}`;
449
+ if (value < 1_000_000) return `${(value / 1000).toFixed(value < 10_000 ? 1 : 0)}k`;
450
+ return `${(value / 1_000_000).toFixed(1)}m`;
451
+ }
452
+
453
+ function formatTime(): string {
454
+ const now = new Date();
455
+ const hours = now.getHours().toString().padStart(2, "0");
456
+ const minutes = now.getMinutes().toString().padStart(2, "0");
457
+ return `${hours}:${minutes}`;
458
+ }
459
+
460
+ function shortenModel(model: string): string {
461
+ return model
462
+ .replace(/^claude-/, "")
463
+ .replace(/^gpt-/, "gpt ")
464
+ .replace(/-20\d{6}$/, "")
465
+ .replace(/-latest$/, "");
466
+ }