0xray 2.1.1 → 2.1.3

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