From 15d0a31936a84f26c62524314db48e057826f0bc Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 12 Aug 2025 17:13:21 -0400 Subject: [PATCH] more code cleanup --- .DS_Store | Bin 8196 -> 0 bytes .claude/CLAUDE.md | 89 ----------------------------------------- cmd/goose/ratelimit.go | 13 ++---- 3 files changed, 4 insertions(+), 98 deletions(-) delete mode 100644 .DS_Store delete mode 100644 .claude/CLAUDE.md diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index caad1eaee45c6df92d1b98b22f0404da708aaf1c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM&2G~`5S~ra#!-dH0i;}zEO8AbPWcs=G))ebfJ2So04UhC3056%l-T4DMami8 zfmh(llkhH_U}kq)*-k4V4nSc>+Wow{-^9D$j(^4h0MX9^2cQK278b(h4p!$FjZ@jM zis`wED9|6|u^&qxTg?qFcd!Di04u->umY^W-=P3Lv&pOrp8I-~YgT|2_%9Wp`-6>z zuxD_sQQbPQQYipp4ZD@$v3mJOw5bEJXK<|%d(eb-Mbxgsq!_~F4nn)*c+c?H8nrtJ zb!Pk>b7o;O6k$>iVJkX_o<^=&0ajpB0m|L0a10X&4&!|OEVQv+0MYqptTA5kRdv}(^G8tnJvA1Ci5_VAyS=IygaXhcbDR&MT zOp4mU=MuLLkKqswUrt&%v!TQkqiI}H zg5o)^L<5d6KKEgO(Kl4rK>3b9ahmtQD~6x{s0kY@a2XY->PfdK{~uob{r@s9jpxh? zumV4+fT#`JK_AKV3Vfc?Q{Kk%1`8SS)*6)yR)rS}@V~ diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md deleted file mode 100644 index 17f7bd7..0000000 --- a/.claude/CLAUDE.md +++ /dev/null @@ -1,89 +0,0 @@ -# CLAUDE.md - -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. - -## Project Overview - -Ready to Review is a macOS/Linux/Windows menubar application that helps developers track GitHub pull requests. It shows a count of incoming/outgoing PRs and highlights when you're blocking someone's review. The app integrates with the Turn API to provide intelligent PR metadata about who's actually blocking progress. - -## Key Commands - -### Building and Running -```bash -make run # Build and run (on macOS: installs to /Applications and launches) -make build # Build for current platform -make app-bundle # Create macOS .app bundle -make install # Install to system (macOS: /Applications, Linux: /usr/local/bin, Windows: %LOCALAPPDATA%) -``` - -### Development -```bash -make lint # Run all linters (golangci-lint with strict config + yamllint) -make fix # Auto-fix linting issues where possible -make deps # Download and tidy Go dependencies -make clean # Remove build artifacts -``` - -## Architecture Overview - -### Core Components - -1. **Main Application Flow** (`main.go`) - - Single `context.Background()` created in main, passed through all functions - - App struct holds GitHub/Turn clients, PR data, and UI state - - Update loop runs every 2 minutes to refresh PR data - - Menu updates only rebuild when PR data actually changes (hash-based optimization) - -2. **GitHub Integration** (`github.go`) - - Uses GitHub CLI token (`gh auth token`) for authentication - - Fetches PRs with a single optimized query: `is:open is:pr involves:USER archived:false` - - No pagination needed (uses 100 per page limit) - -3. **Turn API Integration** (`cache.go`) - - Provides intelligent PR metadata (who's blocking, PR size, tags) - - Implements 2-hour TTL cache with SHA256-based cache keys - - Cache cleanup runs daily, removes files older than 5 days - - Turn API calls are made for each PR to determine blocking status - -4. **UI Management** (`ui.go`) - - System tray integration via energye/systray - - Menu structure: Incoming PRs → Outgoing PRs → Settings → About - - Click handlers open PRs in browser with URL validation - - "Hide stale PRs" option filters PRs older than 90 days - -5. **Platform-Specific Features** - - `loginitem_darwin.go`: macOS "Start at Login" functionality via AppleScript - - `loginitem_other.go`: Stub for non-macOS platforms - -### Key Design Decisions - -- **No Context in Structs**: Context is always passed as a parameter, never stored -- **Graceful Degradation**: Turn API failures don't break the app, PRs still display -- **Security**: Only HTTPS URLs allowed, whitelist of github.com and dash.ready-to-review.dev -- **Minimal Dependencies**: Uses standard library where possible -- **Proper Cancellation**: All goroutines respect context cancellation - -### Linting Configuration - -The project uses an extremely strict golangci-lint configuration (`.golangci.yml`) that enforces: -- All available linters except those that conflict with Go best practices -- No nolint directives without explanations -- Cognitive complexity limit of 55 -- No magic numbers (must use constants) -- Proper error handling (no unchecked errors) -- No naked returns except in very short functions -- Field alignment optimization for structs - -### Special Considerations - -1. **Authentication**: Uses GitHub CLI token, never stores it persistently -2. **Caching**: Turn API responses cached to reduce API calls -3. **Menu Updates**: Hash-based change detection prevents unnecessary UI updates -4. **Context Handling**: Single context from main, proper cancellation in all goroutines -5. **Error Handling**: All errors wrapped with context using `fmt.Errorf` with `%w` - -When making changes: -- Run `make lint` and fix all issues without adding nolint directives -- Follow the strict Go style guidelines in ~/.claude/CLAUDE.md -- Keep functions simple and focused -- Test macOS-specific features carefully (login items, app bundle) \ No newline at end of file diff --git a/cmd/goose/ratelimit.go b/cmd/goose/ratelimit.go index d0c2ef7..a6d9ba7 100644 --- a/cmd/goose/ratelimit.go +++ b/cmd/goose/ratelimit.go @@ -36,7 +36,10 @@ func (r *RateLimiter) Allow() bool { tokensToAdd := int(elapsed / r.refillRate) if tokensToAdd > 0 { - r.tokens = minInt(r.tokens+tokensToAdd, r.maxTokens) + r.tokens += tokensToAdd + if r.tokens > r.maxTokens { + r.tokens = r.maxTokens + } r.lastRefill = now } @@ -48,11 +51,3 @@ func (r *RateLimiter) Allow() bool { return false } - -// minInt returns the minimum of two integers. -func minInt(a, b int) int { - if a < b { - return a - } - return b -}