Workflow
1. Scope Definition
When invoked, ask the user:
What to review:
- Branch vs branch (e.g.,
feature-branch against master)
- Commit vs commit/branch (e.g.,
abc123 against HEAD)
- Specific files or directories
Review mode: Is this your own PR (self-review) or someone else's PR?
- Self-review: I will offer to apply fixes as we find them
- Someone else's PR: I will collect all findings and offer to export/push to GitHub at the end
Collect the diff using git diff with function context (--function-context).
2. Context Expansion
During review, if a code chunk lacks sufficient context to evaluate properly, ask the user for permission to read the full file. Examples of when context expansion is needed:
- Understanding class invariants or preconditions
- Checking function signatures not shown in the diff
- Verifying include/dependency relationships
- Understanding the full implementation of modified functions
- Checking for existing patterns that should be followed
Ask the user: "I need to see more context in file.cpp to properly evaluate this change. May I read the full file?"
Proceed based on user response:
- If yes: Read the file and continue review with expanded context
- If no: Note the limitation and continue with available context, or skip the ambiguous section
3. Verification with clangd
Use clangd-18 to verify code correctness:
- Run from project root:
clangd-18 --check=<path/to/file.cpp>
- This picks up
.clangd config automatically (which includes the compilation database location)
- Use to verify: includes are correct, standard library features are available, missing dependencies
- When unsure about C++ includes or standard library usage, check with clangd before commenting
4. Review Loop
For each logical chunk of changes:
- Analyze the code against the rules below
- Important: Only review code that was actually modified by the author (present in the diff)
- Do not flag issues in pre-existing, untouched code unless it directly relates to the changes being made
- If you need to reference unchanged code for context, clearly distinguish it from the actual changes
- Present findings wrapped in
<findings> tags with:
- File location and line numbers
- Severity:
suggestion, nit, or issue
- Clear explanation of the concern
- Proposed alternative when applicable
- Ask the user for feedback on your thoughts
- Adapt based on user responses (skip similar issues if asked, dive deeper if requested)
For large changes, feel free to use light humor occasionally to keep the review relaxed and enjoyable for the reviewer.
5. External PR Review Mode
When reviewing someone else's PR (as determined in Step 1):
- Collect all findings during the review without offering to apply fixes
- Present findings as structured comments for later export
- At completion, offer to:
6. Completion
Summarize all findings and ask based on review mode:
For self-review:
- Apply any automated fixes
- Continue reviewing other changes
For external PR review:
- Export findings to a file
- Push review comments to GitHub PR
Review Rules
General Principles
Act like a senior developer who prioritizes:
| Priority |
Principle |
| 1 |
Readability - Clear naming, early returns, explicit error handling, meaningful comments |
| 2 |
Standard mechanisms - Prefer C++ standard library over custom solutions |
| 3 |
Reusability - Non-PHP-specific code should be written in a PHP-agnostic way |
| 4 |
C++ best practices - RAII, proper include hygiene (no transitive/missing includes), namespaces, fully qualified identifiers |
| 5 |
Consistency - Follow existing patterns in the codebase; note when a diff introduces pattern changes |
Component-Specific Rules
Compiler (/compiler/)
- C++17 standard
- Follow existing AST transformation patterns
All Runtimes (/runtime-common/, /runtime/, /runtime-light/)
- All functions should be marked
noexcept without any considerations
- PHP function naming: All PHP standard library functions must use the
f$ prefix (e.g., f$array_merge)
Common Runtime (/runtime-common/)
- C++17 standard
- Thread-safe: All code must be safe for concurrent execution
- No resource ownership: Code must not directly own system resources (files, sockets, malloc memory)
Legacy Runtime (/runtime/)
K2 Runtime (/runtime-light/)
- C++23 standard
- Thread-safe: All code must be safe for concurrent execution
- No resource ownership: Code must not directly own system resources; request them through the
k2:: interface instead
- Fork-aware coroutines: When calling a coroutine, wrap the call with
kphp::forks::id_managed unless the coroutine is a KPHP standard library function (prefixed with f$), which already handles this internally
- Braced initialization: Always use braced initialization (e.g.,
T obj{};) unless parentheses are semantically required (e.g., std::vector<int> v(10, 0); for size/value construction)
- Log messages: Log messages should start with a lowercase letter
- Type naming: Types should begin with a lowercase letter (e.g.,
task, component, buffer). Exception: *State types (e.g., InstanceState, ConfdataImageState, RpcServerInstanceState) are currently permitted (this exception is temporary)
- KPHP types in ImageState/ComponentState: KPHP types (
array, string, mixed, class_instance) that are members of *ImageState or *ComponentState types must set their reference counter to ExtraRefCnt::ForGlobalConst to prevent data races. Prefer kphp::core::set_reference_counter_recursive over obj.set_reference_counter_to
Output Format
Use this structure for findings:
<findings>
### File: `path/to/file.cpp` (lines 45-52)
**Severity:** suggestion
**Issue:** Brief description of the concern
**Rationale:** Why this matters (referencing specific rules above)
**Suggestion:** Concrete alternative or fix
</findings>
Severity levels:
issue - Likely bug or violation of hard requirements (thread-safety, resource ownership)
suggestion - Improvement to readability, maintainability, or adherence to best practices
nit - Minor stylistic preference, optional to address
1---2name: review-interactive3description: Review code changes in the KPHP compiler and runtime codebase interactively4---56# Workflow78## 1. Scope Definition910When invoked, ask the user:11121. **What to review:**13 - Branch vs branch (e.g., `feature-branch` against `master`)14 - Commit vs commit/branch (e.g., `abc123` against `HEAD`)15 - Specific files or directories16172. **Review mode:** Is this your own PR (self-review) or someone else's PR?18 - **Self-review:** I will offer to apply fixes as we find them19 - **Someone else's PR:** I will collect all findings and offer to export/push to GitHub at the end2021Collect the diff using `git diff` with function context (`--function-context`).2223## 2. Context Expansion2425During review, if a code chunk lacks sufficient context to evaluate properly, ask the user for permission to read the full file. Examples of when context expansion is needed:26- Understanding class invariants or preconditions27- Checking function signatures not shown in the diff28- Verifying include/dependency relationships29- Understanding the full implementation of modified functions30- Checking for existing patterns that should be followed3132Ask the user: "I need to see more context in `file.cpp` to properly evaluate this change. May I read the full file?"3334Proceed based on user response:35- If **yes**: Read the file and continue review with expanded context36- If **no**: Note the limitation and continue with available context, or skip the ambiguous section3738## 3. Verification with clangd3940Use `clangd-18` to verify code correctness:41- Run from project root: `clangd-18 --check=<path/to/file.cpp>`42- This picks up `.clangd` config automatically (which includes the compilation database location)43- Use to verify: includes are correct, standard library features are available, missing dependencies44- When unsure about C++ includes or standard library usage, check with clangd before commenting4546## 4. Review Loop4748For each logical chunk of changes:49501. **Analyze** the code against the rules below51 - **Important:** Only review code that was actually modified by the author (present in the diff)52 - Do not flag issues in pre-existing, untouched code unless it directly relates to the changes being made53 - If you need to reference unchanged code for context, clearly distinguish it from the actual changes542. **Present** findings wrapped in `<findings>` tags with:55 - File location and line numbers56 - Severity: `suggestion`, `nit`, or `issue`57 - Clear explanation of the concern58 - Proposed alternative when applicable593. **Ask** the user for feedback on your thoughts604. **Adapt** based on user responses (skip similar issues if asked, dive deeper if requested)6162For large changes, feel free to use light humor occasionally to keep the review relaxed and enjoyable for the reviewer.6364## 5. External PR Review Mode6566When reviewing someone else's PR (as determined in Step 1):67681. **Collect all findings** during the review without offering to apply fixes692. Present findings as structured comments for later export703. **At completion**, offer to:71 - **Export to file**: Create a markdown file with all findings72 - **Push to GitHub**: Use `gh` CLI to post review comments to the PR:73 ```bash74 # For each finding, create a review comment75 gh pr review <PR-number> --comment --body "comment text" -- <file>7677 # Or create a single review with all comments78 gh pr review <PR-number> --request-changes --body-file review-comments.md79 ```8081## 6. Completion8283Summarize all findings and ask based on review mode:8485**For self-review:**86- Apply any automated fixes87- Continue reviewing other changes8889**For external PR review:**90- Export findings to a file91- Push review comments to GitHub PR9293---9495# Review Rules9697## General Principles9899Act like a senior developer who prioritizes:100101| Priority | Principle |102|----------|-----------|103| 1 | **Readability** - Clear naming, early returns, explicit error handling, meaningful comments |104| 2 | **Standard mechanisms** - Prefer C++ standard library over custom solutions |105| 3 | **Reusability** - Non-PHP-specific code should be written in a PHP-agnostic way |106| 4 | **C++ best practices** - RAII, proper include hygiene (no transitive/missing includes), namespaces, fully qualified identifiers |107| 5 | **Consistency** - Follow existing patterns in the codebase; note when a diff introduces pattern changes |108109## Component-Specific Rules110111### Compiler (`/compiler/`)112113- C++17 standard114- Follow existing AST transformation patterns115116### All Runtimes (`/runtime-common/`, `/runtime/`, `/runtime-light/`)117118- All functions should be marked `noexcept` without any considerations119- **PHP function naming**: All PHP standard library functions must use the `f$` prefix (e.g., `f$array_merge`)120121### Common Runtime (`/runtime-common/`)122123- C++17 standard124- **Thread-safe**: All code must be safe for concurrent execution125- **No resource ownership**: Code must not directly own system resources (files, sockets, malloc memory)126127### Legacy Runtime (`/runtime/`)128129- C++17 standard130131### K2 Runtime (`/runtime-light/`)132133- C++23 standard134- **Thread-safe**: All code must be safe for concurrent execution135- **No resource ownership**: Code must not directly own system resources; request them through the `k2::` interface instead136- **Fork-aware coroutines**: When calling a coroutine, wrap the call with `kphp::forks::id_managed` unless the coroutine is a KPHP standard library function (prefixed with `f$`), which already handles this internally137- **Braced initialization**: Always use braced initialization (e.g., `T obj{};`) unless parentheses are semantically required (e.g., `std::vector<int> v(10, 0);` for size/value construction)138- **Log messages**: Log messages should start with a lowercase letter139- **Type naming**: Types should begin with a lowercase letter (e.g., `task`, `component`, `buffer`). Exception: `*State` types (e.g., `InstanceState`, `ConfdataImageState`, `RpcServerInstanceState`) are currently permitted (this exception is temporary)140- **KPHP types in ImageState/ComponentState**: KPHP types (`array`, `string`, `mixed`, `class_instance`) that are members of `*ImageState` or `*ComponentState` types must set their reference counter to `ExtraRefCnt::ForGlobalConst` to prevent data races. Prefer `kphp::core::set_reference_counter_recursive` over `obj.set_reference_counter_to`141142---143144# Output Format145146Use this structure for findings:147148```149<findings>150### File: `path/to/file.cpp` (lines 45-52)151**Severity:** suggestion152153**Issue:** Brief description of the concern154155**Rationale:** Why this matters (referencing specific rules above)156157**Suggestion:** Concrete alternative or fix158</findings>159```160161Severity levels:162- `issue` - Likely bug or violation of hard requirements (thread-safety, resource ownership)163- `suggestion` - Improvement to readability, maintainability, or adherence to best practices164- `nit` - Minor stylistic preference, optional to address