scai 0.1.14 → 0.1.15

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.
@@ -11,23 +11,30 @@ function askUserToChoose(suggestions) {
11
11
  console.log('\n---');
12
12
  console.log(`${suggestions.length + 1}) šŸ” Regenerate suggestions`);
13
13
  console.log(`${suggestions.length + 2}) āœļø Write your own commit message`);
14
+ console.log(`${suggestions.length + 3}) āŒ Cancel`);
14
15
  const rl = readline.createInterface({
15
16
  input: process.stdin,
16
17
  output: process.stdout,
17
18
  });
18
- rl.question(`\nšŸ‘‰ Choose a commit message [1-${suggestions.length + 2}]: `, (answer) => {
19
+ rl.question(`\nšŸ‘‰ Choose a commit message [1-${suggestions.length + 3}]: `, (answer) => {
19
20
  rl.close();
20
21
  const choice = parseInt(answer, 10);
21
- if (isNaN(choice) || choice < 1 || choice > suggestions.length + 2) {
22
- console.log('āš ļø Invalid selection. Using the first suggestion by default.');
23
- resolve(0);
22
+ if (choice === suggestions.length + 1) {
23
+ resolve('regenerate');
24
24
  }
25
25
  else if (choice === suggestions.length + 2) {
26
26
  resolve('custom');
27
27
  }
28
- else {
28
+ else if (choice === suggestions.length + 3) {
29
+ resolve('cancel');
30
+ }
31
+ else if (!isNaN(choice) && choice >= 1 && choice <= suggestions.length) {
29
32
  resolve(choice - 1);
30
33
  }
34
+ else {
35
+ console.log('āš ļø Invalid selection. Using the first suggestion by default.');
36
+ resolve(0);
37
+ }
31
38
  });
32
39
  });
33
40
  }
@@ -53,30 +60,50 @@ export async function suggestCommitMessage(options) {
53
60
  console.log('āš ļø No staged changes to suggest a message for.');
54
61
  return;
55
62
  }
56
- let suggestions = [];
63
+ const output = await commitSuggesterModule.run({ code: diff });
64
+ const suggestions = output.suggestions || [];
65
+ if (!suggestions.length) {
66
+ console.log('āš ļø No commit suggestions generated.');
67
+ return;
68
+ }
69
+ // Show-only mode
70
+ if (!options.commit) {
71
+ console.log('\nšŸ’” AI-suggested commit messages:\n');
72
+ suggestions.slice(0, 3).forEach((msg, i) => {
73
+ console.log(`${i + 1}) ${msg}`);
74
+ });
75
+ process.exit(0); // ensure clean exit
76
+ }
77
+ // Commit mode with selection
57
78
  let message = null;
58
79
  while (message === null) {
59
- suggestions = await commitSuggesterModule.run({ code: diff }).then(out => out.suggestions || []);
60
80
  const choice = await askUserToChoose(suggestions);
61
- if (choice === suggestions.length) {
81
+ if (choice === 'regenerate') {
62
82
  console.log('\nšŸ”„ Regenerating suggestions...\n');
83
+ const out = await commitSuggesterModule.run({ code: diff });
84
+ suggestions.splice(0, suggestions.length, ...(out.suggestions || []));
63
85
  continue;
64
86
  }
65
87
  if (choice === 'custom') {
66
88
  message = await promptCustomMessage();
67
- break;
68
89
  }
69
- message = suggestions[choice];
90
+ else if (choice === 'cancel') {
91
+ console.log('āŒ Commit cancelled.');
92
+ return;
93
+ }
94
+ else {
95
+ message = suggestions[choice];
96
+ }
70
97
  }
71
98
  console.log(`\nāœ… Selected commit message:\n${message}\n`);
72
- if (options.commit) {
73
- const commitDiff = execSync("git diff", { encoding: "utf-8" }).trim();
74
- if (commitDiff) {
75
- execSync("git add .", { encoding: "utf-8" });
76
- }
77
- execSync(`git commit -m "${message.replace(/"/g, '\\"')}"`, { stdio: 'inherit' });
78
- console.log('āœ… Committed with selected message.');
99
+ const staged = execSync("git diff --cached", { encoding: "utf-8" }).trim();
100
+ if (!staged) {
101
+ console.log("āš ļø No files are currently staged for commit.");
102
+ console.log("šŸ‘‰ Please stage your changes with 'git add <files>' and rerun the command.");
103
+ return;
79
104
  }
105
+ execSync(`git commit -m "${message.replace(/"/g, '\\"')}"`, { stdio: 'inherit' });
106
+ console.log('āœ… Committed with selected message.');
80
107
  }
81
108
  catch (err) {
82
109
  console.error('āŒ Error in commit message suggestion:', err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scai",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "scai": "./dist/index.js"