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,408 @@
1
+ /**
2
+ * scripts/mcp/server.js
3
+ *
4
+ * Servidor MCP Nativo (Model Context Protocol) — Dispatcher Assíncrono Concorrente
5
+ * Compatível com a especificação JSON-RPC 2.0 / MCP 2024-11-05.
6
+ * Suporta execução síncrona e assíncrona não-bloqueante (Promise/setImmediate),
7
+ * injeção de streams para testes, auditoria oficial OASIS SARIF v2.1.0 e resiliência a falhas.
8
+ *
9
+ * Versão: 5.1.0 Enterprise
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const readline = require('node:readline');
15
+ const { version: PKG_VERSION } = require('../../package.json');
16
+ const { createSarifReport } = require('../core/sarif_engine.js');
17
+
18
+ const {
19
+ TOOLS,
20
+ TOOL_PROFILES,
21
+ getActiveTools,
22
+ setMcpProfile,
23
+ getActiveProfile
24
+ } = require('./tools_registry.js');
25
+
26
+ const {
27
+ ResourcesRegistry,
28
+ RESOURCES,
29
+ handleResourcesList,
30
+ handleResourceRead,
31
+ handleResourceReadAsync
32
+ } = require('./resources_registry.js');
33
+
34
+ const {
35
+ handleToolCall,
36
+ handleToolCallAsync
37
+ } = require('./tool_handlers.js');
38
+
39
+ const PROTOCOL_VERSION = '2024-11-05';
40
+ const JSONRPC_VERSION = '2.0';
41
+ const DEFAULT_SERVER_NAME = 'agent-master-devsecops-mcp';
42
+
43
+ /**
44
+ * Classe Canônica McpServer — Núcleo do Servidor Model Context Protocol
45
+ */
46
+ class McpServer {
47
+ constructor(options = {}) {
48
+ this.serverName = options.serverName || DEFAULT_SERVER_NAME;
49
+ this.protocolVersion = options.protocolVersion || PROTOCOL_VERSION;
50
+ this.pkgVersion = options.pkgVersion || PKG_VERSION;
51
+ this.input = options.input || process.stdin;
52
+ this.output = options.output || process.stdout;
53
+ this.rl = null;
54
+ this.isRunning = false;
55
+ this.metrics = {
56
+ requestsTotal: 0,
57
+ errorsTotal: 0,
58
+ startedAt: new Date().toISOString()
59
+ };
60
+ }
61
+
62
+ static get PROTOCOL_VERSION() {
63
+ return PROTOCOL_VERSION;
64
+ }
65
+
66
+ static get JSONRPC_VERSION() {
67
+ return JSONRPC_VERSION;
68
+ }
69
+
70
+ static get SERVER_NAME() {
71
+ return DEFAULT_SERVER_NAME;
72
+ }
73
+
74
+ /**
75
+ * Responde ao handshake de inicialização MCP
76
+ */
77
+ handleInitialize(id) {
78
+ return {
79
+ jsonrpc: JSONRPC_VERSION,
80
+ id: id !== undefined ? id : null,
81
+ result: {
82
+ protocolVersion: this.protocolVersion,
83
+ capabilities: {
84
+ tools: {},
85
+ resources: {}
86
+ },
87
+ serverInfo: {
88
+ name: this.serverName,
89
+ version: this.pkgVersion
90
+ }
91
+ }
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Lista as ferramentas disponíveis conforme o perfil ativo
97
+ */
98
+ handleToolsList(id) {
99
+ return {
100
+ jsonrpc: JSONRPC_VERSION,
101
+ id: id !== undefined ? id : null,
102
+ result: {
103
+ tools: getActiveTools()
104
+ }
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Despachante unificado de mensagens JSON-RPC 2.0 (DRY: centraliza roteamento síncrono e assíncrono)
110
+ */
111
+ dispatch(message, { isAsync = false } = {}) {
112
+ if (!message || typeof message !== 'object' || Array.isArray(message)) {
113
+ this.metrics.errorsTotal++;
114
+ return {
115
+ jsonrpc: JSONRPC_VERSION,
116
+ id: null,
117
+ error: {
118
+ code: -32600,
119
+ message: 'Invalid Request: O payload deve ser um objeto JSON-RPC 2.0 válido.'
120
+ }
121
+ };
122
+ }
123
+
124
+ const { id, method, params } = message;
125
+ this.metrics.requestsTotal++;
126
+
127
+ // Notificações oficiais MCP: não produzem resposta
128
+ if (method === 'notifications/initialized' || method === 'notifications/cancelled') {
129
+ return null;
130
+ }
131
+
132
+ // Ping nativo do protocolo
133
+ if (method === 'ping') {
134
+ return {
135
+ jsonrpc: JSONRPC_VERSION,
136
+ id: id !== undefined ? id : null,
137
+ result: {}
138
+ };
139
+ }
140
+
141
+ // Handshake de inicialização
142
+ if (method === 'initialize') {
143
+ return this.handleInitialize(id);
144
+ }
145
+
146
+ // Catálogo de ferramentas
147
+ if (method === 'tools/list') {
148
+ return this.handleToolsList(id);
149
+ }
150
+
151
+ // Execução de ferramenta
152
+ if (method === 'tools/call') {
153
+ return isAsync
154
+ ? handleToolCallAsync(id, params)
155
+ : handleToolCall(id, params);
156
+ }
157
+
158
+ // Catálogo de recursos
159
+ if (method === 'resources/list') {
160
+ return handleResourcesList(id);
161
+ }
162
+
163
+ // Leitura de recurso
164
+ if (method === 'resources/read') {
165
+ return isAsync
166
+ ? handleResourceReadAsync(id, params)
167
+ : handleResourceRead(id, params);
168
+ }
169
+
170
+ // Método desconhecido
171
+ this.metrics.errorsTotal++;
172
+ return {
173
+ jsonrpc: JSONRPC_VERSION,
174
+ id: id !== undefined ? id : null,
175
+ error: {
176
+ code: -32601,
177
+ message: `Método não suportado: ${method}`
178
+ }
179
+ };
180
+ }
181
+
182
+ /**
183
+ * Processamento síncrono de mensagens JSON-RPC
184
+ */
185
+ processMessage(message) {
186
+ return this.dispatch(message, { isAsync: false });
187
+ }
188
+
189
+ /**
190
+ * Processamento assíncrono não-bloqueante de mensagens JSON-RPC
191
+ */
192
+ async processMessageAsync(message) {
193
+ const res = this.dispatch(message, { isAsync: true });
194
+ return res instanceof Promise ? await res : res;
195
+ }
196
+
197
+ /**
198
+ * Inicializa o loop de escuta stdio via interface readline
199
+ */
200
+ start(options = {}) {
201
+ if (this.isRunning && this.rl) {
202
+ return this;
203
+ }
204
+
205
+ const input = options.input || this.input || process.stdin;
206
+ const output = options.output || this.output || process.stdout;
207
+
208
+ this.rl = readline.createInterface({
209
+ input,
210
+ output,
211
+ terminal: false
212
+ });
213
+
214
+ this.isRunning = true;
215
+
216
+ this.rl.on('line', (line) => {
217
+ const trimmed = line.trim();
218
+ if (!trimmed) return;
219
+
220
+ setImmediate(async () => {
221
+ try {
222
+ const request = JSON.parse(trimmed);
223
+ const response = await this.processMessageAsync(request);
224
+ if (response) {
225
+ output.write(JSON.stringify(response) + '\n');
226
+ }
227
+ } catch (err) {
228
+ this.metrics.errorsTotal++;
229
+ const errResponse = {
230
+ jsonrpc: JSONRPC_VERSION,
231
+ id: null,
232
+ error: {
233
+ code: -32700,
234
+ message: 'Parse error: JSON inválido.',
235
+ data: String(err)
236
+ }
237
+ };
238
+ output.write(JSON.stringify(errResponse) + '\n');
239
+ }
240
+ });
241
+ });
242
+
243
+ this.rl.on('close', () => {
244
+ this.isRunning = false;
245
+ });
246
+
247
+ return this;
248
+ }
249
+
250
+ /**
251
+ * Encerra o servidor e libera streams e event loop
252
+ */
253
+ stop() {
254
+ if (this.rl) {
255
+ this.rl.close();
256
+ this.rl = null;
257
+ }
258
+ this.isRunning = false;
259
+ return this;
260
+ }
261
+
262
+ /**
263
+ * Auditoria de integridade do servidor MCP no padrão OASIS SARIF v2.1.0
264
+ */
265
+ auditToSarif() {
266
+ const findings = [];
267
+ const activeTools = getActiveTools();
268
+ const activeProfile = getActiveProfile();
269
+
270
+ // 1. Validação estrutural de Ferramentas
271
+ for (const tool of activeTools) {
272
+ if (!tool.name || typeof tool.name !== 'string') {
273
+ findings.push({
274
+ ruleId: 'RULE-MCP-001',
275
+ severity: 'CRITICAL',
276
+ filename: 'scripts/mcp/tools_registry.js',
277
+ line: 1,
278
+ column: 1,
279
+ snippet: JSON.stringify(tool).slice(0, 80),
280
+ message: 'Ferramenta MCP sem propriedade "name" obrigatória.',
281
+ remediation: 'Definir nome canônico da ferramenta conforme especificação MCP.'
282
+ });
283
+ }
284
+ if (!tool.inputSchema || typeof tool.inputSchema !== 'object' || tool.inputSchema.type !== 'object') {
285
+ findings.push({
286
+ ruleId: 'RULE-MCP-001',
287
+ severity: 'HIGH',
288
+ filename: 'scripts/mcp/tools_registry.js',
289
+ line: 1,
290
+ column: 1,
291
+ snippet: `tool: ${tool.name}`,
292
+ message: `Ferramenta MCP '${tool.name}' possui inputSchema inválido (deve ter type: 'object').`,
293
+ remediation: 'Ajustar schema JSON Schema da ferramenta.'
294
+ });
295
+ }
296
+ }
297
+
298
+ // 2. Validação estrutural de Recursos
299
+ for (const res of RESOURCES) {
300
+ if (!res.uri || !res.name || !res.mimeType) {
301
+ findings.push({
302
+ ruleId: 'RULE-MCP-002',
303
+ severity: 'HIGH',
304
+ filename: 'scripts/mcp/resources_registry.js',
305
+ line: 1,
306
+ column: 1,
307
+ snippet: `resource: ${res.uri}`,
308
+ message: `Recurso MCP '${res.uri || 'sem uri'}' possui propriedades obrigatórias ausentes.`,
309
+ remediation: 'Garantir que uri, name e mimeType estejam preenchidos.'
310
+ });
311
+ }
312
+ }
313
+
314
+ return createSarifReport({
315
+ toolName: 'agent-master-mcp-server',
316
+ toolVersion: this.pkgVersion,
317
+ findings,
318
+ properties: {
319
+ serverName: this.serverName,
320
+ protocolVersion: this.protocolVersion,
321
+ activeProfile,
322
+ activeToolsCount: activeTools.length,
323
+ totalResourcesCount: RESOURCES.length,
324
+ metrics: this.metrics
325
+ }
326
+ });
327
+ }
328
+
329
+ /**
330
+ * Emite relatório executivo em Markdown com métricas de execução e estado do servidor
331
+ */
332
+ formatReport() {
333
+ const activeTools = getActiveTools();
334
+ const activeProfile = getActiveProfile();
335
+
336
+ return [
337
+ `# Relatório Executivo: Servidor MCP (${this.serverName})`,
338
+ '',
339
+ `- **Versão do Pacote:** v${this.pkgVersion}`,
340
+ `- **Protocolo MCP:** ${this.protocolVersion}`,
341
+ `- **Perfil Ativo:** \`${activeProfile}\``,
342
+ `- **Ferramentas Ativas:** ${activeTools.length}`,
343
+ `- **Recursos Canônicos:** ${RESOURCES.length}`,
344
+ `- **Status:** ${this.isRunning ? 'RUNNING' : 'STANDBY'}`,
345
+ `- **Requisições Processadas:** ${this.metrics.requestsTotal}`,
346
+ `- **Erros Registrados:** ${this.metrics.errorsTotal}`,
347
+ ''
348
+ ].join('\n');
349
+ }
350
+
351
+ static auditToSarif() {
352
+ return defaultServerInstance.auditToSarif();
353
+ }
354
+
355
+ static formatReport() {
356
+ return defaultServerInstance.formatReport();
357
+ }
358
+ }
359
+
360
+ // Instância singleton padrão para retrocompatibilidade
361
+ const defaultServerInstance = new McpServer();
362
+
363
+ function processMessage(message) {
364
+ return defaultServerInstance.processMessage(message);
365
+ }
366
+
367
+ async function processMessageAsync(message) {
368
+ return await defaultServerInstance.processMessageAsync(message);
369
+ }
370
+
371
+ function startServer(options) {
372
+ return defaultServerInstance.start(options);
373
+ }
374
+
375
+ function stopServer() {
376
+ return defaultServerInstance.stop();
377
+ }
378
+
379
+ function handleInitialize(id) {
380
+ return defaultServerInstance.handleInitialize(id);
381
+ }
382
+
383
+ function handleToolsList(id) {
384
+ return defaultServerInstance.handleToolsList(id);
385
+ }
386
+
387
+ module.exports = {
388
+ McpServer,
389
+ defaultServerInstance,
390
+ processMessage,
391
+ processMessageAsync,
392
+ startServer,
393
+ stopServer,
394
+ handleInitialize,
395
+ handleToolsList,
396
+ handleResourcesList,
397
+ handleResourceRead,
398
+ TOOLS,
399
+ RESOURCES,
400
+ TOOL_PROFILES,
401
+ getActiveTools,
402
+ setMcpProfile,
403
+ getActiveProfile,
404
+ auditToSarif: () => McpServer.auditToSarif(),
405
+ formatReport: () => McpServer.formatReport(),
406
+ PROTOCOL_VERSION,
407
+ JSONRPC_VERSION
408
+ };