{"_id":"@benvargas/pi-model-sort","_rev":"2-9cc2c7342312042957befc60b3ea991b","name":"@benvargas/pi-model-sort","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@benvargas/pi-model-sort","version":"1.0.0","keywords":["pi","pi-package","pi-extension","pi-coding-agent","model","sort","mru","last-used","model-selector","thinking-level"],"author":{"name":"Ben Vargas"},"license":"MIT","_id":"@benvargas/pi-model-sort@1.0.0","maintainers":[{"name":"benvargas","email":"ben@vargas.com"}],"homepage":"https://github.com/ben-vargas/pi-packages/tree/main/packages/pi-model-sort#readme","bugs":{"url":"https://github.com/ben-vargas/pi-packages/issues"},"pi":{"extensions":["./extensions/index.ts"]},"dist":{"shasum":"a570dd2be6e939d51433f4a7ab3af617b6dab95e","tarball":"https://registry.npmjs.org/@benvargas/pi-model-sort/-/pi-model-sort-1.0.0.tgz","fileCount":7,"integrity":"sha512-LJ2WI+2RWORDs9p+sjrRUqV2CPJpYW7hirPYO+yw6wwei1zGsONVJd2hJ+ygVFk7rbzRX0QKlkwaa18cHUaE7A==","signatures":[{"sig":"MEUCIQCWyg47nGzmqViCEPoej6NSqMKwr7qfOKc95o6ZrAOk6AIgKG3Jm7ksLZPCcA8quxWljC9kF9fdOXOl6lIys7c9PGU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":40157},"type":"module","gitHead":"7ee5745eff1fb37444968de2ad911443315a3811","_npmUser":{"name":"benvargas","email":"ben@vargas.com"},"repository":{"url":"git+https://github.com/ben-vargas/pi-packages.git","type":"git","directory":"packages/pi-model-sort"},"_npmVersion":"11.9.0","description":"Sort models in pi by last usage and start fresh sessions on the most recently used model","directories":{},"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.84.0"},"_npmOperationalInternal":{"tmp":"tmp/pi-model-sort_1.0.0_1787945862559_0.5482214943559021","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@benvargas/pi-model-sort","version":"1.0.2","description":"Sort models in pi by last usage and start fresh sessions on the most recently used model","keywords":["pi","pi-package","pi-extension","pi-coding-agent","model","sort","mru","last-used","model-selector","thinking-level"],"type":"module","pi":{"extensions":["./extensions/index.ts"]},"peerDependencies":{"@earendil-works/pi-coding-agent":">=0.84.0"},"repository":{"type":"git","url":"git+https://github.com/ben-vargas/pi-packages.git","directory":"packages/pi-model-sort"},"author":{"name":"Ben Vargas"},"license":"MIT","bugs":{"url":"https://github.com/ben-vargas/pi-packages/issues"},"homepage":"https://github.com/ben-vargas/pi-packages/tree/main/packages/pi-model-sort#readme","gitHead":"a27429aed49cd5e1bd9beb11418b77d47f7bb196","_id":"@benvargas/pi-model-sort@1.0.2","_nodeVersion":"26.8.1","_npmVersion":"11.19.0","dist":{"integrity":"sha512-WO0TmU4+XXUdhDDvzMy+aSSYfYO0ckcRYbtoDUP7CtnVxLcyntawZ6YOKaklEQPjhBhEFCmQISwJ2EqFJ6/1Gw==","shasum":"8c1c37fa5fee3d39c99d6719b9051818b603f6f1","tarball":"https://registry.npmjs.org/@benvargas/pi-model-sort/-/pi-model-sort-1.0.2.tgz","fileCount":7,"unpackedSize":44462,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDq8S8cTu2aELnac4O8Rs0aj+YOPHAUdB7P/Dy0czbECwIhAIZjoQJNBpxKGTyWW1jpZgy6qG4s0/oMqoZOJYtRsk7U"}]},"_npmUser":{"name":"benvargas","email":"ben@vargas.com"},"directories":{},"maintainers":[{"name":"benvargas","email":"ben@vargas.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-model-sort_1.0.2_1789140210002_0.6332934799304368"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-28T19:37:42.377Z","modified":"2026-09-11T15:23:30.375Z","1.0.0":"2026-08-28T19:37:42.695Z","1.0.2":"2026-09-11T15:23:30.159Z"},"bugs":{"url":"https://github.com/ben-vargas/pi-packages/issues"},"author":{"name":"Ben Vargas"},"license":"MIT","homepage":"https://github.com/ben-vargas/pi-packages/tree/main/packages/pi-model-sort#readme","keywords":["pi","pi-package","pi-extension","pi-coding-agent","model","sort","mru","last-used","model-selector","thinking-level"],"repository":{"type":"git","url":"git+https://github.com/ben-vargas/pi-packages.git","directory":"packages/pi-model-sort"},"description":"Sort models in pi by last usage and start fresh sessions on the most recently used model","maintainers":[{"name":"benvargas","email":"ben@vargas.com"}],"readme":"# @benvargas/pi-model-sort\n\nSorts pi's model picker by last usage and starts fresh sessions on your most recently used model.\n\n- `/model` picker — both \"Scope: all\" and \"Scope: scoped\" views, including fuzzy-search results — is sorted by recency: current model first → most recently used → provider/id alphabetical\n- Ctrl+P / Ctrl+Shift+P **scoped** cycling follows last-used order (scoped models come from `enabledModels` or `--models`)\n- Fresh starts and `/new` begin on your most recently used model instead of `enabledModels[0]` or the hardcoded provider default\n- An explicit `--model` on the command line always wins over MRU (so `pi --model provider/id`, scripts, and bb's Pi provider get the model they asked for); that model is recorded as last-used\n- Continued sessions (`pi -c`, `--session`, `/resume`, forks) keep the model saved in the session file, and that restored model is recorded as last-used (fresh `/new` sessions and `/reload` are excluded from that recording)\n- Remembers the thinking level you last used on each model and restores it on every switch, clamped to what each model supports\n- No configuration needed — tracking starts on first use and degrades to the default alphabetical order with no history\n\n> Forked from [monotykamary/pi-model-sort](https://github.com/monotykamary/pi-model-sort) (MIT, v0.3.2). See `THIRD_PARTY_NOTICES.md` for the full list of fork changes and attribution.\n\n## Install\n\n```bash\npi install npm:@benvargas/pi-model-sort\n```\n\nOr try without installing:\n\n```bash\npi -e npm:@benvargas/pi-model-sort\n```\n\n## Usage\n\nThe extension works automatically — there are no commands to learn.\n\n```\n/model                    # Most recently used models appear at the top\nCtrl+P / Ctrl+Shift+P     # Cycle through scoped models in last-used order\npi                        # Fresh starts use MRU\npi --model provider/id    # Explicit model wins over MRU\npi -c                     # Continuations keep the session's model\n```\n\n## How It Works\n\n- Tracking uses pi's documented extension events: `/model` switches (`model_select`) and thinking-level changes (`thinking_level_select`) are timestamped into `~/.pi/agent/extensions/pi-model-sort.json`. Continued sessions restore their model during construction without emitting `model_select` (pi 0.84.3), so the extension records the restored model at `session_start` itself.\n- Sorting has no SDK hook, so the extension wraps (monkey-patches) internal methods: `ModelSelectorComponent.sortModels`, its scoped loader and `filterModels`, and `AgentSession._cycleScopedModel` for scoped cycling. All original methods are preserved and restored on shutdown/reload; the patches survive `modelRegistry.refresh()`.\n- The MRU startup override calls `pi.setModel()` on `session_start` for fresh starts and `/new` only, and never when the process was launched with `--model` (pi exposes no \"model came from the CLI\" signal to extensions, so the extension inspects `process.argv`). A continued session is detected by projecting its branch through pi's own context-message rules (`message`, `custom_message`, non-empty `branch_summary`, and `compaction` entries — exactly what `buildSessionContext()` counts) — pi seeds every new session with `model_change` + `thinking_level_change` entries before `session_start` fires, so raw branch length cannot distinguish fresh from continued.\n\n### Known limitations on pi 0.84.x\n\n- `--list-models` output is **not** sorted: the CLI lists models before extensions load and re-sorts by provider/id internally.\n- `/scoped-models` and unscoped Ctrl+P cycling are **not** re-sorted: they read `ModelRuntime` snapshots directly, not the extension-facing `ModelRegistry` facade this extension wraps. (Scoped cycling — the common case with `enabledModels` set — is sorted via the `_cycleScopedModel` wrapper.)\n\n## Configuration\n\nUsage history lives in `~/.pi/agent/extensions/pi-model-sort.json`:\n\n```json\n{\n  \"lastUsed\": {\n    \"provider/modelId\": 1717000000000\n  },\n  \"thinking\": {\n    \"provider/modelId\": \"high\"\n  }\n}\n```\n\nNo manual editing is needed. To clear usage history, delete the file and `/reload`.\n\n## Notes\n\n- Ctrl+P cycling does not update last-used timestamps — doing so would create a sort feedback loop (each cycle step re-sorts the selected model to the top, making the cycle toggle forever between the top two). Manual selections and session restores still update it.\n- Patches are coupled to pi internals; this package is maintained against current pi releases (peer requirement `>=0.84.0`, the version it is tested with).\n\n## Uninstall\n\n```bash\npi remove npm:@benvargas/pi-model-sort\n```","readmeFilename":"README.md"}