pi-bar 0.3.3 → 0.3.5

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
@@ -9,7 +9,7 @@
9
9
  ◈ claude-opus-4.7 ❯ ✦ think:med ❯ ◷ 2.6% / 1.0M ❯ ✧ plan:active
10
10
  ```
11
11
 
12
- ![pi-bar screenshot, three rows showing green, yellow, and red context usage](https://cdn.jsdelivr.net/npm/pi-bar@0.3.3/assets/screenshot.png)
12
+ ![pi-bar screenshot, three rows showing green, yellow, and red context usage](https://cdn.jsdelivr.net/npm/pi-bar@0.3.5/assets/screenshot.png)
13
13
 
14
14
  ## Why use it?
15
15
 
@@ -48,18 +48,15 @@ Allowed segments are `model`, `thinking`, `context`, and `extensions`. The `exte
48
48
  ### Configure extension statuses
49
49
 
50
50
  pi-bar shows statuses set by other extensions with `ctx.ui.setStatus()`.
51
- Use `/bar status` inside pi to choose which status keys appear.
51
+ Use `/bar` inside pi to open an interactive status-visibility picker.
52
52
 
53
53
  ```text
54
- /bar status list
55
- /bar status hide plan-mode
56
- /bar status show plan-mode
57
- /bar status only plan-mode,preset
58
- /bar status none
59
- /bar status all
54
+ /bar
60
55
  ```
61
56
 
62
- Status filter choices persist in the current session.
57
+ Toggle each status key between `shown` and `hidden`. The `New statuses` row controls whether status keys discovered later are shown or hidden by default.
58
+
59
+ Status filter choices persist globally across pi sessions. Set `PI_BAR_CONFIG=/path/to/config.json` before launching pi to override the default config path (`~/.pi/agent/pi-bar.json`). Advanced command forms like `/bar status hide <key>` still work for scripting.
63
60
 
64
61
  ### Change context thresholds
65
62
 
@@ -16,8 +16,20 @@
16
16
  * PI_BAR_ICONS=unicode|plain|emoji|nerdfont
17
17
  */
18
18
 
19
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
20
- import { truncateToWidth } from "@earendil-works/pi-tui";
19
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
20
+ import { homedir } from "node:os";
21
+ import { dirname, join } from "node:path";
22
+ import {
23
+ getSettingsListTheme,
24
+ type ExtensionAPI,
25
+ type ExtensionContext,
26
+ } from "@earendil-works/pi-coding-agent";
27
+ import {
28
+ Container,
29
+ type SettingItem,
30
+ SettingsList,
31
+ truncateToWidth,
32
+ } from "@earendil-works/pi-tui";
21
33
 
22
34
  type SegmentName = "model" | "thinking" | "context" | "extensions";
23
35
  type IconPreset = "unicode" | "plain" | "emoji" | "nerdfont";
@@ -29,6 +41,8 @@ type SerializedStatusFilter =
29
41
  | { mode: "only"; shown: string[] };
30
42
 
31
43
  const STATUS_FILTER_ENTRY_TYPE = "pi-bar-status-filter";
44
+ const CONFIG_PATH =
45
+ process.env.PI_BAR_CONFIG ?? join(homedir(), ".pi", "agent", "pi-bar.json");
32
46
 
33
47
  const DEFAULT_SEGMENTS: SegmentName[] = [
34
48
  "model",
@@ -241,33 +255,178 @@ function describeStatusFilter(filter: StatusFilter): string {
241
255
  return hidden.length > 0 ? `showing all except: ${hidden.join(", ")}` : "showing all";
242
256
  }
243
257
 
258
+ function readGlobalStatusFilter(): StatusFilter | null {
259
+ try {
260
+ const data = JSON.parse(readFileSync(CONFIG_PATH, "utf8")) as {
261
+ statusFilter?: unknown;
262
+ };
263
+ return parseSerializedStatusFilter(data.statusFilter ?? data);
264
+ } catch {
265
+ return null;
266
+ }
267
+ }
268
+
269
+ function writeGlobalStatusFilter(filter: StatusFilter): void {
270
+ const data = JSON.stringify(
271
+ { statusFilter: serializeStatusFilter(filter) },
272
+ null,
273
+ 2,
274
+ );
275
+ mkdirSync(dirname(CONFIG_PATH), { recursive: true });
276
+ const tmpPath = `${CONFIG_PATH}.${process.pid}.tmp`;
277
+ writeFileSync(tmpPath, `${data}\n`, "utf8");
278
+ renameSync(tmpPath, CONFIG_PATH);
279
+ }
280
+
281
+ function getKnownStatusKeys(filter: StatusFilter, seenStatusKeys: Set<string>): string[] {
282
+ const keys = new Set(seenStatusKeys);
283
+ if (filter.mode === "only") {
284
+ for (const key of filter.shown) keys.add(key);
285
+ } else {
286
+ for (const key of filter.hidden) keys.add(key);
287
+ }
288
+ return Array.from(keys).sort();
289
+ }
290
+
244
291
  export default function (pi: ExtensionAPI) {
245
292
  let requestRender: (() => void) | undefined;
246
293
  let statusFilter: StatusFilter = { mode: "all", hidden: new Set() };
247
294
  const seenStatusKeys = new Set<string>();
248
295
  const refresh = () => requestRender?.();
249
296
  const restoreStatusFilter = (ctx: ExtensionContext) => {
250
- let restoredFilter: StatusFilter | null = null;
251
- for (const entry of ctx.sessionManager.getBranch()) {
252
- if (entry.type === "custom" && entry.customType === STATUS_FILTER_ENTRY_TYPE) {
253
- restoredFilter = parseSerializedStatusFilter(entry.data);
297
+ let restoredFilter = readGlobalStatusFilter();
298
+ if (!restoredFilter) {
299
+ for (const entry of ctx.sessionManager.getBranch()) {
300
+ if (entry.type === "custom" && entry.customType === STATUS_FILTER_ENTRY_TYPE) {
301
+ restoredFilter = parseSerializedStatusFilter(entry.data);
302
+ }
254
303
  }
255
304
  }
256
305
  statusFilter = restoredFilter ?? { mode: "all", hidden: new Set() };
257
306
  };
307
+ const persistStatusFilter = () => {
308
+ writeGlobalStatusFilter(statusFilter);
309
+ refresh();
310
+ };
311
+ const openStatusConfigurator = async (ctx: ExtensionContext) => {
312
+ const knownStatusKeys = getKnownStatusKeys(statusFilter, seenStatusKeys);
313
+ if (knownStatusKeys.length === 0) {
314
+ ctx.ui.notify(
315
+ "No extension statuses seen yet. Open /bar after another extension calls ctx.ui.setStatus().",
316
+ "info",
317
+ );
318
+ return;
319
+ }
320
+
321
+ await ctx.ui.custom((tui, theme, _kb, done) => {
322
+ let futureShown = statusFilter.mode === "all";
323
+ const statusVisibility = new Map(
324
+ knownStatusKeys.map((key) => [key, shouldShowStatus(key, statusFilter)]),
325
+ );
326
+ const persistFromVisibility = () => {
327
+ if (futureShown) {
328
+ statusFilter = {
329
+ mode: "all",
330
+ hidden: new Set(
331
+ knownStatusKeys.filter((key) => !statusVisibility.get(key)),
332
+ ),
333
+ };
334
+ } else {
335
+ statusFilter = {
336
+ mode: "only",
337
+ shown: new Set(
338
+ knownStatusKeys.filter((key) => statusVisibility.get(key)),
339
+ ),
340
+ };
341
+ }
342
+ persistStatusFilter();
343
+ };
344
+
345
+ const items: SettingItem[] = [
346
+ {
347
+ id: "__future",
348
+ label: "New statuses",
349
+ description: "Default visibility for status keys discovered later",
350
+ currentValue: futureShown ? "shown" : "hidden",
351
+ values: ["shown", "hidden"],
352
+ },
353
+ ...knownStatusKeys.map((key): SettingItem => ({
354
+ id: key,
355
+ label: key,
356
+ description: "Extension status visibility",
357
+ currentValue: statusVisibility.get(key) ? "shown" : "hidden",
358
+ values: ["shown", "hidden"],
359
+ })),
360
+ ];
361
+
362
+ const container = new Container();
363
+ container.addChild(
364
+ new (class {
365
+ render(_width: number) {
366
+ return [
367
+ theme.fg("accent", theme.bold("pi-bar status visibility")),
368
+ theme.fg("dim", "Enter/Space toggles · Esc closes"),
369
+ "",
370
+ ];
371
+ }
372
+ invalidate() {}
373
+ })(),
374
+ );
375
+
376
+ const settingsList = new SettingsList(
377
+ items,
378
+ Math.min(items.length + 2, 15),
379
+ getSettingsListTheme(),
380
+ (id, newValue) => {
381
+ if (id === "__future") {
382
+ futureShown = newValue === "shown";
383
+ } else {
384
+ statusVisibility.set(id, newValue === "shown");
385
+ }
386
+ persistFromVisibility();
387
+ },
388
+ () => done(undefined),
389
+ { enableSearch: true },
390
+ );
391
+
392
+ container.addChild(settingsList);
393
+
394
+ return {
395
+ render(width: number) {
396
+ return container.render(width);
397
+ },
398
+ invalidate() {
399
+ container.invalidate();
400
+ },
401
+ handleInput(data: string) {
402
+ settingsList.handleInput?.(data);
403
+ tui.requestRender();
404
+ },
405
+ };
406
+ });
407
+ };
258
408
 
259
409
  pi.registerCommand("bar", {
260
410
  description: "Configure pi-bar footer status segments",
261
411
  handler: async (args, ctx) => {
262
412
  const [section, action, ...rest] = args.trim().split(/\s+/).filter(Boolean);
263
- if (!section || section === "status" || section === "statuses") {
413
+ if (!section || ((section === "status" || section === "statuses") && !action)) {
414
+ await openStatusConfigurator(ctx);
415
+ return;
416
+ }
417
+
418
+ if (section === "status" || section === "statuses") {
264
419
  const keys = splitStatusKeys(rest.join(" "));
265
420
 
266
421
  switch (action) {
267
- case undefined:
422
+ case "config":
423
+ case "configure":
424
+ case "edit":
425
+ await openStatusConfigurator(ctx);
426
+ return;
268
427
  case "list":
269
428
  case "ls": {
270
- const known = Array.from(seenStatusKeys).sort();
429
+ const known = getKnownStatusKeys(statusFilter, seenStatusKeys);
271
430
  ctx.ui.notify(
272
431
  `pi-bar statuses: ${describeStatusFilter(statusFilter)}${known.length > 0 ? `; known: ${known.join(", ")}` : "; known: none yet"}`,
273
432
  "info",
@@ -305,8 +464,7 @@ export default function (pi: ExtensionAPI) {
305
464
  return;
306
465
  }
307
466
 
308
- pi.appendEntry(STATUS_FILTER_ENTRY_TYPE, serializeStatusFilter(statusFilter));
309
- refresh();
467
+ persistStatusFilter();
310
468
  ctx.ui.notify(`pi-bar statuses: ${describeStatusFilter(statusFilter)}`, "info");
311
469
  return;
312
470
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bar",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Never accidentally run Opus on a typo. Pi footer/statusline showing active model, thinking level, context usage, and extension statuses.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -46,6 +46,6 @@
46
46
  "extensions": [
47
47
  "./extensions/status-footer.ts"
48
48
  ],
49
- "image": "https://cdn.jsdelivr.net/npm/pi-bar@0.3.3/assets/screenshot.png"
49
+ "image": "https://cdn.jsdelivr.net/npm/pi-bar@0.3.5/assets/screenshot.png"
50
50
  }
51
51
  }