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
@@ -0,0 +1,443 @@
1
+ /**
2
+ * scripts/mcp/handlers/sre_handlers.js
3
+ *
4
+ * SRE, Observability & Resiliency MCP Handlers.
5
+ * Despacha chamadas JSON-RPC 2.0 para telemetria OpenTelemetry (W3C TraceContext),
6
+ * benchmarks de performance e regressão, auto-remediação de processos/heap,
7
+ * e roteamento resiliente com Circuit Breaker multi-provedor (Princípio 6).
8
+ *
9
+ * Versão: 5.1.0 Enterprise
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const { createSarifReport } = require('../../core/sarif_engine.js');
15
+
16
+ let _sreEngineInstance = null;
17
+ function getSreEngine() {
18
+ if (!_sreEngineInstance) {
19
+ const { SreRemediationEngine } = require('../../core/sre_remediation_engine.js');
20
+ _sreEngineInstance = new SreRemediationEngine();
21
+ }
22
+ return _sreEngineInstance;
23
+ }
24
+
25
+ let _routerInstance = null;
26
+ function getCircuitBreakerRouter(options = {}) {
27
+ if (!_routerInstance) {
28
+ const { MultiProviderRouter } = require('../../core/circuit_breaker.js');
29
+ const failureThreshold = options.failureThreshold || 3;
30
+ _routerInstance = new MultiProviderRouter(['anthropic', 'openai', 'groq', 'ollama'], { failureThreshold });
31
+ }
32
+ return _routerInstance;
33
+ }
34
+
35
+ /**
36
+ * Helpers funcionais puros para construção determinística de respostas JSON-RPC 2.0 (DRY)
37
+ */
38
+ function buildSuccessResponse(id, data) {
39
+ const textContent = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
40
+ return {
41
+ jsonrpc: '2.0',
42
+ id,
43
+ result: {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: textContent
48
+ }
49
+ ]
50
+ }
51
+ };
52
+ }
53
+
54
+ function buildErrorResponse(id, code, message, data = null) {
55
+ const errObj = { code, message };
56
+ if (data) errObj.data = data;
57
+ return {
58
+ jsonrpc: '2.0',
59
+ id,
60
+ error: errObj
61
+ };
62
+ }
63
+
64
+ /**
65
+ * 1. Telemetria OpenTelemetry & Flamegraph W3C (agent_otel_trace)
66
+ */
67
+ function handleOtelTrace(id, args) {
68
+ try {
69
+ const safeArgs = args && typeof args === 'object' ? args : {};
70
+ const { Tracer } = require('../../core/otel_tracer.js');
71
+ const serviceName = safeArgs.serviceName || 'agent-service';
72
+ const thresholdMs = Number(safeArgs.thresholdMs) || 50;
73
+ const format = safeArgs.format || 'json';
74
+ const tracer = new Tracer(serviceName);
75
+
76
+ const inputSpans = Array.isArray(safeArgs.spans) && safeArgs.spans.length > 0
77
+ ? safeArgs.spans
78
+ : [
79
+ { name: 'op_request', durationMs: 15 },
80
+ { name: 'llm_inference', durationMs: 70 },
81
+ { name: 'response_formatting', durationMs: 10 }
82
+ ];
83
+
84
+ let runningOffset = Date.now();
85
+ let rootSpan = null;
86
+
87
+ inputSpans.forEach((s, idx) => {
88
+ const dur = Math.max(1, Number(s.durationMs) || 10);
89
+ const span = tracer.startSpan(s.name, {
90
+ startTime: runningOffset,
91
+ parentSpanId: idx > 0 && rootSpan ? rootSpan.spanId : null,
92
+ attributes: s.attributes || {}
93
+ });
94
+ span.end(runningOffset + dur);
95
+ if (idx === 0) rootSpan = span;
96
+ runningOffset += dur;
97
+ });
98
+
99
+ const bottlenecks = tracer.analyzeBottlenecks(thresholdMs);
100
+ const flamegraph = tracer.renderFlamegraphAscii();
101
+ const traceContext = tracer.getTraceContext(rootSpan);
102
+
103
+ if (format === 'sarif') {
104
+ const findings = bottlenecks.map(b => ({
105
+ ruleId: 'RULE-PERF-001',
106
+ severity: 'MEDIUM',
107
+ filename: 'traces/opentelemetry.log',
108
+ line: 1,
109
+ column: 1,
110
+ snippet: `Span: ${b.name} (${b.durationMs}ms)`,
111
+ message: `Gargalo de latência detectado: o span '${b.name}' durou ${b.durationMs}ms (limiar: ${thresholdMs}ms).`,
112
+ remediation: 'Otimizar o processamento assíncrono ou chavear para modelo/operação de menor latência.'
113
+ }));
114
+
115
+ const sarif = createSarifReport({
116
+ toolName: 'agent-master-otel-tracer',
117
+ toolVersion: '5.1.0',
118
+ findings,
119
+ properties: {
120
+ traceId: traceContext.traceId,
121
+ traceparent: traceContext.traceparent,
122
+ serviceName,
123
+ totalSpans: tracer.spans.length,
124
+ bottlenecksCount: bottlenecks.length
125
+ }
126
+ });
127
+ return buildSuccessResponse(id, sarif);
128
+ }
129
+
130
+ return buildSuccessResponse(id, {
131
+ traceId: traceContext.traceId,
132
+ traceparent: traceContext.traceparent,
133
+ serviceName,
134
+ totalSpans: tracer.spans.length,
135
+ gargalosDetectados: bottlenecks,
136
+ flamegraph
137
+ });
138
+ } catch (err) {
139
+ return buildErrorResponse(id, -32603, `Falha em handleOtelTrace: ${err.message}`);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * 2. Benchmark de Performance & Comparação contra Baseline (agent_perf_benchmark)
145
+ */
146
+ function handlePerfBenchmark(id, args) {
147
+ try {
148
+ const safeArgs = args && typeof args === 'object' ? args : {};
149
+ const { runBenchmark, comparePerformance, formatPerfReport, getOrInitBaseline } = require('../../core/perf_benchmark.js');
150
+ const iterations = Number(safeArgs.iterations) || 50;
151
+ const maxDegradationPct = Number(safeArgs.maxDegradationPct) || 15;
152
+ const format = safeArgs.format || 'json';
153
+
154
+ const baseline = getOrInitBaseline();
155
+ const current = runBenchmark(iterations);
156
+ const comparison = comparePerformance(current, baseline, maxDegradationPct);
157
+ const report = formatPerfReport(comparison);
158
+
159
+ if (format === 'sarif') {
160
+ const findings = [];
161
+ if (!comparison.passed) {
162
+ findings.push({
163
+ ruleId: 'RULE-PERF-002',
164
+ severity: 'HIGH',
165
+ filename: 'perf/benchmark.json',
166
+ line: 1,
167
+ column: 1,
168
+ snippet: `Degradação: +${comparison.deltas.latencyDeltaPct}%`,
169
+ message: `Regressão de performance detectada: latência degradou em ${comparison.deltas.latencyDeltaPct}% (limite: ${maxDegradationPct}%).`,
170
+ remediation: 'Investigar hotspots de CPU/memória e reverter alterações que introduziram complexidade ciclomática elevada.'
171
+ });
172
+ }
173
+
174
+ const sarif = createSarifReport({
175
+ toolName: 'agent-master-perf-benchmark',
176
+ toolVersion: '5.1.0',
177
+ findings,
178
+ properties: {
179
+ verdict: comparison.verdict,
180
+ passed: comparison.passed,
181
+ deltas: comparison.deltas,
182
+ iterations
183
+ }
184
+ });
185
+ return buildSuccessResponse(id, sarif);
186
+ }
187
+
188
+ return buildSuccessResponse(id, {
189
+ veredito: comparison.verdict,
190
+ passou: comparison.passed,
191
+ metricas: current,
192
+ deltas: comparison.deltas,
193
+ relatorio: report
194
+ });
195
+ } catch (err) {
196
+ return buildErrorResponse(id, -32603, `Falha em handlePerfBenchmark: ${err.message}`);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * 3. Gerenciamento do Circuit Breaker Multi-Provedor LLM (agent_circuit_breaker)
202
+ */
203
+ function handleCircuitBreaker(id, args) {
204
+ try {
205
+ const safeArgs = args && typeof args === 'object' ? args : {};
206
+ const action = safeArgs.action || 'status';
207
+ const failureThreshold = Number(safeArgs.failureThreshold) || 3;
208
+ const format = safeArgs.format || 'json';
209
+ const router = getCircuitBreakerRouter({ failureThreshold });
210
+
211
+ let responseData;
212
+
213
+ if (action === 'reset') {
214
+ router.resetAll();
215
+ responseData = {
216
+ status: 'SUCCESS',
217
+ action: 'reset',
218
+ circuitStates: router.getAllStatuses()
219
+ };
220
+ } else if (action === 'simulate_failover') {
221
+ const taskMap = {
222
+ anthropic: () => { throw new Error('HTTP 429: Too Many Requests (Rate limit)'); },
223
+ openai: () => { throw new Error('HTTP 503: Service Unavailable'); },
224
+ groq: () => 'Resposta gerada com sucesso via Groq (Llama 3.3 70B)',
225
+ ollama: () => 'Resposta via Ollama local'
226
+ };
227
+
228
+ const dispatchRes = router.dispatchSync(taskMap);
229
+ responseData = {
230
+ status: 'SUCCESS',
231
+ action: 'simulate_failover',
232
+ dispatchResult: dispatchRes
233
+ };
234
+ } else {
235
+ // Default: 'status'
236
+ responseData = {
237
+ status: 'SUCCESS',
238
+ action: 'status',
239
+ circuitStates: router.getAllStatuses()
240
+ };
241
+ }
242
+
243
+ if (format === 'sarif') {
244
+ const statuses = router.getAllStatuses();
245
+ const findings = [];
246
+
247
+ for (const [provider, st] of Object.entries(statuses)) {
248
+ if (st.state === 'OPEN') {
249
+ findings.push({
250
+ ruleId: 'RULE-CIRCUIT-OPEN',
251
+ severity: 'HIGH',
252
+ filename: 'circuit_breaker.json',
253
+ line: 1,
254
+ column: 1,
255
+ snippet: `Provedor: ${provider} (State: OPEN)`,
256
+ message: `Circuito para '${provider}' está ABERTO devido a falhas consecutivas (${st.consecutiveFailures}).`,
257
+ remediation: 'Verificar status da API remota, rate limits ou executar reset via action: reset.'
258
+ });
259
+ }
260
+ }
261
+
262
+ const sarif = createSarifReport({
263
+ toolName: 'agent-master-circuit-breaker',
264
+ toolVersion: '5.1.0',
265
+ findings,
266
+ properties: {
267
+ action,
268
+ statuses
269
+ }
270
+ });
271
+ return buildSuccessResponse(id, sarif);
272
+ }
273
+
274
+ return buildSuccessResponse(id, responseData);
275
+ } catch (err) {
276
+ return buildErrorResponse(id, -32603, `Falha em handleCircuitBreaker: ${err.message}`);
277
+ }
278
+ }
279
+
280
+ /**
281
+ * 4. Telemetria de Processo & Métricas Prometheus (agent_sre_telemetry)
282
+ */
283
+ function handleSreTelemetry(id, args) {
284
+ try {
285
+ const safeArgs = args && typeof args === 'object' ? args : {};
286
+ const engine = getSreEngine();
287
+ const format = safeArgs.format || 'json';
288
+ const evaluateAlerts = safeArgs.evaluateAlerts;
289
+
290
+ if (format === 'prometheus') {
291
+ const prometheusData = engine.getPrometheusFormat();
292
+ return buildSuccessResponse(id, prometheusData);
293
+ }
294
+
295
+ const summary = engine.getMetricsSummary();
296
+ const alertsEvaluation = evaluateAlerts ? engine.evaluateAlerts() : undefined;
297
+
298
+ const responseData = {
299
+ summary,
300
+ ...(alertsEvaluation ? { alertsEvaluation } : {})
301
+ };
302
+
303
+ if (format === 'sarif') {
304
+ const evalResult = typeof engine.evaluateAlerts === 'function' ? engine.evaluateAlerts() : {};
305
+ const alerts = Array.isArray(evalResult.alerts) ? evalResult.alerts : [];
306
+ const findings = alerts.map(a => ({
307
+ ruleId: 'RULE-SRE-001',
308
+ severity: a.severity === 'CRITICAL' ? 'CRITICAL' : 'HIGH',
309
+ filename: 'metrics/sre.prom',
310
+ line: 1,
311
+ column: 1,
312
+ snippet: `Métrica: ${a.metric} (Valor: ${a.currentValue !== undefined ? a.currentValue : a.value})`,
313
+ message: a.message || `Alerta disparado para ${a.metric}`,
314
+ remediation: 'Executar agent_sre_remediate ou liberar heap não utilizado.'
315
+ }));
316
+
317
+ const sarif = createSarifReport({
318
+ toolName: 'agent-master-sre-telemetry',
319
+ toolVersion: '5.1.0',
320
+ findings,
321
+ properties: {
322
+ metricsSummary: summary,
323
+ alertsCount: alerts.length
324
+ }
325
+ });
326
+ return buildSuccessResponse(id, sarif);
327
+ }
328
+
329
+ return buildSuccessResponse(id, responseData);
330
+ } catch (err) {
331
+ return buildErrorResponse(id, -32603, `Falha em handleSreTelemetry: ${err.message}`);
332
+ }
333
+ }
334
+
335
+ /**
336
+ * 5. Auto-Cura SRE & Gestão de Ciclo de Vida de Memória (agent_sre_remediate)
337
+ */
338
+ function handleSreRemediate(id, args) {
339
+ try {
340
+ const safeArgs = args && typeof args === 'object' ? args : {};
341
+ const engine = getSreEngine();
342
+ const action = safeArgs.action;
343
+ const context = safeArgs.context || {};
344
+ const format = safeArgs.format || 'json';
345
+
346
+ const remediationRecord = engine.executeRemediation(action, context);
347
+
348
+ if (format === 'sarif') {
349
+ const sarif = createSarifReport({
350
+ toolName: 'agent-master-sre-remediation',
351
+ toolVersion: '5.1.0',
352
+ findings: [],
353
+ properties: {
354
+ status: 'SUCCESS',
355
+ action: remediationRecord.action,
356
+ remediationStatus: remediationRecord.status,
357
+ details: remediationRecord.details
358
+ }
359
+ });
360
+ return buildSuccessResponse(id, sarif);
361
+ }
362
+
363
+ return buildSuccessResponse(id, {
364
+ status: 'SUCCESS',
365
+ remediationRecord
366
+ });
367
+ } catch (err) {
368
+ return buildErrorResponse(id, -32603, `Falha em handleSreRemediate: ${err.message}`);
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Classe Canônica SreHandlers
374
+ * Fornece API orientada a objetos com suporte a métodos estáticos e de instância.
375
+ */
376
+ class SreHandlers {
377
+ static buildSuccessResponse(id, data) {
378
+ return buildSuccessResponse(id, data);
379
+ }
380
+
381
+ static buildErrorResponse(id, code, message, data = null) {
382
+ return buildErrorResponse(id, code, message, data);
383
+ }
384
+
385
+ static handleOtelTrace(id, args) {
386
+ return handleOtelTrace(id, args);
387
+ }
388
+
389
+ static handlePerfBenchmark(id, args) {
390
+ return handlePerfBenchmark(id, args);
391
+ }
392
+
393
+ static handleCircuitBreaker(id, args) {
394
+ return handleCircuitBreaker(id, args);
395
+ }
396
+
397
+ static handleSreTelemetry(id, args) {
398
+ return handleSreTelemetry(id, args);
399
+ }
400
+
401
+ static handleSreRemediate(id, args) {
402
+ return handleSreRemediate(id, args);
403
+ }
404
+
405
+ buildSuccessResponse(id, data) {
406
+ return SreHandlers.buildSuccessResponse(id, data);
407
+ }
408
+
409
+ buildErrorResponse(id, code, message, data = null) {
410
+ return SreHandlers.buildErrorResponse(id, code, message, data);
411
+ }
412
+
413
+ handleOtelTrace(id, args) {
414
+ return SreHandlers.handleOtelTrace(id, args);
415
+ }
416
+
417
+ handlePerfBenchmark(id, args) {
418
+ return SreHandlers.handlePerfBenchmark(id, args);
419
+ }
420
+
421
+ handleCircuitBreaker(id, args) {
422
+ return SreHandlers.handleCircuitBreaker(id, args);
423
+ }
424
+
425
+ handleSreTelemetry(id, args) {
426
+ return SreHandlers.handleSreTelemetry(id, args);
427
+ }
428
+
429
+ handleSreRemediate(id, args) {
430
+ return SreHandlers.handleSreRemediate(id, args);
431
+ }
432
+ }
433
+
434
+ module.exports = {
435
+ SreHandlers,
436
+ buildSuccessResponse,
437
+ buildErrorResponse,
438
+ handleOtelTrace,
439
+ handlePerfBenchmark,
440
+ handleCircuitBreaker,
441
+ handleSreTelemetry,
442
+ handleSreRemediate
443
+ };