git-push-mcp 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/.env.example ADDED
@@ -0,0 +1,25 @@
1
+ # Git Push MCP 配置文件示例
2
+
3
+ # 日志级别 (error, warn, info, verbose, debug, silly)
4
+ LOG_LEVEL=info
5
+
6
+ # 是否启用自动暂存
7
+ AUTO_STAGE=true
8
+
9
+ # 是否启用自动推送
10
+ AUTO_PUSH=false
11
+
12
+ # 是否使用约定式提交格式
13
+ CONVENTIONAL_COMMITS=true
14
+
15
+ # 提交消息最大长度
16
+ MAX_COMMIT_LENGTH=72
17
+
18
+ # 允许空提交
19
+ ALLOW_EMPTY_COMMITS=false
20
+
21
+ # Git用户名(可选,会使用全局配置)
22
+ GIT_USER_NAME=
23
+
24
+ # Git用户邮箱(可选,会使用全局配置)
25
+ GIT_USER_EMAIL=
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # Git Push MCP - 基于自然语言的代码提交工具
2
+
3
+ 一个智能化的Git操作工具,让你可以通过自然语言指令来自动化处理代码提交流程。
4
+
5
+ ## 功能特性
6
+
7
+ - 🗣️ **自然语言交互** - 使用中文或英文自然语言指令操作Git
8
+ - 🤖 **智能解析** - 自动识别用户意图并执行相应操作
9
+ - 📝 **约定式提交** - 支持Conventional Commits规范
10
+ - ⚡ **自动化流程** - 可配置自动暂存、自动推送等功能
11
+ - 🔧 **多种操作** - 支持提交、添加、状态查询、日志查看等操作
12
+ - 🛡️ **安全可靠** - 完善的错误处理和状态检查
13
+
14
+ ## 快速开始
15
+
16
+ ### 安装依赖
17
+
18
+ ```bash
19
+ npm install
20
+ ```
21
+
22
+ ### 复制配置文件
23
+
24
+ ```bash
25
+ cp .env.example .env
26
+ ```
27
+
28
+ ### 基本使用
29
+
30
+ ```bash
31
+ # 启动交互模式
32
+ npm start
33
+
34
+ # 或者直接运行
35
+ node index.js
36
+ ```
37
+
38
+ ## 使用示例
39
+
40
+ 在交互模式下,你可以使用以下自然语言指令:
41
+
42
+ ### 提交代码
43
+ ```
44
+ > 提交添加了登录功能
45
+ > commit fix bug in user authentication
46
+ > 把所有修改提交上去
47
+ ```
48
+
49
+ ### 查看状态
50
+ ```
51
+ > 查看当前状态
52
+ > status
53
+ > 有什么变化吗
54
+ ```
55
+
56
+ ### 添加文件
57
+ ```
58
+ > 添加所有文件
59
+ > add package.json
60
+ > 把src目录加到暂存区
61
+ ```
62
+
63
+ ### 查看历史
64
+ ```
65
+ > 查看提交历史
66
+ > log
67
+ > 最近的提交记录
68
+ ```
69
+
70
+ ### 分支操作
71
+ ```
72
+ > 创建新分支 feature/login
73
+ > 切换到develop分支
74
+ > 查看所有分支
75
+ ```
76
+
77
+ ## 配置选项
78
+
79
+ 在 `.env` 文件中可以配置以下选项:
80
+
81
+ ```env
82
+ # 日志级别
83
+ LOG_LEVEL=info
84
+
85
+ # 自动暂存更改
86
+ AUTO_STAGE=true
87
+
88
+ # 自动推送提交
89
+ AUTO_PUSH=false
90
+
91
+ # 使用约定式提交格式
92
+ CONVENTIONAL_COMMITS=true
93
+
94
+ # 提交消息长度限制
95
+ MAX_COMMIT_LENGTH=72
96
+ ```
97
+
98
+ ## 支持的命令模式
99
+
100
+ ### 提交相关
101
+ - 提交 [消息]
102
+ - commit [message]
103
+ - 把[内容]提交
104
+ - 推送 [消息]
105
+ - 发布 [消息]
106
+
107
+ ### 添加文件
108
+ - 添加 [文件]
109
+ - add [files]
110
+ - 把[文件]加到暂存区
111
+ - 暂存 [文件]
112
+
113
+ ### 状态查询
114
+ - 状态
115
+ - status
116
+ - 查看修改
117
+ - 有什么变化
118
+
119
+ ### 日志查看
120
+ - 日志
121
+ - log
122
+ - 提交历史
123
+ - 历史记录
124
+
125
+ ### 分支操作
126
+ - 分支
127
+ - branch
128
+ - 切换分支 [名称]
129
+ - 新建分支 [名称]
130
+
131
+ ## 约定式提交支持
132
+
133
+ 工具支持自动识别提交类型:
134
+
135
+ - **feat**: 新功能、feature、功能
136
+ - **fix**: 修复、bug、修复bug
137
+ - **docs**: 文档、document、说明
138
+ - **style**: 格式、样式
139
+ - **refactor**: 重构
140
+ - **perf**: 性能、优化
141
+ - **test**: 测试
142
+ - **chore**: 杂项、维护
143
+
144
+ ## API使用
145
+
146
+ 除了交互模式,你也可以在代码中直接使用:
147
+
148
+ ```javascript
149
+ const { GitPushMCP } = require('./index');
150
+
151
+ const app = new GitPushMCP();
152
+
153
+ // 处理自然语言请求
154
+ const result = await app.handleRequest({
155
+ command: 'process_natural_language',
156
+ text: '提交修复了登录bug',
157
+ context: {
158
+ autoStage: true,
159
+ autoPush: false,
160
+ conventionalCommits: true
161
+ }
162
+ });
163
+
164
+ console.log(result);
165
+ ```
166
+
167
+ ## 开发指南
168
+
169
+ ### 项目结构
170
+ ```
171
+ git-push-mcp/
172
+ ├── index.js # 主入口文件
173
+ ├── lib/
174
+ │ ├── nlp-processor.js # 自然语言处理器
175
+ │ ├── git-operator.js # Git操作执行器
176
+ │ └── mcp-handler.js # MCP处理器
177
+ ├── package.json # 项目配置
178
+ ├── .env.example # 配置示例
179
+ └── README.md # 说明文档
180
+ ```
181
+
182
+ ### 扩展功能
183
+
184
+ 1. **添加新的命令模式**:在 `nlp-processor.js` 的 `patterns` 对象中添加新的正则表达式
185
+ 2. **新增Git操作**:在 `git-operator.js` 中添加新的方法,并在 `mcp-handler.js` 中注册对应的处理器
186
+ 3. **自定义提交类型**:修改 `nlp-processor.js` 中的 `commitTypes` 映射
187
+
188
+ ## 注意事项
189
+
190
+ - 需要在Git仓库目录中运行
191
+ - 确保有足够的权限执行Git操作
192
+ - 建议先在测试环境中验证配置
193
+ - 自动推送功能需谨慎使用
194
+
195
+ ## 贡献
196
+
197
+ 欢迎提交Issue和Pull Request来改进这个工具!
198
+
199
+ ## 许可证
200
+
201
+ MIT License
package/index.js ADDED
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { GitOperator } = require('./lib/git-operator');
4
+ const { NaturalLanguageProcessor } = require('./lib/nlp-processor');
5
+ const { MCPHandler } = require('./lib/mcp-handler');
6
+ const winston = require('winston');
7
+ const dotenv = require('dotenv');
8
+
9
+ // 加载环境变量
10
+ dotenv.config();
11
+
12
+ // 配置日志
13
+ const logger = winston.createLogger({
14
+ level: process.env.LOG_LEVEL || 'info',
15
+ format: winston.format.combine(
16
+ winston.format.timestamp(),
17
+ winston.format.errors({ stack: true }),
18
+ winston.format.json()
19
+ ),
20
+ defaultMeta: { service: 'git-push-mcp' },
21
+ transports: [
22
+ new winston.transports.Console({
23
+ format: winston.format.simple()
24
+ })
25
+ ]
26
+ });
27
+
28
+ class GitPushMCP {
29
+ constructor() {
30
+ this.nlpProcessor = new NaturalLanguageProcessor();
31
+ this.gitOperator = new GitOperator(logger);
32
+ this.mcpHandler = new MCPHandler(this.nlpProcessor, this.gitOperator, logger);
33
+ }
34
+
35
+ async handleRequest(request) {
36
+ try {
37
+ logger.info('收到请求:', request);
38
+ const response = await this.mcpHandler.processRequest(request);
39
+ logger.info('响应结果:', response);
40
+ return response;
41
+ } catch (error) {
42
+ logger.error('处理请求时出错:', error);
43
+ return {
44
+ success: false,
45
+ error: error.message,
46
+ timestamp: new Date().toISOString()
47
+ };
48
+ }
49
+ }
50
+
51
+ // 直接运行模式(用于测试)
52
+ async runDirectMode() {
53
+ const readline = require('readline');
54
+ const rl = readline.createInterface({
55
+ input: process.stdin,
56
+ output: process.stdout
57
+ });
58
+
59
+ console.log('=== 灵码Git提交助手 ===');
60
+ console.log('输入自然语言指令来操作Git(输入"quit"退出)\n');
61
+
62
+ const askQuestion = () => {
63
+ rl.question('> ', async (input) => {
64
+ if (input.toLowerCase() === 'quit') {
65
+ console.log('再见!');
66
+ rl.close();
67
+ return;
68
+ }
69
+
70
+ try {
71
+ const result = await this.handleRequest({
72
+ command: 'process_natural_language',
73
+ text: input,
74
+ context: {
75
+ autoStage: true,
76
+ autoPush: false,
77
+ conventionalCommits: true
78
+ }
79
+ });
80
+
81
+ this.displayResult(result);
82
+ } catch (error) {
83
+ console.error('❌ 执行出错:', error.message);
84
+ }
85
+
86
+ askQuestion();
87
+ });
88
+ };
89
+
90
+ askQuestion();
91
+ }
92
+
93
+ displayResult(result) {
94
+ if (result.success) {
95
+ console.log('✅ 操作成功!');
96
+
97
+ if (result.action) {
98
+ console.log(`执行动作: ${result.action}`);
99
+ }
100
+
101
+ if (result.message) {
102
+ console.log(`消息: ${result.message}`);
103
+ }
104
+
105
+ if (result.details) {
106
+ console.log('详细信息:');
107
+ console.log(result.details);
108
+ }
109
+
110
+ if (result.changes) {
111
+ console.log('\n变更统计:');
112
+ Object.entries(result.changes).forEach(([key, value]) => {
113
+ console.log(` ${key}: ${value}`);
114
+ });
115
+ }
116
+ } else {
117
+ console.log('❌ 操作失败!');
118
+ console.log(`错误: ${result.error}`);
119
+
120
+ if (result.suggestion) {
121
+ console.log(`建议: ${result.suggestion}`);
122
+ }
123
+ }
124
+
125
+ console.log('---');
126
+ }
127
+ }
128
+
129
+ // 主程序入口
130
+ async function main() {
131
+ const app = new GitPushMCP();
132
+
133
+ // 检查是否作为MCP服务器运行
134
+ if (process.argv.includes('--mcp')) {
135
+ // 这里可以实现MCP协议的具体通信逻辑
136
+ console.log('启动MCP服务器模式...');
137
+ // TODO: 实现MCP协议通信
138
+ } else {
139
+ // 直接交互模式
140
+ await app.runDirectMode();
141
+ }
142
+ }
143
+
144
+ // 错误处理
145
+ process.on('unhandledRejection', (reason, promise) => {
146
+ logger.error('未处理的Promise拒绝:', reason);
147
+ process.exit(1);
148
+ });
149
+
150
+ process.on('uncaughtException', (error) => {
151
+ logger.error('未捕获的异常:', error);
152
+ process.exit(1);
153
+ });
154
+
155
+ // 启动应用
156
+ if (require.main === module) {
157
+ main().catch(error => {
158
+ logger.error('应用启动失败:', error);
159
+ process.exit(1);
160
+ });
161
+ }
162
+
163
+ module.exports = { GitPushMCP };