bermudis-pi-goodies 0.5.2 → 0.5.3

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
@@ -21,7 +21,7 @@ extensions. One entry point, ten independent features.
21
21
  After publishing the package to npm:
22
22
 
23
23
  ```bash
24
- pi install npm:bermudis-pi-goodies@0.5.2
24
+ pi install npm:bermudis-pi-goodies@0.5.3
25
25
  ```
26
26
 
27
27
  Remove any old `bermudis-pi-goodies.ts` symlink before reloading Pi. Each
@@ -79,8 +79,10 @@ manually create or edit a pin for B while settings still name A, the current
79
79
  session remains on A and B starts with the next fresh session. Resuming an
80
80
  existing session restores that session's model instead.
81
81
 
82
- `/new` keeps the model from the session you were just in, rather than switching
83
- to the pinned default. The pin still applies to a fresh `pi` launch.
82
+ `/new` keeps the model and thinking level from the session you were just in,
83
+ rather than switching to the pinned default and the settings thinking level.
84
+ The level is re-applied after any per-model thinking policy, so a `/new`
85
+ carries over a manual override. The pin still applies to a fresh `pi` launch.
84
86
 
85
87
  Older config files may contain `thinkingLevel`; that field is accepted for
86
88
  compatibility but ignored and should be managed in `model-thinking.json` instead.
package/fixed-defaults.ts CHANGED
@@ -15,11 +15,21 @@ import {
15
15
  const CONFIG_FILENAME = "fixed-defaults.json";
16
16
 
17
17
  /**
18
- * Model active in the session being replaced by `/new`, captured during
19
- * `session_before_switch`. The factory is re-invoked per session, so this must
20
- * live at module scope to survive the switch to the new extension instance.
18
+ * Model and thinking level active in the session being replaced by `/new`,
19
+ * captured during `session_before_switch`. The factory is re-invoked per
20
+ * session, so this must live at module scope to survive the switch to the new
21
+ * extension instance.
21
22
  */
22
- let previousModelForNewSession: { provider: string; id: string } | null = null;
23
+ let previousModelForNewSession: PreviousSessionModel | null = null;
24
+
25
+ /** Model + thinking level snapshot taken when `/new` replaces a session. */
26
+ interface PreviousSessionModel {
27
+ provider: string;
28
+ id: string;
29
+ thinkingLevel: ThinkingLevel;
30
+ }
31
+
32
+ type ThinkingLevel = ReturnType<ExtensionAPI["getThinkingLevel"]>;
23
33
  /**
24
34
  * Values read from the override file. `provider` and `model` are a coupled
25
35
  * pair — a model id is meaningless without its provider, so both must be
@@ -233,13 +243,13 @@ export default function fixedDefaults(
233
243
  }
234
244
 
235
245
  /**
236
- * Restore the model that was active before `/new`. Unlike the pin, this only
237
- * applies to the session being created, so the next fresh `pi` still starts
238
- * from the pin.
246
+ * Restore the model and thinking level that were active before `/new`.
247
+ * Unlike the pin, this only applies to the session being created, so the
248
+ * next fresh `pi` still starts from the pin.
239
249
  */
240
250
  async function restorePreviousModel(
241
251
  ctx: ExtensionContext,
242
- previous: { provider: string; id: string } | null,
252
+ previous: PreviousSessionModel | null,
243
253
  ): Promise<void> {
244
254
  if (!previous) return;
245
255
  const model = ctx.modelRegistry.find(previous.provider, previous.id);
@@ -247,7 +257,13 @@ export default function fixedDefaults(
247
257
  // setModel writes the restored model to settings.json, then its model_select
248
258
  // notification re-applies the pin afterwards (see restorePinnedModel), so
249
259
  // the active session keeps the previous model while the pin survives.
250
- await pi.setModel(model);
260
+ // That same notification can re-apply a per-model thinking policy
261
+ // (model-thinking.ts), so the captured level is only restored after
262
+ // setModel resolves — its emit is awaited, giving this the final word.
263
+ // setThinkingLevel clamps to the restored model's capabilities.
264
+ const applied = await pi.setModel(model);
265
+ if (!applied) return;
266
+ pi.setThinkingLevel(previous.thinkingLevel);
251
267
  }
252
268
 
253
269
  function enqueue<T>(
@@ -276,8 +292,9 @@ export default function fixedDefaults(
276
292
 
277
293
  pi.on("session_start", (event, ctx) => {
278
294
  // `/new` has already selected a model (the pinned default) by the time this
279
- // fires, so set the model that was active before the switch here. The
280
- // resulting model_select notification re-applies the pin in settings.json.
295
+ // fires, so restore the model and thinking level that were active before
296
+ // the switch here. The resulting model_select notification re-applies the
297
+ // pin in settings.json.
281
298
  if (event.reason === "new") {
282
299
  const previous = previousModelForNewSession;
283
300
  previousModelForNewSession = null;
@@ -300,7 +317,11 @@ export default function fixedDefaults(
300
317
  if (event.reason === "new") {
301
318
  const model = ctx.model;
302
319
  previousModelForNewSession = model
303
- ? { provider: model.provider, id: model.id }
320
+ ? {
321
+ provider: model.provider,
322
+ id: model.id,
323
+ thinkingLevel: pi.getThinkingLevel(),
324
+ }
304
325
  : null;
305
326
  }
306
327
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bermudis-pi-goodies",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "description": "A bundle of small, frequently-used Pi extensions.",
6
6
  "keywords": ["pi-package"],