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.
Files changed (2) hide show
  1. package/dist/index.js +54 -22
  2. 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 getStagedDiff() {
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 stdout;
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
- Available Tools (use SPARINGLY - only when absolutely necessary):
328
- - git_commit_history: Check last 3-5 commits to understand conventions (use ONLY if diff is ambiguous)
329
- - git_staged_files: See list of staged files (use ONLY if you need to understand scope)
330
- - read_file: Read a file (ONLY if diff references unclear code - read MAX 1-2 files, prefer small files)
331
- - list_dir: List directory contents (RARELY needed)
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 - CRITICAL:
334
- 1. The diff contains ALL the information you need in 90% of cases. START by analyzing it thoroughly.
335
- 2. DO NOT automatically call tools. Only use them if the diff is genuinely unclear.
336
- 3. If using read_file, read ONLY the specific function/class mentioned, not entire files.
337
- 4. NEVER read more than 2 files total.
338
- 5. If checking commit history, limit to 3-5 recent commits maximum.
339
- 6. DO NOT use list_dir unless absolutely critical to understand project structure.
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 (if clear from diff).
345
- 4. OUTPUT FORMAT: Your response must be ONLY the commit message. No explanations, no "Here is...", no analysis.
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. No preamble, no explanation.
381
+ CRITICAL: Your ENTIRE response should be the commit message itself, nothing else.
350
382
 
351
- REMEMBER: The diff is your primary source. Tools are for edge cases only.
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 getStagedDiff();
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.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-agent-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "AI-powered git commit CLI using LangGraph and Claude 4.5",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",