pi-compact-tools 0.13.0 → 0.13.1

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.
@@ -6,14 +6,18 @@ import * as tui from "@earendil-works/pi-tui";
6
6
  export type Rgb = { r: number; g: number; b: number };
7
7
 
8
8
  /**
9
- * What Pi 0.99 added to its Theme for extensions. Older Pi has none of it, so each
10
- * piece is read as optional and the few lines below stand in when it is missing.
9
+ * What Pi 0.99 added to its Theme for extensions, and what Pi 0.85 to 0.87 keep on
10
+ * theirs. Each piece is read as optional, and typed here rather than taken from Pi,
11
+ * so the extension builds and runs against every Pi it supports.
11
12
  */
12
- type HostTheme = Theme & {
13
- colors?: Readonly<Record<string, tui.Color | undefined>>;
13
+ type HostColor = object;
14
+ type HostTheme = {
15
+ colors?: Readonly<Record<string, HostColor | undefined>>;
14
16
  appearance?: "dark" | "light";
17
+ fgColors?: unknown;
15
18
  };
16
- const colorToRgb = (tui as Partial<typeof tui>).colorToRgb;
19
+ const host = (theme: Theme) => theme as unknown as HostTheme;
20
+ const colorToRgb = (tui as unknown as { colorToRgb?: (color: HostColor) => Rgb }).colorToRgb;
17
21
 
18
22
  /**
19
23
  * A theme token's concrete color. Pi 0.99 resolves every token, including one set
@@ -22,7 +26,7 @@ const colorToRgb = (tui as Partial<typeof tui>).colorToRgb;
22
26
  * nothing rather than throwing, since callers compute names from host state.
23
27
  */
24
28
  export function themeColorRgb(theme: Theme, color: ThemeColor): Rgb | undefined {
25
- const { colors } = theme as HostTheme;
29
+ const { colors } = host(theme);
26
30
  if (colors && colorToRgb) {
27
31
  const concrete = colors[color];
28
32
  if (!concrete) return undefined;
@@ -119,7 +123,7 @@ export function rgbPainter(theme: Theme, color: Rgb): (text: string) => string {
119
123
  * neither is told apart by the escape sequences of the colors derived from.
120
124
  */
121
125
  export function paletteOf(theme: Theme): object {
122
- const { colors, fgColors } = theme as HostTheme & { fgColors?: unknown };
126
+ const { colors, fgColors } = host(theme);
123
127
  if (colors) return colors;
124
128
  if (fgColors instanceof Map) return fgColors;
125
129
  let key = theme.getColorMode?.() ?? "";
@@ -164,7 +168,7 @@ const WHITE: Rgb = { r: 255, g: 255, b: 255 };
164
168
 
165
169
  /** The theme's declared appearance; before Pi 0.99, a theme with light text is a dark one. */
166
170
  function isDark(theme: Theme): boolean {
167
- const { appearance } = theme as HostTheme;
171
+ const { appearance } = host(theme);
168
172
  if (appearance) return appearance === "dark";
169
173
  const text = themeColorRgb(theme, "text");
170
174
  return !text || luminanceRgb(text) > 128;
@@ -503,6 +503,14 @@ function noteCalls(message: unknown): void {
503
503
  }
504
504
  }
505
505
 
506
+ /**
507
+ * Whether another tool made the call through `ctx.executeTool()`, as codemode scripts
508
+ * do. Pi 0.99 marks such calls with `parentToolCallId`; older Pi never makes them.
509
+ */
510
+ function madeByTool(event: object): boolean {
511
+ return typeof (event as { parentToolCallId?: unknown }).parentToolCallId === "string";
512
+ }
513
+
506
514
  /** Hand the animation Pi's frame request, reached through an invisible widget as the extension API allows. */
507
515
  function bindRenderer(ctx: ExtensionContext): void {
508
516
  ctx.ui.setWidget(RENDER_WIDGET_KEY, (tui) => {
@@ -572,12 +580,12 @@ export default function compactTools(pi: ExtensionAPI): void {
572
580
  // their rows, and told to extensions before Pi makes them.
573
581
  pi.on("message_update", (event) => noteCalls(event.message));
574
582
  pi.on("tool_execution_start", (event) => {
575
- if (event.parentToolCallId) return runtime.noteNestedCall(event.toolCallId, true);
583
+ if (madeByTool(event)) return runtime.noteNestedCall(event.toolCallId, true);
576
584
  runtime.noteCall(event.toolCallId);
577
585
  runtime.noteExecutionStart(event.toolCallId);
578
586
  });
579
587
  pi.on("tool_execution_end", (event) => {
580
- if (event.parentToolCallId) return runtime.noteNestedCall(event.toolCallId, false);
588
+ if (madeByTool(event)) return runtime.noteNestedCall(event.toolCallId, false);
581
589
  runtime.noteExecutionEnd(event.toolCallId);
582
590
  });
583
591
  pi.on("session_shutdown", (event) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-compact-tools",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Compact, expandable tool rows for Pi in its own compact style or Claude Code's, with a silent mode and a GitHub Dark theme.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,5 @@
1
1
  {
2
+ "0.13.1": [],
2
3
  "0.13.0": [
3
4
  "Follows Pi 0.99's system theme and light terminals: rails, dots, and the working label take their colors from the theme itself",
4
5
  "Running dots, rails, and silent mode's activity line are painted once per theme instead of every frame",