@justmpm/ai-tool 0.3.1 → 0.4.0

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/dist/cli.js CHANGED
@@ -1,13 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  VERSION,
4
+ area,
5
+ areas,
6
+ areasInit,
4
7
  context,
5
8
  dead,
6
9
  deadFix,
7
10
  impact,
8
11
  map,
9
12
  suggest
10
- } from "./chunk-4HXWM7PK.js";
13
+ } from "./chunk-33DHCY2H.js";
11
14
 
12
15
  // src/cli.ts
13
16
  var HELP = `
@@ -21,6 +24,14 @@ COMANDOS:
21
24
  suggest <arquivo> Sugere arquivos para ler antes de modificar
22
25
  context <arquivo> Extrai assinaturas de um arquivo (funcoes, tipos)
23
26
 
27
+ AREAS (NOVO):
28
+ areas Lista todas as areas/dominios do projeto
29
+ areas init Gera arquivo de configuracao .analyze/areas.config.json
30
+ areas init --force Sobrescreve configuracao existente
31
+ area <nome> Mostra arquivos de uma area especifica
32
+ area <nome> --type=hook Filtra por categoria
33
+ area <nome> --full Mostra todos os arquivos
34
+
24
35
  MODOS:
25
36
  --mcp Inicia servidor MCP para integracao com Claude Desktop
26
37
 
@@ -29,6 +40,8 @@ OPCOES:
29
40
  --cwd=<path> Diretorio do projeto (default: cwd)
30
41
  --no-cache Ignora cache e forca regeneracao
31
42
  --limit=<n> Limite de sugestoes (default: 10, apenas suggest)
43
+ --type=<categoria> Filtra por categoria (apenas area)
44
+ --full Mostra todos os arquivos (apenas area)
32
45
  --help, -h Mostra esta ajuda
33
46
  --version, -v Mostra versao
34
47
 
@@ -40,16 +53,16 @@ CACHE:
40
53
  EXEMPLOS:
41
54
  ai-tool map
42
55
  ai-tool map --format=json
43
- ai-tool map --no-cache
44
56
  ai-tool dead
45
57
  ai-tool dead --fix
46
58
  ai-tool impact Button
47
- ai-tool impact src/hooks/useAuth.ts
48
- ai-tool impact src/components/Header.tsx --format=json
49
- ai-tool suggest Button
50
- ai-tool suggest src/hooks/useAuth.ts --limit=5
59
+ ai-tool suggest Button --limit=5
51
60
  ai-tool context Button
52
- ai-tool context src/hooks/useAuth.ts --format=json
61
+ ai-tool areas
62
+ ai-tool areas init
63
+ ai-tool area meus-pets
64
+ ai-tool area meus-pets --type=hook
65
+ ai-tool area firebase --full
53
66
  ai-tool --mcp
54
67
 
55
68
  SOBRE:
@@ -72,7 +85,7 @@ async function main() {
72
85
  }
73
86
  }
74
87
  if (flags.mcp) {
75
- const { startMcpServer } = await import("./server-YV4BWISA.js");
88
+ const { startMcpServer } = await import("./server-62WVGNJD.js");
76
89
  await startMcpServer();
77
90
  return;
78
91
  }
@@ -134,6 +147,27 @@ async function main() {
134
147
  }
135
148
  result = await context(target, { format, cwd });
136
149
  break;
150
+ case "areas":
151
+ if (target === "init") {
152
+ result = await areasInit({ cwd, force: !!flags.force });
153
+ } else {
154
+ result = await areas({ format, cwd });
155
+ }
156
+ break;
157
+ case "area":
158
+ if (!target) {
159
+ console.error("\u274C Erro: nome da \xE1rea \xE9 obrigat\xF3rio para o comando area");
160
+ console.error(" Exemplo: ai-tool area meus-pets");
161
+ console.error(" Use 'ai-tool areas' para listar \xE1reas dispon\xEDveis");
162
+ process.exit(1);
163
+ }
164
+ result = await area(target, {
165
+ format,
166
+ cwd,
167
+ type: flags.type,
168
+ full: !!flags.full
169
+ });
170
+ break;
137
171
  default:
138
172
  console.error(`\u274C Comando desconhecido: ${command}`);
139
173
  console.error(" Use 'ai-tool --help' para ver comandos dispon\xEDveis.");
package/dist/index.d.ts CHANGED
@@ -66,6 +66,14 @@ interface DeadResult {
66
66
  export: string;
67
67
  }>;
68
68
  dependencies: string[];
69
+ /** Informações sobre filtros aplicados (ex: Cloud Functions excluídas) */
70
+ filters?: {
71
+ firebase: {
72
+ detected: boolean;
73
+ excludedCount: number;
74
+ };
75
+ excludedFiles: string[];
76
+ };
69
77
  }
70
78
  interface ImpactFile {
71
79
  path: string;
@@ -150,6 +158,64 @@ interface ContextResult {
150
158
  functions: FunctionInfo[];
151
159
  types: TypeInfo[];
152
160
  }
161
+ interface AreaConfig {
162
+ name: string;
163
+ description?: string;
164
+ patterns: string[];
165
+ keywords?: string[];
166
+ exclude?: string[];
167
+ }
168
+ interface AreasConfigFile {
169
+ $schema?: string;
170
+ version: string;
171
+ areas: Record<string, AreaConfig>;
172
+ descriptions?: Record<string, string>;
173
+ settings?: {
174
+ autoDetect?: boolean;
175
+ inferDescriptions?: boolean;
176
+ groupByCategory?: boolean;
177
+ };
178
+ }
179
+ interface AreaFile {
180
+ path: string;
181
+ category: FileCategory;
182
+ description?: string;
183
+ }
184
+ interface DetectedArea {
185
+ id: string;
186
+ name: string;
187
+ description?: string;
188
+ files: AreaFile[];
189
+ fileCount: number;
190
+ categories: Partial<Record<FileCategory, number>>;
191
+ isAutoDetected: boolean;
192
+ }
193
+ interface AreasResult {
194
+ version: string;
195
+ timestamp: string;
196
+ cwd: string;
197
+ areas: DetectedArea[];
198
+ unmapped: AreaFile[];
199
+ summary: {
200
+ totalAreas: number;
201
+ totalFiles: number;
202
+ unmappedCount: number;
203
+ };
204
+ }
205
+ interface AreaDetailResult {
206
+ version: string;
207
+ timestamp: string;
208
+ area: DetectedArea;
209
+ byCategory: Partial<Record<FileCategory, AreaFile[]>>;
210
+ }
211
+ interface AreasOptions extends CommandOptions {
212
+ full?: boolean;
213
+ type?: FileCategory;
214
+ }
215
+ interface AreaOptions extends CommandOptions {
216
+ full?: boolean;
217
+ type?: FileCategory;
218
+ }
153
219
 
154
220
  /**
155
221
  * Comando MAP - Mapa do projeto usando Skott
@@ -162,6 +228,9 @@ declare function map(options?: MapOptions): Promise<string>;
162
228
 
163
229
  /**
164
230
  * Comando DEAD - Detecção de código morto usando Knip
231
+ *
232
+ * Inclui filtro inteligente para Firebase Cloud Functions que elimina
233
+ * falsos positivos de arquivos exportados via functions/src/index.ts
165
234
  */
166
235
 
167
236
  /**
@@ -200,12 +269,51 @@ declare function suggest(target: string, options?: SuggestOptions): Promise<stri
200
269
  */
201
270
  declare function context(target: string, options?: ContextOptions): Promise<string>;
202
271
 
272
+ /**
273
+ * Comando AREAS - Lista todas as áreas do projeto
274
+ */
275
+
276
+ /**
277
+ * Executa o comando AREAS
278
+ */
279
+ declare function areas(options?: AreasOptions): Promise<string>;
280
+
281
+ /**
282
+ * Comando AREA - Mostra detalhes de uma área específica
283
+ */
284
+
285
+ /**
286
+ * Executa o comando AREA
287
+ */
288
+ declare function area(target: string, options?: AreaOptions): Promise<string>;
289
+
290
+ /**
291
+ * Comando AREAS INIT - Gera configuração inicial de áreas
292
+ */
293
+ interface InitOptions {
294
+ cwd?: string;
295
+ force?: boolean;
296
+ }
297
+ /**
298
+ * Executa o comando AREAS INIT
299
+ */
300
+ declare function areasInit(options?: InitOptions): Promise<string>;
301
+
203
302
  /**
204
303
  * Utilitários para detecção e classificação de arquivos
205
304
  */
206
305
 
207
306
  /**
208
307
  * Detecta a categoria de um arquivo baseado no path
308
+ *
309
+ * Suporta múltiplos frameworks:
310
+ * - Next.js (App Router e Pages Router)
311
+ * - Vite (React, Vue, Svelte)
312
+ * - Create React App
313
+ * - Remix
314
+ * - Nuxt
315
+ * - SvelteKit
316
+ * - Astro
209
317
  */
210
318
  declare function detectCategory(filePath: string): FileCategory;
211
319
  /**
@@ -221,6 +329,41 @@ declare function isEntryPoint(filePath: string): boolean;
221
329
  */
222
330
  declare function isCodeFile(filePath: string): boolean;
223
331
 
332
+ /**
333
+ * Utilitários para detecção de Firebase Cloud Functions
334
+ *
335
+ * Resolve falsos positivos onde arquivos em functions/src/ são marcados
336
+ * como "órfãos" pelo Knip, mas na verdade são exportados via index.ts
337
+ * e deployados como Cloud Functions.
338
+ */
339
+ /**
340
+ * Detecta se é um projeto Firebase (via .firebaserc ou firebase.json)
341
+ */
342
+ declare function isFirebaseProject(cwd: string): boolean;
343
+ /**
344
+ * Detecta se o projeto tem Firebase Cloud Functions
345
+ */
346
+ declare function hasFirebaseFunctions(cwd: string): boolean;
347
+ /**
348
+ * Verifica se um arquivo é uma Cloud Function exportada no index.ts
349
+ */
350
+ declare function isExportedCloudFunction(filePath: string, cwd: string): boolean;
351
+ /**
352
+ * Filtra arquivos órfãos removendo falsos positivos de Cloud Functions
353
+ *
354
+ * @param files - Lista de arquivos marcados como órfãos pelo Knip
355
+ * @param cwd - Diretório do projeto
356
+ * @returns Lista filtrada sem os falsos positivos
357
+ */
358
+ declare function filterCloudFunctionsFalsePositives(files: string[], cwd: string): {
359
+ filtered: string[];
360
+ excluded: string[];
361
+ };
362
+ /**
363
+ * Limpa o cache (útil para testes ou quando o index.ts muda)
364
+ */
365
+ declare function clearFirebaseCache(): void;
366
+
224
367
  /**
225
368
  * Obtém o caminho da pasta de cache
226
369
  */
@@ -234,6 +377,110 @@ declare function isCacheValid(cwd: string): boolean;
234
377
  */
235
378
  declare function invalidateCache(cwd: string): void;
236
379
 
380
+ /**
381
+ * Gerenciamento de configuração de áreas
382
+ *
383
+ * Lê e escreve o arquivo areas.config.json
384
+ */
385
+
386
+ /**
387
+ * Verifica se o arquivo de configuração existe
388
+ */
389
+ declare function configExists(cwd: string): boolean;
390
+ /**
391
+ * Lê o arquivo de configuração
392
+ */
393
+ declare function readConfig(cwd: string): AreasConfigFile;
394
+ /**
395
+ * Escreve o arquivo de configuração
396
+ */
397
+ declare function writeConfig(cwd: string, config: AreasConfigFile): void;
398
+ /**
399
+ * Adiciona ou atualiza uma área na configuração
400
+ */
401
+ declare function setArea(cwd: string, id: string, area: AreaConfig): void;
402
+ /**
403
+ * Remove uma área da configuração
404
+ */
405
+ declare function removeArea(cwd: string, id: string): void;
406
+ /**
407
+ * Define descrição manual para um arquivo
408
+ */
409
+ declare function setFileDescription(cwd: string, filePath: string, description: string): void;
410
+ /**
411
+ * Obtém descrição manual de um arquivo (se existir)
412
+ */
413
+ declare function getFileDescription(cwd: string, filePath: string): string | undefined;
414
+
415
+ /**
416
+ * Detector de áreas
417
+ *
418
+ * Detecta automaticamente a área de cada arquivo baseado em:
419
+ * 1. Configuração manual (areas.config.json)
420
+ * 2. Padrões de pasta
421
+ * 3. Keywords no nome
422
+ */
423
+
424
+ /**
425
+ * Detecta a(s) área(s) de um arquivo
426
+ * Retorna array porque um arquivo pode pertencer a múltiplas áreas
427
+ */
428
+ declare function detectFileAreas(filePath: string, config: AreasConfigFile): string[];
429
+ /**
430
+ * Obtém o nome amigável de uma área
431
+ */
432
+ declare function getAreaName(areaId: string, config: AreasConfigFile): string;
433
+ /**
434
+ * Obtém a descrição de uma área
435
+ */
436
+ declare function getAreaDescription(areaId: string, config: AreasConfigFile): string | undefined;
437
+ /**
438
+ * Infere descrição de um arquivo baseado em seu nome e categoria
439
+ */
440
+ declare function inferFileDescription(filePath: string, category: FileCategory): string | undefined;
441
+
442
+ /**
443
+ * Padrões de detecção automática de áreas
444
+ *
445
+ * Define regras para detectar áreas baseado em:
446
+ * - Padrões de pasta (glob)
447
+ * - Keywords no nome do arquivo
448
+ *
449
+ * Suporta múltiplos frameworks:
450
+ * - Next.js (App Router e Pages Router)
451
+ * - Vite (React, Vue)
452
+ * - Create React App
453
+ * - Remix
454
+ * - Nuxt
455
+ * - SvelteKit
456
+ * - Astro
457
+ */
458
+ /**
459
+ * Padrões de pasta → área
460
+ * Ordem importa: mais específico primeiro
461
+ */
462
+ declare const FOLDER_PATTERNS: Array<{
463
+ pattern: RegExp;
464
+ area: string;
465
+ priority: number;
466
+ }>;
467
+ /**
468
+ * Keywords no nome do arquivo → área
469
+ */
470
+ declare const KEYWORD_PATTERNS: Array<{
471
+ keyword: RegExp;
472
+ area: string;
473
+ priority: number;
474
+ }>;
475
+ /**
476
+ * Nomes amigáveis das áreas
477
+ */
478
+ declare const AREA_NAMES: Record<string, string>;
479
+ /**
480
+ * Descrições padrão das áreas
481
+ */
482
+ declare const AREA_DESCRIPTIONS: Record<string, string>;
483
+
237
484
  /**
238
485
  * ai-tool - Ferramenta de análise de dependências e impacto
239
486
  *
@@ -254,6 +501,6 @@ declare function invalidateCache(cwd: string): void;
254
501
  * ```
255
502
  */
256
503
 
257
- declare const VERSION = "0.3.1";
504
+ declare const VERSION = "0.4.0";
258
505
 
259
- export { type CommandOptions, type ContextOptions, type ContextResult, type DeadFile, type DeadOptions, type DeadResult, type FileCategory, type FileInfo, type FolderStats, type FunctionInfo, type ImpactFile, type ImpactOptions, type ImpactResult, type ImportInfo, type MapOptions, type MapResult, type OutputFormat, type ParamInfo, type RiskInfo, type SuggestOptions, type SuggestResult, type Suggestion, type SuggestionPriority, type TypeInfo, type TypeKind, VERSION, categoryIcons, context, dead, deadFix, detectCategory, getCacheDir, impact, invalidateCache, isCacheValid, isCodeFile, isEntryPoint, map, suggest };
506
+ export { AREA_DESCRIPTIONS, AREA_NAMES, type AreaConfig, type AreaDetailResult, type AreaFile, type AreaOptions, type AreasConfigFile, type AreasOptions, type AreasResult, type CommandOptions, type ContextOptions, type ContextResult, type DeadFile, type DeadOptions, type DeadResult, type DetectedArea, FOLDER_PATTERNS, type FileCategory, type FileInfo, type FolderStats, type FunctionInfo, type ImpactFile, type ImpactOptions, type ImpactResult, type ImportInfo, KEYWORD_PATTERNS, type MapOptions, type MapResult, type OutputFormat, type ParamInfo, type RiskInfo, type SuggestOptions, type SuggestResult, type Suggestion, type SuggestionPriority, type TypeInfo, type TypeKind, VERSION, area, areas, areasInit, categoryIcons, clearFirebaseCache, configExists, context, dead, deadFix, detectCategory, detectFileAreas, filterCloudFunctionsFalsePositives, getAreaDescription, getAreaName, getCacheDir, getFileDescription, hasFirebaseFunctions, impact, inferFileDescription, invalidateCache, isCacheValid, isCodeFile, isEntryPoint, isExportedCloudFunction, isFirebaseProject, map, readConfig, removeArea, setArea, setFileDescription, suggest, writeConfig };
package/dist/index.js CHANGED
@@ -1,32 +1,78 @@
1
1
  import {
2
+ AREA_DESCRIPTIONS,
3
+ AREA_NAMES,
4
+ FOLDER_PATTERNS,
5
+ KEYWORD_PATTERNS,
2
6
  VERSION,
7
+ area,
8
+ areas,
9
+ areasInit,
3
10
  categoryIcons,
11
+ clearFirebaseCache,
12
+ configExists,
4
13
  context,
5
14
  dead,
6
15
  deadFix,
7
16
  detectCategory,
17
+ detectFileAreas,
18
+ filterCloudFunctionsFalsePositives,
19
+ getAreaDescription,
20
+ getAreaName,
8
21
  getCacheDir,
22
+ getFileDescription,
23
+ hasFirebaseFunctions,
9
24
  impact,
25
+ inferFileDescription,
10
26
  invalidateCache,
11
27
  isCacheValid,
12
28
  isCodeFile,
13
29
  isEntryPoint,
30
+ isExportedCloudFunction,
31
+ isFirebaseProject,
14
32
  map,
15
- suggest
16
- } from "./chunk-4HXWM7PK.js";
33
+ readConfig,
34
+ removeArea,
35
+ setArea,
36
+ setFileDescription,
37
+ suggest,
38
+ writeConfig
39
+ } from "./chunk-33DHCY2H.js";
17
40
  export {
41
+ AREA_DESCRIPTIONS,
42
+ AREA_NAMES,
43
+ FOLDER_PATTERNS,
44
+ KEYWORD_PATTERNS,
18
45
  VERSION,
46
+ area,
47
+ areas,
48
+ areasInit,
19
49
  categoryIcons,
50
+ clearFirebaseCache,
51
+ configExists,
20
52
  context,
21
53
  dead,
22
54
  deadFix,
23
55
  detectCategory,
56
+ detectFileAreas,
57
+ filterCloudFunctionsFalsePositives,
58
+ getAreaDescription,
59
+ getAreaName,
24
60
  getCacheDir,
61
+ getFileDescription,
62
+ hasFirebaseFunctions,
25
63
  impact,
64
+ inferFileDescription,
26
65
  invalidateCache,
27
66
  isCacheValid,
28
67
  isCodeFile,
29
68
  isEntryPoint,
69
+ isExportedCloudFunction,
70
+ isFirebaseProject,
30
71
  map,
31
- suggest
72
+ readConfig,
73
+ removeArea,
74
+ setArea,
75
+ setFileDescription,
76
+ suggest,
77
+ writeConfig
32
78
  };