|
| 1 | +# Claude Development Notes |
| 2 | + |
| 3 | +## General Development Flow for All Scripts |
| 4 | + |
| 5 | +### Standard Development Pattern |
| 6 | + |
| 7 | +1. **Install Dependencies**: Use `bun add <package>` for runtime deps, `bun add -d <package>` for dev deps |
| 8 | +2. **Create Implementation**: Write the main functionality in TypeScript |
| 9 | +3. **Add Testing**: Create `.spec.ts` files with comprehensive test coverage |
| 10 | +4. **Test Execution**: Use `bun <file.ts>` to run scripts directly with `if (import.meta.main)` blocks |
| 11 | +5. **Type Safety**: Ensure full TypeScript coverage and proper type definitions |
| 12 | +6. **Error Handling**: Handle errors gracefully and don't cache failed responses |
| 13 | +7. **Documentation**: Update CLAUDE.md with implementation details and usage examples |
| 14 | + |
| 15 | +### Testing Standards |
| 16 | + |
| 17 | +- **File Naming**: Use `.spec.ts` suffix for test files |
| 18 | +- **Mocking**: Mock external APIs and services to avoid real calls during tests |
| 19 | +- **Coverage Areas**: Test happy path, error cases, edge cases, concurrent scenarios |
| 20 | +- **Setup/Teardown**: Clean up resources (files, caches, etc.) in test lifecycle hooks |
| 21 | + |
| 22 | +### Common Patterns |
| 23 | + |
| 24 | +- **Caching**: Use Keyv with SQLite for persistent caching in `node_modules/.cache/Comfy-PR/` |
| 25 | +- **Configuration**: Store config in environment variables with sensible defaults |
| 26 | +- **Logging**: Use console.log sparingly, prefer structured logging for debugging |
| 27 | +- **File Organization**: Keep related functionality together, use clear module exports |
| 28 | + |
| 29 | +### Repository Structure |
| 30 | + |
| 31 | +- **`src/`**: Core utilities and shared functionality |
| 32 | +- **`app/tasks/`**: Specific task implementations |
| 33 | +- **`gh-service/`**: GitHub webhook service components |
| 34 | +- **`run/`**: Executable scripts and services |
| 35 | +- **Tests**: Co-located with source files using `.spec.ts` suffix |
| 36 | + |
| 37 | +## Cached GitHub Client (ghc) |
| 38 | + |
| 39 | +### Overview |
| 40 | + |
| 41 | +Created a cached wrapper around the GitHub API client that transparently caches all API responses to improve performance and reduce API rate limiting. |
| 42 | + |
| 43 | +### Implementation |
| 44 | + |
| 45 | +- **File**: `src/ghc.ts` |
| 46 | +- **Cache Storage**: SQLite via Keyv in `node_modules/.cache/Comfy-PR/gh-cache.sqlite` |
| 47 | +- **Default TTL**: 5 minutes |
| 48 | +- **Cache Key Format**: `gh.{apiPath}({truncatedArgs})#{hash}` |
| 49 | + |
| 50 | +### Key Features |
| 51 | + |
| 52 | +1. **Transparent Caching**: Same interface as `gh` object, just import `ghc` instead |
| 53 | +2. **Smart Cache Keys**: Truncates long arguments but preserves full hash for accuracy |
| 54 | +3. **SQLite Storage**: Persistent cache across runs |
| 55 | +4. **Type Safety**: Maintains full TypeScript types from original GitHub client |
| 56 | + |
| 57 | +### Usage |
| 58 | + |
| 59 | +```typescript |
| 60 | +import { ghc } from "./src/ghc"; |
| 61 | + |
| 62 | +// Same as gh.repos.get() but with caching |
| 63 | +const repo = await ghc.repos.get({ |
| 64 | + owner: "octocat", |
| 65 | + repo: "Hello-World", |
| 66 | +}); |
| 67 | + |
| 68 | +// Second call uses cache |
| 69 | +const cachedRepo = await ghc.repos.get({ |
| 70 | + owner: "octocat", |
| 71 | + repo: "Hello-World", |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +### Cache Management |
| 76 | + |
| 77 | +```typescript |
| 78 | +import { clearGhCache, getGhCacheStats } from "./src/ghc"; |
| 79 | + |
| 80 | +// Clear all cached data |
| 81 | +await clearGhCache(); |
| 82 | + |
| 83 | +// Get cache statistics |
| 84 | +const stats = await getGhCacheStats(); |
| 85 | +``` |
| 86 | + |
| 87 | +### Testing |
| 88 | + |
| 89 | +- **Test File**: `src/ghc.spec.ts` |
| 90 | +- **Coverage**: Cache hits/misses, error handling, concurrent requests, key generation |
| 91 | +- **Mocking**: Uses Jest mocks to avoid real API calls during tests |
| 92 | + |
| 93 | +### Development Flow |
| 94 | + |
| 95 | +1. Install dependencies: `bun add keyv @keyv/sqlite` |
| 96 | +2. Create cached wrapper with Proxy pattern |
| 97 | +3. Implement cache key generation with argument truncation |
| 98 | +4. Add comprehensive test suite |
| 99 | +5. Test with real API calls: `bun src/ghc.ts` |
| 100 | + |
| 101 | +### Cache Key Examples |
| 102 | + |
| 103 | +- Short args: `gh.repos.get({"owner":"octocat","repo":"Hello-World"})#b3117af2` |
| 104 | +- Long args: `gh.repos.get({"owner":"octocat","descripti...bbbbbbbbbb"})#4240f076` |
0 commit comments