@luxass/pi-personal 0.1.1 → 0.1.3
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 -1
- package/package.json +8 -6
- package/src/custom-header.ts +2 -144
- package/src/dependency-policy.ts +16 -0
- package/src/resources/diagnostics.ts +34 -0
- package/src/resources/dialog.ts +312 -0
- package/src/resources/extensions.ts +100 -0
- package/src/resources/index.ts +28 -0
- package/src/resources/key-labels.ts +27 -0
- package/src/resources/loader-hook.ts +31 -0
- package/src/resources/snapshot.ts +80 -0
- package/src/resources/tools.ts +37 -0
package/README.md
CHANGED
|
@@ -12,6 +12,16 @@ pi install npm:@luxass/pi-personal
|
|
|
12
12
|
|
|
13
13
|
The custom header pairs an ASCII terminal-robot mascot with the project, model, and current thinking level. A rounded frame, vertical padding, and a separate shortcut row give it room on wide terminals. Narrow panes use a compact layout and drop shortcut hints before truncating them. The thinking shortcut follows your Pi keybindings.
|
|
14
14
|
|
|
15
|
-
Run `/resources` to
|
|
15
|
+
Run `/resources` to browse the Tools, Context, Skills, Extensions, and Diagnostics tabs. The dialog opens on Tools. Each tool shows its description, active or inactive status, and registered exposure. Exposure controls how Pi can reach a tool. Inactive codemode and deferred tools remain callable from other tools. The dialog does not show per-request changes that hide tool declarations.
|
|
16
|
+
|
|
17
|
+
Skills use compact columns when space allows. Names remain complete, and narrow terminals use a single column. The Extensions tab groups entries into Local, Packages, and Built-in sections using Pi’s source metadata. Extension labels are compact by default. Labels that match retain distinguishing source information. Packages show one row each, with an extension count when they contain several entries. Press `e` in the Extensions tab to show or hide source details and package entry paths. Home-directory paths use `~`. The Diagnostics tab lists loader errors, warnings, and name collisions for extensions, skills, prompts, and themes.
|
|
18
|
+
|
|
19
|
+
Use Left, Right, Tab, or Shift+Tab to switch tabs. Keys `1`–`5` jump directly to a tab. In fullscreen mode, you can also click tabs and scroll inside the dialog with a mouse wheel or trackpad. Use Up, Down, Page Up, Page Down, Home, and End to scroll in either terminal mode. Use your configured confirm or cancel keys to close, or press `q`. The default confirm and cancel keys are Enter and Esc. The dialog’s close and scroll hints show readable labels for the primary configured keys. All configured alternatives remain available.
|
|
20
|
+
|
|
21
|
+
The resources command loads separately from the custom header within this package. Context files and skills come directly from Pi’s resource loader. Context includes loaded instruction files and system-prompt sources in Pi’s loading order. The Extensions tab reads Pi’s loaded extension list, including event-only extensions. It omits hidden entries, like Pi’s startup display.
|
|
22
|
+
|
|
23
|
+
This uses an unsupported hook that temporarily intercepts `DefaultResourceLoader.getExtensions()` to capture the active loader. The hook restores the original method after capture or when the extension runtime shuts down. Pi updates can break this hook. If capture fails, `/resources` reports an error instead of showing an inferred extension list.
|
|
24
|
+
|
|
25
|
+
The dependency policy tells the model to reuse existing code, installed dependencies, and platform APIs first. It requires explicit user approval before adding, replacing, or upgrading dependencies. Routine installs of existing dependencies remain allowed through Socket Firewall. This is a model instruction, not an enforced approval gate.
|
|
16
26
|
|
|
17
27
|
The package also includes Crow provider support, compaction continuation, Git and package-manager interceptors, and a worker configuration guard. These defaults suit one workflow and are meant to be edited in place rather than configured through settings.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/pi-personal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Personal Pi extensions collected in one package, tuned to a single workflow.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"personal",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/luxass/
|
|
14
|
-
"directory": "packages/personal"
|
|
13
|
+
"url": "https://github.com/luxass/agent-extensions",
|
|
14
|
+
"directory": "packages/pi-personal"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"src",
|
|
@@ -28,19 +28,21 @@
|
|
|
28
28
|
"@earendil-works/pi-tui": "*"
|
|
29
29
|
},
|
|
30
30
|
"pi": {
|
|
31
|
-
"image": "https://raw.githubusercontent.com/luxass/
|
|
31
|
+
"image": "https://raw.githubusercontent.com/luxass/agent-extensions/main/packages/pi-personal/docs/cover.png",
|
|
32
32
|
"extensions": [
|
|
33
33
|
"./src/continue-after-compaction.ts",
|
|
34
|
+
"./src/dependency-policy.ts",
|
|
34
35
|
"./src/git-interceptor.ts",
|
|
35
36
|
"./src/package-manager-interceptor.ts",
|
|
36
37
|
"./src/worker-configuration-guard.ts",
|
|
37
38
|
"./src/custom-header.ts",
|
|
39
|
+
"./src/resources/index.ts",
|
|
38
40
|
"./src/crow/index.ts"
|
|
39
41
|
]
|
|
40
42
|
},
|
|
41
43
|
"scripts": {
|
|
42
|
-
"lint": "oxlint
|
|
43
|
-
"lint:fix": "oxlint --fix
|
|
44
|
+
"lint": "oxlint .",
|
|
45
|
+
"lint:fix": "oxlint --fix .",
|
|
44
46
|
"fmt": "oxfmt .",
|
|
45
47
|
"fmt:check": "oxfmt --check .",
|
|
46
48
|
"typecheck": "tsc -p tsconfig.json"
|
package/src/custom-header.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readdir } from "node:fs/promises";
|
|
3
|
-
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import { basename } from "node:path";
|
|
5
2
|
|
|
6
3
|
import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
7
4
|
import { keyText, VERSION } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import {
|
|
9
|
-
Key,
|
|
10
|
-
matchesKey,
|
|
11
|
-
truncateToWidth,
|
|
12
|
-
visibleWidth,
|
|
13
|
-
wrapTextWithAnsi,
|
|
14
|
-
} from "@earendil-works/pi-tui";
|
|
5
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
15
6
|
|
|
16
7
|
const HEADER_MAX_WIDTH = 88;
|
|
17
8
|
const LOGO_MIN_WIDTH = 64;
|
|
@@ -25,72 +16,11 @@ const PI_MASCOT = [
|
|
|
25
16
|
" / \\ ",
|
|
26
17
|
];
|
|
27
18
|
|
|
28
|
-
type ResourceSnapshot = {
|
|
29
|
-
context: string[];
|
|
30
|
-
skills: string[];
|
|
31
|
-
extensions: string[];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
19
|
function fit(text: string, width: number): string {
|
|
35
20
|
const clipped = truncateToWidth(text, width, "…");
|
|
36
21
|
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
37
22
|
}
|
|
38
23
|
|
|
39
|
-
function resourceName(path: string): string {
|
|
40
|
-
const parts = path.replaceAll("\\", "/").split("/");
|
|
41
|
-
const file = parts.at(-1) ?? path;
|
|
42
|
-
if (file === "index.ts" || file === "index.js") return parts.at(-2) ?? file;
|
|
43
|
-
return file.replace(/\.[cm]?[jt]sx?$/i, "");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function collectResources(
|
|
47
|
-
pi: ExtensionAPI,
|
|
48
|
-
ctx: ExtensionContext,
|
|
49
|
-
): Promise<ResourceSnapshot> {
|
|
50
|
-
const extensionPaths = new Set<string>();
|
|
51
|
-
try {
|
|
52
|
-
const extensionDir = dirname(fileURLToPath(import.meta.url));
|
|
53
|
-
for (const entry of await readdir(extensionDir, { withFileTypes: true })) {
|
|
54
|
-
if (entry.isFile() && /\.[cm]?[jt]sx?$/i.test(entry.name)) {
|
|
55
|
-
extensionPaths.add(join(extensionDir, entry.name));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} catch {
|
|
59
|
-
// The extension directory may not be readable.
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (const command of pi.getCommands()) {
|
|
63
|
-
if (command.source === "extension") extensionPaths.add(command.sourceInfo.path);
|
|
64
|
-
}
|
|
65
|
-
for (const tool of pi.getAllTools()) {
|
|
66
|
-
if (tool.sourceInfo.source !== "builtin" && tool.sourceInfo.source !== "sdk") {
|
|
67
|
-
extensionPaths.add(tool.sourceInfo.path);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const context: string[] = [];
|
|
72
|
-
let directory = resolve(ctx.cwd);
|
|
73
|
-
while (true) {
|
|
74
|
-
for (const filename of ["AGENTS.md", "CLAUDE.md"]) {
|
|
75
|
-
const path = join(directory, filename);
|
|
76
|
-
if (existsSync(path)) context.push(relative(ctx.cwd, path) || filename);
|
|
77
|
-
}
|
|
78
|
-
const parent = dirname(directory);
|
|
79
|
-
if (parent === directory) break;
|
|
80
|
-
directory = parent;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
context: context.toSorted(),
|
|
85
|
-
skills: pi
|
|
86
|
-
.getCommands()
|
|
87
|
-
.filter((command) => command.source === "skill")
|
|
88
|
-
.map((command) => command.name.replace(/^skill:/, ""))
|
|
89
|
-
.toSorted(),
|
|
90
|
-
extensions: [...extensionPaths].map(resourceName).filter(Boolean).toSorted(),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
24
|
interface HeaderOptions {
|
|
95
25
|
theme: Theme;
|
|
96
26
|
width: number;
|
|
@@ -200,47 +130,6 @@ export function renderHeader({
|
|
|
200
130
|
];
|
|
201
131
|
}
|
|
202
132
|
|
|
203
|
-
function renderResources(snapshot: ResourceSnapshot, theme: Theme, width: number): string[] {
|
|
204
|
-
if (width < 6) return [fit("Resources", width)];
|
|
205
|
-
|
|
206
|
-
const panelWidth = Math.min(86, width);
|
|
207
|
-
const contentWidth = panelWidth - 2;
|
|
208
|
-
const border = (text: string) => theme.fg("borderAccent", text);
|
|
209
|
-
const heading = (text: string) => theme.fg("mdHeading", theme.bold(text));
|
|
210
|
-
const muted = (text: string) => theme.fg("muted", text);
|
|
211
|
-
const dim = (text: string) => theme.fg("dim", text);
|
|
212
|
-
const accent = (text: string) => theme.fg("accent", text);
|
|
213
|
-
const line = (text = "") => `${border("│")}${fit(text, contentWidth)}${border("│")}`;
|
|
214
|
-
const lines = [
|
|
215
|
-
border(`╭${"─".repeat(panelWidth - 2)}╮`),
|
|
216
|
-
line(`${accent("π")} ${heading("Resources")}`),
|
|
217
|
-
line(dim("Detected context, skill commands, and extensions")),
|
|
218
|
-
line(),
|
|
219
|
-
];
|
|
220
|
-
|
|
221
|
-
const sections: Array<[string, string[], string]> = [
|
|
222
|
-
["Context", snapshot.context, "✓"],
|
|
223
|
-
["Skills", snapshot.skills, "•"],
|
|
224
|
-
["Extensions", snapshot.extensions, "•"],
|
|
225
|
-
];
|
|
226
|
-
for (const [label, items, marker] of sections) {
|
|
227
|
-
lines.push(line(heading(`${label} · ${items.length}`)));
|
|
228
|
-
const entries = wrapTextWithAnsi(
|
|
229
|
-
items.length > 0 ? items.join(", ") : "none detected",
|
|
230
|
-
Math.max(1, contentWidth - 4),
|
|
231
|
-
);
|
|
232
|
-
for (const [index, entry] of entries.entries()) {
|
|
233
|
-
const prefix = index === 0 ? ` ${marker} ` : " ";
|
|
234
|
-
lines.push(line(`${index === 0 ? accent(prefix) : dim(prefix)}${muted(entry)}`));
|
|
235
|
-
}
|
|
236
|
-
lines.push(line());
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
lines.push(line(dim("Press Esc, Enter, or q to close")));
|
|
240
|
-
lines.push(border(`╰${"─".repeat(panelWidth - 2)}╯`));
|
|
241
|
-
return lines;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
133
|
export default function (pi: ExtensionAPI) {
|
|
245
134
|
pi.on("session_start", (_event, ctx) => {
|
|
246
135
|
if (ctx.mode !== "tui") return;
|
|
@@ -258,35 +147,4 @@ export default function (pi: ExtensionAPI) {
|
|
|
258
147
|
invalidate() {},
|
|
259
148
|
}));
|
|
260
149
|
});
|
|
261
|
-
|
|
262
|
-
pi.registerCommand("resources", {
|
|
263
|
-
description: "Show detected context, skill commands, and extensions",
|
|
264
|
-
handler: async (_args, ctx) => {
|
|
265
|
-
if (ctx.mode !== "tui") return;
|
|
266
|
-
const resources = await collectResources(pi, ctx);
|
|
267
|
-
|
|
268
|
-
await ctx.ui.custom<void>(
|
|
269
|
-
(tui, theme, _keybindings, done) => ({
|
|
270
|
-
render: (width: number) => renderResources(resources, theme, width),
|
|
271
|
-
handleInput: (data: string) => {
|
|
272
|
-
if (matchesKey(data, Key.escape) || matchesKey(data, Key.enter) || data === "q") {
|
|
273
|
-
done();
|
|
274
|
-
}
|
|
275
|
-
tui.requestRender();
|
|
276
|
-
},
|
|
277
|
-
invalidate() {},
|
|
278
|
-
}),
|
|
279
|
-
{
|
|
280
|
-
overlay: true,
|
|
281
|
-
overlayOptions: {
|
|
282
|
-
anchor: "center",
|
|
283
|
-
width: "70%",
|
|
284
|
-
minWidth: 46,
|
|
285
|
-
maxHeight: "80%",
|
|
286
|
-
margin: 2,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
);
|
|
290
|
-
},
|
|
291
|
-
});
|
|
292
150
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
const POLICY = `Dependency policy:
|
|
4
|
+
Use existing project code, installed dependencies, and platform APIs first.
|
|
5
|
+
Do not add, replace, or upgrade dependencies unless the user explicitly requests or approves the specific dependency change.
|
|
6
|
+
This applies to runtime, development, optional, and peer dependencies, including changes through commands, manifests, lockfiles, or workspace catalogs.
|
|
7
|
+
Before requesting approval, name the proposed package and explain what it solves, why existing options are insufficient, and its trade-offs.
|
|
8
|
+
A request to implement a feature is not approval to add dependencies. Getting stuck is not an exception.
|
|
9
|
+
Installing dependencies already declared in the project is allowed when it does not change the declared dependency choices or upgrade resolved versions.
|
|
10
|
+
Follow the existing Socket Firewall requirement for package installation commands.`;
|
|
11
|
+
|
|
12
|
+
export default function (pi: ExtensionAPI) {
|
|
13
|
+
pi.on("before_agent_start", (event) => {
|
|
14
|
+
event.systemPromptOptions.sections.dependency_policy = POLICY;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
import type { LoaderDiagnostic } from "./snapshot.ts";
|
|
5
|
+
|
|
6
|
+
export function renderDiagnostics(
|
|
7
|
+
diagnostics: LoaderDiagnostic[],
|
|
8
|
+
theme: Theme,
|
|
9
|
+
width: number,
|
|
10
|
+
): string[] {
|
|
11
|
+
if (diagnostics.length === 0) return [theme.fg("muted", "No loader errors or warnings.")];
|
|
12
|
+
|
|
13
|
+
const lines: string[] = [];
|
|
14
|
+
const row = (text: string, color: "text" | "dim" | "warning" | "error", indent = 0) => {
|
|
15
|
+
for (const line of wrapTextWithAnsi(text, Math.max(1, width - indent))) {
|
|
16
|
+
lines.push(" ".repeat(indent) + theme.fg(color, line));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
for (const diagnostic of diagnostics) {
|
|
20
|
+
row(
|
|
21
|
+
diagnostic.resource + " · " + diagnostic.type,
|
|
22
|
+
diagnostic.type === "error" ? "error" : "warning",
|
|
23
|
+
);
|
|
24
|
+
row(diagnostic.message, "text", 2);
|
|
25
|
+
if (diagnostic.path !== undefined) row(diagnostic.path, "dim", 2);
|
|
26
|
+
if (diagnostic.collision !== undefined) {
|
|
27
|
+
row("Name: " + diagnostic.collision.name, "dim", 2);
|
|
28
|
+
row("Used: " + diagnostic.collision.winnerPath, "dim", 2);
|
|
29
|
+
row("Ignored: " + diagnostic.collision.loserPath, "dim", 2);
|
|
30
|
+
}
|
|
31
|
+
lines.push("");
|
|
32
|
+
}
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
isKeyRelease,
|
|
4
|
+
Key,
|
|
5
|
+
matchesKey,
|
|
6
|
+
ScrollView,
|
|
7
|
+
truncateToWidth,
|
|
8
|
+
type TuiMouseEvent,
|
|
9
|
+
type TuiMouseEventResult,
|
|
10
|
+
visibleWidth,
|
|
11
|
+
wrapTextWithAnsi,
|
|
12
|
+
} from "@earendil-works/pi-tui";
|
|
13
|
+
|
|
14
|
+
import { renderDiagnostics } from "./diagnostics.ts";
|
|
15
|
+
import { renderExtensions } from "./extensions.ts";
|
|
16
|
+
import { keyLabels } from "./key-labels.ts";
|
|
17
|
+
import type { ResourceSnapshot } from "./snapshot.ts";
|
|
18
|
+
import { renderTools } from "./tools.ts";
|
|
19
|
+
|
|
20
|
+
function fit(text: string, width: number): string {
|
|
21
|
+
const clipped = truncateToWidth(text, width, "…");
|
|
22
|
+
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const RESOURCE_TABS = ["Tools", "Context", "Skills", "Extensions", "Diagnostics"] as const;
|
|
26
|
+
type ResourceTab = (typeof RESOURCE_TABS)[number];
|
|
27
|
+
|
|
28
|
+
function tabCount(snapshot: ResourceSnapshot, tab: ResourceTab): number {
|
|
29
|
+
if (tab === "Tools") return snapshot.tools.length;
|
|
30
|
+
if (tab === "Context") return snapshot.context.length;
|
|
31
|
+
if (tab === "Skills") return snapshot.skills.length;
|
|
32
|
+
if (tab === "Extensions") return snapshot.extensions.length;
|
|
33
|
+
return snapshot.diagnostics.length;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function renderResourceBody(
|
|
37
|
+
snapshot: ResourceSnapshot,
|
|
38
|
+
tab: ResourceTab,
|
|
39
|
+
theme: Theme,
|
|
40
|
+
width: number,
|
|
41
|
+
extensionDetails: boolean,
|
|
42
|
+
): string[] {
|
|
43
|
+
const lines: string[] = [];
|
|
44
|
+
const wrap = (text: string, indent: number, color: "text" | "muted" | "dim") => {
|
|
45
|
+
for (const entry of wrapTextWithAnsi(text, Math.max(1, width - indent))) {
|
|
46
|
+
lines.push(" ".repeat(indent) + theme.fg(color, entry));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (tab === "Tools") return renderTools(snapshot.tools, theme, width);
|
|
50
|
+
if (tab === "Extensions")
|
|
51
|
+
return renderExtensions(snapshot.extensions, theme, width, extensionDetails);
|
|
52
|
+
if (tab === "Diagnostics") return renderDiagnostics(snapshot.diagnostics, theme, width);
|
|
53
|
+
|
|
54
|
+
const items = tab === "Context" ? snapshot.context : snapshot.skills;
|
|
55
|
+
if (items.length === 0) {
|
|
56
|
+
wrap("None loaded.", 0, "muted");
|
|
57
|
+
return lines;
|
|
58
|
+
}
|
|
59
|
+
if (tab === "Context") {
|
|
60
|
+
for (const item of items) wrap(item, 0, "text");
|
|
61
|
+
return lines;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Read down each column, like a directory listing. Keep every name intact.
|
|
65
|
+
const gap = 3;
|
|
66
|
+
const longest = Math.max(...items.map(visibleWidth));
|
|
67
|
+
const columns = Math.max(1, Math.min(3, Math.floor((width + gap) / (longest + gap))));
|
|
68
|
+
if (columns === 1) {
|
|
69
|
+
for (const item of items) wrap(item, 0, "text");
|
|
70
|
+
return lines;
|
|
71
|
+
}
|
|
72
|
+
const cellWidth = Math.floor((width - gap * (columns - 1)) / columns);
|
|
73
|
+
const rows = Math.ceil(items.length / columns);
|
|
74
|
+
for (let row = 0; row < rows; row++) {
|
|
75
|
+
const cells: string[] = [];
|
|
76
|
+
for (let column = 0; column < columns; column++) {
|
|
77
|
+
const item = items[column * rows + row];
|
|
78
|
+
cells.push(fit(theme.fg("text", item ?? ""), cellWidth));
|
|
79
|
+
}
|
|
80
|
+
lines.push(cells.join(" ".repeat(gap)));
|
|
81
|
+
}
|
|
82
|
+
return lines;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function showResources(
|
|
86
|
+
ctx: ExtensionContext,
|
|
87
|
+
resources: ResourceSnapshot,
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
await ctx.ui.custom<void>(
|
|
90
|
+
(tui, theme, keybindings, done) => {
|
|
91
|
+
let tab = 0;
|
|
92
|
+
let extensionDetails = false;
|
|
93
|
+
let page = 1;
|
|
94
|
+
let mouseWidth = 0;
|
|
95
|
+
let targets: { index: number; start: number; end: number }[] = [];
|
|
96
|
+
const scroll = new ScrollView(
|
|
97
|
+
{
|
|
98
|
+
render: (width) =>
|
|
99
|
+
renderResourceBody(resources, RESOURCE_TABS[tab]!, theme, width, extensionDetails),
|
|
100
|
+
invalidate() {},
|
|
101
|
+
},
|
|
102
|
+
{ scrollbar: "hidden" },
|
|
103
|
+
);
|
|
104
|
+
const switchTab = (index: number) => {
|
|
105
|
+
tab = (index + RESOURCE_TABS.length) % RESOURCE_TABS.length;
|
|
106
|
+
scroll.scrollToStart();
|
|
107
|
+
tui.requestRender();
|
|
108
|
+
};
|
|
109
|
+
const navigation = (width: number): string[] => {
|
|
110
|
+
targets = [];
|
|
111
|
+
const available = width - (RESOURCE_TABS.length - 1);
|
|
112
|
+
const size = Math.floor(available / RESOURCE_TABS.length);
|
|
113
|
+
const remainder = available % RESOURCE_TABS.length;
|
|
114
|
+
let column = 2;
|
|
115
|
+
const cells = RESOURCE_TABS.map((label, index) => {
|
|
116
|
+
const cellWidth = size + (index < remainder ? 1 : 0);
|
|
117
|
+
const full = label + " " + tabCount(resources, label);
|
|
118
|
+
const text = visibleWidth(full) <= cellWidth ? full : label;
|
|
119
|
+
const fitted = truncateToWidth(text, cellWidth, "…");
|
|
120
|
+
const padding = cellWidth - visibleWidth(fitted);
|
|
121
|
+
const centered =
|
|
122
|
+
" ".repeat(Math.floor(padding / 2)) + fitted + " ".repeat(Math.ceil(padding / 2));
|
|
123
|
+
targets.push({ index, start: column, end: column + cellWidth });
|
|
124
|
+
column += cellWidth + 1;
|
|
125
|
+
const active = index === tab;
|
|
126
|
+
return {
|
|
127
|
+
title: active ? theme.bold(theme.fg("accent", centered)) : theme.fg("muted", centered),
|
|
128
|
+
rail: theme.fg(
|
|
129
|
+
active ? "accent" : "borderMuted",
|
|
130
|
+
(active ? "━" : "─").repeat(cellWidth),
|
|
131
|
+
),
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
return [
|
|
135
|
+
cells.map((cell) => cell.title).join(" "),
|
|
136
|
+
cells.map((cell) => cell.rail).join(theme.fg("borderMuted", "─")),
|
|
137
|
+
];
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
render: (width: number) => {
|
|
141
|
+
mouseWidth = width;
|
|
142
|
+
targets = [];
|
|
143
|
+
const closeKeys = keyLabels([
|
|
144
|
+
...keybindings.getKeys("tui.select.cancel").slice(0, 1),
|
|
145
|
+
...keybindings.getKeys("tui.select.confirm").slice(0, 1),
|
|
146
|
+
"q",
|
|
147
|
+
]);
|
|
148
|
+
const height = Math.min(28, Math.floor(tui.terminal.rows * 0.8), tui.terminal.rows - 4);
|
|
149
|
+
if (width < 24 || height < 10) {
|
|
150
|
+
return [fit("Resize to browse · " + closeKeys + " close", Math.max(0, width))];
|
|
151
|
+
}
|
|
152
|
+
const inner = width - 4;
|
|
153
|
+
const border = (text: string) => theme.fg("borderAccent", text);
|
|
154
|
+
const row = (text = "") => border("│ ") + fit(text, inner) + border(" │");
|
|
155
|
+
const current = RESOURCE_TABS[tab]!;
|
|
156
|
+
const active = resources.tools.filter((tool) => tool.active).length;
|
|
157
|
+
const summary =
|
|
158
|
+
current === "Tools"
|
|
159
|
+
? active +
|
|
160
|
+
" active · " +
|
|
161
|
+
(resources.tools.length - active) +
|
|
162
|
+
" inactive · Registered exposure is shown. Per-request tool hiding is not."
|
|
163
|
+
: current === "Context"
|
|
164
|
+
? "Loaded instruction files and system-prompt sources, in Pi’s loading order."
|
|
165
|
+
: current === "Skills"
|
|
166
|
+
? "Run a skill with /skill:<name>."
|
|
167
|
+
: current === "Extensions"
|
|
168
|
+
? "Loaded extensions by source. Press e to " +
|
|
169
|
+
(extensionDetails ? "hide" : "show") +
|
|
170
|
+
" full paths and package entries."
|
|
171
|
+
: "Loader errors, warnings, and name collisions across extensions, skills, prompts, and themes.";
|
|
172
|
+
const wrapped = wrapTextWithAnsi(summary, inner);
|
|
173
|
+
const heading = wrapped
|
|
174
|
+
.slice(0, 2)
|
|
175
|
+
.map((text, index) =>
|
|
176
|
+
theme.fg(
|
|
177
|
+
"muted",
|
|
178
|
+
index === 1 && wrapped.length > 2
|
|
179
|
+
? truncateToWidth(text, inner - 1, "") + "…"
|
|
180
|
+
: text,
|
|
181
|
+
),
|
|
182
|
+
);
|
|
183
|
+
const nav = navigation(inner);
|
|
184
|
+
const lines = scroll.render(inner);
|
|
185
|
+
// Keep the tab bar and help visible while the body scrolls.
|
|
186
|
+
page = Math.max(1, Math.min(height - 6 - heading.length, Math.max(4, lines.length)));
|
|
187
|
+
scroll.updateLayout(lines.length, page, () => tui.requestRender());
|
|
188
|
+
const visible = lines.slice(scroll.scrollTop, scroll.scrollTop + page);
|
|
189
|
+
while (visible.length < page) visible.push("");
|
|
190
|
+
const position =
|
|
191
|
+
lines.length > page
|
|
192
|
+
? "Rows " +
|
|
193
|
+
(scroll.scrollTop + 1) +
|
|
194
|
+
"–" +
|
|
195
|
+
Math.min(lines.length, scroll.scrollTop + page) +
|
|
196
|
+
" / " +
|
|
197
|
+
lines.length
|
|
198
|
+
: tabCount(resources, current) +
|
|
199
|
+
(current === "Tools"
|
|
200
|
+
? " registered"
|
|
201
|
+
: current === "Diagnostics"
|
|
202
|
+
? " issues"
|
|
203
|
+
: " loaded");
|
|
204
|
+
const footer = theme.fg(
|
|
205
|
+
"dim",
|
|
206
|
+
truncateToWidth(" " + current + " · " + position + " ", width - 4, "…"),
|
|
207
|
+
);
|
|
208
|
+
const help: [string, string][] = [
|
|
209
|
+
[closeKeys, "close"],
|
|
210
|
+
["←→/Tab", "tabs"],
|
|
211
|
+
[
|
|
212
|
+
keyLabels([
|
|
213
|
+
...keybindings.getKeys("tui.select.up").slice(0, 1),
|
|
214
|
+
...keybindings.getKeys("tui.select.down").slice(0, 1),
|
|
215
|
+
]),
|
|
216
|
+
"scroll",
|
|
217
|
+
],
|
|
218
|
+
["1–" + RESOURCE_TABS.length, "jump"],
|
|
219
|
+
[
|
|
220
|
+
keyLabels([
|
|
221
|
+
...keybindings.getKeys("tui.select.pageUp").slice(0, 1),
|
|
222
|
+
...keybindings.getKeys("tui.select.pageDown").slice(0, 1),
|
|
223
|
+
]),
|
|
224
|
+
"page",
|
|
225
|
+
],
|
|
226
|
+
];
|
|
227
|
+
if (current === "Extensions")
|
|
228
|
+
help.splice(2, 0, ["e", extensionDetails ? "collapse" : "expand"]);
|
|
229
|
+
let hints = "";
|
|
230
|
+
for (const [key, label] of help) {
|
|
231
|
+
const hint = theme.fg("accent", key) + theme.fg("dim", " " + label);
|
|
232
|
+
const candidate = hints ? hints + theme.fg("borderMuted", " · ") + hint : hint;
|
|
233
|
+
if (visibleWidth(candidate) <= inner) hints = candidate;
|
|
234
|
+
}
|
|
235
|
+
const title = theme.bold(theme.fg("accent", " Resources "));
|
|
236
|
+
return [
|
|
237
|
+
border("╭─") + title + border("─".repeat(width - 4 - visibleWidth(title)) + "─╮"),
|
|
238
|
+
...nav.map(row),
|
|
239
|
+
...heading.map(row),
|
|
240
|
+
row(),
|
|
241
|
+
...visible.map(row),
|
|
242
|
+
row(hints),
|
|
243
|
+
border("╰─") +
|
|
244
|
+
footer +
|
|
245
|
+
border("─".repeat(Math.max(0, width - 4 - visibleWidth(footer))) + "─╯"),
|
|
246
|
+
];
|
|
247
|
+
},
|
|
248
|
+
handleMouse: (event: TuiMouseEvent): TuiMouseEventResult | undefined => {
|
|
249
|
+
if (event.width !== mouseWidth) return undefined;
|
|
250
|
+
if (event.type === "wheel") {
|
|
251
|
+
scroll.scrollBy(event.wheelDelta ?? 0);
|
|
252
|
+
tui.requestRender();
|
|
253
|
+
// Contain the event even at an edge so the transcript does not scroll.
|
|
254
|
+
return { handled: true, focus: true };
|
|
255
|
+
}
|
|
256
|
+
if (
|
|
257
|
+
event.button !== "left" ||
|
|
258
|
+
event.shift ||
|
|
259
|
+
event.alt ||
|
|
260
|
+
event.ctrl ||
|
|
261
|
+
(event.type !== "press" && event.type !== "click") ||
|
|
262
|
+
(event.y !== 1 && event.y !== 2)
|
|
263
|
+
)
|
|
264
|
+
return undefined;
|
|
265
|
+
const target = targets.find((item) => event.x >= item.start && event.x < item.end);
|
|
266
|
+
if (!target) return undefined;
|
|
267
|
+
if (event.type === "click") switchTab(target.index);
|
|
268
|
+
return { handled: true, focus: true };
|
|
269
|
+
},
|
|
270
|
+
handleInput: (data: string) => {
|
|
271
|
+
if (isKeyRelease(data)) return;
|
|
272
|
+
if (
|
|
273
|
+
keybindings.matches(data, "tui.select.cancel") ||
|
|
274
|
+
keybindings.matches(data, "tui.select.confirm") ||
|
|
275
|
+
data === "q"
|
|
276
|
+
) {
|
|
277
|
+
done();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (RESOURCE_TABS[tab] === "Extensions" && data === "e") {
|
|
281
|
+
extensionDetails = !extensionDetails;
|
|
282
|
+
scroll.scrollToStart();
|
|
283
|
+
} else if (matchesKey(data, Key.tab) || matchesKey(data, Key.right)) switchTab(tab + 1);
|
|
284
|
+
else if (matchesKey(data, Key.shift(Key.tab)) || matchesKey(data, Key.left))
|
|
285
|
+
switchTab(tab - 1);
|
|
286
|
+
else if (/^[1-9]$/.test(data) && Number(data) <= RESOURCE_TABS.length)
|
|
287
|
+
switchTab(Number(data) - 1);
|
|
288
|
+
else if (keybindings.matches(data, "tui.select.up")) scroll.scrollBy(-1);
|
|
289
|
+
else if (keybindings.matches(data, "tui.select.down")) scroll.scrollBy(1);
|
|
290
|
+
else if (keybindings.matches(data, "tui.select.pageUp")) scroll.scrollBy(-page);
|
|
291
|
+
else if (keybindings.matches(data, "tui.select.pageDown")) scroll.scrollBy(page);
|
|
292
|
+
else if (matchesKey(data, Key.home)) scroll.scrollToStart();
|
|
293
|
+
else if (matchesKey(data, Key.end)) scroll.scrollToEnd();
|
|
294
|
+
tui.requestRender();
|
|
295
|
+
},
|
|
296
|
+
invalidate() {
|
|
297
|
+
scroll.invalidate();
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
overlay: true,
|
|
303
|
+
overlayOptions: {
|
|
304
|
+
anchor: "center",
|
|
305
|
+
width: 100,
|
|
306
|
+
minWidth: 46,
|
|
307
|
+
maxHeight: "80%",
|
|
308
|
+
margin: 2,
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
);
|
|
312
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { basename, relative, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { SourceInfo, Theme } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
6
|
+
|
|
7
|
+
function entryPath(source: SourceInfo): string {
|
|
8
|
+
return source.baseDir === undefined ? source.path : relative(source.baseDir, source.path);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function shortPath(path: string): string {
|
|
12
|
+
const home = homedir();
|
|
13
|
+
return path.startsWith(home + sep) ? "~" + path.slice(home.length) : path;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function packageLabel(source: string): string {
|
|
17
|
+
if (source.startsWith("npm:")) return source.slice(4);
|
|
18
|
+
if (source.startsWith("git:")) return source.slice(4);
|
|
19
|
+
return basename(source);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function renderExtensions(
|
|
23
|
+
sources: SourceInfo[],
|
|
24
|
+
theme: Theme,
|
|
25
|
+
width: number,
|
|
26
|
+
expanded: boolean,
|
|
27
|
+
): string[] {
|
|
28
|
+
const lines: string[] = [];
|
|
29
|
+
const local: SourceInfo[] = [];
|
|
30
|
+
const builtin: SourceInfo[] = [];
|
|
31
|
+
const packages = new Map<string, { source: SourceInfo; entries: SourceInfo[] }>();
|
|
32
|
+
|
|
33
|
+
for (const source of sources) {
|
|
34
|
+
if (source.source === "builtin") {
|
|
35
|
+
builtin.push(source);
|
|
36
|
+
} else if (source.origin === "package") {
|
|
37
|
+
const key = JSON.stringify([source.source, source.scope, source.baseDir]);
|
|
38
|
+
const group = packages.get(key);
|
|
39
|
+
if (group) group.entries.push(source);
|
|
40
|
+
else packages.set(key, { source, entries: [source] });
|
|
41
|
+
} else {
|
|
42
|
+
local.push(source);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const heading = (label: string) => {
|
|
47
|
+
if (lines.length > 0) lines.push("");
|
|
48
|
+
lines.push(theme.bold(theme.fg("muted", label)));
|
|
49
|
+
};
|
|
50
|
+
const row = (text: string, indent: number, color: "text" | "dim") => {
|
|
51
|
+
const prefix = " ".repeat(indent);
|
|
52
|
+
for (const line of wrapTextWithAnsi(text, Math.max(1, width - indent))) {
|
|
53
|
+
lines.push(prefix + theme.fg(color, line));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (local.length > 0) {
|
|
58
|
+
heading("Local");
|
|
59
|
+
for (const source of local) {
|
|
60
|
+
const label = entryPath(source);
|
|
61
|
+
const sharedLabel = local.some((other) => other !== source && entryPath(other) === label);
|
|
62
|
+
row("• " + (sharedLabel ? shortPath(source.path) + " · " + source.scope : label), 2, "text");
|
|
63
|
+
if (expanded && !sharedLabel) row(shortPath(source.path) + " · " + source.scope, 4, "dim");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (packages.size > 0) {
|
|
67
|
+
heading("Packages");
|
|
68
|
+
const sorted = [...packages.values()].toSorted((a, b) =>
|
|
69
|
+
packageLabel(a.source.source).localeCompare(packageLabel(b.source.source)),
|
|
70
|
+
);
|
|
71
|
+
for (const group of sorted) {
|
|
72
|
+
const { source, entries } = group;
|
|
73
|
+
const label = packageLabel(source.source);
|
|
74
|
+
// Shorten only the display label. Group identity always uses full source metadata.
|
|
75
|
+
const sharedLabel = sorted.some(
|
|
76
|
+
(other) => other !== group && packageLabel(other.source.source) === label,
|
|
77
|
+
);
|
|
78
|
+
const display = sharedLabel ? shortPath(source.source) + " · " + source.scope : label;
|
|
79
|
+
const count = entries.length > 1 ? " · " + entries.length + " extensions" : "";
|
|
80
|
+
row((expanded ? "▾ " : "▸ ") + display + count, 2, "text");
|
|
81
|
+
if (expanded && !sharedLabel) row(shortPath(source.source) + " · " + source.scope, 4, "dim");
|
|
82
|
+
if (
|
|
83
|
+
(expanded || sharedLabel) &&
|
|
84
|
+
source.baseDir !== undefined &&
|
|
85
|
+
source.baseDir !== source.source
|
|
86
|
+
) {
|
|
87
|
+
row(shortPath(source.baseDir), 4, "dim");
|
|
88
|
+
}
|
|
89
|
+
if (expanded) {
|
|
90
|
+
for (const entry of entries) row(entryPath(entry), 4, "dim");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (builtin.length > 0) {
|
|
95
|
+
heading("Built-in");
|
|
96
|
+
for (const source of builtin) row("• " + source.path.replace(/^builtin:/, ""), 2, "text");
|
|
97
|
+
}
|
|
98
|
+
if (lines.length === 0) row("No visible extensions loaded.", 0, "dim");
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import { showResources } from "./dialog.ts";
|
|
4
|
+
import { captureResourceLoader } from "./loader-hook.ts";
|
|
5
|
+
import { collectResources } from "./snapshot.ts";
|
|
6
|
+
|
|
7
|
+
export default function (pi: ExtensionAPI) {
|
|
8
|
+
const command = "resources";
|
|
9
|
+
const loader = captureResourceLoader(command);
|
|
10
|
+
pi.on("session_shutdown", () => loader.dispose());
|
|
11
|
+
|
|
12
|
+
pi.registerCommand(command, {
|
|
13
|
+
description: "Browse resources and registered tools in a tabbed dialog",
|
|
14
|
+
handler: async (_args, ctx) => {
|
|
15
|
+
if (ctx.mode !== "tui") return;
|
|
16
|
+
const resourceLoader = loader.read();
|
|
17
|
+
if (!resourceLoader) {
|
|
18
|
+
ctx.ui.notify(
|
|
19
|
+
"Could not capture Pi's resource loader. Reload Pi before using /resources.",
|
|
20
|
+
"error",
|
|
21
|
+
);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const resources = collectResources(pi, ctx, resourceLoader);
|
|
25
|
+
await showResources(ctx, resources);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const KEY_LABELS: Record<string, string> = {
|
|
2
|
+
escape: "Esc",
|
|
3
|
+
enter: "Enter",
|
|
4
|
+
tab: "Tab",
|
|
5
|
+
up: "↑",
|
|
6
|
+
down: "↓",
|
|
7
|
+
left: "←",
|
|
8
|
+
right: "→",
|
|
9
|
+
pageUp: "PgUp",
|
|
10
|
+
pageDown: "PgDn",
|
|
11
|
+
home: "Home",
|
|
12
|
+
end: "End",
|
|
13
|
+
ctrl: "Ctrl",
|
|
14
|
+
shift: "Shift",
|
|
15
|
+
alt: process.platform === "darwin" ? "Option" : "Alt",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function keyLabels(keys: readonly string[]): string {
|
|
19
|
+
return [...new Set(keys)]
|
|
20
|
+
.map((key) =>
|
|
21
|
+
key
|
|
22
|
+
.split("+")
|
|
23
|
+
.map((part) => KEY_LABELS[part] ?? part)
|
|
24
|
+
.join("+"),
|
|
25
|
+
)
|
|
26
|
+
.join("/");
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LoadExtensionsResult, ResourceLoader } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { DefaultResourceLoader } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
export function captureResourceLoader(command: string) {
|
|
5
|
+
let readLoader: (() => ResourceLoader) | undefined;
|
|
6
|
+
const prototype = DefaultResourceLoader.prototype;
|
|
7
|
+
// oxlint-disable-next-line typescript/unbound-method -- The interceptor supplies the original receiver with call(this).
|
|
8
|
+
const original = prototype.getExtensions;
|
|
9
|
+
|
|
10
|
+
function restore() {
|
|
11
|
+
if (prototype.getExtensions === intercept) prototype.getExtensions = original;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function intercept(this: DefaultResourceLoader): LoadExtensionsResult {
|
|
15
|
+
const result = original.call(this);
|
|
16
|
+
if (result.extensions.some((extension) => extension.commands.has(command))) {
|
|
17
|
+
readLoader = () => this;
|
|
18
|
+
restore();
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Unsupported bridge: Pi reads this list after loading extensions to build its runtime.
|
|
24
|
+
// Capture that loader once, then leave the shared prototype unchanged.
|
|
25
|
+
prototype.getExtensions = intercept;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
read: () => readLoader?.(),
|
|
29
|
+
dispose: restore,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ExtensionAPI,
|
|
5
|
+
ExtensionContext,
|
|
6
|
+
ResourceDiagnostic,
|
|
7
|
+
ResourceLoader,
|
|
8
|
+
SourceInfo,
|
|
9
|
+
ToolInfo,
|
|
10
|
+
} from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
export type LoaderDiagnostic = ResourceDiagnostic & {
|
|
13
|
+
resource: "Extensions" | "Skills" | "Prompts" | "Themes";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ResourceSnapshot = {
|
|
17
|
+
context: string[];
|
|
18
|
+
skills: string[];
|
|
19
|
+
extensions: SourceInfo[];
|
|
20
|
+
tools: (Pick<ToolInfo, "name" | "description" | "exposure"> & { active: boolean })[];
|
|
21
|
+
diagnostics: LoaderDiagnostic[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function diagnosticsFor(
|
|
25
|
+
resource: LoaderDiagnostic["resource"],
|
|
26
|
+
diagnostics: ResourceDiagnostic[],
|
|
27
|
+
): LoaderDiagnostic[] {
|
|
28
|
+
return diagnostics.map((diagnostic) => Object.assign({}, diagnostic, { resource }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function collectResources(
|
|
32
|
+
pi: ExtensionAPI,
|
|
33
|
+
ctx: ExtensionContext,
|
|
34
|
+
loader: ResourceLoader,
|
|
35
|
+
): ResourceSnapshot {
|
|
36
|
+
const tools = pi.getAllTools();
|
|
37
|
+
const activeTools = new Set(pi.getActiveTools());
|
|
38
|
+
const extensions = loader.getExtensions();
|
|
39
|
+
const skills = loader.getSkills();
|
|
40
|
+
const systemPrompt = loader.getSystemPromptSource();
|
|
41
|
+
const context = [
|
|
42
|
+
...(systemPrompt ? [systemPrompt] : []),
|
|
43
|
+
...loader.getAppendSystemPromptSources(),
|
|
44
|
+
...loader.getAgentsFiles().agentsFiles,
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
tools: tools
|
|
49
|
+
.map(({ name, description, exposure }) => ({
|
|
50
|
+
name,
|
|
51
|
+
description,
|
|
52
|
+
exposure,
|
|
53
|
+
active: activeTools.has(name),
|
|
54
|
+
}))
|
|
55
|
+
.toSorted((a, b) => a.name.localeCompare(b.name)),
|
|
56
|
+
context: context.map(({ path }) => relative(ctx.cwd, path)),
|
|
57
|
+
skills: skills.skills.map((skill) => skill.name).toSorted(),
|
|
58
|
+
extensions: extensions.extensions
|
|
59
|
+
.filter((extension) => !extension.hidden)
|
|
60
|
+
.map((extension) => extension.sourceInfo)
|
|
61
|
+
.toSorted((a, b) => a.path.localeCompare(b.path)),
|
|
62
|
+
diagnostics: [
|
|
63
|
+
...extensions.errors.map(({ path, error }): LoaderDiagnostic => ({
|
|
64
|
+
resource: "Extensions",
|
|
65
|
+
type: "error",
|
|
66
|
+
message: error,
|
|
67
|
+
path,
|
|
68
|
+
})),
|
|
69
|
+
...(extensions.warnings ?? []).map(({ path, warning }): LoaderDiagnostic => ({
|
|
70
|
+
resource: "Extensions",
|
|
71
|
+
type: "warning",
|
|
72
|
+
message: warning,
|
|
73
|
+
path,
|
|
74
|
+
})),
|
|
75
|
+
...diagnosticsFor("Skills", skills.diagnostics),
|
|
76
|
+
...diagnosticsFor("Prompts", loader.getPrompts().diagnostics),
|
|
77
|
+
...diagnosticsFor("Themes", loader.getThemes().diagnostics),
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Theme, ToolExposure } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
import type { ResourceSnapshot } from "./snapshot.ts";
|
|
5
|
+
|
|
6
|
+
const EXPOSURE_HELP: Record<ToolExposure, string> = {
|
|
7
|
+
direct: "Declared to the model and callable from other tools while active.",
|
|
8
|
+
"model-only": "Declared to the model while active. Never callable from other tools.",
|
|
9
|
+
codemode: "Callable from other tools even when inactive. Not normally declared to the model.",
|
|
10
|
+
deferred: "Callable from other tools even when inactive. Tool search can find and activate it.",
|
|
11
|
+
hidden: "Registered but unreachable.",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function renderTools(
|
|
15
|
+
tools: ResourceSnapshot["tools"],
|
|
16
|
+
theme: Theme,
|
|
17
|
+
width: number,
|
|
18
|
+
): string[] {
|
|
19
|
+
if (tools.length === 0) return [theme.fg("muted", "No tools registered.")];
|
|
20
|
+
|
|
21
|
+
const lines: string[] = [];
|
|
22
|
+
const row = (text: string, color: "muted" | "dim") => {
|
|
23
|
+
for (const line of wrapTextWithAnsi(text, Math.max(1, width - 2))) {
|
|
24
|
+
lines.push(" " + theme.fg(color, line));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
for (const tool of tools) {
|
|
28
|
+
const status = tool.active ? theme.fg("success", "● active") : theme.fg("dim", "○ inactive");
|
|
29
|
+
const title = theme.bold(theme.fg("text", tool.name));
|
|
30
|
+
const exposure = theme.fg("accent", "[" + tool.exposure + "]");
|
|
31
|
+
lines.push(...wrapTextWithAnsi(title + " " + status + " " + exposure, Math.max(1, width)));
|
|
32
|
+
row(tool.description.trim(), "muted");
|
|
33
|
+
row(EXPOSURE_HELP[tool.exposure], "dim");
|
|
34
|
+
lines.push("");
|
|
35
|
+
}
|
|
36
|
+
return lines;
|
|
37
|
+
}
|