nothumanallowed 13.5.72 → 13.5.74

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": "nothumanallowed",
3
- "version": "13.5.72",
3
+ "version": "13.5.74",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -4278,6 +4278,25 @@ module.exports = { get, set, del, exists };
4278
4278
  fs.mkdirSync(path.join(sandboxDir, 'server', 'services'), { recursive: true });
4279
4279
  fs.writeFileSync(path.join(sandboxDir, 'server', 'services', 'cache.js'), cacheShim, 'utf8');
4280
4280
 
4281
+ // Errors middleware shim — always overwrite to ensure complete exports
4282
+ const errorsShim = `
4283
+ // NHA WebCraft Sandbox — middleware/errors shim
4284
+ class AppError extends Error { constructor(message, statusCode) { super(message); this.statusCode = statusCode || 500; this.isOperational = true; } }
4285
+ function notFoundHandler(req, res, next) { res.status(404).json({ error: 'Not found: ' + req.originalUrl }); }
4286
+ function errorHandler(err, req, res, next) {
4287
+ var code = err.statusCode || err.status || 500;
4288
+ var msg = (process.env.NODE_ENV !== 'production' || err.isOperational) ? err.message : 'Internal Server Error';
4289
+ res.status(code).json({ error: msg });
4290
+ }
4291
+ module.exports = errorHandler;
4292
+ module.exports.AppError = AppError;
4293
+ module.exports.errorHandler = errorHandler;
4294
+ module.exports.notFoundHandler = notFoundHandler;
4295
+ `;
4296
+ fs.mkdirSync(path.join(sandboxDir, 'server', 'middleware'), { recursive: true });
4297
+ // Always overwrite — older shim versions may be missing exports like notFoundHandler
4298
+ fs.writeFileSync(path.join(sandboxDir, 'server', 'middleware', 'errors.js'), errorsShim, 'utf8');
4299
+
4281
4300
  // Models shim — LLM often generates require('../models/User') etc. that don't exist
4282
4301
  // Create a generic User model shim backed by the in-memory DB shim
4283
4302
  const userModelShim = `
@@ -4373,6 +4392,11 @@ module.exports = { validateEmail, sanitizeText, validatePassword, validateUserna
4373
4392
  [/require\(['"]\.\.\/\.\.\/config['"]\)/g, "{env:process.env}"],
4374
4393
  [/require\(['"]\.\.\/config['"]\)/g, "{env:process.env}"],
4375
4394
  [/require\(['"]\.\/config['"]\)/g, "{env:process.env}"],
4395
+ // middleware/errors — LLM generates a custom error handler that doesn't exist
4396
+ [/require\(['"]\.\.\/middleware\/errors['"]\)/g, "require('../middleware/errors')"],
4397
+ [/require\(['"]\.\/middleware\/errors['"]\)/g, "require('./middleware/errors')"],
4398
+ [/require\(['"]\.\.\/middleware\/errorHandler['"]\)/g, "require('../middleware/errors')"],
4399
+ [/require\(['"]\.\.\/middleware\/error['"]\)/g, "require('../middleware/errors')"],
4376
4400
  // models/* — redirect to shims in server/models/
4377
4401
  [/require\(['"]\.\.\/models\/User['"]\)/g, "require('../models/User')"],
4378
4402
  [/require\(['"]\.\/models\/User['"]\)/g, "require('./models/User')"],
@@ -4504,20 +4528,33 @@ module.exports = { validateEmail, sanitizeText, validatePassword, validateUserna
4504
4528
  global._wcSandboxPort = freePort;
4505
4529
  global._wcSandboxDir = sandboxDir;
4506
4530
 
4531
+ let _lastMissingModule = null;
4532
+ let _lastCrashError = null;
4507
4533
  proc.stdout.on('data', d => { const l = d.toString().trim(); if (l) sendLog(' [server] ' + l); });
4508
4534
  proc.stderr.on('data', d => {
4509
4535
  const raw = d.toString();
4510
- // Extract meaningful error: MODULE_NOT_FOUND → trigger auto-fix
4536
+ // MODULE_NOT_FOUND
4511
4537
  const modMatch = raw.match(/Cannot find module '([^']+)'/);
4512
4538
  if (modMatch) {
4513
4539
  const missingMod = modMatch[1];
4540
+ _lastMissingModule = missingMod;
4541
+ _lastCrashError = "Cannot find module '" + missingMod + "'";
4514
4542
  sendLog(' ❌ Modulo mancante: ' + missingMod);
4515
- // Store error for auto-fix agent — will be picked up by frontend
4516
4543
  if (!global._wcAutoFixQueue) global._wcAutoFixQueue = [];
4517
4544
  global._wcAutoFixQueue.push({ type: 'module_not_found', module: missingMod, dir: sandboxDir, ts: Date.now() });
4518
4545
  sendLog(' 🤖 Avvio auto-fix...');
4519
4546
  return;
4520
4547
  }
4548
+ // TypeError / SyntaxError / ReferenceError — capture for autofix
4549
+ const crashMatch = raw.match(/^(TypeError|SyntaxError|ReferenceError|Error):\s+(.+)/m);
4550
+ if (crashMatch) {
4551
+ _lastCrashError = crashMatch[1] + ': ' + crashMatch[2].trim();
4552
+ sendLog(' ❌ ' + _lastCrashError);
4553
+ if (!global._wcAutoFixQueue) global._wcAutoFixQueue = [];
4554
+ global._wcAutoFixQueue.push({ type: 'crash_error', error: _lastCrashError, dir: sandboxDir, ts: Date.now() });
4555
+ sendLog(' 🤖 Avvio auto-fix...');
4556
+ return;
4557
+ }
4521
4558
  // Skip node internals noise
4522
4559
  const l = raw.trim();
4523
4560
  if (!l || l.startsWith('at ') || l.startsWith('(node:') || l === '^') return;
@@ -4532,7 +4569,7 @@ module.exports = { validateEmail, sanitizeText, validatePassword, validateUserna
4532
4569
  s.on('connect', () => { s.destroy(); resolve(); });
4533
4570
  s.on('error', () => {
4534
4571
  s.destroy();
4535
- if (++attempts > 20) reject(new Error('Server non risponde dopo 10s'));
4572
+ if (++attempts > 20) reject(new Error(_lastMissingModule ? "Cannot find module '" + _lastMissingModule + "'" : 'Server non risponde dopo 10s'));
4536
4573
  else setTimeout(tryConnect, 500);
4537
4574
  });
4538
4575
  };
@@ -7353,6 +7353,9 @@ function wcStartAutoFixPoller() {
7353
7353
  if (item.type === 'module_not_found' && _wcAutoFixAttempts < 3) {
7354
7354
  _wcAutoFixAttempts++;
7355
7355
  wcTriggerAutoFix(item.module);
7356
+ } else if (item.type === 'crash_error' && _wcAutoFixAttempts < 3) {
7357
+ _wcAutoFixAttempts++;
7358
+ wcTriggerCrashFix(item.error);
7356
7359
  }
7357
7360
  });
7358
7361
  }).catch(function(){});
@@ -7366,7 +7369,7 @@ function wcStopAutoFixPoller() {
7366
7369
  async function wcTriggerAutoFix(missingModule) {
7367
7370
  if (wcChatRunning) return;
7368
7371
  var fixMsg = 'AUTO-FIX: Cannot find module ' + missingModule + String.fromCharCode(10) + 'Analizza tutti i file del progetto e correggi il require/import per questo modulo. Se il modulo non esiste, rimuovi il require e implementa la funzionalita con moduli disponibili o Node.js built-in.';
7369
- wcChat.push({ role: 'user', text: '&#129302; Auto-fix modulo mancante: ' + missingModule });
7372
+ wcChat.push({ role: 'user', text: '\uD83E\uDD16 Auto-fix modulo mancante: ' + missingModule });
7370
7373
  wcChatRunning = true;
7371
7374
  renderWebCraft(document.getElementById('content'));
7372
7375
  wcScrollChatToBottom();
@@ -7409,6 +7412,53 @@ async function wcTriggerAutoFix(missingModule) {
7409
7412
  renderWebCraft(document.getElementById('content'));
7410
7413
  wcScrollChatToBottom();
7411
7414
  }
7415
+ async function wcTriggerCrashFix(errorMsg) {
7416
+ if (wcChatRunning) return;
7417
+ var fixMsg = 'AUTO-FIX: ' + errorMsg + String.fromCharCode(10) + 'Il server Express ha crashato con questo errore. Analizza tutti i file del progetto, individua la causa e correggi il codice. Modifica i file necessari usando i tool disponibili.';
7418
+ wcChat.push({ role: 'user', text: '\uD83E\uDD16 Auto-fix crash: ' + errorMsg });
7419
+ wcChatRunning = true;
7420
+ renderWebCraft(document.getElementById('content'));
7421
+ wcScrollChatToBottom();
7422
+
7423
+ try {
7424
+ var r = await fetch(API + '/api/studio/webcraft/agent', {
7425
+ method: 'POST',
7426
+ headers: { 'Content-Type': 'application/json' },
7427
+ body: JSON.stringify({ projectName: wcState.projectName, message: fixMsg, autofix: true })
7428
+ });
7429
+ if (!r.ok) { wcChatRunning = false; renderWebCraft(document.getElementById('content')); return; }
7430
+
7431
+ var agentMsg = { role: 'agent', text: '', tools: [] };
7432
+ wcChat.push(agentMsg);
7433
+ var reader4 = r.body.getReader();
7434
+ var dec4 = new TextDecoder();
7435
+ var buf4 = '';
7436
+ while (true) {
7437
+ var res4 = await reader4.read();
7438
+ if (res4.done) break;
7439
+ buf4 += dec4.decode(res4.value, { stream: true });
7440
+ var parts4 = buf4.split(String.fromCharCode(10)+String.fromCharCode(10));
7441
+ buf4 = parts4.pop();
7442
+ for (var pi4 = 0; pi4 < parts4.length; pi4++) {
7443
+ var line4 = parts4[pi4].replace(/^data: /, '').trim();
7444
+ if (!line4) continue;
7445
+ try {
7446
+ var ev4 = JSON.parse(line4);
7447
+ if (ev4.type === 'text') { agentMsg.text += ev4.token; }
7448
+ else if (ev4.type === 'tool') { agentMsg.tools.push({ op: ev4.op, path: ev4.path, result: ev4.result, oldSnippet: ev4.oldSnippet || '', newSnippet: ev4.newSnippet || '' }); }
7449
+ else if (ev4.type === 'done') { wcChatRunning = false; if (ev4.changed) { wcReloadProjectFiles(); } }
7450
+ else if (ev4.type === 'restart_sandbox') { wcStartSandbox(); }
7451
+ else if (ev4.type === 'error') { agentMsg.text += String.fromCharCode(10)+'Errore: '+ev4.msg; wcChatRunning = false; }
7452
+ } catch(_) {}
7453
+ }
7454
+ }
7455
+ } catch(_) {}
7456
+
7457
+ wcChatRunning = false;
7458
+ renderWebCraft(document.getElementById('content'));
7459
+ wcScrollChatToBottom();
7460
+ }
7461
+
7412
7462
  var _wcPhaseKeys = ['files','shims','pkg','env','deps','install','start'];
7413
7463
  function wcTogglePhase(idx) { var k = _wcPhaseKeys[idx]; if (k) { wcSandboxExpanded[k] = !wcSandboxExpanded[k]; renderWebCraft(document.getElementById('content')); } }
7414
7464
 
@@ -8084,7 +8134,7 @@ async function wcFixSandboxError() {
8084
8134
  String.fromCharCode(10) + String.fromCharCode(10) +
8085
8135
  'STACKTRACE COMPLETO:' + String.fromCharCode(10) + errText;
8086
8136
  // Push as user message so it appears in chat
8087
- wcChat.push({ role: 'user', text: '&#129302; Correggi errore sandbox' });
8137
+ wcChat.push({ role: 'user', text: '\uD83E\uDD16 Correggi errore sandbox' });
8088
8138
  wcScrollChatToBottom();
8089
8139
  wcChatRunning = true;
8090
8140
  renderWebCraft(document.getElementById('content'));