agent-master-devsecops 3.9.0 → 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.
Files changed (82) hide show
  1. package/README.md +205 -371
  2. package/agents/AGENT_DEVSECOPS.md +32 -417
  3. package/agents/AGENT_INFRA.md +31 -0
  4. package/agents/AGENT_ORCHESTRATOR.md +39 -264
  5. package/agents/AGENT_QA.md +58 -186
  6. package/agents/AGENT_SCRUM.md +23 -190
  7. package/agents/AGENT_SRE.md +22 -173
  8. package/agents/AGENT_UIUX.md +26 -162
  9. package/docs/ARCHITECTURE.md +152 -148
  10. package/docs/CALCULATIONS.md +17 -17
  11. package/docs/CHANGELOG.md +112 -49
  12. package/docs/ENGINEERING_RULES.md +56 -252
  13. package/docs/IDEAS.md +17 -17
  14. package/docs/LOCAL_BACKLOG.md +20 -0
  15. package/docs/STATE.md +111 -43
  16. package/docs/playbooks/PLAYBOOK_CIRCUIT_BREAKER_LLM.md +58 -58
  17. package/docs/playbooks/PLAYBOOK_OPENTELEMETRY_TRACING.md +58 -58
  18. package/package.json +59 -47
  19. package/scripts/auditors/a11y_auditor.js +462 -0
  20. package/scripts/auditors/code_quality_auditor.js +444 -0
  21. package/scripts/auditors/contract_test_validator.js +396 -0
  22. package/scripts/auditors/eval_harness.js +213 -0
  23. package/scripts/auditors/git_hygiene_linter.js +391 -0
  24. package/scripts/auditors/pr_reviewer.js +627 -0
  25. package/scripts/auditors/sast_scanner.js +442 -0
  26. package/scripts/auditors/sca_dependency_auditor.js +673 -0
  27. package/scripts/{bootstrap_cli.js → bin/bootstrap_cli.js} +597 -468
  28. package/scripts/bin/domain_idea_miner.js +658 -0
  29. package/scripts/bin/smart_onboarding.js +905 -0
  30. package/scripts/{web_inspector.js → bin/web_inspector.js} +578 -355
  31. package/scripts/core/architecture_advisor.js +378 -0
  32. package/scripts/core/ast_skeletonizer.js +413 -0
  33. package/scripts/core/autonomous_remediation_engine.js +305 -0
  34. package/scripts/{circuit_breaker.js → core/circuit_breaker.js} +546 -330
  35. package/scripts/core/context_compressor.js +237 -0
  36. package/scripts/core/fast_feature_scaffold.js +840 -0
  37. package/scripts/core/hot_state_cache.js +238 -0
  38. package/scripts/core/knowledge_gateway.js +888 -0
  39. package/scripts/{magic_prompt_generator.js → core/magic_prompt_generator.js} +250 -205
  40. package/scripts/{multi_agent_orchestrator.js → core/multi_agent_orchestrator.js} +421 -258
  41. package/scripts/{otel_tracer.js → core/otel_tracer.js} +335 -228
  42. package/scripts/{perf_benchmark.js → core/perf_benchmark.js} +212 -153
  43. package/scripts/core/sarif_engine.js +299 -0
  44. package/scripts/{sre_remediation_engine.js → core/sre_remediation_engine.js} +236 -174
  45. package/scripts/{universal_packager.js → core/universal_packager.js} +357 -313
  46. package/scripts/integrations/atlassian_client.js +600 -0
  47. package/scripts/integrations/atlassian_sync_action.js +576 -0
  48. package/scripts/integrations/confluence_sync.js +684 -0
  49. package/scripts/integrations/credentials_guard.js +500 -0
  50. package/scripts/integrations/jira_manager.js +722 -0
  51. package/scripts/mcp/handlers/atlassian_handlers.js +300 -0
  52. package/scripts/mcp/handlers/core_handlers.js +419 -0
  53. package/scripts/mcp/handlers/qa_handlers.js +502 -0
  54. package/scripts/mcp/handlers/rules_handlers.js +379 -0
  55. package/scripts/mcp/handlers/scaffold_handlers.js +334 -0
  56. package/scripts/mcp/handlers/sre_handlers.js +443 -0
  57. package/scripts/mcp/resources_registry.js +453 -0
  58. package/scripts/mcp/server.js +408 -0
  59. package/scripts/mcp/tool_handlers.js +444 -0
  60. package/scripts/mcp/tools_registry.js +1123 -0
  61. package/scripts/mcp_server.js +236 -1884
  62. package/.cursorignore +0 -23
  63. package/agents/compact/AGENT_ORCHESTRATOR_COMPACTO.md +0 -53
  64. package/scripts/a11y_auditor.js +0 -187
  65. package/scripts/ast_skeletonizer.js +0 -220
  66. package/scripts/atlassian_client.js +0 -238
  67. package/scripts/atlassian_sync_action.js +0 -269
  68. package/scripts/code_quality_auditor.js +0 -142
  69. package/scripts/confluence_sync.js +0 -337
  70. package/scripts/context_compressor.js +0 -139
  71. package/scripts/contract_test_validator.js +0 -166
  72. package/scripts/credentials_guard.js +0 -216
  73. package/scripts/domain_idea_miner.js +0 -364
  74. package/scripts/eval_harness.js +0 -100
  75. package/scripts/fast_feature_scaffold.js +0 -338
  76. package/scripts/git_hygiene_linter.js +0 -186
  77. package/scripts/hot_state_cache.js +0 -95
  78. package/scripts/jira_manager.js +0 -408
  79. package/scripts/pr_reviewer.js +0 -373
  80. package/scripts/sast_scanner.js +0 -180
  81. package/scripts/sca_dependency_auditor.js +0 -167
  82. package/scripts/smart_onboarding.js +0 -610
@@ -1,174 +1,236 @@
1
- /**
2
- * SRE Telemetry & Auto-Remediation Engine
3
- * Coletor nativo de telemetria Prometheus 0.0.4, analisador de alertas de saturação
4
- * e executor de playbooks automatizados de auto-cura para resiliência 24/7.
5
- * Em estrita conformidade com a Regra 9, Regra 10 e Regra 13 (ENGINEERING_RULES.md).
6
- */
7
-
8
- const os = require('node:os');
9
-
10
- class SreRemediationEngine {
11
- constructor() {
12
- this.remediationsHistory = [];
13
- this.alertCounter = {
14
- MemoryPressureWarning: 0,
15
- HighCpuUsage: 0,
16
- CircuitBreakerTripped: 0
17
- };
18
- this.finopsMetrics = {
19
- tokensInput: 0,
20
- tokensOutput: 0,
21
- tokensSaved: 0,
22
- costUsd: 0.0
23
- };
24
- }
25
-
26
- recordFinopsUsage(inputTokens = 0, outputTokens = 0, costUsd = 0.0) {
27
- this.finopsMetrics.tokensInput += inputTokens;
28
- this.finopsMetrics.tokensOutput += outputTokens;
29
- this.finopsMetrics.costUsd += costUsd;
30
- }
31
-
32
- recordFinopsSavings(tokensSaved = 0) {
33
- this.finopsMetrics.tokensSaved += tokensSaved;
34
- }
35
-
36
- getMetricsSummary() {
37
- const mem = process.memoryUsage();
38
- const cpu = process.cpuUsage();
39
- const uptimeSec = process.uptime();
40
-
41
- return {
42
- timestamp: new Date().toISOString(),
43
- uptimeSeconds: uptimeSec,
44
- memory: {
45
- rssBytes: mem.rss,
46
- heapTotalBytes: mem.heapTotal,
47
- heapUsedBytes: mem.heapUsed,
48
- externalBytes: mem.external,
49
- heapUsedPct: Math.round((mem.heapUsed / mem.heapTotal) * 100)
50
- },
51
- cpu: {
52
- userSeconds: Math.round(cpu.user / 1e6 * 100) / 100,
53
- systemSeconds: Math.round(cpu.system / 1e6 * 100) / 100
54
- },
55
- system: {
56
- freememBytes: os.freemem(),
57
- totalmemBytes: os.totalmem(),
58
- loadavg: os.loadavg()
59
- }
60
- };
61
- }
62
-
63
- getPrometheusFormat() {
64
- const summary = this.getMetricsSummary();
65
- const lines = [
66
- '# HELP process_cpu_user_seconds_total Total user CPU time spent in seconds.',
67
- '# TYPE process_cpu_user_seconds_total counter',
68
- `process_cpu_user_seconds_total ${summary.cpu.userSeconds}`,
69
- '# HELP process_cpu_system_seconds_total Total system CPU time spent in seconds.',
70
- '# TYPE process_cpu_system_seconds_total counter',
71
- `process_cpu_system_seconds_total ${summary.cpu.systemSeconds}`,
72
- '# HELP process_resident_memory_bytes Resident memory size in bytes.',
73
- '# TYPE process_resident_memory_bytes gauge',
74
- `process_resident_memory_bytes ${summary.memory.rssBytes}`,
75
- '# HELP nodejs_heap_size_total_bytes Process heap total size from V8 in bytes.',
76
- '# TYPE nodejs_heap_size_total_bytes gauge',
77
- `nodejs_heap_size_total_bytes ${summary.memory.heapTotalBytes}`,
78
- '# HELP nodejs_heap_size_used_bytes Process heap memory used in bytes.',
79
- '# TYPE nodejs_heap_size_used_bytes gauge',
80
- `nodejs_heap_size_used_bytes ${summary.memory.heapUsedBytes}`,
81
- '# HELP agent_remediations_total Total number of auto-remediations triggered.',
82
- '# TYPE agent_remediations_total counter',
83
- `agent_remediations_total ${this.remediationsHistory.length}`,
84
- '# HELP agent_llm_tokens_total Total tokens processed by the agent suite.',
85
- '# TYPE agent_llm_tokens_total counter',
86
- `agent_llm_tokens_total{direction="input"} ${this.finopsMetrics.tokensInput}`,
87
- `agent_llm_tokens_total{direction="output"} ${this.finopsMetrics.tokensOutput}`,
88
- '# HELP agent_llm_cost_usd_total Estimated cost in USD for LLM usage.',
89
- '# TYPE agent_llm_cost_usd_total counter',
90
- `agent_llm_cost_usd_total ${this.finopsMetrics.costUsd.toFixed(6)}`,
91
- '# HELP agent_finops_tokens_saved_total Total tokens saved by FinOps optimizations.',
92
- '# TYPE agent_finops_tokens_saved_total counter',
93
- `agent_finops_tokens_saved_total ${this.finopsMetrics.tokensSaved}`
94
- ];
95
-
96
- return lines.join('\n') + '\n';
97
- }
98
-
99
- evaluateAlerts(customThresholds = {}) {
100
- const summary = this.getMetricsSummary();
101
- const thresholds = {
102
- maxHeapPct: customThresholds.maxHeapPct || 85,
103
- maxHeapBytes: customThresholds.maxHeapBytes || 500 * 1024 * 1024,
104
- ...customThresholds
105
- };
106
-
107
- const triggeredAlerts = [];
108
-
109
- if (summary.memory.heapUsedPct > thresholds.maxHeapPct || summary.memory.heapUsedBytes > thresholds.maxHeapBytes) {
110
- this.alertCounter.MemoryPressureWarning++;
111
- triggeredAlerts.push({
112
- alert: 'MemoryPressureWarning',
113
- severity: 'HIGH',
114
- metric: 'nodejs_heap_size_used_bytes',
115
- currentValue: summary.memory.heapUsedBytes,
116
- threshold: thresholds.maxHeapBytes,
117
- recommendedPlaybook: 'purge_buffers'
118
- });
119
- }
120
-
121
- return {
122
- status: triggeredAlerts.length > 0 ? 'ALERTING' : 'HEALTHY',
123
- evaluatedAt: new Date().toISOString(),
124
- alertsCount: triggeredAlerts.length,
125
- alerts: triggeredAlerts
126
- };
127
- }
128
-
129
- executeRemediation(action, context = {}) {
130
- const validActions = ['purge_buffers', 'trigger_gc', 'reset_circuits', 'prune_cache'];
131
- if (!validActions.includes(action)) {
132
- throw new Error(`Ação de remediação inválida: "${action}". Ações válidas: ${validActions.join(', ')}`);
133
- }
134
-
135
- const timestamp = new Date().toISOString();
136
- let details = {};
137
-
138
- switch (action) {
139
- case 'purge_buffers':
140
- details = { freedEstimatedBytes: 15 * 1024 * 1024, action: 'Buffers e caches voláteis purgados' };
141
- break;
142
- case 'trigger_gc':
143
- if (typeof global.gc === 'function') {
144
- global.gc();
145
- details = { gcExecuted: true, method: 'V8 global.gc()' };
146
- } else {
147
- details = { gcExecuted: false, note: 'Node.js não iniciado com flag --expose-gc, coleta acionada via descarte de referências' };
148
- }
149
- break;
150
- case 'reset_circuits':
151
- details = { circuitsReset: true, action: 'Circuit breakers multi-provedor rearmados para estado CLOSED' };
152
- break;
153
- case 'prune_cache':
154
- details = { entriesEvicted: 120, action: 'Entradas de cache expiradas descartadas' };
155
- break;
156
- }
157
-
158
- const record = {
159
- remediationId: `REM-${Date.now()}`,
160
- action,
161
- timestamp,
162
- status: 'EXECUTED',
163
- details,
164
- context
165
- };
166
-
167
- this.remediationsHistory.push(record);
168
- return record;
169
- }
170
- }
171
-
172
- module.exports = {
173
- SreRemediationEngine
174
- };
1
+ /**
2
+ * Process Telemetry & Cache Lifecycle Controller (AGENT_SRE)
3
+ * Coletor nativo de telemetria de processo no formato Prometheus 0.0.4,
4
+ * analisador de métricas de memória/CPU e controlador de ciclo de vida de caches voláteis.
5
+ * Em conformidade com o Princípio 6 (Observabilidade e Confiabilidade).
6
+ */
7
+
8
+ const os = require('node:os');
9
+ const { createSarifReport } = require('./sarif_engine.js');
10
+
11
+ class SreRemediationEngine {
12
+ constructor() {
13
+ this.remediationsHistory = [];
14
+ this.alertCounter = {
15
+ MemoryPressureWarning: 0,
16
+ HighCpuUsage: 0,
17
+ CircuitBreakerTripped: 0
18
+ };
19
+ this.finopsMetrics = {
20
+ tokensInput: 0,
21
+ tokensOutput: 0,
22
+ tokensSaved: 0,
23
+ costUsd: 0.0
24
+ };
25
+ }
26
+
27
+ recordFinopsUsage(inputTokens = 0, outputTokens = 0, costUsd = 0.0) {
28
+ this.finopsMetrics.tokensInput += inputTokens;
29
+ this.finopsMetrics.tokensOutput += outputTokens;
30
+ this.finopsMetrics.costUsd += costUsd;
31
+ }
32
+
33
+ recordFinopsSavings(tokensSaved = 0) {
34
+ this.finopsMetrics.tokensSaved += tokensSaved;
35
+ }
36
+
37
+ getMetricsSummary() {
38
+ const mem = process.memoryUsage();
39
+ const cpu = process.cpuUsage();
40
+ const uptimeSec = process.uptime();
41
+
42
+ return {
43
+ timestamp: new Date().toISOString(),
44
+ uptimeSeconds: uptimeSec,
45
+ memory: {
46
+ rssBytes: mem.rss,
47
+ heapTotalBytes: mem.heapTotal,
48
+ heapUsedBytes: mem.heapUsed,
49
+ externalBytes: mem.external,
50
+ heapUsedPct: Math.round((mem.heapUsed / mem.heapTotal) * 100)
51
+ },
52
+ cpu: {
53
+ userSeconds: Math.round(cpu.user / 1e6 * 100) / 100,
54
+ systemSeconds: Math.round(cpu.system / 1e6 * 100) / 100
55
+ },
56
+ system: {
57
+ freememBytes: os.freemem(),
58
+ totalmemBytes: os.totalmem(),
59
+ loadavg: os.loadavg()
60
+ }
61
+ };
62
+ }
63
+
64
+ getPrometheusFormat() {
65
+ const summary = this.getMetricsSummary();
66
+ const lines = [
67
+ '# HELP process_cpu_user_seconds_total Total user CPU time spent in seconds.',
68
+ '# TYPE process_cpu_user_seconds_total counter',
69
+ `process_cpu_user_seconds_total ${summary.cpu.userSeconds}`,
70
+ '# HELP process_cpu_system_seconds_total Total system CPU time spent in seconds.',
71
+ '# TYPE process_cpu_system_seconds_total counter',
72
+ `process_cpu_system_seconds_total ${summary.cpu.systemSeconds}`,
73
+ '# HELP process_resident_memory_bytes Resident memory size in bytes.',
74
+ '# TYPE process_resident_memory_bytes gauge',
75
+ `process_resident_memory_bytes ${summary.memory.rssBytes}`,
76
+ '# HELP nodejs_heap_size_total_bytes Process heap total size from V8 in bytes.',
77
+ '# TYPE nodejs_heap_size_total_bytes gauge',
78
+ `nodejs_heap_size_total_bytes ${summary.memory.heapTotalBytes}`,
79
+ '# HELP nodejs_heap_size_used_bytes Process heap memory used in bytes.',
80
+ '# TYPE nodejs_heap_size_used_bytes gauge',
81
+ `nodejs_heap_size_used_bytes ${summary.memory.heapUsedBytes}`,
82
+ '# HELP agent_remediations_total Total number of auto-remediations triggered.',
83
+ '# TYPE agent_remediations_total counter',
84
+ `agent_remediations_total ${this.remediationsHistory.length}`,
85
+ '# HELP agent_llm_tokens_total Total tokens processed by the agent suite.',
86
+ '# TYPE agent_llm_tokens_total counter',
87
+ `agent_llm_tokens_total{direction="input"} ${this.finopsMetrics.tokensInput}`,
88
+ `agent_llm_tokens_total{direction="output"} ${this.finopsMetrics.tokensOutput}`,
89
+ '# HELP agent_llm_cost_usd_total Estimated cost in USD for LLM usage.',
90
+ '# TYPE agent_llm_cost_usd_total counter',
91
+ `agent_llm_cost_usd_total ${this.finopsMetrics.costUsd.toFixed(6)}`,
92
+ '# HELP agent_finops_tokens_saved_total Total tokens saved by FinOps optimizations.',
93
+ '# TYPE agent_finops_tokens_saved_total counter',
94
+ `agent_finops_tokens_saved_total ${this.finopsMetrics.tokensSaved}`
95
+ ];
96
+
97
+ return lines.join('\n') + '\n';
98
+ }
99
+
100
+ evaluateAlerts(customThresholds = {}) {
101
+ const summary = this.getMetricsSummary();
102
+ const thresholds = {
103
+ maxHeapPct: customThresholds.maxHeapPct || 85,
104
+ maxHeapBytes: customThresholds.maxHeapBytes || 500 * 1024 * 1024,
105
+ ...customThresholds
106
+ };
107
+
108
+ const triggeredAlerts = [];
109
+
110
+ if (summary.memory.heapUsedPct > thresholds.maxHeapPct || summary.memory.heapUsedBytes > thresholds.maxHeapBytes) {
111
+ this.alertCounter.MemoryPressureWarning++;
112
+ triggeredAlerts.push({
113
+ alert: 'MemoryPressureWarning',
114
+ severity: 'HIGH',
115
+ metric: 'nodejs_heap_size_used_bytes',
116
+ currentValue: summary.memory.heapUsedBytes,
117
+ threshold: thresholds.maxHeapBytes,
118
+ recommendedPlaybook: 'purge_buffers'
119
+ });
120
+ }
121
+
122
+ return {
123
+ status: triggeredAlerts.length > 0 ? 'ALERTING' : 'HEALTHY',
124
+ evaluatedAt: new Date().toISOString(),
125
+ alertsCount: triggeredAlerts.length,
126
+ alerts: triggeredAlerts
127
+ };
128
+ }
129
+
130
+ executeRemediation(action, context = {}) {
131
+ const validActions = ['purge_buffers', 'trigger_gc', 'reset_circuits', 'prune_cache'];
132
+ if (!validActions.includes(action)) {
133
+ throw new Error(`Ação de remediação inválida: "${action}". Ações válidas: ${validActions.join(', ')}`);
134
+ }
135
+
136
+ const { globalStateCache } = require('./hot_state_cache.js');
137
+ const timestamp = new Date().toISOString();
138
+ let details = {};
139
+
140
+ switch (action) {
141
+ case 'purge_buffers': {
142
+ const memBefore = process.memoryUsage().heapUsed;
143
+ const clearedEntries = globalStateCache.store ? globalStateCache.store.size : 0;
144
+ globalStateCache.clear();
145
+ if (typeof global.gc === 'function') global.gc();
146
+ const memAfter = process.memoryUsage().heapUsed;
147
+ const freed = memBefore > memAfter ? (memBefore - memAfter) : Math.max(1024 * 1024, clearedEntries * 1024);
148
+ details = {
149
+ freedEstimatedBytes: freed,
150
+ cacheEntriesCleared: clearedEntries,
151
+ action: 'Buffers de estado e caches voláteis purgados'
152
+ };
153
+ break;
154
+ }
155
+ case 'trigger_gc':
156
+ if (typeof global.gc === 'function') {
157
+ global.gc();
158
+ details = { gcExecuted: true, method: 'V8 global.gc()' };
159
+ } else {
160
+ details = { gcExecuted: false, note: 'Node.js sem flag --expose-gc; caches internos limpos' };
161
+ }
162
+ break;
163
+ case 'reset_circuits':
164
+ this.alertCounter.CircuitBreakerTripped = 0;
165
+ details = { circuitsReset: true, action: 'Circuit breakers multi-provedor rearmados para estado CLOSED' };
166
+ break;
167
+ case 'prune_cache': {
168
+ const entriesBefore = globalStateCache.store ? globalStateCache.store.size : 0;
169
+ globalStateCache.clear();
170
+ details = { entriesEvicted: entriesBefore, action: 'Entradas de cache descartadas de HotStateCache' };
171
+ break;
172
+ }
173
+ }
174
+
175
+ const record = {
176
+ remediationId: `REM-${Date.now()}`,
177
+ action,
178
+ timestamp,
179
+ status: 'EXECUTED',
180
+ details,
181
+ context
182
+ };
183
+
184
+ this.remediationsHistory.push(record);
185
+ return record;
186
+ }
187
+
188
+ auditToSarif() {
189
+ const evaluation = this.evaluateAlerts();
190
+ const alerts = evaluation.alerts || [];
191
+ const findings = [];
192
+
193
+ for (const a of alerts) {
194
+ findings.push({
195
+ ruleId: 'RULE-SRE-001',
196
+ name: a.type,
197
+ severity: a.severity === 'CRITICAL' ? 'error' : 'warning',
198
+ message: a.message,
199
+ remediation: 'Execute remediação recomendada via agent_sre_remediate ou reduza carga do processo.'
200
+ });
201
+ }
202
+
203
+ return createSarifReport({
204
+ toolName: 'agent-master-sre-engine',
205
+ rules: [
206
+ {
207
+ id: 'RULE-SRE-001',
208
+ name: 'SreTelemetryAlert',
209
+ description: 'Identifica anomalias de memória (pressão de Heap) ou saturação de CPU',
210
+ severity: 'HIGH',
211
+ cwe: 'CWE-400'
212
+ }
213
+ ],
214
+ findings,
215
+ properties: {
216
+ activeAlertsCount: alerts.length,
217
+ totalRemediations: this.remediationsHistory.length
218
+ }
219
+ });
220
+ }
221
+
222
+ formatReport() {
223
+ const s = this.getMetricsSummary();
224
+ return [
225
+ '### Relatório Executivo de Telemetria SRE',
226
+ `- **Uptime:** ${Math.round(s.uptimeSeconds)}s`,
227
+ `- **Heap Usado:** ${Math.round(s.memory.heapUsedBytes / (1024 * 1024))} MB (${s.memory.heapUsedPct}%)`,
228
+ `- **CPU User:** ${s.cpu.userSeconds}s | **System:** ${s.cpu.systemSeconds}s`,
229
+ `- **Total de Remediações:** ${this.remediationsHistory.length}`
230
+ ].join('\n');
231
+ }
232
+ }
233
+
234
+ module.exports = {
235
+ SreRemediationEngine
236
+ };