ghostcommit 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alessandro Macri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,282 @@
1
+ # ghostcommit
2
+
3
+ **Your commits, ghostwritten by AI.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/ghostcommit.svg)](https://www.npmjs.com/package/ghostcommit)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ AI-powered commit message generator that **learns your style**, works **free out-of-the-box**, and handles diffs intelligently.
9
+
10
+ <p align="center">
11
+ <img src="demo.gif" alt="ghostcommit demo" width="900">
12
+ </p>
13
+
14
+ ## Why ghostcommit?
15
+
16
+ - **Free out-of-the-box** - Works instantly with Groq (free API) or Ollama (local). No paid accounts required.
17
+ - **Privacy option** - Run fully local with Ollama. Your code never leaves your machine.
18
+ - **Learns your style** - Analyzes your last 50 commits and adapts tone, format, scopes, and patterns.
19
+ - **Smart diff handling** - Filters lock files, chunks per-file, summarizes large diffs automatically.
20
+ - **Extra context** - Tell the AI what you did with `--context "migrated to OAuth2"`.
21
+ - **Branch-aware** - Reads `feature/JIRA-123-...` and includes ticket references.
22
+ - **Streaming output** - See the message as it generates, not a spinner.
23
+ - **Changelog generation** - Generate changelogs from your commit history with `ghostcommit log`.
24
+ - **GitHub Releases** - Create GitHub releases with auto-generated notes via `ghostcommit release`.
25
+ - **Git hook** - Install a `prepare-commit-msg` hook so every `git commit` gets an AI message automatically.
26
+ - **Amend** - Rewrite the last commit message with AI via `ghostcommit amend`.
27
+
28
+ ## Quick Start
29
+
30
+ ### Option 1: Groq (recommended - free, fast)
31
+
32
+ ```bash
33
+ npm install -g ghostcommit
34
+
35
+ # Get a free API key at https://console.groq.com/keys
36
+ export GROQ_API_KEY=your_key_here
37
+
38
+ git add .
39
+ ghostcommit
40
+ ```
41
+
42
+ ### Option 2: Ollama (local, private)
43
+
44
+ ```bash
45
+ npm install -g ghostcommit
46
+
47
+ # Install Ollama: https://ollama.ai
48
+ # The model downloads automatically on first run
49
+ ollama serve
50
+
51
+ git add .
52
+ ghostcommit
53
+ ```
54
+
55
+ ## Demo
56
+
57
+ ```
58
+ $ git add src/auth.ts src/middleware.ts
59
+
60
+ $ ghostcommit --context "added JWT refresh rotation"
61
+
62
+ ghostcommit
63
+
64
+ Analyzing 2 files (+47 -12)...
65
+
66
+ feat(auth): add JWT refresh token rotation
67
+
68
+ Implement automatic token rotation to prevent replay attacks.
69
+ Adds middleware for token validation with expiry tracking.
70
+
71
+ Refs PROJ-456
72
+
73
+ ----------------------------------------
74
+ [A]ccept [E]dit [R]egenerate [C]ancel? a
75
+
76
+ Commit created.
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ ```bash
82
+ # Commit messages
83
+ ghostcommit # Interactive (auto-detects provider)
84
+ ghostcommit --context "migrated auth to OAuth2" # Extra context for the AI
85
+ ghostcommit --provider groq # Use specific provider (groq, ollama, gemini, openai, anthropic)
86
+ ghostcommit --model gpt-4o # Override model
87
+ ghostcommit --yes # Auto-accept (great for scripts/CI)
88
+ ghostcommit --dry-run # Preview without committing
89
+ ghostcommit --no-style # Skip style learning
90
+
91
+ # Amend last commit message
92
+ ghostcommit amend # Regenerate last commit message
93
+ ghostcommit amend --context "actually a refactor" # With extra context
94
+ ghostcommit amend --dry-run # Preview without amending
95
+ ghostcommit amend --yes # Auto-accept
96
+
97
+ # Git hook (auto-generate on every git commit)
98
+ ghostcommit hook install # Install prepare-commit-msg hook
99
+ ghostcommit hook uninstall # Remove the hook
100
+
101
+ # Changelog
102
+ ghostcommit log # Generate changelog from last tag
103
+ ghostcommit log --from v1.0.0 --to v2.0.0 # Specific range
104
+ ghostcommit log --format json # JSON output
105
+ ghostcommit log --output CHANGELOG.md # Write to file
106
+
107
+ # Release
108
+ ghostcommit release v1.0.0 # Create GitHub release with changelog
109
+
110
+ # Config
111
+ ghostcommit init # Create .ghostcommit.yml config
112
+ ghostcommit --version # Show version
113
+ ```
114
+
115
+ ## Providers
116
+
117
+ | Provider | Cost | Privacy | Speed | Setup |
118
+ |----------|------|---------|-------|-------|
119
+ | **Groq** | Free | Cloud | ~1s | Set `GROQ_API_KEY` ([get key](https://console.groq.com/keys)) |
120
+ | **Gemini** | Free tier | Cloud | ~1-2s | Set `GEMINI_API_KEY` ([get key](https://aistudio.google.com/apikey)) |
121
+ | **Ollama** | Free | Local | ~5-30s | [Install Ollama](https://ollama.ai) (model auto-downloads) |
122
+ | **OpenAI** | Paid | Cloud | ~1-2s | Set `OPENAI_API_KEY` |
123
+ | **Anthropic** | Paid | Cloud | ~1-2s | Set `ANTHROPIC_API_KEY` |
124
+
125
+ ```bash
126
+ # Use a specific provider
127
+ ghostcommit --provider groq
128
+ ghostcommit --provider gemini
129
+ ghostcommit --provider ollama
130
+ ghostcommit --provider openai
131
+ ghostcommit --provider anthropic
132
+
133
+ # Override the model
134
+ ghostcommit --provider openai --model gpt-4o
135
+ ghostcommit --provider anthropic --model claude-sonnet-4-5-20250929
136
+ ghostcommit --provider gemini --model gemini-2.0-flash
137
+ ghostcommit --provider ollama --model qwen2.5-coder:3b
138
+ ```
139
+
140
+ **Auto-detection**: If no provider is configured, ghostcommit tries Groq (if `GROQ_API_KEY` is set), then Ollama (if running). If neither is available, it shows setup instructions.
141
+
142
+ ### Default Models
143
+
144
+ | Provider | Default Model |
145
+ |----------|--------------|
146
+ | Groq | `llama-3.3-70b-versatile` |
147
+ | Gemini | `gemini-2.0-flash` |
148
+ | Ollama | `qwen2.5-coder:0.5b` (auto-downloads) |
149
+ | OpenAI | `gpt-4o-mini` |
150
+ | Anthropic | `claude-haiku-4-5-20251001` |
151
+
152
+ ## Configuration
153
+
154
+ Create `.ghostcommit.yml` in your project root (or `~/.ghostcommit.yml` for global):
155
+
156
+ ```yaml
157
+ provider: groq
158
+ model: llama-3.3-70b-versatile
159
+ language: en
160
+ learnStyle: true
161
+ learnStyleCommits: 50
162
+ ignorePaths:
163
+ - "*.generated.ts"
164
+ - "migrations/"
165
+ branchPrefix: true
166
+ branchPattern: "[A-Z]+-\\d+"
167
+ changelog:
168
+ format: markdown # markdown | json | plain
169
+ output: CHANGELOG.md
170
+ exclude:
171
+ - "^chore\\(deps\\)" # exclude dependency bumps
172
+ release:
173
+ draft: true # create as draft by default
174
+ ```
175
+
176
+ Or run `ghostcommit init` to create one interactively.
177
+
178
+ **Priority**: CLI flags > project config > global config > defaults
179
+
180
+ ## How It Works
181
+
182
+ 1. **Reads staged changes** (`git diff --staged`)
183
+ 2. **Filters noise** - Removes lock files, generated code, build artifacts at git level
184
+ 3. **Learns your style** - Analyzes recent commits for patterns (conventional commits, scopes, language, emoji)
185
+ 4. **Builds smart prompt** - Combines diff + style guide + branch context + your extra context
186
+ 5. **Generates message** - Streams the AI response in real-time
187
+ 6. **You decide** - Accept, edit in `$EDITOR`, regenerate, or cancel
188
+
189
+ ## Features
190
+
191
+ ### Style Learning
192
+
193
+ ghostcommit analyzes your last 50 commits and detects:
194
+ - Conventional Commits usage (`feat:`, `fix:`, etc.)
195
+ - Common scopes (`auth`, `api`, `ui`)
196
+ - Language (English, Italian, mixed)
197
+ - Average subject length
198
+ - Emoji/gitmoji usage
199
+ - Ticket reference patterns
200
+
201
+ This is cached in `.ghostcommit-cache.json` and auto-refreshes.
202
+
203
+ ### Smart Diff Processing
204
+
205
+ - Excludes lock files and build artifacts directly at git level (fast)
206
+ - Chunks diff per-file for better analysis
207
+ - For large diffs (>2000 tokens): prioritizes source files, truncates individual files, summarizes the rest
208
+ - Initial commits with many files: sends only file list (not full diff) for speed
209
+ - Detects renames/moves
210
+
211
+ ### Branch Context
212
+
213
+ If your branch is `feature/PROJ-123-add-oauth`, ghostcommit automatically suggests including `PROJ-123` in the commit message. Configurable via `branchPattern`.
214
+
215
+ ### Changelog Generation
216
+
217
+ Generate changelogs from your commit history:
218
+
219
+ ```bash
220
+ ghostcommit log # From last tag to HEAD
221
+ ghostcommit log --from v1.0.0 # From specific ref
222
+ ghostcommit log --format json # JSON output
223
+ ```
224
+
225
+ Uses hybrid categorization: regex for conventional commits (instant), AI only for freeform messages.
226
+
227
+ ### Git Hook
228
+
229
+ Install a `prepare-commit-msg` hook so every `git commit` automatically gets an AI-generated message:
230
+
231
+ ```bash
232
+ ghostcommit hook install
233
+ ```
234
+
235
+ Now just use git as usual — the message is pre-filled for you:
236
+
237
+ ```bash
238
+ git add src/auth.ts
239
+ git commit # message auto-generated, opens editor to review
240
+ git commit -m "my message" # hook skips when you provide -m (your message wins)
241
+ ```
242
+
243
+ To remove the hook:
244
+
245
+ ```bash
246
+ ghostcommit hook uninstall
247
+ ```
248
+
249
+ The hook never blocks your commit. If ghostcommit fails (no API key, network error), `git commit` proceeds normally.
250
+
251
+ ### Amend
252
+
253
+ Rewrite the last commit message with a fresh AI-generated one:
254
+
255
+ ```bash
256
+ ghostcommit amend
257
+ ```
258
+
259
+ Shows the current message, generates a new one from the same diff, and lets you accept, edit, regenerate, or cancel. Supports `--context`, `--dry-run`, `--yes`, and all provider flags.
260
+
261
+ ### GitHub Releases
262
+
263
+ Create GitHub releases with auto-generated changelog:
264
+
265
+ ```bash
266
+ export GITHUB_TOKEN=your_token
267
+ ghostcommit release v1.0.0
268
+ ```
269
+
270
+ ## Development
271
+
272
+ ```bash
273
+ git clone https://github.com/Alessandro-Mac7/ghostcommit.git
274
+ cd ghostcommit
275
+ npm install
276
+ npm run build
277
+ npm test
278
+ ```
279
+
280
+ ## License
281
+
282
+ MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/index.js";
@@ -0,0 +1,2 @@
1
+
2
+ export { }