wegho-agentes 7.0.0 → 7.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.
- package/.agent/skills/wegho-global-rules/SKILL.md +20 -0
- package/.agent/workflows/PROMPT_GUIDE.md +7 -4
- package/.agents/cli.ts +29 -21
- package/.agents/core/base-agent.ts +28 -12
- package/.agents/core/memory-system.ts +45 -13
- package/.agents/core/report-generator.ts +26 -19
- package/.agents/orchestrator.ts +104 -74
- package/.clinerules +318 -1229
- package/.cursorrules +0 -189
- package/README.md +3 -3
- package/docs/VERSION.md +3 -2
- package/package.json +3 -3
- package/.agents/agents/ai-agents/README.md +0 -175
- package/.agents/agents/ai-agents/agent.ts +0 -83
- package/.agents/agents/ai-agents/specialty.md +0 -14
- package/.agents/agents/architecture/README.md +0 -61
- package/.agents/agents/architecture/agent.ts +0 -238
- package/.agents/agents/architecture/memory.md +0 -111
- package/.agents/agents/architecture/specialty.md +0 -31
- package/.agents/agents/automation/README.md +0 -60
- package/.agents/agents/automation/agent.ts +0 -61
- package/.agents/agents/automation/specialty.md +0 -14
- package/.agents/agents/backend/README.md +0 -155
- package/.agents/agents/backend/agent.ts +0 -100
- package/.agents/agents/backend/specialty.md +0 -14
- package/.agents/agents/cloud/README.md +0 -73
- package/.agents/agents/cloud/agent.ts +0 -53
- package/.agents/agents/cloud/specialty.md +0 -14
- package/.agents/agents/code-auditor/README.md +0 -37
- package/.agents/agents/code-auditor/agent.ts +0 -334
- package/.agents/agents/code-auditor/specialty.md +0 -14
- package/.agents/agents/cro/README.md +0 -200
- package/.agents/agents/cro/agent.ts +0 -61
- package/.agents/agents/cro/specialty.md +0 -14
- package/.agents/agents/database/README.md +0 -67
- package/.agents/agents/database/agent.ts +0 -93
- package/.agents/agents/database/specialty.md +0 -14
- package/.agents/agents/devops/README.md +0 -84
- package/.agents/agents/devops/agent.ts +0 -54
- package/.agents/agents/devops/specialty.md +0 -14
- package/.agents/agents/documentation/README.md +0 -107
- package/.agents/agents/documentation/agent.ts +0 -253
- package/.agents/agents/documentation/memory.md +0 -56
- package/.agents/agents/documentation/specialty.md +0 -33
- package/.agents/agents/frontend/README.md +0 -188
- package/.agents/agents/frontend/agent.ts +0 -211
- package/.agents/agents/frontend/memory.md +0 -139
- package/.agents/agents/frontend/specialty.md +0 -30
- package/.agents/agents/inventory/README.md +0 -35
- package/.agents/agents/inventory/agent.ts +0 -758
- package/.agents/agents/inventory/memory.md +0 -50
- package/.agents/agents/inventory/specialty.md +0 -129
- package/.agents/agents/nextjs/README.md +0 -58
- package/.agents/agents/nextjs/agent.ts +0 -114
- package/.agents/agents/nextjs/specialty.md +0 -14
- package/.agents/agents/pentest/README.md +0 -228
- package/.agents/agents/pentest/agent.ts +0 -96
- package/.agents/agents/pentest/specialty.md +0 -14
- package/.agents/agents/planning/README.md +0 -107
- package/.agents/agents/planning/agent.ts +0 -389
- package/.agents/agents/planning/specialty.md +0 -14
- package/.agents/agents/project-discovery/README.md +0 -35
- package/.agents/agents/project-discovery/agent.ts +0 -344
- package/.agents/agents/project-discovery/specialty.md +0 -14
- package/.agents/agents/quality/README.md +0 -81
- package/.agents/agents/quality/agent.ts +0 -269
- package/.agents/agents/quality/memory.md +0 -110
- package/.agents/agents/quality/specialty.md +0 -31
- package/.agents/agents/rag/README.md +0 -41
- package/.agents/agents/rag/agent.ts +0 -85
- package/.agents/agents/rag/specialty.md +0 -14
- package/.agents/agents/security/README.md +0 -152
- package/.agents/agents/security/agent.ts +0 -218
- package/.agents/agents/security/memory.md +0 -91
- package/.agents/agents/security/specialty.md +0 -31
- package/.agents/agents/task-analyzer/README.md +0 -36
- package/.agents/agents/task-analyzer/agent.ts +0 -462
- package/.agents/agents/task-analyzer/specialty.md +0 -14
- package/.agents/agents/testing/README.md +0 -161
- package/.agents/agents/testing/agent.ts +0 -61
- package/.agents/agents/testing/specialty.md +0 -14
- package/.agents/agents/uiux/README.md +0 -68
- package/.agents/agents/uiux/agent.ts +0 -95
- package/.agents/agents/uiux/specialty.md +0 -14
- package/.agents/base/base-agent.ts +0 -331
- package/.agents/base/memory-system.ts +0 -397
- package/.agents/base/skill-manager.ts +0 -95
- package/.agents/convert-memory.ps1 +0 -153
- package/.agents/examples/reporting-example.md +0 -203
- package/.agents/managers/build-manager.ts +0 -304
- package/.agents/managers/cache-manager.ts +0 -184
- package/.agents/managers/checkpoint-manager.ts +0 -299
- package/.agents/migrate-agents.ps1 +0 -117
- package/.agents/templates/change-report.md +0 -55
- package/.agents/templates/execution-plan.md +0 -36
- package/.agents/unmapped-skills.txt +0 -0
- package/.agents/utils/agent-migrator.ts +0 -360
- package/.agents/utils/agent-monitor.ts +0 -102
- package/.agents/utils/agent-parallelizer.ts +0 -108
- package/.agents/utils/context-monitor.ts +0 -140
- package/.agents/utils/feedback-collector.ts +0 -207
- package/.agents/utils/file-generator.ts +0 -304
- package/.agents/utils/memory-converter.ts +0 -217
- package/.agents/utils/memory-dashboard.ts +0 -147
- package/.agents/utils/performance-tracker.ts +0 -275
- package/.agents/utils/report-generator.ts +0 -193
- package/.agents/utils/retry-utility.ts +0 -140
- package/.agents/utils/workflow-validator.ts +0 -158
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Monitor - Monitora nível de contexto do LLM
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type ContextLevel = 'baixo' | 'baixo-médio' | 'médio' | 'médio-alto' | 'alto' | 'muito-alto' | 'extremo';
|
|
6
|
-
|
|
7
|
-
export interface ContextReport {
|
|
8
|
-
level: ContextLevel;
|
|
9
|
-
percentage: number;
|
|
10
|
-
emoji: string;
|
|
11
|
-
warning: string;
|
|
12
|
-
color: 'green' | 'yellow' | 'orange' | 'red';
|
|
13
|
-
shouldWarn: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class ContextMonitor {
|
|
17
|
-
private maxTokens: number;
|
|
18
|
-
|
|
19
|
-
constructor(maxTokens: number = 200000) {
|
|
20
|
-
this.maxTokens = maxTokens;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Analisa nível de contexto e retorna relatório
|
|
25
|
-
*/
|
|
26
|
-
getContextLevel(currentTokens: number): ContextReport {
|
|
27
|
-
const percentage = (currentTokens / this.maxTokens) * 100;
|
|
28
|
-
|
|
29
|
-
// Definir nível baseado em percentage
|
|
30
|
-
let level: ContextLevel;
|
|
31
|
-
let emoji: string;
|
|
32
|
-
let warning: string;
|
|
33
|
-
let color: 'green' | 'yellow' | 'orange' | 'red';
|
|
34
|
-
let shouldWarn: boolean;
|
|
35
|
-
|
|
36
|
-
if (percentage < 20) {
|
|
37
|
-
level = 'baixo';
|
|
38
|
-
emoji = '🟢';
|
|
39
|
-
warning = 'Contexto saudável. Continue.';
|
|
40
|
-
color = 'green';
|
|
41
|
-
shouldWarn = false;
|
|
42
|
-
} else if (percentage < 40) {
|
|
43
|
-
level = 'baixo-médio';
|
|
44
|
-
emoji = '🟢';
|
|
45
|
-
warning = 'Contexto baixo-médio. Espaço suficiente.';
|
|
46
|
-
color = 'green';
|
|
47
|
-
shouldWarn = false;
|
|
48
|
-
} else if (percentage < 60) {
|
|
49
|
-
level = 'médio';
|
|
50
|
-
emoji = '🟡';
|
|
51
|
-
warning = 'Contexto médio. Monitore o crescimento.';
|
|
52
|
-
color = 'yellow';
|
|
53
|
-
shouldWarn = false;
|
|
54
|
-
} else if (percentage < 80) {
|
|
55
|
-
level = 'médio-alto';
|
|
56
|
-
emoji = '🟠';
|
|
57
|
-
warning = 'Contexto médio-alto. Planeje finalizar tarefas em breve.';
|
|
58
|
-
color = 'orange';
|
|
59
|
-
shouldWarn = false;
|
|
60
|
-
} else if (percentage < 90) {
|
|
61
|
-
level = 'alto';
|
|
62
|
-
emoji = '🟠';
|
|
63
|
-
warning = 'Contexto alto! Considere finalizar a tarefa atual.';
|
|
64
|
-
color = 'orange';
|
|
65
|
-
shouldWarn = true;
|
|
66
|
-
} else if (percentage < 95) {
|
|
67
|
-
level = 'muito-alto';
|
|
68
|
-
emoji = '🔴';
|
|
69
|
-
warning = '⚠️ Contexto MUITO ALTO! Recomendo iniciar nova conversa após esta tarefa.';
|
|
70
|
-
color = 'red';
|
|
71
|
-
shouldWarn = true;
|
|
72
|
-
} else {
|
|
73
|
-
level = 'extremo';
|
|
74
|
-
emoji = '🔴';
|
|
75
|
-
warning = '🚨 CONTEXTO EXTREMO! INICIE NOVA CONVERSA IMEDIATAMENTE!';
|
|
76
|
-
color = 'red';
|
|
77
|
-
shouldWarn = true;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
level,
|
|
82
|
-
percentage: Math.round(percentage * 10) / 10,
|
|
83
|
-
emoji,
|
|
84
|
-
warning,
|
|
85
|
-
color,
|
|
86
|
-
shouldWarn
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Verifica se deve alertar o usuário
|
|
92
|
-
*/
|
|
93
|
-
shouldWarnUser(currentTokens: number): boolean {
|
|
94
|
-
const report = this.getContextLevel(currentTokens);
|
|
95
|
-
return report.shouldWarn;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Gera relatório visual de contexto
|
|
100
|
-
*/
|
|
101
|
-
generateReport(currentTokens: number): string {
|
|
102
|
-
const report = this.getContextLevel(currentTokens);
|
|
103
|
-
|
|
104
|
-
let visual = '📊 NÍVEL DE CONTEXTO\\n';
|
|
105
|
-
visual += `${report.emoji} **${report.level.toUpperCase()}** (${report.percentage}%)\\n`;
|
|
106
|
-
visual += `\\n${report.warning}\\n`;
|
|
107
|
-
|
|
108
|
-
// Barra de progresso visual
|
|
109
|
-
visual += '\\n' + this.generateProgressBar(report.percentage);
|
|
110
|
-
|
|
111
|
-
if (report.shouldWarn) {
|
|
112
|
-
visual += '\\n\\n⚠️ **AÇÃO RECOMENDADA**: Considere iniciar nova conversa após completar a tarefa atual.';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return visual;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Gera barra de progresso ASCII
|
|
120
|
-
*/
|
|
121
|
-
private generateProgressBar(percentage: number): string {
|
|
122
|
-
const barLength = 30;
|
|
123
|
-
const filled = Math.round((percentage / 100) * barLength);
|
|
124
|
-
const empty = barLength - filled;
|
|
125
|
-
|
|
126
|
-
const bar = '█'.repeat(filled) + '░'.repeat(empty);
|
|
127
|
-
return `[${bar}] ${percentage}%`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Estima tokens após uma tarefa (útil para planejamento)
|
|
132
|
-
*/
|
|
133
|
-
estimateAfterTask(currentTokens: number, estimatedTaskTokens: number): ContextReport {
|
|
134
|
-
const projectedTokens = currentTokens + estimatedTaskTokens;
|
|
135
|
-
return this.getContextLevel(projectedTokens);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Singleton global (assume 200k tokens max para Gemini/Claude)
|
|
140
|
-
export const globalContextMonitor = new ContextMonitor(200000);
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feedback Collector - Coletor de Feedback do Usuário
|
|
3
|
-
*
|
|
4
|
-
* Responsabilidades:
|
|
5
|
-
* - Coletar feedback do usuário após tarefas
|
|
6
|
-
* - Registrar feedback na memória dos agentes
|
|
7
|
-
* - Analisar padrões em feedbacks
|
|
8
|
-
* - Gerar sugestões baseadas em histórico
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { MemorySystem, MemoryEntry } from './memory-system';
|
|
12
|
-
import { TaskContext } from './base-agent';
|
|
13
|
-
|
|
14
|
-
export interface UserFeedback {
|
|
15
|
-
taskId: string;
|
|
16
|
-
agentName: string;
|
|
17
|
-
satisfied: boolean;
|
|
18
|
-
likes: string[];
|
|
19
|
-
dislikes: string[];
|
|
20
|
-
suggestions: string[];
|
|
21
|
-
timestamp: Date;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface FeedbackPrompt {
|
|
25
|
-
question: string;
|
|
26
|
-
type: 'boolean' | 'text' | 'multipleChoice';
|
|
27
|
-
options?: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class FeedbackCollector {
|
|
31
|
-
private memory: MemorySystem;
|
|
32
|
-
|
|
33
|
-
constructor(memoryBasePath: string = '.agents/memory') {
|
|
34
|
-
this.memory = new MemorySystem(memoryBasePath);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Coleta feedback do usuário (simulado - em produção seria interativo)
|
|
39
|
-
*/
|
|
40
|
-
async collectFeedback(
|
|
41
|
-
taskId: string,
|
|
42
|
-
agentName: string,
|
|
43
|
-
taskDescription: string
|
|
44
|
-
): Promise<UserFeedback | null> {
|
|
45
|
-
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
46
|
-
console.log('📝 FEEDBACK DO USUÁRIO');
|
|
47
|
-
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
|
48
|
-
console.log(`Tarefa: ${taskDescription}`);
|
|
49
|
-
console.log(`Agente: ${agentName}\n`);
|
|
50
|
-
|
|
51
|
-
// Em produção, isso seria um prompt interativo
|
|
52
|
-
// Por enquanto, retornamos null para indicar que o feedback será coletado manualmente
|
|
53
|
-
console.log('💡 Para fornecer feedback, use o método provideFeedback()');
|
|
54
|
-
console.log(' Exemplo: feedbackCollector.provideFeedback(taskId, agentName, {...})\n');
|
|
55
|
-
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Fornece feedback manualmente
|
|
61
|
-
*/
|
|
62
|
-
async provideFeedback(feedback: UserFeedback): Promise<void> {
|
|
63
|
-
console.log(`\n✅ Feedback recebido para ${feedback.agentName}`);
|
|
64
|
-
console.log(` Satisfeito: ${feedback.satisfied ? '👍 Sim' : '👎 Não'}`);
|
|
65
|
-
|
|
66
|
-
if (feedback.likes.length > 0) {
|
|
67
|
-
console.log(` Gostou: ${feedback.likes.join(', ')}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (feedback.dislikes.length > 0) {
|
|
71
|
-
console.log(` Não gostou: ${feedback.dislikes.join(', ')}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (feedback.suggestions.length > 0) {
|
|
75
|
-
console.log(` Sugestões: ${feedback.suggestions.join(', ')}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Analisar feedback e gerar aprendizados
|
|
79
|
-
await this.analyzeFeedback(feedback);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Analisa feedback e gera aprendizados
|
|
84
|
-
*/
|
|
85
|
-
private async analyzeFeedback(feedback: UserFeedback): Promise<void> {
|
|
86
|
-
// Se não está satisfeito, criar aprendizado negativo
|
|
87
|
-
if (!feedback.satisfied && feedback.dislikes.length > 0) {
|
|
88
|
-
for (const dislike of feedback.dislikes) {
|
|
89
|
-
this.memory.addLearning(
|
|
90
|
-
feedback.agentName,
|
|
91
|
-
`Evitar: ${dislike}`,
|
|
92
|
-
`Usuário não gostou de: ${dislike}`,
|
|
93
|
-
`Evitar fazer: ${dislike}`,
|
|
94
|
-
[feedback.taskId]
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Se está satisfeito, criar aprendizado positivo
|
|
100
|
-
if (feedback.satisfied && feedback.likes.length > 0) {
|
|
101
|
-
for (const like of feedback.likes) {
|
|
102
|
-
this.memory.addLearning(
|
|
103
|
-
feedback.agentName,
|
|
104
|
-
`Repetir: ${like}`,
|
|
105
|
-
`Usuário gostou de: ${like}`,
|
|
106
|
-
`Continuar fazendo: ${like}`,
|
|
107
|
-
[feedback.taskId]
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Processar sugestões
|
|
113
|
-
if (feedback.suggestions.length > 0) {
|
|
114
|
-
for (const suggestion of feedback.suggestions) {
|
|
115
|
-
this.memory.addLearning(
|
|
116
|
-
feedback.agentName,
|
|
117
|
-
`Sugestão: ${suggestion}`,
|
|
118
|
-
`Usuário sugeriu: ${suggestion}`,
|
|
119
|
-
`Considerar implementar: ${suggestion}`,
|
|
120
|
-
[feedback.taskId]
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
console.log(`\n🧠 Aprendizados registrados para ${feedback.agentName}`);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Obtém padrões de feedback
|
|
130
|
-
*/
|
|
131
|
-
getFeedbackPatterns(agentName: string): {
|
|
132
|
-
commonLikes: string[];
|
|
133
|
-
commonDislikes: string[];
|
|
134
|
-
commonSuggestions: string[];
|
|
135
|
-
} {
|
|
136
|
-
const agentMemory = this.memory.loadMemory(agentName);
|
|
137
|
-
|
|
138
|
-
// Extrair padrões dos aprendizados
|
|
139
|
-
const likes = agentMemory.learnings
|
|
140
|
-
.filter(l => l.pattern.startsWith('Repetir:'))
|
|
141
|
-
.sort((a, b) => b.occurrences - a.occurrences)
|
|
142
|
-
.slice(0, 5)
|
|
143
|
-
.map(l => l.pattern.replace('Repetir: ', ''));
|
|
144
|
-
|
|
145
|
-
const dislikes = agentMemory.learnings
|
|
146
|
-
.filter(l => l.pattern.startsWith('Evitar:'))
|
|
147
|
-
.sort((a, b) => b.occurrences - a.occurrences)
|
|
148
|
-
.slice(0, 5)
|
|
149
|
-
.map(l => l.pattern.replace('Evitar: ', ''));
|
|
150
|
-
|
|
151
|
-
const suggestions = agentMemory.learnings
|
|
152
|
-
.filter(l => l.pattern.startsWith('Sugestão:'))
|
|
153
|
-
.sort((a, b) => b.occurrences - a.occurrences)
|
|
154
|
-
.slice(0, 5)
|
|
155
|
-
.map(l => l.pattern.replace('Sugestão: ', ''));
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
commonLikes: likes,
|
|
159
|
-
commonDislikes: dislikes,
|
|
160
|
-
commonSuggestions: suggestions,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Gera relatório de feedback
|
|
166
|
-
*/
|
|
167
|
-
generateFeedbackReport(agentName: string): string {
|
|
168
|
-
const patterns = this.getFeedbackPatterns(agentName);
|
|
169
|
-
const stats = this.memory.getStats(agentName);
|
|
170
|
-
|
|
171
|
-
let report = `\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;
|
|
172
|
-
report += `📊 RELATÓRIO DE FEEDBACK - ${agentName}\n`;
|
|
173
|
-
report += `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n`;
|
|
174
|
-
|
|
175
|
-
report += `📈 Estatísticas:\n`;
|
|
176
|
-
report += ` Total de tarefas: ${stats.totalTasks}\n`;
|
|
177
|
-
report += ` Taxa de sucesso: ${(stats.successRate * 100).toFixed(1)}%\n\n`;
|
|
178
|
-
|
|
179
|
-
if (patterns.commonLikes.length > 0) {
|
|
180
|
-
report += `👍 O que os usuários mais gostam:\n`;
|
|
181
|
-
patterns.commonLikes.forEach((like, i) => {
|
|
182
|
-
report += ` ${i + 1}. ${like}\n`;
|
|
183
|
-
});
|
|
184
|
-
report += `\n`;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (patterns.commonDislikes.length > 0) {
|
|
188
|
-
report += `👎 O que os usuários não gostam:\n`;
|
|
189
|
-
patterns.commonDislikes.forEach((dislike, i) => {
|
|
190
|
-
report += ` ${i + 1}. ${dislike}\n`;
|
|
191
|
-
});
|
|
192
|
-
report += `\n`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (patterns.commonSuggestions.length > 0) {
|
|
196
|
-
report += `💡 Sugestões recorrentes:\n`;
|
|
197
|
-
patterns.commonSuggestions.forEach((suggestion, i) => {
|
|
198
|
-
report += ` ${i + 1}. ${suggestion}\n`;
|
|
199
|
-
});
|
|
200
|
-
report += `\n`;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
report += `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;
|
|
204
|
-
|
|
205
|
-
return report;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { ImplementationPlan } from './planning-agent.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* File Generator - Gera código inteligente baseado em planos
|
|
7
|
-
*
|
|
8
|
-
* Responsabilidades:
|
|
9
|
-
* - Gerar componentes React/Next.js
|
|
10
|
-
* - Gerar APIs/endpoints
|
|
11
|
-
* - Gerar hooks customizados
|
|
12
|
-
* - Gerar tipos TypeScript
|
|
13
|
-
* - Modificar arquivos existentes
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export class FileGenerator {
|
|
17
|
-
private projectRoot: string;
|
|
18
|
-
|
|
19
|
-
constructor(projectRoot: string = process.cwd()) {
|
|
20
|
-
this.projectRoot = projectRoot;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Cria arquivo baseado no plano
|
|
25
|
-
*/
|
|
26
|
-
async createFile(
|
|
27
|
-
filePath: string,
|
|
28
|
-
type: 'component' | 'api' | 'hook' | 'util' | 'type' | 'config',
|
|
29
|
-
purpose: string,
|
|
30
|
-
plan: ImplementationPlan
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
const fullPath = path.join(this.projectRoot, filePath);
|
|
33
|
-
const dir = path.dirname(fullPath);
|
|
34
|
-
|
|
35
|
-
// Criar diretório se não existir
|
|
36
|
-
if (!fs.existsSync(dir)) {
|
|
37
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Gerar conteúdo baseado no tipo
|
|
41
|
-
let content = '';
|
|
42
|
-
|
|
43
|
-
switch (type) {
|
|
44
|
-
case 'component':
|
|
45
|
-
content = this.generateComponent(filePath, purpose, plan);
|
|
46
|
-
break;
|
|
47
|
-
case 'api':
|
|
48
|
-
content = this.generateAPI(filePath, purpose, plan);
|
|
49
|
-
break;
|
|
50
|
-
case 'hook':
|
|
51
|
-
content = this.generateHook(filePath, purpose, plan);
|
|
52
|
-
break;
|
|
53
|
-
case 'util':
|
|
54
|
-
content = this.generateUtil(filePath, purpose);
|
|
55
|
-
break;
|
|
56
|
-
case 'type':
|
|
57
|
-
content = this.generateType(filePath, purpose);
|
|
58
|
-
break;
|
|
59
|
-
case 'config':
|
|
60
|
-
content = this.generateConfig(filePath, purpose);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Escrever arquivo
|
|
65
|
-
fs.writeFileSync(fullPath, content, 'utf-8');
|
|
66
|
-
console.log(` ✨ Criado: ${filePath}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Modifica arquivo existente
|
|
71
|
-
*/
|
|
72
|
-
async modifyFile(filePath: string, changes: string): Promise<void> {
|
|
73
|
-
const fullPath = path.join(this.projectRoot, filePath);
|
|
74
|
-
|
|
75
|
-
if (!fs.existsSync(fullPath)) {
|
|
76
|
-
console.warn(` ⚠️ Arquivo não existe: ${filePath}`);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
81
|
-
|
|
82
|
-
// Aqui seria ideal ter lógica mais sofisticada de modificação
|
|
83
|
-
// Por enquanto, apenas adiciona comentário indicando mudança necessária
|
|
84
|
-
const modifiedContent = content + `\n\n// TODO: ${changes}\n`;
|
|
85
|
-
|
|
86
|
-
fs.writeFileSync(fullPath, modifiedContent, 'utf-8');
|
|
87
|
-
console.log(` ✏️ Modificado: ${filePath}`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Gera componente React
|
|
92
|
-
*/
|
|
93
|
-
private generateComponent(filePath: string, purpose: string, plan: ImplementationPlan): string {
|
|
94
|
-
const componentName = path.basename(filePath, '.tsx');
|
|
95
|
-
const hasAuth = plan.architecture.components.some(c => c.includes('Auth'));
|
|
96
|
-
|
|
97
|
-
return `'use client';
|
|
98
|
-
|
|
99
|
-
import { FC } from 'react';
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* ${componentName}
|
|
103
|
-
*
|
|
104
|
-
* ${purpose}
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
interface ${componentName}Props {
|
|
108
|
-
// TODO: Adicionar props necessárias
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const ${componentName}: FC<${componentName}Props> = (props) => {
|
|
112
|
-
return (
|
|
113
|
-
<div className="p-4">
|
|
114
|
-
<h2 className="text-2xl font-bold">${componentName}</h2>
|
|
115
|
-
{/* TODO: Implementar UI */}
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export default ${componentName};
|
|
121
|
-
`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Gera API route
|
|
126
|
-
*/
|
|
127
|
-
private generateAPI(filePath: string, purpose: string, plan: ImplementationPlan): string {
|
|
128
|
-
const hasDatabase = plan.architecture.database.length > 0;
|
|
129
|
-
|
|
130
|
-
return `import { NextRequest, NextResponse } from 'next/server';
|
|
131
|
-
${hasDatabase ? "import { createClient } from '@/lib/supabase/server';" : ''}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* ${purpose}
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
export async function GET(request: NextRequest) {
|
|
138
|
-
try {
|
|
139
|
-
${hasDatabase ? `
|
|
140
|
-
const supabase = createClient();
|
|
141
|
-
|
|
142
|
-
// TODO: Implementar query
|
|
143
|
-
const { data, error } = await supabase
|
|
144
|
-
.from('table_name')
|
|
145
|
-
.select('*');
|
|
146
|
-
|
|
147
|
-
if (error) throw error;
|
|
148
|
-
` : `
|
|
149
|
-
// TODO: Implementar lógica
|
|
150
|
-
const data = { message: 'Success' };
|
|
151
|
-
`}
|
|
152
|
-
|
|
153
|
-
return NextResponse.json(data);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error('API Error:', error);
|
|
156
|
-
return NextResponse.json(
|
|
157
|
-
{ error: 'Internal Server Error' },
|
|
158
|
-
{ status: 500 }
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function POST(request: NextRequest) {
|
|
164
|
-
try {
|
|
165
|
-
const body = await request.json();
|
|
166
|
-
|
|
167
|
-
${hasDatabase ? `
|
|
168
|
-
const supabase = createClient();
|
|
169
|
-
|
|
170
|
-
// TODO: Implementar insert/update
|
|
171
|
-
const { data, error } = await supabase
|
|
172
|
-
.from('table_name')
|
|
173
|
-
.insert(body)
|
|
174
|
-
.select()
|
|
175
|
-
.single();
|
|
176
|
-
|
|
177
|
-
if (error) throw error;
|
|
178
|
-
` : `
|
|
179
|
-
// TODO: Implementar lógica
|
|
180
|
-
const data = { success: true, ...body };
|
|
181
|
-
`}
|
|
182
|
-
|
|
183
|
-
return NextResponse.json(data);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.error('API Error:', error);
|
|
186
|
-
return NextResponse.json(
|
|
187
|
-
{ error: 'Internal Server Error' },
|
|
188
|
-
{ status: 500 }
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Gera hook customizado
|
|
197
|
-
*/
|
|
198
|
-
private generateHook(filePath: string, purpose: string, plan: ImplementationPlan): string {
|
|
199
|
-
const hookName = path.basename(filePath, '.ts');
|
|
200
|
-
|
|
201
|
-
return `import { useState, useEffect } from 'react';
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* ${hookName}
|
|
205
|
-
*
|
|
206
|
-
* ${purpose}
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
|
-
export function ${hookName}() {
|
|
210
|
-
const [data, setData] = useState<any>(null);
|
|
211
|
-
const [loading, setLoading] = useState(true);
|
|
212
|
-
const [error, setError] = useState<Error | null>(null);
|
|
213
|
-
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
async function fetchData() {
|
|
216
|
-
try {
|
|
217
|
-
setLoading(true);
|
|
218
|
-
|
|
219
|
-
// TODO: Implementar lógica
|
|
220
|
-
const response = await fetch('/api/endpoint');
|
|
221
|
-
const result = await response.json();
|
|
222
|
-
|
|
223
|
-
setData(result);
|
|
224
|
-
} catch (err) {
|
|
225
|
-
setError(err as Error);
|
|
226
|
-
} finally {
|
|
227
|
-
setLoading(false);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
fetchData();
|
|
232
|
-
}, []);
|
|
233
|
-
|
|
234
|
-
return { data, loading, error };
|
|
235
|
-
}
|
|
236
|
-
`;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Gera arquivo de utilidades
|
|
241
|
-
*/
|
|
242
|
-
private generateUtil(filePath: string, purpose: string): string {
|
|
243
|
-
return `/**
|
|
244
|
-
* Utilities
|
|
245
|
-
*
|
|
246
|
-
* ${purpose}
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
export function exampleUtil(input: string): string {
|
|
250
|
-
// TODO: Implementar lógica
|
|
251
|
-
return input;
|
|
252
|
-
}
|
|
253
|
-
`;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Gera arquivo de tipos
|
|
258
|
-
*/
|
|
259
|
-
private generateType(filePath: string, purpose: string): string {
|
|
260
|
-
return `/**
|
|
261
|
-
* Types
|
|
262
|
-
*
|
|
263
|
-
* ${purpose}
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
export interface ExampleType {
|
|
267
|
-
id: string;
|
|
268
|
-
// TODO: Adicionar campos
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export type ExampleUnion = 'option1' | 'option2';
|
|
272
|
-
`;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Gera arquivo de configuração
|
|
277
|
-
*/
|
|
278
|
-
private generateConfig(filePath: string, purpose: string): string {
|
|
279
|
-
return `/**
|
|
280
|
-
* Configuration
|
|
281
|
-
*
|
|
282
|
-
* ${purpose}
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
export const config = {
|
|
286
|
-
// TODO: Adicionar configurações
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
export default config;
|
|
290
|
-
`;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Deleta arquivo
|
|
295
|
-
*/
|
|
296
|
-
async deleteFile(filePath: string): Promise<void> {
|
|
297
|
-
const fullPath = path.join(this.projectRoot, filePath);
|
|
298
|
-
|
|
299
|
-
if (fs.existsSync(fullPath)) {
|
|
300
|
-
fs.unlinkSync(fullPath);
|
|
301
|
-
console.log(` 🗑️ Deletado: ${filePath}`);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|