From 02b8546914c085384cda9205b30800a26694228b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 30 Sep 2025 11:14:52 +0900 Subject: [PATCH 1/6] "Claude PR Assistant workflow" --- .github/workflows/claude.yml | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/claude.yml diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml new file mode 100644 index 000000000..b1a3201d7 --- /dev/null +++ b/.github/workflows/claude.yml @@ -0,0 +1,50 @@ +name: Claude Code + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + issues: + types: [opened, assigned] + pull_request_review: + types: [submitted] + +jobs: + claude: + if: | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + issues: read + id-token: write + actions: read # Required for Claude to read CI results on PRs + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Run Claude Code + id: claude + uses: anthropics/claude-code-action@v1 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + + # This is an optional setting that allows Claude to read CI results on PRs + additional_permissions: | + actions: read + + # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. + # prompt: 'Update the pull request description to include a summary of changes.' + + # Optional: Add claude_args to customize behavior and configuration + # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md + # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options + # claude_args: '--model claude-opus-4-1-20250805 --allowed-tools Bash(gh pr:*)' + From 219cc72d6369e0334aa9e3bd29dc5db62afffb4d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 30 Sep 2025 11:14:53 +0900 Subject: [PATCH 2/6] "Claude Code Review workflow" --- .github/workflows/claude-code-review.yml | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/claude-code-review.yml diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml new file mode 100644 index 000000000..31c04fdf6 --- /dev/null +++ b/.github/workflows/claude-code-review.yml @@ -0,0 +1,57 @@ +name: Claude Code Review + +on: + pull_request: + types: [opened, synchronize] + # Optional: Only run on specific file changes + # paths: + # - "src/**/*.ts" + # - "src/**/*.tsx" + # - "src/**/*.js" + # - "src/**/*.jsx" + +jobs: + claude-review: + # Optional: Filter by PR author + # if: | + # github.event.pull_request.user.login == 'external-contributor' || + # github.event.pull_request.user.login == 'new-developer' || + # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + issues: read + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Run Claude Code Review + id: claude-review + uses: anthropics/claude-code-action@v1 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + prompt: | + REPO: ${{ github.repository }} + PR NUMBER: ${{ github.event.pull_request.number }} + + Please review this pull request and provide feedback on: + - Code quality and best practices + - Potential bugs or issues + - Performance considerations + - Security concerns + - Test coverage + + Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback. + + Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR. + + # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md + # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options + claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"' + From 32b147e6b7acc0c5e336a44dc04a5d5de70d386d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 2 Oct 2025 17:55:07 +0900 Subject: [PATCH 3/6] Add CLAUDE.md instructions file --- CLAUDE.md | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..6f9bf92bf --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,114 @@ +# type-fest + +TypeScript utility types library. Pure type-level programming—no runtime code. + +**Read `.github/contributing.md` for complete guidelines.** + +## Commands + +```bash +npm test # MUST pass before committing (runs all below) +npm run test:tsc # TypeScript compiler +npm run test:tsd # Type tests (tsd) +npm run test:xo # Linter +``` + +## File Structure + +``` +source/type-name.d.ts → Type definition (.d.ts REQUIRED) +test-d/type-name.ts → Tests (tsd) +index.d.ts → Export (MUST add, lint enforces) +readme.md → API docs (add to category) +source/internal/ → Shared helpers (not exported) +``` + +## Code Patterns + +```ts +// ✅ CORRECT +import type {IsNever} from './is-never.d.ts'; // Include .d.ts +export type MyType = ... // Descriptive names (not T/U) +export {}; // REQUIRED at end + +// ❌ WRONG +import type {IsNever} from './is-never'; // Missing .d.ts +export type MyType = ...; // Single-letter + +/** +Creates a tuple type of specified length with elements of specified type. + +Use-cases: +- Define fixed-length arrays with specific types + +@example +``` +import type {TupleOf} from 'type-fest'; +type RGB = TupleOf<3, number>; //=> [number, number, number] +``` + +@category Array +*/ +export type TupleOf = ...; +export {}; +``` + +Type params: `Value`, `Target`, `Item`, `Length`, `Element`, `Key` (not `T`, `U`, `V`, `K`) +Docs: No `*` prefix. First line → readme. Include use-cases, examples, `@category`. + +## Testing + +**ALWAYS test edge cases** (`any`, `never`, `unknown`). + +```ts +expectType('' as MyType<'foo'>); // Basic +expectType('' as MyType); // any/never/unknown +expectNotAssignable>({wrong: true}); // Negative +expectError>(); // Should error +``` + +Study: `source/tuple-of.d.ts`, `is-equal.d.ts`, `literal-union.d.ts`, `internal/*.d.ts` + +## Workflow + +1. Research - Study `source/` similar types + online research +2. Define - `source/type-name.d.ts` with docs +3. Test - `test-d/type-name.ts` with edge cases +4. Export - Add to `index.d.ts` + readme.md +5. Verify - `npm test` must pass +6. Commit - ``Add `TypeName` type`` or `` `TypeName`: Fix description`` + +## Critical Rules + +1. Import paths MUST include `.d.ts` extension +2. Files MUST end with `export {};` +3. Types MUST be exported from `index.d.ts` +4. Type params MUST use descriptive names (not `T`/`U`) +5. MUST test `any`, `never`, `unknown` edge cases +6. First doc line MUST be concise (goes in readme) +7. Use realistic examples with `//=>` comments +8. Include `@category` tags +9. Fix lint issues, don't disable rules + +## Type Programming + +- Conditionals: `T extends U ? X : Y` +- Recursion: `type Loop = ... Loop<...> ...` +- Extract: `infer Item` +- Distribute: `T extends any ? ... : never` +- Count via tuple `['length']` +- Union distribution is tricky—test it + +## Philosophy + +- Correctness > cleverness +- Real problems only +- Docs teach how, not what +- Edge cases mandatory +- One concept per PR +- Descriptive names > brevity + +## Troubleshooting + +- Tests fail? Check `.d.ts` imports, `export {};`, edge cases (`any`, `never`, `unknown`) +- Lint errors? Add to `index.d.ts`, fix issues (don't disable rules) From 6e27ebc7a70f6cba522735c5e8839039f6dd0667 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 2 Oct 2025 18:15:54 +0900 Subject: [PATCH 4/6] Update claude-code-review.yml --- .github/workflows/claude-code-review.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 31c04fdf6..641eaf67c 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -1,36 +1,20 @@ name: Claude Code Review - on: pull_request: types: [opened, synchronize] - # Optional: Only run on specific file changes - # paths: - # - "src/**/*.ts" - # - "src/**/*.tsx" - # - "src/**/*.js" - # - "src/**/*.jsx" - jobs: claude-review: - # Optional: Filter by PR author - # if: | - # github.event.pull_request.user.login == 'external-contributor' || - # github.event.pull_request.user.login == 'new-developer' || - # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' - runs-on: ubuntu-latest permissions: contents: read pull-requests: read issues: read id-token: write - steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 1 - - name: Run Claude Code Review id: claude-review uses: anthropics/claude-code-action@v1 @@ -54,4 +38,3 @@ jobs: # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"' - From 3a8c129d73d3c81d1a796ab9f9cff0448157006a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 2 Oct 2025 18:16:19 +0900 Subject: [PATCH 5/6] Update claude-code-review.yml --- .github/workflows/claude-code-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 641eaf67c..604bafcd2 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -12,7 +12,7 @@ jobs: id-token: write steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: fetch-depth: 1 - name: Run Claude Code Review From c785a2c54524260192cfb9f90f81b8a8331437d3 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 2 Oct 2025 18:17:15 +0900 Subject: [PATCH 6/6] Update claude.yml --- .github/workflows/claude.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index b1a3201d7..45c6704c7 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -1,5 +1,4 @@ name: Claude Code - on: issue_comment: types: [created] @@ -9,7 +8,6 @@ on: types: [opened, assigned] pull_request_review: types: [submitted] - jobs: claude: if: | @@ -29,22 +27,10 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 1 - - name: Run Claude Code id: claude uses: anthropics/claude-code-action@v1 with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} - - # This is an optional setting that allows Claude to read CI results on PRs additional_permissions: | actions: read - - # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. - # prompt: 'Update the pull request description to include a summary of changes.' - - # Optional: Add claude_args to customize behavior and configuration - # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md - # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options - # claude_args: '--model claude-opus-4-1-20250805 --allowed-tools Bash(gh pr:*)' -