@snapcommit/cli 3.8.12 → 3.8.14

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.
@@ -3,6 +3,39 @@
3
3
  * GitHub authentication - Auto-fetches OAuth token from SnapCommit account
4
4
  * Falls back to manual PAT if OAuth token not available
5
5
  */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
6
39
  var __importDefault = (this && this.__importDefault) || function (mod) {
7
40
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
41
  };
@@ -180,46 +213,48 @@ async function githubConnectCommand(tokenArg) {
180
213
  console.log(chalk_1.default.cyan(' • "list my open PRs"\n'));
181
214
  return;
182
215
  }
183
- // Auto-fetch failed, fall back to manual PAT setup
184
- console.log(chalk_1.default.yellow('⚠️ Could not auto-connect GitHub (OAuth token not available)\n'));
185
- console.log(chalk_1.default.gray('No problem! You can manually connect with a Personal Access Token:\n'));
186
- console.log(chalk_1.default.white('This CLI token enables GitHub features in your terminal:\n'));
187
- console.log(chalk_1.default.white(' Create pull requests'));
188
- console.log(chalk_1.default.white(' Check CI/workflow status'));
189
- console.log(chalk_1.default.white(' Manage issues and PRs'));
190
- console.log(chalk_1.default.white(' All with natural language!\n'));
191
- console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
192
- console.log(chalk_1.default.bold.white('Manual Setup (2 minutes):\n'));
193
- console.log(chalk_1.default.gray(' 1. Go to: ') + chalk_1.default.cyan('https://github.com/settings/tokens'));
194
- console.log(chalk_1.default.gray(' 2. Click "Generate new token (classic)"'));
195
- console.log(chalk_1.default.gray(' 3. Name: ') + chalk_1.default.white('"SnapCommit CLI"'));
196
- console.log(chalk_1.default.gray(' 4. Scopes: ') + chalk_1.default.white('repo, workflow, read:user'));
197
- console.log(chalk_1.default.gray(' 5. Generate & copy the token\n'));
198
- console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
199
- let token = tokenArg;
200
- if (!token) {
201
- token = await askQuestion(chalk_1.default.yellow('Paste your GitHub token: '));
202
- }
203
- if (!token || token.trim().length === 0) {
204
- console.log(chalk_1.default.red('\n❌ No token provided. Cancelled.\n'));
216
+ // Auto-fetch failed, initiate GitHub OAuth flow via web browser
217
+ console.log(chalk_1.default.yellow('\n⚠️ GitHub token not found in your account\n'));
218
+ console.log(chalk_1.default.white("Let's connect your GitHub account quickly!\n"));
219
+ console.log(chalk_1.default.bold.cyan('Quick Setup (30 seconds):\n'));
220
+ console.log(chalk_1.default.gray(' 1. A browser window will open'));
221
+ console.log(chalk_1.default.gray(' 2. Authorize SnapCommit to access your GitHub'));
222
+ console.log(chalk_1.default.gray(" 3. Come back here - you'll be connected!\n"));
223
+ console.log(chalk_1.default.gray('This enables:\n'));
224
+ console.log(chalk_1.default.white(' - Create pull requests with natural language'));
225
+ console.log(chalk_1.default.white(' - Check CI/workflow status'));
226
+ console.log(chalk_1.default.white(' - Manage issues and PRs\n'));
227
+ // Get auth config to get user ID
228
+ const authConfig = (0, auth_1.getAuthConfig)();
229
+ if (!authConfig || !authConfig.token) {
230
+ console.log(chalk_1.default.red('\n❌ You must be logged in first!'));
231
+ console.log(chalk_1.default.gray(' Run: ') + chalk_1.default.cyan('snap login\n'));
205
232
  return;
206
233
  }
207
- token = token.trim();
208
- console.log(chalk_1.default.gray('\n🔄 Verifying token with GitHub...\n'));
234
+ // Generate state parameter for OAuth security
235
+ const state = Buffer.from(JSON.stringify({
236
+ userId: authConfig.userId,
237
+ timestamp: Date.now()
238
+ })).toString('base64');
239
+ // Generate OAuth URL
240
+ const oauthUrl = `https://snapcommit.dev/api/github/connect?state=${encodeURIComponent(state)}`;
241
+ console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
242
+ console.log(chalk_1.default.cyan('Opening browser for GitHub authorization...\n'));
209
243
  try {
210
- const result = await verifyGitHubToken(token);
211
- if (result.valid && result.user) {
212
- const config = {
213
- token,
214
- username: result.user.login,
215
- userId: result.user.id,
216
- connectedAt: new Date().toISOString(),
217
- };
218
- saveGitHubToken(config);
219
- console.log(chalk_1.default.green.bold('✅ GITHUB CONNECTED! 🎉\n'));
220
- console.log(chalk_1.default.white(` Connected as: ${chalk_1.default.bold('@' + result.user.login)}`));
221
- console.log(chalk_1.default.gray(` User ID: ${result.user.id}`));
222
- console.log(chalk_1.default.gray(` Name: ${result.user.name || 'N/A'}\n`));
244
+ // Open browser
245
+ const open = (await Promise.resolve().then(() => __importStar(require('open')))).default;
246
+ await open(oauthUrl);
247
+ console.log(chalk_1.default.green('✅ Browser opened!\n'));
248
+ console.log(chalk_1.default.gray('Waiting for you to authorize...\n'));
249
+ console.log(chalk_1.default.yellow('After authorization, come back here and press ENTER'));
250
+ // Wait for user confirmation
251
+ await askQuestion(chalk_1.default.cyan('\nPress ENTER after authorizing in browser: '));
252
+ // Try to fetch the token again
253
+ const autoConfig2 = await autoFetchGitHubToken();
254
+ if (autoConfig2) {
255
+ saveGitHubToken(autoConfig2);
256
+ console.log(chalk_1.default.green.bold('\n✅ GITHUB CONNECTED! 🎉\n'));
257
+ console.log(chalk_1.default.white(` Connected as: ${chalk_1.default.bold('@' + autoConfig2.username)}\n`));
223
258
  console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
224
259
  console.log(chalk_1.default.bold('🚀 You can now use GitHub features!\n'));
225
260
  console.log(chalk_1.default.gray(' Try these commands in snap REPL:\n'));
@@ -228,16 +263,17 @@ async function githubConnectCommand(tokenArg) {
228
263
  console.log(chalk_1.default.cyan(' • "list my open PRs"\n'));
229
264
  }
230
265
  else {
231
- console.log(chalk_1.default.red('\n❌ Invalid GitHub token.\n'));
232
- console.log(chalk_1.default.yellow('Troubleshooting:'));
233
- console.log(chalk_1.default.gray(' • Make sure you copied the ENTIRE token'));
234
- console.log(chalk_1.default.gray(' • Token should start with: ghp_'));
235
- console.log(chalk_1.default.gray(' • Make sure the token has correct scopes'));
236
- console.log(chalk_1.default.gray(' Generate a new token at: https://github.com/settings/tokens\n'));
266
+ console.log(chalk_1.default.red('\n❌ Connection failed\n'));
267
+ console.log(chalk_1.default.yellow('Possible reasons:'));
268
+ console.log(chalk_1.default.gray(' • Authorization was cancelled'));
269
+ console.log(chalk_1.default.gray(' • GitHub authorization not completed'));
270
+ console.log(chalk_1.default.gray(' • Network error\n'));
271
+ console.log(chalk_1.default.gray('Try running ') + chalk_1.default.cyan('github connect') + chalk_1.default.gray(' again\n'));
237
272
  }
238
273
  }
239
274
  catch (error) {
240
275
  console.log(chalk_1.default.red(`\n❌ ${error.message}\n`));
276
+ console.log(chalk_1.default.gray('Try running ') + chalk_1.default.cyan('github connect') + chalk_1.default.gray(' again\n'));
241
277
  }
242
278
  }
243
279
  /**
@@ -174,6 +174,11 @@ async function tryQuickCommands(input, context) {
174
174
  (0, stats_1.statsCommand)();
175
175
  return true;
176
176
  }
177
+ // GitHub management commands (NOT git operations - these are handled in repl/index.ts)
178
+ if (lower === 'github connect' || lower === 'github status' || lower === 'github disconnect') {
179
+ // Skip - let repl/index.ts handle these
180
+ return false;
181
+ }
177
182
  // Push commands
178
183
  if (lower === 'push' || lower === 'push it' || lower === 'push that') {
179
184
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapcommit/cli",
3
- "version": "3.8.12",
3
+ "version": "3.8.14",
4
4
  "description": "Instant AI commits. Beautiful progress tracking. Never write commit messages again.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {