0xray 4.0.34 → 4.0.36

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 (160) 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 +26 -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/grok/plugin/0xray/hooks/hooks.json +6 -6
  19. package/dist/integrations/hooks/goggles-mcp.mjs +10 -3
  20. package/dist/integrations/hooks/goggles-pipeline.mjs +110 -23
  21. package/dist/integrations/hooks/host-truth.mjs +74 -0
  22. package/dist/integrations/hooks/station-hook-runtime.cjs +3 -0
  23. package/dist/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  24. package/dist/mcps/knowledge-skills/storyteller.server.js +0 -1
  25. package/dist/nucleus/delegation-gate.d.ts +2 -2
  26. package/dist/nucleus/delegation-gate.js +13 -2
  27. package/dist/nucleus/work-freshness.mjs +189 -0
  28. package/dist/processors/implementations/agents-md-validation-processor.js +1 -1
  29. package/docs-site/docs/plates/boot.md +17 -2
  30. package/docs-site/docs/plates/governance.md +3 -2
  31. package/docs-site/docs/plates/index.md +3 -1
  32. package/docs-site/docs/plates/memory-recall.md +26 -35
  33. package/docs-site/docs/plates/orchestration.md +39 -35
  34. package/docs-site/docs/plates/processor.md +34 -36
  35. package/docs-site/docs/plates/reporting.md +3 -8
  36. package/docs-site/docs/plates/routing.md +22 -11
  37. package/package.json +3 -2
  38. package/scripts/foundry/release.mjs +48 -5
  39. package/scripts/mjs/run-grok-hook.mjs +50 -0
  40. package/scripts/mjs/test-consumer-readiness.mjs +1 -0
  41. package/scripts/mjs/test-mcp-functionality.mjs +14 -9
  42. package/scripts/node/basic-security-audit.cjs +0 -1
  43. package/scripts/node/bridge-mcp-wiring.cjs +66 -3
  44. package/scripts/node/install-bridges.cjs +3 -3
  45. package/scripts/node/postinstall.cjs +1 -1
  46. package/scripts/node/prepare-consumer.cjs +11 -7
  47. package/scripts/node/setup-dev.cjs +18 -26
  48. package/scripts/node/validate-mcp-connectivity.js +2 -1
  49. package/src/integrations/grok/plugin/0xray/hooks/hooks.json +6 -6
  50. package/src/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
  51. package/src/mcps/knowledge-skills/storyteller.server.ts +0 -1
  52. package/xray/agents_template.md +5 -5
  53. package/xray/codex.json +12 -4
  54. package/xray/features.json +1 -1
  55. package/dist/agents/known-names.d.ts +0 -26
  56. package/dist/agents/known-names.js +0 -72
  57. package/dist/analytics/consent-manager.d.ts +0 -92
  58. package/dist/analytics/consent-manager.js +0 -257
  59. package/dist/benchmark/performance-benchmark.d.ts +0 -103
  60. package/dist/benchmark/performance-benchmark.js +0 -373
  61. package/dist/cli/commands/analytics-disable.d.ts +0 -9
  62. package/dist/cli/commands/analytics-disable.js +0 -72
  63. package/dist/cli/commands/analytics-enable-action.d.ts +0 -8
  64. package/dist/cli/commands/analytics-enable-action.js +0 -82
  65. package/dist/cli/commands/analytics-preview.d.ts +0 -9
  66. package/dist/cli/commands/analytics-preview.js +0 -106
  67. package/dist/cli/commands/analytics-status.d.ts +0 -9
  68. package/dist/cli/commands/analytics-status.js +0 -68
  69. package/dist/cli/commands/enforce.d.ts +0 -12
  70. package/dist/cli/commands/enforce.js +0 -78
  71. package/dist/cli/commands/govern.d.ts +0 -29
  72. package/dist/cli/commands/govern.js +0 -149
  73. package/dist/cli/commands/security-audit.d.ts +0 -23
  74. package/dist/cli/commands/security-audit.js +0 -219
  75. package/dist/cli/server.d.ts +0 -1
  76. package/dist/cli/server.js +0 -147
  77. package/dist/config/routing-mappings.d.ts +0 -26
  78. package/dist/config/routing-mappings.js +0 -151
  79. package/dist/core/bridge.mjs +0 -922
  80. package/dist/core/trace-context.d.ts +0 -12
  81. package/dist/core/trace-context.js +0 -33
  82. package/dist/enforcement/index.d.ts +0 -22
  83. package/dist/enforcement/index.js +0 -40
  84. package/dist/enforcement/loaders/index.d.ts +0 -36
  85. package/dist/enforcement/loaders/index.js +0 -39
  86. package/dist/enforcement/test-auto-healing.d.ts +0 -83
  87. package/dist/enforcement/test-auto-healing.js +0 -325
  88. package/dist/inference/index.d.ts +0 -10
  89. package/dist/inference/index.js +0 -5
  90. package/dist/infrastructure/iac-validator.d.ts +0 -150
  91. package/dist/infrastructure/iac-validator.js +0 -465
  92. package/dist/infrastructure/schemas/cloud-schemas.d.ts +0 -482
  93. package/dist/infrastructure/schemas/cloud-schemas.js +0 -488
  94. package/dist/integrations/base/ExampleIntegration.d.ts +0 -46
  95. package/dist/integrations/base/ExampleIntegration.js +0 -180
  96. package/dist/integrations/enforcement-gate.d.ts +0 -44
  97. package/dist/integrations/enforcement-gate.js +0 -348
  98. package/dist/mcps/connection/connection-manager.d.ts +0 -39
  99. package/dist/mcps/connection/connection-manager.js +0 -79
  100. package/dist/mcps/index.d.ts +0 -17
  101. package/dist/mcps/index.js +0 -65
  102. package/dist/mcps/orchestrator/index.d.ts +0 -6
  103. package/dist/mcps/orchestrator/index.js +0 -5
  104. package/dist/metrics/index.d.ts +0 -6
  105. package/dist/metrics/index.js +0 -6
  106. package/dist/orchestrator/self-direction-activation.d.ts +0 -108
  107. package/dist/orchestrator/self-direction-activation.js +0 -244
  108. package/dist/orchestrator/universal-registry-bridge.d.ts +0 -84
  109. package/dist/orchestrator/universal-registry-bridge.js +0 -246
  110. package/dist/performance/performance-budget-enforcer.d.ts +0 -157
  111. package/dist/performance/performance-budget-enforcer.js +0 -433
  112. package/dist/performance/performance-regression-tester.d.ts +0 -107
  113. package/dist/performance/performance-regression-tester.js +0 -341
  114. package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +0 -11
  115. package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +0 -50
  116. package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +0 -44
  117. package/dist/postprocessor/config/ProcessorConfigLoader.js +0 -16
  118. package/dist/postprocessor/integration.d.ts +0 -156
  119. package/dist/postprocessor/integration.js +0 -194
  120. package/dist/postprocessor/metamorphosis/index.d.ts +0 -2
  121. package/dist/postprocessor/metamorphosis/index.js +0 -1
  122. package/dist/postprocessor/redeploy/RetryHandler.d.ts +0 -49
  123. package/dist/postprocessor/redeploy/RetryHandler.js +0 -118
  124. package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
  125. package/dist/processors/implementations/session-capture-processor.js +0 -37
  126. package/dist/public/XrayService.d.ts +0 -17
  127. package/dist/public/XrayService.js +0 -40
  128. package/dist/public/index.d.ts +0 -4
  129. package/dist/public/index.js +0 -2
  130. package/dist/security/comprehensive-security-audit.d.ts +0 -157
  131. package/dist/security/comprehensive-security-audit.js +0 -1004
  132. package/dist/security/index.d.ts +0 -13
  133. package/dist/security/index.js +0 -13
  134. package/dist/security/security-agent-coordinator.d.ts +0 -71
  135. package/dist/security/security-agent-coordinator.js +0 -203
  136. package/dist/security/security-hardening-system.d.ts +0 -238
  137. package/dist/security/security-hardening-system.js +0 -726
  138. package/dist/security/security-orchestration-layer.d.ts +0 -118
  139. package/dist/security/security-orchestration-layer.js +0 -495
  140. package/dist/testing/memory-regression-suite.d.ts +0 -105
  141. package/dist/testing/memory-regression-suite.js +0 -258
  142. package/dist/tools/assess-complexity-tool.d.ts +0 -28
  143. package/dist/tools/assess-complexity-tool.js +0 -44
  144. package/dist/tools/query-routing-tool.d.ts +0 -17
  145. package/dist/tools/query-routing-tool.js +0 -59
  146. package/dist/utils/batch-operations.d.ts +0 -25
  147. package/dist/utils/batch-operations.js +0 -292
  148. package/dist/utils/task-graph.d.ts +0 -29
  149. package/dist/utils/task-graph.js +0 -106
  150. package/dist/utils/test-template-generator.d.ts +0 -25
  151. package/dist/utils/test-template-generator.js +0 -178
  152. package/dist/utils/token-manager.d.ts +0 -48
  153. package/dist/utils/token-manager.js +0 -163
  154. package/dist/validation/agent-config-validator.d.ts +0 -110
  155. package/dist/validation/agent-config-validator.js +0 -280
  156. package/dist/validation/orchestration-flow-validator.d.ts +0 -87
  157. package/dist/validation/orchestration-flow-validator.js +0 -606
  158. package/src/mcps/connection/connection-manager.ts +0 -91
  159. package/src/mcps/index.ts +0 -80
  160. package/src/mcps/orchestrator/index.ts +0 -29
@@ -1,150 +0,0 @@
1
- /**
2
- * Infrastructure as Code Validation System
3
- *
4
- * Comprehensive IaC validation with schema enforcement, pre-commit hooks,
5
- * and automated CI/CD integration for enterprise-grade cloud deployments.
6
- *
7
- * @since 2026-01-08
8
- */
9
- import { z } from "zod";
10
- export declare enum ValidationSeverity {
11
- ERROR = "error",
12
- WARNING = "warning",
13
- INFO = "info"
14
- }
15
- export interface ValidationResult {
16
- file: string;
17
- valid: boolean;
18
- errors: ValidationError[];
19
- warnings: ValidationWarning[];
20
- }
21
- export interface ValidationError {
22
- path: string;
23
- message: string;
24
- severity: ValidationSeverity.ERROR;
25
- line?: number;
26
- column?: number;
27
- }
28
- export interface ValidationWarning {
29
- path: string;
30
- message: string;
31
- severity: ValidationSeverity.WARNING;
32
- suggestion?: string;
33
- }
34
- export declare const CloudFormationSchema: z.ZodObject<{
35
- AWSTemplateFormatVersion: z.ZodOptional<z.ZodString>;
36
- Description: z.ZodOptional<z.ZodString>;
37
- Metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
38
- Parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
39
- Type: z.ZodString;
40
- Default: z.ZodOptional<z.ZodAny>;
41
- AllowedValues: z.ZodOptional<z.ZodArray<z.ZodAny>>;
42
- Description: z.ZodOptional<z.ZodString>;
43
- }, z.core.$strip>>>;
44
- Mappings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>>;
45
- Conditions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
46
- Transform: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
47
- Resources: z.ZodRecord<z.ZodString, z.ZodObject<{
48
- Type: z.ZodString;
49
- Properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
50
- DependsOn: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
51
- Metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
52
- DeletionPolicy: z.ZodOptional<z.ZodEnum<{
53
- Delete: "Delete";
54
- Retain: "Retain";
55
- Snapshot: "Snapshot";
56
- }>>;
57
- }, z.core.$strip>>;
58
- Outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
59
- Description: z.ZodOptional<z.ZodString>;
60
- Value: z.ZodAny;
61
- Export: z.ZodOptional<z.ZodObject<{
62
- Name: z.ZodString;
63
- }, z.core.$strip>>;
64
- }, z.core.$strip>>>;
65
- }, z.core.$strip>;
66
- export declare const TerraformSchema: z.ZodObject<{
67
- terraform: z.ZodOptional<z.ZodObject<{
68
- required_version: z.ZodOptional<z.ZodString>;
69
- required_providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
70
- version: z.ZodOptional<z.ZodString>;
71
- source: z.ZodOptional<z.ZodString>;
72
- }, z.core.$strip>>>;
73
- backend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
74
- }, z.core.$strip>>;
75
- provider: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>;
76
- resource: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>>;
77
- data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>>;
78
- variable: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
79
- type: z.ZodOptional<z.ZodString>;
80
- default: z.ZodOptional<z.ZodAny>;
81
- description: z.ZodOptional<z.ZodString>;
82
- validation: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
- condition: z.ZodAny;
84
- error_message: z.ZodString;
85
- }, z.core.$strip>>>;
86
- }, z.core.$strip>>>;
87
- output: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
88
- value: z.ZodAny;
89
- description: z.ZodOptional<z.ZodString>;
90
- sensitive: z.ZodOptional<z.ZodBoolean>;
91
- }, z.core.$strip>>>;
92
- locals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
93
- module: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>;
94
- }, z.core.$strip>;
95
- export declare const KubernetesSchema: z.ZodObject<{
96
- apiVersion: z.ZodString;
97
- kind: z.ZodString;
98
- metadata: z.ZodObject<{
99
- name: z.ZodString;
100
- namespace: z.ZodOptional<z.ZodString>;
101
- labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
102
- annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
103
- }, z.core.$strip>;
104
- spec: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
105
- status: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
106
- }, z.core.$strip>;
107
- export declare const DockerComposeSchema: z.ZodObject<{
108
- version: z.ZodOptional<z.ZodString>;
109
- services: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
110
- image: z.ZodOptional<z.ZodString>;
111
- build: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
112
- ports: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
113
- environment: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodString>, z.ZodArray<z.ZodString>]>>;
114
- volumes: z.ZodOptional<z.ZodArray<z.ZodString>>;
115
- depends_on: z.ZodOptional<z.ZodArray<z.ZodString>>;
116
- networks: z.ZodOptional<z.ZodArray<z.ZodString>>;
117
- restart: z.ZodOptional<z.ZodEnum<{
118
- always: "always";
119
- no: "no";
120
- "on-failure": "on-failure";
121
- "unless-stopped": "unless-stopped";
122
- }>>;
123
- }, z.core.$strip>>>;
124
- volumes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>;
125
- networks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>>>;
126
- }, z.core.$strip>;
127
- export declare class IaCValidator {
128
- private schemas;
129
- constructor();
130
- private registerSchemas;
131
- validateFile(filePath: string): Promise<ValidationResult>;
132
- private validateJsonFile;
133
- private validateYamlFile;
134
- private performSecurityChecks;
135
- validateDirectory(dirPath: string): Promise<ValidationResult[]>;
136
- private findIaCFiles;
137
- }
138
- export declare class PreCommitValidator {
139
- private validator;
140
- constructor();
141
- validateStagedFiles(): Promise<{
142
- success: boolean;
143
- results: ValidationResult[];
144
- }>;
145
- validateAllIaCFiles(): Promise<{
146
- success: boolean;
147
- results: ValidationResult[];
148
- }>;
149
- }
150
- export declare function validateCommand(args: string[]): Promise<void>;
@@ -1,465 +0,0 @@
1
- /**
2
- * Infrastructure as Code Validation System
3
- *
4
- * Comprehensive IaC validation with schema enforcement, pre-commit hooks,
5
- * and automated CI/CD integration for enterprise-grade cloud deployments.
6
- *
7
- * @since 2026-01-08
8
- */
9
- import { z } from "zod";
10
- import * as fs from "fs";
11
- import * as path from "path";
12
- import { spawn } from "child_process";
13
- import { frameworkLogger } from "../core/framework-logger.js";
14
- // ============================================================================
15
- // Schema Validation Types
16
- // ============================================================================
17
- export var ValidationSeverity;
18
- (function (ValidationSeverity) {
19
- ValidationSeverity["ERROR"] = "error";
20
- ValidationSeverity["WARNING"] = "warning";
21
- ValidationSeverity["INFO"] = "info";
22
- })(ValidationSeverity || (ValidationSeverity = {}));
23
- // ============================================================================
24
- // Base Schema Validators
25
- // ============================================================================
26
- export const CloudFormationSchema = z.object({
27
- AWSTemplateFormatVersion: z.string().optional(),
28
- Description: z.string().optional(),
29
- Metadata: z.record(z.string(), z.any()).optional(),
30
- Parameters: z
31
- .record(z.string(), z.object({
32
- Type: z.string(),
33
- Default: z.any().optional(),
34
- AllowedValues: z.array(z.any()).optional(),
35
- Description: z.string().optional(),
36
- }))
37
- .optional(),
38
- Mappings: z
39
- .record(z.string(), z.record(z.string(), z.record(z.string(), z.any())))
40
- .optional(),
41
- Conditions: z.record(z.string(), z.any()).optional(),
42
- Transform: z.union([z.string(), z.array(z.string())]).optional(),
43
- Resources: z.record(z.string(), z.object({
44
- Type: z.string(),
45
- Properties: z.record(z.string(), z.any()).optional(),
46
- DependsOn: z.union([z.string(), z.array(z.string())]).optional(),
47
- Metadata: z.record(z.string(), z.any()).optional(),
48
- DeletionPolicy: z.enum(["Delete", "Retain", "Snapshot"]).optional(),
49
- })),
50
- Outputs: z
51
- .record(z.string(), z.object({
52
- Description: z.string().optional(),
53
- Value: z.any(),
54
- Export: z
55
- .object({
56
- Name: z.string(),
57
- })
58
- .optional(),
59
- }))
60
- .optional(),
61
- });
62
- export const TerraformSchema = z.object({
63
- terraform: z
64
- .object({
65
- required_version: z.string().optional(),
66
- required_providers: z
67
- .record(z.string(), z.object({
68
- version: z.string().optional(),
69
- source: z.string().optional(),
70
- }))
71
- .optional(),
72
- backend: z.record(z.string(), z.any()).optional(),
73
- })
74
- .optional(),
75
- provider: z.record(z.string(), z.record(z.string(), z.any())).optional(),
76
- resource: z
77
- .record(z.string(), z.record(z.string(), z.record(z.string(), z.any())))
78
- .optional(),
79
- data: z
80
- .record(z.string(), z.record(z.string(), z.record(z.string(), z.any())))
81
- .optional(),
82
- variable: z
83
- .record(z.string(), z.object({
84
- type: z.string().optional(),
85
- default: z.any().optional(),
86
- description: z.string().optional(),
87
- validation: z
88
- .array(z.object({
89
- condition: z.any(),
90
- error_message: z.string(),
91
- }))
92
- .optional(),
93
- }))
94
- .optional(),
95
- output: z
96
- .record(z.string(), z.object({
97
- value: z.any(),
98
- description: z.string().optional(),
99
- sensitive: z.boolean().optional(),
100
- }))
101
- .optional(),
102
- locals: z.record(z.string(), z.any()).optional(),
103
- module: z.record(z.string(), z.record(z.string(), z.any())).optional(),
104
- });
105
- export const KubernetesSchema = z.object({
106
- apiVersion: z.string(),
107
- kind: z.string(),
108
- metadata: z.object({
109
- name: z.string(),
110
- namespace: z.string().optional(),
111
- labels: z.record(z.string(), z.string()).optional(),
112
- annotations: z.record(z.string(), z.string()).optional(),
113
- }),
114
- spec: z.record(z.string(), z.any()).optional(),
115
- status: z.record(z.string(), z.any()).optional(),
116
- });
117
- export const DockerComposeSchema = z.object({
118
- version: z.string().optional(),
119
- services: z
120
- .record(z.string(), z.object({
121
- image: z.string().optional(),
122
- build: z.union([z.string(), z.record(z.string(), z.any())]).optional(),
123
- ports: z.array(z.union([z.string(), z.number()])).optional(),
124
- environment: z
125
- .union([z.record(z.string(), z.string()), z.array(z.string())])
126
- .optional(),
127
- volumes: z.array(z.string()).optional(),
128
- depends_on: z.array(z.string()).optional(),
129
- networks: z.array(z.string()).optional(),
130
- restart: z
131
- .enum(["no", "always", "on-failure", "unless-stopped"])
132
- .optional(),
133
- }))
134
- .optional(),
135
- volumes: z.record(z.string(), z.record(z.string(), z.any())).optional(),
136
- networks: z.record(z.string(), z.record(z.string(), z.any())).optional(),
137
- });
138
- // ============================================================================
139
- // IaC Validator Class
140
- // ============================================================================
141
- export class IaCValidator {
142
- schemas = new Map();
143
- constructor() {
144
- this.registerSchemas();
145
- }
146
- registerSchemas() {
147
- // CloudFormation
148
- this.schemas.set("template.yaml", CloudFormationSchema);
149
- this.schemas.set("template.yml", CloudFormationSchema);
150
- this.schemas.set("cf-template.yaml", CloudFormationSchema);
151
- this.schemas.set("cf-template.yml", CloudFormationSchema);
152
- // Terraform
153
- this.schemas.set("main.tf", TerraformSchema);
154
- this.schemas.set("variables.tf", TerraformSchema);
155
- this.schemas.set("outputs.tf", TerraformSchema);
156
- this.schemas.set("terraform.tf", TerraformSchema);
157
- // Kubernetes
158
- this.schemas.set("deployment.yaml", KubernetesSchema);
159
- this.schemas.set("deployment.yml", KubernetesSchema);
160
- this.schemas.set("service.yaml", KubernetesSchema);
161
- this.schemas.set("service.yml", KubernetesSchema);
162
- this.schemas.set("configmap.yaml", KubernetesSchema);
163
- this.schemas.set("configmap.yml", KubernetesSchema);
164
- this.schemas.set("secret.yaml", KubernetesSchema);
165
- this.schemas.set("secret.yml", KubernetesSchema);
166
- // Docker Compose
167
- this.schemas.set("docker-compose.yaml", DockerComposeSchema);
168
- this.schemas.set("docker-compose.yml", DockerComposeSchema);
169
- this.schemas.set("compose.yaml", DockerComposeSchema);
170
- this.schemas.set("compose.yml", DockerComposeSchema);
171
- }
172
- async validateFile(filePath) {
173
- const result = {
174
- file: filePath,
175
- valid: true,
176
- errors: [],
177
- warnings: [],
178
- };
179
- try {
180
- const content = fs.readFileSync(filePath, "utf-8");
181
- const ext = path.extname(filePath).toLowerCase();
182
- const filename = path.basename(filePath).toLowerCase();
183
- // Determine file type and validate
184
- if (ext === ".json") {
185
- await this.validateJsonFile(content, result);
186
- }
187
- else if (ext === ".yaml" || ext === ".yml") {
188
- await this.validateYamlFile(filename, content, result);
189
- }
190
- // Additional security and best practice checks
191
- this.performSecurityChecks(filePath, content, result);
192
- }
193
- catch (error) {
194
- result.valid = false;
195
- result.errors.push({
196
- path: filePath,
197
- message: `Failed to read or parse file: ${error instanceof Error ? error.message : String(error)}`,
198
- severity: ValidationSeverity.ERROR,
199
- });
200
- }
201
- return result;
202
- }
203
- async validateJsonFile(content, result) {
204
- try {
205
- JSON.parse(content);
206
- }
207
- catch (error) {
208
- result.valid = false;
209
- result.errors.push({
210
- path: result.file,
211
- message: `Invalid JSON: ${error instanceof Error ? error.message : String(error)}`,
212
- severity: ValidationSeverity.ERROR,
213
- });
214
- }
215
- }
216
- async validateYamlFile(filename, content, result) {
217
- try {
218
- // Import yaml parser dynamically to avoid dependency issues
219
- const yaml = await import("yaml");
220
- const data = yaml.parse(content);
221
- const schema = this.schemas.get(filename);
222
- if (schema) {
223
- const validation = schema.safeParse(data);
224
- if (!validation.success) {
225
- result.valid = false;
226
- validation.error.issues.forEach((err) => {
227
- result.errors.push({
228
- path: `${result.file}.${err.path.join(".")}`,
229
- message: err.message,
230
- severity: ValidationSeverity.ERROR,
231
- });
232
- });
233
- }
234
- }
235
- // Basic YAML structure validation
236
- if (typeof data !== "object" || data === null) {
237
- result.valid = false;
238
- result.errors.push({
239
- path: result.file,
240
- message: "YAML file must contain a valid object structure",
241
- severity: ValidationSeverity.ERROR,
242
- });
243
- }
244
- }
245
- catch (error) {
246
- result.valid = false;
247
- result.errors.push({
248
- path: result.file,
249
- message: `Failed to parse YAML: ${error instanceof Error ? error.message : String(error)}`,
250
- severity: ValidationSeverity.ERROR,
251
- });
252
- }
253
- }
254
- performSecurityChecks(filePath, content, result) {
255
- const filename = path.basename(filePath).toLowerCase();
256
- // Check for hardcoded secrets
257
- const secretPatterns = [
258
- /password\s*[:=]\s*['"]\w+['"]/i,
259
- /secret\s*[:=]\s*['"]\w+['"]/i,
260
- /token\s*[:=]\s*['"]\w+['"]/i,
261
- /key\s*[:=]\s*['"]\w+['"]/i,
262
- /api[_-]?key\s*[:=]\s*['"]\w+['"]/i,
263
- ];
264
- secretPatterns.forEach((pattern) => {
265
- const matches = content.match(pattern);
266
- if (matches) {
267
- result.warnings.push({
268
- path: filePath,
269
- message: "Potential hardcoded secret detected",
270
- severity: ValidationSeverity.WARNING,
271
- suggestion: "Use environment variables or secret management services",
272
- });
273
- }
274
- });
275
- // Check for overly permissive permissions
276
- if (filename.includes("iam") || filename.includes("policy")) {
277
- if (content.includes("*") && content.includes("Action")) {
278
- result.warnings.push({
279
- path: filePath,
280
- message: "Overly permissive IAM policy detected (* action)",
281
- severity: ValidationSeverity.WARNING,
282
- suggestion: "Specify explicit actions instead of wildcard",
283
- });
284
- }
285
- }
286
- // Check for missing resource constraints
287
- if (filename.includes("deployment") || filename.includes("pod")) {
288
- if (!content.includes("resources") && !content.includes("limits")) {
289
- result.warnings.push({
290
- path: filePath,
291
- message: "Missing resource limits in deployment",
292
- severity: ValidationSeverity.WARNING,
293
- suggestion: "Add CPU and memory limits for production deployments",
294
- });
295
- }
296
- }
297
- }
298
- async validateDirectory(dirPath) {
299
- const results = [];
300
- const files = this.findIaCFiles(dirPath);
301
- for (const file of files) {
302
- const result = await this.validateFile(file);
303
- results.push(result);
304
- }
305
- return results;
306
- }
307
- findIaCFiles(dirPath) {
308
- const files = [];
309
- const extensions = [".yaml", ".yml", ".json", ".tf"];
310
- const filenames = Array.from(this.schemas.keys());
311
- function scanDir(currentPath) {
312
- const items = fs.readdirSync(currentPath);
313
- for (const item of items) {
314
- const fullPath = path.join(currentPath, item);
315
- const stat = fs.statSync(fullPath);
316
- if (stat.isDirectory() &&
317
- !item.startsWith(".") &&
318
- item !== "node_modules") {
319
- scanDir(fullPath);
320
- }
321
- else if (stat.isFile()) {
322
- const ext = path.extname(item).toLowerCase();
323
- const filename = item.toLowerCase();
324
- if (extensions.includes(ext) || filenames.includes(filename)) {
325
- files.push(fullPath);
326
- }
327
- }
328
- }
329
- }
330
- scanDir(dirPath);
331
- return files;
332
- }
333
- }
334
- // ============================================================================
335
- // Pre-commit Hook Integration
336
- // ============================================================================
337
- export class PreCommitValidator {
338
- validator;
339
- constructor() {
340
- this.validator = new IaCValidator();
341
- }
342
- async validateStagedFiles() {
343
- try {
344
- // Get staged files using spawn to prevent command injection
345
- const stagedFiles = await new Promise((resolve, reject) => {
346
- const gitProcess = spawn("git", ["diff", "--cached", "--name-only"]);
347
- let stdout = "";
348
- let stderr = "";
349
- gitProcess.stdout?.on("data", (data) => {
350
- stdout += data.toString();
351
- });
352
- gitProcess.stderr?.on("data", (data) => {
353
- stderr += data.toString();
354
- });
355
- gitProcess.on("close", (code) => {
356
- if (code === 0) {
357
- const files = stdout
358
- .split("\n")
359
- .filter((file) => file.trim() &&
360
- (file.endsWith(".yaml") ||
361
- file.endsWith(".yml") ||
362
- file.endsWith(".json") ||
363
- file.endsWith(".tf")));
364
- resolve(files);
365
- }
366
- else {
367
- reject(new Error(`git failed with code ${code}: ${stderr}`));
368
- }
369
- });
370
- gitProcess.on("error", (err) => {
371
- reject(new Error(`Failed to spawn git: ${err.message}`));
372
- });
373
- });
374
- const results = [];
375
- for (const file of stagedFiles) {
376
- if (fs.existsSync(file)) {
377
- const result = await this.validator.validateFile(file);
378
- results.push(result);
379
- }
380
- }
381
- const hasErrors = results.some((r) => !r.valid);
382
- return { success: !hasErrors, results };
383
- }
384
- catch (error) {
385
- frameworkLogger.log("IaCValidator", "validate-staged-files", "error", { error, message: "Failed to validate staged files:" });
386
- return { success: false, results: [] };
387
- }
388
- }
389
- async validateAllIaCFiles() {
390
- const results = await this.validator.validateDirectory(process.cwd());
391
- const hasErrors = results.some((r) => !r.valid);
392
- return { success: !hasErrors, results };
393
- }
394
- }
395
- // ============================================================================
396
- // CLI Interface
397
- // ============================================================================
398
- export async function validateCommand(args) {
399
- const validator = new IaCValidator();
400
- const preCommitValidator = new PreCommitValidator();
401
- if (args.includes("--staged")) {
402
- const { success, results } = await preCommitValidator.validateStagedFiles();
403
- printResults(results);
404
- if (!success) {
405
- frameworkLogger.log("IaCValidator", "validate-staged", "error", { message: "\n❌ IaC validation failed. Please fix errors before committing." });
406
- process.exit(1);
407
- }
408
- else {
409
- await frameworkLogger.log("iac-validator", "-n-all-iac-files-passed-validation-", "success", { message: "\n✅ All IaC files passed validation." });
410
- }
411
- }
412
- else if (args.includes("--all")) {
413
- const { success, results } = await preCommitValidator.validateAllIaCFiles();
414
- printResults(results);
415
- if (!success) {
416
- frameworkLogger.log("IaCValidator", "validate-all", "error", { message: "\n❌ IaC validation failed." });
417
- process.exit(1);
418
- }
419
- else {
420
- await frameworkLogger.log("iac-validator", "-n-all-iac-files-passed-validation-", "success", { message: "\n✅ All IaC files passed validation." });
421
- }
422
- }
423
- else {
424
- const targetPath = args[0] || ".";
425
- const results = await validator.validateDirectory(targetPath);
426
- printResults(results);
427
- const hasErrors = results.some((r) => !r.valid);
428
- if (hasErrors) {
429
- process.exit(1);
430
- }
431
- }
432
- }
433
- async function printResults(results) {
434
- for (const result of results) {
435
- await frameworkLogger.log("iac-validator", "-n-result-file-", "info", {
436
- message: `\n📄 ${result.file}:`,
437
- });
438
- if (result.errors.length > 0) {
439
- await frameworkLogger.log("iac-validator", "-errors-", "error", {
440
- message: " ❌ Errors:",
441
- });
442
- result.errors.forEach((error) => {
443
- void frameworkLogger.log("iac-validator", "-error-path-error-message-", "error", { message: ` • ${error.path}: ${error.message}` });
444
- });
445
- }
446
- if (result.warnings.length > 0) {
447
- await frameworkLogger.log("iac-validator", "-warnings-", "info", {
448
- message: " ⚠️ Warnings:",
449
- });
450
- result.warnings.forEach((warning) => {
451
- void frameworkLogger.log("iac-validator", "-warning-path-warning-message-", "info", { message: ` • ${warning.path}: ${warning.message}` });
452
- if (warning.suggestion) {
453
- void frameworkLogger.log("iac-validator", "-warning-suggestion-", "info", { message: ` 💡 ${warning.suggestion}` });
454
- }
455
- });
456
- }
457
- if (result.valid &&
458
- result.errors.length === 0 &&
459
- result.warnings.length === 0) {
460
- await frameworkLogger.log("iac-validator", "-valid-", "success", {
461
- message: " ✅ Valid",
462
- });
463
- }
464
- }
465
- }