@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.
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +42 -0
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +5 -1
- package/package.json +2 -2
- package/src/model-effort-colors-helpers.ts +2 -0
- package/src/tab-spinner.ts +8 -8
|
@@ -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 {
|
|
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.
|
|
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.
|
|
36
|
+
"@mrclrchtr/supi-core": "2.3.0"
|
|
37
37
|
},
|
|
38
38
|
"bundledDependencies": [
|
|
39
39
|
"@mrclrchtr/supi-core"
|
package/src/tab-spinner.ts
CHANGED
|
@@ -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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
121
|
+
return getSessionName();
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|