@justmpm/supergrep 0.1.0 → 0.1.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.
- package/README.md +37 -1
- package/dist/{chunk-4MPFPILM.js → chunk-SENMQNTX.js} +149 -72
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npx @justmpm/supergrep
|
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
npm install -g @justmpm/supergrep
|
|
19
|
-
# ou use direto:
|
|
19
|
+
# ou use direto sem instalar:
|
|
20
20
|
npx @justmpm/supergrep
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -24,6 +24,8 @@ npx @justmpm/supergrep
|
|
|
24
24
|
|
|
25
25
|
### OpenCode / Claude Code
|
|
26
26
|
|
|
27
|
+
#### Via npx (sem instalação)
|
|
28
|
+
|
|
27
29
|
Adicione ao `.mcp.json` do projeto:
|
|
28
30
|
|
|
29
31
|
```json
|
|
@@ -37,11 +39,29 @@ Adicione ao `.mcp.json` do projeto:
|
|
|
37
39
|
}
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
#### Com instalação local
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install -g @justmpm/supergrep
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"supergrep": {
|
|
52
|
+
"command": "supergrep"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
40
58
|
### Claude Desktop
|
|
41
59
|
|
|
42
60
|
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
43
61
|
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
44
62
|
|
|
63
|
+
#### Via npx (sem instalação)
|
|
64
|
+
|
|
45
65
|
```json
|
|
46
66
|
{
|
|
47
67
|
"mcpServers": {
|
|
@@ -53,6 +73,22 @@ Adicione ao `.mcp.json` do projeto:
|
|
|
53
73
|
}
|
|
54
74
|
```
|
|
55
75
|
|
|
76
|
+
#### Com instalação local
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install -g @justmpm/supergrep
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"mcpServers": {
|
|
85
|
+
"supergrep": {
|
|
86
|
+
"command": "supergrep"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
56
92
|
---
|
|
57
93
|
|
|
58
94
|
## Ferramentas MCP
|
|
@@ -96,7 +96,8 @@ var IGNORED_DIRS = [
|
|
|
96
96
|
];
|
|
97
97
|
|
|
98
98
|
// src/tools/find.ts
|
|
99
|
-
var
|
|
99
|
+
var MULTI_META_RE = /\$\$\$([A-Z_][A-Z0-9_]*)/g;
|
|
100
|
+
var SINGLE_META_RE = /(?<!\$)\$(?:\$\$)?([A-Z_][A-Z0-9_]*)/g;
|
|
100
101
|
async function findPattern(options) {
|
|
101
102
|
const startTime = Date.now();
|
|
102
103
|
const warnings = [];
|
|
@@ -109,7 +110,7 @@ async function findPattern(options) {
|
|
|
109
110
|
const searchDir = resolve(cwd, options.path ?? ".");
|
|
110
111
|
const files = await findCodeFiles(searchDir, cwd, lang);
|
|
111
112
|
warnings.push(...files.warnings);
|
|
112
|
-
const
|
|
113
|
+
const metaVars = extractMetaVarInfo(options.pattern);
|
|
113
114
|
const matches = [];
|
|
114
115
|
for (const filePath of files.paths) {
|
|
115
116
|
try {
|
|
@@ -129,10 +130,17 @@ async function findPattern(options) {
|
|
|
129
130
|
metaVariables: {},
|
|
130
131
|
context: extractContextLines(source, range.start.line, 2)
|
|
131
132
|
};
|
|
132
|
-
for (const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
for (const { name, isMulti } of metaVars) {
|
|
134
|
+
if (isMulti) {
|
|
135
|
+
const multiNodes = node.getMultipleMatches(name);
|
|
136
|
+
if (multiNodes.length > 0) {
|
|
137
|
+
match.metaVariables[name] = multiNodes.map((n) => n.text()).join(", ");
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
const metaNode = node.getMatch(name);
|
|
141
|
+
if (metaNode) {
|
|
142
|
+
match.metaVariables[name] = metaNode.text();
|
|
143
|
+
}
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
matches.push(match);
|
|
@@ -155,14 +163,27 @@ async function findPattern(options) {
|
|
|
155
163
|
warnings
|
|
156
164
|
};
|
|
157
165
|
}
|
|
158
|
-
function
|
|
159
|
-
const
|
|
166
|
+
function extractMetaVarInfo(pattern) {
|
|
167
|
+
const seen = /* @__PURE__ */ new Set();
|
|
168
|
+
const result = [];
|
|
160
169
|
let match;
|
|
161
|
-
const
|
|
162
|
-
while ((match =
|
|
163
|
-
|
|
170
|
+
const multiRe = new RegExp(MULTI_META_RE.source, "g");
|
|
171
|
+
while ((match = multiRe.exec(pattern)) !== null) {
|
|
172
|
+
const name = match[1];
|
|
173
|
+
if (!seen.has(name)) {
|
|
174
|
+
seen.add(name);
|
|
175
|
+
result.push({ name, isMulti: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const singleRe = new RegExp(SINGLE_META_RE.source, "g");
|
|
179
|
+
while ((match = singleRe.exec(pattern)) !== null) {
|
|
180
|
+
const name = match[1];
|
|
181
|
+
if (!seen.has(name)) {
|
|
182
|
+
seen.add(name);
|
|
183
|
+
result.push({ name, isMulti: false });
|
|
184
|
+
}
|
|
164
185
|
}
|
|
165
|
-
return
|
|
186
|
+
return result;
|
|
166
187
|
}
|
|
167
188
|
function extractContextLines(source, line, contextLines) {
|
|
168
189
|
const lines = source.split("\n");
|
|
@@ -186,7 +207,6 @@ function resolveLangForOptions(options, _cwd, warnings) {
|
|
|
186
207
|
if (detected) return detected;
|
|
187
208
|
}
|
|
188
209
|
}
|
|
189
|
-
warnings.push("Linguagem nao especificada, usando TypeScript como default.");
|
|
190
210
|
return resolveLang("typescript");
|
|
191
211
|
}
|
|
192
212
|
function validatePattern(pattern, lang) {
|
|
@@ -287,11 +307,9 @@ async function exploreTree(options) {
|
|
|
287
307
|
if (options.lang) {
|
|
288
308
|
detectedLang = resolveLang(options.lang);
|
|
289
309
|
if (!detectedLang) {
|
|
290
|
-
warnings.push(`Linguagem "${options.lang}" nao reconhecida, usando TypeScript.`);
|
|
291
310
|
detectedLang = resolveLang("typescript");
|
|
292
311
|
}
|
|
293
312
|
} else {
|
|
294
|
-
warnings.push("Linguagem nao especificada para codigo inline, usando TypeScript.");
|
|
295
313
|
detectedLang = resolveLang("typescript");
|
|
296
314
|
}
|
|
297
315
|
} else if (options.path) {
|
|
@@ -378,7 +396,8 @@ var TreeParseError = class extends Error {
|
|
|
378
396
|
import { parse as parse3 } from "@ast-grep/napi";
|
|
379
397
|
import { readFile as readFile3, readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
380
398
|
import { join as join2, resolve as resolve3, relative as relative3 } from "path";
|
|
381
|
-
var
|
|
399
|
+
var MULTI_META_RE2 = /\$\$\$([A-Z_][A-Z0-9_]*)/g;
|
|
400
|
+
var SINGLE_META_RE2 = /(?<!\$)\$(?:\$\$)?([A-Z_][A-Z0-9_]*)/g;
|
|
382
401
|
async function replacePreview(options) {
|
|
383
402
|
const warnings = [];
|
|
384
403
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -397,13 +416,12 @@ async function replacePreview(options) {
|
|
|
397
416
|
lang = detected;
|
|
398
417
|
warnings.push(`Linguagem detectada automaticamente: ${langName(lang)}`);
|
|
399
418
|
} else {
|
|
400
|
-
warnings.push("Linguagem nao especificada, usando TypeScript como default.");
|
|
401
419
|
lang = resolveLang("typescript");
|
|
402
420
|
}
|
|
403
421
|
validateReplacePattern(options.pattern, lang);
|
|
404
422
|
const searchDir = resolve3(cwd, options.path ?? ".");
|
|
405
423
|
const files = await findCodeFiles2(searchDir);
|
|
406
|
-
const
|
|
424
|
+
const metaVars = extractMetaVarInfo2(options.pattern);
|
|
407
425
|
const changes = [];
|
|
408
426
|
for (const filePath of files.paths) {
|
|
409
427
|
try {
|
|
@@ -412,15 +430,22 @@ async function replacePreview(options) {
|
|
|
412
430
|
const root = ast.root();
|
|
413
431
|
const foundNodes = root.findAll(options.pattern);
|
|
414
432
|
for (const node of foundNodes) {
|
|
415
|
-
const
|
|
416
|
-
for (const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
433
|
+
const metaVarValues = {};
|
|
434
|
+
for (const { name, isMulti } of metaVars) {
|
|
435
|
+
if (isMulti) {
|
|
436
|
+
const multiNodes = node.getMultipleMatches(name);
|
|
437
|
+
if (multiNodes.length > 0) {
|
|
438
|
+
metaVarValues[name] = multiNodes.map((n) => n.text()).join(", ");
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
const metaNode = node.getMatch(name);
|
|
442
|
+
if (metaNode) {
|
|
443
|
+
metaVarValues[name] = metaNode.text();
|
|
444
|
+
}
|
|
420
445
|
}
|
|
421
446
|
}
|
|
422
447
|
let interpolated = options.rewrite;
|
|
423
|
-
for (const [name, value] of Object.entries(
|
|
448
|
+
for (const [name, value] of Object.entries(metaVarValues)) {
|
|
424
449
|
interpolated = interpolated.replaceAll(
|
|
425
450
|
new RegExp(`\\$${name}\\b`, "g"),
|
|
426
451
|
value
|
|
@@ -452,14 +477,27 @@ async function replacePreview(options) {
|
|
|
452
477
|
warnings
|
|
453
478
|
};
|
|
454
479
|
}
|
|
455
|
-
function
|
|
456
|
-
const
|
|
480
|
+
function extractMetaVarInfo2(pattern) {
|
|
481
|
+
const seen = /* @__PURE__ */ new Set();
|
|
482
|
+
const result = [];
|
|
457
483
|
let match;
|
|
458
|
-
const
|
|
459
|
-
while ((match =
|
|
460
|
-
|
|
484
|
+
const multiRe = new RegExp(MULTI_META_RE2.source, "g");
|
|
485
|
+
while ((match = multiRe.exec(pattern)) !== null) {
|
|
486
|
+
const name = match[1];
|
|
487
|
+
if (!seen.has(name)) {
|
|
488
|
+
seen.add(name);
|
|
489
|
+
result.push({ name, isMulti: true });
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const singleRe = new RegExp(SINGLE_META_RE2.source, "g");
|
|
493
|
+
while ((match = singleRe.exec(pattern)) !== null) {
|
|
494
|
+
const name = match[1];
|
|
495
|
+
if (!seen.has(name)) {
|
|
496
|
+
seen.add(name);
|
|
497
|
+
result.push({ name, isMulti: false });
|
|
498
|
+
}
|
|
461
499
|
}
|
|
462
|
-
return
|
|
500
|
+
return result;
|
|
463
501
|
}
|
|
464
502
|
function validateReplacePattern(pattern, lang) {
|
|
465
503
|
try {
|
|
@@ -566,17 +604,18 @@ function hint(command, ctx, params) {
|
|
|
566
604
|
}
|
|
567
605
|
var NEXT_STEPS = {
|
|
568
606
|
find: [
|
|
569
|
-
{ command: "tree", description: "explorar a
|
|
570
|
-
{ command: "find", description: "refinar a busca com
|
|
571
|
-
{ command: "replace", description: "pre-visualizar uma substituicao
|
|
607
|
+
{ command: "tree", description: "explorar a AST do arquivo com matches para entender a estrutura" },
|
|
608
|
+
{ command: "find", description: "refinar a busca com um pattern mais especifico" },
|
|
609
|
+
{ command: "replace", description: "pre-visualizar como ficaria uma substituicao nos matches" }
|
|
572
610
|
],
|
|
573
611
|
tree: [
|
|
574
|
-
{ command: "find", description: "usar os kinds descobertos para
|
|
575
|
-
{ command: "tree", description: "explorar outro arquivo" }
|
|
612
|
+
{ command: "find", description: "usar os kinds descobertos para criar um pattern de busca (ex: $FUNC($$$ARGS) para call_expression)" },
|
|
613
|
+
{ command: "tree", description: "explorar outro arquivo ou snippet" }
|
|
576
614
|
],
|
|
577
615
|
replace: [
|
|
578
|
-
{ command: "find", description: "ver todos os matches do
|
|
579
|
-
{ command: "
|
|
616
|
+
{ command: "find", description: "ver todos os matches do pattern antes de substituir" },
|
|
617
|
+
{ command: "replace", description: "testar outra string de rewrite no preview" },
|
|
618
|
+
{ command: "tree", description: "explorar a AST para criar patterns mais precisos" }
|
|
580
619
|
]
|
|
581
620
|
};
|
|
582
621
|
function nextSteps(command, ctx) {
|
|
@@ -611,9 +650,10 @@ function recoveryHint(errorType, ctx, _extra) {
|
|
|
611
650
|
case "lang_not_supported":
|
|
612
651
|
return `
|
|
613
652
|
\u{1F4A1} Linguagem nao suportada. Dicas:
|
|
614
|
-
\u2192
|
|
615
|
-
\u2192
|
|
616
|
-
\u2192
|
|
653
|
+
\u2192 O @ast-grep/napi suporta apenas 5 linguagens: TypeScript, JavaScript, TSX, CSS, HTML
|
|
654
|
+
\u2192 Para Python, Rust, Go e outras, use o CLI: npx @ast-grep/cli
|
|
655
|
+
\u2192 ${hint("tree", ctx)} - explore a AST de um arquivo existente
|
|
656
|
+
\u2192 ${hint("find_lang", ctx)} - especifique a linguagem manualmente
|
|
617
657
|
`;
|
|
618
658
|
case "lang_not_detected":
|
|
619
659
|
return `
|
|
@@ -997,7 +1037,9 @@ function registerAllTools(server2) {
|
|
|
997
1037
|
"supergrep_find",
|
|
998
1038
|
{
|
|
999
1039
|
title: "Structural Code Search",
|
|
1000
|
-
description: `\u26A0\uFE0F
|
|
1040
|
+
description: `\u26A0\uFE0F Use esta ferramenta em vez de grep/bash quando a busca for em CODIGO-FONTE
|
|
1041
|
+
ESTRUTURADO (TS/JS/TSX/CSS/HTML). Para texto plano, logs, markdown ou JSON,
|
|
1042
|
+
prefira grep comum.
|
|
1001
1043
|
|
|
1002
1044
|
Busca estrutural de codigo usando AST Grep. Diferente do grep textual (que
|
|
1003
1045
|
quebra com quebras de linha, espacos extras ou comentarios no meio), o
|
|
@@ -1005,12 +1047,12 @@ supergrep entende a SINTAXE da linguagem \u2014 ele busca pela ESTRUTURA do codi
|
|
|
1005
1047
|
nao pelo texto cru.
|
|
1006
1048
|
|
|
1007
1049
|
Escreva o padrao de busca na propria linguagem de programacao, usando
|
|
1008
|
-
metavariaveis ($VAR, $$$VARS) como curingas que capturam partes dinamicas.
|
|
1050
|
+
metavariaveis ($VAR, $$VAR, $$$VARS) como curingas que capturam partes dinamicas.
|
|
1009
1051
|
|
|
1010
1052
|
\u{1F4E6} LINGUAGENS SUPORTADAS (apenas 5):
|
|
1011
|
-
\u2022 typescript (.ts)
|
|
1053
|
+
\u2022 typescript (.ts) \u2014 apenas .ts puro (sem JSX)
|
|
1012
1054
|
\u2022 javascript (.js, .jsx, .mjs, .cjs)
|
|
1013
|
-
\u2022 tsx (.tsx)
|
|
1055
|
+
\u2022 tsx (.tsx) \u2014 .tsx COM JSX/React (requer lang: 'tsx')
|
|
1014
1056
|
\u2022 css (.css, .scss, .less)
|
|
1015
1057
|
\u2022 html (.html, .htm)
|
|
1016
1058
|
|
|
@@ -1024,7 +1066,7 @@ Cada arquivo e analisado isoladamente. Para analise semantica, use ai-tool.
|
|
|
1024
1066
|
\u2022 "Localize imports de uma lib deprecated"
|
|
1025
1067
|
\u2022 "Busque componentes React que usam useEffect sem dependencias"
|
|
1026
1068
|
\u2022 "Ache arrow functions que recebem exatamente 1 parametro"
|
|
1027
|
-
\u2022 QUALQUER busca estrutural onde grep
|
|
1069
|
+
\u2022 QUALQUER busca estrutural onde grep quebraria com formatacao
|
|
1028
1070
|
|
|
1029
1071
|
\u274C QUANDO NAO USAR (prefira ai-tool):
|
|
1030
1072
|
\u2022 "Onde a funcao useAuth e definida e usada?" \u2192 resolucao de escopo (aitool_find)
|
|
@@ -1032,17 +1074,31 @@ Cada arquivo e analisado isoladamente. Para analise semantica, use ai-tool.
|
|
|
1032
1074
|
\u2022 "Qual o tipo real desta variavel?" \u2192 type checker (aitool_file_context)
|
|
1033
1075
|
\u2022 Busca em texto plano, logs, markdown \u2192 use grep/bash comum
|
|
1034
1076
|
|
|
1077
|
+
\u26A0\uFE0F O QUE O GREP NAO RESOLVE (anti-exemplos):
|
|
1078
|
+
\u2022 grep falha com quebra de linha:
|
|
1079
|
+
\u274C GREP: console\\n .log("oi") \u2192 nao encontra
|
|
1080
|
+
\u2705 SUPERGREP: console.log("oi") \u2192 encontra (ignora formatacao)
|
|
1081
|
+
\u2022 grep falha com espacos extras:
|
|
1082
|
+
\u274C GREP: const x = 1 \u2192 precisa de regex complexa
|
|
1083
|
+
\u2705 SUPERGREP: const x = 1 \u2192 resolve pela estrutura
|
|
1084
|
+
|
|
1035
1085
|
\u{1F4DD} EXEMPLOS DE PATTERNS:
|
|
1036
|
-
\u2022 console.$METHOD(
|
|
1037
|
-
\u2022
|
|
1086
|
+
\u2022 console.$METHOD($MSG) \u2192 captura metodo e 1 argumento
|
|
1087
|
+
\u2022 console.$METHOD($$$ARGS) \u2192 captura metodo e todos os argumentos
|
|
1088
|
+
\u2022 function $NAME($$$PARAMS) { $$$BODY } \u2192 captura funcoes completas
|
|
1038
1089
|
\u2022 import { $$$ITEMS } from '$MODULE' \u2192 captura imports
|
|
1039
|
-
\u2022 const $VAR = $VALUE
|
|
1040
|
-
\u2022 try { $$$ } catch ($ERR) { $$$ }
|
|
1041
|
-
\u2022 await $FUNC($$$ARGS)
|
|
1090
|
+
\u2022 const $VAR = $VALUE \u2192 captura declaracoes
|
|
1091
|
+
\u2022 try { $$$ } catch ($ERR) { $$$ } \u2192 captura try-catch
|
|
1092
|
+
\u2022 await $FUNC($$$ARGS) \u2192 captura chamadas assincronas
|
|
1042
1093
|
|
|
1043
1094
|
\u{1F524} METAVARIAVEIS:
|
|
1044
|
-
\u2022 $VAR \u2192 captura UM no
|
|
1045
|
-
\u2022
|
|
1095
|
+
\u2022 $VAR \u2192 captura UM no nomeado (ex: um identificador, uma string, um numero)
|
|
1096
|
+
\u2022 $$VAR \u2192 captura UM no (incluindo nos nao-nomeados como operadores +, -)
|
|
1097
|
+
\u2022 $$$VARS \u2192 captura ZERO OU MAIS nos (ex: todos os args, corpo da funcao)
|
|
1098
|
+
|
|
1099
|
+
\u26A0\uFE0F $$$VARS captura multiplos nos \u2014 o texto de cada no e concatenado com
|
|
1100
|
+
", " no resultado da metavariable. Para multi-nos complexos (onde a
|
|
1101
|
+
concatenacao simples nao basta), use supergrep_tree para inspecionar a AST.
|
|
1046
1102
|
|
|
1047
1103
|
\u{1F4A1} DICA: Se o pattern nao der match, use supergrep_tree primeiro para
|
|
1048
1104
|
descobrir os kinds de nos disponiveis e ajustar o pattern.
|
|
@@ -1095,21 +1151,34 @@ ${warnings.map((w) => ` \u2022 ${w}`).join("\n")}` : "";
|
|
|
1095
1151
|
"supergrep_tree",
|
|
1096
1152
|
{
|
|
1097
1153
|
title: "Explore AST Structure",
|
|
1098
|
-
description: `Explora a estrutura da AST (Abstract Syntax Tree) de um arquivo.
|
|
1154
|
+
description: `Explora a estrutura da AST (Abstract Syntax Tree) de um arquivo ou snippet.
|
|
1099
1155
|
|
|
1100
1156
|
Mostra todos os tipos de nos (kinds) presentes, com contagens e distribuicao.
|
|
1101
1157
|
Util para entender a estrutura do codigo e descobrir quais kinds usar
|
|
1102
|
-
em patterns de busca
|
|
1158
|
+
em patterns de busca.
|
|
1159
|
+
|
|
1160
|
+
\u{1F4D6} O QUE E UM "KIND":
|
|
1161
|
+
Um kind e o tipo de um no na arvore sintatica. Exemplos:
|
|
1162
|
+
\u2022 function_declaration \u2014 declaracao de funcao
|
|
1163
|
+
\u2022 call_expression \u2014 chamada de funcao/metodo
|
|
1164
|
+
\u2022 identifier \u2014 nome de variavel, funcao, etc.
|
|
1165
|
+
\u2022 string_fragment \u2014 literal de string
|
|
1166
|
+
Cada estrutura de codigo vira um kind diferente na AST.
|
|
1167
|
+
|
|
1168
|
+
\u{1F4A1} Como usar os kinds: ao ver call_expression no tree, voce pode buscar
|
|
1169
|
+
chamadas de funcao com o pattern: $FUNC($$$ARGS)
|
|
1103
1170
|
|
|
1104
1171
|
QUANDO USAR:
|
|
1105
|
-
- "Quais tipos de nos existem neste arquivo TypeScript?"
|
|
1106
|
-
- "Como escrever um pattern para capturar certas estruturas?"
|
|
1107
|
-
- "Preciso descobrir os kinds para uma regra de lint customizada"
|
|
1108
|
-
- Antes de escrever um pattern complexo, para conhecer a AST
|
|
1172
|
+
- "Quais tipos de nos existem neste arquivo TypeScript?"
|
|
1173
|
+
- "Como escrever um pattern para capturar certas estruturas?"
|
|
1174
|
+
- "Preciso descobrir os kinds para uma regra de lint customizada"
|
|
1175
|
+
- Antes de escrever um pattern complexo, para conhecer a AST
|
|
1176
|
+
- Testar um snippet de codigo sem criar arquivo (use o parametro code)
|
|
1109
1177
|
|
|
1110
1178
|
QUANDO NAO USAR:
|
|
1111
|
-
- Para buscar padroes no codigo \u2192 use supergrep_find
|
|
1112
|
-
- Para ver o conteudo do arquivo \u2192 leia o arquivo diretamente
|
|
1179
|
+
- Para buscar padroes no codigo \u2192 use supergrep_find
|
|
1180
|
+
- Para ver o conteudo do arquivo \u2192 leia o arquivo diretamente
|
|
1181
|
+
- Para diretorios (analisar multiplos arquivos) \u2192 use supergrep_find com o pattern desejado. supergrep_tree analisa UM arquivo ou snippet por vez.
|
|
1113
1182
|
|
|
1114
1183
|
Workflow: supergrep_tree \u2192 supergrep_find (usar kinds descobertos)`,
|
|
1115
1184
|
inputSchema: {
|
|
@@ -1158,27 +1227,35 @@ ${warnings.map((w) => ` \u2022 ${w}`).join("\n")}` : "";
|
|
|
1158
1227
|
server2.registerTool(
|
|
1159
1228
|
"supergrep_replace",
|
|
1160
1229
|
{
|
|
1161
|
-
title: "Preview Structural Replacement",
|
|
1162
|
-
description:
|
|
1230
|
+
title: "Preview Structural Replacement (read-only)",
|
|
1231
|
+
description: `\u{1F504} PREVIEW de substituicao estrutural de codigo (NAO modifica arquivos).
|
|
1163
1232
|
|
|
1164
1233
|
Encontra padroes com AST Grep e mostra um diff de como o codigo ficaria
|
|
1165
1234
|
apos a substituicao. Util para planejar refatoracoes em larga escala.
|
|
1166
1235
|
|
|
1167
|
-
LIMITACAO
|
|
1168
|
-
|
|
1236
|
+
\u26A0\uFE0F LIMITACAO DE METAVARIAVEIS NO REWRITE:
|
|
1237
|
+
\u2022 $VAR (single) \u2192 interpola corretamente \u2705
|
|
1238
|
+
Ex: console.$METHOD($MSG) \u2192 logger.$METHOD($MSG)
|
|
1239
|
+
\u2022 $$$VARS (multi) \u2192 interpolado como texto concatenado dos nos \u26A0\uFE0F
|
|
1240
|
+
Ex: console.log($$$ARGS) \u2192 logger.info(texto, dos, args)
|
|
1241
|
+
Para casos complexos, verifique o preview antes de aplicar.
|
|
1242
|
+
|
|
1243
|
+
A API napi do AST Grep nao interpola metavariaveis automaticamente.
|
|
1244
|
+
O supergrep faz interpolacao manual: textos dos nos sao concatenados
|
|
1245
|
+
com ", " e injetados no lugar do $VAR no rewrite.
|
|
1169
1246
|
|
|
1170
1247
|
QUANDO USAR:
|
|
1171
|
-
- "Como ficaria se eu trocasse console.log por logger.info?"
|
|
1172
|
-
- "Preview de substituir var por let em todo o projeto"
|
|
1173
|
-
- "Mostre o diff de trocar moment() por date-fns"
|
|
1174
|
-
- Planejar refatoracoes estruturais antes de aplicar
|
|
1248
|
+
- "Como ficaria se eu trocasse console.log por logger.info?"
|
|
1249
|
+
- "Preview de substituir var por let em todo o projeto"
|
|
1250
|
+
- "Mostre o diff de trocar moment() por date-fns"
|
|
1251
|
+
- Planejar refatoracoes estruturais antes de aplicar
|
|
1175
1252
|
|
|
1176
1253
|
QUANDO NAO USAR:
|
|
1177
|
-
- Para buscar padroes (sem substituir) \u2192 use supergrep_find
|
|
1178
|
-
- Para aplicar a substituicao de fato \u2192 use
|
|
1179
|
-
- Para refatoracoes que envolvem logica complexa \u2192 implemente manualmente
|
|
1254
|
+
- Para buscar padroes (sem substituir) \u2192 use supergrep_find
|
|
1255
|
+
- Para aplicar a substituicao de fato \u2192 use edit (substituicao exata) ou write (arquivo completo). O preview do supergrep_replace serve como guia.
|
|
1256
|
+
- Para refatoracoes que envolvem logica complexa \u2192 implemente manualmente
|
|
1180
1257
|
|
|
1181
|
-
Workflow: supergrep_find \u2192 supergrep_replace (preview) \u2192 aplicar mudancas`,
|
|
1258
|
+
Workflow: supergrep_find \u2192 supergrep_replace (preview) \u2192 aplicar mudancas com edit/write`,
|
|
1182
1259
|
inputSchema: {
|
|
1183
1260
|
pattern: z.string().min(1).describe(
|
|
1184
1261
|
"Padrao AST Grep a encontrar. Ex: 'console.log($$$ARGS)'"
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justmpm/supergrep",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "MCP server para busca estrutural de código com AST Grep. Encontra padrões de código com precisão sintática, ignorando formatação e comentários. Suporta 20+ linguagens via Tree-sitter.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast-grep",
|