From 620978bd49f99345d2a76feb3382d0f05cb21c3a Mon Sep 17 00:00:00 2001 From: gabrypavanello Date: Mon, 12 Jan 2026 11:41:15 +0100 Subject: [PATCH 1/4] feat: Add daily automation workflow for Claude Kaizen tasks Introduce a new GitHub Actions workflow that runs daily to automate code hygiene tasks. The workflow includes steps for checking out the repository, setting up Node.js and pnpm, and executing the Claude Code Kaizen action to identify and address code issues. This aims to enhance code quality through regular, incremental improvements. --- .github/workflows/claude-kaizen.yml | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/claude-kaizen.yml diff --git a/.github/workflows/claude-kaizen.yml b/.github/workflows/claude-kaizen.yml new file mode 100644 index 00000000..cac2477c --- /dev/null +++ b/.github/workflows/claude-kaizen.yml @@ -0,0 +1,95 @@ +name: Claude Kaizen Daily Task + +on: + schedule: + # Runs daily at 6:00 AM UTC (configurable) + - cron: "0 6 * * *" + workflow_dispatch: # Allow manual trigger for testing + +jobs: + claude-kaizen: + runs-on: ubuntu-latest + permissions: + contents: write # Create branches and commits + pull-requests: write # Create and update PRs + issues: write # Reference issues if needed + id-token: write # Required for Claude Code authentication + actions: read # Read CI results + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.19.0 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "20" + cache: "pnpm" + + - name: Run Claude Code Kaizen + id: claude-kaizen + uses: anthropics/claude-code-action@v1 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + + # Additional permissions for Claude to interact with GitHub + additional_permissions: | + actions: read + contents: write + pull-requests: write + issues: write + + # Allow git operations and gh CLI for creating PRs + # Also allow pnpm for running tests/builds if needed + claude_args: '--allowed-tools "Bash(git checkout:*),Bash(git branch:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(gh pr create:*),Bash(gh pr view:*),Bash(pnpm:*)"' + + prompt: | + System Context: You are a Lead Software Engineer automated bot designed to submit one daily "Code Hygiene" Pull Request. Your goal is incremental improvement, not feature building. + + Instructions: + + Step 1: Contextual Analysis + Briefly explain the core functionality of the files currently in context. Demonstrate that you understand the data flow. + + Step 2: Issue Detection (Strict Mode) + Scan the code for issues. You are strictly forbidden from fabricating issues. If a specific category (like a bug) is not found, state "No critical bugs found" and suggest a minor syntax cleanup instead. + + Step 3: The Daily 4 + Generate a task list containing exactly one item for each category below. For each, cite the specific file and line number. + + 1. The Typo Fix: Locate a spelling error in user-facing text, variable names, or internal comments. + 2. The Logic Fix: Locate a bug, undefined variable, dangerous unhandled promise, or off-by-one error. + 3. The Documentation Fix: Locate a discrepancy where the code has changed but the comments/documentation have not, or identify a complex function with zero comments. + 4. The Test Improvement: Identify a critical path that is currently untested or a test that is flaky/weak. + + Step 4: PR Generation + After you've identified the four items and made the necessary code changes: + + 1. Create a new branch with the naming pattern: kaizen/$(date +%Y-%m-%d) + 2. Commit all your changes with a descriptive commit message + 3. Push the branch to the remote repository + 4. Create a Pull Request using `gh pr create` with the following format: + + - PR Title: [Kaizen Daily Task] Daily Hygiene Update - $(date +%Y-%m-%d) + - PR Body: Use the Markdown format below + + # Daily Hygiene Update + + 🔍 Codebase Status + [Brief summary of the code analyzed] + + 🛠 Proposed Changes + - [ ] Fix Typo: [File:Line] - Change x to y + - [ ] Fix Bug: [File:Line] - [Description of the bug] + - [ ] Update Docs: [File:Line] - [Description of the discrepancy] + - [ ] Improve Test: [File:Line] - [Description of the test case to add] + + IMPORTANT: You MUST create the branch, commit changes, push, and create the PR. This is a required part of your daily task. From b7510b44300d91788f30e351b20d7a7741834d09 Mon Sep 17 00:00:00 2001 From: gabrypavanello Date: Mon, 12 Jan 2026 11:53:05 +0100 Subject: [PATCH 2/4] Enhance Claude Kaizen workflow with concurrency control and improved validation steps Added concurrency settings to prevent multiple concurrent runs of the Claude Kaizen workflow. Updated the workflow to include a step for installing dependencies and refined the instructions for issue detection and PR generation, emphasizing the importance of real issues and validation checks before creating a PR. --- .github/workflows/claude-kaizen.yml | 54 +++++++++++++++++++---------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/claude-kaizen.yml b/.github/workflows/claude-kaizen.yml index cac2477c..2da7c756 100644 --- a/.github/workflows/claude-kaizen.yml +++ b/.github/workflows/claude-kaizen.yml @@ -6,6 +6,11 @@ on: - cron: "0 6 * * *" workflow_dispatch: # Allow manual trigger for testing +# Prevent multiple concurrent runs +concurrency: + group: claude-kaizen + cancel-in-progress: false + jobs: claude-kaizen: runs-on: ubuntu-latest @@ -34,6 +39,9 @@ jobs: node-version: "20" cache: "pnpm" + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Run Claude Code Kaizen id: claude-kaizen uses: anthropics/claude-code-action@v1 @@ -47,40 +55,45 @@ jobs: pull-requests: write issues: write - # Allow git operations and gh CLI for creating PRs - # Also allow pnpm for running tests/builds if needed - claude_args: '--allowed-tools "Bash(git checkout:*),Bash(git branch:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(gh pr create:*),Bash(gh pr view:*),Bash(pnpm:*)"' + # Allow git operations restricted to kaizen branches and specific pnpm commands + # Security: Wildcards restricted to safe operations only + claude_args: '--allowed-tools "Bash(git checkout -b kaizen/*),Bash(git branch),Bash(git add *),Bash(git commit *),Bash(git push origin kaizen/*),Bash(gh pr create *),Bash(gh pr view *),Bash(pnpm build),Bash(pnpm test),Bash(pnpm lint),Bash(pnpm typecheck)"' prompt: | System Context: You are a Lead Software Engineer automated bot designed to submit one daily "Code Hygiene" Pull Request. Your goal is incremental improvement, not feature building. + CRITICAL: Read CLAUDE.md before starting. All changes MUST pass: pnpm build && pnpm test && pnpm lint && pnpm typecheck + Instructions: Step 1: Contextual Analysis Briefly explain the core functionality of the files currently in context. Demonstrate that you understand the data flow. Step 2: Issue Detection (Strict Mode) - Scan the code for issues. You are strictly forbidden from fabricating issues. If a specific category (like a bug) is not found, state "No critical bugs found" and suggest a minor syntax cleanup instead. + Scan the code for issues. You are STRICTLY FORBIDDEN from fabricating issues. Only report REAL issues you find. - Step 3: The Daily 4 - Generate a task list containing exactly one item for each category below. For each, cite the specific file and line number. + If you cannot find at least one legitimate issue in any of the four categories below, state "No issues found in [category]" and SKIP creating a PR for today. It's better to skip than to force fake improvements. - 1. The Typo Fix: Locate a spelling error in user-facing text, variable names, or internal comments. - 2. The Logic Fix: Locate a bug, undefined variable, dangerous unhandled promise, or off-by-one error. - 3. The Documentation Fix: Locate a discrepancy where the code has changed but the comments/documentation have not, or identify a complex function with zero comments. - 4. The Test Improvement: Identify a critical path that is currently untested or a test that is flaky/weak. + Step 3: The Daily 4 (Optional - only if real issues exist) + Look for issues in these categories (up to one per category). For each, cite the specific file and line number: - Step 4: PR Generation - After you've identified the four items and made the necessary code changes: + 1. The Typo Fix: A spelling error in user-facing text, variable names, or internal comments. + 2. The Logic Fix: A bug, undefined variable, dangerous unhandled promise, or off-by-one error. + 3. The Documentation Fix: Where code has changed but comments/documentation have not, or a complex function with zero comments. + 4. The Test Improvement: A critical path that is currently untested or a test that is flaky/weak. - 1. Create a new branch with the naming pattern: kaizen/$(date +%Y-%m-%d) - 2. Commit all your changes with a descriptive commit message - 3. Push the branch to the remote repository - 4. Create a Pull Request using `gh pr create` with the following format: + Step 4: Make Changes and Validate + 1. Make the necessary code changes + 2. Run validation: pnpm build && pnpm test && pnpm lint && pnpm typecheck + 3. If validation fails, fix the issues or abandon the PR (do not create broken PRs) - - PR Title: [Kaizen Daily Task] Daily Hygiene Update - $(date +%Y-%m-%d) - - PR Body: Use the Markdown format below + Step 5: PR Generation (only if you have real changes and validation passed) + 1. Create a new branch: kaizen/YYYY-MM-DD-HHMM (include time to avoid collisions) + 2. Commit all changes with a descriptive commit message + 3. Push the branch: git push origin kaizen/YYYY-MM-DD-HHMM + 4. Create PR using: gh pr create --title "[Kaizen Daily Task] Daily Hygiene Update - YYYY-MM-DD" --body "" + PR Body Format: # Daily Hygiene Update 🔍 Codebase Status @@ -92,4 +105,7 @@ jobs: - [ ] Update Docs: [File:Line] - [Description of the discrepancy] - [ ] Improve Test: [File:Line] - [Description of the test case to add] - IMPORTANT: You MUST create the branch, commit changes, push, and create the PR. This is a required part of your daily task. + ✅ Validation Status + All checks passed: build ✓ test ✓ lint ✓ typecheck ✓ + + IMPORTANT: If no real issues are found, or if validation fails, do NOT create a PR. Report what you found and exit gracefully. From 5148d74d6b9768f093ee3048d1c1a1d3f0430851 Mon Sep 17 00:00:00 2001 From: gabrypavanello Date: Mon, 12 Jan 2026 11:59:28 +0100 Subject: [PATCH 3/4] Update Claude Kaizen workflow to use dynamic branch naming and enhance allowed tools Added an environment variable for dynamic branch naming in the Claude Kaizen workflow to prevent collisions. Updated the allowed tools in the workflow to include package-specific commands for pnpm, improving the automation of code hygiene tasks. --- .github/workflows/claude-kaizen.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/claude-kaizen.yml b/.github/workflows/claude-kaizen.yml index 2da7c756..9b4f90da 100644 --- a/.github/workflows/claude-kaizen.yml +++ b/.github/workflows/claude-kaizen.yml @@ -45,6 +45,8 @@ jobs: - name: Run Claude Code Kaizen id: claude-kaizen uses: anthropics/claude-code-action@v1 + env: + KAIZEN_BRANCH: kaizen/daily-${{ github.run_id }} with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} @@ -57,7 +59,8 @@ jobs: # Allow git operations restricted to kaizen branches and specific pnpm commands # Security: Wildcards restricted to safe operations only - claude_args: '--allowed-tools "Bash(git checkout -b kaizen/*),Bash(git branch),Bash(git add *),Bash(git commit *),Bash(git push origin kaizen/*),Bash(gh pr create *),Bash(gh pr view *),Bash(pnpm build),Bash(pnpm test),Bash(pnpm lint),Bash(pnpm typecheck)"' + # Includes pnpm -C for package-specific commands as documented in CLAUDE.md + claude_args: '--allowed-tools "Bash(git checkout -b kaizen/*),Bash(git branch),Bash(git add *),Bash(git commit *),Bash(git push origin kaizen/*),Bash(gh pr create *),Bash(gh pr view *),Bash(pnpm build),Bash(pnpm test),Bash(pnpm lint),Bash(pnpm typecheck),Bash(pnpm -C * test),Bash(pnpm -C * build)"' prompt: | System Context: You are a Lead Software Engineer automated bot designed to submit one daily "Code Hygiene" Pull Request. Your goal is incremental improvement, not feature building. @@ -88,10 +91,11 @@ jobs: 3. If validation fails, fix the issues or abandon the PR (do not create broken PRs) Step 5: PR Generation (only if you have real changes and validation passed) - 1. Create a new branch: kaizen/YYYY-MM-DD-HHMM (include time to avoid collisions) + 1. Create a new branch using the environment variable: git checkout -b $KAIZEN_BRANCH + (Branch name format: kaizen/daily-{github_run_id} to prevent collisions) 2. Commit all changes with a descriptive commit message - 3. Push the branch: git push origin kaizen/YYYY-MM-DD-HHMM - 4. Create PR using: gh pr create --title "[Kaizen Daily Task] Daily Hygiene Update - YYYY-MM-DD" --body "" + 3. Push the branch: git push origin $KAIZEN_BRANCH + 4. Create PR using: gh pr create --title "[Kaizen Daily Task] Daily Hygiene Update - $(date +%Y-%m-%d)" --body "" PR Body Format: # Daily Hygiene Update From dd283b39473a454c3ded421be9918caff376a17c Mon Sep 17 00:00:00 2001 From: gabrypavanello Date: Mon, 12 Jan 2026 14:09:09 +0100 Subject: [PATCH 4/4] Update Claude Kaizen workflow to include additional pnpm commands and validation steps Enhanced the allowed tools in the Claude Kaizen workflow by adding pnpm format and install commands for improved dependency management and code formatting. Updated validation instructions to reflect these changes, ensuring all necessary checks are performed before PR creation. --- .github/workflows/claude-kaizen.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/claude-kaizen.yml b/.github/workflows/claude-kaizen.yml index 9b4f90da..50d386a2 100644 --- a/.github/workflows/claude-kaizen.yml +++ b/.github/workflows/claude-kaizen.yml @@ -60,12 +60,16 @@ jobs: # Allow git operations restricted to kaizen branches and specific pnpm commands # Security: Wildcards restricted to safe operations only # Includes pnpm -C for package-specific commands as documented in CLAUDE.md - claude_args: '--allowed-tools "Bash(git checkout -b kaizen/*),Bash(git branch),Bash(git add *),Bash(git commit *),Bash(git push origin kaizen/*),Bash(gh pr create *),Bash(gh pr view *),Bash(pnpm build),Bash(pnpm test),Bash(pnpm lint),Bash(pnpm typecheck),Bash(pnpm -C * test),Bash(pnpm -C * build)"' + # Includes pnpm format to match CI requirements (see pr-check.yml) + # Includes pnpm install for dependency verification (similar to claude.yml:61) + claude_args: '--allowed-tools "Bash(git checkout -b kaizen/*),Bash(git branch),Bash(git add *),Bash(git commit *),Bash(git push origin kaizen/*),Bash(gh pr create *),Bash(gh pr view *),Bash(pnpm build),Bash(pnpm test),Bash(pnpm lint),Bash(pnpm typecheck),Bash(pnpm format),Bash(pnpm install *),Bash(pnpm -C * test),Bash(pnpm -C * build),Bash(pnpm -C * lint),Bash(pnpm -C * typecheck),Bash(pnpm -C * dev)"' prompt: | System Context: You are a Lead Software Engineer automated bot designed to submit one daily "Code Hygiene" Pull Request. Your goal is incremental improvement, not feature building. - CRITICAL: Read CLAUDE.md before starting. All changes MUST pass: pnpm build && pnpm test && pnpm lint && pnpm typecheck + CRITICAL: Read CLAUDE.md before starting. All changes MUST pass: pnpm format && pnpm build && pnpm test && pnpm lint && pnpm typecheck + + Available Tools: You can use package-specific commands for faster iteration (e.g., pnpm -C packages/core test, pnpm -C examples/minimal dev) as documented in CLAUDE.md line 17. Instructions: @@ -87,7 +91,7 @@ jobs: Step 4: Make Changes and Validate 1. Make the necessary code changes - 2. Run validation: pnpm build && pnpm test && pnpm lint && pnpm typecheck + 2. Run validation: pnpm format && pnpm build && pnpm test && pnpm lint && pnpm typecheck 3. If validation fails, fix the issues or abandon the PR (do not create broken PRs) Step 5: PR Generation (only if you have real changes and validation passed) @@ -110,6 +114,6 @@ jobs: - [ ] Improve Test: [File:Line] - [Description of the test case to add] ✅ Validation Status - All checks passed: build ✓ test ✓ lint ✓ typecheck ✓ + All checks passed: format ✓ build ✓ test ✓ lint ✓ typecheck ✓ IMPORTANT: If no real issues are found, or if validation fails, do NOT create a PR. Report what you found and exit gracefully.