@elsikora/commitizen-plugin-commitlint-ai 1.0.0-dev.1
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/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/cjs/ManualProcess.d.ts +6 -0
- package/dist/cjs/ManualProcess.d.ts.map +1 -0
- package/dist/cjs/ManualProcess.js +111 -0
- package/dist/cjs/ManualProcess.js.map +1 -0
- package/dist/cjs/Process.d.ts +6 -0
- package/dist/cjs/Process.d.ts.map +1 -0
- package/dist/cjs/Process.js +165 -0
- package/dist/cjs/Process.js.map +1 -0
- package/dist/cjs/Question.d.ts +46 -0
- package/dist/cjs/Question.d.ts.map +1 -0
- package/dist/cjs/SectionBody.d.ts +4 -0
- package/dist/cjs/SectionBody.d.ts.map +1 -0
- package/dist/cjs/SectionFooter.d.ts +13 -0
- package/dist/cjs/SectionFooter.d.ts.map +1 -0
- package/dist/cjs/SectionHeader.d.ts +15 -0
- package/dist/cjs/SectionHeader.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +70 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/commitlintConfig.d.ts +4 -0
- package/dist/cjs/services/commitlintConfig.d.ts.map +1 -0
- package/dist/cjs/services/commitlintConfig.js +198 -0
- package/dist/cjs/services/commitlintConfig.js.map +1 -0
- package/dist/cjs/services/commitlintValidator.d.ts +20 -0
- package/dist/cjs/services/commitlintValidator.d.ts.map +1 -0
- package/dist/cjs/services/commitlintValidator.js +145 -0
- package/dist/cjs/services/commitlintValidator.js.map +1 -0
- package/dist/cjs/services/getRuleQuestionConfig.d.ts +4 -0
- package/dist/cjs/services/getRuleQuestionConfig.d.ts.map +1 -0
- package/dist/cjs/services/llm/anthropic.d.ts +3 -0
- package/dist/cjs/services/llm/anthropic.d.ts.map +1 -0
- package/dist/cjs/services/llm/anthropic.js +118 -0
- package/dist/cjs/services/llm/anthropic.js.map +1 -0
- package/dist/cjs/services/llm/config.d.ts +5 -0
- package/dist/cjs/services/llm/config.d.ts.map +1 -0
- package/dist/cjs/services/llm/config.js +181 -0
- package/dist/cjs/services/llm/config.js.map +1 -0
- package/dist/cjs/services/llm/index.d.ts +6 -0
- package/dist/cjs/services/llm/index.d.ts.map +1 -0
- package/dist/cjs/services/llm/index.js +398 -0
- package/dist/cjs/services/llm/index.js.map +1 -0
- package/dist/cjs/services/llm/models.d.ts +34 -0
- package/dist/cjs/services/llm/models.d.ts.map +1 -0
- package/dist/cjs/services/llm/models.js +65 -0
- package/dist/cjs/services/llm/models.js.map +1 -0
- package/dist/cjs/services/llm/openai.d.ts +3 -0
- package/dist/cjs/services/llm/openai.d.ts.map +1 -0
- package/dist/cjs/services/llm/openai.js +111 -0
- package/dist/cjs/services/llm/openai.js.map +1 -0
- package/dist/cjs/services/llm/types.d.ts +71 -0
- package/dist/cjs/services/llm/types.d.ts.map +1 -0
- package/dist/cjs/store/defaultPromptConfigs.d.ts +33 -0
- package/dist/cjs/store/defaultPromptConfigs.d.ts.map +1 -0
- package/dist/cjs/store/defaultPromptConfigs.js +39 -0
- package/dist/cjs/store/defaultPromptConfigs.js.map +1 -0
- package/dist/cjs/store/prompts.d.ts +6 -0
- package/dist/cjs/store/prompts.d.ts.map +1 -0
- package/dist/cjs/store/prompts.js +40 -0
- package/dist/cjs/store/prompts.js.map +1 -0
- package/dist/cjs/store/rules.d.ts +7 -0
- package/dist/cjs/store/rules.d.ts.map +1 -0
- package/dist/cjs/types.d.ts +3 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/utils/case-function.d.ts +9 -0
- package/dist/cjs/utils/case-function.d.ts.map +1 -0
- package/dist/cjs/utils/full-stop-function.d.ts +9 -0
- package/dist/cjs/utils/full-stop-function.d.ts.map +1 -0
- package/dist/cjs/utils/leading-blank-function.d.ts +8 -0
- package/dist/cjs/utils/leading-blank-function.d.ts.map +1 -0
- package/dist/cjs/utils/rules.d.ts +26 -0
- package/dist/cjs/utils/rules.d.ts.map +1 -0
- package/dist/esm/ManualProcess.d.ts +6 -0
- package/dist/esm/ManualProcess.d.ts.map +1 -0
- package/dist/esm/ManualProcess.js +107 -0
- package/dist/esm/ManualProcess.js.map +1 -0
- package/dist/esm/Process.d.ts +6 -0
- package/dist/esm/Process.d.ts.map +1 -0
- package/dist/esm/Process.js +161 -0
- package/dist/esm/Process.js.map +1 -0
- package/dist/esm/Question.d.ts +46 -0
- package/dist/esm/Question.d.ts.map +1 -0
- package/dist/esm/SectionBody.d.ts +4 -0
- package/dist/esm/SectionBody.d.ts.map +1 -0
- package/dist/esm/SectionFooter.d.ts +13 -0
- package/dist/esm/SectionFooter.d.ts.map +1 -0
- package/dist/esm/SectionHeader.d.ts +15 -0
- package/dist/esm/SectionHeader.d.ts.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +67 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/commitlintConfig.d.ts +4 -0
- package/dist/esm/services/commitlintConfig.d.ts.map +1 -0
- package/dist/esm/services/commitlintConfig.js +196 -0
- package/dist/esm/services/commitlintConfig.js.map +1 -0
- package/dist/esm/services/commitlintValidator.d.ts +20 -0
- package/dist/esm/services/commitlintValidator.d.ts.map +1 -0
- package/dist/esm/services/commitlintValidator.js +142 -0
- package/dist/esm/services/commitlintValidator.js.map +1 -0
- package/dist/esm/services/getRuleQuestionConfig.d.ts +4 -0
- package/dist/esm/services/getRuleQuestionConfig.d.ts.map +1 -0
- package/dist/esm/services/llm/anthropic.d.ts +3 -0
- package/dist/esm/services/llm/anthropic.d.ts.map +1 -0
- package/dist/esm/services/llm/anthropic.js +116 -0
- package/dist/esm/services/llm/anthropic.js.map +1 -0
- package/dist/esm/services/llm/config.d.ts +5 -0
- package/dist/esm/services/llm/config.d.ts.map +1 -0
- package/dist/esm/services/llm/config.js +178 -0
- package/dist/esm/services/llm/config.js.map +1 -0
- package/dist/esm/services/llm/index.d.ts +6 -0
- package/dist/esm/services/llm/index.d.ts.map +1 -0
- package/dist/esm/services/llm/index.js +393 -0
- package/dist/esm/services/llm/index.js.map +1 -0
- package/dist/esm/services/llm/models.d.ts +34 -0
- package/dist/esm/services/llm/models.d.ts.map +1 -0
- package/dist/esm/services/llm/models.js +60 -0
- package/dist/esm/services/llm/models.js.map +1 -0
- package/dist/esm/services/llm/openai.d.ts +3 -0
- package/dist/esm/services/llm/openai.d.ts.map +1 -0
- package/dist/esm/services/llm/openai.js +109 -0
- package/dist/esm/services/llm/openai.js.map +1 -0
- package/dist/esm/services/llm/types.d.ts +71 -0
- package/dist/esm/services/llm/types.d.ts.map +1 -0
- package/dist/esm/store/defaultPromptConfigs.d.ts +33 -0
- package/dist/esm/store/defaultPromptConfigs.d.ts.map +1 -0
- package/dist/esm/store/defaultPromptConfigs.js +35 -0
- package/dist/esm/store/defaultPromptConfigs.js.map +1 -0
- package/dist/esm/store/prompts.d.ts +6 -0
- package/dist/esm/store/prompts.d.ts.map +1 -0
- package/dist/esm/store/prompts.js +38 -0
- package/dist/esm/store/prompts.js.map +1 -0
- package/dist/esm/store/rules.d.ts +7 -0
- package/dist/esm/store/rules.d.ts.map +1 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/utils/case-function.d.ts +9 -0
- package/dist/esm/utils/case-function.d.ts.map +1 -0
- package/dist/esm/utils/full-stop-function.d.ts +9 -0
- package/dist/esm/utils/full-stop-function.d.ts.map +1 -0
- package/dist/esm/utils/leading-blank-function.d.ts +8 -0
- package/dist/esm/utils/leading-blank-function.d.ts.map +1 -0
- package/dist/esm/utils/rules.d.ts +26 -0
- package/dist/esm/utils/rules.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.cjs +6 -0
- package/package.json +101 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_fs = require('node:fs');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var load = require('@commitlint/load');
|
|
6
|
+
var chalk = require('chalk');
|
|
7
|
+
var dotenv = require('dotenv');
|
|
8
|
+
var Process = require('./Process.js');
|
|
9
|
+
require('./services/llm/index.js');
|
|
10
|
+
var config = require('./services/llm/config.js');
|
|
11
|
+
|
|
12
|
+
// Load environment variables from .env file
|
|
13
|
+
try {
|
|
14
|
+
dotenv.config();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Silently continue if .env file is not found or cannot be loaded
|
|
18
|
+
}
|
|
19
|
+
// Check what commit mode to use based on config, environment variable, and fallback file
|
|
20
|
+
const getCommitMode = () => {
|
|
21
|
+
try {
|
|
22
|
+
// First check environment variable (highest priority)
|
|
23
|
+
// Next check for manual flag file
|
|
24
|
+
if (node_fs.existsSync(node_path.join("./.elsikora", "manual"))) {
|
|
25
|
+
return "manual";
|
|
26
|
+
}
|
|
27
|
+
// Finally check config file
|
|
28
|
+
const config$1 = config.getLLMConfig();
|
|
29
|
+
if (config$1?.mode && // Validation is now done in config.ts to avoid duplicate messages
|
|
30
|
+
(config$1.mode === "auto" || config$1.mode === "manual")) {
|
|
31
|
+
return config$1.mode;
|
|
32
|
+
}
|
|
33
|
+
// Default to auto if not specified
|
|
34
|
+
return "auto";
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// In case of any errors, default to auto
|
|
38
|
+
return "auto";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Entry point for commitizen
|
|
43
|
+
* @param inquirerIns instance passed by commitizen, unused
|
|
44
|
+
* @param commit callback to execute with complete commit message
|
|
45
|
+
* @return {void}
|
|
46
|
+
*/
|
|
47
|
+
async function prompter(inquirerIns, commit) {
|
|
48
|
+
// eslint-disable-next-line @elsikora-typescript/typedef
|
|
49
|
+
await load().then(async ({ prompt = {}, rules }) => {
|
|
50
|
+
// Use process (AI mode) unless manual mode is enabled
|
|
51
|
+
const commitMode = getCommitMode();
|
|
52
|
+
if (commitMode === "manual") {
|
|
53
|
+
console.log(chalk.blue("Using manual commit mode..."));
|
|
54
|
+
// Import manualProcess dynamically to avoid loading AI deps when not needed
|
|
55
|
+
// eslint-disable-next-line @elsikora-typescript/typedef
|
|
56
|
+
await Promise.resolve().then(function () { return require('./ManualProcess.js'); }).then(async ({ default: manualProcess }) => {
|
|
57
|
+
await manualProcess(rules, prompt, inquirerIns).then(commit);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log(chalk.blue("Using AI-powered commit mode..."));
|
|
62
|
+
await Process.default(rules, prompt, inquirerIns).then(commit);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.getLLMConfig = config.getLLMConfig;
|
|
68
|
+
exports.setLLMConfig = config.setLLMConfig;
|
|
69
|
+
exports.prompter = prompter;
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":["loadDotEnvironment","existsSync","join","config","getLLMConfig","process"],"mappings":";;;;;;;;;;;AAcA;AACA,IAAI;AACH,IAAAA,aAAkB,EAAE;AACrB;AAAE,MAAM;;AAER;AASA;AACA,MAAM,aAAa,GAAG,MAAiB;AACtC,IAAA,IAAI;;;QAIH,IAAIC,kBAAU,CAACC,cAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,EAAE;AAC9C,YAAA,OAAO,QAAQ;;;AAIhB,QAAA,MAAMC,QAAM,GAAmDC,mBAAY,EAAE;AAE7E,QAAA,IACCD,QAAM,EAAE,IAAI;AACZ,aAACA,QAAM,CAAC,IAAI,KAAK,MAAM,IAAIA,QAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,EACnD;YACD,OAAOA,QAAM,CAAC,IAAI;;;AAInB,QAAA,OAAO,MAAM;;AACZ,IAAA,MAAM;;AAEP,QAAA,OAAO,MAAM;;AAEf,CAAC;AAED;;;;;AAKG;AACI,eAAe,QAAQ,CAC7B,WAEC,EACD,MAAc,EAAA;;AAGd,IAAA,MAAM,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,EAAE,KAAI;;AAElD,QAAA,MAAM,UAAU,GAAsB,aAAa,EAAE;AAErD,QAAA,IAAI,UAAU,KAAK,QAAQ,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;;;AAGtD,YAAA,MAAM,oDAAO,oBAAoB,KAAC,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,KAAI;AAC5E,gBAAA,MAAM,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AAC7D,aAAC,CAAC;;aACI;YACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAC1D,YAAA,MAAME,eAAO,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;;AAExD,KAAC,CAAC;AACH;;;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { QualifiedRules, UserPromptConfig } from "@commitlint/types";
|
|
2
|
+
import type { LLMPromptContext } from "./llm/types.js";
|
|
3
|
+
export declare function extractLLMPromptContext(rules: QualifiedRules, prompt: UserPromptConfig): LLMPromptContext;
|
|
4
|
+
//# sourceMappingURL=commitlintConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitlintConfig.d.ts","sourceRoot":"","sources":["../../../src/services/commitlintConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAkB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMvD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CA2PzG"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var types = require('@commitlint/types');
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line no-duplicate-imports
|
|
6
|
+
// eslint-disable-next-line @elsikora-sonar/cognitive-complexity
|
|
7
|
+
function extractLLMPromptContext(rules, prompt) {
|
|
8
|
+
const context = {
|
|
9
|
+
subject: {},
|
|
10
|
+
};
|
|
11
|
+
// Extract type enum
|
|
12
|
+
if (rules["type-enum"] && rules["type-enum"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
13
|
+
const typeEnumRule = rules["type-enum"];
|
|
14
|
+
if (typeEnumRule && typeEnumRule.length >= 3 && Array.isArray(typeEnumRule[2])) {
|
|
15
|
+
context.typeEnum = typeEnumRule[2];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Extract type case rules
|
|
19
|
+
if (rules["type-case"] && rules["type-case"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
20
|
+
const typeCaseRule = rules["type-case"];
|
|
21
|
+
if (typeCaseRule && typeCaseRule.length >= 3) {
|
|
22
|
+
context.typeCase = Array.isArray(typeCaseRule[2]) ? typeCaseRule[2] : [typeCaseRule[2]];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Extract type empty rules
|
|
26
|
+
if (rules["type-empty"] && rules["type-empty"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
27
|
+
const typeEmptyRule = rules["type-empty"];
|
|
28
|
+
if (typeEmptyRule && typeEmptyRule.length >= 2) {
|
|
29
|
+
context.typeEmpty = typeEmptyRule[1] !== "never";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Extract type descriptions from prompt config
|
|
33
|
+
if (prompt.questions?.type) {
|
|
34
|
+
// Get the type description
|
|
35
|
+
if (prompt.questions.type.description) {
|
|
36
|
+
context.typeDescription = prompt.questions.type.description;
|
|
37
|
+
}
|
|
38
|
+
// Get the enum descriptions
|
|
39
|
+
if (prompt.questions.type.enum) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
context.typeDescriptions = prompt.questions.type.enum;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Extract scope case rules
|
|
45
|
+
if (rules["scope-case"] && rules["scope-case"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
46
|
+
const scopeCaseRule = rules["scope-case"];
|
|
47
|
+
if (scopeCaseRule && scopeCaseRule.length >= 3) {
|
|
48
|
+
context.scopeCase = Array.isArray(scopeCaseRule[2]) ? scopeCaseRule[2] : [scopeCaseRule[2]];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Extract scope empty rules
|
|
52
|
+
if (rules["scope-empty"] && rules["scope-empty"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
53
|
+
const scopeEmptyRule = rules["scope-empty"];
|
|
54
|
+
if (scopeEmptyRule && scopeEmptyRule.length >= 2) {
|
|
55
|
+
context.scopeEmpty = scopeEmptyRule[1] !== "never";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Extract scope max length
|
|
59
|
+
if (rules["scope-max-length"] && rules["scope-max-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
60
|
+
const scopeMaxLengthRule = rules["scope-max-length"];
|
|
61
|
+
if (scopeMaxLengthRule && scopeMaxLengthRule.length >= 3 && typeof scopeMaxLengthRule[2] === "number") {
|
|
62
|
+
context.scopeMaxLength = scopeMaxLengthRule[2];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Extract case function options for subject
|
|
66
|
+
if (rules["subject-case"] && rules["subject-case"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
67
|
+
const subjectCaseRule = rules["subject-case"];
|
|
68
|
+
if (subjectCaseRule && subjectCaseRule.length >= 3) {
|
|
69
|
+
context.subject.case = Array.isArray(subjectCaseRule[2]) ? subjectCaseRule[2] : [subjectCaseRule[2]];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Extract subject-empty rules
|
|
73
|
+
if (rules["subject-empty"] && rules["subject-empty"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
74
|
+
const subjectEmptyRule = rules["subject-empty"];
|
|
75
|
+
if (subjectEmptyRule && subjectEmptyRule.length >= 2) {
|
|
76
|
+
context.subject.empty = subjectEmptyRule[1] !== "never";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Extract subject full-stop rules
|
|
80
|
+
if (rules["subject-full-stop"] && rules["subject-full-stop"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
81
|
+
const subjectFullStopRule = rules["subject-full-stop"];
|
|
82
|
+
if (subjectFullStopRule && subjectFullStopRule.length >= 3) {
|
|
83
|
+
context.subject.fullStop = {
|
|
84
|
+
// eslint-disable-next-line @elsikora-typescript/naming-convention
|
|
85
|
+
required: subjectFullStopRule[1] === "always",
|
|
86
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-assignment
|
|
87
|
+
value: subjectFullStopRule[2],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Extract scope and subject descriptions from prompt config
|
|
92
|
+
if (prompt.questions?.scope?.description) {
|
|
93
|
+
context.scopeDescription = prompt.questions.scope.description;
|
|
94
|
+
}
|
|
95
|
+
if (prompt.questions?.subject?.description) {
|
|
96
|
+
context.subject.description = prompt.questions.subject.description;
|
|
97
|
+
}
|
|
98
|
+
// Extract header case rules
|
|
99
|
+
if (rules["header-case"] && rules["header-case"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
100
|
+
const headerCaseRule = rules["header-case"];
|
|
101
|
+
if (headerCaseRule && headerCaseRule.length >= 3) {
|
|
102
|
+
context.headerCase = Array.isArray(headerCaseRule[2]) ? headerCaseRule[2] : [headerCaseRule[2]];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Extract header full-stop rules
|
|
106
|
+
if (rules["header-full-stop"] && rules["header-full-stop"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
107
|
+
const headerFullStopRule = rules["header-full-stop"];
|
|
108
|
+
if (headerFullStopRule && headerFullStopRule.length >= 3) {
|
|
109
|
+
context.headerFullStop = {
|
|
110
|
+
// eslint-disable-next-line @elsikora-typescript/naming-convention
|
|
111
|
+
required: headerFullStopRule[1] === "always",
|
|
112
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-assignment
|
|
113
|
+
value: headerFullStopRule[2],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Extract header max length
|
|
118
|
+
if (rules["header-max-length"] && rules["header-max-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
119
|
+
const headerMaxLengthRule = rules["header-max-length"];
|
|
120
|
+
if (headerMaxLengthRule && headerMaxLengthRule.length >= 3 && typeof headerMaxLengthRule[2] === "number") {
|
|
121
|
+
context.headerMaxLength = headerMaxLengthRule[2];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Extract header min length
|
|
125
|
+
if (rules["header-min-length"] && rules["header-min-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
126
|
+
const headerMinLengthRule = rules["header-min-length"];
|
|
127
|
+
if (headerMinLengthRule && headerMinLengthRule.length >= 3 && typeof headerMinLengthRule[2] === "number") {
|
|
128
|
+
context.headerMinLength = headerMinLengthRule[2];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Extract subject max length
|
|
132
|
+
if (rules["subject-max-length"] && rules["subject-max-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
133
|
+
const subjectMaxLengthRule = rules["subject-max-length"];
|
|
134
|
+
if (subjectMaxLengthRule && subjectMaxLengthRule.length >= 3 && typeof subjectMaxLengthRule[2] === "number") {
|
|
135
|
+
context.subject.maxLength = subjectMaxLengthRule[2];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Extract subject min length
|
|
139
|
+
if (rules["subject-min-length"] && rules["subject-min-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
140
|
+
const subjectMinLengthRule = rules["subject-min-length"];
|
|
141
|
+
if (subjectMinLengthRule && subjectMinLengthRule.length >= 3 && typeof subjectMinLengthRule[2] === "number") {
|
|
142
|
+
context.subject.minLength = subjectMinLengthRule[2];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Extract body related rules
|
|
146
|
+
context.body = {};
|
|
147
|
+
// Body max length
|
|
148
|
+
if (rules["body-max-length"] && rules["body-max-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
149
|
+
const bodyMaxLengthRule = rules["body-max-length"];
|
|
150
|
+
if (bodyMaxLengthRule && bodyMaxLengthRule.length >= 3 && typeof bodyMaxLengthRule[2] === "number") {
|
|
151
|
+
context.body.maxLength = bodyMaxLengthRule[2];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Body max line length
|
|
155
|
+
if (rules["body-max-line-length"] && rules["body-max-line-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
156
|
+
const bodyMaxLineLengthRule = rules["body-max-line-length"];
|
|
157
|
+
if (bodyMaxLineLengthRule && bodyMaxLineLengthRule.length >= 3 && typeof bodyMaxLineLengthRule[2] === "number") {
|
|
158
|
+
context.body.maxLineLength = bodyMaxLineLengthRule[2];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Body full-stop
|
|
162
|
+
if (rules["body-full-stop"] && rules["body-full-stop"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
163
|
+
const bodyFullStopRule = rules["body-full-stop"];
|
|
164
|
+
if (bodyFullStopRule && bodyFullStopRule.length >= 3) {
|
|
165
|
+
context.body.fullStop = {
|
|
166
|
+
// eslint-disable-next-line @elsikora-typescript/naming-convention
|
|
167
|
+
required: bodyFullStopRule[1] === "always",
|
|
168
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-assignment
|
|
169
|
+
value: bodyFullStopRule[2],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Body-leading-blank
|
|
174
|
+
if (rules["body-leading-blank"] && rules["body-leading-blank"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
175
|
+
const bodyLeadingBlankRule = rules["body-leading-blank"];
|
|
176
|
+
if (bodyLeadingBlankRule && bodyLeadingBlankRule.length >= 2) {
|
|
177
|
+
context.body.leadingBlank = bodyLeadingBlankRule[1] === "always";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Footer-leading-blank
|
|
181
|
+
if (rules["footer-leading-blank"] && rules["footer-leading-blank"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
182
|
+
const footerLeadingBlankRule = rules["footer-leading-blank"];
|
|
183
|
+
if (footerLeadingBlankRule && footerLeadingBlankRule.length >= 2) {
|
|
184
|
+
context.footerLeadingBlank = footerLeadingBlankRule[1] === "always";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Footer-max-line-length
|
|
188
|
+
if (rules["footer-max-line-length"] && rules["footer-max-line-length"][0] !== types.RuleConfigSeverity.Disabled) {
|
|
189
|
+
const footerMaxLineLengthRule = rules["footer-max-line-length"];
|
|
190
|
+
if (footerMaxLineLengthRule && footerMaxLineLengthRule.length >= 3 && typeof footerMaxLineLengthRule[2] === "number") {
|
|
191
|
+
context.footerMaxLineLength = footerMaxLineLengthRule[2];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return context;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
exports.extractLLMPromptContext = extractLLMPromptContext;
|
|
198
|
+
//# sourceMappingURL=commitlintConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitlintConfig.js","sources":["../../../../src/services/commitlintConfig.ts"],"sourcesCont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Q,EAAE;AAC1G,QAAA,MAAM,uBAAuB,GAAQ,KAAK,CAAC,wBAAwB,CAAC;AAEpE,QAAA,IAAI,uBAAuB,IAAI,uBAAuB,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,uBAAuB,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AACrH,YAAA,OAAO,CAAC,mBAAmB,GAAG,uBAAuB,CAAC,CAAC,CAAC;;;AAI1D,IAAA,OAAO,OAAO;AACf;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CommitConfig, LLMPromptContext } from "./llm";
|
|
2
|
+
interface ValidationResult {
|
|
3
|
+
errors?: string;
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates a commit message and retries with LLM if there are errors
|
|
8
|
+
* @param commitConfig The original commit configuration
|
|
9
|
+
* @param promptContext The prompt context used to generate the commit
|
|
10
|
+
* @returns A promise that resolves to a valid commit message or null if manual entry is needed
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateAndFixCommitMessage(commitConfig: CommitConfig, promptContext: LLMPromptContext): Promise<null | string>;
|
|
13
|
+
/**
|
|
14
|
+
* Validates a commit message with commitlint
|
|
15
|
+
* @param commitMessage The commit message to validate
|
|
16
|
+
* @returns A promise that resolves to an object with the validation result
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateWithCommitlint(commitMessage: string): Promise<ValidationResult>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=commitlintValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitlintValidator.d.ts","sourceRoot":"","sources":["../../../src/services/commitlintValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAa5D,UAAU,gBAAgB;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAqErI;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAiB7F"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_child_process = require('node:child_process');
|
|
4
|
+
var node_util = require('node:util');
|
|
5
|
+
var chalk = require('chalk');
|
|
6
|
+
var index = require('./llm/index.js');
|
|
7
|
+
|
|
8
|
+
const execAsync = node_util.promisify(node_child_process.exec);
|
|
9
|
+
/**
|
|
10
|
+
* Validates a commit message and retries with LLM if there are errors
|
|
11
|
+
* @param commitConfig The original commit configuration
|
|
12
|
+
* @param promptContext The prompt context used to generate the commit
|
|
13
|
+
* @returns A promise that resolves to a valid commit message or null if manual entry is needed
|
|
14
|
+
*/
|
|
15
|
+
async function validateAndFixCommitMessage(commitConfig, promptContext) {
|
|
16
|
+
// Initial commit message
|
|
17
|
+
const commitMessage = constructCommitMessage(commitConfig);
|
|
18
|
+
// Validate with commitlint
|
|
19
|
+
const validation = await validateWithCommitlint(commitMessage);
|
|
20
|
+
// If valid, return the message
|
|
21
|
+
if (validation.isValid) {
|
|
22
|
+
return commitMessage;
|
|
23
|
+
}
|
|
24
|
+
// If not valid and we have errors, try to fix with LLM
|
|
25
|
+
if (!validation.isValid && validation.errors) {
|
|
26
|
+
console.log(chalk.yellow("Commit message failed validation. Attempting to fix..."));
|
|
27
|
+
const MAX_RETRIES = 3;
|
|
28
|
+
let currentConfig = commitConfig;
|
|
29
|
+
const allErrors = [];
|
|
30
|
+
// Attempt to fix the commit message up to MAX_RETRIES times
|
|
31
|
+
// eslint-disable-next-line @elsikora-typescript/typedef
|
|
32
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
33
|
+
// Add the current validation error to our history
|
|
34
|
+
if (validation.errors) {
|
|
35
|
+
allErrors.push(validation.errors);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
// Generate a fixed commit message with accumulated errors
|
|
39
|
+
currentConfig = await fixCommitMessageWithLLM(currentConfig, validation.errors ?? "", promptContext, allErrors.slice(0, -1));
|
|
40
|
+
// Construct and validate the new commit message
|
|
41
|
+
const fixedCommitMessage = constructCommitMessage(currentConfig);
|
|
42
|
+
const fixedValidation = await validateWithCommitlint(fixedCommitMessage);
|
|
43
|
+
// If valid, return the successful message
|
|
44
|
+
if (fixedValidation.isValid) {
|
|
45
|
+
console.log(chalk.green(`Commit message fixed successfully on attempt ${attempt + 1}!`));
|
|
46
|
+
return fixedCommitMessage;
|
|
47
|
+
}
|
|
48
|
+
// If we still have errors, continue with next attempt
|
|
49
|
+
if (fixedValidation.errors) {
|
|
50
|
+
console.log(chalk.yellow(`Fix attempt ${attempt + 1} still has errors. ${MAX_RETRIES - attempt - 1} retries left.`));
|
|
51
|
+
// Update the validation errors for the next iteration
|
|
52
|
+
validation.errors = fixedValidation.errors;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(chalk.red(`Error while trying to fix commit message (attempt ${attempt + 1}):`, error));
|
|
57
|
+
break; // Exit retry loop on error
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// If we exhausted all retries and still have issues
|
|
61
|
+
console.log(chalk.red(`Unable to fix commit message automatically after ${MAX_RETRIES} attempts.`));
|
|
62
|
+
console.log(chalk.yellow("Switching to manual commit entry mode..."));
|
|
63
|
+
return null; // Signal to switch to manual mode
|
|
64
|
+
}
|
|
65
|
+
// Default case, return original even if there were issues
|
|
66
|
+
return commitMessage;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Validates a commit message with commitlint
|
|
70
|
+
* @param commitMessage The commit message to validate
|
|
71
|
+
* @returns A promise that resolves to an object with the validation result
|
|
72
|
+
*/
|
|
73
|
+
async function validateWithCommitlint(commitMessage) {
|
|
74
|
+
try {
|
|
75
|
+
// Create temporary file with commit message
|
|
76
|
+
const cmd = `echo "${commitMessage}" | npx commitlint`;
|
|
77
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-call
|
|
78
|
+
await execAsync(cmd);
|
|
79
|
+
return { isValid: true };
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// If commitlint exits with non-zero code, it means there are validation errors
|
|
83
|
+
const typedError = error;
|
|
84
|
+
return {
|
|
85
|
+
errors: typedError.stdout ?? typedError.stderr ?? typedError.message,
|
|
86
|
+
isValid: false,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Constructs a commit message from a CommitConfig object
|
|
92
|
+
* @param commitConfig The commit configuration
|
|
93
|
+
* @returns The formatted commit message
|
|
94
|
+
*/
|
|
95
|
+
function constructCommitMessage(commitConfig) {
|
|
96
|
+
const type = commitConfig.type;
|
|
97
|
+
const scope = commitConfig.scope ? `(${commitConfig.scope})` : "";
|
|
98
|
+
const subject = commitConfig.subject;
|
|
99
|
+
const header = `${type}${scope}: ${subject}`;
|
|
100
|
+
// Body with optional breaking change
|
|
101
|
+
let body = "";
|
|
102
|
+
if (commitConfig.isBreaking) {
|
|
103
|
+
body = `BREAKING CHANGE: ${commitConfig.breakingBody ?? "This commit introduces breaking changes."}\n\n`;
|
|
104
|
+
}
|
|
105
|
+
if (commitConfig.body) {
|
|
106
|
+
body += commitConfig.body;
|
|
107
|
+
}
|
|
108
|
+
// Footer with issue references
|
|
109
|
+
let footer = "";
|
|
110
|
+
if (commitConfig.issues && commitConfig.issues.length > 0) {
|
|
111
|
+
footer = `Issues: ${commitConfig.issues.join(", ")}`;
|
|
112
|
+
}
|
|
113
|
+
if (commitConfig.references && commitConfig.references.length > 0) {
|
|
114
|
+
if (footer)
|
|
115
|
+
footer += "\n";
|
|
116
|
+
footer += `References: ${commitConfig.references.join(", ")}`;
|
|
117
|
+
}
|
|
118
|
+
// Combine all parts
|
|
119
|
+
return [header, body, footer].filter(Boolean).join("\n\n");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sends a commit message to the LLM for correction with provided errors
|
|
123
|
+
* @param commitConfig The original commit configuration
|
|
124
|
+
* @param errors The errors from commitlint
|
|
125
|
+
* @param promptContext The prompt context to use for regeneration
|
|
126
|
+
* @param previousErrors Optional accumulated errors from previous attempts
|
|
127
|
+
* @returns A promise that resolves to a new commit configuration
|
|
128
|
+
*/
|
|
129
|
+
async function fixCommitMessageWithLLM(commitConfig, errors, promptContext, previousErrors = []) {
|
|
130
|
+
// Create a history of all errors to help the LLM understand what needs fixing
|
|
131
|
+
const errorHistory = [...previousErrors, errors].map((error, index) => `Attempt ${index + 1} errors:\n${error}`).join("\n\n");
|
|
132
|
+
// Create an enhanced context that includes the original commit and errors
|
|
133
|
+
const enhancedContext = {
|
|
134
|
+
...promptContext,
|
|
135
|
+
// Add a note about the previous attempt and errors
|
|
136
|
+
diff: `${promptContext.diff ?? ""}\n\nCommit message failed validation with these errors:\n${errorHistory}\n\nOriginal commit structure:\n${JSON.stringify(commitConfig, null)}`,
|
|
137
|
+
};
|
|
138
|
+
console.log(chalk.yellow(`Commit message had validation errors. Asking LLM to fix... (Attempt ${previousErrors.length + 1})`));
|
|
139
|
+
// Generate a new commit message with the enhanced context
|
|
140
|
+
return await index.generateCommitMessage(enhancedContext);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
exports.validateAndFixCommitMessage = validateAndFixCommitMessage;
|
|
144
|
+
exports.validateWithCommitlint = validateWithCommitlint;
|
|
145
|
+
//# sourceMappingURL=commitlintValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitlintValidator.js","sources":["../../../../src/services/commitlintValidator.ts"],"sourcesContent":[null],"names":["promisify","exec","generateCommitMessage"],"mappings":";;;;;;;AAWA,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IAAA,MAAM,YAAY,GAAW,CAAC,GAAG,cAAc,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,KAAa,KAAK,CAAA,QAAA,EAAW,KAAK,GAAG,CAAC,CAAa,UAAA,EAAA,KAAK,CAAE,CAAA,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;;AAGrJ,IAAA,MAAM,eAAe,GAAqB;AACzC,QAAA,GAAG,aAAa;;AAEhB,QAAA,IAAI,EAAE,CAAG,EAAA,aAAa,CAAC,IAAI,IAAI,EAAE,CAA4D,yDAAA,EAAA,YAAY,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAE,CAAA;KAChL;AAED,IAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA,oEAAA,EAAuE,cAAc,CAAC,MAAM,GAAG,CAAC,CAAG,CAAA,CAAA,CAAC,CAAC;;AAG9H,IAAA,OAAO,MAAMC,2BAAqB,CAAC,eAAe,CAAC;AACpD;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRuleQuestionConfig.d.ts","sourceRoot":"","sources":["../../../src/services/getRuleQuestionConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,GAAG,cAAc,CA4E1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../../src/services/llm/anthropic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAIjE,wBAAsB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAwHjI"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Anthropic = require('@anthropic-ai/sdk');
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @elsikora-typescript/restrict-plus-operands,@elsikora-sonar/no-nested-conditional */
|
|
6
|
+
async function generateCommitWithAnthropic(apiKey, model, context) {
|
|
7
|
+
const anthropic = new Anthropic({
|
|
8
|
+
apiKey: apiKey,
|
|
9
|
+
});
|
|
10
|
+
// eslint-disable-next-line @elsikora-typescript/typedef
|
|
11
|
+
const typeOptions = context.typeEnum
|
|
12
|
+
?.map((type) => {
|
|
13
|
+
const description = context.typeDescriptions?.[type]?.description ?? "";
|
|
14
|
+
const emoji = context.typeDescriptions?.[type]?.emoji ?? "";
|
|
15
|
+
const title = context.typeDescriptions?.[type]?.title ?? "";
|
|
16
|
+
// eslint-disable-next-line @elsikora-sonar/no-nested-template-literals
|
|
17
|
+
return `${type}${emoji ? ` (${emoji})` : ""}: ${description}${title ? ` (${title})` : ""}`;
|
|
18
|
+
})
|
|
19
|
+
.join("\n") ?? "";
|
|
20
|
+
const systemPrompt = `You are a commit message generator. Your task is to create a conventional commit message based on the git changes provided.`;
|
|
21
|
+
const userPrompt = `I need you to generate a commit message for these changes:
|
|
22
|
+
${context.diff ? `Diff:\n${context.diff}\n` : ""}
|
|
23
|
+
${context.files ? `Files changed:\n${context.files}` : ""}
|
|
24
|
+
|
|
25
|
+
The commit should follow this format:
|
|
26
|
+
<type>[(scope)]: <subject>
|
|
27
|
+
[BLANK LINE]
|
|
28
|
+
[body]
|
|
29
|
+
[BLANK LINE]
|
|
30
|
+
[footer]
|
|
31
|
+
|
|
32
|
+
Type constraints:
|
|
33
|
+
${context.typeEnum ? "- Allowed types: " + context.typeEnum.join(", ") : ""}
|
|
34
|
+
${context.typeCase ? "- Case style: " + context.typeCase.join(", ") : ""}
|
|
35
|
+
${context.typeEmpty === undefined ? "" : "- Can be empty: " + (context.typeEmpty ? "yes" : "no")}
|
|
36
|
+
|
|
37
|
+
Available types:
|
|
38
|
+
${typeOptions}
|
|
39
|
+
|
|
40
|
+
Scope constraints:
|
|
41
|
+
${context.scopeCase ? "- Case style: " + context.scopeCase.join(", ") : ""}
|
|
42
|
+
${context.scopeEmpty === undefined ? "" : "- Can be empty: " + (context.scopeEmpty ? "yes" : "no")}
|
|
43
|
+
${context.scopeMaxLength ? "- Max length: " + context.scopeMaxLength + " characters" : ""}
|
|
44
|
+
|
|
45
|
+
Scope guidelines:
|
|
46
|
+
- The scope should represent the area of the codebase being modified
|
|
47
|
+
- If the changes affect multiple areas, use a comma-separated list or select the most significant area
|
|
48
|
+
- If unsure, use "global" as the scope
|
|
49
|
+
- If the scope is not relevant, it can be omitted
|
|
50
|
+
- Analyze the changed files and determine the most appropriate scope based on directories, modules or components
|
|
51
|
+
- Scopes are usually short (one or two words) and lowercase
|
|
52
|
+
|
|
53
|
+
Subject constraints:
|
|
54
|
+
${context.subject.case ? "- Case style: " + context.subject.case.join(", ") : ""}
|
|
55
|
+
${context.subject.empty === undefined ? "" : "- Can be empty: " + (context.subject.empty ? "yes" : "no")}
|
|
56
|
+
${context.subject.maxLength ? "- Max length: " + context.subject.maxLength + " characters" : ""}
|
|
57
|
+
${context.subject.minLength ? "- Min length: " + context.subject.minLength + " characters" : ""}
|
|
58
|
+
${context.subject.fullStop ? "- End with '" + context.subject.fullStop.value + "': " + (context.subject.fullStop.required ? "yes" : "no") : ""}
|
|
59
|
+
|
|
60
|
+
Header constraints:
|
|
61
|
+
${context.headerCase ? "- Case style: " + context.headerCase.join(", ") : ""}
|
|
62
|
+
${context.headerMaxLength ? "- Max length: " + context.headerMaxLength + " characters" : ""}
|
|
63
|
+
${context.headerMinLength ? "- Min length: " + context.headerMinLength + " characters" : ""}
|
|
64
|
+
${context.headerFullStop ? "- End with '" + context.headerFullStop.value + "': " + (context.headerFullStop.required ? "yes" : "no") : ""}
|
|
65
|
+
|
|
66
|
+
Body constraints:
|
|
67
|
+
${context.body?.maxLength ? "- Max length: " + context.body.maxLength + " characters" : ""}
|
|
68
|
+
${context.body?.maxLineLength ? "- Max line length: " + context.body.maxLineLength + " characters" : ""}
|
|
69
|
+
${context.body?.leadingBlank === undefined ? "" : "- Leading blank line: " + (context.body.leadingBlank ? "required" : "not required")}
|
|
70
|
+
${context.body?.fullStop ? "- End with '" + context.body.fullStop.value + "': " + (context.body.fullStop.required ? "yes" : "no") : ""}
|
|
71
|
+
|
|
72
|
+
Footer constraints:
|
|
73
|
+
${context.footerLeadingBlank === undefined ? "" : "- Leading blank line: " + (context.footerLeadingBlank ? "required" : "not required")}
|
|
74
|
+
${context.footerMaxLineLength ? "- Max line length: " + context.footerMaxLineLength + " characters" : ""}
|
|
75
|
+
|
|
76
|
+
Return a JSON object with these fields:
|
|
77
|
+
{
|
|
78
|
+
"type": "the commit type",
|
|
79
|
+
"scope": "the commit scope (optional)",
|
|
80
|
+
"subject": "the commit subject line",
|
|
81
|
+
"body": "the commit body (optional)",
|
|
82
|
+
"isBreaking": boolean,
|
|
83
|
+
"breakingBody": "description of breaking changes (if isBreaking is true)",
|
|
84
|
+
"issues": ["list of issue references"],
|
|
85
|
+
"references": ["list of other references"]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
The JSON object should be parseable and follow the structure outlined above.`;
|
|
89
|
+
try {
|
|
90
|
+
const response = await anthropic.messages.create({
|
|
91
|
+
// eslint-disable-next-line @elsikora-typescript/no-magic-numbers
|
|
92
|
+
max_tokens: 2048,
|
|
93
|
+
messages: [{ content: userPrompt, role: "user" }],
|
|
94
|
+
model: model,
|
|
95
|
+
system: systemPrompt,
|
|
96
|
+
});
|
|
97
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-member-access,@elsikora-typescript/no-unsafe-assignment
|
|
98
|
+
const content = response.content[0]?.text;
|
|
99
|
+
if (!content) {
|
|
100
|
+
throw new Error("Empty response from Anthropic");
|
|
101
|
+
}
|
|
102
|
+
// Extract JSON from response
|
|
103
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-assignment,@elsikora-typescript/no-unsafe-call,@elsikora-typescript/no-unsafe-member-access,@elsikora-sonar/slow-regex
|
|
104
|
+
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
|
105
|
+
if (!jsonMatch) {
|
|
106
|
+
throw new Error("No JSON found in Anthropic response");
|
|
107
|
+
}
|
|
108
|
+
// eslint-disable-next-line @elsikora-typescript/no-unsafe-argument,@elsikora-typescript/no-unsafe-member-access
|
|
109
|
+
return JSON.parse(jsonMatch[0]);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error("Error generating commit with Anthropic:", error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exports.generateCommitWithAnthropic = generateCommitWithAnthropic;
|
|
118
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sources":["../../../../../src/services/llm/anthropic.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;AAMO,eAAe,2BAA2B,CAAC,MAAc,EAAE,KAAa,EAAE,OAAyB,EAAA;AACzG,IAAA,MAAM,SAAS,GAAc,IAAI,SAAS,CAAC;AAC1C,QAAA,MAAM,EAAE,MAAM;AACd,KAAA,CAAC;;AAGF,IAAA,MAAM,WAAW,GAChB,OAAO,CAAC;AACP,UAAE,GAAG,CAAC,CAAC,IAAY,KAAI;AACtB,QAAA,MAAM,WAAW,GAAW,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE;AAC/E,QAAA,MAAM,KAAK,GAAW,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;AACnE,QAAA,MAAM,KAAK,GAAW,OAA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,CAAC,CAAC,CAAC,EAAE,IAAI;QAE9C,IAAI,CAAC,OAAO,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC;;;;QAKjD,MAAM,SAAS,GAAQ,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC;QAEnD,IAAI,CAAC,SAAS,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;;;QAIvD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAiB;;IAC9C,OAAO,KAAK,EAAE;AACf,QAAA,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC;AAE/D,QAAA,MAAM,KAAK;;AAEb;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LLMConfig } from "./types.js";
|
|
2
|
+
export declare const setLLMConfig: (config: LLMConfig | null) => void;
|
|
3
|
+
export declare const getLLMConfig: () => LLMConfig | null;
|
|
4
|
+
export declare const resetModeErrorFlag: () => void;
|
|
5
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/services/llm/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,YAAY,CAAC;AAsK9D,eAAO,MAAM,YAAY,WAAY,SAAS,GAAG,IAAI,KAAG,IAQvD,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,SAAS,GAAG,IA+B3C,CAAC;AAGF,eAAO,MAAM,kBAAkB,QAAO,IAErC,CAAC"}
|