name: Close stale issues

on:
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:

permissions:
  issues: write
  pull-requests: write

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@v9
        with:
          # Issue settings
          days-before-issue-stale: 90
          days-before-issue-close: 14
          stale-issue-label: 'stale'
          stale-issue-message: >
            This issue has been automatically marked as stale because it has not
            had any activity in 90 days. It will be closed in 14 days if no
            further activity occurs. If this is still relevant, please leave a
            comment or remove the `stale` label.
          close-issue-message: >
            This issue has been closed due to inactivity. If this is still
            relevant, feel free to reopen it or create a new issue.

          # PR settings — mark stale but never auto-close
          days-before-pr-stale: 90
          days-before-pr-close: -1
          stale-pr-label: 'stale'
          stale-pr-message: >
            This pull request has been automatically marked as stale because it
            has not had any activity in 90 days. Please update your branch and
            address any review comments, or it may be closed in the future.

          # Exempt these labels from stale processing
          exempt-issue-labels: 'P0-critical,P1-high,good first issue,security'
          exempt-pr-labels: 'P0-critical,P1-high'

          # Remove stale label when there is new activity
          remove-stale-when-updated: true

          # Process up to 100 issues per run to stay within API limits
          operations-per-run: 100
