commit-agent-cli 0.1.3 → 0.1.4
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 +54 -22
- 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),
|
|
@@ -509,7 +541,7 @@ async function main() {
|
|
|
509
541
|
}
|
|
510
542
|
const s = spinner();
|
|
511
543
|
s.start("Analyzing staged changes...");
|
|
512
|
-
const diff = await
|
|
544
|
+
const diff = await getStagedDiffSmart();
|
|
513
545
|
if (!diff) {
|
|
514
546
|
s.stop("No staged changes found.");
|
|
515
547
|
cancel('Please stage your changes using "git add" first.');
|