@timmyjl12/pi-agy-bridge 0.1.4 → 0.2.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/ARCHITECTURE.md +11 -1
- package/README.md +53 -8
- package/UPGRADING.md +133 -111
- package/compat/baselines/agy-1.5.12.json +259 -0
- package/compat/baselines/agy-1.5.14.json +260 -0
- package/compat/matrix.json +1 -1
- package/compat/probe.ts +71 -2
- package/compat/sdk-canary/canary.py +9 -3
- package/package.json +4 -2
- package/src/account-manager.ts +397 -0
- package/src/accounts.ts +349 -0
- package/src/acp/connection.ts +1 -1
- package/src/config.ts +6 -0
- package/src/doctor.ts +13 -3
- package/src/index.ts +199 -25
- package/src/model-catalog.ts +19 -6
- package/src/provider.ts +30 -8
- package/src/runtime.ts +133 -6
- package/src/session-pool.ts +88 -6
- package/src/stream.ts +41 -8
- package/src/ui/menu.ts +440 -0
- package/src/ui/panel.ts +376 -0
package/src/ui/panel.ts
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
// Full-screen settings/picker panel for /agy-bridge, modelled on pi-advisor's settings overlay so the extension set
|
|
2
|
+
// shares one keyboard model: ↑↓ move · ←→ pane · Tab section · / search · Enter select · Esc back/close.
|
|
3
|
+
// Two panes (sections | items) at ≥70 columns, one pane below that, a compact card below 40×16.
|
|
4
|
+
|
|
5
|
+
import { stripVTControlCharacters } from "node:util";
|
|
6
|
+
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { Input, matchesKey, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
8
|
+
|
|
9
|
+
export type ItemTone = "normal" | "ok" | "warn" | "error" | "muted" | "caution";
|
|
10
|
+
|
|
11
|
+
export interface PanelItem {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
description: string;
|
|
15
|
+
/** Right-aligned value (state, count, provider). */
|
|
16
|
+
value?: string;
|
|
17
|
+
group: string;
|
|
18
|
+
/** Extra words matched by search. */
|
|
19
|
+
search?: string;
|
|
20
|
+
tone?: ItemTone;
|
|
21
|
+
/** Shown as a non-selectable heading line inside the item pane. */
|
|
22
|
+
heading?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PanelView {
|
|
26
|
+
title: string;
|
|
27
|
+
subtitle: string;
|
|
28
|
+
groups: readonly string[];
|
|
29
|
+
items: readonly PanelItem[];
|
|
30
|
+
activeGroup?: string;
|
|
31
|
+
currentId?: string;
|
|
32
|
+
/** Extra detail lines for the highlighted item (shown above the footer). */
|
|
33
|
+
detail?: (item: PanelItem) => string[];
|
|
34
|
+
/** Override of the key hint line. */
|
|
35
|
+
footer?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Labels may come from config or agy output; never let them drive the terminal. */
|
|
39
|
+
export function clean(text: string): string {
|
|
40
|
+
return stripVTControlCharacters(text)
|
|
41
|
+
.replace(/[\x00-\x1f\x7f-\x9f]/g, " ")
|
|
42
|
+
.replace(/\s+/g, " ")
|
|
43
|
+
.trim();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fit(text: string, width: number): string {
|
|
47
|
+
if (width <= 0) return "";
|
|
48
|
+
const clipped = truncateToWidth(text, width, "…");
|
|
49
|
+
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type PanelTheme = Pick<Theme, "fg" | "bg" | "bold">;
|
|
53
|
+
|
|
54
|
+
const DETAIL_ROWS = 3;
|
|
55
|
+
|
|
56
|
+
export class SettingsPanel implements Component {
|
|
57
|
+
focused = true;
|
|
58
|
+
private readonly search = new Input();
|
|
59
|
+
private query = "";
|
|
60
|
+
private groupIndex: number;
|
|
61
|
+
private itemIndex = 0;
|
|
62
|
+
private groupScroll = 0;
|
|
63
|
+
private itemScroll = 0;
|
|
64
|
+
private pane: "groups" | "items" = "items";
|
|
65
|
+
private searchMode = false;
|
|
66
|
+
private height = 24;
|
|
67
|
+
private width = 80;
|
|
68
|
+
private readonly view: PanelView;
|
|
69
|
+
private readonly theme: PanelTheme;
|
|
70
|
+
private readonly requestRender: () => void;
|
|
71
|
+
private readonly done: (id: string | null) => void;
|
|
72
|
+
|
|
73
|
+
constructor(view: PanelView, theme: PanelTheme, requestRender: () => void, done: (id: string | null) => void) {
|
|
74
|
+
this.view = view;
|
|
75
|
+
this.theme = theme;
|
|
76
|
+
this.requestRender = requestRender;
|
|
77
|
+
this.done = done;
|
|
78
|
+
this.groupIndex = Math.max(0, view.groups.indexOf(view.activeGroup ?? ""));
|
|
79
|
+
const initial = view.items.filter((item) => item.group === view.groups[this.groupIndex]);
|
|
80
|
+
this.itemIndex = Math.max(0, initial.findIndex((item) => item.id === view.currentId));
|
|
81
|
+
this.skipHeading(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setTerminalSize(width: number, height: number): void {
|
|
85
|
+
if (width === this.width && height === this.height) return;
|
|
86
|
+
this.width = width;
|
|
87
|
+
this.height = height;
|
|
88
|
+
this.requestRender();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private get matches(): PanelItem[] {
|
|
92
|
+
const query = this.query.trim().toLowerCase();
|
|
93
|
+
if (!query) return this.view.items.filter((item) => item.group === this.view.groups[this.groupIndex]);
|
|
94
|
+
const seen = new Set<string>();
|
|
95
|
+
return this.view.items.filter((item) => {
|
|
96
|
+
if (item.heading) return false;
|
|
97
|
+
const fields = [item.label, item.description, item.value ?? "", item.search ?? "", item.group];
|
|
98
|
+
if (!fields.some((field) => field.toLowerCase().includes(query))) return false;
|
|
99
|
+
if (seen.has(item.id)) return false;
|
|
100
|
+
seen.add(item.id);
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get selected(): PanelItem | undefined {
|
|
106
|
+
const item = this.matches[this.itemIndex];
|
|
107
|
+
return item?.heading ? undefined : item;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private get bodyHeight(): number {
|
|
111
|
+
return Math.max(2, this.height - 11 - DETAIL_ROWS);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Never rest on a heading row: step past it in the direction of travel. */
|
|
115
|
+
private skipHeading(direction: 1 | -1): void {
|
|
116
|
+
const items = this.matches;
|
|
117
|
+
if (items.length === 0 || items.every((item) => item.heading)) return;
|
|
118
|
+
let guard = items.length;
|
|
119
|
+
while (items[this.itemIndex]?.heading && guard-- > 0) {
|
|
120
|
+
this.itemIndex = (this.itemIndex + direction + items.length) % items.length;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private move(delta: number, wrap = true): void {
|
|
125
|
+
if (this.pane === "groups" && this.width >= 70) {
|
|
126
|
+
const size = this.view.groups.length;
|
|
127
|
+
if (size === 0) return;
|
|
128
|
+
this.groupIndex = wrap
|
|
129
|
+
? (((this.groupIndex + delta) % size) + size) % size
|
|
130
|
+
: Math.max(0, Math.min(size - 1, this.groupIndex + delta));
|
|
131
|
+
this.itemIndex = 0;
|
|
132
|
+
this.itemScroll = 0;
|
|
133
|
+
this.clearQuery();
|
|
134
|
+
this.skipHeading(1);
|
|
135
|
+
} else {
|
|
136
|
+
const size = this.matches.length;
|
|
137
|
+
if (size === 0) return;
|
|
138
|
+
this.itemIndex = wrap
|
|
139
|
+
? (((this.itemIndex + delta) % size) + size) % size
|
|
140
|
+
: Math.max(0, Math.min(size - 1, this.itemIndex + delta));
|
|
141
|
+
this.skipHeading(delta < 0 ? -1 : 1);
|
|
142
|
+
}
|
|
143
|
+
this.requestRender();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private clearQuery(): void {
|
|
147
|
+
this.query = "";
|
|
148
|
+
this.search.setValue("");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private changeGroup(delta: number): void {
|
|
152
|
+
const count = this.view.groups.length;
|
|
153
|
+
if (count === 0) return;
|
|
154
|
+
this.groupIndex = (this.groupIndex + delta + count) % count;
|
|
155
|
+
this.itemIndex = 0;
|
|
156
|
+
this.itemScroll = 0;
|
|
157
|
+
this.groupScroll = Math.min(this.groupScroll, this.groupIndex);
|
|
158
|
+
this.clearQuery();
|
|
159
|
+
this.skipHeading(1);
|
|
160
|
+
this.requestRender();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
handleInput(data: string): void {
|
|
164
|
+
if (matchesKey(data, "ctrl+c")) {
|
|
165
|
+
this.done(null);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (matchesKey(data, "escape") && this.searchMode) {
|
|
169
|
+
this.searchMode = false;
|
|
170
|
+
this.requestRender();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (matchesKey(data, "escape")) {
|
|
174
|
+
if (this.query) {
|
|
175
|
+
this.clearQuery();
|
|
176
|
+
this.itemIndex = 0;
|
|
177
|
+
this.itemScroll = 0;
|
|
178
|
+
this.skipHeading(1);
|
|
179
|
+
} else if (this.pane === "items" && this.width >= 70 && this.view.groups.length > 1) this.pane = "groups";
|
|
180
|
+
else {
|
|
181
|
+
this.done(null);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
} else if (matchesKey(data, "tab")) this.changeGroup(1);
|
|
185
|
+
else if (matchesKey(data, "shift+tab")) this.changeGroup(-1);
|
|
186
|
+
else if (matchesKey(data, "up")) this.move(-1);
|
|
187
|
+
else if (matchesKey(data, "down")) this.move(1);
|
|
188
|
+
else if (matchesKey(data, "pageUp")) this.move(-Math.max(1, this.bodyHeight - 1), false);
|
|
189
|
+
else if (matchesKey(data, "pageDown")) this.move(Math.max(1, this.bodyHeight - 1), false);
|
|
190
|
+
else if (matchesKey(data, "home")) this.move(-Number.MAX_SAFE_INTEGER, false);
|
|
191
|
+
else if (matchesKey(data, "end")) this.move(Number.MAX_SAFE_INTEGER, false);
|
|
192
|
+
else if (matchesKey(data, "left") && this.width >= 70) this.pane = "groups";
|
|
193
|
+
else if (matchesKey(data, "right")) this.pane = "items";
|
|
194
|
+
else if (matchesKey(data, "return")) {
|
|
195
|
+
if (this.pane === "groups" && this.width >= 70) this.pane = "items";
|
|
196
|
+
else if (this.selected) {
|
|
197
|
+
this.done(this.selected.id);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
if (!this.searchMode && matchesKey(data, "/")) {
|
|
202
|
+
this.searchMode = true;
|
|
203
|
+
this.requestRender();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const before = this.search.getValue();
|
|
207
|
+
this.search.handleInput(data);
|
|
208
|
+
if (before !== this.search.getValue()) {
|
|
209
|
+
this.query = this.search.getValue();
|
|
210
|
+
this.itemIndex = 0;
|
|
211
|
+
this.itemScroll = 0;
|
|
212
|
+
this.pane = "items";
|
|
213
|
+
this.skipHeading(1);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
this.requestRender();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private row(content: string, width: number): string {
|
|
220
|
+
return this.theme.fg("border", "│ ") + fit(content, Math.max(0, width - 4)) + this.theme.fg("border", " │");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private rule(width: number, left: string, right: string): string {
|
|
224
|
+
return this.theme.fg("border", left + "─".repeat(Math.max(0, width - 2)) + right);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private footerHint(): string {
|
|
228
|
+
if (this.view.footer) return this.view.footer;
|
|
229
|
+
if (this.searchMode) return "type to search all sections · Esc leave search · Enter select";
|
|
230
|
+
return "↑↓ move · ←→ pane · Tab section · / search · Enter select · Esc back/close";
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private visibleGroups(rows: number): string[] {
|
|
234
|
+
if (this.groupIndex < this.groupScroll) this.groupScroll = this.groupIndex;
|
|
235
|
+
if (this.groupIndex >= this.groupScroll + rows) this.groupScroll = this.groupIndex - rows + 1;
|
|
236
|
+
return this.view.groups.slice(this.groupScroll, this.groupScroll + rows);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private visibleItems(rows: number): PanelItem[] {
|
|
240
|
+
const count = this.matches.length;
|
|
241
|
+
this.itemIndex = Math.max(0, Math.min(this.itemIndex, count - 1));
|
|
242
|
+
if (this.itemIndex < this.itemScroll) this.itemScroll = this.itemIndex;
|
|
243
|
+
if (this.itemIndex >= this.itemScroll + rows) this.itemScroll = this.itemIndex - rows + 1;
|
|
244
|
+
return this.matches.slice(this.itemScroll, this.itemScroll + rows);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private toned(item: PanelItem, text: string): string {
|
|
248
|
+
switch (item.tone) {
|
|
249
|
+
case "ok":
|
|
250
|
+
return this.theme.fg("success", text);
|
|
251
|
+
case "warn":
|
|
252
|
+
case "caution":
|
|
253
|
+
return this.theme.fg("warning", text);
|
|
254
|
+
case "error":
|
|
255
|
+
return this.theme.fg("error", text);
|
|
256
|
+
case "muted":
|
|
257
|
+
return this.theme.fg("muted", text);
|
|
258
|
+
default:
|
|
259
|
+
return text;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private itemLine(item: PanelItem, index: number, width: number): string {
|
|
264
|
+
if (item.heading) return this.theme.fg("dim", fit(` ${clean(item.label)}`, width));
|
|
265
|
+
const selected = this.itemIndex === index;
|
|
266
|
+
const marker = selected ? "❯ " : item.id === this.view.currentId ? "● " : " ";
|
|
267
|
+
const value = item.value ? ` ${clean(item.value)}` : "";
|
|
268
|
+
const left = fit(`${marker}${clean(item.label)}`, Math.max(1, width - visibleWidth(value)));
|
|
269
|
+
if (selected) return this.theme.bg("selectedBg", this.theme.fg("text", fit(left + value, width)));
|
|
270
|
+
const valueText = value ? this.toned(item, value) : "";
|
|
271
|
+
return item.id === this.view.currentId ? this.theme.fg("accent", left) + valueText : left + valueText;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private compact(width: number): string[] {
|
|
275
|
+
const item = this.selected;
|
|
276
|
+
return [
|
|
277
|
+
this.rule(width, "╭", "╮"),
|
|
278
|
+
this.row(this.theme.fg("accent", clean(this.view.title)), width),
|
|
279
|
+
this.row(this.theme.fg("muted", `${clean(this.view.groups[this.groupIndex] ?? "")} · ⌕ ${clean(this.query)}`), width),
|
|
280
|
+
this.row(item ? `❯ ${clean(item.label)}${item.value ? ` ${clean(item.value)}` : ""}` : "No matching entries", width),
|
|
281
|
+
this.row("↑↓ choose · Tab page · Enter · Esc", width),
|
|
282
|
+
this.rule(width, "╰", "╯"),
|
|
283
|
+
].map((line) => truncateToWidth(line, width, "…", true));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
render(width: number): string[] {
|
|
287
|
+
const w = Math.max(1, Math.floor(width));
|
|
288
|
+
this.width = w;
|
|
289
|
+
if (w < 40 || this.height < 16) return this.compact(w);
|
|
290
|
+
const body = this.bodyHeight;
|
|
291
|
+
const twoPane = w >= 70 && this.view.groups.length > 1;
|
|
292
|
+
const inner = w - 4;
|
|
293
|
+
const leftWidth = twoPane ? Math.max(18, Math.min(28, Math.floor(inner * 0.31))) : 0;
|
|
294
|
+
const rightWidth = twoPane ? inner - leftWidth - 3 : inner;
|
|
295
|
+
const items = this.matches;
|
|
296
|
+
const groups = this.visibleGroups(body);
|
|
297
|
+
const rows = this.visibleItems(body);
|
|
298
|
+
const lines: string[] = [];
|
|
299
|
+
const realCount = items.filter((item) => !item.heading).length;
|
|
300
|
+
const heading = this.theme.fg("accent", this.theme.bold(` ${clean(this.view.title)} `));
|
|
301
|
+
const range = items.length > body ? ` · ${this.itemScroll + 1}–${Math.min(items.length, this.itemScroll + body)}` : "";
|
|
302
|
+
const count = this.theme.fg("dim", ` ${realCount} entries${range} `);
|
|
303
|
+
lines.push(this.theme.fg("border", "╭─") + fit(heading, Math.max(0, w - 3 - visibleWidth(count))) + count + this.theme.fg("border", "╮"));
|
|
304
|
+
lines.push(this.row(this.theme.fg("muted", clean(this.view.subtitle)), w));
|
|
305
|
+
this.search.focused = this.focused;
|
|
306
|
+
const search = this.search.render(Math.max(4, inner - 14))[0] ?? "";
|
|
307
|
+
lines.push(this.row(`${this.theme.fg("accent", "⌕")} ${search} ${this.theme.fg("dim", `${realCount} found`)}`, w));
|
|
308
|
+
const group = clean(this.view.groups[this.groupIndex] ?? "");
|
|
309
|
+
lines.push(
|
|
310
|
+
this.row(
|
|
311
|
+
this.theme.fg("accent", `● ${this.query ? "Search results" : group}`) +
|
|
312
|
+
this.theme.fg("dim", this.view.groups.length > 1 ? " · Tab changes section · / searches all" : " · / searches"),
|
|
313
|
+
w,
|
|
314
|
+
),
|
|
315
|
+
);
|
|
316
|
+
lines.push(this.rule(w, "├", "┤"));
|
|
317
|
+
for (let i = 0; i < body; i++) {
|
|
318
|
+
const item = rows[i];
|
|
319
|
+
const itemIndex = this.itemScroll + i;
|
|
320
|
+
const right = item
|
|
321
|
+
? this.itemLine(item, itemIndex, rightWidth)
|
|
322
|
+
: i === 0 && items.length === 0
|
|
323
|
+
? this.theme.fg("muted", "No matches · try another search or section")
|
|
324
|
+
: "";
|
|
325
|
+
if (!twoPane) {
|
|
326
|
+
lines.push(this.row(right, w));
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const name = groups[i];
|
|
330
|
+
const index = this.groupScroll + i;
|
|
331
|
+
const tally = name ? this.view.items.filter((entry) => entry.group === name && !entry.heading).length : 0;
|
|
332
|
+
const prefix = this.pane === "groups" && index === this.groupIndex ? "❯ " : index === this.groupIndex ? "● " : " ";
|
|
333
|
+
const label = name ? fit(`${prefix}${clean(name)}`, Math.max(1, leftWidth - 4)) + fit(String(tally), 4) : "";
|
|
334
|
+
const left = index === this.groupIndex ? this.theme.fg("accent", label) : label;
|
|
335
|
+
lines.push(this.row(fit(left, leftWidth) + this.theme.fg("border", " │ ") + fit(right, rightWidth), w));
|
|
336
|
+
}
|
|
337
|
+
lines.push(this.rule(w, "├", "┤"));
|
|
338
|
+
const selected = this.selected;
|
|
339
|
+
lines.push(this.row(selected ? this.theme.fg("accent", clean(selected.label)) : this.theme.fg("muted", "Choose an entry"), w));
|
|
340
|
+
lines.push(this.row(this.theme.fg("muted", clean(selected?.description ?? "Type / to search all sections")), w));
|
|
341
|
+
const detail = selected && this.view.detail ? this.view.detail(selected).map(clean) : [];
|
|
342
|
+
for (let i = 0; i < DETAIL_ROWS; i++) lines.push(this.row(this.theme.fg("dim", detail[i] ?? ""), w));
|
|
343
|
+
lines.push(this.row(this.theme.fg("dim", clean(this.footerHint())), w));
|
|
344
|
+
lines.push(this.rule(w, "╰", "╯"));
|
|
345
|
+
return lines.map((line) => truncateToWidth(line, w, "…", true));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
invalidate(): void {
|
|
349
|
+
this.search.invalidate();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Every opening gets a fresh component; completion disposes its overlay. */
|
|
354
|
+
export async function showPanel(custom: ExtensionContext["ui"]["custom"], view: PanelView): Promise<string | null> {
|
|
355
|
+
let panel: SettingsPanel | undefined;
|
|
356
|
+
return await custom<string | null>(
|
|
357
|
+
(tui, theme, _keys, done) => {
|
|
358
|
+
panel = new SettingsPanel(view, theme, () => tui.requestRender(), done);
|
|
359
|
+
return panel;
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
overlay: true,
|
|
363
|
+
overlayOptions: {
|
|
364
|
+
anchor: "top-left",
|
|
365
|
+
width: "100%",
|
|
366
|
+
maxHeight: "100%",
|
|
367
|
+
margin: 0,
|
|
368
|
+
visible: (termWidth, termHeight) => {
|
|
369
|
+
panel?.setTerminalSize(termWidth, termHeight);
|
|
370
|
+
return true;
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
onHandle: (handle) => handle.focus(),
|
|
374
|
+
},
|
|
375
|
+
);
|
|
376
|
+
}
|