@snapcommit/cli 2.2.1 → 2.3.1

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.
@@ -52,24 +52,89 @@ async function executeCursorStyle(userInput) {
52
52
  console.log(chalk_1.default.red('\n❌ Not a git repository\n'));
53
53
  return;
54
54
  }
55
- const input = userInput.toLowerCase().trim();
56
- // COMMIT/PUSH: Always use AI for commit messages (like Cursor!)
57
- if (input.includes('commit') || input.includes('push') || input.includes('save')) {
58
- await handleCommitAndPush();
55
+ // EVERYTHING goes through AI (like Cursor!)
56
+ // No shortcuts, no special cases - pure AI interpretation
57
+ await handleAICommand(userInput);
58
+ }
59
+ /**
60
+ * AI-powered command handler - handles EVERYTHING
61
+ * Pure AI interpretation for all operations (like Cursor!)
62
+ */
63
+ async function handleAICommand(userInput) {
64
+ const token = (0, auth_1.getToken)();
65
+ if (!token) {
66
+ console.log(chalk_1.default.red('❌ Not authenticated\n'));
67
+ return;
68
+ }
69
+ // Get AI interpretation for EVERYTHING
70
+ const intent = await getAIInterpretation(userInput, token);
71
+ if (!intent) {
72
+ console.log(chalk_1.default.red('❌ Could not understand command'));
73
+ console.log(chalk_1.default.gray('Tip: Try "commit and push" or "show me changes"\n'));
74
+ return;
75
+ }
76
+ // Debug: Show what AI understood (for now)
77
+ if (process.env.DEBUG) {
78
+ console.log(chalk_1.default.gray(`[DEBUG] Intent: ${JSON.stringify(intent, null, 2)}`));
79
+ }
80
+ // Execute based on type
81
+ if (intent.type === 'git') {
82
+ // Status check
83
+ if (intent.action === 'status') {
84
+ await showStatus();
85
+ return;
86
+ }
87
+ // For commits, generate AI message first
88
+ if (intent.action === 'commit') {
89
+ await executeCommitWithAI(intent);
90
+ return;
91
+ }
92
+ // Other git commands
93
+ if (intent.gitCommands && intent.gitCommands.length > 0) {
94
+ await executeGitCommands(intent.gitCommands);
95
+ console.log(chalk_1.default.green('✓ Done\n'));
96
+ }
97
+ else {
98
+ console.log(chalk_1.default.yellow('⚠️ No commands to execute\n'));
99
+ }
100
+ }
101
+ else if (intent.type === 'github') {
102
+ await executeGitHubCommand(intent);
103
+ console.log(chalk_1.default.green('✓ Done\n'));
104
+ }
105
+ else {
106
+ console.log(chalk_1.default.yellow(`⚠️ Unknown intent type: ${intent.type}\n`));
107
+ }
108
+ }
109
+ /**
110
+ * Show git status
111
+ */
112
+ async function showStatus() {
113
+ const status = (0, git_1.getGitStatus)();
114
+ const branch = (0, git_1.getCurrentBranch)();
115
+ const hasChanges = status.staged > 0 || status.unstaged > 0 || status.untracked > 0;
116
+ console.log(chalk_1.default.blue(`\nBranch: ${branch}`));
117
+ if (!hasChanges) {
118
+ console.log(chalk_1.default.gray('✓ Branch clean - no changes\n'));
59
119
  return;
60
120
  }
61
- // OTHER OPERATIONS: Branch, merge, rebase, GitHub, etc.
62
- await handleComplexCommand(userInput);
121
+ console.log(chalk_1.default.yellow('\nChanges detected:'));
122
+ if (status.unstaged > 0)
123
+ console.log(chalk_1.default.yellow(` • ${status.unstaged} modified`));
124
+ if (status.untracked > 0)
125
+ console.log(chalk_1.default.yellow(` • ${status.untracked} new`));
126
+ if (status.staged > 0)
127
+ console.log(chalk_1.default.green(` • ${status.staged} staged`));
128
+ console.log();
63
129
  }
64
130
  /**
65
- * Commit and push - ALWAYS uses AI for commit messages (like Cursor!)
66
- * Fast, clean, no prompts - just generates and commits
131
+ * Execute commit with AI-generated message
67
132
  */
68
- async function handleCommitAndPush() {
133
+ async function executeCommitWithAI(intent) {
69
134
  const status = (0, git_1.getGitStatus)();
70
135
  const hasChanges = status.staged > 0 || status.unstaged > 0 || status.untracked > 0;
71
136
  if (!hasChanges) {
72
- console.log(chalk_1.default.gray('\n✓ Branch clean\n'));
137
+ console.log(chalk_1.default.gray('✓ Branch clean'));
73
138
  return;
74
139
  }
75
140
  // Stage all
@@ -77,59 +142,37 @@ async function handleCommitAndPush() {
77
142
  (0, git_1.stageAllChanges)();
78
143
  }
79
144
  catch (error) {
80
- console.log(chalk_1.default.red(`❌ ${error.message}\n`));
145
+ console.log(chalk_1.default.red(`❌ ${error.message}`));
81
146
  return;
82
147
  }
83
- // Generate AI commit message (THE CORE FEATURE!)
148
+ // Generate AI commit message
84
149
  const diff = (0, git_1.getGitDiff)(true);
85
150
  const commitMessage = await generateCommitMessage(diff);
86
- // Commit with AI-generated message
151
+ // Commit
87
152
  try {
88
153
  (0, child_process_1.execSync)(`git commit -m "${commitMessage.replace(/"/g, '\\"')}"`, { encoding: 'utf-8', stdio: 'pipe' });
89
154
  console.log(chalk_1.default.green(`✓ ${commitMessage.split('\n')[0]}`));
90
155
  }
91
156
  catch (error) {
92
- console.log(chalk_1.default.red(`❌ Commit failed\n`));
157
+ console.log(chalk_1.default.red(`❌ Commit failed`));
93
158
  return;
94
159
  }
95
- // Push to remote
96
- try {
97
- (0, child_process_1.execSync)('git push', { encoding: 'utf-8', stdio: 'pipe' });
98
- console.log(chalk_1.default.green(' Pushed\n'));
99
- }
100
- catch (error) {
101
- if (error.message.includes('no configured push destination')) {
102
- console.log(chalk_1.default.gray('✓ Committed locally (no remote)\n'));
160
+ // Push if requested
161
+ if (intent.shouldPush || intent.gitCommands?.some((cmd) => cmd.includes('push'))) {
162
+ try {
163
+ (0, child_process_1.execSync)('git push', { encoding: 'utf-8', stdio: 'pipe' });
164
+ console.log(chalk_1.default.green('✓ Pushed'));
103
165
  }
104
- else {
105
- console.log(chalk_1.default.yellow(`⚠️ ${error.message}\n`));
166
+ catch (error) {
167
+ if (error.message.includes('no configured push destination')) {
168
+ console.log(chalk_1.default.gray('✓ Committed locally (no remote)'));
169
+ }
170
+ else {
171
+ console.log(chalk_1.default.yellow(`⚠️ ${error.message}`));
172
+ }
106
173
  }
107
174
  }
108
175
  }
109
- /**
110
- * Complex path: Use AI to interpret and execute any Git/GitHub command
111
- */
112
- async function handleComplexCommand(userInput) {
113
- const token = (0, auth_1.getToken)();
114
- if (!token) {
115
- console.log(chalk_1.default.red('❌ Not authenticated\n'));
116
- return;
117
- }
118
- // Get AI interpretation
119
- const intent = await getAIInterpretation(userInput, token);
120
- if (!intent) {
121
- console.log(chalk_1.default.red('❌ Could not understand command\n'));
122
- return;
123
- }
124
- // Execute based on type
125
- if (intent.type === 'git') {
126
- await executeGitCommands(intent.gitCommands || []);
127
- }
128
- else if (intent.type === 'github') {
129
- await executeGitHubCommand(intent);
130
- }
131
- console.log(chalk_1.default.green('✓ Done\n'));
132
- }
133
176
  /**
134
177
  * Execute Git commands with auto-retry on errors
135
178
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapcommit/cli",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "Instant AI commits. Beautiful progress tracking. Never write commit messages again.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {