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
package/dist/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs, { existsSync, mkdirSync, copyFileSync } from 'fs';
|
|
3
|
+
import path, { dirname, join } from 'path';
|
|
4
|
+
import { spawn, exec } from 'child_process';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/loops.config.js
|
|
18
|
+
var CHANNELS, channel, ENABLED_LOOPS;
|
|
19
|
+
var init_loops_config = __esm({
|
|
20
|
+
"src/loops.config.js"() {
|
|
21
|
+
CHANNELS = {
|
|
22
|
+
dev: ["visualization", "backend"],
|
|
23
|
+
staging: ["visualization", "backend"],
|
|
24
|
+
prod: ["visualization", "backend"]
|
|
25
|
+
};
|
|
26
|
+
channel = "prod";
|
|
27
|
+
ENABLED_LOOPS = CHANNELS[channel] || CHANNELS.prod;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// src/bconfig.js
|
|
32
|
+
var bconfig_exports = {};
|
|
33
|
+
__export(bconfig_exports, {
|
|
34
|
+
main: () => main
|
|
35
|
+
});
|
|
36
|
+
function copyDirectory(src, dest) {
|
|
37
|
+
if (!fs.existsSync(dest)) {
|
|
38
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
const srcPath = path.join(src, entry.name);
|
|
43
|
+
const destPath = path.join(dest, entry.name);
|
|
44
|
+
if (entry.isDirectory()) {
|
|
45
|
+
copyDirectory(srcPath, destPath);
|
|
46
|
+
} else {
|
|
47
|
+
fs.copyFileSync(srcPath, destPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function main() {
|
|
52
|
+
const currentDir = process.cwd();
|
|
53
|
+
const bonzaiDir = path.join(currentDir, "bonzai");
|
|
54
|
+
const receiverPath = path.join(bonzaiDir, "receiver.js");
|
|
55
|
+
console.log("Setting up local file server...");
|
|
56
|
+
if (!fs.existsSync(bonzaiDir)) {
|
|
57
|
+
console.log("Creating bonzai directory...");
|
|
58
|
+
fs.mkdirSync(bonzaiDir);
|
|
59
|
+
}
|
|
60
|
+
console.log("Writing receiver.js...");
|
|
61
|
+
const receiverContent = fs.readFileSync(path.join(TEMPLATE_DIR, "receiver.js"), "utf8");
|
|
62
|
+
fs.writeFileSync(receiverPath, receiverContent);
|
|
63
|
+
fs.chmodSync(receiverPath, "755");
|
|
64
|
+
console.log("Writing config.js...");
|
|
65
|
+
const configContent = fs.readFileSync(path.join(TEMPLATE_DIR, "config.js"), "utf8");
|
|
66
|
+
fs.writeFileSync(path.join(bonzaiDir, "config.js"), configContent);
|
|
67
|
+
console.log("Copying handlers...");
|
|
68
|
+
const handlersDest = path.join(bonzaiDir, "handlers");
|
|
69
|
+
if (!fs.existsSync(handlersDest)) {
|
|
70
|
+
fs.mkdirSync(handlersDest, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
if (ENABLED_LOOPS.includes("visualization")) {
|
|
73
|
+
const vizSrc = path.join(TEMPLATE_DIR, "loops", "visualization");
|
|
74
|
+
if (fs.existsSync(vizSrc)) {
|
|
75
|
+
for (const file of fs.readdirSync(vizSrc)) {
|
|
76
|
+
fs.copyFileSync(path.join(vizSrc, file), path.join(handlersDest, file));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (ENABLED_LOOPS.includes("backend")) {
|
|
81
|
+
const backendSrc = path.join(TEMPLATE_DIR, "loops", "backend");
|
|
82
|
+
if (fs.existsSync(backendSrc)) {
|
|
83
|
+
for (const file of fs.readdirSync(backendSrc)) {
|
|
84
|
+
fs.copyFileSync(path.join(backendSrc, file), path.join(handlersDest, file));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.log("Copying utils...");
|
|
89
|
+
const utilsSrc = path.join(TEMPLATE_DIR, "utils");
|
|
90
|
+
const utilsDest = path.join(bonzaiDir, "utils");
|
|
91
|
+
copyDirectory(utilsSrc, utilsDest);
|
|
92
|
+
const ignoreTargetPath = path.join(bonzaiDir, ".ignore");
|
|
93
|
+
if (!fs.existsSync(ignoreTargetPath)) {
|
|
94
|
+
console.log("Writing .ignore file...");
|
|
95
|
+
const ignoreContent = fs.readFileSync(path.join(TEMPLATE_DIR, "ignore.txt"), "utf8");
|
|
96
|
+
fs.writeFileSync(ignoreTargetPath, ignoreContent);
|
|
97
|
+
}
|
|
98
|
+
const packageJsonPath = path.join(bonzaiDir, "package.json");
|
|
99
|
+
let packageJson = {};
|
|
100
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
101
|
+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
102
|
+
} else {
|
|
103
|
+
packageJson = {
|
|
104
|
+
name: "bonzai-server",
|
|
105
|
+
version: "1.0.0",
|
|
106
|
+
description: "Dependencies for bonzai graph server",
|
|
107
|
+
main: "receiver.js",
|
|
108
|
+
scripts: {
|
|
109
|
+
test: 'echo "Error: no test specified" && exit 1'
|
|
110
|
+
},
|
|
111
|
+
author: "",
|
|
112
|
+
license: "ISC"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (!packageJson.dependencies) {
|
|
116
|
+
packageJson.dependencies = {};
|
|
117
|
+
}
|
|
118
|
+
packageJson.dependencies.express = "^4.18.2";
|
|
119
|
+
packageJson.dependencies.cors = "^2.8.5";
|
|
120
|
+
packageJson.dependencies["@babel/parser"] = "^7.23.0";
|
|
121
|
+
packageJson.dependencies.ws = "^8.14.2";
|
|
122
|
+
packageJson.dependencies["node-pty"] = "^1.0.0";
|
|
123
|
+
if (!packageJson.scripts) {
|
|
124
|
+
packageJson.scripts = {};
|
|
125
|
+
}
|
|
126
|
+
packageJson.scripts["file-server"] = "node receiver.js";
|
|
127
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
128
|
+
console.log("Installing dependencies...");
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
const npm = spawn("npm", ["install"], {
|
|
131
|
+
stdio: "inherit",
|
|
132
|
+
cwd: bonzaiDir
|
|
133
|
+
});
|
|
134
|
+
npm.on("close", (code) => {
|
|
135
|
+
if (code === 0) {
|
|
136
|
+
const nodePtyPrebuilds = path.join(bonzaiDir, "node_modules", "node-pty", "prebuilds");
|
|
137
|
+
if (fs.existsSync(nodePtyPrebuilds)) {
|
|
138
|
+
const archDirs = ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64"];
|
|
139
|
+
for (const arch of archDirs) {
|
|
140
|
+
const spawnHelperPath = path.join(nodePtyPrebuilds, arch, "spawn-helper");
|
|
141
|
+
if (fs.existsSync(spawnHelperPath)) {
|
|
142
|
+
try {
|
|
143
|
+
fs.chmodSync(spawnHelperPath, "755");
|
|
144
|
+
console.log(`Fixed node-pty spawn-helper permissions (${arch})`);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.warn(`Warning: Could not fix spawn-helper permissions for ${arch}:`, e.message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
console.log("\nListener endpoints successfully deployed");
|
|
152
|
+
console.log("All code stays on your machine\n");
|
|
153
|
+
console.log("Relay server running on localhost:6767");
|
|
154
|
+
console.log("Terminal WebSocket available at ws://localhost:6767/terminal");
|
|
155
|
+
console.log("App available at http://localhost:6767\n");
|
|
156
|
+
const server = spawn("node", ["receiver.js"], {
|
|
157
|
+
stdio: "inherit",
|
|
158
|
+
cwd: bonzaiDir,
|
|
159
|
+
env: {
|
|
160
|
+
...process.env,
|
|
161
|
+
BONZAI_REPO_DIR: currentDir
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
exec("open http://localhost:6767/visualize?ref=btools");
|
|
165
|
+
server.on("close", (serverCode) => {
|
|
166
|
+
console.log(`
|
|
167
|
+
Server stopped with code ${serverCode}`);
|
|
168
|
+
process.exit(serverCode);
|
|
169
|
+
});
|
|
170
|
+
server.on("error", (err) => {
|
|
171
|
+
console.error("Error starting server:", err.message);
|
|
172
|
+
process.exit(1);
|
|
173
|
+
});
|
|
174
|
+
process.on("SIGINT", () => {
|
|
175
|
+
console.log("\nShutting down server...");
|
|
176
|
+
server.kill("SIGINT");
|
|
177
|
+
});
|
|
178
|
+
process.on("SIGTERM", () => {
|
|
179
|
+
console.log("\nShutting down server...");
|
|
180
|
+
server.kill("SIGTERM");
|
|
181
|
+
});
|
|
182
|
+
resolve();
|
|
183
|
+
} else {
|
|
184
|
+
reject(new Error("npm install failed with code " + code));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
npm.on("error", (err) => {
|
|
188
|
+
reject(err);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
var __filename$1, __dirname$1, TEMPLATE_DIR, _a, isDirectRun;
|
|
193
|
+
var init_bconfig = __esm({
|
|
194
|
+
"src/bconfig.js"() {
|
|
195
|
+
init_loops_config();
|
|
196
|
+
__filename$1 = fileURLToPath(import.meta.url);
|
|
197
|
+
__dirname$1 = path.dirname(__filename$1);
|
|
198
|
+
TEMPLATE_DIR = path.join(__dirname$1, "graph-templates");
|
|
199
|
+
isDirectRun = (_a = process.argv[1]) == null ? void 0 : _a.endsWith("bconfig.js");
|
|
200
|
+
if (isDirectRun) {
|
|
201
|
+
main().catch(console.error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// src/index.js
|
|
207
|
+
init_loops_config();
|
|
208
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
209
|
+
var __dirname2 = dirname(__filename2);
|
|
210
|
+
var BONZAI_DIR = "bonzai";
|
|
211
|
+
var TEMPLATE_DIR2 = join(__dirname2, "payload-bonzai");
|
|
212
|
+
function showHelp() {
|
|
213
|
+
let help = `
|
|
214
|
+
Usage: npx bonzai-tree [option]
|
|
215
|
+
|
|
216
|
+
Options:
|
|
217
|
+
(no option) Initialize bonzai in current directory
|
|
218
|
+
--help Show this help message`;
|
|
219
|
+
if (ENABLED_LOOPS.includes("visualization") || ENABLED_LOOPS.includes("backend")) {
|
|
220
|
+
help = help.replace("--help", "-v, --visualize Launch visualization server\n --help");
|
|
221
|
+
}
|
|
222
|
+
console.log(help);
|
|
223
|
+
}
|
|
224
|
+
function init() {
|
|
225
|
+
const currentDir = process.cwd();
|
|
226
|
+
const bonzaiPath = join(currentDir, BONZAI_DIR);
|
|
227
|
+
if (existsSync(bonzaiPath)) {
|
|
228
|
+
console.log(`${BONZAI_DIR}/ already exists`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
mkdirSync(bonzaiPath, { recursive: true });
|
|
232
|
+
copyFileSync(join(TEMPLATE_DIR2, "config.json"), join(bonzaiPath, "config.json"));
|
|
233
|
+
console.log(`Created ${BONZAI_DIR}/ folder with config.json`);
|
|
234
|
+
console.log("");
|
|
235
|
+
console.log(" \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510");
|
|
236
|
+
console.log(" \u2502 npx bonzai-tree -v Launch visualization server \u2502");
|
|
237
|
+
console.log(" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518");
|
|
238
|
+
}
|
|
239
|
+
async function main2() {
|
|
240
|
+
const args = process.argv.slice(2);
|
|
241
|
+
const flag = args[0];
|
|
242
|
+
if (ENABLED_LOOPS.includes("visualization") || ENABLED_LOOPS.includes("backend")) {
|
|
243
|
+
if (flag === "-v" || flag === "--visualize") {
|
|
244
|
+
const { main: configMain } = await Promise.resolve().then(() => (init_bconfig(), bconfig_exports));
|
|
245
|
+
return configMain == null ? void 0 : configMain();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (flag === "--help") {
|
|
249
|
+
showHelp();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
init();
|
|
253
|
+
}
|
|
254
|
+
main2().catch((error) => {
|
|
255
|
+
console.error("Error:", error.message);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"customChecks": {
|
|
3
|
+
"requirements": "Remove unused imports and variables. Remove all console log statements."
|
|
4
|
+
},
|
|
5
|
+
"eslint": {
|
|
6
|
+
"enabled": true,
|
|
7
|
+
"rules": ["no-unused-vars"]
|
|
8
|
+
},
|
|
9
|
+
"typescript": {
|
|
10
|
+
"enabled": true
|
|
11
|
+
},
|
|
12
|
+
"lineLimit": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"limit": 300,
|
|
15
|
+
"prompt": "Split any file with over {{ linelimit }} lines into smaller files."
|
|
16
|
+
},
|
|
17
|
+
"folderLimit": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"limit": 15,
|
|
20
|
+
"prompt": "Split any folder with over {{ folderlimit }} items into smaller, compartmentalized folders."
|
|
21
|
+
},
|
|
22
|
+
"testCheck": {
|
|
23
|
+
"enabled": false,
|
|
24
|
+
"patterns": {
|
|
25
|
+
".vue": ".test.js",
|
|
26
|
+
".jsx": ".test.jsx",
|
|
27
|
+
".tsx": ".test.tsx"
|
|
28
|
+
},
|
|
29
|
+
"prompt": "Create test files for components that are missing them."
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bonzai-tree",
|
|
3
|
+
"version": "1.0.113",
|
|
4
|
+
"description": "Visualization and file management tools for codebases",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"bonzai-tree": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "RELEASE_CHANNEL=dev node src/index.js",
|
|
12
|
+
"build": "RELEASE_CHANNEL=prod tsup",
|
|
13
|
+
"build:beta": "RELEASE_CHANNEL=staging tsup",
|
|
14
|
+
"build:dev": "RELEASE_CHANNEL=dev tsup",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"release": "npm version patch && npm publish",
|
|
17
|
+
"release:beta": "npm run build:beta && npm publish --tag beta --ignore-scripts",
|
|
18
|
+
"release:dev": "npm run build:dev && npm publish --tag dev --ignore-scripts"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"visualization",
|
|
22
|
+
"codebase",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@modelcontextprotocol/sdk": "^1.25.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"eslint": "^9.39.2",
|
|
37
|
+
"tsup": "^8.5.1",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
|
+
}
|
|
40
|
+
}
|