devbonzai 2.2.302 → 2.2.303

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devbonzai",
3
- "version": "2.2.302",
3
+ "version": "2.2.303",
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": {
@@ -7,7 +7,8 @@ function indexHandler(req, res) {
7
7
  'GET /read?path=<filepath>': 'Read file content',
8
8
  'POST /delete': 'Delete file or directory (body: {path})',
9
9
  'POST /open-cursor': 'Open Cursor (body: {path, line?})',
10
- 'POST /shutdown': 'Gracefully shutdown the server'
10
+ 'POST /shutdown': 'Gracefully shutdown the server',
11
+ 'POST /scan_code_quality': 'Scan code quality (body: {projectPath})'
11
12
  },
12
13
  example: 'Try: /list or /read?path=README.md'
13
14
  });
@@ -0,0 +1,144 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { ROOT } = require('../config');
4
+
5
+ function scanCodeQualityHandler(req, res) {
6
+ try {
7
+ const { projectPath } = req.body;
8
+
9
+ if (!projectPath) {
10
+ return res.status(400).json({ error: 'projectPath is required' });
11
+ }
12
+
13
+ const targetPath = path.join(ROOT, projectPath);
14
+
15
+ if (!targetPath.startsWith(ROOT)) {
16
+ return res.status(400).json({ error: 'Invalid path' });
17
+ }
18
+
19
+ if (!fs.existsSync(targetPath)) {
20
+ return res.status(404).json({ error: 'Path not found' });
21
+ }
22
+
23
+ const issues = [];
24
+
25
+ // Basic code quality checks
26
+ function scanDirectory(dir) {
27
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
28
+
29
+ for (const entry of entries) {
30
+ const fullPath = path.join(dir, entry.name);
31
+ const relativePath = path.relative(ROOT, fullPath);
32
+
33
+ // Skip node_modules and other ignored directories
34
+ if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === 'bonzai') {
35
+ continue;
36
+ }
37
+
38
+ if (entry.isDirectory()) {
39
+ scanDirectory(fullPath);
40
+ } else if (entry.isFile()) {
41
+ // Check file size (warn if > 500KB)
42
+ const stats = fs.statSync(fullPath);
43
+ if (stats.size > 500 * 1024) {
44
+ issues.push({
45
+ file: relativePath,
46
+ severity: 'warning',
47
+ message: `Large file detected (${(stats.size / 1024).toFixed(2)}KB). Consider splitting into smaller modules.`,
48
+ type: 'file-size'
49
+ });
50
+ }
51
+
52
+ // Check for common code quality issues in JS/TS files
53
+ if (entry.name.endsWith('.js') || entry.name.endsWith('.jsx') ||
54
+ entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) {
55
+ try {
56
+ const content = fs.readFileSync(fullPath, 'utf8');
57
+ const lines = content.split('\n');
58
+
59
+ // Check for very long lines
60
+ lines.forEach((line, index) => {
61
+ if (line.length > 200) {
62
+ issues.push({
63
+ file: relativePath,
64
+ line: index + 1,
65
+ severity: 'info',
66
+ message: `Long line detected (${line.length} characters). Consider breaking into multiple lines.`,
67
+ type: 'line-length'
68
+ });
69
+ }
70
+ });
71
+
72
+ // Check for TODO/FIXME comments
73
+ lines.forEach((line, index) => {
74
+ if (line.match(/TODO|FIXME|XXX|HACK/i)) {
75
+ issues.push({
76
+ file: relativePath,
77
+ line: index + 1,
78
+ severity: 'info',
79
+ message: `TODO/FIXME comment found: ${line.trim().substring(0, 100)}`,
80
+ type: 'todo-comment'
81
+ });
82
+ }
83
+ });
84
+
85
+ // Check for console.log statements (potential debug code)
86
+ lines.forEach((line, index) => {
87
+ if (line.match(/console\.(log|debug|info|warn|error)/) && !line.includes('//')) {
88
+ issues.push({
89
+ file: relativePath,
90
+ line: index + 1,
91
+ severity: 'warning',
92
+ message: `Console statement found. Consider removing or using a proper logging library.`,
93
+ type: 'console-statement'
94
+ });
95
+ }
96
+ });
97
+
98
+ } catch (e) {
99
+ // Skip files that can't be read
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ const stat = fs.statSync(targetPath);
107
+ if (stat.isDirectory()) {
108
+ scanDirectory(targetPath);
109
+ } else {
110
+ // Single file scan
111
+ const relativePath = path.relative(ROOT, targetPath);
112
+ const content = fs.readFileSync(targetPath, 'utf8');
113
+ const lines = content.split('\n');
114
+
115
+ lines.forEach((line, index) => {
116
+ if (line.length > 200) {
117
+ issues.push({
118
+ file: relativePath,
119
+ line: index + 1,
120
+ severity: 'info',
121
+ message: `Long line detected (${line.length} characters)`,
122
+ type: 'line-length'
123
+ });
124
+ }
125
+ });
126
+ }
127
+
128
+ res.json({
129
+ success: true,
130
+ issues: issues,
131
+ totalIssues: issues.length,
132
+ summary: {
133
+ errors: issues.filter(i => i.severity === 'error').length,
134
+ warnings: issues.filter(i => i.severity === 'warning').length,
135
+ info: issues.filter(i => i.severity === 'info').length
136
+ }
137
+ });
138
+
139
+ } catch (e) {
140
+ res.status(500).json({ error: e.message });
141
+ }
142
+ }
143
+
144
+ module.exports = scanCodeQualityHandler;
@@ -10,6 +10,7 @@ const readHandler = require('./handlers/read');
10
10
  const deleteHandler = require('./handlers/delete');
11
11
  const openCursorHandler = require('./handlers/open-cursor');
12
12
  const shutdownHandler = require('./handlers/shutdown');
13
+ const scanCodeQualityHandler = require('./handlers/scan_code_quality');
13
14
 
14
15
  const app = express();
15
16
 
@@ -23,6 +24,7 @@ app.get('/read', readHandler);
23
24
  app.post('/delete', deleteHandler);
24
25
  app.post('/open-cursor', openCursorHandler);
25
26
  app.post('/shutdown', shutdownHandler);
27
+ app.post('/scan_code_quality', scanCodeQualityHandler);
26
28
 
27
29
  const port = 3001;
28
30
  app.listen(port, () => {