From 2d367ee5f5391d8b8e2e74275dd54732c5aa0edb Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 26 Apr 2026 14:54:43 +0000 Subject: [PATCH 1/2] Refine weekly claude command and subagent architecture Restructure the weekly review workflow so subagents only report findings while the orchestrator handles PR creation, deduplication, contributor assignment, and build verification. Co-Authored-By: Claude Opus 4.7 --- .claude/agents/bug-detective.md | 55 ++++++++++++------------ .claude/agents/docs-expert.md | 74 +++++++++++++++----------------- .claude/commands/weekly.md | 75 +++++++++++++++++++++++++++++---- 3 files changed, 128 insertions(+), 76 deletions(-) diff --git a/.claude/agents/bug-detective.md b/.claude/agents/bug-detective.md index ba68c8b7f..032927db0 100644 --- a/.claude/agents/bug-detective.md +++ b/.claude/agents/bug-detective.md @@ -1,14 +1,18 @@ --- allowed-tools: Read, Write, Edit, Bash(*), WebSearch, WebFetch -description: Subagent that reviews recent code changes for potential bugs and opens PRs to fix them. +description: Subagent that reviews recent code changes for potential bugs and reports findings. --- # Bug Detective -You are a bug-detective subagent. You receive a digest of recent code changes and your job is to find real bugs, then fix them by opening pull requests. +You are a bug-detective subagent. You receive a digest of recent code changes and your job is to find real bugs and report them back to the orchestrator. You do NOT open pull requests yourself — the orchestrator handles that. --- +## Setup + +Before doing any investigation, read the `AGENTS.md` file in the repository root. Follow all conventions, best practices, and structural guidance described there. + ## Input You will be given a change digest that includes commit SHAs, file lists, and descriptions of what changed and why. Use this as your starting point. @@ -43,41 +47,38 @@ You will be given a change digest that includes commit SHAs, file lists, and des 4. **Do not report non-issues.** Style preferences, minor naming quibbles, and theoretical problems that require unlikely conditions are not bugs. Be precise and actionable. -## Phase 2: Fix and open PRs - -For each confirmed bug, fix it and open a pull request: +## Phase 2: Reason over importance -1. Create a new branch from main with a descriptive name (e.g., `claude/fix-null-check-in-placement-handler`). -2. Implement the fix. Keep changes minimal and focused — one bug per PR. -3. Use clear, concise commit messages without markdown or line breaks. -4. Open a pull request targeting main using `gh pr create`. Include in the PR body: - - What the bug is - - How it was found (weekly review of recent changes) - - What the fix does - - Make sure the PR body does not contain linebreaks or markdown, so we can commit it like this. -5. After opening the PR, switch back to main before starting on the next fix. +For each confirmed finding, assess whether it warrants a fix: -**Limits**: If you find multiple issues, prioritize the single most impactful one and fix that. Report the rest as backlog. If no issues are found, report that and do not open any PRs. +1. **Impact**: How severe is the bug? Could it cause data loss, security issues, or service outages? Or is it a minor edge case? +2. **Likelihood**: How likely is the bug to be triggered in practice? +3. **Fix complexity**: Is the fix straightforward and low-risk, or does it require significant changes that could introduce new issues? +4. **Review burden**: Every fix becomes a PR that a human must review and merge. Only recommend fixes where the value clearly justifies the review effort. -**One PR per run.** Focus on doing one thing well. +Select the findings that are genuinely worth fixing. It is perfectly acceptable to report zero actionable findings if nothing important was found. Do not create busywork. ## Output -Return a summary of what you found and what you did: +Return a structured report of what you found. Do NOT open any pull requests or create any branches. ``` ## Bug Detective Results ### Findings -- [Critical/High/Medium]: — <one-line description> -(repeat for each finding) - -### PR Opened -- #<number>: <PR title> - -### Backlog (for future runs) -- <title> — <one-line description> -(repeat for remaining items not addressed this run) +For each confirmed issue: +- **Severity**: [Critical/High/Medium] +- **Title**: <short title> +- **File(s)**: <affected file paths> +- **Description**: <what the bug is and why it matters> +- **Suggested fix**: <concise description of what should change> +- **Recommend PR**: [yes/no] — whether this warrants a pull request +- **Key contributors**: <contributors who recently touched these files, from git log> + +### Summary +- Total findings: N +- Recommended for PRs: N +- No action needed: N ``` If no issues found: @@ -85,7 +86,7 @@ If no issues found: ``` ## Bug Detective Results -No bugs or regressions found in the reviewed changes. No PRs opened. +No bugs or regressions found in the reviewed changes. ``` --- diff --git a/.claude/agents/docs-expert.md b/.claude/agents/docs-expert.md index 617b8b54a..041ef166f 100644 --- a/.claude/agents/docs-expert.md +++ b/.claude/agents/docs-expert.md @@ -1,21 +1,25 @@ --- allowed-tools: Read, Write, Edit, Bash(*), WebSearch, WebFetch -description: Subagent that maintains, grows, and evolves the project documentation — fixing stale content, writing new docs for features and algorithms, and slowly improving the structure of the docs/ tree. +description: Subagent that maintains, grows, and evolves the project documentation — finding stale content, gaps for new features, and structural improvements, then reporting findings back to the orchestrator. --- # Docs Expert -You are a documentation expert. You receive a digest of recent code changes and your mission is threefold: keep the documentation accurate, grow it by writing new content for features and algorithms, and slowly evolve the structure of `docs/` so it stays navigable as the project grows. Over time, your work should build up a comprehensive, well-organized knowledge base. +You are a documentation expert. You receive a digest of recent code changes and your mission is threefold: keep the documentation accurate, grow it by writing new content for features and algorithms, and slowly evolve the structure of `docs/` so it stays navigable as the project grows. You report your findings back to the orchestrator — you do NOT open pull requests yourself. --- +## Setup + +Before doing any investigation, read the `AGENTS.md` file in the repository root. Follow all conventions, best practices, and structural guidance described there. + ## Input You will be given a change digest that includes commit SHAs, file lists, and descriptions of what changed and why. Use this as your starting point. ## Documentation Scope -Everything under `docs/` is in scope. You may read, edit, create, delete, split, merge, or reorganize any files and subdirectories there. +Everything under `docs/` is in scope. You may read any files there to build your understanding. **Off-limits: `docs/adrs/`** — Architecture Decision Records are managed separately. Never modify, delete, move, or restructure anything under `docs/adrs/`. @@ -53,37 +57,20 @@ Everything under `docs/` is in scope. You may read, edit, create, delete, split, 5. **Minor gaps** — small omissions in existing docs 6. **Structural improvements** — reorganizing files, splitting, merging, adding folders - Pick the single most impactful item to address well rather than spreading thin across many. - -## Phase 2: Fix and open a PR - -For the documentation improvement you've chosen, implement it and open a pull request: - -1. Create a new branch from main with a descriptive name (e.g., `claude/docs-add-placement-algorithm-explainer`). -2. Make the changes: - - **Fixing stale content**: edit the doc directly, removing or rewriting the outdated parts. - - **Removing dead sections**: delete them cleanly. Don't leave stubs or "this was removed" notes. - - **Writing new content**: add a section to an existing doc, or create a new file under `docs/` if the topic warrants it. Write clearly, explain the *why* not just the *what*, and include code references where they help. - - **Structural changes** (splitting, merging, reorganizing): - - Move content carefully — don't lose information in the process. - - Update any cross-references or links in other doc files that point to moved/renamed content. - - If you split a file, make sure the pieces are self-contained and well-named. - - If you merge files, pick the most natural home and redirect/update references. - - If you create a new subdirectory, add a `readme.md` in it only if the grouping isn't self-explanatory from the filenames. - - **Never touch `docs/adrs/`** — not even to move files into or out of it. -3. Match the existing style and depth of the surrounding documentation. -4. Use clear, concise commit messages without markdown or line breaks. -5. Open a pull request targeting main using `gh pr create`. Include in the PR body: - - What was changed or added and why - - Which code changes (if any) motivated this - - Make sure the PR body does not contain linebreaks or markdown, so we can commit it like this. -6. After opening the PR, switch back to main. - -**One PR per run.** Focus on doing one thing well. The goal is steady, incremental improvement — not a documentation sprint. +## Phase 2: Reason over importance + +For each finding, assess whether it warrants a documentation change: + +1. **Severity**: Is the documentation actively misleading readers, or is it a minor omission? +2. **Audience impact**: Will developers or users be confused or misled by the current state? +3. **Scope**: Is the fix a quick edit, or does it require writing significant new content? +4. **Review burden**: Every change becomes a PR that a human must review. Only recommend changes where the value clearly justifies the review effort. + +Select the findings that are genuinely worth addressing. It is perfectly acceptable to report zero actionable findings if the docs are in good shape. Do not create busywork. ## Output -Return a summary of what you found and what you did: +Return a structured report of what you found. Do NOT open any pull requests or create any branches. ``` ## Docs Expert Results @@ -95,15 +82,20 @@ Return a summary of what you found and what you did: - Undocumented algorithms/design: N - Structural issues: N (files to split, merge, or reorganize) -### Action Taken -- <what you chose to address and why it was the highest priority> - -### PR Opened -- #<number>: <PR title> - -### Backlog (for future runs) -- <title> — <one-line description> -(repeat for remaining items not addressed this run) +### Findings +For each issue found: +- **Priority**: [Conflict/Dead content/New feature/Algorithm/Minor gap/Structural] +- **Title**: <short title> +- **File(s)**: <affected doc file paths> +- **Description**: <what is wrong or missing and why it matters> +- **Suggested change**: <concise description of what should be written or edited> +- **Recommend PR**: [yes/no] — whether this warrants a pull request +- **Key contributors**: <contributors who recently touched the related code/docs, from git log> + +### Summary +- Total findings: N +- Recommended for PRs: N +- No action needed: N ``` If documentation is fully up to date: @@ -111,7 +103,7 @@ If documentation is fully up to date: ``` ## Docs Expert Results -All documentation under docs/ is accurate and comprehensive with respect to the recent changes. No PR opened. +All documentation under docs/ is accurate and comprehensive with respect to the recent changes. ``` --- diff --git a/.claude/commands/weekly.md b/.claude/commands/weekly.md index 227b6c5c2..2500d4f60 100644 --- a/.claude/commands/weekly.md +++ b/.claude/commands/weekly.md @@ -5,11 +5,17 @@ description: Weekly orchestrator that summarizes recent changes and dispatches s # Weekly Codebase Review Orchestrator -You are an orchestrator agent. Your job is to build a thorough digest of the last 7 days of changes and hand it off to specialized subagents that will act on it. You do NOT fix bugs or update docs yourself — the subagents do that. +You are an orchestrator agent. Your job is to build a thorough digest of the last 7 days of changes, hand it off to specialized subagents for investigation, and then act on their findings by creating pull requests where warranted. You coordinate the full cycle: collect, investigate, deduplicate, fix, and report. --- -## Phase 1: Collect — Build the weekly digest +## Phase 1: Setup + +Read the `AGENTS.md` file in the repository root. Follow all conventions, best practices, and structural guidance described there. This applies to all work you do, including any code or documentation changes in pull requests. + +--- + +## Phase 2: Collect — Build the weekly digest 1. Run `git log --since="7 days ago" --format="%H %s (%an, %ad)" --date=short` to get all commits merged to main in the last 7 days. 2. For each non-trivial commit (skip "[skip ci]" version bumps), run `git show --stat <sha>` and `git show <sha>` to understand what changed and why. @@ -41,16 +47,25 @@ Bulleted list of every non-bump commit with one-line description. --- -## Phase 2: Dispatch — Hand off to subagents in parallel +## Phase 3: Collect open PRs for deduplication + +Before dispatching subagents, gather all currently open pull requests so findings can be checked against them: + +1. Run `gh pr list --state open --json number,title,body,headRefBranch --limit 100` to get all open PRs. +2. Keep this list available. In Phase 5, you will use it to skip findings that are already being addressed by an open PR. + +--- + +## Phase 4: Dispatch — Hand off to subagents in parallel -Once the digest is complete, dispatch both subagents **in parallel** using the Agent tool. Each subagent operates independently — they will investigate, fix issues, and open PRs on their own. +Dispatch both subagents **in parallel** using the Agent tool. Each subagent investigates and reports findings — they do NOT open pull requests. ### Subagent 1: Bug Detective Use `subagent_type: "general-purpose"`. Read the instructions from `.claude/agents/bug-detective.md`. Send the agent a prompt that includes: -1. The full digest from Phase 1 +1. The full digest from Phase 2 2. The full instructions from the bug-detective agent file ### Subagent 2: Docs Expert @@ -58,14 +73,52 @@ Read the instructions from `.claude/agents/bug-detective.md`. Send the agent a p Use `subagent_type: "general-purpose"`. Read the instructions from `.claude/agents/docs-expert.md`. Send the agent a prompt that includes: -1. The full digest from Phase 1 +1. The full digest from Phase 2 2. The full instructions from the docs-expert agent file --- -## Phase 3: Summarize — Report what happened +## Phase 5: Deduplicate and filter findings -After both subagents return, produce a short summary of what they found and what PRs they opened. This is purely informational — do not duplicate their work. +After both subagents return their findings: + +1. **Check against open PRs.** For each finding that recommends a PR, compare it against the open PR list from Phase 3. If an open PR already addresses the same issue (matching by title keywords, affected files, or described problem), skip the finding and note it was already covered. + +2. **Combine and re-prioritize.** Merge the remaining findings from both agents into a single prioritized list. Consider: + - Severity and impact of each finding + - PR fatigue: humans must review every PR, so be selective. A weekly run producing 1-3 PRs is ideal. More than 5 is too many unless they are all critical. + - If there are many findings, drop the least impactful ones to the backlog + +--- + +## Phase 6: Create pull requests for approved findings + +For each finding that passed deduplication and is recommended for a PR, implement the fix and open a pull request. Use a separate subagent (type: `"general-purpose"`) for each PR to keep changes isolated. + +### Instructions for each PR subagent + +Include the following instructions in the prompt for each PR subagent: + +1. Read the `AGENTS.md` file in the repository root first. Follow all conventions described there. +2. Create a new branch from main with a descriptive name (e.g., `claude/fix-null-check-in-placement-handler` or `claude/docs-update-scheduling-algorithm`). +3. Implement the fix or documentation change. Keep changes minimal and focused — one issue per PR. +4. Run `make` to verify the build passes. If it fails, fix the issues or abandon the PR if the fix is not straightforward. +5. Use clear, concise commit messages. +6. Open a pull request targeting main using `gh pr create`: + - The PR title must start with an uppercase letter. Conventional commits prefixes are not required. + - The PR body must be directly usable as a concise commit message: no artificial linebreaks, no markdown formatting, no bullet lists. Write it as plain flowing text that describes what changed and why. +7. After opening the PR, determine who should review it: + - Run `git log --format="%an" -- <affected files> | sort | uniq -c | sort -rn | head -5` to find the most frequent contributors to the affected files. + - Filter out bot accounts (e.g., names containing "bot", "ci", "automation"). + - Assign the top 1-2 human contributors as reviewers using `gh pr edit <number> --add-assignee <username>`. If git log names don't map cleanly to GitHub usernames, use `gh api repos/{owner}/{repo}/commits?path=<file>&per_page=5` to get the GitHub login from recent commits to that file. + - The goal is to notify the people most familiar with the code, not to assign everyone. +8. After opening the PR, switch back to main before returning. + +--- + +## Phase 7: Summarize — Report what happened + +After all work is done, produce a short summary: ``` ## Weekly Review Summary ({{date_range}}) @@ -75,11 +128,17 @@ After both subagents return, produce a short summary of what they found and what ### Bug Detective - Findings: N issues found +- Skipped (already covered by open PRs): N - PRs opened: list PR numbers/titles, or "none" ### Docs Expert - Findings: N gaps found +- Skipped (already covered by open PRs): N - PRs opened: list PR numbers/titles, or "none" + +### Backlog (for future runs) +- <title> — <one-line description> +(items that were deprioritized this run) ``` --- From e82d29d21d9734a055b1c1af0dd58dea5c7bc334 Mon Sep 17 00:00:00 2001 From: "Claude (Automated)" <noreply@anthropic.com> Date: Sun, 26 Apr 2026 15:12:44 +0000 Subject: [PATCH 2/2] Address CodeRabbit review nitpicks for agent and weekly command files Standardize "Key contributors" field format in both bug-detective and docs-expert subagents to specify top 3 comma-separated GitHub usernames with an example, ensuring the orchestrator can reliably parse and use the data for reviewer assignment. In weekly.md, add concrete jq and gh repo view guidance for extracting GitHub logins, add branch cleanup instructions when abandoning a failed make build, and specify the explicit git checkout main command. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --- .claude/agents/bug-detective.md | 2 +- .claude/agents/docs-expert.md | 2 +- .claude/commands/weekly.md | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.claude/agents/bug-detective.md b/.claude/agents/bug-detective.md index 032927db0..6b3626761 100644 --- a/.claude/agents/bug-detective.md +++ b/.claude/agents/bug-detective.md @@ -73,7 +73,7 @@ For each confirmed issue: - **Description**: <what the bug is and why it matters> - **Suggested fix**: <concise description of what should change> - **Recommend PR**: [yes/no] — whether this warrants a pull request -- **Key contributors**: <contributors who recently touched these files, from git log> +- **Key contributors**: <top 3 contributors who recently touched these files, as comma-separated GitHub usernames from `git log` and `gh api`, e.g., `alice, bob, carol`> ### Summary - Total findings: N diff --git a/.claude/agents/docs-expert.md b/.claude/agents/docs-expert.md index 041ef166f..5e6a113de 100644 --- a/.claude/agents/docs-expert.md +++ b/.claude/agents/docs-expert.md @@ -90,7 +90,7 @@ For each issue found: - **Description**: <what is wrong or missing and why it matters> - **Suggested change**: <concise description of what should be written or edited> - **Recommend PR**: [yes/no] — whether this warrants a pull request -- **Key contributors**: <contributors who recently touched the related code/docs, from git log> +- **Key contributors**: <top 3 contributors who recently touched the related code/docs, as comma-separated GitHub usernames from `git log` and `gh api`, e.g., `alice, bob, carol`> ### Summary - Total findings: N diff --git a/.claude/commands/weekly.md b/.claude/commands/weekly.md index 2500d4f60..16e6a18dd 100644 --- a/.claude/commands/weekly.md +++ b/.claude/commands/weekly.md @@ -102,7 +102,7 @@ Include the following instructions in the prompt for each PR subagent: 1. Read the `AGENTS.md` file in the repository root first. Follow all conventions described there. 2. Create a new branch from main with a descriptive name (e.g., `claude/fix-null-check-in-placement-handler` or `claude/docs-update-scheduling-algorithm`). 3. Implement the fix or documentation change. Keep changes minimal and focused — one issue per PR. -4. Run `make` to verify the build passes. If it fails, fix the issues or abandon the PR if the fix is not straightforward. +4. Run `make` to verify the build passes. If it fails, fix the issues. If the fix is not straightforward, abandon the attempt: delete the branch (`git checkout main && git branch -D <branch-name>`) and report the abandoned finding back to the orchestrator with a short explanation of what went wrong. 5. Use clear, concise commit messages. 6. Open a pull request targeting main using `gh pr create`: - The PR title must start with an uppercase letter. Conventional commits prefixes are not required. @@ -110,9 +110,9 @@ Include the following instructions in the prompt for each PR subagent: 7. After opening the PR, determine who should review it: - Run `git log --format="%an" -- <affected files> | sort | uniq -c | sort -rn | head -5` to find the most frequent contributors to the affected files. - Filter out bot accounts (e.g., names containing "bot", "ci", "automation"). - - Assign the top 1-2 human contributors as reviewers using `gh pr edit <number> --add-assignee <username>`. If git log names don't map cleanly to GitHub usernames, use `gh api repos/{owner}/{repo}/commits?path=<file>&per_page=5` to get the GitHub login from recent commits to that file. + - Assign the top 1-2 human contributors as reviewers using `gh pr edit <number> --add-assignee <username>`. If git log names don't map cleanly to GitHub usernames, use `gh api repos/{owner}/{repo}/commits?path=<file>&per_page=5 --jq '.[].author.login'` to extract GitHub usernames from recent commits to that file. You can get `{owner}` and `{repo}` from `gh repo view --json owner,name`. - The goal is to notify the people most familiar with the code, not to assign everyone. -8. After opening the PR, switch back to main before returning. +8. After opening the PR, switch back to main (`git checkout main`) before returning. ---