Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .claude/skills/ci/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
name: ci-context
description: Constraints and environment details for Claude running inside the GitHub Actions workflow on pytorch/tutorials. This skill is automatically loaded in the CI context. Use when Claude is invoked via @claude mentions on issues or PRs.
---

# CI Environment Skill

This skill applies when Claude is running inside the GitHub Actions workflow (`claude-code.yml`) on `pytorch/tutorials`. It defines what is available, what is allowed, and what is forbidden in this context.

## Environment

| Detail | Value |
|--------|-------|
| Runner | `ubuntu-latest` |
| Python | 3.12 (pre-installed via `actions/setup-python`) |
| Lintrunner | 0.12.5 (pre-installed and initialized) |
| Timeout | 60 minutes |
| Model | `claude-opus-4-6-v1` via AWS Bedrock |

**All tools you need are already installed.** Do not run `pip install`, `apt-get`, or any other installation commands. If a tool is missing, state that it is unavailable and move on.

## Permissions

The workflow grants these GitHub token permissions:

| Permission | Level | What it allows |
|------------|-------|----------------|
| `contents` | `read` | Read repo files, checkout code |
| `pull-requests` | `write` | Comment on PRs, post reviews |
| `issues` | `write` | Comment on issues, add/remove labels |
| `id-token` | `write` | OIDC authentication to AWS Bedrock |

## What You MUST NOT Do

- **Commit or push** — You have read-only access to repo contents. Never attempt `git commit`, `git push`, or create branches.
- **Merge or close PRs** — You cannot and should not merge pull requests.
- **Close issues** — Never close issues. Only add comments and labels.
- **Install packages** — Everything needed is pre-installed. Do not run `pip install`, `npm install`, `apt-get`, etc.
- **Modify workflow files** — Do not suggest changes to `.github/workflows/` files in automated comments.
- **Assign users** — Do not assign issues or PRs to specific people.
- **Add labels that require human judgment** — See the triage skill for the full restricted labels list.

## What You CAN Do

- **Read all repo files** — Full checkout is available at the workspace root.
- **Run lintrunner**`lintrunner -m main` or `lintrunner --all-files` are available.
- **Run make (dry/noplot)**`make html-noplot` works for RST/Sphinx validation (no GPU).
- **Comment on PRs and issues** — Post review comments, inline suggestions, and general comments.
- **Add/remove labels on issues** — Apply triage labels from the approved list.
- **Search for similar issues** — Use GitHub MCP tools to find duplicates or related issues.

## Available MCP Tools

| Tool | Purpose |
|------|---------|
| `mcp__github__issue_read` | Read issue details, comments, and labels |
| `mcp__github__issue_write` | Add/remove labels on issues (do NOT close) |
| `mcp__github__add_issue_comment` | Post a comment on an issue |
| `mcp__github__search_issues` | Search for similar/duplicate issues |
| `mcp__github__pr_read` | Read PR details, diff, and review comments |
| `mcp__github__pr_comment` | Post a comment or review on a PR |

## Trigger Context

Claude is invoked when a user mentions `@claude` in:
- An issue comment (`issue_comment` event)
- A PR review comment (`pull_request_review_comment` event)
- A new issue body (`issues.opened` event)

The triggering comment or issue body is passed as the prompt. Respond directly to what the user asked — do not perform unrequested actions.

## Interaction Style

- You are responding asynchronously via GitHub comments. There is no interactive terminal session.
- Be concise — GitHub comments should be scannable, not walls of text.
- Use markdown formatting (headers, tables, code blocks) for readability.
- If you cannot complete a request due to permission constraints, explain what you tried and what the user should do instead.
186 changes: 186 additions & 0 deletions .claude/skills/pr-review/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
name: pr-review
description: Review PyTorch tutorials pull requests for content quality, code correctness, build compatibility, and style. Use when reviewing PRs, when asked to review code changes, or when the user mentions "review PR", "code review", or "check this PR".
---

# Tutorials PR Review Skill

Review PyTorch tutorials pull requests for content quality, code correctness, tutorial structure, and Sphinx/RST formatting. CI lintrunner only checks trailing whitespace, tabs, and newlines — it does not validate RST syntax, Python formatting, or Sphinx directives, so those must be reviewed manually.

## Usage Modes

### No Argument

If the user invokes `/pr-review` with no arguments, **do not perform a review**. Instead, ask the user what they would like to review:

> What would you like me to review?
> - A PR number or URL (e.g., `/pr-review 12345`)
> - A local branch (e.g., `/pr-review branch`)
### Local CLI Mode

The user provides a PR number or URL:

```
/pr-review 12345
/pr-review https://github.com/pytorch/tutorials/pull/12345
```

For a detailed review with line-by-line specific comments:

```
/pr-review 12345 detailed
```

Use `gh` CLI to fetch PR data:

```bash
# Get PR details
gh pr view <PR_NUMBER> --json title,body,author,baseRefName,headRefName,files,additions,deletions,commits

# Get the diff
gh pr diff <PR_NUMBER>

# Get PR comments
gh pr view <PR_NUMBER> --json comments,reviews
```

### Local Branch Mode

Review changes in the current branch that are not in `main`:

```
/pr-review branch
/pr-review branch detailed
```

Use git commands to get branch changes:

```bash
# Get current branch name
git branch --show-current

# Get list of changed files compared to main
git diff --name-only main...HEAD

# Get full diff compared to main
git diff main...HEAD

# Get commit log for the branch
git log main..HEAD --oneline

# Get diff stats (files changed, insertions, deletions)
git diff --stat main...HEAD
```

For local branch reviews:
- The "Summary" should describe what the branch changes accomplish based on commit messages and diff
- Use the current branch name in the review header instead of a PR number
- All other review criteria apply the same as PR reviews

### GitHub Actions Mode

When invoked via workflow, PR data is passed as context. The PR number or diff will be available in the prompt. See the [CI Environment Skill](../ci/SKILL.md) for environment constraints, available tools, and permissions.

## Review Workflow

### Step 1: Fetch PR Information

For local mode, use `gh` commands to get:
1. PR metadata (title, description, author)
2. List of changed files
3. Full diff of changes
4. Existing comments/reviews

### Step 2: Analyze Changes

Read through the diff systematically:
1. Identify the purpose of the change from title/description
2. Group changes by type (tutorial content, config, build, infra)
3. Note the scope of changes (files affected, lines changed)

### Step 3: Deep Review

Perform thorough analysis using the review checklist. See [review-checklist.md](review-checklist.md) for detailed criteria covering:
- Tutorial content quality and accuracy
- Code correctness in tutorial examples
- Sphinx/RST formatting
- Build compatibility
- Project structure compliance

### Step 4: Formulate Review

Structure your review with actionable feedback organized by category.

## Review Areas

| Area | Focus | Reference |
|------|-------|-----------|
| Content Quality | Accuracy, clarity, learning objectives | [review-checklist.md](review-checklist.md) |
| Code Correctness | Working examples, imports, API usage | [review-checklist.md](review-checklist.md) |
| Structure | File placement, index entries, toctree | [review-checklist.md](review-checklist.md) |
| Formatting | RST/Sphinx syntax, Sphinx Gallery conventions | [review-checklist.md](review-checklist.md) |
| Build | Dependencies, data downloads, CI compat | [review-checklist.md](review-checklist.md) |

## Output Format

Structure your review as follows:

```markdown
## PR Review: #<number>
<!-- Or for local branch reviews: -->
## Branch Review: <branch-name> (vs main)

### Summary
Brief overall assessment of the changes (1-2 sentences).

### Content Quality
[Issues and suggestions, or "No concerns" if none]

### Code Correctness
[Issues with tutorial code examples, imports, API usage, or "No concerns"]

### Structure & Formatting
[File placement, RST/Sphinx issues, index/toctree entries, or "No concerns"]

### Build Compatibility
[Dependency issues, data download concerns, CI compatibility, or "No concerns"]

### Recommendation
**Approve** / **Request Changes** / **Needs Discussion**

[Brief justification for recommendation]
```

### Specific Comments (Detailed Review Only)

**Only include this section if the user requests a "detailed" or "in depth" review.**

**Do not repeat observations already made in other sections.** This section is for additional file-specific feedback that doesn't fit into the categorized sections above.

When requested, add file-specific feedback with line references:

```markdown
### Specific Comments
- `beginner_source/my_tutorial.py:42` - Docstring prose is unclear; rephrase for non-native speakers
- `index.rst:150` - Missing customcarditem entry for the new tutorial
- `requirements.txt:30` - New dependency should be pinned to a specific version
```

## Key Principles

1. **No repetition** - Each observation appears in exactly one section
2. **Focus on what CI cannot check** - Don't comment on trailing whitespace or tab characters (caught by lintrunner). RST syntax, Sphinx directives, and Python code style must still be reviewed
3. **Be specific** - Reference file paths and line numbers
4. **Be actionable** - Provide concrete suggestions, not vague concerns
5. **Be proportionate** - Minor issues shouldn't block, but note them
6. **Audience awareness** - Tutorials are read by beginners; clarity matters more than brevity

## Files to Reference

When reviewing, consult these project files for context:
- `CLAUDE.md` - Project structure and coding style
- `CONTRIBUTING.md` - Submission process, tutorial types, and authoring guidance
- `conf.py` - Sphinx Gallery configuration and extensions
- `requirements.txt` - Approved dependencies
- `index.rst` - Card listings and toctree structure
Loading