bonzai-tools 1.0.92

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.
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ const express = require('./node_modules/express');
4
+ const cors = require('./node_modules/cors');
5
+ const http = require('http');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { ROOT } = require('./config');
9
+
10
+ const app = express();
11
+ const server = http.createServer(app);
12
+
13
+ app.use(cors());
14
+ app.use(express.json());
15
+
16
+ // Root route
17
+ app.get('/', (req, res) => {
18
+ const repoName = path.basename(ROOT);
19
+ res.json({ message: 'Bonzai Server', status: 'running', repoName });
20
+ });
21
+
22
+ // Dynamically load handlers based on what exists
23
+ const handlersDir = path.join(__dirname, 'handlers');
24
+
25
+ function tryLoad(name) {
26
+ const filePath = path.join(handlersDir, name + '.js');
27
+ if (fs.existsSync(filePath)) {
28
+ return require(filePath);
29
+ }
30
+ return null;
31
+ }
32
+
33
+ // Visualization loop handlers
34
+ const listHandler = tryLoad('list');
35
+ const readHandler = tryLoad('read');
36
+
37
+ if (listHandler) app.get('/list', listHandler);
38
+ if (readHandler) app.get('/read', readHandler);
39
+
40
+ // Backend loop handlers
41
+ const deleteHandler = tryLoad('delete');
42
+ const writeHandler = tryLoad('write');
43
+ const shutdownHandler = tryLoad('shutdown');
44
+ const terminalHandlers = tryLoad('terminal');
45
+
46
+ if (deleteHandler) app.post('/delete', deleteHandler);
47
+ if (writeHandler) app.post('/write', writeHandler);
48
+ if (shutdownHandler) app.post('/shutdown', shutdownHandler);
49
+ if (terminalHandlers) {
50
+ const { WebSocketServer } = require('./node_modules/ws');
51
+ const wss = new WebSocketServer({ server, path: '/terminal' });
52
+ terminalHandlers.setupTerminalWebSocket(wss);
53
+ app.get('/terminal', terminalHandlers.terminalHandler);
54
+ }
55
+
56
+ const port = 3001;
57
+ server.listen(port, () => {
58
+ console.log('File server running on http://localhost:' + port);
59
+ });
@@ -0,0 +1,96 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { getIgnorePatterns, shouldIgnore } = require('./ignore');
4
+ const { extractPythonFunctions, extractJavaScriptFunctions, extractVueFunctions } = require('./parsers');
5
+
6
+ // Recursively list all files in a directory, respecting ignore patterns
7
+ function listAllFiles(dir, base = '', ignorePatterns = null) {
8
+ if (ignorePatterns === null) {
9
+ ignorePatterns = getIgnorePatterns();
10
+ }
11
+
12
+ let results = [];
13
+ const list = fs.readdirSync(dir);
14
+
15
+ for (const file of list) {
16
+ const fullPath = path.join(dir, file);
17
+ const relativePath = path.join(base, file);
18
+
19
+ // Check if this path should be ignored
20
+ if (shouldIgnore(relativePath, ignorePatterns)) {
21
+ continue;
22
+ }
23
+
24
+ const stat = fs.statSync(fullPath);
25
+ if (stat && stat.isDirectory()) {
26
+ // Skip node_modules directories explicitly
27
+ if (file === 'node_modules' || relativePath.includes('node_modules/')) {
28
+ continue;
29
+ }
30
+ // Add the directory itself to results
31
+ results.push(relativePath + '/');
32
+ // Recursively list files inside the directory
33
+ results = results.concat(listAllFiles(fullPath, relativePath, ignorePatterns));
34
+ } else {
35
+ // Skip files in node_modules explicitly
36
+ if (relativePath.includes('node_modules/') || fullPath.includes('node_modules')) {
37
+ continue;
38
+ }
39
+
40
+ results.push(relativePath);
41
+
42
+ // Helper function to add functions, classes, and methods as virtual files
43
+ const addVirtualFiles = (parseResult, filePath) => {
44
+ // Add functions
45
+ for (const func of parseResult.functions) {
46
+ const functionFileName = func.name + '.function';
47
+ const functionFilePath = path.join(filePath, functionFileName).replace(/\\/g, '/');
48
+ results.push(functionFilePath);
49
+ }
50
+
51
+ // Add classes and their methods
52
+ for (const cls of parseResult.classes) {
53
+ // Add class itself (optional, but useful)
54
+ const className = cls.name + '.class';
55
+ const classFilePath = path.join(filePath, className).replace(/\\/g, '/');
56
+ results.push(classFilePath);
57
+
58
+ // Add methods nested under the class: ClassName.methodName
59
+ if (cls.methods && cls.methods.length > 0) {
60
+ for (const method of cls.methods) {
61
+ const methodFileName = method.name + '.method';
62
+ const methodFilePath = path.join(classFilePath, methodFileName).replace(/\\/g, '/');
63
+ results.push(methodFilePath);
64
+ }
65
+ }
66
+ }
67
+ };
68
+
69
+ // Handle Python files
70
+ if (file.endsWith('.py')) {
71
+ const parseResult = extractPythonFunctions(fullPath);
72
+ addVirtualFiles(parseResult, relativePath);
73
+ }
74
+
75
+ // Handle JavaScript/TypeScript files
76
+ // Skip .d.ts files (TypeScript declaration files) and .min.js files (minified)
77
+ if ((file.endsWith('.js') || file.endsWith('.jsx') || file.endsWith('.ts') || file.endsWith('.tsx')) &&
78
+ !file.endsWith('.d.ts') && !file.endsWith('.min.js')) {
79
+ const parseResult = extractJavaScriptFunctions(fullPath);
80
+ addVirtualFiles(parseResult, relativePath);
81
+ }
82
+
83
+ // Handle Vue files
84
+ if (file.endsWith('.vue')) {
85
+ const parseResult = extractVueFunctions(fullPath);
86
+ addVirtualFiles(parseResult, relativePath);
87
+ }
88
+ }
89
+ }
90
+ return results;
91
+ }
92
+
93
+ module.exports = {
94
+ listAllFiles
95
+ };
96
+
@@ -0,0 +1,52 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // Read and parse ignore patterns from .ignore file
5
+ function getIgnorePatterns() {
6
+ try {
7
+ const ignorePath = path.join(__dirname, '..', '.ignore');
8
+ if (fs.existsSync(ignorePath)) {
9
+ const content = fs.readFileSync(ignorePath, 'utf8');
10
+ return content
11
+ .split('\n')
12
+ .map(line => line.trim())
13
+ .filter(line => line && !line.startsWith('#'))
14
+ .map(pattern => {
15
+ // Convert simple glob patterns to regex
16
+ if (pattern.endsWith('/')) {
17
+ // Directory pattern
18
+ pattern = pattern.slice(0, -1);
19
+ }
20
+
21
+ // Simple approach: escape dots and convert globs
22
+ pattern = pattern.replace(/\./g, '\\.');
23
+ pattern = pattern.replace(/\*\*/g, '|||DOUBLESTAR|||');
24
+ pattern = pattern.replace(/\*/g, '[^/]*');
25
+ pattern = pattern.replace(/\|\|\|DOUBLESTAR\|\|\|/g, '.*');
26
+
27
+ return new RegExp('^' + pattern + '(/.*)?$');
28
+ });
29
+ }
30
+ } catch (e) {
31
+ console.warn('Could not read .ignore file:', e.message);
32
+ }
33
+
34
+ // Default ignore patterns if no .ignore file exists
35
+ return [
36
+ /^node_modules(\/.*)?$/,
37
+ /^\.git(\/.*)?$/,
38
+ /^\.DS_Store$/,
39
+ /^\.env$/,
40
+ ];
41
+ }
42
+
43
+ // Check if a path should be ignored
44
+ function shouldIgnore(relativePath, ignorePatterns) {
45
+ return ignorePatterns.some(pattern => pattern.test(relativePath));
46
+ }
47
+
48
+ module.exports = {
49
+ getIgnorePatterns,
50
+ shouldIgnore
51
+ };
52
+