@mrclrchtr/supi-extras 2.2.0 → 2.3.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,6 +2,48 @@
2
2
 
3
3
  import type { FileEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
4
4
 
5
+ /**
6
+ * Minimal pi API surface needed to track the current session display name reactively.
7
+ * Accept `ExtensionAPI` or any object satisfying this shape.
8
+ */
9
+ export interface SessionNameTrackerHost {
10
+ on(event: string, handler: (...args: unknown[]) => unknown): void;
11
+ getSessionName(): string | undefined;
12
+ }
13
+
14
+ /**
15
+ * Create a reactive session-name tracker that stays consistent across
16
+ * session starts, renames, and shutdowns without polling.
17
+ *
18
+ * Subscribes to `session_start` (initial name), `session_info_changed`
19
+ * (renames via `/name`, `pi.setSessionName()`, or RPC), and
20
+ * `session_shutdown` (reset to `undefined`).
21
+ *
22
+ * @returns a zero-arg getter that always returns the current session name
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const getSessionName = createSessionNameTracker(pi);
27
+ * // …later, during tool execute or spinner rendering:
28
+ * const name = getSessionName();
29
+ * ```
30
+ */
31
+ export function createSessionNameTracker(pi: SessionNameTrackerHost): () => string | undefined {
32
+ let name: string | undefined;
33
+
34
+ pi.on("session_start", () => {
35
+ name = pi.getSessionName();
36
+ });
37
+ pi.on("session_info_changed", (event) => {
38
+ name = (event as { name?: string }).name;
39
+ });
40
+ pi.on("session_shutdown", () => {
41
+ name = undefined;
42
+ });
43
+
44
+ return () => name;
45
+ }
46
+
5
47
  /**
6
48
  * Resolve the active branch path using PI's append-only tree semantics.
7
49
  *
@@ -1,4 +1,8 @@
1
1
  // supi-core session domain — session utilities and registries.
2
2
 
3
3
  export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
4
- export { getActiveBranchEntries } from "./session-utils.ts";
4
+ export type { SessionNameTrackerHost } from "./session-utils.ts";
5
+ export {
6
+ createSessionNameTracker,
7
+ getActiveBranchEntries,
8
+ } from "./session-utils.ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-extras",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SuPi extras — command aliases, skill shorthand, tab spinner, /supi-stash prompt stash with TUI overlay, and other small utilities",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "clipboardy": "^5.3.1",
36
- "@mrclrchtr/supi-core": "2.2.0"
36
+ "@mrclrchtr/supi-core": "2.3.0"
37
37
  },
38
38
  "bundledDependencies": [
39
39
  "@mrclrchtr/supi-core"
@@ -81,6 +81,8 @@ export function thinkingThemeToken(level: string): ThemeColor {
81
81
  return "thinkingHigh";
82
82
  case "xhigh":
83
83
  return "thinkingXhigh";
84
+ case "max":
85
+ return "thinkingMax";
84
86
  default:
85
87
  return "dim";
86
88
  }
@@ -10,6 +10,7 @@
10
10
  * agent starts or the session shuts down.
11
11
  */
12
12
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
13
+ import { createSessionNameTracker } from "@mrclrchtr/supi-core/session";
13
14
  import { BRAILLE_SPINNER_FRAMES, SPINNER_INTERVAL_MS } from "@mrclrchtr/supi-core/spinner-frames";
14
15
  import { formatTitle, signalDone } from "@mrclrchtr/supi-core/terminal";
15
16
 
@@ -29,6 +30,8 @@ type ReviewTitleState =
29
30
 
30
31
  // biome-ignore lint/complexity/noExcessiveLinesPerFunction: spinner state and event wiring are intentionally colocated
31
32
  export default function tabSpinner(pi: ExtensionAPI) {
33
+ const getSessionName = createSessionNameTracker(pi);
34
+
32
35
  let timer: ReturnType<typeof setInterval> | null = null;
33
36
  let pendingAgentEndTimer: ReturnType<typeof setTimeout> | null = null;
34
37
  let frame = 0;
@@ -38,7 +41,6 @@ export default function tabSpinner(pi: ExtensionAPI) {
38
41
  let askUserActive = 0;
39
42
  let reviewTitleState: ReviewTitleState = { kind: "none" };
40
43
  let currentCtx: ExtensionContext | undefined;
41
- let cachedSessionName: string | undefined;
42
44
  let cachedCwd: string | undefined;
43
45
  const unregisterBusHandlers: Array<() => void> = [];
44
46
 
@@ -106,19 +108,17 @@ export default function tabSpinner(pi: ExtensionAPI) {
106
108
  function rememberContext(ctx: ExtensionContext) {
107
109
  currentCtx = ctx;
108
110
  cachedCwd = ctx.cwd;
109
- cachedSessionName = getSessionNameSafe();
110
111
  }
111
112
 
112
113
  function getSessionNameSafe(): string | undefined {
113
114
  try {
114
- const next = pi.getSessionName();
115
- if (next !== undefined) {
116
- cachedSessionName = next;
117
- }
118
- return cachedSessionName;
115
+ // Call pi.getSessionName() as a canary — throws if context is stale.
116
+ // The actual name is maintained reactively via createSessionNameTracker.
117
+ pi.getSessionName();
118
+ return getSessionName();
119
119
  } catch {
120
120
  handleStaleContext();
121
- return cachedSessionName;
121
+ return getSessionName();
122
122
  }
123
123
  }
124
124