@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 +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 +431 -342
- package/package.json +2 -2
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` --
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
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
|
|
3
|
-
* packages and install one. A
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
}
|
package/extension/src/index.ts
CHANGED
|
@@ -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
|
+
}
|