Class: AgentHarness::Providers::Cursor

Inherits:
Base
  • Object
show all
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!")

Instance Attribute Summary

Attributes inherited from Base

#config, #executor, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#configure, #initialize

Methods included from Adapter

#dangerous_mode_flags, #health_status, included, #session_flags, #supports_dangerous_mode?, #supports_sessions?, #validate_config

Constructor Details

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

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


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

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

.binary_nameObject



20
21
22
# File 'lib/agent_harness/providers/cursor.rb', line 20

def binary_name
  "cursor-agent"
end

.discover_modelsObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/agent_harness/providers/cursor.rb', line 57

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/agent_harness/providers/cursor.rb', line 29

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

.instruction_file_pathsObject



47
48
49
50
51
52
53
54
55
# File 'lib/agent_harness/providers/cursor.rb', line 47

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



71
72
73
74
# File 'lib/agent_harness/providers/cursor.rb', line 71

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_model_name(family_name) ⇒ Object

Convert family name to Cursor’s naming convention



77
78
79
80
# File 'lib/agent_harness/providers/cursor.rb', line 77

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



16
17
18
# File 'lib/agent_harness/providers/cursor.rb', line 16

def provider_name
  :cursor
end

.supports_model_family?(family_name) ⇒ Boolean

Check if this provider supports a given model family

Returns:

  • (Boolean)


83
84
85
# File 'lib/agent_harness/providers/cursor.rb', line 83

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

Instance Method Details

#capabilitiesObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/agent_harness/providers/cursor.rb', line 96

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

#display_nameObject



92
93
94
# File 'lib/agent_harness/providers/cursor.rb', line 92

def display_name
  "Cursor AI"
end

#error_patternsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/agent_harness/providers/cursor.rb', line 117

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

#fetch_mcp_serversObject



112
113
114
115
# File 'lib/agent_harness/providers/cursor.rb', line 112

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

#nameObject



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

def name
  "cursor"
end

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

Override send_message to send prompt via stdin



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/agent_harness/providers/cursor.rb', line 138

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

  # Build command (without prompt in args - we send via stdin)
  command = [self.class.binary_name, "-p"]

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

  # Execute command with prompt on stdin
  start_time = Time.now
  result = @executor.execute(command, timeout: timeout, stdin_data: prompt)
  duration = Time.now - start_time

  # Parse response
  response = parse_response(result, duration: duration)

  # Track tokens
  track_tokens(response) if response.tokens

  log_debug("send_message_complete", duration: duration)

  response
rescue => e
  handle_error(e, prompt: prompt, options: options)
end

#supports_mcp?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/agent_harness/providers/cursor.rb', line 108

def supports_mcp?
  true
end