commit-agent-cli 0.1.4 → 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 +64 -26
- 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 });
|
|
@@ -432,20 +435,26 @@ var packageJson = JSON.parse(
|
|
|
432
435
|
);
|
|
433
436
|
var notifier = updateNotifier({
|
|
434
437
|
pkg: packageJson,
|
|
435
|
-
updateCheckInterval: 1e3 * 60 * 60
|
|
436
|
-
// Check once per
|
|
438
|
+
updateCheckInterval: 1e3 * 60 * 60
|
|
439
|
+
// Check once per hour (was 24h)
|
|
437
440
|
});
|
|
438
441
|
if (notifier.update) {
|
|
439
|
-
const currentVersion =
|
|
440
|
-
const latestVersion =
|
|
441
|
-
const command = import_picocolors.default.cyan(`npm install -g ${packageJson.name}`);
|
|
442
|
+
const currentVersion = notifier.update.current;
|
|
443
|
+
const latestVersion = notifier.update.latest;
|
|
442
444
|
console.log("");
|
|
443
|
-
console.log(import_picocolors.default.yellow("\
|
|
444
|
-
console.log(import_picocolors.default.yellow("\u2502") + "
|
|
445
|
-
console.log(import_picocolors.default.yellow("\u2502") + "
|
|
446
|
-
console.log(import_picocolors.default.yellow("\
|
|
445
|
+
console.log(import_picocolors.default.yellow("\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"));
|
|
446
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
447
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.bold("New version of commit-cli is available!") + " " + import_picocolors.default.yellow("\u2502"));
|
|
448
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
449
|
+
console.log(import_picocolors.default.yellow("\u2502") + " Current: " + import_picocolors.default.dim(currentVersion) + " \u2192 Latest: " + import_picocolors.default.green(import_picocolors.default.bold(latestVersion)) + " " + import_picocolors.default.yellow("\u2502"));
|
|
450
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
451
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.dim("Update after you finish by running:") + " " + import_picocolors.default.yellow("\u2502"));
|
|
452
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.cyan(import_picocolors.default.bold(`npm install -g ${packageJson.name}@latest`)) + " " + import_picocolors.default.yellow("\u2502"));
|
|
453
|
+
console.log(import_picocolors.default.yellow("\u2502") + " " + import_picocolors.default.yellow("\u2502"));
|
|
454
|
+
console.log(import_picocolors.default.yellow("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"));
|
|
447
455
|
console.log("");
|
|
448
456
|
}
|
|
457
|
+
notifier.notify({ defer: false, isGlobal: true });
|
|
449
458
|
var CONFIG_PATH = join2(homedir(), ".commit-cli.json");
|
|
450
459
|
async function getStoredKey() {
|
|
451
460
|
try {
|
|
@@ -514,18 +523,24 @@ async function main() {
|
|
|
514
523
|
let preferences = await getStoredPreferences();
|
|
515
524
|
if (!preferences) {
|
|
516
525
|
note("Let's set up your commit message preferences (one-time setup)", "First Time Setup");
|
|
517
|
-
const useConventional = await
|
|
526
|
+
const useConventional = await select({
|
|
518
527
|
message: "Use conventional commit prefixes (feat:, fix:, chore:, etc.)?",
|
|
528
|
+
options: [
|
|
529
|
+
{ value: true, label: "Yes" },
|
|
530
|
+
{ value: false, label: "No" }
|
|
531
|
+
],
|
|
519
532
|
initialValue: true
|
|
520
533
|
});
|
|
521
534
|
if (isCancel(useConventional)) {
|
|
522
535
|
cancel("Operation cancelled.");
|
|
523
536
|
process.exit(0);
|
|
524
537
|
}
|
|
525
|
-
const styleChoice = await
|
|
538
|
+
const styleChoice = await select({
|
|
526
539
|
message: "Prefer descriptive commit messages?",
|
|
527
|
-
|
|
528
|
-
|
|
540
|
+
options: [
|
|
541
|
+
{ value: true, label: "Descriptive (detailed explanations)" },
|
|
542
|
+
{ value: false, label: "Concise (short and to the point)" }
|
|
543
|
+
],
|
|
529
544
|
initialValue: false
|
|
530
545
|
});
|
|
531
546
|
if (isCancel(styleChoice)) {
|
|
@@ -550,16 +565,22 @@ async function main() {
|
|
|
550
565
|
s.stop("Changes detected.");
|
|
551
566
|
let commitMessage = "";
|
|
552
567
|
let confirmed = false;
|
|
568
|
+
let userFeedback = void 0;
|
|
553
569
|
while (!confirmed) {
|
|
554
570
|
s.start("Generating commit message (Agent is exploring)...");
|
|
555
571
|
try {
|
|
556
|
-
commitMessage = await generateCommitMessage(diff, preferences);
|
|
572
|
+
commitMessage = await generateCommitMessage(diff, preferences, userFeedback);
|
|
573
|
+
userFeedback = void 0;
|
|
557
574
|
} catch (error) {
|
|
558
575
|
s.stop("Generation failed.");
|
|
559
576
|
if (error.message?.includes("401") || error.message?.includes("authentication_error") || error.message?.includes("invalid x-api-key") || error.message?.includes("invalid api key")) {
|
|
560
577
|
cancel("Invalid API Key detected.");
|
|
561
|
-
const retryWithNewKey = await
|
|
578
|
+
const retryWithNewKey = await select({
|
|
562
579
|
message: "Would you like to enter a new API key?",
|
|
580
|
+
options: [
|
|
581
|
+
{ value: true, label: "Yes" },
|
|
582
|
+
{ value: false, label: "No" }
|
|
583
|
+
],
|
|
563
584
|
initialValue: true
|
|
564
585
|
});
|
|
565
586
|
if (isCancel(retryWithNewKey) || !retryWithNewKey) {
|
|
@@ -621,10 +642,12 @@ async function main() {
|
|
|
621
642
|
}
|
|
622
643
|
const formattedMessage = wrappedLines.map((line) => import_picocolors.default.cyan(line)).join("\n");
|
|
623
644
|
note(formattedMessage, import_picocolors.default.bold("Proposed Commit Message"));
|
|
624
|
-
const action = await
|
|
645
|
+
const action = await select({
|
|
625
646
|
message: "Do you want to use this message?",
|
|
626
|
-
|
|
627
|
-
|
|
647
|
+
options: [
|
|
648
|
+
{ value: true, label: "Yes, commit" },
|
|
649
|
+
{ value: false, label: "No, regenerate or cancel" }
|
|
650
|
+
]
|
|
628
651
|
});
|
|
629
652
|
if (isCancel(action)) {
|
|
630
653
|
cancel("Operation cancelled.");
|
|
@@ -633,22 +656,37 @@ async function main() {
|
|
|
633
656
|
if (action) {
|
|
634
657
|
confirmed = true;
|
|
635
658
|
} else {
|
|
636
|
-
const nextStep = await
|
|
659
|
+
const nextStep = await select({
|
|
637
660
|
message: "Try again?",
|
|
638
|
-
|
|
639
|
-
|
|
661
|
+
options: [
|
|
662
|
+
{ value: true, label: "Regenerate" },
|
|
663
|
+
{ value: false, label: "Cancel" }
|
|
664
|
+
]
|
|
640
665
|
});
|
|
641
666
|
if (!nextStep || isCancel(nextStep)) {
|
|
642
667
|
cancel("Operation cancelled.");
|
|
643
668
|
process.exit(0);
|
|
644
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;
|
|
645
679
|
}
|
|
646
680
|
}
|
|
647
681
|
s.start("Committing...");
|
|
648
682
|
await commit(commitMessage);
|
|
649
683
|
s.stop("Committed!");
|
|
650
|
-
const shouldPush = await
|
|
651
|
-
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
|
+
]
|
|
652
690
|
});
|
|
653
691
|
if (isCancel(shouldPush)) {
|
|
654
692
|
outro(`Changes committed but NOT pushed.`);
|