@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
+ ![powerbar screenshot](screenshot.png)
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 stored in `~/.pi/agent/pi-powerbar-settings.json`:
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
- - **left** / **right** Ordered list of segment IDs controlling placement and order.
58
- - **separator** — String drawn between segments on the same side.
59
- - **placement** Where the widget renders (`"belowEditor"`).
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,EAAE,MAAM,+BAA+B,CAAC;AAQlE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAc9D"}
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
- export default function createExtension(pi) {
16
- pi.on("turn_end", async (_event, ctx) => {
17
- const usage = ctx.getContextUsage();
18
- if (usage) {
19
- const pct = Math.round((usage.tokens / usage.contextWindow) * 100);
20
- pi.events.emit("powerbar:update", {
21
- id: "context-usage",
22
- text: "",
23
- suffix: `${pct}%`,
24
- bar: pct,
25
- color: getColor(pct),
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,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAgB;IACvD,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;QACvC,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC;YACnE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE;gBACjC,EAAE,EAAE,eAAe;gBACnB,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,GAAG,GAAG,GAAG;gBACjB,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;aACpB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,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 } 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\nexport default function createExtension(pi: ExtensionAPI): void {\n\tpi.on(\"turn_end\", async (_event, ctx) => {\n\t\tconst usage = ctx.getContextUsage();\n\t\tif (usage) {\n\t\t\tconst pct = Math.round((usage.tokens / usage.contextWindow) * 100);\n\t\t\tpi.events.emit(\"powerbar:update\", {\n\t\t\t\tid: \"context-usage\",\n\t\t\t\ttext: \"\",\n\t\t\t\tsuffix: `${pct}%`,\n\t\t\t\tbar: pct,\n\t\t\t\tcolor: getColor(pct),\n\t\t\t});\n\t\t}\n\t});\n}\n"]}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juanibiapina/pi-powerbar",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Pi extension that renders a persistent powerline status bar with left/right segments updated via events",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",