sncommit 1.2.2 → 1.2.3

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 +81 -72
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -75406,15 +75406,9 @@ class GroqService {
75406
75406
  } catch (e) {
75407
75407
  const error48 = e;
75408
75408
  if (error48?.status === 401) {
75409
- console.warn(`
75410
- \x1B[33m⚠️ Groq API Key is invalid.\x1B[0m`);
75411
- console.warn(` Using static backup suggestions. Run \x1B[36msncommit config\x1B[0m to set your key.
75412
- `);
75413
- } else {
75414
- console.error("Error generation suggestions:", error48?.message || String(e));
75409
+ throw new Error('Invalid API Key. Run "sncommit config" to set your Groq API key. Get one at https://console.groq.com/keys');
75415
75410
  }
75416
- const fallbackSuggestions = this.getFallbackSuggestions(stagedFiles);
75417
- return fallbackSuggestions.map((s) => ({ ...s, isFallback: true }));
75411
+ throw new Error(`Error generating suggestions: ${error48?.message || String(e)}`);
75418
75412
  }
75419
75413
  }
75420
75414
  async generateCommitSuggestionsFromCustomInput(stagedFiles, diff2, userInput, recentCommits = [], diffStats) {
@@ -75453,15 +75447,9 @@ class GroqService {
75453
75447
  } catch (e) {
75454
75448
  const error48 = e;
75455
75449
  if (error48?.status === 401) {
75456
- console.warn(`
75457
- \x1B[33m⚠️ Groq API Key is invalid.\x1B[0m`);
75458
- console.warn(` Using static backup suggestions. Run \x1B[36msncommit config\x1B[0m to set your key.
75459
- `);
75460
- } else {
75461
- console.error("Error generation suggestions:", error48?.message || String(e));
75450
+ throw new Error('Invalid API Key. Run "sncommit config" to set your Groq API key. Get one at https://console.groq.com/keys');
75462
75451
  }
75463
- const fallbackSuggestions = this.getFallbackSuggestions(stagedFiles);
75464
- return fallbackSuggestions.map((s) => ({ ...s, isFallback: true }));
75452
+ throw new Error(`Error generating suggestions: ${error48?.message || String(e)}`);
75465
75453
  }
75466
75454
  }
75467
75455
  buildPromptFromCustomInput(stagedFiles, diff2, userInput, recentCommits, diffStats) {
@@ -75520,32 +75508,6 @@ ${customPrompt}
75520
75508
 
75521
75509
  Output ONLY valid JSON.`;
75522
75510
  }
75523
- getFallbackSuggestions(stagedFiles) {
75524
- const fileNames = stagedFiles.length > 0 ? stagedFiles.map((f) => f.path).slice(0, 3).join(", ") + (stagedFiles.length > 3 ? "..." : "") : "files";
75525
- const suggestions = [
75526
- {
75527
- message: `feat: add ${fileNames}`,
75528
- type: "feat",
75529
- description: `feat: add ${fileNames}`
75530
- },
75531
- {
75532
- message: `fix: update ${fileNames}`,
75533
- type: "fix",
75534
- description: `fix: update ${fileNames}`
75535
- },
75536
- {
75537
- message: `refactor: improve ${fileNames}`,
75538
- type: "refactor",
75539
- description: `refactor: improve ${fileNames}`
75540
- },
75541
- {
75542
- message: `docs: update ${fileNames}`,
75543
- type: "docs",
75544
- description: `docs: update ${fileNames}`
75545
- }
75546
- ];
75547
- return suggestions;
75548
- }
75549
75511
  buildPrompt(stagedFiles, diff2, recentCommits, diffStats) {
75550
75512
  const filesText = stagedFiles.map((f) => `- ${f.path}`).join(`
75551
75513
  `);
@@ -75806,10 +75768,9 @@ var CommitSuggestions = ({
75806
75768
  onCommit,
75807
75769
  onTryAgain,
75808
75770
  onCustomInput,
75809
- isLoading,
75810
- isUsingFallback = false
75771
+ isLoading
75811
75772
  }) => {
75812
- const totalOptions = isUsingFallback ? suggestions.length : suggestions.length + 2;
75773
+ const totalOptions = suggestions.length + 2;
75813
75774
  const [frame, setFrame] = import_react29.useState(0);
75814
75775
  const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
75815
75776
  import_react29.useEffect(() => {
@@ -75830,12 +75791,10 @@ var CommitSuggestions = ({
75830
75791
  } else if (key.return) {
75831
75792
  if (selectedIndex < suggestions.length) {
75832
75793
  onCommit(selectedIndex);
75833
- } else if (!isUsingFallback) {
75834
- if (selectedIndex === suggestions.length) {
75835
- onTryAgain();
75836
- } else if (selectedIndex === suggestions.length + 1) {
75837
- onCustomInput();
75838
- }
75794
+ } else if (selectedIndex === suggestions.length) {
75795
+ onTryAgain();
75796
+ } else if (selectedIndex === suggestions.length + 1) {
75797
+ onCustomInput();
75839
75798
  }
75840
75799
  }
75841
75800
  });
@@ -75912,7 +75871,7 @@ var CommitSuggestions = ({
75912
75871
  ]
75913
75872
  }, index, true, undefined, this);
75914
75873
  }),
75915
- !isUsingFallback && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(Box_default, {
75874
+ /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(Box_default, {
75916
75875
  marginTop: 1,
75917
75876
  paddingLeft: 1,
75918
75877
  flexDirection: "row",
@@ -76069,9 +76028,9 @@ var BetterCommitApp = ({
76069
76028
  suggestions: [],
76070
76029
  selectedIndex: 0,
76071
76030
  isLoading: false,
76072
- error: undefined
76031
+ error: undefined,
76032
+ warning: undefined
76073
76033
  });
76074
- const [isUsingFallback, setIsUsingFallback] = import_react31.useState(false);
76075
76034
  const [exitMessage, setExitMessage] = import_react31.useState(null);
76076
76035
  const [successMessage, setSuccessMessage] = import_react31.useState(undefined);
76077
76036
  const [isPushing, setIsPushing] = import_react31.useState(false);
@@ -76106,6 +76065,15 @@ var BetterCommitApp = ({
76106
76065
  setExitMessage(state.error);
76107
76066
  }
76108
76067
  }, [state.error]);
76068
+ import_react31.useEffect(() => {
76069
+ if (state.warning) {
76070
+ const timer = setTimeout(() => {
76071
+ onExit(state.warning);
76072
+ setExitMessage(state.warning);
76073
+ }, 100);
76074
+ return () => clearTimeout(timer);
76075
+ }
76076
+ }, [state.warning, onExit]);
76109
76077
  use_input_default((input, key) => {
76110
76078
  if (key.escape || key.ctrl && input === "c") {
76111
76079
  onExit("Operation cancelled");
@@ -76137,7 +76105,7 @@ var BetterCommitApp = ({
76137
76105
  if (!config2.groqApiKey || config2.groqApiKey.trim() === "") {
76138
76106
  setState((prev) => ({
76139
76107
  ...prev,
76140
- error: 'Groq API key not configured. Run "sncommit config" to set it up.',
76108
+ warning: 'Groq API key not configured. Run "sncommit config" to set it up. Go to https://console.groq.com/keys to create a Groq API key.',
76141
76109
  isLoading: false
76142
76110
  }));
76143
76111
  return;
@@ -76153,20 +76121,28 @@ var BetterCommitApp = ({
76153
76121
  } else {
76154
76122
  suggestions = await groqService.generateCommitSuggestions(stagedFiles, diff2, recentCommits, diffStats);
76155
76123
  }
76156
- const hasFallback = suggestions.some((s) => s.isFallback);
76157
76124
  setState((prev) => ({
76158
76125
  ...prev,
76159
76126
  suggestions,
76160
76127
  isLoading: false,
76161
76128
  error: undefined
76162
76129
  }));
76163
- setIsUsingFallback(hasFallback);
76164
76130
  } catch (error48) {
76165
- setState((prev) => ({
76166
- ...prev,
76167
- error: `Failed to generate suggestions: ${error48 instanceof Error ? error48.message : String(error48)}`,
76168
- isLoading: false
76169
- }));
76131
+ const errorMessage = error48 instanceof Error ? error48.message : String(error48);
76132
+ const isInvalidApiKey = errorMessage.toLowerCase().includes("invalid api key");
76133
+ if (isInvalidApiKey) {
76134
+ setState((prev) => ({
76135
+ ...prev,
76136
+ warning: errorMessage,
76137
+ isLoading: false
76138
+ }));
76139
+ } else {
76140
+ setState((prev) => ({
76141
+ ...prev,
76142
+ error: `Failed to generate suggestions: ${errorMessage}`,
76143
+ isLoading: false
76144
+ }));
76145
+ }
76170
76146
  }
76171
76147
  };
76172
76148
  const handleSelect = (index) => {
@@ -76243,6 +76219,35 @@ var BetterCommitApp = ({
76243
76219
  ]
76244
76220
  }, undefined, true, undefined, this);
76245
76221
  }
76222
+ if (state.warning) {
76223
+ return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76224
+ flexDirection: "column",
76225
+ paddingX: 2,
76226
+ paddingY: 1,
76227
+ borderStyle: "round",
76228
+ borderColor: colors.border.warning,
76229
+ flexGrow: 1,
76230
+ children: [
76231
+ /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76232
+ flexGrow: 1,
76233
+ justifyContent: "center",
76234
+ alignItems: "center",
76235
+ children: /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
76236
+ bold: true,
76237
+ color: colors.warning,
76238
+ children: "Warning"
76239
+ }, undefined, false, undefined, this)
76240
+ }, undefined, false, undefined, this),
76241
+ /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76242
+ marginTop: 1,
76243
+ children: /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
76244
+ color: colors.text.secondary,
76245
+ children: state.warning
76246
+ }, undefined, false, undefined, this)
76247
+ }, undefined, false, undefined, this)
76248
+ ]
76249
+ }, undefined, true, undefined, this);
76250
+ }
76246
76251
  if (successMessage) {
76247
76252
  return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76248
76253
  flexDirection: "column",
@@ -76299,7 +76304,7 @@ var BetterCommitApp = ({
76299
76304
  ]
76300
76305
  }, undefined, true, undefined, this);
76301
76306
  }
76302
- if (state.stagedFiles.length === 0 && !state.error) {
76307
+ if (state.stagedFiles.length === 0 && !state.error && !state.warning) {
76303
76308
  return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76304
76309
  flexDirection: "column",
76305
76310
  padding: 2,
@@ -76342,7 +76347,7 @@ var BetterCommitApp = ({
76342
76347
  }
76343
76348
  return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76344
76349
  flexDirection: "column",
76345
- paddingX: 2,
76350
+ paddingX: 3,
76346
76351
  paddingY: 1,
76347
76352
  borderStyle: "round",
76348
76353
  borderColor: colors.border.default,
@@ -76380,8 +76385,7 @@ var BetterCommitApp = ({
76380
76385
  onCommit: handleCommit,
76381
76386
  onTryAgain: handleTryAgain,
76382
76387
  onCustomInput: handleCustomInput,
76383
- isLoading: state.isLoading,
76384
- isUsingFallback
76388
+ isLoading: state.isLoading
76385
76389
  }, undefined, false, undefined, this),
76386
76390
  !isCustomInputMode && /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
76387
76391
  borderStyle: "round",
@@ -76485,6 +76489,7 @@ var ConfigApp = ({ onExit }) => {
76485
76489
  const [editValue, setEditValue] = import_react32.useState("");
76486
76490
  const [optionIndex, setOptionIndex] = import_react32.useState(0);
76487
76491
  const [cursorPosition, setCursorPosition] = import_react32.useState(0);
76492
+ const maskedPassword = import_react32.useMemo(() => editValue.split("").map(() => "•").join(""), [editValue]);
76488
76493
  const autoSave = import_react32.useCallback(() => {
76489
76494
  const finalConfig = {
76490
76495
  ...config2,
@@ -76572,10 +76577,15 @@ var ConfigApp = ({ onExit }) => {
76572
76577
  } else if (key.rightArrow) {
76573
76578
  setCursorPosition((prev) => Math.min(editValue.length, prev + 1));
76574
76579
  } else if (key.backspace || key.delete) {
76575
- if (cursorPosition > 0) {
76576
- setEditValue((prev) => prev.slice(0, cursorPosition - 1) + prev.slice(cursorPosition));
76577
- setCursorPosition((prev) => prev - 1);
76578
- }
76580
+ setEditValue((prev) => {
76581
+ if (prev.length === 0)
76582
+ return prev;
76583
+ if (cursorPosition === prev.length) {
76584
+ return prev.slice(0, -1);
76585
+ }
76586
+ return prev.slice(0, cursorPosition - 1) + prev.slice(cursorPosition);
76587
+ });
76588
+ setCursorPosition((prev) => Math.max(0, prev - 1));
76579
76589
  } else if (input && !key.ctrl && !key.meta) {
76580
76590
  setEditValue((prev) => prev.slice(0, cursorPosition) + input + prev.slice(cursorPosition));
76581
76591
  setCursorPosition((prev) => prev + input.length);
@@ -76607,7 +76617,6 @@ var ConfigApp = ({ onExit }) => {
76607
76617
  };
76608
76618
  return /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Box_default, {
76609
76619
  flexDirection: "column",
76610
- paddingY: 1,
76611
76620
  flexGrow: 1,
76612
76621
  width: "100%",
76613
76622
  children: exitMessage ? /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Box_default, {
@@ -76744,7 +76753,7 @@ var ConfigApp = ({ onExit }) => {
76744
76753
  children: [
76745
76754
  /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
76746
76755
  color: colors.text.primary,
76747
- children: editValue.split("").map(() => "•").join("")
76756
+ children: maskedPassword
76748
76757
  }, undefined, false, undefined, this),
76749
76758
  /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
76750
76759
  backgroundColor: colors.warning,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sncommit",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "AI-powered git commit message generator with beautiful TUI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",