@kyubiware/commit-mint 0.4.2 → 0.5.1

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/README.md CHANGED
@@ -1,6 +1,53 @@
1
- # commit-mint
1
+ # 🌿 commit-mint
2
2
 
3
- > commit-mint groups changed files into individual commits, generates commit messages, and cleanly handles commit hook failures. It wraps the entire commit lifecycle — stage, generate, review, attempt, recover, retry — so you never lose a message or stare at raw hook output again.
3
+ [![npm version](https://img.shields.io/npm/v/@kyubiware/commit-mint.svg)](https://www.npmjs.com/package/@kyubiware/commit-mint)
4
+
5
+ > Auto-group your changes into clean, conventional commits. AI handles the grouping, messages, and hook failures so you don't have to.
6
+
7
+ ```
8
+ ┌ 🌿 commit-mint
9
+
10
+ ◇ Files analyzed
11
+
12
+ ● Commit group 1 of 3: "Reading view refactor"
13
+
14
+ ◇ Message generated
15
+
16
+ ● feat(compound): add compound utilities and token handling for text study
17
+
18
+ ◇ Committed successfully.
19
+
20
+ ● ✓ prettier
21
+ │ ✓ eslint
22
+ │ ✓ tsc
23
+ │ ✓ vitest
24
+ ◇ Message generated
25
+
26
+ ● feat(text-study): add compound component support to ReadingInspectorPanel
27
+
28
+ ◇ Committed successfully.
29
+
30
+ ● ✓ prettier
31
+ │ ✓ eslint
32
+ │ ✓ tsc
33
+ │ ✓ vitest
34
+
35
+ ● Commit group 3 of 3: "Reading study list update"
36
+ ◇ Message generated
37
+
38
+ ● feat(reading-study-list-body): add compound component support to reading study list
39
+
40
+ ◇ Committed successfully.
41
+
42
+ ● ✓ prettier
43
+ │ ✓ eslint
44
+ │ ✓ tsc
45
+ │ ✓ vitest
46
+
47
+ └ All groups committed.
48
+ ```
49
+
50
+ Requires **Node.js 18+**.
4
51
 
5
52
  ## Quick Start
6
53
 
@@ -9,46 +56,65 @@ npm install -g @kyubiware/commit-mint
9
56
  ```
10
57
 
11
58
  ```bash
12
- cmint
59
+ cmint -a
13
60
  ```
14
61
 
15
- Requires **Node.js 18+**.
62
+ On first run, you'll be prompted for a `GROQ_API_KEY` if it's not set in `~/.commit-mint` or as an environment variable. It's saved for future runs.
16
63
 
17
- ```
18
- stage files → generate message → review message → attempt commit → hooks fail?
19
- ├─ copy errors to clipboard
20
- ├─ skip hooks & commit
21
- ├─ re-stage & retry
22
- ├─ edit message
23
- └─ cancel (cached for --retry)
24
- ```
64
+ ## Why commit-mint?
65
+
66
+ - **Auto-group by intent.** AI reads your diff and groups files into logical commits. No more `feat: update stuff` that bundles unrelated changes.
67
+ - **Zero-prompt auto mode.** `cmint -a` stages, groups, generates messages, and commits without a single prompt. Walk away and come back to clean history.
68
+ - **Hook failures handled in-flow.** When pre-commit hooks fail, you get a parsed error summary and a menu to copy, skip, retry, or edit. No raw stderr dumps.
69
+ - **Built-in pre-commit checks.** Define checks in a cmint config file and run them before AI generation. A failing check never wastes an API call.
70
+ - **Message caching on failure.** A failed commit caches its message. Fix the error, run `cmint --retry`, and pick up exactly where you left off.
71
+
72
+ ## Auto mode (`-a`)
73
+
74
+ `cmint -a` is the primary way to use commit-mint. It runs the full pipeline with no prompts:
75
+
76
+ 1. AI analyzes all changed files
77
+ 2. Files are grouped into logical commits by intent
78
+ 3. Each group gets its own AI-generated conventional commit message
79
+ 4. Groups are committed sequentially
80
+ 5. Hook failures per group trigger the recovery menu
81
+
82
+ Use this when you want clean history without the ceremony.
83
+
84
+ ## Manual mode
85
+
86
+ Run `cmint` without flags for the interactive flow:
87
+
88
+ 1. **Staging menu** — stage all, select files, auto-group, or cancel
89
+ 2. **File selection** — multi-select specific files if you don't want everything
90
+ 3. **Message review** — review the AI-generated message before committing
91
+ 4. **Commit attempt** — hooks run, recovery menu appears on failure
92
+
93
+ If only one file changed, it's staged automatically.
25
94
 
26
95
  ## Usage
27
96
 
28
97
  ```bash
29
- # Normal commit flow (interactive staging if multiple files)
30
- cmint
31
-
32
- # Auto-group files into commits with auto-accepted messages (no prompts)
98
+ # Auto-group and commit everything (no prompts)
33
99
  cmint -a
34
100
 
101
+ # Normal interactive flow
102
+ cmint
103
+
35
104
  # Skip AI, provide your own message
36
105
  cmint -m "feat: add dark mode"
37
106
 
38
- # Pass context hint to AI for better messages
107
+ # Pass context hint for better messages
39
108
  cmint -H "refactoring auth module"
40
- cmint --hint "splitting monolith into services"
41
109
 
42
110
  # Retry last failed commit (uses cached message)
43
- cmint --retry
44
111
  cmint -r
45
112
 
46
- # Review staged changes with AI
47
- cmint --review
48
- cmint -R
113
+ # Skip pre-commit checks
114
+ cmint -n
49
115
 
50
- # Debug mode — timestamped stderr output
51
- cmint --debug
116
+ # Debug mode
117
+ cmint -d
52
118
 
53
119
  # Configuration
54
120
  cmint config get GROQ_API_KEY
@@ -56,49 +122,25 @@ cmint config set GROQ_API_KEY=gsk_...
56
122
  cmint config set model openai/gpt-oss-20b
57
123
  ```
58
124
 
59
- ### First run
60
-
61
- If no `GROQ_API_KEY` is set in `~/.commit-mint` or `$GROQ_API_KEY`, you'll be prompted to enter one. It's saved to `~/.commit-mint` for future runs.
62
-
63
- ### Interactive staging
64
-
65
- When you have multiple changed files, commit-mint shows an interactive staging menu:
66
-
67
- - **Stage all files** auto-stage everything
68
- - **Select files** multi-select specific files to stage
69
- - **Auto-group into commits** — AI groups files into logical commits (see below)
70
- - **Cancel**
71
-
72
- If only one file has changed, it's staged automatically.
73
-
74
- ### Auto-group
75
-
76
- The auto-group feature uses AI to analyze your changed files and group them into logical, cohesive commits. Each group is committed separately with its own AI-generated message.
77
-
78
- ```
79
- 1. AI analyzes changed files → proposes groups (name, description, files)
80
- 2. You confirm or cancel the groupings
81
- 3. For each group: stage → generate message → review → commit
82
- 4. Hook failures show the recovery menu per-group
83
- ```
84
-
85
- Select "Auto-group into commits" from the staging menu, or use `cmint --auto` / `cmint -a` to auto-group and auto-accept all commit messages with no prompts.
125
+ | Flag | Description |
126
+ |------|-------------|
127
+ | `-a, --auto` | Auto-group files into commits, accept all messages |
128
+ | `-m, --message` | Provide a commit message directly (skip AI) |
129
+ | `-H, --hint` | Add context hint for AI message generation |
130
+ | `-r, --retry` | Retry the last failed commit |
131
+ | `-n, --noCheck` | Skip pre-commit checks |
132
+ | `-d, --debug` | Enable debug output |
133
+ | `-h, --help` | Show help |
134
+ | `-v, --version` | Show version |
86
135
 
87
- ### Message review
136
+ ## Message review
88
137
 
89
- Before every commit, you can review the generated message:
138
+ Before every commit, choose what to do with the generated message:
90
139
 
91
140
  - **Use as-is** — accept the AI-generated message
92
141
  - **Edit** — modify the message in a prompt
93
- - **Review with OpenCode** — run a code review on your staged changes before committing
94
142
  - **Cancel** — exit (message is cached for `--retry`)
95
143
 
96
- ### Code review
97
-
98
- Use `cmint --review` or `cmint -R` to review staged changes without committing. commit-mint checks for [OpenCode](https://github.com/opencode-ai/opencode) first — if available, it uses OpenCode for the review. Otherwise, it falls back to the Groq API.
99
-
100
- The review looks for bugs, security issues, performance problems, code quality, and edge cases. Results are shown in a structured report, with an option to copy findings to clipboard.
101
-
102
144
  ## Recovery menu
103
145
 
104
146
  When a pre-commit hook blocks your commit, commit-mint parses the error output and presents an interactive menu:
@@ -122,23 +164,71 @@ When a pre-commit hook blocks your commit, commit-mint parses the error output a
122
164
 
123
165
  | Option | What it does |
124
166
  |--------|-------------|
125
- | **Copy error report** | Copies parsed, clean error output to clipboard — paste it into another terminal for an AI agent to fix |
126
- | **Skip hooks** | Re-runs `git commit --no-verify` with the same message — for when hooks are wrong or you'll fix later |
127
- | **Re-stage & retry** | Runs `git add -A` again (picks up fixes made in another terminal), then retries the commit |
167
+ | **Copy error report** | Copies parsed, clean error output to clipboard |
168
+ | **Skip hooks** | Re-runs `git commit --no-verify` with the same message |
169
+ | **Re-stage & retry** | Runs `git add -A` again, then retries the commit |
128
170
  | **Edit message** | Opens a prompt to modify the commit message, then retries |
129
171
  | **Cancel** | Exits. Commit message is cached for `cmint --retry` |
130
172
 
131
- ### Supported hook tools
173
+ The recovery menu also appears when cmint config pre-commit checks fail.
174
+
175
+ commit-mint parses errors from **lint-staged**, **biome**, **TypeScript** (`tsc`), **vitest** / **jest**, and **ESLint**. Unrecognized output falls back to raw stderr.
176
+
177
+ ## Pre-commit checks
178
+
179
+ Define custom checks in a cmint config file at your project root. Supported file names (checked in priority order):
180
+ `.cmintrc`, `.cmintrc.json`, `.cmintrc.{mjs,mts,js,ts,cjs,cts}`, `cmint.config.{mjs,mts,js,ts,cjs,cts}`
181
+
182
+ They run after staging, before AI message generation, so a failing check never wastes an API call.
183
+
184
+ ```js
185
+ export default {
186
+ // String: matched files are appended as arguments
187
+ "*.{js,ts,json}": "biome check --write --no-errors-on-unmatched",
188
+
189
+ // Function: receive matched filenames, return command(s)
190
+ "*.ts": () => ["tsc --noEmit", "vitest run --passWithNoTests"],
191
+ };
192
+ ```
193
+
194
+ Glob patterns use [picomatch](https://github.com/micromatch/picomatch). String commands receive matched files as trailing arguments. Functions receive the matched file list and return one or more commands to run.
195
+
196
+ ### TypeScript config
197
+
198
+ Use `.cmintrc.ts` or `cmint.config.ts` for type safety without adding commit-mint as a project dependency. Add an inline interface and use `satisfies`:
199
+
200
+ ```ts
201
+ interface Cmintrc {
202
+ [glob: string]: string | string[] | ((filenames: string[]) => string | string[]);
203
+ }
204
+
205
+ export default {
206
+ "*.{js,ts,json}": "biome check --write --no-errors-on-unmatched",
207
+ "*.ts": () => ["tsc --noEmit", "vitest run --passWithNoTests"],
208
+ } satisfies Cmintrc;
209
+ ```
210
+
211
+ This gives you editor autocomplete and catches invalid values (e.g. numbers, objects) at edit time — no package install needed.
212
+
213
+ Checks execute sequentially and fail fast. Each command has a 60-second timeout.
132
214
 
133
- commit-mint parses errors from:
215
+ ### When checks run
134
216
 
135
- - **lint-staged** task failure detection
136
- - **biome** lint/format errors with file:line:col
137
- - **TypeScript** (`tsc`) type errors with TS error codes
138
- - **vitest** / **jest** — test failure detection
139
- - **ESLint** — lint error/warning detection
217
+ - **Manual mode**: The staging menu shows a "Run checks" option when a cmint config file exists
218
+ - **Auto-group mode**: Checks run automatically on all staged files before grouping
219
+ - **Normal commit**: Checks run on staged files after staging, before diff/AI
140
220
 
141
- Unrecognized error output is shown as raw fallback.
221
+ ### Check failure menu
222
+
223
+ When a check fails, you get a menu with three options:
224
+
225
+ | Option | What it does |
226
+ |--------|-------------|
227
+ | **Copy error report** | Copies the error output to clipboard |
228
+ | **Skip checks** | Proceeds without running checks |
229
+ | **Cancel** | Exits. Message is cached for `cmint --retry` |
230
+
231
+ Pass `--noCheck` or `-n` to skip checks entirely.
142
232
 
143
233
  ## Configuration
144
234
 
@@ -178,7 +268,7 @@ cmint --help
178
268
  --auto, -a Auto-group files into commits, accept all messages (default: false)
179
269
  --message, -m Provide a commit message directly (skip AI generation)
180
270
  --hint, -H Add context hint for AI commit message generation
181
- --review, -R Review staged changes with a coding model (default: false)
271
+ --noCheck, -n Skip pre-commit checks (default: false)
182
272
  --debug, -d Enable debug output (default: false)
183
273
  --help, -h Show help
184
274
  --version, -v Show version
@@ -189,7 +279,7 @@ cmint --help
189
279
 
190
280
  ## Retry persistence
191
281
 
192
- Failed commit messages are cached to `~/.cache/commit-mint/<repo-hash>.json`. Running `cmint --retry` reuses the last message without regenerating useful after fixing errors flagged by the recovery menu.
282
+ Failed commit messages are cached to `~/.cache/commit-mint/<repo-hash>.json`. Running `cmint --retry` reuses the last message without regenerating. Fix errors in another terminal, come back, and retry.
193
283
 
194
284
  ## How it works
195
285
 
@@ -200,37 +290,24 @@ commit-mint/
200
290
  │ ├── commands/
201
291
  │ │ ├── commit.ts # Main commit flow orchestrator
202
292
  │ │ ├── auto-group.ts # Auto-group multi-commit flow
203
- │ │ ├── review.ts # Code review command
204
293
  │ │ └── config.ts # Config get/set subcommand
205
294
  │ ├── services/
206
295
  │ │ ├── git.ts # Git operations (stage, commit, diff, HEAD)
207
296
  │ │ ├── ai.ts # Groq AI commit message generation (3-tier diff compression)
208
297
  │ │ ├── grouping.ts # AI-powered file grouping into logical commits
209
- │ │ ├── review-ai.ts # AI code review via Groq
210
298
  │ │ ├── hooks.ts # Hook error parser (lint-staged, biome, tsc, etc.)
299
+ │ │ ├── checks.ts # Pre-commit checks via cmint config files (glob matching, command execution)
211
300
  │ │ ├── config.ts # INI config read/write at ~/.commit-mint
212
301
  │ │ └── clipboard.ts # Cross-platform clipboard (xclip/wl-copy/pbcopy)
213
302
  │ ├── ui/
214
303
  │ │ ├── menu.ts # Interactive recovery TUI + staging menu
215
304
  │ │ ├── grouping.ts # Grouping confirmation UI
216
- │ │ └── review-message.ts # Message review step (use/edit/review/cancel)
305
+ │ │ └── review-message.ts # Message review step (use/edit/cancel)
217
306
  │ └── utils/
218
307
  │ ├── cache.ts # Commit message persistence at ~/.cache/commit-mint/
219
308
  │ └── debug.ts # Timestamped debug logging to stderr
220
309
  ```
221
310
 
222
- ## Key differentiators
223
-
224
- 1. **Hook error parsing** — No other commit tool parses lint-staged/biome/eslint output into a clean summary
225
- 2. **Interactive recovery menu** — Copy/skip/retry/edit as an in-flow choice, not a manual post-mortem
226
- 3. **Message caching on failure** — `--retry` restores the last message without regenerating
227
- 4. **Re-stage & retry loop** — Fix errors in another terminal, come back, hit "re-stage & retry"
228
- 5. **Auto-group** — AI groups changed files into logical commits, each committed separately
229
- 6. **In-flow code review** — Review staged changes with OpenCode or Groq before committing
230
- 7. **Message review step** — Accept, edit, or review the AI-generated message before committing
231
- 8. **Post-commit summary** — Shows which hook tools passed/failed after every successful commit
232
- 9. **Clipboard integration** — Copy error report and hand it to an AI coding agent for fixes
233
-
234
311
  ## Requirements
235
312
 
236
313
  - **Node.js 18+**
@@ -240,7 +317,7 @@ commit-mint/
240
317
 
241
318
  ## Non-goals
242
319
 
243
- - Not a hook manager — use husky, lefthook
320
+ - Not a git hook manager — cmint config checks run in-flow, not via git hooks. For git hooks, use husky or lefthook
244
321
  - Not a linter/formatter — use biome, eslint, prettier
245
322
  - Not a git TUI — use lazygit, gitui
246
323
  - Not a commitizen replacement — just generates conventional commit messages via AI