gitmage 0.1.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) 2026 long260398
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,118 @@
1
+ # gitmage
2
+
3
+ > Generate conventional commit messages from staged changes using AI — free with Groq, or higher quality with Claude.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![npm version](https://img.shields.io/npm/v/gitmage.svg)](https://www.npmjs.com/package/gitmage)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)](https://nodejs.org)
8
+
9
+ ## Demo
10
+
11
+ ```bash
12
+ $ git add src/auth.ts
13
+ $ gitmage
14
+
15
+ gitmage · AI-powered git commits
16
+
17
+ ⠙ Generating commit message...
18
+
19
+ ✔ Suggested commit message:
20
+
21
+ ❯ feat(auth): add JWT token validation middleware
22
+
23
+ Press Enter to confirm, or type to edit (Ctrl+C to cancel):
24
+ >
25
+
26
+ ✔ Committed: feat(auth): add JWT token validation middleware
27
+ ```
28
+
29
+ ## Features
30
+
31
+ - **Zero configuration** — set your API key once, run `gitmage` anywhere
32
+ - **Always conventional** — follows `feat/fix/docs/chore` format automatically
33
+ - **Edit before commit** — review and change the message before it lands
34
+ - **Dry run mode** — preview without committing: `gitmage --dry-run`
35
+ - **Works with any stack** — language and framework agnostic
36
+
37
+ ## Getting Started
38
+
39
+ ### Prerequisites
40
+
41
+ - Node.js 18+
42
+ - An API key — **Groq is free**, Claude is paid but higher quality
43
+
44
+ ### Install
45
+
46
+ ```bash
47
+ npm install -g gitmage
48
+ ```
49
+
50
+ Or try without installing:
51
+
52
+ ```bash
53
+ npx gitmage --dry-run
54
+ ```
55
+
56
+ ### Set your API key
57
+
58
+ **Option 1 — Groq (free):** [console.groq.com](https://console.groq.com)
59
+
60
+ ```bash
61
+ # Mac / Linux
62
+ export GROQ_API_KEY=gsk_your-key-here
63
+
64
+ # Windows PowerShell
65
+ $env:GROQ_API_KEY="gsk_your-key-here"
66
+ ```
67
+
68
+ **Option 2 — Claude (higher quality):** [console.anthropic.com](https://console.anthropic.com) — ~$0.0001/commit
69
+
70
+ ```bash
71
+ # Mac / Linux
72
+ export ANTHROPIC_API_KEY=sk-ant-your-key-here
73
+
74
+ # Windows PowerShell
75
+ $env:ANTHROPIC_API_KEY="sk-ant-your-key-here"
76
+ ```
77
+
78
+ The tool auto-detects which key is set. Set one and run.
79
+
80
+ ## Usage
81
+
82
+ Stage your changes, then run:
83
+
84
+ ```bash
85
+ git add .
86
+ gitmage
87
+ ```
88
+
89
+ Preview without committing:
90
+
91
+ ```bash
92
+ gitmage --dry-run
93
+ ```
94
+
95
+ Check version:
96
+
97
+ ```bash
98
+ gitmage --version
99
+ ```
100
+
101
+ ## Stack
102
+
103
+ - **Runtime**: Node.js 18+
104
+ - **Language**: TypeScript
105
+ - **AI**: Groq (Llama 3.3, free) or Claude Haiku (paid)
106
+ - **Format**: Conventional Commits
107
+
108
+ ## Contributing
109
+
110
+ Pull requests are welcome. For major changes, open an issue first.
111
+
112
+ ## License
113
+
114
+ [MIT](LICENSE)
115
+
116
+ ## Support
117
+
118
+ If this saves you time on every commit, consider [sponsoring on GitHub](https://github.com/sponsors/long260398).
package/bin/ai-commit ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ require('../dist/index.js');
package/dist/ai.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Config } from './config';
2
+ export declare function generateMessage(diff: string, config: Config): Promise<string>;
package/dist/ai.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateMessage = generateMessage;
7
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
8
+ const groq_sdk_1 = __importDefault(require("groq-sdk"));
9
+ const prompt_1 = require("./prompt");
10
+ const MAX_DIFF_CHARS = 8000;
11
+ async function generateMessage(diff, config) {
12
+ const truncated = diff.length > MAX_DIFF_CHARS
13
+ ? diff.slice(0, MAX_DIFF_CHARS) + '\n\n[diff truncated]'
14
+ : diff;
15
+ const userMessage = `Generate a commit message for this diff:\n\n${truncated}`;
16
+ if (config.provider === 'groq') {
17
+ return generateWithGroq(userMessage, config.apiKey);
18
+ }
19
+ return generateWithClaude(userMessage, config.apiKey);
20
+ }
21
+ async function generateWithGroq(userMessage, apiKey) {
22
+ const client = new groq_sdk_1.default({ apiKey });
23
+ const response = await client.chat.completions.create({
24
+ model: 'llama-3.3-70b-versatile',
25
+ max_tokens: 100,
26
+ messages: [
27
+ { role: 'system', content: prompt_1.SYSTEM_PROMPT },
28
+ { role: 'user', content: userMessage },
29
+ ],
30
+ });
31
+ const text = response.choices[0]?.message?.content;
32
+ if (!text) {
33
+ throw new Error('Empty response from Groq API');
34
+ }
35
+ return text.trim();
36
+ }
37
+ async function generateWithClaude(userMessage, apiKey) {
38
+ const client = new sdk_1.default({ apiKey });
39
+ const response = await client.messages.create({
40
+ model: 'claude-haiku-4-5-20251001',
41
+ max_tokens: 100,
42
+ system: prompt_1.SYSTEM_PROMPT,
43
+ messages: [{ role: 'user', content: userMessage }],
44
+ });
45
+ const block = response.content[0];
46
+ if (block.type !== 'text') {
47
+ throw new Error('Unexpected response type from Claude API');
48
+ }
49
+ return block.text.trim();
50
+ }
51
+ //# sourceMappingURL=ai.js.map
package/dist/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":";;;;;AAOA,0CAaC;AApBD,4DAA0C;AAC1C,wDAA4B;AAC5B,qCAAyC;AAGzC,MAAM,cAAc,GAAG,IAAI,CAAC;AAErB,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,MAAc;IAChE,MAAM,SAAS,GACb,IAAI,CAAC,MAAM,GAAG,cAAc;QAC1B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG,sBAAsB;QACxD,CAAC,CAAC,IAAI,CAAC;IAEX,MAAM,WAAW,GAAG,+CAA+C,SAAS,EAAE,CAAC;IAE/E,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC/B,OAAO,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,WAAmB,EAAE,MAAc;IACjE,MAAM,MAAM,GAAG,IAAI,kBAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;I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ider;
4
+ apiKey: string;
5
+ }
6
+ export declare function getConfig(): Config;
package/dist/config.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getConfig = getConfig;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ function getConfig() {
9
+ const groqKey = process.env.GROQ_API_KEY;
10
+ const claudeKey = process.env.ANTHROPIC_API_KEY;
11
+ if (groqKey) {
12
+ return { provider: 'groq', apiKey: groqKey };
13
+ }
14
+ if (claudeKey) {
15
+ return { provider: 'claude', apiKey: claudeKey };
16
+ }
17
+ console.error(chalk_1.default.red('\n Error: No API key found.\n'));
18
+ console.error(chalk_1.default.bold(' Option 1 — Groq (free):'));
19
+ console.error(chalk_1.default.dim(' Sign up : https://console.groq.com'));
20
+ console.error(chalk_1.default.dim(' Mac/Linux: export GROQ_API_KEY=gsk_...'));
21
+ console.error(chalk_1.default.dim(' Windows : $env:GROQ_API_KEY="gsk_..."\n'));
22
+ console.error(chalk_1.default.bold(' Option 2 — Claude (paid, higher quality):'));
23
+ console.error(chalk_1.default.dim(' Sign up : https://console.anthropic.com'));
24
+ console.error(chalk_1.default.dim(' Mac/Linux: export ANTHROPIC_API_KEY=sk-ant-...'));
25
+ console.error(chalk_1.default.dim(' Windows : $env:ANTHROPIC_API_KEY="sk-ant-..."\n'));
26
+ process.exit(1);
27
+ }
28
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AASA,8BAsBC;AA/BD,kDAA0B;AAS1B,SAAgB,SAAS;IACvB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IACzC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAEhD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC/C,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAAC;IAC3D,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC;IACvD,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC,CAAC;IACpE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC,CAAC;IAC/E,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC,CAAC;IACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
package/dist/git.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function isGitRepo(): boolean;
2
+ export declare function getStagedDiff(): string;
3
+ export declare function runCommit(message: string): void;
package/dist/git.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGitRepo = isGitRepo;
4
+ exports.getStagedDiff = getStagedDiff;
5
+ exports.runCommit = runCommit;
6
+ const child_process_1 = require("child_process");
7
+ function isGitRepo() {
8
+ try {
9
+ (0, child_process_1.execSync)('git rev-parse --git-dir', { stdio: 'pipe' });
10
+ return true;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
16
+ function getStagedDiff() {
17
+ const result = (0, child_process_1.spawnSync)('git', ['diff', '--staged'], { encoding: 'utf-8' });
18
+ if (result.error) {
19
+ throw new Error('git not found. Please install git and try again.');
20
+ }
21
+ return result.stdout;
22
+ }
23
+ function runCommit(message) {
24
+ const result = (0, child_process_1.spawnSync)('git', ['commit', '-m', message], { stdio: 'inherit' });
25
+ if (result.status !== 0) {
26
+ throw new Error('git commit failed');
27
+ }
28
+ }
29
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":";;AAEA,8BAOC;AAED,sCAQC;AAED,8BAMC;AA3BD,iDAAoD;AAEpD,SAAgB,SAAS;IACvB,IAAI,CAAC;QACH,IAAA,wBAAQ,EAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAgB,aAAa;IAC3B,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAE7E,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,SAAgB,SAAS,CAAC,OAAe;IACvC,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const package_json_1 = require("../package.json");
8
+ const git_1 = require("./git");
9
+ const ai_1 = require("./ai");
10
+ const config_1 = require("./config");
11
+ const ui_1 = require("./ui");
12
+ const args = process.argv.slice(2);
13
+ const isDryRun = args.includes('--dry-run') || args.includes('-d');
14
+ const isVersion = args.includes('--version') || args.includes('-v');
15
+ async function main() {
16
+ if (isVersion) {
17
+ console.log(package_json_1.version);
18
+ process.exit(0);
19
+ }
20
+ (0, ui_1.printHeader)();
21
+ if (!(0, git_1.isGitRepo)()) {
22
+ console.error(chalk_1.default.red(' Error: not a git repository.\n'));
23
+ process.exit(1);
24
+ }
25
+ const diff = (0, git_1.getStagedDiff)();
26
+ if (!diff.trim()) {
27
+ console.log(chalk_1.default.yellow(' Nothing staged.') +
28
+ chalk_1.default.dim(' Run ') +
29
+ chalk_1.default.white('git add <files>') +
30
+ chalk_1.default.dim(' first.\n'));
31
+ process.exit(0);
32
+ }
33
+ const config = (0, config_1.getConfig)();
34
+ const stopSpinner = (0, ui_1.startSpinner)(`Generating via ${config.provider}...`);
35
+ let message;
36
+ try {
37
+ message = await (0, ai_1.generateMessage)(diff, config);
38
+ }
39
+ catch (err) {
40
+ stopSpinner();
41
+ const text = err instanceof Error ? err.message : String(err);
42
+ console.error(chalk_1.default.red(`\n Error: ${text}\n`));
43
+ process.exit(1);
44
+ }
45
+ stopSpinner();
46
+ (0, ui_1.printSuggestion)(message);
47
+ if (isDryRun) {
48
+ console.log(chalk_1.default.dim(' Dry run — no commit created.\n'));
49
+ process.exit(0);
50
+ }
51
+ const confirmed = await (0, ui_1.confirmMessage)(message);
52
+ if (confirmed === null) {
53
+ console.log(chalk_1.default.dim('\n Cancelled.\n'));
54
+ process.exit(0);
55
+ }
56
+ try {
57
+ (0, git_1.runCommit)(confirmed);
58
+ console.log(chalk_1.default.green('\n ✔ Committed: ') + chalk_1.default.bold(confirmed) + '\n');
59
+ }
60
+ catch (err) {
61
+ const text = err instanceof Error ? err.message : String(err);
62
+ console.error(chalk_1.default.red(`\n Commit failed: ${text}\n`));
63
+ process.exit(1);
64
+ }
65
+ }
66
+ main().catch((err) => {
67
+ console.error(chalk_1.default.red(`\n Fatal: ${err instanceof Error ? err.message : String(err)}\n`));
68
+ process.exit(1);
69
+ });
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,kDAA0C;AAC1C,+BAA4D;AAC5D,6BAAuC;AACvC,qCAAqC;AACrC,6BAAkF;AAElF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAEpE,KAAK,UAAU,IAAI;IACjB,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,sBAAO,CAAC,CAAC;QACrB,OAAO,CAAC,I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,CAAC,CAAC,CAAC;IAC7F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const SYSTEM_PROMPT = "You are an expert at writing git commit messages following the Conventional Commits specification.\n\nGiven a git diff, generate exactly one commit message that:\n- Follows the format: <type>(<optional scope>): <short description>\n- Uses one of these types: feat, fix, docs, style, refactor, chore, test, perf, ci, build\n- Description uses imperative mood (\"add\" not \"added\"), lowercase, no trailing period\n- Is under 72 characters total\n- Scope is optional \u2014 derive it from the primary file or module changed\n\nExamples:\n- feat(auth): add JWT refresh token rotation\n- fix(api): handle null response from user service\n- docs: add installation steps to README\n- chore: upgrade eslint to v9\n- refactor(db): extract query builder into separate module\n\nOutput ONLY the commit message. No explanation. No markdown. No quotes. No newlines.";
package/dist/prompt.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SYSTEM_PROMPT = void 0;
4
+ exports.SYSTEM_PROMPT = `You are an expert at writing git commit messages following the Conventional Commits specification.
5
+
6
+ Given a git diff, generate exactly one commit message that:
7
+ - Follows the format: <type>(<optional scope>): <short description>
8
+ - Uses one of these types: feat, fix, docs, style, refactor, chore, test, perf, ci, build
9
+ - Description uses imperative mood ("add" not "added"), lowercase, no trailing period
10
+ - Is under 72 characters total
11
+ - Scope is optional — derive it from the primary file or module changed
12
+
13
+ Examples:
14
+ - feat(auth): add JWT refresh token rotation
15
+ - fix(api): handle null response from user service
16
+ - docs: add installation steps to README
17
+ - chore: upgrade eslint to v9
18
+ - refactor(db): extract query builder into separate module
19
+
20
+ Output ONLY the commit message. No explanation. No markdown. No quotes. No newlines.`;
21
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;qFAgBwD,CAAC"}
package/dist/ui.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare function printHeader(): void;
2
+ export declare function startSpinner(text: string): () => void;
3
+ export declare function printSuggestion(message: string): void;
4
+ export declare function printSuccess(message: string): void;
5
+ export declare function confirmMessage(suggested: string): Promise<string | null>;
package/dist/ui.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.printHeader = printHeader;
40
+ exports.startSpinner = startSpinner;
41
+ exports.printSuggestion = printSuggestion;
42
+ exports.printSuccess = printSuccess;
43
+ exports.confirmMessage = confirmMessage;
44
+ const chalk_1 = __importDefault(require("chalk"));
45
+ const readline = __importStar(require("readline"));
46
+ function printHeader() {
47
+ console.log(chalk_1.default.bold.cyan('\n ai-commit') + chalk_1.default.dim(' · AI-powered git commits\n'));
48
+ }
49
+ function startSpinner(text) {
50
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
51
+ let i = 0;
52
+ const interval = setInterval(() => {
53
+ process.stdout.write(`\r ${chalk_1.default.cyan(frames[i])} ${chalk_1.default.dim(text)}`);
54
+ i = (i + 1) % frames.length;
55
+ }, 80);
56
+ // Returns a stop function — caller decides when to stop the spinner
57
+ return () => {
58
+ clearInterval(interval);
59
+ process.stdout.write('\r\x1b[K'); // erase the spinner line
60
+ };
61
+ }
62
+ function printSuggestion(message) {
63
+ console.log(` ${chalk_1.default.green('✔')} ${chalk_1.default.bold('Suggested commit message:')}\n`);
64
+ console.log(` ${chalk_1.default.cyan('❯')} ${chalk_1.default.white.bold(message)}\n`);
65
+ }
66
+ function printSuccess(message) {
67
+ console.log(chalk_1.default.green('\n ✔ Committed: ') + chalk_1.default.bold(message) + '\n');
68
+ }
69
+ async function confirmMessage(suggested) {
70
+ const rl = readline.createInterface({
71
+ input: process.stdin,
72
+ output: process.stdout,
73
+ });
74
+ return new Promise((resolve) => {
75
+ rl.question(chalk_1.default.dim(' Press Enter to confirm, or type to edit (Ctrl+C to cancel):\n > '), (input) => {
76
+ rl.close();
77
+ const trimmed = input.trim();
78
+ // Empty input = user accepted the suggestion as-is
79
+ resolve(trimmed === '' ? suggested : trimmed);
80
+ });
81
+ rl.on('SIGINT', () => {
82
+ rl.close();
83
+ process.stdout.write('\n');
84
+ resolve(null);
85
+ });
86
+ });
87
+ }
88
+ //# sourceMappingURL=ui.js.map
package/dist/ui.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","s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ate conventional commit messages from staged changes using AI",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "gitmage": "bin/ai-commit"
8
+ },
9
+ "files": [
10
+ "dist/",
11
+ "bin/",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "ts-node src/index.ts",
18
+ "start": "node dist/index.js",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "git",
23
+ "commit",
24
+ "ai",
25
+ "claude",
26
+ "conventional-commits",
27
+ "cli",
28
+ "developer-tools",
29
+ "anthropic"
30
+ ],
31
+ "author": "long260398",
32
+ "license": "MIT",
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "dependencies": {
37
+ "@anthropic-ai/sdk": "^0.28.0",
38
+ "chalk": "^4.1.2",
39
+ "groq-sdk": "^1.2.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^20.0.0",
43
+ "ts-node": "^10.9.2",
44
+ "typescript": "^5.4.0"
45
+ }
46
+ }