bonzai-tree 1.0.113
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 +4 -0
- package/dist/bconfig.js +224 -0
- package/dist/graph-templates/config.js +18 -0
- package/dist/graph-templates/ignore.txt +58 -0
- package/dist/graph-templates/loops/backend/delete.js +20 -0
- package/dist/graph-templates/loops/backend/shutdown.js +16 -0
- package/dist/graph-templates/loops/backend/terminal.js +142 -0
- package/dist/graph-templates/loops/backend/write.js +18 -0
- package/dist/graph-templates/loops/visualization/list.js +18 -0
- package/dist/graph-templates/loops/visualization/read.js +120 -0
- package/dist/graph-templates/receiver.js +85 -0
- package/dist/graph-templates/utils/fileList.js +96 -0
- package/dist/graph-templates/utils/ignore.js +52 -0
- package/dist/graph-templates/utils/parsers.js +720 -0
- package/dist/index.js +257 -0
- package/dist/payload-bonzai/config.json +31 -0
- package/package.json +40 -0
|
@@ -0,0 +1,85 @@
|
|
|
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 port = 6767;
|
|
11
|
+
const app = express();
|
|
12
|
+
const server = http.createServer(app);
|
|
13
|
+
|
|
14
|
+
app.use(cors());
|
|
15
|
+
app.use(express.json());
|
|
16
|
+
|
|
17
|
+
// Health check
|
|
18
|
+
app.get('/health', (req, res) => {
|
|
19
|
+
const repoName = path.basename(ROOT);
|
|
20
|
+
res.json({ message: 'Bonzai Server', status: 'running', repoName });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Dynamically load handlers based on what exists
|
|
24
|
+
const handlersDir = path.join(__dirname, 'handlers');
|
|
25
|
+
|
|
26
|
+
function tryLoad(name) {
|
|
27
|
+
const filePath = path.join(handlersDir, name + '.js');
|
|
28
|
+
if (fs.existsSync(filePath)) {
|
|
29
|
+
return require(filePath);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Visualization loop handlers
|
|
35
|
+
const listHandler = tryLoad('list');
|
|
36
|
+
const readHandler = tryLoad('read');
|
|
37
|
+
|
|
38
|
+
if (listHandler) app.get('/list', listHandler);
|
|
39
|
+
if (readHandler) app.get('/read', readHandler);
|
|
40
|
+
|
|
41
|
+
// Backend loop handlers
|
|
42
|
+
const deleteHandler = tryLoad('delete');
|
|
43
|
+
const writeHandler = tryLoad('write');
|
|
44
|
+
const shutdownHandler = tryLoad('shutdown');
|
|
45
|
+
const terminalHandlers = tryLoad('terminal');
|
|
46
|
+
|
|
47
|
+
if (deleteHandler) app.post('/delete', deleteHandler);
|
|
48
|
+
if (writeHandler) app.post('/write', writeHandler);
|
|
49
|
+
if (shutdownHandler) app.post('/shutdown', shutdownHandler);
|
|
50
|
+
if (terminalHandlers) {
|
|
51
|
+
const { WebSocketServer } = require('./node_modules/ws');
|
|
52
|
+
const wss = new WebSocketServer({ server, path: '/terminal' });
|
|
53
|
+
terminalHandlers.setupTerminalWebSocket(wss);
|
|
54
|
+
app.get('/terminal', terminalHandlers.terminalHandler);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Catch-all for SPA routing - serve HTML shell for any non-API route
|
|
58
|
+
app.get('*', (req, res) => {
|
|
59
|
+
const repoName = path.basename(ROOT);
|
|
60
|
+
res.send(`<!DOCTYPE html>
|
|
61
|
+
<html>
|
|
62
|
+
<head>
|
|
63
|
+
<meta charset="UTF-8">
|
|
64
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
65
|
+
<title>Bonzai - ${repoName}</title>
|
|
66
|
+
<link rel="stylesheet" href="https://bonzai.dev/app.css">
|
|
67
|
+
<style>
|
|
68
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
69
|
+
html, body, #root { height: 100%; }
|
|
70
|
+
</style>
|
|
71
|
+
</head>
|
|
72
|
+
<body>
|
|
73
|
+
<div id="root"></div>
|
|
74
|
+
<script>
|
|
75
|
+
window.BONZAI_REPO = "${repoName}";
|
|
76
|
+
window.BONZAI_API = "http://localhost:${port}";
|
|
77
|
+
</script>
|
|
78
|
+
<script src="https://bonzai.dev/app.js"></script>
|
|
79
|
+
</body>
|
|
80
|
+
</html>`);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
server.listen(port, () => {
|
|
84
|
+
console.log('File server running on http://localhost:' + port);
|
|
85
|
+
});
|
|
@@ -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
|
+
|