From ab45bea41a9b21759e912804a93649afd6887432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 20 Oct 2025 11:02:28 +0200 Subject: [PATCH 1/4] add big files chunking instructions --- .claude/agents/code-inline-reviewer.md | 43 +++++++++++++++++------ .claude/agents/helpdot-inline-reviewer.md | 15 ++++++-- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.claude/agents/code-inline-reviewer.md b/.claude/agents/code-inline-reviewer.md index 90b53663251a..c97976267cff 100644 --- a/.claude/agents/code-inline-reviewer.md +++ b/.claude/agents/code-inline-reviewer.md @@ -220,24 +220,47 @@ const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => { ## Instructions -1. **Read each changed file carefully** using the Read tool -2. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool -3. **Required parameters for each inline comment:** +1. **First, get the list of changed files and their diffs:** + - Use `gh pr diff` to see what actually changed in the PR + - Focus ONLY on the changed lines, not the entire file + +2. **For analyzing changed files:** + - **For large files (>5000 lines):** Use the Grep tool to search for specific violation patterns instead of reading the entire file. Focus grep searches on the changed portions shown in the diff. + - **For smaller files:** You may read the full file using the Read tool + - **If a Read fails with token limit error:** Immediately switch to using Grep with targeted patterns for the rules you're checking + +3. **Search strategy for large files:** + - PERF-1: Search for `renderItem` and `...` patterns in the same vicinity + - PERF-2: Search for `.every(`, `.some(`, `.find(`, `.filter(` patterns + - PERF-3: Search for `useOnyx` within components used in `renderItem` + - PERF-4: Search for `useMemo`, `useCallback`, and prop passing patterns + - PERF-5: Search for `React.memo` and `deepEqual` patterns + - PERF-6: Search for `useEffect`, `useMemo`, `useCallback` dependency arrays + +4. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool + +5. **Required parameters for each inline comment:** - `path`: Full file path (e.g., "src/components/ReportActionsList.tsx") - `line`: Line number where the issue occurs - `body`: Concise and actionable description of the violation and fix, following the below Comment Format -4. **Each comment must reference exactly one Rule ID.** -5. **Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format.** No other text, Markdown, or prose is allowed. -6. **If no violations are found, create a comment** (with no quotes, markdown, or additional text): + +6. **Each comment must reference exactly one Rule ID.** + +7. **Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format.** No other text, Markdown, or prose is allowed. + +8. **If no violations are found, create a comment** (with no quotes, markdown, or additional text): LGTM :feelsgood:. Thank you for your hard work! -7. **Output LGTM if and only if**: - - You examined EVERY line of EVERY changed file + +9. **Output LGTM if and only if**: + - You examined EVERY changed line in EVERY changed file (via diff + targeted grep/read) - You checked EVERY changed file against ALL rules - You found ZERO violations matching the exact rule criteria - You verified no false negatives by checking each rule systematically If you found even ONE violation or have ANY uncertainty do NOT create LGTM comment - create inline comments instead. -8. **DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.** -9. **DO NOT describe what you are doing, create comments with a summary, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE.** + +10. **DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.** + +11. **DO NOT describe what you are doing, create comments with a summary, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE.** Only inline comments regarding rules violations or general comment with LGTM message are allowed. EXCEPTION: If you believe something MIGHT be a Rule violation but are uncertain, err on the side of creating an inline comment with your concern rather than skipping it. diff --git a/.claude/agents/helpdot-inline-reviewer.md b/.claude/agents/helpdot-inline-reviewer.md index 1f8e821817be..312334904d1c 100644 --- a/.claude/agents/helpdot-inline-reviewer.md +++ b/.claude/agents/helpdot-inline-reviewer.md @@ -52,9 +52,18 @@ keywords: [feature name, related terms, navigation path, etc.] ## Instructions -1. **Read each changed file carefully** using the Read tool -2. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool -3. **Required parameters for each inline comment:** +1. **First, get the list of changed files:** + - Use `gh pr diff` to see what actually changed in the PR + - Focus ONLY on documentation files (*.md, *.csv, etc.) + +2. **For analyzing changed files:** + - **For large files (>5000 lines):** Use the Grep tool to search for specific patterns (e.g., "policy", "user", wrong terminology) or read specific line ranges + - **For normal-sized files:** Read the full file using the Read tool + - **If a Read fails with token limit error:** Use Grep to search for specific violation patterns or use offset/limit parameters to read the file in chunks + +3. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool + +4. **Required parameters for each inline comment:** - `path`: Full file path (e.g., "docs/articles/new-expensify/chat/Create-a-New-Chat.md") - `line`: Line number where the issue occurs - `body`: Concise description of the violation and fix From db6a4eef43382f9126722b7c117654e0c8a88a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 20 Oct 2025 18:28:25 +0200 Subject: [PATCH 2/4] remove empty lines --- .claude/agents/code-inline-reviewer.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.claude/agents/code-inline-reviewer.md b/.claude/agents/code-inline-reviewer.md index c97976267cff..d23bf0a1d413 100644 --- a/.claude/agents/code-inline-reviewer.md +++ b/.claude/agents/code-inline-reviewer.md @@ -223,12 +223,10 @@ const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => { 1. **First, get the list of changed files and their diffs:** - Use `gh pr diff` to see what actually changed in the PR - Focus ONLY on the changed lines, not the entire file - 2. **For analyzing changed files:** - **For large files (>5000 lines):** Use the Grep tool to search for specific violation patterns instead of reading the entire file. Focus grep searches on the changed portions shown in the diff. - **For smaller files:** You may read the full file using the Read tool - **If a Read fails with token limit error:** Immediately switch to using Grep with targeted patterns for the rules you're checking - 3. **Search strategy for large files:** - PERF-1: Search for `renderItem` and `...` patterns in the same vicinity - PERF-2: Search for `.every(`, `.some(`, `.find(`, `.filter(` patterns @@ -236,30 +234,22 @@ const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => { - PERF-4: Search for `useMemo`, `useCallback`, and prop passing patterns - PERF-5: Search for `React.memo` and `deepEqual` patterns - PERF-6: Search for `useEffect`, `useMemo`, `useCallback` dependency arrays - 4. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool - 5. **Required parameters for each inline comment:** - `path`: Full file path (e.g., "src/components/ReportActionsList.tsx") - `line`: Line number where the issue occurs - `body`: Concise and actionable description of the violation and fix, following the below Comment Format - 6. **Each comment must reference exactly one Rule ID.** - 7. **Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format.** No other text, Markdown, or prose is allowed. - 8. **If no violations are found, create a comment** (with no quotes, markdown, or additional text): LGTM :feelsgood:. Thank you for your hard work! - 9. **Output LGTM if and only if**: - You examined EVERY changed line in EVERY changed file (via diff + targeted grep/read) - You checked EVERY changed file against ALL rules - You found ZERO violations matching the exact rule criteria - You verified no false negatives by checking each rule systematically If you found even ONE violation or have ANY uncertainty do NOT create LGTM comment - create inline comments instead. - 10. **DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.** - 11. **DO NOT describe what you are doing, create comments with a summary, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE.** Only inline comments regarding rules violations or general comment with LGTM message are allowed. EXCEPTION: If you believe something MIGHT be a Rule violation but are uncertain, err on the side of creating an inline comment with your concern rather than skipping it. From 154ff9db9174f8cca8538742d20a0c4941450f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 20 Oct 2025 18:32:42 +0200 Subject: [PATCH 3/4] co-locate search patterns with perf rules --- .claude/agents/code-inline-reviewer.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.claude/agents/code-inline-reviewer.md b/.claude/agents/code-inline-reviewer.md index d23bf0a1d413..aca4d78393c3 100644 --- a/.claude/agents/code-inline-reviewer.md +++ b/.claude/agents/code-inline-reviewer.md @@ -17,12 +17,15 @@ Your job is to scan through changed files and create **inline comments** for spe Each rule includes: - A unique **Rule ID** +- **Search patterns**: Grep patterns to efficiently locate potential violations in large files - **Pass/Fail condition** - **Reasoning**: Technical explanation of why the rule is important - Examples of good and bad usage ### [PERF-1] No spread in list item's renderItem +- **Search patterns**: `renderItem`, `...` (look for both in proximity) + - **Condition**: Flag ONLY when ALL of these are true: - Code is inside a renderItem function (function passed to FlatList, SectionList, etc.) @@ -65,6 +68,8 @@ Bad: ### [PERF-2] Use early returns in array iteration methods +- **Search patterns**: `.every(`, `.some(`, `.find(`, `.filter(` + - **Condition**: Flag ONLY when ALL of these are true: - Using .every(), .some(), .find(), .filter() or similar function @@ -119,6 +124,8 @@ const areAllTransactionsValid = transactions.every((transaction) => { ### [PERF-3] Use OnyxListItemProvider hooks instead of useOnyx in renderItem +- **Search patterns**: `useOnyx` within components used in `renderItem` + - **Condition**: Components rendered inside `renderItem` functions should use dedicated hooks from `OnyxListItemProvider` instead of individual `useOnyx` calls. - **Reasoning**: Individual `useOnyx` calls in renderItem create separate subscriptions for each list item, causing memory overhead and update cascades. `OnyxListItemProvider` hooks provide optimized data access patterns specifically designed for list rendering performance. @@ -138,6 +145,8 @@ const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); ### [PERF-4] Memoize objects and functions passed as props +- **Search patterns**: `useMemo`, `useCallback`, and prop passing patterns + - **Condition**: Objects and functions passed as props should be properly memoized or simplified to primitive values to prevent unnecessary re-renders. - **Reasoning**: React uses referential equality to determine if props changed. New object/function instances on every render trigger unnecessary re-renders of child components, even when the actual data hasn't changed. Memoization preserves referential stability. @@ -165,6 +174,8 @@ return ### [PERF-5] Use shallow comparisons instead of deep comparisons +- **Search patterns**: `React.memo`, `deepEqual` + - **Condition**: In `React.memo` and similar optimization functions, compare only specific relevant properties instead of using deep equality checks. - **Reasoning**: Deep equality checks recursively compare all nested properties, creating performance overhead that often exceeds the re-render cost they aim to prevent. Shallow comparisons of specific relevant properties provide the same optimization benefits with minimal computational cost. @@ -191,6 +202,8 @@ memo(ReportActionItem, (prevProps, nextProps) => ### [PERF-6] Use specific properties as hook dependencies +- **Search patterns**: `useEffect`, `useMemo`, `useCallback` dependency arrays + - **Condition**: In `useEffect`, `useMemo`, and `useCallback`, specify individual object properties as dependencies instead of passing entire objects. - **Reasoning**: Passing entire objects as dependencies causes hooks to re-execute whenever any property changes, even unrelated ones. Specifying individual properties creates more granular dependency tracking, reducing unnecessary hook executions and improving performance predictability. @@ -227,13 +240,7 @@ const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => { - **For large files (>5000 lines):** Use the Grep tool to search for specific violation patterns instead of reading the entire file. Focus grep searches on the changed portions shown in the diff. - **For smaller files:** You may read the full file using the Read tool - **If a Read fails with token limit error:** Immediately switch to using Grep with targeted patterns for the rules you're checking -3. **Search strategy for large files:** - - PERF-1: Search for `renderItem` and `...` patterns in the same vicinity - - PERF-2: Search for `.every(`, `.some(`, `.find(`, `.filter(` patterns - - PERF-3: Search for `useOnyx` within components used in `renderItem` - - PERF-4: Search for `useMemo`, `useCallback`, and prop passing patterns - - PERF-5: Search for `React.memo` and `deepEqual` patterns - - PERF-6: Search for `useEffect`, `useMemo`, `useCallback` dependency arrays +3. **Search strategy for large files:** Use the search patterns defined in each rule's "Search patterns" field to efficiently locate potential violations with Grep. 4. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool 5. **Required parameters for each inline comment:** - `path`: Full file path (e.g., "src/components/ReportActionsList.tsx") From 6a4f74ccafb15a7f4653a71cb44b43ad78837527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 20 Oct 2025 19:04:39 +0200 Subject: [PATCH 4/4] change strategy for reading doc files --- .claude/agents/helpdot-inline-reviewer.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.claude/agents/helpdot-inline-reviewer.md b/.claude/agents/helpdot-inline-reviewer.md index 312334904d1c..3835fd8a79c9 100644 --- a/.claude/agents/helpdot-inline-reviewer.md +++ b/.claude/agents/helpdot-inline-reviewer.md @@ -57,9 +57,19 @@ keywords: [feature name, related terms, navigation path, etc.] - Focus ONLY on documentation files (*.md, *.csv, etc.) 2. **For analyzing changed files:** - - **For large files (>5000 lines):** Use the Grep tool to search for specific patterns (e.g., "policy", "user", wrong terminology) or read specific line ranges - - **For normal-sized files:** Read the full file using the Read tool - - **If a Read fails with token limit error:** Use Grep to search for specific violation patterns or use offset/limit parameters to read the file in chunks + - **Use a hybrid approach** because different violations require different analysis methods: + - **Grep is suitable for pattern-based violations only:** + - Terminology violations ("policy" → "workspace", "user" → "member") + - Button label violations ("Save" → "Confirm", "Continue" → "Next") + - Missing YAML frontmatter markers (`---`) + - **Full file reading is required for semantic violations:** + - Readability issues (clarity, flow, scannability, reading level) + - AI Readiness issues (vague headings, unclear references, logical structure) + - Proper hierarchy and document structure + - **Reading strategy:** + - Most documentation files are small (<1000 lines) - read them in full + - For files >1000 lines: Read in overlapping chunks using offset/limit to maintain context + - **Never rely on grep alone** - semantic violations require understanding context, not just pattern matching 3. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool