@danypops/pi-packed 0.16.1 → 0.17.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 +11 -8
- package/extension/src/discover.ts +124 -140
- package/extension/src/index.ts +1 -1
- package/extension/src/menu-theme.ts +11 -1
- package/extension/src/resource-config.ts +170 -138
- package/extension/src/security-tui.ts +98 -18
- package/extension/src/tab-host.ts +30 -0
- package/extension/src/tui.ts +414 -351
- package/package.json +2 -2
package/extension/src/tui.ts
CHANGED
|
@@ -1,63 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tui.ts — /packed's
|
|
3
|
-
* convention (folke/lazy.nvim lua/lazy/view/config.lua): uppercase
|
|
4
|
-
* every row, lowercase acts on the row under the cursor -- U/u
|
|
5
|
-
* X/x was lazy's delete key (clean); here that pairing is
|
|
6
|
-
* only (x remove -- there is no safe "remove every
|
|
7
|
-
* bulk analog, so no X is bound). Adds d disable/
|
|
8
|
-
* extensions, c jump to
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
2
|
+
* tui.ts — /packed's one panel, four tabs. Mnemonics follow lazy.nvim's
|
|
3
|
+
* own convention (folke/lazy.nvim lua/lazy/view/config.lua): uppercase
|
|
4
|
+
* acts on every row, lowercase acts on the row under the cursor -- U/u
|
|
5
|
+
* update, X/x was lazy's delete key (clean); here that pairing is
|
|
6
|
+
* single-target only (x remove -- there is no safe "remove every
|
|
7
|
+
* installed package" bulk analog, so no X is bound). Adds d disable/
|
|
8
|
+
* enable this package's extensions, c jump to Config (scoped to the
|
|
9
|
+
* selected row), f jump to Find, s jump to Settings.
|
|
10
|
+
*
|
|
11
|
+
* All four (Packages/Find/Config/Settings) live inside ONE
|
|
12
|
+
* `ctx.ui.custom` floating overlay for the panel's whole lifetime --
|
|
13
|
+
* Malevich's Envelope for the box (rounded border), TabbedContainer for
|
|
14
|
+
* the persistent tab bar + active-tab content swap, and (on top of that)
|
|
15
|
+
* a Dialog swapped in for any y/n decision, the same content-replacement
|
|
16
|
+
* stacking Envelope's own setContent already provides, generalized one
|
|
17
|
+
* level further here. This replaced each tab opening its own separate
|
|
18
|
+
* screen (Find/Config: a second, visually distinct ctx.ui.custom with no
|
|
19
|
+
* Envelope at all; Settings: Pi's own native ctx.ui.select/confirm) --
|
|
20
|
+
* confirmed live as a real user complaint ("Find, Settings, Config all
|
|
21
|
+
* open a different TUI"). Left/Right cycle tabs; Escape returns to
|
|
22
|
+
* Packages from anywhere else, or closes the whole panel from Packages
|
|
23
|
+
* itself -- unless the active tab's own capturesEscape()/
|
|
24
|
+
* capturesHorizontalArrows() says it wants that key for itself right now
|
|
25
|
+
* (an active text filter, an in-flight mutation, or Find's always-on
|
|
26
|
+
* query box), in which case it's delegated straight through instead.
|
|
27
|
+
*
|
|
28
|
+
* Packages itself: an indeterminate spinner (Malevich's Spinner) renders
|
|
29
|
+
* inline next to the row currently updating, settling into a real ✓/✗
|
|
30
|
+
* plus a bounded tail of that row's own actual captured stdout/stderr
|
|
31
|
+
* once it finishes, never a determinate bar (a single subprocess call has
|
|
32
|
+
* no knowable percentage). Rows render through Malevich's Table (real
|
|
33
|
+
* column-aligned Package/Version/status cells, per-row selection styling
|
|
34
|
+
* baked into each cell since Table's own cellStyle is column-wide, not
|
|
35
|
+
* row-wide) inside this tab's own scroll-window slice -- Table
|
|
36
|
+
* deliberately owns no pagination of its own, so the visible-window-
|
|
37
|
+
* around-selectedIndex math stays here. u/x/d and the Enter action menu
|
|
38
|
+
* all run their whole approve+mutate+confirmReload flow inline, via the
|
|
39
|
+
* shared TabHost's inlineCtx -- every confirm() along the way renders as
|
|
40
|
+
* a real Malevich Dialog on this SAME overlay, dispatched by literal y/n
|
|
41
|
+
* keys, instead of ctx.ui.confirm's own separate native dialog. Every
|
|
42
|
+
* non-"changed" settle point (already up to date, pinned, deferred, a
|
|
43
|
+
* genuine failure) shows its own real reason on that row too via the same
|
|
44
|
+
* settled map U's batch path uses, not only as a scrollback toast. All
|
|
45
|
+
* data flows through the packed CLI (thin seam).
|
|
42
46
|
*/
|
|
43
47
|
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
44
48
|
import { DynamicBorder, rawKeyHint } from "@earendil-works/pi-coding-agent";
|
|
45
49
|
import { Container, Input, Spacer, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
46
|
-
import { Dialog, Envelope, Menu, Spinner, Table, type
|
|
50
|
+
import { Dialog, Envelope, Menu, Spinner, Table, TabbedContainer, type Component, type MenuItem, type TextMeasure } from "malevich-tui-components";
|
|
47
51
|
import { filterRows, mergeRows, nextMode, visibleRows } from "./model.js";
|
|
48
52
|
import type { Row, ViewMode } from "./model.js";
|
|
49
53
|
import type { Natives, PackageResources } from "./packed.js";
|
|
50
54
|
import { approvePackageOperation } from "./tools.js";
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import { dialogTheme, menuTheme } from "./menu-theme.js";
|
|
55
|
+
import { createSettingsTab, SettingsTab } from "./security-tui.js";
|
|
56
|
+
import { createConfigTab, ConfigTab, applyResourceToggle } from "./resource-config.js";
|
|
57
|
+
import { createFindTab, FindTab } from "./discover.js";
|
|
58
|
+
import { dialogTheme, menuTheme, tabBarTheme } from "./menu-theme.js";
|
|
55
59
|
import { confirmReload } from "./reload.js";
|
|
60
|
+
import type { TabHost } from "./tab-host.js";
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
type: "config" | "find" | "refresh" | "settings";
|
|
59
|
-
row?: Row;
|
|
60
|
-
}
|
|
62
|
+
export type PackedTabKey = "packages" | "find" | "config" | "settings";
|
|
61
63
|
|
|
62
64
|
/** Outcome of a confirmed row action, resolved after any real mutation and
|
|
63
65
|
* reload decision -- "changed" means the daemon state changed and Pi has
|
|
@@ -369,86 +371,327 @@ async function showActionMenu(ctx: ExtensionCommandContext, row: Row): Promise<"
|
|
|
369
371
|
);
|
|
370
372
|
}
|
|
371
373
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
374
|
+
interface PackagesTabTheme { fg(color: string, s: string): string; bold(s: string): string; }
|
|
375
|
+
|
|
376
|
+
/** Packages -- the panel's default/"home" tab. A real Component (not the
|
|
377
|
+
* panel's own top-level ctx.ui.custom owner anymore); the shared TabHost
|
|
378
|
+
* gives it inline approval/reload dialogs and a way to signal the overlay
|
|
379
|
+
* should close once a mutation actually replaces the session. */
|
|
380
|
+
export class PackagesTab implements Component {
|
|
381
|
+
private rows: Row[];
|
|
382
|
+
private mode: ViewMode = "all";
|
|
383
|
+
private readonly searchInput = new Input();
|
|
384
|
+
private searchActive = false;
|
|
385
|
+
private filtered: Row[];
|
|
386
|
+
private selectedIndex = 0;
|
|
387
|
+
// Set only while U's batch update (or a single row's own u/x/d) is
|
|
388
|
+
// running -- blocks input for the duration (the mutation/installer owns
|
|
389
|
+
// input until it finishes). Which specific row currently shows a spinner
|
|
390
|
+
// vs. a settled ✓/✗ is settled's own job, not this -- a just-finished row
|
|
391
|
+
// must show its glyph immediately, even for the instant before the next
|
|
392
|
+
// row's "start" event reassigns this to the next name.
|
|
393
|
+
private updatingRowName: string | undefined;
|
|
394
|
+
private readonly spinner = new Spinner();
|
|
395
|
+
private readonly settled = new Map<string, { ok: boolean; tail: string | undefined }>();
|
|
396
|
+
private readonly table: Table;
|
|
397
|
+
private readonly maxVisible = 20;
|
|
398
|
+
|
|
399
|
+
constructor(
|
|
400
|
+
private readonly natives: Natives,
|
|
401
|
+
private readonly host: TabHost,
|
|
402
|
+
private readonly theme: PackagesTabTheme,
|
|
403
|
+
measure: TextMeasure,
|
|
404
|
+
initialRows: Row[],
|
|
405
|
+
/** c on a row, or the Enter action menu's "Configure resources" --
|
|
406
|
+
* switches the shared TabbedContainer to Config, seeded with that
|
|
407
|
+
* row's own name as its filter. f/s switch tabs with no filter. */
|
|
408
|
+
private readonly switchTab: (target: "find" | "config" | "settings", configFilter?: string) => void,
|
|
409
|
+
) {
|
|
410
|
+
this.rows = initialRows;
|
|
411
|
+
this.filtered = visibleRows(this.rows, this.mode);
|
|
412
|
+
this.table = new Table({
|
|
413
|
+
columns: [
|
|
414
|
+
{ header: "Package", key: "name" },
|
|
415
|
+
{ header: "Version", key: "version" },
|
|
416
|
+
{ header: "", key: "status" },
|
|
417
|
+
],
|
|
418
|
+
rows: [],
|
|
419
|
+
measure,
|
|
420
|
+
headerStyle: (s) => theme.fg("muted", s),
|
|
421
|
+
});
|
|
376
422
|
}
|
|
377
423
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
424
|
+
/** An active filter or an in-flight mutation means Escape/Left-Right
|
|
425
|
+
* belong to this tab (clearing the filter; blocking navigation away
|
|
426
|
+
* mid-mutation), not the host's own back/tab-cycle handling. Packages
|
|
427
|
+
* never uses Left/Right for itself otherwise. */
|
|
428
|
+
capturesEscape(): boolean {
|
|
429
|
+
return this.searchActive || this.updatingRowName !== undefined;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
invalidate(): void {
|
|
433
|
+
this.table.invalidate();
|
|
382
434
|
}
|
|
383
435
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
async function refreshRows(): Promise<void> {
|
|
388
|
-
({ rows, error } = await loadRows(natives));
|
|
389
|
-
if (error) ctx.ui.notify(`refresh failed: ${error}`, "error");
|
|
436
|
+
private applyFilter(): void {
|
|
437
|
+
this.filtered = filterRows(visibleRows(this.rows, this.mode), this.searchInput.getValue());
|
|
438
|
+
this.selectedIndex = 0;
|
|
390
439
|
}
|
|
391
440
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
441
|
+
private statusLine(): string {
|
|
442
|
+
if (this.updatingRowName) return "updating…";
|
|
443
|
+
const outdated = this.rows.filter((r) => r.hasUpdate).length;
|
|
444
|
+
return outdated > 0 ? `${outdated} update(s)` : "up to date";
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
render(width: number): string[] {
|
|
448
|
+
const { theme } = this;
|
|
449
|
+
const hint = this.searchActive
|
|
450
|
+
? rawKeyHint("esc", "clear")
|
|
451
|
+
: rawKeyHint("enter", "menu") +
|
|
452
|
+
theme.fg("muted", " · ") +
|
|
453
|
+
rawKeyHint("u/U", "update/all") +
|
|
454
|
+
theme.fg("muted", " · ") +
|
|
455
|
+
rawKeyHint("x", "remove") +
|
|
456
|
+
theme.fg("muted", " · ") +
|
|
457
|
+
rawKeyHint("d", "disable") +
|
|
458
|
+
theme.fg("muted", " · ") +
|
|
459
|
+
rawKeyHint("c", "config") +
|
|
460
|
+
theme.fg("muted", " · ") +
|
|
461
|
+
rawKeyHint("r", "refresh");
|
|
462
|
+
const line1 = truncateToWidth(hint, width, "");
|
|
463
|
+
const dot = "·";
|
|
464
|
+
const line2 = truncateToWidth(
|
|
465
|
+
theme.fg("muted", `${this.statusLine()} ${dot} view: ${this.mode} ${dot} / filter ${dot} tab view ${dot} ${this.rows.length} installed`),
|
|
466
|
+
width,
|
|
467
|
+
"",
|
|
468
|
+
);
|
|
469
|
+
const lines: string[] = [line1, line2];
|
|
470
|
+
if (this.searchActive) lines.push(...this.searchInput.render(width));
|
|
471
|
+
lines.push("");
|
|
472
|
+
if (this.filtered.length === 0) {
|
|
473
|
+
lines.push(theme.fg("muted", " No packages"));
|
|
474
|
+
return lines;
|
|
404
475
|
}
|
|
476
|
+
// No scrolling of its own (Malevich's Table is deliberately
|
|
477
|
+
// unopinionated about pagination) -- the visible window around
|
|
478
|
+
// selectedIndex stays this tab's own job.
|
|
479
|
+
const start = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filtered.length - this.maxVisible));
|
|
480
|
+
const end = Math.min(start + this.maxVisible, this.filtered.length);
|
|
481
|
+
this.table.setRows(
|
|
482
|
+
this.filtered.slice(start, end).map((row, offset) => {
|
|
483
|
+
const i = start + offset;
|
|
484
|
+
const selected = i === this.selectedIndex;
|
|
485
|
+
const cursor = selected ? theme.fg("accent", "❯ ") : " ";
|
|
486
|
+
const name = selected ? theme.bold(row.name) : row.name;
|
|
487
|
+
// A settled row shows its real outcome even for the instant before
|
|
488
|
+
// the next row's "start" event moves updatingRowName off it --
|
|
489
|
+
// settled always wins over "still spinning".
|
|
490
|
+
const rowSettled = this.settled.get(row.name);
|
|
491
|
+
const isUpdating = !rowSettled && this.updatingRowName === row.name;
|
|
492
|
+
const status = isUpdating
|
|
493
|
+
? theme.fg("accent", `${this.spinner.glyph()} updating…`)
|
|
494
|
+
: rowSettled
|
|
495
|
+
? theme.fg(rowSettled.ok ? "success" : "error", `${rowSettled.ok ? "✓" : "✗"}${rowSettled.tail ? ` ${rowSettled.tail}` : ""}`)
|
|
496
|
+
: row.hasUpdate ? theme.fg("warning", `↑${row.latest}`) : "";
|
|
497
|
+
return { name: `${cursor}${name}`, version: theme.fg("dim", row.version), status };
|
|
498
|
+
}),
|
|
499
|
+
);
|
|
500
|
+
lines.push(...this.table.render(width));
|
|
501
|
+
const hasScroll = start > 0 || end < this.filtered.length;
|
|
502
|
+
lines.push(theme.fg("dim", ` ${hasScroll ? `${this.selectedIndex + 1}/${this.filtered.length} ` : ""}${this.mode}`));
|
|
503
|
+
return lines;
|
|
504
|
+
}
|
|
405
505
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
506
|
+
handleInput(data: string): void {
|
|
507
|
+
if (this.updatingRowName) return; // the mutation/installer owns input until it finishes
|
|
508
|
+
|
|
509
|
+
if (this.searchActive) {
|
|
510
|
+
if (data === "\x1b") {
|
|
511
|
+
this.searchActive = false;
|
|
512
|
+
this.searchInput.setValue?.("");
|
|
513
|
+
this.applyFilter();
|
|
514
|
+
} else if (data === "\r") {
|
|
515
|
+
this.searchActive = false;
|
|
516
|
+
} else {
|
|
517
|
+
this.searchInput.handleInput(data);
|
|
518
|
+
this.applyFilter();
|
|
519
|
+
}
|
|
520
|
+
this.host.requestRender();
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
switch (data) {
|
|
525
|
+
case "\x1b[A":
|
|
526
|
+
this.selectedIndex = (this.selectedIndex - 1 + this.filtered.length) % Math.max(this.filtered.length, 1);
|
|
527
|
+
break;
|
|
528
|
+
case "\x1b[B":
|
|
529
|
+
this.selectedIndex = (this.selectedIndex + 1) % Math.max(this.filtered.length, 1);
|
|
530
|
+
break;
|
|
531
|
+
case "\t":
|
|
532
|
+
this.mode = nextMode(this.mode);
|
|
533
|
+
this.applyFilter();
|
|
534
|
+
break;
|
|
535
|
+
case "/":
|
|
536
|
+
this.searchActive = true;
|
|
537
|
+
break;
|
|
538
|
+
case "r":
|
|
539
|
+
void this.refresh();
|
|
540
|
+
return;
|
|
541
|
+
case "s":
|
|
542
|
+
this.switchTab("settings");
|
|
543
|
+
return;
|
|
544
|
+
case "f":
|
|
545
|
+
this.switchTab("find");
|
|
546
|
+
return;
|
|
547
|
+
case "U":
|
|
548
|
+
void this.runUpdateAllInline();
|
|
549
|
+
return;
|
|
550
|
+
case "u": {
|
|
551
|
+
const row = this.filtered[this.selectedIndex];
|
|
552
|
+
if (row?.hasUpdate) void this.runRowActionInline({ type: "update", row });
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
case "x": {
|
|
556
|
+
const row = this.filtered[this.selectedIndex];
|
|
557
|
+
if (row) void this.runRowActionInline({ type: "remove", row });
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
case "d": {
|
|
561
|
+
const row = this.filtered[this.selectedIndex];
|
|
562
|
+
if (row) void this.runRowActionInline({ type: "disable", row });
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
case "c": {
|
|
566
|
+
const row = this.filtered[this.selectedIndex];
|
|
567
|
+
if (row) this.switchTab("config", row.name);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
case "\r": {
|
|
571
|
+
const row = this.filtered[this.selectedIndex];
|
|
572
|
+
if (!row) return;
|
|
573
|
+
void (async () => {
|
|
574
|
+
const choice = await showActionMenu(this.host.inlineCtx, row);
|
|
575
|
+
if (choice === "update" || choice === "remove" || choice === "disable") void this.runRowActionInline({ type: choice, row });
|
|
576
|
+
else if (choice === "config") this.switchTab("config", row.name);
|
|
577
|
+
})();
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
default:
|
|
581
|
+
return;
|
|
409
582
|
}
|
|
583
|
+
this.host.requestRender();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
private async refresh(): Promise<void> {
|
|
587
|
+
const reloaded = await loadRows(this.natives);
|
|
588
|
+
if (reloaded.error) this.host.ctx.ui.notify(`refresh failed: ${reloaded.error}`, "error");
|
|
589
|
+
else this.rows = reloaded.rows;
|
|
590
|
+
this.applyFilter();
|
|
591
|
+
this.host.requestRender();
|
|
592
|
+
}
|
|
410
593
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
594
|
+
/** u/x/d and the Enter action menu all funnel through here: approval and
|
|
595
|
+
* reload confirms render inline (via host.inlineCtx) on this same
|
|
596
|
+
* overlay, never closing it first. */
|
|
597
|
+
private async runRowActionInline(action: { type: "update" | "remove" | "disable"; row: Row }): Promise<void> {
|
|
598
|
+
this.updatingRowName = action.row.name;
|
|
599
|
+
this.host.requestRender();
|
|
600
|
+
// A non-"changed" settle point (already up to date, pinned, deferred, a
|
|
601
|
+
// genuine failure) shows its own real reason on this row, the same
|
|
602
|
+
// settled map U's batch path already renders -- not just a scrollback
|
|
603
|
+
// toast.
|
|
604
|
+
const onSettled = (result: PackageChoiceSettled) => this.settled.set(action.row.name, { ok: result.ok, tail: result.message });
|
|
605
|
+
const outcome = action.type === "disable"
|
|
606
|
+
? await applyDisableExtensions(action.row, this.natives, this.host.inlineCtx)
|
|
607
|
+
: await applyPackageChoice(action.type === "update" ? `Update to ${action.row.latest}` : "Remove", action.row, this.natives, this.host.inlineCtx, onSettled);
|
|
608
|
+
this.updatingRowName = undefined;
|
|
609
|
+
if (outcome === "changed") {
|
|
610
|
+
this.host.onSessionReplaced(); // ctx.reload() already replaced the session
|
|
611
|
+
return;
|
|
414
612
|
}
|
|
613
|
+
const reloaded = await loadRows(this.natives);
|
|
614
|
+
if (reloaded.error) this.host.ctx.ui.notify(`refresh failed: ${reloaded.error}`, "error");
|
|
615
|
+
else this.rows = reloaded.rows;
|
|
616
|
+
this.applyFilter();
|
|
617
|
+
this.host.requestRender();
|
|
618
|
+
}
|
|
415
619
|
|
|
416
|
-
|
|
417
|
-
|
|
620
|
+
/** U -- runs the whole approve+update+notify+reload flow without ever
|
|
621
|
+
* closing this tab or replacing the list: each row's own settled outcome
|
|
622
|
+
* (spinner while in flight, then a real ✓/✗ plus a bounded tail of its
|
|
623
|
+
* actual captured output) appears inline next to that row. Rows refresh
|
|
624
|
+
* in place afterward unless a reload already ended the session. */
|
|
625
|
+
private async runUpdateAllInline(): Promise<void> {
|
|
626
|
+
const outdated = this.rows.filter((row) => row.hasUpdate);
|
|
627
|
+
this.settled.clear();
|
|
628
|
+
const outcome = await approveAndRunUpdateAll(outdated, this.natives, this.host.inlineCtx, (batch, approved) => {
|
|
629
|
+
this.spinner.start(() => this.host.requestRender());
|
|
630
|
+
return performUpdateAll(batch, this.natives, approved, (event) => {
|
|
631
|
+
this.updatingRowName = event.row.name;
|
|
632
|
+
if (event.phase === "done" && event.result) {
|
|
633
|
+
this.settled.set(event.row.name, { ok: event.result.ok, tail: logTail(event.result.output) });
|
|
634
|
+
}
|
|
635
|
+
this.host.requestRender();
|
|
636
|
+
}).finally(() => this.spinner.stop());
|
|
637
|
+
});
|
|
638
|
+
this.updatingRowName = undefined;
|
|
639
|
+
if (outcome === "changed") {
|
|
640
|
+
this.host.onSessionReplaced(); // ctx.reload() already replaced the session
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const reloaded = await loadRows(this.natives);
|
|
644
|
+
if (reloaded.error) this.host.ctx.ui.notify(`refresh failed: ${reloaded.error}`, "error");
|
|
645
|
+
else this.rows = reloaded.rows;
|
|
646
|
+
this.settled.clear(); // fresh state for a subsequent batch
|
|
647
|
+
this.applyFilter();
|
|
648
|
+
this.host.requestRender();
|
|
418
649
|
}
|
|
419
650
|
}
|
|
420
651
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
652
|
+
interface TabScope {
|
|
653
|
+
/** True while this tab wants Escape for itself right now (an active
|
|
654
|
+
* filter, an in-flight mutation) instead of the host's own "back to
|
|
655
|
+
* Packages, or close from Packages" handling. Defaults to false. */
|
|
656
|
+
capturesEscape?(): boolean;
|
|
657
|
+
/** True while this tab wants Left/Right for itself right now (Find's
|
|
658
|
+
* always-on query cursor) instead of the host's own tab-cycling.
|
|
659
|
+
* Defaults to false. */
|
|
660
|
+
capturesHorizontalArrows?(): boolean;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export async function showPackedPanel(
|
|
664
|
+
ctx: ExtensionCommandContext,
|
|
665
|
+
natives: Natives,
|
|
666
|
+
opts?: { initialTab?: PackedTabKey; initialConfigFilter?: string },
|
|
667
|
+
): Promise<void> {
|
|
668
|
+
if (!ctx.hasUI) {
|
|
669
|
+
ctx.ui.notify("/packed requires interactive mode", "warning");
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const { rows, error } = await loadRows(natives);
|
|
674
|
+
if (error) {
|
|
675
|
+
ctx.ui.notify(`packed unavailable: ${error}`, "error");
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
446
678
|
|
|
679
|
+
await renderUnifiedPanel(ctx, natives, rows, opts?.initialTab ?? "packages", opts?.initialConfigFilter);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function renderUnifiedPanel(
|
|
683
|
+
ctx: ExtensionCommandContext,
|
|
684
|
+
natives: Natives,
|
|
685
|
+
initialRows: Row[],
|
|
686
|
+
initialTab: PackedTabKey,
|
|
687
|
+
initialConfigFilter: string | undefined,
|
|
688
|
+
): Promise<void> {
|
|
689
|
+
return ctx.ui.custom<void>((tui, theme, _kb, done) => {
|
|
447
690
|
// A y/n decision rendered as this SAME overlay's own content (via a real
|
|
448
691
|
// Malevich Dialog, dispatched by literal key press) instead of
|
|
449
|
-
// ctx.ui.confirm's separate native dialog --
|
|
450
|
-
//
|
|
451
|
-
//
|
|
692
|
+
// ctx.ui.confirm's separate native dialog -- shared by every tab via
|
|
693
|
+
// host.inlineCtx below, exactly like the panel's own approval/reload
|
|
694
|
+
// dialogs always have been.
|
|
452
695
|
let pendingDialog: Dialog | undefined;
|
|
453
696
|
|
|
454
697
|
function confirmInline(title: string, message: string): Promise<boolean> {
|
|
@@ -466,194 +709,75 @@ function renderPanel(ctx: ExtensionCommandContext, natives: Natives, initialRows
|
|
|
466
709
|
{ label: "No", key: "n", action: () => settle(false) },
|
|
467
710
|
],
|
|
468
711
|
theme: dialogTheme(theme),
|
|
712
|
+
framed: false, // this overlay's own Envelope already draws a border; a second rule would double up on it
|
|
469
713
|
});
|
|
470
714
|
tui.requestRender();
|
|
471
715
|
});
|
|
472
716
|
}
|
|
473
717
|
|
|
474
|
-
// Every confirm() call inside a mutation flow driven from this open
|
|
475
|
-
// overlay (approvePackageOperation's own approval, confirmReload's
|
|
476
|
-
// separate reload gate) routes through confirmInline instead of the
|
|
477
|
-
// real ctx.ui.confirm -- notify/reload/etc. stay the genuine ctx.
|
|
478
718
|
const inlineCtx: ExtensionCommandContext = { ...ctx, hasUI: true, ui: { ...ctx.ui, confirm: confirmInline } };
|
|
719
|
+
const host: TabHost = {
|
|
720
|
+
ctx,
|
|
721
|
+
inlineCtx,
|
|
722
|
+
requestRender: () => tui.requestRender(),
|
|
723
|
+
onSessionReplaced: () => done(undefined),
|
|
724
|
+
};
|
|
479
725
|
|
|
480
|
-
|
|
481
|
-
* reload confirms render inline (via inlineCtx/confirmInline) on this
|
|
482
|
-
* same overlay, never closing it first the way done()-dispatch used to. */
|
|
483
|
-
async function runRowActionInline(action: { type: "update" | "remove" | "disable"; row: Row }): Promise<void> {
|
|
484
|
-
updatingRowName = action.row.name;
|
|
485
|
-
tui.requestRender();
|
|
486
|
-
// A non-"changed" settle point (already up to date, pinned, deferred,
|
|
487
|
-
// a genuine failure) shows its own real reason on this row, the same
|
|
488
|
-
// settled map U's batch path already renders -- not just a scrollback
|
|
489
|
-
// toast, which was the whole bug: nothing on the panel itself ever
|
|
490
|
-
// acknowledged that a single-row action had even run.
|
|
491
|
-
const onSettled = (result: PackageChoiceSettled) => settled.set(action.row.name, { ok: result.ok, tail: result.message });
|
|
492
|
-
const outcome = action.type === "disable"
|
|
493
|
-
? await applyDisableExtensions(action.row, natives, inlineCtx)
|
|
494
|
-
: await applyPackageChoice(action.type === "update" ? `Update to ${action.row.latest}` : "Remove", action.row, natives, inlineCtx, onSettled);
|
|
495
|
-
updatingRowName = undefined;
|
|
496
|
-
if (outcome === "changed") {
|
|
497
|
-
done(undefined); // ctx.reload() already replaced the session
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
const reloaded = await loadRows(natives);
|
|
501
|
-
if (reloaded.error) ctx.ui.notify(`refresh failed: ${reloaded.error}`, "error");
|
|
502
|
-
else rows = reloaded.rows;
|
|
503
|
-
applyFilter();
|
|
504
|
-
tui.requestRender();
|
|
505
|
-
}
|
|
726
|
+
const measure: TextMeasure = { visibleWidth, truncateToWidth };
|
|
506
727
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
* updatingRowName/spinner/settled, which list's own render checks. Rows
|
|
512
|
-
* refresh in place afterward unless a reload already ended the session. */
|
|
513
|
-
async function runUpdateAllInline(): Promise<void> {
|
|
514
|
-
const outdated = rows.filter((row) => row.hasUpdate);
|
|
515
|
-
settled.clear();
|
|
516
|
-
const outcome = await approveAndRunUpdateAll(outdated, natives, inlineCtx, (batch, approved) => {
|
|
517
|
-
spinner.start(() => tui.requestRender());
|
|
518
|
-
return performUpdateAll(batch, natives, approved, (event) => {
|
|
519
|
-
updatingRowName = event.row.name;
|
|
520
|
-
if (event.phase === "done" && event.result) {
|
|
521
|
-
settled.set(event.row.name, { ok: event.result.ok, tail: logTail(event.result.output) });
|
|
522
|
-
}
|
|
523
|
-
tui.requestRender();
|
|
524
|
-
}).finally(() => spinner.stop());
|
|
525
|
-
});
|
|
526
|
-
updatingRowName = undefined;
|
|
527
|
-
if (outcome === "changed") {
|
|
528
|
-
done(undefined); // ctx.reload() already replaced the session
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
const reloaded = await loadRows(natives);
|
|
532
|
-
if (reloaded.error) ctx.ui.notify(`refresh failed: ${reloaded.error}`, "error");
|
|
533
|
-
else rows = reloaded.rows;
|
|
534
|
-
settled.clear(); // fresh state for a subsequent batch
|
|
535
|
-
applyFilter();
|
|
536
|
-
tui.requestRender();
|
|
537
|
-
}
|
|
728
|
+
const packagesTab = new PackagesTab(natives, host, theme, measure, initialRows, (target, configFilter) => {
|
|
729
|
+
if (target === "config" && configFilter !== undefined) configTab.setFilter(configFilter);
|
|
730
|
+
tabbedContainer.setActive(target);
|
|
731
|
+
});
|
|
538
732
|
|
|
539
|
-
|
|
540
|
-
if (updatingRowName) return "Packages · updating…";
|
|
541
|
-
const outdated = rows.filter((r) => r.hasUpdate).length;
|
|
542
|
-
return outdated > 0 ? `Packages · ${outdated} update(s)` : "Packages";
|
|
543
|
-
}
|
|
733
|
+
const findTab = createFindTab(natives, host, theme);
|
|
544
734
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
rawKeyHint("u/U", "update/all") +
|
|
553
|
-
theme.fg("muted", " · ") +
|
|
554
|
-
rawKeyHint("x", "remove") +
|
|
555
|
-
theme.fg("muted", " · ") +
|
|
556
|
-
rawKeyHint("d", "disable") +
|
|
557
|
-
theme.fg("muted", " · ") +
|
|
558
|
-
rawKeyHint("c", "config") +
|
|
559
|
-
theme.fg("muted", " · ") +
|
|
560
|
-
rawKeyHint("f", "find") +
|
|
561
|
-
theme.fg("muted", " · ") +
|
|
562
|
-
rawKeyHint("s", "settings") +
|
|
563
|
-
theme.fg("muted", " · ") +
|
|
564
|
-
rawKeyHint("esc", "close");
|
|
565
|
-
const line1 = truncateToWidth(hint, width, "");
|
|
566
|
-
const dot = "·";
|
|
567
|
-
const line2 = truncateToWidth(
|
|
568
|
-
theme.fg("muted", `view: ${mode} ${dot} / filter ${dot} tab view ${dot} r refresh ${dot} ${rows.length} installed`),
|
|
569
|
-
width,
|
|
570
|
-
"",
|
|
571
|
-
);
|
|
572
|
-
return [line1, line2];
|
|
573
|
-
},
|
|
574
|
-
};
|
|
735
|
+
// Config/Settings both need theme (only available once this factory
|
|
736
|
+
// runs) so they're constructed here rather than before the overlay
|
|
737
|
+
// opens; both load their own data asynchronously in the background and
|
|
738
|
+
// render their own "Loading…" state until it resolves -- no
|
|
739
|
+
// placeholder-swap machinery needed.
|
|
740
|
+
const configTab = new ConfigTab(natives, host, theme, initialTab === "config" ? initialConfigFilter : undefined);
|
|
741
|
+
void configTab.load().then(() => tui.requestRender());
|
|
575
742
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
{ header: "Version", key: "version" },
|
|
585
|
-
{ header: "", key: "status" },
|
|
586
|
-
];
|
|
587
|
-
const table = new Table({ columns, rows: [], measure, headerStyle: (s) => theme.fg("muted", s) });
|
|
588
|
-
|
|
589
|
-
const list = {
|
|
590
|
-
invalidate() {},
|
|
591
|
-
render(width: number): string[] {
|
|
592
|
-
const lines: string[] = [];
|
|
593
|
-
if (searchActive) lines.push(...searchInput.render(width));
|
|
594
|
-
lines.push("");
|
|
595
|
-
if (filtered.length === 0) {
|
|
596
|
-
lines.push(theme.fg("muted", " No packages"));
|
|
597
|
-
return lines;
|
|
598
|
-
}
|
|
599
|
-
// No scrolling of its own (Malevich's Table is deliberately
|
|
600
|
-
// unopinionated about pagination) -- the visible window around
|
|
601
|
-
// selectedIndex stays this panel's own job, same as before.
|
|
602
|
-
const start = Math.max(0, Math.min(selectedIndex - Math.floor(maxVisible / 2), filtered.length - maxVisible));
|
|
603
|
-
const end = Math.min(start + maxVisible, filtered.length);
|
|
604
|
-
table.setRows(
|
|
605
|
-
filtered.slice(start, end).map((row, offset) => {
|
|
606
|
-
const i = start + offset;
|
|
607
|
-
const selected = i === selectedIndex;
|
|
608
|
-
const cursor = selected ? theme.fg("accent", "❯ ") : " ";
|
|
609
|
-
const name = selected ? theme.bold(row.name) : row.name;
|
|
610
|
-
// A settled row shows its real outcome even for the instant
|
|
611
|
-
// before the next row's "start" event moves updatingRowName
|
|
612
|
-
// off it -- settled always wins over "still spinning".
|
|
613
|
-
const rowSettled = settled.get(row.name);
|
|
614
|
-
const isUpdating = !rowSettled && updatingRowName === row.name;
|
|
615
|
-
const status = isUpdating
|
|
616
|
-
? theme.fg("accent", `${spinner.glyph()} updating…`)
|
|
617
|
-
: rowSettled
|
|
618
|
-
? theme.fg(rowSettled.ok ? "success" : "error", `${rowSettled.ok ? "✓" : "✗"}${rowSettled.tail ? ` ${rowSettled.tail}` : ""}`)
|
|
619
|
-
: row.hasUpdate ? theme.fg("warning", `↑${row.latest}`) : "";
|
|
620
|
-
return { name: `${cursor}${name}`, version: theme.fg("dim", row.version), status };
|
|
621
|
-
}),
|
|
622
|
-
);
|
|
623
|
-
lines.push(...table.render(width));
|
|
624
|
-
const hasScroll = start > 0 || end < filtered.length;
|
|
625
|
-
lines.push(theme.fg("dim", ` ${hasScroll ? `${selectedIndex + 1}/${filtered.length} ` : ""}${mode}`));
|
|
626
|
-
return lines;
|
|
627
|
-
},
|
|
743
|
+
const settingsTab = new SettingsTab(natives, host, theme);
|
|
744
|
+
void settingsTab.load().then(() => tui.requestRender());
|
|
745
|
+
|
|
746
|
+
const tabByKey: Record<PackedTabKey, Component & TabScope> = {
|
|
747
|
+
packages: packagesTab,
|
|
748
|
+
find: findTab,
|
|
749
|
+
config: configTab,
|
|
750
|
+
settings: settingsTab,
|
|
628
751
|
};
|
|
629
752
|
|
|
630
|
-
|
|
631
|
-
|
|
753
|
+
const tabbedContainer = new TabbedContainer({
|
|
754
|
+
tabs: [
|
|
755
|
+
{ key: "packages", label: "Packages", content: tabByKey.packages },
|
|
756
|
+
{ key: "find", label: "Find", content: tabByKey.find },
|
|
757
|
+
{ key: "config", label: "Config", content: tabByKey.config },
|
|
758
|
+
{ key: "settings", label: "Settings", content: tabByKey.settings },
|
|
759
|
+
],
|
|
760
|
+
theme: tabBarTheme(theme),
|
|
761
|
+
initialKey: initialTab,
|
|
762
|
+
});
|
|
763
|
+
|
|
632
764
|
// measure must be explicit: Envelope's own default is ASCII-only (raw
|
|
633
|
-
// .length, blind to ANSI escape codes) and every
|
|
634
|
-
// through theme.fg/theme.bold -- without this, Envelope pads
|
|
635
|
-
// against its own escape-code-inflated "length" instead of
|
|
636
|
-
// visible width, so the right border lands at a different
|
|
637
|
-
// every line depending on how much styling
|
|
765
|
+
// .length, blind to ANSI escape codes) and every tab's own content is
|
|
766
|
+
// styled through theme.fg/theme.bold -- without this, Envelope pads
|
|
767
|
+
// each line against its own escape-code-inflated "length" instead of
|
|
768
|
+
// its real visible width, so the right border lands at a different
|
|
769
|
+
// column on every line depending on how much styling it carries.
|
|
638
770
|
const envelope = new Envelope({
|
|
639
|
-
title:
|
|
771
|
+
title: "packed",
|
|
640
772
|
borderStyle: "rounded",
|
|
641
773
|
style: (s) => theme.fg("border", s),
|
|
642
774
|
titleStyle: (s) => theme.bold(theme.fg("accent", s)),
|
|
643
775
|
measure,
|
|
644
776
|
});
|
|
645
|
-
const body = {
|
|
646
|
-
invalidate() { header.invalidate(); list.invalidate(); },
|
|
647
|
-
render(width: number): string[] {
|
|
648
|
-
return [...header.render(width), "", ...list.render(width)];
|
|
649
|
-
},
|
|
650
|
-
};
|
|
651
|
-
envelope.setContent(body);
|
|
652
777
|
|
|
653
778
|
return {
|
|
654
779
|
render(width: number): string[] {
|
|
655
|
-
envelope.
|
|
656
|
-
envelope.setContent(pendingDialog ?? body);
|
|
780
|
+
envelope.setContent(pendingDialog ?? tabbedContainer);
|
|
657
781
|
return envelope.render(width);
|
|
658
782
|
},
|
|
659
783
|
invalidate: () => envelope.invalidate(),
|
|
@@ -663,85 +787,24 @@ function renderPanel(ctx: ExtensionCommandContext, natives: Natives, initialRows
|
|
|
663
787
|
tui.requestRender();
|
|
664
788
|
return;
|
|
665
789
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
} else {
|
|
676
|
-
searchInput.handleInput(data);
|
|
677
|
-
applyFilter();
|
|
678
|
-
}
|
|
790
|
+
const activeKey = tabbedContainer.getActiveKey() as PackedTabKey;
|
|
791
|
+
const activeTab = tabByKey[activeKey];
|
|
792
|
+
// Each host-level key is checked against that tab's own capture flag
|
|
793
|
+
// independently -- conflating them would, e.g., let Find's always-on
|
|
794
|
+
// capturesHorizontalArrows() also swallow Escape into the query box
|
|
795
|
+
// instead of navigating back.
|
|
796
|
+
if (data === "\x1b" && !(activeTab.capturesEscape?.() ?? false)) {
|
|
797
|
+
if (activeKey !== "packages") tabbedContainer.setActive("packages");
|
|
798
|
+
else { done(undefined); return; }
|
|
679
799
|
tui.requestRender();
|
|
680
800
|
return;
|
|
681
801
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
break;
|
|
687
|
-
case "\x1b[B": // down
|
|
688
|
-
selectedIndex = (selectedIndex + 1) % Math.max(filtered.length, 1);
|
|
689
|
-
break;
|
|
690
|
-
case "\t":
|
|
691
|
-
mode = nextMode(mode);
|
|
692
|
-
applyFilter();
|
|
693
|
-
break;
|
|
694
|
-
case "/":
|
|
695
|
-
searchActive = true;
|
|
696
|
-
break;
|
|
697
|
-
case "r":
|
|
698
|
-
done({ type: "refresh" });
|
|
699
|
-
return;
|
|
700
|
-
case "s":
|
|
701
|
-
done({ type: "settings" });
|
|
702
|
-
return;
|
|
703
|
-
case "f":
|
|
704
|
-
done({ type: "find" });
|
|
705
|
-
return;
|
|
706
|
-
case "U":
|
|
707
|
-
void runUpdateAllInline();
|
|
708
|
-
return;
|
|
709
|
-
case "u": {
|
|
710
|
-
const row = filtered[selectedIndex];
|
|
711
|
-
if (row?.hasUpdate) void runRowActionInline({ type: "update", row });
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
case "x": {
|
|
715
|
-
const row = filtered[selectedIndex];
|
|
716
|
-
if (row) void runRowActionInline({ type: "remove", row });
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
case "d": {
|
|
720
|
-
const row = filtered[selectedIndex];
|
|
721
|
-
if (row) void runRowActionInline({ type: "disable", row });
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
case "c": {
|
|
725
|
-
const row = filtered[selectedIndex];
|
|
726
|
-
if (row) done({ type: "config", row });
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
case "\r": {
|
|
730
|
-
const row = filtered[selectedIndex];
|
|
731
|
-
if (!row) return;
|
|
732
|
-
void (async () => {
|
|
733
|
-
const choice = await showActionMenu(ctx, row);
|
|
734
|
-
if (choice === "update" || choice === "remove" || choice === "disable") void runRowActionInline({ type: choice, row });
|
|
735
|
-
else if (choice === "config") done({ type: "config", row });
|
|
736
|
-
})();
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
case "\x1b":
|
|
740
|
-
done(undefined);
|
|
741
|
-
return;
|
|
742
|
-
default:
|
|
743
|
-
return;
|
|
802
|
+
if ((data === "\x1b[C" || data === "\x1b[D") && !(activeTab.capturesHorizontalArrows?.() ?? false)) {
|
|
803
|
+
tabbedContainer.handleInput(data); // owns Left/Right cycling itself
|
|
804
|
+
tui.requestRender();
|
|
805
|
+
return;
|
|
744
806
|
}
|
|
807
|
+
activeTab.handleInput?.(data);
|
|
745
808
|
tui.requestRender();
|
|
746
809
|
},
|
|
747
810
|
};
|