Skip to content

Commit 45dd07d

Browse files
committed
Merge branch 'master' into dev
2 parents 89d2aa6 + fa16437 commit 45dd07d

File tree

7 files changed

+69
-40
lines changed

7 files changed

+69
-40
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ oco config set OCO_EMOJI=false
162162

163163
Other config options are behaving the same.
164164

165+
### Output WHY the changes were done (WIP)
166+
167+
You can set the `OCO_WHY` config to `true` to have OpenCommit output a short description of WHY the changes were done after the commit message. Default is `false`.
168+
169+
To make this perform accurate we must store 'what files do' in some kind of an index or embedding and perform a lookup (kinda RAG) for the accurate git commit message. If you feel like building this comment on this ticket https://github.com/di-sukharev/opencommit/issues/398 and let's go from there together.
170+
171+
```sh
172+
oco config set OCO_WHY=true
173+
```
174+
165175
### Switch to GPT-4 or other models
166176

167177
By default, OpenCommit uses `gpt-4o-mini` model.

out/cli.cjs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25193,7 +25193,7 @@ function G3(t2, e3) {
2519325193
// package.json
2519425194
var package_default = {
2519525195
name: "opencommit",
25196-
version: "3.1.0",
25196+
version: "3.1.1",
2519725197
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
2519825198
keywords: [
2519925199
"git",
@@ -27752,6 +27752,7 @@ var CONFIG_KEYS = /* @__PURE__ */ ((CONFIG_KEYS2) => {
2775227752
CONFIG_KEYS2["OCO_EMOJI"] = "OCO_EMOJI";
2775327753
CONFIG_KEYS2["OCO_MODEL"] = "OCO_MODEL";
2775427754
CONFIG_KEYS2["OCO_LANGUAGE"] = "OCO_LANGUAGE";
27755+
CONFIG_KEYS2["OCO_WHY"] = "OCO_WHY";
2775527756
CONFIG_KEYS2["OCO_MESSAGE_TEMPLATE_PLACEHOLDER"] = "OCO_MESSAGE_TEMPLATE_PLACEHOLDER";
2775627757
CONFIG_KEYS2["OCO_PROMPT_MODULE"] = "OCO_PROMPT_MODULE";
2775727758
CONFIG_KEYS2["OCO_AI_PROVIDER"] = "OCO_AI_PROVIDER";
@@ -28042,6 +28043,7 @@ var DEFAULT_CONFIG = {
2804228043
OCO_ONE_LINE_COMMIT: false,
2804328044
OCO_TEST_MOCK_TYPE: "commit-message",
2804428045
OCO_FLOWISE_ENDPOINT: ":",
28046+
OCO_WHY: false,
2804528047
OCO_GITPUSH: true
2804628048
};
2804728049
var initGlobalConfig = (configPath = defaultConfigPath) => {
@@ -42568,7 +42570,7 @@ Example Git Diff is to follow:`
4256842570
];
4256942571
var INIT_MAIN_PROMPT = (language, prompts) => ({
4257042572
role: "system",
42571-
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
42573+
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${config2.OCO_WHY ? "and WHY the changes were done" : ""}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
4257242574
${config2.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
4257342575
${config2.OCO_DESCRIPTION ? `Add a short description of WHY the changes are done after the commit message. Don't start it with "This commit", just describe the changes.` : "Don't add any descriptions to the commit, only commit message."}
4257442576
Use the present tense. Use ${language} to answer.
@@ -42588,34 +42590,39 @@ var commitlintPrompts = {
4258842590
// src/modules/commitlint/pwd-commitlint.ts
4258942591
var import_promises = __toESM(require("fs/promises"), 1);
4259042592
var import_path3 = __toESM(require("path"), 1);
42593+
var findModulePath = (moduleName) => {
42594+
const searchPaths = [
42595+
import_path3.default.join("node_modules", moduleName),
42596+
import_path3.default.join("node_modules", ".pnpm")
42597+
];
42598+
for (const basePath of searchPaths) {
42599+
try {
42600+
const resolvedPath = require.resolve(moduleName, { paths: [basePath] });
42601+
return resolvedPath;
42602+
} catch {
42603+
}
42604+
}
42605+
throw new Error(`Cannot find module ${moduleName}`);
42606+
};
4259142607
var getCommitLintModuleType = async () => {
42592-
const packageFile = "node_modules/@commitlint/load/package.json";
42593-
const packageJsonPath = import_path3.default.join(
42594-
process.env.PWD || process.cwd(),
42595-
packageFile
42596-
);
42608+
const packageFile = "@commitlint/load/package.json";
42609+
const packageJsonPath = findModulePath(packageFile);
4259742610
const packageJson = JSON.parse(await import_promises.default.readFile(packageJsonPath, "utf8"));
4259842611
if (!packageJson) {
4259942612
throw new Error(`Failed to parse ${packageFile}`);
4260042613
}
4260142614
return packageJson.type === "module" ? "esm" : "cjs";
4260242615
};
4260342616
var getCommitLintPWDConfig = async () => {
42604-
let load, nodeModulesPath;
42617+
let load, modulePath;
4260542618
switch (await getCommitLintModuleType()) {
4260642619
case "cjs":
42607-
nodeModulesPath = import_path3.default.join(
42608-
process.env.PWD || process.cwd(),
42609-
"node_modules/@commitlint/load"
42610-
);
42611-
load = require(nodeModulesPath).default;
42620+
modulePath = findModulePath("@commitlint/load");
42621+
load = require(modulePath).default;
4261242622
break;
4261342623
case "esm":
42614-
nodeModulesPath = import_path3.default.join(
42615-
process.env.PWD || process.cwd(),
42616-
"node_modules/@commitlint/load/lib/load.js"
42617-
);
42618-
load = (await import(nodeModulesPath)).default;
42624+
modulePath = await findModulePath("@commitlint/load/lib/load.js");
42625+
load = (await import(modulePath)).default;
4261942626
break;
4262042627
}
4262142628
if (load && typeof load === "function") {
@@ -43350,7 +43357,7 @@ var commitlintConfigCommand = G3(
4335043357
const { mode } = argv._;
4335143358
if (mode === "get" /* get */) {
4335243359
const commitLintConfig = await getCommitlintLLMConfig();
43353-
ce(commitLintConfig.toString());
43360+
ce(JSON.stringify(commitLintConfig, null, 2));
4335443361
return;
4335543362
}
4335643363
if (mode === "force" /* force */) {

out/github-action.cjs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46564,6 +46564,7 @@ var CONFIG_KEYS = /* @__PURE__ */ ((CONFIG_KEYS2) => {
4656446564
CONFIG_KEYS2["OCO_EMOJI"] = "OCO_EMOJI";
4656546565
CONFIG_KEYS2["OCO_MODEL"] = "OCO_MODEL";
4656646566
CONFIG_KEYS2["OCO_LANGUAGE"] = "OCO_LANGUAGE";
46567+
CONFIG_KEYS2["OCO_WHY"] = "OCO_WHY";
4656746568
CONFIG_KEYS2["OCO_MESSAGE_TEMPLATE_PLACEHOLDER"] = "OCO_MESSAGE_TEMPLATE_PLACEHOLDER";
4656846569
CONFIG_KEYS2["OCO_PROMPT_MODULE"] = "OCO_PROMPT_MODULE";
4656946570
CONFIG_KEYS2["OCO_AI_PROVIDER"] = "OCO_AI_PROVIDER";
@@ -46854,6 +46855,7 @@ var DEFAULT_CONFIG = {
4685446855
OCO_ONE_LINE_COMMIT: false,
4685546856
OCO_TEST_MOCK_TYPE: "commit-message",
4685646857
OCO_FLOWISE_ENDPOINT: ":",
46858+
OCO_WHY: false,
4685746859
OCO_GITPUSH: true
4685846860
};
4685946861
var initGlobalConfig = (configPath = defaultConfigPath) => {
@@ -61380,7 +61382,7 @@ Example Git Diff is to follow:`
6138061382
];
6138161383
var INIT_MAIN_PROMPT = (language, prompts) => ({
6138261384
role: "system",
61383-
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
61385+
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${config2.OCO_WHY ? "and WHY the changes were done" : ""}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
6138461386
${config2.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
6138561387
${config2.OCO_DESCRIPTION ? `Add a short description of WHY the changes are done after the commit message. Don't start it with "This commit", just describe the changes.` : "Don't add any descriptions to the commit, only commit message."}
6138661388
Use the present tense. Use ${language} to answer.
@@ -61400,34 +61402,39 @@ var commitlintPrompts = {
6140061402
// src/modules/commitlint/pwd-commitlint.ts
6140161403
var import_promises = __toESM(require("fs/promises"), 1);
6140261404
var import_path3 = __toESM(require("path"), 1);
61405+
var findModulePath = (moduleName) => {
61406+
const searchPaths = [
61407+
import_path3.default.join("node_modules", moduleName),
61408+
import_path3.default.join("node_modules", ".pnpm")
61409+
];
61410+
for (const basePath of searchPaths) {
61411+
try {
61412+
const resolvedPath = require.resolve(moduleName, { paths: [basePath] });
61413+
return resolvedPath;
61414+
} catch {
61415+
}
61416+
}
61417+
throw new Error(`Cannot find module ${moduleName}`);
61418+
};
6140361419
var getCommitLintModuleType = async () => {
61404-
const packageFile = "node_modules/@commitlint/load/package.json";
61405-
const packageJsonPath = import_path3.default.join(
61406-
process.env.PWD || process.cwd(),
61407-
packageFile
61408-
);
61420+
const packageFile = "@commitlint/load/package.json";
61421+
const packageJsonPath = findModulePath(packageFile);
6140961422
const packageJson = JSON.parse(await import_promises.default.readFile(packageJsonPath, "utf8"));
6141061423
if (!packageJson) {
6141161424
throw new Error(`Failed to parse ${packageFile}`);
6141261425
}
6141361426
return packageJson.type === "module" ? "esm" : "cjs";
6141461427
};
6141561428
var getCommitLintPWDConfig = async () => {
61416-
let load, nodeModulesPath;
61429+
let load, modulePath;
6141761430
switch (await getCommitLintModuleType()) {
6141861431
case "cjs":
61419-
nodeModulesPath = import_path3.default.join(
61420-
process.env.PWD || process.cwd(),
61421-
"node_modules/@commitlint/load"
61422-
);
61423-
load = require(nodeModulesPath).default;
61432+
modulePath = findModulePath("@commitlint/load");
61433+
load = require(modulePath).default;
6142461434
break;
6142561435
case "esm":
61426-
nodeModulesPath = import_path3.default.join(
61427-
process.env.PWD || process.cwd(),
61428-
"node_modules/@commitlint/load/lib/load.js"
61429-
);
61430-
load = (await import(nodeModulesPath)).default;
61436+
modulePath = await findModulePath("@commitlint/load/lib/load.js");
61437+
load = (await import(modulePath)).default;
6143161438
break;
6143261439
}
6143361440
if (load && typeof load === "function") {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencommit",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
55
"keywords": [
66
"git",

src/commands/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export enum CONFIG_KEYS {
2323
OCO_EMOJI = 'OCO_EMOJI',
2424
OCO_MODEL = 'OCO_MODEL',
2525
OCO_LANGUAGE = 'OCO_LANGUAGE',
26+
OCO_WHY = 'OCO_WHY',
2627
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
2728
OCO_PROMPT_MODULE = 'OCO_PROMPT_MODULE',
2829
OCO_AI_PROVIDER = 'OCO_AI_PROVIDER',
@@ -376,6 +377,7 @@ export type ConfigType = {
376377
[CONFIG_KEYS.OCO_OPENAI_BASE_PATH]?: string;
377378
[CONFIG_KEYS.OCO_DESCRIPTION]: boolean;
378379
[CONFIG_KEYS.OCO_EMOJI]: boolean;
380+
[CONFIG_KEYS.OCO_WHY]: boolean;
379381
[CONFIG_KEYS.OCO_MODEL]: string;
380382
[CONFIG_KEYS.OCO_LANGUAGE]: string;
381383
[CONFIG_KEYS.OCO_MESSAGE_TEMPLATE_PLACEHOLDER]: string;
@@ -435,6 +437,7 @@ export const DEFAULT_CONFIG = {
435437
OCO_ONE_LINE_COMMIT: false,
436438
OCO_TEST_MOCK_TYPE: 'commit-message',
437439
OCO_FLOWISE_ENDPOINT: ':',
440+
OCO_WHY: false,
438441
OCO_GITPUSH: true // todo: deprecate
439442
};
440443

src/modules/commitlint/prompts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ const INIT_MAIN_PROMPT = (
258258
prompts: string[]
259259
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
260260
role: 'system',
261-
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
261+
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${
262+
config.OCO_WHY ? 'and WHY the changes were done' : ''
263+
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
262264
${
263265
config.OCO_EMOJI
264266
? 'Use GitMoji convention to preface the commit.'

0 commit comments

Comments
 (0)