@luxass/pi-personal 0.1.3 → 0.2.1
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 +1 -9
- package/package.json +1 -2
- package/src/crow/codex-stream.ts +41 -0
- package/src/custom-header.ts +6 -3
- package/src/resources/diagnostics.ts +0 -34
- package/src/resources/dialog.ts +0 -312
- package/src/resources/extensions.ts +0 -100
- package/src/resources/index.ts +0 -28
- package/src/resources/key-labels.ts +0 -27
- package/src/resources/loader-hook.ts +0 -31
- package/src/resources/snapshot.ts +0 -80
- package/src/resources/tools.ts +0 -37
package/README.md
CHANGED
|
@@ -12,15 +12,7 @@ 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
|
-
|
|
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.
|
|
15
|
+
The `/resources` dialog now lives in [`@luxass/pi-resources`](../pi-resources/README.md). Install that package separately to keep the command. The header shows its shortcut only when the command is available.
|
|
24
16
|
|
|
25
17
|
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.
|
|
26
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/pi-personal",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Personal Pi extensions collected in one package, tuned to a single workflow.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"personal",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"./src/package-manager-interceptor.ts",
|
|
37
37
|
"./src/worker-configuration-guard.ts",
|
|
38
38
|
"./src/custom-header.ts",
|
|
39
|
-
"./src/resources/index.ts",
|
|
40
39
|
"./src/crow/index.ts"
|
|
41
40
|
]
|
|
42
41
|
},
|
package/src/crow/codex-stream.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* - chatgpt-account-id header is omitted when account id is unavailable
|
|
7
7
|
* - provider id(s) are added to CODEX_TOOL_CALL_PROVIDERS for tool-call id handling
|
|
8
8
|
* - model/message api id uses cliproxyapi-codex-responses
|
|
9
|
+
* - rate-limit errors preserve proxy messages instead of assuming a ChatGPT plan
|
|
10
|
+
* - model cooldown errors include the retry delay and absolute UTC retry time
|
|
9
11
|
*
|
|
10
12
|
* The patched module is derived at runtime from the installed
|
|
11
13
|
* @earendil-works/pi-ai openai-codex-responses implementation so we track
|
|
@@ -496,6 +498,45 @@ export function patchCodexSource(source: string, providerIds: string[]): string
|
|
|
496
498
|
`const CODEX_TOOL_CALL_PROVIDERS = new Set([${existing}${extras ? `, ${extras}` : ""}]);`,
|
|
497
499
|
);
|
|
498
500
|
|
|
501
|
+
// Crow can route non-OpenAI models. Preserve the proxy's error instead of
|
|
502
|
+
// letting the Codex transport replace every 429 with a ChatGPT-plan warning.
|
|
503
|
+
const usageLimitMessage =
|
|
504
|
+
"friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();";
|
|
505
|
+
if (!src.includes(usageLimitMessage)) {
|
|
506
|
+
throw new Error("openai-codex-responses source no longer defines the usage-limit message");
|
|
507
|
+
}
|
|
508
|
+
src = src.replace(
|
|
509
|
+
usageLimitMessage,
|
|
510
|
+
"friendlyMessage = err.message || `CLIProxyAPI rate limit or quota exceeded.${when}`.trim();",
|
|
511
|
+
);
|
|
512
|
+
src = src.replace(/^\s*const plan = err\.plan_type \? `[^\n]+` : "";\n/m, "");
|
|
513
|
+
|
|
514
|
+
const errorMessageAssignment = "message = err.message || friendlyMessage || message;";
|
|
515
|
+
if (!src.includes(errorMessageAssignment)) {
|
|
516
|
+
throw new Error("openai-codex-responses source no longer assigns the parsed error message");
|
|
517
|
+
}
|
|
518
|
+
src = src.replace(
|
|
519
|
+
errorMessageAssignment,
|
|
520
|
+
`${errorMessageAssignment}
|
|
521
|
+
if (err.code === "model_cooldown" && typeof err.reset_seconds === "number" && Number.isFinite(err.reset_seconds) && err.reset_seconds >= 0) {
|
|
522
|
+
const seconds = Math.ceil(err.reset_seconds);
|
|
523
|
+
const retryAt = new Date(Date.now() + seconds * 1000);
|
|
524
|
+
if (Number.isFinite(retryAt.getTime())) {
|
|
525
|
+
const hours = Math.floor(seconds / 3600);
|
|
526
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
527
|
+
const remainingSeconds = seconds % 60;
|
|
528
|
+
const duration = [
|
|
529
|
+
hours > 0 ? hours + "h" : "",
|
|
530
|
+
minutes > 0 ? minutes + "m" : "",
|
|
531
|
+
remainingSeconds > 0 || seconds === 0 ? remainingSeconds + "s" : "",
|
|
532
|
+
].filter(Boolean).join(" ");
|
|
533
|
+
const utc = retryAt.toISOString().replace("T", " ").replace(/\\.\\d{3}Z$/, " UTC");
|
|
534
|
+
message += "\\nNext retry allowed in " + duration + " (" + utc + ").";
|
|
535
|
+
friendlyMessage = message;
|
|
536
|
+
}
|
|
537
|
+
}`,
|
|
538
|
+
);
|
|
539
|
+
|
|
499
540
|
// Keep assistant message api metadata aligned with the registered custom api id.
|
|
500
541
|
src = src.replaceAll(
|
|
501
542
|
`api: "openai-codex-responses"`,
|
package/src/custom-header.ts
CHANGED
|
@@ -28,6 +28,7 @@ interface HeaderOptions {
|
|
|
28
28
|
model: Pick<NonNullable<ExtensionContext["model"]>, "provider" | "id" | "reasoning"> | undefined;
|
|
29
29
|
thinking: ReturnType<ExtensionAPI["getThinkingLevel"]>;
|
|
30
30
|
thinkingKey: string;
|
|
31
|
+
resources: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export function renderHeader({
|
|
@@ -37,6 +38,7 @@ export function renderHeader({
|
|
|
37
38
|
model,
|
|
38
39
|
thinking,
|
|
39
40
|
thinkingKey,
|
|
41
|
+
resources,
|
|
40
42
|
}: HeaderOptions): string[] {
|
|
41
43
|
if (width < 1) return [""];
|
|
42
44
|
|
|
@@ -66,9 +68,9 @@ export function renderHeader({
|
|
|
66
68
|
...(model?.reasoning && thinkingKey
|
|
67
69
|
? [`${accent(thinkingKey === "shift+tab" ? "⇧Tab" : thinkingKey)} ${muted("thinking")}`]
|
|
68
70
|
: []),
|
|
69
|
-
accent("/resources"),
|
|
71
|
+
...(resources ? [accent("/resources")] : []),
|
|
70
72
|
];
|
|
71
|
-
// Drop complete hints, not half a shortcut. Keep
|
|
73
|
+
// Drop complete hints, not half a shortcut. Keep the final hint available longest.
|
|
72
74
|
const hintWidth = expanded ? contentWidth - 4 : contentWidth;
|
|
73
75
|
while (hints.length > 1 && visibleWidth(hints.join(" ")) > hintWidth) {
|
|
74
76
|
hints.splice(hints.length - 2, 1);
|
|
@@ -113,7 +115,7 @@ export function renderHeader({
|
|
|
113
115
|
if (visibleWidth(metadata) <= contentWidth) lines.push(metadata);
|
|
114
116
|
else lines.push(modelLabel, ...(thinkingLabel ? [thinkingLabel] : []));
|
|
115
117
|
}
|
|
116
|
-
if (contentWidth >= visibleWidth(
|
|
118
|
+
if (contentWidth >= visibleWidth(hints[hints.length - 1]!)) {
|
|
117
119
|
if (boxed) lines.push("");
|
|
118
120
|
lines.push(hints.join(" "));
|
|
119
121
|
}
|
|
@@ -143,6 +145,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
143
145
|
model: ctx.model,
|
|
144
146
|
thinking: pi.getThinkingLevel(),
|
|
145
147
|
thinkingKey: keyText("app.thinking.cycle"),
|
|
148
|
+
resources: pi.getCommands().some((command) => command.name === "resources"),
|
|
146
149
|
}),
|
|
147
150
|
invalidate() {},
|
|
148
151
|
}));
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
package/src/resources/dialog.ts
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
}
|
package/src/resources/index.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
}
|
package/src/resources/tools.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|