@luxass/pi-personal 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,8 @@ 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 inspect detected context files, skill commands, and extensions. This list is inferred from files and registered commands/tools, not a complete inventory of loaded resources.
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.
16
+
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.
16
18
 
17
19
  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.2",
3
+ "version": "0.2.0",
4
4
  "description": "Personal Pi extensions collected in one package, tuned to a single workflow.",
5
5
  "keywords": [
6
6
  "personal",
@@ -31,6 +31,7 @@
31
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",
@@ -39,8 +40,8 @@
39
40
  ]
40
41
  },
41
42
  "scripts": {
42
- "lint": "oxlint --deny-warnings .",
43
- "lint:fix": "oxlint --fix --deny-warnings .",
43
+ "lint": "oxlint .",
44
+ "lint:fix": "oxlint --fix .",
44
45
  "fmt": "oxfmt .",
45
46
  "fmt:check": "oxfmt --check .",
46
47
  "typecheck": "tsc -p tsconfig.json"
@@ -1,17 +1,8 @@
1
- import { existsSync } from "node:fs";
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;
@@ -98,6 +28,7 @@ interface HeaderOptions {
98
28
  model: Pick<NonNullable<ExtensionContext["model"]>, "provider" | "id" | "reasoning"> | undefined;
99
29
  thinking: ReturnType<ExtensionAPI["getThinkingLevel"]>;
100
30
  thinkingKey: string;
31
+ resources: boolean;
101
32
  }
102
33
 
103
34
  export function renderHeader({
@@ -107,6 +38,7 @@ export function renderHeader({
107
38
  model,
108
39
  thinking,
109
40
  thinkingKey,
41
+ resources,
110
42
  }: HeaderOptions): string[] {
111
43
  if (width < 1) return [""];
112
44
 
@@ -136,9 +68,9 @@ export function renderHeader({
136
68
  ...(model?.reasoning && thinkingKey
137
69
  ? [`${accent(thinkingKey === "shift+tab" ? "⇧Tab" : thinkingKey)} ${muted("thinking")}`]
138
70
  : []),
139
- accent("/resources"),
71
+ ...(resources ? [accent("/resources")] : []),
140
72
  ];
141
- // Drop complete hints, not half a shortcut. Keep /resources available longest.
73
+ // Drop complete hints, not half a shortcut. Keep the final hint available longest.
142
74
  const hintWidth = expanded ? contentWidth - 4 : contentWidth;
143
75
  while (hints.length > 1 && visibleWidth(hints.join(" ")) > hintWidth) {
144
76
  hints.splice(hints.length - 2, 1);
@@ -183,7 +115,7 @@ export function renderHeader({
183
115
  if (visibleWidth(metadata) <= contentWidth) lines.push(metadata);
184
116
  else lines.push(modelLabel, ...(thinkingLabel ? [thinkingLabel] : []));
185
117
  }
186
- if (contentWidth >= visibleWidth("/resources")) {
118
+ if (contentWidth >= visibleWidth(hints[hints.length - 1]!)) {
187
119
  if (boxed) lines.push("");
188
120
  lines.push(hints.join(" "));
189
121
  }
@@ -200,47 +132,6 @@ export function renderHeader({
200
132
  ];
201
133
  }
202
134
 
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
135
  export default function (pi: ExtensionAPI) {
245
136
  pi.on("session_start", (_event, ctx) => {
246
137
  if (ctx.mode !== "tui") return;
@@ -254,39 +145,9 @@ export default function (pi: ExtensionAPI) {
254
145
  model: ctx.model,
255
146
  thinking: pi.getThinkingLevel(),
256
147
  thinkingKey: keyText("app.thinking.cycle"),
148
+ resources: pi.getCommands().some((command) => command.name === "resources"),
257
149
  }),
258
150
  invalidate() {},
259
151
  }));
260
152
  });
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
153
  }
@@ -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
+ }