@andrebuzeli/git-mcp 5.0.4 → 5.0.6

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.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -89
  3. package/dist/config.d.ts +72 -71
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +226 -139
  6. package/dist/config.js.map +1 -1
  7. package/dist/index.d.ts +15 -17
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +133 -128
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/base-provider.d.ts +42 -153
  12. package/dist/providers/base-provider.d.ts.map +1 -1
  13. package/dist/providers/base-provider.js +42 -302
  14. package/dist/providers/base-provider.js.map +1 -1
  15. package/dist/providers/gitea-provider.d.ts +67 -118
  16. package/dist/providers/gitea-provider.d.ts.map +1 -1
  17. package/dist/providers/gitea-provider.js +487 -1161
  18. package/dist/providers/gitea-provider.js.map +1 -1
  19. package/dist/providers/github-provider.d.ts +70 -81
  20. package/dist/providers/github-provider.d.ts.map +1 -1
  21. package/dist/providers/github-provider.js +641 -278
  22. package/dist/providers/github-provider.js.map +1 -1
  23. package/dist/providers/index.d.ts +9 -9
  24. package/dist/providers/index.d.ts.map +1 -1
  25. package/dist/providers/index.js +13 -19
  26. package/dist/providers/index.js.map +1 -1
  27. package/dist/providers/provider-factory.d.ts +29 -59
  28. package/dist/providers/provider-factory.d.ts.map +1 -1
  29. package/dist/providers/provider-factory.js +134 -265
  30. package/dist/providers/provider-factory.js.map +1 -1
  31. package/dist/providers/provider-operation-handler.d.ts +93 -0
  32. package/dist/providers/provider-operation-handler.d.ts.map +1 -0
  33. package/dist/providers/provider-operation-handler.js +280 -0
  34. package/dist/providers/provider-operation-handler.js.map +1 -0
  35. package/dist/providers/types.d.ts +201 -355
  36. package/dist/providers/types.d.ts.map +1 -1
  37. package/dist/providers/types.js +3 -2
  38. package/dist/providers/types.js.map +1 -1
  39. package/dist/server.d.ts +34 -4
  40. package/dist/server.d.ts.map +1 -1
  41. package/dist/server.js +439 -262
  42. package/dist/server.js.map +1 -1
  43. package/dist/tools/git-analytics.d.ts +239 -16
  44. package/dist/tools/git-analytics.d.ts.map +1 -1
  45. package/dist/tools/git-analytics.js +737 -25
  46. package/dist/tools/git-analytics.js.map +1 -1
  47. package/dist/tools/git-archive.d.ts +109 -15
  48. package/dist/tools/git-archive.d.ts.map +1 -1
  49. package/dist/tools/git-archive.js +462 -10
  50. package/dist/tools/git-archive.js.map +1 -1
  51. package/dist/tools/git-backup.d.ts +101 -15
  52. package/dist/tools/git-backup.d.ts.map +1 -1
  53. package/dist/tools/git-backup.js +410 -10
  54. package/dist/tools/git-backup.js.map +1 -1
  55. package/dist/tools/git-branches.d.ts +141 -15
  56. package/dist/tools/git-branches.d.ts.map +1 -1
  57. package/dist/tools/git-branches.js +466 -11
  58. package/dist/tools/git-branches.js.map +1 -1
  59. package/dist/tools/git-config.d.ts +115 -15
  60. package/dist/tools/git-config.d.ts.map +1 -1
  61. package/dist/tools/git-config.js +446 -11
  62. package/dist/tools/git-config.js.map +1 -1
  63. package/dist/tools/git-files.d.ts +179 -59
  64. package/dist/tools/git-files.d.ts.map +1 -1
  65. package/dist/tools/git-files.js +682 -222
  66. package/dist/tools/git-files.js.map +1 -1
  67. package/dist/tools/git-issues.d.ts +158 -15
  68. package/dist/tools/git-issues.d.ts.map +1 -1
  69. package/dist/tools/git-issues.js +323 -11
  70. package/dist/tools/git-issues.js.map +1 -1
  71. package/dist/tools/git-monitor.d.ts +149 -14
  72. package/dist/tools/git-monitor.d.ts.map +1 -1
  73. package/dist/tools/git-monitor.js +528 -11
  74. package/dist/tools/git-monitor.js.map +1 -1
  75. package/dist/tools/git-packages.d.ts +163 -15
  76. package/dist/tools/git-packages.d.ts.map +1 -1
  77. package/dist/tools/git-packages.js +526 -11
  78. package/dist/tools/git-packages.js.map +1 -1
  79. package/dist/tools/git-pulls.d.ts +174 -15
  80. package/dist/tools/git-pulls.d.ts.map +1 -1
  81. package/dist/tools/git-pulls.js +352 -11
  82. package/dist/tools/git-pulls.js.map +1 -1
  83. package/dist/tools/git-release.d.ts +167 -15
  84. package/dist/tools/git-release.d.ts.map +1 -1
  85. package/dist/tools/git-release.js +465 -11
  86. package/dist/tools/git-release.js.map +1 -1
  87. package/dist/tools/git-remote.d.ts +124 -15
  88. package/dist/tools/git-remote.d.ts.map +1 -1
  89. package/dist/tools/git-remote.js +539 -11
  90. package/dist/tools/git-remote.js.map +1 -1
  91. package/dist/tools/git-reset.d.ts +100 -15
  92. package/dist/tools/git-reset.d.ts.map +1 -1
  93. package/dist/tools/git-reset.js +409 -11
  94. package/dist/tools/git-reset.js.map +1 -1
  95. package/dist/tools/git-stash.d.ts +120 -15
  96. package/dist/tools/git-stash.d.ts.map +1 -1
  97. package/dist/tools/git-stash.js +503 -11
  98. package/dist/tools/git-stash.js.map +1 -1
  99. package/dist/tools/git-sync.d.ts +160 -16
  100. package/dist/tools/git-sync.d.ts.map +1 -1
  101. package/dist/tools/git-sync.js +462 -113
  102. package/dist/tools/git-sync.js.map +1 -1
  103. package/dist/tools/git-tags.d.ts +142 -15
  104. package/dist/tools/git-tags.d.ts.map +1 -1
  105. package/dist/tools/git-tags.js +471 -11
  106. package/dist/tools/git-tags.js.map +1 -1
  107. package/dist/tools/git-workflow.d.ts +151 -80
  108. package/dist/tools/git-workflow.d.ts.map +1 -1
  109. package/dist/tools/git-workflow.js +407 -912
  110. package/dist/tools/git-workflow.js.map +1 -1
  111. package/dist/utils/credential-manager.d.ts +119 -0
  112. package/dist/utils/credential-manager.d.ts.map +1 -0
  113. package/dist/utils/credential-manager.js +450 -0
  114. package/dist/utils/credential-manager.js.map +1 -0
  115. package/dist/utils/git-command-executor.d.ts +326 -0
  116. package/dist/utils/git-command-executor.d.ts.map +1 -0
  117. package/dist/utils/git-command-executor.js +877 -0
  118. package/dist/utils/git-command-executor.js.map +1 -0
  119. package/dist/utils/logger.d.ts +143 -0
  120. package/dist/utils/logger.d.ts.map +1 -0
  121. package/dist/utils/logger.js +473 -0
  122. package/dist/utils/logger.js.map +1 -0
  123. package/dist/utils/operation-error-handler.d.ts +54 -41
  124. package/dist/utils/operation-error-handler.d.ts.map +1 -1
  125. package/dist/utils/operation-error-handler.js +211 -227
  126. package/dist/utils/operation-error-handler.js.map +1 -1
  127. package/dist/utils/parameter-validator.d.ts +41 -0
  128. package/dist/utils/parameter-validator.d.ts.map +1 -0
  129. package/dist/utils/parameter-validator.js +464 -0
  130. package/dist/utils/parameter-validator.js.map +1 -0
  131. package/dist/utils/repository-detector.d.ts +128 -0
  132. package/dist/utils/repository-detector.d.ts.map +1 -0
  133. package/dist/utils/repository-detector.js +422 -0
  134. package/dist/utils/repository-detector.js.map +1 -0
  135. package/dist/utils/response-formatter.d.ts +146 -0
  136. package/dist/utils/response-formatter.d.ts.map +1 -0
  137. package/dist/utils/response-formatter.js +378 -0
  138. package/dist/utils/response-formatter.js.map +1 -0
  139. package/dist/utils/retry.d.ts +12 -0
  140. package/dist/utils/retry.d.ts.map +1 -0
  141. package/dist/utils/retry.js +28 -0
  142. package/dist/utils/retry.js.map +1 -0
  143. package/dist/utils/terminal-controller.d.ts +73 -139
  144. package/dist/utils/terminal-controller.d.ts.map +1 -1
  145. package/dist/utils/terminal-controller.js +234 -459
  146. package/dist/utils/terminal-controller.js.map +1 -1
  147. package/package.json +79 -60
  148. package/dist/providers/error-handler.d.ts +0 -51
  149. package/dist/providers/error-handler.d.ts.map +0 -1
  150. package/dist/providers/error-handler.js +0 -176
  151. package/dist/providers/error-handler.js.map +0 -1
  152. package/dist/providers/github-provider-backup.d.ts +0 -81
  153. package/dist/providers/github-provider-backup.d.ts.map +0 -1
  154. package/dist/providers/github-provider-backup.js +0 -1179
  155. package/dist/providers/github-provider-backup.js.map +0 -1
  156. package/dist/providers/github-provider-complete.d.ts +0 -1
  157. package/dist/providers/github-provider-complete.d.ts.map +0 -1
  158. package/dist/providers/github-provider-complete.js +0 -2
  159. package/dist/providers/github-provider-complete.js.map +0 -1
  160. package/dist/tools/git-init.d.ts +0 -50
  161. package/dist/tools/git-init.d.ts.map +0 -1
  162. package/dist/tools/git-init.js +0 -258
  163. package/dist/tools/git-init.js.map +0 -1
  164. package/dist/tools/git-log.d.ts +0 -67
  165. package/dist/tools/git-log.d.ts.map +0 -1
  166. package/dist/tools/git-log.js +0 -320
  167. package/dist/tools/git-log.js.map +0 -1
  168. package/dist/tools/git-status.d.ts +0 -29
  169. package/dist/tools/git-status.d.ts.map +0 -1
  170. package/dist/tools/git-status.js +0 -182
  171. package/dist/tools/git-status.js.map +0 -1
  172. package/dist/tools/git-update.d.ts +0 -34
  173. package/dist/tools/git-update.d.ts.map +0 -1
  174. package/dist/tools/git-update.js +0 -191
  175. package/dist/tools/git-update.js.map +0 -1
  176. package/dist/utils/auto-detection.d.ts +0 -120
  177. package/dist/utils/auto-detection.d.ts.map +0 -1
  178. package/dist/utils/auto-detection.js +0 -259
  179. package/dist/utils/auto-detection.js.map +0 -1
  180. package/dist/utils/configuration-error-generator.d.ts +0 -41
  181. package/dist/utils/configuration-error-generator.d.ts.map +0 -1
  182. package/dist/utils/configuration-error-generator.js +0 -168
  183. package/dist/utils/configuration-error-generator.js.map +0 -1
  184. package/dist/utils/configuration-validator.d.ts +0 -67
  185. package/dist/utils/configuration-validator.d.ts.map +0 -1
  186. package/dist/utils/configuration-validator.js +0 -257
  187. package/dist/utils/configuration-validator.js.map +0 -1
  188. package/dist/utils/error-handler.d.ts +0 -107
  189. package/dist/utils/error-handler.d.ts.map +0 -1
  190. package/dist/utils/error-handler.js +0 -331
  191. package/dist/utils/error-handler.js.map +0 -1
  192. package/dist/utils/git-operations.d.ts +0 -200
  193. package/dist/utils/git-operations.d.ts.map +0 -1
  194. package/dist/utils/git-operations.js +0 -836
  195. package/dist/utils/git-operations.js.map +0 -1
  196. package/dist/utils/multi-provider-error-handler.d.ts +0 -75
  197. package/dist/utils/multi-provider-error-handler.d.ts.map +0 -1
  198. package/dist/utils/multi-provider-error-handler.js +0 -276
  199. package/dist/utils/multi-provider-error-handler.js.map +0 -1
  200. package/dist/utils/multi-provider-operation-handler.d.ts +0 -113
  201. package/dist/utils/multi-provider-operation-handler.d.ts.map +0 -1
  202. package/dist/utils/multi-provider-operation-handler.js +0 -303
  203. package/dist/utils/multi-provider-operation-handler.js.map +0 -1
  204. package/dist/utils/provider-operation-handler.d.ts +0 -80
  205. package/dist/utils/provider-operation-handler.d.ts.map +0 -1
  206. package/dist/utils/provider-operation-handler.js +0 -201
  207. package/dist/utils/provider-operation-handler.js.map +0 -1
  208. package/dist/utils/response-helper.d.ts +0 -57
  209. package/dist/utils/response-helper.d.ts.map +0 -1
  210. package/dist/utils/response-helper.js +0 -54
  211. package/dist/utils/response-helper.js.map +0 -1
  212. package/dist/utils/user-detection.d.ts +0 -25
  213. package/dist/utils/user-detection.d.ts.map +0 -1
  214. package/dist/utils/user-detection.js +0 -54
  215. package/dist/utils/user-detection.js.map +0 -1
@@ -1,19 +1,145 @@
1
- import { UniversalResponse } from '../utils/auto-detection.js';
2
- export declare const gitBranchesTool: {
3
- name: string;
4
- description: string;
5
- inputSchema: {
6
- type: string;
7
- properties: {
8
- action: {
9
- type: string;
10
- };
11
- projectPath: {
12
- type: string;
1
+ /**
2
+ * Git Branches Tool
3
+ *
4
+ * Branch management tool providing comprehensive Git branch operations.
5
+ * Supports both local Git operations and remote provider operations.
6
+ *
7
+ * Operations: create, list, get, delete, merge, compare
8
+ */
9
+ import { ToolParams } from '../utils/parameter-validator.js';
10
+ import { ToolResult } from '../utils/operation-error-handler.js';
11
+ import { ProviderConfig } from '../providers/types.js';
12
+ export interface GitBranchesParams extends ToolParams {
13
+ action: 'create' | 'list' | 'get' | 'delete' | 'merge' | 'compare';
14
+ branchName?: string;
15
+ sourceBranch?: string;
16
+ targetBranch?: string;
17
+ baseBranch?: string;
18
+ compareBranch?: string;
19
+ force?: boolean;
20
+ remote?: string;
21
+ checkout?: boolean;
22
+ owner?: string;
23
+ repo?: string;
24
+ }
25
+ export declare class GitBranchesTool {
26
+ private gitExecutor;
27
+ private providerHandler?;
28
+ constructor(providerConfig?: ProviderConfig);
29
+ /**
30
+ * Execute git-branches operation
31
+ */
32
+ execute(params: GitBranchesParams): Promise<ToolResult>;
33
+ /**
34
+ * Execute local Git branch operations
35
+ */
36
+ private executeLocalOperation;
37
+ /**
38
+ * Execute remote provider operations
39
+ */
40
+ private executeRemoteOperation;
41
+ /**
42
+ * Handle create branch operation
43
+ */
44
+ private handleCreateBranch;
45
+ /**
46
+ * Handle list branches operation
47
+ */
48
+ private handleListBranches;
49
+ /**
50
+ * Handle get branch operation
51
+ */
52
+ private handleGetBranch;
53
+ /**
54
+ * Handle delete branch operation
55
+ */
56
+ private handleDeleteBranch;
57
+ /**
58
+ * Handle merge branch operation
59
+ */
60
+ private handleMergeBranch;
61
+ /**
62
+ * Handle compare branches operation
63
+ */
64
+ private handleCompareBranches;
65
+ /**
66
+ * Check if operation is a remote operation
67
+ */
68
+ private isRemoteOperation;
69
+ /**
70
+ * Extract parameters for remote operations
71
+ */
72
+ private extractRemoteParameters;
73
+ /**
74
+ * Map git-branches actions to provider operations
75
+ */
76
+ private mapActionToProviderOperation;
77
+ /**
78
+ * Get tool schema for MCP registration
79
+ */
80
+ static getToolSchema(): {
81
+ name: string;
82
+ description: string;
83
+ inputSchema: {
84
+ type: string;
85
+ properties: {
86
+ action: {
87
+ type: string;
88
+ enum: string[];
89
+ description: string;
90
+ };
91
+ projectPath: {
92
+ type: string;
93
+ description: string;
94
+ };
95
+ provider: {
96
+ type: string;
97
+ enum: string[];
98
+ description: string;
99
+ };
100
+ branchName: {
101
+ type: string;
102
+ description: string;
103
+ };
104
+ sourceBranch: {
105
+ type: string;
106
+ description: string;
107
+ };
108
+ targetBranch: {
109
+ type: string;
110
+ description: string;
111
+ };
112
+ baseBranch: {
113
+ type: string;
114
+ description: string;
115
+ };
116
+ compareBranch: {
117
+ type: string;
118
+ description: string;
119
+ };
120
+ force: {
121
+ type: string;
122
+ description: string;
123
+ };
124
+ remote: {
125
+ type: string;
126
+ description: string;
127
+ };
128
+ checkout: {
129
+ type: string;
130
+ description: string;
131
+ };
132
+ owner: {
133
+ type: string;
134
+ description: string;
135
+ };
136
+ repo: {
137
+ type: string;
138
+ description: string;
139
+ };
13
140
  };
141
+ required: string[];
14
142
  };
15
- required: string[];
16
143
  };
17
- handler(input: any): Promise<UniversalResponse>;
18
- };
144
+ }
19
145
  //# sourceMappingURL=git-branches.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-branches.d.ts","sourceRoot":"","sources":["../../src/tools/git-branches.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,iBAAiB,EAAc,MAAM,4BAA4B,CAAC;AAEpG,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;mBAIL,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAItD,CAAC"}
1
+ {"version":3,"file":"git-branches.d.ts","sourceRoot":"","sources":["../../src/tools/git-branches.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAsB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAAyB,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EAAE,cAAc,EAAqB,MAAM,uBAAuB,CAAC;AAE1E,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IAGnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,eAAe,CAAC,CAA2B;gBAEvC,cAAc,CAAC,EAAE,cAAc;IAO3C;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IAiD7D;;OAEG;YACW,qBAAqB;IAyBnC;;OAEG;YACW,sBAAsB;IA4DpC;;OAEG;YACW,kBAAkB;IAuEhC;;OAEG;YACW,kBAAkB;IAyChC;;OAEG;YACW,eAAe;IAmD7B;;OAEG;YACW,kBAAkB;IA2DhC;;OAEG;YACW,iBAAiB;IAsE/B;;OAEG;YACW,qBAAqB;IAuDnC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAY/B;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAWpC;;OAEG;IACH,MAAM,CAAC,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkErB"}
@@ -1,14 +1,469 @@
1
1
  "use strict";
2
+ /**
3
+ * Git Branches Tool
4
+ *
5
+ * Branch management tool providing comprehensive Git branch operations.
6
+ * Supports both local Git operations and remote provider operations.
7
+ *
8
+ * Operations: create, list, get, delete, merge, compare
9
+ */
2
10
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gitBranchesTool = void 0;
4
- const auto_detection_js_1 = require("../utils/auto-detection.js");
5
- exports.gitBranchesTool = {
6
- name: 'git-branches',
7
- description: '🌿 BRANCHES - Gerenciamento de branches',
8
- inputSchema: { type: 'object', properties: { action: { type: 'string' }, projectPath: { type: 'string' } }, required: ['action', 'projectPath'] },
9
- async handler(input) {
10
- const detection = (0, auto_detection_js_1.autoDetect)(input.projectPath);
11
- return (0, auto_detection_js_1.createUniversalResponse)(true, input.action, 'Operação de branch executada', detection, 'git-branches', { branches: ['main', 'develop'] });
12
- }
13
- };
11
+ exports.GitBranchesTool = void 0;
12
+ const git_command_executor_js_1 = require("../utils/git-command-executor.js");
13
+ const parameter_validator_js_1 = require("../utils/parameter-validator.js");
14
+ const operation_error_handler_js_1 = require("../utils/operation-error-handler.js");
15
+ const provider_operation_handler_js_1 = require("../providers/provider-operation-handler.js");
16
+ class GitBranchesTool {
17
+ gitExecutor;
18
+ providerHandler;
19
+ constructor(providerConfig) {
20
+ this.gitExecutor = new git_command_executor_js_1.GitCommandExecutor();
21
+ if (providerConfig) {
22
+ this.providerHandler = new provider_operation_handler_js_1.ProviderOperationHandler(providerConfig);
23
+ }
24
+ }
25
+ /**
26
+ * Execute git-branches operation
27
+ */
28
+ async execute(params) {
29
+ const startTime = Date.now();
30
+ try {
31
+ // Validate basic parameters
32
+ const validation = parameter_validator_js_1.ParameterValidator.validateToolParams('git-branches', params);
33
+ if (!validation.isValid) {
34
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('VALIDATION_ERROR', `Parameter validation failed: ${validation.errors.join(', ')}`, params.action, { validationErrors: validation.errors }, validation.suggestions);
35
+ }
36
+ // Validate operation-specific parameters
37
+ const operationValidation = parameter_validator_js_1.ParameterValidator.validateOperationParams('git-branches', params.action, params);
38
+ if (!operationValidation.isValid) {
39
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('VALIDATION_ERROR', `Operation validation failed: ${operationValidation.errors.join(', ')}`, params.action, { validationErrors: operationValidation.errors }, operationValidation.suggestions);
40
+ }
41
+ // Route to appropriate handler
42
+ const isRemoteOperation = this.isRemoteOperation(params.action);
43
+ if (isRemoteOperation) {
44
+ return await this.executeRemoteOperation(params, startTime);
45
+ }
46
+ else {
47
+ return await this.executeLocalOperation(params, startTime);
48
+ }
49
+ }
50
+ catch (error) {
51
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
52
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('EXECUTION_ERROR', `Failed to execute ${params.action}: ${errorMessage}`, params.action, { error: errorMessage }, ['Check the error details and try again']);
53
+ }
54
+ }
55
+ /**
56
+ * Execute local Git branch operations
57
+ */
58
+ async executeLocalOperation(params, startTime) {
59
+ switch (params.action) {
60
+ case 'create':
61
+ return await this.handleCreateBranch(params, startTime);
62
+ case 'list':
63
+ return await this.handleListBranches(params, startTime);
64
+ case 'get':
65
+ return await this.handleGetBranch(params, startTime);
66
+ case 'delete':
67
+ return await this.handleDeleteBranch(params, startTime);
68
+ case 'merge':
69
+ return await this.handleMergeBranch(params, startTime);
70
+ case 'compare':
71
+ return await this.handleCompareBranches(params, startTime);
72
+ default:
73
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('UNSUPPORTED_OPERATION', `Local operation '${params.action}' is not supported`, params.action, {}, ['Use one of: create, list, get, delete, merge, compare']);
74
+ }
75
+ }
76
+ /**
77
+ * Execute remote provider operations
78
+ */
79
+ async executeRemoteOperation(params, startTime) {
80
+ if (!this.providerHandler) {
81
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('PROVIDER_NOT_CONFIGURED', 'Provider handler is not configured for remote operations', params.action, {}, ['Configure GitHub or Gitea provider to use remote operations']);
82
+ }
83
+ if (!params.provider) {
84
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('PROVIDER_REQUIRED', 'Provider parameter is required for remote operations', params.action, {}, ['Specify provider as: github, gitea, or both']);
85
+ }
86
+ const operation = {
87
+ provider: params.provider,
88
+ operation: this.mapActionToProviderOperation(params.action),
89
+ parameters: this.extractRemoteParameters(params),
90
+ requiresAuth: true,
91
+ isRemoteOperation: true
92
+ };
93
+ try {
94
+ const result = await this.providerHandler.executeOperation(operation);
95
+ return {
96
+ success: result.success,
97
+ data: result.partialFailure ? result : result.results[0]?.data,
98
+ error: result.success ? undefined : {
99
+ code: result.errors[0]?.error?.code || 'REMOTE_OPERATION_ERROR',
100
+ message: result.errors[0]?.error?.message || 'Remote operation failed',
101
+ details: result.errors,
102
+ suggestions: ['Check provider configuration and credentials']
103
+ },
104
+ metadata: {
105
+ provider: params.provider,
106
+ operation: params.action,
107
+ timestamp: new Date().toISOString(),
108
+ executionTime: Date.now() - startTime
109
+ }
110
+ };
111
+ }
112
+ catch (error) {
113
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
114
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('REMOTE_OPERATION_ERROR', `Remote operation failed: ${errorMessage}`, params.action, { error: errorMessage }, ['Check provider configuration and network connectivity']);
115
+ }
116
+ }
117
+ /**
118
+ * Handle create branch operation
119
+ */
120
+ async handleCreateBranch(params, startTime) {
121
+ try {
122
+ if (!params.branchName) {
123
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_PARAMETER', 'branchName is required for branch creation', 'create', {}, ['Provide a name for the new branch']);
124
+ }
125
+ // Check if branch already exists
126
+ const existingBranches = await this.gitExecutor.listBranches(params.projectPath, { all: false });
127
+ if (existingBranches.success && existingBranches.branches?.includes(params.branchName)) {
128
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('BRANCH_EXISTS', `Branch '${params.branchName}' already exists`, 'create', { branchName: params.branchName }, ['Use a different branch name or delete the existing branch first']);
129
+ }
130
+ // Create branch
131
+ const result = await this.gitExecutor.createBranch(params.projectPath, params.branchName, params.sourceBranch);
132
+ if (!result.success) {
133
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(result.stderr, 'create branch', params.projectPath);
134
+ }
135
+ // Checkout branch if requested
136
+ let checkoutResult = null;
137
+ if (params.checkout) {
138
+ checkoutResult = await this.gitExecutor.checkoutBranch(params.projectPath, params.branchName);
139
+ if (!checkoutResult.success) {
140
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(checkoutResult.stderr, 'checkout branch', params.projectPath);
141
+ }
142
+ }
143
+ return {
144
+ success: true,
145
+ data: {
146
+ message: `Branch '${params.branchName}' created successfully`,
147
+ branchName: params.branchName,
148
+ sourceBranch: params.sourceBranch || 'current branch',
149
+ checkedOut: params.checkout || false,
150
+ output: result.stdout,
151
+ checkoutOutput: checkoutResult?.stdout
152
+ },
153
+ metadata: {
154
+ operation: 'create',
155
+ timestamp: new Date().toISOString(),
156
+ executionTime: Date.now() - startTime
157
+ }
158
+ };
159
+ }
160
+ catch (error) {
161
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
162
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('CREATE_BRANCH_ERROR', `Failed to create branch: ${errorMessage}`, 'create', { error: errorMessage, projectPath: params.projectPath });
163
+ }
164
+ }
165
+ /**
166
+ * Handle list branches operation
167
+ */
168
+ async handleListBranches(params, startTime) {
169
+ try {
170
+ const result = await this.gitExecutor.listBranches(params.projectPath, {
171
+ all: true,
172
+ remote: params.remote
173
+ });
174
+ if (!result.success) {
175
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(result.stderr, 'list branches', params.projectPath);
176
+ }
177
+ // Get current branch
178
+ const currentBranchResult = await this.gitExecutor.getCurrentBranch(params.projectPath);
179
+ const currentBranch = currentBranchResult.success ? currentBranchResult.branch : null;
180
+ return {
181
+ success: true,
182
+ data: {
183
+ branches: result.branches || [],
184
+ remoteBranches: result.remoteBranches || [],
185
+ currentBranch,
186
+ total: (result.branches?.length || 0) + (result.remoteBranches?.length || 0),
187
+ raw: result.stdout
188
+ },
189
+ metadata: {
190
+ operation: 'list',
191
+ timestamp: new Date().toISOString(),
192
+ executionTime: Date.now() - startTime
193
+ }
194
+ };
195
+ }
196
+ catch (error) {
197
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
198
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('LIST_BRANCHES_ERROR', `Failed to list branches: ${errorMessage}`, 'list', { error: errorMessage, projectPath: params.projectPath });
199
+ }
200
+ }
201
+ /**
202
+ * Handle get branch operation
203
+ */
204
+ async handleGetBranch(params, startTime) {
205
+ try {
206
+ if (!params.branchName) {
207
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_PARAMETER', 'branchName is required for get branch operation', 'get', {}, ['Provide the name of the branch to get information about']);
208
+ }
209
+ // Get branch information
210
+ const branchInfo = await this.gitExecutor.getBranchInfo(params.projectPath, params.branchName);
211
+ if (!branchInfo.success) {
212
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(branchInfo.stderr, 'get branch info', params.projectPath);
213
+ }
214
+ // Get branch commits
215
+ const commitsResult = await this.gitExecutor.getBranchCommits(params.projectPath, params.branchName, 10);
216
+ return {
217
+ success: true,
218
+ data: {
219
+ branchName: params.branchName,
220
+ exists: branchInfo.exists,
221
+ isRemote: branchInfo.isRemote,
222
+ lastCommit: branchInfo.lastCommit,
223
+ commits: commitsResult.success ? commitsResult.commits : [],
224
+ upstream: branchInfo.upstream,
225
+ ahead: branchInfo.ahead,
226
+ behind: branchInfo.behind
227
+ },
228
+ metadata: {
229
+ operation: 'get',
230
+ timestamp: new Date().toISOString(),
231
+ executionTime: Date.now() - startTime
232
+ }
233
+ };
234
+ }
235
+ catch (error) {
236
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
237
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('GET_BRANCH_ERROR', `Failed to get branch information: ${errorMessage}`, 'get', { error: errorMessage, projectPath: params.projectPath });
238
+ }
239
+ }
240
+ /**
241
+ * Handle delete branch operation
242
+ */
243
+ async handleDeleteBranch(params, startTime) {
244
+ try {
245
+ if (!params.branchName) {
246
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_PARAMETER', 'branchName is required for branch deletion', 'delete', {}, ['Provide the name of the branch to delete']);
247
+ }
248
+ // Check if trying to delete current branch
249
+ const currentBranchResult = await this.gitExecutor.getCurrentBranch(params.projectPath);
250
+ if (currentBranchResult.success && currentBranchResult.branch === params.branchName) {
251
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('CANNOT_DELETE_CURRENT_BRANCH', `Cannot delete current branch '${params.branchName}'`, 'delete', { branchName: params.branchName }, ['Switch to a different branch before deleting this one']);
252
+ }
253
+ const result = await this.gitExecutor.deleteBranch(params.projectPath, params.branchName, params.force || false);
254
+ if (!result.success) {
255
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(result.stderr, 'delete branch', params.projectPath);
256
+ }
257
+ return {
258
+ success: true,
259
+ data: {
260
+ message: `Branch '${params.branchName}' deleted successfully`,
261
+ branchName: params.branchName,
262
+ forced: params.force || false,
263
+ output: result.stdout
264
+ },
265
+ metadata: {
266
+ operation: 'delete',
267
+ timestamp: new Date().toISOString(),
268
+ executionTime: Date.now() - startTime
269
+ }
270
+ };
271
+ }
272
+ catch (error) {
273
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
274
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('DELETE_BRANCH_ERROR', `Failed to delete branch: ${errorMessage}`, 'delete', { error: errorMessage, projectPath: params.projectPath });
275
+ }
276
+ }
277
+ /**
278
+ * Handle merge branch operation
279
+ */
280
+ async handleMergeBranch(params, startTime) {
281
+ try {
282
+ if (!params.branchName) {
283
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_PARAMETER', 'branchName is required for branch merge', 'merge', {}, ['Provide the name of the branch to merge']);
284
+ }
285
+ // Get current branch (target branch)
286
+ const currentBranchResult = await this.gitExecutor.getCurrentBranch(params.projectPath);
287
+ if (!currentBranchResult.success) {
288
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(currentBranchResult.stderr, 'get current branch', params.projectPath);
289
+ }
290
+ const targetBranch = params.targetBranch || currentBranchResult.branch;
291
+ // Check for uncommitted changes
292
+ const statusResult = await this.gitExecutor.getStatus(params.projectPath);
293
+ if (statusResult.success && statusResult.parsedStatus &&
294
+ (statusResult.parsedStatus.modified.length > 0 || statusResult.parsedStatus.added.length > 0)) {
295
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('UNCOMMITTED_CHANGES', 'Cannot merge with uncommitted changes', 'merge', { uncommittedFiles: [...statusResult.parsedStatus.modified, ...statusResult.parsedStatus.added] }, ['Commit or stash your changes before merging']);
296
+ }
297
+ const result = await this.gitExecutor.mergeBranch(params.projectPath, params.branchName, { force: params.force });
298
+ if (!result.success) {
299
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(result.stderr, 'merge branch', params.projectPath);
300
+ }
301
+ return {
302
+ success: true,
303
+ data: {
304
+ message: `Branch '${params.branchName}' merged into '${targetBranch}' successfully`,
305
+ sourceBranch: params.branchName,
306
+ targetBranch,
307
+ mergeCommit: result.mergeCommit,
308
+ conflicts: result.conflicts || [],
309
+ output: result.stdout
310
+ },
311
+ metadata: {
312
+ operation: 'merge',
313
+ timestamp: new Date().toISOString(),
314
+ executionTime: Date.now() - startTime
315
+ }
316
+ };
317
+ }
318
+ catch (error) {
319
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
320
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MERGE_BRANCH_ERROR', `Failed to merge branch: ${errorMessage}`, 'merge', { error: errorMessage, projectPath: params.projectPath });
321
+ }
322
+ }
323
+ /**
324
+ * Handle compare branches operation
325
+ */
326
+ async handleCompareBranches(params, startTime) {
327
+ try {
328
+ if (!params.baseBranch || !params.compareBranch) {
329
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_PARAMETER', 'baseBranch and compareBranch are required for comparison', 'compare', {}, ['Provide both branch names to compare']);
330
+ }
331
+ const result = await this.gitExecutor.compareBranches(params.projectPath, params.baseBranch, params.compareBranch);
332
+ if (!result.success) {
333
+ return operation_error_handler_js_1.OperationErrorHandler.handleGitError(result.stderr, 'compare branches', params.projectPath);
334
+ }
335
+ return {
336
+ success: true,
337
+ data: {
338
+ baseBranch: params.baseBranch,
339
+ compareBranch: params.compareBranch,
340
+ ahead: result.ahead || 0,
341
+ behind: result.behind || 0,
342
+ commits: result.commits || [],
343
+ files: result.files || [],
344
+ summary: {
345
+ totalCommits: result.commits?.length || 0,
346
+ filesChanged: result.files?.length || 0,
347
+ insertions: result.insertions || 0,
348
+ deletions: result.deletions || 0
349
+ }
350
+ },
351
+ metadata: {
352
+ operation: 'compare',
353
+ timestamp: new Date().toISOString(),
354
+ executionTime: Date.now() - startTime
355
+ }
356
+ };
357
+ }
358
+ catch (error) {
359
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
360
+ return operation_error_handler_js_1.OperationErrorHandler.createToolError('COMPARE_BRANCHES_ERROR', `Failed to compare branches: ${errorMessage}`, 'compare', { error: errorMessage, projectPath: params.projectPath });
361
+ }
362
+ }
363
+ /**
364
+ * Check if operation is a remote operation
365
+ */
366
+ isRemoteOperation(action) {
367
+ // For now, all branch operations are local
368
+ // Remote branch operations would be handled through git-workflow or specific remote tools
369
+ return false;
370
+ }
371
+ /**
372
+ * Extract parameters for remote operations
373
+ */
374
+ extractRemoteParameters(params) {
375
+ const remoteParams = {
376
+ projectPath: params.projectPath
377
+ };
378
+ if (params.owner)
379
+ remoteParams.owner = params.owner;
380
+ if (params.repo)
381
+ remoteParams.repo = params.repo;
382
+ if (params.branchName)
383
+ remoteParams.branchName = params.branchName;
384
+ return remoteParams;
385
+ }
386
+ /**
387
+ * Map git-branches actions to provider operations
388
+ */
389
+ mapActionToProviderOperation(action) {
390
+ const actionMap = {
391
+ 'list': 'branch-list',
392
+ 'get': 'branch-get',
393
+ 'create': 'branch-create',
394
+ 'delete': 'branch-delete'
395
+ };
396
+ return actionMap[action] || action;
397
+ }
398
+ /**
399
+ * Get tool schema for MCP registration
400
+ */
401
+ static getToolSchema() {
402
+ return {
403
+ name: 'git-branches',
404
+ description: 'Git branch management tool for branch lifecycle operations. Supports create, list, get, delete, merge, and compare operations.',
405
+ inputSchema: {
406
+ type: 'object',
407
+ properties: {
408
+ action: {
409
+ type: 'string',
410
+ enum: ['create', 'list', 'get', 'delete', 'merge', 'compare'],
411
+ description: 'The branch operation to perform'
412
+ },
413
+ projectPath: {
414
+ type: 'string',
415
+ description: 'Absolute path to the project directory'
416
+ },
417
+ provider: {
418
+ type: 'string',
419
+ enum: ['github', 'gitea', 'both'],
420
+ description: 'Provider for remote operations (if supported)'
421
+ },
422
+ branchName: {
423
+ type: 'string',
424
+ description: 'Name of the branch (required for create, get, delete, merge)'
425
+ },
426
+ sourceBranch: {
427
+ type: 'string',
428
+ description: 'Source branch to create from (for create action)'
429
+ },
430
+ targetBranch: {
431
+ type: 'string',
432
+ description: 'Target branch to merge into (for merge action)'
433
+ },
434
+ baseBranch: {
435
+ type: 'string',
436
+ description: 'Base branch for comparison (required for compare action)'
437
+ },
438
+ compareBranch: {
439
+ type: 'string',
440
+ description: 'Branch to compare against base (required for compare action)'
441
+ },
442
+ force: {
443
+ type: 'boolean',
444
+ description: 'Force operation (for delete, merge actions)'
445
+ },
446
+ remote: {
447
+ type: 'string',
448
+ description: 'Remote name (default: origin)'
449
+ },
450
+ checkout: {
451
+ type: 'boolean',
452
+ description: 'Checkout branch after creation (for create action)'
453
+ },
454
+ owner: {
455
+ type: 'string',
456
+ description: 'Repository owner (for remote operations)'
457
+ },
458
+ repo: {
459
+ type: 'string',
460
+ description: 'Repository name (for remote operations)'
461
+ }
462
+ },
463
+ required: ['action', 'projectPath']
464
+ }
465
+ };
466
+ }
467
+ }
468
+ exports.GitBranchesTool = GitBranchesTool;
14
469
  //# sourceMappingURL=git-branches.js.map