pi-hide-providers 0.1.3 → 0.1.4

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
@@ -30,7 +30,8 @@ Pi has `enabledModels` in `settings.json` as an allowlist, but maintaining it ma
30
30
  - The `/model` selector, `Ctrl+P` cycling, `--list-models`, and session restoration all see only visible models
31
31
  - `/hide-models reset` unpatches the registry — all models return immediately
32
32
  - Changes via `/hide-models add` and `/hide-models remove` take effect immediately (no reload needed)
33
- - Interactive `/hide-models` command — no-args opens the TUI selector; subcommands for adding, removing, and inspecting rules
33
+ - Interactive `/hide-models` TUI lists visible providers/models first, re-sorting as you hide or show items — same ordering behavior as pi core's `/scoped-models`
34
+ - `/hide-models` subcommands for adding, removing, and inspecting rules
34
35
 
35
36
  No `settings.json` is modified. No 250+ entry explosion. No allowlist semantics.
36
37
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-hide-providers",
3
- "version": "0.1.3",
4
- "description": "Hide providers and models from pi's model selector \u2014 filter the /model list and Ctrl+P cycling via a configurable blocklist",
3
+ "version": "0.1.4",
4
+ "description": "Hide providers and models from pi's model selector — filter the /model list and Ctrl+P cycling via a configurable blocklist",
5
5
  "type": "module",
6
6
  "author": "Tom X Nguyen",
7
7
  "license": "MIT",
@@ -103,6 +103,8 @@ export class HideProviderSelectorComponent implements Component {
103
103
  hidden: isHidden(currentRules, m.provider, m.id),
104
104
  });
105
105
  }
106
+ // Enabled (visible) providers/models first, then alphabetical within each group
107
+ this.sortItems(this.allItems);
106
108
  this.filteredItems = [...this.allItems];
107
109
 
108
110
  this.searchInput = new Input();
@@ -268,6 +270,15 @@ export class HideProviderSelectorComponent implements Component {
268
270
 
269
271
  private refresh(): void {
270
272
  const query = this.searchInput.getValue();
273
+
274
+ // Recompute hidden status on the canonical full list first, then sort it.
275
+ // This ensures both allItems and filteredItems stay ordered as enabled
276
+ // (visible) models first, disabled (hidden) models second.
277
+ for (const item of this.allItems) {
278
+ item.hidden = isHidden(this.hiddenRules, item.provider, item.modelId);
279
+ }
280
+ this.sortItems(this.allItems);
281
+
271
282
  this.filteredItems = query
272
283
  ? fuzzyFilter(
273
284
  this.allItems,
@@ -276,18 +287,42 @@ export class HideProviderSelectorComponent implements Component {
276
287
  )
277
288
  : [...this.allItems];
278
289
 
279
- // Update hidden status on all items (rules may have changed)
280
- for (const item of this.filteredItems) {
281
- item.hidden = isHidden(this.hiddenRules, item.provider, item.modelId);
282
- }
290
+ // Ensure filtered results also honor enabled-first ordering.
291
+ this.sortItems(this.filteredItems);
283
292
 
293
+ // Keep the cursor at the same relative position after re-sorting. The
294
+ // selected model may change, which matches pi's /scoped-models behavior.
284
295
  this.selectedIndex = Math.min(
285
296
  this.selectedIndex,
286
297
  Math.max(0, this.filteredItems.length - 1),
287
298
  );
299
+
288
300
  this.updateList();
289
301
  }
290
302
 
303
+ /** Sort items so enabled (visible) models come before disabled (hidden)
304
+ * models, then alphabetically by provider and model id. Each model is ranked
305
+ * individually — a single visible model in a provider does not pull the whole
306
+ * provider to the top.
307
+ */
308
+ private sortItems(items: DisplayItem[]): void {
309
+ items.sort((a, b) => {
310
+ // Visible models first, then hidden models.
311
+ if (a.hidden !== b.hidden) {
312
+ return a.hidden ? 1 : -1;
313
+ }
314
+
315
+ // Then alphabetical by provider.
316
+ const providerCompare = a.provider.localeCompare(b.provider);
317
+ if (providerCompare !== 0) {
318
+ return providerCompare;
319
+ }
320
+
321
+ // Then alphabetical by model id.
322
+ return a.modelId.localeCompare(b.modelId);
323
+ });
324
+ }
325
+
291
326
  private updateList(): void {
292
327
  this.listContainer.clear();
293
328