entkapp 4.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.
Files changed (46) hide show
  1. package/.scaffold-ignore +22 -0
  2. package/LICENSE +211 -0
  3. package/NOTICE +13 -0
  4. package/README.md +33 -0
  5. package/bin/cli.js +174 -0
  6. package/entkapp/config.json +42 -0
  7. package/entkapp/plugins/README.md +19 -0
  8. package/index.js +2254 -0
  9. package/logo.png +0 -0
  10. package/package.json +96 -0
  11. package/src/EngineContext.js +185 -0
  12. package/src/api/HeadlessAPI.js +376 -0
  13. package/src/api/PluginSDK.js +299 -0
  14. package/src/ast/ASTAnalyzer.js +492 -0
  15. package/src/ast/BarrelParser.js +221 -0
  16. package/src/ast/DeadCodeDetector.js +73 -0
  17. package/src/ast/MagicDetector.js +203 -0
  18. package/src/ast/OxcAnalyzer.js +337 -0
  19. package/src/ast/SecretScanner.js +304 -0
  20. package/src/healing/GitSandbox.js +82 -0
  21. package/src/healing/SelfHealer.js +52 -0
  22. package/src/index.js +723 -0
  23. package/src/performance/GraphCache.js +87 -0
  24. package/src/performance/SupplyChainGuard.js +92 -0
  25. package/src/performance/WorkerPool.js +109 -0
  26. package/src/plugins/BasePlugin.js +71 -0
  27. package/src/plugins/KnipAdapter.js +106 -0
  28. package/src/plugins/PluginRegistry.js +197 -0
  29. package/src/plugins/ecosystems/BackendServices.js +61 -0
  30. package/src/plugins/ecosystems/GenericPlugins.js +64 -0
  31. package/src/plugins/ecosystems/ModernFrameworks.js +159 -0
  32. package/src/plugins/ecosystems/MorePlugins.js +184 -0
  33. package/src/plugins/ecosystems/NextJsPlugin.js +33 -0
  34. package/src/plugins/ecosystems/PluginLoader.js +20 -0
  35. package/src/plugins/ecosystems/TypeScriptPlugin.js +56 -0
  36. package/src/refractor/ImpactAnalyzer.js +92 -0
  37. package/src/refractor/SourceRewriter.js +86 -0
  38. package/src/refractor/TransactionManager.js +138 -0
  39. package/src/refractor/TypeIntegrity.js +75 -0
  40. package/src/resolution/CircularDetector.js +91 -0
  41. package/src/resolution/ConfigLoader.js +87 -0
  42. package/src/resolution/DepencyResolver.js +133 -0
  43. package/src/resolution/DependencyProfiler.js +268 -0
  44. package/src/resolution/PathMapper.js +125 -0
  45. package/src/resolution/WorkSpaceGraph.js +474 -0
  46. package/tsconfig.json +26 -0
@@ -0,0 +1,299 @@
1
+ /**
2
+ * ============================================================================
3
+ * Plugin SDK for entkapp v4.0.0
4
+ * ============================================================================
5
+ * Provides utilities and helpers for developing custom plugins that extend
6
+ * entkapp's analysis and healing capabilities.
7
+ */
8
+
9
+ import { BasePlugin } from '../plugins/BasePlugin.js';
10
+
11
+ /**
12
+ * Extended plugin base class with SDK utilities
13
+ */
14
+ export class PluginSDKBase extends BasePlugin {
15
+ constructor(context) {
16
+ super(context);
17
+ this.hooks = new Map();
18
+ this.transformers = [];
19
+ this.validators = [];
20
+ }
21
+
22
+ /**
23
+ * Register a hook for a specific lifecycle event
24
+ * @param {string} eventName - Event name (e.g., 'analyze:start', 'refactor:complete')
25
+ * @param {Function} handler - Handler function
26
+ */
27
+ registerHook(eventName, handler) {
28
+ if (!this.hooks.has(eventName)) {
29
+ this.hooks.set(eventName, []);
30
+ }
31
+ this.hooks.get(eventName).push(handler);
32
+ }
33
+
34
+ /**
35
+ * Emit a hook event
36
+ * @param {string} eventName - Event name
37
+ * @param {Object} data - Event data
38
+ */
39
+ async emitHook(eventName, data) {
40
+ const handlers = this.hooks.get(eventName) || [];
41
+ for (const handler of handlers) {
42
+ await handler(data);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Register a code transformer
48
+ * @param {Function} transformer - Transformer function
49
+ */
50
+ registerTransformer(transformer) {
51
+ this.transformers.push(transformer);
52
+ }
53
+
54
+ /**
55
+ * Register a validator
56
+ * @param {Function} validator - Validator function
57
+ */
58
+ registerValidator(validator) {
59
+ this.validators.push(validator);
60
+ }
61
+
62
+ /**
63
+ * Apply all registered transformers to a code string
64
+ * @param {string} code - Source code
65
+ * @param {string} filePath - File path
66
+ * @returns {Promise<string>} Transformed code
67
+ */
68
+ async applyTransformers(code, filePath) {
69
+ let result = code;
70
+ for (const transformer of this.transformers) {
71
+ result = await transformer(result, filePath);
72
+ }
73
+ return result;
74
+ }
75
+
76
+ /**
77
+ * Run all validators on a code string
78
+ * @param {string} code - Source code
79
+ * @param {string} filePath - File path
80
+ * @returns {Promise<Array>} Validation errors
81
+ */
82
+ async runValidators(code, filePath) {
83
+ const errors = [];
84
+ for (const validator of this.validators) {
85
+ const result = await validator(code, filePath);
86
+ if (result && result.length > 0) {
87
+ errors.push(...result);
88
+ }
89
+ }
90
+ return errors;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * SDK utilities for plugin development
96
+ */
97
+ export class PluginSDK {
98
+ /**
99
+ * Create a custom plugin class
100
+ * @param {Object} config - Plugin configuration
101
+ * @returns {Class} Plugin class
102
+ */
103
+ static createPlugin(config) {
104
+ return class CustomPlugin extends PluginSDKBase {
105
+ get name() {
106
+ return config.name;
107
+ }
108
+
109
+ getConfigFiles() {
110
+ return config.configFiles || [];
111
+ }
112
+
113
+ getRoutePatterns() {
114
+ return config.routePatterns || [];
115
+ }
116
+
117
+ getRequiredSystemContracts() {
118
+ return config.requiredContracts || ['default'];
119
+ }
120
+
121
+ async isActive(baseDir) {
122
+ if (config.isActive) {
123
+ return await config.isActive(baseDir);
124
+ }
125
+ return super.isActive(baseDir);
126
+ }
127
+
128
+ async initialize() {
129
+ if (config.initialize) {
130
+ await config.initialize(this.context);
131
+ }
132
+ }
133
+
134
+ async analyze(node, filePath) {
135
+ if (config.analyze) {
136
+ return await config.analyze(node, filePath, this.context);
137
+ }
138
+ }
139
+
140
+ async transform(code, filePath) {
141
+ if (config.transform) {
142
+ return await config.transform(code, filePath, this.context);
143
+ }
144
+ return code;
145
+ }
146
+
147
+ async validate(code, filePath) {
148
+ if (config.validate) {
149
+ return await config.validate(code, filePath, this.context);
150
+ }
151
+ return [];
152
+ }
153
+ };
154
+ }
155
+
156
+ /**
157
+ * Create a CSS-in-JS analyzer plugin
158
+ * @param {Object} config - Configuration for CSS-in-JS analysis
159
+ * @returns {Class} Plugin class
160
+ */
161
+ static createCSSInJSPlugin(config = {}) {
162
+ const cssLibraries = config.libraries || [
163
+ 'styled-components',
164
+ 'emotion',
165
+ '@emotion/react',
166
+ '@emotion/styled',
167
+ 'linaria',
168
+ 'vanilla-extract'
169
+ ];
170
+
171
+ return this.createPlugin({
172
+ name: config.name || 'css-in-js-analyzer',
173
+ configFiles: [],
174
+ routePatterns: [/\.(tsx?|jsx?)$/],
175
+ requiredContracts: [],
176
+
177
+ async analyze(node, filePath) {
178
+ // Track CSS-in-JS imports
179
+ for (const lib of cssLibraries) {
180
+ if (node.explicitImports.has(lib)) {
181
+ node.cssInJsLibraries = node.cssInJsLibraries || new Set();
182
+ node.cssInJsLibraries.add(lib);
183
+ }
184
+ }
185
+
186
+ // Detect styled component definitions
187
+ const styledPattern = /(?:styled|css|keyframes)\s*\.\w+|styled\(\w+\)/g;
188
+ for (const match of (node.rawCode || '').matchAll(styledPattern)) {
189
+ node.styledComponentUsages = node.styledComponentUsages || [];
190
+ node.styledComponentUsages.push(match[0]);
191
+ }
192
+ },
193
+
194
+ async validate(code, filePath) {
195
+ const errors = [];
196
+ // Check for unused CSS-in-JS definitions
197
+ const unusedStylesPattern = /(?:const|let|var)\s+(\w+)\s*=\s*(?:styled|css)\./g;
198
+ const matches = [...code.matchAll(unusedStylesPattern)];
199
+
200
+ for (const match of matches) {
201
+ const styleName = match[1];
202
+ const usagePattern = new RegExp(`\\b${styleName}\\b`);
203
+ if (!usagePattern.test(code.substring(match.index + match[0].length))) {
204
+ errors.push({
205
+ type: 'unused-style',
206
+ name: styleName,
207
+ line: code.substring(0, match.index).split('\n').length,
208
+ message: `Unused CSS-in-JS definition: ${styleName}`
209
+ });
210
+ }
211
+ }
212
+
213
+ return errors;
214
+ }
215
+ });
216
+ }
217
+
218
+ /**
219
+ * Create an asset tracking plugin
220
+ * @param {Object} config - Configuration for asset tracking
221
+ * @returns {Class} Plugin class
222
+ */
223
+ static createAssetTrackingPlugin(config = {}) {
224
+ const assetExtensions = config.extensions || [
225
+ '.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp',
226
+ '.mp4', '.webm', '.mp3', '.wav',
227
+ '.woff', '.woff2', '.ttf', '.eot'
228
+ ];
229
+
230
+ return this.createPlugin({
231
+ name: config.name || 'asset-tracker',
232
+ configFiles: [],
233
+ routePatterns: [/\.(tsx?|jsx?)$/],
234
+
235
+ async analyze(node, filePath) {
236
+ node.assetReferences = node.assetReferences || new Set();
237
+
238
+ // Track asset imports
239
+ const assetImportPattern = /import\s+(?:\*\s+as\s+\w+|[\w\s,{}]+)\s+from\s+['"]([^'"]+(?:${assetExtensions.join('|')}))['"]/g;
240
+ for (const match of (node.rawCode || '').matchAll(assetImportPattern)) {
241
+ node.assetReferences.add(match[1]);
242
+ }
243
+
244
+ // Track asset requires
245
+ const assetRequirePattern = /require\s*\(\s*['"]([^'"]+(?:${assetExtensions.join('|')}))['"]\s*\)/g;
246
+ for (const match of (node.rawCode || '').matchAll(assetRequirePattern)) {
247
+ node.assetReferences.add(match[1]);
248
+ }
249
+
250
+ // Track asset URLs in strings
251
+ const assetUrlPattern = /['"]([^'"]*(?:${assetExtensions.join('|')}))['"]/g;
252
+ for (const match of (node.rawCode || '').matchAll(assetUrlPattern)) {
253
+ node.assetReferences.add(match[1]);
254
+ }
255
+ }
256
+ });
257
+ }
258
+
259
+ /**
260
+ * Create a monorepo awareness plugin
261
+ * @param {Object} config - Configuration for monorepo support
262
+ * @returns {Class} Plugin class
263
+ */
264
+ static createMonorepoPlugin(config = {}) {
265
+ return this.createPlugin({
266
+ name: config.name || 'monorepo-aware',
267
+ configFiles: config.configFiles || ['nx.json', 'pnpm-workspace.yaml', 'lerna.json'],
268
+
269
+ async analyze(node, filePath) {
270
+ // Track workspace package references
271
+ node.workspaceReferences = node.workspaceReferences || new Set();
272
+
273
+ // Detect workspace imports (e.g., @workspace/package-name)
274
+ const workspacePattern = /@[\w-]+\/[\w-]+/g;
275
+ for (const match of (node.rawCode || '').matchAll(workspacePattern)) {
276
+ node.workspaceReferences.add(match[0]);
277
+ }
278
+ }
279
+ });
280
+ }
281
+
282
+ /**
283
+ * Create a circular dependency detector plugin
284
+ * @param {Object} config - Configuration
285
+ * @returns {Class} Plugin class
286
+ */
287
+ static createCircularDepPlugin(config = {}) {
288
+ return this.createPlugin({
289
+ name: config.name || 'circular-dep-detector',
290
+
291
+ async analyze(node, filePath) {
292
+ node.potentialCycles = node.potentialCycles || [];
293
+ // Cycle detection will be handled by the main engine
294
+ }
295
+ });
296
+ }
297
+ }
298
+
299
+ export default PluginSDK;