@andrebuzeli/git-mcp 15.8.3 → 15.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -125
- package/package.json +27 -44
- package/src/index.js +146 -139
- package/src/providers/providerManager.js +203 -203
- package/src/tools/git-diff.js +137 -126
- package/src/tools/git-help.js +285 -285
- package/src/tools/git-remote.js +472 -472
- package/src/tools/git-workflow.js +403 -403
- package/src/utils/env.js +104 -104
- package/src/utils/errors.js +431 -431
- package/src/utils/gitAdapter.js +932 -932
- package/src/utils/hooks.js +255 -255
- package/src/utils/metrics.js +198 -198
- package/src/utils/providerExec.js +58 -58
- package/src/utils/repoHelpers.js +160 -160
- package/src/utils/retry.js +123 -123
- package/install.sh +0 -68
package/src/tools/git-diff.js
CHANGED
|
@@ -1,126 +1,137 @@
|
|
|
1
|
-
import Ajv from "ajv";
|
|
2
|
-
import { asToolError, asToolResult, errorToResponse } from "../utils/errors.js";
|
|
3
|
-
import { validateProjectPath } from "../utils/repoHelpers.js";
|
|
4
|
-
|
|
5
|
-
const ajv = new Ajv({ allErrors: true });
|
|
6
|
-
|
|
7
|
-
export function createGitDiffTool(git) {
|
|
8
|
-
const inputSchema = {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {
|
|
11
|
-
projectPath: {
|
|
12
|
-
type: "string",
|
|
13
|
-
description: "Caminho absoluto do diretório do projeto"
|
|
14
|
-
},
|
|
15
|
-
action: {
|
|
16
|
-
type: "string",
|
|
17
|
-
enum: ["show", "compare", "stat"],
|
|
18
|
-
description: `Ação a executar:
|
|
19
|
-
- show: Mostra diff do working directory (arquivos não commitados)
|
|
20
|
-
- compare: Compara dois commits/branches/tags
|
|
21
|
-
- stat: Mostra estatísticas (arquivos alterados, linhas +/-)`
|
|
22
|
-
},
|
|
23
|
-
from: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Ref inicial para comparação (commit SHA, branch, tag). Default: HEAD"
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
type: "string",
|
|
33
|
-
description: "
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
type: "
|
|
37
|
-
description: "
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
message:
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import { asToolError, asToolResult, errorToResponse } from "../utils/errors.js";
|
|
3
|
+
import { validateProjectPath } from "../utils/repoHelpers.js";
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
|
|
7
|
+
export function createGitDiffTool(git) {
|
|
8
|
+
const inputSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
projectPath: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Caminho absoluto do diretório do projeto"
|
|
14
|
+
},
|
|
15
|
+
action: {
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: ["show", "compare", "stat"],
|
|
18
|
+
description: `Ação a executar:
|
|
19
|
+
- show: Mostra diff do working directory (arquivos não commitados)
|
|
20
|
+
- compare: Compara dois commits/branches/tags
|
|
21
|
+
- stat: Mostra estatísticas (arquivos alterados, linhas +/-)`
|
|
22
|
+
},
|
|
23
|
+
from: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Ref inicial para comparação (commit SHA, branch, tag). Default: HEAD"
|
|
26
|
+
},
|
|
27
|
+
fromRef: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Alias para 'from'. Ref inicial para comparação"
|
|
30
|
+
},
|
|
31
|
+
to: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Ref final para comparação. Se não fornecido, compara com working directory"
|
|
34
|
+
},
|
|
35
|
+
toRef: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Alias para 'to'. Ref final para comparação"
|
|
38
|
+
},
|
|
39
|
+
file: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Arquivo específico para ver diff. Se não fornecido, mostra todos"
|
|
42
|
+
},
|
|
43
|
+
filepath: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "Alias para 'file'. Arquivo específico para ver diff"
|
|
46
|
+
},
|
|
47
|
+
context: {
|
|
48
|
+
type: "number",
|
|
49
|
+
description: "Número de linhas de contexto ao redor das mudanças. Default: 3"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
required: ["projectPath", "action"],
|
|
53
|
+
additionalProperties: false
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const description = `Ver diferenças entre commits, branches ou arquivos.
|
|
57
|
+
|
|
58
|
+
QUANDO USAR:
|
|
59
|
+
- Ver o que mudou antes de commitar (action='show')
|
|
60
|
+
- Comparar branches antes de merge (action='compare')
|
|
61
|
+
- Ver estatísticas de mudanças (action='stat')
|
|
62
|
+
|
|
63
|
+
EXEMPLOS:
|
|
64
|
+
- Ver mudanças não commitadas: action='show'
|
|
65
|
+
- Ver mudanças de um arquivo: action='show' file='src/index.js'
|
|
66
|
+
- Comparar com último commit: action='compare' from='HEAD~1'
|
|
67
|
+
- Comparar branches: action='compare' from='main' to='feature/x'
|
|
68
|
+
- Ver stats: action='stat' from='main' to='develop'`;
|
|
69
|
+
|
|
70
|
+
async function handle(args) {
|
|
71
|
+
const validate = ajv.compile(inputSchema);
|
|
72
|
+
if (!validate(args || {})) return asToolError("VALIDATION_ERROR", "Parâmetros inválidos", validate.errors);
|
|
73
|
+
const { projectPath, action } = args;
|
|
74
|
+
|
|
75
|
+
// Support aliases: fromRef -> from, toRef -> to, filepath -> file
|
|
76
|
+
const fromParam = args.from || args.fromRef || "HEAD";
|
|
77
|
+
const toParam = args.to || args.toRef;
|
|
78
|
+
const fileParam = args.file || args.filepath;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
validateProjectPath(projectPath);
|
|
82
|
+
if (action === "show") {
|
|
83
|
+
const diff = await git.diff(projectPath, {
|
|
84
|
+
file: fileParam,
|
|
85
|
+
context: args.context || 3
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (!diff || diff.length === 0) {
|
|
89
|
+
return asToolResult({
|
|
90
|
+
changes: [],
|
|
91
|
+
message: "Nenhuma mudança detectada no working directory"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return asToolResult({
|
|
96
|
+
changes: diff,
|
|
97
|
+
totalFiles: diff.length,
|
|
98
|
+
message: `${diff.length} arquivo(s) com mudanças`
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (action === "compare") {
|
|
103
|
+
const diff = await git.diffCommits(projectPath, fromParam, toParam, {
|
|
104
|
+
file: fileParam,
|
|
105
|
+
context: args.context || 3
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return asToolResult({
|
|
109
|
+
from: fromParam,
|
|
110
|
+
to: toParam || "working directory",
|
|
111
|
+
changes: diff,
|
|
112
|
+
totalFiles: diff.length,
|
|
113
|
+
message: `Comparando ${fromParam} com ${toParam || 'working directory'}: ${diff.length} arquivo(s)`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (action === "stat") {
|
|
118
|
+
const stats = await git.diffStats(projectPath, fromParam, toParam);
|
|
119
|
+
|
|
120
|
+
return asToolResult({
|
|
121
|
+
from: fromParam,
|
|
122
|
+
to: toParam || "working directory",
|
|
123
|
+
...stats,
|
|
124
|
+
message: `${stats.filesChanged} arquivo(s), +${stats.insertions} -${stats.deletions}`
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return asToolError("VALIDATION_ERROR", `Ação '${action}' não suportada`, {
|
|
129
|
+
availableActions: ["show", "compare", "stat"]
|
|
130
|
+
});
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return errorToResponse(e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return { name: "git-diff", description, inputSchema, handle };
|
|
137
|
+
}
|