0xray 4.0.33 → 4.0.35

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 (156) hide show
  1. package/.grok-plugin/plugin.json +1 -1
  2. package/.xray/codex.json +12 -4
  3. package/.xray/features.json +1 -1
  4. package/AGENTS-consumer.md +6 -6
  5. package/AGENTS.md +5 -5
  6. package/README.md +2 -2
  7. package/dist/AGENTS.md +5 -5
  8. package/dist/CHANGELOG.md +25 -0
  9. package/dist/README.md +2 -2
  10. package/dist/cli/index.js +2 -5
  11. package/dist/governance/governance-service.js +1 -1
  12. package/dist/integrations/base/README.md +1 -9
  13. package/dist/integrations/base/index.d.ts +0 -1
  14. package/dist/integrations/base/index.js +0 -2
  15. package/dist/integrations/governance/index.js +31 -8
  16. package/dist/integrations/grok/hooks/grok-hook-utils.js +1 -1
  17. package/dist/integrations/grok/hooks/session-start.js +12 -0
  18. package/dist/integrations/hooks/goggles-pipeline.mjs +108 -22
  19. package/dist/integrations/hooks/goggles-planes.json +23 -0
  20. package/dist/integrations/hooks/host-truth.mjs +74 -0
  21. package/dist/integrations/hooks/station-hook-runtime.cjs +3 -0
  22. package/dist/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  23. package/dist/mcps/knowledge-skills/storyteller.server.js +0 -1
  24. package/dist/nucleus/delegation-gate.d.ts +2 -2
  25. package/dist/nucleus/delegation-gate.js +13 -2
  26. package/dist/nucleus/work-freshness.mjs +189 -0
  27. package/dist/processors/implementations/agents-md-validation-processor.js +1 -1
  28. package/docs-site/docs/plates/boot.md +17 -2
  29. package/docs-site/docs/plates/governance.md +3 -2
  30. package/docs-site/docs/plates/index.md +3 -1
  31. package/docs-site/docs/plates/memory-recall.md +26 -35
  32. package/docs-site/docs/plates/orchestration.md +39 -35
  33. package/docs-site/docs/plates/processor.md +34 -36
  34. package/docs-site/docs/plates/reporting.md +3 -8
  35. package/docs-site/docs/plates/routing.md +22 -11
  36. package/package.json +2 -2
  37. package/scripts/foundry/release.mjs +48 -5
  38. package/scripts/mjs/test-consumer-readiness.mjs +1 -0
  39. package/scripts/mjs/test-mcp-functionality.mjs +14 -9
  40. package/scripts/node/basic-security-audit.cjs +0 -1
  41. package/scripts/node/bridge-mcp-wiring.cjs +66 -3
  42. package/scripts/node/postinstall.cjs +1 -1
  43. package/scripts/node/prepare-consumer.cjs +11 -7
  44. package/scripts/node/setup-dev.cjs +18 -26
  45. package/scripts/node/validate-mcp-connectivity.js +2 -1
  46. package/src/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  47. package/src/mcps/knowledge-skills/storyteller.server.ts +0 -1
  48. package/xray/agents_template.md +5 -5
  49. package/xray/codex.json +12 -4
  50. package/xray/features.json +1 -1
  51. package/dist/agents/known-names.d.ts +0 -26
  52. package/dist/agents/known-names.js +0 -72
  53. package/dist/analytics/consent-manager.d.ts +0 -92
  54. package/dist/analytics/consent-manager.js +0 -257
  55. package/dist/benchmark/performance-benchmark.d.ts +0 -103
  56. package/dist/benchmark/performance-benchmark.js +0 -373
  57. package/dist/cli/commands/analytics-disable.d.ts +0 -9
  58. package/dist/cli/commands/analytics-disable.js +0 -72
  59. package/dist/cli/commands/analytics-enable-action.d.ts +0 -8
  60. package/dist/cli/commands/analytics-enable-action.js +0 -82
  61. package/dist/cli/commands/analytics-preview.d.ts +0 -9
  62. package/dist/cli/commands/analytics-preview.js +0 -106
  63. package/dist/cli/commands/analytics-status.d.ts +0 -9
  64. package/dist/cli/commands/analytics-status.js +0 -68
  65. package/dist/cli/commands/enforce.d.ts +0 -12
  66. package/dist/cli/commands/enforce.js +0 -78
  67. package/dist/cli/commands/govern.d.ts +0 -29
  68. package/dist/cli/commands/govern.js +0 -149
  69. package/dist/cli/commands/security-audit.d.ts +0 -23
  70. package/dist/cli/commands/security-audit.js +0 -219
  71. package/dist/cli/server.d.ts +0 -1
  72. package/dist/cli/server.js +0 -147
  73. package/dist/config/routing-mappings.d.ts +0 -26
  74. package/dist/config/routing-mappings.js +0 -151
  75. package/dist/core/bridge.mjs +0 -922
  76. package/dist/core/trace-context.d.ts +0 -12
  77. package/dist/core/trace-context.js +0 -33
  78. package/dist/enforcement/index.d.ts +0 -22
  79. package/dist/enforcement/index.js +0 -40
  80. package/dist/enforcement/loaders/index.d.ts +0 -36
  81. package/dist/enforcement/loaders/index.js +0 -39
  82. package/dist/enforcement/test-auto-healing.d.ts +0 -83
  83. package/dist/enforcement/test-auto-healing.js +0 -325
  84. package/dist/inference/index.d.ts +0 -10
  85. package/dist/inference/index.js +0 -5
  86. package/dist/infrastructure/iac-validator.d.ts +0 -150
  87. package/dist/infrastructure/iac-validator.js +0 -465
  88. package/dist/infrastructure/schemas/cloud-schemas.d.ts +0 -482
  89. package/dist/infrastructure/schemas/cloud-schemas.js +0 -488
  90. package/dist/integrations/base/ExampleIntegration.d.ts +0 -46
  91. package/dist/integrations/base/ExampleIntegration.js +0 -180
  92. package/dist/integrations/enforcement-gate.d.ts +0 -44
  93. package/dist/integrations/enforcement-gate.js +0 -348
  94. package/dist/mcps/connection/connection-manager.d.ts +0 -39
  95. package/dist/mcps/connection/connection-manager.js +0 -79
  96. package/dist/mcps/index.d.ts +0 -17
  97. package/dist/mcps/index.js +0 -65
  98. package/dist/mcps/orchestrator/index.d.ts +0 -6
  99. package/dist/mcps/orchestrator/index.js +0 -5
  100. package/dist/metrics/index.d.ts +0 -6
  101. package/dist/metrics/index.js +0 -6
  102. package/dist/orchestrator/self-direction-activation.d.ts +0 -108
  103. package/dist/orchestrator/self-direction-activation.js +0 -244
  104. package/dist/orchestrator/universal-registry-bridge.d.ts +0 -84
  105. package/dist/orchestrator/universal-registry-bridge.js +0 -246
  106. package/dist/performance/performance-budget-enforcer.d.ts +0 -157
  107. package/dist/performance/performance-budget-enforcer.js +0 -433
  108. package/dist/performance/performance-regression-tester.d.ts +0 -107
  109. package/dist/performance/performance-regression-tester.js +0 -341
  110. package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +0 -11
  111. package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +0 -50
  112. package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +0 -44
  113. package/dist/postprocessor/config/ProcessorConfigLoader.js +0 -16
  114. package/dist/postprocessor/integration.d.ts +0 -156
  115. package/dist/postprocessor/integration.js +0 -194
  116. package/dist/postprocessor/metamorphosis/index.d.ts +0 -2
  117. package/dist/postprocessor/metamorphosis/index.js +0 -1
  118. package/dist/postprocessor/redeploy/RetryHandler.d.ts +0 -49
  119. package/dist/postprocessor/redeploy/RetryHandler.js +0 -118
  120. package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
  121. package/dist/processors/implementations/session-capture-processor.js +0 -37
  122. package/dist/public/XrayService.d.ts +0 -17
  123. package/dist/public/XrayService.js +0 -40
  124. package/dist/public/index.d.ts +0 -4
  125. package/dist/public/index.js +0 -2
  126. package/dist/security/comprehensive-security-audit.d.ts +0 -157
  127. package/dist/security/comprehensive-security-audit.js +0 -1004
  128. package/dist/security/index.d.ts +0 -13
  129. package/dist/security/index.js +0 -13
  130. package/dist/security/security-agent-coordinator.d.ts +0 -71
  131. package/dist/security/security-agent-coordinator.js +0 -203
  132. package/dist/security/security-hardening-system.d.ts +0 -238
  133. package/dist/security/security-hardening-system.js +0 -726
  134. package/dist/security/security-orchestration-layer.d.ts +0 -118
  135. package/dist/security/security-orchestration-layer.js +0 -495
  136. package/dist/testing/memory-regression-suite.d.ts +0 -105
  137. package/dist/testing/memory-regression-suite.js +0 -258
  138. package/dist/tools/assess-complexity-tool.d.ts +0 -28
  139. package/dist/tools/assess-complexity-tool.js +0 -44
  140. package/dist/tools/query-routing-tool.d.ts +0 -17
  141. package/dist/tools/query-routing-tool.js +0 -59
  142. package/dist/utils/batch-operations.d.ts +0 -25
  143. package/dist/utils/batch-operations.js +0 -292
  144. package/dist/utils/task-graph.d.ts +0 -29
  145. package/dist/utils/task-graph.js +0 -106
  146. package/dist/utils/test-template-generator.d.ts +0 -25
  147. package/dist/utils/test-template-generator.js +0 -178
  148. package/dist/utils/token-manager.d.ts +0 -48
  149. package/dist/utils/token-manager.js +0 -163
  150. package/dist/validation/agent-config-validator.d.ts +0 -110
  151. package/dist/validation/agent-config-validator.js +0 -280
  152. package/dist/validation/orchestration-flow-validator.d.ts +0 -87
  153. package/dist/validation/orchestration-flow-validator.js +0 -606
  154. package/src/mcps/connection/connection-manager.ts +0 -91
  155. package/src/mcps/index.ts +0 -80
  156. package/src/mcps/orchestrator/index.ts +0 -29
@@ -1,118 +0,0 @@
1
- /**
2
- * Security Orchestration Layer
3
- *
4
- * Coordinates multiple security agents for comprehensive vulnerability scanning,
5
- * automated remediation, and compliance validation using weighted voting
6
- * for architectural decisions.
7
- *
8
- */
9
- import { EventEmitter } from "events";
10
- import { Vulnerability, RemediationPlan, ComplianceStandard } from "./comprehensive-security-audit.js";
11
- export interface SecurityAgent {
12
- id: string;
13
- name: string;
14
- type: SecurityAgentType;
15
- weight: number;
16
- status: AgentStatus;
17
- lastActive?: Date;
18
- capabilities: string[];
19
- }
20
- export type SecurityAgentType = "security-auditor" | "code-analyzer" | "testing-lead" | "architect" | "vulnerability-scanner" | "compliance-validator" | "remediation-specialist";
21
- export type AgentStatus = "idle" | "scanning" | "analyzing" | "reporting" | "error";
22
- export interface OrchestrationConfig {
23
- enableWeightedVoting: boolean;
24
- enableAutoRemediation: boolean;
25
- decisionThreshold: number;
26
- agentWeights: Record<SecurityAgentType, number>;
27
- scanDepth: "shallow" | "medium" | "deep";
28
- complianceStandards: ComplianceStandard[];
29
- maxConcurrentAgents: number;
30
- timeout: number;
31
- }
32
- export interface SecurityTask {
33
- id: string;
34
- type: SecurityTaskType;
35
- priority: "critical" | "high" | "medium" | "low";
36
- assignedAgent?: SecurityAgent;
37
- status: "pending" | "in-progress" | "completed" | "failed";
38
- result?: unknown;
39
- error?: string;
40
- createdAt: Date;
41
- completedAt?: Date;
42
- }
43
- export type SecurityTaskType = "vulnerability-scan" | "code-analysis" | "compliance-check" | "remediation" | "threat-detection" | "security-review";
44
- export interface AgentVote {
45
- agentId: string;
46
- agentName: string;
47
- vote: "approve" | "reject" | "abstain";
48
- weight: number;
49
- reasoning: string;
50
- concerns: string[] | undefined;
51
- confidence: number;
52
- }
53
- export interface SecurityDecision {
54
- id: string;
55
- title: string;
56
- description: string;
57
- type: "approval" | "rejection" | "revision-required";
58
- votes: AgentVote[];
59
- weightedApproval: number;
60
- threshold: number;
61
- approved: boolean;
62
- timestamp: Date;
63
- relatedVulnerabilities: string[] | undefined;
64
- }
65
- export interface SecurityOrchestrationReport {
66
- auditId: string;
67
- timestamp: Date;
68
- duration: number;
69
- agents: SecurityAgent[];
70
- tasks: SecurityTask[];
71
- decisions: SecurityDecision[];
72
- summary: {
73
- totalVulnerabilities: number;
74
- critical: number;
75
- high: number;
76
- medium: number;
77
- low: number;
78
- securityScore: number;
79
- complianceScore: number;
80
- };
81
- vulnerabilities: Vulnerability[];
82
- prioritizedRemediation: RemediationPlan[];
83
- recommendations: string[];
84
- }
85
- export declare class SecurityOrchestrationLayer extends EventEmitter {
86
- private config;
87
- private agents;
88
- private tasks;
89
- private decisions;
90
- private auditSystem;
91
- private isRunning;
92
- constructor(config?: Partial<OrchestrationConfig>);
93
- private initializeAgents;
94
- runSecurityOrchestration(projectPath: string): Promise<SecurityOrchestrationReport>;
95
- private createTask;
96
- private executeVulnerabilityScan;
97
- private executeComplianceCheck;
98
- private executeRemediationPlanning;
99
- private updateAgentStatus;
100
- private collectAgentVotes;
101
- private generateAgentVote;
102
- private makeSecurityDecisions;
103
- private createDecision;
104
- private generateOrchestrationReport;
105
- private calculateSecurityScore;
106
- private calculateComplianceScore;
107
- private prioritizeRemediation;
108
- private estimateFixTime;
109
- private generateRecommendations;
110
- getAgents(): SecurityAgent[];
111
- getAgent(agentId: string): SecurityAgent | undefined;
112
- getTasks(): SecurityTask[];
113
- getDecisions(): SecurityDecision[];
114
- getActiveAgents(): SecurityAgent[];
115
- getVulnerabilities(): Vulnerability[];
116
- }
117
- export declare function createSecurityOrchestrationLayer(config?: Partial<OrchestrationConfig>): SecurityOrchestrationLayer;
118
- export declare function runSecurityOrchestration(projectPath: string, config?: Partial<OrchestrationConfig>): Promise<SecurityOrchestrationReport>;
@@ -1,495 +0,0 @@
1
- /**
2
- * Security Orchestration Layer
3
- *
4
- * Coordinates multiple security agents for comprehensive vulnerability scanning,
5
- * automated remediation, and compliance validation using weighted voting
6
- * for architectural decisions.
7
- *
8
- */
9
- import { EventEmitter } from "events";
10
- import { frameworkLogger } from "../core/framework-logger.js";
11
- import { createSecurityAuditSystem, } from "./comprehensive-security-audit.js";
12
- const DEFAULT_CONFIG = {
13
- enableWeightedVoting: true,
14
- enableAutoRemediation: true,
15
- decisionThreshold: 0.5,
16
- agentWeights: {
17
- "security-auditor": 0.35,
18
- "code-analyzer": 0.30,
19
- "testing-lead": 0.20,
20
- architect: 0.15,
21
- "vulnerability-scanner": 0.25,
22
- "compliance-validator": 0.20,
23
- "remediation-specialist": 0.15,
24
- },
25
- scanDepth: "medium",
26
- complianceStandards: ["owasp-top-10", "cwe", "nist", "iso-27001", "pci-dss"],
27
- maxConcurrentAgents: 4,
28
- timeout: 300000,
29
- };
30
- export class SecurityOrchestrationLayer extends EventEmitter {
31
- config;
32
- agents = new Map();
33
- tasks = new Map();
34
- decisions = new Map();
35
- auditSystem = null;
36
- isRunning = false;
37
- constructor(config = {}) {
38
- super();
39
- this.config = { ...DEFAULT_CONFIG, ...config };
40
- this.initializeAgents();
41
- }
42
- initializeAgents() {
43
- const agentConfigs = [
44
- {
45
- id: "agent-security-auditor",
46
- name: "Security Auditor",
47
- type: "security-auditor",
48
- capabilities: [
49
- "vulnerability-scanning",
50
- "threat-detection",
51
- "security-auditing",
52
- "compliance-validation",
53
- ],
54
- },
55
- {
56
- id: "agent-code-analyzer",
57
- name: "Code Analyzer",
58
- type: "code-analyzer",
59
- capabilities: [
60
- "code-pattern-analysis",
61
- "static-analysis",
62
- "dependency-scanning",
63
- "security-hotspot-detection",
64
- ],
65
- },
66
- {
67
- id: "agent-testing-lead",
68
- name: "Testing Lead",
69
- type: "testing-lead",
70
- capabilities: [
71
- "security-testing",
72
- "penetration-testing",
73
- "test-coverage-analysis",
74
- "vulnerability-validation",
75
- ],
76
- },
77
- {
78
- id: "agent-architect",
79
- name: "Architect",
80
- type: "architect",
81
- capabilities: [
82
- "security-architecture",
83
- "threat-modeling",
84
- "design-review",
85
- "risk-assessment",
86
- ],
87
- },
88
- {
89
- id: "agent-vuln-scanner",
90
- name: "Vulnerability Scanner",
91
- type: "vulnerability-scanner",
92
- capabilities: [
93
- "automated-scanning",
94
- "dependency-analysis",
95
- "configuration-review",
96
- "exploit-detection",
97
- ],
98
- },
99
- {
100
- id: "agent-compliance",
101
- name: "Compliance Validator",
102
- type: "compliance-validator",
103
- capabilities: [
104
- "owasp-validation",
105
- "cwe-compliance",
106
- "nist-compliance",
107
- "iso-27001-validation",
108
- "pci-dss-validation",
109
- ],
110
- },
111
- {
112
- id: "agent-remediation",
113
- name: "Remediation Specialist",
114
- type: "remediation-specialist",
115
- capabilities: [
116
- "automated-remediation",
117
- "fix-prioritization",
118
- "patch-management",
119
- "code-generation",
120
- ],
121
- },
122
- ];
123
- for (const config of agentConfigs) {
124
- const agent = {
125
- id: config.id,
126
- name: config.name,
127
- type: config.type,
128
- weight: this.config.agentWeights[config.type] || 0.2,
129
- status: "idle",
130
- capabilities: config.capabilities,
131
- };
132
- this.agents.set(agent.id, agent);
133
- }
134
- frameworkLogger.log("security-orchestration", "agents-initialized", "info", { agentCount: this.agents.size });
135
- }
136
- async runSecurityOrchestration(projectPath) {
137
- if (this.isRunning) {
138
- throw new Error("Security orchestration is already running");
139
- }
140
- const startTime = Date.now();
141
- const auditId = `security-orchestration-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
142
- this.isRunning = true;
143
- frameworkLogger.log("security-orchestration", "orchestration-start", "info", {
144
- auditId,
145
- projectPath,
146
- config: this.config,
147
- });
148
- try {
149
- this.emit("orchestration:start", { auditId, projectPath });
150
- const securityTask = await this.createTask("vulnerability-scan", "high");
151
- const complianceTask = await this.createTask("compliance-check", "medium");
152
- const remediationTask = await this.createTask("remediation", "low");
153
- await Promise.all([
154
- this.executeVulnerabilityScan(projectPath, securityTask),
155
- this.executeComplianceCheck(complianceTask),
156
- this.executeRemediationPlanning(remediationTask),
157
- ]);
158
- if (this.config.enableWeightedVoting) {
159
- await this.collectAgentVotes();
160
- this.makeSecurityDecisions();
161
- }
162
- const report = await this.generateOrchestrationReport(auditId, startTime);
163
- this.emit("orchestration:complete", report);
164
- return report;
165
- }
166
- catch (error) {
167
- const errorMessage = error instanceof Error ? error.message : String(error);
168
- frameworkLogger.log("security-orchestration", "orchestration-error", "error", { auditId, error: errorMessage });
169
- this.emit("orchestration:error", { auditId, error: errorMessage });
170
- throw error;
171
- }
172
- finally {
173
- this.isRunning = false;
174
- }
175
- }
176
- async createTask(type, priority) {
177
- const task = {
178
- id: `task-${type}-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`,
179
- type,
180
- priority,
181
- status: "pending",
182
- createdAt: new Date(),
183
- };
184
- this.tasks.set(task.id, task);
185
- return task;
186
- }
187
- async executeVulnerabilityScan(projectPath, task) {
188
- task.status = "in-progress";
189
- this.updateAgentStatus("agent-security-auditor", "scanning");
190
- this.updateAgentStatus("agent-code-analyzer", "analyzing");
191
- try {
192
- this.auditSystem = createSecurityAuditSystem({
193
- projectPath,
194
- scanDepth: this.config.scanDepth,
195
- includeDependencies: true,
196
- complianceStandards: this.config.complianceStandards,
197
- enableAutoRemediation: this.config.enableAutoRemediation,
198
- enableWeightedVoting: this.config.enableWeightedVoting,
199
- agentWeights: this.config.agentWeights,
200
- });
201
- const report = await this.auditSystem.runAudit();
202
- task.result = report;
203
- task.status = "completed";
204
- task.completedAt = new Date();
205
- frameworkLogger.log("security-orchestration", "vulnerability-scan-complete", "info", {
206
- taskId: task.id,
207
- vulnerabilities: report.summary.totalVulnerabilities,
208
- score: report.summary.securityScore,
209
- });
210
- this.emit("task:complete", task);
211
- }
212
- catch (error) {
213
- task.status = "failed";
214
- task.error = error instanceof Error ? error.message : String(error);
215
- this.emit("task:failed", task);
216
- }
217
- finally {
218
- this.updateAgentStatus("agent-security-auditor", "idle");
219
- this.updateAgentStatus("agent-code-analyzer", "idle");
220
- }
221
- }
222
- async executeComplianceCheck(task) {
223
- task.status = "in-progress";
224
- this.updateAgentStatus("agent-compliance", "analyzing");
225
- try {
226
- if (this.auditSystem) {
227
- await new Promise((resolve) => setTimeout(resolve, 100));
228
- }
229
- task.status = "completed";
230
- task.completedAt = new Date();
231
- this.emit("task:complete", task);
232
- }
233
- catch (error) {
234
- task.status = "failed";
235
- task.error = error instanceof Error ? error.message : String(error);
236
- this.emit("task:failed", task);
237
- }
238
- finally {
239
- this.updateAgentStatus("agent-compliance", "idle");
240
- }
241
- }
242
- async executeRemediationPlanning(task) {
243
- task.status = "in-progress";
244
- this.updateAgentStatus("agent-remediation", "analyzing");
245
- try {
246
- if (this.auditSystem) {
247
- await new Promise((resolve) => setTimeout(resolve, 50));
248
- }
249
- task.status = "completed";
250
- task.completedAt = new Date();
251
- this.emit("task:complete", task);
252
- }
253
- catch (error) {
254
- task.status = "failed";
255
- task.error = error instanceof Error ? error.message : String(error);
256
- this.emit("task:failed", task);
257
- }
258
- finally {
259
- this.updateAgentStatus("agent-remediation", "idle");
260
- }
261
- }
262
- updateAgentStatus(agentId, status) {
263
- const agent = this.agents.get(agentId);
264
- if (agent) {
265
- agent.status = status;
266
- agent.lastActive = new Date();
267
- this.emit("agent:status-change", agent);
268
- }
269
- }
270
- async collectAgentVotes() {
271
- frameworkLogger.log("security-orchestration", "collecting-agent-votes", "info", { agentCount: this.agents.size });
272
- const vulnerabilities = this.auditSystem?.getVulnerabilities() || [];
273
- const criticalCount = vulnerabilities.filter((v) => v.severity === "critical").length;
274
- const highCount = vulnerabilities.filter((v) => v.severity === "high").length;
275
- for (const [agentId, agent] of this.agents) {
276
- const vote = await this.generateAgentVote(agent, vulnerabilities);
277
- this.emit("agent:vote", { agentId, vote });
278
- frameworkLogger.log("security-orchestration", "agent-vote-received", "info", {
279
- agentId,
280
- agentName: agent.name,
281
- vote: vote.vote,
282
- weight: vote.weight,
283
- });
284
- }
285
- }
286
- async generateAgentVote(agent, vulnerabilities) {
287
- const criticalCount = vulnerabilities.filter((v) => v.severity === "critical").length;
288
- const highCount = vulnerabilities.filter((v) => v.severity === "high").length;
289
- const totalVulns = vulnerabilities.length;
290
- let vote = "approve";
291
- let reasoning = `Security review complete. Found ${totalVulns} vulnerabilities.`;
292
- const concerns = [];
293
- if (criticalCount > 0) {
294
- concerns.push(`${criticalCount} critical vulnerabilities require immediate attention`);
295
- }
296
- if (highCount > 5) {
297
- concerns.push(`${highCount} high-severity vulnerabilities detected`);
298
- }
299
- if (criticalCount > 5) {
300
- vote = "reject";
301
- reasoning = "Too many critical vulnerabilities. Security posture unacceptable.";
302
- }
303
- else if (criticalCount > 0 || highCount > 10) {
304
- reasoning = "Acceptable with noted concerns. Priority fixes required.";
305
- }
306
- return {
307
- agentId: agent.id,
308
- agentName: agent.name,
309
- vote,
310
- weight: agent.weight,
311
- reasoning,
312
- concerns: concerns.length > 0 ? concerns : [],
313
- confidence: Math.max(0.5, 1 - (criticalCount * 0.1 + highCount * 0.02)),
314
- };
315
- }
316
- makeSecurityDecisions() {
317
- const vulnerabilities = this.auditSystem?.getVulnerabilities() || [];
318
- const decisions = [];
319
- const criticalVulns = vulnerabilities.filter((v) => v.severity === "critical");
320
- if (criticalVulns.length > 0) {
321
- const decision = this.createDecision("Critical Vulnerabilities Detected", `Found ${criticalVulns.length} critical vulnerabilities requiring immediate remediation`, "revision-required", criticalVulns.map((v) => v.id));
322
- decisions.push(decision);
323
- }
324
- const highVulns = vulnerabilities.filter((v) => v.severity === "high");
325
- if (highVulns.length > 5) {
326
- const decision = this.createDecision("High-Severity Vulnerability Threshold Exceeded", `Found ${highVulns.length} high-severity vulnerabilities. Security enhancements required.`, "approval", highVulns.map((v) => v.id));
327
- decisions.push(decision);
328
- }
329
- if (vulnerabilities.length === 0) {
330
- const decision = this.createDecision("Security Approval", "No vulnerabilities detected. System meets security standards.", "approval");
331
- decisions.push(decision);
332
- }
333
- for (const decision of decisions) {
334
- this.decisions.set(decision.id, decision);
335
- }
336
- frameworkLogger.log("security-orchestration", "decisions-made", "info", { decisionCount: decisions.length });
337
- }
338
- createDecision(title, description, type, relatedVulnerabilities) {
339
- const agents = Array.from(this.agents.values());
340
- const votes = agents.map((agent) => ({
341
- agentId: agent.id,
342
- agentName: agent.name,
343
- vote: type === "rejection" ? "reject" : "approve",
344
- weight: agent.weight,
345
- reasoning: "Automated voting based on vulnerability analysis",
346
- concerns: undefined,
347
- confidence: 0.85,
348
- }));
349
- const weightedApproval = votes.reduce((sum, v) => (v.vote === "approve" ? sum + v.weight : sum), 0) /
350
- votes.reduce((sum, v) => sum + v.weight, 0);
351
- return {
352
- id: `decision-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`,
353
- title,
354
- description,
355
- type,
356
- votes,
357
- weightedApproval,
358
- threshold: this.config.decisionThreshold,
359
- approved: weightedApproval >= this.config.decisionThreshold,
360
- timestamp: new Date(),
361
- relatedVulnerabilities,
362
- };
363
- }
364
- async generateOrchestrationReport(auditId, startTime) {
365
- const vulnerabilities = this.auditSystem?.getVulnerabilities() || [];
366
- const decisions = Array.from(this.decisions.values());
367
- const tasks = Array.from(this.tasks.values());
368
- const agents = Array.from(this.agents.values());
369
- const bySeverity = {
370
- critical: vulnerabilities.filter((v) => v.severity === "critical").length,
371
- high: vulnerabilities.filter((v) => v.severity === "high").length,
372
- medium: vulnerabilities.filter((v) => v.severity === "medium").length,
373
- low: vulnerabilities.filter((v) => v.severity === "low").length,
374
- };
375
- const securityScore = this.calculateSecurityScore(vulnerabilities);
376
- const complianceScore = this.calculateComplianceScore(vulnerabilities);
377
- const prioritizedRemediation = this.prioritizeRemediation(vulnerabilities);
378
- const report = {
379
- auditId,
380
- timestamp: new Date(),
381
- duration: Date.now() - startTime,
382
- agents,
383
- tasks,
384
- decisions,
385
- summary: {
386
- totalVulnerabilities: vulnerabilities.length,
387
- ...bySeverity,
388
- securityScore,
389
- complianceScore,
390
- },
391
- vulnerabilities,
392
- prioritizedRemediation,
393
- recommendations: this.generateRecommendations(vulnerabilities, decisions),
394
- };
395
- this.emit("orchestration:report", report);
396
- return report;
397
- }
398
- calculateSecurityScore(vulnerabilities) {
399
- const weights = {
400
- critical: 20,
401
- high: 10,
402
- medium: 5,
403
- low: 2,
404
- info: 0,
405
- };
406
- let score = 100;
407
- for (const vuln of vulnerabilities) {
408
- score -= weights[vuln.severity] || 0;
409
- }
410
- return Math.max(0, Math.min(100, score));
411
- }
412
- calculateComplianceScore(vulnerabilities) {
413
- const criticalVulns = vulnerabilities.filter((v) => v.severity === "critical").length;
414
- const highVulns = vulnerabilities.filter((v) => v.severity === "high").length;
415
- return Math.max(0, 100 - criticalVulns * 15 - highVulns * 5);
416
- }
417
- prioritizeRemediation(vulnerabilities) {
418
- const severityPriority = {
419
- critical: 1,
420
- high: 2,
421
- medium: 3,
422
- low: 4,
423
- info: 5,
424
- };
425
- return vulnerabilities
426
- .map((vuln) => ({
427
- vulnerabilityId: vuln.id,
428
- title: vuln.title,
429
- severity: vuln.severity,
430
- priority: severityPriority[vuln.severity],
431
- steps: vuln.autoRemediation || [],
432
- dependencies: [],
433
- estimatedTime: this.estimateFixTime(vuln.autoRemediation),
434
- }))
435
- .sort((a, b) => a.priority - b.priority);
436
- }
437
- estimateFixTime(steps) {
438
- if (!steps || steps.length === 0)
439
- return "30 minutes";
440
- const efforts = steps.map((s) => s.estimatedEffort || "medium");
441
- if (efforts.includes("high"))
442
- return "4 hours";
443
- if (efforts.includes("medium"))
444
- return "1 hour";
445
- return "15 minutes";
446
- }
447
- generateRecommendations(vulnerabilities, decisions) {
448
- const recommendations = [];
449
- const criticalCount = vulnerabilities.filter((v) => v.severity === "critical").length;
450
- const highCount = vulnerabilities.filter((v) => v.severity === "high").length;
451
- if (criticalCount > 0) {
452
- recommendations.push(`🚨 Address ${criticalCount} critical vulnerabilities immediately`);
453
- }
454
- if (highCount > 0) {
455
- recommendations.push(`⚠️ Prioritize fixing ${highCount} high-severity vulnerabilities`);
456
- }
457
- const automatable = vulnerabilities.filter((v) => v.autoRemediation?.[0]?.automated).length;
458
- if (automatable > 0) {
459
- recommendations.push(`🔧 ${automatable} vulnerabilities can be fixed automatically`);
460
- }
461
- const rejectedDecisions = decisions.filter((d) => d.type === "rejection");
462
- if (rejectedDecisions.length > 0) {
463
- recommendations.push("❌ Security architecture requires revision before deployment");
464
- }
465
- if (recommendations.length === 0) {
466
- recommendations.push("✅ No immediate security actions required");
467
- }
468
- return recommendations;
469
- }
470
- getAgents() {
471
- return Array.from(this.agents.values());
472
- }
473
- getAgent(agentId) {
474
- return this.agents.get(agentId);
475
- }
476
- getTasks() {
477
- return Array.from(this.tasks.values());
478
- }
479
- getDecisions() {
480
- return Array.from(this.decisions.values());
481
- }
482
- getActiveAgents() {
483
- return Array.from(this.agents.values()).filter((a) => a.status !== "idle");
484
- }
485
- getVulnerabilities() {
486
- return this.auditSystem?.getVulnerabilities() || [];
487
- }
488
- }
489
- export function createSecurityOrchestrationLayer(config) {
490
- return new SecurityOrchestrationLayer(config);
491
- }
492
- export async function runSecurityOrchestration(projectPath, config) {
493
- const orchestration = new SecurityOrchestrationLayer(config);
494
- return orchestration.runSecurityOrchestration(projectPath);
495
- }