pi-lean-host 0.6.0 → 0.7.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
@@ -397,8 +397,8 @@ the toolset's packaged default:
397
397
  ```
398
398
 
399
399
  - Keys are the toolsets' `persistKey` values.
400
- - Pins do not apply in spawned subagent children (see pi-tool-masking
401
- 1.3.0's `piToolMasking.childPolicy` for the opt-out).
400
+ - Pins do not apply in spawned subagent children (see pi-tool-masking's
401
+ `piToolMasking.childPolicy` for the opt-out).
402
402
  - Omit a key to use the packaged default (`api` defaults `true`; `api-learn`
403
403
  defaults `false`).
404
404
  - The `api-learn` toolset `requires` `api`, so enabling learn cascades api on;
@@ -22,11 +22,7 @@ import type {
22
22
  ExtensionContext,
23
23
  ThemeColor,
24
24
  } from "@earendil-works/pi-coding-agent";
25
- import {
26
- defineToolset,
27
- TOOLSET_EVENTS,
28
- getDefaultResolutionMode,
29
- } from "pi-tool-masking";
25
+ import { defineToolset, TOOLSET_EVENTS } from "pi-tool-masking";
30
26
  import type { ToolsetSpec } from "pi-tool-masking";
31
27
  import { handleHelpersSubcommand } from "./helpers-command.js";
32
28
  import { handleSecretsSubcommand } from "./secrets-command.js";
@@ -38,11 +34,24 @@ import { getAllHelpers, getDisabledHelperDomains } from "./local-helpers.js";
38
34
  import { resolveProvisionedParentDomain } from "./auth.js";
39
35
  import { listNames } from "./secrets-store.js";
40
36
 
41
- // Focus-mode guard: refuse actuating subcommands while allowlist focus holds
42
- // (an upstream pi-tool-masking consumer). A sibling toggle must not write a
43
- // focus-indistinguishable {enabled} entry.
44
- function isFocusHolding(): boolean {
45
- return getDefaultResolutionMode() === "allowlist";
37
+ // Catch AllowlistModeError by name, never `instanceof` — the handle may come
38
+ // from a different library copy via the shared registry. Returns true when
39
+ // the toggle ran, false when it was refused (nothing changed).
40
+ function refuseOnAllowlist(
41
+ ctx: ExtensionCommandContext,
42
+ toggle: () => unknown,
43
+ message = "Focus mode (allowlist) is active — this toolset can't be toggled while focus is holding the line. Exit focus there first.",
44
+ ): boolean {
45
+ try {
46
+ toggle();
47
+ return true;
48
+ } catch (err) {
49
+ if ((err as { name?: string } | undefined)?.name === "AllowlistModeError") {
50
+ ctx.ui.notify(message, "warning");
51
+ return false;
52
+ }
53
+ throw err;
54
+ }
46
55
  }
47
56
 
48
57
  // ---- Toolset specs -----------------------------------------------
@@ -316,7 +325,7 @@ user.`;
316
325
  */
317
326
  async function handleBootstrapSubcommand(
318
327
  args: string,
319
- hooks: { learnEnabled: () => boolean; enableLearn: () => void },
328
+ hooks: { learnEnabled: () => boolean; enableLearn: () => boolean },
320
329
  pi: ExtensionAPI,
321
330
  ctx: ExtensionCommandContext,
322
331
  ): Promise<void> {
@@ -361,16 +370,10 @@ async function handleBootstrapSubcommand(
361
370
  }
362
371
 
363
372
  // F5: auto-enable learn when off (same as the user running /api learn);
364
- // loud fail if the focus-mode guard blocks the enable. Learn stays off.
373
+ // a refused enable (allowlist focus) leaves learn off and returns after
374
+ // the hook's own refusal notify.
365
375
  if (!hooks.learnEnabled()) {
366
- if (isFocusHolding()) {
367
- ctx.ui.notify(
368
- "Focus mode (allowlist) is active — bootstrap needs to enable learn mode, which can't be toggled while focus is holding the line. Exit focus there first.",
369
- "warning",
370
- );
371
- return;
372
- }
373
- hooks.enableLearn();
376
+ if (!hooks.enableLearn()) return;
374
377
  // A mode flip the user didn't ask for must not be silent (inject-and-exit
375
378
  // otherwise produces no output).
376
379
  ctx.ui.notify(
@@ -421,22 +424,19 @@ export default function initApiToggle(pi: ExtensionAPI): void {
421
424
  const sub = parts[0]?.toLowerCase() ?? "";
422
425
  const rest = parts.slice(1).join(" ");
423
426
 
424
- // Focus-mode guard: refuse actuating subcommands while allowlist
425
- // focus holds (an upstream pi-tool-masking consumer) — a sibling
426
- // toggle must not write a focus-indistinguishable {enabled} entry.
427
- // Read-only subcommands (status/helpers/bare /api) stay unguarded.
428
- if (["on", "off", "learn"].includes(sub) && isFocusHolding()) {
429
- ctx.ui.notify(
430
- "Focus mode (allowlist) is active — this toolset can't be toggled while focus is holding the line. Exit focus there first.",
431
- "warning",
432
- );
433
- return;
434
- }
435
-
427
+ // Focus-mode handling: allowlist refusals are caught by
428
+ // refuseOnAllowlist — a caught AllowlistModeError means "refused,
429
+ // nothing changed". Non-actuating subcommands (status/helpers/bare
430
+ // /api) never toggle, so they need no guard.
436
431
  switch (sub) {
437
432
  case "on": {
438
- apiToolset.enable(pi);
439
- learnToolset.disable(pi);
433
+ if (
434
+ !refuseOnAllowlist(ctx, () => {
435
+ apiToolset.enable(pi, ctx.sessionManager);
436
+ learnToolset.disable(pi, ctx.sessionManager);
437
+ })
438
+ )
439
+ return;
440
440
  ctx.ui.notify(
441
441
  `📡 API tools enabled. /api learn to make ${learnToolNames()} available.`,
442
442
  "info",
@@ -445,13 +445,24 @@ export default function initApiToggle(pi: ExtensionAPI): void {
445
445
  }
446
446
 
447
447
  case "off": {
448
- apiToolset.disable(pi); // cascades learn off via requires
448
+ if (
449
+ !refuseOnAllowlist(ctx, () =>
450
+ apiToolset.disable(pi, ctx.sessionManager), // cascades learn off via requires
451
+ )
452
+ )
453
+ return;
449
454
  ctx.ui.notify("📡 API tools disabled. /api on to re-enable.", "info");
450
455
  return;
451
456
  }
452
457
 
453
458
  case "learn": {
454
- learnToolset.enable(pi); // cascades api on via requires
459
+ if (
460
+ !refuseOnAllowlist(
461
+ ctx,
462
+ () => learnToolset.enable(pi, ctx.sessionManager), // cascades api on via requires
463
+ )
464
+ )
465
+ return;
455
466
  ctx.ui.notify(
456
467
  `📖 ${learnToolNames()} tools are now available. ` +
457
468
  "Agent will discover shapes and save/update guides when asked.",
@@ -512,7 +523,12 @@ export default function initApiToggle(pi: ExtensionAPI): void {
512
523
  rest,
513
524
  {
514
525
  learnEnabled: () => learnToolset.isEnabled(pi),
515
- enableLearn: () => learnToolset.enable(pi), // cascades api on via requires
526
+ enableLearn: () =>
527
+ refuseOnAllowlist(
528
+ ctx,
529
+ () => learnToolset.enable(pi, ctx.sessionManager), // cascades api on via requires
530
+ "Focus mode (allowlist) is active — bootstrap needs to enable learn mode, which can't be toggled while focus is holding the line. Exit focus there first.",
531
+ ),
516
532
  },
517
533
  pi,
518
534
  ctx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-lean-host",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Read-only REST API client for Pi. Your agent authors and calls YAML recipes handling the tedious parts: pagination, OAuth2, rate limits, backoff. Credentials live in a local store, injected in code, never in agent context. Churn-free research + retrieval",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "dependencies": {
88
88
  "fast-xml-parser": "^5.7.0",
89
- "pi-tool-masking": "^1.3.0",
89
+ "pi-tool-masking": "^2.0.1",
90
90
  "undici": "^8.0.0",
91
91
  "yaml": "^2.7.0"
92
92
  },