@papicandela/mcx-core 0.2.0 → 0.2.1

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/dist/index.js CHANGED
@@ -6005,6 +6005,16 @@ var allRules = [
6005
6005
  ];
6006
6006
 
6007
6007
  // src/sandbox/analyzer/analyzer.ts
6008
+ var visitorMapCache = new Map;
6009
+ function getVisitorMap(rules, config) {
6010
+ const cacheKey = JSON.stringify(config.rules);
6011
+ let map = visitorMapCache.get(cacheKey);
6012
+ if (!map) {
6013
+ map = buildVisitorMap(rules, config);
6014
+ visitorMapCache.set(cacheKey, map);
6015
+ }
6016
+ return map;
6017
+ }
6008
6018
  function buildVisitorMap(rules, config) {
6009
6019
  const map = new Map;
6010
6020
  for (const rule6 of rules) {
@@ -6093,7 +6103,7 @@ function analyze(code, config = {}) {
6093
6103
  elapsed: performance.now() - start
6094
6104
  };
6095
6105
  }
6096
- const visitorMap = buildVisitorMap(allRules, fullConfig);
6106
+ const visitorMap = getVisitorMap(allRules, fullConfig);
6097
6107
  const context = {
6098
6108
  code,
6099
6109
  getLine: (node) => getLineNumber(code, node.start),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papicandela/mcx-core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "MCX Core - MCP Code Execution Framework",
5
5
  "author": "papicandela",
6
6
  "license": "MIT",
@@ -36,6 +36,24 @@ import { allRules } from "./rules/index.js";
36
36
  */
37
37
  type VisitorMap = Map<string, Array<{ rule: Rule; visitor: Rule["visitors"][string] }>>;
38
38
 
39
+ // Cache for visitor maps - keyed by stringified rules config
40
+ const visitorMapCache = new Map<string, VisitorMap>();
41
+
42
+ /**
43
+ * Get or build a visitor map (cached for performance)
44
+ */
45
+ function getVisitorMap(rules: Rule[], config: Required<AnalysisConfig>): VisitorMap {
46
+ // Create cache key from rules config
47
+ const cacheKey = JSON.stringify(config.rules);
48
+
49
+ let map = visitorMapCache.get(cacheKey);
50
+ if (!map) {
51
+ map = buildVisitorMap(rules, config);
52
+ visitorMapCache.set(cacheKey, map);
53
+ }
54
+ return map;
55
+ }
56
+
39
57
  /**
40
58
  * Build a visitor map from rules for efficient traversal
41
59
  */
@@ -162,8 +180,8 @@ export function analyze(
162
180
  };
163
181
  }
164
182
 
165
- // Build visitor map
166
- const visitorMap = buildVisitorMap(allRules, fullConfig);
183
+ // Get visitor map (cached for repeated calls with same config)
184
+ const visitorMap = getVisitorMap(allRules, fullConfig);
167
185
 
168
186
  // Create context
169
187
  const context: RuleContext = {