Class: Aidp::Providers::Cursor

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

Constant Summary

Constants included from DebugMixin

DebugMixin::DEBUG_BASIC, DebugMixin::DEBUG_OFF, DebugMixin::DEBUG_VERBOSE

Constants inherited from Base

Base::ACTIVITY_STATES, Base::DEFAULT_STUCK_TIMEOUT, Base::TIER_TIMEOUT_MULTIPLIERS, Base::TIMEOUT_ARCHITECTURE_ANALYSIS, Base::TIMEOUT_DEFAULT, Base::TIMEOUT_DOCUMENTATION_ANALYSIS, Base::TIMEOUT_FUNCTIONALITY_ANALYSIS, Base::TIMEOUT_IMPLEMENTATION, Base::TIMEOUT_QUICK_MODE, Base::TIMEOUT_REFACTORING_RECOMMENDATIONS, Base::TIMEOUT_REPOSITORY_ANALYSIS, Base::TIMEOUT_STATIC_ANALYSIS, Base::TIMEOUT_TEST_ANALYSIS

Constants included from MessageDisplay

MessageDisplay::COLOR_MAP

Instance Attribute Summary

Attributes inherited from Base

#activity_state, #last_activity_time, #model, #start_time, #step_name, #stuck_timeout

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DebugMixin

#debug_basic?, #debug_command, #debug_enabled?, #debug_error, #debug_execute_command, #debug_level, #debug_log, #debug_logger, #debug_provider, #debug_step, #debug_timing, #debug_verbose?, included, shared_logger

Methods inherited from Base

#activity_summary, #available?, #configure, discover_models_from_registry, #execution_time, #harness_config, #harness_health_status, #harness_healthy?, #harness_metrics, #harness_mode?, #initialize, #mark_completed, #mark_failed, #record_activity, #record_harness_request, #send_with_harness, #set_harness_context, #set_job_context, #setup_activity_monitoring, #stuck?, #supports_activity_monitoring?, #time_since_last_activity, #update_activity_state

Methods included from Adapter

#available?, #capabilities, #classify_error, #dangerous_mode=, #dangerous_mode_enabled?, #dangerous_mode_flags, #error_metadata, #error_patterns, #health_status, #logging_metadata, #redact_secrets, #retryable_error?, #supports_dangerous_mode?, #validate_config

Methods included from MessageDisplay

#display_message, included, #message_display_prompt

Constructor Details

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

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/aidp/providers/cursor.rb', line 13

def self.available?
  !!Aidp::Util.which("cursor-agent")
end

.discover_modelsArray<Hash>

Discover available models from Cursor

Note: Cursor doesn’t have a public model listing API Returns registry-based models that match Cursor patterns

Returns:

  • (Array<Hash>)

    Array of discovered models



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/aidp/providers/cursor.rb', line 77

def self.discover_models
  return [] unless available?

  begin
    require_relative "../harness/model_registry"
    registry = Aidp::Harness::ModelRegistry.new

    # Get all models from registry that Cursor might support
    models = registry.all_families.filter_map do |family|
      next unless supports_model_family?(family)

      info = registry.get_model_info(family)
      next unless info

      {
        name: provider_model_name(family),
        family: family,
        tier: info["tier"],
        capabilities: info["capabilities"] || [],
        context_window: info["context_window"],
        provider: "cursor"
      }
    end

    Aidp.log_info("cursor_provider", "using registry models", count: models.size)
    models
  rescue => e
    Aidp.log_debug("cursor_provider", "discovery failed", error: e.message)
    []
  end
end

.firewall_requirementsObject

Get firewall requirements for Cursor provider



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aidp/providers/cursor.rb', line 50

def self.firewall_requirements
  {
    domains: [
      "cursor.com",
      "www.cursor.com",
      "downloads.cursor.com",
      "api.cursor.sh",
      "cursor.sh",
      "app.cursor.sh",
      "www.cursor.sh",
      # Authentication (Auth0)
      "auth.cursor.sh",
      "auth0.com",
      "*.auth0.com",
      "a0core.net",
      "*.a0core.net"
    ],
    ip_ranges: []
  }
end

.model_family(provider_model_name) ⇒ String

Normalize Cursor’s model name to family name

Cursor may use different naming conventions (e.g., dots vs hyphens)

Parameters:

  • provider_model_name (String)

    Cursor’s model name

Returns:

  • (String)

    The normalized family name



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

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

.provider_model_name(family_name) ⇒ String

Convert family name to Cursor’s naming convention

Parameters:

  • family_name (String)

    The model family name

Returns:

  • (String)

    Cursor’s model name



33
34
35
36
37
# File 'lib/aidp/providers/cursor.rb', line 33

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

.supports_model_family?(family_name) ⇒ Boolean

Check if this provider supports a given model family

Cursor supports Claude, GPT, and Cursor-specific models

Parameters:

  • family_name (String)

    The model family name

Returns:

  • (Boolean)

    True if likely supported



45
46
47
# File 'lib/aidp/providers/cursor.rb', line 45

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

Instance Method Details

#display_nameObject



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

def display_name
  "Cursor AI"
end

#fetch_mcp_serversObject



121
122
123
124
# File 'lib/aidp/providers/cursor.rb', line 121

def fetch_mcp_servers
  # Try cursor-agent CLI first, then fallback to config file
  fetch_mcp_servers_cli || fetch_mcp_servers_config
end

#nameObject



109
110
111
# File 'lib/aidp/providers/cursor.rb', line 109

def name
  "cursor"
end

#send_message(prompt:, session: nil, options: {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/aidp/providers/cursor.rb', line 126

def send_message(prompt:, session: nil, options: {})
  raise "cursor-agent not available" unless self.class.available?

  # Smart timeout calculation
  timeout_seconds = calculate_timeout

  debug_provider("cursor", "Starting execution", {timeout: timeout_seconds})
  debug_log("📝 Sending prompt to cursor-agent (length: #{prompt.length})", level: :info)

  # Set up activity monitoring
  setup_activity_monitoring("cursor-agent", method(:activity_callback))
  record_activity("Starting cursor-agent execution")

  # Create a spinner for activity display
  spinner = TTY::Spinner.new("[:spinner] :title", format: :dots, hide_cursor: true)
  spinner.auto_spin

  activity_display_thread = Thread.new do
    start_time = Time.now
    loop do
      sleep 0.5 # Update every 500ms to reduce spam
      elapsed = Time.now - start_time

      # Break if we've been running too long or state changed
      break if elapsed > timeout_seconds || @activity_state == :completed || @activity_state == :failed

      update_spinner_status(spinner, elapsed, "🔄 cursor-agent")
    end
  end

  begin
    # Use debug_execute_command for better debugging
    # Use -p mode (designed for non-interactive/script use)
    # No fallback to interactive modes - they would hang AIDP's automation workflow
    result = debug_execute_command("cursor-agent", args: ["-p"], input: prompt, timeout: timeout_seconds)

    # Log the results
    debug_command("cursor-agent", args: ["-p"], input: prompt, output: result.out, error: result.err, exit_code: result.exit_status)

    if result.exit_status == 0
      spinner.success("✓")
      mark_completed
      result.out
    else
      spinner.error("✗")
      mark_failed("cursor-agent failed with exit code #{result.exit_status}")
      debug_error(StandardError.new("cursor-agent failed"), {exit_code: result.exit_status, stderr: result.err})
      raise "cursor-agent failed with exit code #{result.exit_status}: #{result.err}"
    end
  rescue => e
    spinner&.error("✗")
    mark_failed("cursor-agent execution failed: #{e.message}")
    debug_error(e, {provider: "cursor", prompt_length: prompt.length})
    raise
  ensure
    cleanup_activity_display(activity_display_thread, spinner)
  end
end

#supports_mcp?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/aidp/providers/cursor.rb', line 117

def supports_mcp?
  true
end