commic 1.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 (50) hide show
  1. package/.husky/pre-commit +2 -0
  2. package/README.md +306 -0
  3. package/biome.json +50 -0
  4. package/dist/ai/AIService.d.ts +51 -0
  5. package/dist/ai/AIService.d.ts.map +1 -0
  6. package/dist/ai/AIService.js +351 -0
  7. package/dist/ai/AIService.js.map +1 -0
  8. package/dist/config/ConfigManager.d.ts +49 -0
  9. package/dist/config/ConfigManager.d.ts.map +1 -0
  10. package/dist/config/ConfigManager.js +124 -0
  11. package/dist/config/ConfigManager.js.map +1 -0
  12. package/dist/errors/CustomErrors.d.ts +54 -0
  13. package/dist/errors/CustomErrors.d.ts.map +1 -0
  14. package/dist/errors/CustomErrors.js +99 -0
  15. package/dist/errors/CustomErrors.js.map +1 -0
  16. package/dist/git/GitService.d.ts +77 -0
  17. package/dist/git/GitService.d.ts.map +1 -0
  18. package/dist/git/GitService.js +219 -0
  19. package/dist/git/GitService.js.map +1 -0
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +48 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/orchestrator/MainOrchestrator.d.ts +63 -0
  25. package/dist/orchestrator/MainOrchestrator.d.ts.map +1 -0
  26. package/dist/orchestrator/MainOrchestrator.js +225 -0
  27. package/dist/orchestrator/MainOrchestrator.js.map +1 -0
  28. package/dist/types/index.d.ts +55 -0
  29. package/dist/types/index.d.ts.map +1 -0
  30. package/dist/types/index.js +2 -0
  31. package/dist/types/index.js.map +1 -0
  32. package/dist/ui/UIManager.d.ts +118 -0
  33. package/dist/ui/UIManager.d.ts.map +1 -0
  34. package/dist/ui/UIManager.js +369 -0
  35. package/dist/ui/UIManager.js.map +1 -0
  36. package/dist/validation/ConventionalCommitsValidator.d.ts +33 -0
  37. package/dist/validation/ConventionalCommitsValidator.d.ts.map +1 -0
  38. package/dist/validation/ConventionalCommitsValidator.js +114 -0
  39. package/dist/validation/ConventionalCommitsValidator.js.map +1 -0
  40. package/package.json +49 -0
  41. package/src/ai/AIService.ts +413 -0
  42. package/src/config/ConfigManager.ts +141 -0
  43. package/src/errors/CustomErrors.ts +176 -0
  44. package/src/git/GitService.ts +246 -0
  45. package/src/index.ts +55 -0
  46. package/src/orchestrator/MainOrchestrator.ts +263 -0
  47. package/src/types/index.ts +60 -0
  48. package/src/ui/UIManager.ts +420 -0
  49. package/src/validation/ConventionalCommitsValidator.ts +139 -0
  50. package/tsconfig.json +24 -0
@@ -0,0 +1,2 @@
1
+ # Run Biome check and auto-fix
2
+ npx @biomejs/biome check --write --unsafe --no-errors-on-unmatched .
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # Commic ✨
2
+
3
+ AI-powered Git commit message generator that creates beautiful, Conventional Commits compliant messages using Google's Gemini API.
4
+
5
+ ## Features
6
+
7
+ 🤖 **AI-Powered**: Leverages Google Gemini to analyze your changes and generate contextual commit messages
8
+ 📝 **Conventional Commits**: All messages follow the [Conventional Commits](https://www.conventionalcommits.org/) specification
9
+ 🎨 **Beautiful UI**: Colorful, emoji-enhanced terminal interface
10
+ ⚡ **Fast & Easy**: Interactive selection from 3-5 AI-generated suggestions
11
+ 🔧 **Flexible**: Works with any Git repository, supports custom paths
12
+
13
+ ## Installation
14
+
15
+ ### Global Installation
16
+
17
+ ```bash
18
+ npm install -g commic
19
+ ```
20
+
21
+ ### Local Development
22
+
23
+ ```bash
24
+ git clone <repository-url>
25
+ cd commic
26
+ npm install
27
+ npm link
28
+ ```
29
+
30
+ ## First-Time Setup
31
+
32
+ On your first run, Commic will guide you through a quick setup:
33
+
34
+ 1. **API Key**: You'll be prompted to enter your Google Gemini API key
35
+ - Get your free API key at [Google AI Studio](https://makersuite.google.com/app/apikey)
36
+
37
+ 2. **Model Selection**: Choose your preferred Gemini model
38
+ - Currently supports: Gemini 2.5 Flash
39
+
40
+ Your configuration is saved to `~/.commic/config.json` for future use.
41
+
42
+ ## Usage
43
+
44
+ ### Basic Usage
45
+
46
+ Run in your current Git repository:
47
+
48
+ ```bash
49
+ commic .
50
+ ```
51
+
52
+ ### Specify a Repository Path
53
+
54
+ Commit to a different repository:
55
+
56
+ ```bash
57
+ # Relative path
58
+ commic ../other-repo/
59
+
60
+ # Absolute path
61
+ commic /path/to/repository/
62
+ ```
63
+
64
+ ### Reconfigure
65
+
66
+ Update your API key or model preference:
67
+
68
+ ```bash
69
+ commic --reconfigure
70
+ ```
71
+
72
+ ## How It Works
73
+
74
+ 1. 🔍 **Analyzes** your Git changes (staged and unstaged)
75
+ 2. 🤖 **Generates** 3-5 commit message suggestions using AI
76
+ 3. 🎯 **Validates** all messages against Conventional Commits spec
77
+ 4. ✨ **Presents** an interactive menu for selection
78
+ 5. 🚀 **Commits** automatically with your chosen message
79
+
80
+ ## Conventional Commits Format
81
+
82
+ All generated messages follow this format:
83
+
84
+ ```
85
+ <type>[optional scope]: <description>
86
+
87
+ [optional body]
88
+
89
+ [optional footer(s)]
90
+ ```
91
+
92
+ ### Types
93
+
94
+ - `feat`: New feature
95
+ - `fix`: Bug fix
96
+ - `docs`: Documentation changes
97
+ - `style`: Code style changes (formatting, etc.)
98
+ - `refactor`: Code refactoring
99
+ - `test`: Adding or updating tests
100
+ - `chore`: Maintenance tasks
101
+ - `perf`: Performance improvements
102
+ - `ci`: CI/CD changes
103
+ - `build`: Build system changes
104
+
105
+ ### Examples
106
+
107
+ ```
108
+ feat(auth): add JWT authentication
109
+
110
+ fix: resolve memory leak in event handler
111
+
112
+ docs: update installation instructions
113
+
114
+ refactor(api)!: restructure endpoint handlers
115
+
116
+ BREAKING CHANGE: API endpoints now require authentication
117
+ ```
118
+
119
+ ## Troubleshooting
120
+
121
+ ### "No Git repository found"
122
+
123
+ Make sure you're running the command in a Git repository or providing a valid path to one.
124
+
125
+ ```bash
126
+ git init # Initialize a new repository if needed
127
+ ```
128
+
129
+ ### "Repository has no commits"
130
+
131
+ Create an initial commit first:
132
+
133
+ ```bash
134
+ git add .
135
+ git commit -m "Initial commit"
136
+ ```
137
+
138
+ ### "API key invalid"
139
+
140
+ Reconfigure with a valid API key:
141
+
142
+ ```bash
143
+ commic --reconfigure
144
+ ```
145
+
146
+ ### "No changes to commit"
147
+
148
+ Make some changes to your files first, or check if everything is already committed:
149
+
150
+ ```bash
151
+ git status
152
+ ```
153
+
154
+ ## Configuration
155
+
156
+ Configuration is stored at `~/.commic/config.json`:
157
+
158
+ ```json
159
+ {
160
+ "apiKey": "your-api-key",
161
+ "model": "gemini-2.5-flash",
162
+ "version": "1.0.0"
163
+ }
164
+ ```
165
+
166
+ ## Requirements
167
+
168
+ - Node.js >= 18.0.0
169
+ - Git installed and configured
170
+ - Google Gemini API key
171
+
172
+ ## Contributing
173
+
174
+ We welcome contributions from the open-source community! This guide will help you get started.
175
+
176
+ ### Development Setup
177
+
178
+ 1. **Fork and clone the repository**
179
+ ```bash
180
+ git clone https://github.com/your-username/commic.git
181
+ cd commic
182
+ ```
183
+
184
+ 2. **Install dependencies and set up Git hooks**
185
+ ```bash
186
+ npm install
187
+ ```
188
+
189
+ > **Note**: `npm install` automatically runs the `prepare` script which sets up Git hooks via Husky. If Git hooks don't work after installation, manually run `npm run prepare` to set them up.
190
+
191
+ 3. **Link the package locally for testing**
192
+ ```bash
193
+ npm link
194
+ ```
195
+
196
+ ### Code Quality & Linting
197
+
198
+ This project uses [Biome](https://biomejs.dev/) for linting and formatting to ensure consistent code quality.
199
+
200
+ #### Automatic Linting on Commit
201
+
202
+ We use [Husky](https://typicode.github.io/husky/) to automatically run linting and auto-fix issues before each commit. This ensures all code follows our standards:
203
+
204
+ - **Pre-commit hook**: Automatically runs `biome check --write --unsafe` before every commit
205
+ - **Auto-fix**: Automatically fixes linting issues that can be auto-fixed
206
+ - **Commit blocked**: If there are unfixable errors, the commit will be blocked
207
+
208
+ > **Setup**: Git hooks are automatically set up when you run `npm install` (via the `prepare` script). If hooks don't work, run `npm run prepare` manually.
209
+
210
+ You don't need to do anything special - just commit as normal, and the hook will handle the rest!
211
+
212
+ #### Manual Linting Commands
213
+
214
+ You can also run linting manually:
215
+
216
+ ```bash
217
+ # Check for linting issues
218
+ npm run lint
219
+
220
+ # Auto-fix linting issues
221
+ npm run lint:fix
222
+
223
+ # Format code only
224
+ npm run format
225
+ ```
226
+
227
+ #### Linting Rules
228
+
229
+ Our Biome configuration enforces:
230
+ - ✅ **Code formatting**: Consistent indentation, spacing, and line breaks
231
+ - ✅ **Import organization**: Automatic import sorting
232
+ - ✅ **Unused code detection**: Flags unused variables and imports
233
+ - ✅ **Best practices**: Enforces const usage, template literals, and more
234
+ - ⚠️ **TypeScript**: Warns on explicit `any` types
235
+
236
+ ### Making Changes
237
+
238
+ 1. **Create a feature branch**
239
+ ```bash
240
+ git checkout -b feat/your-feature-name
241
+ # or
242
+ git checkout -b fix/your-bug-fix
243
+ ```
244
+
245
+ 2. **Make your changes**
246
+ - Write clean, readable code
247
+ - Follow existing code patterns
248
+ - Add comments for complex logic
249
+
250
+ 3. **Test your changes**
251
+ ```bash
252
+ npm run build
253
+ npm run link # Test locally
254
+ ```
255
+
256
+ 4. **Commit your changes**
257
+ ```bash
258
+ commic .
259
+ ```
260
+
261
+ The pre-commit hook will automatically:
262
+ - Format your code
263
+ - Fix linting issues
264
+ - Organize imports
265
+
266
+ If there are errors that can't be auto-fixed, fix them manually and try again.
267
+
268
+ 5. **Push and create a Pull Request**
269
+ ```bash
270
+ git push origin feat/your-feature-name
271
+ ```
272
+
273
+ ### Commit Message Guidelines
274
+
275
+ We follow [Conventional Commits](https://www.conventionalcommits.org/) specification:
276
+
277
+ - `feat:` - New features
278
+ - `fix:` - Bug fixes
279
+ - `docs:` - Documentation changes
280
+ - `style:` - Code style changes (formatting, etc.)
281
+ - `refactor:` - Code refactoring
282
+ - `test:` - Adding or updating tests
283
+ - `chore:` - Maintenance tasks
284
+ - `ci:` - CI/CD changes
285
+ - `build:` - Build system changes
286
+
287
+ ### Pull Request Process
288
+
289
+ 1. Ensure your code passes all linting checks (handled automatically)
290
+ 2. Update documentation if needed
291
+ 3. Write clear commit messages
292
+ 4. Reference any related issues in your PR description
293
+ 5. Wait for code review and address feedback
294
+
295
+ ### Questions?
296
+
297
+ If you have questions or need help, feel free to:
298
+ - Open an issue for discussion
299
+ - Check existing issues and PRs
300
+ - Review the codebase to understand patterns
301
+
302
+ Thank you for contributing! 🎉
303
+
304
+ ## License
305
+
306
+ MIT
package/biome.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false
10
+ },
11
+ "formatter": {
12
+ "enabled": true,
13
+ "indentStyle": "space",
14
+ "indentWidth": 2,
15
+ "lineEnding": "lf",
16
+ "lineWidth": 100,
17
+ "formatWithErrors": false
18
+ },
19
+ "linter": {
20
+ "enabled": true,
21
+ "rules": {
22
+ "recommended": true,
23
+ "correctness": {
24
+ "noUnusedVariables": "error",
25
+ "noUnusedImports": "error"
26
+ },
27
+ "style": {
28
+ "useConst": "error",
29
+ "useTemplate": "error"
30
+ },
31
+ "suspicious": {
32
+ "noExplicitAny": "warn"
33
+ }
34
+ }
35
+ },
36
+ "javascript": {
37
+ "formatter": {
38
+ "quoteStyle": "single",
39
+ "jsxQuoteStyle": "double",
40
+ "trailingCommas": "es5",
41
+ "semicolons": "always",
42
+ "arrowParentheses": "always"
43
+ }
44
+ },
45
+ "json": {
46
+ "formatter": {
47
+ "enabled": true
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,51 @@
1
+ import type { CommitSuggestion, GitDiff } from '../types/index.js';
2
+ /**
3
+ * Handles AI-powered commit message generation using Google's Gemini API
4
+ */
5
+ export declare class AIService {
6
+ private readonly genAI;
7
+ private readonly model;
8
+ constructor(apiKey: string, modelName: string);
9
+ /**
10
+ * Build prompt for Gemini API to generate commit messages
11
+ * @param diff Git diff information
12
+ * @param count Number of suggestions to generate (3-5)
13
+ * @returns Formatted prompt string
14
+ */
15
+ private buildPrompt;
16
+ /**
17
+ * Parse API response into CommitSuggestion array
18
+ * Tries multiple parsing strategies for robustness
19
+ * @param response Raw response text from API
20
+ * @returns Array of commit suggestions
21
+ */
22
+ private parseResponse;
23
+ /**
24
+ * Filter and validate suggestions, returning only valid ones
25
+ * @param suggestions Array of suggestions to validate
26
+ * @returns Array of valid suggestions
27
+ */
28
+ private filterValidSuggestions;
29
+ /**
30
+ * Check if suggestions meet minimum requirements
31
+ * @param suggestions Array of suggestions to check
32
+ * @returns true if meets minimum requirements
33
+ */
34
+ private meetsMinimumRequirements;
35
+ /**
36
+ * Generate commit message suggestions using Gemini API
37
+ * @param diff Git diff information
38
+ * @param count Number of suggestions to generate (3-5)
39
+ * @returns Array of validated commit suggestions
40
+ * @throws APIError if API request fails
41
+ * @throws ValidationError if no valid suggestions generated
42
+ */
43
+ generateCommitMessages(diff: GitDiff, count?: number): Promise<CommitSuggestion[]>;
44
+ /**
45
+ * Generate a simple fallback commit message when AI fails
46
+ * @param diff Git diff information
47
+ * @returns Simple commit message or null
48
+ */
49
+ private generateFallbackMessage;
50
+ }
51
+ //# sourceMappingURL=AIService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIService.d.ts","sourceRoot":"","sources":["../../src/ai/AIService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGnE;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkB;gBAE5B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAK7C;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAwDnB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAsHrB;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAehC;;;;;;;OAOG;IACG,sBAAsB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAwH3F;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAsChC"}