@jadelclemens/pi-model-map 0.0.0-stage → 0.1.1
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/LICENSE +86 -0
- package/README.md +299 -2
- package/examples/README.md +60 -0
- package/examples/cursor.json +571 -0
- package/package.json +51 -4
- package/src/catalog.ts +29 -0
- package/src/config.ts +84 -0
- package/src/constants.ts +10 -0
- package/src/index.ts +392 -0
- package/src/log.ts +36 -0
- package/src/mapping.ts +439 -0
- package/src/source-check.ts +87 -0
- package/src/warnings.ts +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pi-model-map contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Portions of this software are derived from `@open-cursor/pi-agent`, part of the
|
|
26
|
+
open-cursor project:
|
|
27
|
+
|
|
28
|
+
https://github.com/brandonkramer/open-cursor
|
|
29
|
+
(integrations/pi-agent/src/models/mapping.ts)
|
|
30
|
+
|
|
31
|
+
Copyright (c) open-cursor contributors
|
|
32
|
+
Licensed under the MIT License.
|
|
33
|
+
|
|
34
|
+
Specifically:
|
|
35
|
+
|
|
36
|
+
1. The logic of `ModelMapper.toBackendRef()` in `src/mapping.ts`, along
|
|
37
|
+
with the index-building in `ModelMapper.buildIndexes()`, is ported from
|
|
38
|
+
open-cursor's `toCursorId()` and its accompanying module-level index
|
|
39
|
+
construction over `MODEL_MAP`. Identifiers and data structures were
|
|
40
|
+
changed to fit this project (including adding the
|
|
41
|
+
`default`/`thinking`/`fast`/`thinking-fast` variant axes, which have no
|
|
42
|
+
open-cursor equivalent), but the control flow and core lookup/fallback
|
|
43
|
+
algorithm of this function originates from open-cursor.
|
|
44
|
+
|
|
45
|
+
(An earlier version of this project also ported open-cursor's reverse
|
|
46
|
+
lookup, `toCanonicalId()`, as `ModelMapper.toCanonicalId()`. That method
|
|
47
|
+
was never called anywhere in this project and has been removed.)
|
|
48
|
+
|
|
49
|
+
Note: `examples/cursor.json`'s model mapping data is NOT derived from
|
|
50
|
+
open-cursor. Earlier revisions of that example copied data from
|
|
51
|
+
open-cursor's `MODEL_MAP`, but it is now generated independently from
|
|
52
|
+
Cursor's own live model catalog (see examples/README.md). Only the
|
|
53
|
+
resolution logic described in item 1 above remains derived from open-cursor.
|
|
54
|
+
|
|
55
|
+
All other code and data in this software — including the JSON configuration
|
|
56
|
+
format, multi-provider delegate resolution, the config directory loader, Pi
|
|
57
|
+
provider registration, the `/pi-model-map-thinking` / `/pi-model-map-fast`
|
|
58
|
+
commands, namespace-clash validation, and the current `examples/cursor.json`
|
|
59
|
+
data — was written/generated independently and has no open-cursor
|
|
60
|
+
counterpart.
|
|
61
|
+
|
|
62
|
+
The original license text for open-cursor is reproduced below in accordance
|
|
63
|
+
with the MIT License's requirement to include the copyright and permission
|
|
64
|
+
notice in all copies or substantial portions of the software:
|
|
65
|
+
|
|
66
|
+
MIT License
|
|
67
|
+
|
|
68
|
+
Copyright (c) open-cursor contributors
|
|
69
|
+
|
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
71
|
+
of this software and associated documentation files (the "Software"), to
|
|
72
|
+
deal in the Software without restriction, including without limitation the
|
|
73
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
74
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
75
|
+
furnished to do so, subject to the following conditions:
|
|
76
|
+
|
|
77
|
+
The above copyright notice and this permission notice shall be included in
|
|
78
|
+
all copies or substantial portions of the Software.
|
|
79
|
+
|
|
80
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
81
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
82
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
83
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
84
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
85
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
86
|
+
IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,300 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jadelclemens/pi-model-map
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JSON-configurable Pi extension that collapses provider-specific baked-in effort/thinking/fast model variants into canonical model IDs, controlled by Pi's native effort selector plus two extra mapping-only toggles: `/pi-model-map-thinking` and `/pi-model-map-fast`.
|
|
4
|
+
|
|
5
|
+
> **Terminology note:** this README calls Pi's `/thinking` selector **"effort"** throughout (as most other harnesses do — `low`/`medium`/`high`/etc.), to avoid confusion with the separate "thinking mode" axis described below.
|
|
6
|
+
|
|
7
|
+
The core resolution function in [`src/mapping.ts`](src/mapping.ts) — the canonical-id/effort-level → backend-id lookup — is ported from `@open-cursor/pi-agent`'s `toCursorId()` / `MODEL_MAP` index-building in [`src/models/mapping.ts`](https://github.com/brandonkramer/open-cursor/blob/main/integrations/pi-agent/src/models/mapping.ts). Everything else — the JSON config format, the `mappings`/`map` schema (including the `default`/`thinking`/`fast`/`thinking-fast` variant axes), multi-provider `"provider/modelId"` delegate references, loading multiple config files from a `model-map/` directory, per-family registration via Pi's `registerVirtualModel`, the `/pi-model-map-thinking` / `/pi-model-map-fast` commands, and the namespace-clash warnings — is original to pi-model-map and has no equivalent in open-cursor. See [Credits & License](#credits--license) below for the precise breakdown.
|
|
8
|
+
|
|
9
|
+
## Why this exists
|
|
10
|
+
|
|
11
|
+
Some providers don't expose reasoning/effort as a normal API parameter. Cursor, for example, bakes **three separate axes** into the model ID string itself:
|
|
12
|
+
|
|
13
|
+
- **Effort level** — `claude-opus-5-low` / `-medium` / `-high` / etc. This maps naturally onto Pi's native `/thinking <level>` selector (what this README calls "effort").
|
|
14
|
+
- **Thinking mode** — a distinct `-thinking-` segment (`claude-opus-5-thinking-high` vs. `claude-opus-5-high`). This is closer to Anthropic's own `thinking.type: enabled/adaptive/disabled` API concept — whether the model uses extended-thinking blocks at all — and is **independent of effort level**.
|
|
15
|
+
- **Fast tier** — a `-fast` suffix (`claude-opus-5-high-fast`) selecting a faster routing tier. Undocumented by Cursor, but distinct from a "priority" request header some other providers use for the same idea.
|
|
16
|
+
|
|
17
|
+
That's up to 4 backend model IDs per effort level (`normal`, `thinking`, `fast`, `thinking+fast`) — usually surfaced to users as a wall of near-duplicate picker entries. pi-model-map collapses all of that into **one canonical model**, letting Pi's native effort selector handle the first axis, and adding two small, mapping-scoped toggle commands for the other two:
|
|
18
|
+
|
|
19
|
+
- `/pi-model-map-thinking [on|off]` — use the mapped **"thinking"** backend variant for the current effort level.
|
|
20
|
+
- `/pi-model-map-fast [on|off]` — use the mapped **"fast"** backend variant for the current effort level.
|
|
21
|
+
|
|
22
|
+
**Important:** these commands do not add, emulate, or send any real API parameter (no `thinking.type`, no `service_tier` header, nothing). They only change **which pre-baked backend model ID string** a `map` entry resolves to. If a provider instead exposes these as real request parameters, use that provider's own mechanism (e.g. a `before_provider_request` hook) instead of pi-model-map.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pi install /home/jadelclemens/code/pi-model-map
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Each mapping delegates inference to an existing Pi provider (e.g. `cursor-agent`, `opencode`) that owns real authentication.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Configs live in a **`model-map/` directory** — one `.json` file per provider mapping:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mkdir -p ~/.pi/agent/model-map
|
|
38
|
+
cp examples/cursor.json ~/.pi/agent/model-map/cursor.json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Pi loads **every** `*.json` file in the first matching directory:
|
|
42
|
+
|
|
43
|
+
1. `./model-map/`
|
|
44
|
+
2. `./.pi/model-map/`
|
|
45
|
+
3. `~/.pi/agent/model-map/`
|
|
46
|
+
|
|
47
|
+
Each file registers a separate provider namespace (e.g. `cursor/...`). Add another `.json` file (e.g. `opencode.json`) to register additional provider namespaces alongside it, one file per delegate provider.
|
|
48
|
+
|
|
49
|
+
### Per-file schema
|
|
50
|
+
|
|
51
|
+
```jsonc
|
|
52
|
+
{
|
|
53
|
+
// Provider the virtual models are listed under in /model. Defaults to the filename stem
|
|
54
|
+
// (cursor.json → "cursor"). May be a provider that also has physical models; a family id
|
|
55
|
+
// equal to a physical model id of that provider hides the physical one.
|
|
56
|
+
"provider": "cursor",
|
|
57
|
+
|
|
58
|
+
// Optional: path to the delegate provider's live catalog cache, used only to warn if a
|
|
59
|
+
// backend id below has been renamed/retired upstream (see "Verifying backend ids still
|
|
60
|
+
// exist" below). "~" expands to $HOME; relative paths resolve against this config file.
|
|
61
|
+
"source": "~/.pi/agent/cache/pi-cursor-agent/models.json",
|
|
62
|
+
"sourceListPath": "models",
|
|
63
|
+
|
|
64
|
+
// Canonical model id -> mapping entry (no need to re-prefix with "cursor-" — the
|
|
65
|
+
// provider namespace above already disambiguates it as /model cursor claude-opus-5)
|
|
66
|
+
"mappings": {
|
|
67
|
+
"claude-opus-5": {
|
|
68
|
+
// Display/catalog metadata (all optional)
|
|
69
|
+
"name": "Claude Opus 5 (Cursor)",
|
|
70
|
+
// "offSupported" overrides the automatic check for whether Pi's "off" thinking level
|
|
71
|
+
// means anything real for this family; see "Hiding a misleading 'off' level" below.
|
|
72
|
+
// "offSupported": false,
|
|
73
|
+
"contextWindow": 1000000,
|
|
74
|
+
"maxTokens": 128000,
|
|
75
|
+
|
|
76
|
+
// Effort level -> backend reference(s). Required.
|
|
77
|
+
"map": {
|
|
78
|
+
// Bare "provider/modelId" string = only a "default" variant exists for this level.
|
|
79
|
+
"low": "cursor-agent/claude-opus-5-low",
|
|
80
|
+
|
|
81
|
+
// Object form: up to 4 variants for this effort level.
|
|
82
|
+
// "default" is required; the rest are optional and fall back to "default"
|
|
83
|
+
// (or to "thinking"/"fast" for "thinking-fast") when omitted or toggled off.
|
|
84
|
+
"high": {
|
|
85
|
+
"default": "cursor-agent/claude-opus-5-high",
|
|
86
|
+
"thinking": "cursor-agent/claude-opus-5-thinking-high",
|
|
87
|
+
"fast": "cursor-agent/claude-opus-5-high-fast",
|
|
88
|
+
"thinking-fast": "cursor-agent/claude-opus-5-thinking-high-fast"
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
// A level can exist only in "thinking" form (no plain non-thinking backend at all).
|
|
92
|
+
// "default" still must be present — set it to whatever backend you want used when
|
|
93
|
+
// /pi-model-map-thinking is off but no non-thinking backend exists.
|
|
94
|
+
"xhigh": {
|
|
95
|
+
"default": "cursor-agent/claude-opus-5-thinking-xhigh",
|
|
96
|
+
"thinking": "cursor-agent/claude-opus-5-thinking-xhigh",
|
|
97
|
+
"thinking-fast": "cursor-agent/claude-opus-5-thinking-xhigh-fast"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Effort level keys: `default` (used when no `/thinking` level is set), `minimal`, `low`, `medium`, `high`, `xhigh`, `max`.
|
|
106
|
+
|
|
107
|
+
### Pi's `/thinking` picker only shows levels you actually mapped
|
|
108
|
+
|
|
109
|
+
Each family only lists a `map` entry for the effort levels it genuinely supports — e.g. a family whose real backends are only `low`/`high`/`max` has no `minimal`/`medium`/`xhigh` entries at all. pi-model-map reflects this in the registered model's `thinkingLevelMap` by setting every **unmapped** level to `null` explicitly, rather than leaving it out. This matters because Pi treats an *omitted* standard-level key (`minimal` through `high`) as "supported via provider default," not as unsupported — only an explicit `null` hides/clamps a level from `/thinking` and `pi.setThinkingLevel()`. Without this, a family that only mapped `low`/`high`/`max` would still show `minimal`/`medium` as selectable in the picker, silently falling back to `default` underneath instead of honoring what was picked. With it, `/thinking` (and its autocomplete/picker UI) only ever offers the levels a given canonical family actually maps.
|
|
110
|
+
|
|
111
|
+
### Hiding a misleading "off" level
|
|
112
|
+
|
|
113
|
+
Pi's `/thinking` picker always includes a literal `off` state ("no reasoning parameter sent at all") — that's baked into Pi's own `ModelThinkingLevel` type and UI, not something pi-model-map can rename. The trouble is some provider families have no genuine non-reasoning backend at all: every one of their raw backend ids implies *some* minimum reasoning tier, so this project's own `map.default` entry ends up aliased to whatever the provider treats as its floor (e.g. Cursor's `claude-sonnet-5` has no bare `claude-sonnet-5` id in its catalog at all — `map.default` is aliased to the exact same backend as `map.medium`). Selecting "off" for that family doesn't actually turn reasoning off; it silently reasons at `medium` anyway, which is exactly the mismatch this project should not paper over.
|
|
114
|
+
|
|
115
|
+
pi-model-map detects this automatically per family: if `mappings.<id>.map.default`'s `default` variant resolves to the *exact same* backend reference as one of that family's own named effort levels, it sets `thinkingLevelMap.off = null` for that model, hiding "off" from `/thinking` entirely (same mechanism Pi's own `models.md` documents for models where thinking can't be disabled, via a `"off": null` entry in `thinkingLevelMap`) — so you're never offered a state that lies about what's actually happening underneath. Families with a genuine floor (a bare id with no effort suffix, or a provider's own explicit "none"/no-reasoning id, e.g. `gpt-5.1`, `composer-2.5`) keep "off" as a real, distinct option.
|
|
116
|
+
|
|
117
|
+
Set `"offSupported": true` or `"offSupported": false` explicitly on a `mappings.<id>` entry to override the automatic check in either direction.
|
|
118
|
+
|
|
119
|
+
### `map` values are `provider/modelId`, optionally split into 4 variants
|
|
120
|
+
|
|
121
|
+
Every backend reference is a full delegate reference — **`"<delegateProvider>/<backendModelId>"`** — not a bare model ID. There is no separate top-level `delegateProvider` field; the delegate is embedded per reference.
|
|
122
|
+
|
|
123
|
+
Each effort level's value is either:
|
|
124
|
+
|
|
125
|
+
- a **bare string** — shorthand for `{ "default": "<value>" }`, i.e. no thinking/fast split exists for that level, or
|
|
126
|
+
- an **object** with up to 4 keys:
|
|
127
|
+
|
|
128
|
+
| Key | Meaning |
|
|
129
|
+
| --------------- | ------------------------------------- |
|
|
130
|
+
| `default` | thinking off, fast off. **Required.** |
|
|
131
|
+
| `thinking` | thinking on, fast off. |
|
|
132
|
+
| `fast` | thinking off, fast on. |
|
|
133
|
+
| `thinking-fast` | thinking on, fast on. |
|
|
134
|
+
|
|
135
|
+
At request time, pi-model-map picks a key based on the current `/pi-model-map-thinking` and `/pi-model-map-fast` toggle state. If the exact combination isn't configured for that level, it falls back to whichever configured variant honors the most of what was actually requested — e.g. if a level only has `thinking`/`thinking-fast` configured (no `default`/`fast` at all) and only `/pi-model-map-fast` is on, it uses `thinking-fast` rather than plain `thinking`, since `thinking-fast` also honors the fast request (both force thinking on regardless, since that's all the level has). Ties between equally-honored fallbacks prefer satisfying `thinking` over `fast`. See `resolveVariant()` in [`src/mapping.ts`](src/mapping.ts) for the exact scoring.
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
cursor/claude-opus-5 + /thinking high + /pi-model-map-thinking on
|
|
139
|
+
→ map.high.thinking = "cursor-agent/claude-opus-5-thinking-high"
|
|
140
|
+
→ route() returns the physical model cursor-agent/claude-opus-5-thinking-high
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This also means:
|
|
144
|
+
|
|
145
|
+
- **Different mappings in the same file can delegate to different providers.** `claude-opus-5` could route to `cursor-agent/...` while another entry in the same file routes to `anthropic/...`.
|
|
146
|
+
- **Different levels, or different variants within one level, can in principle delegate to different providers**, though this isn't a typical use case.
|
|
147
|
+
- pi-model-map resolves every distinct provider referenced anywhere in `map` and validates/monitors each one independently (see warnings below).
|
|
148
|
+
|
|
149
|
+
### Virtual models, not providers
|
|
150
|
+
|
|
151
|
+
Each canonical family is registered with Pi's `registerVirtualModel()`. Per request, `route()` resolves the backend and returns that **physical** model; Pi then streams it with the delegate's own credentials. Consequences:
|
|
152
|
+
|
|
153
|
+
- Assistant messages, `/session` cost, context limits and compaction use the physical backend. The footer shows `canonical • effort → backend`. Resuming a session restores the canonical selection.
|
|
154
|
+
- Backends must be physical models. A `map` entry pointing at another virtual model (e.g. `roundrobin/*`, `billing/*`) fails at request time.
|
|
155
|
+
- A backend that isn't registered (or lacks credentials) fails the request with a clear error. Families with no registered backend at all are unregistered on session start.
|
|
156
|
+
- `contextWindow`/`maxTokens`/`input` are only shown before the first response; per-family `reasoning` and `cost` no longer exist (Pi bills the backend's own cost).
|
|
157
|
+
- Config-level `api`, `baseUrl` and `name` fields are ignored.
|
|
158
|
+
|
|
159
|
+
### Naming convention
|
|
160
|
+
|
|
161
|
+
Canonical model IDs generally do **not** need a provider-echoing prefix (e.g. `claude-opus-5`, not `cursor-claude-opus-5`) — the config file's own `provider` field (`/model cursor claude-opus-5`) already disambiguates which mapping a picker entry came from. Only prefix a canonical ID when the bare name would otherwise collide with another family in the *same* config file, or when it improves clarity for a specific integration chain (e.g. Cursor's own raw `cursor-grok-4.5`/`cursor-grok-4.6` backend IDs already carry a literal `cursor-` segment from Cursor itself, which is left as-is rather than stripped or doubled).
|
|
162
|
+
|
|
163
|
+
### Verifying backend ids still exist (`source`)
|
|
164
|
+
|
|
165
|
+
Providers periodically rename or retire raw backend model ids (Cursor especially, given how much of its naming bakes effort/thinking/fast into the id string itself). Nothing about the mapping schema itself would ever tell you a `map` entry now points at a dead id — it would just surface as a runtime API error from the delegate the next time someone actually selects it.
|
|
166
|
+
|
|
167
|
+
Set `source` (plus `sourceListPath` / `sourceIdField` if needed) in a config file to point at a JSON file describing that provider's live catalog, and pi-model-map will cross-check every backend id in `mappings` against it:
|
|
168
|
+
|
|
169
|
+
```jsonc
|
|
170
|
+
{
|
|
171
|
+
"source": "~/.pi/agent/cache/pi-cursor-agent/models.json",
|
|
172
|
+
"sourceListPath": "models",
|
|
173
|
+
// "sourceIdField" defaults to "modelId" (Cursor's cache shape) and only matters when list
|
|
174
|
+
// entries are objects rather than bare strings.
|
|
175
|
+
...
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- `source` — path to the catalog file. `~` expands to `$HOME`; relative paths resolve against the config file's own directory. **Optional** — omit it and this check is skipped entirely (no assumption is made about where, or whether, a given provider even maintains such a file; this is deliberately not Cursor-specific, since other delegates like a hypothetical `opencode` mapping may have a completely different cache format or none at all).
|
|
180
|
+
- `sourceListPath` — dot-path to the array of catalog entries inside the parsed JSON (e.g. `"models"` for Cursor's `{ "models": [...] }` shape). Omit if the file's root value is already that array.
|
|
181
|
+
- `sourceIdField` — field name holding each entry's raw id, when entries are objects rather than bare strings. Defaults to `"modelId"`.
|
|
182
|
+
|
|
183
|
+
When `source` is set, pi-model-map warns (at config-load time, same as the other startup checks) about any backend id referenced anywhere in `mappings` that isn't present in the catalog file, naming exactly where it's used (e.g. `mappings.claude-opus-5.map.high.thinking`) so you can find and fix it quickly. You can also re-run the same check on demand, without restarting Pi, with `/pi-model-map-check-source` — useful right after refreshing a delegate's cache file.
|
|
184
|
+
|
|
185
|
+
That catalog check is independent of whether Pi's live model registry has actually registered those ids. On session start, pi-model-map also compares each mapping against `modelRegistry.find()` and records any families whose backends are missing from the registry. Pi's TUI startup output is ephemeral, so those warnings (and the other config-load / session-start warnings) are appended to:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
~/.pi/agent/model-map/pi-model-map.log
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
If any families are omitted or only partially registered, a one-line UI toast points at that file. The registry scan does not re-run on every request.
|
|
192
|
+
|
|
193
|
+
## Commands
|
|
194
|
+
|
|
195
|
+
| Command | Effect |
|
|
196
|
+
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
197
|
+
| `/pi-model-map-thinking [on\|off]` | Set (or, with no argument, toggle) use of each family's mapped `thinking`/`thinking-fast` backend variant. |
|
|
198
|
+
| `/pi-model-map-thinking-on` / `-off` | Explicit enable/disable shortcuts. |
|
|
199
|
+
| `/pi-model-map-fast [on\|off]` | Set (or toggle) use of each family's mapped `fast`/`thinking-fast` backend variant. |
|
|
200
|
+
| `/pi-model-map-fast-on` / `-off` | Explicit enable/disable shortcuts. |
|
|
201
|
+
| `/pi-model-map-check-source` | Re-check every config file's `source` catalog now and report any backend ids missing from it. No-op (with a hint) for config files that don't set `source`. |
|
|
202
|
+
|
|
203
|
+
Both toggles are session-wide and apply across every pi-model-map provider/family currently in use. If the active model's family has no matching variant configured for the requested state, pi-model-map notifies you and falls back to `default` (or the nearest configured variant) rather than erroring.
|
|
204
|
+
|
|
205
|
+
These toggles are independent of Pi's own `/thinking <level>` effort selector — set effort with `/thinking`, and layer `/pi-model-map-thinking` / `/pi-model-map-fast` on top for providers whose backend also splits thinking-mode and routing-tier into separate model IDs.
|
|
206
|
+
|
|
207
|
+
Some effort levels only exist in "thinking" form for a given family (e.g. `claude-opus-5`'s `xhigh`/`max` levels have no non-thinking backend at all — see ["Hiding a misleading 'off' level"](#hiding-a-misleading-off-level)). Selecting one of those levels with `/pi-model-map-thinking off` still resolves to the thinking backend regardless — there's nothing else to fall back to — and pi-model-map warns about it. This warning fires from three places, so you see it as early as possible rather than only after actually sending a message:
|
|
208
|
+
|
|
209
|
+
- **The moment you select an affected model** (`/model`, `Ctrl+P` cycling, or session restore) at whatever effort level is already active.
|
|
210
|
+
- **The moment you change `/thinking` to an affected level** on the currently active model.
|
|
211
|
+
- **At the start of a session** that already had an affected model+level combination selected (e.g. from before this check existed, or across `/reload`).
|
|
212
|
+
|
|
213
|
+
It's also still checked at request time as a final backstop (in case a session's effective thinking level was clamped by some path other than the two events above), so it can never go completely unwarned before an affected request actually goes out.
|
|
214
|
+
|
|
215
|
+
It tracks only the *most recently checked* model+level combination, not "every combination ever warned about this session" — so cycling `/thinking xhigh` -> `/thinking max` -> `/thinking xhigh` warns all three times (each is a genuine change from whatever was checked immediately before it), while sending several turns in a row without changing the model or effort level does not repeat the warning, since request-time checks see the same combination the preceding selection-time check already reported. Turning `/pi-model-map-thinking` on and back off again while staying on the same affected level also re-warns, since that's a real change in whether the toggle mismatch applies.
|
|
216
|
+
|
|
217
|
+
## Startup checks
|
|
218
|
+
|
|
219
|
+
Per config file:
|
|
220
|
+
|
|
221
|
+
1. **Rejects** duplicate `provider` ids across files in the same directory.
|
|
222
|
+
2. **Warns** if a single config file's `mappings` reference more than one distinct delegate provider overall, and separately (more specifically) if a *single mapping* splits its own effort levels/variants across more than one provider (see below).
|
|
223
|
+
3. **Warns** (only if `source` is set) about any backend id in `mappings` that's missing from the referenced live catalog file, or if that file can't be read/parsed as configured.
|
|
224
|
+
4. **On session start**, verifies each distinct delegate provider referenced in `map` is registered, records any mapped backends that Pi's live registry has not registered (log file above), and unregisters families with no registered backend.
|
|
225
|
+
|
|
226
|
+
### One config file, one delegate provider
|
|
227
|
+
|
|
228
|
+
The `"provider/modelId"` syntax on every `map` entry exists so a mapping's target is explicit and self-contained (and so different effort levels/variants can technically point anywhere) — not to let one canonical model fan out across multiple real backend providers. Grouping unrelated providers under one virtual model (e.g. a "thinking tier" or "planning tier" that round-robins between different providers' models based on task type) is a different kind of plugin and out of scope here: pi-model-map has no cross-provider fallback, health-check, or selection logic — whichever provider a given effort level/variant happens to reference is what gets used, deterministically, every time.
|
|
229
|
+
|
|
230
|
+
Because of this, pi-model-map warns (but does not block loading) if a config file's mappings collectively reference more than one delegate provider, and warns more specifically if a *single* canonical mapping does so across its own levels/variants — the latter usually indicates a typo (e.g. mistakenly writing `anthropic/claude-opus-4-5` in one level of a mapping that's otherwise entirely `cursor-agent/...`). If you genuinely want to map models from more than one real provider, use one config file per provider in the `model-map/` directory (see [Configuration](#configuration)) rather than mixing providers inside a single file.
|
|
231
|
+
|
|
232
|
+
## Usage
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
/model cursor claude-opus-5
|
|
236
|
+
/thinking high
|
|
237
|
+
/pi-model-map-thinking on
|
|
238
|
+
/pi-model-map-fast on
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
With multiple config files, each registers its own `/model <provider> ...` namespace (e.g. a second file with `provider: "opencode"` would add `/model opencode ...`).
|
|
242
|
+
|
|
243
|
+
### Verifying routing (debug logging)
|
|
244
|
+
|
|
245
|
+
Set `PI_MODEL_MAP_DEBUG=1` (or `true`) before starting Pi to print a one-line trace for every request a mapped provider handles, showing exactly which backend provider/model id it resolved to:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
PI_MODEL_MAP_DEBUG=1 pi
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
[pi-model-map:debug] cursor/claude-opus-5 (reasoning=high, thinking=true, fast=false) -> cursor-agent/claude-opus-5-thinking-high
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This is off by default (silent, like every other Pi provider) and is printed via `console.error` from inside the extension's `route()` handler — i.e. it reflects the exact backend reference `toBackendRef()` resolved and handed off to the delegate provider, not a guess. Each line is printed with a leading blank line, since Pi's TUI doesn't otherwise insert one before extension stderr output and it would otherwise print immediately after your echoed input on the same terminal line.
|
|
256
|
+
|
|
257
|
+
If you want to independently confirm the *actual outbound request* (not just what pi-model-map thinks it resolved to), Pi's own `before_provider_request` extension hook fires right before the payload is sent and includes the real serialized model/request body — see the "Extension Hooks" section of Pi's own `docs/extensions.md` for a ready-to-use snippet (e.g. `pi.on("before_provider_request", (event) => console.log(JSON.stringify(event.payload, null, 2)))`). Pi's hidden `/debug` command also writes the last messages sent to the LLM to `~/.pi/agent/pi-debug.log`.
|
|
258
|
+
|
|
259
|
+
## Examples
|
|
260
|
+
|
|
261
|
+
Bundled configs are in [`examples/`](examples/). See [`examples/README.md`](examples/README.md).
|
|
262
|
+
|
|
263
|
+
I recommend using [`@zigai/pi-model-filter`](https://pi.dev/packages/@zigai/pi-model-filter) to hide the providers/models behind your configured mappings (e.g. raw `cursor-agent/*` entries once you've mapped them via `cursor/*`), simplifying your model list. See [`examples/README.md`](examples/README.md) for more information.
|
|
264
|
+
|
|
265
|
+
## Releasing
|
|
266
|
+
|
|
267
|
+
[`.forgejo/workflows/publish.yml`](.forgejo/workflows/publish.yml) publishes to npm whenever a `vX.Y.Z` tag is pushed. It's a PoC drafted against a Forgejo instance that was offline at the time — review before relying on it:
|
|
268
|
+
|
|
269
|
+
1. Verifies the tag's commit is reachable from `main` (refuses to publish tags cut from other branches).
|
|
270
|
+
2. Installs dependencies and runs `npm run typecheck`.
|
|
271
|
+
3. Verifies the tag version (`vX.Y.Z` -> `X.Y.Z`) matches `package.json`'s `version` field, so a forgotten version bump fails the build instead of publishing under the wrong number.
|
|
272
|
+
4. Runs `npm publish --access public` using an `NPM_TOKEN` repo/org secret.
|
|
273
|
+
|
|
274
|
+
Forgejo reads workflows from `.forgejo/workflows/` (preferred) or `.gitea/workflows/` (Gitea-compatible) — don't duplicate the file in both. Before this can actually run on a live instance you'll need to:
|
|
275
|
+
|
|
276
|
+
- Confirm a Forgejo Actions runner is registered for the repo and update `runs-on:` to match its label(s) (the workflow assumes the default `ubuntu-latest` mapping).
|
|
277
|
+
- Confirm `actions/checkout` and `actions/setup-node` are reachable from your instance (mirrored internally, or your runner has outbound access to fetch them).
|
|
278
|
+
- Add an `NPM_TOKEN` secret (an npm [automation token](https://docs.npmjs.com/creating-and-viewing-access-tokens), which bypasses 2FA prompts for CI) under the repo's or org's Actions secrets.
|
|
279
|
+
|
|
280
|
+
Cutting a release: bump `version` in `package.json`, commit to `main`, then `git tag vX.Y.Z && git push origin vX.Y.Z`.
|
|
281
|
+
|
|
282
|
+
## Credits & License
|
|
283
|
+
|
|
284
|
+
pi-model-map is licensed under the [MIT License](LICENSE).
|
|
285
|
+
|
|
286
|
+
**[`@open-cursor/pi-agent`](https://github.com/brandonkramer/open-cursor)** (`integrations/pi-agent`), also MIT-licensed, is the direct source of two things in this project:
|
|
287
|
+
|
|
288
|
+
**Logic — ported, not just inspired by.** `ModelMapper.toBackendRef()` in `src/mapping.ts` reproduces the same algorithm as open-cursor's `toCursorId()` in `src/models/mapping.ts`: look up the family/map for a canonical id, use the `default` entry when no effort level is requested, otherwise look up the level with a fallback to `default`. The index-building loop (`buildIndexes()`, populating the family/map lookup structures) is likewise the same approach as open-cursor's module-level index construction. Identifiers, data structures (`Map`/class fields vs. plain objects/module-level functions), the provider-prefixed key format (`"provider/modelId"`), and the `default`/`thinking`/`fast`/`thinking-fast` variant split were added/changed to fit this project's multi-provider, multi-axis design, but the control flow and logic of `toBackendRef()` is a **port** of open-cursor's, not an independent reimplementation.
|
|
289
|
+
|
|
290
|
+
(An earlier version of pi-model-map also ported open-cursor's reverse lookup, `toCanonicalId()`, for hiding raw backend-variant models from the picker. That method was unused dead code — nothing in this project ever called it — and has been removed; use [`@zigai/pi-model-filter`](https://pi.dev/packages/@zigai/pi-model-filter) to hide a delegate provider's raw models instead, per the recommendation above.)
|
|
291
|
+
|
|
292
|
+
**`examples/cursor.json`'s data is not from open-cursor.** Earlier revisions of this example file copied `mappings` data from open-cursor's hardcoded `MODEL_MAP`, but that data had drifted noticeably from Cursor's actual current catalog (missing several model families, referencing IDs Cursor no longer serves). `examples/cursor.json` is now generated directly from Cursor's own live model catalog (the cached response at `~/.pi/agent/cache/pi-cursor-agent/models.json`, see [`examples/README.md`](examples/README.md#regenerating-from-a-fresh-catalog)), grouped and split into the `default`/`thinking`/`fast`/`thinking-fast` schema by this project's own generation logic. Only the **resolution logic** that consumes this data remains ported from open-cursor, as described above — the example data itself is independently sourced.
|
|
293
|
+
|
|
294
|
+
Everything outside of `src/mapping.ts`'s two resolution functions — including the JSON-driven config design, the `mappings`/`map` schema and its thinking/fast variant axes, multi-provider delegate references, the `model-map/` directory config loader, Pi provider-registration wiring in `src/index.ts`, the `/pi-model-map-thinking` / `/pi-model-map-fast` commands, the namespace-clash validation/warnings in `src/warnings.ts`, and the current `examples/cursor.json` data — was written/generated independently for this project and has no open-cursor counterpart.
|
|
295
|
+
|
|
296
|
+
In accordance with the MIT License's requirement to preserve copyright and permission notices for reused/derivative code, the original open-cursor license text is reproduced in [`LICENSE`](LICENSE) alongside this project's own license.
|
|
297
|
+
|
|
298
|
+
## Renamed from pi-thinking-map
|
|
299
|
+
|
|
300
|
+
This project was originally named `pi-thinking-map`. It was renamed to `pi-model-map` once its scope grew beyond effort-level mapping to include the `/pi-model-map-thinking` and `/pi-model-map-fast` toggles, which needed a command prefix that wasn't specific to "thinking." Config directories, the fake registration API key, and all internal identifiers were updated accordingly — see the [Configuration](#configuration) section for the current `model-map/` directory convention.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Example configs
|
|
2
|
+
|
|
3
|
+
Copy one or more files into `~/.pi/agent/model-map/`:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
mkdir -p ~/.pi/agent/model-map
|
|
7
|
+
cp examples/cursor.json ~/.pi/agent/model-map/cursor.json
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Each file registers its own provider namespace. `/reload` in Pi after changes.
|
|
11
|
+
|
|
12
|
+
## `cursor.json`
|
|
13
|
+
|
|
14
|
+
Registered as provider **`cursor`**. Every `map` entry delegates to **`cursor-agent/...`** (backend IDs match `@open-cursor/pi-agent`, which exposes Cursor's raw model catalog 1:1 under the `cursor-agent` provider).
|
|
15
|
+
|
|
16
|
+
Generated from Cursor's own live model catalog — specifically the cached response Cursor's CLI itself returns, at `~/.pi/agent/cache/pi-cursor-agent/models.json` (`.models[].modelId`) — grouped by family and by effort level, splitting each raw backend ID into `default`/`thinking`/`fast`/`thinking-fast` variants based on its `-thinking-` segment and `-fast` suffix. 32 canonical families are covered, down from 204 raw backend model IDs.
|
|
17
|
+
|
|
18
|
+
Most families are plain effort-level maps (bare `"provider/modelId"` strings, no thinking/fast axis). A few demonstrate the full `default`/`thinking`/`fast`/`thinking-fast` variant object, since Cursor exposes all four axes for these models — e.g. **8 raw Opus 5 backend IDs at the `high` effort level alone** (`claude-opus-5-high`, `-high-fast`, `-thinking-high`, `-thinking-high-fast`, and the equivalents at `low`/`medium`/`xhigh`/`max`) collapse into **one** canonical `claude-opus-5` family:
|
|
19
|
+
|
|
20
|
+
| Picker model | Effort (`/thinking`) | `/pi-model-map-thinking` | `/pi-model-map-fast` | Delegates to |
|
|
21
|
+
| --- | --- | --- | --- | --- |
|
|
22
|
+
| `cursor/claude-opus-5` | `high` (default) | off | off | `cursor-agent/claude-opus-5-high` |
|
|
23
|
+
| `cursor/claude-opus-5` | `high` | **on** | off | `cursor-agent/claude-opus-5-thinking-high` |
|
|
24
|
+
| `cursor/claude-opus-5` | `high` | off | **on** | `cursor-agent/claude-opus-5-high-fast` |
|
|
25
|
+
| `cursor/claude-opus-5` | `high` | **on** | **on** | `cursor-agent/claude-opus-5-thinking-high-fast` |
|
|
26
|
+
| `cursor/claude-opus-5` | `xhigh` | off | off | `cursor-agent/claude-opus-5-thinking-xhigh` (no non-thinking backend exists at this effort level; falls back to the thinking backend regardless of the toggle) |
|
|
27
|
+
| `cursor/kimi-k3` | *(none set)* | off | off | `cursor-agent/kimi-k3-low` (this family has no bare/no-suffix backend ID at all; `default` is aliased to `low`, the lowest genuinely-distinct effort tier Cursor exposes) |
|
|
28
|
+
| `cursor/gpt-5.4-mini` | *(none set)* | off | off | `cursor-agent/gpt-5.4-mini-none` (Cursor's own `-none` suffix is treated as this family's `default` tier) |
|
|
29
|
+
| `cursor/composer-2.5` | n/a | n/a | **on** | `cursor-agent/composer-2.5-fast` (plain mapping — no effort levels or thinking axis, only a fast toggle) |
|
|
30
|
+
|
|
31
|
+
**Note on `/thinking`:** several families here only support a subset of effort levels (`kimi-k3` is `low`/`high`/`max` only, with no `minimal`/`medium`/`xhigh`; `composer-2.5` supports no effort levels at all). `/thinking`'s picker/autocomplete only offers the levels each family actually maps — see the root [README's "Pi's `/thinking` picker only shows levels you actually mapped" section](../README.md#pis-thinking-picker-only-shows-levels-you-actually-mapped) for why this requires more than just omitting the unsupported keys.
|
|
32
|
+
|
|
33
|
+
**Important:** Backend model IDs apply specifically to **`@open-cursor/pi-agent`** (`open-cursor` / `brandonkramer/open-cursor`) and to Cursor's catalog as of when the cache snapshot above was captured. Cursor adds/renames/retires model IDs over time — regenerate this file from a fresh `~/.pi/agent/cache/pi-cursor-agent/models.json` periodically, or if `/model cursor ...` shows resolution errors for a family.
|
|
34
|
+
|
|
35
|
+
This file sets `"source": "~/.pi/agent/cache/pi-cursor-agent/models.json"` (with `"sourceListPath": "models"`) itself, so pi-model-map automatically warns at load time (and via `/pi-model-map-check-source` on demand) if any backend id below has disappeared from that cache — see the root [README's "Verifying backend ids still exist" section](../README.md#verifying-backend-ids-still-exist-source) for details. This doesn't replace the manual regeneration process below when Cursor adds *new* families/effort levels (the check only catches ids going away, not new ones appearing), but it does catch stale/retired ids without you having to remember to diff anything by hand.
|
|
36
|
+
|
|
37
|
+
**Provenance:** Earlier versions of this file were derived from `@open-cursor/pi-agent`'s hardcoded `MODEL_MAP` (MIT-licensed) rather than a live catalog snapshot, and had drifted noticeably from Cursor's actual current model lineup (missing several families, referencing IDs Cursor no longer serves). The current file is regenerated directly from Cursor's own catalog data instead. The **resolution logic** that consumes this data (`src/mapping.ts`'s `toBackendRef`) remains a ported version of open-cursor's `toCursorId()` — see the root [README's Credits & License section](../README.md#credits--license) and [`LICENSE`](../LICENSE) for the full breakdown.
|
|
38
|
+
|
|
39
|
+
### Setup
|
|
40
|
+
|
|
41
|
+
1. Install `@open-cursor/pi-agent` and `/login cursor`.
|
|
42
|
+
2. Install `pi-model-map`.
|
|
43
|
+
3. Copy `cursor.json` → `~/.pi/agent/model-map/cursor.json`.
|
|
44
|
+
4. Use `cursor/*` models; `cursor-agent/*` remains available from pi-agent if installed and not hidden.
|
|
45
|
+
|
|
46
|
+
If using [`@zigai/pi-model-filter`](https://pi.dev/packages/@zigai/pi-model-filter), you can add this config snippet to hide the underlying `cursor-agent` models:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Regenerating from a fresh catalog
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
jq -r '.models[].modelId' ~/.pi/agent/cache/pi-cursor-agent/models.json | sort
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Compare against the `map` values currently in `cursor.json` to spot new, renamed, or retired backend IDs (or just run `/pi-model-map-check-source` in Pi to catch retired ones automatically — see above), then update the affected family/families by hand (or write a small script that groups by family, splits `-thinking-<effort>` / `-fast` segments, and emits the `default`/`thinking`/`fast`/`thinking-fast` variant object per effort level, aliasing `default` to the best available level when no bare/`-none`-suffixed backend ID exists for a family).
|
|
59
|
+
|
|
60
|
+
**Key order within each `map`:** always `default` first, then ascending effort (`minimal`, `low`, `medium`, `high`, `xhigh`, `max`), omitting any levels a family doesn't support — e.g. `cursor-grok-4.6` is `default, low, medium, high, xhigh` and `gemini-3.6-flash` is `default, minimal, low, medium, high`. This is purely a readability convention (JSON key order isn't semantically meaningful to the parser); keep it when hand-editing or regenerating.
|