Class: AgentHarness::Providers::Cursor

Inherits:
Base
  • Object
show all
Includes:
RateLimitResetParsing
Defined in:
lib/agent_harness/providers/cursor.rb

Overview

Cursor AI CLI provider

Provides integration with the Cursor AI coding assistant via its CLI tool.

Examples:

Basic usage

provider = AgentHarness::Providers::Cursor.new
response = provider.send_message(prompt: "Hello!")

Constant Summary collapse

INSTALL_SCRIPT_URL =
"https://cursor.com/install"
INSTALL_TARGET_LATEST =
"latest"
INSTALL_BUILD =
"2026.03.30-a5d3e17"
INSTALL_SCRIPT_SHA256 =
"8371988b483abec13c07c10e95cccc839da81ebf9596e430d3c90835a227cbad"
INSTALL_LINUX_X64_PACKAGE_SHA256 =
"e0d4b611db111d2dbe76474386271bff3e1dbb2cc6ddf527f9d5d5801b2ce2a0"

Constants inherited from Base

Base::COMMON_ERROR_PATTERNS, Base::DEFAULT_SMOKE_TEST_CONTRACT

Instance Attribute Summary

Attributes inherited from Base

#config, #executor, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RateLimitResetParsing

#parse_rate_limit_reset

Methods inherited from Base

#cli_env_overrides, #configure, #initialize, #parse_rate_limit_reset, #parse_test_error, #sandboxed_environment?, #subscription_unset_vars, #test_command_overrides

Methods included from Adapter

#auth_lock_config, #build_mcp_flags, #config_file_content, #dangerous_mode_flags, #error_classification_patterns, #health_status, included, metadata_package_name, #noisy_error_patterns, normalize_metadata_installation, normalize_metadata_source_type, normalize_metadata_version_requirement, #notify_hook_content, #parse_rate_limit_reset, #session_flags, #smoke_test, #smoke_test_contract, #supports_dangerous_mode?, #supports_sessions?, #supports_text_mode?, #supports_token_counting?, #supports_tool_control?, #token_usage_from_api_response, #translate_error, #validate_config, #validate_mcp_servers!

Constructor Details

This class inherits a constructor from AgentHarness::Providers::Base

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/agent_harness/providers/cursor.rb', line 32

def available?
  executor = AgentHarness.configuration.command_executor
  !!executor.which(binary_name)
end

.binary_nameObject



28
29
30
# File 'lib/agent_harness/providers/cursor.rb', line 28

def binary_name
  "cursor-agent"
end

.discover_modelsObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/agent_harness/providers/cursor.rb', line 74

def discover_models
  return [] unless available?

  # Cursor doesn't have a public model listing API
  # Return common model families it supports
  [
    {name: "claude-3.5-sonnet", family: "claude-3-5-sonnet", tier: "standard", provider: "cursor"},
    {name: "claude-3.5-haiku", family: "claude-3-5-haiku", tier: "mini", provider: "cursor"},
    {name: "gpt-4o", family: "gpt-4o", tier: "standard", provider: "cursor"},
    {name: "cursor-small", family: "cursor-small", tier: "mini", provider: "cursor"}
  ]
end

.firewall_requirementsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/agent_harness/providers/cursor.rb', line 46

def firewall_requirements
  {
    domains: [
      "cursor.com",
      "www.cursor.com",
      "downloads.cursor.com",
      "api.cursor.sh",
      "cursor.sh",
      "app.cursor.sh",
      "www.cursor.sh",
      "auth.cursor.sh",
      "auth0.com",
      "*.auth0.com"
    ],
    ip_ranges: []
  }
end

.install_metadata(version: nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/agent_harness/providers/cursor.rb', line 104

def (version: nil)
  install_target = normalize_install_target(version)
  linux_x64_package_url = package_url_for(os: "linux", arch: "x64")

  {
    source: {
      type: :shell_script,
      url: INSTALL_SCRIPT_URL,
      resolved_version: INSTALL_BUILD,
      default_artifact_url: linux_x64_package_url
    },
    checksum: {
      strategy: :sha256,
      targets: {
        script: {
          url: INSTALL_SCRIPT_URL,
          value: INSTALL_SCRIPT_SHA256
        },
        artifacts: {
          "linux/x64" => {
            url: linux_x64_package_url,
            value: INSTALL_LINUX_X64_PACKAGE_SHA256
          }
        }
      }
    },
    binary: {
      name: binary_name,
      path: "$HOME/.local/bin/#{binary_name}",
      suggested_global_path: "/usr/local/bin/#{binary_name}"
    },
    version: {
      default: INSTALL_TARGET_LATEST,
      supported: install_target,
      command: [binary_name, "--version"]
    }
  }
end

.instruction_file_pathsObject



64
65
66
67
68
69
70
71
72
# File 'lib/agent_harness/providers/cursor.rb', line 64

def instruction_file_paths
  [
    {
      path: ".cursorrules",
      description: "Cursor AI agent instructions",
      symlink: true
    }
  ]
end

.model_family(provider_model_name) ⇒ Object

Normalize Cursor’s model name to family name



88
89
90
91
# File 'lib/agent_harness/providers/cursor.rb', line 88

def model_family(provider_model_name)
  # Normalize cursor naming: "claude-3.5-sonnet" -> "claude-3-5-sonnet"
  provider_model_name.gsub(/(\d)\.(\d)/, '\1-\2')
end

.provider_metadata_overridesObject



37
38
39
40
41
42
43
44
# File 'lib/agent_harness/providers/cursor.rb', line 37

def 
  {
    auth: {
      service: :cursor,
      api_family: :cursor
    }
  }
end

.provider_model_name(family_name) ⇒ Object

Convert family name to Cursor’s naming convention



94
95
96
97
# File 'lib/agent_harness/providers/cursor.rb', line 94

def provider_model_name(family_name)
  # Cursor uses dots: "claude-3-5-sonnet" -> "claude-3.5-sonnet"
  family_name.gsub(/(\d)-(\d)/, '\1.\2')
end

.provider_nameObject



24
25
26
# File 'lib/agent_harness/providers/cursor.rb', line 24

def provider_name
  :cursor
end

.smoke_test_contractObject



143
144
145
# File 'lib/agent_harness/providers/cursor.rb', line 143

def smoke_test_contract
  Base::DEFAULT_SMOKE_TEST_CONTRACT
end

.supports_model_family?(family_name) ⇒ Boolean

Check if this provider supports a given model family

Returns:

  • (Boolean)


100
101
102
# File 'lib/agent_harness/providers/cursor.rb', line 100

def supports_model_family?(family_name)
  family_name.match?(/^(claude|gpt|cursor)-/)
end

Instance Method Details

#api_key_env_var_namesObject



211
# File 'lib/agent_harness/providers/cursor.rb', line 211

def api_key_env_var_names = ["ANTHROPIC_API_KEY"]

#api_key_unset_varsObject



213
# File 'lib/agent_harness/providers/cursor.rb', line 213

def api_key_unset_vars = ["ANTHROPIC_BASE_URL", "ANTHROPIC_HEADER_X_AGENT_RUN_ID", "ANTHROPIC_HEADER_X_PROXY_TOKEN"]

#auth_typeObject



215
216
217
# File 'lib/agent_harness/providers/cursor.rb', line 215

def auth_type
  :oauth
end

#capabilitiesObject



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/agent_harness/providers/cursor.rb', line 182

def capabilities
  {
    streaming: false,
    file_upload: true,
    vision: false,
    tool_use: true,
    json_mode: false,
    mcp: true,
    dangerous_mode: false
  }
end

#configuration_schemaObject



174
175
176
177
178
179
180
# File 'lib/agent_harness/providers/cursor.rb', line 174

def configuration_schema
  {
    fields: [],
    auth_modes: [:oauth],
    openai_compatible: false
  }
end

#display_nameObject



170
171
172
# File 'lib/agent_harness/providers/cursor.rb', line 170

def display_name
  "Cursor AI"
end

#error_patternsObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/agent_harness/providers/cursor.rb', line 232

def error_patterns
  {
    rate_limited: [
      /rate.?limit/i,
      /too.?many.?requests/i,
      /\b429\b/
    ],
    auth_expired: [
      /authentication.*error/i,
      /invalid.*credentials/i,
      /unauthorized/i
    ],
    transient: [
      /timeout/i,
      /connection.*error/i,
      /temporary/i
    ]
  }
end

#execution_semanticsObject



219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/agent_harness/providers/cursor.rb', line 219

def execution_semantics
  {
    prompt_delivery: :stdin,
    output_format: :text,
    sandbox_aware: false,
    uses_subcommand: false,
    non_interactive_flag: "-p",
    legitimate_exit_codes: [0],
    stderr_is_diagnostic: true,
    parses_rate_limit_reset: false
  }
end

#fetch_mcp_serversObject



206
207
208
209
# File 'lib/agent_harness/providers/cursor.rb', line 206

def fetch_mcp_servers
  # Try CLI first, then config file
  fetch_mcp_servers_cli || fetch_mcp_servers_config
end

#nameObject



166
167
168
# File 'lib/agent_harness/providers/cursor.rb', line 166

def name
  "cursor"
end

#send_message(prompt:, **options) ⇒ Object

Override send_message to send prompt via stdin



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/agent_harness/providers/cursor.rb', line 253

def send_message(prompt:, **options)
  log_debug("send_message_start", prompt_length: prompt.length, options: options.keys)

  # Coerce provider_runtime from Hash if needed (same as Base#send_message)
  options = normalize_provider_runtime(options)
  runtime = options[:provider_runtime]

  # Normalize and validate MCP servers (same as Base#send_message)
  options = normalize_mcp_servers(options)
  validate_mcp_servers!(options[:mcp_servers]) if options[:mcp_servers]&.any?

  # Build command (without prompt in args - we send via stdin)
  command = [self.class.binary_name, "-p"]
  command.concat(runtime.flags) if runtime&.flags&.any?

  # Calculate timeout
  timeout = options[:timeout] || @config.timeout || default_timeout

  # Execute command with prompt on stdin
  env = build_env(options)
  preparation = build_execution_preparation(options)
  start_time = Time.now
  result = execute_with_timeout(
    command,
    timeout: timeout,
    env: env,
    stdin_data: prompt,
    preparation: preparation,
    **command_execution_options(options)
  )
  duration = Time.now - start_time

  # Parse response
  response = parse_response(result, duration: duration)
  # Runtime model is a per-request override and always takes precedence
  # over both the config-level model and whatever parse_response returned.
  # See Base#send_message for rationale.
  if runtime&.model
    response = Response.new(
      output: response.output,
      exit_code: response.exit_code,
      duration: response.duration,
      provider: response.provider,
      model: runtime.model,
      tokens: response.tokens,
      metadata: response.,
      error: response.error
    )
  end

  # Track tokens
  track_tokens(response) if response.tokens

  log_debug("send_message_complete", duration: duration)

  response
rescue McpConfigurationError, McpUnsupportedError, McpTransportUnsupportedError
  raise
rescue => e
  handle_error(e, prompt: prompt, options: options)
end

#supported_mcp_transportsObject

Cursor supports MCP for fetching existing server configurations (via fetch_mcp_servers) but does not support injecting request-time MCP servers into CLI invocations. Returning an empty list causes validate_mcp_servers! to raise McpUnsupportedError with a clear message.



202
203
204
# File 'lib/agent_harness/providers/cursor.rb', line 202

def supported_mcp_transports
  []
end

#supports_mcp?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/agent_harness/providers/cursor.rb', line 194

def supports_mcp?
  true
end