@andre.buzeli/git-mcp 16.0.6 → 16.1.2
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/package.json +32 -29
- package/src/index.js +159 -147
- package/src/providers/providerManager.js +31 -104
- package/src/tools/git-branches.js +13 -3
- package/src/tools/git-clone.js +48 -85
- package/src/tools/git-config.js +13 -3
- package/src/tools/git-diff.js +121 -137
- package/src/tools/git-files.js +13 -3
- package/src/tools/git-help.js +322 -284
- package/src/tools/git-history.js +13 -3
- package/src/tools/git-ignore.js +13 -3
- package/src/tools/git-issues.js +13 -3
- package/src/tools/git-merge.js +13 -3
- package/src/tools/git-pulls.js +14 -4
- package/src/tools/git-remote.js +503 -492
- package/src/tools/git-reset.js +23 -4
- package/src/tools/git-stash.js +13 -3
- package/src/tools/git-sync.js +13 -3
- package/src/tools/git-tags.js +13 -3
- package/src/tools/git-workflow.js +599 -469
- package/src/tools/git-worktree.js +180 -0
- package/src/utils/errors.js +434 -433
- package/src/utils/gitAdapter.js +133 -11
- package/src/utils/mcpNotify.js +45 -0
- package/src/utils/repoHelpers.js +5 -31
- package/src/utils/hooks.js +0 -255
- package/src/utils/metrics.js +0 -198
package/src/utils/metrics.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// Sistema de Métricas/Telemetria para git-mcp
|
|
2
|
-
// Opt-in via variável de ambiente ENABLE_METRICS=true
|
|
3
|
-
|
|
4
|
-
const metricsEnabled = process.env.ENABLE_METRICS === "true";
|
|
5
|
-
|
|
6
|
-
// Armazena métricas em memória
|
|
7
|
-
const metricsStore = {
|
|
8
|
-
operations: [],
|
|
9
|
-
errors: [],
|
|
10
|
-
startTime: Date.now(),
|
|
11
|
-
summary: {
|
|
12
|
-
totalOperations: 0,
|
|
13
|
-
successfulOperations: 0,
|
|
14
|
-
failedOperations: 0,
|
|
15
|
-
totalDurationMs: 0,
|
|
16
|
-
operationsByType: {}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Registra início de uma operação
|
|
22
|
-
* @param {string} operation - Nome da operação (ex: "git-workflow:push")
|
|
23
|
-
* @param {Object} metadata - Metadados adicionais
|
|
24
|
-
* @returns {string} - ID da operação para tracking
|
|
25
|
-
*/
|
|
26
|
-
export function startOperation(operation, metadata = {}) {
|
|
27
|
-
if (!metricsEnabled) return null;
|
|
28
|
-
|
|
29
|
-
const id = `${operation}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
30
|
-
|
|
31
|
-
metricsStore.operations.push({
|
|
32
|
-
id,
|
|
33
|
-
operation,
|
|
34
|
-
startTime: Date.now(),
|
|
35
|
-
endTime: null,
|
|
36
|
-
duration: null,
|
|
37
|
-
status: "running",
|
|
38
|
-
metadata,
|
|
39
|
-
error: null
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return id;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Finaliza uma operação
|
|
47
|
-
* @param {string} id - ID da operação
|
|
48
|
-
* @param {string} status - "success" ou "error"
|
|
49
|
-
* @param {Error|null} error - Erro se houver
|
|
50
|
-
*/
|
|
51
|
-
export function endOperation(id, status = "success", error = null) {
|
|
52
|
-
if (!metricsEnabled || !id) return;
|
|
53
|
-
|
|
54
|
-
const op = metricsStore.operations.find(o => o.id === id);
|
|
55
|
-
if (!op) return;
|
|
56
|
-
|
|
57
|
-
op.endTime = Date.now();
|
|
58
|
-
op.duration = op.endTime - op.startTime;
|
|
59
|
-
op.status = status;
|
|
60
|
-
|
|
61
|
-
if (error) {
|
|
62
|
-
op.error = {
|
|
63
|
-
message: error.message || String(error),
|
|
64
|
-
code: error.code || "UNKNOWN"
|
|
65
|
-
};
|
|
66
|
-
metricsStore.errors.push({
|
|
67
|
-
timestamp: Date.now(),
|
|
68
|
-
operation: op.operation,
|
|
69
|
-
error: op.error
|
|
70
|
-
});
|
|
71
|
-
metricsStore.summary.failedOperations++;
|
|
72
|
-
} else {
|
|
73
|
-
metricsStore.summary.successfulOperations++;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
metricsStore.summary.totalOperations++;
|
|
77
|
-
metricsStore.summary.totalDurationMs += op.duration;
|
|
78
|
-
|
|
79
|
-
// Atualiza contagem por tipo
|
|
80
|
-
const opType = op.operation.split(":")[0];
|
|
81
|
-
metricsStore.summary.operationsByType[opType] =
|
|
82
|
-
(metricsStore.summary.operationsByType[opType] || 0) + 1;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Wrapper para medir tempo de execução de uma função
|
|
87
|
-
* @param {string} operation - Nome da operação
|
|
88
|
-
* @param {Function} fn - Função async para executar
|
|
89
|
-
* @param {Object} metadata - Metadados adicionais
|
|
90
|
-
*/
|
|
91
|
-
export async function withMetrics(operation, fn, metadata = {}) {
|
|
92
|
-
const id = startOperation(operation, metadata);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const result = await fn();
|
|
96
|
-
endOperation(id, "success");
|
|
97
|
-
return result;
|
|
98
|
-
} catch (error) {
|
|
99
|
-
endOperation(id, "error", error);
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Retorna resumo das métricas
|
|
106
|
-
*/
|
|
107
|
-
export function getMetricsSummary() {
|
|
108
|
-
if (!metricsEnabled) {
|
|
109
|
-
return { enabled: false, message: "Métricas desabilitadas. Use ENABLE_METRICS=true para habilitar." };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const uptimeMs = Date.now() - metricsStore.startTime;
|
|
113
|
-
const avgDuration = metricsStore.summary.totalOperations > 0
|
|
114
|
-
? metricsStore.summary.totalDurationMs / metricsStore.summary.totalOperations
|
|
115
|
-
: 0;
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
enabled: true,
|
|
119
|
-
uptime: {
|
|
120
|
-
ms: uptimeMs,
|
|
121
|
-
formatted: formatDuration(uptimeMs)
|
|
122
|
-
},
|
|
123
|
-
operations: {
|
|
124
|
-
total: metricsStore.summary.totalOperations,
|
|
125
|
-
successful: metricsStore.summary.successfulOperations,
|
|
126
|
-
failed: metricsStore.summary.failedOperations,
|
|
127
|
-
successRate: metricsStore.summary.totalOperations > 0
|
|
128
|
-
? ((metricsStore.summary.successfulOperations / metricsStore.summary.totalOperations) * 100).toFixed(2) + "%"
|
|
129
|
-
: "N/A"
|
|
130
|
-
},
|
|
131
|
-
performance: {
|
|
132
|
-
totalDurationMs: metricsStore.summary.totalDurationMs,
|
|
133
|
-
avgDurationMs: avgDuration.toFixed(2),
|
|
134
|
-
operationsPerMinute: uptimeMs > 0
|
|
135
|
-
? ((metricsStore.summary.totalOperations / uptimeMs) * 60000).toFixed(2)
|
|
136
|
-
: 0
|
|
137
|
-
},
|
|
138
|
-
byType: metricsStore.summary.operationsByType,
|
|
139
|
-
recentErrors: metricsStore.errors.slice(-10)
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Retorna operações recentes
|
|
145
|
-
* @param {number} limit - Número máximo de operações
|
|
146
|
-
*/
|
|
147
|
-
export function getRecentOperations(limit = 20) {
|
|
148
|
-
if (!metricsEnabled) return [];
|
|
149
|
-
return metricsStore.operations.slice(-limit);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Limpa métricas antigas
|
|
154
|
-
* @param {number} maxAgeMs - Idade máxima em ms (default: 1 hora)
|
|
155
|
-
*/
|
|
156
|
-
export function pruneMetrics(maxAgeMs = 3600000) {
|
|
157
|
-
if (!metricsEnabled) return;
|
|
158
|
-
|
|
159
|
-
const cutoff = Date.now() - maxAgeMs;
|
|
160
|
-
metricsStore.operations = metricsStore.operations.filter(o => o.startTime > cutoff);
|
|
161
|
-
metricsStore.errors = metricsStore.errors.filter(e => e.timestamp > cutoff);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Reseta todas as métricas
|
|
166
|
-
*/
|
|
167
|
-
export function resetMetrics() {
|
|
168
|
-
metricsStore.operations = [];
|
|
169
|
-
metricsStore.errors = [];
|
|
170
|
-
metricsStore.startTime = Date.now();
|
|
171
|
-
metricsStore.summary = {
|
|
172
|
-
totalOperations: 0,
|
|
173
|
-
successfulOperations: 0,
|
|
174
|
-
failedOperations: 0,
|
|
175
|
-
totalDurationMs: 0,
|
|
176
|
-
operationsByType: {}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Formata duração em formato legível
|
|
182
|
-
*/
|
|
183
|
-
function formatDuration(ms) {
|
|
184
|
-
const seconds = Math.floor(ms / 1000);
|
|
185
|
-
const minutes = Math.floor(seconds / 60);
|
|
186
|
-
const hours = Math.floor(minutes / 60);
|
|
187
|
-
|
|
188
|
-
if (hours > 0) return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
|
|
189
|
-
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
|
190
|
-
return `${seconds}s`;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Verifica se métricas estão habilitadas
|
|
195
|
-
*/
|
|
196
|
-
export function isMetricsEnabled() {
|
|
197
|
-
return metricsEnabled;
|
|
198
|
-
}
|