Skip to content

[harness] Add Cursor CLI provider to Python SDK #292

@santoshkumarradha

Description

@santoshkumarradha

Parent Epic

Part of #291 — Add Cursor as a Harness Provider

Summary

Add CursorProvider to the Python SDK harness system. This follows the exact same pattern as the existing ClaudeCodeProvider, CodexProvider, GeminiProvider, and OpenCodeProvider.

Files to Create/Modify

New

  • sdk/python/agentfield/harness/providers/cursor.pyCursorProvider class

Modify

  • sdk/python/agentfield/harness/providers/_factory.py — Add "cursor" to SUPPORTED_PROVIDERS, wire factory
  • sdk/python/agentfield/harness/_runner.py — Add cursor_bin to config (if not already generic)
  • sdk/python/agentfield/harness/providers/__init__.py — Export

Tests

  • sdk/python/tests/harness/test_cursor.py

Implementation Details

CLI Command Construction

cmd = ["agent", "-p", "--force", "--trust", "--output-format", "stream-json"]

if options.cwd:
    cmd.extend(["--workspace", options.cwd])
if options.model:
    cmd.extend(["--model", options.model])
if options.resume_session_id:
    cmd.extend(["--resume", options.resume_session_id])
if options.permission_mode == "plan":
    cmd.extend(["--mode", "plan"])

# API key via env
env["CURSOR_API_KEY"] = api_key

cmd.append(prompt)

Output Parsing

Use stream-json mode (NDJSON). Parse events:

  • {"type": "result", "subtype": "success", "result": "<text>", "session_id": "<uuid>", "duration_ms": N} — final result
  • Tool call events for streaming (optional first pass — can use json mode if simpler)

Session Resume

session_id from result event maps to --resume <chatId> on next invocation. Store in RawResult.session_id.

Config

Add to HarnessConfig:

cursor_bin: Optional[str] = None  # Override binary path (default: "agent")

Permission Mode Mapping

AgentField Cursor CLI
"auto" --force (default, already in base flags)
"plan" --mode plan
None --mode ask

Acceptance Criteria

  • CursorProvider implements HarnessProvider protocol
  • Factory resolves "cursor" to CursorProvider
  • Prompt passed as last positional argument
  • JSON/stream-json output parsed correctly
  • Session resume works via --resume
  • cursor_bin config allows custom binary path
  • Schema validation uses same .agentfield_output.json pattern
  • Tests cover: basic execution, session resume, error handling, timeout
  • Follows exact patterns from existing providers (reference: codex.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-friendlyWell-documented task suitable for AI-assisted developmentarea:harnessCoding agent harness integrationcore-teamMaintained by core team — not open for external contributionenhancementNew feature or requestsdk:pythonPython SDK related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions