@aaronshaf/ger 1.2.11 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/.ast-grep/rules/no-as-casting.yml +13 -0
  2. package/.claude-plugin/plugin.json +22 -0
  3. package/.github/workflows/ci-simple.yml +53 -0
  4. package/.github/workflows/ci.yml +171 -0
  5. package/.github/workflows/claude-code-review.yml +83 -0
  6. package/.github/workflows/claude.yml +50 -0
  7. package/.github/workflows/dependency-update.yml +84 -0
  8. package/.github/workflows/release.yml +166 -0
  9. package/.github/workflows/security-scan.yml +113 -0
  10. package/.github/workflows/security.yml +96 -0
  11. package/.husky/pre-commit +16 -0
  12. package/.husky/pre-push +25 -0
  13. package/.lintstagedrc.json +6 -0
  14. package/.tool-versions +1 -0
  15. package/CLAUDE.md +105 -0
  16. package/DEVELOPMENT.md +361 -0
  17. package/EXAMPLES.md +457 -0
  18. package/README.md +831 -16
  19. package/bin/ger +3 -18
  20. package/biome.json +36 -0
  21. package/bun.lock +678 -0
  22. package/bunfig.toml +8 -0
  23. package/docs/adr/0001-use-effect-for-side-effects.md +65 -0
  24. package/docs/adr/0002-use-bun-runtime.md +64 -0
  25. package/docs/adr/0003-store-credentials-in-home-directory.md +75 -0
  26. package/docs/adr/0004-use-commander-for-cli.md +76 -0
  27. package/docs/adr/0005-use-effect-schema-for-validation.md +93 -0
  28. package/docs/adr/0006-use-msw-for-api-mocking.md +89 -0
  29. package/docs/adr/0007-git-hooks-for-quality.md +94 -0
  30. package/docs/adr/0008-no-as-typecasting.md +83 -0
  31. package/docs/adr/0009-file-size-limits.md +82 -0
  32. package/docs/adr/0010-llm-friendly-xml-output.md +93 -0
  33. package/docs/adr/0011-ai-tool-strategy-pattern.md +102 -0
  34. package/docs/adr/0012-build-status-message-parsing.md +94 -0
  35. package/docs/adr/0013-git-subprocess-integration.md +98 -0
  36. package/docs/adr/0014-group-management-support.md +95 -0
  37. package/docs/adr/0015-batch-comment-processing.md +111 -0
  38. package/docs/adr/0016-flexible-change-identifiers.md +94 -0
  39. package/docs/adr/0017-git-worktree-support.md +102 -0
  40. package/docs/adr/0018-auto-install-commit-hook.md +103 -0
  41. package/docs/adr/0019-sdk-package-exports.md +95 -0
  42. package/docs/adr/0020-code-coverage-enforcement.md +105 -0
  43. package/docs/adr/0021-typescript-isolated-declarations.md +83 -0
  44. package/docs/adr/0022-biome-oxlint-tooling.md +124 -0
  45. package/docs/adr/README.md +30 -0
  46. package/docs/prd/README.md +12 -0
  47. package/docs/prd/architecture.md +325 -0
  48. package/docs/prd/commands.md +425 -0
  49. package/docs/prd/data-model.md +349 -0
  50. package/docs/prd/overview.md +124 -0
  51. package/index.ts +219 -0
  52. package/oxlint.json +24 -0
  53. package/package.json +82 -15
  54. package/scripts/check-coverage.ts +69 -0
  55. package/scripts/check-file-size.ts +38 -0
  56. package/scripts/fix-test-mocks.ts +55 -0
  57. package/skills/gerrit-workflow/SKILL.md +247 -0
  58. package/skills/gerrit-workflow/examples.md +572 -0
  59. package/skills/gerrit-workflow/reference.md +728 -0
  60. package/src/api/gerrit.ts +696 -0
  61. package/src/cli/commands/abandon.ts +65 -0
  62. package/src/cli/commands/add-reviewer.ts +156 -0
  63. package/src/cli/commands/build-status.ts +282 -0
  64. package/src/cli/commands/checkout.ts +422 -0
  65. package/src/cli/commands/comment.ts +460 -0
  66. package/src/cli/commands/comments.ts +85 -0
  67. package/src/cli/commands/diff.ts +71 -0
  68. package/src/cli/commands/extract-url.ts +266 -0
  69. package/src/cli/commands/groups-members.ts +104 -0
  70. package/src/cli/commands/groups-show.ts +169 -0
  71. package/src/cli/commands/groups.ts +137 -0
  72. package/src/cli/commands/incoming.ts +226 -0
  73. package/src/cli/commands/init.ts +164 -0
  74. package/src/cli/commands/mine.ts +115 -0
  75. package/src/cli/commands/open.ts +57 -0
  76. package/src/cli/commands/projects.ts +68 -0
  77. package/src/cli/commands/push.ts +430 -0
  78. package/src/cli/commands/rebase.ts +52 -0
  79. package/src/cli/commands/remove-reviewer.ts +123 -0
  80. package/src/cli/commands/restore.ts +50 -0
  81. package/src/cli/commands/review.ts +486 -0
  82. package/src/cli/commands/search.ts +162 -0
  83. package/src/cli/commands/setup.ts +286 -0
  84. package/src/cli/commands/show.ts +491 -0
  85. package/src/cli/commands/status.ts +35 -0
  86. package/src/cli/commands/submit.ts +108 -0
  87. package/src/cli/commands/vote.ts +119 -0
  88. package/src/cli/commands/workspace.ts +200 -0
  89. package/src/cli/index.ts +53 -0
  90. package/src/cli/register-commands.ts +659 -0
  91. package/src/cli/register-group-commands.ts +88 -0
  92. package/src/cli/register-reviewer-commands.ts +97 -0
  93. package/src/prompts/default-review.md +86 -0
  94. package/src/prompts/system-inline-review.md +135 -0
  95. package/src/prompts/system-overall-review.md +206 -0
  96. package/src/schemas/config.test.ts +245 -0
  97. package/src/schemas/config.ts +84 -0
  98. package/src/schemas/gerrit.ts +681 -0
  99. package/src/services/commit-hook.ts +314 -0
  100. package/src/services/config.test.ts +150 -0
  101. package/src/services/config.ts +250 -0
  102. package/src/services/git-worktree.ts +342 -0
  103. package/src/services/review-strategy.ts +292 -0
  104. package/src/test-utils/mock-generator.ts +138 -0
  105. package/src/utils/change-id.test.ts +98 -0
  106. package/src/utils/change-id.ts +63 -0
  107. package/src/utils/comment-formatters.ts +153 -0
  108. package/src/utils/diff-context.ts +103 -0
  109. package/src/utils/diff-formatters.ts +141 -0
  110. package/src/utils/formatters.ts +85 -0
  111. package/src/utils/git-commit.test.ts +277 -0
  112. package/src/utils/git-commit.ts +122 -0
  113. package/src/utils/index.ts +55 -0
  114. package/src/utils/message-filters.ts +26 -0
  115. package/src/utils/review-formatters.ts +89 -0
  116. package/src/utils/review-prompt-builder.ts +110 -0
  117. package/src/utils/shell-safety.ts +117 -0
  118. package/src/utils/status-indicators.ts +100 -0
  119. package/src/utils/url-parser.test.ts +271 -0
  120. package/src/utils/url-parser.ts +118 -0
  121. package/tests/abandon.test.ts +230 -0
  122. package/tests/add-reviewer.test.ts +579 -0
  123. package/tests/build-status-watch.test.ts +344 -0
  124. package/tests/build-status.test.ts +789 -0
  125. package/tests/change-id-formats.test.ts +268 -0
  126. package/tests/checkout/integration.test.ts +653 -0
  127. package/tests/checkout/parse-input.test.ts +55 -0
  128. package/tests/checkout/validation.test.ts +178 -0
  129. package/tests/comment-batch-advanced.test.ts +431 -0
  130. package/tests/comment-gerrit-api-compliance.test.ts +414 -0
  131. package/tests/comment.test.ts +708 -0
  132. package/tests/comments.test.ts +323 -0
  133. package/tests/config-service-simple.test.ts +100 -0
  134. package/tests/diff.test.ts +419 -0
  135. package/tests/extract-url.test.ts +517 -0
  136. package/tests/groups-members.test.ts +256 -0
  137. package/tests/groups-show.test.ts +323 -0
  138. package/tests/groups.test.ts +334 -0
  139. package/tests/helpers/build-status-test-setup.ts +83 -0
  140. package/tests/helpers/config-mock.ts +27 -0
  141. package/tests/incoming.test.ts +357 -0
  142. package/tests/init.test.ts +70 -0
  143. package/tests/integration/commit-hook.test.ts +246 -0
  144. package/tests/interactive-incoming.test.ts +173 -0
  145. package/tests/mine.test.ts +285 -0
  146. package/tests/mocks/msw-handlers.ts +80 -0
  147. package/tests/open.test.ts +233 -0
  148. package/tests/projects.test.ts +259 -0
  149. package/tests/rebase.test.ts +271 -0
  150. package/tests/remove-reviewer.test.ts +357 -0
  151. package/tests/restore.test.ts +237 -0
  152. package/tests/review.test.ts +135 -0
  153. package/tests/search.test.ts +712 -0
  154. package/tests/setup.test.ts +63 -0
  155. package/tests/show-auto-detect.test.ts +324 -0
  156. package/tests/show.test.ts +813 -0
  157. package/tests/status.test.ts +145 -0
  158. package/tests/submit.test.ts +316 -0
  159. package/tests/unit/commands/push.test.ts +194 -0
  160. package/tests/unit/git-branch-detection.test.ts +82 -0
  161. package/tests/unit/git-worktree.test.ts +55 -0
  162. package/tests/unit/patterns/push-patterns.test.ts +148 -0
  163. package/tests/unit/schemas/gerrit.test.ts +85 -0
  164. package/tests/unit/services/commit-hook.test.ts +132 -0
  165. package/tests/unit/services/review-strategy.test.ts +349 -0
  166. package/tests/unit/test-utils/mock-generator.test.ts +154 -0
  167. package/tests/unit/utils/comment-formatters.test.ts +415 -0
  168. package/tests/unit/utils/diff-context.test.ts +171 -0
  169. package/tests/unit/utils/diff-formatters.test.ts +165 -0
  170. package/tests/unit/utils/formatters.test.ts +411 -0
  171. package/tests/unit/utils/message-filters.test.ts +227 -0
  172. package/tests/unit/utils/shell-safety.test.ts +230 -0
  173. package/tests/unit/utils/status-indicators.test.ts +137 -0
  174. package/tests/vote.test.ts +317 -0
  175. package/tests/workspace.test.ts +295 -0
  176. package/tsconfig.json +36 -5
  177. package/src/commands/branch.ts +0 -196
  178. package/src/ger.ts +0 -22
  179. package/src/types.d.ts +0 -35
  180. package/src/utils.ts +0 -130
package/DEVELOPMENT.md ADDED
@@ -0,0 +1,361 @@
1
+ # Development Guide
2
+
3
+ This document contains information for developers working on the Gerrit CLI project.
4
+
5
+ ## Prerequisites
6
+
7
+ - **Bun 1.0+** - Primary runtime and package manager
8
+ - **Node.js 18+** - For tooling compatibility
9
+ - **Git** - Version control
10
+
11
+ ## Getting Started
12
+
13
+ ### Initial Setup
14
+ ```bash
15
+ git clone https://github.com/your-org/gerrit-cli
16
+ cd gerrit-cli
17
+ bun install
18
+ ```
19
+
20
+ ### Development Commands
21
+ ```bash
22
+ # Development
23
+ bun run dev # Run CLI in development mode
24
+ bun run dev --help # Show CLI help
25
+ bun run build # Build for production
26
+
27
+ # Testing
28
+ bun test # Run all tests
29
+ bun run test:coverage # Run tests with coverage report
30
+ bun test tests/unit/ # Run only unit tests
31
+ bun test tests/integration/ # Run only integration tests
32
+
33
+ # Code Quality
34
+ bun run typecheck # TypeScript type checking
35
+ bun run lint # Run oxlint
36
+ bun run format # Format code with Biome
37
+ bun run format:check # Check code formatting
38
+ bun run check:all # Run all checks (typecheck, lint, format, test)
39
+ ```
40
+
41
+ ## Architecture
42
+
43
+ The project follows a clean, functional architecture using Effect:
44
+
45
+ ### Directory Structure
46
+ ```
47
+ src/
48
+ ├── cli/ # Ink components and command definitions
49
+ │ ├── commands/ # Individual command implementations
50
+ │ └── index.ts # Main CLI entry point
51
+ ├── services/ # Effect services
52
+ │ └── config.ts # Configuration management
53
+ ├── api/ # Gerrit REST API client
54
+ │ └── gerrit.ts # API service implementation
55
+ ├── db/ # SQLite caching layer
56
+ │ ├── database.ts # Database service
57
+ │ └── schema.ts # SQL schema definitions
58
+ ├── schemas/ # Effect Schema definitions
59
+ │ └── gerrit.ts # Type-safe data models
60
+ ├── i18n/ # Internationalization (future)
61
+ └── utils/ # Shared utilities
62
+
63
+ tests/
64
+ ├── unit/ # Unit tests
65
+ ├── integration/ # Integration tests
66
+ ├── mocks/ # MSW mock handlers
67
+ └── setup.ts # Test setup and configuration
68
+ ```
69
+
70
+ ### Key Technologies
71
+
72
+ - **Effect** - Functional effect system for managing side effects
73
+ - **Effect Schema** - Type-safe data validation and transformation
74
+ - **Ink** - React for CLIs, providing interactive terminal UI
75
+ - **Bun SQLite** - Built-in SQLite support for caching
76
+ - **MSW** - Mock Service Worker for API testing
77
+ - **Commander.js** - CLI argument parsing
78
+
79
+ ### Design Principles
80
+
81
+ 1. **Functional Programming** - Use Effect for all side effects
82
+ 2. **Type Safety** - Leverage TypeScript with strict settings
83
+ 3. **Local-First** - Cache everything, work offline when possible
84
+ 4. **Error Handling** - Comprehensive error types and handling
85
+ 5. **Testing** - High test coverage with shared schemas
86
+
87
+ ## Code Quality Standards
88
+
89
+ ### TypeScript Configuration
90
+ - `isolatedDeclarations: true` - Explicit type exports
91
+ - `noImplicitAny: true` - No implicit any types
92
+ - `strictNullChecks: true` - Strict null checking
93
+ - Only `.ts` files allowed (no `.js/.jsx/.tsx`)
94
+
95
+ ### Linting & Formatting
96
+ - **oxlint** - Fast, strict linting
97
+ - **Biome** - Consistent code formatting
98
+ - **ast-grep** - Pattern-based code rules
99
+
100
+ ### File Size Limits
101
+ - **Warning** at 500 lines
102
+ - **Error** at 700 lines
103
+ - Enforced in pre-commit hooks
104
+
105
+ ### Banned Patterns
106
+ - `as` type casting (except `as const` and `as unknown`)
107
+ - `--no-verify` flag usage
108
+ - Implicit any types
109
+ - console.log in production code
110
+
111
+ ## Testing Strategy
112
+
113
+ ### Test Types
114
+ 1. **Unit Tests** - Pure functions, schemas, utilities
115
+ 2. **Integration Tests** - API clients with MSW mocks
116
+ 3. **Component Tests** - CLI command behavior
117
+
118
+ ### Shared Schemas
119
+ Test mocks use the same Effect Schemas as production code, ensuring type safety and consistency.
120
+
121
+ ### Coverage Requirements
122
+ - **Minimum 80%** line coverage
123
+ - **Minimum 80%** function coverage
124
+ - **Minimum 80%** branch coverage
125
+ - **Minimum 80%** statement coverage
126
+
127
+ ### Running Tests
128
+ ```bash
129
+ # All tests
130
+ bun test
131
+
132
+ # Watch mode
133
+ bun test --watch
134
+
135
+ # Specific test file
136
+ bun test tests/unit/schemas/gerrit.test.ts
137
+
138
+ # Coverage report
139
+ bun run test:coverage
140
+ ```
141
+
142
+ ## Git Workflow
143
+
144
+ ### Branch Strategy
145
+ - `main` branch for stable releases
146
+ - Feature branches: `feat/feature-name`
147
+ - Bug fixes: `fix/bug-description`
148
+ - Use conventional commit messages
149
+
150
+ ### Pre-commit Hooks
151
+ Automatically run on every commit:
152
+ - TypeScript type checking
153
+ - Code linting (oxlint)
154
+ - Code formatting check (Biome)
155
+ - File size validation
156
+ - ast-grep pattern checks
157
+ - Tests for changed files
158
+
159
+ ### Pre-push Hooks
160
+ Run before pushing to remote:
161
+ - Full test suite
162
+ - Code coverage validation
163
+ - Complete build verification
164
+ - All linting and formatting checks
165
+
166
+ ### Conventional Commits
167
+ ```bash
168
+ feat: add support for patch comparison
169
+ fix: handle empty diff responses
170
+ docs: update API documentation
171
+ test: add integration tests for diff command
172
+ refactor: simplify error handling logic
173
+ ```
174
+
175
+ ## Adding New Commands
176
+
177
+ ### 1. Define Schema
178
+ Add types to `src/schemas/gerrit.ts`:
179
+ ```typescript
180
+ export const NewCommandOptions = Schema.Struct({
181
+ option1: Schema.String,
182
+ option2: Schema.optional(Schema.Number),
183
+ })
184
+ export type NewCommandOptions = Schema.Schema.Type<typeof NewCommandOptions>
185
+ ```
186
+
187
+ ### 2. Extend API Service
188
+ Add methods to `src/api/gerrit.ts`:
189
+ ```typescript
190
+ readonly newMethod: (param: string) => Effect.Effect<ReturnType, ApiError>
191
+ ```
192
+
193
+ ### 3. Create Command Component
194
+ Create `src/cli/commands/new-command.tsx`:
195
+ ```typescript
196
+ import React from 'react'
197
+ import { Box, Text } from 'ink'
198
+ // Implementation...
199
+ ```
200
+
201
+ ### 4. Register Command
202
+ Add to `src/cli/index.ts`:
203
+ ```typescript
204
+ program
205
+ .command('new-command <param>')
206
+ .description('Description of new command')
207
+ .action(/* implementation */)
208
+ ```
209
+
210
+ ### 5. Add Tests
211
+ Create test files in `tests/unit/` and `tests/integration/`
212
+
213
+ ### 6. Update Documentation
214
+ Update README.md with usage examples
215
+
216
+ ## Database Management
217
+
218
+ ### Schema Changes
219
+ 1. Update `src/db/schema.ts` with new tables/columns
220
+ 2. Add migration logic to `src/db/database.ts`
221
+ 3. Test with fresh database creation
222
+ 4. Update cache invalidation logic if needed
223
+
224
+ ### Caching Strategy
225
+ - **Cache-first** - Always check local cache first
226
+ - **Smart invalidation** - Update cache on write operations
227
+ - **Offline support** - Gracefully handle network failures
228
+
229
+ ## MSW Mock Setup
230
+
231
+ ### Adding New API Endpoints
232
+ 1. Define response schema in `src/schemas/gerrit.ts`
233
+ 2. Add handler to `tests/mocks/handlers.ts`
234
+ 3. Use schema validation in mock responses
235
+ 4. Test both success and error cases
236
+
237
+ ### Mock Data Generation
238
+ ```typescript
239
+ const mockData: Schema.Schema.Type<typeof YourSchema> = {
240
+ // Properly typed mock data
241
+ }
242
+
243
+ const validated = Schema.decodeUnknownSync(YourSchema)(mockData)
244
+ return HttpResponse.json(validated)
245
+ ```
246
+
247
+ ## Performance Considerations
248
+
249
+ ### Caching
250
+ - Cache API responses in SQLite
251
+ - Implement cache expiration
252
+ - Provide cache management commands
253
+
254
+ ### Bundle Size
255
+ - Use dynamic imports for large dependencies
256
+ - Tree-shake unused code
257
+ - Monitor bundle size in CI
258
+
259
+ ### CLI Responsiveness
260
+ - Show loading indicators
261
+ - Stream large outputs
262
+ - Implement request cancellation
263
+
264
+ ## Security Guidelines
265
+
266
+ ### Credential Storage
267
+ - Store in `~/.gi/credentials.json` with 600 permissions
268
+ - Never log credentials
269
+ - Use secure environment variable handling
270
+
271
+ ### API Communication
272
+ - Always use HTTPS
273
+ - Validate all inputs with Effect Schema
274
+ - Handle authentication errors gracefully
275
+
276
+ ### Error Messages
277
+ - Never expose sensitive information
278
+ - Provide helpful debugging information
279
+ - Log errors for debugging without sensitive data
280
+
281
+ ## Release Process
282
+
283
+ ### Version Management
284
+ - Use semantic versioning (semver)
285
+ - Update version in `package.json`
286
+ - Create git tags for releases
287
+
288
+ ### Build Process
289
+ ```bash
290
+ bun run build # Build optimized bundle
291
+ bun test # Ensure all tests pass
292
+ bun run check:all # Run all quality checks
293
+ ```
294
+
295
+ ### Distribution
296
+ - Create platform-specific binaries
297
+ - Upload to GitHub releases
298
+ - Update installation instructions
299
+
300
+ ## Contributing Guidelines
301
+
302
+ ### Code Review Checklist
303
+ - [ ] All tests pass
304
+ - [ ] Code coverage maintained
305
+ - [ ] TypeScript strict mode compliance
306
+ - [ ] Follows existing patterns
307
+ - [ ] Documentation updated
308
+ - [ ] Error handling implemented
309
+ - [ ] Security considerations addressed
310
+
311
+ ### Pull Request Process
312
+ 1. Create feature branch
313
+ 2. Implement changes with tests
314
+ 3. Run `bun run check:all`
315
+ 4. Create pull request with description
316
+ 5. Address review feedback
317
+ 6. Merge after approval
318
+
319
+ ## Troubleshooting
320
+
321
+ ### Common Development Issues
322
+
323
+ **Build failures**
324
+ ```bash
325
+ rm -rf node_modules bun.lockb
326
+ bun install
327
+ ```
328
+
329
+ **Test failures**
330
+ ```bash
331
+ bun test --verbose
332
+ ```
333
+
334
+ **Type errors**
335
+ ```bash
336
+ bun run typecheck
337
+ ```
338
+
339
+ **Lint errors**
340
+ ```bash
341
+ bun run format # Auto-fix formatting
342
+ bun run lint # Check for issues
343
+ ```
344
+
345
+ ### Debug Mode
346
+ ```bash
347
+ DEBUG=1 bun run dev <command> # Enable debug logging
348
+ ```
349
+
350
+ ### Database Issues
351
+ ```bash
352
+ rm -rf ~/.gi/cache.db # Reset local cache
353
+ ```
354
+
355
+ ## Resources
356
+
357
+ - [Effect Documentation](https://effect.website/)
358
+ - [Ink Documentation](https://github.com/vadimdemedes/ink)
359
+ - [Bun Documentation](https://bun.sh/docs)
360
+ - [MSW Documentation](https://mswjs.io/)
361
+ - [Gerrit REST API](https://gerrit-review.googlesource.com/Documentation/rest-api.html)