@0xkahi/pi-qol 1.0.5 → 1.0.6

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
@@ -54,8 +54,9 @@ shows the current directory as an icon plus basename, supports hex color overrid
54
54
  can hide token/cache clusters, and adds an OAuth subscription-usage progress bar
55
55
  for supported providers (Anthropic and OpenAI Codex).
56
56
 
57
- - **Directory line** — directory icon + basename, with optional git branch and
58
- session name.
57
+ - **Directory line** — optional inverse-styled agent badge followed by the
58
+ directory icon + basename, with optional git branch and session name. The badge
59
+ is disabled by default.
59
60
  - **Stats line** — cumulative input/output tokens, cache read/write/hit cluster,
60
61
  session cost (or `(sub)` when on a subscription), context-window usage, and the
61
62
  right-aligned model name (with provider prefix when multiple providers are
@@ -117,12 +118,15 @@ them (project overrides global):
117
118
  "enabled": true,
118
119
  "colors": {
119
120
  "directory": "#A78BFA",
120
- "modelName": "#60A5FA"
121
+ "modelName": "#60A5FA",
122
+ "agentName": "#FBBF24"
121
123
  },
122
124
  "display": {
123
125
  "tokens": true,
124
- "cache": true
125
- }
126
+ "cache": true,
127
+ "agentName": true
128
+ },
129
+ "defaultAgentName": "DEFAULT"
126
130
  }
127
131
  }
128
132
  ```
@@ -188,8 +192,11 @@ Context View is a fork of Dmitry Makarov's [pi-context-view](https://github.com/
188
192
  | `enabled` | `boolean` | `false` | Replace pi's built-in interactive footer. |
189
193
  | `display.tokens` | `boolean` | `true` | Show cumulative input/output token counts. |
190
194
  | `display.cache` | `boolean` | `true` | Show the custom cache read/write/hit cluster. |
195
+ | `display.agentName` | `boolean` | `false` | Prefix the first line with a padded bold inverse agent badge. |
196
+ | `defaultAgentName` | `string` | `DEFAULT` | Agent name restored at the start of each session. |
191
197
  | `colors.directory` | `hex` | — | Color the directory icon and basename. |
192
198
  | `colors.modelName` | `hex` | — | Color the right-aligned model name. |
199
+ | `colors.agentName` | `hex` | — | Agent badge foreground color before inversion. |
193
200
  | `colors.anthropicUsage` | `hex` | `#D97706` | Color the Claude subscription usage segment (bar + percentage). |
194
201
  | `colors.codexUsage` | `hex` | `#10B981` | Color the Codex subscription usage segment (bar + percentage). |
195
202
  | `icons.directory` | `string` | nerd font | Glyph shown before the directory basename. |
@@ -198,6 +205,29 @@ Context View is a fork of Dmitry Makarov's [pi-context-view](https://github.com/
198
205
  | `icons.cacheWrite` | `string` | nerd font | Glyph for cache-write tokens. |
199
206
  | `icons.refresh` | `string` | nerd font | Glyph shown before the subscription reset time. |
200
207
 
208
+ When enabled, the badge has no brackets, uses bold and inverse styling, and adds
209
+ one styled padding space on each side of the name. One normal, unstyled space
210
+ separates the trailing badge padding from the directory. Names are trimmed and
211
+ sanitized. Names wider than ten terminal columns are rendered as their first ten
212
+ visible columns plus `...`; badge padding does not count toward that limit, and
213
+ wide Unicode characters are never split. Badge color precedence is a valid event
214
+ color,
215
+ `colors.agentName`, then pi's `accent` theme color. Event-selected names and
216
+ colors are session-scoped: every `session_start` restores `defaultAgentName` and
217
+ clears the event color.
218
+
219
+ Other extensions can update the current identity through pi's event bus:
220
+
221
+ ```ts
222
+ pi.events.emit('pi.qol.event:set-agent-name', {
223
+ agentName: 'Reviewer',
224
+ color: '#FFFFFF', // optional; must be #RRGGBB
225
+ });
226
+ ```
227
+
228
+ Invalid or empty names are ignored. A missing or invalid event color clears any
229
+ previous event color and uses the normal fallback precedence.
230
+
201
231
  Project config shallow-merges each top-level section over global config. Arrays
202
232
  replace lower-precedence arrays, so project `model_select.favourite` or
203
233
  `model_select.groups` replaces the corresponding global array. Nested objects are
@@ -168,8 +168,10 @@
168
168
  },
169
169
  "display": {
170
170
  "tokens": true,
171
- "cache": true
172
- }
171
+ "cache": true,
172
+ "agentName": false
173
+ },
174
+ "defaultAgentName": "DEFAULT"
173
175
  },
174
176
  "type": "object",
175
177
  "properties": {
@@ -192,6 +194,10 @@
192
194
  "type": "string",
193
195
  "pattern": "^#[0-9a-fA-F]{6}$"
194
196
  },
197
+ "agentName": {
198
+ "type": "string",
199
+ "pattern": "^#[0-9a-fA-F]{6}$"
200
+ },
195
201
  "anthropicUsage": {
196
202
  "default": "#D97706",
197
203
  "type": "string",
@@ -239,7 +245,8 @@
239
245
  "display": {
240
246
  "default": {
241
247
  "tokens": true,
242
- "cache": true
248
+ "cache": true,
249
+ "agentName": false
243
250
  },
244
251
  "type": "object",
245
252
  "properties": {
@@ -250,8 +257,16 @@
250
257
  "cache": {
251
258
  "default": true,
252
259
  "type": "boolean"
260
+ },
261
+ "agentName": {
262
+ "default": false,
263
+ "type": "boolean"
253
264
  }
254
265
  }
266
+ },
267
+ "defaultAgentName": {
268
+ "default": "DEFAULT",
269
+ "type": "string"
255
270
  }
256
271
  }
257
272
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xkahi/pi-qol",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "quality of life pi extensions",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -43,13 +43,14 @@
43
43
  "@earendil-works/pi-tui": "*"
44
44
  },
45
45
  "devDependencies": {
46
- "@earendil-works/pi-ai": "^0.84.3",
47
- "@earendil-works/pi-coding-agent": "^0.84.3",
48
- "@earendil-works/pi-tui": "^0.84.3",
49
46
  "@biomejs/biome": "^2.4.15",
50
47
  "@changesets/cli": "^2.31.0",
51
- "@types/node": "^24.0.0",
48
+ "@earendil-works/pi-ai": "^0.85.0",
49
+ "@earendil-works/pi-coding-agent": "^0.85.0",
50
+ "@earendil-works/pi-server": "0.85.0",
51
+ "@earendil-works/pi-tui": "^0.85.0",
52
52
  "@types/bun": "latest",
53
+ "@types/node": "^24.0.0",
53
54
  "bun-types": "latest",
54
55
  "typescript": "^5"
55
56
  },
package/src/constants.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ObjectValues } from './types';
2
2
 
3
3
  export const EXTENSION_ID = 'pi-qol';
4
+ export const SET_AGENT_NAME_EVENT_ID = 'pi.qol.event:set-agent-name';
4
5
 
5
6
  const SUB_EXTENSION_IDS = {
6
7
  auto_session_name: 'auto_session_name',
@@ -0,0 +1,60 @@
1
+ import { sliceByColumn, stripTerminalSequences, visibleWidth } from '@earendil-works/pi-tui';
2
+ import { COLOR_HEX_REGEX } from '../../constants';
3
+
4
+ const MAX_AGENT_NAME_WIDTH = 10;
5
+
6
+ function normalizeAgentName(value: string): string {
7
+ const sanitized = stripTerminalSequences(value)
8
+ .replace(/\p{Cc}/gu, '')
9
+ .trim();
10
+ return visibleWidth(sanitized) > MAX_AGENT_NAME_WIDTH ? `${sliceByColumn(sanitized, 0, MAX_AGENT_NAME_WIDTH, true)}...` : sanitized;
11
+ }
12
+
13
+ export type AgentDisplay = {
14
+ name: string;
15
+ eventColor?: string;
16
+ };
17
+
18
+ export class AgentDisplayState {
19
+ private current: AgentDisplay;
20
+ private readonly listeners = new Set<() => void>();
21
+
22
+ constructor(defaultName: string) {
23
+ this.current = { name: normalizeAgentName(defaultName) };
24
+ }
25
+
26
+ snapshot(): Readonly<AgentDisplay> {
27
+ return this.current;
28
+ }
29
+
30
+ reset(defaultName: string): void {
31
+ this.current = { name: normalizeAgentName(defaultName) };
32
+ this.notify();
33
+ }
34
+
35
+ update(payload: unknown): boolean {
36
+ if (!payload || typeof payload !== 'object') return false;
37
+
38
+ const { agentName, color } = payload as Record<string, unknown>;
39
+ if (typeof agentName !== 'string') return false;
40
+
41
+ const name = normalizeAgentName(agentName);
42
+ if (!name) return false;
43
+
44
+ this.current = {
45
+ name,
46
+ eventColor: typeof color === 'string' && COLOR_HEX_REGEX.test(color) ? color : undefined,
47
+ };
48
+ this.notify();
49
+ return true;
50
+ }
51
+
52
+ onChange(listener: () => void): () => void {
53
+ this.listeners.add(listener);
54
+ return () => this.listeners.delete(listener);
55
+ }
56
+
57
+ private notify(): void {
58
+ for (const listener of this.listeners) listener();
59
+ }
60
+ }
@@ -18,6 +18,7 @@ function sanitizeStatusText(text: string): string {
18
18
  export class CustomFooterComponent implements Component {
19
19
  private readonly usageManager: SubscriptionUsageManager;
20
20
  private readonly unsubscribeBranch: () => void;
21
+ private readonly unsubscribeAgentDisplay: () => void;
21
22
  private restoredDefaultFooter = false;
22
23
  private disposed = false;
23
24
 
@@ -26,6 +27,9 @@ export class CustomFooterComponent implements Component {
26
27
  if (!this.disposed) deps.tui.requestRender();
27
28
  });
28
29
  this.unsubscribeBranch = deps.footerData.onBranchChange(() => deps.tui.requestRender());
30
+ this.unsubscribeAgentDisplay = deps.agentDisplayState.onChange(() => {
31
+ if (!this.disposed) deps.tui.requestRender();
32
+ });
29
33
  }
30
34
 
31
35
  invalidate(): void {
@@ -35,6 +39,7 @@ export class CustomFooterComponent implements Component {
35
39
  dispose(): void {
36
40
  this.disposed = true;
37
41
  this.unsubscribeBranch();
42
+ this.unsubscribeAgentDisplay();
38
43
  }
39
44
 
40
45
  render(width: number): string[] {
@@ -84,9 +89,26 @@ export class CustomFooterComponent implements Component {
84
89
  line = this.deps.theme.fg('dim', rawLine);
85
90
  }
86
91
 
92
+ if (config.display.agentName) {
93
+ line = `${this.renderAgentBadge(config)} ${line}`;
94
+ }
95
+
87
96
  return truncateToWidth(line, width, this.deps.theme.fg('dim', '...'));
88
97
  }
89
98
 
99
+ private renderAgentBadge(config: CustomFooterConfig): string {
100
+ const agentDisplay = this.deps.agentDisplayState.snapshot();
101
+ const badgeText = ` ${agentDisplay.name} `;
102
+ const color = agentDisplay.eventColor ?? config.colors.agentName;
103
+ if (color) {
104
+ return dye
105
+ .colorize({ fg: dye.hex(color) })
106
+ .bold()
107
+ .inverse(badgeText);
108
+ }
109
+ return dye.inverse(dye.bold(this.deps.theme.fg('accent', badgeText)));
110
+ }
111
+
90
112
  private renderStatsLine(width: number, config: CustomFooterConfig): string {
91
113
  const model = this.deps.ctx.model;
92
114
  const usingSubscription = model ? this.deps.ctx.modelRegistry.isUsingOAuth(model) : false;
@@ -1,17 +1,33 @@
1
1
  import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
2
  import type { ConfigLoader } from '../../config-loader';
3
+ import { SET_AGENT_NAME_EVENT_ID } from '../../constants';
4
+ import { AgentDisplayState } from './agent-display-state';
3
5
  import { CustomFooterComponent } from './footer-component';
4
6
 
5
7
  export function registerCustomFooter(pi: ExtensionAPI, deps: { config: ConfigLoader }): void {
6
8
  let installed = false;
9
+ const agentDisplayState = new AgentDisplayState('DEFAULT');
10
+
11
+ pi.events.on(SET_AGENT_NAME_EVENT_ID, payload => {
12
+ agentDisplayState.update(payload);
13
+ });
7
14
 
8
15
  pi.on('session_start', (_event, ctx) => {
16
+ agentDisplayState.reset(deps.config.getCustomFooter().defaultAgentName);
9
17
  if (!deps.config.isEnabled('custom_footer')) return;
10
18
  if (installed) return;
11
19
 
12
20
  ctx.ui.setFooter(
13
21
  (tui, theme, footerData) =>
14
- new CustomFooterComponent({ tui, theme, footerData, ctx, config: deps.config, getThinkingLevel: () => pi.getThinkingLevel() }),
22
+ new CustomFooterComponent({
23
+ tui,
24
+ theme,
25
+ footerData,
26
+ ctx,
27
+ config: deps.config,
28
+ agentDisplayState,
29
+ getThinkingLevel: () => pi.getThinkingLevel(),
30
+ }),
15
31
  );
16
32
  installed = true;
17
33
  });
@@ -2,6 +2,7 @@ import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
2
2
  import type { TUI } from '@earendil-works/pi-tui';
3
3
  import type { ConfigLoader } from '../../config-loader';
4
4
  import type { Config } from '../../schemas/config.schema';
5
+ import type { AgentDisplayState } from './agent-display-state';
5
6
 
6
7
  export type SupportedProvider = 'anthropic' | 'openai-codex';
7
8
 
@@ -11,7 +12,7 @@ export type CustomFooterDisplay = CustomFooterConfig['display'];
11
12
  export type CustomFooterIcons = CustomFooterConfig['icons'];
12
13
 
13
14
  export type FooterTheme = {
14
- fg(color: 'dim' | 'error' | 'warning', text: string): string;
15
+ fg(color: 'accent' | 'dim' | 'error' | 'warning', text: string): string;
15
16
  };
16
17
 
17
18
  export type FooterDataProvider = {
@@ -27,6 +28,7 @@ export type CustomFooterComponentDeps = {
27
28
  footerData: FooterDataProvider;
28
29
  ctx: ExtensionContext;
29
30
  config: ConfigLoader;
31
+ agentDisplayState: AgentDisplayState;
30
32
  getThinkingLevel: () => string;
31
33
  };
32
34
 
@@ -1,9 +1,15 @@
1
1
  import z from 'zod';
2
2
  import { ColorHexSchema } from './shared-config.schema';
3
3
 
4
+ const AgentNameSchema = z
5
+ .string()
6
+ .refine(value => value.trim().length > 0, { message: 'Agent name must not be empty' })
7
+ .default('DEFAULT');
8
+
4
9
  const CustomFooterColorsSchema = z.object({
5
10
  directory: ColorHexSchema.optional(),
6
11
  modelName: ColorHexSchema.optional(),
12
+ agentName: ColorHexSchema.optional(),
7
13
  anthropicUsage: ColorHexSchema.optional().default('#D97706'),
8
14
  codexUsage: ColorHexSchema.optional().default('#10B981'),
9
15
  });
@@ -19,6 +25,7 @@ const CustomFooterIconsSchema = z.object({
19
25
  const CustomFooterDisplaySchema = z.object({
20
26
  tokens: z.boolean().optional().default(true),
21
27
  cache: z.boolean().optional().default(true),
28
+ agentName: z.boolean().optional().default(false),
22
29
  });
23
30
 
24
31
  const DEFAULT_CUSTOM_FOOTER_COLORS = CustomFooterColorsSchema.parse({});
@@ -30,6 +37,7 @@ export const CustomFooterConfigSchema = z.object({
30
37
  colors: CustomFooterColorsSchema.default(DEFAULT_CUSTOM_FOOTER_COLORS),
31
38
  icons: CustomFooterIconsSchema.default(DEFAULT_CUSTOM_FOOTER_ICONS),
32
39
  display: CustomFooterDisplaySchema.default(DEFAULT_CUSTOM_FOOTER_DISPLAY),
40
+ defaultAgentName: AgentNameSchema,
33
41
  });
34
42
  export type CustomFooterConfig = z.infer<typeof CustomFooterConfigSchema>;
35
43
 
@@ -41,6 +49,7 @@ export const PartialCustomFooterConfigSchema = z.object({
41
49
  .object({
42
50
  directory: ColorHexSchema.optional(),
43
51
  modelName: ColorHexSchema.optional(),
52
+ agentName: ColorHexSchema.optional(),
44
53
  anthropicUsage: ColorHexSchema.optional(),
45
54
  codexUsage: ColorHexSchema.optional(),
46
55
  })
@@ -58,7 +67,9 @@ export const PartialCustomFooterConfigSchema = z.object({
58
67
  .object({
59
68
  tokens: z.boolean().optional(),
60
69
  cache: z.boolean().optional(),
70
+ agentName: z.boolean().optional(),
61
71
  })
62
72
  .optional(),
73
+ defaultAgentName: AgentNameSchema.optional(),
63
74
  });
64
75
  export type PartialCustomFooterConfig = z.infer<typeof PartialCustomFooterConfigSchema>;