@git-ai/cli 1.0.2 → 1.0.3
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 +22 -0
- package/README.md +369 -369
- package/bin/index.cjs +13 -14
- package/bin/index.mjs +40 -41
- package/package.json +72 -46
- package/src/actions/BaseAction.mjs +42 -44
- package/src/actions/BaseUrlAction.mjs +24 -24
- package/src/actions/CommitAction.mjs +432 -484
- package/src/actions/MaxTokenAction.mjs +34 -38
- package/src/actions/ModelAction.mjs +122 -131
- package/src/actions/SelectModelAction.mjs +151 -161
- package/src/actions/TokenAction.mjs +25 -25
- package/src/const.mjs +43 -41
- package/src/index.mjs +95 -69
- package/src/services/AIService.mjs +106 -113
- package/src/services/GitService.mjs +366 -388
- package/src/utils/ConflictUtils.mjs +39 -39
- package/src/utils/Log.mjs +138 -146
- package/src/utils/Logger.mjs +34 -34
- package/src/utils/MessageUtils.mjs +189 -197
- package/src/utils/OpenAI.mjs +64 -68
- package/src/utils/Spinner.mjs +39 -39
- package/src/utils/Storage.mjs +7 -7
- package/src/utils/Utils.mjs +71 -72
package/bin/index.cjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const { pathToFileURL } = require('url')
|
|
4
|
-
|
|
5
|
-
const run = async () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
run().catch((error) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { pathToFileURL } = require('url');
|
|
4
|
+
|
|
5
|
+
const run = async () => {
|
|
6
|
+
const entryUrl = pathToFileURL(path.resolve(__dirname, '../src/index.mjs'));
|
|
7
|
+
const { default: lib } = await import(entryUrl.href);
|
|
8
|
+
await lib(process.argv.slice(2));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
run().catch((error) => {
|
|
12
|
+
console.error(error && error.message ? error.message : error);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
package/bin/index.mjs
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
const MIN_NODE_VERSION = '12.20.0'
|
|
3
|
-
|
|
4
|
-
const parseVersion = (version = '') =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const isVersionLessThan = (current, target) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const notifyNodeVersion = () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!notifyNodeVersion()) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
import('./index.cjs').catch((error) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const MIN_NODE_VERSION = '12.20.0';
|
|
3
|
+
|
|
4
|
+
const parseVersion = (version = '') =>
|
|
5
|
+
version
|
|
6
|
+
.replace(/^v/, '')
|
|
7
|
+
.split('.')
|
|
8
|
+
.map((part) => Number(part || 0));
|
|
9
|
+
|
|
10
|
+
const isVersionLessThan = (current, target) => {
|
|
11
|
+
const currentParts = parseVersion(current);
|
|
12
|
+
const targetParts = parseVersion(target);
|
|
13
|
+
for (let i = 0; i < Math.max(currentParts.length, targetParts.length); i += 1) {
|
|
14
|
+
const currentPart = currentParts[i] || 0;
|
|
15
|
+
const targetPart = targetParts[i] || 0;
|
|
16
|
+
if (currentPart < targetPart) return true;
|
|
17
|
+
if (currentPart > targetPart) return false;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const notifyNodeVersion = () => {
|
|
23
|
+
const currentVersion = process.version;
|
|
24
|
+
if (isVersionLessThan(process.versions.node, MIN_NODE_VERSION)) {
|
|
25
|
+
console.error(
|
|
26
|
+
`当前 Node.js 版本为 ${currentVersion},请升级至 ${MIN_NODE_VERSION} 或更高版本后再使用。`
|
|
27
|
+
);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (!notifyNodeVersion()) {
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
import('./index.cjs').catch((error) => {
|
|
38
|
+
console.error(error && error.message ? error.message : error);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,46 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@git-ai/cli",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "一个基于 AI 的 Git 提交消息生成器 CLI 工具,可自动分析代码变更并生成符合规范的提交信息",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"git-ai": "bin/index.cjs"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"git",
|
|
11
|
+
"ai",
|
|
12
|
+
"commit",
|
|
13
|
+
"cli"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=12.20.0"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/code-ba/git-ai",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/code-ba/git-ai/issues",
|
|
21
|
+
"email": "info@cxvh.com"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/code-ba/git-ai.git"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"bin/",
|
|
29
|
+
"src/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org/",
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "Baran",
|
|
39
|
+
"email": "info@cxvh.com",
|
|
40
|
+
"url": "https://github.com/code-ba"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"lint": "eslint . --ext .js,.mjs,.cjs",
|
|
45
|
+
"lint:fix": "eslint . --ext .js,.mjs,.cjs --fix",
|
|
46
|
+
"format": "prettier --check .",
|
|
47
|
+
"format:write": "prettier --write .",
|
|
48
|
+
"prepare": "husky install",
|
|
49
|
+
"prepublishOnly": "npm run lint && npm run format"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"axios": "1.13.1",
|
|
53
|
+
"chalk": "4.1.2",
|
|
54
|
+
"cli-spinner": "0.2.10",
|
|
55
|
+
"commander": "9.5.0",
|
|
56
|
+
"configstore": "6.0.0",
|
|
57
|
+
"inquirer": "7.3.3",
|
|
58
|
+
"npmlog": "6.0.2"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"eslint": "8.57.0",
|
|
62
|
+
"husky": "^9.1.7",
|
|
63
|
+
"lint-staged": "^16.2.7",
|
|
64
|
+
"prettier": "2.8.8"
|
|
65
|
+
},
|
|
66
|
+
"lint-staged": {
|
|
67
|
+
"*.{js,mjs,cjs}": [
|
|
68
|
+
"eslint --fix",
|
|
69
|
+
"prettier --write"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import { exitProcess } from
|
|
2
|
-
import Logger from
|
|
3
|
-
/**
|
|
4
|
-
* Action 基类
|
|
5
|
-
* 所有 action 都应该继承此类并实现 execute 方法
|
|
6
|
-
*/
|
|
7
|
-
class BaseAction {
|
|
8
|
-
constructor(args) {
|
|
9
|
-
this.args = args;
|
|
10
|
-
this.startTimestamp = Date.now();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 子类需要实现此方法来执行具体的业务逻辑
|
|
15
|
-
*/
|
|
16
|
-
async execute() {
|
|
17
|
-
throw new Error(
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 运行 action,处理错误和退出逻辑
|
|
22
|
-
*/
|
|
23
|
-
async run() {
|
|
24
|
-
const handleCtrlC = () => {
|
|
25
|
-
console.log(
|
|
26
|
-
Logger.warn(
|
|
27
|
-
exitProcess(1, this.startTimestamp);
|
|
28
|
-
};
|
|
29
|
-
process.once(
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
await this.execute();
|
|
33
|
-
process.off(
|
|
34
|
-
exitProcess(0, this.startTimestamp);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
process.off(
|
|
37
|
-
Logger.error(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
export default BaseAction;
|
|
1
|
+
import { exitProcess } from '../utils/Utils.mjs';
|
|
2
|
+
import Logger from '../utils/Logger.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Action 基类
|
|
5
|
+
* 所有 action 都应该继承此类并实现 execute 方法
|
|
6
|
+
*/
|
|
7
|
+
class BaseAction {
|
|
8
|
+
constructor(args) {
|
|
9
|
+
this.args = args;
|
|
10
|
+
this.startTimestamp = Date.now();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 子类需要实现此方法来执行具体的业务逻辑
|
|
15
|
+
*/
|
|
16
|
+
async execute() {
|
|
17
|
+
throw new Error('execute() method must be implemented by subclass');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 运行 action,处理错误和退出逻辑
|
|
22
|
+
*/
|
|
23
|
+
async run() {
|
|
24
|
+
const handleCtrlC = () => {
|
|
25
|
+
console.log('\n');
|
|
26
|
+
Logger.warn('检测到 Ctrl+C,正在安全退出...');
|
|
27
|
+
exitProcess(1, this.startTimestamp);
|
|
28
|
+
};
|
|
29
|
+
process.once('SIGINT', handleCtrlC);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await this.execute();
|
|
33
|
+
process.off('SIGINT', handleCtrlC);
|
|
34
|
+
exitProcess(0, this.startTimestamp);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
process.off('SIGINT', handleCtrlC);
|
|
37
|
+
Logger.error(error && typeof error.message === 'string' ? error.message : error);
|
|
38
|
+
exitProcess(1, this.startTimestamp);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default BaseAction;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { config } from
|
|
2
|
-
import Logger from
|
|
3
|
-
import BaseAction from
|
|
4
|
-
|
|
5
|
-
class SetBaseUrlAction extends BaseAction {
|
|
6
|
-
constructor(baseURL =
|
|
7
|
-
super(baseURL);
|
|
8
|
-
this.baseURL = baseURL.trim();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async execute() {
|
|
12
|
-
config.set(
|
|
13
|
-
if (this.baseURL) {
|
|
14
|
-
Logger.success(`Base URL 已设置为: ${this.baseURL}`);
|
|
15
|
-
} else {
|
|
16
|
-
Logger.warn(`Base URL 已清空。`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default async function (args) {
|
|
22
|
-
const action = new SetBaseUrlAction(args);
|
|
23
|
-
await action.run();
|
|
24
|
-
}
|
|
1
|
+
import { config } from '../utils/Storage.mjs';
|
|
2
|
+
import Logger from '../utils/Logger.mjs';
|
|
3
|
+
import BaseAction from './BaseAction.mjs';
|
|
4
|
+
|
|
5
|
+
class SetBaseUrlAction extends BaseAction {
|
|
6
|
+
constructor(baseURL = '') {
|
|
7
|
+
super(baseURL);
|
|
8
|
+
this.baseURL = baseURL.trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async execute() {
|
|
12
|
+
config.set('baseURL', this.baseURL);
|
|
13
|
+
if (this.baseURL) {
|
|
14
|
+
Logger.success(`Base URL 已设置为: ${this.baseURL}`);
|
|
15
|
+
} else {
|
|
16
|
+
Logger.warn(`Base URL 已清空。`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default async function (args) {
|
|
22
|
+
const action = new SetBaseUrlAction(args);
|
|
23
|
+
await action.run();
|
|
24
|
+
}
|