name: Cursor Agent
description: Run Cursor CLI on @cursor mentions in Gitea issues and pull requests
inputs:
  cursor_api_key:
    description: Cursor API key
    required: true
  gitea_token:
    description: Gitea API token for the cursor bot user
    required: true
  gitea_base_url:
    description: Gitea instance URL (e.g. https://gitea.schwenk.online)
    required: true
  ai_model:
    description: Cursor model id
    required: false
    default: composer-2.5

runs:
  using: composite
  steps:
    - name: Check comment and capture context
      id: check
      shell: bash
      run: |
        chmod +x "$GITHUB_ACTION_PATH/scripts/"*.sh
        "$GITHUB_ACTION_PATH/scripts/check-comment.sh"

    - name: Install dependencies
      if: steps.check.outputs.run_cursor == 'true'
      shell: bash
      run: |
        "$GITHUB_ACTION_PATH/scripts/install-deps.sh"

    - name: Run Cursor
      if: steps.check.outputs.run_cursor == 'true'
      shell: bash
      env:
        CURSOR_API_KEY: ${{ inputs.cursor_api_key }}
        GITEA_ACCESS_TOKEN: ${{ inputs.gitea_token }}
        GITEA_BASE_URL: ${{ inputs.gitea_base_url }}
        AI_MODEL: ${{ inputs.ai_model }}
      run: |
        "$GITHUB_ACTION_PATH/scripts/run-cursor.sh"
