devbonzai 2.2.303 → 2.2.305
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/cli.js +2 -0
- package/package.json +4 -2
- package/templates/handlers/index.js +2 -1
- package/templates/handlers/terminal.js +93 -0
- package/templates/receiver.js +28 -1
package/cli.js
CHANGED
|
@@ -109,6 +109,8 @@ async function main() {
|
|
|
109
109
|
packageJson.dependencies.express = "^4.18.2";
|
|
110
110
|
packageJson.dependencies.cors = "^2.8.5";
|
|
111
111
|
packageJson.dependencies["@babel/parser"] = "^7.23.0";
|
|
112
|
+
packageJson.dependencies["node-pty"] = "^1.0.0";
|
|
113
|
+
packageJson.dependencies.ws = "^8.16.0";
|
|
112
114
|
|
|
113
115
|
// Add script to run receiver
|
|
114
116
|
if (!packageJson.scripts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devbonzai",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.305",
|
|
4
4
|
"description": "Quickly set up a local file server in any repository for browser-based file access",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"express": "^4.18.2",
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
|
-
"@babel/parser": "^7.23.0"
|
|
27
|
+
"@babel/parser": "^7.23.0",
|
|
28
|
+
"node-pty": "^1.0.0",
|
|
29
|
+
"ws": "^8.16.0"
|
|
28
30
|
}
|
|
29
31
|
}
|
|
@@ -8,7 +8,8 @@ function indexHandler(req, res) {
|
|
|
8
8
|
'POST /delete': 'Delete file or directory (body: {path})',
|
|
9
9
|
'POST /open-cursor': 'Open Cursor (body: {path, line?})',
|
|
10
10
|
'POST /shutdown': 'Gracefully shutdown the server',
|
|
11
|
-
'POST /scan_code_quality': 'Scan code quality (body: {projectPath})'
|
|
11
|
+
'POST /scan_code_quality': 'Scan code quality (body: {projectPath})',
|
|
12
|
+
'WS /terminal?cwd=<path>': 'WebSocket terminal connection (optional cwd query param)'
|
|
12
13
|
},
|
|
13
14
|
example: 'Try: /list or /read?path=README.md'
|
|
14
15
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const pty = require('node-pty');
|
|
2
|
+
|
|
3
|
+
// Store active terminal sessions
|
|
4
|
+
const terminals = new Map();
|
|
5
|
+
|
|
6
|
+
function handleTerminalConnection(ws, workingDirectory) {
|
|
7
|
+
// Use user's default shell, fallback to /bin/zsh
|
|
8
|
+
const shell = process.platform === 'win32' ? 'powershell.exe' : (process.env.SHELL || '/bin/zsh');
|
|
9
|
+
const cwd = workingDirectory || process.env.HOME;
|
|
10
|
+
|
|
11
|
+
console.log('🖥️ Terminal session started in:', cwd);
|
|
12
|
+
|
|
13
|
+
const ptyProcess = pty.spawn(shell, [], {
|
|
14
|
+
name: 'xterm-256color',
|
|
15
|
+
cols: 80,
|
|
16
|
+
rows: 24,
|
|
17
|
+
cwd: cwd,
|
|
18
|
+
env: {
|
|
19
|
+
...process.env,
|
|
20
|
+
TERM: 'xterm-256color',
|
|
21
|
+
COLORTERM: 'truecolor',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const terminalId = Date.now().toString();
|
|
26
|
+
terminals.set(terminalId, { pty: ptyProcess, ws });
|
|
27
|
+
|
|
28
|
+
// Send PTY output to WebSocket
|
|
29
|
+
ptyProcess.onData((data) => {
|
|
30
|
+
try {
|
|
31
|
+
if (ws.readyState === 1) { // WebSocket.OPEN
|
|
32
|
+
ws.send(data);
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error('Error sending to WebSocket:', err);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Handle incoming messages from WebSocket
|
|
40
|
+
ws.on('message', (msg) => {
|
|
41
|
+
try {
|
|
42
|
+
const message = msg.toString();
|
|
43
|
+
|
|
44
|
+
// Check if it's a resize command
|
|
45
|
+
if (message.startsWith('\x1b[8;')) {
|
|
46
|
+
// Parse resize: ESC[8;rows;colst
|
|
47
|
+
const match = message.match(/\x1b\[8;(\d+);(\d+)t/);
|
|
48
|
+
if (match) {
|
|
49
|
+
const rows = parseInt(match[1], 10);
|
|
50
|
+
const cols = parseInt(match[2], 10);
|
|
51
|
+
ptyProcess.resize(cols, rows);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Check for JSON resize command
|
|
57
|
+
if (message.startsWith('{')) {
|
|
58
|
+
try {
|
|
59
|
+
const json = JSON.parse(message);
|
|
60
|
+
if (json.type === 'resize' && json.cols && json.rows) {
|
|
61
|
+
ptyProcess.resize(json.cols, json.rows);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// Not JSON, treat as regular input
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Regular terminal input
|
|
70
|
+
ptyProcess.write(message);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error('Error processing message:', err);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Clean up on WebSocket close
|
|
77
|
+
ws.on('close', () => {
|
|
78
|
+
console.log('🖥️ Terminal session closed');
|
|
79
|
+
ptyProcess.kill();
|
|
80
|
+
terminals.delete(terminalId);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Handle PTY exit
|
|
84
|
+
ptyProcess.onExit(({ exitCode, signal }) => {
|
|
85
|
+
console.log(`🖥️ Terminal process exited (code: ${exitCode}, signal: ${signal})`);
|
|
86
|
+
terminals.delete(terminalId);
|
|
87
|
+
if (ws.readyState === 1) {
|
|
88
|
+
ws.close();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = { handleTerminalConnection };
|
package/templates/receiver.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const express = require('./node_modules/express');
|
|
4
4
|
const cors = require('./node_modules/cors');
|
|
5
|
+
const WebSocket = require('./node_modules/ws');
|
|
6
|
+
const { ROOT } = require('./config');
|
|
5
7
|
|
|
6
8
|
// Import handlers
|
|
7
9
|
const indexHandler = require('./handlers/index');
|
|
@@ -11,6 +13,7 @@ const deleteHandler = require('./handlers/delete');
|
|
|
11
13
|
const openCursorHandler = require('./handlers/open-cursor');
|
|
12
14
|
const shutdownHandler = require('./handlers/shutdown');
|
|
13
15
|
const scanCodeQualityHandler = require('./handlers/scan_code_quality');
|
|
16
|
+
const { handleTerminalConnection } = require('./handlers/terminal');
|
|
14
17
|
|
|
15
18
|
const app = express();
|
|
16
19
|
|
|
@@ -27,6 +30,30 @@ app.post('/shutdown', shutdownHandler);
|
|
|
27
30
|
app.post('/scan_code_quality', scanCodeQualityHandler);
|
|
28
31
|
|
|
29
32
|
const port = 3001;
|
|
30
|
-
app.listen(port, () => {
|
|
33
|
+
const server = app.listen(port, () => {
|
|
31
34
|
console.log('📂 File server running on http://localhost:' + port);
|
|
32
35
|
});
|
|
36
|
+
|
|
37
|
+
// WebSocket server for terminal
|
|
38
|
+
const wss = new WebSocket.Server({
|
|
39
|
+
server,
|
|
40
|
+
path: '/terminal'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
wss.on('connection', (ws, req) => {
|
|
44
|
+
// Extract working directory from query string if provided
|
|
45
|
+
let workingDirectory = ROOT;
|
|
46
|
+
|
|
47
|
+
if (req.url) {
|
|
48
|
+
const urlMatch = req.url.match(/[?&]cwd=([^&]+)/);
|
|
49
|
+
if (urlMatch) {
|
|
50
|
+
try {
|
|
51
|
+
workingDirectory = decodeURIComponent(urlMatch[1]);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.warn('Invalid cwd parameter, using default:', e.message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
handleTerminalConnection(ws, workingDirectory);
|
|
59
|
+
});
|