commit-agent-cli 0.1.5 → 0.1.6
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.
- package/dist/index.js +49 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -100,7 +100,7 @@ var require_picocolors = __commonJS({
|
|
|
100
100
|
|
|
101
101
|
// src/index.ts
|
|
102
102
|
import "dotenv/config";
|
|
103
|
-
import { intro, outro, text, spinner,
|
|
103
|
+
import { intro, outro, text, spinner, isCancel, cancel, note, select } from "@clack/prompts";
|
|
104
104
|
|
|
105
105
|
// src/git.ts
|
|
106
106
|
import { execa } from "execa";
|
|
@@ -349,7 +349,7 @@ function getApp() {
|
|
|
349
349
|
app = workflow.compile();
|
|
350
350
|
return app;
|
|
351
351
|
}
|
|
352
|
-
async function generateCommitMessage(diff, preferences) {
|
|
352
|
+
async function generateCommitMessage(diff, preferences, userFeedback) {
|
|
353
353
|
const conventionalGuide = preferences.useConventionalCommits ? "Use conventional commit format with prefixes like feat:, fix:, chore:, docs:, style:, refactor:, test:, etc." : "Do NOT use conventional commit prefixes. Write natural commit messages.";
|
|
354
354
|
const styleGuide = preferences.commitMessageStyle === "descriptive" ? 'Be descriptive and detailed. Explain the "why" behind changes when relevant. Multi-line messages are encouraged.' : "Be concise and to the point. Keep it short, ideally one line.";
|
|
355
355
|
const systemPrompt = `You are an expert developer. Your task is to generate a commit message for the provided git diff.
|
|
@@ -386,7 +386,10 @@ DEFAULT ACTION: Read the diff, generate the message, done. NO TOOLS.
|
|
|
386
386
|
new SystemMessage(systemPrompt),
|
|
387
387
|
new HumanMessage(`Generate a commit message for this diff:
|
|
388
388
|
|
|
389
|
-
${diff}`
|
|
389
|
+
${diff}${userFeedback ? `
|
|
390
|
+
|
|
391
|
+
User feedback on previous attempt: ${userFeedback}
|
|
392
|
+
Please adjust the commit message based on this feedback.` : ""}`)
|
|
390
393
|
];
|
|
391
394
|
const graph = getApp();
|
|
392
395
|
const result = await graph.invoke({ messages });
|
|
@@ -520,18 +523,24 @@ async function main() {
|
|
|
520
523
|
let preferences = await getStoredPreferences();
|
|
521
524
|
if (!preferences) {
|
|
522
525
|
note("Let's set up your commit message preferences (one-time setup)", "First Time Setup");
|
|
523
|
-
const useConventional = await
|
|
526
|
+
const useConventional = await select({
|
|
524
527
|
message: "Use conventional commit prefixes (feat:, fix:, chore:, etc.)?",
|
|
528
|
+
options: [
|
|
529
|
+
{ value: true, label: "Yes" },
|
|
530
|
+
{ value: false, label: "No" }
|
|
531
|
+
],
|
|
525
532
|
initialValue: true
|
|
526
533
|
});
|
|
527
534
|
if (isCancel(useConventional)) {
|
|
528
535
|
cancel("Operation cancelled.");
|
|
529
536
|
process.exit(0);
|
|
530
537
|
}
|
|
531
|
-
const styleChoice = await
|
|
538
|
+
const styleChoice = await select({
|
|
532
539
|
message: "Prefer descriptive commit messages?",
|
|
533
|
-
|
|
534
|
-
|
|
540
|
+
options: [
|
|
541
|
+
{ value: true, label: "Descriptive (detailed explanations)" },
|
|
542
|
+
{ value: false, label: "Concise (short and to the point)" }
|
|
543
|
+
],
|
|
535
544
|
initialValue: false
|
|
536
545
|
});
|
|
537
546
|
if (isCancel(styleChoice)) {
|
|
@@ -556,16 +565,22 @@ async function main() {
|
|
|
556
565
|
s.stop("Changes detected.");
|
|
557
566
|
let commitMessage = "";
|
|
558
567
|
let confirmed = false;
|
|
568
|
+
let userFeedback = void 0;
|
|
559
569
|
while (!confirmed) {
|
|
560
570
|
s.start("Generating commit message (Agent is exploring)...");
|
|
561
571
|
try {
|
|
562
|
-
commitMessage = await generateCommitMessage(diff, preferences);
|
|
572
|
+
commitMessage = await generateCommitMessage(diff, preferences, userFeedback);
|
|
573
|
+
userFeedback = void 0;
|
|
563
574
|
} catch (error) {
|
|
564
575
|
s.stop("Generation failed.");
|
|
565
576
|
if (error.message?.includes("401") || error.message?.includes("authentication_error") || error.message?.includes("invalid x-api-key") || error.message?.includes("invalid api key")) {
|
|
566
577
|
cancel("Invalid API Key detected.");
|
|
567
|
-
const retryWithNewKey = await
|
|
578
|
+
const retryWithNewKey = await select({
|
|
568
579
|
message: "Would you like to enter a new API key?",
|
|
580
|
+
options: [
|
|
581
|
+
{ value: true, label: "Yes" },
|
|
582
|
+
{ value: false, label: "No" }
|
|
583
|
+
],
|
|
569
584
|
initialValue: true
|
|
570
585
|
});
|
|
571
586
|
if (isCancel(retryWithNewKey) || !retryWithNewKey) {
|
|
@@ -627,10 +642,12 @@ async function main() {
|
|
|
627
642
|
}
|
|
628
643
|
const formattedMessage = wrappedLines.map((line) => import_picocolors.default.cyan(line)).join("\n");
|
|
629
644
|
note(formattedMessage, import_picocolors.default.bold("Proposed Commit Message"));
|
|
630
|
-
const action = await
|
|
645
|
+
const action = await select({
|
|
631
646
|
message: "Do you want to use this message?",
|
|
632
|
-
|
|
633
|
-
|
|
647
|
+
options: [
|
|
648
|
+
{ value: true, label: "Yes, commit" },
|
|
649
|
+
{ value: false, label: "No, regenerate or cancel" }
|
|
650
|
+
]
|
|
634
651
|
});
|
|
635
652
|
if (isCancel(action)) {
|
|
636
653
|
cancel("Operation cancelled.");
|
|
@@ -639,22 +656,37 @@ async function main() {
|
|
|
639
656
|
if (action) {
|
|
640
657
|
confirmed = true;
|
|
641
658
|
} else {
|
|
642
|
-
const nextStep = await
|
|
659
|
+
const nextStep = await select({
|
|
643
660
|
message: "Try again?",
|
|
644
|
-
|
|
645
|
-
|
|
661
|
+
options: [
|
|
662
|
+
{ value: true, label: "Regenerate" },
|
|
663
|
+
{ value: false, label: "Cancel" }
|
|
664
|
+
]
|
|
646
665
|
});
|
|
647
666
|
if (!nextStep || isCancel(nextStep)) {
|
|
648
667
|
cancel("Operation cancelled.");
|
|
649
668
|
process.exit(0);
|
|
650
669
|
}
|
|
670
|
+
const feedback = await text({
|
|
671
|
+
message: "How should I adjust it?",
|
|
672
|
+
placeholder: "e.g., make it shorter, add more detail, or press enter to skip"
|
|
673
|
+
});
|
|
674
|
+
if (isCancel(feedback)) {
|
|
675
|
+
cancel("Operation cancelled.");
|
|
676
|
+
process.exit(0);
|
|
677
|
+
}
|
|
678
|
+
userFeedback = feedback && feedback.trim() !== "" ? feedback : void 0;
|
|
651
679
|
}
|
|
652
680
|
}
|
|
653
681
|
s.start("Committing...");
|
|
654
682
|
await commit(commitMessage);
|
|
655
683
|
s.stop("Committed!");
|
|
656
|
-
const shouldPush = await
|
|
657
|
-
message: "Do you want to push changes now?"
|
|
684
|
+
const shouldPush = await select({
|
|
685
|
+
message: "Do you want to push changes now?",
|
|
686
|
+
options: [
|
|
687
|
+
{ value: true, label: "Yes" },
|
|
688
|
+
{ value: false, label: "No" }
|
|
689
|
+
]
|
|
658
690
|
});
|
|
659
691
|
if (isCancel(shouldPush)) {
|
|
660
692
|
outro(`Changes committed but NOT pushed.`);
|