pi-session-subagents 0.1.1 → 0.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/CHANGELOG.md +14 -0
- package/README.md +3 -0
- package/package.json +1 -1
- package/src/ui/conversation-viewer.ts +30 -5
- package/src/ui/outside-click.ts +88 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0](https://github.com/rbajaj1997/pi-session-subagents/compare/v0.2.0...v0.3.0) (2026-11-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* show cumulative cost in the subagent inspector ([#6](https://github.com/rbajaj1997/pi-session-subagents/issues/6)) ([40f46ab](https://github.com/rbajaj1997/pi-session-subagents/commit/40f46abfb96218cd51caf50d53f2064a19b08c78))
|
|
9
|
+
|
|
10
|
+
## [0.2.0](https://github.com/rbajaj1997/pi-session-subagents/compare/v0.1.1...v0.2.0) (2026-11-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* dismiss subagent inspector on outside click ([#4](https://github.com/rbajaj1997/pi-session-subagents/issues/4)) ([c917e49](https://github.com/rbajaj1997/pi-session-subagents/commit/c917e49180cd190ead3f0e7b39fa37e3f7f8a6cc))
|
|
16
|
+
|
|
3
17
|
## [0.1.1](https://github.com/rbajaj1997/pi-session-subagents/compare/v0.1.0...v0.1.1) (2026-11-15)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -133,11 +133,14 @@ For longer results, call `inspect_subagent` with `includeResult: true`, the repo
|
|
|
133
133
|
|
|
134
134
|
The main widget and the inspector need the interactive TUI. In RPC mode, use `list_subagents` and `inspect_subagent`. The main widget shows worker status and activity. In fullscreen mode, Pi's default, click a worker in the widget to open its inspector. In regular mode the terminal handles the mouse, so use `/subagents:inspect [name]`. The inspector renders the worker's full session branch, including messages before compaction, with Pi's native assistant, user, custom-message, tool, and summary components. Tool cards use registered renderers, including edit diffs. Inline tool images are off in the inspector.
|
|
135
135
|
|
|
136
|
+
The header shows elapsed time for the current or most recent assignment in whole minutes (`<1m` for the first minute). The cost at the end, for example `~$0.123 total`, is Pi’s estimate across all assignments in that worker session, not a billing total.
|
|
137
|
+
|
|
136
138
|
- Arrows or `j`/`k` scroll. PageUp/PageDown page. Home/End jump.
|
|
137
139
|
- Scrolling up pauses following. End resumes it.
|
|
138
140
|
- Mouse-wheel scrolling and native click controls work in fullscreen mode.
|
|
139
141
|
- `t` or the configured `app.tools.expand` shortcut expands or collapses tool cards.
|
|
140
142
|
- The configured `app.thinking.toggle` shortcut changes thinking visibility inside the inspector only.
|
|
143
|
+
- In fullscreen mode, left-click outside the inspector to close it without activating the main session. Clicks anywhere inside its frame keep it open. Scrolling and dragging do not dismiss it. Outside drags are consumed rather than passed to the main session and can clear its existing text selection.
|
|
141
144
|
- Escape or `q` closes the inspector without stopping the worker.
|
|
142
145
|
|
|
143
146
|
## Reviewing past work
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type Component,
|
|
18
18
|
Container,
|
|
19
19
|
matchesKey,
|
|
20
|
+
type OverlayHandle,
|
|
20
21
|
Text,
|
|
21
22
|
TruncatedText,
|
|
22
23
|
type TUI,
|
|
@@ -24,8 +25,9 @@ import {
|
|
|
24
25
|
type TuiMouseEventResult,
|
|
25
26
|
truncateToWidth,
|
|
26
27
|
} from "@earendil-works/pi-tui";
|
|
27
|
-
import { clip,
|
|
28
|
+
import { clip, formatTokens, shortModelLabel } from "../text";
|
|
28
29
|
import type { Worker } from "../worker";
|
|
30
|
+
import { dismissOnOutsideClick } from "./outside-click";
|
|
29
31
|
|
|
30
32
|
type ToolView = { component: ToolExecutionComponent; result?: unknown; durationMs?: number };
|
|
31
33
|
|
|
@@ -57,9 +59,17 @@ export async function openInspector(ctx: ExtensionContext, workers: Worker[], na
|
|
|
57
59
|
if (!worker) return;
|
|
58
60
|
}
|
|
59
61
|
const selected = worker;
|
|
62
|
+
let viewer: ConversationViewer;
|
|
60
63
|
await ctx.ui.custom<void>(
|
|
61
|
-
(tui, theme, keybindings, done) =>
|
|
62
|
-
|
|
64
|
+
(tui, theme, keybindings, done) => {
|
|
65
|
+
viewer = new ConversationViewer(tui, selected, theme, keybindings, () => done());
|
|
66
|
+
return viewer;
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
overlay: true,
|
|
70
|
+
overlayOptions: { anchor: "center", width: "90%", margin: 1 },
|
|
71
|
+
onHandle: (handle) => viewer.attachOverlay(handle),
|
|
72
|
+
},
|
|
63
73
|
);
|
|
64
74
|
}
|
|
65
75
|
|
|
@@ -69,6 +79,7 @@ class ConversationViewer implements Component {
|
|
|
69
79
|
private readonly tools = new Map<string, ToolView>();
|
|
70
80
|
private readonly unsubscribe: () => void;
|
|
71
81
|
private leafId: string | null | undefined;
|
|
82
|
+
private sessionCost: { entryCount: number; total: number } | undefined;
|
|
72
83
|
private streaming: AssistantMessageComponent | undefined;
|
|
73
84
|
private scrollOffset = 0;
|
|
74
85
|
private autoScroll = true;
|
|
@@ -79,6 +90,7 @@ class ConversationViewer implements Component {
|
|
|
79
90
|
private expanded = false;
|
|
80
91
|
private hideThinking: boolean;
|
|
81
92
|
private disposed = false;
|
|
93
|
+
private removeOutsideClick: (() => void) | undefined;
|
|
82
94
|
|
|
83
95
|
constructor(
|
|
84
96
|
private readonly tui: TUI,
|
|
@@ -125,6 +137,11 @@ class ConversationViewer implements Component {
|
|
|
125
137
|
});
|
|
126
138
|
}
|
|
127
139
|
|
|
140
|
+
attachOverlay(handle: OverlayHandle): void {
|
|
141
|
+
if (this.disposed || this.removeOutsideClick) return;
|
|
142
|
+
this.removeOutsideClick = dismissOnOutsideClick(this.tui, handle, this.done);
|
|
143
|
+
}
|
|
144
|
+
|
|
128
145
|
handleInput(data: string): void {
|
|
129
146
|
if (matchesKey(data, "escape") || matchesKey(data, "q") || this.keybindings.matches(data, "tui.select.cancel")) {
|
|
130
147
|
this.done();
|
|
@@ -210,13 +227,20 @@ class ConversationViewer implements Component {
|
|
|
210
227
|
const maxScroll = Math.max(0, this.contentHeight - this.viewportHeight);
|
|
211
228
|
this.scrollOffset = this.autoScroll ? maxScroll : Math.min(this.scrollOffset, maxScroll);
|
|
212
229
|
const run = this.worker.stats();
|
|
230
|
+
const minutes = Math.floor(run.durationMs / 60_000);
|
|
231
|
+
const session = this.worker.session;
|
|
232
|
+
const entryCount = session.sessionManager.getEntryCount();
|
|
233
|
+
// Pi totals cost across all entries, even those outside the current branch.
|
|
234
|
+
if (this.sessionCost?.entryCount !== entryCount) {
|
|
235
|
+
this.sessionCost = { entryCount, total: session.getSessionStats().cost };
|
|
236
|
+
}
|
|
213
237
|
const stats = [
|
|
214
238
|
shortModelLabel(this.worker.info.modelLabel),
|
|
215
239
|
this.worker.status,
|
|
216
|
-
`⟳${run.turns}`,
|
|
217
240
|
`${run.toolUses} tools`,
|
|
218
241
|
formatTokens(run.tokens),
|
|
219
|
-
|
|
242
|
+
minutes > 0 ? `${minutes}m` : "<1m",
|
|
243
|
+
`~$${this.sessionCost.total.toFixed(3)} total`,
|
|
220
244
|
].join(" · ");
|
|
221
245
|
const border = (text: string) => this.theme.fg("borderAccent", text);
|
|
222
246
|
const rule = (left: string, right: string) => border(`${left}${"─".repeat(width - 2)}${right}`);
|
|
@@ -246,6 +270,7 @@ class ConversationViewer implements Component {
|
|
|
246
270
|
dispose(): void {
|
|
247
271
|
if (this.disposed) return;
|
|
248
272
|
this.disposed = true;
|
|
273
|
+
this.removeOutsideClick?.();
|
|
249
274
|
this.unsubscribe();
|
|
250
275
|
this.history.clear();
|
|
251
276
|
this.rows.clear();
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Component, OverlayHandle, TUI, TuiMouseEvent, TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
type Dismissal = { handle: OverlayHandle; close: () => void };
|
|
4
|
+
// Pi's TUI proxy forwards symbol values unchanged, but wraps functions on every read.
|
|
5
|
+
const ROUTING = Symbol.for("pi-session-subagents.outside-click");
|
|
6
|
+
type OverlayDispatch = {
|
|
7
|
+
hit: boolean;
|
|
8
|
+
result?: TuiMouseEventResult & {
|
|
9
|
+
target: { component: Component; originX: number; originY: number; width: number; height: number };
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type Registration = {
|
|
13
|
+
dismissals: Set<Dismissal>;
|
|
14
|
+
intercept?: (event: TuiMouseEvent) => OverlayDispatch | undefined;
|
|
15
|
+
};
|
|
16
|
+
type MouseRouter = {
|
|
17
|
+
[ROUTING]?: Registration;
|
|
18
|
+
dispatchMouseToOverlay?: (event: TuiMouseEvent) => OverlayDispatch;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Pi 1.5.2 consumes fullscreen mouse input before extension input listeners run. */
|
|
22
|
+
export function dismissOnOutsideClick(tui: TUI, handle: OverlayHandle, close: () => void): () => void {
|
|
23
|
+
const router = tui as unknown as MouseRouter;
|
|
24
|
+
if (
|
|
25
|
+
tui.mode !== "fullscreen" ||
|
|
26
|
+
typeof router.dispatchMouseToOverlay !== "function" ||
|
|
27
|
+
typeof handle.getBounds !== "function" ||
|
|
28
|
+
typeof handle.isFocused !== "function"
|
|
29
|
+
) {
|
|
30
|
+
return () => {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let registration = router[ROUTING];
|
|
34
|
+
if (!registration) {
|
|
35
|
+
const original = router.dispatchMouseToOverlay;
|
|
36
|
+
const state: Registration = { dismissals: new Set() };
|
|
37
|
+
router[ROUTING] = state;
|
|
38
|
+
// Install once per renderer; refresh the interception logic when reopening after /reload.
|
|
39
|
+
router.dispatchMouseToOverlay = (event) => state.intercept?.(event) ?? original.call(tui, event);
|
|
40
|
+
registration = state;
|
|
41
|
+
}
|
|
42
|
+
const active = registration.dismissals;
|
|
43
|
+
registration.intercept = (event) => {
|
|
44
|
+
if (event.type === "press" && event.button === "left") {
|
|
45
|
+
for (const dismissal of active) {
|
|
46
|
+
const bounds = dismissal.handle.getBounds();
|
|
47
|
+
if (!dismissal.handle.isFocused() || !bounds) continue;
|
|
48
|
+
const inside =
|
|
49
|
+
event.screenX >= bounds.col &&
|
|
50
|
+
event.screenX < bounds.col + bounds.width &&
|
|
51
|
+
event.screenY >= bounds.row &&
|
|
52
|
+
event.screenY < bounds.row + bounds.height;
|
|
53
|
+
if (inside) break;
|
|
54
|
+
// Claim the entire gesture. Pi emits click only after a release without a drag.
|
|
55
|
+
const target: Component = {
|
|
56
|
+
render: () => [],
|
|
57
|
+
invalidate: () => {},
|
|
58
|
+
handleMouse: (next) => {
|
|
59
|
+
if (next.type === "click" && active.has(dismissal) && dismissal.handle.isFocused()) {
|
|
60
|
+
dismissal.close();
|
|
61
|
+
}
|
|
62
|
+
return { handled: true };
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
hit: true,
|
|
67
|
+
result: {
|
|
68
|
+
handled: true,
|
|
69
|
+
target: {
|
|
70
|
+
component: target,
|
|
71
|
+
originX: event.screenX - event.x,
|
|
72
|
+
originY: event.screenY - event.y,
|
|
73
|
+
width: event.width,
|
|
74
|
+
height: event.height,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
};
|
|
82
|
+
const dismissal = { handle, close };
|
|
83
|
+
active.add(dismissal);
|
|
84
|
+
return () => {
|
|
85
|
+
active.delete(dismissal);
|
|
86
|
+
if (active.size === 0) registration.intercept = undefined;
|
|
87
|
+
};
|
|
88
|
+
}
|