pi-lean-portal 0.3.3 → 0.4.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.
Files changed (3) hide show
  1. package/README.md +20 -45
  2. package/browser-toggle.ts +10 -101
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -115,17 +115,10 @@ toggles guide-saving mode, and manages browser profiles.
115
115
  ### Persistence
116
116
 
117
117
  The toggle state is stored in the conversation's branch history. A fresh
118
- conversation starts with the default from `settings.json` (`browserToggle.defaultEnabled`,
119
- which defaults to `true`).
120
-
121
- > ⚠️ `browserToggle.defaultEnabled` is still read today but is scheduled to be
122
- > replaced by the `pi-tool-masking` library's `toolsetDefaults` block in an
123
- > upcoming release — **that block is not read yet**, so keep the legacy key
124
- > until the replacement ships. See
125
- > [Configuration (`settings.json`)](#configuration-settingsjson) for the
126
- > future shape and how to pre-add it harmlessly. A migration warning fires on
127
- > session start once the legacy key is present and the web default hasn't yet
128
- > been mirrored into `toolsetDefaults`.
118
+ conversation starts with the default from `settings.json` — the
119
+ `pi-tool-masking` library's `toolsetDefaults` block (see
120
+ [Configuration (`settings.json`)](#configuration-settingsjson)), falling back
121
+ to the toolset's packaged default (`true` for `web`).
129
122
 
130
123
  ---
131
124
 
@@ -615,48 +608,30 @@ a `profile` parameter:
615
608
  }
616
609
  ```
617
610
 
618
- ### `browserToggle.defaultEnabled` *(deprecated — not yet replaced)*
611
+ ### `toolsetDefaults` *(settings-based toolset defaults)*
619
612
 
620
- Whether browser tools are enabled on fresh conversations. **This key is still
621
- read today and works as shown.** It is *scheduled* to be replaced by the
622
- `pi-tool-masking` library's `toolsetDefaults` block in an upcoming release —
623
- **that block is not read yet**, so keep this key until the replacement ships.
613
+ Whether browser tools are enabled on fresh conversations. Read by the
614
+ `pi-tool-masking` library at restore time, between the chat-branch tier and
615
+ the toolset's packaged default:
624
616
 
625
617
  ```jsonc
626
618
  {
627
- "browserToggle": {
628
- "defaultEnabled": true
619
+ "toolsetDefaults": {
620
+ "toolset-state:pi-lean-dimension.web": { "enabled": true },
621
+ "toolset-state:pi-lean-dimension.web-learn": { "enabled": false },
622
+ "toolset-state:pi-lean-dimension.search": { "enabled": true }
629
623
  }
630
624
  }
631
625
  ```
632
626
 
633
- > ⚠️ **Preparing for the offload.** Settings-based toolset defaults are being
634
- > offloaded to the `pi-tool-masking` library, which will read a new
635
- > `toolsetDefaults` block keyed by persist key. **The new block is not read
636
- > by the current release** — it's harmless to add now and will take effect
637
- > automatically once the offload ships, at which point the legacy key stops
638
- > being read. To pre-stage the migration, set both:
639
- >
640
- > ```jsonc
641
- > {
642
- > "browserToggle": { "defaultEnabled": true },
643
- > "toolsetDefaults": {
644
- > "toolset-state:pi-lean-dimension.web": { "enabled": true },
645
- > "toolset-state:pi-lean-dimension.web-learn": { "enabled": false },
646
- > "toolset-state:pi-lean-dimension.search": { "enabled": true }
647
- > }
648
- > }
649
- > ```
650
- >
651
- > - Keys are the toolsets' `persistKey` values (`toolset-state:<id>`).
652
- > - Omit a `toolsetDefaults` key to use the toolset's packaged default (`web`
653
- > and `search` default `true`; `web-learn` defaults `false`).
654
- > - The `search` key only applies when `pi-lean-search` is installed.
655
- >
656
- > Once the offload ships and the legacy read is removed, delete the
657
- > `browserToggle` block. Until then, a migration warning fires on session
658
- > start when the legacy key is present and the web default hasn't yet been
659
- > mirrored into `toolsetDefaults`; mirroring it suppresses the warning.
627
+ - Keys are the toolsets' `persistKey` values (`toolset-state:<id>`).
628
+ - Omit a `toolsetDefaults` key to use the toolset's packaged default (`web`
629
+ and `search` default `true`; `web-learn` defaults `false`).
630
+ - The `search` key only applies when `pi-lean-search` is installed.
631
+
632
+ > The legacy `browserToggle.defaultEnabled` key is **removed in 0.4.0** — it
633
+ > is no longer read. If you pinned it, move the value into the matching
634
+ > `toolsetDefaults` entry above.
660
635
 
661
636
  ### `browser.maxStorageStateSize`
662
637
 
package/browser-toggle.ts CHANGED
@@ -9,24 +9,12 @@ import {
9
9
  getDefaultResolutionMode,
10
10
  } from "pi-tool-masking";
11
11
  import type { ToolsetSpec } from "pi-tool-masking";
12
- import { readMergedSettings } from "./core/shared/settings-reader.js";
13
-
14
- // Focus-mode guard helper. The library's published `DefaultResolutionMode`
15
- // type is `"exclusion" | "inclusion"` (the allowlist mode is unpublished /
16
- // ships in pi-tool-masking 1.2.0), so the string cast is load-bearing: an
17
- // allowlist-capable consumer sharing the `globalThis` module state writes
18
- // `"allowlist"` into it, and this consumer reads that value back at runtime
19
- // even though its own bundled type doesn't name the mode. On published
20
- // versions no caller ever writes `"allowlist"`, so this is a no-op for
21
- // ordinary users — it only activates when an allowlist-capable
22
- // pi-tool-masking consumer is in play.
23
- //
24
- // Cleanup at the ^1.2.0 bump: once `DefaultResolutionMode` names
25
- // `"allowlist"`, drop the `as string` cast here and in pi-lean-search's
26
- // co-activation mirror — the type system can then check the comparison
27
- // directly and the cast becomes a suppressor of a check it should perform.
12
+
13
+ // Focus-mode guard: refuse actuating subcommands while the library holds the
14
+ // line — inclusion mode or allowlist focus (an upstream pi-tool-masking
15
+ // consumer).
28
16
  function isFocusHolding(): boolean {
29
- const mode = getDefaultResolutionMode() as string;
17
+ const mode = getDefaultResolutionMode();
30
18
  return mode === "inclusion" || mode === "allowlist";
31
19
  }
32
20
 
@@ -154,86 +142,13 @@ function renderBrowserGlyph(
154
142
  }
155
143
  }
156
144
 
157
- // ---- Legacy settings migration warning ---------------------------
158
- //
159
- // The portal currently seeds the web toolset's fresh-session default from
160
- // `browserToggle.defaultEnabled` in settings.json. An upcoming pi-tool-masking
161
- // release takes over settings-based toolset defaults and reads a new
162
- // `toolsetDefaults` block instead. Warn users who pinned the legacy key so
163
- // they can migrate before the offload lands and the legacy read is removed.
164
- //
165
- // ponytail: warn-only — we still honor the legacy key for backward compat
166
- // until pi-tool-masking owns the settings tier; then delete this helper and
167
- // the `browserToggle` read below. Ceiling: a silent default shift for users
168
- // who ignore the warning; upgrade path is the pi-tool-masking bump.
169
- const TOOLSET_DEFAULTS_MIGRATION_MSG =
170
- "⚠️ pi-lean-portal: settings-based toolset defaults are moving to the " +
171
- "pi-tool-masking library. The `browserToggle.defaultEnabled` key in your " +
172
- "settings.json will stop being read in an upcoming release. It still works " +
173
- "today — KEEP it until the replacement ships, and add the new " +
174
- "`toolsetDefaults` block alongside it so your config is ready (the new " +
175
- "block is not read yet, but is harmless now and will take effect " +
176
- "automatically once the offload lands):\n\n" +
177
- "{\n" +
178
- ' "browserToggle": { "defaultEnabled": true },\n' +
179
- ' "toolsetDefaults": {\n' +
180
- ' "toolset-state:pi-lean-dimension.web": { "enabled": true },\n' +
181
- ' "toolset-state:pi-lean-dimension.web-learn": { "enabled": true },\n' +
182
- ' "toolset-state:pi-lean-dimension.search": { "enabled": true }\n' +
183
- " }\n" +
184
- "}\n" +
185
- "(omit a `toolsetDefaults` key to use the toolset's packaged default; the " +
186
- "`search` key only applies when pi-lean-search is installed). Mirror your " +
187
- "web default into `toolset-state:pi-lean-dimension.web` to silence this " +
188
- "warning.";
189
-
190
- function hasLegacyToolsetDefault(merged: Record<string, unknown>): boolean {
191
- const seg = merged["browserToggle"];
192
- if (!seg || typeof seg !== "object" || Array.isArray(seg)) return false;
193
- return (
194
- typeof (seg as Record<string, unknown>)["defaultEnabled"] === "boolean"
195
- );
196
- }
197
-
198
- // The new `toolsetDefaults` block the pi-tool-masking offload will read.
199
- // When the user has already migrated the web toolset's default into it,
200
- // the warning is redundant even if the legacy `browserToggle.defaultEnabled`
201
- // key is still sitting on disk — suppress so a migrated settings file stays
202
- // quiet. Only the web persist key gates this: it's the one the legacy key
203
- // controlled, so its presence means the user acted on the migration.
204
- const WEB_TOOLSET_PERSIST_KEY = "toolset-state:pi-lean-dimension.web";
205
- function hasMigratedToolsetDefault(merged: Record<string, unknown>): boolean {
206
- const td = merged["toolsetDefaults"];
207
- if (!td || typeof td !== "object" || Array.isArray(td)) return false;
208
- const entry = (td as Record<string, unknown>)[WEB_TOOLSET_PERSIST_KEY];
209
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) return false;
210
- return typeof (entry as Record<string, unknown>)["enabled"] === "boolean";
211
- }
212
-
213
145
  // ---- Toggle initializer ------------------------------------------
214
146
 
215
147
  export default function initBrowserToggle(pi: ExtensionAPI) {
216
- const merged = readMergedSettings();
217
- // Warn only when the legacy key is pinned AND the user hasn't already
218
- // migrated the web default into `toolsetDefaults`. Once the migrated
219
- // entry exists, pi-tool-masking will read it directly and the legacy
220
- // key is dead weight — no need to nag.
221
- const legacyDefaultPinned =
222
- hasLegacyToolsetDefault(merged) && !hasMigratedToolsetDefault(merged);
223
- const browserToggleSegment = (merged as Record<string, unknown>)[
224
- "browserToggle"
225
- ] as Record<string, unknown> | undefined;
226
- const webDefault =
227
- browserToggleSegment &&
228
- typeof browserToggleSegment["defaultEnabled"] === "boolean"
229
- ? (browserToggleSegment["defaultEnabled"] as boolean)
230
- : true;
231
-
232
- const webSpec: ToolsetSpec = {
233
- ...PORTAL_WEB_SPEC,
234
- defaultEnabled: webDefault,
235
- };
236
- const webToolset = defineToolset(pi, webSpec);
148
+ // Settings-based toolset defaults (`toolsetDefaults` tier) are read by
149
+ // pi-tool-masking itself inside defineToolset/restore — pass the packaged
150
+ // spec straight through.
151
+ const webToolset = defineToolset(pi, PORTAL_WEB_SPEC);
237
152
  const learnToolset = defineToolset(pi, PORTAL_LEARN_SPEC);
238
153
 
239
154
  // ── Keep cached state in sync with library events ─────────
@@ -267,8 +182,7 @@ export default function initBrowserToggle(pi: ExtensionAPI) {
267
182
  // unguarded, matching the focus controller's treatment of its own
268
183
  // read-only commands.
269
184
  if (["on", "off", "learn"].includes(cmd) && isFocusHolding()) {
270
- const inInclusion =
271
- (getDefaultResolutionMode() as string) === "inclusion";
185
+ const inInclusion = getDefaultResolutionMode() === "inclusion";
272
186
  ctx.ui.notify(
273
187
  inInclusion
274
188
  ? "Another plugin has active inclusion mode — this toolset can't be toggled while inclusion is holding the line. Deactivate it there first."
@@ -348,11 +262,6 @@ export default function initBrowserToggle(pi: ExtensionAPI) {
348
262
  restoreProfile(pi, ctx);
349
263
  _lastCtx = ctx;
350
264
  syncCachedState();
351
- // One-time-per-session migration warning when the legacy
352
- // `browserToggle.defaultEnabled` pin is still on disk.
353
- if (legacyDefaultPinned) {
354
- ctx.ui.notify(TOOLSET_DEFAULTS_MIGRATION_MSG, "warning");
355
- }
356
265
  });
357
266
 
358
267
  pi.on("session_tree", async (_event, ctx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-lean-portal",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "Pi extension. Interactive web browsing for Pi — a /web toggle removes the tools from context when switched off, Playwright Chromium/Firefox deliver accessibility-tree snapshots, persistent profiles, cookies, and domain-matched guides; custom/stealth backends (Camoufox) plug in when a site blocks the shipped browsers.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "node-html-parser": "^6.1.0",
59
- "pi-tool-masking": "^1.1.0",
59
+ "pi-tool-masking": "^1.2.0",
60
60
  "playwright": "^1.60.0",
61
61
  "turndown": "^7.2.0"
62
62
  },