@henryqw/pi-footer 0.2.0

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 Henry Wang
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,64 @@
1
+ # `@henryqw/pi-footer`
2
+
3
+ Henry's opinionated Pi footer style: concise checkout identity plus essential usage and extension status details.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@henryqw/pi-footer
9
+ ```
10
+
11
+ ## With
12
+
13
+ | Package | Why |
14
+ | --- | --- |
15
+ | `@henryqw/pi-multi-codex` | Adds active Codex subscription quota and reset status. |
16
+ | `@henryqw/pi-open-in` | Adds `/open` and `/set-open-in` commands for editor configuration. |
17
+
18
+ ## Use
19
+
20
+ | Surface | Type | Purpose |
21
+ | --- | --- | --- |
22
+ | Footer | UI | Show checkout, usage, model, thinking, and extension statuses. |
23
+
24
+ ```text
25
+ pi-packages · clear-field-f8d2
26
+ ↑ 12.4k · ↓ 2.1k · ↺ 84.3% · $ 0.127 · ◔ 36.8% gpt-5.6-luna • high
27
+ Codex #1 · 50% · 7d 1d 1h 22m
28
+ ```
29
+
30
+ First line shows repository and branch. Linked-worktree branches drop generated `worktree/` prefix.
31
+
32
+ Second line shows cumulative input tokens, output tokens, latest cache-hit rate, estimated cost, and context usage. Unavailable values render as `—` without a misleading percent sign. Active model and thinking level are right-aligned.
33
+
34
+ `off` uses the same dim grey as the model name. Active levels use an ANSI-256 gradient: green `minimal`, yellow-green `low`, lime `medium`, yellow `high`, orange `xhigh`, and red `max`. `ultra` renders as a rainbow when the runtime supplies it. Pi 0.84.2 does not yet accept `ultra`, so that footer path remains unreachable until Pi adds it.
35
+
36
+ Final line renders every non-empty status emitted through `ctx.ui.setStatus()`, sorted by status key. Producer text, spacing, colors, links, and glyphs are preserved, including Ponytail mode, GitHub PR state, and Codex quota.
37
+
38
+ ## Clickable checkout
39
+
40
+ When `pi-open-in.json` command is exactly `code`, the accent-colored checkout name is an OSC 8 `vscode://` link to the current path. Other configured commands remain plain because terminal links cannot run arbitrary shell commands.
41
+
42
+ Use Pi fullscreen TUI so Pi handles the custom URI:
43
+
44
+ ```json
45
+ {
46
+ "tuiMode": "fullscreen"
47
+ }
48
+ ```
49
+
50
+ Set this through `/settings`, or launch with `--tui-mode fullscreen`. Then use normal primary click. Regular TUI delegates OSC 8 activation to the terminal; Ghostty uses `Cmd+click` but may not open custom URI schemes.
51
+
52
+ ## Remove
53
+
54
+ ```bash
55
+ pi remove npm:@henryqw/pi-footer
56
+ ```
57
+
58
+ ## Development
59
+
60
+ ```bash
61
+ npm test --workspace @henryqw/pi-footer
62
+ npm run typecheck --workspace @henryqw/pi-footer
63
+ npm run pack:check --workspace @henryqw/pi-footer
64
+ ```
@@ -0,0 +1,119 @@
1
+ import { basename, dirname } from "node:path";
2
+ import type { Usage } from "@earendil-works/pi-ai";
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
5
+ import { configuredOpenUri } from "@henryqw/pi-open-in/open-uri";
6
+
7
+ const THINKING_COLORS = {
8
+ minimal: 46,
9
+ low: 82,
10
+ medium: 118,
11
+ high: 220,
12
+ xhigh: 208,
13
+ max: 196,
14
+ } as const;
15
+
16
+ function formatTokens(count: number): string {
17
+ if (count < 1_000) return `${count}`;
18
+ if (count < 1_000_000) return `${(count / 1_000).toFixed(1)}k`;
19
+ return `${(count / 1_000_000).toFixed(1)}M`;
20
+ }
21
+
22
+ function sanitizeStatus(text: string): string {
23
+ return text.replace(/[\r\n]+/g, " ").trim();
24
+ }
25
+
26
+ function align(left: string, right: string, width: number, ellipsis: string): string {
27
+ const available = width - visibleWidth(left) - 2;
28
+ if (available <= 0) return truncateToWidth(left, width, ellipsis);
29
+ const clippedRight = truncateToWidth(right, available, "");
30
+ return left + " ".repeat(width - visibleWidth(left) - visibleWidth(clippedRight)) + clippedRight;
31
+ }
32
+
33
+ function color(text: string, ansi256: number): string {
34
+ return `\x1b[38;5;${ansi256}m${text}\x1b[39m`;
35
+ }
36
+
37
+ function rainbow(text: string): string {
38
+ const colors = [196, 220, 46, 39, 201];
39
+ return [...text].map((character, index) => color(character, colors[index % colors.length]!)).join("");
40
+ }
41
+
42
+ export default function footerExtension(pi: ExtensionAPI): void {
43
+ pi.on("session_start", async (_event, ctx) => {
44
+ if (ctx.mode !== "tui") return;
45
+
46
+ const git = await pi.exec(
47
+ "git",
48
+ ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir"],
49
+ { cwd: ctx.cwd },
50
+ );
51
+ const [root, commonDir] = git.stdout.trim().split(/\r?\n/);
52
+ const rootName = basename(root || ctx.cwd);
53
+ const commonName = commonDir && basename(commonDir) === ".git" ? basename(dirname(commonDir)) : undefined;
54
+ const repo = git.code === 0 ? commonName && commonName !== rootName ? commonName : rootName : basename(ctx.cwd);
55
+
56
+ ctx.ui.setFooter((tui, theme, data) => {
57
+ const unsubscribe = data.onBranchChange(() => tui.requestRender());
58
+ return {
59
+ dispose: unsubscribe,
60
+ invalidate() { },
61
+ render(width: number): string[] {
62
+ let input = 0;
63
+ let output = 0;
64
+ let cost = 0;
65
+ let cacheRate: number | undefined;
66
+ const add = (usage: Usage | undefined) => {
67
+ if (!usage) return;
68
+ input += usage.input;
69
+ output += usage.output;
70
+ cost += usage.cost.total;
71
+ };
72
+
73
+ for (const entry of ctx.sessionManager.getEntries()) {
74
+ if (entry.type === "message" && entry.message.role === "assistant") {
75
+ const usage = entry.message.usage;
76
+ const prompt = usage.input + usage.cacheRead + usage.cacheWrite;
77
+ cacheRate = prompt ? usage.cacheRead / prompt * 100 : 0;
78
+ add(usage);
79
+ } else if (entry.type === "message" && entry.message.role === "toolResult") {
80
+ add(entry.message.usage);
81
+ } else if (entry.type === "branch_summary" || entry.type === "compaction") {
82
+ add(entry.usage);
83
+ }
84
+ }
85
+
86
+ const branch = data.getGitBranch()?.replace(/^worktree\//, "");
87
+ const context = ctx.getContextUsage()?.percent;
88
+ const openUri = configuredOpenUri(ctx.cwd);
89
+ const statuses = [...data.getExtensionStatuses()]
90
+ .sort(([a], [b]) => a.localeCompare(b))
91
+ .map(([, text]) => sanitizeStatus(text))
92
+ .filter(Boolean);
93
+ const thinking = String(ctx.thinkingLevel ?? "off");
94
+ const thinkingColor = THINKING_COLORS[thinking as keyof typeof THINKING_COLORS];
95
+ const ellipsis = theme.fg("dim", "…");
96
+ const usage = theme.fg("dim", [
97
+ `↑ ${formatTokens(input)}`,
98
+ `↓ ${formatTokens(output)}`,
99
+ `↺ ${cacheRate === undefined ? "—" : `${cacheRate.toFixed(1)}%`}`,
100
+ `$ ${cost.toFixed(3)}`,
101
+ `◔ ${context == null ? "—" : `${context.toFixed(1)}%`}`,
102
+ ].join(" · "));
103
+ const thinkingText = thinking === "ultra"
104
+ ? rainbow(thinking)
105
+ : thinkingColor === undefined ? theme.fg("dim", thinking) : color(thinking, thinkingColor);
106
+ const model = theme.fg("dim", `${ctx.model?.id ?? "no-model"} • `) + thinkingText;
107
+ const identity = branch ? theme.fg("dim", `${repo} · `) : "";
108
+ const checkout = branch ?? repo;
109
+ const lines = [
110
+ identity + (openUri ? hyperlink(theme.fg("accent", checkout), openUri) : theme.fg("dim", checkout)),
111
+ align(usage, model, width, ellipsis),
112
+ ];
113
+ if (statuses.length) lines.push(statuses.join(" "));
114
+ return lines.map((line) => truncateToWidth(line, width, ellipsis));
115
+ },
116
+ };
117
+ });
118
+ });
119
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@henryqw/pi-footer",
3
+ "version": "0.2.0",
4
+ "description": "Show concise repository, branch, and usage details in the Pi footer.",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "footer",
9
+ "worktree"
10
+ ],
11
+ "type": "module",
12
+ "engines": {
13
+ "node": ">=22.19.0"
14
+ },
15
+ "license": "MIT",
16
+ "files": [
17
+ "extensions",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "test": "node --test test/*.test.ts",
23
+ "typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/*.ts test/*.test.ts",
24
+ "pack:check": "npm pack --dry-run"
25
+ },
26
+ "peerDependencies": {
27
+ "@earendil-works/pi-ai": "^0.84.2",
28
+ "@earendil-works/pi-coding-agent": "^0.84.2",
29
+ "@earendil-works/pi-tui": "^0.84.2"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/HenryQW/pi-packages.git",
34
+ "directory": "packages/pi-footer"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/HenryQW/pi-packages/issues"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "pi": {
43
+ "extensions": [
44
+ "./extensions/footer.ts"
45
+ ]
46
+ },
47
+ "dependencies": {
48
+ "@henryqw/pi-open-in": "^0.2.0"
49
+ }
50
+ }