@marcosgilf/pi-footer 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +18 -2
- package/package.json +34 -4
- package/src/index.ts +125 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcos Gil
|
|
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
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-footer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Single owner for Pi's custom footer. It loads `pi-session` and `pi-usage`, then combines their data and click actions. Both feature extensions use `pi-modal` for details.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pi install npm:@marcosgilf/pi-footer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`pi-footer` loads `pi-session` and `pi-usage` from package dependencies. Remove separate `npm:@marcosgilf/pi-session` and `npm:@marcosgilf/pi-usage` entries from Pi settings to avoid loading either extension twice.
|
|
12
|
+
|
|
13
|
+
- Click context indicator to open session details.
|
|
14
|
+
- Click Copilot plan usage to open quota details.
|
|
15
|
+
- Wide terminals combine session/skill info on the left and usage/model info on the right; narrow terminals stack usage/model and session/skill lines.
|
|
16
|
+
- `/session-usage` and Command+Shift+S (`super+shift+s`) open session details.
|
|
17
|
+
- `/copilot-usage` and `super+shift+u` open Copilot details.
|
|
18
|
+
|
|
19
|
+
Pi extensions run with Pi's operating-system permissions. Review package source before installing.
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcosgilf/pi-footer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One Pi footer that combines session and Copilot usage extensions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"pi-package",
|
|
10
|
+
"pi-extension",
|
|
11
|
+
"pi",
|
|
12
|
+
"footer",
|
|
13
|
+
"statusline"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"pi": {
|
|
21
|
+
"extensions": [
|
|
22
|
+
"./src/index.ts"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@marcosgilf/pi-session": "^0.1.0",
|
|
27
|
+
"@marcosgilf/pi-usage": "^0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
31
|
+
"@earendil-works/pi-tui": "*"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type TuiMouseEvent, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import registerSession from "@marcosgilf/pi-session";
|
|
4
|
+
import { getContextUsageStyle } from "@marcosgilf/pi-session/core";
|
|
5
|
+
import { OPEN_SESSION_USAGE_EVENT, SESSION_USAGE_STATUS_KEY } from "@marcosgilf/pi-session/events";
|
|
6
|
+
import registerUsage from "@marcosgilf/pi-usage";
|
|
7
|
+
import { COPILOT_USAGE_STATUS_KEY, OPEN_COPILOT_USAGE_EVENT } from "@marcosgilf/pi-usage/events";
|
|
8
|
+
|
|
9
|
+
type ClickBounds = { left: number; right: number };
|
|
10
|
+
|
|
11
|
+
function usageStyle(text: string): "warning" | "accent" {
|
|
12
|
+
const match = text.match(/(?:^|\s)(\d+(?:\.\d+)?)%/);
|
|
13
|
+
return match && Number(match[1]) >= 90 ? "warning" : "accent";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function addCustomFooter(ctx: ExtensionContext, pi: ExtensionAPI): void {
|
|
17
|
+
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
18
|
+
let disposed = false;
|
|
19
|
+
const requestRender = () => {
|
|
20
|
+
if (!disposed) tui.requestRender();
|
|
21
|
+
};
|
|
22
|
+
const unsubscribe = footerData.onBranchChange(requestRender);
|
|
23
|
+
let usageClickBounds: ClickBounds | undefined;
|
|
24
|
+
let contextClickBounds: ClickBounds | undefined;
|
|
25
|
+
let usageClickRow = 1;
|
|
26
|
+
let contextClickRow = 1;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
dispose() {
|
|
30
|
+
disposed = true;
|
|
31
|
+
unsubscribe();
|
|
32
|
+
},
|
|
33
|
+
handleMouse(event: TuiMouseEvent) {
|
|
34
|
+
if (event.button !== "left" || event.type !== "click") return;
|
|
35
|
+
const clickedUsage =
|
|
36
|
+
event.y === usageClickRow &&
|
|
37
|
+
usageClickBounds !== undefined &&
|
|
38
|
+
event.x >= usageClickBounds.left &&
|
|
39
|
+
event.x < usageClickBounds.right;
|
|
40
|
+
const clickedContext =
|
|
41
|
+
event.y === contextClickRow &&
|
|
42
|
+
contextClickBounds !== undefined &&
|
|
43
|
+
event.x >= contextClickBounds.left &&
|
|
44
|
+
event.x < contextClickBounds.right;
|
|
45
|
+
if (!clickedUsage && !clickedContext) return;
|
|
46
|
+
pi.events.emit(clickedContext ? OPEN_SESSION_USAGE_EVENT : OPEN_COPILOT_USAGE_EVENT, undefined);
|
|
47
|
+
return { handled: true, render: true };
|
|
48
|
+
},
|
|
49
|
+
invalidate() {},
|
|
50
|
+
render(width: number) {
|
|
51
|
+
const contextText = footerData.getExtensionStatuses().get(SESSION_USAGE_STATUS_KEY) ?? "";
|
|
52
|
+
const contextPercent = Number.parseFloat(contextText);
|
|
53
|
+
const contextLabel = contextText
|
|
54
|
+
? theme.fg(getContextUsageStyle(Number.isFinite(contextPercent) ? contextPercent : null), contextText)
|
|
55
|
+
: "";
|
|
56
|
+
|
|
57
|
+
const model = ctx.model;
|
|
58
|
+
const modelName = model?.name || model?.id || "no-model";
|
|
59
|
+
const thinking = model?.reasoning ? ` • ${ctx.thinkingLevel || "off"}` : "";
|
|
60
|
+
let modelText = `${modelName}${thinking}`;
|
|
61
|
+
if (footerData.getAvailableProviderCount() > 1 && model) modelText = `(${model.provider}) ${modelText}`;
|
|
62
|
+
|
|
63
|
+
const usageText = footerData.getExtensionStatuses().get(COPILOT_USAGE_STATUS_KEY) ?? "";
|
|
64
|
+
const usageLabel = usageText ? theme.fg(usageStyle(usageText), usageText) : "";
|
|
65
|
+
const right = usageLabel ? `${usageLabel} · ${modelText}` : modelText;
|
|
66
|
+
const clippedRight = truncateToWidth(right, width, "");
|
|
67
|
+
const rightWidth = visibleWidth(clippedRight);
|
|
68
|
+
const usageWidth = visibleWidth(usageLabel);
|
|
69
|
+
const usageRight = Math.min(usageWidth, rightWidth);
|
|
70
|
+
const home = process.env.HOME || "";
|
|
71
|
+
let cwd = home && ctx.cwd.startsWith(`${home}/`) ? `~${ctx.cwd.slice(home.length)}` : ctx.cwd;
|
|
72
|
+
const branch = footerData.getGitBranch();
|
|
73
|
+
if (branch) cwd += ` (${branch})`;
|
|
74
|
+
const sessionName = ctx.sessionManager.getSessionName();
|
|
75
|
+
if (sessionName) cwd += ` • ${sessionName}`;
|
|
76
|
+
|
|
77
|
+
const statuses = Array.from(footerData.getExtensionStatuses().entries())
|
|
78
|
+
.filter(([key]) => key !== SESSION_USAGE_STATUS_KEY && key !== COPILOT_USAGE_STATUS_KEY)
|
|
79
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
80
|
+
.map(([, text]) => text);
|
|
81
|
+
const statusText = [contextLabel, statuses.join(" ")].filter(Boolean).join(" · ");
|
|
82
|
+
const statusWidth = visibleWidth(statusText);
|
|
83
|
+
const statusLine = truncateToWidth(statusText, width, theme.fg("dim", "..."));
|
|
84
|
+
const statusClickRight = Math.min(visibleWidth(contextLabel), visibleWidth(statusLine));
|
|
85
|
+
const lines = [truncateToWidth(theme.fg("dim", cwd), width, theme.fg("dim", "..."))];
|
|
86
|
+
|
|
87
|
+
if (statusText && statusWidth + rightWidth + 2 <= width) {
|
|
88
|
+
const rightLeft = width - rightWidth;
|
|
89
|
+
lines.push(`${statusText}${" ".repeat(Math.max(0, rightLeft - statusWidth))}${clippedRight}`);
|
|
90
|
+
contextClickBounds = contextLabel ? { left: 0, right: statusClickRight } : undefined;
|
|
91
|
+
usageClickBounds = usageRight > 0 ? { left: rightLeft, right: rightLeft + usageRight } : undefined;
|
|
92
|
+
contextClickRow = 1;
|
|
93
|
+
usageClickRow = 1;
|
|
94
|
+
} else if (statusText) {
|
|
95
|
+
lines.push(clippedRight, statusLine);
|
|
96
|
+
contextClickBounds = contextLabel ? { left: 0, right: statusClickRight } : undefined;
|
|
97
|
+
usageClickBounds = usageRight > 0 ? { left: 0, right: usageRight } : undefined;
|
|
98
|
+
contextClickRow = 2;
|
|
99
|
+
usageClickRow = 1;
|
|
100
|
+
} else {
|
|
101
|
+
lines.push(`${" ".repeat(Math.max(0, width - rightWidth))}${clippedRight}`);
|
|
102
|
+
contextClickBounds = undefined;
|
|
103
|
+
usageClickBounds =
|
|
104
|
+
usageRight > 0 ? { left: width - rightWidth, right: width - rightWidth + usageRight } : undefined;
|
|
105
|
+
contextClickRow = 1;
|
|
106
|
+
usageClickRow = 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return lines;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default function (pi: ExtensionAPI): void {
|
|
116
|
+
registerSession(pi);
|
|
117
|
+
registerUsage(pi);
|
|
118
|
+
|
|
119
|
+
pi.on("session_start", (_event, ctx) => {
|
|
120
|
+
if (ctx.mode === "tui") addCustomFooter(ctx, pi);
|
|
121
|
+
});
|
|
122
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
123
|
+
if (ctx.mode === "tui") ctx.ui.setFooter(undefined);
|
|
124
|
+
});
|
|
125
|
+
}
|