@thankarezos/git-ai-commit 0.1.2 → 0.1.3
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 +1 -0
- package/bin/git-aic.js +44 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ First run launches an **interactive wizard** that asks you to pick a provider, e
|
|
|
51
51
|
| `--no-require-edit` | Allow committing the AI message unchanged |
|
|
52
52
|
| `--init` | Run the interactive setup wizard |
|
|
53
53
|
| `--config` | Print the active config path and contents |
|
|
54
|
+
| `-v`, `--version` | Print the package version |
|
|
54
55
|
| `-h` | Show usage. (`--help` is intercepted by git, so use `-h`.) |
|
|
55
56
|
|
|
56
57
|
## How it decides to commit
|
package/bin/git-aic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
4
4
|
import {
|
|
5
5
|
existsSync,
|
|
6
6
|
mkdtempSync,
|
|
@@ -37,6 +37,7 @@ function parseArgs(argv) {
|
|
|
37
37
|
let shouldCommit = null;
|
|
38
38
|
let requireEdit = null;
|
|
39
39
|
let printConfig = false;
|
|
40
|
+
let printVersion = false;
|
|
40
41
|
let runInit = false;
|
|
41
42
|
let shouldAdd = false;
|
|
42
43
|
let providerName = null;
|
|
@@ -99,6 +100,11 @@ function parseArgs(argv) {
|
|
|
99
100
|
continue;
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
if (arg === "-v" || arg === "--version") {
|
|
104
|
+
printVersion = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
if (arg === "--init") {
|
|
103
109
|
runInit = true;
|
|
104
110
|
continue;
|
|
@@ -115,6 +121,7 @@ Usage:
|
|
|
115
121
|
git aic --provider # list available providers
|
|
116
122
|
git aic --no-commit
|
|
117
123
|
git aic --config
|
|
124
|
+
git aic -v, --version
|
|
118
125
|
git aic --init
|
|
119
126
|
|
|
120
127
|
Examples:
|
|
@@ -143,6 +150,7 @@ Environment:
|
|
|
143
150
|
shouldCommit,
|
|
144
151
|
requireEdit,
|
|
145
152
|
printConfig,
|
|
153
|
+
printVersion,
|
|
146
154
|
runInit,
|
|
147
155
|
shouldAdd,
|
|
148
156
|
providerName,
|
|
@@ -159,8 +167,36 @@ function buildPrompt(extraPrompt) {
|
|
|
159
167
|
return cfg.prompt.join("\n").replaceAll(token, extraPrompt || extraPromptFallback);
|
|
160
168
|
}
|
|
161
169
|
|
|
170
|
+
function getVersion() {
|
|
171
|
+
const packageJsonPath = new URL("../package.json", import.meta.url);
|
|
172
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
173
|
+
return packageJson.version;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readStagedDiff() {
|
|
177
|
+
try {
|
|
178
|
+
return execFileSync(
|
|
179
|
+
"git",
|
|
180
|
+
["diff", "--cached", "--no-ext-diff"],
|
|
181
|
+
{
|
|
182
|
+
encoding: "utf8",
|
|
183
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const detail = error?.message ? `\n${error.message}` : "";
|
|
188
|
+
throw new Error(`Failed to read staged diff.${detail}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
162
192
|
|
|
163
193
|
const args = parseArgs(process.argv.slice(2));
|
|
194
|
+
|
|
195
|
+
if (args.printVersion) {
|
|
196
|
+
console.log(getVersion());
|
|
197
|
+
process.exit(0);
|
|
198
|
+
}
|
|
199
|
+
|
|
164
200
|
const configPath = getConfigPath();
|
|
165
201
|
|
|
166
202
|
if (args.runInit) {
|
|
@@ -223,11 +259,12 @@ if (hasStagedChanges.status === 0) {
|
|
|
223
259
|
fail("No staged changes found. Use: git add <files>");
|
|
224
260
|
}
|
|
225
261
|
|
|
226
|
-
const diff =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
262
|
+
const diff = readStagedDiff();
|
|
263
|
+
const MAX_DIFF_CHARS = 120_000;
|
|
264
|
+
const safeDiff =
|
|
265
|
+
diff.length > MAX_DIFF_CHARS
|
|
266
|
+
? `${diff.slice(0, MAX_DIFF_CHARS)}\n\n[Diff truncated because it was too large.]`
|
|
267
|
+
: diff;
|
|
231
268
|
|
|
232
269
|
const prompt = buildPrompt(args.extraPrompt);
|
|
233
270
|
|
|
@@ -235,7 +272,7 @@ console.log(`Using provider: ${config.provider.command}`);
|
|
|
235
272
|
|
|
236
273
|
let raw;
|
|
237
274
|
try {
|
|
238
|
-
raw = runProvider(config.provider, prompt,
|
|
275
|
+
raw = runProvider(config.provider, prompt, safeDiff);
|
|
239
276
|
} catch (error) {
|
|
240
277
|
fail(error.message);
|
|
241
278
|
}
|