mcp-adr-analysis-server 2.0.21 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -839
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/config/ai-config.d.ts.map +1 -1
- package/dist/src/config/ai-config.js +9 -9
- package/dist/src/config/ai-config.js.map +1 -1
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1594 -837
- package/dist/src/index.js.map +1 -1
- package/dist/src/prompts/analysis-prompts.d.ts +4 -1
- package/dist/src/prompts/analysis-prompts.d.ts.map +1 -1
- package/dist/src/prompts/analysis-prompts.js +61 -30
- package/dist/src/prompts/analysis-prompts.js.map +1 -1
- package/dist/src/prompts/index.d.ts +17 -1
- package/dist/src/prompts/index.d.ts.map +1 -1
- package/dist/src/prompts/index.js +325 -1
- package/dist/src/prompts/index.js.map +1 -1
- package/dist/src/prompts/rule-generation-prompts.d.ts +5 -1
- package/dist/src/prompts/rule-generation-prompts.d.ts.map +1 -1
- package/dist/src/prompts/rule-generation-prompts.js +5 -1
- package/dist/src/prompts/rule-generation-prompts.js.map +1 -1
- package/dist/src/prompts/security-prompts.d.ts +6 -1
- package/dist/src/prompts/security-prompts.d.ts.map +1 -1
- package/dist/src/prompts/security-prompts.js +6 -1
- package/dist/src/prompts/security-prompts.js.map +1 -1
- package/dist/src/prompts/todo-prompts.d.ts +49 -0
- package/dist/src/prompts/todo-prompts.d.ts.map +1 -0
- package/dist/src/prompts/todo-prompts.js +824 -0
- package/dist/src/prompts/todo-prompts.js.map +1 -0
- package/dist/src/resources/index.d.ts.map +1 -1
- package/dist/src/resources/index.js +9 -7
- package/dist/src/resources/index.js.map +1 -1
- package/dist/src/tools/adr-bootstrap-validation-tool.d.ts +47 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.d.ts.map +1 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.js +979 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.js.map +1 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts +1 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.js +330 -32
- package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
- package/dist/src/tools/content-masking-tool.d.ts +5 -0
- package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
- package/dist/src/tools/content-masking-tool.js +631 -28
- package/dist/src/tools/content-masking-tool.js.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.d.ts +8 -5
- package/dist/src/tools/deployment-readiness-tool.d.ts.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.js +1017 -93
- package/dist/src/tools/deployment-readiness-tool.js.map +1 -1
- package/dist/src/tools/environment-analysis-tool.d.ts +4 -0
- package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
- package/dist/src/tools/environment-analysis-tool.js +568 -24
- package/dist/src/tools/environment-analysis-tool.js.map +1 -1
- package/dist/src/tools/interactive-adr-planning-tool.d.ts.map +1 -1
- package/dist/src/tools/interactive-adr-planning-tool.js +270 -108
- package/dist/src/tools/interactive-adr-planning-tool.js.map +1 -1
- package/dist/src/tools/mcp-planning-tool.d.ts.map +1 -1
- package/dist/src/tools/mcp-planning-tool.js +316 -183
- package/dist/src/tools/mcp-planning-tool.js.map +1 -1
- package/dist/src/tools/memory-loading-tool.d.ts +60 -0
- package/dist/src/tools/memory-loading-tool.d.ts.map +1 -0
- package/dist/src/tools/memory-loading-tool.js +457 -0
- package/dist/src/tools/memory-loading-tool.js.map +1 -0
- package/dist/src/tools/research-integration-tool.d.ts +4 -1
- package/dist/src/tools/research-integration-tool.d.ts.map +1 -1
- package/dist/src/tools/research-integration-tool.js +5 -1
- package/dist/src/tools/research-integration-tool.js.map +1 -1
- package/dist/src/tools/review-existing-adrs-tool.d.ts +19 -0
- package/dist/src/tools/review-existing-adrs-tool.d.ts.map +1 -0
- package/dist/src/tools/review-existing-adrs-tool.js +1204 -0
- package/dist/src/tools/review-existing-adrs-tool.js.map +1 -0
- package/dist/src/tools/rule-generation-tool.d.ts +2 -0
- package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
- package/dist/src/tools/rule-generation-tool.js +274 -33
- package/dist/src/tools/rule-generation-tool.js.map +1 -1
- package/dist/src/tools/smart-git-push-tool-v2.d.ts +4 -0
- package/dist/src/tools/smart-git-push-tool-v2.d.ts.map +1 -1
- package/dist/src/tools/smart-git-push-tool-v2.js +423 -229
- package/dist/src/tools/smart-git-push-tool-v2.js.map +1 -1
- package/dist/src/tools/smart-git-push-tool.d.ts +3 -0
- package/dist/src/tools/smart-git-push-tool.d.ts.map +1 -1
- package/dist/src/tools/smart-git-push-tool.js +241 -235
- package/dist/src/tools/smart-git-push-tool.js.map +1 -1
- package/dist/src/tools/tool-chain-orchestrator.d.ts +2 -2
- package/dist/src/tools/tool-chain-orchestrator.d.ts.map +1 -1
- package/dist/src/tools/tool-chain-orchestrator.js +152 -93
- package/dist/src/tools/tool-chain-orchestrator.js.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts +22 -13
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js +660 -28
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js.map +1 -1
- package/dist/src/types/ape-framework.d.ts +93 -0
- package/dist/src/types/ape-framework.d.ts.map +1 -1
- package/dist/src/types/ape-framework.js +10 -10
- package/dist/src/types/ape-framework.js.map +1 -1
- package/dist/src/types/enhanced-errors.d.ts +173 -0
- package/dist/src/types/enhanced-errors.d.ts.map +1 -0
- package/dist/src/types/enhanced-errors.js +668 -0
- package/dist/src/types/enhanced-errors.js.map +1 -0
- package/dist/src/types/index.d.ts +129 -3
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +15 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/knowledge-generation.d.ts +78 -0
- package/dist/src/types/knowledge-generation.d.ts.map +1 -1
- package/dist/src/types/knowledge-generation.js +10 -6
- package/dist/src/types/knowledge-generation.js.map +1 -1
- package/dist/src/types/knowledge-graph-schemas.d.ts +92 -0
- package/dist/src/types/knowledge-graph-schemas.d.ts.map +1 -1
- package/dist/src/types/knowledge-graph-schemas.js +45 -17
- package/dist/src/types/knowledge-graph-schemas.js.map +1 -1
- package/dist/src/types/memory-entities.d.ts +7209 -0
- package/dist/src/types/memory-entities.d.ts.map +1 -0
- package/dist/src/types/memory-entities.js +395 -0
- package/dist/src/types/memory-entities.js.map +1 -0
- package/dist/src/types/reflexion-framework.d.ts +44 -0
- package/dist/src/types/reflexion-framework.d.ts.map +1 -1
- package/dist/src/types/reflexion-framework.js +7 -7
- package/dist/src/types/reflexion-framework.js.map +1 -1
- package/dist/src/types/todo-json-schemas.d.ts +7 -653
- package/dist/src/types/todo-json-schemas.d.ts.map +1 -1
- package/dist/src/types/todo-json-schemas.js +6 -110
- package/dist/src/types/todo-json-schemas.js.map +1 -1
- package/dist/src/types/tool-arguments.d.ts +224 -0
- package/dist/src/types/tool-arguments.d.ts.map +1 -0
- package/dist/src/types/tool-arguments.js +6 -0
- package/dist/src/types/tool-arguments.js.map +1 -0
- package/dist/src/utils/actual-file-operations.d.ts.map +1 -1
- package/dist/src/utils/actual-file-operations.js +25 -9
- package/dist/src/utils/actual-file-operations.js.map +1 -1
- package/dist/src/utils/adr-discovery.d.ts +33 -1
- package/dist/src/utils/adr-discovery.d.ts.map +1 -1
- package/dist/src/utils/adr-discovery.js +14 -9
- package/dist/src/utils/adr-discovery.js.map +1 -1
- package/dist/src/utils/adr-suggestions.d.ts +72 -0
- package/dist/src/utils/adr-suggestions.d.ts.map +1 -1
- package/dist/src/utils/adr-suggestions.js +6 -0
- package/dist/src/utils/adr-suggestions.js.map +1 -1
- package/dist/src/utils/cache.d.ts.map +1 -1
- package/dist/src/utils/cache.js +22 -19
- package/dist/src/utils/cache.js.map +1 -1
- package/dist/src/utils/chain-of-thought-template.d.ts +13 -1
- package/dist/src/utils/chain-of-thought-template.d.ts.map +1 -1
- package/dist/src/utils/chain-of-thought-template.js +31 -22
- package/dist/src/utils/chain-of-thought-template.js.map +1 -1
- package/dist/src/utils/config.d.ts.map +1 -1
- package/dist/src/utils/config.js +1 -0
- package/dist/src/utils/config.js.map +1 -1
- package/dist/src/utils/directory-compat.js +1 -1
- package/dist/src/utils/directory-compat.js.map +1 -1
- package/dist/src/utils/enhanced-logging.d.ts +195 -0
- package/dist/src/utils/enhanced-logging.d.ts.map +1 -0
- package/dist/src/utils/enhanced-logging.js +449 -0
- package/dist/src/utils/enhanced-logging.js.map +1 -0
- package/dist/src/utils/file-system.d.ts +182 -34
- package/dist/src/utils/file-system.d.ts.map +1 -1
- package/dist/src/utils/file-system.js +648 -774
- package/dist/src/utils/file-system.js.map +1 -1
- package/dist/src/utils/gitleaks-detector.d.ts +50 -0
- package/dist/src/utils/gitleaks-detector.d.ts.map +1 -0
- package/dist/src/utils/gitleaks-detector.js +334 -0
- package/dist/src/utils/gitleaks-detector.js.map +1 -0
- package/dist/src/utils/interactive-approval.d.ts +1 -1
- package/dist/src/utils/interactive-approval.d.ts.map +1 -1
- package/dist/src/utils/interactive-approval.js +22 -17
- package/dist/src/utils/interactive-approval.js.map +1 -1
- package/dist/src/utils/json-safe.d.ts.map +1 -1
- package/dist/src/utils/json-safe.js +9 -6
- package/dist/src/utils/json-safe.js.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts +37 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.js +315 -70
- package/dist/src/utils/knowledge-graph-manager.js.map +1 -1
- package/dist/src/utils/location-filter.d.ts +35 -10
- package/dist/src/utils/location-filter.d.ts.map +1 -1
- package/dist/src/utils/location-filter.js +360 -94
- package/dist/src/utils/location-filter.js.map +1 -1
- package/dist/src/utils/mcp-response-validator.d.ts.map +1 -1
- package/dist/src/utils/mcp-response-validator.js +34 -19
- package/dist/src/utils/mcp-response-validator.js.map +1 -1
- package/dist/src/utils/memory-entity-manager.d.ts +134 -0
- package/dist/src/utils/memory-entity-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-entity-manager.js +851 -0
- package/dist/src/utils/memory-entity-manager.js.map +1 -0
- package/dist/src/utils/memory-health-scoring.d.ts +125 -0
- package/dist/src/utils/memory-health-scoring.d.ts.map +1 -0
- package/dist/src/utils/memory-health-scoring.js +277 -0
- package/dist/src/utils/memory-health-scoring.js.map +1 -0
- package/dist/src/utils/memory-migration-manager.d.ts +93 -0
- package/dist/src/utils/memory-migration-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-migration-manager.js +842 -0
- package/dist/src/utils/memory-migration-manager.js.map +1 -0
- package/dist/src/utils/memory-relationship-mapper.d.ts +87 -0
- package/dist/src/utils/memory-relationship-mapper.d.ts.map +1 -0
- package/dist/src/utils/memory-relationship-mapper.js +482 -0
- package/dist/src/utils/memory-relationship-mapper.js.map +1 -0
- package/dist/src/utils/memory-rollback-manager.d.ts +105 -0
- package/dist/src/utils/memory-rollback-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-rollback-manager.js +575 -0
- package/dist/src/utils/memory-rollback-manager.js.map +1 -0
- package/dist/src/utils/memory-transformation.d.ts +59 -0
- package/dist/src/utils/memory-transformation.d.ts.map +1 -0
- package/dist/src/utils/memory-transformation.js +742 -0
- package/dist/src/utils/memory-transformation.js.map +1 -0
- package/dist/src/utils/output-masking.d.ts +12 -0
- package/dist/src/utils/output-masking.d.ts.map +1 -1
- package/dist/src/utils/output-masking.js +5 -0
- package/dist/src/utils/output-masking.js.map +1 -1
- package/dist/src/utils/prompt-execution.d.ts.map +1 -1
- package/dist/src/utils/prompt-execution.js +72 -51
- package/dist/src/utils/prompt-execution.js.map +1 -1
- package/dist/src/utils/release-readiness-detector.d.ts.map +1 -1
- package/dist/src/utils/release-readiness-detector.js +43 -42
- package/dist/src/utils/release-readiness-detector.js.map +1 -1
- package/dist/src/utils/research-integration.d.ts.map +1 -1
- package/dist/src/utils/research-integration.js +73 -44
- package/dist/src/utils/research-integration.js.map +1 -1
- package/dist/src/utils/research-questions.d.ts.map +1 -1
- package/dist/src/utils/research-questions.js +40 -14
- package/dist/src/utils/research-questions.js.map +1 -1
- package/dist/src/utils/ripgrep-wrapper.d.ts +84 -0
- package/dist/src/utils/ripgrep-wrapper.d.ts.map +1 -0
- package/dist/src/utils/ripgrep-wrapper.js +255 -0
- package/dist/src/utils/ripgrep-wrapper.js.map +1 -0
- package/dist/src/utils/rule-generation.d.ts.map +1 -1
- package/dist/src/utils/rule-generation.js +26 -15
- package/dist/src/utils/rule-generation.js.map +1 -1
- package/dist/src/utils/todo-file-watcher.d.ts +11 -23
- package/dist/src/utils/todo-file-watcher.d.ts.map +1 -1
- package/dist/src/utils/todo-file-watcher.js +18 -156
- package/dist/src/utils/todo-file-watcher.js.map +1 -1
- package/dist/src/utils/tree-sitter-analyzer.d.ts +185 -0
- package/dist/src/utils/tree-sitter-analyzer.d.ts.map +1 -0
- package/dist/src/utils/tree-sitter-analyzer.js +885 -0
- package/dist/src/utils/tree-sitter-analyzer.js.map +1 -0
- package/package.json +51 -10
- package/dist/src/tools/smart-score-tool.d.ts +0 -173
- package/dist/src/tools/smart-score-tool.d.ts.map +0 -1
- package/dist/src/tools/smart-score-tool.js +0 -681
- package/dist/src/tools/smart-score-tool.js.map +0 -1
- package/dist/src/tools/todo-management-tool-v2.d.ts +0 -368
- package/dist/src/tools/todo-management-tool-v2.d.ts.map +0 -1
- package/dist/src/tools/todo-management-tool-v2.js +0 -922
- package/dist/src/tools/todo-management-tool-v2.js.map +0 -1
- package/dist/src/utils/enhanced-sensitive-detector.d.ts +0 -61
- package/dist/src/utils/enhanced-sensitive-detector.d.ts.map +0 -1
- package/dist/src/utils/enhanced-sensitive-detector.js +0 -437
- package/dist/src/utils/enhanced-sensitive-detector.js.map +0 -1
- package/dist/src/utils/project-health-scoring.d.ts +0 -177
- package/dist/src/utils/project-health-scoring.d.ts.map +0 -1
- package/dist/src/utils/project-health-scoring.js +0 -370
- package/dist/src/utils/project-health-scoring.js.map +0 -1
- package/dist/src/utils/todo-json-manager.d.ts +0 -71
- package/dist/src/utils/todo-json-manager.d.ts.map +0 -1
- package/dist/src/utils/todo-json-manager.js +0 -396
- package/dist/src/utils/todo-json-manager.js.map +0 -1
- package/dist/src/utils/todo-markdown-converter.d.ts +0 -16
- package/dist/src/utils/todo-markdown-converter.d.ts.map +0 -1
- package/dist/src/utils/todo-markdown-converter.js +0 -362
- package/dist/src/utils/todo-markdown-converter.js.map +0 -1
- package/dist/src/utils/todo-migration.d.ts +0 -47
- package/dist/src/utils/todo-migration.d.ts.map +0 -1
- package/dist/src/utils/todo-migration.js +0 -261
- package/dist/src/utils/todo-migration.js.map +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Location-based filtering system
|
|
2
|
+
* Enterprise Location-based filtering system with Tree-sitter intelligence
|
|
3
3
|
*
|
|
4
4
|
* Determines if files are in appropriate locations based on their type and content
|
|
5
|
+
* Enhanced with AI-powered code analysis for multi-language DevOps stacks
|
|
5
6
|
*/
|
|
6
|
-
import { basename, dirname
|
|
7
|
+
import { basename, dirname } from 'path';
|
|
8
|
+
import { TreeSitterAnalyzer } from './tree-sitter-analyzer.js';
|
|
7
9
|
/**
|
|
8
10
|
* Default location rules for common development artifacts
|
|
9
11
|
*/
|
|
@@ -11,23 +13,23 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
11
13
|
// Debug files
|
|
12
14
|
{
|
|
13
15
|
name: 'debug-scripts',
|
|
14
|
-
description: '
|
|
16
|
+
description: 'debug scripts should be in development directories',
|
|
15
17
|
filePattern: /^debug_.*\.(py|js|ts|sh|rb|go)$/,
|
|
16
18
|
contentPattern: /print\s*\(.*debug.*\)|console\.log\s*\(.*debug.*\)|logging\.debug|debugger;/i,
|
|
17
19
|
allowedPaths: ['tests/', 'test/', 'scripts/', 'tools/', 'dev/', 'debug/'],
|
|
18
20
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
19
21
|
severity: 'warning',
|
|
20
|
-
category: 'development'
|
|
22
|
+
category: 'development',
|
|
21
23
|
},
|
|
22
24
|
// Test files
|
|
23
25
|
{
|
|
24
26
|
name: 'test-files',
|
|
25
|
-
description: '
|
|
27
|
+
description: 'test files should be in test directories',
|
|
26
28
|
filePattern: /^test_.*\.(py|js|ts|rb|go)$|.*\.test\.(js|ts|py)$|.*\.spec\.(js|ts|py)$/,
|
|
27
29
|
allowedPaths: ['tests/', 'test/', '__tests__/', 'spec/', 'specs/'],
|
|
28
30
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
29
31
|
severity: 'error',
|
|
30
|
-
category: 'testing'
|
|
32
|
+
category: 'testing',
|
|
31
33
|
},
|
|
32
34
|
// Mock files
|
|
33
35
|
{
|
|
@@ -38,7 +40,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
38
40
|
allowedPaths: ['tests/', 'test/', '__tests__/', 'fixtures/', 'mocks/', 'dev/'],
|
|
39
41
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
40
42
|
severity: 'warning',
|
|
41
|
-
category: 'testing'
|
|
43
|
+
category: 'testing',
|
|
42
44
|
},
|
|
43
45
|
// Temporary files
|
|
44
46
|
{
|
|
@@ -48,7 +50,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
48
50
|
allowedPaths: ['tmp/', 'temp/', 'dev/'],
|
|
49
51
|
blockedPaths: ['src/', 'lib/', 'app/', 'tests/', './'],
|
|
50
52
|
severity: 'error',
|
|
51
|
-
category: 'temporary'
|
|
53
|
+
category: 'temporary',
|
|
52
54
|
},
|
|
53
55
|
// Log files
|
|
54
56
|
{
|
|
@@ -58,7 +60,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
58
60
|
allowedPaths: ['logs/', 'dev/', 'examples/'],
|
|
59
61
|
blockedPaths: ['src/', 'lib/', 'app/', 'tests/', './'],
|
|
60
62
|
severity: 'error',
|
|
61
|
-
category: 'temporary'
|
|
63
|
+
category: 'temporary',
|
|
62
64
|
},
|
|
63
65
|
// Configuration files with secrets
|
|
64
66
|
{
|
|
@@ -69,7 +71,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
69
71
|
allowedPaths: ['config/', 'configs/', 'env/', 'examples/'],
|
|
70
72
|
blockedPaths: ['./'],
|
|
71
73
|
severity: 'error',
|
|
72
|
-
category: 'security'
|
|
74
|
+
category: 'security',
|
|
73
75
|
},
|
|
74
76
|
// Scripts
|
|
75
77
|
{
|
|
@@ -79,7 +81,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
79
81
|
allowedPaths: ['scripts/', 'tools/', 'bin/', 'utils/'],
|
|
80
82
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
81
83
|
severity: 'info',
|
|
82
|
-
category: 'development'
|
|
84
|
+
category: 'development',
|
|
83
85
|
},
|
|
84
86
|
// Experimental code
|
|
85
87
|
{
|
|
@@ -89,7 +91,7 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
89
91
|
allowedPaths: ['experiments/', 'poc/', 'dev/', 'playground/', 'prototypes/'],
|
|
90
92
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
91
93
|
severity: 'warning',
|
|
92
|
-
category: 'development'
|
|
94
|
+
category: 'development',
|
|
93
95
|
},
|
|
94
96
|
// Documentation drafts
|
|
95
97
|
{
|
|
@@ -99,126 +101,281 @@ export const DEFAULT_LOCATION_RULES = [
|
|
|
99
101
|
allowedPaths: ['docs/', 'documentation/', 'dev/', 'drafts/'],
|
|
100
102
|
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
101
103
|
severity: 'info',
|
|
102
|
-
category: 'development'
|
|
103
|
-
}
|
|
104
|
+
category: 'development',
|
|
105
|
+
},
|
|
106
|
+
// Enterprise IaC Rules for RedHat/Cloud Architecture
|
|
107
|
+
// Ansible Playbooks and Roles
|
|
108
|
+
{
|
|
109
|
+
name: 'ansible-structure',
|
|
110
|
+
description: 'Ansible playbooks and roles must follow standard structure',
|
|
111
|
+
filePattern: /.*\.(yml|yaml)$/,
|
|
112
|
+
contentPattern: /hosts:|become:|tasks:|handlers:|vars:|playbook|ansible/i,
|
|
113
|
+
allowedPaths: [
|
|
114
|
+
'ansible/',
|
|
115
|
+
'playbooks/',
|
|
116
|
+
'roles/',
|
|
117
|
+
'inventory/',
|
|
118
|
+
'group_vars/',
|
|
119
|
+
'host_vars/',
|
|
120
|
+
'automation/',
|
|
121
|
+
],
|
|
122
|
+
blockedPaths: ['src/', 'lib/', 'app/', 'tests/', './'],
|
|
123
|
+
severity: 'error',
|
|
124
|
+
category: 'security',
|
|
125
|
+
},
|
|
126
|
+
// Terraform Infrastructure
|
|
127
|
+
{
|
|
128
|
+
name: 'terraform-organization',
|
|
129
|
+
description: 'Terraform files must be properly organized by environment/provider',
|
|
130
|
+
filePattern: /.*\.tf$|.*\.tfvars$|.*\.tfstate$/,
|
|
131
|
+
allowedPaths: ['terraform/', 'infra/', 'infrastructure/', 'environments/', 'modules/'],
|
|
132
|
+
blockedPaths: ['src/', 'lib/', 'app/', 'ansible/', './'],
|
|
133
|
+
severity: 'error',
|
|
134
|
+
category: 'security',
|
|
135
|
+
},
|
|
136
|
+
// Container Security
|
|
137
|
+
{
|
|
138
|
+
name: 'container-configs',
|
|
139
|
+
description: 'Container configs must be in designated directories',
|
|
140
|
+
filePattern: /Dockerfile|docker-compose.*\.ya?ml$|\.dockerignore$/,
|
|
141
|
+
contentPattern: /FROM|COPY|RUN|EXPOSE|CMD|ENTRYPOINT/i,
|
|
142
|
+
allowedPaths: ['docker/', 'containers/', 'deployments/', 'k8s/', 'kubernetes/', './'],
|
|
143
|
+
blockedPaths: ['src/', 'lib/', 'ansible/'],
|
|
144
|
+
severity: 'warning',
|
|
145
|
+
category: 'security',
|
|
146
|
+
},
|
|
147
|
+
// Kubernetes Manifests
|
|
148
|
+
{
|
|
149
|
+
name: 'k8s-manifests',
|
|
150
|
+
description: 'Kubernetes manifests must be properly organized',
|
|
151
|
+
filePattern: /.*\.(yaml|yml)$/,
|
|
152
|
+
contentPattern: /apiVersion:|kind:|metadata:|spec:|kubernetes|k8s/i,
|
|
153
|
+
allowedPaths: ['k8s/', 'kubernetes/', 'manifests/', 'deployments/', 'helm/', 'charts/'],
|
|
154
|
+
blockedPaths: ['src/', 'lib/', 'app/', 'ansible/', './'],
|
|
155
|
+
severity: 'error',
|
|
156
|
+
category: 'security',
|
|
157
|
+
},
|
|
158
|
+
// CI/CD Pipeline Security
|
|
159
|
+
{
|
|
160
|
+
name: 'cicd-security',
|
|
161
|
+
description: 'CI/CD configs must not contain hardcoded secrets',
|
|
162
|
+
filePattern: /\.github\/workflows\/.*\.ya?ml$|\.gitlab-ci\.ya?ml$|Jenkinsfile|\.tekton\/.*$/,
|
|
163
|
+
contentPattern: /password|secret|token|key|credential/i,
|
|
164
|
+
allowedPaths: ['.github/workflows/', '.gitlab/', 'jenkins/', 'tekton/', 'ci/', 'pipelines/'],
|
|
165
|
+
blockedPaths: ['src/', 'lib/', 'app/'],
|
|
166
|
+
severity: 'error',
|
|
167
|
+
category: 'security',
|
|
168
|
+
},
|
|
169
|
+
// Python Virtual Environments and Dependencies
|
|
170
|
+
{
|
|
171
|
+
name: 'python-dependencies',
|
|
172
|
+
description: 'Python virtual environments should not be committed',
|
|
173
|
+
filePattern: /^venv\/|^\.venv\/|^env\/|^\.env\/|__pycache__\/|.*\.pyc$/,
|
|
174
|
+
allowedPaths: [],
|
|
175
|
+
blockedPaths: ['./'],
|
|
176
|
+
severity: 'error',
|
|
177
|
+
category: 'temporary',
|
|
178
|
+
},
|
|
179
|
+
// Node.js Enterprise Patterns
|
|
180
|
+
{
|
|
181
|
+
name: 'nodejs-enterprise',
|
|
182
|
+
description: 'Node.js enterprise configs must be properly organized',
|
|
183
|
+
filePattern: /package\.json$|package-lock\.json$|yarn\.lock$|\.npmrc$/,
|
|
184
|
+
contentPattern: /registry|token|auth/i,
|
|
185
|
+
allowedPaths: ['./', 'packages/', 'apps/', 'services/'],
|
|
186
|
+
blockedPaths: [],
|
|
187
|
+
severity: 'warning',
|
|
188
|
+
category: 'security',
|
|
189
|
+
},
|
|
190
|
+
// RedHat OpenShift Configs
|
|
191
|
+
{
|
|
192
|
+
name: 'openshift-configs',
|
|
193
|
+
description: 'OpenShift configs must be in designated directories',
|
|
194
|
+
filePattern: /.*\.(yaml|yml)$/,
|
|
195
|
+
contentPattern: /openshift|oc\s|route:|buildconfig:|deploymentconfig/i,
|
|
196
|
+
allowedPaths: ['openshift/', 'ocp/', 'deployments/', 'k8s/', 'manifests/'],
|
|
197
|
+
blockedPaths: ['src/', 'lib/', 'app/', './'],
|
|
198
|
+
severity: 'error',
|
|
199
|
+
category: 'security',
|
|
200
|
+
},
|
|
104
201
|
];
|
|
202
|
+
// Create tree-sitter analyzer instance
|
|
203
|
+
let treeSitterAnalyzer = null;
|
|
204
|
+
/**
|
|
205
|
+
* Initialize tree-sitter analyzer (lazy loading)
|
|
206
|
+
*/
|
|
207
|
+
async function getTreeSitterAnalyzer() {
|
|
208
|
+
if (!treeSitterAnalyzer) {
|
|
209
|
+
try {
|
|
210
|
+
treeSitterAnalyzer = new TreeSitterAnalyzer();
|
|
211
|
+
return treeSitterAnalyzer;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
console.warn('Tree-sitter analyzer initialization failed:', error);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return treeSitterAnalyzer;
|
|
219
|
+
}
|
|
105
220
|
/**
|
|
221
|
+
* Enhanced file location validation with tree-sitter intelligence
|
|
222
|
+
*/
|
|
223
|
+
export async function validateFileLocationIntelligent(filePath, content, customRules = []) {
|
|
224
|
+
// Perform basic validation first
|
|
225
|
+
const basicResult = validateFileLocation(filePath, content, customRules);
|
|
226
|
+
// Add tree-sitter analysis for enhanced intelligence
|
|
227
|
+
try {
|
|
228
|
+
const analyzer = await getTreeSitterAnalyzer();
|
|
229
|
+
if (analyzer && content) {
|
|
230
|
+
const analysis = await analyzer.analyzeFile(filePath, content);
|
|
231
|
+
// Enhance validation with tree-sitter insights
|
|
232
|
+
const intelligentResult = enhanceValidationWithTreeSitter(basicResult, analysis, filePath);
|
|
233
|
+
return {
|
|
234
|
+
...intelligentResult,
|
|
235
|
+
treeSitterAnalysis: analysis,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.warn('Tree-sitter analysis failed:', error);
|
|
241
|
+
}
|
|
242
|
+
return basicResult;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Legacy function for backward compatibility
|
|
106
246
|
* Validate file location against rules
|
|
107
247
|
*/
|
|
108
248
|
export function validateFileLocation(filePath, content, customRules = []) {
|
|
109
249
|
const fileName = basename(filePath);
|
|
110
250
|
const dirPath = dirname(filePath);
|
|
111
|
-
const allRules = [...
|
|
251
|
+
const allRules = [...customRules, ...DEFAULT_LOCATION_RULES]; // Custom rules first for priority
|
|
112
252
|
// Check each rule
|
|
113
253
|
for (const rule of allRules) {
|
|
114
|
-
if
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
254
|
+
// Rule matches if either:
|
|
255
|
+
// 1. File pattern matches AND no content pattern specified
|
|
256
|
+
// 2. File pattern matches AND content pattern matches (if content provided)
|
|
257
|
+
// 3. Content pattern matches (regardless of file pattern, if content provided)
|
|
258
|
+
const fileMatches = rule.filePattern.test(fileName);
|
|
259
|
+
const hasContentPattern = !!rule.contentPattern;
|
|
260
|
+
const contentMatches = hasContentPattern && content ? rule.contentPattern.test(content) : false;
|
|
261
|
+
// Rule applies if:
|
|
262
|
+
// - File pattern matches (regardless of content pattern)
|
|
263
|
+
// - Content pattern matches (when content is provided)
|
|
264
|
+
const ruleApplies = fileMatches || contentMatches;
|
|
265
|
+
if (ruleApplies) {
|
|
119
266
|
// Check if current path is blocked
|
|
120
|
-
const isBlocked = rule.blockedPaths.some(blocked =>
|
|
267
|
+
const isBlocked = rule.blockedPaths.some(blocked => {
|
|
268
|
+
const cleanBlocked = blocked.replace(/\/$/, ''); // Remove trailing slash
|
|
269
|
+
return (dirPath.startsWith(cleanBlocked + '/') ||
|
|
270
|
+
dirPath === cleanBlocked ||
|
|
271
|
+
filePath.startsWith(cleanBlocked + '/'));
|
|
272
|
+
});
|
|
121
273
|
if (isBlocked) {
|
|
122
274
|
return {
|
|
123
275
|
isValid: false,
|
|
124
276
|
rule,
|
|
125
|
-
currentPath:
|
|
277
|
+
currentPath: filePath,
|
|
126
278
|
suggestedPaths: rule.allowedPaths,
|
|
127
279
|
severity: rule.severity,
|
|
128
|
-
message: `${rule.description}.
|
|
280
|
+
message: `${rule.description}. File '${fileName}' currently in '${dirPath}/', should be in: ${rule.allowedPaths.join(', ')}`,
|
|
129
281
|
};
|
|
130
282
|
}
|
|
131
283
|
// Check if current path is allowed
|
|
132
|
-
const isAllowed = rule.allowedPaths.
|
|
284
|
+
const isAllowed = rule.allowedPaths.length === 0 ||
|
|
285
|
+
rule.allowedPaths.some(allowed => {
|
|
286
|
+
const cleanAllowed = allowed.replace(/\/$/, ''); // Remove trailing slash
|
|
287
|
+
return (dirPath.includes(cleanAllowed) ||
|
|
288
|
+
dirPath === cleanAllowed ||
|
|
289
|
+
filePath.startsWith(cleanAllowed + '/') ||
|
|
290
|
+
(cleanAllowed === '.' && dirPath === '.') ||
|
|
291
|
+
(cleanAllowed === './' && (dirPath === '.' || dirPath === '')));
|
|
292
|
+
});
|
|
133
293
|
if (!isAllowed) {
|
|
134
294
|
return {
|
|
135
295
|
isValid: false,
|
|
136
296
|
rule,
|
|
137
|
-
currentPath:
|
|
297
|
+
currentPath: filePath,
|
|
138
298
|
suggestedPaths: rule.allowedPaths,
|
|
139
299
|
severity: rule.severity,
|
|
140
|
-
message: `${rule.description}.
|
|
300
|
+
message: `${rule.description}. File '${fileName}' currently in '${dirPath}/', should be in: ${rule.allowedPaths.join(', ')}`,
|
|
141
301
|
};
|
|
142
302
|
}
|
|
143
303
|
// File is in correct location
|
|
144
304
|
return {
|
|
145
305
|
isValid: true,
|
|
146
306
|
rule,
|
|
147
|
-
currentPath:
|
|
307
|
+
currentPath: filePath,
|
|
148
308
|
suggestedPaths: [],
|
|
149
309
|
severity: 'info',
|
|
150
|
-
message: `File is correctly located in '${dirPath}/'
|
|
310
|
+
message: `File is correctly located in '${dirPath}/'`,
|
|
151
311
|
};
|
|
152
312
|
}
|
|
153
313
|
}
|
|
154
314
|
// No specific rule found, file is generally acceptable
|
|
155
315
|
return {
|
|
156
316
|
isValid: true,
|
|
157
|
-
currentPath:
|
|
317
|
+
currentPath: filePath,
|
|
158
318
|
suggestedPaths: [],
|
|
159
319
|
severity: 'info',
|
|
160
|
-
message: 'No specific location restrictions apply'
|
|
320
|
+
message: 'No specific location restrictions apply',
|
|
161
321
|
};
|
|
162
322
|
}
|
|
163
323
|
/**
|
|
164
|
-
* Get location suggestions for a file
|
|
324
|
+
* Get location suggestions for a file (backward compatible overloads)
|
|
165
325
|
*/
|
|
166
|
-
export function getLocationSuggestions(filePath,
|
|
326
|
+
export function getLocationSuggestions(filePath, categoryOrDescription) {
|
|
167
327
|
const fileName = basename(filePath);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
suggestions: rule.allowedPaths,
|
|
180
|
-
reasoning: rule.description,
|
|
181
|
-
category: rule.category
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
// Generic suggestions based on file type
|
|
185
|
-
const genericSuggestions = getGenericLocationSuggestions(fileName, fileExt);
|
|
186
|
-
return {
|
|
187
|
-
suggestions: genericSuggestions,
|
|
188
|
-
reasoning: 'Based on file type and naming conventions',
|
|
189
|
-
category: 'general'
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Get generic location suggestions based on file characteristics
|
|
194
|
-
*/
|
|
195
|
-
function getGenericLocationSuggestions(fileName, fileExt) {
|
|
196
|
-
const suggestions = [];
|
|
197
|
-
// Test files
|
|
198
|
-
if (fileName.includes('test') || fileName.includes('spec')) {
|
|
199
|
-
suggestions.push('tests/', 'test/', '__tests__/');
|
|
328
|
+
// Check if this is the old API (category parameter) or new API (description parameter)
|
|
329
|
+
// Old API can be valid categories OR any other single-word string that isn't a description
|
|
330
|
+
const validOldCategories = ['development', 'security', 'temporary', 'testing'];
|
|
331
|
+
const isOldApi = validOldCategories.includes(categoryOrDescription || '') ||
|
|
332
|
+
(categoryOrDescription &&
|
|
333
|
+
categoryOrDescription.length < 20 &&
|
|
334
|
+
!categoryOrDescription.includes(' '));
|
|
335
|
+
let category;
|
|
336
|
+
if (isOldApi) {
|
|
337
|
+
// Old API: category is provided (might be unknown)
|
|
338
|
+
category = categoryOrDescription;
|
|
200
339
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
340
|
+
else {
|
|
341
|
+
// New API: determine category based on filename patterns
|
|
342
|
+
category = 'development';
|
|
343
|
+
if (fileName.startsWith('temp_') || fileName.includes('.tmp') || fileName.includes('.temp')) {
|
|
344
|
+
category = 'temporary';
|
|
345
|
+
}
|
|
346
|
+
else if (fileName.startsWith('test_') ||
|
|
347
|
+
fileName.includes('.test.') ||
|
|
348
|
+
fileName.includes('.spec.')) {
|
|
349
|
+
category = 'testing';
|
|
350
|
+
}
|
|
351
|
+
else if (fileName.includes('config') ||
|
|
352
|
+
fileName.includes('.env') ||
|
|
353
|
+
fileName.includes('secret')) {
|
|
354
|
+
category = 'security';
|
|
355
|
+
}
|
|
212
356
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
357
|
+
const categoryMap = {
|
|
358
|
+
testing: ['tests/', 'test/', '__tests__/'],
|
|
359
|
+
development: ['dev/', 'tools/', 'scripts/'],
|
|
360
|
+
temporary: ['tmp/', 'temp/'],
|
|
361
|
+
security: ['config/', 'env/', 'examples/'],
|
|
362
|
+
};
|
|
363
|
+
const baseSuggestions = categoryMap[category] || [];
|
|
364
|
+
if (isOldApi) {
|
|
365
|
+
// Old API: return array with file names included
|
|
366
|
+
// For unknown categories, return empty array
|
|
367
|
+
if (!categoryMap[category]) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
return baseSuggestions.map(dir => `${dir}${fileName}`);
|
|
216
371
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
372
|
+
else {
|
|
373
|
+
// New API: return object with suggestions and category
|
|
374
|
+
return {
|
|
375
|
+
suggestions: baseSuggestions,
|
|
376
|
+
category,
|
|
377
|
+
};
|
|
220
378
|
}
|
|
221
|
-
return suggestions;
|
|
222
379
|
}
|
|
223
380
|
/**
|
|
224
381
|
* Check if a file should be ignored based on common patterns
|
|
@@ -235,14 +392,14 @@ export function shouldIgnoreFile(filePath) {
|
|
|
235
392
|
{ pattern: /^\.DS_Store$/, reason: 'macOS system file' },
|
|
236
393
|
{ pattern: /^Thumbs\.db$/, reason: 'Windows system file' },
|
|
237
394
|
{ pattern: /^\.env\.local$/, reason: 'Local environment file' },
|
|
238
|
-
{ pattern: /^\.env\.dev$/, reason: 'Development environment file' }
|
|
395
|
+
{ pattern: /^\.env\.dev$/, reason: 'Development environment file' },
|
|
239
396
|
];
|
|
240
397
|
for (const { pattern, reason } of temporaryPatterns) {
|
|
241
398
|
if (pattern.test(fileName)) {
|
|
242
399
|
return {
|
|
243
400
|
shouldIgnore: true,
|
|
244
401
|
reason,
|
|
245
|
-
severity: 'error'
|
|
402
|
+
severity: 'error',
|
|
246
403
|
};
|
|
247
404
|
}
|
|
248
405
|
}
|
|
@@ -253,21 +410,21 @@ export function shouldIgnoreFile(filePath) {
|
|
|
253
410
|
{ pattern: /^playground_/, reason: 'Playground file' },
|
|
254
411
|
{ pattern: /^experiment_/, reason: 'Experimental file' },
|
|
255
412
|
{ pattern: /.*\.debug$/, reason: 'Debug file' },
|
|
256
|
-
{ pattern: /.*\.log$/, reason: 'Log file' }
|
|
413
|
+
{ pattern: /.*\.log$/, reason: 'Log file' },
|
|
257
414
|
];
|
|
258
415
|
for (const { pattern, reason } of developmentPatterns) {
|
|
259
416
|
if (pattern.test(fileName)) {
|
|
260
417
|
return {
|
|
261
418
|
shouldIgnore: true,
|
|
262
419
|
reason,
|
|
263
|
-
severity: 'warning'
|
|
420
|
+
severity: 'warning',
|
|
264
421
|
};
|
|
265
422
|
}
|
|
266
423
|
}
|
|
267
424
|
return {
|
|
268
425
|
shouldIgnore: false,
|
|
269
426
|
reason: 'File appears to be legitimate',
|
|
270
|
-
severity: 'info'
|
|
427
|
+
severity: 'info',
|
|
271
428
|
};
|
|
272
429
|
}
|
|
273
430
|
/**
|
|
@@ -282,7 +439,7 @@ export function createLocationRule(name, description, filePattern, allowedPaths,
|
|
|
282
439
|
allowedPaths,
|
|
283
440
|
blockedPaths,
|
|
284
441
|
severity,
|
|
285
|
-
category
|
|
442
|
+
category,
|
|
286
443
|
};
|
|
287
444
|
}
|
|
288
445
|
/**
|
|
@@ -296,11 +453,120 @@ export function loadLocationRules(_projectPath) {
|
|
|
296
453
|
/**
|
|
297
454
|
* Validate multiple files at once
|
|
298
455
|
*/
|
|
299
|
-
export function validateMultipleFiles(
|
|
300
|
-
return
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
})
|
|
456
|
+
export function validateMultipleFiles(filePaths, fileContents, customRules = []) {
|
|
457
|
+
return filePaths.map((filePath, index) => {
|
|
458
|
+
const content = fileContents?.[index];
|
|
459
|
+
return validateFileLocation(filePath, content, customRules);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Enhance validation result with tree-sitter intelligence
|
|
464
|
+
*/
|
|
465
|
+
function enhanceValidationWithTreeSitter(basicResult, analysis, filePath) {
|
|
466
|
+
const intelligentReasons = [];
|
|
467
|
+
let newSeverity = basicResult.severity;
|
|
468
|
+
let isValid = basicResult.isValid;
|
|
469
|
+
// Security-based location enforcement
|
|
470
|
+
if (analysis.hasSecrets) {
|
|
471
|
+
intelligentReasons.push(`Contains ${analysis.secrets.length} potential secret(s): ${analysis.secrets.map(s => s.type).join(', ')}`);
|
|
472
|
+
// Force security files to secure locations
|
|
473
|
+
if (!isInSecureLocation(filePath)) {
|
|
474
|
+
isValid = false;
|
|
475
|
+
newSeverity = 'error';
|
|
476
|
+
intelligentReasons.push('Files with secrets must be in secure locations (config/, env/, examples/)');
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
// Infrastructure analysis
|
|
480
|
+
if (analysis.infraStructure.length > 0) {
|
|
481
|
+
const infraTypes = analysis.infraStructure.map(i => i.resourceType);
|
|
482
|
+
intelligentReasons.push(`Infrastructure resources detected: ${infraTypes.join(', ')}`);
|
|
483
|
+
// Terraform files with dangerous resources
|
|
484
|
+
const dangerousResources = analysis.infraStructure.filter(i => i.securityRisks.length > 0);
|
|
485
|
+
if (dangerousResources.length > 0) {
|
|
486
|
+
intelligentReasons.push('Contains infrastructure with security risks');
|
|
487
|
+
if (newSeverity === 'info')
|
|
488
|
+
newSeverity = 'warning';
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// Dangerous import analysis
|
|
492
|
+
const dangerousImports = analysis.imports.filter(i => i.isDangerous);
|
|
493
|
+
if (dangerousImports.length > 0) {
|
|
494
|
+
intelligentReasons.push(`Contains dangerous imports: ${dangerousImports.map(i => i.module).join(', ')}`);
|
|
495
|
+
if (newSeverity === 'info')
|
|
496
|
+
newSeverity = 'warning';
|
|
497
|
+
}
|
|
498
|
+
// Security-sensitive functions
|
|
499
|
+
const sensitiveFunctions = analysis.functions.filter(f => f.securitySensitive);
|
|
500
|
+
if (sensitiveFunctions.length > 0) {
|
|
501
|
+
intelligentReasons.push(`Contains security-sensitive functions: ${sensitiveFunctions.map(f => f.name).join(', ')}`);
|
|
502
|
+
}
|
|
503
|
+
// High complexity functions (potential technical debt)
|
|
504
|
+
const complexFunctions = analysis.functions.filter(f => f.complexity > 10);
|
|
505
|
+
if (complexFunctions.length > 0) {
|
|
506
|
+
intelligentReasons.push(`Contains high-complexity functions (>10): ${complexFunctions.map(f => f.name).join(', ')}`);
|
|
507
|
+
}
|
|
508
|
+
// Enterprise architecture violations
|
|
509
|
+
const violations = detectArchitecturalViolations(analysis, filePath);
|
|
510
|
+
if (violations.length > 0) {
|
|
511
|
+
intelligentReasons.push(...violations);
|
|
512
|
+
isValid = false;
|
|
513
|
+
newSeverity = 'error';
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
...basicResult,
|
|
517
|
+
isValid,
|
|
518
|
+
severity: newSeverity,
|
|
519
|
+
intelligentReasons,
|
|
520
|
+
message: intelligentReasons.length > 0
|
|
521
|
+
? `${basicResult.message} | Tree-sitter analysis: ${intelligentReasons.join('; ')}`
|
|
522
|
+
: basicResult.message,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Check if file is in a secure location
|
|
527
|
+
*/
|
|
528
|
+
function isInSecureLocation(filePath) {
|
|
529
|
+
const secureLocations = ['config/', 'env/', 'examples/', 'secrets/', '.env', 'vault/'];
|
|
530
|
+
return secureLocations.some(location => filePath.includes(location));
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Detect architectural violations based on imports and function calls
|
|
534
|
+
*/
|
|
535
|
+
function detectArchitecturalViolations(analysis, filePath) {
|
|
536
|
+
const violations = [];
|
|
537
|
+
// Database access in UI layer
|
|
538
|
+
if (filePath.includes('/ui/') || filePath.includes('/components/')) {
|
|
539
|
+
const dbImports = analysis.imports.filter(i => i.module.includes('sql') ||
|
|
540
|
+
i.module.includes('database') ||
|
|
541
|
+
i.module.includes('mongoose') ||
|
|
542
|
+
i.module.includes('sequelize'));
|
|
543
|
+
if (dbImports.length > 0) {
|
|
544
|
+
violations.push('UI layer contains direct database imports (violates clean architecture)');
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// Business logic in view layer
|
|
548
|
+
if (filePath.includes('/views/') || filePath.includes('/templates/')) {
|
|
549
|
+
const businessLogic = analysis.functions.filter(f => f.name.includes('calculate') ||
|
|
550
|
+
f.name.includes('process') ||
|
|
551
|
+
f.name.includes('validate') ||
|
|
552
|
+
f.complexity > 5);
|
|
553
|
+
if (businessLogic.length > 0) {
|
|
554
|
+
violations.push('View layer contains business logic (should be in service/business layer)');
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
// Cloud provider coupling
|
|
558
|
+
const awsImports = analysis.imports.filter(i => i.module.includes('aws'));
|
|
559
|
+
const gcpImports = analysis.imports.filter(i => i.module.includes('gcp') || i.module.includes('google-cloud'));
|
|
560
|
+
const azureImports = analysis.imports.filter(i => i.module.includes('azure'));
|
|
561
|
+
const cloudProviders = [
|
|
562
|
+
...(awsImports.length > 0 ? ['AWS'] : []),
|
|
563
|
+
...(gcpImports.length > 0 ? ['GCP'] : []),
|
|
564
|
+
...(azureImports.length > 0 ? ['Azure'] : []),
|
|
565
|
+
];
|
|
566
|
+
if (cloudProviders.length > 1) {
|
|
567
|
+
violations.push(`Multi-cloud coupling detected: ${cloudProviders.join(', ')} (consider abstraction layer)`);
|
|
568
|
+
}
|
|
569
|
+
return violations;
|
|
304
570
|
}
|
|
305
571
|
/**
|
|
306
572
|
* Get summary statistics for location validation
|
|
@@ -313,7 +579,7 @@ export function getLocationValidationSummary(results) {
|
|
|
313
579
|
errorCount: results.filter(r => r.severity === 'error').length,
|
|
314
580
|
warningCount: results.filter(r => r.severity === 'warning').length,
|
|
315
581
|
infoCount: results.filter(r => r.severity === 'info').length,
|
|
316
|
-
categorySummary: {}
|
|
582
|
+
categorySummary: {},
|
|
317
583
|
};
|
|
318
584
|
// Count by category
|
|
319
585
|
for (const result of results) {
|