commit-agent-cli 0.1.1 → 0.1.2

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 +43 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -499,11 +499,40 @@ async function main() {
499
499
  commitMessage = await generateCommitMessage(diff, preferences);
500
500
  } catch (error) {
501
501
  s.stop("Generation failed.");
502
+ if (error.message?.includes("401") || error.message?.includes("authentication_error") || error.message?.includes("invalid x-api-key") || error.message?.includes("invalid api key")) {
503
+ cancel("Invalid API Key detected.");
504
+ const retryWithNewKey = await confirm({
505
+ message: "Would you like to enter a new API key?",
506
+ initialValue: true
507
+ });
508
+ if (isCancel(retryWithNewKey) || !retryWithNewKey) {
509
+ cancel("Operation cancelled.");
510
+ process.exit(0);
511
+ }
512
+ const newKey = await text({
513
+ message: "Enter your Anthropic API Key (sk-...):",
514
+ placeholder: "sk-ant-api...",
515
+ validate: (value) => {
516
+ if (!value) return "API Key is required";
517
+ if (!value.startsWith("sk-")) return "Invalid API Key format (should start with sk-)";
518
+ }
519
+ });
520
+ if (isCancel(newKey)) {
521
+ cancel("Operation cancelled.");
522
+ process.exit(0);
523
+ }
524
+ apiKey = newKey;
525
+ process.env.ANTHROPIC_API_KEY = apiKey;
526
+ await storeKey(apiKey);
527
+ note("API Key updated. Retrying...", "Key Updated");
528
+ continue;
529
+ }
502
530
  cancel(`Error: ${error.message}`);
503
531
  return;
504
532
  }
505
533
  s.stop("Message generated.");
506
- const maxWidth = 80;
534
+ const terminalWidth = process.stdout.columns || 80;
535
+ const maxWidth = Math.max(40, terminalWidth - 12);
507
536
  const lines = commitMessage.split("\n");
508
537
  const wrappedLines = [];
509
538
  for (const line of lines) {
@@ -513,11 +542,21 @@ async function main() {
513
542
  const words = line.split(" ");
514
543
  let currentLine = "";
515
544
  for (const word of words) {
516
- if ((currentLine + " " + word).trim().length <= maxWidth) {
517
- currentLine = currentLine ? currentLine + " " + word : word;
545
+ const testLine = currentLine ? currentLine + " " + word : word;
546
+ if (testLine.length <= maxWidth) {
547
+ currentLine = testLine;
518
548
  } else {
519
549
  if (currentLine) wrappedLines.push(currentLine);
520
- currentLine = word;
550
+ if (word.length > maxWidth) {
551
+ let remaining = word;
552
+ while (remaining.length > maxWidth) {
553
+ wrappedLines.push(remaining.substring(0, maxWidth));
554
+ remaining = remaining.substring(maxWidth);
555
+ }
556
+ currentLine = remaining;
557
+ } else {
558
+ currentLine = word;
559
+ }
521
560
  }
522
561
  }
523
562
  if (currentLine) wrappedLines.push(currentLine);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-agent-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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",