feat: Enhance model resolution for Cursor models

- Added support for Cursor models in the model resolver, allowing cursor-prefixed models to pass through unchanged.
- Implemented logic to handle bare Cursor model IDs by adding the cursor- prefix.
- Updated logging to provide detailed information on model resolution processes for both Claude and Cursor models.
- Expanded unit tests to cover new Cursor model handling scenarios, ensuring robust validation of model resolution logic.
This commit is contained in:
Shirone
2025-12-28 01:55:40 +01:00
parent 0bcc8fca5d
commit b32eacc913
6 changed files with 134 additions and 10 deletions

View File

@@ -499,8 +499,11 @@ export class CursorProvider extends BaseProvider {
// Extract model from options (strip 'cursor-' prefix if present)
let model = options.model || 'auto';
logger.debug(`CursorProvider.executeQuery called with model: "${model}"`);
if (model.startsWith('cursor-')) {
const originalModel = model;
model = model.substring(7);
logger.debug(`Stripped cursor- prefix: "${originalModel}" -> "${model}"`);
}
const cwd = options.cwd || process.cwd();

View File

@@ -3,6 +3,7 @@ import {
resolveModelString,
getEffectiveModel,
CLAUDE_MODEL_MAP,
CURSOR_MODEL_MAP,
DEFAULT_MODELS,
} from '@automaker/model-resolver';
@@ -36,7 +37,7 @@ describe('model-resolver.ts', () => {
const result = resolveModelString('opus');
expect(result).toBe('claude-opus-4-5-20251101');
expect(consoleSpy.log).toHaveBeenCalledWith(
expect.stringContaining('Resolved model alias: "opus"')
expect.stringContaining('Resolved Claude model alias: "opus"')
);
});
@@ -83,6 +84,32 @@ describe('model-resolver.ts', () => {
const result = resolveModelString('');
expect(result).toBe(DEFAULT_MODELS.claude);
});
describe('Cursor models', () => {
it('should pass through cursor-prefixed models unchanged', () => {
const result = resolveModelString('cursor-composer-1');
expect(result).toBe('cursor-composer-1');
expect(consoleSpy.log).toHaveBeenCalledWith(expect.stringContaining('Using Cursor model'));
});
it('should add cursor- prefix to bare Cursor model IDs', () => {
const result = resolveModelString('composer-1');
expect(result).toBe('cursor-composer-1');
});
it('should handle cursor-auto model', () => {
const result = resolveModelString('cursor-auto');
expect(result).toBe('cursor-auto');
});
it('should handle all known Cursor model IDs with prefix', () => {
const cursorModelIds = Object.keys(CURSOR_MODEL_MAP);
cursorModelIds.forEach((modelId) => {
const result = resolveModelString(`cursor-${modelId}`);
expect(result).toBe(`cursor-${modelId}`);
});
});
});
});
describe('getEffectiveModel', () => {