@juanibiapina/pi-powerbar 0.1.0 → 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/README.md
CHANGED
|
@@ -14,10 +14,7 @@ pi install npm:@juanibiapina/pi-powerbar
|
|
|
14
14
|
|
|
15
15
|
The powerbar renders a widget with two sides, like tmux:
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
│ ⎇ main │ 42% used model: sonnet │ 12k tokens │
|
|
19
|
-
← left → ←── right ──→
|
|
20
|
-
```
|
|
17
|
+

|
|
21
18
|
|
|
22
19
|
### Producing segments
|
|
23
20
|
|
|
@@ -43,20 +40,15 @@ pi.events.emit("powerbar:update", {
|
|
|
43
40
|
|
|
44
41
|
### Configuration
|
|
45
42
|
|
|
46
|
-
Settings are
|
|
47
|
-
|
|
48
|
-
```json
|
|
49
|
-
{
|
|
50
|
-
"left": ["git-branch", "sub-usage"],
|
|
51
|
-
"right": ["model", "tokens"],
|
|
52
|
-
"separator": " │ ",
|
|
53
|
-
"placement": "belowEditor"
|
|
54
|
-
}
|
|
55
|
-
```
|
|
43
|
+
Settings are managed through [`pi-extension-settings`](https://github.com/juanibiapina/pi-extension-settings) and can be changed via the `/settings` command in pi.
|
|
56
44
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
| Setting | Description | Default |
|
|
46
|
+
|---------|-------------|---------|
|
|
47
|
+
| **Left segments** | Comma-separated segment IDs for the left side | `git-branch,tokens,context-usage` |
|
|
48
|
+
| **Right segments** | Comma-separated segment IDs for the right side | `model,sub-hourly,sub-weekly` |
|
|
49
|
+
| **Separator** | String drawn between segments on the same side | ` │ ` |
|
|
50
|
+
| **Placement** | Where the powerbar appears (`belowEditor` or `aboveEditor`) | `belowEditor` |
|
|
51
|
+
| **Bar width** | Width of progress bars in characters (4–24) | `10` |
|
|
60
52
|
|
|
61
53
|
Segments not listed in either side are ignored.
|
|
62
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/powerbar-context/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/powerbar-context/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,+BAA+B,CAAC;AAgCpF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAS9D"}
|
|
@@ -12,19 +12,35 @@ function getColor(pct) {
|
|
|
12
12
|
return "warning";
|
|
13
13
|
return "muted";
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
function emitContextUsage(pi, ctx) {
|
|
16
|
+
const usage = ctx.getContextUsage();
|
|
17
|
+
if (usage) {
|
|
18
|
+
const pct = Math.round((usage.tokens / usage.contextWindow) * 100);
|
|
19
|
+
pi.events.emit("powerbar:update", {
|
|
20
|
+
id: "context-usage",
|
|
21
|
+
text: "",
|
|
22
|
+
suffix: `${pct}%`,
|
|
23
|
+
bar: pct,
|
|
24
|
+
color: getColor(pct),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function resetContextUsage(pi) {
|
|
29
|
+
pi.events.emit("powerbar:update", {
|
|
30
|
+
id: "context-usage",
|
|
31
|
+
text: "",
|
|
32
|
+
suffix: "0%",
|
|
33
|
+
bar: 0,
|
|
34
|
+
color: "muted",
|
|
28
35
|
});
|
|
29
36
|
}
|
|
37
|
+
export default function createExtension(pi) {
|
|
38
|
+
// Reset on new/switched session
|
|
39
|
+
pi.on("session_start", async () => resetContextUsage(pi));
|
|
40
|
+
pi.on("session_switch", async () => resetContextUsage(pi));
|
|
41
|
+
// Update frequently during agent work
|
|
42
|
+
pi.on("turn_start", async (_event, ctx) => emitContextUsage(pi, ctx));
|
|
43
|
+
pi.on("tool_result", async (_event, ctx) => emitContextUsage(pi, ctx));
|
|
44
|
+
pi.on("turn_end", async (_event, ctx) => emitContextUsage(pi, ctx));
|
|
45
|
+
}
|
|
30
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/powerbar-context/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,SAAS,QAAQ,CAAC,GAAW;IAC5B,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,OAAO,CAAC;IAC7B,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/powerbar-context/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,SAAS,QAAQ,CAAC,GAAW;IAC5B,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,OAAO,CAAC;IAC7B,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAgB,EAAE,GAAqB;IAChE,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;IACpC,IAAI,KAAK,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC;QACnE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;YACjC,EAAE,EAAE,eAAe;YACnB,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,GAAG,GAAG,GAAG;YACjB,GAAG,EAAE,GAAG;YACR,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;SACpB,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAgB;IAC1C,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;QACjC,EAAE,EAAE,eAAe;QACnB,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,CAAC;QACN,KAAK,EAAE,OAAO;KACd,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAgB;IACvD,gCAAgC;IAChC,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,EAAE,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3D,sCAAsC;IACtC,EAAE,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACtE,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACvE,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Powerbar Context Producer\n *\n * Shows context window usage as a progress bar with percentage.\n * Color changes based on usage level: accent → warning → error.\n * Segment ID: \"context-usage\"\n */\n\nimport type { ExtensionAPI, ExtensionContext } from \"@mariozechner/pi-coding-agent\";\n\nfunction getColor(pct: number): string {\n\tif (pct > 80) return \"error\";\n\tif (pct > 60) return \"warning\";\n\treturn \"muted\";\n}\n\nfunction emitContextUsage(pi: ExtensionAPI, ctx: ExtensionContext): void {\n\tconst usage = ctx.getContextUsage();\n\tif (usage) {\n\t\tconst pct = Math.round((usage.tokens / usage.contextWindow) * 100);\n\t\tpi.events.emit(\"powerbar:update\", {\n\t\t\tid: \"context-usage\",\n\t\t\ttext: \"\",\n\t\t\tsuffix: `${pct}%`,\n\t\t\tbar: pct,\n\t\t\tcolor: getColor(pct),\n\t\t});\n\t}\n}\n\nfunction resetContextUsage(pi: ExtensionAPI): void {\n\tpi.events.emit(\"powerbar:update\", {\n\t\tid: \"context-usage\",\n\t\ttext: \"\",\n\t\tsuffix: \"0%\",\n\t\tbar: 0,\n\t\tcolor: \"muted\",\n\t});\n}\n\nexport default function createExtension(pi: ExtensionAPI): void {\n\t// Reset on new/switched session\n\tpi.on(\"session_start\", async () => resetContextUsage(pi));\n\tpi.on(\"session_switch\", async () => resetContextUsage(pi));\n\n\t// Update frequently during agent work\n\tpi.on(\"turn_start\", async (_event, ctx) => emitContextUsage(pi, ctx));\n\tpi.on(\"tool_result\", async (_event, ctx) => emitContextUsage(pi, ctx));\n\tpi.on(\"turn_end\", async (_event, ctx) => emitContextUsage(pi, ctx));\n}\n"]}
|
package/package.json
CHANGED