@diegopetrucci/pi-extensions 0.1.21 → 0.1.22

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
@@ -5,7 +5,7 @@ A collection of [pi](https://github.com/earendil-works/pi-mono) agent extensions
5
5
  - [`confirm-destructive`](./extensions/confirm-destructive): Confirms before destructive session actions like clear, switch, and fork.
6
6
  - [`context-cap`](./extensions/context-cap): Caps effective model context windows at 200k tokens by default so pi avoids the `dumb zone`; toggle temporarily with `/context-cap`.
7
7
  - [`context-inspector`](./extensions/context-inspector): Adds `/context`, a local self-contained HTML dashboard that breaks down where the current session context is going, with category overview, top offenders, and drilldown search.
8
- - [`librarian`](./extensions/librarian): Adds a GitHub research scout that asks whether to use an opt-in local repo checkout cache under the OS user cache directory, with cached repos expiring after 30 days of non-use.
8
+ - [`librarian`](./extensions/librarian): Adds a GitHub research scout with a local repo checkout cache enabled by default under the OS user cache directory, toggleable with `/librarian-cache`, with cached repos expiring after 30 days of non-use.
9
9
  - [`minimal-footer`](./extensions/minimal-footer): Replaces pi's built-in footer with a minimal configurable two-line layout: branch/repo on the first line, context/model on the second, optional `DUMB ZONE`, plus OpenAI Codex 5-hour and 7-day usage when available.
10
10
  - [`notify`](./extensions/notify): Sends configurable terminal, desktop, bell, and sound notifications when pi finishes and is ready for input.
11
11
  - [`openai-fast`](./extensions/openai-fast): Adds `/fast` to enable OpenAI Codex Fast mode for ChatGPT-auth GPT-5.4 and GPT-5.5 by injecting the priority service tier.
@@ -26,7 +26,7 @@ pi install npm:@diegopetrucci/pi-extensions
26
26
  Or pin the GitHub package to this release:
27
27
 
28
28
  ```bash
29
- pi install git:github.com/diegopetrucci/pi-extensions@v0.1.21
29
+ pi install git:github.com/diegopetrucci/pi-extensions@v0.1.22
30
30
  ```
31
31
 
32
32
  Or a specific extension:
@@ -1,8 +1,8 @@
1
1
  # librarian
2
2
 
3
- A pi GitHub research scout inspired by `pi-librarian`, with an opt-in local checkout cache.
3
+ A pi GitHub research scout inspired by `pi-librarian`, with a local checkout cache enabled by default.
4
4
 
5
- When the `librarian` tool runs, it asks whether to cache/reuse repository checkouts locally. If you say no, cancel, time out, or run without UI, it uses GitHub API/search and temporary fetched files only.
5
+ When the `librarian` tool runs, it can cache/reuse repository checkouts locally. Use `/librarian-cache off` to force GitHub API/search and temporary fetched files only, or `/librarian-cache on` to re-enable cached local checkouts.
6
6
 
7
7
  ## Install
8
8
 
@@ -35,10 +35,21 @@ Then reload pi:
35
35
  - Tool name: `librarian`
36
36
  - Uses a restricted subagent with `bash` and `read`
37
37
  - Uses `gh` for GitHub search/API access
38
- - Asks on each call whether to use cached local checkouts
39
- - Defaults to no checkout/cache
38
+ - Uses cached local checkouts by default
39
+ - Toggle cache behavior for future calls with `/librarian-cache on | off | toggle | status`
40
40
  - Cached repos are removed lazily after 30 days without use
41
41
 
42
+ ## Commands
43
+
44
+ ```text
45
+ /librarian-cache status
46
+ /librarian-cache off
47
+ /librarian-cache on
48
+ /librarian-cache toggle
49
+ ```
50
+
51
+ The command works in interactive mode, RPC mode, and print/JSON mode. It writes a global preference to `~/.pi/agent/extensions/librarian.json`, so separate non-UI invocations use the same setting. In non-UI modes, command feedback is written to stderr so stdout remains usable for normal output or JSON events.
52
+
42
53
  ## Cache location
43
54
 
44
55
  macOS:
@@ -25,11 +25,14 @@ const CACHE_TTL_DAYS = 30;
25
25
  const CACHE_TTL_MS = CACHE_TTL_DAYS * 24 * 60 * 60 * 1000;
26
26
  const CACHE_METADATA_FILE = ".pi-librarian-cache.json";
27
27
  const CACHE_MARKER_FILE = ".pi-librarian-cache-used";
28
+ const CACHE_CONFIG_FILE = "librarian.json";
28
29
 
29
30
  type LibrarianStatus = "running" | "done" | "error" | "aborted";
30
31
 
31
32
  type CacheMode = "disabled" | "enabled";
32
33
 
34
+ const DEFAULT_CACHE_MODE: CacheMode = "enabled";
35
+
33
36
  type ToolCall = {
34
37
  id: string;
35
38
  name: string;
@@ -252,30 +255,67 @@ async function cleanupExpiredCache(cacheRoot: string): Promise<{ deleted: number
252
255
  }
253
256
  }
254
257
 
255
- async function askForCache(ctx: ExtensionContext, cacheRoot: string): Promise<{ enabled: boolean; reason: string }> {
256
- if (!ctx.hasUI) return { enabled: false, reason: "no UI available; using GitHub API/temp files only" };
258
+ function getCacheConfigPath(): string {
259
+ return path.join(getAgentDir(), "extensions", CACHE_CONFIG_FILE);
260
+ }
261
+
262
+ function parseCacheMode(value: unknown): CacheMode | undefined {
263
+ if (value === "enabled" || value === "on" || value === true) return "enabled";
264
+ if (value === "disabled" || value === "off" || value === false) return "disabled";
265
+ return undefined;
266
+ }
257
267
 
268
+ async function readCachePreference(): Promise<CacheMode> {
258
269
  try {
259
- const enabled = await ctx.ui.confirm(
260
- "Librarian repo cache",
261
- [
262
- "Cache/reuse local GitHub repo checkouts for this Librarian call?",
263
- "",
264
- `Cache directory: ${cacheRoot}`,
265
- `Repos unused for ${CACHE_TTL_DAYS} days are removed lazily on future Librarian calls.`,
266
- "",
267
- "Choose No to use GitHub API and temporary fetched files only.",
268
- ].join("\n"),
269
- { timeout: 30_000 },
270
+ const raw = await fs.readFile(getCacheConfigPath(), "utf8");
271
+ const parsed = JSON.parse(raw) as {
272
+ cacheMode?: unknown;
273
+ cacheEnabled?: unknown;
274
+ cache?: { mode?: unknown; enabled?: unknown };
275
+ };
276
+ return (
277
+ parseCacheMode(parsed.cacheMode) ??
278
+ parseCacheMode(parsed.cache?.mode) ??
279
+ parseCacheMode(parsed.cacheEnabled) ??
280
+ parseCacheMode(parsed.cache?.enabled) ??
281
+ DEFAULT_CACHE_MODE
270
282
  );
283
+ } catch {
284
+ return DEFAULT_CACHE_MODE;
285
+ }
286
+ }
271
287
 
272
- return enabled
273
- ? { enabled: true, reason: "user opted into cached local checkouts" }
274
- : { enabled: false, reason: "user declined or prompt timed out" };
275
- } catch (error) {
276
- const message = error instanceof Error ? error.message : String(error);
277
- return { enabled: false, reason: `cache prompt failed (${message}); using GitHub API/temp files only` };
288
+ async function writeCachePreference(preference: CacheMode): Promise<void> {
289
+ const configPath = getCacheConfigPath();
290
+ const config = {
291
+ cacheMode: preference,
292
+ cacheEnabled: preference === "enabled",
293
+ updatedAt: new Date().toISOString(),
294
+ };
295
+
296
+ await fs.mkdir(path.dirname(configPath), { recursive: true });
297
+ await fs.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
298
+ }
299
+
300
+ function resolveCacheDecision(preference: CacheMode): { enabled: boolean; reason: string } {
301
+ if (preference === "enabled") {
302
+ return { enabled: true, reason: "cache preference enabled; using cached local checkouts" };
303
+ }
304
+
305
+ return { enabled: false, reason: "cache preference disabled; using GitHub API/temp files only" };
306
+ }
307
+
308
+ function formatCachePreference(preference: CacheMode): string {
309
+ return preference === "enabled" ? "on" : "off";
310
+ }
311
+
312
+ function notifyCommand(ctx: ExtensionContext, message: string, type: "info" | "warning" | "error" = "info"): void {
313
+ if (ctx.hasUI) {
314
+ ctx.ui.notify(message, type);
315
+ return;
278
316
  }
317
+
318
+ console.error(message);
279
319
  }
280
320
 
281
321
  function resolveToolPath(cwd: string, rawPath: string): string {
@@ -438,13 +478,81 @@ function isAbortLikeError(error: unknown): boolean {
438
478
  }
439
479
 
440
480
  export default function librarianExtension(pi: ExtensionAPI) {
481
+ let cachePreference: CacheMode = DEFAULT_CACHE_MODE;
482
+
483
+ pi.on("session_start", async () => {
484
+ cachePreference = await readCachePreference();
485
+ });
486
+
487
+ pi.registerCommand("librarian-cache", {
488
+ description: "Toggle Librarian local checkout cache for future librarian calls",
489
+ getArgumentCompletions: (prefix) => {
490
+ const commands = ["on", "off", "toggle", "status"];
491
+ const query = prefix.trim().toLowerCase();
492
+ const matches = commands.filter((command) => command.startsWith(query));
493
+ return matches.length > 0 ? matches.map((value) => ({ value, label: value })) : null;
494
+ },
495
+ handler: async (args, ctx) => {
496
+ const action = args.trim().toLowerCase() || "status";
497
+ const cacheRoot = getUserCacheReposRoot();
498
+ const configPath = getCacheConfigPath();
499
+
500
+ const setPreference = async (mode: CacheMode): Promise<string | undefined> => {
501
+ cachePreference = mode;
502
+ try {
503
+ await writeCachePreference(mode);
504
+ return undefined;
505
+ } catch (error) {
506
+ const message = error instanceof Error ? error.message : String(error);
507
+ return `Preference changed for this process, but could not save ${configPath}: ${message}`;
508
+ }
509
+ };
510
+
511
+ const formatSetMessage = (mode: CacheMode, warning?: string): string => {
512
+ const main = mode === "enabled"
513
+ ? `Librarian cache enabled. Future librarian calls will reuse local checkouts under ${cacheRoot}.`
514
+ : "Librarian cache disabled. Future librarian calls will use GitHub API/search and temporary fetched files only.";
515
+ return warning ? `${main} ${warning}` : main;
516
+ };
517
+
518
+ if (action === "on" || action === "enable") {
519
+ const warning = await setPreference("enabled");
520
+ notifyCommand(ctx, formatSetMessage("enabled", warning), warning ? "warning" : "info");
521
+ return;
522
+ }
523
+
524
+ if (action === "off" || action === "disable") {
525
+ const warning = await setPreference("disabled");
526
+ notifyCommand(ctx, formatSetMessage("disabled", warning), warning ? "warning" : "info");
527
+ return;
528
+ }
529
+
530
+ if (action === "toggle") {
531
+ const next = cachePreference === "enabled" ? "disabled" : "enabled";
532
+ const warning = await setPreference(next);
533
+ notifyCommand(ctx, formatSetMessage(next, warning), warning ? "warning" : "info");
534
+ return;
535
+ }
536
+
537
+ if (action === "status") {
538
+ notifyCommand(
539
+ ctx,
540
+ `Librarian cache is ${formatCachePreference(cachePreference)}. Cache directory: ${cacheRoot}. Config: ${configPath}. Repos unused for ${CACHE_TTL_DAYS} days are removed lazily.`,
541
+ );
542
+ return;
543
+ }
544
+
545
+ notifyCommand(ctx, "Usage: /librarian-cache on | off | toggle | status", "warning");
546
+ },
547
+ });
548
+
441
549
  pi.registerTool({
442
550
  name: "librarian",
443
551
  label: "Librarian",
444
552
  description:
445
- "GitHub research scout for coding and personal-assistant tasks. Use when the answer likely lives in GitHub repos, exact repo/path locations are unknown, or you'd otherwise do exploratory gh search/tree probes plus local rg/read inspection. Librarian asks whether to use an optional 30-day local checkout cache, otherwise it behaves like API-only pi-librarian.",
553
+ "GitHub research scout for coding and personal-assistant tasks. Use when the answer likely lives in GitHub repos, exact repo/path locations are unknown, or you'd otherwise do exploratory gh search/tree probes plus local rg/read inspection. Librarian uses an optional 30-day local checkout cache by default; toggle it with /librarian-cache.",
446
554
  promptSnippet:
447
- "Research GitHub repositories with evidence-first path and line citations; optionally ask the user to cache local repo checkouts.",
555
+ "Research GitHub repositories with evidence-first path and line citations; local checkout cache is enabled by default and user-toggleable with /librarian-cache.",
448
556
  promptGuidelines: [
449
557
  "Use librarian when the answer likely requires exploratory GitHub repository search or line-cited evidence from external repos.",
450
558
  "Do not use librarian for files already present in the current workspace unless the user asks for external GitHub research.",
@@ -472,7 +580,7 @@ export default function librarianExtension(pi: ExtensionAPI) {
472
580
  await fs.mkdir(path.join(workspace, "repos"), { recursive: true });
473
581
 
474
582
  const cacheRoot = getUserCacheReposRoot();
475
- const cacheDecision = await askForCache(ctx, cacheRoot);
583
+ const cacheDecision = resolveCacheDecision(cachePreference);
476
584
  if (cacheDecision.enabled) await fs.mkdir(cacheRoot, { recursive: true });
477
585
  const cleanup = cacheDecision.enabled ? await cleanupExpiredCache(cacheRoot) : { deleted: 0, errors: [] };
478
586
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-librarian",
3
3
  "version": "0.1.0",
4
- "description": "A pi GitHub research scout that can optionally cache local repo checkouts under the user's OS cache directory.",
4
+ "description": "A pi GitHub research scout with a toggleable local repo checkout cache under the user's OS cache directory.",
5
5
  "keywords": ["pi-package", "pi", "github", "research", "subagent", "cache"],
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -25,6 +25,7 @@ Fast mode is only injected when all of these are true:
25
25
  ## Commands
26
26
 
27
27
  ```text
28
+ /fast
28
29
  /fast status
29
30
  /fast on
30
31
  /fast off
@@ -32,7 +33,7 @@ Fast mode is only injected when all of these are true:
32
33
  /fast toggle
33
34
  ```
34
35
 
35
- `/fast on` and `/fast off` are temporary session/runtime overrides. Use `/fast auto` to reload and follow config defaults again.
36
+ Run `/fast` without arguments to pick an action from a menu. `/fast on` and `/fast off` are temporary session/runtime overrides. Use `/fast auto` to reload and follow config defaults again.
36
37
 
37
38
  The extension defaults to off so installing the full collection does not accidentally spend Fast-mode credits.
38
39
 
@@ -249,7 +249,17 @@ export default function openAIFastExtension(pi: ExtensionAPI) {
249
249
  },
250
250
  handler: async (args, ctx) => {
251
251
  const state = getState(ctx);
252
- const action = args.trim().toLowerCase() || "status";
252
+ let action = args.trim().toLowerCase();
253
+
254
+ if (!action) {
255
+ if (!ctx.hasUI) {
256
+ action = "status";
257
+ } else {
258
+ const selection = await ctx.ui.select("OpenAI Fast mode", COMMANDS);
259
+ if (!selection) return;
260
+ action = selection;
261
+ }
262
+ }
253
263
 
254
264
  if (action === "on" || action === "enable") {
255
265
  state.override = "on";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-openai-fast",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A pi extension that enables OpenAI Codex Fast mode for ChatGPT-auth GPT-5.4 and GPT-5.5 by injecting the priority service tier.",
5
5
  "keywords": ["pi-package", "pi", "openai", "codex", "fast"],
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-extensions",
3
- "version": "0.1.21",
4
- "description": "A collection of pi extensions, including a GitHub librarian with opt-in local repo checkout caching, a minimal custom footer, an Amp-style oracle, a 200k context cap for auto-compaction, a local HTML context inspector, OpenAI Codex Fast mode controls, quiet one-line collapsed invocation previews, a permission gate for dangerous bash commands, confirm-before-destructive session actions, and terminal notifications when pi is ready for input.",
3
+ "version": "0.1.22",
4
+ "description": "A collection of pi extensions, including a GitHub librarian with toggleable local repo checkout caching, a minimal custom footer, an Amp-style oracle, a 200k context cap for auto-compaction, a local HTML context inspector, OpenAI Codex Fast mode controls, quiet one-line collapsed invocation previews, a permission gate for dangerous bash commands, confirm-before-destructive session actions, and terminal notifications when pi is ready for input.",
5
5
  "keywords": ["pi-package", "pi", "terminal", "agent"],
6
6
  "license": "MIT",
7
7
  "repository": {