-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(cursor): canonical Claude-id normalizer replaces the three Fable 5.1 seeds #3275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| export type CursorClaudeSpelling = "anthropic" | "version-first"; | ||
|
|
||
| export interface NormalizedCursorClaudeId { | ||
| /** The sole key used by CURSOR_CAPABILITIES and pricing metadata. */ | ||
| canonicalBaseId: string; | ||
| /** Exact input stem, preserving `5-1` versus `5.1` for wire round-trips. */ | ||
| sourceBaseId: string; | ||
| spelling: CursorClaudeSpelling; | ||
| thinking: boolean; | ||
| fast: boolean; | ||
| level?: string; | ||
| } | ||
|
|
||
| const CLAUDE_LEVELS = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max", "extra-high"]); | ||
|
|
||
| /** Existing picker bases whose canonical key stays version-first (saved configs). */ | ||
| const VERSION_FIRST_CANONICAL_BASES = new Set([ | ||
| "claude-4.5-haiku", "claude-4.5-opus", "claude-4.6-opus", "claude-4.5-sonnet", "claude-4.6-sonnet", "claude-4-sonnet", | ||
| ]); | ||
|
|
||
| function parseClaudeBase(raw: string): { canonicalBaseId: string; sourceBaseId: string; spelling: CursorClaudeSpelling } | undefined { | ||
| const anthropic = /^claude-(fable|haiku|opus|sonnet)-(\d+(?:[.-]\d+)*)$/.exec(raw); | ||
| if (anthropic) { | ||
| const family = anthropic[1]!; | ||
| const version = anthropic[2]!.replaceAll(".", "-"); | ||
| const versionFirst = `claude-${version.replaceAll("-", ".")}-${family}`; | ||
| return { | ||
| canonicalBaseId: VERSION_FIRST_CANONICAL_BASES.has(versionFirst) ? versionFirst : `claude-${family}-${version}`, | ||
| sourceBaseId: raw, | ||
| spelling: "anthropic", | ||
| }; | ||
| } | ||
| const versionFirst = /^claude-(\d+(?:\.\d+)*)-(fable|haiku|opus|sonnet)$/.exec(raw); | ||
| if (!versionFirst) return undefined; | ||
| const sourceBaseId = `claude-${versionFirst[1]!}-${versionFirst[2]!}`; | ||
| return { | ||
| canonicalBaseId: VERSION_FIRST_CANONICAL_BASES.has(sourceBaseId) ? sourceBaseId : `claude-${versionFirst[2]!}-${versionFirst[1]!.replaceAll(".", "-")}`, | ||
| sourceBaseId, | ||
| spelling: "version-first", | ||
| }; | ||
| } | ||
|
|
||
| export function normalizeCursorClaudeId(raw: string): NormalizedCursorClaudeId | undefined { | ||
| const id = raw.trim().toLowerCase(); | ||
| const patterns: ReadonlyArray<readonly [RegExp, (m: RegExpExecArray) => { base: string; thinking: boolean; fast: boolean; level?: string }]> = [ | ||
| [/^(.*)-thinking-([a-z-]+)-fast$/, m => ({ base: m[1]!, thinking: true, fast: true, level: m[2]! })], | ||
| [/^(.*)-([a-z-]+)-thinking-fast$/, m => ({ base: m[1]!, thinking: true, fast: true, level: m[2]! })], | ||
| [/^(.*)-thinking-([a-z-]+)$/, m => ({ base: m[1]!, thinking: true, fast: false, level: m[2]! })], | ||
| [/^(.*)-([a-z-]+)-thinking$/, m => ({ base: m[1]!, thinking: true, fast: false, level: m[2]! })], | ||
| [/^(.*)-([a-z-]+)-fast$/, m => ({ base: m[1]!, thinking: false, fast: true, level: m[2]! })], | ||
| [/^(.*)-thinking-fast$/, m => ({ base: m[1]!, thinking: true, fast: true })], | ||
| [/^(.*)-thinking$/, m => ({ base: m[1]!, thinking: true, fast: false })], | ||
| [/^(.*)-fast$/, m => ({ base: m[1]!, thinking: false, fast: true })], | ||
| ]; | ||
| for (const [pattern, dims] of patterns) { | ||
| const match = pattern.exec(id); | ||
| if (!match) continue; | ||
| const parsed = dims(match); | ||
| if (parsed.level && !CLAUDE_LEVELS.has(parsed.level)) continue; | ||
| const base = parseClaudeBase(parsed.base); | ||
| if (base) return { ...base, ...parsed, sourceBaseId: base.sourceBaseId }; | ||
| } | ||
| const base = parseClaudeBase(id); | ||
| return base ? { ...base, thinking: false, fast: false } : undefined; | ||
| } | ||
|
|
||
| export function composeCursorClaudeWireId( | ||
| identity: Pick<NormalizedCursorClaudeId, "sourceBaseId" | "spelling">, | ||
| options: { thinking: boolean; fast: boolean; effort?: string; bareThinking?: boolean }, | ||
| ): string { | ||
| const { sourceBaseId: base, spelling } = identity; | ||
| const fast = options.fast ? "-fast" : ""; | ||
| if (!options.thinking) return options.effort ? `${base}-${options.effort}${fast}` : `${base}${fast}`; | ||
| if (options.bareThinking || !options.effort) return `${base}-thinking${fast}`; | ||
| return spelling === "version-first" ? `${base}-${options.effort}-thinking${fast}` : `${base}-thinking-${options.effort}${fast}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a configuration contains two named providers using
adapter: "cursor", every successful discovery replaces this process-global map with its own roster, whileresolveCursorSelectionreads it without knowing which provider is handling the request. If the accounts expose different Fable spellings or marker orders, whichever discovery finishes last causes requests through the other provider to use an unsupported wire ID and receiveERROR_BAD_MODEL_NAME. Store the identities per provider/account and select the corresponding map in the request path.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changed here: a single process has one
cursoradapter roster today, matching the existingliveCursorMaxModeBasesprecedent. Keying by provider name is recorded as the follow-up if a second Cursor-adapter provider ever ships (050 §risks).