@maheidem/pi-delegate 0.2.2 → 0.2.3
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/index.ts +9 -1
- package/package.json +1 -1
- package/ui/peek-view.ts +37 -28
- package/ui/running-view.ts +49 -42
package/index.ts
CHANGED
|
@@ -524,7 +524,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
524
524
|
return renderFeedEvents([...feed.all()], {
|
|
525
525
|
startMs: feedStartMs || Date.now(),
|
|
526
526
|
maxChars: 150,
|
|
527
|
-
maxEvents:
|
|
527
|
+
maxEvents: 6,
|
|
528
528
|
});
|
|
529
529
|
};
|
|
530
530
|
const runPromise = app.run(request, {
|
|
@@ -779,6 +779,14 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
779
779
|
const view = new PeekView({ theme, keybindings, state, done: wrappedDone });
|
|
780
780
|
timer = setInterval(() => tui.requestRender(), 1000);
|
|
781
781
|
return view;
|
|
782
|
+
}, {
|
|
783
|
+
overlay: true,
|
|
784
|
+
overlayOptions: {
|
|
785
|
+
width: "92%",
|
|
786
|
+
minWidth: 60,
|
|
787
|
+
maxHeight: "80%",
|
|
788
|
+
anchor: "center",
|
|
789
|
+
},
|
|
782
790
|
});
|
|
783
791
|
} else {
|
|
784
792
|
const { startMs, events } = feedEventsFromTranscript(meta.transcriptPath, { maxEvents: 400 });
|
package/package.json
CHANGED
package/ui/peek-view.ts
CHANGED
|
@@ -26,6 +26,11 @@ export interface PeekViewHost {
|
|
|
26
26
|
done(result: { closed?: boolean }): void;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/** Fixed overlay height — rows never change between frames (smear guard). */
|
|
30
|
+
const PEEK_ROWS = 20;
|
|
31
|
+
/** Content rows inside the fixed frame (top + summary + status + bottom = 4). */
|
|
32
|
+
const CONTENT_ROWS = PEEK_ROWS - 4;
|
|
33
|
+
|
|
29
34
|
export class PeekView implements Component {
|
|
30
35
|
private readonly host: PeekViewHost;
|
|
31
36
|
private offsetFromEnd = 0;
|
|
@@ -44,11 +49,12 @@ export class PeekView implements Component {
|
|
|
44
49
|
(kb?.matches?.(data, "tui.select.cancel") ?? false) ||
|
|
45
50
|
matchesKey(data, "escape") ||
|
|
46
51
|
matchesKey(data, "q");
|
|
52
|
+
const maxOffset = Math.max(0, this.host.state().lines.length - CONTENT_ROWS);
|
|
47
53
|
if (cancel) {
|
|
48
54
|
this.host.done({ closed: true });
|
|
49
55
|
} else if (up) {
|
|
50
56
|
this.following = false;
|
|
51
|
-
this.offsetFromEnd
|
|
57
|
+
this.offsetFromEnd = Math.min(maxOffset, this.offsetFromEnd + 1);
|
|
52
58
|
} else if (down) {
|
|
53
59
|
this.offsetFromEnd = Math.max(0, this.offsetFromEnd - 1);
|
|
54
60
|
if (this.offsetFromEnd === 0) this.following = true;
|
|
@@ -66,43 +72,46 @@ export class PeekView implements Component {
|
|
|
66
72
|
const s = this.host.state();
|
|
67
73
|
const theme = this.host.theme;
|
|
68
74
|
const w = Math.max(1, Math.floor(width));
|
|
69
|
-
const fg = (kind: ThemeColor, text: string) => (theme?.fg ? theme.fg(kind, text) : text);
|
|
70
|
-
const title = ` Peek · ${s.title} `;
|
|
71
|
-
const top = `╭─${truncateToWidth(title, Math.max(4, w - 4))}${"─".repeat(Math.max(0, w - 3 - Math.min(title.length, Math.max(4, w - 4))))}─╮`;
|
|
72
|
-
const bottom = `╰${"─".repeat(Math.max(0, w - 2))}╯`;
|
|
73
75
|
const inner = Math.max(1, w - 4);
|
|
76
|
+
|
|
77
|
+
// Borders stay UNSTYLED so Pi's per-frame width/clear math is exact;
|
|
78
|
+
// color is applied to inner text only.
|
|
79
|
+
const title = truncateToWidth(` Peek · ${s.title} `, Math.max(4, w - 4));
|
|
80
|
+
const top = truncateToWidth(`╭─${title}${"─".repeat(Math.max(0, w - 2 - title.length - 1))}╮`, w);
|
|
81
|
+
const bottom = truncateToWidth(`╰${"─".repeat(Math.max(0, w - 2))}╯`, w);
|
|
74
82
|
const pad = (text: string, color?: ThemeColor) => {
|
|
75
|
-
const
|
|
76
|
-
return
|
|
83
|
+
const body = color && theme?.fg ? theme.fg(color, truncateToWidth(text, inner)) : truncateToWidth(text, inner);
|
|
84
|
+
return `│ ${body} │`;
|
|
77
85
|
};
|
|
78
86
|
|
|
79
|
-
//
|
|
80
|
-
|
|
87
|
+
// Fixed-height viewport: exactly CONTENT_ROWS, newest at the bottom
|
|
88
|
+
// (blank-padded at the top) so the frame height never changes.
|
|
81
89
|
const total = s.lines.length;
|
|
82
90
|
if (total !== this.lastLineCount && this.following) this.offsetFromEnd = 0;
|
|
83
91
|
this.lastLineCount = total;
|
|
84
|
-
const
|
|
85
|
-
|
|
92
|
+
const maxOffset = Math.max(0, total - CONTENT_ROWS);
|
|
93
|
+
if (this.offsetFromEnd > maxOffset) this.offsetFromEnd = maxOffset;
|
|
94
|
+
const end = total - this.offsetFromEnd;
|
|
95
|
+
const start = Math.max(0, end - CONTENT_ROWS);
|
|
86
96
|
const window = s.lines.slice(start, end);
|
|
97
|
+
const content = [...Array<string>(Math.max(0, CONTENT_ROWS - window.length)).fill(""), ...window];
|
|
98
|
+
|
|
99
|
+
const counts = [start > 0 ? `↑${start}` : "", end < total ? `↓${total - end}` : ""].filter(Boolean).join(" ");
|
|
100
|
+
const status = s.live
|
|
101
|
+
? `● live — following · j/k scroll · f re-follow · q close${counts ? ` · ${counts}` : ""}`
|
|
102
|
+
: `final — ${total} event(s) · j/k scroll · q close${counts ? ` · ${counts}` : ""}`;
|
|
87
103
|
|
|
88
104
|
const lines: string[] = [
|
|
89
|
-
|
|
90
|
-
pad(s.summary, "muted"),
|
|
91
|
-
pad(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
: `final — ${total} events (j/k scroll, q close)`,
|
|
95
|
-
s.live ? "success" : "dim",
|
|
96
|
-
),
|
|
105
|
+
top,
|
|
106
|
+
pad(truncateToWidth(s.summary, inner), "muted"),
|
|
107
|
+
pad(status, s.live ? "success" : "dim"),
|
|
108
|
+
...content.map((l) => pad(l, l ? "text" : undefined)),
|
|
109
|
+
bottom,
|
|
97
110
|
];
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (end < total) lines.push(pad(`… ${total - end} newer event(s) — k to scroll down`, "dim"));
|
|
104
|
-
}
|
|
105
|
-
lines.push(truncateToWidth(bottom, w));
|
|
106
|
-
return lines.map((l) => (visibleWidth(l) > w ? truncateToWidth(l, w) : l));
|
|
111
|
+
|
|
112
|
+
// Belt-and-braces: exact height, exact width.
|
|
113
|
+
const clipped = lines.slice(0, PEEK_ROWS);
|
|
114
|
+
while (clipped.length < PEEK_ROWS) clipped.splice(clipped.length - 1, 0, pad(""));
|
|
115
|
+
return clipped.map((l) => (visibleWidth(l) > w ? truncateToWidth(l, w) : l));
|
|
107
116
|
}
|
|
108
117
|
}
|
package/ui/running-view.ts
CHANGED
|
@@ -4,8 +4,14 @@
|
|
|
4
4
|
* A window into the running child: identity + budgets header, elapsed-vs-hard
|
|
5
5
|
* progress, in-flight tools, and a bounded scrolling feed of the child's
|
|
6
6
|
* activity (tool starts/ends, assistant lines, provider errors, handoff).
|
|
7
|
-
*
|
|
8
|
-
* (
|
|
7
|
+
*
|
|
8
|
+
* RENDER CONTRACT (hard-won): this runs as an inline `ctx.ui.custom`
|
|
9
|
+
* component, which REPLACES the composer region while a run is active. The
|
|
10
|
+
* panel MUST render a FIXED number of rows every frame — a height that
|
|
11
|
+
* changes between refreshes smears the previous frame over the input bar.
|
|
12
|
+
* So: constant height, blank-padded, and color ONLY inner text (never the
|
|
13
|
+
* border/padding structure, whose width Pi recomputes every frame).
|
|
14
|
+
* Cancels via Escape twice (armed). Refresh cadence is owned by the host.
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
17
|
import { truncateToWidth, visibleWidth, matchesKey, type Component } from "@earendil-works/pi-tui";
|
|
@@ -25,7 +31,7 @@ export interface RunningViewState {
|
|
|
25
31
|
tokens?: { input?: number; output?: number };
|
|
26
32
|
/** Tools currently in flight. */
|
|
27
33
|
openTools?: string[];
|
|
28
|
-
/** Pre-formatted feed lines (newest last)
|
|
34
|
+
/** Pre-formatted feed lines (newest last); the panel slices/pads itself. */
|
|
29
35
|
feedLines: string[];
|
|
30
36
|
}
|
|
31
37
|
|
|
@@ -36,6 +42,11 @@ export interface RunningViewHost {
|
|
|
36
42
|
done(result: { cancelled?: boolean }): void;
|
|
37
43
|
}
|
|
38
44
|
|
|
45
|
+
/** Constant panel height (top + header + progress + in-flight + FEED + footer + bottom). */
|
|
46
|
+
const PANEL_ROWS = 9;
|
|
47
|
+
/** Feed rows inside the fixed frame; the rest are the fixed scaffold. */
|
|
48
|
+
const FEED_ROWS = PANEL_ROWS - 5;
|
|
49
|
+
|
|
39
50
|
function fmtDuration(ms: number): string {
|
|
40
51
|
const s = Math.max(0, Math.round(ms / 1000));
|
|
41
52
|
if (s < 60) return `${s}s`;
|
|
@@ -82,66 +93,62 @@ export class RunningView implements Component {
|
|
|
82
93
|
const s = this.host.state();
|
|
83
94
|
const theme = this.host.theme;
|
|
84
95
|
const w = Math.max(1, Math.floor(width));
|
|
85
|
-
const title = " Delegating ";
|
|
86
|
-
const border = "─".repeat(Math.max(0, w - title.length - 2));
|
|
87
|
-
const top = `╭─${title}${border.slice(0, Math.max(0, border.length))}─╮`.slice(0, w);
|
|
88
|
-
const bottom = `╰${"─".repeat(Math.max(0, w - 2))}╯`.slice(0, w);
|
|
89
96
|
const inner = Math.max(1, w - 4);
|
|
97
|
+
|
|
98
|
+
// Borders stay UNSTYLED so Pi's per-frame width/clear math is exact;
|
|
99
|
+
// color is applied to inner text only.
|
|
100
|
+
const title = " Delegating ";
|
|
101
|
+
const fill = Math.max(0, w - 2 - title.length - 2);
|
|
102
|
+
const top = truncateToWidth(`╭─${title}${"─".repeat(fill + 1)}╮`, w);
|
|
103
|
+
const bottom = truncateToWidth(`╰${"─".repeat(Math.max(0, w - 2))}╯`, w);
|
|
90
104
|
const pad = (text: string, color?: ThemeColor) => {
|
|
91
|
-
const
|
|
92
|
-
return
|
|
105
|
+
const body = color && theme?.fg ? theme.fg(color, truncateToWidth(text, inner)) : truncateToWidth(text, inner);
|
|
106
|
+
return `│ ${body} │`;
|
|
93
107
|
};
|
|
94
|
-
|
|
95
108
|
const fg = (kind: ThemeColor, text: string) => (theme?.fg ? theme.fg(kind, text) : text);
|
|
96
|
-
const lines: string[] = [top];
|
|
97
109
|
|
|
98
|
-
//
|
|
110
|
+
// Fixed scaffold rows — always exactly PANEL_ROWS - 2 inner rows.
|
|
99
111
|
const head = [
|
|
100
112
|
s.role,
|
|
101
113
|
s.model,
|
|
102
|
-
|
|
114
|
+
fmtDuration(s.elapsedMs),
|
|
103
115
|
...(s.turns !== undefined ? [`turn ${s.turns}`] : []),
|
|
104
116
|
...(s.tokens ? [`↑${fmtTokens(s.tokens.input)} ↓${fmtTokens(s.tokens.output)}`] : []),
|
|
105
117
|
]
|
|
106
118
|
.filter(Boolean)
|
|
107
119
|
.join(" · ");
|
|
108
|
-
lines.push(pad(head));
|
|
109
120
|
|
|
110
|
-
|
|
121
|
+
let progress = "running…";
|
|
111
122
|
if (s.hardMs && s.hardMs > 0) {
|
|
112
123
|
const frac = Math.min(1, s.elapsedMs / s.hardMs);
|
|
113
124
|
const barWidth = Math.max(4, Math.min(inner - 14, 24));
|
|
114
125
|
const filled = Math.round(frac * barWidth);
|
|
115
|
-
|
|
116
|
-
lines.push(pad(`${bar} ${Math.round(frac * 100)}% of ${fmtDuration(s.hardMs)} hard`));
|
|
126
|
+
progress = `${"█".repeat(filled)}${"░".repeat(Math.max(0, barWidth - filled))} ${Math.round(frac * 100)}% of ${fmtDuration(s.hardMs)} hard`;
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
lines.push(pad(fg("warning", `in flight: ${s.openTools.join(", ")}`)));
|
|
122
|
-
}
|
|
129
|
+
const openTools = s.openTools ?? [];
|
|
130
|
+
const inFlight = openTools.length > 0 ? `in flight: ${openTools.join(", ")}` : "";
|
|
123
131
|
|
|
124
|
-
// Feed: newest last
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
// Feed: newest last, right-aligned in a fixed block (blank-padded on top).
|
|
133
|
+
const feed = s.feedLines.slice(-FEED_ROWS);
|
|
134
|
+
const feedRows: string[] = [...Array<string>(Math.max(0, FEED_ROWS - feed.length)).fill(""), ...feed];
|
|
135
|
+
|
|
136
|
+
const footer = this.cancelArmed ? fg("error", "ESC again: CONFIRM cancel") : "esc/q cancel (press twice)";
|
|
137
|
+
|
|
138
|
+
// Assemble a fixed-height body: header, progress, in-flight, feed block, footer.
|
|
139
|
+
const body: Array<[string, ThemeColor?]> = [
|
|
140
|
+
[head],
|
|
141
|
+
[progress, "accent"],
|
|
142
|
+
[inFlight, inFlight ? "warning" : undefined],
|
|
143
|
+
...feedRows.map((l): [string, ThemeColor?] => [l, l ? "text" : undefined]),
|
|
144
|
+
[footer, this.cancelArmed ? "error" : "dim"],
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const lines: string[] = [top, ...body.map(([t, c]) => pad(t, c)), bottom];
|
|
132
148
|
|
|
133
|
-
//
|
|
134
|
-
lines.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
? fg("error", "ESC again: CONFIRM cancel")
|
|
138
|
-
: "esc/q cancel (press twice)",
|
|
139
|
-
this.cancelArmed ? "error" : "dim",
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
lines.push(bottom);
|
|
143
|
-
|
|
144
|
-
// Width safety: hard-clip rather than corrupt layout.
|
|
145
|
-
return lines.map((l) => (visibleWidth(l) > w ? truncateToWidth(l, w) : l));
|
|
149
|
+
// Belt-and-braces: hard-clip to the exact height and width.
|
|
150
|
+
const clipped = lines.slice(0, PANEL_ROWS);
|
|
151
|
+
while (clipped.length < PANEL_ROWS) clipped.splice(clipped.length - 1, 0, pad(""));
|
|
152
|
+
return clipped.map((l) => (visibleWidth(l) > w ? truncateToWidth(l, w) : l));
|
|
146
153
|
}
|
|
147
154
|
}
|