@danypops/pi-packed 0.16.0 → 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 CHANGED
@@ -10,13 +10,16 @@ The extension connects to Packed's authenticated user daemon and starts the pack
10
10
 
11
11
  ## Commands
12
12
 
13
- - `/packed` -- a floating overlay panel: every installed Pi package, with update availability. Mnemonics follow lazy.nvim's own convention (uppercase acts on every row, lowercase on the one under the cursor):
14
- - `u` / `U` -- update the selected package / update every outdated package, one combined confirmation and one reload. `U` shows a spinner inline next to the package currently updating, settling into a real ✓ or ✗ plus a short tail of that update's own captured output once it finishes -- the list stays visible throughout, nothing swaps to a separate screen. A reload is confirmed separately from the update itself -- decline it to defer: the update already happened, only picking it up in this Pi session is deferred until `/reload`. Every confirm in this flow -- approval and reload alike -- renders inline on this same panel (`y`/`n` keys), never a separate popup.
15
- - `x` -- remove the selected package.
16
- - `d` -- disable (or re-enable) the selected package's own extensions.
17
- - `c` -- jump to resource config for the selected package (skills, prompts, themes).
18
- - `f` -- find: search the npm registry for new Pi packages and install one.
19
- - `s` -- settings. `Enter` opens a smaller floating action menu with all of the above. `r` refreshes, `/` filters, `Tab` cycles view modes.
20
- - `/packed config` -- enable or disable individual extensions, skills, prompt templates, and themes declared by installed packages, per package, at global or project scope.
13
+ - `/packed` -- one floating overlay, four tabs (Packages/Find/Config/Settings), always shown in a persistent tab bar at the top -- `←`/`→` cycle between them, `Esc` returns to Packages from anywhere else (or closes the panel from Packages itself). Every approval and reload confirmation, on any tab, renders inline on this same panel (`y`/`n` keys), never a separate popup or native dialog.
14
+ - **Packages** (the default tab) -- every installed Pi package, with update availability. Mnemonics follow lazy.nvim's own convention (uppercase acts on every row, lowercase on the one under the cursor):
15
+ - `u` / `U` -- update the selected package / update every outdated package, one combined confirmation and one reload. `U` shows a spinner inline next to the package currently updating, settling into a real ✓ or ✗ plus a short tail of that update's own captured output once it finishes -- the list stays visible throughout, nothing swaps to a separate screen. A reload is confirmed separately from the update itself -- decline it to defer: the update already happened, only picking it up in this Pi session is deferred until `/reload`.
16
+ - `x` -- remove the selected package.
17
+ - `d` -- disable (or re-enable) the selected package's own extensions.
18
+ - `c` -- jump to the Config tab, scoped to the selected package.
19
+ - `f` -- jump to the Find tab. `s` -- jump to the Settings tab.
20
+ - `Enter` opens a smaller floating action menu with all of the above. `r` refreshes, `/` filters, `Tab` cycles view modes.
21
+ - **Find** -- search the npm registry for new Pi packages and install one.
22
+ - **Config** -- enable or disable individual extensions, skills, prompt templates, and themes declared by installed packages, per package, at global or project scope (`Tab` switches global/project). `/packed config` opens the panel landing directly on this tab.
23
+ - **Settings** -- change whether package mutations (install/update/remove/toggle) require confirmation.
21
24
  - `/packed setup plan [path] [--prune]` / `/packed setup apply [path] [--prune]` -- preview or apply a reproducible-environment manifest (`pi-setup.json`) against installed packages and profiles.
22
25
  - `/profile [name]` -- switch to a named Pi profile (provider, model, tools, instructions, theme), reading `~/.pi/agent/profiles.json` and a trusted project's own `.pi/profiles.json`. `pi --profile <name>` activates one at startup; `Ctrl+Shift+U` cycles through them.
@@ -1,27 +1,26 @@
1
1
  /**
2
- * discover.ts — /packed find: query the npm registry for installable Pi
3
- * packages and install one. A sub-flow like settings/config, reachable
4
- * from the packages panel via f and returning to it on close. Search
5
- * itself never mutates; only Install/Cancel (behind the standard
6
- * approval) does.
2
+ * discover.ts — /packed's Find tab: query the npm registry for installable
3
+ * Pi packages and install one. A real Component (not its own ctx.ui.custom
4
+ * overlay) so it plugs straight into TabbedContainer alongside
5
+ * Packages/Config/Settings on the same overlay -- it used to open a
6
+ * second, visually distinct screen (no Malevich Envelope, its own
7
+ * hand-rolled Container+DynamicBorder chrome), confirmed live as a real
8
+ * "opens a different TUI" complaint. Search itself never mutates; only
9
+ * Install (behind a quick inline confirm, then the standard approval
10
+ * every mutation surface requires) does.
7
11
  */
8
12
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
9
- import { DynamicBorder, rawKeyHint } from "@earendil-works/pi-coding-agent";
10
- import { Container, Input, Spacer, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
11
- import { Menu, type MenuItem } from "malevich-tui-components";
13
+ import { rawKeyHint } from "@earendil-works/pi-coding-agent";
14
+ import { Input, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
15
+ import type { Component } from "malevich-tui-components";
12
16
  import { shouldSearch } from "./discover-model.js";
13
17
  import type { Natives, PackageSummary } from "./packed.js";
14
18
  import { InstallServiceError } from "./packed.js";
15
19
  import { approvePackageOperation } from "./tools.js";
16
- import { menuTheme } from "./menu-theme.js";
20
+ import type { TabHost } from "./tab-host.js";
17
21
 
18
22
  const SEARCH_LIMIT = 20;
19
23
 
20
- interface FindPanelAction {
21
- type: "install" | "close";
22
- result?: PackageSummary;
23
- }
24
-
25
24
  export type InstallOutcome = "installed" | "cancelled" | "failed";
26
25
 
27
26
  /** Approve-then-install-then-reload, mirroring applyPackageChoice's own
@@ -53,141 +52,126 @@ export async function applyInstall(result: PackageSummary, natives: Natives, ctx
53
52
  }
54
53
  }
55
54
 
56
- async function showInstallMenu(ctx: ExtensionCommandContext, result: PackageSummary): Promise<boolean> {
57
- return ctx.ui.custom<boolean>(
58
- (_tui, theme, _kb, done) => {
59
- const items: MenuItem[] = [
60
- { label: `Install ${result.name}@${result.version}`, action: () => done(true) },
61
- { label: "Cancel", action: () => done(false) },
62
- ];
63
- return new Menu({ items, theme: menuTheme(theme), onClose: () => done(false) });
64
- },
65
- { overlay: true, overlayOptions: { width: 40, anchor: "center" } },
66
- );
67
- }
55
+ interface Theme { fg(color: string, s: string): string; bold(s: string): string; }
56
+
57
+ /** /packed's Find tab -- a real Component. Its query box always captures
58
+ * free text (isCapturingInput() is unconditionally true), unlike
59
+ * Packages/Config's toggleable search: there's no "browse mode" here to
60
+ * fall back to, searching is the whole point of this tab. */
61
+ export class FindTab implements Component {
62
+ private readonly queryInput = new Input();
63
+ private results: PackageSummary[] = [];
64
+ private lastSearchedQuery: string | undefined;
65
+ private selectedIndex = 0;
66
+ private searching = false;
67
+ private error: string | undefined;
68
+ private busy = false;
69
+ private readonly maxVisible = 15;
70
+
71
+ constructor(
72
+ private readonly natives: Natives,
73
+ private readonly host: TabHost,
74
+ private readonly theme: Theme,
75
+ ) {}
68
76
 
69
- export async function showDiscoverPanel(ctx: ExtensionCommandContext, natives: Natives): Promise<void> {
70
- if (!ctx.hasUI) {
71
- ctx.ui.notify("/packed find requires interactive mode", "warning");
72
- return;
77
+ /** Find's query box is always in text-edit mode (no separate toggle like
78
+ * Packages/Config's `/`) -- Left/Right must stay cursor movement, never
79
+ * the host's own tab-cycling. Escape, though, is only captured while an
80
+ * install is actually in flight (a genuine "don't let go" moment); no one
81
+ * types a literal Escape byte into a search query on purpose, so it's
82
+ * otherwise the host's own "back to Packages" to handle. */
83
+ capturesHorizontalArrows(): boolean {
84
+ return true;
73
85
  }
74
86
 
75
- for (;;) {
76
- const action = await renderDiscoverPanel(ctx, natives);
77
- if (action.type === "close") return;
78
- if (!action.result) continue;
79
- const install = await showInstallMenu(ctx, action.result);
80
- if (!install) continue;
81
- const outcome = await applyInstall(action.result, natives, ctx);
82
- if (outcome === "installed") return; // ctx.reload() already replaced the session
87
+ capturesEscape(): boolean {
88
+ return this.busy;
83
89
  }
84
- }
85
90
 
86
- function renderDiscoverPanel(ctx: ExtensionCommandContext, natives: Natives): Promise<FindPanelAction> {
87
- return ctx.ui.custom<FindPanelAction>((tui, theme, _kb, done) => {
88
- const queryInput = new Input();
89
- let results: PackageSummary[] = [];
90
- let lastSearchedQuery: string | undefined;
91
- let selectedIndex = 0;
92
- let searching = false;
93
- let error: string | undefined;
94
- const maxVisible = 15;
91
+ invalidate(): void {}
95
92
 
96
- async function runSearch(): Promise<void> {
97
- const query = queryInput.getValue().trim();
98
- if (!query) return;
99
- searching = true;
100
- error = undefined;
101
- tui.requestRender();
102
- try {
103
- const response = await natives.search(query, SEARCH_LIMIT);
104
- results = response.results;
105
- lastSearchedQuery = queryInput.getValue();
106
- selectedIndex = 0;
107
- } catch (e) {
108
- error = e instanceof Error ? e.message : String(e);
109
- results = [];
110
- } finally {
111
- searching = false;
112
- tui.requestRender();
113
- }
93
+ render(width: number): string[] {
94
+ const { theme } = this;
95
+ const hint = rawKeyHint("enter", "search/install");
96
+ const status = this.searching ? "searching…" : this.error ? theme.fg("error", this.error) : `${this.results.length} result(s)`;
97
+ const spacing = Math.max(1, width - visibleWidth(hint) - visibleWidth(status));
98
+ const line1 = truncateToWidth(`${hint}${" ".repeat(spacing)}`, width, "") + status;
99
+ const lines = [line1, ...this.queryInput.render(width), ""];
100
+ if (this.results.length === 0) {
101
+ lines.push(theme.fg("muted", this.searching ? " …" : " Type a query and press enter to search npm"));
102
+ return lines;
103
+ }
104
+ const start = Math.max(0, Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.results.length - this.maxVisible));
105
+ const end = Math.min(start + this.maxVisible, this.results.length);
106
+ for (let i = start; i < end; i++) {
107
+ const result = this.results[i]!;
108
+ const selected = i === this.selectedIndex;
109
+ const cursor = selected ? theme.fg("accent", "❯") : " ";
110
+ const name = selected ? theme.bold(result.name) : result.name;
111
+ const ver = theme.fg("dim", `@${result.version}`);
112
+ const description = result.description ? theme.fg("muted", ` — ${result.description}`) : "";
113
+ lines.push(truncateToWidth(`${cursor} ${name}${ver}${description}`, width, ""));
114
114
  }
115
+ return lines;
116
+ }
115
117
 
116
- const header = {
117
- invalidate() {},
118
- render(width: number): string[] {
119
- const title = theme.bold("Find packages");
120
- const hint = rawKeyHint("enter", "search/install") + theme.fg("muted", " · ") + rawKeyHint("esc", "back");
121
- const spacing = Math.max(1, width - visibleWidth(title) - visibleWidth(hint));
122
- const line1 = truncateToWidth(`${title}${" ".repeat(spacing)}`, width, "") + hint;
123
- const status = searching ? "searching…" : error ? theme.fg("error", error) : `${results.length} result(s)`;
124
- const line2 = truncateToWidth(theme.fg("muted", status), width, "");
125
- return [line1, line2];
126
- },
127
- };
118
+ handleInput(data: string): void {
119
+ if (this.busy) return;
120
+ switch (data) {
121
+ case "\x1b[A":
122
+ if (this.results.length > 0) this.selectedIndex = (this.selectedIndex - 1 + this.results.length) % this.results.length;
123
+ break;
124
+ case "\x1b[B":
125
+ if (this.results.length > 0) this.selectedIndex = (this.selectedIndex + 1) % this.results.length;
126
+ break;
127
+ case "\r":
128
+ if (shouldSearch(this.queryInput.getValue(), this.lastSearchedQuery, this.results.length > 0)) void this.runSearch();
129
+ else void this.installSelected();
130
+ return;
131
+ default:
132
+ this.queryInput.handleInput(data);
133
+ break;
134
+ }
135
+ this.host.requestRender();
136
+ }
128
137
 
129
- const list = {
130
- invalidate() {},
131
- render(width: number): string[] {
132
- const lines = [...queryInput.render(width), ""];
133
- if (results.length === 0) {
134
- lines.push(theme.fg("muted", searching ? " …" : " Type a query and press enter to search npm"));
135
- return lines;
136
- }
137
- const start = Math.max(0, Math.min(selectedIndex - Math.floor(maxVisible / 2), results.length - maxVisible));
138
- const end = Math.min(start + maxVisible, results.length);
139
- for (let i = start; i < end; i++) {
140
- const result = results[i]!;
141
- const selected = i === selectedIndex;
142
- const cursor = selected ? theme.fg("accent", "❯") : " ";
143
- const name = selected ? theme.bold(result.name) : result.name;
144
- const ver = theme.fg("dim", `@${result.version}`);
145
- const description = result.description ? theme.fg("muted", ` — ${result.description}`) : "";
146
- lines.push(truncateToWidth(`${cursor} ${name}${ver}${description}`, width, ""));
147
- }
148
- return lines;
149
- },
150
- };
138
+ private async runSearch(): Promise<void> {
139
+ const query = this.queryInput.getValue().trim();
140
+ if (!query) return;
141
+ this.searching = true;
142
+ this.error = undefined;
143
+ this.host.requestRender();
144
+ try {
145
+ const response = await this.natives.search(query, SEARCH_LIMIT);
146
+ this.results = response.results;
147
+ this.lastSearchedQuery = this.queryInput.getValue();
148
+ this.selectedIndex = 0;
149
+ } catch (e) {
150
+ this.error = e instanceof Error ? e.message : String(e);
151
+ this.results = [];
152
+ } finally {
153
+ this.searching = false;
154
+ this.host.requestRender();
155
+ }
156
+ }
151
157
 
152
- const border = () => new DynamicBorder((s) => theme.fg("border", s));
153
- const container = new Container();
154
- container.addChild(new Spacer(1));
155
- container.addChild(border());
156
- container.addChild(new Spacer(1));
157
- container.addChild(header);
158
- container.addChild(new Spacer(1));
159
- container.addChild(list);
160
- container.addChild(new Spacer(1));
161
- container.addChild(border());
158
+ private async installSelected(): Promise<void> {
159
+ const result = this.results[this.selectedIndex];
160
+ if (!result) return;
161
+ this.busy = true;
162
+ this.host.requestRender();
163
+ try {
164
+ const confirmed = await this.host.inlineCtx.ui.confirm(`Install ${result.name}@${result.version}`, "Search itself never mutates -- this is the first of two confirmations before anything installs.");
165
+ if (!confirmed) return;
166
+ const outcome = await applyInstall(result, this.natives, this.host.inlineCtx);
167
+ if (outcome === "installed") this.host.onSessionReplaced();
168
+ } finally {
169
+ this.busy = false;
170
+ this.host.requestRender();
171
+ }
172
+ }
173
+ }
162
174
 
163
- return {
164
- render: (width: number) => container.render(width),
165
- invalidate: () => container.invalidate(),
166
- handleInput(data: string) {
167
- switch (data) {
168
- case "\x1b[A": // up
169
- if (results.length > 0) selectedIndex = (selectedIndex - 1 + results.length) % results.length;
170
- break;
171
- case "\x1b[B": // down
172
- if (results.length > 0) selectedIndex = (selectedIndex + 1) % results.length;
173
- break;
174
- case "\r":
175
- if (shouldSearch(queryInput.getValue(), lastSearchedQuery, results.length > 0)) {
176
- void runSearch();
177
- } else {
178
- const result = results[selectedIndex];
179
- if (result) done({ type: "install", result });
180
- }
181
- return;
182
- case "\x1b":
183
- done({ type: "close" });
184
- return;
185
- default:
186
- queryInput.handleInput(data);
187
- break;
188
- }
189
- tui.requestRender();
190
- },
191
- };
192
- });
175
+ export function createFindTab(natives: Natives, host: TabHost, theme: Theme): FindTab {
176
+ return new FindTab(natives, host, theme);
193
177
  }
@@ -28,7 +28,7 @@ export default async function (pi: ExtensionAPI) {
28
28
  description: "Browse and manage installed Pi packages -- u/U update, x remove, d disable, c config, f find, s settings -- or run setup plan/apply or config directly",
29
29
  handler: async (args, ctx) => {
30
30
  if (await handleSetupCommand(args, ctx, natives)) return;
31
- if (await handleResourceConfigCommand(args, ctx, natives)) return;
31
+ if (await handleResourceConfigCommand(args, ctx, natives, showPackedPanel)) return;
32
32
  await showPackedPanel(ctx, natives);
33
33
  },
34
34
  });
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
- import type { DialogTheme, MenuTheme } from "malevich-tui-components";
2
+ import type { DialogTheme, MenuTheme, TabBarTheme } from "malevich-tui-components";
3
3
 
4
4
  /** Maps Pi's own Theme onto Malevich's Menu -- the one place this mapping
5
5
  * exists, shared by every ctx.ui.custom overlay menu in this extension. */
@@ -25,3 +25,13 @@ export function dialogTheme(theme: Theme): DialogTheme {
25
25
  dim: (s) => theme.fg("muted", s),
26
26
  };
27
27
  }
28
+
29
+ /** Maps Pi's own Theme onto Malevich's TabbedContainer -- the persistent
30
+ * Packages/Find/Config/Settings tab bar at the top of /packed's one
31
+ * overlay, replacing what used to be four separately-opened screens. */
32
+ export function tabBarTheme(theme: Theme): TabBarTheme {
33
+ return {
34
+ tab: (s) => theme.fg("muted", s),
35
+ activeTab: (s) => theme.bold(theme.fg("accent", s)),
36
+ };
37
+ }