nothumanallowed 16.0.36 → 16.0.37

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": "16.0.36",
3
+ "version": "16.0.37",
4
4
  "description": "Local AI assistant: 80 tools (Gmail, Calendar, Drive, GitHub, Slack, browser, code, files), 38 agents, visual workflows (Studio, AWF, WebCraft). Install with `npm i -g nothumanallowed`, run with `nha ui`. Free tier built-in (Liara), no API key required. Your data stays on your PC — OAuth tokens local, no cloud. Open-source MIT.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '16.0.36';
8
+ export const VERSION = '16.0.37';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -218,6 +218,17 @@ class SandboxManager {
218
218
  emit({ type: 'warn', msg: `Pre-flight repair: ${repaired.length} file${repaired.length === 1 ? '' : 's'} quarantined (corrupted content) → ${repaired.join(', ')}. Re-generate from chat to restore them.` });
219
219
  }
220
220
 
221
+ // Pre-flight: create missing data dirs/files referenced by code.
222
+ // LLMs frequently generate `fs.writeFile('data/users.json', ...)` without
223
+ // creating data/ first → ENOENT crash on boot. Scan code for these
224
+ // references and seed empty placeholders BEFORE the sandbox starts.
225
+ try {
226
+ const dataFiles = _detectMissingDataFiles(projectDir);
227
+ if (dataFiles.length > 0) {
228
+ emit({ type: 'status', msg: `Pre-flight: seeded ${dataFiles.length} data file${dataFiles.length === 1 ? '' : 's'} → ${dataFiles.slice(0, 5).join(', ')}${dataFiles.length > 5 ? '...' : ''}` });
229
+ }
230
+ } catch {}
231
+
221
232
  // ── Phase 2: Dependencies (pre-scan + batch install) ──────────────────
222
233
  // Pre-scan the project source files for require()/import statements and
223
234
  // diff against package.json + node_modules. Install everything missing in
@@ -454,6 +465,36 @@ class SandboxManager {
454
465
  return this.start(projectName, projectDir, emit, _attempt + 1);
455
466
  }
456
467
  }
468
+ }
469
+
470
+ // ── Tier 1b: ENOENT on file write → create missing path + retry ──────
471
+ // Deterministic. LLM SaaS code often writes to data/users.json without
472
+ // mkdir -p data/ first → ENOENT. We detect, create the dir + empty
473
+ // placeholder JSON, and retry. Zero LLM call needed.
474
+ const enoentMatch = stderrBuf.match(/ENOENT[^']*open\s+['"]([^'"]+)['"]/);
475
+ if (enoentMatch && _attempt < MAX_RETRIES) {
476
+ const missingPath = enoentMatch[1];
477
+ // Only auto-create if path is inside the project
478
+ const projectAbs = path.resolve(projectDir);
479
+ const missingAbs = path.resolve(missingPath);
480
+ if (missingAbs.startsWith(projectAbs)) {
481
+ emit({ type: 'phase', phase: 'autofix', msg: `ENOENT on ${missingPath} — creating directory + empty placeholder...` });
482
+ try {
483
+ ensureDir(path.dirname(missingAbs));
484
+ if (!fs.existsSync(missingAbs)) {
485
+ const ext = path.extname(missingAbs).toLowerCase();
486
+ let stub = '';
487
+ if (ext === '.json') stub = /users|posts|items|list|todos|comments|orders|products/i.test(missingPath) ? '[]' : '{}';
488
+ else if (ext === '.sqlite' || ext === '.db') { /* skip binary */ }
489
+ else stub = '';
490
+ if (ext !== '.sqlite' && ext !== '.db') fs.writeFileSync(missingAbs, stub, 'utf-8');
491
+ }
492
+ emit({ type: 'status', msg: `Created ${missingPath} — retrying (attempt ${_attempt + 1}/${MAX_RETRIES})...` });
493
+ return this.start(projectName, projectDir, emit, _attempt + 1);
494
+ } catch (e) {
495
+ emit({ type: 'warn', msg: `Failed to create ${missingPath}: ${e.message.slice(0, 200)}` });
496
+ }
497
+ }
457
498
  } else if (missingModules.length > 0 && uniqueMissing.length === 0) {
458
499
  // All missing modules are shimmable in THIS version of the CLI. If we
459
500
  // reached this branch, the user has an OLDER CLI installed that doesn't
@@ -3554,6 +3595,61 @@ function _placeholderContent(kind, refPath) {
3554
3595
  return '';
3555
3596
  }
3556
3597
 
3598
+ /**
3599
+ * Scan all .js/.mjs/.ts files for filesystem paths referenced in string
3600
+ * literals (typically used for file-based storage by LLM-generated SaaS code:
3601
+ * fs.writeFile('data/users.json', ...), fs.readFile('db/posts.json'), etc).
3602
+ * Creates missing directories + empty JSON placeholders so the app can boot
3603
+ * instead of crashing with ENOENT on first write.
3604
+ */
3605
+ export function _detectMissingDataFiles(projectDir) {
3606
+ const created = [];
3607
+ const exts = new Set(['.js', '.mjs', '.cjs', '.ts']);
3608
+ const skipDirs = new Set(['node_modules', '.git', '.nha-shims', 'dist', 'build', '.next', 'public']);
3609
+ // Match string literals that look like project-relative storage paths:
3610
+ // "data/users.json", './db/posts.json', "uploads/", "logs/app.log"
3611
+ // Skip absolute paths, URLs, node_modules/, dotfiles.
3612
+ const re = /['"`](?:\.\/)?((?:data|db|storage|uploads|logs|tmp|cache|sessions)\/[A-Za-z0-9_\-./]+)['"`]/g;
3613
+ const stack = [projectDir];
3614
+ const seen = new Set();
3615
+ while (stack.length) {
3616
+ const cur = stack.pop();
3617
+ let entries;
3618
+ try { entries = fs.readdirSync(cur, { withFileTypes: true }); } catch { continue; }
3619
+ for (const ent of entries) {
3620
+ if (skipDirs.has(ent.name) || ent.name.startsWith('.')) continue;
3621
+ const abs = path.join(cur, ent.name);
3622
+ if (ent.isDirectory()) { stack.push(abs); continue; }
3623
+ if (!exts.has(path.extname(ent.name))) continue;
3624
+ let content;
3625
+ try { content = fs.readFileSync(abs, 'utf-8'); } catch { continue; }
3626
+ let m;
3627
+ re.lastIndex = 0;
3628
+ while ((m = re.exec(content)) !== null) {
3629
+ const rel = m[1].replace(/\\/g, '/');
3630
+ if (seen.has(rel)) continue;
3631
+ seen.add(rel);
3632
+ const fullPath = path.join(projectDir, rel);
3633
+ try {
3634
+ ensureDir(path.dirname(fullPath));
3635
+ // Only create file if it looks like a file (has extension) and doesn't exist
3636
+ if (path.extname(rel) && !fs.existsSync(fullPath)) {
3637
+ const ext = path.extname(rel).toLowerCase();
3638
+ let stub = '';
3639
+ if (ext === '.json') stub = rel.includes('users') || rel.includes('posts') || rel.includes('items') || rel.includes('list') ? '[]' : '{}';
3640
+ else if (ext === '.txt' || ext === '.log') stub = '';
3641
+ else if (ext === '.sqlite' || ext === '.db') continue; // skip binary
3642
+ else stub = '';
3643
+ fs.writeFileSync(fullPath, stub, 'utf-8');
3644
+ created.push(rel);
3645
+ }
3646
+ } catch {}
3647
+ }
3648
+ }
3649
+ }
3650
+ return created;
3651
+ }
3652
+
3557
3653
  export function autoRepairProject(projectName) {
3558
3654
  const dir = ProjectStore.dir(projectName);
3559
3655
  if (!fs.existsSync(dir)) throw new Error('project not found');
@@ -3562,6 +3658,13 @@ export function autoRepairProject(projectName) {
3562
3658
  const filesRepaired = new Set();
3563
3659
  const filesCreated = [];
3564
3660
 
3661
+ // Phase 0: create missing data files referenced by code (data/X.json, etc)
3662
+ const dataCreated = _detectMissingDataFiles(dir);
3663
+ for (const f of dataCreated) {
3664
+ filesCreated.push(f);
3665
+ repairs.push({ file: f, kind: 'missing-data-file', source: 'code-reference' });
3666
+ }
3667
+
3565
3668
  // Walk every HTML file in the project
3566
3669
  const stack = [dir];
3567
3670
  const skipDirs = new Set(['node_modules', '.git', '.nha-shims', 'dist', 'build', '.next']);
@@ -4031,6 +4134,14 @@ const _LLM_ERROR_MARKERS = [
4031
4134
  /^\s*error code:\s*\d{3,4}/i,
4032
4135
  // Standalone HTTP status phrase at the start of a code file is suspicious
4033
4136
  /^\s*(HTTP\/[\d.]+\s+)?[45]\d{2}\s+/,
4137
+ // NHA/Liara backend retry-wrapper errors leaked as file content:
4138
+ // "/* Retry: NHA Free 502: {"error":"Failed to reach Liara",...}"
4139
+ // "Retry: NHA 503", "// NHA Free Error 429"
4140
+ /^\s*(?:\/\*\s*|\/\/\s*)?Retry:?\s*NHA(\s+Free)?(\s+\d{3})?/i,
4141
+ /^\s*(?:\/\*\s*|\/\/\s*)?Failed to reach (Liara|NHA|OpenAI|Anthropic|Gemini|provider)/i,
4142
+ /^\s*\{?\s*"error"\s*:\s*"Failed to reach/i,
4143
+ // Plain "fetch failed", "ECONNRESET" etc. as first line of a code file
4144
+ /^\s*(?:\/\*\s*|\/\/\s*)?(?:fetch failed|ECONNRESET|ECONNREFUSED|ETIMEDOUT)\b/i,
4034
4145
  ];
4035
4146
 
4036
4147
  function _looksLikeLLMError(content) {