@andrebuzeli/git-mcp 2.48.0 → 3.0.1

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 (61) hide show
  1. package/README.md +356 -329
  2. package/dist/server.d.ts.map +1 -1
  3. package/dist/server.js +82 -83
  4. package/dist/server.js.map +1 -1
  5. package/dist/tools/git-branches.d.ts +125 -359
  6. package/dist/tools/git-branches.d.ts.map +1 -1
  7. package/dist/tools/git-branches.js +179 -530
  8. package/dist/tools/git-branches.js.map +1 -1
  9. package/dist/tools/git-commits.d.ts +2 -2
  10. package/dist/tools/git-config.d.ts +2 -2
  11. package/dist/tools/git-files.d.ts +246 -406
  12. package/dist/tools/git-files.d.ts.map +1 -1
  13. package/dist/tools/git-files.js +556 -499
  14. package/dist/tools/git-files.js.map +1 -1
  15. package/dist/tools/git-issues.d.ts +10 -10
  16. package/dist/tools/git-packages.d.ts +2 -2
  17. package/dist/tools/git-projects.d.ts +142 -57
  18. package/dist/tools/git-projects.d.ts.map +1 -1
  19. package/dist/tools/git-projects.js +281 -283
  20. package/dist/tools/git-projects.js.map +1 -1
  21. package/dist/tools/git-pulls.d.ts +16 -16
  22. package/dist/tools/git-releases.d.ts +131 -401
  23. package/dist/tools/git-releases.d.ts.map +1 -1
  24. package/dist/tools/git-releases.js +374 -469
  25. package/dist/tools/git-releases.js.map +1 -1
  26. package/dist/tools/git-remote.d.ts +4 -4
  27. package/dist/tools/git-repositories.d.ts +8 -8
  28. package/dist/tools/git-reset.d.ts +106 -65
  29. package/dist/tools/git-reset.d.ts.map +1 -1
  30. package/dist/tools/git-reset.js +265 -149
  31. package/dist/tools/git-reset.js.map +1 -1
  32. package/dist/tools/git-stash.d.ts +110 -68
  33. package/dist/tools/git-stash.d.ts.map +1 -1
  34. package/dist/tools/git-stash.js +311 -186
  35. package/dist/tools/git-stash.js.map +1 -1
  36. package/dist/tools/git-sync.d.ts +149 -80
  37. package/dist/tools/git-sync.d.ts.map +1 -1
  38. package/dist/tools/git-sync.js +346 -246
  39. package/dist/tools/git-sync.js.map +1 -1
  40. package/dist/tools/git-tags.d.ts +2 -2
  41. package/dist/tools/git-undo.d.ts +268 -0
  42. package/dist/tools/git-undo.d.ts.map +1 -0
  43. package/dist/tools/git-undo.js +516 -0
  44. package/dist/tools/git-undo.js.map +1 -0
  45. package/dist/tools/git-update-project.d.ts +4 -159
  46. package/dist/tools/git-update-project.d.ts.map +1 -1
  47. package/dist/tools/git-update-project.js +7 -349
  48. package/dist/tools/git-update-project.js.map +1 -1
  49. package/dist/tools/git-versioning.d.ts +286 -0
  50. package/dist/tools/git-versioning.d.ts.map +1 -0
  51. package/dist/tools/git-versioning.js +483 -0
  52. package/dist/tools/git-versioning.js.map +1 -0
  53. package/dist/tools/git-workflow.d.ts +200 -259
  54. package/dist/tools/git-workflow.d.ts.map +1 -1
  55. package/dist/tools/git-workflow.js +424 -498
  56. package/dist/tools/git-workflow.js.map +1 -1
  57. package/package.json +5 -14
  58. package/dist/tools/git-publish.d.ts +0 -327
  59. package/dist/tools/git-publish.d.ts.map +0 -1
  60. package/dist/tools/git-publish.js +0 -632
  61. package/dist/tools/git-publish.js.map +0 -1
@@ -2,86 +2,96 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gitWorkflowTool = void 0;
4
4
  const zod_1 = require("zod");
5
+ const index_js_1 = require("../providers/index.js");
6
+ const user_detection_js_1 = require("../utils/user-detection.js");
7
+ const git_operations_js_1 = require("../utils/git-operations.js");
5
8
  /**
6
9
  * Tool: git-workflow
7
10
  *
8
- * DESCRIÇÃO:
9
- * Automação completa de workflows de desenvolvimento para programadores individuais autônomos
11
+ * FERRAMENTA UNIFICADA PARA WORKFLOW PRINCIPAL
12
+ * Combina as funcionalidades essenciais de:
13
+ * - git-update-project (init, update, sync)
14
+ * - git-commits (create, push, pull)
15
+ * - git-repositories (create, clone)
10
16
  *
11
- * FUNCIONALIDADES:
12
- * - Setup inicial automatizado de projetos
13
- * - Workflows diários de desenvolvimento
14
- * - Gerenciamento de features automatizado
15
- * - Processos de release completos
16
- * - Limpeza automática de repositórios
17
- * - Templates para diferentes tipos de projeto
18
- *
19
- * USO:
20
- * - Automação de todo o ciclo de desenvolvimento
21
- * - Setup consistente de novos projetos
22
- * - Workflows padronizados
23
- * - Eliminação de tarefas manuais repetitivas
24
- *
25
- * OTIMIZADO PARA AI AGENTS:
26
- * - Interface simples e intuitiva
27
- * - Auto-detecção de contexto
28
- * - Validação automática
29
- * - Error handling robusto
30
- * - Workflows em uma única chamada
17
+ * DESIGNED FOR: Programador individual autônomo
18
+ * PHILOSOPHY: Workflow principal completo em uma única ferramenta
31
19
  */
32
20
  const GitWorkflowInputSchema = zod_1.z.discriminatedUnion('action', [
33
- // Action: setup-project - Setup inicial completo
21
+ // WORKFLOW PRINCIPAL - Substitui git-update-project
22
+ zod_1.z.object({
23
+ action: zod_1.z.literal('init'),
24
+ repo: zod_1.z.string(),
25
+ projectPath: zod_1.z.string(),
26
+ provider: zod_1.z.enum(['gitea', 'github']),
27
+ message: zod_1.z.string().min(1, 'Commit message is required'),
28
+ createRemote: zod_1.z.boolean().optional().default(false),
29
+ branch: zod_1.z.string().optional().default('main')
30
+ }),
31
+ zod_1.z.object({
32
+ action: zod_1.z.literal('commit'),
33
+ projectPath: zod_1.z.string(),
34
+ message: zod_1.z.string().min(1, 'Commit message is required'),
35
+ addAll: zod_1.z.boolean().optional().default(true),
36
+ push: zod_1.z.boolean().optional().default(false),
37
+ branch: zod_1.z.string().optional().default('main'),
38
+ provider: zod_1.z.enum(['gitea', 'github']).optional()
39
+ }),
34
40
  zod_1.z.object({
35
- action: zod_1.z.literal('setup-project'),
41
+ action: zod_1.z.literal('sync'),
36
42
  repo: zod_1.z.string(),
43
+ projectPath: zod_1.z.string(),
37
44
  provider: zod_1.z.enum(['gitea', 'github']),
45
+ message: zod_1.z.string().min(1, 'Commit message is required'),
46
+ branch: zod_1.z.string().optional().default('main'),
47
+ forcePush: zod_1.z.boolean().optional().default(false)
48
+ }),
49
+ // STATUS E MONITORAMENTO
50
+ zod_1.z.object({
51
+ action: zod_1.z.literal('status'),
52
+ projectPath: zod_1.z.string(),
53
+ detailed: zod_1.z.boolean().optional().default(false)
54
+ }),
55
+ zod_1.z.object({
56
+ action: zod_1.z.literal('diff'),
38
57
  projectPath: zod_1.z.string(),
39
- template: zod_1.z.enum(['node-api', 'react-app', 'python-package', 'go-service', 'rust-binary']).optional().default('node-api'),
40
- platforms: zod_1.z.array(zod_1.z.enum(['npm', 'github', 'docker', 'pypi'])).optional().default(['github']),
41
- autoConfigure: zod_1.z.boolean().optional().default(true),
42
- createRemote: zod_1.z.boolean().optional().default(true),
43
- initGit: zod_1.z.boolean().optional().default(true)
58
+ staged: zod_1.z.boolean().optional().default(false),
59
+ file: zod_1.z.string().optional()
44
60
  }),
45
- // Action: daily-dev - Workflow diário completo
46
61
  zod_1.z.object({
47
- action: zod_1.z.literal('daily-dev'),
62
+ action: zod_1.z.literal('log'),
48
63
  projectPath: zod_1.z.string(),
49
- autoCommit: zod_1.z.boolean().optional().default(true),
50
- autoPush: zod_1.z.boolean().optional().default(true),
51
- createBackup: zod_1.z.boolean().optional().default(true),
52
- runTests: zod_1.z.boolean().optional().default(false),
53
- checkLint: zod_1.z.boolean().optional().default(false)
64
+ limit: zod_1.z.number().optional().default(10),
65
+ oneline: zod_1.z.boolean().optional().default(true)
66
+ }),
67
+ // REPOSITORIES - Substitui parte do git-repositories
68
+ zod_1.z.object({
69
+ action: zod_1.z.literal('create-repo'),
70
+ name: zod_1.z.string(),
71
+ description: zod_1.z.string().optional(),
72
+ private: zod_1.z.boolean().optional().default(false),
73
+ provider: zod_1.z.enum(['gitea', 'github'])
54
74
  }),
55
- // Action: feature-dev - Desenvolvimento de features
56
75
  zod_1.z.object({
57
- action: zod_1.z.literal('feature-dev'),
76
+ action: zod_1.z.literal('clone-repo'),
77
+ name: zod_1.z.string(),
78
+ provider: zod_1.z.enum(['gitea', 'github']),
58
79
  projectPath: zod_1.z.string(),
59
- featureName: zod_1.z.string(),
60
- createBranch: zod_1.z.boolean().optional().default(true),
61
- baseBranch: zod_1.z.string().optional().default('main'),
62
- mergeWhenReady: zod_1.z.boolean().optional().default(true),
63
- runTests: zod_1.z.boolean().optional().default(true),
64
- createPR: zod_1.z.boolean().optional().default(false)
80
+ branch: zod_1.z.string().optional().default('main')
65
81
  }),
66
- // Action: release-workflow - Processo completo de release
82
+ // QUICK ACTIONS
67
83
  zod_1.z.object({
68
- action: zod_1.z.literal('release-workflow'),
84
+ action: zod_1.z.literal('pull'),
69
85
  projectPath: zod_1.z.string(),
70
- version: zod_1.z.string().optional(),
71
- platforms: zod_1.z.array(zod_1.z.enum(['npm', 'github', 'docker', 'pypi'])).optional().default(['npm', 'github']),
72
- createTag: zod_1.z.boolean().optional().default(true),
73
- createRelease: zod_1.z.boolean().optional().default(true),
74
- updateChangelog: zod_1.z.boolean().optional().default(true),
75
- runTests: zod_1.z.boolean().optional().default(true)
86
+ branch: zod_1.z.string().optional().default('main'),
87
+ provider: zod_1.z.enum(['gitea', 'github']).optional()
76
88
  }),
77
- // Action: cleanup-workflow - Limpeza de repositório
78
89
  zod_1.z.object({
79
- action: zod_1.z.literal('cleanup-workflow'),
90
+ action: zod_1.z.literal('push'),
80
91
  projectPath: zod_1.z.string(),
81
- removeMergedBranches: zod_1.z.boolean().optional().default(true),
82
- removeOldBackups: zod_1.z.boolean().optional().default(true),
83
- optimizeRepository: zod_1.z.boolean().optional().default(true),
84
- daysOld: zod_1.z.number().optional().default(30)
92
+ branch: zod_1.z.string().optional().default('main'),
93
+ provider: zod_1.z.enum(['gitea', 'github']).optional(),
94
+ force: zod_1.z.boolean().optional().default(false)
85
95
  })
86
96
  ]);
87
97
  const GitWorkflowResultSchema = zod_1.z.object({
@@ -89,555 +99,471 @@ const GitWorkflowResultSchema = zod_1.z.object({
89
99
  action: zod_1.z.string(),
90
100
  message: zod_1.z.string(),
91
101
  data: zod_1.z.any().optional(),
92
- error: zod_1.z.string().optional()
102
+ error: zod_1.z.string().optional(),
103
+ recoverable: zod_1.z.boolean().optional(),
104
+ suggestion: zod_1.z.string().optional()
93
105
  });
106
+ /**
107
+ * Enhanced Error Handler with Recovery Suggestions
108
+ */
109
+ class WorkflowErrorHandler {
110
+ static handleError(error, context) {
111
+ const errorMessage = error instanceof Error ? error.message : String(error);
112
+ // Error patterns and recovery suggestions
113
+ const errorPatterns = [
114
+ {
115
+ pattern: /not a git repository/i,
116
+ suggestion: "Run 'git init' first or check the project path",
117
+ recoverable: true
118
+ },
119
+ {
120
+ pattern: /no commits/i,
121
+ suggestion: "Make initial commit first",
122
+ recoverable: true
123
+ },
124
+ {
125
+ pattern: /repository.*already exists/i,
126
+ suggestion: "Choose a different repository name",
127
+ recoverable: true
128
+ },
129
+ {
130
+ pattern: /authentication failed/i,
131
+ suggestion: "Check your token configuration",
132
+ recoverable: true
133
+ },
134
+ {
135
+ pattern: /permission denied/i,
136
+ suggestion: "Check repository permissions and token scope",
137
+ recoverable: true
138
+ },
139
+ {
140
+ pattern: /network error/i,
141
+ suggestion: "Check internet connection and try again",
142
+ recoverable: true
143
+ }
144
+ ];
145
+ const matchedPattern = errorPatterns.find(p => p.pattern.test(errorMessage));
146
+ return {
147
+ success: false,
148
+ action: context,
149
+ message: `Error in ${context}: ${errorMessage}`,
150
+ error: errorMessage,
151
+ recoverable: matchedPattern?.recoverable || false,
152
+ suggestion: matchedPattern?.suggestion
153
+ };
154
+ }
155
+ }
94
156
  exports.gitWorkflowTool = {
95
157
  name: 'git-workflow',
96
- description: 'tool: WORKFLOW AUTOMATION - Sistema completo de automação para programadores individuais\\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\nAÇÕES DISPONÍVEIS (5 workflows automatizados):\\n\\n🚀 SETUP COMPLETO:\\n• setup-project: Setup inicial automatizado com templates\\n\\n📅 WORKFLOWS DIÁRIOS:\\n• daily-dev: Workflow diário completo (backup+commit+push)\\n• feature-dev: Desenvolvimento de features automatizado\\n\\n🎯 RELEASE COMPLETO:\\n• release-workflow: Processo completo de release\\n\\n🧹 MANUTENÇÃO:\\n• cleanup-workflow: Limpeza automática de repositório\\n\\n🤖 OTIMIZADO PARA AI AGENTS:\\n• Workflows em 1 chamada\\n• Auto-configuração inteligente\\n• Templates padronizados\\n• Validação automática\\n• Error recovery automático\\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n💡 USO TÍPICO:\\n1. setup-project (novo projeto)\\n2. daily-dev (desenvolvimento diário)\\n3. feature-dev (nova feature)\\n4. release-workflow (publicação)\\n5. cleanup-workflow (manutenção)\\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
158
+ description: `🛠️ WORKFLOW PRINCIPAL - Tudo que você precisa para trabalhar
159
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
160
+ 🎯 WORKFLOW PRINCIPAL:
161
+ • init: Inicializar projeto completo
162
+ • commit: Commit + push automático
163
+ • sync: Pull + commit + push completo
164
+
165
+ 📊 STATUS & MONITORAMENTO:
166
+ • status: Status detalhado do projeto
167
+ • diff: Ver diferenças nos arquivos
168
+ • log: Histórico de commits
169
+
170
+ 🏗️ REPOSITÓRIOS:
171
+ • create-repo: Criar repositório remoto
172
+ • clone-repo: Clonar repositório localmente
173
+
174
+ ⚡ QUICK ACTIONS:
175
+ • pull: Baixar mudanças
176
+ • push: Enviar mudanças
177
+
178
+ ✨ DIFERENCIAIS:
179
+ • Error handling inteligente com sugestões
180
+ • Workflow completo em uma ferramenta
181
+ • Auto-detecção de providers
182
+ • Operações seguras com validação`,
97
183
  inputSchema: {
98
184
  type: 'object',
99
185
  properties: {
100
186
  action: {
101
187
  type: 'string',
102
- enum: ['setup-project', 'daily-dev', 'feature-dev', 'release-workflow', 'cleanup-workflow'],
188
+ enum: ['init', 'commit', 'sync', 'status', 'diff', 'log', 'create-repo', 'clone-repo', 'pull', 'push'],
103
189
  description: 'Workflow action to perform'
104
190
  },
105
191
  repo: { type: 'string', description: 'Repository name' },
106
- provider: { type: 'string', enum: ['gitea', 'github'], description: 'Provider to use' },
107
192
  projectPath: { type: 'string', description: 'Local project path' },
108
- template: {
109
- type: 'string',
110
- enum: ['node-api', 'react-app', 'python-package', 'go-service', 'rust-binary'],
111
- description: 'Project template to use',
112
- default: 'node-api'
113
- },
114
- platforms: {
115
- type: 'array',
116
- items: { type: 'string', enum: ['npm', 'github', 'docker', 'pypi'] },
117
- description: 'Platforms for setup/publishing',
118
- default: ['github']
119
- },
120
- autoConfigure: { type: 'boolean', description: 'Auto-configure project', default: true },
121
- createRemote: { type: 'boolean', description: 'Create remote repository', default: true },
122
- initGit: { type: 'boolean', description: 'Initialize Git repository', default: true },
123
- autoCommit: { type: 'boolean', description: 'Auto-commit changes', default: true },
124
- autoPush: { type: 'boolean', description: 'Auto-push after commit', default: true },
125
- createBackup: { type: 'boolean', description: 'Create backup before operations', default: true },
126
- runTests: { type: 'boolean', description: 'Run tests before operations', default: true },
127
- checkLint: { type: 'boolean', description: 'Check linting', default: false },
128
- featureName: { type: 'string', description: 'Name of the feature to develop' },
129
- createBranch: { type: 'boolean', description: 'Create feature branch', default: true },
130
- baseBranch: { type: 'string', description: 'Base branch for feature', default: 'main' },
131
- mergeWhenReady: { type: 'boolean', description: 'Merge when feature is ready', default: true },
132
- createPR: { type: 'boolean', description: 'Create pull request', default: false },
133
- version: { type: 'string', description: 'Release version' },
134
- createTag: { type: 'boolean', description: 'Create release tag', default: true },
135
- createRelease: { type: 'boolean', description: 'Create GitHub release', default: true },
136
- updateChangelog: { type: 'boolean', description: 'Update changelog', default: true },
137
- removeMergedBranches: { type: 'boolean', description: 'Remove merged branches', default: true },
138
- removeOldBackups: { type: 'boolean', description: 'Remove old backup stashes', default: true },
139
- optimizeRepository: { type: 'boolean', description: 'Optimize repository', default: true },
140
- daysOld: { type: 'number', description: 'Days threshold for cleanup', default: 30 }
193
+ provider: { type: 'string', enum: ['gitea', 'github'], description: 'Git provider' },
194
+ message: { type: 'string', description: 'Commit message' },
195
+ createRemote: { type: 'boolean', description: 'Create remote repository', default: false },
196
+ branch: { type: 'string', description: 'Branch name', default: 'main' },
197
+ addAll: { type: 'boolean', description: 'Add all files before commit', default: true },
198
+ push: { type: 'boolean', description: 'Push after commit', default: false },
199
+ forcePush: { type: 'boolean', description: 'Force push', default: false },
200
+ detailed: { type: 'boolean', description: 'Detailed output', default: false },
201
+ staged: { type: 'boolean', description: 'Show staged changes', default: false },
202
+ file: { type: 'string', description: 'Specific file for diff' },
203
+ limit: { type: 'number', description: 'Limit for log', default: 10 },
204
+ oneline: { type: 'boolean', description: 'One line log format', default: true },
205
+ name: { type: 'string', description: 'Repository name' },
206
+ description: { type: 'string', description: 'Repository description' },
207
+ private: { type: 'boolean', description: 'Private repository', default: false },
208
+ force: { type: 'boolean', description: 'Force push', default: false }
141
209
  },
142
- required: ['action', 'projectPath']
210
+ required: ['action']
143
211
  },
144
212
  async handler(input) {
145
213
  try {
146
214
  const validatedInput = GitWorkflowInputSchema.parse(input);
147
215
  switch (validatedInput.action) {
148
- case 'setup-project':
149
- return await this.handleSetupProject(validatedInput);
150
- case 'daily-dev':
151
- return await this.handleDailyDev(validatedInput);
152
- case 'feature-dev':
153
- return await this.handleFeatureDev(validatedInput);
154
- case 'release-workflow':
155
- return await this.handleReleaseWorkflow(validatedInput);
156
- case 'cleanup-workflow':
157
- return await this.handleCleanupWorkflow(validatedInput);
216
+ case 'init':
217
+ return await this.handleInit(validatedInput);
218
+ case 'commit':
219
+ return await this.handleCommit(validatedInput);
220
+ case 'sync':
221
+ return await this.handleSync(validatedInput);
222
+ case 'status':
223
+ return await this.handleStatus(validatedInput);
224
+ case 'diff':
225
+ return await this.handleDiff(validatedInput);
226
+ case 'log':
227
+ return await this.handleLog(validatedInput);
228
+ case 'create-repo':
229
+ return await this.handleCreateRepo(validatedInput);
230
+ case 'clone-repo':
231
+ return await this.handleCloneRepo(validatedInput);
232
+ case 'pull':
233
+ return await this.handlePull(validatedInput);
234
+ case 'push':
235
+ return await this.handlePush(validatedInput);
158
236
  default:
159
- throw new Error(`Action '${validatedInput.action}' não suportada`);
237
+ throw new Error(`Action '${validatedInput.action}' not supported`);
160
238
  }
161
239
  }
162
240
  catch (error) {
163
- return {
164
- success: false,
165
- action: input.action,
166
- message: `Erro na operação ${input.action}`,
167
- error: error instanceof Error ? error.message : String(error)
168
- };
241
+ return WorkflowErrorHandler.handleError(error, `workflow.${input.action}`);
169
242
  }
170
243
  },
171
- // Handler para setup-project
172
- async handleSetupProject(params) {
173
- try {
174
- const { repo, provider, projectPath, template = 'node-api', platforms = ['github'], autoConfigure = true, createRemote = true, initGit = true } = params;
175
- const results = {
176
- gitInit: false,
177
- remoteCreated: false,
178
- templateApplied: false,
179
- configured: false
180
- };
181
- // 1. Initialize Git if requested
182
- if (initGit) {
183
- const initResult = await this.initializeGit(projectPath);
184
- results.gitInit = initResult.success;
185
- }
186
- // 2. Create remote repository if requested
187
- if (createRemote) {
188
- const remoteResult = await this.createRemoteRepository(repo, provider, projectPath);
189
- results.remoteCreated = remoteResult.success;
190
- }
191
- // 3. Apply template
192
- const templateResult = await this.applyTemplate(projectPath, template);
193
- results.templateApplied = templateResult.success;
194
- // 4. Auto-configure if requested
195
- if (autoConfigure) {
196
- const configResult = await this.autoConfigureProject(projectPath, template, platforms);
197
- results.configured = configResult.success;
198
- }
199
- const allSuccessful = Object.values(results).every(r => r);
200
- return {
201
- success: allSuccessful,
202
- action: 'setup-project',
203
- message: `Setup de projeto ${allSuccessful ? 'concluído' : 'com problemas'}`,
204
- data: {
205
- repo,
206
- template,
207
- platforms,
208
- results,
209
- implementation: 'SETUP_PROJECT_v2.39.0'
210
- }
211
- };
212
- }
213
- catch (error) {
244
+ async handleInit(params) {
245
+ const { repo, projectPath, message, createRemote, branch, provider } = params;
246
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
247
+ // Check if already a git repo
248
+ const isGit = await gitOps.isGitRepository();
249
+ if (isGit) {
214
250
  return {
215
251
  success: false,
216
- action: 'setup-project',
217
- message: 'Erro no setup de projeto',
218
- error: error instanceof Error ? error.message : String(error)
252
+ action: 'init',
253
+ message: 'Project is already a Git repository',
254
+ suggestion: 'Use commit or sync instead'
219
255
  };
220
256
  }
221
- },
222
- // Handler para daily-dev
223
- async handleDailyDev(params) {
224
257
  try {
225
- const { projectPath, autoCommit = true, autoPush = true, createBackup = true, runTests = false, checkLint = false } = params;
226
- const results = {
227
- backup: false,
228
- tests: false,
229
- lint: false,
230
- commit: false,
231
- push: false
232
- };
233
- // 1. Create backup if requested
234
- if (createBackup) {
235
- const backupResult = await this.createBackup(projectPath);
236
- results.backup = backupResult.success;
258
+ // Initialize git repo
259
+ const initResult = await gitOps.initRepository();
260
+ if (!initResult.success) {
261
+ throw new Error(`Failed to initialize Git repository: ${initResult.error}`);
237
262
  }
238
- // 2. Run tests if requested
239
- if (runTests) {
240
- const testResult = await this.runTests(projectPath);
241
- results.tests = testResult.success;
263
+ // Add all files
264
+ const addResult = await gitOps.addFiles();
265
+ if (!addResult.success) {
266
+ throw new Error(`Failed to add files: ${addResult.error}`);
242
267
  }
243
- // 3. Check lint if requested
244
- if (checkLint) {
245
- const lintResult = await this.checkLinting(projectPath);
246
- results.lint = lintResult.success;
268
+ // Create initial commit
269
+ const commitResult = await gitOps.commit(message);
270
+ if (!commitResult.success) {
271
+ throw new Error(`Failed to create initial commit: ${commitResult.error}`);
247
272
  }
248
- // 4. Commit changes if requested
249
- if (autoCommit) {
250
- const commitResult = await this.smartCommit(projectPath);
251
- results.commit = commitResult.success;
252
- }
253
- // 5. Push if requested
254
- if (autoPush && results.commit) {
255
- const pushResult = await this.pushChanges(projectPath);
256
- results.push = pushResult.success;
273
+ // Create remote if requested
274
+ if (createRemote) {
275
+ const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)({ provider }, provider);
276
+ if (processedInput.owner) {
277
+ const providerInstance = index_js_1.globalProviderFactory.getProvider(provider);
278
+ if (providerInstance) {
279
+ try {
280
+ const remoteResult = await providerInstance.createRepository(repo, `Project initialized via MCP`, false);
281
+ const remoteUrl = await providerInstance.getRepositoryUrl(processedInput.owner, repo);
282
+ // Add remote
283
+ const remoteAddResult = await gitOps.remote('add', 'origin', remoteUrl);
284
+ if (remoteAddResult.success) {
285
+ // Push to remote
286
+ const pushResult = await gitOps.push('origin', branch);
287
+ if (pushResult.success) {
288
+ return {
289
+ success: true,
290
+ action: 'init',
291
+ message: `Project initialized with remote repository`,
292
+ data: { remoteUrl, branch, commit: commitResult.output }
293
+ };
294
+ }
295
+ }
296
+ }
297
+ catch (remoteError) {
298
+ // Remote creation failed, but local repo is ready
299
+ console.warn('Remote creation failed:', remoteError);
300
+ }
301
+ }
302
+ }
257
303
  }
258
- const allSuccessful = Object.values(results).filter(r => r !== false).every(r => r);
259
304
  return {
260
- success: allSuccessful,
261
- action: 'daily-dev',
262
- message: `Workflow diário ${allSuccessful ? 'concluído' : 'com problemas'}`,
263
- data: {
264
- results,
265
- implementation: 'DAILY_DEV_v2.39.0'
266
- }
305
+ success: true,
306
+ action: 'init',
307
+ message: 'Project initialized successfully',
308
+ data: { branch, commit: commitResult.output }
267
309
  };
268
310
  }
269
311
  catch (error) {
270
- return {
271
- success: false,
272
- action: 'daily-dev',
273
- message: 'Erro no workflow diário',
274
- error: error instanceof Error ? error.message : String(error)
275
- };
312
+ return WorkflowErrorHandler.handleError(error, 'init');
276
313
  }
277
314
  },
278
- // Handler para feature-dev
279
- async handleFeatureDev(params) {
315
+ async handleCommit(params) {
316
+ const { projectPath, message, addAll, push, branch, provider } = params;
317
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
318
+ // Verify git repo
319
+ if (!(await gitOps.isGitRepository())) {
320
+ return WorkflowErrorHandler.handleError(new Error('Not a Git repository'), 'commit');
321
+ }
280
322
  try {
281
- const { projectPath, featureName, createBranch = true, baseBranch = 'main', mergeWhenReady = true, runTests = true, createPR = false } = params;
282
- const results = {
283
- branch: false,
284
- tests: false,
285
- merge: false,
286
- pr: false
287
- };
288
- // 1. Create feature branch if requested
289
- if (createBranch) {
290
- const branchResult = await this.createFeatureBranch(projectPath, featureName, baseBranch);
291
- results.branch = branchResult.success;
323
+ // Add files if requested
324
+ if (addAll) {
325
+ const addResult = await gitOps.addFiles();
326
+ if (!addResult.success) {
327
+ throw new Error(`Failed to add files: ${addResult.error}`);
328
+ }
292
329
  }
293
- // 2. Run tests if requested
294
- if (runTests) {
295
- const testResult = await this.runTests(projectPath);
296
- results.tests = testResult.success;
330
+ // Check if there are changes to commit
331
+ const statusResult = await gitOps.status({ porcelain: true });
332
+ if (!statusResult.output.trim()) {
333
+ return {
334
+ success: false,
335
+ action: 'commit',
336
+ message: 'No changes to commit',
337
+ suggestion: 'Make some changes first'
338
+ };
297
339
  }
298
- // 3. Merge when ready if requested
299
- if (mergeWhenReady && results.tests) {
300
- const mergeResult = await this.mergeFeature(projectPath, featureName, baseBranch);
301
- results.merge = mergeResult.success;
340
+ // Commit
341
+ const commitResult = await gitOps.commit(message);
342
+ if (!commitResult.success) {
343
+ throw new Error(`Commit failed: ${commitResult.error}`);
302
344
  }
303
- // 4. Create PR if requested
304
- if (createPR && results.merge) {
305
- const prResult = await this.createPullRequest(projectPath, featureName);
306
- results.pr = prResult.success;
345
+ // Push if requested
346
+ if (push && provider) {
347
+ const pushResult = await gitOps.push('origin', branch);
348
+ if (!pushResult.success) {
349
+ return {
350
+ success: true,
351
+ action: 'commit',
352
+ message: 'Commit successful, but push failed',
353
+ data: { commit: commitResult.output },
354
+ error: pushResult.error,
355
+ suggestion: 'Check remote configuration or network connection'
356
+ };
357
+ }
307
358
  }
308
- const allSuccessful = Object.values(results).filter(r => r !== false).every(r => r);
309
359
  return {
310
- success: allSuccessful,
311
- action: 'feature-dev',
312
- message: `Desenvolvimento de feature ${allSuccessful ? 'concluído' : 'com problemas'}`,
313
- data: {
314
- featureName,
315
- results,
316
- implementation: 'FEATURE_DEV_v2.39.0'
317
- }
360
+ success: true,
361
+ action: 'commit',
362
+ message: push ? 'Commit and push successful' : 'Commit successful',
363
+ data: { commit: commitResult.output, pushed: push || false }
318
364
  };
319
365
  }
320
366
  catch (error) {
321
- return {
322
- success: false,
323
- action: 'feature-dev',
324
- message: 'Erro no desenvolvimento de feature',
325
- error: error instanceof Error ? error.message : String(error)
326
- };
367
+ return WorkflowErrorHandler.handleError(error, 'commit');
327
368
  }
328
369
  },
329
- // Handler para release-workflow
330
- async handleReleaseWorkflow(params) {
370
+ async handleSync(params) {
371
+ const { repo, projectPath, message, branch, forcePush, provider } = params;
372
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
331
373
  try {
332
- const { projectPath, version, platforms = ['npm', 'github'], createTag = true, createRelease = true, updateChangelog = true, runTests = true } = params;
333
- const results = {
334
- tests: false,
335
- changelog: false,
336
- tag: false,
337
- release: false
338
- };
339
- // 1. Run tests if requested
340
- if (runTests) {
341
- const testResult = await this.runTests(projectPath);
342
- results.tests = testResult.success;
374
+ // Pull first
375
+ const pullResult = await gitOps.pull('origin', branch);
376
+ if (!pullResult.success && !pullResult.error?.includes('up-to-date')) {
377
+ console.warn('Pull failed:', pullResult.error);
343
378
  }
344
- // 2. Update changelog if requested
345
- if (updateChangelog) {
346
- const changelogResult = await this.updateChangelog(projectPath, version || '1.0.0');
347
- results.changelog = changelogResult.success;
379
+ // Add and commit
380
+ const addResult = await gitOps.addFiles();
381
+ if (!addResult.success) {
382
+ throw new Error(`Failed to add files: ${addResult.error}`);
348
383
  }
349
- // 3. Create tag if requested
350
- if (createTag && results.tests) {
351
- const tagResult = await this.createReleaseTag(projectPath, version || '1.0.0');
352
- results.tag = tagResult.success;
353
- }
354
- // 4. Create release if requested
355
- if (createRelease && results.tag) {
356
- const releaseResult = await this.createRelease(projectPath, version || '1.0.0', platforms);
357
- results.release = releaseResult.success;
358
- }
359
- const allSuccessful = Object.values(results).filter(r => r !== false).every(r => r);
360
- return {
361
- success: allSuccessful,
362
- action: 'release-workflow',
363
- message: `Workflow de release ${allSuccessful ? 'concluído' : 'com problemas'}`,
364
- data: {
365
- version,
366
- platforms,
367
- results,
368
- implementation: 'RELEASE_WORKFLOW_v2.39.0'
384
+ const statusResult = await gitOps.status({ porcelain: true });
385
+ if (statusResult.output.trim()) {
386
+ const commitResult = await gitOps.commit(message);
387
+ if (!commitResult.success) {
388
+ throw new Error(`Commit failed: ${commitResult.error}`);
369
389
  }
370
- };
371
- }
372
- catch (error) {
373
- return {
374
- success: false,
375
- action: 'release-workflow',
376
- message: 'Erro no workflow de release',
377
- error: error instanceof Error ? error.message : String(error)
378
- };
379
- }
380
- },
381
- // Handler para cleanup-workflow
382
- async handleCleanupWorkflow(params) {
383
- try {
384
- const { projectPath, removeMergedBranches = true, removeOldBackups = true, optimizeRepository = true, daysOld = 30 } = params;
385
- const results = {
386
- mergedBranches: false,
387
- oldBackups: false,
388
- optimization: false
389
- };
390
- // 1. Remove merged branches if requested
391
- if (removeMergedBranches) {
392
- const branchResult = await this.removeMergedBranches(projectPath);
393
- results.mergedBranches = branchResult.success;
394
- }
395
- // 2. Remove old backup stashes if requested
396
- if (removeOldBackups) {
397
- const backupResult = await this.removeOldBackups(projectPath, daysOld);
398
- results.oldBackups = backupResult.success;
399
390
  }
400
- // 3. Optimize repository if requested
401
- if (optimizeRepository) {
402
- const optimizeResult = await this.optimizeRepository(projectPath);
403
- results.optimization = optimizeResult.success;
391
+ // Push
392
+ const pushOptions = {};
393
+ if (forcePush)
394
+ pushOptions.force = true;
395
+ const pushResult = await gitOps.push('origin', branch, pushOptions);
396
+ if (!pushResult.success) {
397
+ throw new Error(`Push failed: ${pushResult.error}`);
404
398
  }
405
- const allSuccessful = Object.values(results).filter(r => r !== false).every(r => r);
406
- return {
407
- success: allSuccessful,
408
- action: 'cleanup-workflow',
409
- message: `Limpeza de repositório ${allSuccessful ? 'concluída' : 'com problemas'}`,
410
- data: {
411
- results,
412
- daysOld,
413
- implementation: 'CLEANUP_WORKFLOW_v2.39.0'
414
- }
415
- };
416
- }
417
- catch (error) {
418
- return {
419
- success: false,
420
- action: 'cleanup-workflow',
421
- message: 'Erro na limpeza de repositório',
422
- error: error instanceof Error ? error.message : String(error)
423
- };
424
- }
425
- },
426
- // Helper methods
427
- async initializeGit(projectPath) {
428
- try {
429
- // TODO: Initialize Git repository
430
- return { success: true };
431
- }
432
- catch (error) {
433
- return {
434
- success: false,
435
- error: error instanceof Error ? error.message : String(error)
436
- };
437
- }
438
- },
439
- async createRemoteRepository(repo, provider, projectPath) {
440
- try {
441
- // TODO: Create remote repository
442
- return { success: true };
443
- }
444
- catch (error) {
445
- return {
446
- success: false,
447
- error: error instanceof Error ? error.message : String(error)
448
- };
449
- }
450
- },
451
- async applyTemplate(projectPath, template) {
452
- try {
453
- // TODO: Apply project template
454
- return { success: true };
455
- }
456
- catch (error) {
457
399
  return {
458
- success: false,
459
- error: error instanceof Error ? error.message : String(error)
400
+ success: true,
401
+ action: 'sync',
402
+ message: 'Sync completed successfully',
403
+ data: { pulled: pullResult.success, pushed: true, branch }
460
404
  };
461
405
  }
462
- },
463
- async autoConfigureProject(projectPath, template, platforms) {
464
- try {
465
- // TODO: Auto-configure project
466
- return { success: true };
467
- }
468
406
  catch (error) {
469
- return {
470
- success: false,
471
- error: error instanceof Error ? error.message : String(error)
472
- };
407
+ return WorkflowErrorHandler.handleError(error, 'sync');
473
408
  }
474
409
  },
475
- async createBackup(projectPath) {
410
+ async handleStatus(params) {
411
+ const { projectPath, detailed } = params;
412
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
476
413
  try {
477
- // TODO: Create backup
478
- return { success: true };
479
- }
480
- catch (error) {
414
+ const statusResult = await gitOps.status(detailed ? {} : { short: true });
415
+ if (!statusResult.success) {
416
+ throw new Error(`Status check failed: ${statusResult.error}`);
417
+ }
481
418
  return {
482
- success: false,
483
- error: error instanceof Error ? error.message : String(error)
419
+ success: true,
420
+ action: 'status',
421
+ message: 'Status retrieved successfully',
422
+ data: { status: statusResult.output, detailed }
484
423
  };
485
424
  }
486
- },
487
- async runTests(projectPath) {
488
- try {
489
- // TODO: Run test suite
490
- return { success: true };
491
- }
492
425
  catch (error) {
493
- return {
494
- success: false,
495
- error: error instanceof Error ? error.message : String(error)
496
- };
426
+ return WorkflowErrorHandler.handleError(error, 'status');
497
427
  }
498
428
  },
499
- async checkLinting(projectPath) {
429
+ async handleDiff(params) {
430
+ const { projectPath, staged, file } = params;
431
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
500
432
  try {
501
- // TODO: Check linting
502
- return { success: true };
503
- }
504
- catch (error) {
433
+ const diffOptions = { patch: true };
434
+ if (staged)
435
+ diffOptions.cached = true;
436
+ if (file)
437
+ diffOptions.path = file;
438
+ const diffResult = await gitOps.diff(diffOptions);
505
439
  return {
506
- success: false,
507
- error: error instanceof Error ? error.message : String(error)
440
+ success: true,
441
+ action: 'diff',
442
+ message: 'Diff retrieved successfully',
443
+ data: { diff: diffResult.output, staged, file }
508
444
  };
509
445
  }
510
- },
511
- async smartCommit(projectPath) {
512
- try {
513
- // TODO: Smart commit
514
- return { success: true };
515
- }
516
446
  catch (error) {
517
- return {
518
- success: false,
519
- error: error instanceof Error ? error.message : String(error)
520
- };
447
+ return WorkflowErrorHandler.handleError(error, 'diff');
521
448
  }
522
449
  },
523
- async pushChanges(projectPath) {
450
+ async handleLog(params) {
451
+ const { projectPath, limit, oneline } = params;
452
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
524
453
  try {
525
- // TODO: Push changes
526
- return { success: true };
527
- }
528
- catch (error) {
454
+ const logOptions = { maxCount: limit };
455
+ if (oneline)
456
+ logOptions.oneline = true;
457
+ const logResult = await gitOps.log(logOptions);
458
+ if (!logResult.success) {
459
+ throw new Error(`Log retrieval failed: ${logResult.error}`);
460
+ }
529
461
  return {
530
- success: false,
531
- error: error instanceof Error ? error.message : String(error)
462
+ success: true,
463
+ action: 'log',
464
+ message: 'Log retrieved successfully',
465
+ data: { log: logResult.output, limit, oneline }
532
466
  };
533
467
  }
534
- },
535
- async createFeatureBranch(projectPath, featureName, baseBranch) {
536
- try {
537
- // TODO: Create feature branch
538
- return { success: true };
539
- }
540
468
  catch (error) {
541
- return {
542
- success: false,
543
- error: error instanceof Error ? error.message : String(error)
544
- };
469
+ return WorkflowErrorHandler.handleError(error, 'log');
545
470
  }
546
471
  },
547
- async mergeFeature(projectPath, featureName, baseBranch) {
472
+ async handleCreateRepo(params) {
473
+ const { name, description, private: isPrivate, provider } = params;
548
474
  try {
549
- // TODO: Merge feature
550
- return { success: true };
551
- }
552
- catch (error) {
475
+ const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)({ provider }, provider);
476
+ const providerInstance = index_js_1.globalProviderFactory.getProvider(provider);
477
+ if (!providerInstance) {
478
+ throw new Error(`Provider ${provider} not configured`);
479
+ }
480
+ const repo = await providerInstance.createRepository(name, description || `Repository created via MCP`, isPrivate);
553
481
  return {
554
- success: false,
555
- error: error instanceof Error ? error.message : String(error)
482
+ success: true,
483
+ action: 'create-repo',
484
+ message: 'Repository created successfully',
485
+ data: {
486
+ name,
487
+ url: repo.html_url,
488
+ clone_url: repo.clone_url,
489
+ private: repo.private
490
+ }
556
491
  };
557
492
  }
558
- },
559
- async createPullRequest(projectPath, featureName) {
560
- try {
561
- // TODO: Create pull request
562
- return { success: true };
563
- }
564
493
  catch (error) {
565
- return {
566
- success: false,
567
- error: error instanceof Error ? error.message : String(error)
568
- };
494
+ return WorkflowErrorHandler.handleError(error, 'create-repo');
569
495
  }
570
496
  },
571
- async updateChangelog(projectPath, version) {
497
+ async handleCloneRepo(params) {
498
+ const { name, provider, projectPath, branch } = params;
572
499
  try {
573
- // TODO: Update changelog
574
- return { success: true };
575
- }
576
- catch (error) {
500
+ const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)({ provider }, provider);
501
+ const providerInstance = index_js_1.globalProviderFactory.getProvider(provider);
502
+ if (!providerInstance) {
503
+ throw new Error(`Provider ${provider} not configured`);
504
+ }
505
+ const repo = await providerInstance.getRepository(processedInput.owner, name);
506
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
507
+ // Clone repository
508
+ const cloneResult = await gitOps.cloneRepository(repo.clone_url, undefined, { branch });
509
+ if (!cloneResult.success) {
510
+ throw new Error(`Clone failed: ${cloneResult.error}`);
511
+ }
577
512
  return {
578
- success: false,
579
- error: error instanceof Error ? error.message : String(error)
513
+ success: true,
514
+ action: 'clone-repo',
515
+ message: 'Repository cloned successfully',
516
+ data: {
517
+ path: projectPath,
518
+ url: repo.clone_url,
519
+ branch,
520
+ name: repo.name
521
+ }
580
522
  };
581
523
  }
582
- },
583
- async createReleaseTag(projectPath, version) {
584
- try {
585
- // TODO: Create release tag
586
- return { success: true };
587
- }
588
524
  catch (error) {
589
- return {
590
- success: false,
591
- error: error instanceof Error ? error.message : String(error)
592
- };
525
+ return WorkflowErrorHandler.handleError(error, 'clone-repo');
593
526
  }
594
527
  },
595
- async createRelease(projectPath, version, platforms) {
528
+ async handlePull(params) {
529
+ const { projectPath, branch } = params;
530
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
596
531
  try {
597
- // TODO: Create release
598
- return { success: true };
599
- }
600
- catch (error) {
532
+ const pullResult = await gitOps.pull('origin', branch);
533
+ if (!pullResult.success && !pullResult.error?.includes('up-to-date')) {
534
+ throw new Error(`Pull failed: ${pullResult.error}`);
535
+ }
601
536
  return {
602
- success: false,
603
- error: error instanceof Error ? error.message : String(error)
537
+ success: true,
538
+ action: 'pull',
539
+ message: pullResult.error?.includes('up-to-date') ? 'Already up-to-date' : 'Pull completed successfully',
540
+ data: { branch, upToDate: pullResult.error?.includes('up-to-date') || false }
604
541
  };
605
542
  }
606
- },
607
- async removeMergedBranches(projectPath) {
608
- try {
609
- // TODO: Remove merged branches
610
- return { success: true };
611
- }
612
543
  catch (error) {
613
- return {
614
- success: false,
615
- error: error instanceof Error ? error.message : String(error)
616
- };
544
+ return WorkflowErrorHandler.handleError(error, 'pull');
617
545
  }
618
546
  },
619
- async removeOldBackups(projectPath, daysOld) {
547
+ async handlePush(params) {
548
+ const { projectPath, branch, force } = params;
549
+ const gitOps = new git_operations_js_1.GitOperations(projectPath);
620
550
  try {
621
- // TODO: Remove old backup stashes
622
- return { success: true };
623
- }
624
- catch (error) {
551
+ const pushOptions = {};
552
+ if (force)
553
+ pushOptions.force = true;
554
+ const pushResult = await gitOps.push('origin', branch, pushOptions);
555
+ if (!pushResult.success) {
556
+ throw new Error(`Push failed: ${pushResult.error}`);
557
+ }
625
558
  return {
626
- success: false,
627
- error: error instanceof Error ? error.message : String(error)
559
+ success: true,
560
+ action: 'push',
561
+ message: 'Push completed successfully',
562
+ data: { branch, force }
628
563
  };
629
564
  }
630
- },
631
- async optimizeRepository(projectPath) {
632
- try {
633
- // TODO: Optimize repository
634
- return { success: true };
635
- }
636
565
  catch (error) {
637
- return {
638
- success: false,
639
- error: error instanceof Error ? error.message : String(error)
640
- };
566
+ return WorkflowErrorHandler.handleError(error, 'push');
641
567
  }
642
568
  }
643
569
  };