@firstpick/pi-utils 0.1.1 → 0.1.2

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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/index.ts +58 -0
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -7,3 +7,7 @@ Shared helper utilities used by `@firstpick/pi-extension-*` packages.
7
7
  - `getAgentDir()`
8
8
  - `envFlag(name, fallback?)`
9
9
  - `resolvePathFromAgentDir(configuredPath)`
10
+ - `createExtensionWorkingIndicator(ctx, initialMessage, options?)`
11
+ - `withExtensionWorkingIndicator(ctx, initialMessage, run, options?)`
12
+
13
+ `createExtensionWorkingIndicator` renders a reusable extension-owned spinner using `ctx.ui.setWidget` plus footer `setStatus`, so it works inside slash-command handlers where Pi's built-in model-streaming working row is not shown.
package/index.ts CHANGED
@@ -2,6 +2,19 @@ import os from "node:os";
2
2
  import path from "node:path";
3
3
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
4
 
5
+ export type ExtensionWorkingIndicator = {
6
+ update(message: string): void;
7
+ stop(): void;
8
+ };
9
+
10
+ export type ExtensionWorkingIndicatorOptions = {
11
+ id?: string;
12
+ title?: string;
13
+ placement?: "aboveEditor" | "belowEditor";
14
+ intervalMs?: number;
15
+ frames?: string[];
16
+ };
17
+
5
18
  export function getAgentDir(): string {
6
19
  const env = process.env.PI_CODING_AGENT_DIR?.trim();
7
20
  if (env) return path.resolve(env);
@@ -18,6 +31,51 @@ export function resolvePathFromAgentDir(configuredPath: string): string {
18
31
  return path.isAbsolute(configuredPath) ? path.normalize(configuredPath) : path.resolve(getAgentDir(), configuredPath);
19
32
  }
20
33
 
34
+ export function createExtensionWorkingIndicator(ctx: any, initialMessage: string, options: ExtensionWorkingIndicatorOptions = {}): ExtensionWorkingIndicator {
35
+ const id = options.id ?? "extension-working";
36
+ const title = options.title ?? "Working";
37
+ const frames = options.frames ?? ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
38
+ const intervalMs = options.intervalMs ?? 100;
39
+ const placement = options.placement ?? "aboveEditor";
40
+ let frameIndex = 0;
41
+ let message = initialMessage;
42
+ let stopped = false;
43
+
44
+ const render = () => {
45
+ if (stopped) return;
46
+ const frame = frames[frameIndex % frames.length] ?? "•";
47
+ frameIndex += 1;
48
+ ctx?.ui?.setStatus?.(id, `${frame} ${message}`);
49
+ ctx?.ui?.setWidget?.(id, [`${frame} ${title}… ${message}`], { placement });
50
+ };
51
+
52
+ render();
53
+ const timer = setInterval(render, intervalMs);
54
+
55
+ return {
56
+ update(nextMessage: string) {
57
+ message = nextMessage;
58
+ render();
59
+ },
60
+ stop() {
61
+ if (stopped) return;
62
+ stopped = true;
63
+ clearInterval(timer);
64
+ ctx?.ui?.setStatus?.(id, undefined);
65
+ ctx?.ui?.setWidget?.(id, undefined);
66
+ },
67
+ };
68
+ }
69
+
70
+ export async function withExtensionWorkingIndicator<T>(ctx: any, initialMessage: string, run: (indicator: ExtensionWorkingIndicator) => Promise<T>, options?: ExtensionWorkingIndicatorOptions): Promise<T> {
71
+ const indicator = createExtensionWorkingIndicator(ctx, initialMessage, options);
72
+ try {
73
+ return await run(indicator);
74
+ } finally {
75
+ indicator.stop();
76
+ }
77
+ }
78
+
21
79
  export default function piUtilsExtension(_pi: ExtensionAPI): void {
22
80
  // Utility package: no runtime behavior.
23
81
  }
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@firstpick/pi-utils",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Shared utilities for Firstpick Pi extension packages.",
5
+ "main": "index.ts",
6
+ "exports": "./index.ts",
5
7
  "license": "MIT",
6
8
  "keywords": [
7
9
  "pi-package",