rules-enforcer 1.0.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.
Files changed (33) hide show
  1. package/README.md +58 -0
  2. package/detector/README.md +212 -0
  3. package/detector/decision-engine/README.md +203 -0
  4. package/detector/decision-engine/conflict-resolver.js +336 -0
  5. package/detector/decision-engine/de-verify.js +461 -0
  6. package/detector/decision-engine/index.js +204 -0
  7. package/detector/decision-engine/optimizer.js +325 -0
  8. package/detector/decision-engine/scorer.js +359 -0
  9. package/detector/knowledge-base/README.md +140 -0
  10. package/detector/knowledge-base/agent-knowledge.json +62 -0
  11. package/detector/knowledge-base/index.js +332 -0
  12. package/detector/knowledge-base/kb-verify.js +287 -0
  13. package/detector/knowledge-base/mcp-knowledge.json +135 -0
  14. package/detector/knowledge-base/rules-knowledge.json +184 -0
  15. package/detector/mcp-server.js +157 -0
  16. package/detector/mcp-service.js +118 -0
  17. package/detector/package.json +13 -0
  18. package/detector/plugin.json +122 -0
  19. package/detector/project-detector.js +710 -0
  20. package/detector/render-engine/ag-config-render.js +195 -0
  21. package/detector/render-engine/index.js +124 -0
  22. package/detector/render-engine/render-core.js +200 -0
  23. package/detector/render-engine/render-verify.js +282 -0
  24. package/detector/render-engine/rule-render.js +231 -0
  25. package/detector/test-exceptions.js +366 -0
  26. package/detector/verify-plugin.js +233 -0
  27. package/hooks/chain-invoker.js +98 -0
  28. package/hooks/custom-hook-server.js +312 -0
  29. package/hooks/mcp-hooks.js +153 -0
  30. package/hooks/validate-chain.js +147 -0
  31. package/package.json +35 -0
  32. package/rules-server.js +350 -0
  33. package/test/test-mcp-full.js +193 -0
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Project Detector MCP Server
3
+ * MCP 服务器入口,包装 project-detector 功能
4
+ */
5
+
6
+ const readline = require('readline');
7
+ const { stdin, stdout } = require('process');
8
+ const path = require('path');
9
+ const { ProjectDetector } = require('./project-detector.js');
10
+
11
+ const rl = readline.createInterface({
12
+ input: stdin,
13
+ output: stdout,
14
+ terminal: false
15
+ });
16
+
17
+ rl.on('line', (input) => {
18
+ try {
19
+ const request = JSON.parse(input);
20
+ const { id, method, params } = request;
21
+ let response;
22
+
23
+ if (method === 'initialize') {
24
+ response = {
25
+ jsonrpc: "2.0",
26
+ id: id,
27
+ result: {
28
+ protocolVersion: "2024-11-05",
29
+ capabilities: {
30
+ tools: {}
31
+ },
32
+ serverInfo: {
33
+ name: "project-detector",
34
+ version: "1.0.0"
35
+ }
36
+ }
37
+ };
38
+ } else if (method === 'notifications/initialized') {
39
+ return;
40
+ } else if (method === 'tools/list') {
41
+ response = {
42
+ jsonrpc: "2.0",
43
+ id: id,
44
+ result: {
45
+ tools: [
46
+ {
47
+ name: "scan_project",
48
+ description: "执行完整项目探测,扫描技术栈、目录拓扑、已有组件",
49
+ inputSchema: {
50
+ type: "object",
51
+ properties: {
52
+ projectPath: { type: "string", description: "项目路径,默认当前工作目录" },
53
+ maxDepth: { type: "number", description: "扫描最大深度,默认4" }
54
+ }
55
+ }
56
+ },
57
+ {
58
+ name: "quick_scan",
59
+ description: "快速扫描项目基本信息(技术栈+MCP+Agent)",
60
+ inputSchema: {
61
+ type: "object",
62
+ properties: {
63
+ projectPath: { type: "string", description: "项目路径" }
64
+ }
65
+ }
66
+ },
67
+ {
68
+ name: "list_rules",
69
+ description: "列出当前项目已配置的所有规则",
70
+ inputSchema: {
71
+ type: "object",
72
+ properties: {
73
+ projectPath: { type: "string", description: "项目路径" }
74
+ }
75
+ }
76
+ }
77
+ ]
78
+ }
79
+ };
80
+ } else if (method === 'tools/call') {
81
+ const toolName = params?.name;
82
+ const toolArgs = params?.arguments || {};
83
+ const projectPath = toolArgs.projectPath || process.cwd();
84
+
85
+ try {
86
+ const detector = new ProjectDetector(projectPath);
87
+ let result;
88
+
89
+ if (toolName === 'scan_project') {
90
+ detector.scan();
91
+ result = detector.getReport();
92
+ } else if (toolName === 'quick_scan') {
93
+ detector.scanTechStack();
94
+ detector.scanMCP();
95
+ detector.scanAgents();
96
+ result = {
97
+ projectRoot: detector.root,
98
+ techStack: detector.techStack,
99
+ mcp: detector.existingComponents.mcp,
100
+ agents: detector.existingComponents.agents.map(a => a.name),
101
+ complexity: detector.estimateComplexity()
102
+ };
103
+ } else if (toolName === 'list_rules') {
104
+ detector.scanRules();
105
+ result = {
106
+ projectRoot: detector.root,
107
+ rules: detector.existingComponents.rules,
108
+ stats: {
109
+ total: detector.existingComponents.rules.length,
110
+ l1: detector.existingComponents.rules.filter(r => r.level === 'L1').length,
111
+ l2: detector.existingComponents.rules.filter(r => r.level === 'L2').length,
112
+ l3: detector.existingComponents.rules.filter(r => r.level === 'L3').length
113
+ }
114
+ };
115
+ } else {
116
+ response = {
117
+ jsonrpc: "2.0",
118
+ id: id,
119
+ error: { code: -32601, message: 'Tool not found' }
120
+ };
121
+ stdout.write(JSON.stringify(response) + '\n');
122
+ return;
123
+ }
124
+
125
+ response = {
126
+ jsonrpc: "2.0",
127
+ id: id,
128
+ result: {
129
+ content: [{ type: "text", text: JSON.stringify(result) }]
130
+ }
131
+ };
132
+ } catch (e) {
133
+ response = {
134
+ jsonrpc: "2.0",
135
+ id: id,
136
+ result: {
137
+ content: [{ type: "text", text: JSON.stringify({ error: e.message }) }]
138
+ }
139
+ };
140
+ }
141
+ } else {
142
+ response = {
143
+ jsonrpc: "2.0",
144
+ id: id,
145
+ error: { code: -32601, message: 'Method not found' }
146
+ };
147
+ }
148
+
149
+ stdout.write(JSON.stringify(response) + '\n');
150
+ } catch (error) {
151
+ stdout.write(JSON.stringify({
152
+ jsonrpc: "2.0",
153
+ id: null,
154
+ error: { code: -32603, message: 'Internal error' }
155
+ }) + '\n');
156
+ }
157
+ });
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Project Detector MCP Service Integration
3
+ * 对接 rules-enforcer MCP,暴露 scan_project 工具
4
+ */
5
+
6
+ const { ProjectDetector } = require('./project-detector.js');
7
+
8
+ /**
9
+ * MCP 工具定义
10
+ */
11
+ const TOOLS = [
12
+ {
13
+ name: 'scan_project',
14
+ description: '执行完整项目探测,扫描技术栈、目录拓扑、已有组件',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ projectPath: {
19
+ type: 'string',
20
+ description: '项目路径,默认当前工作目录'
21
+ },
22
+ maxDepth: {
23
+ type: 'number',
24
+ description: '扫描最大深度,默认4',
25
+ default: 4
26
+ }
27
+ }
28
+ }
29
+ },
30
+ {
31
+ name: 'quick_scan',
32
+ description: '快速扫描项目基本信息(技术栈+MCP+Agent)',
33
+ inputSchema: {
34
+ type: 'object',
35
+ properties: {
36
+ projectPath: {
37
+ type: 'string',
38
+ description: '项目路径,默认当前工作目录'
39
+ }
40
+ }
41
+ }
42
+ },
43
+ {
44
+ name: 'list_rules',
45
+ description: '列出当前项目已配置的所有规则',
46
+ inputSchema: {
47
+ type: 'object',
48
+ properties: {
49
+ projectPath: {
50
+ type: 'string',
51
+ description: '项目路径,默认当前工作目录'
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ];
57
+
58
+ /**
59
+ * 处理 MCP 调用
60
+ */
61
+ function handleToolCall(toolName, args) {
62
+ const projectPath = args.projectPath || process.cwd();
63
+
64
+ try {
65
+ const detector = new ProjectDetector(projectPath);
66
+
67
+ switch (toolName) {
68
+ case 'scan_project':
69
+ detector.scan();
70
+ return detector.getReport();
71
+
72
+ case 'quick_scan':
73
+ detector.scanTechStack();
74
+ detector.scanMCP();
75
+ detector.scanAgents();
76
+ return {
77
+ projectRoot: detector.root,
78
+ techStack: detector.techStack,
79
+ mcp: detector.existingComponents.mcp,
80
+ agents: detector.existingComponents.agents.map(a => a.name),
81
+ complexity: detector.estimateComplexity()
82
+ };
83
+
84
+ case 'list_rules':
85
+ detector.scanRules();
86
+ return {
87
+ projectRoot: detector.root,
88
+ rules: detector.existingComponents.rules,
89
+ stats: {
90
+ total: detector.existingComponents.rules.length,
91
+ l1: detector.existingComponents.rules.filter(r => r.level === 'L1').length,
92
+ l2: detector.existingComponents.rules.filter(r => r.level === 'L2').length,
93
+ l3: detector.existingComponents.rules.filter(r => r.level === 'L3').length
94
+ }
95
+ };
96
+
97
+ default:
98
+ throw new Error(`Unknown tool: ${toolName}`);
99
+ }
100
+ } catch (error) {
101
+ return { error: error.message };
102
+ }
103
+ }
104
+
105
+ /**
106
+ * 导出 MCP 服务接口
107
+ */
108
+ module.exports = {
109
+ TOOLS,
110
+ handleToolCall,
111
+
112
+ // MCP 服务元信息
113
+ serviceInfo: {
114
+ name: 'project-detector',
115
+ version: '1.0.0',
116
+ description: 'Trae项目探测工具'
117
+ }
118
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "project-detector",
3
+ "version": "1.0.1",
4
+ "description": "| 灞炴€?| 鍊?| |------|-----| | 鍚嶇О | project-detector | | 鐗堟湰 | 1.0.0 | | 鏄剧ず鍚?| Project Detector | | 鎻忚堪 | Trae椤圭洰鎺㈡祴宸ュ叿 - 鑷姩鎵弿椤圭洰鎶€鏈爤銆佺洰褰曟嫇鎵戙€佸凡鏈夌粍浠讹紝涓洪厤缃渶浼樿В鐢熸垚鎻愪緵鏁版嵁鏀拺 | | 绫诲瀷 | Trae宸ュ叿鎻掍欢 | | 鐩綍 | `.trae/plugins/project-detector/` | | MCP鏈嶅姟 | project-detector | | 鍏煎鎬?| Trae >= 1.0.0 | | 璁稿彲璇?| MIT |",
5
+ "main": "project-detector.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "commonjs"
13
+ }
@@ -0,0 +1,122 @@
1
+ {
2
+ "name": "project-detector",
3
+ "version": "1.0.0",
4
+ "displayName": "Project Detector",
5
+ "description": "Trae项目探测工具 - 自动扫描项目技术栈、目录拓扑、已有组件,为配置最优解生成提供数据支撑",
6
+ "author": {
7
+ "name": "TRAIDE",
8
+ "url": "https://trae.ai"
9
+ },
10
+ "publisher": "TRAIDE",
11
+ "license": "MIT",
12
+ "enabled": true,
13
+ "engines": {
14
+ "trae": ">=1.0.0"
15
+ },
16
+ "categories": ["Utility", "Programming Languages"],
17
+ "keywords": ["project", "detector", "scan", "tech-stack", "mcp"],
18
+ "icon": "icon.png",
19
+
20
+ "pluginType": "tool",
21
+ "entryPoint": "./project-detector.js",
22
+
23
+ "activationEvents": [
24
+ "onCommand:trae.project-detector.scan",
25
+ "onCommand:trae.project-detector.quickScan",
26
+ "onCommand:trae.project-detector.listRules",
27
+ "workspaceContains:**/package.json"
28
+ ],
29
+
30
+ "contributes": {
31
+ "commands": [
32
+ {
33
+ "command": "trae.project-detector.scan",
34
+ "title": "Project Detector: Full Scan",
35
+ "category": "TRAIDE",
36
+ "description": "执行完整项目探测,扫描技术栈、目录拓扑、已有组件"
37
+ },
38
+ {
39
+ "command": "trae.project-detector.quickScan",
40
+ "title": "Project Detector: Quick Scan",
41
+ "category": "TRAIDE",
42
+ "description": "快速扫描项目基本信息"
43
+ },
44
+ {
45
+ "command": "trae.project-detector.listRules",
46
+ "title": "Project Detector: List Rules",
47
+ "category": "TRAIDE",
48
+ "description": "列出当前项目已配置的所有规则"
49
+ }
50
+ ],
51
+ "menus": {
52
+ "commandPalette": [
53
+ {
54
+ "command": "trae.project-detector.scan",
55
+ "when": "workspaceFolderCount > 0"
56
+ },
57
+ {
58
+ "command": "trae.project-detector.quickScan",
59
+ "when": "workspaceFolderCount > 0"
60
+ }
61
+ ],
62
+ "explorerContextMenu": [
63
+ {
64
+ "command": "trae.project-detector.scan",
65
+ "when": "ExplorerResourceIsFolder",
66
+ "group": "navigation"
67
+ }
68
+ ]
69
+ },
70
+ "configuration": {
71
+ "title": "Project Detector",
72
+ "properties": {
73
+ "projectDetector.maxScanDepth": {
74
+ "type": "number",
75
+ "default": 4,
76
+ "description": "目录扫描最大深度"
77
+ },
78
+ "projectDetector.excludePatterns": {
79
+ "type": "array",
80
+ "default": ["node_modules", ".git", "dist", "coverage"],
81
+ "description": "扫描排除的目录模式"
82
+ },
83
+ "projectDetector.autoScanOnStartup": {
84
+ "type": "boolean",
85
+ "default": false,
86
+ "description": "IDE启动时自动扫描"
87
+ }
88
+ }
89
+ }
90
+ },
91
+
92
+ "dependencies": {},
93
+
94
+ "mcpIntegration": {
95
+ "enabled": true,
96
+ "serviceName": "project-detector-mcp",
97
+ "tools": [
98
+ "scan_project",
99
+ "quick_scan",
100
+ "list_rules"
101
+ ]
102
+ },
103
+
104
+ "shortcuts": {
105
+ "detect": "$detect",
106
+ "scan": "$scan-project",
107
+ "quick": "$quick-scan"
108
+ },
109
+
110
+ "repository": {
111
+ "type": "git",
112
+ "url": ""
113
+ },
114
+
115
+ "bugs": {
116
+ "url": ""
117
+ },
118
+
119
+ "scripts": {
120
+ "test": "node verify-plugin.js"
121
+ }
122
+ }