feat: add ChapterContext and per-chapter line counts#28
Conversation
DRY up the repeated green/red +N/-N line count pattern used in file-picker and file-header into a reusable LineCounts component.
Introduce ChapterContext that centralizes chapter data and per-chapter line counts (linesAdded/linesDeleted). The provider lives in PullRequestLayout, making chapter data available to both the index and detail pages without prop drilling.
ChapterNavigator now reads runId, chapters, and line counts from ChapterContext instead of receiving them as props. Each chapter in the dropdown shows its +N/-N line change counts. Removes runId and allChapters props from ChapterSidePanel.
Display +N/-N line change counts below the chapter title in the side panel, sourced from ChapterContext.
Each chapter entry in the index now shows +N/-N line change counts floated to the right of the chapter title, sourced from ChapterContext.
ChapterDetailContent now reads runId and allChapters from ChapterContext instead of receiving them as props, reducing its interface from 5 props to 3.
There was a problem hiding this comment.
Code Review
This pull request introduces a ChapterProvider and useChapterContext to centralize chapter data and calculate line counts (additions and deletions) per chapter. A new shared LineCounts component was added and integrated into the chapter navigator, side panel, file picker, and index page to provide visual feedback on the scale of changes. Feedback indicates that the current calculation for chapter line counts incorrectly uses total file additions/deletions instead of summing specific hunks, leading to inflated numbers when files span multiple chapters. Furthermore, the patch parsing logic within the context provider should be optimized to avoid redundant processing for each chapter.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1282050. Configure here.
When a chapter has zero additions and deletions, LineCounts returns null but the fallback spacer was unreachable because the counts object is always truthy. Check for non-zero counts before rendering.
ChapterDetailPage now reads the sorted chapters array from ChapterContext instead of maintaining its own duplicate sort, eliminating the fragile coupling between two independent sorts.

Summary
Introduces a
ChapterContextto centralize shared chapter data and adds per-chapter line change counts (+N/-N) across the UI, mirroring the hosted Stage monorepo.Changes
LineCountscomponent from the repeated green/red +N/-N pattern in file-picker and file-headerChapterContextwithChapterProvider(inPullRequestLayout) exposingrunId, sortedchapters, and achapterLineCountsMapChapterNavigator,ChapterSidePanel, andChapterDetailContentto read shared data from context instead of props, reducing prop drillingTesting
pnpm typecheckpassespnpm lintpassesserver.test.ts(unrelated to these changes)