@mrclrchtr/supi-review 7.3.0 → 7.4.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/README.md +4 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/README.md +10 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-agent-runtime/package.json +7 -3
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/api.ts +37 -1
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/run.ts +151 -21
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/session/agent-run-registry-types.ts +95 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/session/agent-run-registry.ts +372 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/session/transcript-format.ts +184 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/session/transcript-store.ts +284 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/types.ts +22 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-command.ts +206 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-overlay-data.ts +78 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-overlay-render.ts +167 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-overlay.ts +400 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-list.ts +95 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-switcher.ts +29 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-viewer-input.ts +69 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-viewer-render.ts +246 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-viewer.ts +400 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-run-viewport.ts +112 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-steering-input.ts +50 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-transcript-context.ts +56 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-transcript-pane.ts +386 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-transcript-payload.ts +66 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/ui/agents-transcript.ts +380 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/index.js +25 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/legacy.js +22 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/connection.js +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.d.ts +1 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.js +7 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.d.ts +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineCompletion.d.ts +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.d.ts +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/package.json +4 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/package.json +5 -5
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/package.json +4 -4
- package/src/review.ts +5 -2
- package/src/tool/review_run/child-session.ts +29 -7
- package/src/tool/review_run/execute.ts +6 -1
- package/src/tool/review_run/execution.ts +6 -0
- package/src/tool/review_run/register.ts +3 -1
- package/src/tool/review_run/runner.ts +40 -0
- package/src/tool/review_run/workflow.ts +7 -1
- package/src/tui/review-command.ts +74 -3
- package/src/types.ts +5 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import type { KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
Input,
|
|
4
|
+
Key,
|
|
5
|
+
type KeyId,
|
|
6
|
+
matchesKey,
|
|
7
|
+
type SelectItem,
|
|
8
|
+
SelectList,
|
|
9
|
+
type TuiMouseEvent,
|
|
10
|
+
type TuiMouseEventResult,
|
|
11
|
+
truncateToWidth,
|
|
12
|
+
} from "@earendil-works/pi-tui";
|
|
13
|
+
import type { AgentsOverlayData, AgentsOverlayRun } from "./agents-overlay-data.ts";
|
|
14
|
+
import { orderedRuns, type RunSection, runListItem } from "./agents-run-list.ts";
|
|
15
|
+
import { nextRunSelection } from "./agents-run-switcher.ts";
|
|
16
|
+
import { handleRunViewerPageInput, handleTranscriptNavigation } from "./agents-run-viewer-input.ts";
|
|
17
|
+
import {
|
|
18
|
+
formatRunConversationHeading,
|
|
19
|
+
formatRunViewerStatus,
|
|
20
|
+
renderAgentsRunFooter,
|
|
21
|
+
renderAgentsRunHeader,
|
|
22
|
+
renderAgentsRunHints,
|
|
23
|
+
renderAgentsRunList,
|
|
24
|
+
} from "./agents-run-viewer-render.ts";
|
|
25
|
+
import { AgentsTranscriptPane } from "./agents-transcript-pane.ts";
|
|
26
|
+
|
|
27
|
+
type AgentsKeybindings = Pick<KeybindingsManager, "getKeys" | "matches">;
|
|
28
|
+
type KeybindingAction = Parameters<KeybindingsManager["matches"]>[1];
|
|
29
|
+
export type AgentsRunViewerAction = "handled" | "steer" | "stop" | "close";
|
|
30
|
+
|
|
31
|
+
type ViewerPage = "list" | "conversation" | "details";
|
|
32
|
+
|
|
33
|
+
/** Show a searchable run list and one full-width selected-run view. */
|
|
34
|
+
export class AgentsRunViewer {
|
|
35
|
+
#data: AgentsOverlayData;
|
|
36
|
+
#page: ViewerPage = "list";
|
|
37
|
+
#section: RunSection = "agents";
|
|
38
|
+
#selectedKey: string | undefined;
|
|
39
|
+
#selectedIndex = 0;
|
|
40
|
+
#visibleRuns: AgentsOverlayRun[] = [];
|
|
41
|
+
#search = new Input({ prompt: "Search: ", placeholder: "task, label, target, result" });
|
|
42
|
+
#listMaxVisible = 8;
|
|
43
|
+
#listPageSize = 1;
|
|
44
|
+
#selectList: SelectList;
|
|
45
|
+
#listTop = 0;
|
|
46
|
+
#listHeight = 0;
|
|
47
|
+
#bodyTop = 0;
|
|
48
|
+
#bodyHeight = 0;
|
|
49
|
+
#focused = false;
|
|
50
|
+
readonly #transcript: AgentsTranscriptPane;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
data: AgentsOverlayData,
|
|
54
|
+
private readonly theme: Theme,
|
|
55
|
+
private readonly onChange: () => void,
|
|
56
|
+
private readonly keybindings?: AgentsKeybindings,
|
|
57
|
+
) {
|
|
58
|
+
this.#data = data;
|
|
59
|
+
this.#transcript = new AgentsTranscriptPane(theme, onChange);
|
|
60
|
+
this.#selectList = this.#createSelectList([]);
|
|
61
|
+
this.#refreshList();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get isList(): boolean {
|
|
65
|
+
return this.#page === "list";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get selectedRun(): AgentsOverlayRun | undefined {
|
|
69
|
+
return this.#selectedKey
|
|
70
|
+
? this.#data.runs.find((run) => run.key === this.#selectedKey)
|
|
71
|
+
: this.#visibleRuns[this.#selectedIndex];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Show only the selected caller-facing section. */
|
|
75
|
+
setSection(section: RunSection): void {
|
|
76
|
+
if (this.#section === section) return;
|
|
77
|
+
this.#section = section;
|
|
78
|
+
this.#refreshList();
|
|
79
|
+
this.onChange();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
set focused(value: boolean) {
|
|
83
|
+
this.#focused = value;
|
|
84
|
+
this.#search.focused = value && this.#page === "list";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Rebuild elapsed descriptions without changing the current selection. */
|
|
88
|
+
refreshElapsed(): void {
|
|
89
|
+
const pinnedKey = this.#page === "list" ? undefined : this.selectedRun?.key;
|
|
90
|
+
this.#refreshList(pinnedKey);
|
|
91
|
+
this.onChange();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Replace live data and keep an opened run selected until list return or removal. */
|
|
95
|
+
updateData(data: AgentsOverlayData): void {
|
|
96
|
+
const selectedKey = this.selectedRun?.key;
|
|
97
|
+
this.#data = data;
|
|
98
|
+
const pinnedKey =
|
|
99
|
+
this.#page !== "list" && selectedKey && data.runs.some((run) => run.key === selectedKey)
|
|
100
|
+
? selectedKey
|
|
101
|
+
: undefined;
|
|
102
|
+
this.#refreshList(pinnedKey);
|
|
103
|
+
if (this.#page !== "list") {
|
|
104
|
+
if (this.selectedRun?.key !== selectedKey) this.#transcript.select(this.selectedRun);
|
|
105
|
+
else this.#transcript.update(this.selectedRun);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
render(options: {
|
|
110
|
+
readonly width: number;
|
|
111
|
+
readonly height: number;
|
|
112
|
+
readonly header: string;
|
|
113
|
+
readonly tabs: string;
|
|
114
|
+
readonly notice?: string;
|
|
115
|
+
readonly steeringLines: readonly string[];
|
|
116
|
+
readonly steeringActive: boolean;
|
|
117
|
+
readonly stopConfirmation: boolean;
|
|
118
|
+
}): string[] {
|
|
119
|
+
const { width, height, header, tabs, notice, steeringLines, steeringActive, stopConfirmation } =
|
|
120
|
+
options;
|
|
121
|
+
if (steeringActive && height <= 4) {
|
|
122
|
+
const content = [
|
|
123
|
+
...steeringLines,
|
|
124
|
+
...(notice ? [this.#line(this.theme.fg("warning", notice), width)] : []),
|
|
125
|
+
].slice(-height);
|
|
126
|
+
while (content.length < height) content.unshift("");
|
|
127
|
+
return content.map((line) => truncateToWidth(line, width));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const headerLines = renderAgentsRunHeader({
|
|
131
|
+
theme: this.theme,
|
|
132
|
+
header,
|
|
133
|
+
tabs,
|
|
134
|
+
width,
|
|
135
|
+
height,
|
|
136
|
+
steeringActive,
|
|
137
|
+
});
|
|
138
|
+
const selectedRun = this.selectedRun;
|
|
139
|
+
const runHeading = formatRunConversationHeading(
|
|
140
|
+
selectedRun,
|
|
141
|
+
this.#visibleRuns,
|
|
142
|
+
this.#section,
|
|
143
|
+
this.#transcript.isIncomplete,
|
|
144
|
+
);
|
|
145
|
+
const pageHeading = this.#page === "list" ? [] : [this.#line(runHeading.text, width)];
|
|
146
|
+
const footerContent = renderAgentsRunFooter({
|
|
147
|
+
theme: this.theme,
|
|
148
|
+
hints: renderAgentsRunHints({
|
|
149
|
+
stopConfirmation,
|
|
150
|
+
page: this.#page,
|
|
151
|
+
height,
|
|
152
|
+
run: selectedRun,
|
|
153
|
+
theme: this.theme,
|
|
154
|
+
keybindings: this.keybindings,
|
|
155
|
+
canSwitchRuns: runHeading.canSwitchRuns,
|
|
156
|
+
}),
|
|
157
|
+
notice,
|
|
158
|
+
status:
|
|
159
|
+
this.#page === "list"
|
|
160
|
+
? undefined
|
|
161
|
+
: formatRunViewerStatus({
|
|
162
|
+
run: this.selectedRun,
|
|
163
|
+
transcriptStatus: this.#transcript.status,
|
|
164
|
+
transcriptIncomplete: this.#transcript.isIncomplete,
|
|
165
|
+
}),
|
|
166
|
+
steeringLines,
|
|
167
|
+
steeringActive,
|
|
168
|
+
width,
|
|
169
|
+
});
|
|
170
|
+
this.#bodyTop = headerLines.length + pageHeading.length;
|
|
171
|
+
const footerRows = Math.min(footerContent.length, Math.max(0, height - this.#bodyTop));
|
|
172
|
+
// The tail keeps status and notice rows before optional hints when height is low.
|
|
173
|
+
const footer = footerContent.slice(footerContent.length - footerRows);
|
|
174
|
+
this.#bodyHeight = Math.max(0, height - this.#bodyTop - footer.length);
|
|
175
|
+
|
|
176
|
+
if (this.#page !== "list") {
|
|
177
|
+
this.#transcript.setBounds({ top: this.#bodyTop, height: this.#bodyHeight, left: 0, width });
|
|
178
|
+
}
|
|
179
|
+
const body =
|
|
180
|
+
this.#page === "list"
|
|
181
|
+
? this.#renderList(width, this.#bodyHeight)
|
|
182
|
+
: this.#transcript.render(this.selectedRun, width, this.#bodyHeight);
|
|
183
|
+
const lines = [
|
|
184
|
+
...headerLines,
|
|
185
|
+
...pageHeading,
|
|
186
|
+
...body.slice(0, this.#bodyHeight),
|
|
187
|
+
...footer,
|
|
188
|
+
].slice(0, height);
|
|
189
|
+
while (lines.length < height) lines.push("");
|
|
190
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
handleInput(data: string, controlsEnabled: boolean): AgentsRunViewerAction | undefined {
|
|
194
|
+
if (this.#page === "list") return this.#handleListInput(data);
|
|
195
|
+
if (
|
|
196
|
+
handleRunViewerPageInput(data, {
|
|
197
|
+
isCancel: (input) => this.#isCancel(input),
|
|
198
|
+
returnToList: () => {
|
|
199
|
+
this.#page = "list";
|
|
200
|
+
this.#transcript.setDetails(false);
|
|
201
|
+
this.#search.focused = this.#focused;
|
|
202
|
+
this.#refreshList();
|
|
203
|
+
},
|
|
204
|
+
toggleView: () => {
|
|
205
|
+
this.#page = this.#page === "conversation" ? "details" : "conversation";
|
|
206
|
+
this.#transcript.setDetails(this.#page === "details");
|
|
207
|
+
},
|
|
208
|
+
switchRun: (direction) => this.#moveSelection(direction),
|
|
209
|
+
})
|
|
210
|
+
) {
|
|
211
|
+
return "handled";
|
|
212
|
+
}
|
|
213
|
+
if (this.#handleTranscriptNavigation(data)) return "handled";
|
|
214
|
+
if (this.#matches(data, "app.tools.expand", Key.ctrl("o"))) {
|
|
215
|
+
this.#transcript.toggleToolDetails();
|
|
216
|
+
return "handled";
|
|
217
|
+
}
|
|
218
|
+
if (this.#matches(data, "app.thinking.toggle", Key.ctrl("t"))) {
|
|
219
|
+
this.#transcript.toggleThinking();
|
|
220
|
+
return "handled";
|
|
221
|
+
}
|
|
222
|
+
const run = this.selectedRun;
|
|
223
|
+
if (!controlsEnabled || !run?.active) return undefined;
|
|
224
|
+
if (data === "s" && run.steeringAvailable) return "steer";
|
|
225
|
+
if (data === "x" && (run.status === "starting" || run.status === "running")) return "stop";
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
230
|
+
if (this.#page !== "list") {
|
|
231
|
+
if (
|
|
232
|
+
event.type === "wheel" &&
|
|
233
|
+
event.y >= this.#bodyTop &&
|
|
234
|
+
event.y < this.#bodyTop + this.#bodyHeight
|
|
235
|
+
) {
|
|
236
|
+
this.#transcript.scrollBy(event.wheelDelta ?? 0);
|
|
237
|
+
this.onChange();
|
|
238
|
+
return { handled: true };
|
|
239
|
+
}
|
|
240
|
+
return this.#transcript.handleMouse(event);
|
|
241
|
+
}
|
|
242
|
+
if (event.y < this.#listTop || event.y >= this.#listTop + this.#listHeight) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
const result = this.#selectList.handleMouse({ ...event, y: event.y - this.#listTop });
|
|
246
|
+
if (result?.handled) {
|
|
247
|
+
const selected = this.#selectList.getSelectedItem();
|
|
248
|
+
if (selected) this.#selectRun(selected.value);
|
|
249
|
+
this.onChange();
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
invalidate(): void {
|
|
255
|
+
this.#search.invalidate();
|
|
256
|
+
this.#selectList.invalidate();
|
|
257
|
+
this.#transcript.invalidate();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
dispose(): void {
|
|
261
|
+
this.#transcript.dispose();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
#handleListInput(data: string): AgentsRunViewerAction {
|
|
265
|
+
if (this.#isCancel(data)) return "close";
|
|
266
|
+
if (this.#matches(data, "tui.select.confirm", Key.enter)) {
|
|
267
|
+
this.#openSelectedRun();
|
|
268
|
+
return "handled";
|
|
269
|
+
}
|
|
270
|
+
if (this.#matches(data, "tui.select.up", Key.up)) {
|
|
271
|
+
this.#moveSelection(-1);
|
|
272
|
+
return "handled";
|
|
273
|
+
}
|
|
274
|
+
if (this.#matches(data, "tui.select.down", Key.down)) {
|
|
275
|
+
this.#moveSelection(1);
|
|
276
|
+
return "handled";
|
|
277
|
+
}
|
|
278
|
+
if (this.#matches(data, "tui.select.pageUp", Key.pageUp)) {
|
|
279
|
+
this.#moveSelection(-Math.max(1, this.#listPageSize), false);
|
|
280
|
+
return "handled";
|
|
281
|
+
}
|
|
282
|
+
if (this.#matches(data, "tui.select.pageDown", Key.pageDown)) {
|
|
283
|
+
this.#moveSelection(Math.max(1, this.#listPageSize), false);
|
|
284
|
+
return "handled";
|
|
285
|
+
}
|
|
286
|
+
this.#search.handleInput(data);
|
|
287
|
+
this.#refreshList();
|
|
288
|
+
this.onChange();
|
|
289
|
+
return "handled";
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
#renderList(width: number, height: number): string[] {
|
|
293
|
+
const rendered = renderAgentsRunList({
|
|
294
|
+
theme: this.theme,
|
|
295
|
+
search: this.#search,
|
|
296
|
+
getSelectList: (maxVisible) => {
|
|
297
|
+
if (maxVisible !== this.#listMaxVisible) {
|
|
298
|
+
this.#listMaxVisible = maxVisible;
|
|
299
|
+
this.#selectList = this.#createSelectList(
|
|
300
|
+
this.#visibleRuns.map((run) => runListItem(run)),
|
|
301
|
+
maxVisible,
|
|
302
|
+
);
|
|
303
|
+
if (this.#visibleRuns.length > 0) this.#selectList.setSelectedIndex(this.#selectedIndex);
|
|
304
|
+
}
|
|
305
|
+
return this.#selectList;
|
|
306
|
+
},
|
|
307
|
+
selectedRun: this.selectedRun,
|
|
308
|
+
itemCount: this.#visibleRuns.length,
|
|
309
|
+
emptyMessage:
|
|
310
|
+
this.#section === "agents" ? "No Agent Runs are registered." : "No Reviews are registered.",
|
|
311
|
+
width,
|
|
312
|
+
height,
|
|
313
|
+
bodyTop: this.#bodyTop,
|
|
314
|
+
});
|
|
315
|
+
this.#listPageSize = rendered.visibleItemCount;
|
|
316
|
+
this.#listTop = rendered.listTop;
|
|
317
|
+
this.#listHeight = rendered.listHeight;
|
|
318
|
+
return rendered.lines;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#createSelectList(items: SelectItem[], maxVisible = this.#listMaxVisible): SelectList {
|
|
322
|
+
const list = new SelectList(items, maxVisible, {
|
|
323
|
+
selectedPrefix: (text) => this.theme.fg("accent", text),
|
|
324
|
+
selectedText: (text) => this.theme.fg("accent", text),
|
|
325
|
+
description: (text) => this.theme.fg("dim", text),
|
|
326
|
+
scrollInfo: (text) => this.theme.fg("dim", text),
|
|
327
|
+
noMatch: (text) => this.theme.fg("warning", text),
|
|
328
|
+
});
|
|
329
|
+
list.onSelectionChange = (item) => this.#selectRun(item.value);
|
|
330
|
+
list.onSelect = (item) => {
|
|
331
|
+
this.#selectRun(item.value);
|
|
332
|
+
this.#openSelectedRun();
|
|
333
|
+
};
|
|
334
|
+
return list;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
#refreshList(pinnedKey?: string): void {
|
|
338
|
+
const current = pinnedKey ?? this.selectedRun?.key ?? this.#selectedKey;
|
|
339
|
+
this.#visibleRuns = orderedRuns(this.#data.runs, this.#section, this.#search.getValue());
|
|
340
|
+
const currentIndex = current ? this.#visibleRuns.findIndex((run) => run.key === current) : -1;
|
|
341
|
+
this.#selectedIndex = currentIndex >= 0 ? currentIndex : pinnedKey ? -1 : 0;
|
|
342
|
+
this.#selectedKey = pinnedKey ?? this.#visibleRuns[this.#selectedIndex]?.key;
|
|
343
|
+
this.#selectList = this.#createSelectList(this.#visibleRuns.map((run) => runListItem(run)));
|
|
344
|
+
if (this.#visibleRuns.length > 0) this.#selectList.setSelectedIndex(this.#selectedIndex);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
#moveSelection(delta: number, wrap = true): void {
|
|
348
|
+
const next = nextRunSelection(this.#visibleRuns, this.#selectedIndex, delta, wrap);
|
|
349
|
+
if (!next) return;
|
|
350
|
+
this.#selectedIndex = next.index;
|
|
351
|
+
this.#selectedKey = next.run.key;
|
|
352
|
+
this.#selectList.setSelectedIndex(next.index);
|
|
353
|
+
if (this.#page !== "list") this.#transcript.select(next.run);
|
|
354
|
+
this.onChange();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
#selectRun(runKey: string): void {
|
|
358
|
+
const index = this.#visibleRuns.findIndex((run) => run.key === runKey);
|
|
359
|
+
if (index < 0) return;
|
|
360
|
+
this.#selectedIndex = index;
|
|
361
|
+
this.#selectedKey = runKey;
|
|
362
|
+
if (this.#page !== "list") this.#transcript.select(this.selectedRun);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
#handleTranscriptNavigation(data: string): boolean {
|
|
366
|
+
return handleTranscriptNavigation(
|
|
367
|
+
data,
|
|
368
|
+
(input, action, fallback) => this.#matches(input, action, fallback),
|
|
369
|
+
(lines) => this.#transcript.scrollBy(lines),
|
|
370
|
+
(action) => this.#transcript.navigate(action),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
#openSelectedRun(): void {
|
|
375
|
+
const run = this.selectedRun;
|
|
376
|
+
if (!run) return;
|
|
377
|
+
this.#page = "conversation";
|
|
378
|
+
this.#search.focused = false;
|
|
379
|
+
this.#transcript.setDetails(false);
|
|
380
|
+
this.#transcript.select(run);
|
|
381
|
+
this.onChange();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
#isCancel(data: string): boolean {
|
|
385
|
+
return (
|
|
386
|
+
this.#matches(data, "app.interrupt", Key.escape) ||
|
|
387
|
+
this.#matches(data, "tui.select.cancel", Key.ctrl("c"))
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
#matches(data: string, action: KeybindingAction, fallback: KeyId): boolean {
|
|
392
|
+
return typeof this.keybindings?.matches === "function"
|
|
393
|
+
? this.keybindings.matches(data, action)
|
|
394
|
+
: matchesKey(data, fallback);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
#line(text: string, width: number): string {
|
|
398
|
+
return truncateToWidth(` ${text}`, width);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** One ordered section of the rendered Agent Run details. */
|
|
2
|
+
export interface AgentRunBlock {
|
|
3
|
+
/** Negative keys identify metadata; conversation keys include the retention offset. */
|
|
4
|
+
readonly key: number;
|
|
5
|
+
readonly lines: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Navigation = "page-up" | "page-down" | "start" | "end" | "toggle";
|
|
9
|
+
|
|
10
|
+
interface Row {
|
|
11
|
+
key: number;
|
|
12
|
+
offset: number;
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Follow new output, or keep a retained entry and wrapped-line offset in view. */
|
|
17
|
+
export class AgentRunViewport {
|
|
18
|
+
#following = true;
|
|
19
|
+
#anchor: Pick<Row, "key" | "offset"> | undefined;
|
|
20
|
+
#rows: Row[] = [];
|
|
21
|
+
#height = 1;
|
|
22
|
+
#start = 0;
|
|
23
|
+
|
|
24
|
+
/** Show whether new output moves the viewport, and how much output is below it. */
|
|
25
|
+
get status(): string {
|
|
26
|
+
if (this.#following) return "LIVE · auto-scroll on";
|
|
27
|
+
const below = Math.max(0, this.#rows.length - this.#start - this.#height);
|
|
28
|
+
return `PAUSED · ${below} lines below`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Current first visible line, used to map mouse events to transcript components. */
|
|
32
|
+
get scrollOffset(): number {
|
|
33
|
+
return this.#start;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Fit wrapped rows to the available height without moving a paused reading position. */
|
|
37
|
+
render(blocks: readonly AgentRunBlock[], height: number): string[] {
|
|
38
|
+
this.#height = Math.max(1, height);
|
|
39
|
+
this.#rows = blocks.flatMap((block) =>
|
|
40
|
+
block.lines.map((text, offset) => ({ key: block.key, offset, text })),
|
|
41
|
+
);
|
|
42
|
+
const maximum = this.#maximumStart();
|
|
43
|
+
this.#start = this.#following ? maximum : Math.min(maximum, this.#anchorStart());
|
|
44
|
+
this.#rememberAnchor();
|
|
45
|
+
return this.#rows.slice(this.#start, this.#start + this.#height).map((row) => row.text);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Scroll by logical lines. Scrolling up pauses following; reaching the end resumes it. */
|
|
49
|
+
scrollBy(lines: number): void {
|
|
50
|
+
const maximum = this.#maximumStart();
|
|
51
|
+
this.#start = Math.max(0, Math.min(maximum, this.#start + Math.trunc(lines)));
|
|
52
|
+
this.#following = lines > 0 && this.#start === maximum;
|
|
53
|
+
this.#rememberAnchor();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Page through wrapped lines. Reaching the end with Page Down restores live following. */
|
|
57
|
+
navigate(action: Navigation): void {
|
|
58
|
+
const maximum = this.#maximumStart();
|
|
59
|
+
switch (action) {
|
|
60
|
+
case "page-up":
|
|
61
|
+
this.#following = false;
|
|
62
|
+
this.#start = Math.max(0, this.#start - this.#height);
|
|
63
|
+
break;
|
|
64
|
+
case "page-down":
|
|
65
|
+
this.#start = Math.min(maximum, this.#start + this.#height);
|
|
66
|
+
this.#following = this.#start === maximum;
|
|
67
|
+
break;
|
|
68
|
+
case "start":
|
|
69
|
+
this.#following = false;
|
|
70
|
+
this.#start = 0;
|
|
71
|
+
break;
|
|
72
|
+
case "end":
|
|
73
|
+
this.#following = true;
|
|
74
|
+
this.#start = maximum;
|
|
75
|
+
break;
|
|
76
|
+
case "toggle":
|
|
77
|
+
this.#following = !this.#following;
|
|
78
|
+
if (this.#following) this.#start = maximum;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
this.#rememberAnchor();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Follow the latest output when a different Agent Run is selected. */
|
|
85
|
+
reset(): void {
|
|
86
|
+
this.#following = true;
|
|
87
|
+
this.#anchor = undefined;
|
|
88
|
+
this.#rows = [];
|
|
89
|
+
this.#start = 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#maximumStart(): number {
|
|
93
|
+
return Math.max(0, this.#rows.length - this.#height);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#rememberAnchor(): void {
|
|
97
|
+
const row = this.#rows[this.#start];
|
|
98
|
+
this.#anchor = row ? { key: row.key, offset: row.offset } : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#anchorStart(): number {
|
|
102
|
+
const anchor = this.#anchor;
|
|
103
|
+
if (!anchor) return 0;
|
|
104
|
+
const start = this.#rows.findIndex((row) => row.key >= anchor.key);
|
|
105
|
+
if (start < 0) return this.#maximumStart();
|
|
106
|
+
// If retention removed the entry, show the oldest entry still available.
|
|
107
|
+
if (this.#rows[start]?.key !== anchor.key) return start;
|
|
108
|
+
let end = start;
|
|
109
|
+
while (this.#rows[end + 1]?.key === anchor.key) end++;
|
|
110
|
+
return Math.min(end, start + anchor.offset);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type Focusable, Input } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
/** Callbacks for the embedded Agent Run steering input. */
|
|
5
|
+
export interface AgentsSteeringInputCallbacks {
|
|
6
|
+
readonly onSubmit: (message: string) => void;
|
|
7
|
+
readonly onEmpty: () => void;
|
|
8
|
+
readonly onCancel: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** TUI input for one selected Agent Run steering request. */
|
|
12
|
+
export class AgentsSteeringInput implements Focusable {
|
|
13
|
+
readonly taskId: string;
|
|
14
|
+
readonly #input: Input;
|
|
15
|
+
|
|
16
|
+
constructor(taskId: string, theme: Theme, callbacks: AgentsSteeringInputCallbacks) {
|
|
17
|
+
this.taskId = taskId;
|
|
18
|
+
this.#input = new Input({
|
|
19
|
+
placeholder: "Steering message",
|
|
20
|
+
placeholderStyle: (text) => theme.fg("dim", text),
|
|
21
|
+
});
|
|
22
|
+
this.#input.onSubmit = (value) => {
|
|
23
|
+
const message = value.trim();
|
|
24
|
+
if (message) callbacks.onSubmit(message);
|
|
25
|
+
else callbacks.onEmpty();
|
|
26
|
+
};
|
|
27
|
+
this.#input.onEscape = callbacks.onCancel;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether PI should show the hardware cursor in this input. */
|
|
31
|
+
get focused(): boolean {
|
|
32
|
+
return this.#input.focused;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set focused(value: boolean) {
|
|
36
|
+
this.#input.focused = value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
handleInput(data: string): void {
|
|
40
|
+
this.#input.handleInput(data);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
render(width: number): string[] {
|
|
44
|
+
return [`Steer ${this.taskId}`, ...this.#input.render(Math.max(1, width))];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
invalidate(): void {
|
|
48
|
+
this.#input.invalidate();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, Text } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { AgentRunTranscriptDocument } from "../session/transcript-store.ts";
|
|
4
|
+
|
|
5
|
+
/** Render Agent Run metadata for the transcript. */
|
|
6
|
+
export function renderTranscriptMetadata(
|
|
7
|
+
document: AgentRunTranscriptDocument,
|
|
8
|
+
theme: Theme,
|
|
9
|
+
): Container {
|
|
10
|
+
const { metadata } = document;
|
|
11
|
+
const container = new Container();
|
|
12
|
+
const statusColor = document.status === "complete" ? "success" : "warning";
|
|
13
|
+
container.addChild(
|
|
14
|
+
new Text(
|
|
15
|
+
theme.fg("accent", theme.bold(`${metadata.taskId} · ${metadata.kind}: ${metadata.label}`)) +
|
|
16
|
+
theme.fg(statusColor, ` · capture ${document.status} · ${document.messageCount} messages`),
|
|
17
|
+
0,
|
|
18
|
+
0,
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
const fields = [
|
|
22
|
+
`Batch: ${metadata.batchId}`,
|
|
23
|
+
`Model: ${metadata.modelId} · thinking ${metadata.thinkingLevel}`,
|
|
24
|
+
`Working directory: ${metadata.cwd}`,
|
|
25
|
+
`Tools: ${metadata.tools.join(", ") || "none"}`,
|
|
26
|
+
`Started: ${new Date(metadata.startedAt).toLocaleString()}`,
|
|
27
|
+
...(metadata.taskDescription ? [`Task: ${metadata.taskDescription}`] : []),
|
|
28
|
+
...(metadata.sharedContext ? [`Shared context: ${metadata.sharedContext}`] : []),
|
|
29
|
+
];
|
|
30
|
+
for (const field of fields) container.addChild(new Text(field, 0, 0));
|
|
31
|
+
if (document.status === "incomplete") {
|
|
32
|
+
container.addChild(
|
|
33
|
+
new Text(
|
|
34
|
+
theme.fg(
|
|
35
|
+
"warning",
|
|
36
|
+
"Transcript capture is incomplete. The Agent Run continued after a storage failure.",
|
|
37
|
+
),
|
|
38
|
+
0,
|
|
39
|
+
0,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return container;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Render each effective system prompt in the transcript. */
|
|
47
|
+
export function renderSystemPrompt(
|
|
48
|
+
prompt: { readonly occurredAt: number; readonly text: string },
|
|
49
|
+
theme: Theme,
|
|
50
|
+
): Container {
|
|
51
|
+
const container = new Container();
|
|
52
|
+
const date = new Date(prompt.occurredAt).toLocaleTimeString();
|
|
53
|
+
container.addChild(new Text(theme.fg("accent", `Effective system prompt · ${date}`), 0, 0));
|
|
54
|
+
container.addChild(new Text(prompt.text || "(empty system prompt)", 1, 0));
|
|
55
|
+
return container;
|
|
56
|
+
}
|