commit-agent-cli 0.1.3 → 0.1.5
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/dist/index.js +69 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -104,11 +104,41 @@ import { intro, outro, text, spinner, confirm, isCancel, cancel, note } from "@c
|
|
|
104
104
|
|
|
105
105
|
// src/git.ts
|
|
106
106
|
import { execa } from "execa";
|
|
107
|
-
async function
|
|
108
|
-
const { stdout } = await execa("git", ["diff", "--cached"], {
|
|
107
|
+
async function getStagedDiffSmart() {
|
|
108
|
+
const { stdout: fileList } = await execa("git", ["diff", "--cached", "--name-status"], {
|
|
109
109
|
reject: false
|
|
110
110
|
});
|
|
111
|
-
return
|
|
111
|
+
if (!fileList) return "";
|
|
112
|
+
const { stdout: stats } = await execa("git", ["diff", "--cached", "--stat"], {
|
|
113
|
+
reject: false
|
|
114
|
+
});
|
|
115
|
+
const { stdout: diff } = await execa("git", ["diff", "--cached", "--unified=1", "--no-color", "--no-prefix"], {
|
|
116
|
+
reject: false
|
|
117
|
+
});
|
|
118
|
+
const estimatedTokens = diff.length / 4;
|
|
119
|
+
if (estimatedTokens > 2e3) {
|
|
120
|
+
const { stdout: compactDiff } = await execa("git", ["diff", "--cached", "--unified=0", "--no-color", "--no-prefix"], {
|
|
121
|
+
reject: false
|
|
122
|
+
});
|
|
123
|
+
return `FILES CHANGED (${fileList.split("\n").length} files):
|
|
124
|
+
${fileList}
|
|
125
|
+
|
|
126
|
+
STATS:
|
|
127
|
+
${stats}
|
|
128
|
+
|
|
129
|
+
DIFF (function signatures only - large changeset):
|
|
130
|
+
${compactDiff}
|
|
131
|
+
|
|
132
|
+
Note: This is a large changeset. The diff shows only changed lines without context.`;
|
|
133
|
+
}
|
|
134
|
+
return `FILES CHANGED:
|
|
135
|
+
${fileList}
|
|
136
|
+
|
|
137
|
+
STATS:
|
|
138
|
+
${stats}
|
|
139
|
+
|
|
140
|
+
DIFF:
|
|
141
|
+
${diff}`;
|
|
112
142
|
}
|
|
113
143
|
async function commit(message) {
|
|
114
144
|
await execa("git", ["commit", "-m", message]);
|
|
@@ -324,31 +354,33 @@ async function generateCommitMessage(diff, preferences) {
|
|
|
324
354
|
const styleGuide = preferences.commitMessageStyle === "descriptive" ? 'Be descriptive and detailed. Explain the "why" behind changes when relevant. Multi-line messages are encouraged.' : "Be concise and to the point. Keep it short, ideally one line.";
|
|
325
355
|
const systemPrompt = `You are an expert developer. Your task is to generate a commit message for the provided git diff.
|
|
326
356
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
-
|
|
331
|
-
-
|
|
357
|
+
The diff provided is OPTIMIZED for token efficiency - it includes file changes, stats, and minimal context.
|
|
358
|
+
|
|
359
|
+
Available Tools (use EXTREMELY RARELY):
|
|
360
|
+
- git_commit_history: Check last commits (use ONLY if you truly cannot understand the convention)
|
|
361
|
+
- git_staged_files: See staged files (ALREADY in the diff - don't call this)
|
|
362
|
+
- read_file: Read a file (use ONLY if critical context is missing - VERY rare)
|
|
363
|
+
- list_dir: List directory (almost NEVER needed)
|
|
332
364
|
|
|
333
|
-
EFFICIENCY RULES
|
|
334
|
-
1. The diff
|
|
335
|
-
2. DO NOT
|
|
336
|
-
3.
|
|
337
|
-
4. NEVER read
|
|
338
|
-
5.
|
|
339
|
-
6.
|
|
365
|
+
CRITICAL EFFICIENCY RULES:
|
|
366
|
+
1. The diff is ALREADY optimized and contains everything you need in 95%+ of cases
|
|
367
|
+
2. DO NOT call ANY tools unless absolutely critical for understanding
|
|
368
|
+
3. The diff shows: file list, stats, and changes - this is sufficient
|
|
369
|
+
4. NEVER read files just to "understand better" - the diff IS the understanding
|
|
370
|
+
5. NEVER check commit history unless the changes are completely ambiguous
|
|
371
|
+
6. Aim for ZERO tool calls - generate the message directly from the diff
|
|
340
372
|
|
|
341
373
|
Commit Message Rules:
|
|
342
374
|
1. ${conventionalGuide}
|
|
343
375
|
2. ${styleGuide}
|
|
344
|
-
3. Focus on WHAT changed and WHY
|
|
345
|
-
4. OUTPUT FORMAT: Your response must be ONLY the commit message. No explanations
|
|
346
|
-
5. Do NOT use markdown code blocks or formatting
|
|
347
|
-
6. If multi-line, use proper git commit format (subject line, blank line, body)
|
|
376
|
+
3. Focus on WHAT changed (clear from diff) and WHY if obvious from context
|
|
377
|
+
4. OUTPUT FORMAT: Your response must be ONLY the commit message. No explanations.
|
|
378
|
+
5. Do NOT use markdown code blocks or formatting
|
|
379
|
+
6. If multi-line, use proper git commit format (subject line, blank line, body)
|
|
348
380
|
|
|
349
|
-
CRITICAL: Your ENTIRE response should be the commit message itself, nothing else.
|
|
381
|
+
CRITICAL: Your ENTIRE response should be the commit message itself, nothing else.
|
|
350
382
|
|
|
351
|
-
|
|
383
|
+
DEFAULT ACTION: Read the diff, generate the message, done. NO TOOLS.
|
|
352
384
|
`;
|
|
353
385
|
const messages = [
|
|
354
386
|
new SystemMessage(systemPrompt),
|
|
@@ -400,20 +432,26 @@ var packageJson = JSON.parse(
|
|
|
400
432
|
);
|
|
401
433
|
var notifier = updateNotifier({
|
|
402
434
|
pkg: packageJson,
|
|
403
|
-
updateCheckInterval: 1e3 * 60 * 60
|
|
404
|
-
// Check once per
|
|
435
|
+
updateCheckInterval: 1e3 * 60 * 60
|
|
436
|
+
// Check once per hour (was 24h)
|
|
405
437
|
});
|
|
406
438
|
if (notifier.update) {
|
|
407
|
-
const currentVersion =
|
|
408
|
-
const latestVersion =
|
|
409
|
-
const command = import_picocolors.default.cyan(`npm install -g ${packageJson.name}`);
|
|
439
|
+
const currentVersion = notifier.update.current;
|
|
440
|
+
const latestVersion = notifier.update.latest;
|
|
410
441
|
console.log("");
|
|
411
|
-
console.log(import_picocolors.default.yellow("\
|
|
412
|
-
console.log(import_picocolors.default.yellow("\u2502") + "
|
|
413
|
-
console.log(import_picocolors.default.yellow("\u2502") + "
|
|
414
|
-
console.log(import_picocolors.default.yellow("\
|
|
442
|
+
console.log(import_picocolors.default.yellow("\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"));
|
|
443
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
444
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.bold("New version of commit-cli is available!") + " " + import_picocolors.default.yellow("\u2502"));
|
|
445
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
446
|
+
console.log(import_picocolors.default.yellow("\u2502") + " Current: " + import_picocolors.default.dim(currentVersion) + " \u2192 Latest: " + import_picocolors.default.green(import_picocolors.default.bold(latestVersion)) + " " + import_picocolors.default.yellow("\u2502"));
|
|
447
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
448
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.dim("Update after you finish by running:") + " " + import_picocolors.default.yellow("\u2502"));
|
|
449
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.cyan(import_picocolors.default.bold(`npm install -g ${packageJson.name}@latest`)) + " " + import_picocolors.default.yellow("\u2502"));
|
|
450
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
451
|
+
console.log(import_picocolors.default.yellow("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"));
|
|
415
452
|
console.log("");
|
|
416
453
|
}
|
|
454
|
+
notifier.notify({ defer: false, isGlobal: true });
|
|
417
455
|
var CONFIG_PATH = join2(homedir(), ".commit-cli.json");
|
|
418
456
|
async function getStoredKey() {
|
|
419
457
|
try {
|
|
@@ -509,7 +547,7 @@ async function main() {
|
|
|
509
547
|
}
|
|
510
548
|
const s = spinner();
|
|
511
549
|
s.start("Analyzing staged changes...");
|
|
512
|
-
const diff = await
|
|
550
|
+
const diff = await getStagedDiffSmart();
|
|
513
551
|
if (!diff) {
|
|
514
552
|
s.stop("No staged changes found.");
|
|
515
553
|
cancel('Please stage your changes using "git add" first.');
|