0xray 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/codex.codex +1 -1
- package/.opencode/commands/auto-format.md +3 -3
- package/.opencode/commands/auto-summary-capture.md +2 -2
- package/.opencode/commands/enforcer-daily-scan.md +3 -3
- package/.opencode/commands/framework-compliance-audit.md +4 -4
- package/.opencode/commands/interactive-validator.md +2 -2
- package/.opencode/commands/job-summary-logger.md +2 -2
- package/.opencode/commands/mode-switch.md +1 -1
- package/.opencode/commands/model-health-check.md +2 -2
- package/.opencode/commands/performance-analysis.md +2 -2
- package/.opencode/commands/pre-commit-introspection.md +3 -3
- package/.opencode/commands/security-scan.md +3 -3
- package/.opencode/commands/sisyphus-validation.md +3 -3
- package/.opencode/commands/summary-logger.md +2 -2
- package/AGENTS.md +3 -13
- package/README.md +3 -3
- package/dist/AGENTS.md +3 -13
- package/dist/CHANGELOG.md +29 -0
- package/dist/README.md +3 -3
- package/dist/analytics/consent-manager.js +0 -1
- package/dist/analytics/emerging-pattern-detector.js +0 -1
- package/dist/analytics/pattern-learning-engine.js +0 -1
- package/dist/analytics/pattern-performance-tracker.js +0 -1
- package/dist/analytics/predictive-analytics.js +0 -1
- package/dist/analytics/prompt-pattern-analyzer.js +0 -1
- package/dist/analytics/routing-performance-analyzer.js +0 -1
- package/dist/analytics/routing-refiner.js +0 -1
- package/dist/analytics/simple-pattern-analyzer.js +0 -1
- package/dist/cli/commands/archive-logs.js +0 -1
- package/dist/cli/commands/opencode-install.js +13 -0
- package/dist/cli/commands/plugin-commands.js +0 -1
- package/dist/cli/commands/status.js +11 -13
- package/dist/cli/index.js +2 -7
- package/dist/core/activity-logger.js +0 -1
- package/dist/core/adaptive-kernel.js +0 -1
- package/dist/core/boot-orchestrator.js +2 -12
- package/dist/core/bridge.mjs +0 -1
- package/dist/core/codex-formatter.js +0 -1
- package/dist/core/codex-injector.js +0 -1
- package/dist/core/config-loader.js +36 -28
- package/dist/core/context-loader.js +0 -1
- package/dist/core/context-validator.js +0 -1
- package/dist/core/features-config.js +37 -1
- package/dist/core/kernel-patterns.js +0 -1
- package/dist/core/model-router.js +23 -64
- package/dist/core/system-prompt-generator.js +0 -1
- package/dist/delegation/agent-delegator.js +0 -1
- package/dist/delegation/agent-expertise.js +0 -1
- package/dist/delegation/analytics/index.js +0 -1
- package/dist/delegation/analytics/learning-engine.js +0 -1
- package/dist/delegation/analytics/outcome-tracker.js +0 -1
- package/dist/delegation/analytics/routing-analytics.js +0 -1
- package/dist/delegation/ast-code-parser.js +0 -1
- package/dist/delegation/complexity-analyzer.js +0 -1
- package/dist/delegation/dependency-graph-builder.js +0 -1
- package/dist/delegation/index.js +0 -1
- package/dist/delegation/metrics-aggregator.js +0 -1
- package/dist/delegation/session-coordinator.js +0 -1
- package/dist/delegation/strategy-selector.js +0 -1
- package/dist/delegation/voting-coordinator.js +0 -1
- package/dist/delegation/voting-types.js +0 -1
- package/dist/delegation/weighted-voting-aggregator.js +0 -1
- package/dist/enforcement/core/index.js +0 -1
- package/dist/enforcement/core/rule-executor.js +0 -1
- package/dist/enforcement/core/rule-hierarchy.js +0 -1
- package/dist/enforcement/core/rule-registry.js +0 -1
- package/dist/enforcement/core/violation-fixer.js +0 -1
- package/dist/enforcement/index.js +0 -1
- package/dist/enforcement/loaders/agent-triage-loader.js +0 -1
- package/dist/enforcement/loaders/agents-md-validation-loader.js +0 -1
- package/dist/enforcement/loaders/base-loader.js +0 -1
- package/dist/enforcement/loaders/codex-loader.js +0 -1
- package/dist/enforcement/loaders/index.js +0 -1
- package/dist/enforcement/loaders/loader-orchestrator.js +0 -1
- package/dist/enforcement/loaders/processor-loader.js +0 -1
- package/dist/enforcement/types.js +0 -1
- package/dist/enforcement/validators/architecture-validators.js +0 -1
- package/dist/enforcement/validators/base-validator.js +0 -1
- package/dist/enforcement/validators/code-quality-validators.js +0 -1
- package/dist/enforcement/validators/index.js +0 -1
- package/dist/enforcement/validators/security-validators.js +0 -1
- package/dist/enforcement/validators/testing-validators.js +0 -1
- package/dist/enforcement/validators/validator-registry.js +0 -1
- package/dist/governance/codex-policy.service.js +0 -1
- package/dist/inference/inference-agent-invoker.js +67 -0
- package/dist/inference/inference-applier.js +178 -0
- package/dist/inference/inference-cycle.js +51 -827
- package/dist/inference/inference-proposal-generator.js +149 -0
- package/dist/infrastructure/iac-validator.js +465 -0
- package/dist/infrastructure/schemas/cloud-schemas.js +488 -0
- package/dist/integrations/base/ExampleIntegration.js +0 -1
- package/dist/integrations/base/Integration.js +0 -1
- package/dist/integrations/base/index.js +0 -1
- package/dist/integrations/base/registry.js +0 -1
- package/dist/integrations/base/types.js +0 -1
- package/dist/integrations/enforcement-gate.js +3 -3
- package/dist/integrations/governance/governance-client.js +0 -1
- package/dist/integrations/governance/index.js +11 -19
- package/dist/integrations/governance/types.js +0 -1
- package/dist/integrations/hermes-agent/__init__.py +4 -0
- package/dist/integrations/hermes-agent/bridge.mjs +37 -0
- package/dist/integrations/openclaw/api-server.js +0 -1
- package/dist/integrations/openclaw/client.js +0 -1
- package/dist/integrations/openclaw/config.js +0 -1
- package/dist/integrations/openclaw/hooks/xray-hooks.js +0 -1
- package/dist/integrations/openclaw/index.js +0 -1
- package/dist/integrations/openclaw/types.js +0 -1
- package/dist/integrations/plugins/index.js +0 -1
- package/dist/integrations/plugins/plugin-integration.js +0 -1
- package/dist/integrations/plugins/plugin-registry.js +0 -1
- package/dist/mcps/agent-resolver.js +0 -1
- package/dist/mcps/architect-tools.server.js +119 -185
- package/dist/mcps/auto-format.server.js +56 -74
- package/dist/mcps/boot-orchestrator.server.js +67 -85
- package/dist/mcps/config/config-loader.js +6 -0
- package/dist/mcps/config/plugin-server-registry.js +0 -1
- package/dist/mcps/enforcer-tools.server.js +207 -273
- package/dist/mcps/estimation.server.js +63 -107
- package/dist/mcps/framework-compliance-audit.server.js +52 -81
- package/dist/mcps/framework-help.server.js +71 -89
- package/dist/mcps/governance.server.js +97 -149
- package/dist/mcps/knowledge-skills/api-design.server.js +33 -65
- package/dist/mcps/knowledge-skills/architecture-patterns.server.js +33 -65
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +123 -163
- package/dist/mcps/knowledge-skills/code-analyzer.server.js +210 -237
- package/dist/mcps/knowledge-skills/code-review.server.js +108 -142
- package/dist/mcps/knowledge-skills/content-creator.server.js +203 -225
- package/dist/mcps/knowledge-skills/database-design.server.js +116 -150
- package/dist/mcps/knowledge-skills/devops-deployment.server.js +123 -157
- package/dist/mcps/knowledge-skills/git-workflow.server.js +34 -67
- package/dist/mcps/knowledge-skills/growth-strategist.server.js +301 -323
- package/dist/mcps/knowledge-skills/log-monitor.server.js +139 -159
- package/dist/mcps/knowledge-skills/mobile-development.server.js +170 -200
- package/dist/mcps/knowledge-skills/multimodal-looker.server.js +122 -158
- package/dist/mcps/knowledge-skills/performance-optimization.server.js +88 -138
- package/dist/mcps/knowledge-skills/project-analysis.server.js +131 -218
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +115 -150
- package/dist/mcps/knowledge-skills/security-audit.server.js +16 -143
- package/dist/mcps/knowledge-skills/seo-consultant.server.js +20 -213
- package/dist/mcps/knowledge-skills/session-management.server.js +13 -90
- package/dist/mcps/knowledge-skills/skill-invocation.server.js +43 -421
- package/dist/mcps/knowledge-skills/strategist.server.js +10 -55
- package/dist/mcps/knowledge-skills/tech-writer.server.js +16 -191
- package/dist/mcps/knowledge-skills/testing-best-practices.server.js +18 -191
- package/dist/mcps/knowledge-skills/testing-strategy.server.js +18 -156
- package/dist/mcps/knowledge-skills/ui-ux-design.server.js +22 -296
- package/dist/mcps/lint.server.js +50 -91
- package/dist/mcps/model-health-check.server.js +32 -60
- package/dist/mcps/orchestrator/aside-context.js +207 -0
- package/dist/mcps/orchestrator/handlers/complexity-handler.js +5 -1
- package/dist/mcps/orchestrator/handlers/status-handler.js +8 -1
- package/dist/mcps/orchestrator/handlers/task-handler.js +5 -0
- package/dist/mcps/orchestrator/index.js +5 -0
- package/dist/mcps/orchestrator/server.js +63 -8
- package/dist/mcps/performance-analysis.server.js +56 -87
- package/dist/mcps/processor-pipeline.server.js +68 -99
- package/dist/mcps/researcher.server.js +80 -153
- package/dist/mcps/security-scan.server.js +56 -70
- package/dist/mcps/shared/knowledge-skill-base.js +11 -4
- package/dist/mcps/state-manager.server.js +124 -152
- package/dist/monitoring/nudge-watchdog.js +0 -1
- package/dist/nucleus/default-plugins.js +13 -19
- package/dist/nucleus/index.js +0 -1
- package/dist/orchestrator/agent-spawn-governor.js +0 -1
- package/dist/orchestrator/intelligent-commit-batcher.js +2 -10
- package/dist/orchestrator/multi-agent-orchestration-coordinator.js +0 -1
- package/dist/orchestrator/orchestrator.js +8 -18
- package/dist/orchestrator/self-direction-activation.js +0 -1
- package/dist/orchestrator/universal-registry-bridge.js +0 -1
- package/dist/performance/performance-budget-enforcer.js +0 -1
- package/dist/performance/performance-regression-tester.js +0 -1
- package/dist/plugin/plugin-codex-context.js +87 -0
- package/dist/plugin/plugin-helpers.js +155 -0
- package/dist/plugin/plugin-logger.js +46 -0
- package/dist/plugin/plugin-modules.js +144 -0
- package/dist/plugin/plugin-quality-gate.js +88 -0
- package/dist/plugin/plugin-types.js +1 -0
- package/dist/plugin/xray-codex-injection.js +338 -0
- package/dist/postprocessor/PostProcessor.js +3 -9
- package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +50 -0
- package/dist/postprocessor/config/ProcessorConfigLoader.js +16 -0
- package/dist/postprocessor/integration.js +194 -0
- package/dist/postprocessor/metamorphosis/SelfProposalEngine.js +472 -0
- package/dist/postprocessor/metamorphosis/index.js +1 -0
- package/dist/postprocessor/redeploy/RetryHandler.js +118 -0
- package/dist/postprocessor/services/RegressionAnalysisService.js +0 -1
- package/dist/postprocessor/triggers/APITrigger.js +0 -1
- package/dist/postprocessor/triggers/WebhookTrigger.js +0 -1
- package/dist/processors/implementations/agents-md-validation-processor.js +0 -1
- package/dist/processors/implementations/async-pattern-processor.js +0 -1
- package/dist/processors/implementations/console-log-guard-processor.js +0 -1
- package/dist/processors/implementations/coverage-analysis-processor.js +0 -1
- package/dist/processors/implementations/inference-improvement-processor.js +2 -9
- package/dist/processors/implementations/log-protection-processor.js +0 -1
- package/dist/processors/implementations/nudge-processor.js +0 -1
- package/dist/processors/implementations/performance-budget-processor.js +0 -1
- package/dist/processors/implementations/postprocessor-chain-validator.js +0 -1
- package/dist/processors/implementations/publish-preflight-processor.js +4 -12
- package/dist/processors/implementations/session-summary-processor.js +8 -16
- package/dist/processors/implementations/spawn-governance-processor.js +0 -1
- package/dist/processors/implementations/storytelling-trigger-processor.js +3 -28
- package/dist/processors/implementations/test-auto-creation-processor.js +0 -1
- package/dist/processors/implementations/typescript-compilation-processor.js +0 -1
- package/dist/processors/implementations/version-compliance-processor.js +0 -1
- package/dist/processors/processor-interfaces.js +0 -1
- package/dist/processors/processor-types.js +0 -1
- package/dist/scripts/integration.js +0 -1
- package/dist/security/comprehensive-security-audit.js +0 -1
- package/dist/security/security-agent-coordinator.js +0 -1
- package/dist/security/security-auditor.js +0 -1
- package/dist/security/security-hardener.js +0 -1
- package/dist/security/security-hardening-system.js +0 -1
- package/dist/security/security-headers.js +0 -1
- package/dist/security/security-orchestration-layer.js +0 -1
- package/dist/services/inference-tuner.js +0 -1
- package/dist/session/session-cleanup-manager.js +0 -1
- package/dist/session/session-monitor.js +0 -1
- package/dist/session/session-state-manager.js +0 -1
- package/dist/skills/xray-orchestrator/index.js +0 -1
- package/dist/utils/codex-parser.js +0 -1
- package/dist/utils/language-detector.js +0 -1
- package/dist/utils/shutdown-handler.js +0 -1
- package/dist/validation/agent-config-validator.js +280 -0
- package/dist/validation/orchestration-flow-validator.js +606 -0
- package/package.json +1 -1
- package/scripts/node/release.mjs +2 -2
- package/scripts/node/setup.cjs +28 -0
- package/scripts/node/universal-version-manager.js +1 -1
- package/src/mcps/agent-resolver.ts +0 -1
- package/src/mcps/architect-tools.server.ts +129 -211
- package/src/mcps/auto-format.server.ts +74 -103
- package/src/mcps/boot-orchestrator.server.ts +71 -96
- package/src/mcps/config/__tests__/config-loader.test.ts +6 -6
- package/src/mcps/config/config-loader.ts +7 -0
- package/src/mcps/config/plugin-server-registry.ts +0 -1
- package/src/mcps/enforcer-tools.server.ts +217 -294
- package/src/mcps/estimation.server.ts +62 -122
- package/src/mcps/framework-compliance-audit.server.ts +53 -95
- package/src/mcps/framework-help.server.ts +74 -96
- package/src/mcps/governance.server.ts +97 -162
- package/src/mcps/knowledge-skills/api-design.server.ts +33 -72
- package/src/mcps/knowledge-skills/architecture-patterns.server.ts +33 -72
- package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +148 -193
- package/src/mcps/knowledge-skills/code-analyzer.server.ts +222 -254
- package/src/mcps/knowledge-skills/code-review.server.ts +115 -157
- package/src/mcps/knowledge-skills/content-creator.server.ts +219 -246
- package/src/mcps/knowledge-skills/database-design.server.ts +119 -160
- package/src/mcps/knowledge-skills/devops-deployment.server.ts +126 -167
- package/src/mcps/knowledge-skills/git-workflow.server.ts +32 -77
- package/src/mcps/knowledge-skills/growth-strategist.server.ts +322 -360
- package/src/mcps/knowledge-skills/log-monitor.server.ts +68 -95
- package/src/mcps/knowledge-skills/mobile-development.server.ts +16 -56
- package/src/mcps/knowledge-skills/multimodal-looker.server.ts +13 -59
- package/src/mcps/knowledge-skills/performance-optimization.server.ts +13 -74
- package/src/mcps/knowledge-skills/project-analysis.server.ts +13 -120
- package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +13 -60
- package/src/mcps/knowledge-skills/security-audit.server.ts +19 -157
- package/src/mcps/knowledge-skills/seo-consultant.server.ts +23 -227
- package/src/mcps/knowledge-skills/session-management.server.ts +17 -106
- package/src/mcps/knowledge-skills/skill-invocation.server.ts +45 -446
- package/src/mcps/knowledge-skills/strategist.server.ts +13 -63
- package/src/mcps/knowledge-skills/tech-writer.server.ts +19 -204
- package/src/mcps/knowledge-skills/testing-best-practices.server.ts +21 -204
- package/src/mcps/knowledge-skills/testing-strategy.server.ts +21 -165
- package/src/mcps/knowledge-skills/ui-ux-design.server.ts +25 -342
- package/src/mcps/lint.server.ts +52 -105
- package/src/mcps/model-health-check.server.ts +34 -70
- package/src/mcps/orchestrator/aside-context.ts +245 -0
- package/src/mcps/orchestrator/handlers/complexity-handler.ts +9 -3
- package/src/mcps/orchestrator/handlers/status-handler.ts +11 -1
- package/src/mcps/orchestrator/handlers/task-handler.ts +8 -1
- package/src/mcps/orchestrator/index.ts +29 -0
- package/src/mcps/orchestrator/server.ts +79 -24
- package/src/mcps/orchestrator/types.ts +37 -0
- package/src/mcps/performance-analysis.server.ts +59 -102
- package/src/mcps/processor-pipeline.server.ts +70 -108
- package/src/mcps/researcher.server.ts +87 -175
- package/src/mcps/security-scan.server.ts +57 -76
- package/src/mcps/shared/knowledge-skill-base.ts +12 -4
- package/src/mcps/state-manager.server.ts +129 -169
- package/src/opencode/codex.codex +1 -1
- package/src/opencode/commands/auto-format.md +3 -3
- package/src/opencode/commands/auto-summary-capture.md +2 -2
- package/src/opencode/commands/enforcer-daily-scan.md +3 -3
- package/src/opencode/commands/framework-compliance-audit.md +4 -4
- package/src/opencode/commands/interactive-validator.md +2 -2
- package/src/opencode/commands/job-summary-logger.md +2 -2
- package/src/opencode/commands/mode-switch.md +1 -1
- package/src/opencode/commands/model-health-check.md +2 -2
- package/src/opencode/commands/performance-analysis.md +2 -2
- package/src/opencode/commands/pre-commit-introspection.md +3 -3
- package/src/opencode/commands/security-scan.md +3 -3
- package/src/opencode/commands/sisyphus-validation.md +3 -3
- package/src/opencode/commands/summary-logger.md +2 -2
- package/src/skills/xray-orchestrator/index.ts +0 -1
- package/dist/nucleus/orchestrator.js +0 -479
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
function classifyProposalType(problemPattern) {
|
|
2
|
+
const lower = problemPattern.toLowerCase();
|
|
3
|
+
if (lower.includes("bug") || lower.includes("fix") || lower.includes("stability"))
|
|
4
|
+
return "fix";
|
|
5
|
+
if (lower.includes("dead code") || lower.includes("remove") || lower.includes("health"))
|
|
6
|
+
return "refactor";
|
|
7
|
+
if (lower.includes("manual") || lower.includes("automate"))
|
|
8
|
+
return "automate";
|
|
9
|
+
if (lower.includes("guard") || lower.includes("path") || lower.includes("timing") || lower.includes("edge case"))
|
|
10
|
+
return "guard";
|
|
11
|
+
return "codify";
|
|
12
|
+
}
|
|
13
|
+
function patternToProposalType(pattern) {
|
|
14
|
+
const name = pattern.name.toLowerCase();
|
|
15
|
+
if (name.includes("dead code"))
|
|
16
|
+
return "refactor";
|
|
17
|
+
if (name.includes("extract"))
|
|
18
|
+
return "refactor";
|
|
19
|
+
if (name.includes("registry") || name.includes("facade"))
|
|
20
|
+
return "codify";
|
|
21
|
+
if (name.includes("test"))
|
|
22
|
+
return "guard";
|
|
23
|
+
if (name.includes("stability"))
|
|
24
|
+
return "fix";
|
|
25
|
+
return "codify";
|
|
26
|
+
}
|
|
27
|
+
const ACTION_MAP = [
|
|
28
|
+
[/^Bug fix$/i, "Fix recurring bug pattern"],
|
|
29
|
+
[/^Code health cleanup$/i, "Clean up code health issues"],
|
|
30
|
+
[/^Accumulated dead code$/i, "Remove accumulated dead code"],
|
|
31
|
+
[/^Incomplete implementation$/i, "Complete partial implementation"],
|
|
32
|
+
[/^Technical debt/i, "Address technical debt"],
|
|
33
|
+
[/^Missing guard/i, "Add missing guard"],
|
|
34
|
+
[/^Manual step/i, "Automate manual step"],
|
|
35
|
+
];
|
|
36
|
+
function generateTitle(problem) {
|
|
37
|
+
const pattern = problem.pattern;
|
|
38
|
+
for (const [re, title] of ACTION_MAP) {
|
|
39
|
+
if (re.test(pattern)) {
|
|
40
|
+
return `${title} (${problem.occurrences}x across ${problem.sessions.length} sessions)`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (pattern.length > 80) {
|
|
44
|
+
return `Address: ${pattern.substring(0, 77)}... (${problem.occurrences}x)`;
|
|
45
|
+
}
|
|
46
|
+
return `Address: ${pattern} (${problem.occurrences}x)`;
|
|
47
|
+
}
|
|
48
|
+
function adjustConfidenceFromHistory(proposals, history) {
|
|
49
|
+
if (history.length === 0)
|
|
50
|
+
return;
|
|
51
|
+
const recentVotes = history.slice(-10).flatMap((h) => h.votes);
|
|
52
|
+
const approvedIds = new Set(recentVotes.filter((v) => v.decision === "approve").map((v) => v.proposalId));
|
|
53
|
+
const approvedTypes = new Map();
|
|
54
|
+
const rejectedTypes = new Map();
|
|
55
|
+
for (const h of history.slice(-10)) {
|
|
56
|
+
for (const p of h.proposals) {
|
|
57
|
+
if (p.status === "approved" || p.status === "applied") {
|
|
58
|
+
approvedTypes.set(p.type, (approvedTypes.get(p.type) ?? 0) + 1);
|
|
59
|
+
}
|
|
60
|
+
else if (p.status === "rejected" || p.status === "failed") {
|
|
61
|
+
rejectedTypes.set(p.type, (rejectedTypes.get(p.type) ?? 0) + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const proposal of proposals) {
|
|
66
|
+
const approved = approvedTypes.get(proposal.type) ?? 0;
|
|
67
|
+
const rejected = rejectedTypes.get(proposal.type) ?? 0;
|
|
68
|
+
const total = approved + rejected;
|
|
69
|
+
if (total >= 3) {
|
|
70
|
+
const successRate = approved / total;
|
|
71
|
+
if (successRate < 0.3) {
|
|
72
|
+
proposal.confidence *= 0.8;
|
|
73
|
+
}
|
|
74
|
+
else if (successRate > 0.7) {
|
|
75
|
+
proposal.confidence = Math.min(0.95, proposal.confidence * 1.05);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function generateProposals(corpus, history) {
|
|
81
|
+
const proposals = [];
|
|
82
|
+
for (const problem of corpus.recurringProblems) {
|
|
83
|
+
proposals.push({
|
|
84
|
+
id: `prop-${Date.now()}-${proposals.length}`,
|
|
85
|
+
type: classifyProposalType(problem.pattern),
|
|
86
|
+
title: generateTitle(problem),
|
|
87
|
+
description: `Recurring across ${problem.occurrences} sessions: ${problem.pattern}`,
|
|
88
|
+
evidence: problem.sessions.map((s) => `Seen in session ${s}`),
|
|
89
|
+
confidence: Math.min(0.95, 0.5 + problem.occurrences * 0.15),
|
|
90
|
+
source: "recurring_problem",
|
|
91
|
+
status: "pending",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const seenPatterns = new Set(corpus.recurringProblems.map((p) => p.pattern));
|
|
95
|
+
const allProblems = corpus.sessions.flatMap((s) => s.problems.map((p) => ({ problem: p, session: s.sessionId })));
|
|
96
|
+
for (const { problem, session } of allProblems) {
|
|
97
|
+
const normalized = problem.replace(/\([a-f0-9]{7}\)/g, "").trim();
|
|
98
|
+
if (seenPatterns.has(normalized))
|
|
99
|
+
continue;
|
|
100
|
+
if (proposals.length >= 5)
|
|
101
|
+
break;
|
|
102
|
+
proposals.push({
|
|
103
|
+
id: `prop-${Date.now()}-${proposals.length}`,
|
|
104
|
+
type: classifyProposalType(problem),
|
|
105
|
+
title: `Investigate: ${problem.substring(0, 80)}`,
|
|
106
|
+
description: `Observed in session ${session}: ${problem}`,
|
|
107
|
+
evidence: [problem],
|
|
108
|
+
confidence: 0.4,
|
|
109
|
+
source: "recurring_problem",
|
|
110
|
+
status: "pending",
|
|
111
|
+
});
|
|
112
|
+
seenPatterns.add(normalized);
|
|
113
|
+
}
|
|
114
|
+
for (const pattern of corpus.recurringPatterns) {
|
|
115
|
+
if (pattern.occurrences < 2)
|
|
116
|
+
continue;
|
|
117
|
+
const type = patternToProposalType(pattern);
|
|
118
|
+
proposals.push({
|
|
119
|
+
id: `prop-${Date.now()}-${proposals.length}`,
|
|
120
|
+
type,
|
|
121
|
+
title: `Codify ${pattern.name} pattern`,
|
|
122
|
+
description: `${pattern.name} detected across ${pattern.occurrences} sessions (avg confidence: ${Math.round(pattern.avgConfidence * 100)}%). ${pattern.description}`,
|
|
123
|
+
evidence: pattern.evidence,
|
|
124
|
+
confidence: pattern.avgConfidence,
|
|
125
|
+
source: "recurring_pattern",
|
|
126
|
+
status: "pending",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const wrongTurns = corpus.allWrongTurns.slice(0, 2);
|
|
130
|
+
for (const wt of wrongTurns) {
|
|
131
|
+
const summary = wt.length > 50 ? `${wt.substring(0, 47)}...` : wt;
|
|
132
|
+
proposals.push({
|
|
133
|
+
id: `prop-${Date.now()}-${proposals.length}`,
|
|
134
|
+
type: "guard",
|
|
135
|
+
title: `Guard against: ${summary}`,
|
|
136
|
+
description: `Recurring wrong turn detected: ${wt}. Add a guard or validation to prevent this pattern.`,
|
|
137
|
+
evidence: [wt],
|
|
138
|
+
confidence: 0.7,
|
|
139
|
+
source: "wrong_turn",
|
|
140
|
+
status: "pending",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const sorted = proposals.sort((a, b) => b.confidence - a.confidence).slice(0, 3);
|
|
144
|
+
if (history && history.length > 0) {
|
|
145
|
+
adjustConfidenceFromHistory(sorted, history);
|
|
146
|
+
sorted.sort((a, b) => b.confidence - a.confidence);
|
|
147
|
+
}
|
|
148
|
+
return sorted;
|
|
149
|
+
}
|
|
@@ -0,0 +1,465 @@
|
|
|
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
|
+
}
|