bonzai-burn 1.0.19 → 1.0.20
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/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
// GET /git/burns - List all bonzai-burn branches
|
|
4
|
+
function listBurns(req, res) {
|
|
5
|
+
try {
|
|
6
|
+
// Get all bonzai-burn branches
|
|
7
|
+
let branchOutput;
|
|
8
|
+
try {
|
|
9
|
+
branchOutput = execSync('git branch --list "bonzai-burn*"', { encoding: 'utf-8' });
|
|
10
|
+
} catch (e) {
|
|
11
|
+
// No matching branches
|
|
12
|
+
branchOutput = '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const branches = branchOutput
|
|
16
|
+
.split('\n')
|
|
17
|
+
.filter(b => b.trim())
|
|
18
|
+
.map(b => b.trim().replace('* ', ''));
|
|
19
|
+
|
|
20
|
+
if (branches.length === 0) {
|
|
21
|
+
return res.json({ burns: [] });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Get timestamp for each branch
|
|
25
|
+
const burns = branches.map(branch => {
|
|
26
|
+
const timestamp = execSync(`git log -1 --format=%at ${branch}`, { encoding: 'utf-8' }).trim();
|
|
27
|
+
return {
|
|
28
|
+
name: branch,
|
|
29
|
+
timestamp: parseInt(timestamp) * 1000
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Sort chronologically (oldest first)
|
|
34
|
+
burns.sort((a, b) => a.timestamp - b.timestamp);
|
|
35
|
+
|
|
36
|
+
// Get current branch
|
|
37
|
+
const currentBranch = execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
38
|
+
|
|
39
|
+
res.json({
|
|
40
|
+
burns: burns.map(b => ({
|
|
41
|
+
...b,
|
|
42
|
+
current: b.name === currentBranch
|
|
43
|
+
}))
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
res.status(500).json({ error: error.message });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// POST /git/checkout - Checkout a branch
|
|
51
|
+
function checkoutBranch(req, res) {
|
|
52
|
+
try {
|
|
53
|
+
const { branchName } = req.body;
|
|
54
|
+
|
|
55
|
+
if (!branchName) {
|
|
56
|
+
return res.status(400).json({ error: 'branchName is required' });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Validate branch name to prevent command injection
|
|
60
|
+
if (!/^[a-zA-Z0-9_\-\.\/]+$/.test(branchName)) {
|
|
61
|
+
return res.status(400).json({ error: 'Invalid branch name' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
execSync(`git checkout ${branchName}`, { encoding: 'utf-8' });
|
|
65
|
+
|
|
66
|
+
res.json({ checkedOut: branchName });
|
|
67
|
+
} catch (error) {
|
|
68
|
+
res.status(500).json({ error: error.message });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = { listBurns, checkoutBranch };
|
|
@@ -9,6 +9,9 @@ function indexHandler(req, res) {
|
|
|
9
9
|
'POST /open-cursor': 'Open Cursor (body: {path, line?})',
|
|
10
10
|
'POST /shutdown': 'Gracefully shutdown the server',
|
|
11
11
|
'POST /scan_code_quality': 'Scan code quality (body: {projectPath})',
|
|
12
|
+
'POST /write': 'Write file content (body: {path, content})',
|
|
13
|
+
'GET /git/burns': 'List all bonzai-burn branches',
|
|
14
|
+
'POST /git/checkout': 'Checkout a branch (body: {branchName})',
|
|
12
15
|
'WS /terminal': 'Interactive terminal via WebSocket'
|
|
13
16
|
},
|
|
14
17
|
example: 'Try: /list or /read?path=README.md'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { ROOT } = require('../config');
|
|
4
|
+
|
|
5
|
+
function writeHandler(req, res) {
|
|
6
|
+
try {
|
|
7
|
+
const filePath = path.join(ROOT, req.body.path || '');
|
|
8
|
+
if (!filePath.startsWith(ROOT)) {
|
|
9
|
+
return res.status(400).send('Invalid path');
|
|
10
|
+
}
|
|
11
|
+
fs.writeFileSync(filePath, req.body.content, 'utf8');
|
|
12
|
+
res.json({ status: 'ok' });
|
|
13
|
+
} catch (e) {
|
|
14
|
+
res.status(500).send(e.message);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = writeHandler;
|
|
@@ -13,6 +13,8 @@ const deleteHandler = require('./handlers/delete');
|
|
|
13
13
|
const openCursorHandler = require('./handlers/open-cursor');
|
|
14
14
|
const shutdownHandler = require('./handlers/shutdown');
|
|
15
15
|
const scanCodeQualityHandler = require('./handlers/scan_code_quality');
|
|
16
|
+
const writeHandler = require('./handlers/write');
|
|
17
|
+
const { listBurns, checkoutBranch } = require('./handlers/git');
|
|
16
18
|
const { terminalHandler, setupTerminalWebSocket } = require('./handlers/terminal');
|
|
17
19
|
|
|
18
20
|
const app = express();
|
|
@@ -33,6 +35,9 @@ app.post('/delete', deleteHandler);
|
|
|
33
35
|
app.post('/open-cursor', openCursorHandler);
|
|
34
36
|
app.post('/shutdown', shutdownHandler);
|
|
35
37
|
app.post('/scan_code_quality', scanCodeQualityHandler);
|
|
38
|
+
app.post('/write', writeHandler);
|
|
39
|
+
app.get('/git/burns', listBurns);
|
|
40
|
+
app.post('/git/checkout', checkoutBranch);
|
|
36
41
|
app.get('/terminal', terminalHandler);
|
|
37
42
|
|
|
38
43
|
const port = 3001;
|