pi-better-subagents 0.21.1 → 0.22.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/package.json +1 -1
- package/shared-navigator.ts +107 -10
package/package.json
CHANGED
package/shared-navigator.ts
CHANGED
|
@@ -328,28 +328,92 @@ function themeFgFromTheme(theme: unknown): (color: string, value: string) => str
|
|
|
328
328
|
return (color, value) => maybeTheme?.fg ? maybeTheme.fg(color, value) : value;
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
|
|
331
|
+
// Structural typing keeps keyboard-only Pi hosts (no mouse API) loading this widget unchanged.
|
|
332
|
+
type WidgetMouseEvent = {
|
|
333
|
+
type: string;
|
|
334
|
+
button: string;
|
|
335
|
+
/** Coordinates local to this component, zero-based. */
|
|
336
|
+
x: number;
|
|
337
|
+
y: number;
|
|
338
|
+
width: number;
|
|
339
|
+
shift?: boolean;
|
|
340
|
+
alt?: boolean;
|
|
341
|
+
ctrl?: boolean;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
type WidgetMouseResult = { handled: true; render: boolean };
|
|
345
|
+
|
|
346
|
+
type MainListWidget = Component & {
|
|
347
|
+
dispose?(): void;
|
|
348
|
+
handleMouse(event: WidgetMouseEvent): WidgetMouseResult | undefined;
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, deps: HostDeps): MainListWidget {
|
|
332
352
|
const requestRender = () => tui.requestRender?.();
|
|
333
353
|
state().mainListRequestRender = requestRender;
|
|
354
|
+
// navigatorId per rendered line, so a pointer row resolves by structure, never by row text.
|
|
355
|
+
let lineOwners: Array<string | undefined> = [];
|
|
356
|
+
let lineWidth = MAIN_LIST_FALLBACK_WIDTH;
|
|
357
|
+
// Pi synthesizes a click only for the component that handled the initial press.
|
|
358
|
+
let pressedRow: { navigatorId: string; y: number } | undefined;
|
|
359
|
+
const rowAt = (event: WidgetMouseEvent): string | undefined => {
|
|
360
|
+
const width = Number.isFinite(event.width) && event.width > 0 ? Math.floor(event.width) : lineWidth;
|
|
361
|
+
if (!Number.isFinite(event.x) || event.x < 0 || event.x >= width) return undefined;
|
|
362
|
+
if (!Number.isInteger(event.y) || event.y < 0 || event.y >= lineOwners.length) return undefined;
|
|
363
|
+
return lineOwners[event.y];
|
|
364
|
+
};
|
|
334
365
|
return {
|
|
335
366
|
render(width: number): string[] {
|
|
336
367
|
const rows = listRows();
|
|
337
368
|
syncMainListSelection(rows);
|
|
338
369
|
if (!rows.length) {
|
|
339
370
|
state().lastMainListLines = undefined;
|
|
371
|
+
lineOwners = [];
|
|
372
|
+
pressedRow = undefined;
|
|
340
373
|
return [];
|
|
341
374
|
}
|
|
342
|
-
const
|
|
375
|
+
const layout = buildMainListLayout(rows, renderWidth(width), deps.truncate, themeFgFromTheme(theme), {
|
|
343
376
|
selectedId: state().mainListFocused ? state().mainListSelectedId : undefined,
|
|
344
377
|
focused: state().mainListFocused === true,
|
|
345
|
-
})
|
|
378
|
+
});
|
|
379
|
+
lineWidth = renderWidth(width);
|
|
380
|
+
// The leading gap line belongs to the widget too, so its slot stays ownerless.
|
|
381
|
+
lineOwners = [undefined, ...layout.owners];
|
|
382
|
+
const lines = ["", ...layout.lines];
|
|
346
383
|
state().lastMainListLines = lines;
|
|
347
384
|
return lines;
|
|
348
385
|
},
|
|
349
|
-
|
|
386
|
+
handleMouse(event: WidgetMouseEvent): WidgetMouseResult | undefined {
|
|
387
|
+
// Only an unmodified left press is ours; every other gesture reaches the host untouched.
|
|
388
|
+
if (event.button !== "left" || event.shift === true || event.alt === true || event.ctrl === true) {
|
|
389
|
+
pressedRow = undefined;
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
if (event.type === "press") {
|
|
393
|
+
pressedRow = undefined;
|
|
394
|
+
const navigatorId = rowAt(event);
|
|
395
|
+
if (!navigatorId || !listRows().some((row) => row.navigatorId === navigatorId)) return undefined;
|
|
396
|
+
pressedRow = { navigatorId, y: event.y };
|
|
397
|
+
return { handled: true, render: false };
|
|
398
|
+
}
|
|
399
|
+
if (event.type !== "click") return undefined;
|
|
400
|
+
const pressed = pressedRow;
|
|
401
|
+
pressedRow = undefined;
|
|
402
|
+
// A click after another component's press, or after the layout moved, is not the row we claimed.
|
|
403
|
+
if (!pressed || pressed.y !== event.y || rowAt(event) !== pressed.navigatorId) return undefined;
|
|
404
|
+
if (!openNavigatorRow(pressed.navigatorId)) return undefined;
|
|
405
|
+
return { handled: true, render: true };
|
|
406
|
+
},
|
|
407
|
+
invalidate() {
|
|
408
|
+
state().lastMainListLines = undefined;
|
|
409
|
+
lineOwners = [];
|
|
410
|
+
pressedRow = undefined;
|
|
411
|
+
},
|
|
350
412
|
dispose() {
|
|
351
413
|
const s = state();
|
|
352
414
|
if (s.mainListRequestRender === requestRender) s.mainListRequestRender = undefined;
|
|
415
|
+
lineOwners = [];
|
|
416
|
+
pressedRow = undefined;
|
|
353
417
|
},
|
|
354
418
|
};
|
|
355
419
|
}
|
|
@@ -454,7 +518,26 @@ function buildMainListLines(
|
|
|
454
518
|
fg: (color: string, value: string) => string,
|
|
455
519
|
options: { selectedId?: string; focused?: boolean } = {},
|
|
456
520
|
): string[] {
|
|
521
|
+
return buildMainListLayout(rows, width, truncate, fg, options).lines;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* The list's lines plus the navigatorId each line shows, so pointer input maps a rendered row to its
|
|
526
|
+
* stable row identity. Headers, separators and the shortcut line keep an undefined owner.
|
|
527
|
+
*/
|
|
528
|
+
function buildMainListLayout(
|
|
529
|
+
rows: InternalRow[],
|
|
530
|
+
width: number,
|
|
531
|
+
truncate: (s: string, width: number) => string,
|
|
532
|
+
fg: (color: string, value: string) => string,
|
|
533
|
+
options: { selectedId?: string; focused?: boolean } = {},
|
|
534
|
+
): { lines: string[]; owners: Array<string | undefined> } {
|
|
457
535
|
const lines: string[] = [];
|
|
536
|
+
const owners: Array<string | undefined> = [];
|
|
537
|
+
const push = (line: string, owner?: string) => {
|
|
538
|
+
lines.push(line);
|
|
539
|
+
owners.push(owner);
|
|
540
|
+
};
|
|
458
541
|
const grouped = new Map<string, InternalRow[]>();
|
|
459
542
|
for (const row of rows) {
|
|
460
543
|
const existing = grouped.get(row.providerLabel) ?? [];
|
|
@@ -466,16 +549,16 @@ function buildMainListLines(
|
|
|
466
549
|
for (let i = 0; i < orderedLabels.length; i += 1) {
|
|
467
550
|
const label = orderedLabels[i]!;
|
|
468
551
|
const group = grouped.get(label)!;
|
|
469
|
-
if (i > 0)
|
|
470
|
-
|
|
552
|
+
if (i > 0) push("");
|
|
553
|
+
push(providerGroupLabel(label, fg));
|
|
471
554
|
for (const row of group) {
|
|
472
555
|
const selected = options.focused && row.navigatorId === options.selectedId;
|
|
473
|
-
|
|
556
|
+
push(formatMainListRow(row, selected === true, fg, width), row.navigatorId);
|
|
474
557
|
}
|
|
475
558
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return lines.map((line) => safeTruncate(line, width, truncate));
|
|
559
|
+
push("");
|
|
560
|
+
push(shortcutsLine(options.focused === true, fg));
|
|
561
|
+
return { lines: lines.map((line) => safeTruncate(line, width, truncate)), owners };
|
|
479
562
|
}
|
|
480
563
|
|
|
481
564
|
function shortcutsLine(focused: boolean, fg: (color: string, value: string) => string): string {
|
|
@@ -766,6 +849,20 @@ function handleMainListCloseKey(): void {
|
|
|
766
849
|
refreshMainListWidget();
|
|
767
850
|
}
|
|
768
851
|
|
|
852
|
+
/**
|
|
853
|
+
* Open the shared detail overlay on the row a pointer chose. Setting the selection first keeps the
|
|
854
|
+
* keyboard path identical: Enter, x and the overlay's own keys then act on the clicked row.
|
|
855
|
+
*/
|
|
856
|
+
function openNavigatorRow(navigatorId: string): boolean {
|
|
857
|
+
const rows = listRows();
|
|
858
|
+
if (!rows.some((row) => row.navigatorId === navigatorId)) return false;
|
|
859
|
+
clearMainListCloseArm();
|
|
860
|
+
state().mainListSelectedId = navigatorId;
|
|
861
|
+
refreshMainListWidget();
|
|
862
|
+
openNavigator();
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
|
|
769
866
|
function openNavigator(): void {
|
|
770
867
|
const s = state();
|
|
771
868
|
const ctx = s.uiCtx;
|