# CLI tools: gh, glab, glp, git-cliff

allowlists:
  commands:
    # ── glp (GitLab Pipeline CLI): read-only invocations ──────────
    - { command: "glp status", trust: minimal }
    - { command: "glp jobs", trust: minimal }
    - { command: "glp log", trust: minimal }
    - { command: "glp --version", trust: minimal }
    - { command: "glp --help", trust: minimal }
    - { command: "glp -h", trust: minimal }
    # ── glp: remote-write operations (full trust) ────────────────
    - { command: "glp retry", trust: full, reason: "Retries a GitLab CI/CD pipeline job" }
    # ── glab (GitLab CLI): read-only invocations ──────────────────
    # Note: mutating API calls (POST/PUT/DELETE/PATCH) caught by glab-api-mutating rule
    - { command: "glab auth status", trust: minimal }
    - { command: "glab ci status", trust: minimal }
    - { command: "glab ci view", trust: minimal }
    - { command: "glab ci list", trust: minimal }
    - { command: "glab ci trace", trust: minimal }
    - { command: "glab ci get", trust: minimal }
    - { command: "glab repo list", trust: minimal }
    - { command: "glab repo view", trust: minimal }
    - { command: "glab group list", trust: minimal }
    - { command: "glab issue list", trust: minimal }
    - { command: "glab issue view", trust: minimal }
    - { command: "glab mr list", trust: minimal }
    - { command: "glab mr view", trust: minimal }
    - { command: "glab --version", trust: minimal }
    - { command: "glab --help", trust: minimal }
    # ── gh (GitHub CLI): version / help short-circuits ──────────────
    # Note: read-only subcommands (pr view/list/diff/checks/status,
    # issue view/list/status, repo view/list, run view/list/watch,
    # workflow view/list, auth status, release view/list, search *,
    # gist view/list, label list, secret list, variable list, cache list,
    # status, api GET) are handled by the gh-readonly-classifier in
    # evaluate_leaf; no YAML entries needed for them.
    # Mutating API calls (POST/PUT/DELETE/PATCH) caught by gh-api-mutating rule.
    - { command: "gh --version", trust: minimal }
    - { command: "gh --help", trust: minimal }
    - { command: "gh -h", trust: minimal }
    # ── gh: remote-write operations (full trust) ───────────────────
    - { command: "gh api", trust: full, reason: "Makes authenticated GitHub API requests" }
    - { command: "gh pr create", trust: full, reason: "Creates a pull request on GitHub" }
    - { command: "gh pr merge", trust: full, reason: "Merges a pull request on GitHub" }
    - { command: "gh pr close", trust: full, reason: "Closes a pull request on GitHub" }
    - { command: "gh pr reopen", trust: full, reason: "Reopens a closed pull request" }
    - { command: "gh pr comment", trust: full, reason: "Adds a comment to a pull request" }
    - { command: "gh pr review", trust: full, reason: "Submits a review on a pull request" }
    - { command: "gh pr edit", trust: full, reason: "Edits a pull request's metadata" }
    - { command: "gh pr ready", trust: full, reason: "Marks a pull request as ready for review" }
    - { command: "gh issue create", trust: full, reason: "Creates a new GitHub issue" }
    - { command: "gh issue close", trust: full, reason: "Closes a GitHub issue" }
    - { command: "gh issue reopen", trust: full, reason: "Reopens a closed GitHub issue" }
    - { command: "gh issue comment", trust: full, reason: "Adds a comment to a GitHub issue" }
    - { command: "gh issue edit", trust: full, reason: "Edits a GitHub issue's metadata" }
    - { command: "gh issue delete", trust: full, reason: "Permanently deletes a GitHub issue" }
    - { command: "gh release create", trust: full, reason: "Creates a new GitHub release" }
    - { command: "gh release delete", trust: full, reason: "Deletes a GitHub release" }
    - { command: "gh release edit", trust: full, reason: "Edits a GitHub release" }
    - { command: "gh repo create", trust: full, reason: "Creates a new GitHub repository" }
    - { command: "gh repo delete", trust: full, reason: "Permanently deletes a GitHub repository" }
    - { command: "gh repo edit", trust: full, reason: "Edits GitHub repository settings" }
    - { command: "gh repo fork", trust: full, reason: "Forks a GitHub repository" }
    - { command: "gh label create", trust: full, reason: "Creates a new label in a repository" }
    - { command: "gh label edit", trust: full, reason: "Edits an existing repository label" }
    - { command: "gh label delete", trust: full, reason: "Deletes a repository label" }
    - { command: "gh run rerun", trust: full, reason: "Re-runs a GitHub Actions workflow run" }
    - { command: "gh run cancel", trust: full, reason: "Cancels a GitHub Actions workflow run" }
    - { command: "gh workflow run", trust: full, reason: "Triggers a GitHub Actions workflow" }
    - { command: "gh workflow enable", trust: full, reason: "Enables a GitHub Actions workflow" }
    - { command: "gh workflow disable", trust: full, reason: "Disables a GitHub Actions workflow" }
    # ── glab: remote-write operations (full trust) ─────────────────
    - { command: "glab api", trust: full, reason: "Makes authenticated GitLab API requests" }
    - { command: "glab mr create", trust: full, reason: "Creates a merge request on GitLab" }
    - { command: "glab mr merge", trust: full, reason: "Merges a merge request on GitLab" }
    - { command: "glab mr close", trust: full, reason: "Closes a merge request on GitLab" }
    - { command: "glab mr reopen", trust: full, reason: "Reopens a closed merge request" }
    - { command: "glab mr approve", trust: full, reason: "Approves a merge request on GitLab" }
    - { command: "glab mr revoke", trust: full, reason: "Revokes approval from a merge request" }
    - { command: "glab mr comment", trust: full, reason: "Adds a comment to a merge request" }
    - { command: "glab mr note", trust: full, reason: "Adds a note to a merge request" }
    - { command: "glab mr update", trust: full, reason: "Updates a merge request's metadata" }
    - { command: "glab mr delete", trust: full, reason: "Deletes a merge request on GitLab" }
    - { command: "glab issue create", trust: full, reason: "Creates a new GitLab issue" }
    - { command: "glab issue close", trust: full, reason: "Closes a GitLab issue" }
    - { command: "glab issue reopen", trust: full, reason: "Reopens a closed GitLab issue" }
    - { command: "glab issue comment", trust: full, reason: "Adds a comment to a GitLab issue" }
    - { command: "glab issue note", trust: full, reason: "Adds a note to a GitLab issue" }
    - { command: "glab issue update", trust: full, reason: "Updates a GitLab issue's metadata" }
    - { command: "glab issue delete", trust: full, reason: "Permanently deletes a GitLab issue" }
    - { command: "glab release create", trust: full, reason: "Creates a new GitLab release" }
    - { command: "glab release delete", trust: full, reason: "Deletes a GitLab release" }
    - { command: "glab ci run", trust: full, reason: "Triggers a GitLab CI/CD pipeline" }
    - { command: "glab ci retry", trust: full, reason: "Retries a GitLab CI/CD pipeline job" }
    - { command: "glab ci cancel", trust: full, reason: "Cancels a GitLab CI/CD pipeline" }
    - { command: "glab repo create", trust: full, reason: "Creates a new GitLab repository" }
    - { command: "glab repo fork", trust: full, reason: "Forks a GitLab repository" }
    - { command: "glab repo delete", trust: full, reason: "Permanently deletes a GitLab repository" }
    - { command: "glab label create", trust: full, reason: "Creates a new label in a GitLab project" }
    - { command: "glab label delete", trust: full, reason: "Deletes a label from a GitLab project" }
    # ── pfp (Prefect Pipeline CLI): read-only invocations ─────────
    - { command: "pfp ls", trust: minimal }
    - { command: "pfp list", trust: minimal }
    - { command: "pfp runs", trust: minimal }
    - { command: "pfp logs", trust: minimal }
    - { command: "pfp --help", trust: minimal }
    - { command: "pfp -h", trust: minimal }
    - { command: "pfp --version", trust: minimal }
    - { command: "pfp -V", trust: minimal }
    # ── pfp: mutating operations (full trust) ────────────────────
    - { command: "pfp run", trust: full, reason: "Triggers a Prefect flow run" }
    - { command: "pfp pause", trust: full, reason: "Pauses a Prefect flow run" }
    - { command: "pfp resume", trust: full, reason: "Resumes a paused Prefect flow run" }
    - { command: "pfp cancel", trust: full, reason: "Cancels a Prefect flow run" }
    # ── git-cliff: stdout-only invocations ────────────────────────
    - { command: "git-cliff", trust: standard, reason: "Generates a changelog from git history" }
    - { command: "git-cliff --unreleased", trust: standard, reason: "Generates changelog for unreleased changes" }
    - { command: "git-cliff --latest", trust: standard, reason: "Generates changelog for the latest release" }
    - { command: "git-cliff --current", trust: standard, reason: "Generates changelog for the current version" }
    # ── chezmoi (dotfile manager): read-only subcommands ─────────
    # Mutating subcommands (apply, init, add, edit, update, forget,
    # re-add, merge, import, archive, secret, chattr, edit-config,
    # upgrade, purge, state) are deliberately NOT allowlisted and
    # fall through to the default (ask).
    - { command: "chezmoi --version", trust: minimal }
    - { command: "chezmoi --help", trust: minimal }
    - { command: "chezmoi -h", trust: minimal }
    - { command: "chezmoi managed", trust: minimal }
    - { command: "chezmoi unmanaged", trust: minimal }
    - { command: "chezmoi list", trust: minimal }
    - { command: "chezmoi status", trust: minimal }
    - { command: "chezmoi diff", trust: minimal }
    - { command: "chezmoi cat", trust: minimal }
    - { command: "chezmoi cat-config", trust: minimal }
    - { command: "chezmoi data", trust: minimal }
    - { command: "chezmoi doctor", trust: minimal }
    - { command: "chezmoi dump", trust: minimal }
    - { command: "chezmoi dump-config", trust: minimal }
    - { command: "chezmoi source-path", trust: minimal }
    - { command: "chezmoi target-path", trust: minimal }
    - { command: "chezmoi verify", trust: minimal }
    - { command: "chezmoi execute-template", trust: minimal }

rules:
  # ============================================================
  # HIGH: CLI tool mutating operations
  # ============================================================
  - id: glab-api-mutating
    level: high
    match:
      command: glab
      args:
        any_of: ["POST", "PUT", "DELETE", "PATCH"]
    decision: ask
    reason: "GitLab API mutating operation (POST/PUT/DELETE/PATCH)"

  - id: gh-api-mutating
    level: high
    match:
      command: gh
      args:
        any_of: ["POST", "PUT", "DELETE", "PATCH"]
    decision: ask
    reason: "GitHub API mutating operation (POST/PUT/DELETE/PATCH)"

  - id: git-cliff-write-file
    level: high
    match:
      command: git-cliff
      flags:
        any_of: ["-o", "--output", "--init", "--tag"]
    decision: ask
    reason: "git-cliff operation that writes files or modifies state"
