git-ai-shen 1.0.0
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/README.en.md +36 -0
- package/README.md +23 -0
- package/bin/git-ai.js +97 -0
- package/git-ai-working.js +393 -0
- package/lib/commands/commit.js +256 -0
- package/lib/core/ai-reviewer.js +321 -0
- package/lib/core/config.js +120 -0
- package/lib/core/git-operations.js +285 -0
- package/lib/core/simple-config.js +171 -0
- package/lib/index.js +19 -0
- package/lib/utils/file-utils.js +98 -0
- package/lib/utils/logger.js +71 -0
- package/node +0 -0
- package/package.json +25 -0
- package/simple-init.js +76 -0
- package/test-ai.js +42 -0
- package/test-init.js +28 -0
package/simple-init.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
// 极简配置管理
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const readline = require('readline');
|
|
7
|
+
|
|
8
|
+
const CONFIG_DIR = path.join(os.homedir(), '.git-ai-test');
|
|
9
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
10
|
+
|
|
11
|
+
// 确保配置目录存在
|
|
12
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
13
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 颜色函数(简单实现)
|
|
17
|
+
const colors = {
|
|
18
|
+
cyan: (text) => `\x1b[36m${text}\x1b[0m`,
|
|
19
|
+
green: (text) => `\x1b[32m${text}\x1b[0m`,
|
|
20
|
+
yellow: (text) => `\x1b[33m${text}\x1b[0m`,
|
|
21
|
+
gray: (text) => `\x1b[90m${text}\x1b[0m`,
|
|
22
|
+
red: (text) => `\x1b[31m${text}\x1b[0m`
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function initConfig() {
|
|
26
|
+
console.log(colors.cyan('\n' + '='.repeat(50)));
|
|
27
|
+
console.log(colors.cyan('🔧 Git AI 配置初始化'));
|
|
28
|
+
console.log(colors.cyan('='.repeat(50)) + '\n');
|
|
29
|
+
|
|
30
|
+
const rl = readline.createInterface({
|
|
31
|
+
input: process.stdin,
|
|
32
|
+
output: process.stdout
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(colors.yellow('(可选) 配置 OpenAI API 密钥'));
|
|
36
|
+
console.log(colors.gray('如果不配置,将使用基础功能\n'));
|
|
37
|
+
|
|
38
|
+
// 使用递归方式处理异步
|
|
39
|
+
function askApiKey() {
|
|
40
|
+
rl.question(colors.cyan('OpenAI API密钥 (直接回车跳过): '), (apiKey) => {
|
|
41
|
+
const config = {
|
|
42
|
+
ai: {
|
|
43
|
+
apiKey: apiKey.trim() || '',
|
|
44
|
+
apiUrl: 'https://api.openai.com/v1'
|
|
45
|
+
},
|
|
46
|
+
git: {
|
|
47
|
+
autoAdd: true,
|
|
48
|
+
autoPush: true
|
|
49
|
+
},
|
|
50
|
+
review: {
|
|
51
|
+
enabled: true
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
57
|
+
console.log(colors.green('\n✅ 配置保存成功!'));
|
|
58
|
+
console.log(colors.gray(`配置文件: ${CONFIG_FILE}`));
|
|
59
|
+
console.log(colors.cyan('\n配置内容:'));
|
|
60
|
+
console.log(JSON.stringify(config, null, 2));
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.log(colors.red(`\n❌ 配置保存失败: ${error.message}`));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
rl.close();
|
|
66
|
+
console.log(colors.green('\n✅ 初始化完成!'));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
askApiKey();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 执行初始化
|
|
74
|
+
console.log('程序启动...');
|
|
75
|
+
initConfig();
|
|
76
|
+
console.log('初始化函数调用完成,等待输入...');
|
package/test-ai.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// test-ai.js
|
|
2
|
+
const { OpenAI } = require('openai');
|
|
3
|
+
|
|
4
|
+
const openai = new OpenAI({
|
|
5
|
+
apiKey: 'ms-114c4bf4-ab3e-442b-a30c-6b355db26263',
|
|
6
|
+
baseURL: 'https://api-inference.modelscope.cn/v1'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function test() {
|
|
10
|
+
try {
|
|
11
|
+
console.log('测试国产API连接...');
|
|
12
|
+
console.log('API地址:', 'https://api-inference.modelscope.cn/v1');
|
|
13
|
+
console.log('模型:', 'gpt-4o-mini');
|
|
14
|
+
|
|
15
|
+
const response = await openai.chat.completions.create({
|
|
16
|
+
model: 'Qwen/Qwen3-Coder-30B-A3B-Instruct', // 使用你配置的模型
|
|
17
|
+
messages: [
|
|
18
|
+
{
|
|
19
|
+
role: 'system',
|
|
20
|
+
content: '你是一个Git提交信息生成助手。'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
role: 'user',
|
|
24
|
+
content: '根据以下文件生成提交信息:\n- src/index.js\n- package.json\n内容:修改了登录功能'
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
max_tokens: 50
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log('✅ API连接成功!');
|
|
31
|
+
console.log('响应内容:', response.choices[0].message.content);
|
|
32
|
+
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('❌ API连接失败:');
|
|
35
|
+
console.error('错误信息:', error.message);
|
|
36
|
+
if (error.response) {
|
|
37
|
+
console.error('错误详情:', error.response.data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
test();
|
package/test-init.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// test-init.js - 最简测试版本
|
|
2
|
+
const readline = require('readline');
|
|
3
|
+
|
|
4
|
+
console.log('='.repeat(50));
|
|
5
|
+
console.log('🔧 Git AI 测试初始化,你好你在干嘛呢');
|
|
6
|
+
console.log('='.repeat(50));
|
|
7
|
+
console.log('');
|
|
8
|
+
|
|
9
|
+
console.log('1. 正在创建 readline 接口...');
|
|
10
|
+
const rl = readline.createInterface({
|
|
11
|
+
input: process.stdin,
|
|
12
|
+
output: process.stdout
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
console.log('2. readline 接口创建成功');
|
|
16
|
+
console.log('3. 准备提问...');
|
|
17
|
+
|
|
18
|
+
rl.question('请输入任意文字测试输入: ', (answer) => {
|
|
19
|
+
console.log('4. 收到输入: ' + answer);
|
|
20
|
+
|
|
21
|
+
console.log('5. 准备关闭 readline...');
|
|
22
|
+
rl.close();
|
|
23
|
+
console.log('6. readline 已关闭');
|
|
24
|
+
|
|
25
|
+
console.log('\n✅ 测试完成!');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log('7. 等待输入中...');
|