agent-master-devsecops 0.0.0-stage → 5.1.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/README.md +204 -2
- package/agents/AGENT_DEVSECOPS.md +32 -0
- package/agents/AGENT_INFRA.md +31 -0
- package/agents/AGENT_ORCHESTRATOR.md +39 -0
- package/agents/AGENT_QA.md +58 -0
- package/agents/AGENT_SCRUM.md +23 -0
- package/agents/AGENT_SRE.md +22 -0
- package/agents/AGENT_UIUX.md +26 -0
- package/docs/ARCHITECTURE.md +152 -0
- package/docs/CALCULATIONS.md +17 -0
- package/docs/CHANGELOG.md +112 -0
- package/docs/ENGINEERING_RULES.md +56 -0
- package/docs/IDEAS.md +17 -0
- package/docs/LOCAL_BACKLOG.md +20 -0
- package/docs/STATE.md +111 -0
- package/docs/playbooks/PLAYBOOK_CIRCUIT_BREAKER_LLM.md +58 -0
- package/docs/playbooks/PLAYBOOK_OPENTELEMETRY_TRACING.md +58 -0
- package/package.json +57 -4
- package/scripts/auditors/a11y_auditor.js +462 -0
- package/scripts/auditors/code_quality_auditor.js +444 -0
- package/scripts/auditors/contract_test_validator.js +396 -0
- package/scripts/auditors/eval_harness.js +213 -0
- package/scripts/auditors/git_hygiene_linter.js +391 -0
- package/scripts/auditors/pr_reviewer.js +627 -0
- package/scripts/auditors/sast_scanner.js +442 -0
- package/scripts/auditors/sca_dependency_auditor.js +673 -0
- package/scripts/bin/bootstrap_cli.js +597 -0
- package/scripts/bin/domain_idea_miner.js +658 -0
- package/scripts/bin/smart_onboarding.js +905 -0
- package/scripts/bin/web_inspector.js +578 -0
- package/scripts/core/architecture_advisor.js +378 -0
- package/scripts/core/ast_skeletonizer.js +413 -0
- package/scripts/core/autonomous_remediation_engine.js +305 -0
- package/scripts/core/circuit_breaker.js +546 -0
- package/scripts/core/context_compressor.js +237 -0
- package/scripts/core/fast_feature_scaffold.js +840 -0
- package/scripts/core/hot_state_cache.js +238 -0
- package/scripts/core/knowledge_gateway.js +888 -0
- package/scripts/core/magic_prompt_generator.js +250 -0
- package/scripts/core/multi_agent_orchestrator.js +421 -0
- package/scripts/core/otel_tracer.js +335 -0
- package/scripts/core/perf_benchmark.js +212 -0
- package/scripts/core/sarif_engine.js +299 -0
- package/scripts/core/sre_remediation_engine.js +236 -0
- package/scripts/core/universal_packager.js +357 -0
- package/scripts/integrations/atlassian_client.js +600 -0
- package/scripts/integrations/atlassian_sync_action.js +576 -0
- package/scripts/integrations/confluence_sync.js +684 -0
- package/scripts/integrations/credentials_guard.js +500 -0
- package/scripts/integrations/jira_manager.js +722 -0
- package/scripts/mcp/handlers/atlassian_handlers.js +300 -0
- package/scripts/mcp/handlers/core_handlers.js +419 -0
- package/scripts/mcp/handlers/qa_handlers.js +502 -0
- package/scripts/mcp/handlers/rules_handlers.js +379 -0
- package/scripts/mcp/handlers/scaffold_handlers.js +334 -0
- package/scripts/mcp/handlers/sre_handlers.js +443 -0
- package/scripts/mcp/resources_registry.js +453 -0
- package/scripts/mcp/server.js +408 -0
- package/scripts/mcp/tool_handlers.js +444 -0
- package/scripts/mcp/tools_registry.js +1123 -0
- package/scripts/mcp_server.js +236 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* scripts/core/magic_prompt_generator.js
|
|
4
|
+
*
|
|
5
|
+
* Magic Prompt Generator & Web Bookmarklet (AGDEV-27 / v5.1.0 Enterprise).
|
|
6
|
+
* Gera prompt autocontido de ativação instantânea (< 900 tokens) e bookmarklet
|
|
7
|
+
* web para injeção em 1 clique no ChatGPT, Claude.ai, Gemini e DeepSeek Web.
|
|
8
|
+
* Em conformidade estrita com os 10 Princípios Canônicos de Engenharia e Tríplice Registro.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const path = require('node:path');
|
|
15
|
+
const { createSarifReport } = require('./sarif_engine.js');
|
|
16
|
+
|
|
17
|
+
class MagicPromptGenerator {
|
|
18
|
+
constructor(baseDir = path.resolve(__dirname, '../..')) {
|
|
19
|
+
this.baseDir = baseDir;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
generateMagicPrompt(target = 'generic') {
|
|
23
|
+
const prompt = `=== AGENT ORCHESTRATOR & SUÍTE MULTI-AGENTE (UNIVERSAL INSTANT ACTIVATION) ===
|
|
24
|
+
[DIRECTIVE]: You are now running the canonical Agent Suite (Orchestrator, DevSecOps, QA, Scrum, SRE, UI/UX & Infra Engineer). Assume 100% adherence to the 10 Canonical Engineering Principles (v5.1 Enterprise) and rules below:
|
|
25
|
+
|
|
26
|
+
[THE 14 GOLDEN ENGINEERING RULES & 10 CANONICAL PRINCIPLES]:
|
|
27
|
+
1. Code Quality & Clean Architecture: DRY, defensive programming, explicit contracts and typed interfaces.
|
|
28
|
+
2. DevSecOps Shift-Left: Immune to OWASP Top 10 (CWE-78, CWE-79, CWE-89, CWE-1333 ReDoS); zero secrets in commits.
|
|
29
|
+
3. Triple Ledger Traceability: Dedicated branch per ticket (<TICKET>), formatted commits, Kanban sync and ADRs.
|
|
30
|
+
4. TDD & Strict DoD: Automated tests (unit, integration, regression) written before/alongside implementation.
|
|
31
|
+
5. Exception Handling & Resilience: No empty catches; graceful circuit breaking and resilient fallbacks.
|
|
32
|
+
6. Observabilidade & SRE: Prometheus metrics (/metrics), process telemetry and W3C TraceContext headers.
|
|
33
|
+
7. Value Engineering & Anti-Overengineering: Proportionate solutions without accidental complexity or premature microservices.
|
|
34
|
+
8. Requirements Engineering & Invariant Acceptance Criteria: BDD Given-When-Then criteria remain immutable unless explicitly approved.
|
|
35
|
+
9. Justified Technical Decision (Anti-Hype & ADRs): Formal trade-off evaluation documented in Confluence/Markdown ADRs.
|
|
36
|
+
10. Continuous Kaizen: Root cause analysis on any defect; prevent recurrent regression autonomously.
|
|
37
|
+
|
|
38
|
+
[OPERATIONAL MODES]:
|
|
39
|
+
- modo: orchestrator (central coordination, triage and multi-agent dispatch)
|
|
40
|
+
- modo: devsecops (secure, robust code, clean architecture and CI/CD)
|
|
41
|
+
- modo: qa (adversarial cold review, bug hunting and breaking tests)
|
|
42
|
+
- modo: scrum (Kaizen/PDCA continuous improvement without overengineering)
|
|
43
|
+
- modo: sre (SRE, telemetry, incident diagnosis and self-healing)
|
|
44
|
+
- modo: uiux (design system, accessibility WCAG 2.1 AA, UX ergonomics, design tokens)
|
|
45
|
+
- modo: infra (real networking, containers, Docker, Cloudflare Tunnel and CI/CD)
|
|
46
|
+
- modo: full-dev (autonomous sequential idea implementation loop)
|
|
47
|
+
|
|
48
|
+
[ACTIVATION ACKNOWLEDGEMENT]:
|
|
49
|
+
Acknowledge activation with a 2-line executive greeting:
|
|
50
|
+
"⚡ Suíte Multi-Agente universalmente ativada e pronta para qualquer demanda.
|
|
51
|
+
Informe a stack e solicite credenciais Atlassian (Jira/Confluence) e GitHub CLI se for nova máquina ou projeto."`;
|
|
52
|
+
|
|
53
|
+
return prompt;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
generateBookmarklet() {
|
|
57
|
+
const rawPrompt = this.generateMagicPrompt();
|
|
58
|
+
const encodedPrompt = JSON.stringify(rawPrompt);
|
|
59
|
+
|
|
60
|
+
// Bookmarklet inline seguro que detecta o campo de chat e copia para o clipboard
|
|
61
|
+
const script = `javascript:(function(){
|
|
62
|
+
var promptText = ${encodedPrompt};
|
|
63
|
+
|
|
64
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
65
|
+
navigator.clipboard.writeText(promptText).then(function() {
|
|
66
|
+
showToast("⚡ Suíte Multi-Agente copiada! Cole (Ctrl+V) no chat da IA.");
|
|
67
|
+
}).catch(function() {
|
|
68
|
+
fallbackPrompt(promptText);
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
fallbackPrompt(promptText);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var inputEl = document.querySelector('#prompt-textarea') ||
|
|
75
|
+
document.querySelector('div[contenteditable="true"]') ||
|
|
76
|
+
document.querySelector('textarea');
|
|
77
|
+
if (inputEl) {
|
|
78
|
+
if (inputEl.tagName === 'TEXTAREA') {
|
|
79
|
+
inputEl.value = promptText;
|
|
80
|
+
inputEl.dispatchEvent(new Event('input', { bubbles: true }));
|
|
81
|
+
} else if (inputEl.isContentEditable) {
|
|
82
|
+
inputEl.innerText = promptText;
|
|
83
|
+
inputEl.dispatchEvent(new Event('input', { bubbles: true }));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function showToast(msg) {
|
|
88
|
+
var toast = document.createElement('div');
|
|
89
|
+
toast.innerText = msg;
|
|
90
|
+
toast.style.position = 'fixed';
|
|
91
|
+
toast.style.top = '20px';
|
|
92
|
+
toast.style.right = '20px';
|
|
93
|
+
toast.style.backgroundColor = '#0f172a';
|
|
94
|
+
toast.style.color = '#38bdf8';
|
|
95
|
+
toast.style.padding = '14px 20px';
|
|
96
|
+
toast.style.borderRadius = '8px';
|
|
97
|
+
toast.style.boxShadow = '0 10px 25px rgba(0,0,0,0.5)';
|
|
98
|
+
toast.style.zIndex = '999999';
|
|
99
|
+
toast.style.fontFamily = 'system-ui, sans-serif';
|
|
100
|
+
toast.style.fontSize = '14px';
|
|
101
|
+
toast.style.border = '1px solid #38bdf8';
|
|
102
|
+
document.body.appendChild(toast);
|
|
103
|
+
setTimeout(function() { toast.remove(); }, 3500);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function fallbackPrompt(text) {
|
|
107
|
+
window.prompt("Copie o Magic Prompt abaixo:", text);
|
|
108
|
+
}
|
|
109
|
+
})();`.replace(/\n\s*/g, '');
|
|
110
|
+
|
|
111
|
+
return script;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
estimateTokens(text = '') {
|
|
115
|
+
if (!text || typeof text !== 'string') return 0;
|
|
116
|
+
return Math.ceil(text.length / 4);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
exportArtifacts(targetDir = path.join(this.baseDir, 'dist', 'magic_prompt'), options = {}) {
|
|
120
|
+
const dryRun = Boolean(options.dryRun);
|
|
121
|
+
const magicPrompt = this.generateMagicPrompt();
|
|
122
|
+
const bookmarklet = this.generateBookmarklet();
|
|
123
|
+
const tokens = this.estimateTokens(magicPrompt);
|
|
124
|
+
|
|
125
|
+
const htmlContent = `<!DOCTYPE html>
|
|
126
|
+
<html lang="pt-BR">
|
|
127
|
+
<head>
|
|
128
|
+
<meta charset="UTF-8">
|
|
129
|
+
<title>Suíte Multi-Agente — Magic Prompt & Bookmarklet</title>
|
|
130
|
+
<style>
|
|
131
|
+
body { font-family: system-ui, -apple-system, sans-serif; background: #0f172a; color: #f8fafc; padding: 40px; line-height: 1.6; }
|
|
132
|
+
.card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 24px; max-width: 800px; margin: 0 auto 30px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); }
|
|
133
|
+
h1 { color: #38bdf8; margin-top: 0; }
|
|
134
|
+
pre { background: #090d16; padding: 16px; border-radius: 8px; overflow-x: auto; font-size: 13px; color: #cbd5e1; border: 1px solid #1e293b; }
|
|
135
|
+
.btn { display: inline-block; background: #0284c7; color: white; padding: 12px 20px; border-radius: 8px; text-decoration: none; font-weight: bold; cursor: grab; }
|
|
136
|
+
.btn:hover { background: #0369a1; }
|
|
137
|
+
</style>
|
|
138
|
+
</head>
|
|
139
|
+
<body>
|
|
140
|
+
<div class="card">
|
|
141
|
+
<h1>⚡ Suíte Multi-Agente — Ativação Instantânea</h1>
|
|
142
|
+
<p>Arraste o botão abaixo para a sua <strong>Barra de Favoritos</strong> do navegador. Ao clicar nele em qualquer aba do ChatGPT, Claude, Gemini ou DeepSeek, a suíte de agentes será ativada instantaneamente!</p>
|
|
143
|
+
<p style="margin: 30px 0;">
|
|
144
|
+
<a class="btn" href="${bookmarklet}">⚡ Ativar Suíte Multi-Agente</a>
|
|
145
|
+
</p>
|
|
146
|
+
<small style="color: #94a3b8;">Dica: você também pode clicar com o botão direito e selecionar "Adicionar aos favoritos".</small>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<div class="card">
|
|
150
|
+
<h2>📋 Magic Prompt (Cópia Manual — ~${tokens} tokens)</h2>
|
|
151
|
+
<pre id="promptText">${magicPrompt.replace(/</g, '<').replace(/>/g, '>')}</pre>
|
|
152
|
+
</div>
|
|
153
|
+
</body>
|
|
154
|
+
</html>`;
|
|
155
|
+
|
|
156
|
+
const mdContent = `# ⚡ Magic Prompt — Ativação Instantânea da Suíte Multi-Agente
|
|
157
|
+
|
|
158
|
+
Copie o bloco abaixo e cole como primeira mensagem em **qualquer LLM** (ChatGPT, Claude.ai, Gemini, DeepSeek Web, Ollama ou LeChat) para assumir imediatamente 100% dos 10 Princípios Canônicos de Engenharia:
|
|
159
|
+
|
|
160
|
+
\`\`\`text
|
|
161
|
+
${magicPrompt}
|
|
162
|
+
\`\`\`
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
*Orçamento semântico: ~${tokens} tokens (limite estrito de 1.000 tokens respeitado com 100% de conformidade).*
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
const files = [
|
|
169
|
+
{ path: path.join(targetDir, 'MAGIC_PROMPT.md'), content: mdContent },
|
|
170
|
+
{ path: path.join(targetDir, 'bookmarklet.html'), content: htmlContent }
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
if (!dryRun) {
|
|
174
|
+
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
|
|
175
|
+
files.forEach(f => fs.writeFileSync(f.path, f.content, 'utf8'));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
status: 'SUCCESS',
|
|
180
|
+
targetDir,
|
|
181
|
+
tokens,
|
|
182
|
+
dryRun,
|
|
183
|
+
filesCount: files.length,
|
|
184
|
+
files: files.map(f => f.path),
|
|
185
|
+
magicPrompt,
|
|
186
|
+
bookmarklet
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
auditToSarif() {
|
|
191
|
+
const magicPrompt = this.generateMagicPrompt();
|
|
192
|
+
const tokens = this.estimateTokens(magicPrompt);
|
|
193
|
+
const findings = [];
|
|
194
|
+
|
|
195
|
+
if (tokens > 1000) {
|
|
196
|
+
findings.push({
|
|
197
|
+
ruleId: 'RULE-MAGIC-001',
|
|
198
|
+
name: 'MagicPromptBudgetExceeded',
|
|
199
|
+
severity: 'WARNING',
|
|
200
|
+
message: `O Magic Prompt excedeu o teto estrito de 1.000 tokens (atual: ${tokens} tokens).`,
|
|
201
|
+
remediation: 'Mantenha o prompt enxuto e hiper-focado.'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return createSarifReport({
|
|
206
|
+
toolName: 'agent-master-magic-prompt-generator',
|
|
207
|
+
rules: [
|
|
208
|
+
{
|
|
209
|
+
id: 'RULE-MAGIC-001',
|
|
210
|
+
name: 'MagicPromptBudgetExceeded',
|
|
211
|
+
description: 'Valida se o Magic Prompt cabe no orçamento estrito de < 1.000 tokens',
|
|
212
|
+
severity: 'MEDIUM',
|
|
213
|
+
cwe: 'CWE-400'
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
findings,
|
|
217
|
+
properties: {
|
|
218
|
+
tokens,
|
|
219
|
+
underBudget: tokens <= 1000
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
formatReport() {
|
|
225
|
+
const prompt = this.generateMagicPrompt();
|
|
226
|
+
const tokens = this.estimateTokens(prompt);
|
|
227
|
+
return [
|
|
228
|
+
'### Relatório do Gerador de Magic Prompt & Bookmarklet',
|
|
229
|
+
`- **Tokens:** ~${tokens} tokens (< 1.000 tokens)`,
|
|
230
|
+
`- **Bookmarklet:** Gerado com injeção automática e fallback`,
|
|
231
|
+
`- **Conformidade:** 10 Princípios Canônicos Universais (v5.1)`
|
|
232
|
+
].join('\n');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (require.main === module) {
|
|
237
|
+
const generator = new MagicPromptGenerator();
|
|
238
|
+
const res = generator.exportArtifacts();
|
|
239
|
+
console.log('\n============================================================');
|
|
240
|
+
console.log('⚡ Magic Prompt Generator & Web Bookmarklet (AGDEV-27)');
|
|
241
|
+
console.log('============================================================\n');
|
|
242
|
+
console.log(`✅ Arquivos exportados com sucesso em: ${res.targetDir}`);
|
|
243
|
+
console.log(`📊 Orçamento de Tokens Estimado: ~${res.tokens} tokens (< 1.000 tokens)`);
|
|
244
|
+
console.log(`📄 Arquivos gerados:`, res.files.join(', '));
|
|
245
|
+
console.log('\nO bookmarklet HTML e o MAGIC_PROMPT.md estão prontos para uso!\n');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
module.exports = {
|
|
249
|
+
MagicPromptGenerator
|
|
250
|
+
};
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Agent Event Bus & Orchestration Engine
|
|
3
|
+
* Topologia de cooperação determinística, barramento de eventos lógicos
|
|
4
|
+
* e handovers automáticos entre os 6 modos da suíte multi-agente.
|
|
5
|
+
* Conforme especificado em docs/ARCHITECTURE.md.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const crypto = require('node:crypto');
|
|
11
|
+
const { SECURITY_RULES } = require('../auditors/sast_scanner.js');
|
|
12
|
+
const { createSarifReport } = require('./sarif_engine.js');
|
|
13
|
+
|
|
14
|
+
// Definição canônica dos 7 modos / personas oficiais (+ full-dev)
|
|
15
|
+
const AGENT_PERSONAS = {
|
|
16
|
+
ORCHESTRATOR: 'modo: orchestrator',
|
|
17
|
+
UIUX: 'modo: uiux',
|
|
18
|
+
DEVSECOPS: 'modo: devsecops',
|
|
19
|
+
QA: 'modo: qa',
|
|
20
|
+
SCRUM: 'modo: scrum',
|
|
21
|
+
SRE: 'modo: sre',
|
|
22
|
+
INFRA: 'modo: infra',
|
|
23
|
+
FULL_DEV: 'modo: full-dev'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Definição canônica dos eventos de barramento
|
|
27
|
+
const EVENT_TYPES = {
|
|
28
|
+
EVENT_REQUIREMENTS_READY: 'EVENT_REQUIREMENTS_READY',
|
|
29
|
+
EVENT_DESIGN_READY: 'EVENT_DESIGN_READY',
|
|
30
|
+
EVENT_UI_REVIEW: 'EVENT_UI_REVIEW',
|
|
31
|
+
EVENT_CODE_COMPLETE: 'EVENT_CODE_COMPLETE',
|
|
32
|
+
EVENT_REVIEW_FAILED: 'EVENT_REVIEW_FAILED',
|
|
33
|
+
EVENT_REVIEW_PASSED: 'EVENT_REVIEW_PASSED',
|
|
34
|
+
EVENT_METRIC_ANOMALY: 'EVENT_METRIC_ANOMALY',
|
|
35
|
+
EVENT_REFACTOR_PROPOSAL: 'EVENT_REFACTOR_PROPOSAL',
|
|
36
|
+
EVENT_AGENT_SELF_IMPROVE: 'EVENT_AGENT_SELF_IMPROVE',
|
|
37
|
+
EVENT_KANBAN_DISPATCH: 'EVENT_KANBAN_DISPATCH',
|
|
38
|
+
EVENT_INFRA_PROVISIONED: 'EVENT_INFRA_PROVISIONED'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
class MultiAgentOrchestrator {
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.history = [];
|
|
44
|
+
this.subscribers = new Map();
|
|
45
|
+
this.storagePath = typeof options === 'string' ? options : (options?.storagePath || null);
|
|
46
|
+
this.db = null;
|
|
47
|
+
this._initDatabase(this.storagePath);
|
|
48
|
+
this._setupDefaultRoutes();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_initDatabase(storagePath) {
|
|
52
|
+
try {
|
|
53
|
+
const { DatabaseSync } = require('node:sqlite');
|
|
54
|
+
if (storagePath) {
|
|
55
|
+
const dir = path.dirname(storagePath);
|
|
56
|
+
if (dir && !fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
this.db = new DatabaseSync(storagePath);
|
|
58
|
+
} else {
|
|
59
|
+
this.db = new DatabaseSync(':memory:');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.db.exec(`
|
|
63
|
+
CREATE TABLE IF NOT EXISTS event_log (
|
|
64
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
65
|
+
event_id TEXT UNIQUE,
|
|
66
|
+
event_type TEXT,
|
|
67
|
+
timestamp TEXT,
|
|
68
|
+
payload_json TEXT,
|
|
69
|
+
result_json TEXT
|
|
70
|
+
);
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_event_type ON event_log(event_type);
|
|
72
|
+
`);
|
|
73
|
+
|
|
74
|
+
// Se existir histórico prévio persistido no banco, carrega na memória
|
|
75
|
+
const rows = this.db.prepare('SELECT * FROM event_log ORDER BY id ASC').all();
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
try {
|
|
78
|
+
this.history.push({
|
|
79
|
+
eventId: row.event_id,
|
|
80
|
+
eventType: row.event_type,
|
|
81
|
+
timestamp: row.timestamp,
|
|
82
|
+
payload: JSON.parse(row.payload_json || '{}'),
|
|
83
|
+
result: JSON.parse(row.result_json || '{}')
|
|
84
|
+
});
|
|
85
|
+
} catch (parseErr) {
|
|
86
|
+
void parseErr;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch (_) {
|
|
90
|
+
// Fallback transparente para armazenamento puramente em memória
|
|
91
|
+
this.db = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_setupDefaultRoutes() {
|
|
96
|
+
// Rota 0A: EVENT_REQUIREMENTS_READY (Orchestrator/Scrum -> UIUX)
|
|
97
|
+
this.on(EVENT_TYPES.EVENT_REQUIREMENTS_READY, (payload) => {
|
|
98
|
+
return {
|
|
99
|
+
handoffTo: AGENT_PERSONAS.UIUX,
|
|
100
|
+
status: 'READY_FOR_DESIGN',
|
|
101
|
+
reason: 'Requisitos funcionais homologados; necessário design visual e acessibilidade.',
|
|
102
|
+
nextAction: 'UIUX elabora jornada, tokens e especificações WCAG 2.1 AA.',
|
|
103
|
+
requiresFix: false
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Rota 0B: EVENT_DESIGN_READY (UIUX -> DevSecOps)
|
|
108
|
+
this.on(EVENT_TYPES.EVENT_DESIGN_READY, (payload) => {
|
|
109
|
+
return {
|
|
110
|
+
handoffTo: AGENT_PERSONAS.DEVSECOPS,
|
|
111
|
+
status: 'READY_FOR_IMPLEMENTATION',
|
|
112
|
+
reason: 'Especificações visuais, design tokens e estados de componentes concluídos.',
|
|
113
|
+
nextAction: 'DevSecOps implementa código semântico aderente aos tokens e contratos.',
|
|
114
|
+
requiresFix: false
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Rota 0C: EVENT_UI_REVIEW (QA -> UIUX)
|
|
119
|
+
this.on(EVENT_TYPES.EVENT_UI_REVIEW, (payload) => {
|
|
120
|
+
const a11yPassed = payload.a11yPassed !== false;
|
|
121
|
+
return {
|
|
122
|
+
handoffTo: AGENT_PERSONAS.UIUX,
|
|
123
|
+
status: a11yPassed ? 'A11Y_APPROVED' : 'A11Y_REJECTED',
|
|
124
|
+
reason: a11yPassed ? 'Auditoria de acessibilidade WCAG aprovada.' : 'Violação de contraste ou semântica ARIA detectada.',
|
|
125
|
+
nextAction: a11yPassed ? 'Tokens e componentes homologados.' : 'UIUX deve reajustar contraste e hierarquia visual.',
|
|
126
|
+
requiresFix: !a11yPassed
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Rota 0D: EVENT_INFRA_PROVISIONED (Infra -> DevSecOps / SRE)
|
|
131
|
+
this.on(EVENT_TYPES.EVENT_INFRA_PROVISIONED, (payload) => {
|
|
132
|
+
return {
|
|
133
|
+
handoffTo: AGENT_PERSONAS.DEVSECOPS,
|
|
134
|
+
status: 'INFRA_READY',
|
|
135
|
+
reason: 'Infraestrutura de CI/CD, containers e OTLP devidamente provisionados.',
|
|
136
|
+
nextAction: 'DevSecOps valida deployment local e SRE conecta monitoramento Prometheus.',
|
|
137
|
+
requiresFix: false
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Rota 1: EVENT_CODE_COMPLETE (DevSecOps -> QA)
|
|
142
|
+
this.on(EVENT_TYPES.EVENT_CODE_COMPLETE, (payload) => {
|
|
143
|
+
const codeOrDiff = payload.diff || payload.code || '';
|
|
144
|
+
const hasTests = codeOrDiff.includes('test') || payload.testsPassing === true;
|
|
145
|
+
const hasSecrets = SECURITY_RULES.some(r => r.cwe === 'CWE-798' && r.pattern.test(codeOrDiff));
|
|
146
|
+
|
|
147
|
+
if (hasSecrets) {
|
|
148
|
+
return {
|
|
149
|
+
handoffTo: AGENT_PERSONAS.QA,
|
|
150
|
+
status: 'REJECTED',
|
|
151
|
+
reason: 'Credencial ou segredo em texto plano detectado no diff (Regra 5).',
|
|
152
|
+
nextAction: 'QA emite veto e exige expurgo imediato.',
|
|
153
|
+
requiresFix: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!hasTests) {
|
|
158
|
+
return {
|
|
159
|
+
handoffTo: AGENT_PERSONAS.QA,
|
|
160
|
+
status: 'REJECTED',
|
|
161
|
+
reason: 'Entrega de código sem testes automatizados comprovados (Regra 4).',
|
|
162
|
+
nextAction: 'QA exige inclusão de testes unitários antes de qualquer aprovação.',
|
|
163
|
+
requiresFix: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
handoffTo: AGENT_PERSONAS.QA,
|
|
169
|
+
status: 'READY_FOR_INSPECTION',
|
|
170
|
+
reason: 'Código submetido à auditoria cética adversária.',
|
|
171
|
+
nextAction: 'QA realiza análise de segurança AST e casos de borda.',
|
|
172
|
+
requiresFix: false
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Rota 2: EVENT_REVIEW_FAILED (QA -> DevSecOps)
|
|
177
|
+
this.on(EVENT_TYPES.EVENT_REVIEW_FAILED, (payload) => {
|
|
178
|
+
return {
|
|
179
|
+
handoffTo: AGENT_PERSONAS.DEVSECOPS,
|
|
180
|
+
status: 'CORRECTION_REQUIRED',
|
|
181
|
+
reason: payload.finding || 'Falha apontada pela auditoria adversária.',
|
|
182
|
+
nextAction: 'DevSecOps deve sanar a causa raiz sem contornar testes ou lint.',
|
|
183
|
+
requiresFix: true
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Rota 3: EVENT_REVIEW_PASSED (QA -> Orchestrator / CI)
|
|
188
|
+
this.on(EVENT_TYPES.EVENT_REVIEW_PASSED, (payload) => {
|
|
189
|
+
return {
|
|
190
|
+
handoffTo: AGENT_PERSONAS.ORCHESTRATOR,
|
|
191
|
+
status: 'APPROVED',
|
|
192
|
+
reason: 'Auditoria cética concluída com 100% de conformidade.',
|
|
193
|
+
nextAction: 'Liberar Pull Request, validar esteira de CI e efetuar Tríplice Registro.',
|
|
194
|
+
requiresFix: false
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Rota 4: EVENT_METRIC_ANOMALY (SRE -> Scrum & SRE)
|
|
199
|
+
this.on(EVENT_TYPES.EVENT_METRIC_ANOMALY, (payload) => {
|
|
200
|
+
const metric = payload.metric || 'unknown';
|
|
201
|
+
const value = payload.value || 0;
|
|
202
|
+
const threshold = payload.threshold || 0;
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
handoffTo: AGENT_PERSONAS.SCRUM,
|
|
206
|
+
status: 'ANOMALY_TRIGGERED',
|
|
207
|
+
reason: `Métrica ${metric} atingiu ${value} (limiar: ${threshold}).`,
|
|
208
|
+
nextAction: 'Disparar playbook de auto-remediação SRE e iniciar investigação Ishikawa/PDCA.',
|
|
209
|
+
remediation: payload.recommendedPlaybook || 'PLAYBOOK_CIRCUIT_BREAKER_LLM.md'
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Rota 5: EVENT_REFACTOR_PROPOSAL (Scrum/DevSecOps -> QA Shift-Left Gate -> Backlog)
|
|
214
|
+
this.on(EVENT_TYPES.EVENT_REFACTOR_PROPOSAL, (payload) => {
|
|
215
|
+
const isAligned = payload.contextAligned !== false;
|
|
216
|
+
const isQaApproved = payload.qaApproved !== false;
|
|
217
|
+
const isOffDomain = payload.isOffDomain === true;
|
|
218
|
+
const isRedundant = payload.isRedundant === true;
|
|
219
|
+
|
|
220
|
+
if (!isAligned || !isQaApproved || isOffDomain || isRedundant) {
|
|
221
|
+
return {
|
|
222
|
+
handoffTo: AGENT_PERSONAS.QA,
|
|
223
|
+
status: 'REJECTED_SANITY_FILTER',
|
|
224
|
+
reason: 'Veto do Quality Architect (Regra 14 / Shift-Left Gate): proposta fora de domínio, overengineering ou arquivos redundantes.',
|
|
225
|
+
nextAction: 'Ideia descartada para evitar inchaço do repositório e preservar foco no produto real.',
|
|
226
|
+
ideaId: payload.ideaId || 'I-REJECTED',
|
|
227
|
+
requiresFix: true
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
handoffTo: AGENT_PERSONAS.DEVSECOPS,
|
|
233
|
+
status: 'QUEUED',
|
|
234
|
+
reason: 'Proposta de melhoria homologada pelo Quality Architect em conformidade com a Regra 14.',
|
|
235
|
+
nextAction: 'Cadastrar card no backlog e criar branch dedicada.',
|
|
236
|
+
ideaId: payload.ideaId || 'I-NEW',
|
|
237
|
+
requiresFix: false
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Rota 6: EVENT_AGENT_SELF_IMPROVE (Suíte Completa -> QA Auditoria Empírica -> Orchestrator)
|
|
242
|
+
this.on(EVENT_TYPES.EVENT_AGENT_SELF_IMPROVE, (payload) => {
|
|
243
|
+
const evalPassed = payload.evalPassed !== false;
|
|
244
|
+
if (!evalPassed) {
|
|
245
|
+
return {
|
|
246
|
+
handoffTo: AGENT_PERSONAS.QA,
|
|
247
|
+
status: 'SELF_IMPROVE_REJECTED',
|
|
248
|
+
reason: 'Veto de Auditoria Empírica de QA: auto-evolução reflexiva reprovada por falta de evidência empírica mensurável.',
|
|
249
|
+
nextAction: 'Descartar hipótese para prevenir alucinação cumulativa de regras.',
|
|
250
|
+
requiresFix: true
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
handoffTo: AGENT_PERSONAS.ORCHESTRATOR,
|
|
256
|
+
status: 'REFLEXIVE_LOGGED',
|
|
257
|
+
reason: 'Ciclo de auto-evolução reflexiva validado pelo Quality Architect com evidência empírica.',
|
|
258
|
+
nextAction: 'Registrar hipótese validada de domínio em IDEAS.md.',
|
|
259
|
+
tokenBudget: payload.tokenBudget || 'Under 1500 tokens',
|
|
260
|
+
requiresFix: false
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Rota 7: EVENT_KANBAN_DISPATCH (Full Dev continuous loop)
|
|
265
|
+
this.on(EVENT_TYPES.EVENT_KANBAN_DISPATCH, (payload) => {
|
|
266
|
+
const { processFullDevPipeline } = require('../integrations/jira_manager.js');
|
|
267
|
+
const pipeline = processFullDevPipeline(payload.tasks || [], payload.projectContext || {});
|
|
268
|
+
return {
|
|
269
|
+
handoffTo: AGENT_PERSONAS.FULL_DEV,
|
|
270
|
+
status: pipeline.activeTask ? 'RESUME_IN_PROGRESS' : (pipeline.nextApprovedTask ? 'START_NEXT_TASK' : 'IDLE_TODO_EMPTY'),
|
|
271
|
+
reason: pipeline.activeTask ? 'Concluir tarefa atualmente em andamento antes de avançar.' : (pipeline.nextApprovedTask ? 'Ideia aprovada pelo filtro de sanidade (Regra 14).' : 'Nenhuma tarefa pendente viável em A fazer.'),
|
|
272
|
+
nextAction: pipeline.lifecyclePlan[0] ? pipeline.lifecyclePlan[0].message : 'Aguardar novas demandas.',
|
|
273
|
+
pipeline
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Rota 8: EVENT_INFRA_PROVISIONED (Infra Engineer -> DevSecOps)
|
|
278
|
+
this.on(EVENT_TYPES.EVENT_INFRA_PROVISIONED, (payload) => {
|
|
279
|
+
return {
|
|
280
|
+
handoffTo: AGENT_PERSONAS.DEVSECOPS,
|
|
281
|
+
status: 'INFRA_READY',
|
|
282
|
+
reason: payload.reason || 'Infraestrutura e túneis de rede provisionados com sucesso.',
|
|
283
|
+
nextAction: 'DevSecOps integra código à infraestrutura e CI/CD.',
|
|
284
|
+
requiresFix: false,
|
|
285
|
+
details: payload.details || {}
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
on(eventType, handler) {
|
|
291
|
+
this.subscribers.set(eventType, handler);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
dispatch(eventType, payload = {}) {
|
|
295
|
+
if (!EVENT_TYPES[eventType]) {
|
|
296
|
+
throw new Error(`Evento desconhecido: ${eventType}. Eventos suportados: ${Object.keys(EVENT_TYPES).join(', ')}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const handler = this.subscribers.get(eventType);
|
|
300
|
+
const result = handler ? handler(payload) : { status: 'NO_HANDLER' };
|
|
301
|
+
|
|
302
|
+
const eventRecord = {
|
|
303
|
+
eventId: `EVT-${Date.now()}-${crypto.randomUUID().slice(0, 8)}`,
|
|
304
|
+
eventType,
|
|
305
|
+
timestamp: new Date().toISOString(),
|
|
306
|
+
payload,
|
|
307
|
+
result
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
this.history.push(eventRecord);
|
|
311
|
+
|
|
312
|
+
if (this.db) {
|
|
313
|
+
try {
|
|
314
|
+
const stmt = this.db.prepare(`
|
|
315
|
+
INSERT INTO event_log (event_id, event_type, timestamp, payload_json, result_json)
|
|
316
|
+
VALUES (?, ?, ?, ?, ?)
|
|
317
|
+
`);
|
|
318
|
+
stmt.run(
|
|
319
|
+
eventRecord.eventId,
|
|
320
|
+
eventRecord.eventType,
|
|
321
|
+
eventRecord.timestamp,
|
|
322
|
+
JSON.stringify(eventRecord.payload),
|
|
323
|
+
JSON.stringify(eventRecord.result)
|
|
324
|
+
);
|
|
325
|
+
} catch (insertErr) {
|
|
326
|
+
void insertErr;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return eventRecord;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
processKanbanPipeline(tasks = [], projectContext = {}) {
|
|
334
|
+
const { processFullDevPipeline } = require('../integrations/jira_manager.js');
|
|
335
|
+
return processFullDevPipeline(tasks, projectContext);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
getHistory(options = {}) {
|
|
339
|
+
if (options && options.eventType) {
|
|
340
|
+
return this.history.filter(h => h.eventType === options.eventType);
|
|
341
|
+
}
|
|
342
|
+
return [...this.history];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
getEventLog(options = {}) {
|
|
346
|
+
return this.getHistory(options);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
clearHistory() {
|
|
350
|
+
this.history = [];
|
|
351
|
+
if (this.db) {
|
|
352
|
+
try {
|
|
353
|
+
this.db.exec('DELETE FROM event_log');
|
|
354
|
+
} catch (delErr) {
|
|
355
|
+
void delErr;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
closeDatabase() {
|
|
361
|
+
if (this.db) {
|
|
362
|
+
try {
|
|
363
|
+
this.db.close();
|
|
364
|
+
} catch (closeErr) {
|
|
365
|
+
void closeErr;
|
|
366
|
+
}
|
|
367
|
+
this.db = null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
auditToSarif() {
|
|
372
|
+
const history = this.getHistory();
|
|
373
|
+
const reviewFailures = history.filter(h => h.eventType === EVENT_TYPES.EVENT_REVIEW_FAILED);
|
|
374
|
+
const findings = [];
|
|
375
|
+
|
|
376
|
+
if (reviewFailures.length > 0) {
|
|
377
|
+
findings.push({
|
|
378
|
+
ruleId: 'RULE-BUS-001',
|
|
379
|
+
name: 'ReviewFailureEventsDetected',
|
|
380
|
+
severity: 'WARNING',
|
|
381
|
+
message: `Detectados ${reviewFailures.length} eventos de falha de revisão adversária no barramento.`,
|
|
382
|
+
remediation: 'Investigue os bloqueios do AGENT_QA e aplique autocura adaptativa.'
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return createSarifReport({
|
|
387
|
+
toolName: 'agent-master-orchestrator',
|
|
388
|
+
rules: [
|
|
389
|
+
{
|
|
390
|
+
id: 'RULE-BUS-001',
|
|
391
|
+
name: 'ReviewFailureEventsDetected',
|
|
392
|
+
description: 'Identifica eventos de falha de revisão nos handovers entre agentes',
|
|
393
|
+
severity: 'HIGH',
|
|
394
|
+
cwe: 'CWE-400'
|
|
395
|
+
}
|
|
396
|
+
],
|
|
397
|
+
findings,
|
|
398
|
+
properties: {
|
|
399
|
+
totalEvents: history.length,
|
|
400
|
+
reviewFailuresCount: reviewFailures.length,
|
|
401
|
+
storageEngine: this.db ? 'SQLite WAL' : 'In-Memory'
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
formatReport() {
|
|
407
|
+
const h = this.getHistory();
|
|
408
|
+
return [
|
|
409
|
+
'### Relatório do Barramento de Eventos Multi-Agente',
|
|
410
|
+
`- **Total de Eventos:** ${h.length}`,
|
|
411
|
+
`- **Engine de Armazenamento:** ${this.db ? 'SQLite WAL' : 'In-Memory'}`,
|
|
412
|
+
`- **Personas Homologadas:** ${Object.values(AGENT_PERSONAS).join(', ')}`
|
|
413
|
+
].join('\n');
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
module.exports = {
|
|
418
|
+
MultiAgentOrchestrator,
|
|
419
|
+
AGENT_PERSONAS,
|
|
420
|
+
EVENT_TYPES
|
|
421
|
+
};
|